@open-pencil/scene-graph 0.17.0-beta.4 → 0.17.0-beta.6

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.
Files changed (345) hide show
  1. package/dist/buffered-events.js +1 -1
  2. package/dist/buffered-events.js.map +1 -1
  3. package/dist/clipping.d.ts +7 -1
  4. package/dist/clipping.d.ts.map +1 -1
  5. package/dist/clipping.js +23 -19
  6. package/dist/clipping.js.map +1 -1
  7. package/dist/comments/schema.d.ts.map +1 -1
  8. package/dist/comments/schema.js +1 -0
  9. package/dist/comments/schema.js.map +1 -1
  10. package/dist/comments/threads.d.ts +2 -0
  11. package/dist/comments/threads.d.ts.map +1 -1
  12. package/dist/comments/threads.js +11 -5
  13. package/dist/comments/threads.js.map +1 -1
  14. package/dist/components/index.d.ts +2 -2
  15. package/dist/components/index.js +2 -2
  16. package/dist/components/properties.d.ts +1 -3
  17. package/dist/components/properties.d.ts.map +1 -1
  18. package/dist/components/properties.js +3 -10
  19. package/dist/components/properties.js.map +1 -1
  20. package/dist/constants.d.ts +12 -2
  21. package/dist/constants.d.ts.map +1 -1
  22. package/dist/constants.js +42 -1
  23. package/dist/constants.js.map +1 -1
  24. package/dist/copy.d.ts.map +1 -1
  25. package/dist/copy.js +2 -0
  26. package/dist/copy.js.map +1 -1
  27. package/dist/corners.d.ts +22 -0
  28. package/dist/corners.d.ts.map +1 -0
  29. package/dist/corners.js +52 -0
  30. package/dist/corners.js.map +1 -0
  31. package/dist/css/grid.d.ts +4 -1
  32. package/dist/css/grid.d.ts.map +1 -1
  33. package/dist/css/grid.js +40 -7
  34. package/dist/css/grid.js.map +1 -1
  35. package/dist/css/index.d.ts +3 -3
  36. package/dist/css/index.js +3 -3
  37. package/dist/css/layout.d.ts +13 -1
  38. package/dist/css/layout.d.ts.map +1 -1
  39. package/dist/css/layout.js +26 -1
  40. package/dist/css/layout.js.map +1 -1
  41. package/dist/css/values.d.ts +23 -1
  42. package/dist/css/values.d.ts.map +1 -1
  43. package/dist/css/values.js +39 -1
  44. package/dist/css/values.js.map +1 -1
  45. package/dist/font-style.d.ts +2 -1
  46. package/dist/font-style.d.ts.map +1 -1
  47. package/dist/font-style.js +31 -6
  48. package/dist/font-style.js.map +1 -1
  49. package/dist/geometry.d.ts +68 -3
  50. package/dist/geometry.d.ts.map +1 -1
  51. package/dist/geometry.js +159 -25
  52. package/dist/geometry.js.map +1 -1
  53. package/dist/gradient.d.ts +9 -2
  54. package/dist/gradient.d.ts.map +1 -1
  55. package/dist/gradient.js +29 -1
  56. package/dist/gradient.js.map +1 -1
  57. package/dist/graph.d.ts +9 -2
  58. package/dist/graph.d.ts.map +1 -1
  59. package/dist/graph.js +46 -10
  60. package/dist/graph.js.map +1 -1
  61. package/dist/group-bounds.d.ts.map +1 -1
  62. package/dist/group-bounds.js +4 -3
  63. package/dist/group-bounds.js.map +1 -1
  64. package/dist/guides.d.ts +11 -2
  65. package/dist/guides.d.ts.map +1 -1
  66. package/dist/guides.js +30 -1
  67. package/dist/guides.js.map +1 -1
  68. package/dist/hit-test.d.ts.map +1 -1
  69. package/dist/hit-test.js +57 -5
  70. package/dist/hit-test.js.map +1 -1
  71. package/dist/icons/fit.d.ts +17 -0
  72. package/dist/icons/fit.d.ts.map +1 -0
  73. package/dist/icons/fit.js +21 -0
  74. package/dist/icons/fit.js.map +1 -0
  75. package/dist/icons/glyph.d.ts.map +1 -1
  76. package/dist/icons/glyph.js +5 -4
  77. package/dist/icons/glyph.js.map +1 -1
  78. package/dist/icons/index.d.ts +2 -1
  79. package/dist/icons/index.js +2 -1
  80. package/dist/ids.js +1 -1
  81. package/dist/ids.js.map +1 -1
  82. package/dist/images.d.ts +14 -4
  83. package/dist/images.d.ts.map +1 -1
  84. package/dist/images.js +45 -5
  85. package/dist/images.js.map +1 -1
  86. package/dist/index.d.ts +2 -2
  87. package/dist/instances/assignments.js +39 -6
  88. package/dist/instances/assignments.js.map +1 -1
  89. package/dist/instances/index.d.ts +6 -1
  90. package/dist/instances/index.d.ts.map +1 -1
  91. package/dist/instances/index.js +58 -9
  92. package/dist/instances/index.js.map +1 -1
  93. package/dist/instances/kept-overrides.js +2 -2
  94. package/dist/instances/kept-overrides.js.map +1 -1
  95. package/dist/instances/matching.js +68 -0
  96. package/dist/instances/matching.js.map +1 -0
  97. package/dist/instances/overrides.d.ts +4 -1
  98. package/dist/instances/overrides.d.ts.map +1 -1
  99. package/dist/instances/overrides.js +13 -1
  100. package/dist/instances/overrides.js.map +1 -1
  101. package/dist/instances/protection.js +67 -0
  102. package/dist/instances/protection.js.map +1 -0
  103. package/dist/instances/swap.js +7 -5
  104. package/dist/instances/swap.js.map +1 -1
  105. package/dist/instances/sync.js +34 -116
  106. package/dist/instances/sync.js.map +1 -1
  107. package/dist/layout/guides.d.ts +17 -1
  108. package/dist/layout/guides.d.ts.map +1 -1
  109. package/dist/layout/guides.js +31 -11
  110. package/dist/layout/guides.js.map +1 -1
  111. package/dist/layout/index.d.ts +5 -2
  112. package/dist/layout/index.js +5 -2
  113. package/dist/layout/limits.d.ts +40 -0
  114. package/dist/layout/limits.d.ts.map +1 -0
  115. package/dist/layout/limits.js +54 -0
  116. package/dist/layout/limits.js.map +1 -0
  117. package/dist/layout/sizing.d.ts.map +1 -1
  118. package/dist/layout/sizing.js +0 -1
  119. package/dist/layout/sizing.js.map +1 -1
  120. package/dist/layout/spacing.d.ts +10 -0
  121. package/dist/layout/spacing.d.ts.map +1 -0
  122. package/dist/layout/spacing.js +12 -0
  123. package/dist/layout/spacing.js.map +1 -0
  124. package/dist/layout/strokes.d.ts +10 -0
  125. package/dist/layout/strokes.d.ts.map +1 -0
  126. package/dist/layout/strokes.js +30 -0
  127. package/dist/layout/strokes.js.map +1 -0
  128. package/dist/masks.d.ts +28 -0
  129. package/dist/masks.d.ts.map +1 -0
  130. package/dist/masks.js +53 -0
  131. package/dist/masks.js.map +1 -0
  132. package/dist/matrix.d.ts +2 -1
  133. package/dist/matrix.d.ts.map +1 -1
  134. package/dist/matrix.js +14 -1
  135. package/dist/matrix.js.map +1 -1
  136. package/dist/node-defaults.d.ts +9 -1
  137. package/dist/node-defaults.d.ts.map +1 -1
  138. package/dist/node-defaults.js +65 -38
  139. package/dist/node-defaults.js.map +1 -1
  140. package/dist/outline/flatten.d.ts.map +1 -1
  141. package/dist/outline/flatten.js +24 -17
  142. package/dist/outline/flatten.js.map +1 -1
  143. package/dist/outline/hit.d.ts +2 -8
  144. package/dist/outline/hit.d.ts.map +1 -1
  145. package/dist/outline/hit.js +16 -25
  146. package/dist/outline/hit.js.map +1 -1
  147. package/dist/outline/index.d.ts +3 -3
  148. package/dist/outline/index.js +3 -3
  149. package/dist/outline/shapes.d.ts +3 -1
  150. package/dist/outline/shapes.d.ts.map +1 -1
  151. package/dist/outline/shapes.js +18 -39
  152. package/dist/outline/shapes.js.map +1 -1
  153. package/dist/paints/index.d.ts +3 -1
  154. package/dist/paints/index.js +3 -1
  155. package/dist/paints/pattern.d.ts +13 -0
  156. package/dist/paints/pattern.d.ts.map +1 -0
  157. package/dist/paints/pattern.js +47 -0
  158. package/dist/paints/pattern.js.map +1 -0
  159. package/dist/paints/shows.d.ts +11 -0
  160. package/dist/paints/shows.d.ts.map +1 -0
  161. package/dist/paints/shows.js +16 -0
  162. package/dist/paints/shows.js.map +1 -0
  163. package/dist/parse-path.d.ts +4 -1
  164. package/dist/parse-path.d.ts.map +1 -1
  165. package/dist/parse-path.js +15 -1
  166. package/dist/parse-path.js.map +1 -1
  167. package/dist/paths/arc.d.ts +32 -0
  168. package/dist/paths/arc.d.ts.map +1 -0
  169. package/dist/paths/arc.js +49 -0
  170. package/dist/paths/arc.js.map +1 -0
  171. package/dist/paths/index.d.ts +5 -0
  172. package/dist/paths/index.js +5 -0
  173. package/dist/paths/network.d.ts +63 -0
  174. package/dist/paths/network.d.ts.map +1 -0
  175. package/dist/paths/network.js +315 -0
  176. package/dist/paths/network.js.map +1 -0
  177. package/dist/paths/sink.d.ts +20 -0
  178. package/dist/paths/sink.d.ts.map +1 -0
  179. package/dist/paths/sink.js +32 -0
  180. package/dist/paths/sink.js.map +1 -0
  181. package/dist/paths/smooth-corners.d.ts +25 -0
  182. package/dist/paths/smooth-corners.d.ts.map +1 -0
  183. package/dist/paths/smooth-corners.js +196 -0
  184. package/dist/paths/smooth-corners.js.map +1 -0
  185. package/dist/plugin-data/fields.d.ts +4 -0
  186. package/dist/plugin-data/fields.d.ts.map +1 -1
  187. package/dist/plugin-data/fields.js +2 -0
  188. package/dist/plugin-data/fields.js.map +1 -1
  189. package/dist/polygon.d.ts +1 -3
  190. package/dist/polygon.d.ts.map +1 -1
  191. package/dist/polygon.js +1 -16
  192. package/dist/polygon.js.map +1 -1
  193. package/dist/primitives/index.d.ts +1 -7
  194. package/dist/primitives/index.d.ts.map +1 -1
  195. package/dist/resize.d.ts.map +1 -1
  196. package/dist/resize.js +5 -5
  197. package/dist/resize.js.map +1 -1
  198. package/dist/scaling/node.d.ts.map +1 -1
  199. package/dist/scaling/node.js +25 -3
  200. package/dist/scaling/node.js.map +1 -1
  201. package/dist/shaders/model.d.ts.map +1 -1
  202. package/dist/shaders/model.js +1 -1
  203. package/dist/shaders/model.js.map +1 -1
  204. package/dist/shared-styles.d.ts.map +1 -1
  205. package/dist/shared-styles.js +2 -9
  206. package/dist/shared-styles.js.map +1 -1
  207. package/dist/strokes.d.ts +39 -0
  208. package/dist/strokes.d.ts.map +1 -0
  209. package/dist/strokes.js +104 -0
  210. package/dist/strokes.js.map +1 -0
  211. package/dist/text/auto-resize.d.ts +15 -0
  212. package/dist/text/auto-resize.d.ts.map +1 -0
  213. package/dist/text/auto-resize.js +23 -0
  214. package/dist/text/auto-resize.js.map +1 -0
  215. package/dist/text/index.d.ts +5 -3
  216. package/dist/text/index.js +5 -3
  217. package/dist/text/lengths.d.ts +6 -1
  218. package/dist/text/lengths.d.ts.map +1 -1
  219. package/dist/text/lengths.js +10 -1
  220. package/dist/text/lengths.js.map +1 -1
  221. package/dist/text/overflow.d.ts +14 -5
  222. package/dist/text/overflow.d.ts.map +1 -1
  223. package/dist/text/overflow.js +24 -6
  224. package/dist/text/overflow.js.map +1 -1
  225. package/dist/text/path.js +10 -0
  226. package/dist/text/path.js.map +1 -0
  227. package/dist/text/picture.js +5 -5
  228. package/dist/text/picture.js.map +1 -1
  229. package/dist/text/runs.d.ts +29 -0
  230. package/dist/text/runs.d.ts.map +1 -0
  231. package/dist/text/runs.js +72 -0
  232. package/dist/text/runs.js.map +1 -0
  233. package/dist/transfer/dependencies.d.ts.map +1 -1
  234. package/dist/transfer/dependencies.js +3 -2
  235. package/dist/transfer/dependencies.js.map +1 -1
  236. package/dist/transfer/nodes.js +2 -1
  237. package/dist/transfer/nodes.js.map +1 -1
  238. package/dist/types.d.ts +56 -10
  239. package/dist/types.d.ts.map +1 -1
  240. package/dist/types.js.map +1 -1
  241. package/dist/variables/index.d.ts +4 -3
  242. package/dist/variables/index.d.ts.map +1 -1
  243. package/dist/variables/index.js +4 -3
  244. package/dist/variables/index.js.map +1 -1
  245. package/dist/variables/lookup.d.ts +20 -0
  246. package/dist/variables/lookup.d.ts.map +1 -0
  247. package/dist/variables/lookup.js +34 -0
  248. package/dist/variables/lookup.js.map +1 -0
  249. package/dist/variables/paints.d.ts +35 -4
  250. package/dist/variables/paints.d.ts.map +1 -1
  251. package/dist/variables/paints.js +67 -16
  252. package/dist/variables/paints.js.map +1 -1
  253. package/dist/variables/resolution.d.ts +3 -1
  254. package/dist/variables/resolution.d.ts.map +1 -1
  255. package/dist/variables/resolution.js +8 -3
  256. package/dist/variables/resolution.js.map +1 -1
  257. package/dist/variables/subtree.js +1 -1
  258. package/dist/variables/subtree.js.map +1 -1
  259. package/dist/vector-network.d.ts.map +1 -1
  260. package/dist/vector-network.js +13 -79
  261. package/dist/vector-network.js.map +1 -1
  262. package/package.json +28 -7
  263. package/src/buffered-events.ts +2 -1
  264. package/src/clipping.ts +11 -8
  265. package/src/comments/schema.ts +1 -0
  266. package/src/comments/threads.ts +13 -5
  267. package/src/components/properties.ts +3 -14
  268. package/src/constants.ts +25 -1
  269. package/src/copy.ts +2 -0
  270. package/src/corners.ts +93 -0
  271. package/src/css/grid.ts +49 -7
  272. package/src/css/index.ts +13 -2
  273. package/src/css/layout.ts +36 -0
  274. package/src/css/values.ts +49 -0
  275. package/src/font-style.ts +38 -4
  276. package/src/geometry.ts +223 -28
  277. package/src/gradient.ts +23 -1
  278. package/src/graph.ts +35 -10
  279. package/src/group-bounds.ts +7 -3
  280. package/src/guides.ts +26 -1
  281. package/src/hit-test.ts +68 -10
  282. package/src/icons/fit.ts +24 -0
  283. package/src/icons/glyph.ts +6 -4
  284. package/src/icons/index.ts +1 -0
  285. package/src/ids.ts +1 -1
  286. package/src/images.ts +67 -7
  287. package/src/instances/assignments.ts +65 -7
  288. package/src/instances/index.ts +77 -13
  289. package/src/instances/kept-overrides.ts +2 -5
  290. package/src/instances/matching.ts +101 -0
  291. package/src/instances/overrides.ts +18 -0
  292. package/src/instances/protection.ts +103 -0
  293. package/src/instances/swap.ts +12 -9
  294. package/src/instances/sync.ts +52 -184
  295. package/src/layout/guides.ts +42 -9
  296. package/src/layout/index.ts +3 -0
  297. package/src/layout/limits.ts +64 -0
  298. package/src/layout/sizing.ts +0 -2
  299. package/src/layout/spacing.ts +11 -0
  300. package/src/layout/strokes.ts +23 -0
  301. package/src/masks.ts +51 -0
  302. package/src/matrix.ts +15 -2
  303. package/src/node-defaults.ts +71 -36
  304. package/src/outline/flatten.ts +31 -18
  305. package/src/outline/hit.ts +16 -33
  306. package/src/outline/index.ts +2 -2
  307. package/src/outline/shapes.ts +19 -36
  308. package/src/paints/index.ts +2 -0
  309. package/src/paints/pattern.ts +45 -0
  310. package/src/paints/shows.ts +13 -0
  311. package/src/parse-path.ts +14 -0
  312. package/src/paths/arc.ts +59 -0
  313. package/src/paths/index.ts +4 -0
  314. package/src/paths/network.ts +411 -0
  315. package/src/paths/sink.ts +50 -0
  316. package/src/paths/smooth-corners.ts +357 -0
  317. package/src/plugin-data/fields.ts +2 -0
  318. package/src/polygon.ts +0 -17
  319. package/src/primitives/index.ts +0 -5
  320. package/src/resize.ts +6 -7
  321. package/src/scaling/node.ts +29 -3
  322. package/src/shaders/model.ts +2 -1
  323. package/src/shared-styles.ts +3 -4
  324. package/src/strokes.ts +121 -0
  325. package/src/text/auto-resize.ts +25 -0
  326. package/src/text/index.ts +2 -0
  327. package/src/text/lengths.ts +11 -0
  328. package/src/text/overflow.ts +32 -6
  329. package/src/text/path.ts +13 -0
  330. package/src/text/picture.ts +5 -5
  331. package/src/text/runs.ts +80 -0
  332. package/src/transfer/dependencies.ts +4 -2
  333. package/src/transfer/nodes.ts +2 -1
  334. package/src/types.ts +62 -8
  335. package/src/variables/index.ts +1 -0
  336. package/src/variables/lookup.ts +31 -0
  337. package/src/variables/paints.ts +101 -20
  338. package/src/variables/resolution.ts +15 -2
  339. package/src/variables/subtree.ts +1 -1
  340. package/src/vector-network.ts +19 -142
  341. package/dist/random.d.ts +0 -7
  342. package/dist/random.d.ts.map +0 -1
  343. package/dist/random.js +0 -25
  344. package/dist/random.js.map +0 -1
  345. package/src/random.ts +0 -28
