Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

refactor: host hyphenate-style-name (#3421)

Bogdan Chadkina74f8954873b
diff --git a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
index 6b42e0b7cc..32f820f571 100644
--- a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
@@ -25,7 +25,7 @@ import type {
StyleSource,
StyleSources,
} from "@webstudio-is/sdk";
-import { toProperty } from "@webstudio-is/css-engine";
+import { hyphenateProperty } from "@webstudio-is/css-engine";
import {
$breakpoints,
$instances,
@@ -225,7 +225,7 @@ export const TooltipContent = ({
cursor: "text",
}}
>
- {scrollableContent ?? properties.map(toProperty).join("\n")}
+ {scrollableContent ?? properties.map(hyphenateProperty).join("\n")}
</Text>
</ScrollArea>
{descriptionWithFallback && <Text>{descriptionWithFallback}</Text>}
diff --git a/apps/builder/package.json b/apps/builder/package.json
index 2d4883c032..66a25fef1b 100644
--- a/apps/builder/package.json
+++ b/apps/builder/package.json
@@ -88,7 +88,6 @@
"downshift": "^6.1.7",
"fast-deep-equal": "^3.1.3",
"hono": "^3.7.3",
- "hyphenate-style-name": "^1.0.4",
"immer": "^10.0.3",
"immerhin": "^0.9.0",
"lexical": "^0.14.3",
@@ -134,8 +133,6 @@
"@storybook/react": "^8.1.2",
"@testing-library/react-hooks": "^8.0.1",
"@types/cookie": "^0.6.0",
- "@types/hyphenate-style-name": "^1.0.0",
- "@types/lodash.debounce": "^4.0.6",
"@types/prismjs": "^1.26.0",
"@types/react": "^18.2.70",
"@types/react-dom": "^18.2.25",
diff --git a/packages/css-data/package.json b/packages/css-data/package.json
index f467a336bf..fd94e57b69 100644
--- a/packages/css-data/package.json
+++ b/packages/css-data/package.json
@@ -15,7 +15,6 @@
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/css-tree": "^2.3.1",
- "@types/hyphenate-style-name": "^1.0.0",
"@types/node": "^20.12.7",
"@webstudio-is/jest-config": "workspace:*",
"@webstudio-is/react-sdk": "workspace:*",
@@ -43,7 +42,6 @@
"change-case": "^5.0.2",
"colord": "^2.9.3",
"css-tree": "^2.3.1",
- "hyphenate-style-name": "^1.0.4",
"openai": "^3.2.1",
"warn-once": "^0.1.1"
}
diff --git a/packages/css-data/src/parse-css-value.ts b/packages/css-data/src/parse-css-value.ts
index f96565d649..08c3c6d8fe 100644
--- a/packages/css-data/src/parse-css-value.ts
+++ b/packages/css-data/src/parse-css-value.ts
@@ -1,9 +1,9 @@
import { colord } from "colord";
import * as csstree from "css-tree";
-import hyphenate from "hyphenate-style-name";
import warnOnce from "warn-once";
import {
TupleValue,
+ hyphenateProperty,
type StyleProperty,
type StyleValue,
type Unit,
@@ -27,7 +27,7 @@ export const isValidDeclaration = (
property: string,
value: string
): boolean => {
- const cssPropertyName = hyphenate(property);
+ const cssPropertyName = hyphenateProperty(property);
// @todo remove after csstree fixes
// - https://github.com/csstree/csstree/issues/246
diff --git a/packages/css-engine/package.json b/packages/css-engine/package.json
index 05fc7fc88b..f49ecce471 100644
--- a/packages/css-engine/package.json
+++ b/packages/css-engine/package.json
@@ -19,7 +19,6 @@
"@emotion/hash": "^0.9.1",
"@webstudio-is/error-utils": "workspace:*",
"@webstudio-is/fonts": "workspace:*",
- "hyphenate-style-name": "^1.0.4",
"zod": "^3.22.4"
},
"devDependencies": {
@@ -27,7 +26,6 @@
"@storybook/addon-essentials": "^8.1.2",
"@storybook/addon-links": "^8.1.2",
"@storybook/react": "^8.1.2",
- "@types/hyphenate-style-name": "^1.0.0",
"@types/react": "^18.2.70",
"@types/react-dom": "^18.2.25",
"@webstudio-is/jest-config": "workspace:*",
diff --git a/packages/css-engine/src/core/index.ts b/packages/css-engine/src/core/index.ts
index c32c2ef973..445448c884 100644
--- a/packages/css-engine/src/core/index.ts
+++ b/packages/css-engine/src/core/index.ts
@@ -8,7 +8,7 @@ export type {
export type { StyleSheetRegular } from "./style-sheet-regular";
export * from "./create-style-sheet";
export * from "./to-value";
-export * from "./to-property";
+export { hyphenateProperty } from "./to-property";
export * from "./match-media";
export * from "./equal-media";
export * from "./compare-media";
diff --git a/packages/css-engine/src/core/to-property.test.ts b/packages/css-engine/src/core/to-property.test.ts
index 50aad11595..ab90590e1c 100644
--- a/packages/css-engine/src/core/to-property.test.ts
+++ b/packages/css-engine/src/core/to-property.test.ts
@@ -1,5 +1,21 @@
import { describe, test, expect } from "@jest/globals";
-import { toProperty } from "./to-property";
+import { hyphenateProperty, toProperty } from "./to-property";
+
+describe("hyphenateProperty", () => {
+ test("hyphenates regular css", () => {
+ expect(hyphenateProperty("backgroundColor")).toEqual("background-color");
+ expect(hyphenateProperty("fontSize")).toEqual("font-size");
+ expect(hyphenateProperty("color")).toEqual("color");
+ expect(hyphenateProperty("borderTopLeftRadius")).toEqual(
+ "border-top-left-radius"
+ );
+ });
+
+ test("hyphenates vendor prefixes correctly", () => {
+ expect(hyphenateProperty("MozTransition")).toEqual("-moz-transition");
+ expect(hyphenateProperty("WebkitTransition")).toEqual("-webkit-transition");
+ });
+});
describe("toProperty", () => {
test("boxSizing", () => {
diff --git a/packages/css-engine/src/core/to-property.ts b/packages/css-engine/src/core/to-property.ts
index 83650434c7..2cd1414b2b 100644
--- a/packages/css-engine/src/core/to-property.ts
+++ b/packages/css-engine/src/core/to-property.ts
@@ -1,6 +1,11 @@
-import hyphenate from "hyphenate-style-name";
import type { StyleProperty } from "../schema";
+/**
+ * Hyphenates a camelcased CSS property name
+ */
+export const hyphenateProperty = (property: string) =>
+ property.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
+
export const toProperty = (property: StyleProperty) => {
// chrome started to support unprefixed background-clip in December 2023
// https://caniuse.com/background-clip-text
@@ -8,5 +13,5 @@ export const toProperty = (property: StyleProperty) => {
if (property === "backgroundClip") {
return "-webkit-background-clip";
}
- return hyphenate(property);
+ return hyphenateProperty(property);
};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d5022b46fd..49d2603db0 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -273,9 +273,6 @@ importers:
hono:
specifier: ^3.7.3
version: 3.7.3
- hyphenate-style-name:
- specifier: ^1.0.4
- version: 1.0.4
immer:
specifier: ^10.0.3
version: 10.0.3
@@ -406,12 +403,6 @@ importers:
'@types/cookie':
specifier: ^0.6.0
version: 0.6.0
- '@types/hyphenate-style-name':
- specifier: ^1.0.0
- version: 1.0.0
- '@types/lodash.debounce':
- specifier: ^4.0.6
- version: 4.0.7
'@types/prismjs':
specifier: ^1.26.0
version: 1.26.0
@@ -1069,9 +1060,6 @@ importers:
css-tree:
specifier: ^2.3.1
version: 2.3.1(patch_hash=epgcmebti7rfrc2ej4odb3t4jy)
- hyphenate-style-name:
- specifier: ^1.0.4
- version: 1.0.4
openai:
specifier: ^3.2.1
version: 3.2.1
@@ -1085,9 +1073,6 @@ importers:
'@types/css-tree':
specifier: ^2.3.1
version: 2.3.1(patch_hash=ac22lciodhaj6xmoeignv36gyq)
- '@types/hyphenate-style-name':
- specifier: ^1.0.0
- version: 1.0.0
'@types/node':
specifier: ^20.12.7
version: 20.12.7
@@ -1130,9 +1115,6 @@ importers:
'@webstudio-is/fonts':
specifier: workspace:*
version: link:../fonts
- hyphenate-style-name:
- specifier: ^1.0.4
- version: 1.0.4
zod:
specifier: ^3.22.4
version: 3.22.4
@@ -1149,9 +1131,6 @@ importers:
'@storybook/react':
specifier: ^8.1.2
- '@types/hyphenate-style-name':
- specifier: ^1.0.0
- version: 1.0.0
'@types/react':
specifier: ^18.2.70
version: 18.2.79
@@ -4814,9 +4793,6 @@ packages:
resolution: {integrity: sha512-/K3ds8TRAfBvi5vfjuz8y6+GiAYBZ0x4tXv1Av6CWBWn0IlADc+ZX9pMq7oU0fNQPnBwIZl3rmeLp6SBApbxSQ==}
- '@types/[email protected]':
- resolution: {integrity: sha512-sjO5w5XZTF2zKepC9ZOv8e0K6n5JVuCjhD/9WRxsDTJTX7Oz3APlN5Arsio8cFj/zrHBqv8jIKBuUOVIr9ckUQ==}
-
resolution: {integrity: sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==}
@@ -4835,9 +4811,6 @@ packages:
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
- '@types/[email protected]':
- resolution: {integrity: sha512-X1T4wMZ+gT000M2/91SYj0d/7JfeNZ9PeeOldSNoE/lunLeQXKvkmIumI29IaKMotU/ln/McOIvgzZcQ/3TrSA==}
-
resolution: {integrity: sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==}
@@ -6605,9 +6578,6 @@ packages:
resolution: {integrity: sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==}
- resolution: {integrity: sha512-ygGZLjmXfPHj+ZWh6LwbC37l43MhfztxetbFCoYTM2VjkIUpeHgSNn7QIyVFj7YQ1Wl9Cbw5sholVJPzWvC2MQ==}
-
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
engines: {node: '>=0.10.0'}
@@ -13330,8 +13300,6 @@ snapshots:
'@types/[email protected]': {}
- '@types/[email protected]': {}
-
'@types/[email protected]': {}
@@ -13352,10 +13320,6 @@ snapshots:
'@types/[email protected]': {}
- '@types/[email protected]':
- dependencies:
- '@types/lodash': 4.14.182
-
'@types/[email protected]': {}
@@ -15425,8 +15389,6 @@ snapshots:
dependencies:
ms: 2.1.3
-
dependencies:
safer-buffer: 2.1.2