@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
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { escapeAttribute, escapeText } from 'entities'
|
|
2
|
+
import { twirl } from 'twirlwind'
|
|
3
|
+
|
|
4
|
+
import type { DesignDocument, DesignElement, DesignNode, DesignText } from '../types'
|
|
5
|
+
|
|
6
|
+
export interface SerializeHTMLOptions {
|
|
7
|
+
style?: 'inline' | 'tailwind'
|
|
8
|
+
/** Custom properties declared in `@theme`; a `var()` naming one becomes its utility. */
|
|
9
|
+
themeVariables?: readonly string[]
|
|
10
|
+
/**
|
|
11
|
+
* Put each child of an element that holds only elements on its own indented line, for code
|
|
12
|
+
* people read. Text keeps its whitespace; whitespace between elements in a projected layer
|
|
13
|
+
* changes nothing, since its children are placed by flex, grid, or absolute position.
|
|
14
|
+
*/
|
|
15
|
+
indent?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const VOID_ELEMENTS = new Set([
|
|
19
|
+
'area',
|
|
20
|
+
'base',
|
|
21
|
+
'br',
|
|
22
|
+
'col',
|
|
23
|
+
'embed',
|
|
24
|
+
'hr',
|
|
25
|
+
'img',
|
|
26
|
+
'input',
|
|
27
|
+
'link',
|
|
28
|
+
'meta',
|
|
29
|
+
'param',
|
|
30
|
+
'source',
|
|
31
|
+
'track',
|
|
32
|
+
'wbr'
|
|
33
|
+
])
|
|
34
|
+
|
|
35
|
+
export function splitWhitespace(value: string): string[] {
|
|
36
|
+
const parts: string[] = []
|
|
37
|
+
let current = ''
|
|
38
|
+
for (const char of value) {
|
|
39
|
+
if (char === ' ' || char === '\n' || char === '\t' || char === '\r' || char === '\f') {
|
|
40
|
+
if (current.length > 0) parts.push(current)
|
|
41
|
+
current = ''
|
|
42
|
+
} else {
|
|
43
|
+
current += char
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (current.length > 0) parts.push(current)
|
|
47
|
+
return parts
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function serializeText(node: DesignText): string {
|
|
51
|
+
return escapeText(node.text)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function serializeStyle(node: DesignElement): string | undefined {
|
|
55
|
+
if (!node.inlineStyle || Object.keys(node.inlineStyle).length === 0) return undefined
|
|
56
|
+
return Object.entries(node.inlineStyle)
|
|
57
|
+
.filter(([, value]) => value !== '')
|
|
58
|
+
.map(([property, value]) => `${property}: ${value}`)
|
|
59
|
+
.join('; ')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function serializeTailwindClasses(
|
|
63
|
+
node: DesignElement,
|
|
64
|
+
themeVariables: readonly string[] = []
|
|
65
|
+
): string | undefined {
|
|
66
|
+
const style = serializeStyle(node)
|
|
67
|
+
if (!style) return undefined
|
|
68
|
+
const className = twirl(style, { theme: { variables: themeVariables } })
|
|
69
|
+
return className.length > 0 ? className : undefined
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function mergeClassNames(...values: Array<string | undefined>): string | undefined {
|
|
73
|
+
const className = values
|
|
74
|
+
.flatMap((value) => (value ? splitWhitespace(value) : []))
|
|
75
|
+
.map((value) => value.trim())
|
|
76
|
+
.filter((value) => value.length > 0)
|
|
77
|
+
.join(' ')
|
|
78
|
+
return className.length > 0 ? className : undefined
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function serializeAttrs(node: DesignElement, options: SerializeHTMLOptions): string {
|
|
82
|
+
const style = serializeStyle(node)
|
|
83
|
+
const tailwindClass =
|
|
84
|
+
options.style === 'tailwind'
|
|
85
|
+
? serializeTailwindClasses(node, options.themeVariables)
|
|
86
|
+
: undefined
|
|
87
|
+
const attrsWithoutStyle = { ...node.attrs }
|
|
88
|
+
delete attrsWithoutStyle.style
|
|
89
|
+
const sourceAttrs = options.style === 'tailwind' && tailwindClass ? attrsWithoutStyle : node.attrs
|
|
90
|
+
const attrs: Record<string, string | undefined> = { ...sourceAttrs }
|
|
91
|
+
if (tailwindClass) attrs.class = mergeClassNames(node.attrs.class, tailwindClass)
|
|
92
|
+
if (style && options.style !== 'tailwind') attrs.style = style
|
|
93
|
+
const serialized = Object.entries(attrs)
|
|
94
|
+
.filter((entry): entry is [string, string] => typeof entry[1] === 'string' && entry[1] !== '')
|
|
95
|
+
.map(([name, value]) => `${name}="${escapeAttribute(value)}"`)
|
|
96
|
+
|
|
97
|
+
if (serialized.length === 0) return ''
|
|
98
|
+
return ` ${serialized.join(' ')}`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Static HTML cannot play a shader, so its layer shows the still frame behind its content. */
|
|
102
|
+
const SHADER_FRAME_STYLE =
|
|
103
|
+
'position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:-1;border-radius:inherit;pointer-events:none'
|
|
104
|
+
|
|
105
|
+
function shaderFrame(node: DesignElement): string {
|
|
106
|
+
const frame = node.shader?.frame
|
|
107
|
+
return frame ? `<img src="${escapeAttribute(frame)}" alt="" style="${SHADER_FRAME_STYLE}">` : ''
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function serializeElement(
|
|
111
|
+
node: DesignElement,
|
|
112
|
+
options: SerializeHTMLOptions,
|
|
113
|
+
depth: number
|
|
114
|
+
): string {
|
|
115
|
+
// SVG names such as `linearGradient` keep their case, as an SVG parser needs them.
|
|
116
|
+
const tagName = node.tagName
|
|
117
|
+
const attrs = serializeAttrs(node, options)
|
|
118
|
+
if (VOID_ELEMENTS.has(tagName.toLowerCase())) return `<${tagName}${attrs}>`
|
|
119
|
+
const children = [
|
|
120
|
+
shaderFrame(node),
|
|
121
|
+
...node.children.map((child) => serializeNode(child, options, depth + 1))
|
|
122
|
+
].filter((child) => child !== '')
|
|
123
|
+
const block =
|
|
124
|
+
options.indent && children.length > 0 && node.children.every((child) => child.type !== 'text')
|
|
125
|
+
if (!block) return `<${tagName}${attrs}>${children.join('')}</${tagName}>`
|
|
126
|
+
const inner = ' '.repeat(depth + 1)
|
|
127
|
+
const outer = ' '.repeat(depth)
|
|
128
|
+
return `<${tagName}${attrs}>\n${children.map((child) => inner + child).join('\n')}\n${outer}</${tagName}>`
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function serializeNode(
|
|
132
|
+
node: DesignNode,
|
|
133
|
+
options: SerializeHTMLOptions = {},
|
|
134
|
+
depth = 0
|
|
135
|
+
): string {
|
|
136
|
+
return node.type === 'text' ? serializeText(node) : serializeElement(node, options, depth)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The elements `serializeHTML` writes, in the order they open: the document's own, and `null`
|
|
141
|
+
* for a shader's still frame, which it adds in front of its layer's content.
|
|
142
|
+
*/
|
|
143
|
+
export function serializedElements(document: DesignDocument): (DesignElement | null)[] {
|
|
144
|
+
const visit = (node: DesignNode): (DesignElement | null)[] => {
|
|
145
|
+
if (node.type === 'text') return []
|
|
146
|
+
if (VOID_ELEMENTS.has(node.tagName.toLowerCase())) return [node]
|
|
147
|
+
return [node, ...(node.shader?.frame ? [null] : []), ...node.children.flatMap(visit)]
|
|
148
|
+
}
|
|
149
|
+
return document.children.flatMap(visit)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function serializeHTML(
|
|
153
|
+
document: DesignDocument,
|
|
154
|
+
options: SerializeHTMLOptions = {}
|
|
155
|
+
): string {
|
|
156
|
+
const resolved: SerializeHTMLOptions = {
|
|
157
|
+
...options,
|
|
158
|
+
themeVariables: options.themeVariables ?? document.tokens?.themeVariables()
|
|
159
|
+
}
|
|
160
|
+
return document.children
|
|
161
|
+
.map((node) => serializeNode(node, resolved))
|
|
162
|
+
.join(options.indent ? '\n' : '')
|
|
163
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// SceneGraph → HTML and JSX without the CSS runtimes, so browsers can bundle it.
|
|
2
|
+
export {
|
|
3
|
+
sceneGraphToDesignDocument,
|
|
4
|
+
sceneNodeToDesignDocument,
|
|
5
|
+
type SceneGraphToDesignOptions,
|
|
6
|
+
type VectorElementRenderer
|
|
7
|
+
} from './projection'
|
|
8
|
+
export { exportHTMLBundle } from './bundle'
|
|
9
|
+
export {
|
|
10
|
+
designDocumentToTailwindJSX,
|
|
11
|
+
sceneNodesToTailwindJSX,
|
|
12
|
+
sceneNodesToTailwindJSXWithLayers,
|
|
13
|
+
type TailwindJSXWithLayers
|
|
14
|
+
} from './tailwind-jsx'
|
|
15
|
+
export { serializeHTML } from './html'
|
|
16
|
+
export {
|
|
17
|
+
LAYER_COMPONENT_FRAMEWORKS,
|
|
18
|
+
layerComponents,
|
|
19
|
+
layerMarkup,
|
|
20
|
+
type LayerComponent,
|
|
21
|
+
type LayerComponentFramework,
|
|
22
|
+
type LayerMarkup
|
|
23
|
+
} from './components/layers'
|
|
24
|
+
export { COMPONENT_STYLINGS, type ComponentStyling } from './components/styling'
|
|
25
|
+
export {
|
|
26
|
+
ICON_PACKAGES,
|
|
27
|
+
iconPackagesFor,
|
|
28
|
+
isIconPackage,
|
|
29
|
+
type IconFramework,
|
|
30
|
+
type IconPackage
|
|
31
|
+
} from './components/icons'
|
|
32
|
+
export * from '../tokens'
|
|
33
|
+
export * from '../behaviours'
|
|
34
|
+
export type {
|
|
35
|
+
ExportHTMLBundle,
|
|
36
|
+
ExportHTMLBundleOptions,
|
|
37
|
+
ExportHTMLFile,
|
|
38
|
+
TailwindStylesheetId,
|
|
39
|
+
TailwindStylesheetLoader,
|
|
40
|
+
WebFontFaceAsset,
|
|
41
|
+
WebFontFaceRequest,
|
|
42
|
+
WebFontFaceResolver
|
|
43
|
+
} from './bundle'
|
|
44
|
+
export type { DesignDocument, DesignElement, DesignNode } from '../types'
|