@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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Danila Poyarkov and OpenPencil contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,220 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pairdraw/dom-css
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DOM and CSS projection utilities for Pairdraw.
|
|
4
|
+
|
|
5
|
+
This package is the compatibility layer between Pairdraw's scene graph and DOM-shaped design documents. It is intentionally separate from `@pairdraw/core` so browser/CSS parser integrations can evolve without adding DOM dependencies to the renderer and editor core.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bun add @pairdraw/dom-css @pairdraw/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`@pairdraw/core` is a peer dependency because `@pairdraw/dom-css` projects to and from Pairdraw scene graphs. Consumers that only parse/serialize DesignDOM still need the peer installed for the package entrypoint.
|
|
14
|
+
|
|
15
|
+
## Package-local checks
|
|
16
|
+
|
|
17
|
+
This package can be validated independently from the app shell:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
cd packages/dom-css
|
|
21
|
+
bun run test
|
|
22
|
+
bun run typecheck
|
|
23
|
+
bun run check
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Package scripts:
|
|
27
|
+
|
|
28
|
+
- `bun run test` — package-local Bun tests for runtime, conversion, and Tailwind APIs
|
|
29
|
+
- `bun run typecheck` — type-checks `src` and tests
|
|
30
|
+
- `bun run build` — builds the distributable `dist` entrypoint
|
|
31
|
+
- `bun run check` — runs typecheck, tests, and build in sequence
|
|
32
|
+
|
|
33
|
+
The repository also keeps integration/oracle coverage under `tests/engine/dom-css` and `tests/e2e/dom-css`. The package-local suite focuses on the library's public API, while the repo-level E2E suite verifies browser `getComputedStyle()` parity through Playwright.
|
|
34
|
+
|
|
35
|
+
## Runtime model
|
|
36
|
+
|
|
37
|
+
Use the browser runtime as the high-fidelity source of truth whenever a DOM is available. It uses native parsing and `getComputedStyle()` inside an isolated sandbox. Prefer `sandbox: 'iframe'` for production-style conversion because it isolates authored CSS from host-page styles:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { createBrowserCSSRuntime } from '@pairdraw/dom-css'
|
|
41
|
+
|
|
42
|
+
const runtime = createBrowserCSSRuntime({ sandbox: 'iframe' })
|
|
43
|
+
const document = runtime.parseHTML('<article class="card">Pairdraw</article>')
|
|
44
|
+
const styled = await runtime.computeStyles(document, '.card { width: calc(10rem + 16px); }')
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The headless runtime is useful for Bun/Node tests, CLI flows, and fast approximate conversion. It supports common selectors, inheritance, shorthands, CSSOM grouping rules, and simple variable/calc values, but it is not a browser replacement. Do not use it as an oracle for browser-only CSS behavior such as layout-dependent computed values, full custom-property fallback behavior, modern color serialization, or UA defaults. Do not expand headless CSS parsing with ad hoc regex/string parsers; add a maintained parser/runtime dependency or use the browser runtime instead.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { createHeadlessCSSRuntime } from '@pairdraw/dom-css'
|
|
51
|
+
|
|
52
|
+
const runtime = createHeadlessCSSRuntime()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## HTML/CSS to scene graph
|
|
56
|
+
|
|
57
|
+
The convenience helpers run the full pipeline:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { htmlToSceneGraph } from '@pairdraw/dom-css'
|
|
61
|
+
|
|
62
|
+
const graph = await htmlToSceneGraph(
|
|
63
|
+
'<article class="card"><h1>Pairdraw</h1></article>',
|
|
64
|
+
{
|
|
65
|
+
cssText: '.card { display: flex; gap: 12px; width: 320px; padding: 24px; }'
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
For DesignDOM output without creating a scene graph, use `htmlToDesignDocument()`.
|
|
71
|
+
|
|
72
|
+
## JSX/DOM authoring
|
|
73
|
+
|
|
74
|
+
Use the package as a JSX import source when you want DOM-shaped authoring that still flows through DesignDOM, CSSOM, and SceneGraph conversion:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
/** @jsxImportSource @pairdraw/dom-css */
|
|
78
|
+
import { createBrowserCSSRuntime, jsxToSceneGraph } from '@pairdraw/dom-css'
|
|
79
|
+
|
|
80
|
+
const graph = await jsxToSceneGraph(
|
|
81
|
+
<article class="card">
|
|
82
|
+
<h1>Pairdraw</h1>
|
|
83
|
+
</article>,
|
|
84
|
+
{
|
|
85
|
+
cssText: '.card { display: flex; width: 320px; padding: 24px; }',
|
|
86
|
+
runtime: createBrowserCSSRuntime({ sandbox: 'iframe' })
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The JSX runtime preserves `class`, attributes, inline `style`, text, fragments, and simple function components as DesignDOM. Class semantics still come from generated or authored CSS passed to a CSS runtime; the JSX layer does not interpret Tailwind or CSS utility names directly.
|
|
92
|
+
|
|
93
|
+
When running in a browser, use the browser-first helpers so native `getComputedStyle()` is used automatically. Import them from `@pairdraw/dom-css/browser` so browser bundles do not load headless-only CSSOM dependencies:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
/** @jsxImportSource @pairdraw/dom-css */
|
|
97
|
+
import { browserJSXToSceneGraph } from '@pairdraw/dom-css/browser'
|
|
98
|
+
|
|
99
|
+
const graph = await browserJSXToSceneGraph(
|
|
100
|
+
<article class="card">
|
|
101
|
+
<h1>Pairdraw</h1>
|
|
102
|
+
</article>,
|
|
103
|
+
{
|
|
104
|
+
cssText: '.card { display: flex; width: 320px; padding: 24px; }',
|
|
105
|
+
sandbox: 'iframe'
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Use `browserJSXToDesignDocument()` / `browserJSXToSceneGraph()` for authored CSS. Use `browserTailwindJSXToDesignDocument()` / `browserTailwindJSXToSceneGraph()` only when Tailwind utilities should be compiled at runtime by the host app. Browser Tailwind compilation needs the host bundler to provide Tailwind source CSS or stylesheet loading; see the Tailwind recipes below.
|
|
111
|
+
|
|
112
|
+
## Tailwind pipeline
|
|
113
|
+
|
|
114
|
+
Tailwind classes flow through Tailwind's own compiler, then through the CSS runtime. Prefer the browser helpers when a document is available so custom properties, `calc()`, modern colors, and browser-default behavior come from native `getComputedStyle()`.
|
|
115
|
+
|
|
116
|
+
### Browser recipe: precompiled Tailwind CSS
|
|
117
|
+
|
|
118
|
+
The most portable browser path is to compile Tailwind CSS in the host app, then pass the resulting CSS as normal `cssText`:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { browserHTMLToSceneGraph } from '@pairdraw/dom-css/browser'
|
|
122
|
+
|
|
123
|
+
import tailwindCSS from './generated-tailwind.css?raw'
|
|
124
|
+
|
|
125
|
+
const graph = await browserHTMLToSceneGraph(
|
|
126
|
+
'<article class="flex w-80 rounded-xl bg-white p-6">Pairdraw</article>',
|
|
127
|
+
{
|
|
128
|
+
cssText: tailwindCSS,
|
|
129
|
+
sandbox: 'iframe'
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
This also works with JSX:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
/** @jsxImportSource @pairdraw/dom-css */
|
|
138
|
+
import { browserJSXToSceneGraph } from '@pairdraw/dom-css/browser'
|
|
139
|
+
|
|
140
|
+
import tailwindCSS from './generated-tailwind.css?raw'
|
|
141
|
+
|
|
142
|
+
const graph = await browserJSXToSceneGraph(
|
|
143
|
+
<article class="flex w-80 rounded-xl bg-white p-6">Pairdraw</article>,
|
|
144
|
+
{
|
|
145
|
+
cssText: tailwindCSS,
|
|
146
|
+
sandbox: 'iframe'
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Browser recipe: runtime Tailwind compilation with supplied CSS
|
|
152
|
+
|
|
153
|
+
If the app wants to compile utility candidates at runtime, provide Tailwind source CSS yourself. Do not rely on the default Node-oriented stylesheet loader in browser bundles:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { browserTailwindHTMLToSceneGraph } from '@pairdraw/dom-css/browser'
|
|
157
|
+
|
|
158
|
+
const classes = ['flex', 'w-80', 'rounded-xl', 'bg-white', 'p-6']
|
|
159
|
+
const graph = await browserTailwindHTMLToSceneGraph(
|
|
160
|
+
`<article class="${classes.join(' ')}">Pairdraw</article>`,
|
|
161
|
+
classes,
|
|
162
|
+
{
|
|
163
|
+
css: await fetch('/tailwind-source.css').then((response) => response.text()),
|
|
164
|
+
sandbox: 'iframe'
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Use `loadStylesheet` when the supplied Tailwind CSS contains imports and the host app owns import resolution:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { browserTailwindHTMLToSceneGraph } from '@pairdraw/dom-css/browser'
|
|
173
|
+
|
|
174
|
+
const classes = ['flex', 'w-80', 'rounded-xl', 'bg-white', 'p-6']
|
|
175
|
+
const graph = await browserTailwindHTMLToSceneGraph(
|
|
176
|
+
`<article class="${classes.join(' ')}">Pairdraw</article>`,
|
|
177
|
+
classes,
|
|
178
|
+
{
|
|
179
|
+
css: '@import "tailwindcss";',
|
|
180
|
+
loadStylesheet: async (id) => {
|
|
181
|
+
const url = id === 'tailwindcss' ? '/tailwindcss/index.css' : `/tailwindcss/${id}`
|
|
182
|
+
return fetch(url).then((response) => response.text())
|
|
183
|
+
},
|
|
184
|
+
sandbox: 'iframe'
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Bun/Node recipe
|
|
190
|
+
|
|
191
|
+
In Bun or Node, the package can load Tailwind's default stylesheet through filesystem-backed module resolution. Without a DOM, this uses the headless CSS runtime; pass a browser runtime only when the process has a real `document` available, such as Playwright or a browser extension page:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { tailwindHTMLToSceneGraph } from '@pairdraw/dom-css'
|
|
195
|
+
|
|
196
|
+
const classes = ['flex', 'w-80', 'p-6', 'rounded-xl', 'bg-white']
|
|
197
|
+
const graph = await tailwindHTMLToSceneGraph(
|
|
198
|
+
`<article class="${classes.join(' ')}">Pairdraw</article>`,
|
|
199
|
+
classes
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
`compileTailwindCSS()` remains available when callers want to manage CSS compilation and runtime selection themselves.
|
|
204
|
+
|
|
205
|
+
## Current scope
|
|
206
|
+
|
|
207
|
+
- DOM-shaped `DesignDocument` / `DesignElement` types
|
|
208
|
+
- Browser-backed runtime adapter for native HTML parsing, serialization, and computed-style extraction
|
|
209
|
+
- Headless runtime adapter with `parse5` HTML parsing and CSSOM-backed style computation for basic selectors, nested CSSOM rules, cascade order, inheritance, common shorthands, and simple custom-property/calc values
|
|
210
|
+
- SceneGraph ⇄ DesignDOM conversion for simple HTML/CSS-shaped layouts, including flex alignment/wrapping, self alignment, absolute positioning basics, logical padding, independent side borders, constraints, clipping, opacity, typography, and shadows
|
|
211
|
+
- JSX runtime helpers for DOM-shaped authoring into DesignDOM and SceneGraph
|
|
212
|
+
- Tailwind v4 compiler adapter
|
|
213
|
+
- Browser oracle fixtures for CSS variables, `calc()`, sandboxed browser-runtime output, modern color output, JSX/Tailwind browser helpers, and Tailwind utility output
|
|
214
|
+
|
|
215
|
+
## Roadmap
|
|
216
|
+
|
|
217
|
+
- Expand reusable fixtures: inputs, badges, nav/menu rows, dialog shells, and richer cards
|
|
218
|
+
- Map more computed CSS properties to scene graph fields through browser-native computed style or dependency-backed parsers: richer shadows, typography details, position constraints, borders, gradients, and grid once Pairdraw's grid support matures
|
|
219
|
+
- Improve SceneGraph → CSS export so generated HTML/CSS is useful for JSX, Tailwind, and web export
|
|
220
|
+
- Keep `@pairdraw/dom-css` stable before splitting lower-level file-format packages such as future `@pairdraw/kiwi` and `@pairdraw/fig`
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CSSComputeOptions, DesignDocument } from "./types.js";
|
|
2
|
+
import { CompileTailwindCSSOptions, Fragment, JSXChild, JSXElementProps, JSXStyleInput, JSXTag, jsx, jsxs } from "./tailwind.js";
|
|
3
|
+
import { DesignDocumentToSceneGraphOptions } from "./scene-graph2.js";
|
|
4
|
+
import { BrowserCSSRuntimeOptions } from "./runtime.js";
|
|
5
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
6
|
+
//#region src/browser.d.ts
|
|
7
|
+
interface BrowserToDesignDocumentOptions extends BrowserCSSRuntimeOptions {
|
|
8
|
+
cssText?: string;
|
|
9
|
+
compute?: CSSComputeOptions;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
type BrowserHTMLToDesignDocumentOptions = BrowserToDesignDocumentOptions;
|
|
13
|
+
interface BrowserHTMLToSceneGraphOptions extends BrowserToDesignDocumentOptions, DesignDocumentToSceneGraphOptions {}
|
|
14
|
+
interface BrowserTailwindHTMLToDesignDocumentOptions extends Omit<BrowserHTMLToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}
|
|
15
|
+
interface BrowserTailwindHTMLToSceneGraphOptions extends BrowserTailwindHTMLToDesignDocumentOptions, DesignDocumentToSceneGraphOptions {}
|
|
16
|
+
interface BrowserToSceneGraphOptions extends BrowserToDesignDocumentOptions, DesignDocumentToSceneGraphOptions {}
|
|
17
|
+
interface BrowserTailwindToDesignDocumentOptions extends Omit<BrowserToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}
|
|
18
|
+
interface BrowserTailwindToSceneGraphOptions extends BrowserTailwindToDesignDocumentOptions, DesignDocumentToSceneGraphOptions {}
|
|
19
|
+
declare function browserHTMLToDesignDocument(html: string, options?: BrowserHTMLToDesignDocumentOptions): Promise<DesignDocument>;
|
|
20
|
+
declare function browserHTMLToSceneGraph(html: string, options?: BrowserHTMLToSceneGraphOptions): Promise<SceneGraph>;
|
|
21
|
+
declare function browserTailwindHTMLToDesignDocument(html: string, candidates: string | Iterable<string>, options?: BrowserTailwindHTMLToDesignDocumentOptions): Promise<DesignDocument>;
|
|
22
|
+
declare function browserTailwindHTMLToSceneGraph(html: string, candidates: string | Iterable<string>, options?: BrowserTailwindHTMLToSceneGraphOptions): Promise<SceneGraph>;
|
|
23
|
+
declare function browserJSXToDesignDocument(input: JSXChild, options?: BrowserToDesignDocumentOptions): Promise<DesignDocument>;
|
|
24
|
+
declare function browserJSXToSceneGraph(input: JSXChild, options?: BrowserToSceneGraphOptions): Promise<SceneGraph>;
|
|
25
|
+
declare function browserTailwindJSXToDesignDocument(input: JSXChild, candidates: string | Iterable<string>, options?: BrowserTailwindToDesignDocumentOptions): Promise<DesignDocument>;
|
|
26
|
+
declare function browserTailwindJSXToSceneGraph(input: JSXChild, candidates: string | Iterable<string>, options?: BrowserTailwindToSceneGraphOptions): Promise<SceneGraph>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { BrowserHTMLToDesignDocumentOptions, BrowserHTMLToSceneGraphOptions, BrowserTailwindHTMLToDesignDocumentOptions, BrowserTailwindHTMLToSceneGraphOptions, BrowserTailwindToDesignDocumentOptions, BrowserTailwindToSceneGraphOptions, BrowserToDesignDocumentOptions, BrowserToSceneGraphOptions, Fragment, type JSXChild, type JSXElementProps, type JSXStyleInput, type JSXTag, browserHTMLToDesignDocument, browserHTMLToSceneGraph, browserJSXToDesignDocument, browserJSXToSceneGraph, browserTailwindHTMLToDesignDocument, browserTailwindHTMLToSceneGraph, browserTailwindJSXToDesignDocument, browserTailwindJSXToSceneGraph, jsx, jsxs };
|
|
29
|
+
//# sourceMappingURL=browser.d.ts.map
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Fragment, browserHTMLToDesignDocument, browserHTMLToSceneGraph, browserJSXToDesignDocument, browserJSXToSceneGraph, browserTailwindHTMLToDesignDocument, browserTailwindHTMLToSceneGraph, browserTailwindJSXToDesignDocument, browserTailwindJSXToSceneGraph, jsx, jsxs } from "./chunks/browser.js";
|
|
2
|
+
export { Fragment, browserHTMLToDesignDocument, browserHTMLToSceneGraph, browserJSXToDesignDocument, browserJSXToSceneGraph, browserTailwindHTMLToDesignDocument, browserTailwindHTMLToSceneGraph, browserTailwindJSXToDesignDocument, browserTailwindJSXToSceneGraph, jsx, jsxs };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { behaviourProperties, readBehaviour } from "@pairdraw/scene-graph/behaviours";
|
|
2
|
+
//#region src/behaviours/args.ts
|
|
3
|
+
/** Values a behaviour derives from others instead of taking as props. */
|
|
4
|
+
const DERIVED_VALUES = /* @__PURE__ */ new Set(["filled"]);
|
|
5
|
+
function booleanArgName(kind, valueId) {
|
|
6
|
+
if (valueId !== "value") return valueId;
|
|
7
|
+
return kind === "toggle" ? "pressed" : "checked";
|
|
8
|
+
}
|
|
9
|
+
/** The variant property a field's `filled` value draws, with its on and off values. */
|
|
10
|
+
function filledArg(behaviour, variant) {
|
|
11
|
+
const binding = Object.hasOwn(behaviour.booleans, "filled") ? behaviour.booleans.filled : void 0;
|
|
12
|
+
const definition = binding && variant(binding.propertyId);
|
|
13
|
+
if (!definition || binding.on === void 0 || binding.off === void 0) return void 0;
|
|
14
|
+
return {
|
|
15
|
+
property: definition.name,
|
|
16
|
+
on: binding.on,
|
|
17
|
+
off: binding.off
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The props of a component set with a behaviour. Only variant properties become props here,
|
|
22
|
+
* since each variant is drawn; a boolean value becomes a boolean prop when its property offers
|
|
23
|
+
* exactly its on and off values.
|
|
24
|
+
*/
|
|
25
|
+
function behaviourArgs(graph, set) {
|
|
26
|
+
const behaviour = readBehaviour(set);
|
|
27
|
+
if (!behaviour) return null;
|
|
28
|
+
const variants = behaviourProperties(graph, set).filter((item) => item.type === "VARIANT");
|
|
29
|
+
const variant = (id) => variants.find((item) => item.id === id);
|
|
30
|
+
const booleans = /* @__PURE__ */ new Map();
|
|
31
|
+
for (const [valueId, binding] of Object.entries(behaviour.booleans)) {
|
|
32
|
+
const definition = variant(binding.propertyId);
|
|
33
|
+
const { on, off } = binding;
|
|
34
|
+
if (!definition || on === void 0 || off === void 0 || DERIVED_VALUES.has(valueId)) continue;
|
|
35
|
+
const options = new Set(definition.variantOptions);
|
|
36
|
+
if (options.size !== 2 || !options.has(on) || !options.has(off)) continue;
|
|
37
|
+
booleans.set(definition.name, {
|
|
38
|
+
name: booleanArgName(behaviour.kind, valueId),
|
|
39
|
+
on,
|
|
40
|
+
off
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const statesProperty = behaviour.states && variant(behaviour.states.propertyId);
|
|
44
|
+
const states = statesProperty ? {
|
|
45
|
+
property: statesProperty.name,
|
|
46
|
+
rest: behaviour.states?.rest ?? statesProperty.defaultValue,
|
|
47
|
+
disabled: behaviour.states?.disabled
|
|
48
|
+
} : void 0;
|
|
49
|
+
const filled = filledArg(behaviour, variant);
|
|
50
|
+
return {
|
|
51
|
+
booleans,
|
|
52
|
+
states,
|
|
53
|
+
...filled ? { filled } : {}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { behaviourArgs };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","names":[],"sources":["../../../src/behaviours/args.ts"],"sourcesContent":["import type { ComponentPropertyDefinition, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n behaviourProperties,\n readBehaviour,\n type Behaviour,\n type BehaviourKind\n} from '@pairdraw/scene-graph/behaviours'\n\n/** A variant property a boolean value draws, as the component's boolean prop. */\nexport interface BooleanArg {\n /** The prop's name, as Reka and Radix call it: `checked`, `pressed`, `open`, `disabled`. */\n name: string\n on: string\n off: string\n}\n\n/** The props a component with a behaviour has, read from the variant properties that draw it. */\nexport interface BehaviourArgs {\n /** Boolean props by the name of the variant property that draws them. */\n booleans: Map<string, BooleanArg>\n /**\n * The variant property that draws interaction states. States follow the pointer and focus,\n * so they are not props; `rest` is the value shown without one, and `disabled` the value the\n * disabled prop shows, if the set draws it.\n */\n states?: { property: string; rest: string; disabled?: string }\n /**\n * The variant property that draws a field with text, which the field shows while its input\n * has text rather than taking as a prop.\n */\n filled?: { property: string; on: string; off: string }\n}\n\n/** Values a behaviour derives from others instead of taking as props. */\nconst DERIVED_VALUES = new Set(['filled'])\n\nfunction booleanArgName(kind: BehaviourKind, valueId: string): string {\n if (valueId !== 'value') return valueId\n return kind === 'toggle' ? 'pressed' : 'checked'\n}\n\n/** The variant property a field's `filled` value draws, with its on and off values. */\nfunction filledArg(\n behaviour: Behaviour,\n variant: (id: string) => ComponentPropertyDefinition | undefined\n): BehaviourArgs['filled'] {\n const binding = Object.hasOwn(behaviour.booleans, 'filled')\n ? behaviour.booleans.filled\n : undefined\n const definition = binding && variant(binding.propertyId)\n if (!definition || binding.on === undefined || binding.off === undefined) return undefined\n return { property: definition.name, on: binding.on, off: binding.off }\n}\n\n/**\n * The props of a component set with a behaviour. Only variant properties become props here,\n * since each variant is drawn; a boolean value becomes a boolean prop when its property offers\n * exactly its on and off values.\n */\nexport function behaviourArgs(graph: SceneGraph, set: SceneNode): BehaviourArgs | null {\n const behaviour = readBehaviour(set)\n if (!behaviour) return null\n const variants = behaviourProperties(graph, set).filter((item) => item.type === 'VARIANT')\n const variant = (id: string) => variants.find((item) => item.id === id)\n const booleans = new Map<string, BooleanArg>()\n for (const [valueId, binding] of Object.entries(behaviour.booleans)) {\n const definition = variant(binding.propertyId)\n const { on, off } = binding\n if (!definition || on === undefined || off === undefined || DERIVED_VALUES.has(valueId))\n continue\n const options = new Set(definition.variantOptions)\n if (options.size !== 2 || !options.has(on) || !options.has(off)) continue\n booleans.set(definition.name, { name: booleanArgName(behaviour.kind, valueId), on, off })\n }\n const statesProperty = behaviour.states && variant(behaviour.states.propertyId)\n const states = statesProperty\n ? {\n property: statesProperty.name,\n rest: behaviour.states?.rest ?? statesProperty.defaultValue,\n disabled: behaviour.states?.disabled\n }\n : undefined\n const filled = filledArg(behaviour, variant)\n return { booleans, states, ...(filled ? { filled } : {}) }\n}\n"],"mappings":";;;AAkCA,MAAM,iCAAiB,IAAI,IAAI,CAAC,QAAQ,CAAC;AAEzC,SAAS,eAAe,MAAqB,SAAyB;CACpE,IAAI,YAAY,S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eAAe;EAC/C,UAAU,UAAU,QAAQ;CAC9B,IACA,KAAA;CACJ,MAAM,SAAS,UAAU,WAAW,OAAO;CAC3C,OAAO;EAAE;EAAU;EAAQ,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;CAAG;AAC3D"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { behaviourContract, behaviourOwner, behaviourProperties, booleanBinding, hasBehaviour, layerPath, partBinding, readBehaviour, textBinding } from "@pairdraw/scene-graph/behaviours";
|
|
2
|
+
import { instanceMainComponent } from "@pairdraw/scene-graph/instances";
|
|
3
|
+
import { instanceSlotFrames, slotPropertyId } from "@pairdraw/scene-graph/slots";
|
|
4
|
+
import { findComponentPropertyTargets } from "@pairdraw/scene-graph/components";
|
|
5
|
+
//#region src/behaviours/controls.ts
|
|
6
|
+
function designedBoolean(graph, instance, definition, on) {
|
|
7
|
+
if (definition.type === "BOOLEAN") {
|
|
8
|
+
const assignments = instance.componentPropertyAssignments;
|
|
9
|
+
return (Object.hasOwn(assignments, definition.id) ? assignments[definition.id] : definition.defaultValue) === "true";
|
|
10
|
+
}
|
|
11
|
+
return instanceMainComponent(graph, instance)?.componentPropertyValues[definition.name] === on;
|
|
12
|
+
}
|
|
13
|
+
function statesModel(graph, instance, owner, behaviour) {
|
|
14
|
+
const states = behaviour.states;
|
|
15
|
+
const definition = states ? behaviourProperties(graph, owner).find((item) => item.id === states.propertyId && item.type === "VARIANT") : void 0;
|
|
16
|
+
if (!states || !definition) return null;
|
|
17
|
+
const authored = instanceMainComponent(graph, instance)?.componentPropertyValues[definition.name];
|
|
18
|
+
return {
|
|
19
|
+
name: definition.name,
|
|
20
|
+
values: states,
|
|
21
|
+
rest: states.rest ?? authored,
|
|
22
|
+
designedDisabled: !!states.disabled && authored === states.disabled
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function controlModel(graph, rootId, instance) {
|
|
26
|
+
const component = instanceMainComponent(graph, instance);
|
|
27
|
+
const owner = component && behaviourOwner(graph, component);
|
|
28
|
+
const behaviour = owner && readBehaviour(owner);
|
|
29
|
+
if (!owner || !behaviour) return null;
|
|
30
|
+
const path = layerPath(graph, rootId, instance.id);
|
|
31
|
+
const properties = behaviourProperties(graph, owner);
|
|
32
|
+
const booleans = {};
|
|
33
|
+
for (const valueId of Object.keys(behaviour.booleans)) {
|
|
34
|
+
const binding = booleanBinding(behaviour, valueId);
|
|
35
|
+
const definition = properties.find((item) => item.id === binding?.propertyId);
|
|
36
|
+
if (!binding || !definition) continue;
|
|
37
|
+
booleans[valueId] = {
|
|
38
|
+
definition,
|
|
39
|
+
on: binding.on,
|
|
40
|
+
off: binding.off,
|
|
41
|
+
designed: designedBoolean(graph, instance, definition, binding.on)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const frames = instanceSlotFrames(graph, instance);
|
|
45
|
+
const parts = Object.fromEntries(Object.entries(behaviour.parts).flatMap(([partId, propertyId]) => {
|
|
46
|
+
const frame = frames.find((item) => slotPropertyId(item) === propertyId);
|
|
47
|
+
return frame ? [[partId, layerPath(graph, rootId, frame.id)]] : [];
|
|
48
|
+
}));
|
|
49
|
+
const texts = Object.fromEntries(Object.keys(behaviour.texts).flatMap((valueId) => {
|
|
50
|
+
const propertyId = textBinding(behaviour, valueId);
|
|
51
|
+
const target = propertyId ? findComponentPropertyTargets(graph, instance, propertyId).find((item) => item.node.type === "TEXT") : void 0;
|
|
52
|
+
return target ? [[valueId, {
|
|
53
|
+
path: layerPath(graph, rootId, target.node.id),
|
|
54
|
+
designed: target.node.text
|
|
55
|
+
}]] : [];
|
|
56
|
+
}));
|
|
57
|
+
const frameOf = (partId) => {
|
|
58
|
+
const propertyId = partBinding(behaviour, partId);
|
|
59
|
+
return propertyId ? frames.find((item) => slotPropertyId(item) === propertyId) : void 0;
|
|
60
|
+
};
|
|
61
|
+
const itemsPart = behaviourContract(behaviour.kind).parts.find((part) => part.items);
|
|
62
|
+
const itemsFrame = itemsPart ? frameOf(itemsPart.id) : void 0;
|
|
63
|
+
const items = (itemsFrame ? graph.getChildren(itemsFrame.id) : []).flatMap((child) => {
|
|
64
|
+
const item = controlModel(graph, rootId, child);
|
|
65
|
+
return item ? [item] : [];
|
|
66
|
+
});
|
|
67
|
+
const childPaths = (frame) => (frame ? graph.getChildren(frame.id) : []).map((child) => layerPath(graph, rootId, child.id));
|
|
68
|
+
const panels = behaviour.kind === "tabs" ? childPaths(frameOf("panels")) : [];
|
|
69
|
+
const content = behaviour.kind === "collapsible" ? frameOf("content") : void 0;
|
|
70
|
+
return {
|
|
71
|
+
path,
|
|
72
|
+
kind: behaviour.kind,
|
|
73
|
+
behaviour,
|
|
74
|
+
booleans,
|
|
75
|
+
states: statesModel(graph, instance, owner, behaviour),
|
|
76
|
+
parts,
|
|
77
|
+
texts,
|
|
78
|
+
items,
|
|
79
|
+
reveal: content ? [layerPath(graph, rootId, content.id)] : panels,
|
|
80
|
+
panels,
|
|
81
|
+
triggers: behaviour.kind === "tabs" ? childPaths(frameOf("list")) : []
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The controls below a root layer, by layer path, outermost first. Items of a group are listed
|
|
86
|
+
* both in the group's `items` and on their own, since each keeps its own state. Preview runs
|
|
87
|
+
* them as live islands; export generates components from them.
|
|
88
|
+
*/
|
|
89
|
+
function behaviourControls(graph, rootId) {
|
|
90
|
+
const controls = /* @__PURE__ */ new Map();
|
|
91
|
+
const visit = (node) => {
|
|
92
|
+
if (hasBehaviour(graph, node)) {
|
|
93
|
+
const control = controlModel(graph, rootId, node);
|
|
94
|
+
if (control) controls.set(control.path, control);
|
|
95
|
+
}
|
|
96
|
+
for (const child of graph.getChildren(node.id)) visit(child);
|
|
97
|
+
};
|
|
98
|
+
const root = graph.getNode(rootId);
|
|
99
|
+
if (root) visit(root);
|
|
100
|
+
return controls;
|
|
101
|
+
}
|
|
102
|
+
/** A control's boolean value, if the behaviour binds it. */
|
|
103
|
+
function booleanOf(control, valueId) {
|
|
104
|
+
return Object.hasOwn(control.booleans, valueId) ? control.booleans[valueId] : void 0;
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { behaviourControls, booleanOf };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controls.js","names":[],"sources":["../../../src/behaviours/controls.ts"],"sourcesContent":["import type { ComponentPropertyDefinition, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n behaviourContract,\n behaviourOwner,\n behaviourProperties,\n booleanBinding,\n hasBehaviour,\n layerPath,\n partBinding,\n readBehaviour,\n textBinding,\n type Behaviour\n} from '@pairdraw/scene-graph/behaviours'\nimport { findComponentPropertyTargets } from '@pairdraw/scene-graph/components'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\nimport { instanceSlotFrames, slotPropertyId } from '@pairdraw/scene-graph/slots'\n\n/** A boolean value of a control and the property that draws it. */\nexport interface BooleanModel {\n definition: ComponentPropertyDefinition\n on?: string\n off?: string\n /** The value as the document's instance draws it. */\n designed: boolean\n}\n\n/** The variant property that draws a control's interaction states. */\nexport interface StatesModel {\n name: string\n values: NonNullable<Behaviour['states']>\n /** The value the instance shows at rest. */\n rest: string | undefined\n /** Whether the document's instance is drawn disabled. */\n designedDisabled: boolean\n}\n\n/** An instance with a behaviour below a root layer: its values, states, and bound layers. */\nexport interface ControlModel {\n /** The instance's layer path below the root. */\n path: string\n kind: Behaviour['kind']\n behaviour: Behaviour\n booleans: Record<string, BooleanModel>\n states: StatesModel | null\n /** Each bound part's slot frame, by part id, as a layer path below the root. */\n parts: Record<string, string>\n /** Each bound text value's text layer, by value id, as a layer path below the root. */\n texts: Record<string, { path: string; designed: string }>\n /** The children of the items slot that are controls themselves, in order. */\n items: ControlModel[]\n /**\n * Layers the control decides to show, which the design may hide: tab panels, or a\n * collapsible's content, as layer paths below the root.\n */\n reveal: string[]\n /** For tabs, each panel's layer path, in order. */\n panels: string[]\n /** For tabs, each trigger's layer path, in order. */\n triggers: string[]\n}\n\nfunction designedBoolean(\n graph: SceneGraph,\n instance: SceneNode,\n definition: ComponentPropertyDefinition,\n on: string | undefined\n): boolean {\n if (definition.type === 'BOOLEAN') {\n const assignments = instance.componentPropertyAssignments\n const value = Object.hasOwn(assignments, definition.id)\n ? assignments[definition.id]\n : definition.defaultValue\n return value === 'true'\n }\n return instanceMainComponent(graph, instance)?.componentPropertyValues[definition.name] === on\n}\n\nfunction statesModel(\n graph: SceneGraph,\n instance: SceneNode,\n owner: SceneNode,\n behaviour: Behaviour\n): StatesModel | null {\n const states = behaviour.states\n const definition = states\n ? behaviourProperties(graph, owner).find(\n (item) => item.id === states.propertyId && item.type === 'VARIANT'\n )\n : undefined\n if (!states || !definition) return null\n const authored = instanceMainComponent(graph, instance)?.componentPropertyValues[definition.name]\n return {\n name: definition.name,\n values: states,\n rest: states.rest ?? authored,\n designedDisabled: !!states.disabled && authored === states.disabled\n }\n}\n\nfunction controlModel(graph: SceneGraph, rootId: string, instance: SceneNode): ControlModel | null {\n const component = instanceMainComponent(graph, instance)\n const owner = component && behaviourOwner(graph, component)\n const behaviour = owner && readBehaviour(owner)\n if (!owner || !behaviour) return null\n const path = layerPath(graph, rootId, instance.id)\n const properties = behaviourProperties(graph, owner)\n const booleans: Record<string, BooleanModel> = {}\n for (const valueId of Object.keys(behaviour.booleans)) {\n const binding = booleanBinding(behaviour, valueId)\n const definition = properties.find((item) => item.id === binding?.propertyId)\n if (!binding || !definition) continue\n booleans[valueId] = {\n definition,\n on: binding.on,\n off: binding.off,\n designed: designedBoolean(graph, instance, definition, binding.on)\n }\n }\n const frames = instanceSlotFrames(graph, instance)\n const parts = Object.fromEntries(\n Object.entries(behaviour.parts).flatMap(([partId, propertyId]) => {\n const frame = frames.find((item) => slotPropertyId(item) === propertyId)\n return frame ? [[partId, layerPath(graph, rootId, frame.id)]] : []\n })\n )\n const texts = Object.fromEntries(\n Object.keys(behaviour.texts).flatMap((valueId) => {\n const propertyId = textBinding(behaviour, valueId)\n const target = propertyId\n ? findComponentPropertyTargets(graph, instance, propertyId).find(\n (item) => item.node.type === 'TEXT'\n )\n : undefined\n return target\n ? [\n [\n valueId,\n { path: layerPath(graph, rootId, target.node.id), designed: target.node.text }\n ]\n ]\n : []\n })\n )\n const frameOf = (partId: string) => {\n const propertyId = partBinding(behaviour, partId)\n return propertyId ? frames.find((item) => slotPropertyId(item) === propertyId) : undefined\n }\n const itemsPart = behaviourContract(behaviour.kind).parts.find((part) => part.items)\n const itemsFrame = itemsPart ? frameOf(itemsPart.id) : undefined\n const items = (itemsFrame ? graph.getChildren(itemsFrame.id) : []).flatMap((child) => {\n const item = controlModel(graph, rootId, child)\n return item ? [item] : []\n })\n const childPaths = (frame: SceneNode | undefined) =>\n (frame ? graph.getChildren(frame.id) : []).map((child) => layerPath(graph, rootId, child.id))\n const panels = behaviour.kind === 'tabs' ? childPaths(frameOf('panels')) : []\n const content = behaviour.kind === 'collapsible' ? frameOf('content') : undefined\n return {\n path,\n kind: behaviour.kind,\n behaviour,\n booleans,\n states: statesModel(graph, instance, owner, behaviour),\n parts,\n texts,\n items,\n reveal: content ? [layerPath(graph, rootId, content.id)] : panels,\n panels,\n triggers: behaviour.kind === 'tabs' ? childPaths(frameOf('list')) : []\n }\n}\n\n/**\n * The controls below a root layer, by layer path, outermost first. Items of a group are listed\n * both in the group's `items` and on their own, since each keeps its own state. Preview runs\n * them as live islands; export generates components from them.\n */\nexport function behaviourControls(graph: SceneGraph, rootId: string): Map<string, ControlModel> {\n const controls = new Map<string, ControlModel>()\n const visit = (node: SceneNode) => {\n if (hasBehaviour(graph, node)) {\n const control = controlModel(graph, rootId, node)\n if (control) controls.set(control.path, control)\n }\n for (const child of graph.getChildren(node.id)) visit(child)\n }\n const root = graph.getNode(rootId)\n if (root) visit(root)\n return controls\n}\n\n/** A control's boolean value, if the behaviour binds it. */\nexport function booleanOf(control: ControlModel, valueId: string): BooleanModel | undefined {\n return Object.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,IAAI,IAAI,CAAC;CAC1B,CAAC;CACD,MAAM,cAAc,WACjB,QAAQ,MAAM,YAAY,MAAM,EAAE,IAAI,CAAC,EAAA,CAAG,KAAK,UAAU,UAAU,OAAO,QAAQ,MAAM,EAAE,CAAC;CAC9F,MAAM,SAAS,UAAU,SAAS,SAAS,WAAW,QAAQ,QAAQ,CAAC,IAAI,CAAC;CAC5E,MAAM,UAAU,UAAU,SAAS,gBAAgB,QAAQ,SAAS,IAAI,KAAA;CACxE,OAAO;EACL;EACA,MAAM,UAAU;EAChB;EACA;EACA,QAAQ,YAAY,OAAO,UAAU,OAAO,SAAS;EACrD;EACA;EACA;EACA,QAAQ,UAAU,CAAC,UAAU,OAAO,QAAQ,QAAQ,EAAE,CAAC,IAAI;EAC3D;EACA,UAAU,UAAU,SAAS,SAAS,WAAW,QAAQ,MAAM,CAAC,IAAI,CAAC;CACvE;AACF;;;;;;AAOA,SAAgB,kBAAkB,OAAmB,QAA2C;CAC9F,MAAM,2BAAW,IAAI,IAA0B;CAC/C,MAAM,SAAS,SAAoB;EACjC,IAAI,aAAa,OAAO,IAAI,GAAG;GAC7B,MAAM,UAAU,aAAa,OAAO,QAAQ,IAAI;GAChD,IAAI,SAAS,SAAS,IAAI,QAAQ,MAAM,OAAO;EACjD;EACA,KAAK,MAAM,SAAS,MAAM,YAAY,KAAK,EAAE,GAAG,MAAM,KAAK;CAC7D;CACA,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,MAAM,MAAM,IAAI;CACpB,OAAO;AACT;;AAGA,SAAgB,UAAU,SAAuB,SAA2C;CAC1F,OAAO,OAAO,OAAO,QAAQ,UAAU,OAAO,IAAI,QAAQ,SAAS,WAAW,KAAA;AAChF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/behaviours/reset.ts
|
|
2
|
+
/**
|
|
3
|
+
* Element styles a native `<button>` adds, cleared so the design's own styles show. Preview
|
|
4
|
+
* and generated components render control roots and triggers as buttons for their semantics.
|
|
5
|
+
*/
|
|
6
|
+
const BUTTON_RESET = {
|
|
7
|
+
border: "none",
|
|
8
|
+
padding: "0",
|
|
9
|
+
margin: "0",
|
|
10
|
+
background: "none",
|
|
11
|
+
font: "inherit",
|
|
12
|
+
color: "inherit",
|
|
13
|
+
"text-align": "inherit",
|
|
14
|
+
cursor: "pointer"
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Element styles the heading around an accordion trigger adds, cleared so the trigger lays
|
|
18
|
+
* out as designed while the heading keeps its level.
|
|
19
|
+
*/
|
|
20
|
+
const HEADING_RESET = {
|
|
21
|
+
margin: "0",
|
|
22
|
+
font: "inherit"
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Element styles an input or textarea adds, cleared so the field's text layer it replaces
|
|
26
|
+
* keeps its look. Preview and generated components both draw a field's text as one.
|
|
27
|
+
*/
|
|
28
|
+
const INPUT_RESET = {
|
|
29
|
+
border: "none",
|
|
30
|
+
outline: "none",
|
|
31
|
+
padding: "0",
|
|
32
|
+
margin: "0",
|
|
33
|
+
background: "transparent",
|
|
34
|
+
resize: "none",
|
|
35
|
+
"box-sizing": "border-box"
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { BUTTON_RESET, HEADING_RESET, INPUT_RESET };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=reset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reset.js","names":[],"sources":["../../../src/behaviours/reset.ts"],"sourcesContent":["/**\n * Element styles a native `<button>` adds, cleared so the design's own styles show. Preview\n * and generated components render control roots and triggers as buttons for their semantics.\n */\nexport const BUTTON_RESET: Record<string, string> = {\n border: 'none',\n padding: '0',\n margin: '0',\n background: 'none',\n font: 'inherit',\n color: 'inherit',\n 'text-align': 'inherit',\n cursor: 'pointer'\n}\n\n/**\n * Element styles the heading around an accordion trigger adds, cleared so the trigger lays\n * out as designed while the heading keeps its level.\n */\nexport const HEADING_RESET: Record<string, string> = {\n margin: '0',\n font: 'inherit'\n}\n\n/**\n * Element styles an input or textarea adds, cleared so the field's text layer it replaces\n * keeps its look. Preview and generated components both draw a field's text as one.\n */\nexport const INPUT_RESET: Record<string, string> = {\n border: 'none',\n outline: 'none',\n padding: '0',\n margin: '0',\n background: 'transparent',\n resize: 'none',\n 'box-sizing': 'border-box'\n}\n"],"mappings":";;;;;AAIA,MAAa,eAAuC;CAClD,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,MAAM;CACN,OAAO;CACP,cAAc;CACd,QAAQ;AACV;;;;;AAMA,MAAa,gBAAwC;CACnD,QAAQ;CACR,MAAM;AACR;;;;;AAMA,MAAa,cAAsC;CACjD,QAAQ;CACR,SAAS;CACT,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,QAAQ;CACR,cAAc;AAChB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/behaviours/roles.ts
|
|
2
|
+
/**
|
|
3
|
+
* Each layer's role by layer path: control roots, their parts, items of groups, tab triggers
|
|
4
|
+
* and panels, and the text layers that become inputs. Items of a group take the item role in
|
|
5
|
+
* place of their root role, since the group drives them.
|
|
6
|
+
*/
|
|
7
|
+
function controlRoles(controls) {
|
|
8
|
+
const roles = /* @__PURE__ */ new Map();
|
|
9
|
+
for (const control of controls.values()) {
|
|
10
|
+
if (!roles.has(control.path)) roles.set(control.path, {
|
|
11
|
+
type: "root",
|
|
12
|
+
control
|
|
13
|
+
});
|
|
14
|
+
for (const [part, path] of Object.entries(control.parts)) if (!roles.has(path)) roles.set(path, {
|
|
15
|
+
type: "part",
|
|
16
|
+
control,
|
|
17
|
+
part
|
|
18
|
+
});
|
|
19
|
+
for (const [valueId, text] of Object.entries(control.texts)) roles.set(text.path, {
|
|
20
|
+
type: "text",
|
|
21
|
+
control,
|
|
22
|
+
valueId
|
|
23
|
+
});
|
|
24
|
+
for (const [index, path] of control.triggers.entries()) roles.set(path, {
|
|
25
|
+
type: "trigger",
|
|
26
|
+
control,
|
|
27
|
+
index
|
|
28
|
+
});
|
|
29
|
+
for (const [index, path] of control.panels.entries()) roles.set(path, {
|
|
30
|
+
type: "panel",
|
|
31
|
+
control,
|
|
32
|
+
index
|
|
33
|
+
});
|
|
34
|
+
for (const [index, item] of control.items.entries()) roles.set(item.path, {
|
|
35
|
+
type: "item",
|
|
36
|
+
group: control,
|
|
37
|
+
control: item,
|
|
38
|
+
index
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return roles;
|
|
42
|
+
}
|
|
43
|
+
/** The group a control is an item of, if any. */
|
|
44
|
+
function groupOf(roles, control) {
|
|
45
|
+
const role = roles.get(control.path);
|
|
46
|
+
return role?.type === "item" ? role.group : void 0;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { controlRoles, groupOf };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=roles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.js","names":[],"sources":["../../../src/behaviours/roles.ts"],"sourcesContent":["import type { ControlModel } from './controls'\n\n/** What a layer below a root is to the controls in it. */\nexport type ControlRole =\n | { type: 'root'; control: ControlModel }\n | { type: 'part'; control: ControlModel; part: string }\n | { type: 'item'; group: ControlModel; control: ControlModel; index: number }\n | { type: 'trigger'; control: ControlModel; index: number }\n | { type: 'panel'; control: ControlModel; index: number }\n | { type: 'text'; control: ControlModel; valueId: string }\n\n/**\n * Each layer's role by layer path: control roots, their parts, items of groups, tab triggers\n * and panels, and the text layers that become inputs. Items of a group take the item role in\n * place of their root role, since the group drives them.\n */\nexport function controlRoles(\n controls: ReadonlyMap<string, ControlModel>\n): Map<string, ControlRole> {\n const roles = new Map<string, ControlRole>()\n for (const control of controls.values()) {\n if (!roles.has(control.path)) roles.set(control.path, { type: 'root', control })\n for (const [part, path] of Object.entries(control.parts))\n if (!roles.has(path)) roles.set(path, { type: 'part', control, part })\n for (const [valueId, text] of Object.entries(control.texts))\n roles.set(text.path, { type: 'text', control, valueId })\n for (const [index, path] of control.triggers.entries())\n roles.set(path, { type: 'trigger', control, index })\n for (const [index, path] of control.panels.entries())\n roles.set(path, { type: 'panel', control, index })\n for (const [index, item] of control.items.entries())\n roles.set(item.path, { type: 'item', group: control, control: item, index })\n }\n return roles\n}\n\n/** The group a control is an item of, if any. */\nexport function groupOf(\n roles: ReadonlyMap<string, ControlRole>,\n control: ControlModel\n): ControlModel | undefined {\n const role = roles.get(control.path)\n return role?.type === 'item' ? role.group : undefined\n}\n"],"mappings":";;;;;;AAgBA,SAAgB,aACd,UAC0B;CAC1B,MAAM,wBAAQ,IAAI,IAAyB;CAC3C,KAAK,MAAM,WAAW,SAAS,OAAO,GAAG;EACvC,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,GAAG,MAAM,IAAI,QAAQ,MAAM;GAAE,MAAM;GAAQ;EAAQ,CAAC;EAC/E,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,QAAQ,KAAK,GACrD,IAAI,CAAC,MAAM,IAAI,IAAI,GAAG,MAAM,IAAI,MAAM;GAAE,MAAM;GAAQ;GAAS;EAAK,CAAC;EACvE,KAAK,MAAM,CAAC,SAAS,SAAS,OAAO,QAAQ,QAAQ,KAAK,GACxD,MAAM,IAAI,KAAK,MAAM;GAAE,MAAM;GAAQ;GAAS;EAAQ,CAAC;EACzD,KAAK,MAAM,CAAC,OAAO,SAAS,QAAQ,SAAS,QAAQ,GACnD,MAAM,IAAI,MAAM;GAAE,MAAM;GAAW;GAAS;EAAM,CAAC;EACrD,KAAK,MAAM,CAAC,OAAO,SAAS,QAAQ,OAAO,QAAQ,GACjD,MAAM,IAAI,MAAM;GAAE,MAAM;GAAS;GAAS;EAAM,CAAC;EACnD,KAAK,MAAM,CAAC,OAAO,SAAS,QAAQ,MAAM,QAAQ,GAChD,MAAM,IAAI,KAAK,MAAM;GAAE,MAAM;GAAQ,OAAO;GAAS,SAAS;GAAM;EAAM,CAAC;CAC/E;CACA,OAAO;AACT;;AAGA,SAAgB,QACd,OACA,SAC0B;CAC1B,MAAM,OAAO,MAAM,IAAI,QAAQ,IAAI;CACnC,OAAO,MAAM,SAAS,SAAS,KAAK,QAAQ,KAAA;AAC9C"}
|