@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.3
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/asset-keys.d.ts +11 -1
- package/dist/asset-keys.d.ts.map +1 -1
- package/dist/asset-keys.js +16 -1
- package/dist/asset-keys.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 +211 -10
- 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 +18 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +66 -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/constants.d.ts +6 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -1
- package/dist/constants.js.map +1 -1
- package/dist/constraints.d.ts +25 -0
- package/dist/constraints.d.ts.map +1 -0
- package/dist/constraints.js +51 -0
- package/dist/constraints.js.map +1 -0
- package/dist/coordinate.d.ts +64 -1
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +217 -1
- package/dist/coordinate.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -16
- 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 +4 -2
- package/dist/css/index.js +4 -2
- package/dist/css/text.d.ts +28 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +84 -17
- package/dist/css/text.js.map +1 -1
- package/dist/css/transform.d.ts +34 -0
- package/dist/css/transform.d.ts.map +1 -0
- package/dist/css/transform.js +320 -0
- package/dist/css/transform.js.map +1 -0
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +11 -1
- package/dist/css/values.js.map +1 -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 +37 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +80 -137
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -12
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +125 -27
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +14 -4
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +76 -11
- package/dist/group-bounds.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 +5 -0
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +57 -38
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +27 -3
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +57 -3
- package/dist/images.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 +39 -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/placement.js +55 -12
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap.js +291 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +112 -39
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +2 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.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 +4 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +21 -4
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +22 -11
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +227 -93
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +3 -2
- package/dist/scaling/index.js +3 -2
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +5 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/scaling/snapshot.d.ts +25 -0
- package/dist/scaling/snapshot.d.ts.map +1 -0
- package/dist/scaling/snapshot.js +39 -0
- package/dist/scaling/snapshot.js.map +1 -0
- package/dist/scaling/tree.d.ts +24 -2
- package/dist/scaling/tree.d.ts.map +1 -1
- package/dist/scaling/tree.js +38 -15
- package/dist/scaling/tree.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +2 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts +16 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +69 -2
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +6 -1
- 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/direction.d.ts +3 -1
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +5 -1
- package/dist/text/direction.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/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +1 -6
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +35 -3
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +44 -13
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +38 -0
- package/dist/transfer/dependencies.d.ts.map +1 -0
- package/dist/transfer/dependencies.js +100 -0
- package/dist/transfer/dependencies.js.map +1 -0
- package/dist/transfer/history.js +0 -1
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/index.d.ts +5 -3
- package/dist/transfer/index.js +5 -3
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +16 -19
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +0 -1
- package/dist/transfer/plan.js +3 -5
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +5 -2
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/resources.d.ts +21 -0
- package/dist/transfer/resources.d.ts.map +1 -0
- package/dist/transfer/resources.js +38 -0
- package/dist/transfer/resources.js.map +1 -0
- package/dist/transfer/variables.d.ts +8 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +24 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +73 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +28 -3
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +24 -7
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +37 -11
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +122 -74
- 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/formula/check.d.ts +1 -1
- package/dist/variables/formula/index.d.ts +2 -2
- package/dist/variables/formula/index.js +1 -1
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/print.d.ts +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +7 -7
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +57 -26
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +57 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +231 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -11
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +36 -17
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +2 -8
- package/dist/vector-network.js.map +1 -1
- package/package.json +14 -1
- package/src/arrow-caps.ts +2 -5
- package/src/asset-keys.ts +20 -0
- 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 +319 -17
- package/src/components/properties.ts +101 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/constants.ts +17 -0
- package/src/constraints.ts +60 -0
- package/src/coordinate.ts +220 -0
- package/src/copy.ts +18 -19
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +18 -1
- package/src/css/text.ts +85 -17
- package/src/css/transform.ts +266 -0
- package/src/css/values.ts +8 -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 +97 -206
- package/src/graph.ts +155 -45
- package/src/group-bounds.ts +84 -17
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +93 -64
- package/src/images.ts +71 -3
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +62 -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/placement.ts +63 -10
- package/src/instances/swap.ts +456 -0
- package/src/instances/sync.ts +176 -50
- package/src/node-defaults.ts +3 -1
- package/src/order-keys.ts +6 -0
- 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 +21 -2
- package/src/resize.ts +267 -119
- package/src/scaling/index.ts +9 -1
- package/src/scaling/node.ts +9 -1
- package/src/scaling/snapshot.ts +51 -0
- package/src/scaling/tree.ts +63 -19
- package/src/shaders/model.ts +2 -3
- package/src/shared-styles.ts +90 -1
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +6 -1
- package/src/slots/frames.ts +9 -7
- package/src/text/direction.ts +5 -0
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- package/src/transfer/apply.ts +1 -13
- package/src/transfer/copied.ts +83 -15
- package/src/transfer/dependencies.ts +126 -0
- package/src/transfer/history.ts +0 -6
- package/src/transfer/index.ts +20 -2
- package/src/transfer/nodes.ts +17 -31
- package/src/transfer/plan.ts +3 -11
- package/src/transfer/remove.ts +5 -2
- package/src/transfer/resources.ts +54 -0
- package/src/transfer/variables.ts +34 -0
- package/src/types.ts +83 -1
- package/src/undo.ts +48 -10
- package/src/variables/bindings.ts +152 -88
- package/src/variables/fields.ts +46 -1
- package/src/variables/formula/index.ts +3 -1
- package/src/variables/index.ts +90 -39
- package/src/variables/paints.ts +296 -0
- package/src/variables/resolution.ts +39 -28
- package/src/variables/subtree.ts +15 -0
- package/src/vector-network.ts +4 -2
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import valueParser from 'postcss-value-parser'
|
|
2
|
+
|
|
3
|
+
import Matrix, { type Mat3 } from '../matrix'
|
|
4
|
+
import type { Vector } from '../primitives'
|
|
5
|
+
import { dimension, splitCSSValue } from './values'
|
|
6
|
+
|
|
7
|
+
/** The size percentages in a transform resolve against: the element's border box. */
|
|
8
|
+
export interface CSSTransformBox {
|
|
9
|
+
width: number
|
|
10
|
+
height: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The properties that transform an element, as CSS applies them: translate, rotate, scale, transform. */
|
|
14
|
+
export interface CSSTransformStyle {
|
|
15
|
+
transform?: string
|
|
16
|
+
translate?: string
|
|
17
|
+
rotate?: string
|
|
18
|
+
scale?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ANGLE_UNITS: Partial<Record<string, number>> = {
|
|
22
|
+
deg: Math.PI / 180,
|
|
23
|
+
rad: 1,
|
|
24
|
+
grad: Math.PI / 200,
|
|
25
|
+
turn: Math.PI * 2
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** An angle in radians; a bare zero counts, as CSS allows. Null for anything else. */
|
|
29
|
+
function angle(value: string): number | null {
|
|
30
|
+
const parsed = dimension(value.trim())
|
|
31
|
+
if (!parsed) return null
|
|
32
|
+
if (parsed.unit === '') return parsed.number === 0 ? 0 : null
|
|
33
|
+
const radians = ANGLE_UNITS[parsed.unit]
|
|
34
|
+
return radians === undefined ? null : parsed.number * radians
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A length in pixels, a percentage of `extent`, or null for units this cannot resolve. */
|
|
38
|
+
function length(value: string, extent: number): number | null {
|
|
39
|
+
const parsed = dimension(value.trim())
|
|
40
|
+
if (!parsed) return null
|
|
41
|
+
if (parsed.unit === '%') return (parsed.number / 100) * extent
|
|
42
|
+
return parsed.unit === 'px' || (parsed.unit === '' && parsed.number === 0) ? parsed.number : null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A plain number, or a percentage as a fraction, as `scale` takes them. */
|
|
46
|
+
function factor(value: string): number | null {
|
|
47
|
+
const parsed = dimension(value.trim())
|
|
48
|
+
if (!parsed) return null
|
|
49
|
+
if (parsed.unit === '%') return parsed.number / 100
|
|
50
|
+
return parsed.unit === '' ? parsed.number : null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function skewed(x: number, y: number): Mat3 {
|
|
54
|
+
return [1, Math.tan(x), 0, Math.tan(y), 1, 0, 0, 0, 1]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The 2D matrix `matrix(a, b, c, d, e, f)` names. */
|
|
58
|
+
function affine([a, b, c, d, e, f]: number[]): Mat3 {
|
|
59
|
+
return [a, c, e, b, d, f, 0, 0, 1]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function translation(x: string, y: string | undefined, box: CSSTransformBox): Mat3 | null {
|
|
63
|
+
const dx = length(x, box.width)
|
|
64
|
+
const dy = y === undefined ? 0 : length(y, box.height)
|
|
65
|
+
return dx === null || dy === null ? null : Matrix.translated(dx, dy)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function scaling(x: string, y: string | undefined): Mat3 | null {
|
|
69
|
+
const sx = factor(x)
|
|
70
|
+
const sy = y === undefined ? sx : factor(y)
|
|
71
|
+
return sx === null || sy === null ? null : Matrix.scaled(sx, sy)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function numbers(values: string[]): number[] | null {
|
|
75
|
+
const parsed = values.map(Number)
|
|
76
|
+
return parsed.every(Number.isFinite) ? parsed : null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function rotation(value: string | undefined): Mat3 | null {
|
|
80
|
+
const radians = value === undefined ? null : angle(value)
|
|
81
|
+
return radians === null ? null : Matrix.rotated(radians)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function skewing(x: string | undefined, y: string | undefined): Mat3 | null {
|
|
85
|
+
const ax = x === undefined ? 0 : angle(x)
|
|
86
|
+
const ay = y === undefined ? 0 : angle(y)
|
|
87
|
+
return ax === null || ay === null ? null : skewed(ax, ay)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A transform function: how many arguments it takes, and the matrix they make. */
|
|
91
|
+
interface TransformFunction {
|
|
92
|
+
arity: readonly [min: number, max: number]
|
|
93
|
+
build: (args: string[], box: CSSTransformBox) => Mat3 | null
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The 2D transform functions by lowercase name; 3D turns and perspective are left out. */
|
|
97
|
+
const TRANSFORM_FUNCTIONS: Partial<Record<string, TransformFunction>> = {
|
|
98
|
+
matrix: {
|
|
99
|
+
arity: [6, 6],
|
|
100
|
+
build: (args) => {
|
|
101
|
+
const m = numbers(args)
|
|
102
|
+
return m && affine(m)
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
matrix3d: {
|
|
106
|
+
arity: [16, 16],
|
|
107
|
+
build: (args) => {
|
|
108
|
+
const m = numbers(args)
|
|
109
|
+
return m && inPlane(m) ? affine([m[0], m[1], m[4], m[5], m[12], m[13]]) : null
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
translate: { arity: [1, 2], build: (args, box) => translation(args[0], args.at(1), box) },
|
|
113
|
+
translate3d: {
|
|
114
|
+
arity: [3, 3],
|
|
115
|
+
build: (args, box) => (depth(args[2]) ? translation(args[0], args[1], box) : null)
|
|
116
|
+
},
|
|
117
|
+
translatex: { arity: [1, 1], build: (args, box) => translation(args[0], undefined, box) },
|
|
118
|
+
translatey: { arity: [1, 1], build: (args, box) => translation('0', args[0], box) },
|
|
119
|
+
rotate: { arity: [1, 1], build: (args) => rotation(args[0]) },
|
|
120
|
+
rotatez: { arity: [1, 1], build: (args) => rotation(args[0]) },
|
|
121
|
+
scale: { arity: [1, 2], build: (args) => scaling(args[0], args.at(1)) },
|
|
122
|
+
scale3d: {
|
|
123
|
+
arity: [3, 3],
|
|
124
|
+
build: (args) => (factor(args[2]) === null ? null : scaling(args[0], args[1]))
|
|
125
|
+
},
|
|
126
|
+
scalex: { arity: [1, 1], build: (args) => scaling(args[0], '1') },
|
|
127
|
+
scaley: { arity: [1, 1], build: (args) => scaling('1', args[0]) },
|
|
128
|
+
skew: { arity: [1, 2], build: (args) => skewing(args[0], args.at(1)) },
|
|
129
|
+
skewx: { arity: [1, 1], build: (args) => skewing(args[0], undefined) },
|
|
130
|
+
skewy: { arity: [1, 1], build: (args) => skewing(undefined, args[0]) }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Whether a `matrix3d`, column by column, keeps the plane where it was: no turn out of it and no
|
|
135
|
+
* perspective. Depth, which moves nothing on the plane without perspective, may change.
|
|
136
|
+
*/
|
|
137
|
+
function inPlane(m: number[]): boolean {
|
|
138
|
+
const outOfPlane = [m[2], m[3], m[6], m[7], m[8], m[9], m[11]]
|
|
139
|
+
return outOfPlane.every((value) => value === 0) && m[15] === 1
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Whether a z offset is a length, which a percentage never is. It moves nothing on the plane without perspective, which a
|
|
144
|
+
* layer cannot hold, so it is read and dropped.
|
|
145
|
+
*/
|
|
146
|
+
function depth(value: string): boolean {
|
|
147
|
+
return !value.trim().endsWith('%') && length(value, 0) !== null
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A function's arguments, which CSS separates with commas: null when one is missing, or two
|
|
152
|
+
* stand without a comma between them.
|
|
153
|
+
*/
|
|
154
|
+
function functionArguments(nodes: valueParser.Node[]): string[] | null {
|
|
155
|
+
const parts = nodes.filter((node) => node.type !== 'space' && node.type !== 'comment')
|
|
156
|
+
const args: string[] = []
|
|
157
|
+
for (const [index, node] of parts.entries()) {
|
|
158
|
+
const expectsArgument = index % 2 === 0
|
|
159
|
+
if (expectsArgument && node.type !== 'word') return null
|
|
160
|
+
if (!expectsArgument && (node.type !== 'div' || node.value !== ',')) return null
|
|
161
|
+
if (expectsArgument) args.push(node.value)
|
|
162
|
+
}
|
|
163
|
+
return parts.length % 2 === 1 ? args : null
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** One transform function as a matrix; null for one this does not know or cannot read. */
|
|
167
|
+
function transformFunction(name: string, args: string[], box: CSSTransformBox): Mat3 | null {
|
|
168
|
+
// Own names only, so `constructor` or `__proto__` reads as unknown instead of a prototype member.
|
|
169
|
+
const fn = Object.hasOwn(TRANSFORM_FUNCTIONS, name) ? TRANSFORM_FUNCTIONS[name] : undefined
|
|
170
|
+
if (!fn || args.length < fn.arity[0] || args.length > fn.arity[1]) return null
|
|
171
|
+
return fn.build(args, box)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A CSS `transform` as a 2D matrix about the transform origin, with percentages resolved against
|
|
176
|
+
* `box`. The identity for `none`; null when it turns out of the plane or cannot be read.
|
|
177
|
+
*/
|
|
178
|
+
export function parseCSSTransform(value: string | undefined, box: CSSTransformBox): Mat3 | null {
|
|
179
|
+
const text = value?.trim()
|
|
180
|
+
if (!text || text === 'none') return Matrix.identity()
|
|
181
|
+
let matrix = Matrix.identity()
|
|
182
|
+
for (const node of valueParser(text).nodes) {
|
|
183
|
+
if (node.type === 'space' || node.type === 'comment') continue
|
|
184
|
+
if (node.type !== 'function') return null
|
|
185
|
+
const args = functionArguments(node.nodes)
|
|
186
|
+
const step = args && transformFunction(node.value.toLowerCase(), args, box)
|
|
187
|
+
if (!step) return null
|
|
188
|
+
matrix = Matrix.multiply(matrix, step)
|
|
189
|
+
}
|
|
190
|
+
return matrix
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The `rotate` property: an angle, or one about the z axis. Null when it turns out of the plane. */
|
|
194
|
+
function rotateProperty(parts: string[]): Mat3 | null {
|
|
195
|
+
const last = parts.at(-1)
|
|
196
|
+
const axis = parts.slice(0, -1).join(' ').toLowerCase()
|
|
197
|
+
const radians = last === undefined ? null : angle(last)
|
|
198
|
+
if (radians === null || !['', 'z', '0 0 1'].includes(axis)) return null
|
|
199
|
+
return Matrix.rotated(radians)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** A transform property's value as a matrix; the identity when it is unset or `none`. */
|
|
203
|
+
function property(value: string | undefined, parse: (parts: string[]) => Mat3 | null): Mat3 | null {
|
|
204
|
+
const text = value?.trim()
|
|
205
|
+
if (!text || text === 'none') return Matrix.identity()
|
|
206
|
+
return parse(splitCSSValue(text))
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The 2D matrix about the transform origin that an element's `translate`, `rotate`, `scale`, and
|
|
211
|
+
* `transform` make together, applied in that order as CSS applies them. Null when one of them
|
|
212
|
+
* turns out of the plane or cannot be read.
|
|
213
|
+
*/
|
|
214
|
+
export function parseCSSTransforms(style: CSSTransformStyle, box: CSSTransformBox): Mat3 | null {
|
|
215
|
+
const steps = [
|
|
216
|
+
property(style.translate, (parts) => {
|
|
217
|
+
const [x, y, z] = [parts.at(0), parts.at(1), parts.at(2)]
|
|
218
|
+
if (x === undefined || parts.length > 3 || (z !== undefined && !depth(z))) return null
|
|
219
|
+
return translation(x, y, box)
|
|
220
|
+
}),
|
|
221
|
+
property(style.rotate, rotateProperty),
|
|
222
|
+
property(style.scale, (parts) => {
|
|
223
|
+
const [x, y, z] = [parts.at(0), parts.at(1), parts.at(2)]
|
|
224
|
+
if (x === undefined || parts.length > 3 || (z !== undefined && factor(z) === null)) {
|
|
225
|
+
return null
|
|
226
|
+
}
|
|
227
|
+
return scaling(x, y)
|
|
228
|
+
}),
|
|
229
|
+
parseCSSTransform(style.transform, box)
|
|
230
|
+
]
|
|
231
|
+
if (steps.some((step) => step === null)) return null
|
|
232
|
+
return Matrix.multiply(...steps.filter((step) => step !== null))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const ORIGIN_KEYWORDS: Partial<Record<string, { axis: 'x' | 'y' | 'either'; fraction: number }>> = {
|
|
236
|
+
left: { axis: 'x', fraction: 0 },
|
|
237
|
+
right: { axis: 'x', fraction: 1 },
|
|
238
|
+
top: { axis: 'y', fraction: 0 },
|
|
239
|
+
bottom: { axis: 'y', fraction: 1 },
|
|
240
|
+
center: { axis: 'either', fraction: 0.5 }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Where a CSS `transform-origin` puts the point an element transforms about, from its border
|
|
245
|
+
* box's top left corner. Its center when it is unset or cannot be read.
|
|
246
|
+
*/
|
|
247
|
+
export function parseCSSTransformOrigin(value: string | undefined, box: CSSTransformBox): Vector {
|
|
248
|
+
const center = { x: box.width / 2, y: box.height / 2 }
|
|
249
|
+
const tokens = splitCSSValue(value?.trim() ?? '')
|
|
250
|
+
// A third value is the depth, which must be a length; anything past it is not an origin.
|
|
251
|
+
const depthOk = tokens.length < 3 || (tokens.length === 3 && depth(tokens[2]))
|
|
252
|
+
if (tokens.length === 0 || !depthOk) return center
|
|
253
|
+
const parts = tokens.slice(0, 2)
|
|
254
|
+
// A vertical keyword first, as in `top left`, names the y offset.
|
|
255
|
+
const [first = 'center', second = 'center'] = parts.map((part) => part.toLowerCase())
|
|
256
|
+
const swapped = ORIGIN_KEYWORDS[first]?.axis === 'y' || ORIGIN_KEYWORDS[second]?.axis === 'x'
|
|
257
|
+
const [x, y] = swapped ? [second, first] : [first, second]
|
|
258
|
+
const resolve = (part: string, extent: number, axis: 'x' | 'y') => {
|
|
259
|
+
const keyword = ORIGIN_KEYWORDS[part]
|
|
260
|
+
if (!keyword) return length(part, extent)
|
|
261
|
+
return keyword.axis === axis || keyword.axis === 'either' ? keyword.fraction * extent : null
|
|
262
|
+
}
|
|
263
|
+
const ox = resolve(x, box.width, 'x')
|
|
264
|
+
const oy = resolve(y, box.height, 'y')
|
|
265
|
+
return ox === null || oy === null ? center : { x: ox, y: oy }
|
|
266
|
+
}
|
package/src/css/values.ts
CHANGED
|
@@ -3,6 +3,14 @@ import valueParser from 'postcss-value-parser'
|
|
|
3
3
|
import { tryParseColor } from '../color'
|
|
4
4
|
import type { Color } from '../primitives'
|
|
5
5
|
|
|
6
|
+
/** A CSS dimension's number and lowercase unit, or null. */
|
|
7
|
+
export function dimension(value: string): { number: number; unit: string } | null {
|
|
8
|
+
const parsed = valueParser.unit(value)
|
|
9
|
+
if (!parsed) return null
|
|
10
|
+
const number = Number(parsed.number)
|
|
11
|
+
return Number.isFinite(number) ? { number, unit: parsed.unit.toLowerCase() } : null
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
/** Pixels in a rem, as browsers use by default. */
|
|
7
15
|
const ROOT_FONT_SIZE = 16
|
|
8
16
|
|
package/src/cubic.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Vector } from './primitives'
|
|
2
|
+
|
|
3
|
+
/** The point at `t` along the cubic from `p0` to `p3` with control points `p1` and `p2`. */
|
|
4
|
+
export function cubicPoint(p0: Vector, p1: Vector, p2: Vector, p3: Vector, t: number): Vector {
|
|
5
|
+
const u = 1 - t
|
|
6
|
+
const a = u * u * u
|
|
7
|
+
const b = 3 * u * u * t
|
|
8
|
+
const c = 3 * u * t * t
|
|
9
|
+
const d = t * t * t
|
|
10
|
+
return {
|
|
11
|
+
x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,
|
|
12
|
+
y: a * p0.y + b * p1.y + c * p2.y + d * p3.y
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/export-format.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { omitBy } from 'es-toolkit/object'
|
|
2
|
+
|
|
3
|
+
import type { ExportSetting } from './types'
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Formats a node's export settings may persist. Each id must name a Core IO
|
|
3
7
|
* export adapter that supports node export; labels and options come from that
|
|
@@ -10,3 +14,28 @@ export type ExportFormatId = (typeof EXPORT_FORMAT_IDS)[number]
|
|
|
10
14
|
export function isExportFormatId(value: unknown): value is ExportFormatId {
|
|
11
15
|
return EXPORT_FORMAT_IDS.some((id) => id === value)
|
|
12
16
|
}
|
|
17
|
+
|
|
18
|
+
/** What each of Figma's export options reads as when an export leaves it out. */
|
|
19
|
+
export const EXPORT_OPTION_DEFAULTS = {
|
|
20
|
+
suffix: '',
|
|
21
|
+
contentsOnly: true,
|
|
22
|
+
useAbsoluteBounds: false,
|
|
23
|
+
colorProfile: 'DOCUMENT',
|
|
24
|
+
svgOutlineText: true,
|
|
25
|
+
svgIdAttribute: false,
|
|
26
|
+
svgSimplifyStroke: true
|
|
27
|
+
} as const satisfies Required<Omit<ExportSetting, 'scale' | 'format' | 'size'>>
|
|
28
|
+
|
|
29
|
+
/** An export as the model keeps it: options that are unset or at Figma's default left out. */
|
|
30
|
+
export function compactExportSetting({
|
|
31
|
+
scale,
|
|
32
|
+
format,
|
|
33
|
+
size,
|
|
34
|
+
...options
|
|
35
|
+
}: ExportSetting): ExportSetting {
|
|
36
|
+
const changed = omitBy(
|
|
37
|
+
options,
|
|
38
|
+
(value, key) => value === undefined || value === EXPORT_OPTION_DEFAULTS[key]
|
|
39
|
+
)
|
|
40
|
+
return size ? { scale, format, size, ...changed } : { scale, format, ...changed }
|
|
41
|
+
}
|
package/src/fields/text.ts
CHANGED
|
@@ -16,7 +16,9 @@ export const TEXT_METRIC_FIELDS = [
|
|
|
16
16
|
'listSpacing',
|
|
17
17
|
'paragraphSpacing',
|
|
18
18
|
'paragraphIndent',
|
|
19
|
-
'hangingList'
|
|
19
|
+
'hangingList',
|
|
20
|
+
// A cap-height trim drops the space above and below the glyphs, so the text measures shorter.
|
|
21
|
+
'leadingTrim'
|
|
20
22
|
] as const satisfies readonly (keyof SceneNode)[]
|
|
21
23
|
|
|
22
24
|
export const TEXT_SHAPING_FIELDS = [
|
package/src/figjam/palette.ts
CHANGED
|
@@ -244,6 +244,27 @@ export function figJamOutlineColorName(color: Color | undefined): FigJamColorNam
|
|
|
244
244
|
)
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
/**
|
|
248
|
+
* How FigJam draws a section's title on a board, measured in FigJam: a pill in the colour of the
|
|
249
|
+
* outline drawn on top, with white text on the palette's darkest colours and black on the rest;
|
|
250
|
+
* null for a section without an outline from the palette. `colorOf` reads an outline's colour as
|
|
251
|
+
* drawn, such as a variable's value in the section's mode.
|
|
252
|
+
*/
|
|
253
|
+
export function figJamSectionTitleColors(
|
|
254
|
+
section: Pick<SceneNode, 'strokes'>,
|
|
255
|
+
colorOf: (stroke: Stroke, index: number) => Color = (stroke) => stroke.color
|
|
256
|
+
): { strokeIndex: number; background: Color; lightText: boolean } | null {
|
|
257
|
+
const strokeIndex = section.strokes.findLastIndex(
|
|
258
|
+
(stroke) => stroke.visible && stroke.opacity > 0
|
|
259
|
+
)
|
|
260
|
+
const outline = section.strokes.at(strokeIndex)
|
|
261
|
+
if (strokeIndex === -1 || !outline) return null
|
|
262
|
+
const color = colorOf(outline, strokeIndex)
|
|
263
|
+
const name = figJamOutlineColorName(color)
|
|
264
|
+
if (!name) return null
|
|
265
|
+
return { strokeIndex, background: { ...color, a: 1 }, lightText: PALETTE[name].lightLabel }
|
|
266
|
+
}
|
|
267
|
+
|
|
247
268
|
/** The fill mode a shape's first fill shows. */
|
|
248
269
|
export function figJamFillMode(fill: Fill | undefined): FigJamFillMode {
|
|
249
270
|
if (!fill || !fill.visible || fill.opacity === 0) return 'none'
|
|
@@ -380,9 +401,16 @@ export function figJamSectionColorFields(
|
|
|
380
401
|
name: FigJamColorName
|
|
381
402
|
): Partial<SceneNode> {
|
|
382
403
|
const { sectionFill, sectionStroke } = PALETTE[name]
|
|
404
|
+
// The outline shows in full at FigJam's 2, as its menu draws it, unless the line menu hid it.
|
|
405
|
+
const strokes = strokesIn(section.strokes, parseColor(sectionStroke), SECTION_STROKE_WEIGHT).map(
|
|
406
|
+
(stroke): Stroke =>
|
|
407
|
+
stroke.opacity === 0
|
|
408
|
+
? stroke
|
|
409
|
+
: { ...stroke, opacity: 1, visible: true, weight: SECTION_STROKE_WEIGHT }
|
|
410
|
+
)
|
|
383
411
|
return {
|
|
384
412
|
fills: [{ type: 'SOLID', color: parseColor(sectionFill), opacity: 1, visible: true }],
|
|
385
|
-
strokes
|
|
413
|
+
strokes,
|
|
386
414
|
strokeWeight: SECTION_STROKE_WEIGHT
|
|
387
415
|
}
|
|
388
416
|
}
|
|
@@ -9,9 +9,15 @@ import type { GeneratedFrameKind } from './kind'
|
|
|
9
9
|
|
|
10
10
|
/** FigJam makes a shape with text 176 px square, from its tool and from its plugin API. */
|
|
11
11
|
export const SHAPE_WITH_TEXT_SIZE = 176
|
|
12
|
-
/** FigJam rounds every corner of a shape by 6 px. */
|
|
12
|
+
/** FigJam rounds every corner of a shape by 6 px, but a rounded rectangle's. */
|
|
13
13
|
export const SHAPE_WITH_TEXT_CORNER_RADIUS = 6
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* FigJam keeps a rounded rectangle's corner radius at 0.4 of its shorter side, through resizes,
|
|
17
|
+
* measured in FigJam; Figma draws the shape from that radius.
|
|
18
|
+
*/
|
|
19
|
+
const ROUNDED_RECTANGLE_RADIUS = 0.4
|
|
20
|
+
|
|
15
21
|
const LABEL_FILL: Fill = { type: 'SOLID', color: { ...BLACK }, opacity: 0.8, visible: true }
|
|
16
22
|
|
|
17
23
|
/** How the label sits in its shape: as wide as the label box, as tall as its text. */
|
|
@@ -42,7 +48,27 @@ export function shapeWithTextFrameFields(
|
|
|
42
48
|
paddingRight: Math.max(0, width - box.x - box.width),
|
|
43
49
|
paddingBottom: Math.max(0, height - box.y - box.height),
|
|
44
50
|
paddingLeft: box.x,
|
|
45
|
-
clipsContent: false
|
|
51
|
+
clipsContent: false,
|
|
52
|
+
...(kind === 'ROUNDED_RECTANGLE'
|
|
53
|
+
? { cornerRadius: ROUNDED_RECTANGLE_RADIUS * Math.min(width, height) }
|
|
54
|
+
: {})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* What turning a shape into `kind` changes, keeping its size, as FigJam's shape switcher does: the
|
|
60
|
+
* label area, and the corners a rounded rectangle leaves go back to FigJam's 6.
|
|
61
|
+
*/
|
|
62
|
+
export function shapeWithTextKindFields(
|
|
63
|
+
shape: Pick<SceneNode, 'shapeWithTextType' | 'width' | 'height'>,
|
|
64
|
+
kind: ShapeWithTextType
|
|
65
|
+
): Partial<SceneNode> {
|
|
66
|
+
const leavesRounded =
|
|
67
|
+
shape.shapeWithTextType === 'ROUNDED_RECTANGLE' && kind !== shape.shapeWithTextType
|
|
68
|
+
return {
|
|
69
|
+
shapeWithTextType: kind,
|
|
70
|
+
...(leavesRounded ? { cornerRadius: SHAPE_WITH_TEXT_CORNER_RADIUS } : {}),
|
|
71
|
+
...shapeWithTextFrameFields(kind, shape.width, shape.height)
|
|
46
72
|
}
|
|
47
73
|
}
|
|
48
74
|
|