@styleflow.app/astro 0.3.0-beta.6 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/dist/S.astro.d.ts +9 -22
- package/dist/html.d.ts +5 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +22 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +39 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/integration.d.ts +0 -1
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +67 -12
- package/dist/integration.js.map +1 -1
- package/dist/runtime.d.ts +9 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +109 -140
- package/dist/runtime.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -7
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ export default defineConfig({
|
|
|
21
21
|
---
|
|
22
22
|
import S from "@styleflow.app/astro/S.astro";
|
|
23
23
|
---
|
|
24
|
-
<S.section tone="main" intensity=
|
|
24
|
+
<S.section tone="main" intensity="base" surface="raised" layoutRole="section" density="regular" theme="light">
|
|
25
25
|
<S.h1 v="1">Title</S.h1>
|
|
26
26
|
<S.p v="md">Body copy.</S.p>
|
|
27
27
|
<S.button type="submit" ty="body" v="md" w="strong" interactivePriority="primary">
|
|
@@ -31,11 +31,16 @@ import S from "@styleflow.app/astro/S.astro";
|
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
`<S.*>` is transformed at build time into the stable `<S as="...">` form.
|
|
34
|
-
Out-of-contract prop values (`tone="banana"`,
|
|
34
|
+
Out-of-contract prop values (`tone="banana"`, numeric intensity, invalid
|
|
35
35
|
`ty`/`v` coordinates, contradictory override aliases) throw during
|
|
36
36
|
server-side rendering — they fail `astro dev`/`astro build` instead of
|
|
37
37
|
shipping bad markup.
|
|
38
38
|
|
|
39
|
+
The integration is mandatory in v1. It reads the generated project contract,
|
|
40
|
+
watches `styleflow.consumer.json` and its bundle through `addWatchFile()`, and
|
|
41
|
+
injects project-specific unions through Astro `injectTypes()`. `theme` emits a
|
|
42
|
+
`data-styleflow-theme` scope; browser states are never component props.
|
|
43
|
+
|
|
39
44
|
## Integration options
|
|
40
45
|
|
|
41
46
|
| Option | Default | Effect |
|
|
@@ -45,6 +50,6 @@ shipping bad markup.
|
|
|
45
50
|
| `usage` | `false` | Collect rendered combinations into `.styleflow/astro-usage.json`; the CLI merges them into `usage-report.json` |
|
|
46
51
|
| `cwd` | Astro root | StyleFlow project directory |
|
|
47
52
|
|
|
48
|
-
|
|
53
|
+
CLI and contract dependencies are exact for the prerelease line.
|
|
49
54
|
|
|
50
55
|
License: MIT.
|
package/dist/S.astro.d.ts
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
StyleFlowSemanticProps,
|
|
3
|
-
StyleFlowSupportedHtmlTag
|
|
4
|
-
} from "@styleflow.app/core";
|
|
5
1
|
import type { HTMLAttributes, HTMLTag } from "astro/types";
|
|
2
|
+
import type { StyleFlowSemanticProps, StyleFlowSupportedHtmlTag } from "./index.js";
|
|
6
3
|
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Tag extends HTMLTag ? HTMLAttributes<Tag> : Record<string, unknown>;
|
|
11
|
-
|
|
4
|
+
type Component<Props> = (_props: Props) => any;
|
|
5
|
+
type HtmlProps<Tag extends StyleFlowSupportedHtmlTag> = Tag extends HTMLTag
|
|
6
|
+
? HTMLAttributes<Tag> : Record<string, unknown>;
|
|
12
7
|
export type StyleFlowAstroMemberProps<Tag extends StyleFlowSupportedHtmlTag> =
|
|
13
|
-
StyleFlowSemanticProps &
|
|
14
|
-
|
|
8
|
+
StyleFlowSemanticProps & HtmlProps<Tag>;
|
|
15
9
|
export type StyleFlowAstroStableProps = StyleFlowSemanticProps & {
|
|
16
|
-
as: StyleFlowSupportedHtmlTag;
|
|
17
|
-
|
|
10
|
+
as: StyleFlowSupportedHtmlTag; [key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
export type StyleFlowAstroAuthoringComponent = Component<StyleFlowAstroStableProps> & {
|
|
13
|
+
[Tag in StyleFlowSupportedHtmlTag]: Component<StyleFlowAstroMemberProps<Tag>>;
|
|
18
14
|
};
|
|
19
|
-
|
|
20
|
-
export type StyleFlowAstroAuthoringComponent =
|
|
21
|
-
StyleFlowAstroComponent<StyleFlowAstroStableProps> & {
|
|
22
|
-
[Tag in StyleFlowSupportedHtmlTag]: StyleFlowAstroComponent<
|
|
23
|
-
StyleFlowAstroMemberProps<Tag>
|
|
24
|
-
>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
15
|
declare const S: StyleFlowAstroAuthoringComponent;
|
|
28
|
-
|
|
29
16
|
export default S;
|
package/dist/html.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const STYLEFLOW_SUPPORTED_HTML_TAGS: readonly ["a", "abbr", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "menu", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "span", "small", "source", "strong", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "u", "ul", "var", "video", "wbr"];
|
|
2
|
+
export type StyleFlowSupportedHtmlTag = (typeof STYLEFLOW_SUPPORTED_HTML_TAGS)[number];
|
|
3
|
+
export declare const STYLEFLOW_RESERVED_DATA_ATTRIBUTES: readonly ["data-color-tone", "data-color-intensity", "data-surface-type", "data-foreground", "data-layout-role", "data-layout-density", "data-text-style", "data-text-type", "data-text-variant", "data-text-weight", "data-interactive-priority", "data-styleflow-theme", "data-sf-no-background", "data-sf-no-border", "data-sf-no-padding", "data-sf-no-gap", "data-sf-no-radius", "data-sf-no-foreground"];
|
|
4
|
+
export declare const OVERRIDE_FLAG_ALIASES: readonly [readonly ["noBackground", "noBg"], readonly ["noBorder", "noB"], readonly ["noPadding", "noP"], readonly ["noGap", "noG"], readonly ["noRadius", "noR"], readonly ["noForeground", "noFg"]];
|
|
5
|
+
//# sourceMappingURL=html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,g2BAUhC,CAAC;AACX,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvF,eAAO,MAAM,kCAAkC,gZAKrC,CAAC;AAEX,eAAO,MAAM,qBAAqB,uMAGxB,CAAC"}
|
package/dist/html.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const STYLEFLOW_SUPPORTED_HTML_TAGS = [
|
|
2
|
+
"a", "abbr", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "blockquote",
|
|
3
|
+
"body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "data", "datalist",
|
|
4
|
+
"dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption",
|
|
5
|
+
"figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "html",
|
|
6
|
+
"i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "menu",
|
|
7
|
+
"meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "picture", "pre",
|
|
8
|
+
"progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "span", "small",
|
|
9
|
+
"source", "strong", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead",
|
|
10
|
+
"time", "tr", "track", "u", "ul", "var", "video", "wbr"
|
|
11
|
+
];
|
|
12
|
+
export const STYLEFLOW_RESERVED_DATA_ATTRIBUTES = [
|
|
13
|
+
"data-color-tone", "data-color-intensity", "data-surface-type", "data-foreground", "data-layout-role",
|
|
14
|
+
"data-layout-density", "data-text-style", "data-text-type", "data-text-variant", "data-text-weight",
|
|
15
|
+
"data-interactive-priority", "data-styleflow-theme", "data-sf-no-background", "data-sf-no-border",
|
|
16
|
+
"data-sf-no-padding", "data-sf-no-gap", "data-sf-no-radius", "data-sf-no-foreground"
|
|
17
|
+
];
|
|
18
|
+
export const OVERRIDE_FLAG_ALIASES = [
|
|
19
|
+
["noBackground", "noBg"], ["noBorder", "noB"], ["noPadding", "noP"],
|
|
20
|
+
["noGap", "noG"], ["noRadius", "noR"], ["noForeground", "noFg"]
|
|
21
|
+
];
|
|
22
|
+
//# sourceMappingURL=html.js.map
|
package/dist/html.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY;IAC5F,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU;IAClG,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAA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AG;IACnC,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC;IACnE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,CAAC;CACvD,CAAC","sourcesContent":["export const STYLEFLOW_SUPPORTED_HTML_TAGS = [\n \"a\", \"abbr\", \"address\", \"area\", \"article\", \"aside\", \"audio\", \"b\", \"bdi\", \"bdo\", \"blockquote\",\n \"body\", \"br\", \"button\", \"canvas\", \"caption\", \"cite\", \"code\", \"col\", \"colgroup\", \"data\", \"datalist\",\n \"dd\", \"del\", \"details\", \"dfn\", \"dialog\", \"div\", \"dl\", \"dt\", \"em\", \"embed\", \"fieldset\", \"figcaption\",\n \"figure\", \"footer\", \"form\", \"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\", \"header\", \"hgroup\", \"hr\", \"html\",\n \"i\", \"iframe\", \"img\", \"input\", \"ins\", \"kbd\", \"label\", \"legend\", \"li\", \"main\", \"map\", \"mark\", \"menu\",\n \"meter\", \"nav\", \"noscript\", \"object\", \"ol\", \"optgroup\", \"option\", \"output\", \"p\", \"picture\", \"pre\",\n \"progress\", \"q\", \"rp\", \"rt\", \"ruby\", \"s\", \"samp\", \"search\", \"section\", \"select\", \"span\", \"small\",\n \"source\", \"strong\", \"sub\", \"summary\", \"sup\", \"table\", \"tbody\", \"td\", \"textarea\", \"tfoot\", \"th\", \"thead\",\n \"time\", \"tr\", \"track\", \"u\", \"ul\", \"var\", \"video\", \"wbr\"\n] as const;\nexport type StyleFlowSupportedHtmlTag = (typeof STYLEFLOW_SUPPORTED_HTML_TAGS)[number];\n\nexport const STYLEFLOW_RESERVED_DATA_ATTRIBUTES = [\n \"data-color-tone\", \"data-color-intensity\", \"data-surface-type\", \"data-foreground\", \"data-layout-role\",\n \"data-layout-density\", \"data-text-style\", \"data-text-type\", \"data-text-variant\", \"data-text-weight\",\n \"data-interactive-priority\", \"data-styleflow-theme\", \"data-sf-no-background\", \"data-sf-no-border\",\n \"data-sf-no-padding\", \"data-sf-no-gap\", \"data-sf-no-radius\", \"data-sf-no-foreground\"\n] as const;\n\nexport const OVERRIDE_FLAG_ALIASES = [\n [\"noBackground\", \"noBg\"], [\"noBorder\", \"noB\"], [\"noPadding\", \"noP\"],\n [\"noGap\", \"noG\"], [\"noRadius\", \"noR\"], [\"noForeground\", \"noFg\"]\n] as const;\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,50 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StyleFlowSupportedHtmlTag } from "./html.js";
|
|
2
|
+
declare global {
|
|
3
|
+
interface StyleflowProjectAxes {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
type ProjectAxis<Key extends PropertyKey> = Key extends keyof StyleflowProjectAxes ? StyleflowProjectAxes[Key] : string;
|
|
7
|
+
export interface StyleFlowSemanticProps {
|
|
8
|
+
theme?: ProjectAxis<"theme">;
|
|
9
|
+
tone?: ProjectAxis<"tone">;
|
|
10
|
+
intensity?: ProjectAxis<"intensity">;
|
|
11
|
+
surface?: ProjectAxis<"surface">;
|
|
12
|
+
foreground?: ProjectAxis<"foreground">;
|
|
13
|
+
layoutRole?: ProjectAxis<"layoutRole">;
|
|
14
|
+
density?: ProjectAxis<"density">;
|
|
15
|
+
ty?: ProjectAxis<"ty">;
|
|
16
|
+
v?: ProjectAxis<"v">;
|
|
17
|
+
w?: ProjectAxis<"w">;
|
|
18
|
+
interactivePriority?: ProjectAxis<"interactivePriority">;
|
|
19
|
+
noBackground?: boolean;
|
|
20
|
+
noBg?: boolean;
|
|
21
|
+
noBorder?: boolean;
|
|
22
|
+
noB?: boolean;
|
|
23
|
+
noPadding?: boolean;
|
|
24
|
+
noP?: boolean;
|
|
25
|
+
noGap?: boolean;
|
|
26
|
+
noG?: boolean;
|
|
27
|
+
noRadius?: boolean;
|
|
28
|
+
noR?: boolean;
|
|
29
|
+
noForeground?: boolean;
|
|
30
|
+
noFg?: boolean;
|
|
31
|
+
}
|
|
2
32
|
export declare const STYLEFLOW_ASTRO_BOOTSTRAP_STATUS: "runtime-v1";
|
|
3
33
|
export interface StyleFlowAstroPrimitiveProps extends StyleFlowSemanticProps {
|
|
4
34
|
as: StyleFlowSupportedHtmlTag;
|
|
5
35
|
class?: string;
|
|
6
36
|
id?: string;
|
|
7
37
|
}
|
|
8
|
-
export
|
|
9
|
-
stableForm: "<S as=\"...\">";
|
|
10
|
-
publicForm: "<S.*>";
|
|
11
|
-
status:
|
|
12
|
-
}
|
|
13
|
-
export declare const STYLEFLOW_ASTRO_PACKAGE_SURFACE: StyleFlowAstroPackageSurface;
|
|
38
|
+
export declare const STYLEFLOW_ASTRO_PACKAGE_SURFACE: {
|
|
39
|
+
readonly stableForm: "<S as=\"...\">";
|
|
40
|
+
readonly publicForm: "<S.*>";
|
|
41
|
+
readonly status: "runtime-v1";
|
|
42
|
+
};
|
|
14
43
|
export declare function defineStyleFlowAstroPrimitive<Props extends StyleFlowAstroPrimitiveProps>(props: Props): Props;
|
|
15
44
|
export { styleflowAstro, transformStyleFlowAstroAuthoring } from "./integration.js";
|
|
16
45
|
export type { StyleFlowAstroIntegrationOptions, StyleFlowAstroLintMode } from "./integration.js";
|
|
17
46
|
export { clearStyleFlowUsageEntries, normalizeHtmlTag, readStyleFlowUsageEntries, resolveStyleFlowAstroPrimitive } from "./runtime.js";
|
|
18
|
-
export type { StyleFlowAstroAttributeValue, StyleFlowAstroPrimitiveInput, StyleFlowAstroResolvedPrimitive } from "./runtime.js";
|
|
47
|
+
export type { StyleFlowAstroAttributeValue, StyleFlowAstroPrimitiveInput, StyleFlowAstroResolvedPrimitive, StyleflowRuntimeProjectContract } from "./runtime.js";
|
|
48
|
+
export { STYLEFLOW_SUPPORTED_HTML_TAGS } from "./html.js";
|
|
49
|
+
export type { StyleFlowSupportedHtmlTag } from "./html.js";
|
|
19
50
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,CAAC,MAAM,CAAC;IAAE,UAAU,oBAAoB;KAAG;CAAE;AACpD,KAAK,WAAW,CAAC,GAAG,SAAS,WAAW,IAAI,GAAG,SAAS,MAAM,oBAAoB,GAC9E,oBAAoB,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;AAEvC,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7B,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACjC,UAAU,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IACvC,OAAO,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACjC,EAAE,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;IACrB,mBAAmB,CAAC,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAC;IACzD,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,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TRO_PACKAGE_SURFACE = {
|
|
3
|
-
stableForm: '<S as="...">',
|
|
4
|
-
publicForm: "<S.*>",
|
|
5
|
-
status: STYLEFLOW_ASTRO_BOOTSTRAP_STATUS
|
|
3
|
+
stableForm: '<S as="...">', publicForm: "<S.*>", status: STYLEFLOW_ASTRO_BOOTSTRAP_STATUS
|
|
6
4
|
};
|
|
7
|
-
export function defineStyleFlowAstroPrimitive(props) {
|
|
8
|
-
return props;
|
|
9
|
-
}
|
|
5
|
+
export function defineStyleFlowAstroPrimitive(props) { return props; }
|
|
10
6
|
export { styleflowAstro, transformStyleFlowAstroAuthoring } from "./integration.js";
|
|
11
7
|
export { clearStyleFlowUsageEntries, normalizeHtmlTag, readStyleFlowUsageEntries, resolveStyleFlowAstroPrimitive } from "./runtime.js";
|
|
8
|
+
export { STYLEFLOW_SUPPORTED_HTML_TAGS } from "./html.js";
|
|
12
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAC,MAAM,gCAAgC,GAAG,YAAqB,CAAC;AAItE,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,gCAAgC;CACjF,CAAC;AACX,MAAM,UAAU,6BAA6B,CAA6C,KAAY,IAAW,OAAO,KAAK,CAAC,CAAC,CAAC;AAEhI,OAAO,EAAE,cAAc,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAEpF,OAAO,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAC;AAEvI,OAAO,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC","sourcesContent":["import type { StyleFlowSupportedHtmlTag } from \"./html.js\";\n\ndeclare global { interface StyleflowProjectAxes {} }\ntype ProjectAxis<Key extends PropertyKey> = Key extends keyof StyleflowProjectAxes\n ? StyleflowProjectAxes[Key] : string;\n\nexport interface StyleFlowSemanticProps {\n theme?: ProjectAxis<\"theme\">;\n tone?: ProjectAxis<\"tone\">;\n intensity?: ProjectAxis<\"intensity\">;\n surface?: ProjectAxis<\"surface\">;\n foreground?: ProjectAxis<\"foreground\">;\n layoutRole?: ProjectAxis<\"layoutRole\">;\n density?: ProjectAxis<\"density\">;\n ty?: ProjectAxis<\"ty\">;\n v?: ProjectAxis<\"v\">;\n w?: ProjectAxis<\"w\">;\n interactivePriority?: ProjectAxis<\"interactivePriority\">;\n noBackground?: boolean; noBg?: boolean; noBorder?: boolean; noB?: boolean;\n noPadding?: boolean; noP?: boolean; noGap?: boolean; noG?: boolean;\n noRadius?: boolean; noR?: boolean; noForeground?: boolean; noFg?: boolean;\n}\n\nexport const STYLEFLOW_ASTRO_BOOTSTRAP_STATUS = \"runtime-v1\" as const;\nexport interface StyleFlowAstroPrimitiveProps extends StyleFlowSemanticProps {\n as: StyleFlowSupportedHtmlTag; class?: string; id?: string;\n}\nexport const STYLEFLOW_ASTRO_PACKAGE_SURFACE = {\n stableForm: '<S as=\"...\">', publicForm: \"<S.*>\", status: STYLEFLOW_ASTRO_BOOTSTRAP_STATUS\n} as const;\nexport function defineStyleFlowAstroPrimitive<Props extends StyleFlowAstroPrimitiveProps>(props: Props): Props { return props; }\n\nexport { styleflowAstro, transformStyleFlowAstroAuthoring } from \"./integration.js\";\nexport type { StyleFlowAstroIntegrationOptions, StyleFlowAstroLintMode } from \"./integration.js\";\nexport { clearStyleFlowUsageEntries, normalizeHtmlTag, readStyleFlowUsageEntries, resolveStyleFlowAstroPrimitive } from \"./runtime.js\";\nexport type { StyleFlowAstroAttributeValue, StyleFlowAstroPrimitiveInput, StyleFlowAstroResolvedPrimitive, StyleflowRuntimeProjectContract } from \"./runtime.js\";\nexport { STYLEFLOW_SUPPORTED_HTML_TAGS } from \"./html.js\";\nexport type { StyleFlowSupportedHtmlTag } from \"./html.js\";\n"]}
|
package/dist/integration.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,gBAAgB,EAA0B,MAAM,OAAO,CAAC;AAWtE,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AAE9D,MAAM,WAAW,gCAAgC;IAM/C,IAAI,CAAC,EAAE,sBAAsB,CAAC;IAE9B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,cAAc,CAC5B,OAAO,GAAE,gCAAqC,GAC7C,gBAAgB,CAkElB;AAsGD,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,MAAM,EACd,EAAE,SAAa,GACd,MAAM,CAUR"}
|
package/dist/integration.js
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import {
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
+
import { STYLEFLOW_SUPPORTED_HTML_TAGS } from "./html.js";
|
|
6
6
|
import { clearStyleFlowUsageEntries, readStyleFlowUsageEntries } from "./runtime.js";
|
|
7
7
|
const STYLEFLOW_MEMBER_TAG_OPEN_RE = /<S\.([A-Za-z][A-Za-z0-9-]*)(?=[\s>/])/g;
|
|
8
8
|
const STYLEFLOW_MEMBER_TAG_CLOSE_RE = /<\/S\.([A-Za-z][A-Za-z0-9-]*)\s*>/g;
|
|
9
9
|
export function styleflowAstro(options = {}) {
|
|
10
10
|
const lintMode = options.lint ?? "warn";
|
|
11
11
|
let projectRoot = options.cwd ?? process.cwd();
|
|
12
|
+
let projectContract;
|
|
12
13
|
return {
|
|
13
14
|
name: "@styleflow.app/astro",
|
|
14
15
|
hooks: {
|
|
15
|
-
"astro:config:setup": ({ updateConfig }) => {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
"astro:config:setup": async ({ config, updateConfig, addWatchFile }) => {
|
|
17
|
+
projectRoot = options.cwd ?? fileURLToPath(config.root);
|
|
18
|
+
const generatedContractPath = path.join(projectRoot, ".styleflow", "contract.json");
|
|
19
|
+
projectContract = await loadGeneratedContract(generatedContractPath);
|
|
20
|
+
addWatchFile(pathToFileURL(generatedContractPath));
|
|
21
|
+
const consumerPath = path.join(projectRoot, "styleflow.consumer.json");
|
|
22
|
+
addWatchFile(pathToFileURL(consumerPath));
|
|
23
|
+
try {
|
|
24
|
+
const consumer = JSON.parse(await fs.readFile(consumerPath, "utf8"));
|
|
25
|
+
if (typeof consumer.bundle === "string") {
|
|
26
|
+
addWatchFile(pathToFileURL(path.resolve(projectRoot, consumer.bundle)));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// The CLI lint/build path reports malformed consumer configuration.
|
|
18
31
|
}
|
|
19
32
|
if (options.usage) {
|
|
20
33
|
process.env.STYLEFLOW_ASTRO_USAGE = "1";
|
|
@@ -22,29 +35,34 @@ export function styleflowAstro(options = {}) {
|
|
|
22
35
|
}
|
|
23
36
|
updateConfig({
|
|
24
37
|
vite: {
|
|
38
|
+
define: {
|
|
39
|
+
__STYLEFLOW_PROJECT_CONTRACT__: JSON.stringify(projectContract)
|
|
40
|
+
},
|
|
25
41
|
plugins: [createStyleFlowAstroTransformPlugin()]
|
|
26
42
|
}
|
|
27
43
|
});
|
|
28
44
|
},
|
|
29
|
-
"astro:config:done": ({ config }) => {
|
|
30
|
-
if (!options.cwd)
|
|
45
|
+
"astro:config:done": ({ config, injectTypes }) => {
|
|
46
|
+
if (!options.cwd)
|
|
31
47
|
projectRoot = fileURLToPath(config.root);
|
|
32
|
-
|
|
48
|
+
if (!projectContract)
|
|
49
|
+
throw new Error("Styleflow generated contract was not loaded.");
|
|
50
|
+
injectTypes({ filename: "styleflow-project.d.ts", content: projectTypes(projectContract) });
|
|
33
51
|
},
|
|
34
52
|
"astro:server:start": async ({ logger }) => {
|
|
35
|
-
if (
|
|
53
|
+
if (lintMode === "off") {
|
|
36
54
|
return;
|
|
37
55
|
}
|
|
38
56
|
await runStyleFlowLint(projectRoot, "warn", logger);
|
|
39
57
|
},
|
|
40
58
|
"astro:build:start": async ({ logger }) => {
|
|
41
|
-
if (
|
|
59
|
+
if (lintMode === "off") {
|
|
42
60
|
return;
|
|
43
61
|
}
|
|
44
62
|
await runStyleFlowLint(projectRoot, lintMode, logger);
|
|
45
63
|
},
|
|
46
64
|
"astro:build:done": async ({ logger }) => {
|
|
47
|
-
if (
|
|
65
|
+
if (!options.usage) {
|
|
48
66
|
return;
|
|
49
67
|
}
|
|
50
68
|
await flushStyleFlowUsage(projectRoot, logger);
|
|
@@ -78,13 +96,50 @@ async function flushStyleFlowUsage(cwd, logger) {
|
|
|
78
96
|
const outputPath = path.join(outputDir, "astro-usage.json");
|
|
79
97
|
await fs.mkdir(outputDir, { recursive: true });
|
|
80
98
|
await fs.writeFile(outputPath, `${JSON.stringify({
|
|
81
|
-
version:
|
|
99
|
+
version: "1.0.0",
|
|
82
100
|
generatedAt: new Date().toISOString(),
|
|
83
101
|
source: "astro-runtime",
|
|
84
102
|
entries
|
|
85
103
|
}, null, 2)}\n`, "utf8");
|
|
86
104
|
logger.info(`StyleFlow runtime usage written to ${outputPath} (${entries.length} entries).`);
|
|
87
105
|
}
|
|
106
|
+
async function loadGeneratedContract(contractPath) {
|
|
107
|
+
let raw;
|
|
108
|
+
try {
|
|
109
|
+
raw = await fs.readFile(contractPath, "utf8");
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
throw new Error(`Styleflow generated contract not found at ${contractPath}. Run styleflow build before Astro.`);
|
|
113
|
+
}
|
|
114
|
+
const value = JSON.parse(raw);
|
|
115
|
+
if (value.version !== "1.0.0" || !value.defaultTheme || !value.semantic || !value.resolved) {
|
|
116
|
+
throw new Error(".styleflow/contract.json is not a Styleflow v1 generated project contract.");
|
|
117
|
+
}
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
function projectTypes(contract) {
|
|
121
|
+
const union = (values) => values.map((value) => JSON.stringify(value)).join(" | ") || "never";
|
|
122
|
+
const axes = contract.semantic.axes;
|
|
123
|
+
return [
|
|
124
|
+
"declare global {",
|
|
125
|
+
" interface StyleflowProjectAxes {",
|
|
126
|
+
` theme: ${union(contract.semantic.themes)};`,
|
|
127
|
+
` tone: ${union(axes.color.tones)};`,
|
|
128
|
+
` intensity: ${union([...new Set(Object.values(axes.color.intensitiesByTone).flat())])};`,
|
|
129
|
+
` surface: ${union(axes.color.surfaces)};`,
|
|
130
|
+
` foreground: ${union(axes.color.foregrounds)};`,
|
|
131
|
+
` layoutRole: ${union(axes.layout.roles)};`,
|
|
132
|
+
` density: ${union(axes.layout.densities)};`,
|
|
133
|
+
` ty: ${union(axes.typography.types)};`,
|
|
134
|
+
` v: ${union([...new Set(Object.values(axes.typography.variantsByType).flat())])};`,
|
|
135
|
+
` w: ${union(axes.typography.weights)};`,
|
|
136
|
+
` interactivePriority: ${union(axes.interaction.priorities)};`,
|
|
137
|
+
" }",
|
|
138
|
+
"}",
|
|
139
|
+
"export {};",
|
|
140
|
+
""
|
|
141
|
+
].join("\n");
|
|
142
|
+
}
|
|
88
143
|
export function transformStyleFlowAstroAuthoring(source, id = "<inline>") {
|
|
89
144
|
return source
|
|
90
145
|
.replace(STYLEFLOW_MEMBER_TAG_OPEN_RE, (_match, tag) => {
|
package/dist/integration.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-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AAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAClC,GAAW,EACX,EAAU;IAEV,IAAI,CAAC,6BAA6B,CAAC,QAAQ,CAAC,GAAgC,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,KAAK,CAAC,0CAA0C,GAAG,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,EAAU;IAChC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import { promises as fs } from \"node:fs\";\nimport { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport {\n STYLEFLOW_PUBLIC_CONTRACT_VERSION,\n STYLEFLOW_SUPPORTED_HTML_TAGS,\n type StyleFlowSupportedHtmlTag\n} from \"@styleflow.app/core\";\nimport type { AstroIntegration, AstroIntegrationLogger } from \"astro\";\n\nimport { clearStyleFlowUsageEntries, readStyleFlowUsageEntries } from \"./runtime.js\";\n\nconst STYLEFLOW_MEMBER_TAG_OPEN_RE = /<S\\.([A-Za-z][A-Za-z0-9-]*)(?=[\\s>/])/g;\nconst STYLEFLOW_MEMBER_TAG_CLOSE_RE = /<\\/S\\.([A-Za-z][A-Za-z0-9-]*)\\s*>/g;\n\nexport type StyleFlowAstroLintMode = \"off\" | \"warn\" | \"error\";\n\nexport interface StyleFlowAstroIntegrationOptions {\n enabled?: boolean;\n /*\n * Runs the StyleFlow lint (from @styleflow.app/cli, optional peer\n * dependency) at build start. \"error\" fails `astro build`; the dev server\n * always downgrades to warnings so it never dies on authoring mistakes.\n */\n lint?: StyleFlowAstroLintMode;\n /* Collect runtime usage and flush it to .styleflow/astro-usage.json. */\n usage?: boolean;\n cwd?: string;\n}\n\nexport function styleflowAstro(\n options: StyleFlowAstroIntegrationOptions = {}\n): AstroIntegration {\n const lintMode = options.lint ?? \"warn\";\n let projectRoot = options.cwd ?? process.cwd();\n\n return {\n name: \"@styleflow.app/astro\",\n hooks: {\n \"astro:config:setup\": ({ updateConfig }) => {\n if (options.enabled === false) {\n return;\n }\n\n if (options.usage) {\n process.env.STYLEFLOW_ASTRO_USAGE = \"1\";\n clearStyleFlowUsageEntries();\n }\n\n updateConfig({\n vite: {\n plugins: [createStyleFlowAstroTransformPlugin()]\n }\n });\n },\n \"astro:config:done\": ({ config }) => {\n if (!options.cwd) {\n projectRoot = fileURLToPath(config.root);\n }\n },\n \"astro:server:start\": async ({ logger }) => {\n if (options.enabled === false || lintMode === \"off\") {\n return;\n }\n\n await runStyleFlowLint(projectRoot, \"warn\", logger);\n },\n \"astro:build:start\": async ({ logger }) => {\n if (options.enabled === false || lintMode === \"off\") {\n return;\n }\n\n await runStyleFlowLint(projectRoot, lintMode, logger);\n },\n \"astro:build:done\": async ({ logger }) => {\n if (options.enabled === false || !options.usage) {\n return;\n }\n\n await flushStyleFlowUsage(projectRoot, logger);\n }\n }\n };\n}\n\nasync function runStyleFlowLint(\n cwd: string,\n mode: Exclude<StyleFlowAstroLintMode, \"off\">,\n logger: AstroIntegrationLogger\n): Promise<void> {\n let cli: typeof import(\"@styleflow.app/cli\");\n\n try {\n cli = await import(\"@styleflow.app/cli\");\n } catch {\n logger.warn(\n \"StyleFlow lint skipped: install @styleflow.app/cli to lint authoring during astro builds.\"\n );\n return;\n }\n\n const result = await cli.lintStyleFlowProject(cwd);\n\n if (result.ok) {\n logger.info(`StyleFlow lint passed (${result.files.length} Astro file(s)).`);\n return;\n }\n\n const rendered = cli.renderDiagnostics(\n result.diagnostics.filter((diagnostic) => diagnostic.blocking)\n );\n\n if (mode === \"error\") {\n throw new Error(`StyleFlow lint failed:\\n${rendered}`);\n }\n\n logger.warn(`StyleFlow lint found problems:\\n${rendered}`);\n}\n\nasync function flushStyleFlowUsage(\n cwd: string,\n logger: AstroIntegrationLogger\n): Promise<void> {\n const entries = readStyleFlowUsageEntries();\n const outputDir = path.join(cwd, \".styleflow\");\n const outputPath = path.join(outputDir, \"astro-usage.json\");\n\n await fs.mkdir(outputDir, { recursive: true });\n await fs.writeFile(\n outputPath,\n `${JSON.stringify(\n {\n version: STYLEFLOW_PUBLIC_CONTRACT_VERSION,\n generatedAt: new Date().toISOString(),\n source: \"astro-runtime\",\n entries\n },\n null,\n 2\n )}\\n`,\n \"utf8\"\n );\n\n logger.info(`StyleFlow runtime usage written to ${outputPath} (${entries.length} entries).`);\n}\n\nexport function transformStyleFlowAstroAuthoring(\n source: string,\n id = \"<inline>\"\n): string {\n return source\n .replace(STYLEFLOW_MEMBER_TAG_OPEN_RE, (_match, tag: string) => {\n assertSupportedStyleFlowTag(tag, id);\n return `<S as=\"${tag}\"`;\n })\n .replace(STYLEFLOW_MEMBER_TAG_CLOSE_RE, (_match, tag: string) => {\n assertSupportedStyleFlowTag(tag, id);\n return \"</S>\";\n });\n}\n\nfunction createStyleFlowAstroTransformPlugin() {\n return {\n name: \"styleflow-astro-authoring-transform\",\n enforce: \"pre\" as const,\n load(id: string) {\n const filePath = stripViteQuery(id);\n if (!filePath.endsWith(\".astro\")) {\n return null;\n }\n\n const source = readFileSync(filePath, \"utf8\");\n const code = transformStyleFlowAstroAuthoring(source, filePath);\n if (code === source) {\n return null;\n }\n\n return code;\n },\n transform(source: string, id: string) {\n const filePath = stripViteQuery(id);\n if (!filePath.endsWith(\".astro\")) {\n return null;\n }\n\n const code = transformStyleFlowAstroAuthoring(source, filePath);\n if (code === source) {\n return null;\n }\n\n return { code, map: null };\n }\n };\n}\n\nfunction assertSupportedStyleFlowTag(\n tag: string,\n id: string\n): asserts tag is StyleFlowSupportedHtmlTag {\n if (!STYLEFLOW_SUPPORTED_HTML_TAGS.includes(tag as StyleFlowSupportedHtmlTag)) {\n throw new Error(`Unsupported StyleFlow authoring tag <S.${tag}> in ${id}.`);\n }\n}\n\nfunction stripViteQuery(id: string): string {\n return id.split(\"?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AM,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QACD,SAAS,CAAC,MAAc,EAAE,EAAU;YAClC,MAAM,QAAQ,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC;YACpC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACjC,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,IAAI,GAAG,gCAAgC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAChE,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAClC,GAAW,EACX,EAAU;IAEV,IAAI,CAAC,6BAA6B,CAAC,QAAQ,CAAC,GAAgC,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,KAAK,CAAC,0CAA0C,GAAG,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,EAAU;IAChC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import { promises as fs } from \"node:fs\";\nimport { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\n\nimport {\n STYLEFLOW_SUPPORTED_HTML_TAGS,\n type StyleFlowSupportedHtmlTag\n} from \"./html.js\";\nimport type { AstroIntegration, AstroIntegrationLogger } from \"astro\";\n\nimport {\n clearStyleFlowUsageEntries,\n readStyleFlowUsageEntries,\n type StyleflowRuntimeProjectContract\n} from \"./runtime.js\";\n\nconst STYLEFLOW_MEMBER_TAG_OPEN_RE = /<S\\.([A-Za-z][A-Za-z0-9-]*)(?=[\\s>/])/g;\nconst STYLEFLOW_MEMBER_TAG_CLOSE_RE = /<\\/S\\.([A-Za-z][A-Za-z0-9-]*)\\s*>/g;\n\nexport type StyleFlowAstroLintMode = \"off\" | \"warn\" | \"error\";\n\nexport interface StyleFlowAstroIntegrationOptions {\n /*\n * Runs the StyleFlow lint from the exact @styleflow.app/cli dependency at\n * build start. \"error\" fails `astro build`; the dev server\n * always downgrades to warnings so it never dies on authoring mistakes.\n */\n lint?: StyleFlowAstroLintMode;\n /* Collect runtime usage and flush it to .styleflow/astro-usage.json. */\n usage?: boolean;\n cwd?: string;\n}\n\nexport function styleflowAstro(\n options: StyleFlowAstroIntegrationOptions = {}\n): AstroIntegration {\n const lintMode = options.lint ?? \"warn\";\n let projectRoot = options.cwd ?? process.cwd();\n let projectContract: StyleflowRuntimeProjectContract | undefined;\n\n return {\n name: \"@styleflow.app/astro\",\n hooks: {\n \"astro:config:setup\": async ({ config, updateConfig, addWatchFile }) => {\n projectRoot = options.cwd ?? fileURLToPath(config.root);\n const generatedContractPath = path.join(projectRoot, \".styleflow\", \"contract.json\");\n projectContract = await loadGeneratedContract(generatedContractPath);\n addWatchFile(pathToFileURL(generatedContractPath));\n const consumerPath = path.join(projectRoot, \"styleflow.consumer.json\");\n addWatchFile(pathToFileURL(consumerPath));\n try {\n const consumer = JSON.parse(await fs.readFile(consumerPath, \"utf8\")) as { bundle?: unknown };\n if (typeof consumer.bundle === \"string\") {\n addWatchFile(pathToFileURL(path.resolve(projectRoot, consumer.bundle)));\n }\n } catch {\n // The CLI lint/build path reports malformed consumer configuration.\n }\n\n if (options.usage) {\n process.env.STYLEFLOW_ASTRO_USAGE = \"1\";\n clearStyleFlowUsageEntries();\n }\n\n updateConfig({\n vite: {\n define: {\n __STYLEFLOW_PROJECT_CONTRACT__: JSON.stringify(projectContract)\n },\n plugins: [createStyleFlowAstroTransformPlugin()]\n }\n });\n },\n \"astro:config:done\": ({ config, injectTypes }) => {\n if (!options.cwd) projectRoot = fileURLToPath(config.root);\n if (!projectContract) throw new Error(\"Styleflow generated contract was not loaded.\");\n injectTypes({ filename: \"styleflow-project.d.ts\", content: projectTypes(projectContract) });\n },\n \"astro:server:start\": async ({ logger }) => {\n if (lintMode === \"off\") {\n return;\n }\n\n await runStyleFlowLint(projectRoot, \"warn\", logger);\n },\n \"astro:build:start\": async ({ logger }) => {\n if (lintMode === \"off\") {\n return;\n }\n\n await runStyleFlowLint(projectRoot, lintMode, logger);\n },\n \"astro:build:done\": async ({ logger }) => {\n if (!options.usage) {\n return;\n }\n\n await flushStyleFlowUsage(projectRoot, logger);\n }\n }\n };\n}\n\nasync function runStyleFlowLint(\n cwd: string,\n mode: Exclude<StyleFlowAstroLintMode, \"off\">,\n logger: AstroIntegrationLogger\n): Promise<void> {\n let cli: typeof import(\"@styleflow.app/cli\");\n\n try {\n cli = await import(\"@styleflow.app/cli\");\n } catch {\n logger.warn(\n \"StyleFlow lint skipped: install @styleflow.app/cli to lint authoring during astro builds.\"\n );\n return;\n }\n\n const result = await cli.lintStyleFlowProject(cwd);\n\n if (result.ok) {\n logger.info(`StyleFlow lint passed (${result.files.length} Astro file(s)).`);\n return;\n }\n\n const rendered = cli.renderDiagnostics(\n result.diagnostics.filter((diagnostic) => diagnostic.blocking)\n );\n\n if (mode === \"error\") {\n throw new Error(`StyleFlow lint failed:\\n${rendered}`);\n }\n\n logger.warn(`StyleFlow lint found problems:\\n${rendered}`);\n}\n\nasync function flushStyleFlowUsage(\n cwd: string,\n logger: AstroIntegrationLogger\n): Promise<void> {\n const entries = readStyleFlowUsageEntries();\n const outputDir = path.join(cwd, \".styleflow\");\n const outputPath = path.join(outputDir, \"astro-usage.json\");\n\n await fs.mkdir(outputDir, { recursive: true });\n await fs.writeFile(\n outputPath,\n `${JSON.stringify(\n {\n version: \"1.0.0\",\n generatedAt: new Date().toISOString(),\n source: \"astro-runtime\",\n entries\n },\n null,\n 2\n )}\\n`,\n \"utf8\"\n );\n\n logger.info(`StyleFlow runtime usage written to ${outputPath} (${entries.length} entries).`);\n}\n\nasync function loadGeneratedContract(contractPath: string): Promise<StyleflowRuntimeProjectContract> {\n let raw: string;\n try {\n raw = await fs.readFile(contractPath, \"utf8\");\n } catch {\n throw new Error(`Styleflow generated contract not found at ${contractPath}. Run styleflow build before Astro.`);\n }\n const value = JSON.parse(raw) as Partial<StyleflowRuntimeProjectContract>;\n if (value.version !== \"1.0.0\" || !value.defaultTheme || !value.semantic || !value.resolved) {\n throw new Error(\".styleflow/contract.json is not a Styleflow v1 generated project contract.\");\n }\n return value as StyleflowRuntimeProjectContract;\n}\n\nfunction projectTypes(contract: StyleflowRuntimeProjectContract): string {\n const union = (values: readonly string[]): string =>\n values.map((value) => JSON.stringify(value)).join(\" | \") || \"never\";\n const axes = contract.semantic.axes;\n return [\n \"declare global {\",\n \" interface StyleflowProjectAxes {\",\n ` theme: ${union(contract.semantic.themes)};`,\n ` tone: ${union(axes.color.tones)};`,\n ` intensity: ${union([...new Set(Object.values(axes.color.intensitiesByTone).flat())])};`,\n ` surface: ${union(axes.color.surfaces)};`,\n ` foreground: ${union(axes.color.foregrounds)};`,\n ` layoutRole: ${union(axes.layout.roles)};`,\n ` density: ${union(axes.layout.densities)};`,\n ` ty: ${union(axes.typography.types)};`,\n ` v: ${union([...new Set(Object.values(axes.typography.variantsByType).flat())])};`,\n ` w: ${union(axes.typography.weights)};`,\n ` interactivePriority: ${union(axes.interaction.priorities)};`,\n \" }\",\n \"}\",\n \"export {};\",\n \"\"\n ].join(\"\\n\");\n}\n\nexport function transformStyleFlowAstroAuthoring(\n source: string,\n id = \"<inline>\"\n): string {\n return source\n .replace(STYLEFLOW_MEMBER_TAG_OPEN_RE, (_match, tag: string) => {\n assertSupportedStyleFlowTag(tag, id);\n return `<S as=\"${tag}\"`;\n })\n .replace(STYLEFLOW_MEMBER_TAG_CLOSE_RE, (_match, tag: string) => {\n assertSupportedStyleFlowTag(tag, id);\n return \"</S>\";\n });\n}\n\nfunction createStyleFlowAstroTransformPlugin() {\n return {\n name: \"styleflow-astro-authoring-transform\",\n enforce: \"pre\" as const,\n load(id: string) {\n const filePath = stripViteQuery(id);\n if (!filePath.endsWith(\".astro\")) {\n return null;\n }\n\n const source = readFileSync(filePath, \"utf8\");\n const code = transformStyleFlowAstroAuthoring(source, filePath);\n if (code === source) {\n return null;\n }\n\n return code;\n },\n transform(source: string, id: string) {\n const filePath = stripViteQuery(id);\n if (!filePath.endsWith(\".astro\")) {\n return null;\n }\n\n const code = transformStyleFlowAstroAuthoring(source, filePath);\n if (code === source) {\n return null;\n }\n\n return { code, map: null };\n }\n };\n}\n\nfunction assertSupportedStyleFlowTag(\n tag: string,\n id: string\n): asserts tag is StyleFlowSupportedHtmlTag {\n if (!STYLEFLOW_SUPPORTED_HTML_TAGS.includes(tag as StyleFlowSupportedHtmlTag)) {\n throw new Error(`Unsupported StyleFlow authoring tag <S.${tag}> in ${id}.`);\n }\n}\n\nfunction stripViteQuery(id: string): string {\n return id.split(\"?\")[0];\n}\n"]}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StyleflowResolvedThemeContract, StyleflowSemanticContract } from "@styleflow.app/contract";
|
|
2
|
+
import { type StyleFlowSupportedHtmlTag } from "./html.js";
|
|
3
|
+
export interface StyleflowRuntimeProjectContract {
|
|
4
|
+
version: "1.0.0";
|
|
5
|
+
defaultTheme: string;
|
|
6
|
+
semantic: StyleflowSemanticContract;
|
|
7
|
+
resolved: Record<string, StyleflowResolvedThemeContract>;
|
|
8
|
+
}
|
|
2
9
|
export type StyleFlowAstroAttributeValue = string | number | boolean | undefined;
|
|
3
10
|
export interface StyleFlowAstroPrimitiveInput {
|
|
4
11
|
as: string;
|
|
@@ -8,7 +15,7 @@ export interface StyleFlowAstroResolvedPrimitive {
|
|
|
8
15
|
tag: StyleFlowSupportedHtmlTag;
|
|
9
16
|
attributes: Record<string, StyleFlowAstroAttributeValue>;
|
|
10
17
|
}
|
|
11
|
-
export declare function resolveStyleFlowAstroPrimitive(props: StyleFlowAstroPrimitiveInput): StyleFlowAstroResolvedPrimitive;
|
|
18
|
+
export declare function resolveStyleFlowAstroPrimitive(props: StyleFlowAstroPrimitiveInput, suppliedContract?: StyleflowRuntimeProjectContract): StyleFlowAstroResolvedPrimitive;
|
|
12
19
|
export declare function normalizeHtmlTag(value: string): StyleFlowSupportedHtmlTag;
|
|
13
20
|
export declare function readStyleFlowUsageEntries(): Record<string, string | number | boolean>[];
|
|
14
21
|
export declare function clearStyleFlowUsageEntries(): void;
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEzG,OAAO,EAIL,KAAK,yBAAyB,EAC/B,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,+BAA+B;IAC9C,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,yBAAyB,CAAC;IACpC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAAC;CAC1D;AAKD,MAAM,MAAM,4BAA4B,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AACjF,MAAM,WAAW,4BAA4B;IAAG,EAAE,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE;AACpF,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,yBAAyB,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,4BAA4B,CAAC,CAAC;CAC1D;AAQD,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,4BAA4B,EACnC,gBAAgB,CAAC,EAAE,+BAA+B,GACjD,+BAA+B,CAYjC;AAsBD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,yBAAyB,CAGzE;AA6ED,wBAAgB,yBAAyB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAEvF;AACD,wBAAgB,0BAA0B,IAAI,IAAI,CAAqE"}
|