Skip to content

Commit 8175fdb

Browse files
qMerge remote-tracking branch 'origin/main' into fix-4729
2 parents 3db5f7b + 250b525 commit 8175fdb

File tree

11 files changed

+48
-48
lines changed

11 files changed

+48
-48
lines changed

apps/builder/app/canvas/shared/styles.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import {
99
rootComponent,
1010
type StyleDecl,
1111
type StyleSourceSelection,
12+
createImageValueTransformer,
13+
addFontRules,
1214
} from "@webstudio-is/sdk";
1315
import {
1416
collapsedAttribute,
1517
idAttribute,
1618
editingPlaceholderVariable,
17-
addGlobalRules,
18-
createImageValueTransformer,
1919
editablePlaceholderVariable,
2020
componentAttribute,
2121
} from "@webstudio-is/react-sdk";
@@ -500,7 +500,8 @@ export const GlobalStyles = () => {
500500

501501
useLayoutEffect(() => {
502502
fontsAndDefaultsSheet.clear();
503-
addGlobalRules(fontsAndDefaultsSheet, {
503+
addFontRules({
504+
sheet: fontsAndDefaultsSheet,
504505
assets,
505506
assetBaseUrl,
506507
});

packages/cli/src/prebuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import pLimit from "p-limit";
1616
import { log, spinner } from "@clack/prompts";
1717
import merge from "deepmerge";
1818
import {
19-
generateCss,
2019
generateWebstudioComponent,
2120
getIndexesWithinAncestors,
2221
type Params,
@@ -48,6 +47,7 @@ import {
4847
isCoreComponent,
4948
coreMetas,
5049
SYSTEM_VARIABLE_ID,
50+
generateCss,
5151
} from "@webstudio-is/sdk";
5252
import type { Data } from "@webstudio-is/http-client";
5353
import { LOCAL_DATA_FILE } from "./config";

packages/react-sdk/src/css/global-rules.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/react-sdk/src/css/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/react-sdk/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from "./remix";
2-
export * from "./css/index";
32
export * from "./components/components-utils";
43
export * from "./embed-template";
54
export * from "./props";

packages/sdk-cli/src/generate-stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
parseComponentName,
1212
getStyleDeclKey,
1313
coreMetas,
14+
generateCss,
1415
} from "@webstudio-is/sdk";
1516
import {
16-
generateCss,
1717
generateWebstudioComponent,
1818
getIndexesWithinAncestors,
1919
namespaceMeta,

packages/sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@webstudio-is/icons": "workspace:*",
4747
"acorn": "^8.14.0",
4848
"acorn-walk": "^8.3.4",
49+
"change-case": "^5.4.4",
4950
"reserved-identifiers": "^1.0.0",
5051
"type-fest": "^4.32.0",
5152
"zod": "^3.22.4"

packages/react-sdk/src/css/css.test.tsx renamed to packages/sdk/src/css.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect, test } from "vitest";
2-
import type { Breakpoint } from "@webstudio-is/sdk";
3-
import { rootComponent } from "@webstudio-is/sdk";
42
import { $, ws, css, renderData } from "@webstudio-is/template";
53
import { generateCss, type CssConfig } from "./css";
4+
import type { Breakpoint } from "./schema/breakpoints";
5+
import { rootComponent } from "./core-metas";
66

77
const toMap = <T extends { id: string }>(list: T[]) =>
88
new Map(list.map((item) => [item.id, item] as const));

packages/react-sdk/src/css/css.ts renamed to packages/sdk/src/css.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
1+
import { kebabCase } from "change-case";
12
import {
23
createRegularStyleSheet,
34
generateAtomic,
45
type NestingRule,
6+
type StyleSheetRegular,
57
type TransformValue,
68
} from "@webstudio-is/css-engine";
7-
import {
8-
ROOT_INSTANCE_ID,
9-
createScope,
10-
parseComponentName,
11-
descendantComponent,
12-
rootComponent,
13-
type Assets,
14-
type Breakpoints,
15-
type Instance,
16-
type Instances,
17-
type Props,
18-
type StyleSourceSelections,
19-
type Styles,
20-
type WsComponentMeta,
21-
} from "@webstudio-is/sdk";
22-
import { addGlobalRules } from "./global-rules";
23-
import { kebabCase } from "change-case";
9+
import { getFontFaces } from "@webstudio-is/fonts";
10+
import type { Assets, FontAsset } from "./schema/assets";
11+
import type { Instance, Instances } from "./schema/instances";
12+
import type { Props } from "./schema/props";
13+
import type { Breakpoints } from "./schema/breakpoints";
14+
import type { Styles } from "./schema/styles";
15+
import type { StyleSourceSelections } from "./schema/style-source-selections";
16+
import type { WsComponentMeta } from "./schema/component-meta";
17+
import { createScope } from "./scope";
18+
import { parseComponentName, ROOT_INSTANCE_ID } from "./instances-utils";
19+
import { descendantComponent, rootComponent } from "./core-metas";
20+
21+
export const addFontRules = ({
22+
sheet,
23+
assets,
24+
assetBaseUrl,
25+
}: {
26+
sheet: StyleSheetRegular;
27+
assets: Assets;
28+
assetBaseUrl: string;
29+
}) => {
30+
const fontAssets: FontAsset[] = [];
31+
for (const asset of assets.values()) {
32+
if (asset.type === "font") {
33+
fontAssets.push(asset);
34+
}
35+
}
36+
const fontFaces = getFontFaces(fontAssets, { assetBaseUrl });
37+
for (const fontFace of fontFaces) {
38+
sheet.addFontFaceRule(fontFace);
39+
}
40+
};
2441

2542
export type CssConfig = {
2643
assets: Assets;
@@ -76,7 +93,7 @@ export const generateCss = ({
7693
const globalSheet = createRegularStyleSheet({ name: "ssr" });
7794
const sheet = createRegularStyleSheet({ name: "ssr" });
7895

79-
addGlobalRules(globalSheet, { assets, assetBaseUrl });
96+
addFontRules({ sheet: globalSheet, assets, assetBaseUrl });
8097
globalSheet.addMediaRule("presets");
8198
const presetClasses = new Map<Instance["component"], string>();
8299
const scope = createScope([], normalizeClassName, "-");

packages/sdk/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export * from "./expression";
2222
export * from "./resources-generator";
2323
export * from "./page-meta-generator";
2424
export * from "./url-pattern";
25+
export * from "./css";

0 commit comments

Comments
 (0)