@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +2 -5
- package/dist/arrow-caps.js.map +1 -1
- package/dist/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/kinds.d.ts +11 -5
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +76 -75
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/layers.d.ts.map +1 -1
- package/dist/behaviours/layers.js +3 -2
- package/dist/behaviours/layers.js.map +1 -1
- package/dist/behaviours/model.d.ts +7 -4
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js +16 -9
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +118 -4
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +18 -3
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +3 -2
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/bindings.js +9 -1
- package/dist/bindings.js.map +1 -1
- package/dist/checkpoint.d.ts +31 -2
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +176 -5
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +3 -3
- package/dist/components/properties.d.ts +13 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +58 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +16 -10
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +39 -13
- package/dist/components/variants.js.map +1 -1
- package/dist/connectors/hit.d.ts.map +1 -1
- package/dist/connectors/hit.js +1 -7
- package/dist/connectors/hit.js.map +1 -1
- package/dist/connectors/pieces.d.ts.map +1 -1
- package/dist/connectors/pieces.js +2 -5
- package/dist/connectors/pieces.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +9 -15
- package/dist/copy.js.map +1 -1
- package/dist/css/blend.d.ts +11 -0
- package/dist/css/blend.d.ts.map +1 -0
- package/dist/css/blend.js +30 -0
- package/dist/css/blend.js.map +1 -0
- package/dist/css/index.d.ts +2 -1
- package/dist/css/index.js +2 -1
- package/dist/cubic.d.ts +7 -0
- package/dist/cubic.d.ts.map +1 -0
- package/dist/cubic.js +17 -0
- package/dist/cubic.js.map +1 -0
- package/dist/export-format.d.ts +14 -1
- package/dist/export-format.d.ts.map +1 -1
- package/dist/export-format.js +26 -1
- package/dist/export-format.js.map +1 -1
- package/dist/fields/text.d.ts +2 -2
- package/dist/fields/text.d.ts.map +1 -1
- package/dist/fields/text.js +2 -1
- package/dist/fields/text.js.map +1 -1
- package/dist/figjam/index.d.ts +2 -2
- package/dist/figjam/index.js +2 -2
- package/dist/figjam/palette.d.ts +13 -2
- package/dist/figjam/palette.d.ts.map +1 -1
- package/dist/figjam/palette.js +30 -2
- package/dist/figjam/palette.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/geometry.d.ts +30 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +63 -131
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +1 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +15 -3
- package/dist/graph.js.map +1 -1
- package/dist/guides.d.ts +3 -1
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +5 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +42 -29
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +8 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +1 -3
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +36 -30
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +3 -1
- package/dist/instances/main-component.d.ts.map +1 -1
- package/dist/instances/main-component.js +10 -2
- package/dist/instances/main-component.js.map +1 -1
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +18 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/swap.js +288 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +84 -32
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +1 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/outline/flatten.d.ts +15 -0
- package/dist/outline/flatten.d.ts.map +1 -0
- package/dist/outline/flatten.js +189 -0
- package/dist/outline/flatten.js.map +1 -0
- package/dist/outline/heads.js +34 -0
- package/dist/outline/heads.js.map +1 -0
- package/dist/outline/hit.d.ts +21 -0
- package/dist/outline/hit.d.ts.map +1 -0
- package/dist/outline/hit.js +276 -0
- package/dist/outline/hit.js.map +1 -0
- package/dist/outline/index.d.ts +5 -0
- package/dist/outline/index.js +5 -0
- package/dist/outline/point.d.ts +16 -0
- package/dist/outline/point.d.ts.map +1 -0
- package/dist/outline/point.js +42 -0
- package/dist/outline/point.js.map +1 -0
- package/dist/outline/shapes.d.ts +35 -0
- package/dist/outline/shapes.d.ts.map +1 -0
- package/dist/outline/shapes.js +181 -0
- package/dist/outline/shapes.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +2 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +19 -4
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/scaling/tree.js +1 -1
- package/dist/shared-styles.d.ts +14 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +63 -2
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +2 -0
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/frames.d.ts +2 -0
- package/dist/slots/frames.d.ts.map +1 -1
- package/dist/slots/frames.js +7 -2
- package/dist/slots/frames.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +2 -2
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/picture.d.ts +1 -2
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +1 -4
- package/dist/text/picture.js.map +1 -1
- package/dist/transfer/index.js +1 -1
- package/dist/transfer/nodes.js +9 -5
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +27 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +28 -5
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +104 -14
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +19 -1
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +36 -1
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/index.d.ts +3 -3
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +23 -8
- package/dist/variables/index.js.map +1 -1
- package/package.json +7 -1
- package/src/arrow-caps.ts +2 -5
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +4 -2
- package/src/behaviours/model.ts +22 -11
- package/src/behaviours/schema.ts +20 -4
- package/src/behaviours/spec.ts +8 -2
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +251 -4
- package/src/components/properties.ts +92 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/copy.ts +9 -15
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +1 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +29 -0
- package/src/fields/text.ts +3 -1
- package/src/figjam/palette.ts +29 -1
- package/src/generated/shape-with-text.ts +28 -2
- package/src/geometry.ts +78 -198
- package/src/graph.ts +27 -3
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +67 -54
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +58 -31
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +12 -0
- package/src/instances/overrides.ts +27 -1
- package/src/instances/swap.ts +451 -0
- package/src/instances/sync.ts +141 -42
- package/src/node-defaults.ts +2 -1
- package/src/outline/flatten.ts +190 -0
- package/src/outline/heads.ts +52 -0
- package/src/outline/hit.ts +369 -0
- package/src/outline/index.ts +4 -0
- package/src/outline/point.ts +59 -0
- package/src/outline/shapes.ts +207 -0
- package/src/plugin-data/fields.ts +15 -2
- package/src/shared-styles.ts +82 -1
- package/src/slots/content.ts +2 -0
- package/src/slots/frames.ts +9 -7
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- package/src/transfer/nodes.ts +7 -5
- package/src/types.ts +28 -0
- package/src/variables/bindings.ts +125 -14
- package/src/variables/fields.ts +46 -1
- package/src/variables/index.ts +35 -2
package/src/arrow-caps.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cubicPoint } from './cubic'
|
|
1
2
|
import type { Vector } from './primitives'
|
|
2
3
|
import type { Stroke, StrokeCap, VectorNetwork } from './types'
|
|
3
4
|
|
|
@@ -256,11 +257,7 @@ export function trimArrowShafts(
|
|
|
256
257
|
type Cubic = [Vector, Vector, Vector, Vector]
|
|
257
258
|
|
|
258
259
|
function cubicAt([a, b, c, d]: Cubic, t: number): Vector {
|
|
259
|
-
|
|
260
|
-
return {
|
|
261
|
-
x: u * u * u * a.x + 3 * u * u * t * b.x + 3 * u * t * t * c.x + t * t * t * d.x,
|
|
262
|
-
y: u * u * u * a.y + 3 * u * u * t * b.y + 3 * u * t * t * c.y + t * t * t * d.y
|
|
263
|
-
}
|
|
260
|
+
return cubicPoint(a, b, c, d, t)
|
|
264
261
|
}
|
|
265
262
|
|
|
266
263
|
function lerp(a: Vector, b: Vector, t: number): Vector {
|
package/src/behaviours/kinds.ts
CHANGED
|
@@ -13,6 +13,7 @@ export const BEHAVIOUR_KINDS = [
|
|
|
13
13
|
'slider',
|
|
14
14
|
'progress',
|
|
15
15
|
'tabs',
|
|
16
|
+
'tab',
|
|
16
17
|
'collapsible',
|
|
17
18
|
'accordion'
|
|
18
19
|
] as const
|
|
@@ -21,9 +22,17 @@ export type BehaviourKind = (typeof BEHAVIOUR_KINDS)[number]
|
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* The interaction states a control can show, each drawn as a value of one variant property:
|
|
24
|
-
* at rest, under the pointer, while pressed, focused from the keyboard, and
|
|
25
|
+
* at rest, under the pointer, while pressed, focused from the keyboard, disabled, and invalid. Only
|
|
26
|
+
* a form control has an invalid state (`hasInvalidState`), shown while its value fails validation.
|
|
25
27
|
*/
|
|
26
|
-
export const INTERACTION_STATES = [
|
|
28
|
+
export const INTERACTION_STATES = [
|
|
29
|
+
'rest',
|
|
30
|
+
'hover',
|
|
31
|
+
'pressed',
|
|
32
|
+
'focus',
|
|
33
|
+
'disabled',
|
|
34
|
+
'invalid'
|
|
35
|
+
] as const
|
|
27
36
|
|
|
28
37
|
export type InteractionState = (typeof INTERACTION_STATES)[number]
|
|
29
38
|
|
|
@@ -52,7 +61,8 @@ export interface BehaviourPartContract {
|
|
|
52
61
|
required: boolean
|
|
53
62
|
/**
|
|
54
63
|
* Whether the slot holds the control's items, each an instance with its own behaviour (a
|
|
55
|
-
* radio, a toggle, a collapsible), which the control turns on and off.
|
|
64
|
+
* radio, a toggle, a collapsible, a tab), which the control turns on and off. A tab list's
|
|
65
|
+
* triggers may also be plain layers, which have no state of their own.
|
|
56
66
|
*/
|
|
57
67
|
items?: boolean
|
|
58
68
|
/**
|
|
@@ -67,6 +77,11 @@ export interface BehaviourContract {
|
|
|
67
77
|
parts: BehaviourPartContract[]
|
|
68
78
|
}
|
|
69
79
|
|
|
80
|
+
const DISABLED: BehaviourValueContract = { id: 'disabled', type: 'boolean', required: false }
|
|
81
|
+
|
|
82
|
+
/** Whether a form control's value fails validation, which code marks with `aria-invalid`. */
|
|
83
|
+
const INVALID: BehaviourValueContract = { id: 'invalid', type: 'boolean', required: false }
|
|
84
|
+
|
|
70
85
|
/**
|
|
71
86
|
* A text field or textarea: its text is a text property, and `filled`, when bound, draws the
|
|
72
87
|
* empty field with its placeholder.
|
|
@@ -75,7 +90,8 @@ const TEXT_INPUT: BehaviourContract = {
|
|
|
75
90
|
values: [
|
|
76
91
|
{ id: 'value', type: 'text', required: true },
|
|
77
92
|
{ id: 'filled', type: 'boolean', required: false },
|
|
78
|
-
|
|
93
|
+
DISABLED,
|
|
94
|
+
INVALID
|
|
79
95
|
],
|
|
80
96
|
parts: []
|
|
81
97
|
}
|
|
@@ -87,7 +103,7 @@ const TEXT_INPUT: BehaviourContract = {
|
|
|
87
103
|
*/
|
|
88
104
|
export const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContract>> = {
|
|
89
105
|
button: {
|
|
90
|
-
values: [
|
|
106
|
+
values: [DISABLED],
|
|
91
107
|
parts: []
|
|
92
108
|
},
|
|
93
109
|
textField: TEXT_INPUT,
|
|
@@ -96,7 +112,8 @@ export const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContra
|
|
|
96
112
|
values: [
|
|
97
113
|
{ id: 'value', type: 'number', required: false },
|
|
98
114
|
{ id: 'text', type: 'text', required: true },
|
|
99
|
-
|
|
115
|
+
DISABLED,
|
|
116
|
+
INVALID
|
|
100
117
|
],
|
|
101
118
|
parts: [
|
|
102
119
|
{ id: 'increment', required: false },
|
|
@@ -104,46 +121,31 @@ export const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContra
|
|
|
104
121
|
]
|
|
105
122
|
},
|
|
106
123
|
toggle: {
|
|
107
|
-
values: [
|
|
108
|
-
{ id: 'value', type: 'boolean', required: true },
|
|
109
|
-
{ id: 'disabled', type: 'boolean', required: false }
|
|
110
|
-
],
|
|
124
|
+
values: [{ id: 'value', type: 'boolean', required: true }, DISABLED],
|
|
111
125
|
parts: []
|
|
112
126
|
},
|
|
113
127
|
switch: {
|
|
114
|
-
values: [
|
|
115
|
-
{ id: 'value', type: 'boolean', required: true },
|
|
116
|
-
{ id: 'disabled', type: 'boolean', required: false }
|
|
117
|
-
],
|
|
128
|
+
values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],
|
|
118
129
|
parts: [{ id: 'thumb', required: false }]
|
|
119
130
|
},
|
|
120
131
|
checkbox: {
|
|
121
|
-
values: [
|
|
122
|
-
{ id: 'value', type: 'boolean', required: true },
|
|
123
|
-
{ id: 'disabled', type: 'boolean', required: false }
|
|
124
|
-
],
|
|
132
|
+
values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],
|
|
125
133
|
parts: [{ id: 'indicator', required: false }]
|
|
126
134
|
},
|
|
127
135
|
radio: {
|
|
128
|
-
values: [
|
|
129
|
-
{ id: 'value', type: 'boolean', required: true },
|
|
130
|
-
{ id: 'disabled', type: 'boolean', required: false }
|
|
131
|
-
],
|
|
136
|
+
values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],
|
|
132
137
|
parts: [{ id: 'indicator', required: false }]
|
|
133
138
|
},
|
|
134
139
|
radioGroup: {
|
|
135
|
-
values: [
|
|
140
|
+
values: [DISABLED, INVALID],
|
|
136
141
|
parts: [{ id: 'items', required: true, items: true, children: 'item' }]
|
|
137
142
|
},
|
|
138
143
|
toggleGroup: {
|
|
139
|
-
values: [
|
|
144
|
+
values: [DISABLED],
|
|
140
145
|
parts: [{ id: 'items', required: true, items: true, children: 'item' }]
|
|
141
146
|
},
|
|
142
147
|
slider: {
|
|
143
|
-
values: [
|
|
144
|
-
{ id: 'value', type: 'number', required: false },
|
|
145
|
-
{ id: 'disabled', type: 'boolean', required: false }
|
|
146
|
-
],
|
|
148
|
+
values: [{ id: 'value', type: 'number', required: false }, DISABLED],
|
|
147
149
|
parts: [
|
|
148
150
|
{ id: 'track', required: true },
|
|
149
151
|
{ id: 'range', required: false },
|
|
@@ -153,10 +155,18 @@ export const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContra
|
|
|
153
155
|
tabs: {
|
|
154
156
|
values: [{ id: 'value', type: 'choice', required: false }],
|
|
155
157
|
parts: [
|
|
156
|
-
{ id: 'list', required: true, children: 'trigger' },
|
|
158
|
+
{ id: 'list', required: true, items: true, children: 'trigger' },
|
|
157
159
|
{ id: 'panels', required: false, children: 'content' }
|
|
158
160
|
]
|
|
159
161
|
},
|
|
162
|
+
// A tab list's trigger, after Reka's TabsTrigger: on while its tab is the chosen one.
|
|
163
|
+
tab: {
|
|
164
|
+
values: [
|
|
165
|
+
{ id: 'value', type: 'boolean', required: true },
|
|
166
|
+
{ id: 'disabled', type: 'boolean', required: false }
|
|
167
|
+
],
|
|
168
|
+
parts: []
|
|
169
|
+
},
|
|
160
170
|
progress: {
|
|
161
171
|
values: [{ id: 'value', type: 'number', required: false }],
|
|
162
172
|
parts: [
|
|
@@ -165,17 +175,14 @@ export const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContra
|
|
|
165
175
|
]
|
|
166
176
|
},
|
|
167
177
|
collapsible: {
|
|
168
|
-
values: [
|
|
169
|
-
{ id: 'open', type: 'boolean', required: false },
|
|
170
|
-
{ id: 'disabled', type: 'boolean', required: false }
|
|
171
|
-
],
|
|
178
|
+
values: [{ id: 'open', type: 'boolean', required: false }, DISABLED],
|
|
172
179
|
parts: [
|
|
173
180
|
{ id: 'trigger', required: true },
|
|
174
181
|
{ id: 'content', required: true }
|
|
175
182
|
]
|
|
176
183
|
},
|
|
177
184
|
accordion: {
|
|
178
|
-
values: [
|
|
185
|
+
values: [DISABLED],
|
|
179
186
|
parts: [{ id: 'items', required: true, items: true, children: 'item' }]
|
|
180
187
|
}
|
|
181
188
|
}
|
|
@@ -183,3 +190,13 @@ export const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContra
|
|
|
183
190
|
export function behaviourContract(kind: BehaviourKind): BehaviourContract {
|
|
184
191
|
return BEHAVIOUR_CONTRACTS[kind]
|
|
185
192
|
}
|
|
193
|
+
|
|
194
|
+
/** Whether a kind of control can be invalid: a form control, whose contract has `invalid`. */
|
|
195
|
+
export function hasInvalidState(kind: BehaviourKind): boolean {
|
|
196
|
+
return BEHAVIOUR_CONTRACTS[kind].values.some((value) => value.id === 'invalid')
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The interaction states a kind of control can show. */
|
|
200
|
+
export function interactionStatesOf(kind: BehaviourKind): InteractionState[] {
|
|
201
|
+
return INTERACTION_STATES.filter((state) => state !== 'invalid' || hasInvalidState(kind))
|
|
202
|
+
}
|
package/src/behaviours/layers.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { SceneGraph } from '../graph'
|
|
2
|
+
import { instanceMainComponent } from '../instances/main-component'
|
|
2
3
|
import type { SceneNode } from '../types'
|
|
3
4
|
import { behaviourOwner, readBehaviour } from './model'
|
|
4
5
|
|
|
5
6
|
/** Whether an instance's main component, or its set, has a behaviour. */
|
|
6
7
|
export function hasBehaviour(graph: SceneGraph, node: SceneNode): boolean {
|
|
7
|
-
if (node.type !== 'INSTANCE'
|
|
8
|
-
|
|
8
|
+
if (node.type !== 'INSTANCE') return false
|
|
9
|
+
// A copy of a nested instance names the instance it copies, so follow it to the component.
|
|
10
|
+
const component = instanceMainComponent(graph, node)
|
|
9
11
|
const owner = component && behaviourOwner(graph, component)
|
|
10
12
|
return !!owner && !!readBehaviour(owner)
|
|
11
13
|
}
|
package/src/behaviours/model.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { mapValues } from 'es-toolkit'
|
|
2
2
|
|
|
3
|
+
import { resolvedVariantDefinition } from '../components/variants'
|
|
3
4
|
import type { SceneGraph } from '../graph'
|
|
4
5
|
import { readPluginData, withPluginData } from '../plugin-data/field'
|
|
5
6
|
import { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'
|
|
6
7
|
import type { ComponentPropertyDefinition, SceneNode } from '../types'
|
|
7
8
|
import {
|
|
8
9
|
behaviourContract,
|
|
9
|
-
|
|
10
|
+
interactionStatesOf,
|
|
10
11
|
type BehaviourKind,
|
|
11
12
|
type InteractionState
|
|
12
13
|
} from './kinds'
|
|
@@ -85,17 +86,25 @@ export function withBehaviour(
|
|
|
85
86
|
return withPluginData(owner.pluginData, OPEN_PENCIL_PLUGIN_DATA.behaviour, behaviour ?? undefined)
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* Component properties the behaviour can bind to: the owner's, with a set's variant values and
|
|
91
|
+
* defaults read from its variants, and a set's variants' own.
|
|
92
|
+
*/
|
|
89
93
|
export function behaviourProperties(
|
|
90
94
|
graph: SceneGraph,
|
|
91
95
|
owner: SceneNode
|
|
92
96
|
): ComponentPropertyDefinition[] {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
const isSet = owner.type === 'COMPONENT_SET'
|
|
98
|
+
const own = isSet
|
|
99
|
+
? owner.componentPropertyDefinitions.map((definition) =>
|
|
100
|
+
resolvedVariantDefinition(graph, owner, definition)
|
|
101
|
+
)
|
|
102
|
+
: owner.componentPropertyDefinitions
|
|
103
|
+
const variants = isSet
|
|
104
|
+
? owner.childIds.flatMap((id) => graph.getNode(id)?.componentPropertyDefinitions ?? [])
|
|
105
|
+
: []
|
|
97
106
|
const seen = new Set<string>()
|
|
98
|
-
return [...
|
|
107
|
+
return [...own, ...variants].filter((definition) => {
|
|
99
108
|
if (seen.has(definition.id)) return false
|
|
100
109
|
seen.add(definition.id)
|
|
101
110
|
return true
|
|
@@ -142,19 +151,21 @@ const STATE_NAMES: Record<InteractionState, readonly string[]> = {
|
|
|
142
151
|
hover: ['hover', 'hovered', 'hovering'],
|
|
143
152
|
pressed: ['pressed', 'active', 'down', 'pressing'],
|
|
144
153
|
focus: ['focus', 'focused', 'focus visible', 'focus-visible'],
|
|
145
|
-
disabled: ['disabled', 'inactive']
|
|
154
|
+
disabled: ['disabled', 'inactive'],
|
|
155
|
+
invalid: ['invalid', 'error']
|
|
146
156
|
}
|
|
147
157
|
|
|
148
158
|
/**
|
|
149
|
-
*
|
|
150
|
-
* as `Hover` or `Pressed`; states without such a value are left unset.
|
|
159
|
+
* A kind of control's interaction states for a variant property, each mapped to the value whose
|
|
160
|
+
* name means it, such as `Hover` or `Pressed`; states without such a value are left unset.
|
|
151
161
|
*/
|
|
152
162
|
export function guessInteractionStates(
|
|
163
|
+
kind: BehaviourKind,
|
|
153
164
|
propertyId: string,
|
|
154
165
|
values: readonly string[]
|
|
155
166
|
): BehaviourInteractionStates {
|
|
156
167
|
const states: BehaviourInteractionStates = { propertyId }
|
|
157
|
-
for (const state of
|
|
168
|
+
for (const state of interactionStatesOf(kind)) {
|
|
158
169
|
const match = values.find((value) => STATE_NAMES[state].includes(value.trim().toLowerCase()))
|
|
159
170
|
if (match) states[state] = match
|
|
160
171
|
}
|
package/src/behaviours/schema.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as v from 'valibot'
|
|
2
2
|
|
|
3
|
-
import { BEHAVIOUR_KINDS, type InteractionState } from './kinds'
|
|
3
|
+
import { BEHAVIOUR_KINDS, hasInvalidState, type InteractionState } from './kinds'
|
|
4
4
|
|
|
5
5
|
const booleanBindingSchema = v.object({
|
|
6
6
|
propertyId: v.string(),
|
|
@@ -33,12 +33,13 @@ export const interactionStateValues = {
|
|
|
33
33
|
hover: v.optional(v.string()),
|
|
34
34
|
pressed: v.optional(v.string()),
|
|
35
35
|
focus: v.optional(v.string()),
|
|
36
|
-
disabled: v.optional(v.string())
|
|
36
|
+
disabled: v.optional(v.string()),
|
|
37
|
+
invalid: v.optional(v.string())
|
|
37
38
|
} satisfies Record<InteractionState, unknown>
|
|
38
39
|
|
|
39
40
|
const interactionStatesSchema = v.object({ propertyId: v.string(), ...interactionStateValues })
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
const storedBehaviourSchema = v.object({
|
|
42
43
|
kind: v.picklist(BEHAVIOUR_KINDS),
|
|
43
44
|
/** Boolean values, by value id, bound to component properties. */
|
|
44
45
|
booleans: v.record(v.string(), booleanBindingSchema),
|
|
@@ -51,8 +52,23 @@ export const behaviourSchema = v.object({
|
|
|
51
52
|
states: v.optional(interactionStatesSchema)
|
|
52
53
|
})
|
|
53
54
|
|
|
55
|
+
type StoredBehaviour = v.InferOutput<typeof storedBehaviourSchema>
|
|
56
|
+
|
|
57
|
+
/** The behaviour without an invalid state when its kind of control has none. */
|
|
58
|
+
function withoutUnsupportedStates(behaviour: StoredBehaviour): StoredBehaviour {
|
|
59
|
+
if (behaviour.states?.invalid === undefined || hasInvalidState(behaviour.kind)) return behaviour
|
|
60
|
+
const { invalid: _invalid, ...states } = behaviour.states
|
|
61
|
+
return { ...behaviour, states }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A stored behaviour. An invalid state on a kind of control that has none, such as a button,
|
|
66
|
+
* is dropped as it is read, so nothing draws or exports it; the rest of the behaviour stays.
|
|
67
|
+
*/
|
|
68
|
+
export const behaviourSchema = v.pipe(storedBehaviourSchema, v.transform(withoutUnsupportedStates))
|
|
69
|
+
|
|
54
70
|
/** How a main component behaves as a control, as kept in its plugin data. */
|
|
55
|
-
export type Behaviour =
|
|
71
|
+
export type Behaviour = StoredBehaviour
|
|
56
72
|
export type BehaviourBooleanBinding = v.InferOutput<typeof booleanBindingSchema>
|
|
57
73
|
export type BehaviourNumberSettings = v.InferOutput<typeof numberSettingsSchema>
|
|
58
74
|
export type BehaviourInteractionStates = v.InferOutput<typeof interactionStatesSchema>
|
package/src/behaviours/spec.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { omitBy } from 'es-toolkit/object'
|
|
|
2
2
|
|
|
3
3
|
import type { SceneGraph } from '../graph'
|
|
4
4
|
import type { ComponentPropertyDefinition, SceneNode } from '../types'
|
|
5
|
-
import { behaviourContract } from './kinds'
|
|
5
|
+
import { behaviourContract, hasInvalidState } from './kinds'
|
|
6
6
|
import { behaviourProperties, emptyBehaviour, guessInteractionStates, textBinding } from './model'
|
|
7
7
|
import { isNumberRange, type Behaviour, type BehaviourSpec } from './schema'
|
|
8
8
|
|
|
@@ -90,12 +90,18 @@ function resolveStates(
|
|
|
90
90
|
): void {
|
|
91
91
|
const name = typeof states === 'string' ? states : states.property
|
|
92
92
|
const definition = findProperty(properties, name, ['VARIANT'], 'states')
|
|
93
|
-
const guessed = guessInteractionStates(
|
|
93
|
+
const guessed = guessInteractionStates(
|
|
94
|
+
behaviour.kind,
|
|
95
|
+
definition.id,
|
|
96
|
+
definition.variantOptions ?? []
|
|
97
|
+
)
|
|
94
98
|
if (typeof states === 'string') {
|
|
95
99
|
behaviour.states = guessed
|
|
96
100
|
return
|
|
97
101
|
}
|
|
98
102
|
const { property: _property, ...values } = states
|
|
103
|
+
if (values.invalid !== undefined && !hasInvalidState(behaviour.kind))
|
|
104
|
+
throw new Error(`A ${behaviour.kind} has no invalid state`)
|
|
99
105
|
behaviour.states = { ...guessed, ...stripUndefined(values) }
|
|
100
106
|
}
|
|
101
107
|
|
package/src/bindings.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { omit } from 'es-toolkit/object'
|
|
2
2
|
|
|
3
3
|
import type { SceneNode } from './types'
|
|
4
|
+
import { effectBindableProperties, effectBindingTarget } from './variables/fields'
|
|
5
|
+
|
|
6
|
+
/** Whether an effect binding names a property its effect still has: a blur binds only radius. */
|
|
7
|
+
function bindsEffectProperty(node: SceneNode, key: string): boolean {
|
|
8
|
+
const target = effectBindingTarget(key)
|
|
9
|
+
const effect = target && node.effects.at(target.index)
|
|
10
|
+
return !effect || effectBindableProperties(effect.type).includes(target.property)
|
|
11
|
+
}
|
|
4
12
|
|
|
5
13
|
export function removeStaleBindings(
|
|
6
14
|
node: SceneNode,
|
|
7
|
-
field: 'fills' | 'strokes',
|
|
15
|
+
field: 'fills' | 'strokes' | 'effects',
|
|
8
16
|
changes: Partial<SceneNode>
|
|
9
17
|
): void {
|
|
10
18
|
const length = node[field].length
|
|
@@ -12,7 +20,8 @@ export function removeStaleBindings(
|
|
|
12
20
|
if (key === field) return true
|
|
13
21
|
if (!key.startsWith(`${field}/`)) return false
|
|
14
22
|
const index = Number.parseInt(key.split('/')[1] ?? '', 10)
|
|
15
|
-
|
|
23
|
+
if (Number.isNaN(index) || index < 0 || index >= length) return true
|
|
24
|
+
return field === 'effects' && !bindsEffectProperty(node, key)
|
|
16
25
|
})
|
|
17
26
|
if (stale.length === 0) return
|
|
18
27
|
node.boundVariables = omit(node.boundVariables, stale)
|