@pairdraw/dom-css 0.0.0-stage → 0.16.1
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/LICENSE +21 -0
- package/README.md +219 -2
- package/dist/browser.d.ts +29 -0
- package/dist/browser.js +2 -0
- package/dist/chunks/behaviours/args.js +59 -0
- package/dist/chunks/behaviours/args.js.map +1 -0
- package/dist/chunks/behaviours/controls.js +109 -0
- package/dist/chunks/behaviours/controls.js.map +1 -0
- package/dist/chunks/behaviours/reset.js +40 -0
- package/dist/chunks/behaviours/reset.js.map +1 -0
- package/dist/chunks/behaviours/roles.js +51 -0
- package/dist/chunks/behaviours/roles.js.map +1 -0
- package/dist/chunks/behaviours/states/conditions.js +103 -0
- package/dist/chunks/behaviours/states/conditions.js.map +1 -0
- package/dist/chunks/behaviours/states/css.js +172 -0
- package/dist/chunks/behaviours/states/css.js.map +1 -0
- package/dist/chunks/behaviours/states/layers.js +1736 -0
- package/dist/chunks/behaviours/states/layers.js.map +1 -0
- package/dist/chunks/behaviours/states/model.js +144 -0
- package/dist/chunks/behaviours/states/model.js.map +1 -0
- package/dist/chunks/behaviours/states/tailwind.js +198 -0
- package/dist/chunks/behaviours/states/tailwind.js.map +1 -0
- package/dist/chunks/browser.js +1352 -0
- package/dist/chunks/browser.js.map +1 -0
- package/dist/chunks/export/bundle.js +337 -0
- package/dist/chunks/export/bundle.js.map +1 -0
- package/dist/chunks/export/components/drawn.js +60 -0
- package/dist/chunks/export/components/drawn.js.map +1 -0
- package/dist/chunks/export/components/fields.js +178 -0
- package/dist/chunks/export/components/fields.js.map +1 -0
- package/dist/chunks/export/components/groups.js +297 -0
- package/dist/chunks/export/components/groups.js.map +1 -0
- package/dist/chunks/export/components/icons.js +260 -0
- package/dist/chunks/export/components/icons.js.map +1 -0
- package/dist/chunks/export/components/layers.js +1599 -0
- package/dist/chunks/export/components/layers.js.map +1 -0
- package/dist/chunks/export/index.js +477 -0
- package/dist/chunks/export/index.js.map +1 -0
- package/dist/chunks/export/storybook/component.js +448 -0
- package/dist/chunks/export/storybook/component.js.map +1 -0
- package/dist/chunks/export/storybook/export.js +410 -0
- package/dist/chunks/export/storybook/export.js.map +1 -0
- package/dist/chunks/import/html.js +406 -0
- package/dist/chunks/import/html.js.map +1 -0
- package/dist/chunks/import/jsx/dev-runtime.js +37 -0
- package/dist/chunks/import/jsx/dev-runtime.js.map +1 -0
- package/dist/chunks/tokens/cssom-validator.js +10 -0
- package/dist/chunks/tokens/cssom-validator.js.map +1 -0
- package/dist/export.d.ts +594 -0
- package/dist/export.js +13 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +7 -0
- package/dist/jsx-dev-runtime.d.ts +8 -0
- package/dist/jsx-dev-runtime.js +3 -0
- package/dist/jsx-runtime.d.ts +20 -0
- package/dist/jsx-runtime.js +3 -0
- package/dist/rolldown-runtime.js +13 -0
- package/dist/runtime.d.ts +10 -0
- package/dist/scene-graph.d.ts +2 -0
- package/dist/scene-graph.js +2 -0
- package/dist/scene-graph2.d.ts +10 -0
- package/dist/styling.d.ts +93 -0
- package/dist/tailwind.d.ts +39 -0
- package/dist/types.d.ts +89 -0
- package/package.json +88 -4
- package/src/behaviours/args.ts +85 -0
- package/src/behaviours/controls.ts +195 -0
- package/src/behaviours/index.ts +11 -0
- package/src/behaviours/reset.ts +37 -0
- package/src/behaviours/roles.ts +44 -0
- package/src/behaviours/states/conditions.ts +105 -0
- package/src/behaviours/states/css.ts +123 -0
- package/src/behaviours/states/index.ts +4 -0
- package/src/behaviours/states/layers.ts +205 -0
- package/src/behaviours/states/model.ts +175 -0
- package/src/behaviours/states/names.ts +39 -0
- package/src/behaviours/states/tailwind.ts +148 -0
- package/src/behaviours/states/types.ts +56 -0
- package/src/browser.ts +146 -0
- package/src/cssom.d.ts +38 -0
- package/src/export/bundle.ts +461 -0
- package/src/export/components/drawn.ts +73 -0
- package/src/export/components/fields.ts +178 -0
- package/src/export/components/groups.ts +78 -0
- package/src/export/components/icons.ts +230 -0
- package/src/export/components/layers.ts +121 -0
- package/src/export/components/model.ts +544 -0
- package/src/export/components/properties.ts +167 -0
- package/src/export/components/react/fields.ts +129 -0
- package/src/export/components/react/index.ts +412 -0
- package/src/export/components/react/props.ts +151 -0
- package/src/export/components/react/radix.ts +52 -0
- package/src/export/components/react/shared.ts +76 -0
- package/src/export/components/references.ts +212 -0
- package/src/export/components/repeats.ts +128 -0
- package/src/export/components/shaders.ts +125 -0
- package/src/export/components/styling.ts +31 -0
- package/src/export/components/tree.ts +72 -0
- package/src/export/components/vue.ts +517 -0
- package/src/export/css.ts +57 -0
- package/src/export/grid.ts +42 -0
- package/src/export/html.ts +163 -0
- package/src/export/index.ts +44 -0
- package/src/export/projection.ts +581 -0
- package/src/export/storybook/component.ts +334 -0
- package/src/export/storybook/export.ts +430 -0
- package/src/export/storybook/groups.ts +161 -0
- package/src/export/storybook/module.ts +319 -0
- package/src/export/storybook/names.ts +51 -0
- package/src/export/tailwind-jsx.ts +156 -0
- package/src/export/text.ts +415 -0
- package/src/import/css-text.ts +4 -0
- package/src/import/css-values.ts +31 -0
- package/src/import/flow.ts +248 -0
- package/src/import/html.ts +88 -0
- package/src/import/jsx/core.ts +130 -0
- package/src/import/jsx/dev-runtime.ts +8 -0
- package/src/import/jsx/runtime.ts +76 -0
- package/src/import/scene-graph.ts +582 -0
- package/src/import/style-attribute.ts +25 -0
- package/src/import/tailwind.ts +54 -0
- package/src/import/text.ts +518 -0
- package/src/index.ts +51 -0
- package/src/runtime/browser/runtime.ts +301 -0
- package/src/runtime/headless/runtime.ts +99 -0
- package/src/runtime/headless/styles.ts +330 -0
- package/src/runtime/index.ts +11 -0
- package/src/tokens/conditions.ts +66 -0
- package/src/tokens/cssom-validator.ts +8 -0
- package/src/tokens/custom-properties.ts +331 -0
- package/src/tokens/expression.ts +128 -0
- package/src/tokens/formula.ts +140 -0
- package/src/tokens/index.ts +43 -0
- package/src/tokens/names.ts +161 -0
- package/src/tokens/references.ts +201 -0
- package/src/tokens/stylesheet.ts +304 -0
- package/src/tokens/validate.ts +86 -0
- package/src/tokens/values.ts +44 -0
- package/src/types.ts +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { CSSComputeOptions as CSSComputeOptions$1, CSSRuntime as CSSRuntime$1, DesignDocument as DesignDocument$1, DesignElement as DesignElement$1, DesignNode as DesignNode$1, DesignStyleDeclaration as DesignStyleDeclaration$1, DesignStyleSheet as DesignStyleSheet$1, DesignText as DesignText$1 } from "./types.js";
|
|
2
|
+
import { CompileTailwindCSSOptions, JSXStyleObject, JSXStyleValue, compileTailwindCSS } from "./tailwind.js";
|
|
3
|
+
import { DesignDocumentToSceneGraphOptions } from "./scene-graph2.js";
|
|
4
|
+
import { BrowserCSSRuntimeOptions, createBrowserCSSRuntime } from "./runtime.js";
|
|
5
|
+
import { ComponentStyling, ExportHTMLFile, SerializeHTMLOptions, VectorElementRenderer, WebFontFaceResolver, serializeNode } from "./styling.js";
|
|
6
|
+
import { JSXToDesignDocumentOptions, JSXToSceneGraphOptions, TailwindJSXToDesignDocumentOptions, TailwindJSXToSceneGraphOptions, jsxToDesignDocument, jsxToSceneGraph, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph } from "./jsx-runtime.js";
|
|
7
|
+
import { es } from "@pairdraw/emit";
|
|
8
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
9
|
+
//#region src/export/storybook/module.d.ts
|
|
10
|
+
declare const STORYBOOK_FRAMEWORKS: readonly ["react", "vue", "html"];
|
|
11
|
+
type StorybookFramework = (typeof STORYBOOK_FRAMEWORKS)[number];
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/export/storybook/export.d.ts
|
|
14
|
+
interface ExportStorybookOptions {
|
|
15
|
+
framework?: StorybookFramework;
|
|
16
|
+
/**
|
|
17
|
+
* How Vue and React components are styled: a stylesheet beside each, by default, or Tailwind
|
|
18
|
+
* utilities in their markup, which needs Tailwind set up in the Storybook project.
|
|
19
|
+
*/
|
|
20
|
+
styling?: ComponentStyling;
|
|
21
|
+
/** Limit the export to one page. Defaults to every page. */
|
|
22
|
+
pageId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The document's name, which titles its stories, such as `Pricing/Plan picker`, with each
|
|
25
|
+
* page's name between when it has several. Without it, stories are titled by page.
|
|
26
|
+
*/
|
|
27
|
+
document?: string;
|
|
28
|
+
/** Repository-relative `.fig`/`.pen` path; adds a `pairdraw://` design link to stories. */
|
|
29
|
+
linkPath?: string;
|
|
30
|
+
/** Renders a variant to PNG; each story then shows it next to the link as its design. */
|
|
31
|
+
renderDesignImage?: (nodeId: string) => Promise<Uint8Array>;
|
|
32
|
+
/** Draws vector layers as inline SVG, from the engine's SVG export. */
|
|
33
|
+
vectorElement?: VectorElementRenderer;
|
|
34
|
+
/**
|
|
35
|
+
* How each story file is written, which a caller decides, such as from rules a user wrote:
|
|
36
|
+
* which stories it has and its title. Every file is written as `variants` by default.
|
|
37
|
+
*/
|
|
38
|
+
plan?: (target: StoryTarget) => StoryPlan;
|
|
39
|
+
/**
|
|
40
|
+
* Finds the font files the stories' text uses, which ship with them in `fonts/` and load
|
|
41
|
+
* before a story shows, so its text draws in the document's fonts. Without it, text uses
|
|
42
|
+
* whatever fonts Storybook's page has.
|
|
43
|
+
*/
|
|
44
|
+
fonts?: WebFontFaceResolver;
|
|
45
|
+
/**
|
|
46
|
+
* The folder a document's shared files go in, its fonts and design tokens, which must differ
|
|
47
|
+
* for each document exported into the same place; `pairdraw/<document>` by default.
|
|
48
|
+
*/
|
|
49
|
+
folder?: string;
|
|
50
|
+
}
|
|
51
|
+
/** How a story file shows its component: every variant, Default alone, a gallery, or not. */
|
|
52
|
+
declare const STORY_MODES: readonly ["variants", "single", "gallery", "none"];
|
|
53
|
+
type StoryMode = (typeof STORY_MODES)[number];
|
|
54
|
+
/** A story file the export would write, as a plan reads it. */
|
|
55
|
+
interface StoryTarget {
|
|
56
|
+
/** The document's name, when the export knows it. */
|
|
57
|
+
document: string | undefined;
|
|
58
|
+
page: string;
|
|
59
|
+
/** The component set's or component's name, or a slash-named group's prefix. */
|
|
60
|
+
name: string;
|
|
61
|
+
/** The title the file has unless the plan gives another. */
|
|
62
|
+
title: string;
|
|
63
|
+
}
|
|
64
|
+
/** What a plan says about a story file; anything it leaves out stays as it would be. */
|
|
65
|
+
interface StoryPlan {
|
|
66
|
+
stories?: StoryMode;
|
|
67
|
+
title?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Whether a Vue or React export generates a component for the file, as it does by default,
|
|
70
|
+
* or keeps static stories of its variants.
|
|
71
|
+
*/
|
|
72
|
+
generate?: boolean;
|
|
73
|
+
}
|
|
74
|
+
interface StorybookFile extends ExportHTMLFile {
|
|
75
|
+
/** Name of the page the file was generated from. */
|
|
76
|
+
page: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Generate one CSF3 `.stories.ts` file per component or component set, plus a
|
|
80
|
+
* `<Name>.design/` folder of variant images when `renderDesignImage` is given.
|
|
81
|
+
*/
|
|
82
|
+
declare function exportStorybook(graph: SceneGraph, options?: ExportStorybookOptions): Promise<StorybookFile[]>;
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/runtime/headless/runtime.d.ts
|
|
85
|
+
declare function createHeadlessCSSRuntime(): CSSRuntime$1;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/runtime/index.d.ts
|
|
88
|
+
declare function createCSSRuntime(): CSSRuntime$1;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/import/html.d.ts
|
|
91
|
+
interface HTMLToDesignDocumentOptions {
|
|
92
|
+
cssText?: string;
|
|
93
|
+
runtime?: CSSRuntime$1;
|
|
94
|
+
compute?: CSSComputeOptions$1;
|
|
95
|
+
}
|
|
96
|
+
interface HTMLToSceneGraphOptions extends HTMLToDesignDocumentOptions, DesignDocumentToSceneGraphOptions {}
|
|
97
|
+
interface TailwindHTMLToDesignDocumentOptions extends Omit<HTMLToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}
|
|
98
|
+
interface TailwindHTMLToSceneGraphOptions extends TailwindHTMLToDesignDocumentOptions, DesignDocumentToSceneGraphOptions {}
|
|
99
|
+
declare function htmlToDesignDocument(html: string, options?: HTMLToDesignDocumentOptions): Promise<DesignDocument$1>;
|
|
100
|
+
declare function htmlToSceneGraph(html: string, options?: HTMLToSceneGraphOptions): Promise<SceneGraph>;
|
|
101
|
+
declare function tailwindHTMLToDesignDocument(html: string, candidates: string | Iterable<string>, options?: TailwindHTMLToDesignDocumentOptions): Promise<DesignDocument$1>;
|
|
102
|
+
declare function tailwindHTMLToSceneGraph(html: string, candidates: string | Iterable<string>, options?: TailwindHTMLToSceneGraphOptions): Promise<SceneGraph>;
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/index.d.ts
|
|
105
|
+
type CSSComputeOptions = CSSComputeOptions$1;
|
|
106
|
+
type CSSRuntime = CSSRuntime$1;
|
|
107
|
+
type DesignDocument = DesignDocument$1;
|
|
108
|
+
type DesignElement = DesignElement$1;
|
|
109
|
+
type DesignNode = DesignNode$1;
|
|
110
|
+
type DesignStyleDeclaration = DesignStyleDeclaration$1;
|
|
111
|
+
type DesignStyleSheet = DesignStyleSheet$1;
|
|
112
|
+
type DesignText = DesignText$1;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { type BrowserCSSRuntimeOptions, CSSComputeOptions, CSSRuntime, type CompileTailwindCSSOptions, DesignDocument, DesignElement, DesignNode, DesignStyleDeclaration, DesignStyleSheet, DesignText, type ExportStorybookOptions, type HTMLToDesignDocumentOptions, type HTMLToSceneGraphOptions, type JSXStyleObject, type JSXStyleValue, type JSXToDesignDocumentOptions, type JSXToSceneGraphOptions, STORYBOOK_FRAMEWORKS, STORY_MODES, type SerializeHTMLOptions, type StoryMode, type StoryPlan, type StoryTarget, type StorybookFile, type StorybookFramework, type TailwindHTMLToDesignDocumentOptions, type TailwindHTMLToSceneGraphOptions, type TailwindJSXToDesignDocumentOptions, type TailwindJSXToSceneGraphOptions, compileTailwindCSS, createBrowserCSSRuntime, createCSSRuntime, createHeadlessCSSRuntime, exportStorybook, htmlToDesignDocument, htmlToSceneGraph, jsxToDesignDocument, jsxToSceneGraph, serializeNode, tailwindHTMLToDesignDocument, tailwindHTMLToSceneGraph, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph };
|
|
115
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { serializeNode } from "./chunks/behaviours/states/tailwind.js";
|
|
2
|
+
import { STORYBOOK_FRAMEWORKS } from "./chunks/export/storybook/component.js";
|
|
3
|
+
import { STORY_MODES, exportStorybook } from "./chunks/export/storybook/export.js";
|
|
4
|
+
import { createBrowserCSSRuntime } from "./chunks/browser.js";
|
|
5
|
+
import { compileTailwindCSS, createCSSRuntime, createHeadlessCSSRuntime, htmlToDesignDocument, htmlToSceneGraph, tailwindHTMLToDesignDocument, tailwindHTMLToSceneGraph } from "./chunks/import/html.js";
|
|
6
|
+
import { jsxToDesignDocument, jsxToSceneGraph, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph } from "./chunks/import/jsx/dev-runtime.js";
|
|
7
|
+
export { STORYBOOK_FRAMEWORKS, STORY_MODES, compileTailwindCSS, createBrowserCSSRuntime, createCSSRuntime, createHeadlessCSSRuntime, exportStorybook, htmlToDesignDocument, htmlToSceneGraph, jsxToDesignDocument, jsxToSceneGraph, serializeNode, tailwindHTMLToDesignDocument, tailwindHTMLToSceneGraph, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DesignNode } from "./types.js";
|
|
2
|
+
import { Fragment, JSX, JSXChild, JSXElementProps, JSXStyleInput, JSXStyleObject, JSXStyleValue, JSXTag, jsx, jsxs } from "./tailwind.js";
|
|
3
|
+
import { JSXToDesignDocumentOptions, JSXToSceneGraphOptions, TailwindJSXToDesignDocumentOptions, TailwindJSXToSceneGraphOptions, jsxToDesignDocument, jsxToSceneGraph, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph } from "./jsx-runtime.js";
|
|
4
|
+
//#region src/import/jsx/dev-runtime.d.ts
|
|
5
|
+
declare function jsxDEV(tag: JSXTag, props?: JSXElementProps): DesignNode | DesignNode[];
|
|
6
|
+
//#endregion
|
|
7
|
+
export { Fragment, type JSX, type JSXChild, type JSXElementProps, type JSXStyleInput, type JSXStyleObject, type JSXStyleValue, type JSXTag, type JSXToDesignDocumentOptions, type JSXToSceneGraphOptions, type TailwindJSXToDesignDocumentOptions, type TailwindJSXToSceneGraphOptions, type jsx, jsxDEV, type jsxToDesignDocument, type jsxToSceneGraph, type jsxs, type tailwindJSXToDesignDocument, type tailwindJSXToSceneGraph };
|
|
8
|
+
//# sourceMappingURL=jsx-dev-runtime.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CSSComputeOptions, CSSRuntime, DesignDocument } from "./types.js";
|
|
2
|
+
import { CompileTailwindCSSOptions, Fragment, JSX, JSXChild, JSXElementProps, JSXStyleInput, JSXStyleObject, JSXStyleValue, JSXTag, jsx, jsxs } from "./tailwind.js";
|
|
3
|
+
import { DesignDocumentToSceneGraphOptions } from "./scene-graph2.js";
|
|
4
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
5
|
+
//#region src/import/jsx/runtime.d.ts
|
|
6
|
+
interface JSXToDesignDocumentOptions {
|
|
7
|
+
cssText?: string;
|
|
8
|
+
runtime?: CSSRuntime;
|
|
9
|
+
compute?: CSSComputeOptions;
|
|
10
|
+
}
|
|
11
|
+
interface JSXToSceneGraphOptions extends JSXToDesignDocumentOptions, DesignDocumentToSceneGraphOptions {}
|
|
12
|
+
interface TailwindJSXToDesignDocumentOptions extends Omit<JSXToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}
|
|
13
|
+
interface TailwindJSXToSceneGraphOptions extends TailwindJSXToDesignDocumentOptions, DesignDocumentToSceneGraphOptions {}
|
|
14
|
+
declare function jsxToDesignDocument(input: JSXChild, options?: JSXToDesignDocumentOptions): Promise<DesignDocument>;
|
|
15
|
+
declare function jsxToSceneGraph(input: JSXChild, options?: JSXToSceneGraphOptions): Promise<SceneGraph>;
|
|
16
|
+
declare function tailwindJSXToDesignDocument(input: JSXChild, candidates: string | Iterable<string>, options?: TailwindJSXToDesignDocumentOptions): Promise<DesignDocument>;
|
|
17
|
+
declare function tailwindJSXToSceneGraph(input: JSXChild, candidates: string | Iterable<string>, options?: TailwindJSXToSceneGraphOptions): Promise<SceneGraph>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Fragment, type JSX, type JSXChild, type JSXElementProps, type JSXStyleInput, type JSXStyleObject, type JSXStyleValue, type JSXTag, JSXToDesignDocumentOptions, JSXToSceneGraphOptions, TailwindJSXToDesignDocumentOptions, TailwindJSXToSceneGraphOptions, jsx, jsxToDesignDocument, jsxToSceneGraph, jsxs, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph };
|
|
20
|
+
//# sourceMappingURL=jsx-runtime.d.ts.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "./chunks/browser.js";
|
|
2
|
+
import { jsxToDesignDocument, jsxToSceneGraph, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph } from "./chunks/import/jsx/dev-runtime.js";
|
|
3
|
+
export { Fragment, jsx, jsxToDesignDocument, jsxToSceneGraph, jsxs, tailwindJSXToDesignDocument, tailwindJSXToSceneGraph };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CSSRuntime } from "./types.js";
|
|
2
|
+
//#region src/runtime/browser/runtime.d.ts
|
|
3
|
+
interface BrowserCSSRuntimeOptions {
|
|
4
|
+
document?: Document;
|
|
5
|
+
sandbox?: 'shadow-root' | 'iframe';
|
|
6
|
+
}
|
|
7
|
+
declare function createBrowserCSSRuntime(options?: BrowserCSSRuntimeOptions): CSSRuntime;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { BrowserCSSRuntimeOptions, createBrowserCSSRuntime };
|
|
10
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DesignDocument } from "./types.js";
|
|
2
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
3
|
+
//#region src/import/scene-graph.d.ts
|
|
4
|
+
interface DesignDocumentToSceneGraphOptions {
|
|
5
|
+
pageName?: string;
|
|
6
|
+
}
|
|
7
|
+
declare function designDocumentToSceneGraph(document: DesignDocument, options?: DesignDocumentToSceneGraphOptions): SceneGraph;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DesignDocumentToSceneGraphOptions, designDocumentToSceneGraph };
|
|
10
|
+
//# sourceMappingURL=scene-graph2.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { DesignDocument, DesignElement, DesignNode } from "./types.js";
|
|
2
|
+
import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
3
|
+
//#region src/export/projection.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Draws a vector-shaped layer as an inline `<svg>` element sized to the layer, from the
|
|
6
|
+
* engine's own SVG export. dom-css cannot depend on that engine, so it comes in as an option.
|
|
7
|
+
*/
|
|
8
|
+
type VectorElementRenderer = (graph: SceneGraph, node: SceneNode) => DesignElement | null;
|
|
9
|
+
interface SceneGraphToDesignOptions {
|
|
10
|
+
rootId?: string;
|
|
11
|
+
/** Write each layer's ID as `data-pairdraw-node-id`. Default true. */
|
|
12
|
+
includeSourceIds?: boolean;
|
|
13
|
+
/** Write each layer's own name as `data-name`, as the Tailwind JSX export does. Default false. */
|
|
14
|
+
includeLayerNames?: boolean;
|
|
15
|
+
/** Write variable-bound values as `var(--name)` where CSS resolves them as drawn. Default true. */
|
|
16
|
+
tokens?: boolean;
|
|
17
|
+
/** Vector, boolean, star, polygon, and icon layers as inline SVG; without it they project as boxes. */
|
|
18
|
+
vectorElement?: VectorElementRenderer;
|
|
19
|
+
/** Hidden layers to project as shown, such as the tab panels a component reveals itself. */
|
|
20
|
+
shown?: ReadonlySet<string>;
|
|
21
|
+
}
|
|
22
|
+
declare function sceneGraphToDesignDocument(graph: SceneGraph, options?: SceneGraphToDesignOptions): DesignDocument;
|
|
23
|
+
/** Project one node, including its own box, instead of the children of a root. */
|
|
24
|
+
declare function sceneNodeToDesignDocument(graph: SceneGraph, nodeId: string, options?: Omit<SceneGraphToDesignOptions, 'rootId'>): DesignDocument;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/export/bundle.d.ts
|
|
27
|
+
/** A font face the exported text uses. */
|
|
28
|
+
interface WebFontFaceRequest {
|
|
29
|
+
family: string;
|
|
30
|
+
weight: number;
|
|
31
|
+
style?: 'normal' | 'italic';
|
|
32
|
+
}
|
|
33
|
+
/** A font file to ship next to the page, described as an `@font-face` rule. */
|
|
34
|
+
interface WebFontFaceAsset {
|
|
35
|
+
family: string;
|
|
36
|
+
weight: string | number | [number, number];
|
|
37
|
+
style: string;
|
|
38
|
+
display?: string;
|
|
39
|
+
stretch?: string;
|
|
40
|
+
unicodeRange?: string[];
|
|
41
|
+
format: 'woff2' | 'woff' | 'opentype' | 'truetype';
|
|
42
|
+
path: string;
|
|
43
|
+
content: Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
/** Finds font files for the requested faces; paths start with `assetBasePath`. */
|
|
46
|
+
type WebFontFaceResolver = (fonts: WebFontFaceRequest[], assetBasePath: string) => Promise<WebFontFaceAsset[]>;
|
|
47
|
+
interface ExportHTMLBundleOptions {
|
|
48
|
+
html?: 'fragment' | 'standalone';
|
|
49
|
+
style?: 'inline' | 'tailwind';
|
|
50
|
+
assets?: 'inline' | 'external';
|
|
51
|
+
/** Resolves font files to include with external assets; `none` includes no fonts. */
|
|
52
|
+
fonts?: 'none' | WebFontFaceResolver;
|
|
53
|
+
assetBasePath?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Reads one of Tailwind's stylesheets, `tailwindcss/theme.css` or `tailwindcss/utilities.css`,
|
|
56
|
+
* for a standalone Tailwind page. Browsers pass one; Node and Bun read the installed package.
|
|
57
|
+
*/
|
|
58
|
+
loadTailwindStylesheet?: TailwindStylesheetLoader;
|
|
59
|
+
}
|
|
60
|
+
type TailwindStylesheetLoader = (id: TailwindStylesheetId) => Promise<string>;
|
|
61
|
+
type TailwindStylesheetId = 'tailwindcss/theme.css' | 'tailwindcss/utilities.css';
|
|
62
|
+
interface ExportHTMLFile {
|
|
63
|
+
path: string;
|
|
64
|
+
content: string | Uint8Array;
|
|
65
|
+
}
|
|
66
|
+
interface ExportHTMLBundle {
|
|
67
|
+
entrypoint: string;
|
|
68
|
+
files: ExportHTMLFile[];
|
|
69
|
+
}
|
|
70
|
+
declare function exportHTMLBundle(document: DesignDocument, options?: ExportHTMLBundleOptions): Promise<ExportHTMLBundle>;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/export/html.d.ts
|
|
73
|
+
interface SerializeHTMLOptions {
|
|
74
|
+
style?: 'inline' | 'tailwind';
|
|
75
|
+
/** Custom properties declared in `@theme`; a `var()` naming one becomes its utility. */
|
|
76
|
+
themeVariables?: readonly string[];
|
|
77
|
+
/**
|
|
78
|
+
* Put each child of an element that holds only elements on its own indented line, for code
|
|
79
|
+
* people read. Text keeps its whitespace; whitespace between elements in a projected layer
|
|
80
|
+
* changes nothing, since its children are placed by flex, grid, or absolute position.
|
|
81
|
+
*/
|
|
82
|
+
indent?: boolean;
|
|
83
|
+
}
|
|
84
|
+
declare function serializeNode(node: DesignNode, options?: SerializeHTMLOptions, depth?: number): string;
|
|
85
|
+
declare function serializeHTML(document: DesignDocument, options?: SerializeHTMLOptions): string;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/export/components/styling.d.ts
|
|
88
|
+
/** How a generated component is styled: a stylesheet, or Tailwind utilities in its markup. */
|
|
89
|
+
declare const COMPONENT_STYLINGS: readonly ["css", "tailwind"];
|
|
90
|
+
type ComponentStyling = (typeof COMPONENT_STYLINGS)[number];
|
|
91
|
+
//#endregion
|
|
92
|
+
export { COMPONENT_STYLINGS, ComponentStyling, ExportHTMLBundle, ExportHTMLBundleOptions, ExportHTMLFile, SceneGraphToDesignOptions, SerializeHTMLOptions, TailwindStylesheetId, TailwindStylesheetLoader, VectorElementRenderer, WebFontFaceAsset, WebFontFaceRequest, WebFontFaceResolver, exportHTMLBundle, sceneGraphToDesignDocument, sceneNodeToDesignDocument, serializeHTML, serializeNode };
|
|
93
|
+
//# sourceMappingURL=styling.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DesignNode } from "./types.js";
|
|
2
|
+
//#region src/import/jsx/core.d.ts
|
|
3
|
+
declare const Fragment: unique symbol;
|
|
4
|
+
type JSXComponent = (props: JSXElementProps) => JSXChild;
|
|
5
|
+
type JSXTag = string | JSXComponent | typeof Fragment;
|
|
6
|
+
type JSXStyleValue = string | number | null | undefined;
|
|
7
|
+
type JSXStyleObject = Record<string, JSXStyleValue>;
|
|
8
|
+
type JSXStyleInput = string | JSXStyleObject;
|
|
9
|
+
type JSXChild = DesignNode | JSXChild[] | string | number | boolean | null | undefined;
|
|
10
|
+
interface JSXElementProps {
|
|
11
|
+
children?: JSXChild;
|
|
12
|
+
class?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: JSXStyleInput;
|
|
15
|
+
key?: string | number;
|
|
16
|
+
[name: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
declare function jsx(tag: JSXTag, props?: JSXElementProps): DesignNode | DesignNode[];
|
|
19
|
+
declare const jsxs: typeof jsx;
|
|
20
|
+
declare namespace JSX {
|
|
21
|
+
type Element = DesignNode | DesignNode[];
|
|
22
|
+
interface ElementChildrenAttribute {
|
|
23
|
+
children: unknown;
|
|
24
|
+
}
|
|
25
|
+
interface IntrinsicElements {
|
|
26
|
+
[tagName: string]: JSXElementProps;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/import/tailwind.d.ts
|
|
31
|
+
interface CompileTailwindCSSOptions {
|
|
32
|
+
css?: string;
|
|
33
|
+
base?: string;
|
|
34
|
+
loadStylesheet?: (id: string, base: string) => Promise<string>;
|
|
35
|
+
}
|
|
36
|
+
declare function compileTailwindCSS(classes: string | Iterable<string>, options?: CompileTailwindCSSOptions): Promise<string>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { CompileTailwindCSSOptions, Fragment, JSX, JSXChild, JSXElementProps, JSXStyleInput, JSXStyleObject, JSXStyleValue, JSXTag, compileTailwindCSS, jsx, jsxs };
|
|
39
|
+
//# sourceMappingURL=tailwind.d.ts.map
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ShaderPreset } from "@pairdraw/scene-graph/shaders";
|
|
2
|
+
import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
3
|
+
//#region src/tokens/references.d.ts
|
|
4
|
+
/** The mode CSS applies for each collection, by collection id. */
|
|
5
|
+
type CSSModes = ReadonlyMap<string, string>;
|
|
6
|
+
/**
|
|
7
|
+
* Variable references for design-to-code. A bound field becomes `var(--name)` only when the
|
|
8
|
+
* stylesheet resolves it to what the canvas draws: the element sits in the same modes, and the
|
|
9
|
+
* token's CSS value is a length for a length, a bare number for opacity, or the paint's color.
|
|
10
|
+
* Anything else keeps its literal value.
|
|
11
|
+
*/
|
|
12
|
+
declare class DesignTokens {
|
|
13
|
+
#private;
|
|
14
|
+
readonly names: ReadonlyMap<string, string>;
|
|
15
|
+
/** Tokens the output references, with every variable their aliases reach. */
|
|
16
|
+
readonly used: Set<string>;
|
|
17
|
+
constructor(graph: SceneGraph);
|
|
18
|
+
/** The modes CSS applies outside the exported nodes: every collection's default. */
|
|
19
|
+
defaultModes(): CSSModes;
|
|
20
|
+
/**
|
|
21
|
+
* Attributes that put an element in the modes the canvas draws it in, and the modes CSS then
|
|
22
|
+
* applies to it. An exported root takes the editor's active modes; below it, a node changes
|
|
23
|
+
* modes only where it sets one. Only a mode without its own condition can be set this way.
|
|
24
|
+
*/
|
|
25
|
+
enter(node: SceneNode, inherited: CSSModes, root: boolean): {
|
|
26
|
+
attrs: Record<string, string>;
|
|
27
|
+
modes: CSSModes;
|
|
28
|
+
};
|
|
29
|
+
/** `var(--name)` for a bound field, or `undefined` where the literal value must stay. */
|
|
30
|
+
reference(node: SceneNode, field: string, modes: CSSModes): string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The variables a stylesheet for this output declares: the referenced ones and every variable
|
|
33
|
+
* their aliases reach in any mode, since each mode's scope declares its own alias targets.
|
|
34
|
+
*/
|
|
35
|
+
stylesheetVariables(): Set<string>;
|
|
36
|
+
/** Custom properties the Tailwind stylesheet declares in `@theme`, which name utilities. */
|
|
37
|
+
themeVariables(): string[];
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/types.d.ts
|
|
41
|
+
type DesignNode = DesignElement | DesignText;
|
|
42
|
+
interface DesignDocument {
|
|
43
|
+
type: 'document';
|
|
44
|
+
children: DesignNode[];
|
|
45
|
+
stylesheets?: DesignStyleSheet[];
|
|
46
|
+
sourceGraph?: SceneGraph;
|
|
47
|
+
/** Variable references the projection wrote, for Tailwind names and the token stylesheet. */
|
|
48
|
+
tokens?: DesignTokens;
|
|
49
|
+
}
|
|
50
|
+
interface DesignElement {
|
|
51
|
+
type: 'element';
|
|
52
|
+
tagName: string;
|
|
53
|
+
attrs: Record<string, string>;
|
|
54
|
+
children: DesignNode[];
|
|
55
|
+
inlineStyle?: DesignStyleDeclaration;
|
|
56
|
+
computedStyle?: DesignStyleDeclaration;
|
|
57
|
+
sourceSceneNodeId?: string;
|
|
58
|
+
sourceSceneNode?: SceneNode;
|
|
59
|
+
/**
|
|
60
|
+
* The shader the layer fills with, which plays behind its content: a framework draws it with
|
|
61
|
+
* the `shaders` library, static HTML shows `frame`, its still frame as a data URL.
|
|
62
|
+
*/
|
|
63
|
+
shader?: {
|
|
64
|
+
preset: ShaderPreset;
|
|
65
|
+
frame?: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
interface DesignText {
|
|
69
|
+
type: 'text';
|
|
70
|
+
text: string;
|
|
71
|
+
}
|
|
72
|
+
interface DesignStyleSheet {
|
|
73
|
+
type: 'stylesheet';
|
|
74
|
+
cssText: string;
|
|
75
|
+
href?: string;
|
|
76
|
+
}
|
|
77
|
+
type DesignStyleDeclaration = Record<string, string>;
|
|
78
|
+
interface CSSComputeOptions {
|
|
79
|
+
includeBrowserDefaults?: boolean;
|
|
80
|
+
}
|
|
81
|
+
interface CSSRuntime {
|
|
82
|
+
readonly kind: 'browser' | 'headless';
|
|
83
|
+
parseHTML(html: string): DesignDocument;
|
|
84
|
+
serializeHTML(document: DesignDocument): string;
|
|
85
|
+
computeStyles(document: DesignDocument, cssText?: string, options?: CSSComputeOptions): Promise<DesignDocument>;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { CSSComputeOptions, CSSRuntime, DesignDocument, DesignElement, DesignNode, DesignStyleDeclaration, DesignStyleSheet, DesignText };
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,90 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pairdraw/dom-css",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.16.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"src",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@acemir/cssom": "^0.9.31",
|
|
14
|
+
"@pairdraw/emit": "^0.16.1",
|
|
15
|
+
"css-tree": "^3.2.1",
|
|
16
|
+
"cssesc": "^3.0.0",
|
|
17
|
+
"dedent": "^1.7.2",
|
|
18
|
+
"entities": "^8.0.0",
|
|
19
|
+
"es-toolkit": "^1.52.0",
|
|
20
|
+
"js-base64": "^3.9.3",
|
|
21
|
+
"parse5": "^8.0.1",
|
|
22
|
+
"postcss-value-parser": "^4.2.0",
|
|
23
|
+
"tailwindcss": "^4.3.3",
|
|
24
|
+
"twirlwind": "^0.4.1"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@pairdraw/scene-graph": "^0.16.1"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./browser": {
|
|
36
|
+
"types": "./dist/browser.d.ts",
|
|
37
|
+
"import": "./dist/browser.js",
|
|
38
|
+
"default": "./dist/browser.js"
|
|
39
|
+
},
|
|
40
|
+
"./export": {
|
|
41
|
+
"types": "./dist/export.d.ts",
|
|
42
|
+
"import": "./dist/export.js",
|
|
43
|
+
"default": "./dist/export.js"
|
|
44
|
+
},
|
|
45
|
+
"./scene-graph": {
|
|
46
|
+
"types": "./dist/scene-graph.d.ts",
|
|
47
|
+
"import": "./dist/scene-graph.js",
|
|
48
|
+
"default": "./dist/scene-graph.js"
|
|
49
|
+
},
|
|
50
|
+
"./jsx-runtime": {
|
|
51
|
+
"types": "./dist/jsx-runtime.d.ts",
|
|
52
|
+
"import": "./dist/jsx-runtime.js",
|
|
53
|
+
"default": "./dist/jsx-runtime.js"
|
|
54
|
+
},
|
|
55
|
+
"./jsx-dev-runtime": {
|
|
56
|
+
"types": "./dist/jsx-dev-runtime.d.ts",
|
|
57
|
+
"import": "./dist/jsx-dev-runtime.js",
|
|
58
|
+
"default": "./dist/jsx-dev-runtime.js"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"imports": {
|
|
62
|
+
"#dom-css/*": {
|
|
63
|
+
"types": "./src/*.ts",
|
|
64
|
+
"default": "./dist/*.js"
|
|
65
|
+
},
|
|
66
|
+
"#dom-css-tests/*": "./tests/*.ts"
|
|
67
|
+
},
|
|
68
|
+
"description": "DOM, CSS, HTML, JSX, and Tailwind projection between Pairdraw documents and SceneGraph, with browser and headless CSS runtimes.",
|
|
69
|
+
"keywords": [
|
|
70
|
+
"pairdraw",
|
|
71
|
+
"design",
|
|
72
|
+
"html",
|
|
73
|
+
"css",
|
|
74
|
+
"tailwind",
|
|
75
|
+
"jsx",
|
|
76
|
+
"export"
|
|
77
|
+
],
|
|
78
|
+
"author": "Badryansah Bangsawan",
|
|
79
|
+
"homepage": "https://github.com/BadryansahBangsawan/pairdraw/tree/main/packages/dom-css#readme",
|
|
80
|
+
"bugs": {
|
|
81
|
+
"url": "https://github.com/BadryansahBangsawan/pairdraw/issues"
|
|
82
|
+
},
|
|
83
|
+
"type": "module",
|
|
84
|
+
"sideEffects": false,
|
|
85
|
+
"repository": {
|
|
86
|
+
"type": "git",
|
|
87
|
+
"url": "git+https://github.com/BadryansahBangsawan/pairdraw.git",
|
|
88
|
+
"directory": "packages/dom-css"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ComponentPropertyDefinition, SceneGraph, SceneNode } from '@pairdraw/scene-graph'
|
|
2
|
+
import {
|
|
3
|
+
behaviourProperties,
|
|
4
|
+
readBehaviour,
|
|
5
|
+
type Behaviour,
|
|
6
|
+
type BehaviourKind
|
|
7
|
+
} from '@pairdraw/scene-graph/behaviours'
|
|
8
|
+
|
|
9
|
+
/** A variant property a boolean value draws, as the component's boolean prop. */
|
|
10
|
+
export interface BooleanArg {
|
|
11
|
+
/** The prop's name, as Reka and Radix call it: `checked`, `pressed`, `open`, `disabled`. */
|
|
12
|
+
name: string
|
|
13
|
+
on: string
|
|
14
|
+
off: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The props a component with a behaviour has, read from the variant properties that draw it. */
|
|
18
|
+
export interface BehaviourArgs {
|
|
19
|
+
/** Boolean props by the name of the variant property that draws them. */
|
|
20
|
+
booleans: Map<string, BooleanArg>
|
|
21
|
+
/**
|
|
22
|
+
* The variant property that draws interaction states. States follow the pointer and focus,
|
|
23
|
+
* so they are not props; `rest` is the value shown without one, and `disabled` the value the
|
|
24
|
+
* disabled prop shows, if the set draws it.
|
|
25
|
+
*/
|
|
26
|
+
states?: { property: string; rest: string; disabled?: string }
|
|
27
|
+
/**
|
|
28
|
+
* The variant property that draws a field with text, which the field shows while its input
|
|
29
|
+
* has text rather than taking as a prop.
|
|
30
|
+
*/
|
|
31
|
+
filled?: { property: string; on: string; off: string }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Values a behaviour derives from others instead of taking as props. */
|
|
35
|
+
const DERIVED_VALUES = new Set(['filled'])
|
|
36
|
+
|
|
37
|
+
function booleanArgName(kind: BehaviourKind, valueId: string): string {
|
|
38
|
+
if (valueId !== 'value') return valueId
|
|
39
|
+
return kind === 'toggle' ? 'pressed' : 'checked'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The variant property a field's `filled` value draws, with its on and off values. */
|
|
43
|
+
function filledArg(
|
|
44
|
+
behaviour: Behaviour,
|
|
45
|
+
variant: (id: string) => ComponentPropertyDefinition | undefined
|
|
46
|
+
): BehaviourArgs['filled'] {
|
|
47
|
+
const binding = Object.hasOwn(behaviour.booleans, 'filled')
|
|
48
|
+
? behaviour.booleans.filled
|
|
49
|
+
: undefined
|
|
50
|
+
const definition = binding && variant(binding.propertyId)
|
|
51
|
+
if (!definition || binding.on === undefined || binding.off === undefined) return undefined
|
|
52
|
+
return { property: definition.name, on: binding.on, off: binding.off }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The props of a component set with a behaviour. Only variant properties become props here,
|
|
57
|
+
* since each variant is drawn; a boolean value becomes a boolean prop when its property offers
|
|
58
|
+
* exactly its on and off values.
|
|
59
|
+
*/
|
|
60
|
+
export function behaviourArgs(graph: SceneGraph, set: SceneNode): BehaviourArgs | null {
|
|
61
|
+
const behaviour = readBehaviour(set)
|
|
62
|
+
if (!behaviour) return null
|
|
63
|
+
const variants = behaviourProperties(graph, set).filter((item) => item.type === 'VARIANT')
|
|
64
|
+
const variant = (id: string) => variants.find((item) => item.id === id)
|
|
65
|
+
const booleans = new Map<string, BooleanArg>()
|
|
66
|
+
for (const [valueId, binding] of Object.entries(behaviour.booleans)) {
|
|
67
|
+
const definition = variant(binding.propertyId)
|
|
68
|
+
const { on, off } = binding
|
|
69
|
+
if (!definition || on === undefined || off === undefined || DERIVED_VALUES.has(valueId))
|
|
70
|
+
continue
|
|
71
|
+
const options = new Set(definition.variantOptions)
|
|
72
|
+
if (options.size !== 2 || !options.has(on) || !options.has(off)) continue
|
|
73
|
+
booleans.set(definition.name, { name: booleanArgName(behaviour.kind, valueId), on, off })
|
|
74
|
+
}
|
|
75
|
+
const statesProperty = behaviour.states && variant(behaviour.states.propertyId)
|
|
76
|
+
const states = statesProperty
|
|
77
|
+
? {
|
|
78
|
+
property: statesProperty.name,
|
|
79
|
+
rest: behaviour.states?.rest ?? statesProperty.defaultValue,
|
|
80
|
+
disabled: behaviour.states?.disabled
|
|
81
|
+
}
|
|
82
|
+
: undefined
|
|
83
|
+
const filled = filledArg(behaviour, variant)
|
|
84
|
+
return { booleans, states, ...(filled ? { filled } : {}) }
|
|
85
|
+
}
|