@@ -23,6 +23,17 @@ export function lineStepPixels(lineHeight: TextLength | null, fontSize: number):
23
23
  return lineHeight.unit === 'PIXELS' ? pixels : Math.round(pixels)
24
24
  }
25
25
 
26
+ /** How far an automatic line height steps lines when no font metrics measure them. */
27
+ const ESTIMATED_LINE_STEP = 1.2
28
+
29
+ /**
30
+ * How far apart lines step where no font metrics measure them: as `lineStepPixels` steps them,
31
+ * and 1.2 times the font size when automatic.
32
+ */
33
+ export function estimatedLineStep(lineHeight: TextLength | null, fontSize: number): number {
34
+ return lineStepPixels(lineHeight, fontSize) ?? fontSize * ESTIMATED_LINE_STEP
35
+ }
36
+
26
37
  /** A length in pixels, as a bound number variable and most authored formats give one. */
27
38
  export function pixelLength(value: number): TextLength {
28
39
  return { value, unit: 'PIXELS' }
@@ -1,12 +1,38 @@
1
+ import type { VisualBounds } from '../geometry'
1
2
  import type { SceneNode } from '../types'
2
3
 
3
- type TextBoundsNode = Pick<SceneNode, 'type' | 'height' | 'derivedTextHeight'>
4
+ type TextBoxNode = Pick<SceneNode, 'height' | 'textAlignVertical'>
5
+ type TextBoundsNode = TextBoxNode & Pick<SceneNode, 'type' | 'derivedTextHeight'>
6
+
7
+ export type TextLinesReach = Pick<VisualBounds, 'minY' | 'maxY'>
8
+
9
+ /**
10
+ * Where the top of laid-out lines `contentHeight` tall sits in a text's box, by its vertical
11
+ * alignment. Lines taller than the box overflow on the side away from the alignment, as Figma
12
+ * lays them out.
13
+ */
14
+ export function textVerticalOffset(node: TextBoxNode, contentHeight: number): number {
15
+ const available = node.height - contentHeight
16
+ if (node.textAlignVertical === 'CENTER') {
17
+ return available / 2
18
+ }
19
+ if (node.textAlignVertical === 'BOTTOM') {
20
+ return available
21
+ }
22
+ return 0
23
+ }
4
24
 
5
25
  /**
6
- * How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,
7
- * and the renderer starts them at its top.
26
+ * The rows a text draws its lines over, in its own axes: its box, grown by the lines a fixed-size
27
+ * box lets run past it above or below, as in Figma.
8
28
  */
9
- export function textLinesOverflow(node: TextBoundsNode): number {
10
- if (node.type !== 'TEXT' || !node.derivedTextHeight) return 0
11
- return Math.max(0, node.derivedTextHeight - node.height)
29
+ export function textLinesReach(node: TextBoundsNode): TextLinesReach {
30
+ if (node.type !== 'TEXT' || !node.derivedTextHeight) {
31
+ return { minY: 0, maxY: node.height }
32
+ }
33
+ const linesTop = textVerticalOffset(node, node.derivedTextHeight)
34
+ return {
35
+ minY: Math.min(0, linesTop),
36
+ maxY: Math.max(node.height, linesTop + node.derivedTextHeight)
37
+ }
12
38
  }
@@ -0,0 +1,13 @@
1
+ import type { SceneNode } from '../types'
2
+
3
+ export function followsPath(
4
+ node: Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>
5
+ ): boolean {
6
+ const glyphs = node.derivedTextGlyphs ?? []
7
+ if (glyphs.length === 0) {
8
+ return false
9
+ }
10
+ return (
11
+ !!node.textPathData || !!node.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)
12
+ )
13
+ }
@@ -36,16 +36,16 @@ export function textCacheInvalidationChanges(
36
36
  keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) ||
37
37
  TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key))
