@rien7/design-surface-runtime 0.0.0-stage → 0.3.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/dist/flow.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { Flow } from './types.ts';
3
+ export type FlowApi = {
4
+ state: string;
5
+ history: string[];
6
+ send: (event: string) => void;
7
+ };
8
+ export declare const useDesignFlow: () => FlowApi;
9
+ export declare function FlowProvider({ flow, initial, frame, children, }: {
10
+ flow?: Flow;
11
+ initial?: string;
12
+ frame: string;
13
+ children: ReactNode;
14
+ }): import("react").JSX.Element;
15
+ //# sourceMappingURL=flow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../src/flow.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAC9B,CAAA;AAeD,eAAO,MAAM,aAAa,eAAgC,CAAA;AAE1D,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,OAAO,EACP,KAAK,EACL,QAAQ,GACT,EAAE;IACD,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,SAAS,CAAA;CACpB,+BA2CA"}
package/dist/flow.js ADDED
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
3
+ const idle = {
4
+ state: 'default',
5
+ history: [],
6
+ send: () => { },
7
+ };
8
+ // Share one React Context across host node_modules and global npx runtime copies.
9
+ const FLOW_CONTEXT_KEY = Symbol.for('design-surface.flow-context');
10
+ const globalScope = globalThis;
11
+ const FlowContext = (globalScope[FLOW_CONTEXT_KEY] ??= createContext(idle));
12
+ export const useDesignFlow = () => useContext(FlowContext);
13
+ export function FlowProvider({ flow, initial, frame, children, }) {
14
+ const [state, setState] = useState(initial ?? flow?.initial ?? 'default');
15
+ const [history, setHistory] = useState([]);
16
+ const stateRef = useRef(state);
17
+ const historyRef = useRef(history);
18
+ stateRef.current = state;
19
+ historyRef.current = history;
20
+ const send = useCallback((event) => {
21
+ if (!flow)
22
+ return;
23
+ const current = stateRef.current;
24
+ const next = flow.states[current]?.on?.[event];
25
+ if (!next)
26
+ return;
27
+ const entry = `${current} --${event}--> ${next}`;
28
+ setState(next);
29
+ setHistory((previous) => [...previous, entry].slice(-30));
30
+ }, [flow]);
31
+ useEffect(() => {
32
+ window.parent.postMessage({ type: 'design:state', frame, state, history: historyRef.current }, '*');
33
+ }, [frame, state, history]);
34
+ useEffect(() => {
35
+ const onMessage = (event) => {
36
+ if (event.source !== window.parent)
37
+ return;
38
+ const data = event.data;
39
+ if (data?.type !== 'design:command' || data.action !== 'event')
40
+ return;
41
+ if (typeof data.event !== 'string')
42
+ return;
43
+ send(data.event);
44
+ };
45
+ window.addEventListener('message', onMessage);
46
+ return () => window.removeEventListener('message', onMessage);
47
+ }, [send]);
48
+ const value = useMemo(() => ({ state, history, send }), [state, history, send]);
49
+ return _jsx(FlowContext.Provider, { value: value, children: children });
50
+ }
51
+ //# sourceMappingURL=flow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.js","sourceRoot":"","sources":["../src/flow.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GAGT,MAAM,OAAO,CAAA;AAUd,MAAM,IAAI,GAA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AE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;IAExF,OAAO,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAwB,CAAA;AAC9E,CAAC","sourcesContent":["import {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type Context,\n type ReactNode,\n} from 'react'\n\nimport type { Flow } from './types.ts'\n\nexport type FlowApi = {\n state: string\n history: string[]\n send: (event: string) => void\n}\n\nconst idle: FlowApi = {\n state: 'default',\n history: [],\n send: () => {},\n}\n\n// Share one React Context across host node_modules and global npx runtime copies.\nconst FLOW_CONTEXT_KEY = Symbol.for('design-surface.flow-context')\nconst globalScope = globalThis as unknown as Record<PropertyKey, unknown>\nconst FlowContext = (globalScope[FLOW_CONTEXT_KEY] ??= createContext<FlowApi>(\n idle,\n)) as Context<FlowApi>\n\nexport const useDesignFlow = () => useContext(FlowContext)\n\nexport function FlowProvider({\n flow,\n initial,\n frame,\n children,\n}: {\n flow?: Flow\n initial?: string\n frame: string\n children: ReactNode\n}) {\n const [state, setState] = useState(initial ?? flow?.initial ?? 'default')\n const [history, setHistory] = useState<string[]>([])\n const stateRef = useRef(state)\n const historyRef = useRef(history)\n stateRef.current = state\n historyRef.current = history\n\n const send = useCallback(\n (event: string) => {\n if (!flow) return\n const current = stateRef.current\n const next = flow.states[current]?.on?.[event]\n if (!next) return\n const entry = `${current} --${event}--> ${next}`\n setState(next)\n setHistory((previous) => [...previous, entry].slice(-30))\n },\n [flow],\n )\n\n useEffect(() => {\n window.parent.postMessage(\n { type: 'design:state', frame, state, history: historyRef.current },\n '*',\n )\n }, [frame, state, history])\n\n useEffect(() => {\n const onMessage = (event: MessageEvent) => {\n if (event.source !== window.parent) return\n const data = event.data as { type?: unknown; action?: unknown; event?: unknown }\n if (data?.type !== 'design:command' || data.action !== 'event') return\n if (typeof data.event !== 'string') return\n send(data.event)\n }\n window.addEventListener('message', onMessage)\n return () => window.removeEventListener('message', onMessage)\n }, [send])\n\n const value = useMemo<FlowApi>(() => ({ state, history, send }), [state, history, send])\n\n return <FlowContext.Provider value={value}>{children}</FlowContext.Provider>\n}\n"]}
package/dist/free.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { CSSProperties, ReactNode } from 'react';
2
+ export declare function FreeCanvas({ width, height, className, children, }: {
3
+ width: number;
4
+ height: number;
5
+ className?: string;
6
+ children: ReactNode;
7
+ }): import("react").JSX.Element;
8
+ export declare function FreeItem({ id, x, y, width, height, className, style, children, }: {
9
+ id: string;
10
+ x: number;
11
+ y: number;
12
+ width: number | string;
13
+ height: number | string;
14
+ className?: string;
15
+ style?: CSSProperties;
16
+ children: ReactNode;
17
+ }): import("react").JSX.Element;
18
+ //# sourceMappingURL=free.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"free.d.ts","sourceRoot":"","sources":["../src/free.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAErD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,MAAM,EACN,SAAS,EACT,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,SAAS,CAAA;CACpB,+BAUA;AAED,wBAAgB,QAAQ,CAAC,EACvB,EAAE,EACF,CAAC,EACD,CAAC,EACD,KAAK,EACL,MAAM,EACN,SAAS,EACT,KAAK,EACL,QAAQ,GACT,EAAE;IACD,EAAE,EAAE,MAAM,CAAA;IACV,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,QAAQ,EAAE,SAAS,CAAA;CACpB,+BAWA"}
package/dist/free.js ADDED
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function FreeCanvas({ width, height, className, children, }) {
3
+ return (_jsx("div", { "data-free-canvas": "", className: className, style: { position: 'relative', width, height, overflow: 'hidden' }, children: children }));
4
+ }
5
+ export function FreeItem({ id, x, y, width, height, className, style, children, }) {
6
+ return (_jsx("div", { "data-ds": id, "data-free-item": id, className: className, style: { position: 'absolute', left: x, top: y, width, height, ...style }, children: children }));
7
+ }
8
+ //# sourceMappingURL=free.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"free.js","sourceRoot":"","sources":["../src/free.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,UAAU,CAAC,EACzB,KAAK,EACL,MAAM,EACN,SAAS,EACT,QAAQ,GAMT;IACC,OAAO,CACL,kCACmB,EAAE,EACnB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAEjE,QAAQ,GACL,CACP,CAAA;AACH,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,EACvB,EAAE,EACF,CAAC,EACD,CAAC,EACD,KAAK,EACL,MAAM,EACN,SAAS,EACT,KAAK,EACL,QAAQ,GAUT;IACC,OAAO,CACL,yBACW,EAAE,oBACK,EAAE,EAClB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,YAExE,QAAQ,GACL,CACP,CAAA;AACH,CAAC","sourcesContent":["import type { CSSProperties, ReactNode } from 'react'\n\nexport function FreeCanvas({\n width,\n height,\n className,\n children,\n}: {\n width: number\n height: number\n className?: string\n children: ReactNode\n}) {\n return (\n <div\n data-free-canvas=\"\"\n className={className}\n style={{ position: 'relative', width, height, overflow: 'hidden' }}\n >\n {children}\n </div>\n )\n}\n\nexport function FreeItem({\n id,\n x,\n y,\n width,\n height,\n className,\n style,\n children,\n}: {\n id: string\n x: number\n y: number\n width: number | string\n height: number | string\n className?: string\n style?: CSSProperties\n children: ReactNode\n}) {\n return (\n <div\n data-ds={id}\n data-free-item={id}\n className={className}\n style={{ position: 'absolute', left: x, top: y, width, height, ...style }}\n >\n {children}\n </div>\n )\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { DesignConfig, FrameConfig } from './types.ts';
2
+ export declare function DesignFrame({ design, frame }: {
3
+ design: DesignConfig;
4
+ frame: FrameConfig;
5
+ }): import("react").JSX.Element;
6
+ export * from './free.tsx';
7
+ export * from './flow.tsx';
8
+ export * from './types.ts';
9
+ export type * from './tokens.ts';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAoB,WAAW,EAAE,MAAM,YAAY,CAAA;AA+D7E,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,+BAM1F;AAED,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,mBAAmB,aAAa,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Component } from 'react';
3
+ import { FlowProvider, useDesignFlow } from "./flow.js";
4
+ class DesignErrorBoundary extends Component {
5
+ state = { error: null };
6
+ static getDerivedStateFromError(error) {
7
+ return { error };
8
+ }
9
+ componentDidCatch(error, info) {
10
+ console.error(`[design-surface] frame ${this.props.frame} crashed`, error, info);
11
+ }
12
+ render() {
13
+ if (this.state.error) {
14
+ return (_jsx("div", { style: {
15
+ margin: 24,
16
+ padding: 16,
17
+ border: '1px solid #fecaca',
18
+ borderRadius: 12,
19
+ background: '#fef2f2',
20
+ color: '#991b1b',
21
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
22
+ fontSize: 12,
23
+ whiteSpace: 'pre-wrap',
24
+ }, children: this.state.error.message }));
25
+ }
26
+ return this.props.children;
27
+ }
28
+ }
29
+ function FrameBody({ design, frame }) {
30
+ const flow = useDesignFlow();
31
+ const props = { state: flow.state, send: flow.send, frame };
32
+ const Component = frame.component ?? design.component;
33
+ const content = frame.render
34
+ ? frame.render(props)
35
+ : Component
36
+ ? _jsx(Component, { ...props })
37
+ : (_jsx("div", { style: { padding: 24, fontFamily: 'system-ui', color: '#64748b' }, children: "This design has no component or render function." }));
38
+ return (_jsx(DesignErrorBoundary, { frame: frame.id, children: _jsx("div", { "data-design-frame": frame.id, style: { minHeight: '100%' }, children: content }) }));
39
+ }
40
+ export function DesignFrame({ design, frame }) {
41
+ return (_jsx(FlowProvider, { flow: design.flow, initial: frame.state, frame: frame.id, children: _jsx(FrameBody, { design: design, frame: frame }) }));
42
+ }
43
+ export * from "./free.js";
44
+ export * from "./flow.js";
45
+ export * from "./types.js";
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAA;AAEjE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAY,CAAA;AAGxD,MAAM,mBAAoB,SAAQ,SAGjC;IACC,KAAK,GAA4B,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;IAEhD,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC1C,OAAO,EAAE,KAAK,EAAE,CAAA;IAClB,CAAC;IAED,iBAAiB,CAAC,KAAY,EAAE,IAAe;QAC7C,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C,KAAK,EAAE,KAAK,CAAC,EAAE,YAClC,mCAAwB,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,YAC3D,OAAO,GACJ,GACc,CACvB,CAAA;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,EAAgD;IACzF,OAAO,CACL,KAAC,YAAY,IAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,YACpE,KAAC,SAAS,IAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAI,GAC9B,CAChB,CAAA;AACH,CAAC;AAED,cAAc,WAAY,CAAA;AAC1B,cAAc,WAAY,CAAA;AAC1B,cAAc,YAAY,CAAA","sourcesContent":["import { Component, type ErrorInfo, type ReactNode } from 'react'\n\nimport { FlowProvider, useDesignFlow } from './flow.tsx'\nimport type { DesignConfig, DesignFrameProps, FrameConfig } from './types.ts'\n\nclass DesignErrorBoundary extends Component<\n { frame: string; children: ReactNode },\n { error: Error | null }\n> {\n state: { error: Error | null } = { error: null }\n\n static getDerivedStateFromError(error: Error) {\n return { error }\n }\n\n componentDidCatch(error: Error, info: ErrorInfo) {\n console.error(`[design-surface] frame ${this.props.frame} crashed`, error, info)\n }\n\n render() {\n if (this.state.error) {\n return (\n <div\n style={{\n margin: 24,\n padding: 16,\n border: '1px solid #fecaca',\n borderRadius: 12,\n background: '#fef2f2',\n color: '#991b1b',\n fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',\n fontSize: 12,\n whiteSpace: 'pre-wrap',\n }}\n >\n {this.state.error.message}\n </div>\n )\n }\n return this.props.children\n }\n}\n\nfunction FrameBody({ design, frame }: { design: DesignConfig; frame: FrameConfig }) {\n const flow = useDesignFlow()\n const props: DesignFrameProps = { state: flow.state, send: flow.send, frame }\n const Component = frame.component ?? design.component\n const content = frame.render\n ? frame.render(props)\n : Component\n ? <Component {...props} />\n : (\n <div style={{ padding: 24, fontFamily: 'system-ui', color: '#64748b' }}>\n This design has no component or render function.\n </div>\n )\n\n return (\n <DesignErrorBoundary frame={frame.id}>\n <div data-design-frame={frame.id} style={{ minHeight: '100%' }}>\n {content}\n </div>\n </DesignErrorBoundary>\n )\n}\n\nexport function DesignFrame({ design, frame }: { design: DesignConfig; frame: FrameConfig }) {\n return (\n <FlowProvider flow={design.flow} initial={frame.state} frame={frame.id}>\n <FrameBody design={design} frame={frame} />\n </FlowProvider>\n )\n}\n\nexport * from './free.tsx'\nexport * from './flow.tsx'\nexport * from './types.ts'\nexport type * from './tokens.ts'\n"]}
@@ -0,0 +1,66 @@
1
+ export type TokenType = 'color' | 'length' | 'text' | 'select';
2
+ export type TokenTier = 'primitive' | 'semantic' | 'component';
3
+ export type TokenDef = {
4
+ name: string;
5
+ label: string;
6
+ labelZh?: string;
7
+ type: TokenType;
8
+ description?: string;
9
+ options?: string[];
10
+ min?: number;
11
+ max?: number;
12
+ step?: number;
13
+ /** Source-backed token metadata, generated from DTCG. */
14
+ tier?: TokenTier;
15
+ path?: string;
16
+ alias?: string;
17
+ source?: string;
18
+ value?: string;
19
+ usedIn?: string[];
20
+ aliasedBy?: string[];
21
+ };
22
+ export type TokenGroup = {
23
+ id: string;
24
+ label: string;
25
+ labelZh?: string;
26
+ tier?: TokenTier;
27
+ tokens: TokenDef[];
28
+ };
29
+ export type TokenCluster = {
30
+ value: string;
31
+ count: number;
32
+ files: string[];
33
+ adapters: string[];
34
+ };
35
+ export type UnsupportedStyleDiagnostic = {
36
+ file: string;
37
+ adapter: string;
38
+ reason: string;
39
+ count: number;
40
+ line?: number;
41
+ };
42
+ export type TokenHealth = {
43
+ duplicates: {
44
+ group: string;
45
+ value: string;
46
+ tokens: string[];
47
+ }[];
48
+ orphans: string[];
49
+ semanticLiterals: string[];
50
+ componentPrimitive: {
51
+ token: string;
52
+ alias: string;
53
+ }[];
54
+ hardcoded: {
55
+ file: string;
56
+ count: number;
57
+ values?: {
58
+ value: string;
59
+ count: number;
60
+ }[];
61
+ }[];
62
+ clusters?: TokenCluster[];
63
+ unsupported?: UnsupportedStyleDiagnostic[];
64
+ };
65
+ export type TokenHealthAction = 'alias' | 'deprecate' | 'promote';
66
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE9D,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAA;AAE9D,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,SAAS,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,yDAAyD;IACzD,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,SAAS,CA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tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"","sourcesContent":["export type TokenType = 'color' | 'length' | 'text' | 'select'\n\nexport type TokenTier = 'primitive' | 'semantic' | 'component'\n\nexport type TokenDef = {\n name: string\n label: string\n labelZh?: string\n type: TokenType\n description?: string\n options?: string[]\n min?: number\n max?: number\n step?: number\n /** Source-backed token metadata, generated from DTCG. */\n tier?: TokenTier\n path?: string\n alias?: string\n source?: string\n value?: string\n usedIn?: string[]\n aliasedBy?: string[]\n}\n\nexport type TokenGroup = {\n id: string\n label: string\n labelZh?: string\n tier?: TokenTier\n tokens: TokenDef[]\n}\n\nexport type TokenCluster = {\n value: string\n count: number\n files: string[]\n adapters: string[]\n}\n\nexport type UnsupportedStyleDiagnostic = {\n file: string\n adapter: string\n reason: string\n count: number\n line?: number\n}\n\nexport type TokenHealth = {\n duplicates: { group: string; value: string; tokens: string[] }[]\n orphans: string[]\n semanticLiterals: string[]\n componentPrimitive: { token: string; alias: string }[]\n hardcoded: { file: string; count: number; values?: { value: string; count: number }[] }[]\n clusters?: TokenCluster[]\n unsupported?: UnsupportedStyleDiagnostic[]\n}\n\nexport type TokenHealthAction = 'alias' | 'deprecate' | 'promote'\n"]}
@@ -0,0 +1,57 @@
1
+ import type { ComponentType, ReactNode } from 'react';
2
+ import type { TokenGroup } from './tokens.ts';
3
+ export type FrameSize = [number, number];
4
+ export type DesignFrameProps = {
5
+ state: string;
6
+ send: (event: string) => void;
7
+ frame: FrameConfig;
8
+ };
9
+ export type FrameConfig = {
10
+ id: string;
11
+ title?: string;
12
+ titleZh?: string;
13
+ size: FrameSize;
14
+ state?: string;
15
+ component?: ComponentType<DesignFrameProps>;
16
+ render?: (props: DesignFrameProps) => ReactNode;
17
+ };
18
+ export type PageBoardProps = {
19
+ page: PageConfig;
20
+ frames: FrameConfig[];
21
+ activeFrameId: string;
22
+ playing: ReadonlySet<string>;
23
+ onActivateFrame: (frameId: string) => void;
24
+ renderFrame: (frame: FrameConfig) => ReactNode;
25
+ };
26
+ export type PageConfig = {
27
+ id: string;
28
+ title?: string;
29
+ titleZh?: string;
30
+ description?: string;
31
+ size: FrameSize;
32
+ board?: ComponentType<PageBoardProps>;
33
+ frames: FrameConfig[];
34
+ };
35
+ export type Flow = {
36
+ initial: string;
37
+ states: Record<string, {
38
+ on?: Record<string, string>;
39
+ }>;
40
+ };
41
+ export type DesignConfig = {
42
+ title?: string;
43
+ titleZh?: string;
44
+ pages?: PageConfig[];
45
+ /** Legacy one-frame pages. New designs use pages. */
46
+ frames?: FrameConfig[];
47
+ flow?: Flow;
48
+ component?: ComponentType<DesignFrameProps>;
49
+ tokens?: TokenGroup[];
50
+ };
51
+ export declare function designPages(design: DesignConfig): PageConfig[];
52
+ export type DesignModule = DesignConfig & {
53
+ id: string;
54
+ };
55
+ export declare const defineDesign: (config: DesignConfig) => DesignConfig;
56
+ export declare const defineFlow: (flow: Flow) => Flow;
57
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAExC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7B,KAAK,EAAE,WAAW,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,SAAS,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;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C3C,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;CACtB,CAAA;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,EAAE,CAS9D;AAED,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA;AAExD,eAAO,MAAM,YAAY,GAAI,QAAQ,YAAY,KAAG,YAAsB,CAAA;AAE1E,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,KAAG,IAAY,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,14 @@
1
+ export function designPages(design) {
2
+ if (design.pages)
3
+ return design.pages;
4
+ return (design.frames ?? []).map((frame) => ({
5
+ id: frame.id,
6
+ title: frame.title,
7
+ titleZh: frame.titleZh,
8
+ size: frame.size,
9
+ frames: [frame],
10
+ }));
11
+ }
12
+ export const defineDesign = (config) => config;
13
+ export const defineFlow = (flow) => flow;
14
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAyDA,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC9C,IAAI,MAAM,CAAC,KAAK;QAAE,OAAO,MAAM,CAAC,KAAK,CAAA;IACrC,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC3C,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,CAAC,KAAK,CAAC;KAChB,CAAC,CAAC,CAAA;AACL,CAAC;AAID,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAoB,EAAgB,EAAE,CAAC,MAAM,CAAA;AAE1E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAU,EAAQ,EAAE,CAAC,IAAI,CAAA","sourcesContent":["import type { ComponentType, ReactNode } from 'react'\n\nimport type { TokenGroup } from './tokens.ts'\n\nexport type FrameSize = [number, number]\n\nexport type DesignFrameProps = {\n state: string\n send: (event: string) => void\n frame: FrameConfig\n}\n\nexport type FrameConfig = {\n id: string\n title?: string\n titleZh?: string\n size: FrameSize\n state?: string\n component?: ComponentType<DesignFrameProps>\n render?: (props: DesignFrameProps) => ReactNode\n}\n\nexport type PageBoardProps = {\n page: PageConfig\n frames: FrameConfig[]\n activeFrameId: string\n playing: ReadonlySet<string>\n onActivateFrame: (frameId: string) => void\n renderFrame: (frame: FrameConfig) => ReactNode\n}\n\nexport type PageConfig = {\n id: string\n title?: string\n titleZh?: string\n description?: string\n size: FrameSize\n board?: ComponentType<PageBoardProps>\n frames: FrameConfig[]\n}\n\nexport type Flow = {\n initial: string\n states: Record<string, { on?: Record<string, string> }>\n}\n\nexport type DesignConfig = {\n title?: string\n titleZh?: string\n pages?: PageConfig[]\n /** Legacy one-frame pages. New designs use pages. */\n frames?: FrameConfig[]\n flow?: Flow\n component?: ComponentType<DesignFrameProps>\n tokens?: TokenGroup[]\n}\n\nexport function designPages(design: DesignConfig): PageConfig[] {\n if (design.pages) return design.pages\n return (design.frames ?? []).map((frame) => ({\n id: frame.id,\n title: frame.title,\n titleZh: frame.titleZh,\n size: frame.size,\n frames: [frame],\n }))\n}\n\nexport type DesignModule = DesignConfig & { id: string }\n\nexport const defineDesign = (config: DesignConfig): DesignConfig => config\n\nexport const defineFlow = (flow: Flow): Flow => flow\n"]}
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@rien7/design-surface-runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "type": "module",
5
+ "description": "Zero-dependency React runtime and types for Design Surface artboards.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/rien7/design-surface.git",
10
+ "directory": "packages/runtime"
11
+ },
12
+ "homepage": "https://github.com/rien7/design-surface#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/rien7/design-surface/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "engines": {
20
+ "node": ">=20.19.0"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
30
+ },
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.build.json",
33
+ "prepublishOnly": "tsc -p tsconfig.build.json",
34
+ "typecheck": "tsc --noEmit -p tsconfig.json"
35
+ },
36
+ "peerDependencies": {
37
+ "react": ">=18"
38
+ },
39
+ "devDependencies": {
40
+ "@types/react": "^19.2.0",
41
+ "react": "^19.2.0",
42
+ "typescript": "^5.9.3"
43
+ }
44
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.