38
38
  if (glyphsInvalidated && !('derivedLayout' in changes)) invalidated.derivedLayout = null
39
- // A successful path-text edit supplies reflowed glyphs in `changes`. Every
40
- // other mutation path must drop stale baked glyphs and path identity rather
41
- // than pair new text/style with old visible outlines.
42
- if (node.derivedTextGlyphs && glyphsInvalidated && !changes.derivedTextGlyphs) {
39
+ if (glyphsInvalidated && !changes.derivedTextGlyphs) {
43
40
  // Path-text resize supplies transformed glyphs through the resize workflow. A raw box
44
41
  // preview keeps them until that workflow commits or an actual shaping edit occurs.
45
42
  const onlyPathBoxResize =
46
43
  !!node.textPathData && keys.every((key) => key === 'width' || key === 'height')
47
- if (!onlyPathBoxResize) {
44
+ const placesPath = keys.includes('textPathBox') && !!changes.textPathBox
45
+ if (node.derivedTextGlyphs && !onlyPathBoxResize) {
48
46
  invalidated.derivedTextGlyphs = null
47
+ }
48
+ if (node.textPathData && !onlyPathBoxResize && !placesPath) {
49
49
  invalidated.textPathData = null
50
50
  }
51
51
  }
@@ -0,0 +1,80 @@
1
+ import { isEqual } from 'es-toolkit/predicate'
2
+
3
+ import type { CharacterStyleOverride, SceneNode, StyleRun } from '../types'
4
+
5
+ /** The run that styles `text[index]`, if one does. */
6
+ export function styleRunAt(runs: readonly StyleRun[], index: number): StyleRun | undefined {
7
+ return runs.find((run) => index >= run.start && index < run.start + run.length)
8
+ }
9
+
10
+ /** The language `text[index]` is shaped in: its run's, or the text's own. */
11
+ export function textLanguageAt(
12
+ node: Pick<SceneNode, 'styleRuns' | 'textLanguage'>,
13
+ index: number
14
+ ): string | null {
15
+ const language = styleRunAt(node.styleRuns, index)?.style.textLanguage
16
+ return language !== undefined ? language : node.textLanguage
17
+ }
18
+
19
+ /**
20
+ * Adds `style` over `[start, start + length)` to runs built in text order, extending the last
21
+ * run instead when it ends at `start` with an equal style. An empty style or range adds nothing,
22
+ * since those characters keep the text's own style.
23
+ */
24
+ export function appendStyleRun(
25
+ runs: StyleRun[],
26
+ start: number,
27
+ length: number,
28
+ style: CharacterStyleOverride
29
+ ): void {
30
+ if (length <= 0 || Object.keys(style).length === 0) return
31
+ const previous = runs.at(-1)
32
+ if (previous && previous.start + previous.length === start && isEqual(previous.style, style))
33
+ previous.length += length
34
+ else runs.push({ start, length, style })
35
+ }
36
+
37
+ /** A stretch of text in one style: a run's, or the text's own where `style` is null. */
38
+ export interface StyleRunPiece {
39
+ start: number
40
+ end: number
41
+ style: CharacterStyleOverride | null
42
+ }
43
+
44
+ /**
45
+ * The first `length` characters cut at their runs, in order and covering every character once:
46
+ * a run's part that an earlier run already covers, or that lies past the text, is left out.
47
+ * `boundary` moves each cut to where the text may be cut, such as out of a surrogate pair.
48
+ */
49
+ export function styleRunPieces(
50
+ runs: readonly StyleRun[],
51
+ length: number,
52
+ boundary: (index: number) => number = (index) => index
53
+ ): StyleRunPiece[] {
54
+ const pieces: StyleRunPiece[] = []
55
+ let at = 0
56
+ for (const run of runs.toSorted((a, b) => a.start - b.start)) {
57
+ const start = Math.min(length, Math.max(at, boundary(run.start)))
58
+ const end = Math.min(length, boundary(run.start + run.length))
59
+ if (start > at) pieces.push({ start: at, end: start, style: null })
60
+ if (end > start) pieces.push({ start, end, style: run.style })
61
+ at = Math.max(start, end)
62
+ }
63
+ if (at < length) pieces.push({ start: at, end: length, style: null })
64
+ return pieces
65
+ }
66
+
67
+ /** Each of the first `length` characters' overrides, merged from the runs over it in order. */
68
+ export function characterOverrides(
69
+ runs: readonly StyleRun[],
70
+ length: number
71
+ ): CharacterStyleOverride[] {
72
+ const styles = Array.from({ length }, (): CharacterStyleOverride => ({}))
73
+ for (const run of runs) {
74
+ const end = Math.min(length, run.start + run.length)
75
+ for (let index = Math.max(0, run.start); index < end; index++) {
76
+ styles[index] = { ...styles[index], ...run.style }
77
+ }
78
+ }
79
+ return styles
80
+ }
@@ -1,3 +1,5 @@
1
+ import { appendAll } from '@open-pencil/std/arrays'
2
+
1
3
  import type { SceneGraph } from '../graph'
2
4
  import { imagePaintHashes } from '../images'
3
5
  import { overriddenBindingField } from '../instances/overrides'
@@ -70,7 +72,7 @@ export function layerDependencies(
70
72
  (styleLayers ??= sharedStyleLayers(graph)).get(id)
71
73
  const visit = (node: SceneNode): void => {
72
74
  for (const hash of layerImageHashes(node)) images.add(hash)
73
- pending.push(...layerVariableIds(node))
75
+ appendAll(pending, layerVariableIds(node))
74
76
  for (const id of Object.keys(node.variableModes))
75
77
  if (graph.variableCollections.has(id)) collections.add(id)
76
78
  for (const id of referencedStyleIds(node)) {
@@ -113,7 +115,7 @@ export function variableDependencies(
113
115
  variables.add(id)
114
116
  collections.add(variable.collectionId)
115
117
  for (const value of Object.values(variable.valuesByMode)) {
116
- pending.push(...variableValueReferences(value))
118
+ appendAll(pending, variableValueReferences(value))
117
119
  // A kept expression can name a mode of a collection none of its aliases reach.
118
120
  if (!isUnsupportedVariableValue(value)) continue
119
121
  for (const modeId of value.modes) {
@@ -67,7 +67,8 @@ export function prepareNodeTransfer(
67
67
  result.instanceOverrides = remapInstanceOverrideState(source.instanceOverrides, {
68
68
  node,
69
69
  variable,
70
- collection: (id) => refs.collections.get(id)
70
+ collection: (id) => refs.collections.get(id),
71
+ property: (id) => refs.properties.get(id)
71
72
  })
72
73
  Object.assign(
73
74
  result,
package/src/types.ts CHANGED
@@ -43,6 +43,8 @@ export interface NodeChangeObserver {
43
43
  before: (node: SceneNode) => void
44
44
  /** A node was just added. */
45
45
  created: (node: SceneNode) => void
46
+ /** A node is about to take a preview's changes, which no history keeps. */
47
+ previewed?: (node: SceneNode) => void
46
48
  /**
47
49
  * A variable or collection is about to change, be added, or be removed, and is still as it
48
50
  * was: absent, for one about to be added.
@@ -192,7 +194,10 @@ export interface Fill {
192
194
  blendMode?: BlendMode
193
195
  gradientStops?: GradientStop[]
194
196
  gradientTransform?: GradientTransform
197
+ /** The image an IMAGE paint draws, or the poster frame a VIDEO paint draws in its clip's place. */
195
198
  imageHash?: string
199
+ /** A VIDEO paint's clip, which `imageHash`'s poster frame stands in for when drawn. */
200
+ videoHash?: string
196
201
  imageScaleMode?: ImageScaleMode
197
202
  /** A crop's image-space window; Fill, Fit and Tile ignore it. */
198
203
  imageTransform?: GradientTransform
@@ -282,6 +287,33 @@ export interface ProgressiveBlur {
282
287
  endOffset: Vector
283
288
  }
284
289
 
290
+ /**
291
+ * A Noise effect's grain, in Figma's plugin terms: `MONOTONE` grains in the effect's colour,
292
+ * `DUOTONE` in it and `secondaryColor`, `MULTITONE` in many colours at `opacity`. `noiseSize` is a
293
+ * grain's size in px, which Figma keeps within 0 to 100, and `density` how much of the layer the
294
+ * grains cover, 0 to 1. `seed` picks the pattern; Figma's plugin API neither shows nor sets it.
295
+ */
296
+ export interface NoiseEffectParams {
297
+ noiseType: NoiseType
298
+ noiseSize: Vector
299
+ density: number
300
+ secondaryColor?: Color
301
+ opacity?: number
302
+ seed?: number
303
+ }
304
+
305
+ /**
306
+ * A Texture effect's grain, which roughens the layer's edges: `noiseSize` is the grain's size in
307
+ * px, within 0 to 100 as Figma keeps it, and `clipToShape` keeps the roughened layer inside its
308
+ * own outline. The effect's `radius` is how far the grain moves the edges. `.fig` files name the
309
+ * effect `GRAIN`.
310
+ */
311
+ export interface TextureEffectParams {
312
+ noiseSize: Vector
313
+ clipToShape: boolean
314
+ seed?: number
315
+ }
316
+
285
317
  export interface Effect {
286
318
  type:
287
319
  | 'DROP_SHADOW'
@@ -290,6 +322,8 @@ export interface Effect {
290
322
  | 'BACKGROUND_BLUR'
291
323
  | 'FOREGROUND_BLUR'
292
324
  | 'GLASS'
325
+ | 'NOISE'
326
+ | 'TEXTURE'
293
327
  color: Color
294
328
  offset: Vector
295
329
  radius: number
@@ -301,10 +335,14 @@ export interface Effect {
301
335
  glass?: GlassEffectParams
302
336
  /** Set on a layer or background blur that is progressive, and only there. */
303
337
  progressive?: ProgressiveBlur
338
+ /** Set on a `NOISE` effect, and only there. */
339
+ noise?: NoiseEffectParams
340
+ /** Set on a `TEXTURE` effect, and only there. */
341
+ texture?: TextureEffectParams
304
342
  }
305
343
 
306
344
  export type ConstraintType = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'SCALE'
307
- export type TextAutoResize = 'NONE' | 'HEIGHT' | 'WIDTH_AND_HEIGHT' | 'TRUNCATE'
345
+ export type TextAutoResize = 'NONE' | 'HEIGHT' | 'WIDTH_AND_HEIGHT'
308
346
 
309
347
  /** Where a connector end attaches to a layer: a side, the side Figma picks, or a fixed point. */
310
348
  export type ConnectorMagnet =
@@ -649,6 +687,8 @@ export interface CommentReply {
649
687
  author: string
650
688
  /** The author's collaboration color when they wrote it, for their avatar. */
651
689
  authorColor?: Color
690
+ /** The agent that wrote it, for `author` or as itself. */
691
+ agent?: string
652
692
  /** Markdown: bold, italic, strikethrough, links and lists. */
653
693
  text: string
654
694
  createdAt: string
@@ -673,6 +713,8 @@ export interface CommentThread {
673
713
  author: string
674
714
  /** The author's collaboration color when they wrote it, for their avatar. */
675
715
  authorColor?: Color
716
+ /** The agent that wrote it, for `author` or as itself. */
717
+ agent?: string
676
718
  /** Markdown: bold, italic, strikethrough, links and lists. */
677
719
  text: string
678
720
  createdAt: string
@@ -698,7 +740,7 @@ export interface SceneNode {
698
740
  height: number
699
741
  rotation: number
700
742
  source: SourceMetadata
701
- /** Materialized layout hint imported or generated outside the live Yoga layout pass. */
743
+ /** Materialized layout hint imported or generated outside the live layout pass. */
702
744
  derivedLayout: Partial<Rect> | null
703
745
 
704
746
  fills: Fill[]
@@ -789,7 +831,8 @@ export interface SceneNode {
789
831
  primaryAxisSizing: AxisSizingMode
790
832
  counterAxisSizing: AxisSizingMode
791
833
  itemSpacing: number
792
- counterAxisSpacing: number
834
+ /** Space between wrapped lines; null follows `itemSpacing`. Read it with `counterAxisSpacingOf`. */
835
+ counterAxisSpacing: number | null
793
836
  paddingTop: number
794
837
  paddingRight: number
795
838
  paddingBottom: number
@@ -942,9 +985,10 @@ export interface SceneNode {
942
985
  textPicture: Uint8Array | null
943
986
  derivedTextGlyphs: DerivedTextGlyph[] | null
944
987
  /**
945
- * How far a text's lines reach down from its top: measured at its width when its text or width
946
- * changes, or read from the lines a file saved, and never saved itself. A fixed-size box does not
947
- * clip them, as in Figma, so its visual bounds reach this far. Null when not known.
988
+ * How tall a text's lines are, from the top of the first to the bottom of the last: measured at
989
+ * its width when its text or width changes, or read from the lines a file saved, and never saved
990
+ * itself. A fixed-size box does not clip them, as in Figma, so its visual bounds reach past the
991
+ * box on the side away from its vertical alignment (`textLinesReach`). Null when not known.
948
992
  */
949
993
  derivedTextHeight: number | null
950
994
  /** Format-neutral layout path for text-on-path nodes. */
@@ -1128,14 +1172,24 @@ export interface Variable {
1128
1172
  version?: string
1129
1173
  }
1130
1174
 
1131
- /** Scalar numeric node fields accepted by numeric property controls. */
1175
+ /** Scalar numeric node fields accepted by numeric property controls; some may also be null. */
1132
1176
  export type NumericNodeProperty = {
1133
- [K in keyof SceneNode]-?: SceneNode[K] extends number ? K : never
1177
+ [K in keyof SceneNode]-?: SceneNode[K] extends number | null
1178
+ ? number extends SceneNode[K]
1179
+ ? K
1180
+ : never
1181
+ : never
1134
1182
  }[keyof SceneNode]
1135
1183
 
1136
1184
  export interface VariableCollectionMode {
1137
1185
  modeId: string
1138
1186
  name: string
1187
+ /**
1188
+ * The library mode this one came from, for a mode of a collection copied from a library. A
1189
+ * library that renames its mode renames this one with it, so the layers and the document set
1190
+ * to it keep following the library.
1191
+ */
1192
+ libraryModeId?: string
1139
1193
  /**
1140
1194
  * Where the mode applies in CSS: a selector (`[data-theme="dark"]`, `.compact`) or an
1141
1195
  * at-rule prelude (`@media (max-width: 640px)`). Absent means the default for its axis.
@@ -399,6 +399,7 @@ export * from './bindings'
399
399
  export * from './corners'
400
400
  export * from './formula'
401
401
  export * from './formula/schema'
402
+ export * from './lookup'
402
403
  export * from './paints'
403
404
  export * from './schema'
404
405
  export * from './text'
@@ -0,0 +1,31 @@
1
+ import type { SceneGraph } from '../graph'
2
+ import type { VariableCollection, VariableCollectionMode } from '../types'
3
+
4
+ /** What a reference by ID or name finds: one match, none, or several that share the name. */
5
+ export type NamedLookup<T> =
6
+ | { kind: 'found'; value: T }
7
+ | { kind: 'missing' }
8
+ | { kind: 'ambiguous'; matches: T[] }
9
+
10
+ function byName<T extends { name: string }>(items: Iterable<T>, name: string): NamedLookup<T> {
11
+ const matches = [...items].filter((item) => item.name === name)
12
+ if (matches.length === 1) return { kind: 'found', value: matches[0] }
13
+ return matches.length === 0 ? { kind: 'missing' } : { kind: 'ambiguous', matches }
14
+ }
15
+
16
+ /** The collection with this ID or, failing that, the one with this exact name. */
17
+ export function lookupCollection(graph: SceneGraph, ref: string): NamedLookup<VariableCollection> {
18
+ const byId = graph.variableCollections.get(ref)
19
+ if (byId) return { kind: 'found', value: byId }
20
+ return byName(graph.variableCollections.values(), ref)
21
+ }
22
+
23
+ /** The mode of `collection` with this ID or, failing that, the one with this exact name. */
24
+ export function lookupMode(
25
+ collection: VariableCollection,
26
+ ref: string
27
+ ): NamedLookup<VariableCollectionMode> {
28
+ const byId = collection.modes.find((mode) => mode.modeId === ref)
29
+ if (byId) return { kind: 'found', value: byId }
30
+ return byName(collection.modes, ref)
31
+ }
@@ -1,23 +1,28 @@
1
+ import { isEqual } from 'es-toolkit/predicate'
2
+
1
3
  import { copyFills, copyStrokes } from '../copy'
2
4
  import type { SceneGraph } from '../graph'
3
5
  import { hasInstanceOverride } from '../instances/overrides'
4
6
  import type { Color } from '../primitives'
5
7
  import type { Fill, SceneNode, Stroke } from '../types'
6
8
  import { paintBindingTarget, type PaintBindingList } from './fields'
7
- import { collectionsResolving, getNodeVariableModeId } from './resolution'
9
+ import { collectionsResolving, getNodeExplicitVariableModeId } from './resolution'
8
10
  import { subtreeNodes } from './subtree'
9
11
 
10
12
  /**
11
13
  * Figma keeps a bound paint's color and opacity as a cache of its variable: it draws and reads
12
14
  * what the paint holds, and writes the variable's color into it again only once the color the
13
- * variable gives that layer changes, so an edit to the paint sticks until then. The color each
14
- * binding last gave its paint lives here, beside the graph and never saved, by layer and binding
15
- * field. A layer without an entry, such as one just loaded, pasted, or restored, counts its
16
- * paint's own color as the last one applied.
15
+ * variable gives that layer changes, or the mode set for the layer changes, so an edit to the
16
+ * paint sticks until then. The color each binding last gave its paint, and the modes set for the
17
+ * layer then, live here, beside the graph and never saved, by layer and binding field. A layer
18
+ * without an entry, such as one just restored, counts its paint's own color as the last one
19
+ * applied, in the modes it has now.
17
20
  */
18
- interface AppliedColor {
21
+ export interface AppliedColor {
19
22
  readonly variableId: string
20
23
  readonly color: Color
24
+ /** The mode set for the layer, or null, in each collection the variable resolves through. */
25
+ readonly modes: Readonly<Record<string, string | null>>
21
26
  }
22
27
 
23
28
  const appliedColors = new WeakMap<SceneNode, Map<string, AppliedColor>>()
@@ -64,9 +69,32 @@ function sameColor(a: Color, b: Color): boolean {
64
69
  )
65
70
  }
66
71
 
67
- function lastApplied(node: SceneNode, bound: BoundPaint, paint: Fill): Color {
72
+ /**
73
+ * The modes set for a layer, or null, in the collections a variable resolves through. Figma
74
+ * refreshes a bound paint whenever one of them changes, even to a mode giving the same color.
75
+ */
76
+ function explicitModes(
77
+ graph: SceneGraph,
78
+ node: SceneNode,
79
+ variableId: string
80
+ ): Record<string, string | null> {
81
+ const modes: Record<string, string | null> = {}
82
+ for (const collectionId of collectionsResolving(graph, [variableId]))
83
+ modes[collectionId] = getNodeExplicitVariableModeId(graph, node.id, collectionId)
84
+ return modes
85
+ }
86
+
87
+ /** Whether the color a binding last applied is stale: another color, or set in other modes. */
88
+ function staleApplied(
89
+ node: SceneNode,
90
+ bound: BoundPaint,
91
+ paint: Fill,
92
+ color: Color,
93
+ modes: Readonly<Record<string, string | null>>
94
+ ): boolean {
68
95
  const entry = appliedColors.get(node)?.get(bound.field)
69
- return entry?.variableId === bound.variableId ? entry.color : paintColor(paint)
96
+ if (entry?.variableId !== bound.variableId) return !sameColor(paintColor(paint), color)
97
+ return !sameColor(entry.color, color) || !isEqual(entry.modes, modes)
70
98
  }
71
99
 
72
100
  /**
@@ -78,13 +106,63 @@ export function copyAppliedBoundPaints(source: SceneNode, copy: SceneNode): void
78
106
  if (entries) appliedColors.set(copy, new Map(entries))
79
107
  }
80
108
 
81
- function recordApplied(node: SceneNode, bound: BoundPaint, color: Color): void {
109
+ /** The colors copied layers' bindings last applied, by layer id, as a copy captured them. */
110
+ export type AppliedBoundPaints = ReadonlyMap<string, ReadonlyMap<string, AppliedColor>>
111
+
112
+ /**
113
+ * The colors the bindings of the layers `nodeIds` names last applied, captured when they are
114
+ * copied, so a paste counts what the copied paints were applied from, not what the source has now.
115
+ */
116
+ export function captureAppliedBoundPaints(
117
+ graph: SceneGraph,
118
+ nodeIds: Iterable<string>
119
+ ): AppliedBoundPaints {
120
+ const captured = new Map<string, ReadonlyMap<string, AppliedColor>>()
121
+ for (const id of nodeIds) {
122
+ const node = graph.nodes.get(id)
123
+ const entries = node && appliedColors.get(node)
124
+ if (entries) captured.set(id, new Map(entries))
125
+ }
126
+ return captured
127
+ }
128
+
129
+ /**
130
+ * Pasted layers keep their paints, edits included, as Figma's copies do. One copied in this
131
+ * document takes the colors its source's bindings had last applied when it was copied, so a paste
132
+ * into another mode refreshes them as a move there would; one from elsewhere counts the colors
133
+ * its variables give it now as applied, as a loaded document does. `copies` maps each copied
134
+ * layer's id to its copy's.
135
+ */
136
+ export function keepPastedBoundPaints(
137
+ graph: SceneGraph,
138
+ copies: ReadonlyMap<string, string>,
139
+ applied: AppliedBoundPaints
140
+ ): void {
141
+ for (const [sourceId, copyId] of copies) {
142
+ const copy = graph.nodes.get(copyId)
143
+ if (!copy || !hasBoundPaints(copy)) continue
144
+ const entries = applied.get(sourceId)
145
+ if (!entries) {
146
+ recordWrittenBoundPaints(graph, copy, { fills: copy.fills, strokes: copy.strokes })
147
+ continue
148
+ }
149
+ appliedColors.set(copy, new Map(entries))
150
+ refresh(graph, copy, NONE_FORCED)
151
+ }
152
+ }
153
+
154
+ function recordApplied(
155
+ node: SceneNode,
156
+ bound: BoundPaint,
157
+ color: Color,
158
+ modes: Readonly<Record<string, string | null>>
159
+ ): void {
82
160
  let entries = appliedColors.get(node)
83
161
  if (!entries) {
84
162
  entries = new Map()
85
163
  appliedColors.set(node, entries)
86
164
  }
87
- entries.set(bound.field, { variableId: bound.variableId, color: { ...color } })
165
+ entries.set(bound.field, { variableId: bound.variableId, color: { ...color }, modes })
88
166
  }
89
167
 
90
168
  /** The variable's RGB at full alpha in the paint, and its alpha as the paint's opacity. */
@@ -143,9 +221,10 @@ function refresh(graph: SceneGraph, node: SceneNode, forced: (field: string) =>
143
221
  const color = graph.resolveColorVariableForNode(node.id, bound.variableId)
144
222
  const paint = node[bound.list].at(bound.index)
145
223
  if (!color || !paint) continue
146
- const last = lastApplied(node, bound, paint)
147
- recordApplied(node, bound, color)
148
- if ((!forced(bound.field) && sameColor(last, color)) || showsColor(paint, color)) continue
224
+ const modes = explicitModes(graph, node, bound.variableId)
225
+ const stale = staleApplied(node, bound, paint, color, modes)
226
+ recordApplied(node, bound, color, modes)
227
+ if ((!forced(bound.field) && !stale) || showsColor(paint, color)) continue
149
228
  if (bound.list === 'fills') {
150
229
  fills ??= copyFills(node.fills)
151
230
  applyColor(fills[bound.index], color)
@@ -204,15 +283,15 @@ export function recordWrittenBoundPaints(
204
283
  for (const bound of boundPaints(node)) {
205
284
  if (!written[bound.list]) continue
206
285
  const color = graph.resolveColorVariableForNode(node.id, bound.variableId)
207
- if (color) recordApplied(node, bound, color)
286
+ if (color) recordApplied(node, bound, color, explicitModes(graph, node, bound.variableId))
208
287
  }
209
288
  }
210
289
 
211
290
  /**
212
291
  * Refreshes the bound paints in a moved layer's subtree that resolve through a collection whose
213
- * mode the move changed, as Figma does when a layer enters a frame or page in another mode. A
214
- * move between parents in the same modes, or of layers that bind no paint, costs no more than
215
- * comparing those modes.
292
+ * mode set the move changed, as Figma does when a layer enters a frame or page that sets another
293
+ * mode, or one where none was. A move between parents setting the same modes, or of layers that
294
+ * bind no paint, costs no more than comparing those modes.
216
295
  */
217
296
  export function refreshMovedBoundPaints(
218
297
  graph: SceneGraph,
@@ -227,7 +306,8 @@ export function refreshMovedBoundPaints(
227
306
  [...graph.variableCollections.keys()].filter(
228
307
  (id) =>
229
308
  !previous ||
230
- getNodeVariableModeId(graph, previous, id) !== getNodeVariableModeId(graph, parentId, id)
309
+ getNodeExplicitVariableModeId(graph, previous, id) !==
310
+ getNodeExplicitVariableModeId(graph, parentId, id)
231
311
  )
232
312
  )
233
313
  if (changed.size === 0) return
@@ -289,8 +369,9 @@ export function keepCopyBoundPaints(
289
369
  }
290
370
  const color = graph.resolveColorVariableForNode(target.id, variableId)
291
371
  if (!color) return
292
- if (!keeps || !sameColor(lastApplied(target, bound, own), color)) applyColor(paint, color)
293
- recordApplied(target, bound, color)
372
+ const modes = explicitModes(graph, target, variableId)
373
+ if (!keeps || staleApplied(target, bound, own, color, modes)) applyColor(paint, color)
374
+ recordApplied(target, bound, color, modes)
294
375
  })
295
376
  }
296
377
  }
@@ -1,3 +1,5 @@
1
+ import { appendAll } from '@open-pencil/std/arrays'
2
+
1
3
  import type { SceneGraph } from '../graph'
2
4
  import type { Color } from '../primitives'
3
5
  import type { Variable, VariableLiteral, VariableValue } from '../types'
@@ -17,13 +19,24 @@ export function getNodeVariableModeId(
17
19
  nodeId: string,
18
20
  collectionId: string
19
21
  ): string {
22
+ return (
23
+ getNodeExplicitVariableModeId(graph, nodeId, collectionId) ?? defaultModeId(graph, collectionId)
24
+ )
25
+ }
26
+
27
+ /** The nearest mode set on a node or an ancestor for a collection, or null where none is. */
28
+ export function getNodeExplicitVariableModeId(
29
+ graph: SceneGraph,
30
+ nodeId: string,
31
+ collectionId: string
32
+ ): string | null {
20
33
  let node = graph.nodes.get(nodeId)
21
34
  while (node) {
22
35
  const modeId = node.variableModes[collectionId]
23
36
  if (modeId) return modeId
24
37
  node = node.parentId ? graph.nodes.get(node.parentId) : undefined
25
38
  }
26
- return defaultModeId(graph, collectionId)
39
+ return null
27
40
  }
28
41
 
29
42
  /**
@@ -44,7 +57,7 @@ export function collectionsResolving(
44
57
  if (!variable) continue
45
58
  collections.add(variable.collectionId)
46
59
  for (const value of Object.values(variable.valuesByMode))
47
- pending.push(...variableValueReferences(value))
60
+ appendAll(pending, variableValueReferences(value))
48
61
  }
49
62
  return collections
50
63
  }
@@ -9,7 +9,7 @@ export function subtreeNodes(graph: SceneGraph, roots: Iterable<string>): SceneN
9
9
  const node = graph.getNode(id)
10
10
  if (!node) continue
11
11
  nodes.push(node)
12
- pending.push(...node.childIds)
12
+ for (const childId of node.childIds) pending.push(childId)
13
13
  }
14
14
  return nodes
15
15
  }