@pairdraw/scene-graph 0.19.2 → 0.21.0

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 (285) hide show
  1. package/dist/color/index.d.ts +28 -7
  2. package/dist/color/index.d.ts.map +1 -1
  3. package/dist/color/index.js +40 -15
  4. package/dist/color/index.js.map +1 -1
  5. package/dist/color/management.d.ts +19 -6
  6. package/dist/color/management.d.ts.map +1 -1
  7. package/dist/color/management.js +56 -1
  8. package/dist/color/management.js.map +1 -1
  9. package/dist/color/profile.d.ts +32 -0
  10. package/dist/color/profile.d.ts.map +1 -0
  11. package/dist/color/profile.js +140 -0
  12. package/dist/color/profile.js.map +1 -0
  13. package/dist/comments/index.d.ts +2 -2
  14. package/dist/comments/index.js +2 -2
  15. package/dist/comments/merge.d.ts.map +1 -1
  16. package/dist/comments/merge.js +1 -0
  17. package/dist/comments/merge.js.map +1 -1
  18. package/dist/comments/schema.d.ts +3 -1
  19. package/dist/comments/schema.d.ts.map +1 -1
  20. package/dist/comments/schema.js +19 -2
  21. package/dist/comments/schema.js.map +1 -1
  22. package/dist/comments/threads.d.ts +3 -1
  23. package/dist/comments/threads.d.ts.map +1 -1
  24. package/dist/comments/threads.js +2 -1
  25. package/dist/comments/threads.js.map +1 -1
  26. package/dist/components/index.d.ts +2 -2
  27. package/dist/components/index.js +2 -2
  28. package/dist/components/properties.d.ts.map +1 -1
  29. package/dist/components/properties.js +7 -7
  30. package/dist/components/properties.js.map +1 -1
  31. package/dist/components/variants.d.ts +12 -1
  32. package/dist/components/variants.d.ts.map +1 -1
  33. package/dist/components/variants.js +30 -1
  34. package/dist/components/variants.js.map +1 -1
  35. package/dist/constants.d.ts +25 -1
  36. package/dist/constants.d.ts.map +1 -1
  37. package/dist/constants.js +94 -1
  38. package/dist/constants.js.map +1 -1
  39. package/dist/copy.d.ts.map +1 -1
  40. package/dist/copy.js +17 -1
  41. package/dist/copy.js.map +1 -1
  42. package/dist/css/index.d.ts +2 -2
  43. package/dist/css/index.js +2 -2
  44. package/dist/css/shadows.d.ts +2 -2
  45. package/dist/css/shadows.d.ts.map +1 -1
  46. package/dist/css/shadows.js +4 -4
  47. package/dist/css/shadows.js.map +1 -1
  48. package/dist/css/text.d.ts +17 -1
  49. package/dist/css/text.d.ts.map +1 -1
  50. package/dist/css/text.js +62 -1
  51. package/dist/css/text.js.map +1 -1
  52. package/dist/css/values.d.ts +7 -2
  53. package/dist/css/values.d.ts.map +1 -1
  54. package/dist/css/values.js +8 -4
  55. package/dist/css/values.js.map +1 -1
  56. package/dist/design-memory/index.d.ts +3 -0
  57. package/dist/design-memory/index.js +3 -0
  58. package/dist/design-memory/model.d.ts +33 -0
  59. package/dist/design-memory/model.d.ts.map +1 -0
  60. package/dist/design-memory/model.js +142 -0
  61. package/dist/design-memory/model.js.map +1 -0
  62. package/dist/design-memory/schema.d.ts +76 -0
  63. package/dist/design-memory/schema.d.ts.map +1 -0
  64. package/dist/design-memory/schema.js +72 -0
  65. package/dist/design-memory/schema.js.map +1 -0
  66. package/dist/effects.d.ts +7 -4
  67. package/dist/effects.d.ts.map +1 -1
  68. package/dist/effects.js +9 -4
  69. package/dist/effects.js.map +1 -1
  70. package/dist/empty-values.js +102 -0
  71. package/dist/empty-values.js.map +1 -0
  72. package/dist/fields/components.d.ts +9 -0
  73. package/dist/fields/components.d.ts.map +1 -0
  74. package/dist/fields/components.js +24 -0
  75. package/dist/fields/components.js.map +1 -0
  76. package/dist/fields/index.d.ts +3 -2
  77. package/dist/fields/index.js +3 -2
  78. package/dist/fields/layout.d.ts +3 -1
  79. package/dist/fields/layout.d.ts.map +1 -1
  80. package/dist/fields/layout.js +10 -1
  81. package/dist/fields/layout.js.map +1 -1
  82. package/dist/graph.d.ts +12 -1
  83. package/dist/graph.d.ts.map +1 -1
  84. package/dist/graph.js +39 -7
  85. package/dist/graph.js.map +1 -1
  86. package/dist/grid-values.d.ts +10 -0
  87. package/dist/grid-values.d.ts.map +1 -0
  88. package/dist/grid-values.js +53 -0
  89. package/dist/grid-values.js.map +1 -0
  90. package/dist/hit-test/drop.d.ts +20 -0
  91. package/dist/hit-test/drop.d.ts.map +1 -0
  92. package/dist/hit-test/drop.js +54 -0
  93. package/dist/hit-test/drop.js.map +1 -0
  94. package/dist/hit-test/geometry.js +86 -0
  95. package/dist/hit-test/geometry.js.map +1 -0
  96. package/dist/hit-test/masks.d.ts +14 -0
  97. package/dist/hit-test/masks.d.ts.map +1 -0
  98. package/dist/hit-test/masks.js +41 -0
  99. package/dist/hit-test/masks.js.map +1 -0
  100. package/dist/hit-test/paint.d.ts +6 -0
  101. package/dist/hit-test/paint.d.ts.map +1 -0
  102. package/dist/hit-test/paint.js +19 -0
  103. package/dist/hit-test/paint.js.map +1 -0
  104. package/dist/hit-test.d.ts +4 -15
  105. package/dist/hit-test.d.ts.map +1 -1
  106. package/dist/hit-test.js +5 -173
  107. package/dist/hit-test.js.map +1 -1
  108. package/dist/images.d.ts +3 -2
  109. package/dist/images.d.ts.map +1 -1
  110. package/dist/images.js +18 -2
  111. package/dist/images.js.map +1 -1
  112. package/dist/index.d.ts +2 -2
  113. package/dist/instances/copies.js +2 -1
  114. package/dist/instances/copies.js.map +1 -1
  115. package/dist/instances/fields.d.ts.map +1 -1
  116. package/dist/instances/fields.js +2 -0
  117. package/dist/instances/fields.js.map +1 -1
  118. package/dist/instances/index.d.ts +2 -1
  119. package/dist/instances/index.d.ts.map +1 -1
  120. package/dist/instances/index.js +13 -12
  121. package/dist/instances/index.js.map +1 -1
  122. package/dist/instances/overrides.d.ts +15 -1
  123. package/dist/instances/overrides.d.ts.map +1 -1
  124. package/dist/instances/overrides.js +37 -1
  125. package/dist/instances/overrides.js.map +1 -1
  126. package/dist/instances/source-walk.d.ts +12 -0
  127. package/dist/instances/source-walk.d.ts.map +1 -0
  128. package/dist/instances/swap-overrides.js +3 -3
  129. package/dist/instances/swap-overrides.js.map +1 -1
  130. package/dist/instances/sync.js +9 -7
  131. package/dist/instances/sync.js.map +1 -1
  132. package/dist/node-defaults.d.ts.map +1 -1
  133. package/dist/node-defaults.js +43 -38
  134. package/dist/node-defaults.js.map +1 -1
  135. package/dist/plugin-data/fields.d.ts +90 -0
  136. package/dist/plugin-data/fields.d.ts.map +1 -1
  137. package/dist/plugin-data/fields.js +33 -24
  138. package/dist/plugin-data/fields.js.map +1 -1
  139. package/dist/plugin-data/index.d.ts +2 -2
  140. package/dist/plugin-data/index.js +2 -2
  141. package/dist/plugin-data/schema.d.ts +6 -1
  142. package/dist/plugin-data/schema.d.ts.map +1 -1
  143. package/dist/plugin-data/schema.js +24 -1
  144. package/dist/plugin-data/schema.js.map +1 -1
  145. package/dist/preview.d.ts.map +1 -1
  146. package/dist/preview.js +2 -0
  147. package/dist/preview.js.map +1 -1
  148. package/dist/scaling/node.d.ts.map +1 -1
  149. package/dist/scaling/node.js +5 -1
  150. package/dist/scaling/node.js.map +1 -1
  151. package/dist/shaders/animation.d.ts +21 -0
  152. package/dist/shaders/animation.d.ts.map +1 -0
  153. package/dist/shaders/animation.js +25 -0
  154. package/dist/shaders/animation.js.map +1 -0
  155. package/dist/shaders/index.d.ts +2 -1
  156. package/dist/shaders/index.js +2 -1
  157. package/dist/slots/content.d.ts.map +1 -1
  158. package/dist/slots/content.js +4 -4
  159. package/dist/slots/content.js.map +1 -1
  160. package/dist/statuses/index.d.ts +2 -2
  161. package/dist/statuses/index.js +2 -2
  162. package/dist/statuses/workflow.d.ts +3 -1
  163. package/dist/statuses/workflow.d.ts.map +1 -1
  164. package/dist/statuses/workflow.js +6 -2
  165. package/dist/statuses/workflow.js.map +1 -1
  166. package/dist/token-sources/document.d.ts +26 -0
  167. package/dist/token-sources/document.d.ts.map +1 -0
  168. package/dist/token-sources/document.js +80 -0
  169. package/dist/token-sources/document.js.map +1 -0
  170. package/dist/token-sources/index.d.ts +3 -0
  171. package/dist/token-sources/index.js +3 -0
  172. package/dist/token-sources/schema.d.ts +43 -0
  173. package/dist/token-sources/schema.d.ts.map +1 -0
  174. package/dist/token-sources/schema.js +50 -0
  175. package/dist/token-sources/schema.js.map +1 -0
  176. package/dist/transfer/variables.d.ts.map +1 -1
  177. package/dist/transfer/variables.js +1 -1
  178. package/dist/transfer/variables.js.map +1 -1
  179. package/dist/types.d.ts +135 -15
  180. package/dist/types.d.ts.map +1 -1
  181. package/dist/types.js.map +1 -1
  182. package/dist/variables/bindings.d.ts +6 -5
  183. package/dist/variables/bindings.d.ts.map +1 -1
  184. package/dist/variables/bindings.js +24 -16
  185. package/dist/variables/bindings.js.map +1 -1
  186. package/dist/variables/formula/index.d.ts.map +1 -1
  187. package/dist/variables/formula/index.js +12 -6
  188. package/dist/variables/formula/index.js.map +1 -1
  189. package/dist/variables/index.d.ts +14 -1
  190. package/dist/variables/index.d.ts.map +1 -1
  191. package/dist/variables/index.js +38 -10
  192. package/dist/variables/index.js.map +1 -1
  193. package/dist/variables/paints.d.ts +9 -8
  194. package/dist/variables/paints.d.ts.map +1 -1
  195. package/dist/variables/paints.js +35 -26
  196. package/dist/variables/paints.js.map +1 -1
  197. package/dist/variables/resolver.d.ts +45 -0
  198. package/dist/variables/resolver.d.ts.map +1 -0
  199. package/dist/variables/resolver.js +106 -0
  200. package/dist/variables/resolver.js.map +1 -0
  201. package/dist/variations/copy.d.ts +16 -0
  202. package/dist/variations/copy.d.ts.map +1 -0
  203. package/dist/variations/copy.js +78 -0
  204. package/dist/variations/copy.js.map +1 -0
  205. package/dist/variations/index.d.ts +6 -0
  206. package/dist/variations/index.js +6 -0
  207. package/dist/variations/match.d.ts +23 -0
  208. package/dist/variations/match.d.ts.map +1 -0
  209. package/dist/variations/match.js +80 -0
  210. package/dist/variations/match.js.map +1 -0
  211. package/dist/variations/model.d.ts +39 -0
  212. package/dist/variations/model.d.ts.map +1 -0
  213. package/dist/variations/model.js +90 -0
  214. package/dist/variations/model.js.map +1 -0
  215. package/dist/variations/pick.d.ts +43 -0
  216. package/dist/variations/pick.d.ts.map +1 -0
  217. package/dist/variations/pick.js +211 -0
  218. package/dist/variations/pick.js.map +1 -0
  219. package/dist/variations/schema.d.ts +27 -0
  220. package/dist/variations/schema.d.ts.map +1 -0
  221. package/dist/variations/schema.js +27 -0
  222. package/dist/variations/schema.js.map +1 -0
  223. package/package.json +21 -1
  224. package/src/color/index.ts +43 -9
  225. package/src/color/management.ts +54 -1
  226. package/src/color/profile.ts +131 -0
  227. package/src/comments/merge.ts +3 -0
  228. package/src/comments/schema.ts +32 -2
  229. package/src/comments/threads.ts +5 -2
  230. package/src/components/properties.ts +13 -7
  231. package/src/components/variants.ts +39 -0
  232. package/src/constants.ts +75 -0
  233. package/src/copy.ts +20 -1
  234. package/src/css/index.ts +7 -1
  235. package/src/css/shadows.ts +8 -5
  236. package/src/css/text.ts +62 -0
  237. package/src/css/values.ts +12 -5
  238. package/src/design-memory/index.ts +2 -0
  239. package/src/design-memory/model.ts +143 -0
  240. package/src/design-memory/schema.ts +84 -0
  241. package/src/effects.ts +16 -7
  242. package/src/empty-values.ts +117 -0
  243. package/src/fields/components.ts +21 -0
  244. package/src/fields/index.ts +1 -0
  245. package/src/fields/layout.ts +10 -0
  246. package/src/graph.ts +50 -6
  247. package/src/grid-values.ts +47 -0
  248. package/src/hit-test/drop.ts +90 -0
  249. package/src/hit-test/geometry.ts +131 -0
  250. package/src/hit-test/masks.ts +57 -0
  251. package/src/hit-test/paint.ts +24 -0
  252. package/src/hit-test.ts +8 -277
  253. package/src/images.ts +27 -3
  254. package/src/instances/copies.ts +2 -1
  255. package/src/instances/fields.ts +2 -0
  256. package/src/instances/index.ts +20 -11
  257. package/src/instances/overrides.ts +49 -0
  258. package/src/instances/swap-overrides.ts +3 -2
  259. package/src/instances/sync.ts +11 -7
  260. package/src/node-defaults.ts +51 -41
  261. package/src/plugin-data/fields.ts +34 -32
  262. package/src/plugin-data/index.ts +1 -0
  263. package/src/plugin-data/schema.ts +30 -0
  264. package/src/preview.ts +2 -0
  265. package/src/scaling/node.ts +7 -2
  266. package/src/shaders/animation.ts +39 -0
  267. package/src/shaders/index.ts +1 -0
  268. package/src/slots/content.ts +8 -4
  269. package/src/statuses/workflow.ts +6 -4
  270. package/src/token-sources/document.ts +104 -0
  271. package/src/token-sources/index.ts +2 -0
  272. package/src/token-sources/schema.ts +59 -0
  273. package/src/transfer/variables.ts +2 -1
  274. package/src/types.ts +145 -14
  275. package/src/variables/bindings.ts +35 -18
  276. package/src/variables/formula/index.ts +19 -18
  277. package/src/variables/index.ts +49 -10
  278. package/src/variables/paints.ts +64 -29
  279. package/src/variables/resolver.ts +178 -0
  280. package/src/variations/copy.ts +89 -0
  281. package/src/variations/index.ts +5 -0
  282. package/src/variations/match.ts +100 -0
  283. package/src/variations/model.ts +132 -0
  284. package/src/variations/pick.ts +293 -0
  285. package/src/variations/schema.ts +29 -0
@@ -0,0 +1,21 @@
1
+ import { ShaderPreset } from "./schema.js";
2
+ //#region src/shaders/animation.d.ts
3
+ /**
4
+ * What the library says of an effect's motion: whether it is driven by time, and whether a
5
+ * `speed` prop of its own decides how fast it moves.
6
+ */
7
+ interface ShaderEffectMotion {
8
+ animates: boolean;
9
+ speed: boolean;
10
+ }
11
+ /** What the caller knows of an effect's motion, or undefined for an effect it does not know yet. */
12
+ type ShaderMotion = (type: string) => ShaderEffectMotion | undefined;
13
+ /**
14
+ * Whether `preset` changes between frames: any of its effects animates. A preset of still
15
+ * effects, or one whose animated effects are all at `speed: 0`, draws one picture forever and
16
+ * does not need a player.
17
+ */
18
+ declare function presetAnimates(preset: ShaderPreset, motion: ShaderMotion): boolean;
19
+ //#endregion
20
+ export { ShaderEffectMotion, ShaderMotion, presetAnimates };
21
+ //# sourceMappingURL=animation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation.d.ts","names":[],"sources":["../../src/shaders/animation.ts"],"mappings":";;;;;;UAMiB;EACf;EACA;;;KAIU,gBAAgB,iBAAiB;;;;;;iBAwB7B,eAAe,QAAQ,cAAc,QAAQ"}
@@ -0,0 +1,25 @@
1
+ //#region src/shaders/animation.ts
2
+ /**
3
+ * Whether `component` draws a picture that changes with time. An effect missing from the
4
+ * library's metadata counts as animated, so a newer effect plays rather than freezing; `speed: 0`
5
+ * and an `animated` switch turned off stop it.
6
+ */
7
+ function componentAnimates(component, motion) {
8
+ const props = component.props ?? {};
9
+ if (props.animated === true) return true;
10
+ const known = motion(component.type);
11
+ if (typeof props.speed === "number" ? props.speed !== 0 : known === void 0 || known.animates || known.speed) return true;
12
+ return (component.children ?? []).some((child) => componentAnimates(child, motion));
13
+ }
14
+ /**
15
+ * Whether `preset` changes between frames: any of its effects animates. A preset of still
16
+ * effects, or one whose animated effects are all at `speed: 0`, draws one picture forever and
17
+ * does not need a player.
18
+ */
19
+ function presetAnimates(preset, motion) {
20
+ return preset.components.some((component) => componentAnimates(component, motion));
21
+ }
22
+ //#endregion
23
+ export { presetAnimates };
24
+
25
+ //# sourceMappingURL=animation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation.js","names":[],"sources":["../../src/shaders/animation.ts"],"sourcesContent":["import type { ShaderComponent, ShaderPreset } from './schema'\n\n/**\n * What the library says of an effect's motion: whether it is driven by time, and whether a\n * `speed` prop of its own decides how fast it moves.\n */\nexport interface ShaderEffectMotion {\n animates: boolean\n speed: boolean\n}\n\n/** What the caller knows of an effect's motion, or undefined for an effect it does not know yet. */\nexport type ShaderMotion = (type: string) => ShaderEffectMotion | undefined\n\n/**\n * Whether `component` draws a picture that changes with time. An effect missing from the\n * library's metadata counts as animated, so a newer effect plays rather than freezing; `speed: 0`\n * and an `animated` switch turned off stop it.\n */\nfunction componentAnimates(component: ShaderComponent, motion: ShaderMotion): boolean {\n const props = component.props ?? {}\n if (props.animated === true) return true\n const known = motion(component.type)\n const moves =\n typeof props.speed === 'number'\n ? props.speed !== 0\n : known === undefined || known.animates || known.speed\n if (moves) return true\n return (component.children ?? []).some((child) => componentAnimates(child, motion))\n}\n\n/**\n * Whether `preset` changes between frames: any of its effects animates. A preset of still\n * effects, or one whose animated effects are all at `speed: 0`, draws one picture forever and\n * does not need a player.\n */\nexport function presetAnimates(preset: ShaderPreset, motion: ShaderMotion): boolean {\n return preset.components.some((component) => componentAnimates(component, motion))\n}\n"],"mappings":";;;;;;AAmBA,SAAS,kBAAkB,WAA4B,QAA+B;CACpF,MAAM,QAAQ,UAAU,SAAS,CAAC;CAClC,IAAI,MAAM,aAAa,MAAM,OAAO;CACpC,MAAM,QAAQ,OAAO,UAAU,IAAI;CAKnC,IAHE,OAAO,MAAM,UAAU,WACnB,MAAM,UAAU,IAChB,UAAU,KAAA,KAAa,MAAM,YAAY,MAAM,OAC1C,OAAO;CAClB,QAAQ,UAAU,YAAY,CAAC,EAAA,CAAG,MAAM,UAAU,kBAAkB,OAAO,MAAM,CAAC;AACpF;;;;;;AAOA,SAAgB,eAAe,QAAsB,QAA+B;CAClF,OAAO,OAAO,WAAW,MAAM,cAAc,kBAAkB,WAAW,MAAM,CAAC;AACnF"}
@@ -1,5 +1,6 @@
1
1
  import { ShaderComponent, ShaderPaint, ShaderPreset, ShaderPresetPaint, ShaderSourcePaint, ShaderUniformValue, shaderPaintSchema, shaderPresetPaintSchema, shaderPresetSchema, shaderSourcePaintSchema, shaderUniformValueSchema } from "./schema.js";
2
+ import { ShaderEffectMotion, ShaderMotion, presetAnimates } from "./animation.js";
2
3
  import { SHADER_MAX_UNIFORMS, SHADER_MAX_UNIFORM_FLOATS, SHADER_SOURCE_MAX_BYTES, ShaderAutomaticInput, ShaderUniform, ShaderUniformKind, ShaderUniforms, parseShaderUniforms } from "./directives.js";
3
4
  import { createShaderPaint, createShaderSourcePaint, hasShaderPaint, isShaderFrameCurrent, isShaderPresetPaint, isShaderSourcePaint, readShaderPaints, shaderFrameKey, shaderOfPaint, shaderPresetKey, shaderSourceKey, withShaderPaints } from "./model.js";
4
5
  import { ShaderFrameEncoding, shaderFrameEncoding, shaderFramePixels } from "./still.js";
5
- export { SHADER_MAX_UNIFORMS, SHADER_MAX_UNIFORM_FLOATS, SHADER_SOURCE_MAX_BYTES, ShaderAutomaticInput, ShaderComponent, ShaderFrameEncoding, ShaderPaint, ShaderPreset, ShaderPresetPaint, ShaderSourcePaint, ShaderUniform, ShaderUniformKind, ShaderUniformValue, ShaderUniforms, createShaderPaint, createShaderSourcePaint, hasShaderPaint, isShaderFrameCurrent, isShaderPresetPaint, isShaderSourcePaint, parseShaderUniforms, readShaderPaints, shaderFrameEncoding, shaderFrameKey, shaderFramePixels, shaderOfPaint, shaderPaintSchema, shaderPresetKey, shaderPresetPaintSchema, shaderPresetSchema, shaderSourceKey, shaderSourcePaintSchema, shaderUniformValueSchema, withShaderPaints };
6
+ export { SHADER_MAX_UNIFORMS, SHADER_MAX_UNIFORM_FLOATS, SHADER_SOURCE_MAX_BYTES, ShaderAutomaticInput, ShaderComponent, ShaderEffectMotion, ShaderFrameEncoding, ShaderMotion, ShaderPaint, ShaderPreset, ShaderPresetPaint, ShaderSourcePaint, ShaderUniform, ShaderUniformKind, ShaderUniformValue, ShaderUniforms, createShaderPaint, createShaderSourcePaint, hasShaderPaint, isShaderFrameCurrent, isShaderPresetPaint, isShaderSourcePaint, parseShaderUniforms, presetAnimates, readShaderPaints, shaderFrameEncoding, shaderFrameKey, shaderFramePixels, shaderOfPaint, shaderPaintSchema, shaderPresetKey, shaderPresetPaintSchema, shaderPresetSchema, shaderSourceKey, shaderSourcePaintSchema, shaderUniformValueSchema, withShaderPaints };
@@ -1,5 +1,6 @@
1
1
  import { shaderPaintSchema, shaderPresetPaintSchema, shaderPresetSchema, shaderSourcePaintSchema, shaderUniformValueSchema } from "./schema.js";
2
2
  import { createShaderPaint, createShaderSourcePaint, hasShaderPaint, isShaderFrameCurrent, isShaderPresetPaint, isShaderSourcePaint, readShaderPaints, shaderFrameKey, shaderOfPaint, shaderPresetKey, shaderSourceKey, withShaderPaints } from "./model.js";
3
+ import { presetAnimates } from "./animation.js";
3
4
  import { SHADER_MAX_UNIFORMS, SHADER_MAX_UNIFORM_FLOATS, SHADER_SOURCE_MAX_BYTES, parseShaderUniforms } from "./directives.js";
4
5
  import { shaderFrameEncoding, shaderFramePixels } from "./still.js";
5
- export { SHADER_MAX_UNIFORMS, SHADER_MAX_UNIFORM_FLOATS, SHADER_SOURCE_MAX_BYTES, createShaderPaint, createShaderSourcePaint, hasShaderPaint, isShaderFrameCurrent, isShaderPresetPaint, isShaderSourcePaint, parseShaderUniforms, readShaderPaints, shaderFrameEncoding, shaderFrameKey, shaderFramePixels, shaderOfPaint, shaderPaintSchema, shaderPresetKey, shaderPresetPaintSchema, shaderPresetSchema, shaderSourceKey, shaderSourcePaintSchema, shaderUniformValueSchema, withShaderPaints };
6
+ export { SHADER_MAX_UNIFORMS, SHADER_MAX_UNIFORM_FLOATS, SHADER_SOURCE_MAX_BYTES, createShaderPaint, createShaderSourcePaint, hasShaderPaint, isShaderFrameCurrent, isShaderPresetPaint, isShaderSourcePaint, parseShaderUniforms, presetAnimates, readShaderPaints, shaderFrameEncoding, shaderFrameKey, shaderFramePixels, shaderOfPaint, shaderPaintSchema, shaderPresetKey, shaderPresetPaintSchema, shaderPresetSchema, shaderSourceKey, shaderSourcePaintSchema, shaderUniformValueSchema, withShaderPaints };
@@ -1 +1 @@
1
- {"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;KAeY;EACN;;EACA;EAAc,OAAO;EAAW,UAAU;EAAW;;EACrD;EAAgB,OAAO;;iBAQb,UAAU,OAAO,YAAY,mBAAmB;;;;;;iBAiChD,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAwCd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAcd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa"}
1
+ {"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;KAmBY;EACN;;EACA;EAAc,OAAO;EAAW,UAAU;EAAW;;EACrD;EAAgB,OAAO;;iBAQb,UAAU,OAAO,YAAY,mBAAmB;;;;;;iBAiChD,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAwCd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAcd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa"}
@@ -1,4 +1,4 @@
1
- import { getInstanceOverride, setInstanceOverride } from "../instances/overrides.js";
1
+ import { getInstanceOverride, ownInstanceOverrides, setInstanceOverride } from "../instances/overrides.js";
2
2
  import { isGeneratedFrame } from "../generated/index.js";
3
3
  import { ownsSlotContent, slotPropertyId } from "./frames.js";
4
4
  import { applyBoundPaintColorsIn } from "../variables/paints.js";
@@ -45,7 +45,7 @@ function descendants(graph, node, enterInstances) {
45
45
  function claimSlotContent(graph, scope) {
46
46
  const { frame, instance, propertyId } = scope;
47
47
  if (ownsSlotContent(graph, frame, propertyId)) return;
48
- const overrides = instance.instanceOverrides;
48
+ const overrides = ownInstanceOverrides(instance);
49
49
  for (const node of descendants(graph, frame, false)) {
50
50
  overrides.descendants.delete(node.id);
51
51
  if (node.type !== "INSTANCE") {
@@ -55,10 +55,10 @@ function claimSlotContent(graph, scope) {
55
55
  for (const inner of descendants(graph, node, true)) {
56
56
  const fields = overrides.descendants.get(inner.id);
57
57
  if (!fields) continue;
58
- for (const [field, value] of fields) if (field !== "sourceComponentId") setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value);
58
+ for (const [field, value] of fields) if (field !== "sourceComponentId") setInstanceOverride(ownInstanceOverrides(node), node.id, inner.id, field, value);
59
59
  overrides.descendants.delete(inner.id);
60
60
  }
61
- graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides });
61
+ graph.updateNode(node.id, { instanceOverrides: ownInstanceOverrides(node) });
62
62
  }
63
63
  graph.updateNode(instance.id, {
64
64
  instanceOverrides: overrides,
@@ -1 +1 @@
1
- {"version":3,"file":"content.js","names":[],"sources":["../../src/slots/content.ts"],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport { getInstanceOverride, setInstanceOverride } from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { applyBoundPaintColorsIn } from '../variables/paints'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction nearestInstance(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId\n ? graph.closest(node.parentId, (current) => current.type === 'INSTANCE')\n : undefined\n}\n\nexport function slotScope(graph: SceneGraph, parentId: string): SlotScope {\n const owner = graph.closest(\n parentId,\n (current) =>\n !!slotPropertyId(current) || current.type === 'INSTANCE' || isGeneratedFrame(current)\n )\n if (!owner) return { kind: 'free' }\n const propertyId = slotPropertyId(owner)\n if (!propertyId) return { kind: 'locked', owner }\n const instance = nearestInstance(graph, owner)\n return instance ? { kind: 'slot', frame: owner, instance, propertyId } : { kind: 'free' }\n}\n\n/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */\nfunction descendants(graph: SceneGraph, node: SceneNode, enterInstances: boolean): SceneNode[] {\n const result: SceneNode[] = []\n const visit = (parent: SceneNode): void => {\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n result.push(child)\n if (enterInstances || child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(node)\n return result\n}\n\n/**\n * Make the instance own its slot's content, as Figma does on the first edit: the layers\n * stay where they are, but stop following the component. Overrides the instance held for\n * them become their own values, or move to the nested instance they belong to.\n */\nexport function claimSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n if (ownsSlotContent(graph, frame, propertyId)) return\n const overrides = instance.instanceOverrides\n for (const node of descendants(graph, frame, false)) {\n overrides.descendants.delete(node.id)\n if (node.type !== 'INSTANCE') {\n graph.updateNode(node.id, { componentId: null })\n continue\n }\n // A nested instance keeps the overrides its former owner applied inside it.\n for (const inner of descendants(graph, node, true)) {\n const fields = overrides.descendants.get(inner.id)\n if (!fields) continue\n for (const [field, value] of fields)\n if (field !== 'sourceComponentId')\n setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value)\n overrides.descendants.delete(inner.id)\n }\n graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides })\n }\n graph.updateNode(instance.id, {\n instanceOverrides: overrides,\n componentPropertyAssignments: { ...instance.componentPropertyAssignments, [propertyId]: '' }\n })\n}\n\n/** The component layer an instance layer was cloned from. */\nfunction componentSource(instance: SceneNode, node: SceneNode): string | null {\n const mapped = getInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n node.id,\n 'sourceComponentId'\n )\n return typeof mapped === 'string' ? mapped : node.componentId\n}\n\n/** Return the slot to its component's content: the instance stops owning it. */\nexport function resetSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId)\n const assignments = { ...instance.componentPropertyAssignments }\n Reflect.deleteProperty(assignments, propertyId)\n graph.updateNode(instance.id, { componentPropertyAssignments: assignments })\n const source = componentSource(instance, frame)\n if (!source || !graph.nodes.has(source)) return\n cloneChildrenWithMapping(graph, source, frame.id)\n for (const childId of frame.childIds) applyBoundPaintColorsIn(graph, childId)\n}\n\n/** Remove everything from the slot; the instance keeps owning it, now empty. */\nexport function clearSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n claimSlotContent(graph, scope)\n for (const childId of Array.from(scope.frame.childIds)) graph.deleteNode(childId)\n}\n"],"mappings":";;;;;;AAoBA,SAA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],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport {\n getInstanceOverride,\n ownInstanceOverrides,\n setInstanceOverride\n} from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { applyBoundPaintColorsIn } from '../variables/paints'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction nearestInstance(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId\n ? graph.closest(node.parentId, (current) => current.type === 'INSTANCE')\n : undefined\n}\n\nexport function slotScope(graph: SceneGraph, parentId: string): SlotScope {\n const owner = graph.closest(\n parentId,\n (current) =>\n !!slotPropertyId(current) || current.type === 'INSTANCE' || isGeneratedFrame(current)\n )\n if (!owner) return { kind: 'free' }\n const propertyId = slotPropertyId(owner)\n if (!propertyId) return { kind: 'locked', owner }\n const instance = nearestInstance(graph, owner)\n return instance ? { kind: 'slot', frame: owner, instance, propertyId } : { kind: 'free' }\n}\n\n/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */\nfunction descendants(graph: SceneGraph, node: SceneNode, enterInstances: boolean): SceneNode[] {\n const result: SceneNode[] = []\n const visit = (parent: SceneNode): void => {\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n result.push(child)\n if (enterInstances || child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(node)\n return result\n}\n\n/**\n * Make the instance own its slot's content, as Figma does on the first edit: the layers\n * stay where they are, but stop following the component. Overrides the instance held for\n * them become their own values, or move to the nested instance they belong to.\n */\nexport function claimSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n if (ownsSlotContent(graph, frame, propertyId)) return\n const overrides = ownInstanceOverrides(instance)\n for (const node of descendants(graph, frame, false)) {\n overrides.descendants.delete(node.id)\n if (node.type !== 'INSTANCE') {\n graph.updateNode(node.id, { componentId: null })\n continue\n }\n // A nested instance keeps the overrides its former owner applied inside it.\n for (const inner of descendants(graph, node, true)) {\n const fields = overrides.descendants.get(inner.id)\n if (!fields) continue\n for (const [field, value] of fields)\n if (field !== 'sourceComponentId')\n setInstanceOverride(ownInstanceOverrides(node), node.id, inner.id, field, value)\n overrides.descendants.delete(inner.id)\n }\n graph.updateNode(node.id, { instanceOverrides: ownInstanceOverrides(node) })\n }\n graph.updateNode(instance.id, {\n instanceOverrides: overrides,\n componentPropertyAssignments: { ...instance.componentPropertyAssignments, [propertyId]: '' }\n })\n}\n\n/** The component layer an instance layer was cloned from. */\nfunction componentSource(instance: SceneNode, node: SceneNode): string | null {\n const mapped = getInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n node.id,\n 'sourceComponentId'\n )\n return typeof mapped === 'string' ? mapped : node.componentId\n}\n\n/** Return the slot to its component's content: the instance stops owning it. */\nexport function resetSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId)\n const assignments = { ...instance.componentPropertyAssignments }\n Reflect.deleteProperty(assignments, propertyId)\n graph.updateNode(instance.id, { componentPropertyAssignments: assignments })\n const source = componentSource(instance, frame)\n if (!source || !graph.nodes.has(source)) return\n cloneChildrenWithMapping(graph, source, frame.id)\n for (const childId of frame.childIds) applyBoundPaintColorsIn(graph, childId)\n}\n\n/** Remove everything from the slot; the instance keeps owning it, now empty. */\nexport function clearSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n claimSlotContent(graph, scope)\n for (const childId of Array.from(scope.frame.childIds)) graph.deleteNode(childId)\n}\n"],"mappings":";;;;;;AAwBA,SAAS,gBAAgB,OAAmB,MAAwC;CAClF,OAAO,KAAK,WACR,MAAM,QAAQ,KAAK,WAAW,YAAY,QAAQ,SAAS,UAAU,IACrE,KAAA;AACN;AAEA,SAAgB,UAAU,OAAmB,UAA6B;CACxE,MAAM,QAAQ,MAAM,QAClB,WACC,YACC,CAAC,CAAC,eAAe,OAAO,KAAK,QAAQ,SAAS,cAAc,iBAAiB,OAAO,CACxF;CACA,IAAI,CAAC,OAAO,OAAO,EAAE,MAAM,OAAO;CAClC,MAAM,aAAa,eAAe,KAAK;CACvC,IAAI,CAAC,YAAY,OAAO;EAAE,MAAM;EAAU;CAAM;CAChD,MAAM,WAAW,gBAAgB,OAAO,KAAK;CAC7C,OAAO,WAAW;EAAE,MAAM;EAAQ,OAAO;EAAO;EAAU;CAAW,IAAI,EAAE,MAAM,OAAO;AAC1F;;AAGA,SAAS,YAAY,OAAmB,MAAiB,gBAAsC;CAC7F,MAAM,SAAsB,CAAC;CAC7B,MAAM,SAAS,WAA4B;EACzC,KAAK,MAAM,WAAW,OAAO,UAAU;GACrC,MAAM,QAAQ,MAAM,MAAM,IAAI,OAAO;GACrC,IAAI,CAAC,OAAO;GACZ,OAAO,KAAK,KAAK;GACjB,IAAI,kBAAkB,MAAM,SAAS,YAAY,MAAM,KAAK;EAC9D;CACF;CACA,MAAM,IAAI;CACV,OAAO;AACT;;;;;;AAOA,SAAgB,iBACd,OACA,OACM;CACN,MAAM,EAAE,OAAO,UAAU,eAAe;CACxC,IAAI,gBAAgB,OAAO,OAAO,UAAU,GAAG;CAC/C,MAAM,YAAY,qBAAqB,QAAQ;CAC/C,KAAK,MAAM,QAAQ,YAAY,OAAO,OAAO,KAAK,GAAG;EACnD,UAAU,YAAY,OAAO,KAAK,EAAE;EACpC,IAAI,KAAK,SAAS,YAAY;GAC5B,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C7B,KAAK,MAAM,WAAW,MAAM,KAAK,MAAM,MAAM,QAAQ,GAAG,MAAM,WAAW,OAAO;AAClF"}
@@ -1,5 +1,5 @@
1
1
  import { FIGMA_DEV_STATUSES, FigmaDevStatus, StatusState, StatusWorkflow, nodeStatusSchema, statusWorkflowSchema } from "./schema.js";
2
2
  import { StatusWorkflowImpact, statusWorkflowImpact } from "./impact.js";
3
3
  import { STATUS_NODE_TYPES, StatusPlacement, effectiveStatus, statusPlacement } from "./node.js";
4
- import { FIGMA_STATUS_STATE_IDS, STATUS_WORKFLOW_PRESETS, StatusWorkflowPreset, cachedStatusWorkflow, figmaDevStatusOf, findStatusState, readStatusWorkflow, shownStatusState, writeStatusWorkflow } from "./workflow.js";
5
- export { FIGMA_DEV_STATUSES, FIGMA_STATUS_STATE_IDS, FigmaDevStatus, STATUS_NODE_TYPES, STATUS_WORKFLOW_PRESETS, StatusPlacement, StatusState, StatusWorkflow, StatusWorkflowImpact, StatusWorkflowPreset, cachedStatusWorkflow, effectiveStatus, figmaDevStatusOf, findStatusState, nodeStatusSchema, readStatusWorkflow, shownStatusState, statusPlacement, statusWorkflowImpact, statusWorkflowSchema, writeStatusWorkflow };
4
+ import { FIGMA_STATUS_STATE_IDS, STATUS_WORKFLOW_PRESETS, StatusWorkflowPreset, cachedStatusWorkflow, figmaDevStatusOf, findStatusState, readStatusWorkflow, readStoredStatusWorkflow, shownStatusState, writeStatusWorkflow } from "./workflow.js";
5
+ export { FIGMA_DEV_STATUSES, FIGMA_STATUS_STATE_IDS, FigmaDevStatus, STATUS_NODE_TYPES, STATUS_WORKFLOW_PRESETS, StatusPlacement, StatusState, StatusWorkflow, StatusWorkflowImpact, StatusWorkflowPreset, cachedStatusWorkflow, effectiveStatus, figmaDevStatusOf, findStatusState, nodeStatusSchema, readStatusWorkflow, readStoredStatusWorkflow, shownStatusState, statusPlacement, statusWorkflowImpact, statusWorkflowSchema, writeStatusWorkflow };
@@ -1,5 +1,5 @@
1
1
  import { FIGMA_DEV_STATUSES, nodeStatusSchema, statusWorkflowSchema } from "./schema.js";
2
2
  import { STATUS_NODE_TYPES, effectiveStatus, statusPlacement } from "./node.js";
3
- import { FIGMA_STATUS_STATE_IDS, STATUS_WORKFLOW_PRESETS, cachedStatusWorkflow, figmaDevStatusOf, findStatusState, readStatusWorkflow, shownStatusState, writeStatusWorkflow } from "./workflow.js";
3
+ import { FIGMA_STATUS_STATE_IDS, STATUS_WORKFLOW_PRESETS, cachedStatusWorkflow, figmaDevStatusOf, findStatusState, readStatusWorkflow, readStoredStatusWorkflow, shownStatusState, writeStatusWorkflow } from "./workflow.js";
4
4
  import { statusWorkflowImpact } from "./impact.js";
5
- export { FIGMA_DEV_STATUSES, FIGMA_STATUS_STATE_IDS, STATUS_NODE_TYPES, STATUS_WORKFLOW_PRESETS, cachedStatusWorkflow, effectiveStatus, figmaDevStatusOf, findStatusState, nodeStatusSchema, readStatusWorkflow, shownStatusState, statusPlacement, statusWorkflowImpact, statusWorkflowSchema, writeStatusWorkflow };
5
+ export { FIGMA_DEV_STATUSES, FIGMA_STATUS_STATE_IDS, STATUS_NODE_TYPES, STATUS_WORKFLOW_PRESETS, cachedStatusWorkflow, effectiveStatus, figmaDevStatusOf, findStatusState, nodeStatusSchema, readStatusWorkflow, readStoredStatusWorkflow, shownStatusState, statusPlacement, statusWorkflowImpact, statusWorkflowSchema, writeStatusWorkflow };
@@ -99,6 +99,8 @@ type StatusWorkflowPreset = keyof typeof STATUS_WORKFLOW_PRESETS;
99
99
  * Ready for dev and Completed read as statuses without setup.
100
100
  */
101
101
  declare function readStatusWorkflow(graph: SceneGraph): StatusWorkflow;
102
+ /** The workflow the document stored, or `undefined` when it never chose one. */
103
+ declare function readStoredStatusWorkflow(graph: SceneGraph): StatusWorkflow | undefined;
102
104
  /** Stores the workflow on the document node, as an undoable document change. */
103
105
  declare function writeStatusWorkflow(graph: SceneGraph, workflow: StatusWorkflow): void;
104
106
  /**
@@ -116,5 +118,5 @@ declare function cachedStatusWorkflow(graph: SceneGraph): StatusWorkflow;
116
118
  /** The state a layer shows, if any. */
117
119
  declare function shownStatusState(graph: SceneGraph, node: SceneNode): StatusState | null;
118
120
  //#endregion
119
- export { FIGMA_STATUS_STATE_IDS, STATUS_WORKFLOW_PRESETS, StatusWorkflowPreset, cachedStatusWorkflow, figmaDevStatusOf, findStatusState, readStatusWorkflow, shownStatusState, writeStatusWorkflow };
121
+ export { FIGMA_STATUS_STATE_IDS, STATUS_WORKFLOW_PRESETS, StatusWorkflowPreset, cachedStatusWorkflow, figmaDevStatusOf, findStatusState, readStatusWorkflow, readStoredStatusWorkflow, shownStatusState, writeStatusWorkflow };
120
122
  //# sourceMappingURL=workflow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.d.ts","names":[],"sources":["../../src/statuses/workflow.ts"],"mappings":";;;;;;;;;cAca;WAAA;WAAA;;;;;;cAqBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAuBD,oCAAoC;;;;;iBAMhC,mBAAmB,OAAO,aAAa;;iBAQvC,oBAAoB,OAAO,YAAY,UAAU;;;;;iBAYjD,gBACd,UAAU,gBACV,kBACC;;iBAQa,iBAAiB,kBAAkB;;;;;iBAYnC,qBAAqB,OAAO,aAAa;;iBAUzC,iBAAiB,OAAO,YAAY,MAAM,YAAY"}
1
+ {"version":3,"file":"workflow.d.ts","names":[],"sources":["../../src/statuses/workflow.ts"],"mappings":";;;;;;;;;cAca;WAAA;WAAA;;;;;;cAqBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAuBD,oCAAoC;;;;;iBAMhC,mBAAmB,OAAO,aAAa;;iBAKvC,yBAAyB,OAAO,aAAa;;iBAK7C,oBAAoB,OAAO,YAAY,UAAU;;;;;iBAYjD,gBACd,UAAU,gBACV,kBACC;;iBAQa,iBAAiB,kBAAkB;;;;;iBAYnC,qBAAqB,OAAO,aAAa;;iBAUzC,iBAAiB,OAAO,YAAY,MAAM,YAAY"}
@@ -87,7 +87,11 @@ const STATUS_WORKFLOW_PRESETS = {
87
87
  * Ready for dev and Completed read as statuses without setup.
88
88
  */
89
89
  function readStatusWorkflow(graph) {
90
- return readPluginData(graph.getNode(graph.rootId)?.pluginData, statuses) ?? STATUS_WORKFLOW_PRESETS.handoff;
90
+ return readStoredStatusWorkflow(graph) ?? STATUS_WORKFLOW_PRESETS.handoff;
91
+ }
92
+ /** The workflow the document stored, or `undefined` when it never chose one. */
93
+ function readStoredStatusWorkflow(graph) {
94
+ return readPluginData(graph.getNode(graph.rootId)?.pluginData, statuses);
91
95
  }
92
96
  /** Stores the workflow on the document node, as an undoable document change. */
93
97
  function writeStatusWorkflow(graph, workflow) {
@@ -130,6 +134,6 @@ function shownStatusState(graph, node) {
130
134
  return id === null ? null : findStatusState(cachedStatusWorkflow(graph), id) ?? null;
131
135
  }
132
136
  //#endregion
133
- export { FIGMA_STATUS_STATE_IDS, STATUS_WORKFLOW_PRESETS, cachedStatusWorkflow, figmaDevStatusOf, findStatusState, readStatusWorkflow, shownStatusState, writeStatusWorkflow };
137
+ export { FIGMA_STATUS_STATE_IDS, STATUS_WORKFLOW_PRESETS, cachedStatusWorkflow, figmaDevStatusOf, findStatusState, readStatusWorkflow, readStoredStatusWorkflow, shownStatusState, writeStatusWorkflow };
134
138
 
135
139
  //# sourceMappingURL=workflow.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.js","names":[],"sources":["../../src/statuses/workflow.ts"],"sourcesContent":["import { parseColor } from '../color'\nimport type { SceneGraph } from '../graph'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { SceneNode } from '../types'\nimport { effectiveStatus } from './node'\nimport type { FigmaDevStatus, StatusState, StatusWorkflow } from './schema'\n\nconst { statuses } = PAIRDRAW_PLUGIN_DATA\n\n/**\n * The states Figma shows, by fixed id. Teams rename them as they like, but a `.fig` file's\n * Ready for dev and Completed always read back as these, without the document's workflow.\n */\nexport const FIGMA_STATUS_STATE_IDS = {\n READY_FOR_DEV: 'ready-for-dev',\n COMPLETED: 'completed'\n} as const satisfies Record<FigmaDevStatus, string>\n\nconst READY_FOR_DEV: StatusState = {\n id: FIGMA_STATUS_STATE_IDS.READY_FOR_DEV,\n name: 'Ready for dev',\n color: parseColor('#14ae5c')\n}\n\nconst COMPLETED: StatusState = {\n id: FIGMA_STATUS_STATE_IDS.COMPLETED,\n name: 'Completed',\n color: parseColor('#8a8a8a')\n}\n\n/**\n * Workflows to start from. Their states keep fixed ids, so a document using a preset, or no\n * workflow of its own, reads the same states back.\n */\nexport const STATUS_WORKFLOW_PRESETS = {\n handoff: { preset: 'handoff', states: [READY_FOR_DEV, COMPLETED] },\n simple: {\n preset: 'simple',\n states: [\n { id: 'draft', name: 'Draft', color: parseColor('#b3b3b3') },\n { id: 'in-progress', name: 'In progress', color: parseColor('#0d99ff') },\n { ...COMPLETED, name: 'Done', color: parseColor('#14ae5c') }\n ]\n },\n review: {\n preset: 'review',\n states: [\n { id: 'draft', name: 'Draft', color: parseColor('#b3b3b3') },\n { id: 'in-review', name: 'In review', color: parseColor('#9747ff') },\n { id: 'changes-requested', name: 'Changes requested', color: parseColor('#f24822') },\n { id: 'approved', name: 'Approved', color: parseColor('#0d99ff') },\n READY_FOR_DEV,\n { ...COMPLETED, name: 'Shipped' }\n ]\n }\n} as const satisfies Record<string, StatusWorkflow>\n\nexport type StatusWorkflowPreset = keyof typeof STATUS_WORKFLOW_PRESETS\n\n/**\n * The document's statuses. A document that never chose any has Figma's own, so a `.fig` file's\n * Ready for dev and Completed read as statuses without setup.\n */\nexport function readStatusWorkflow(graph: SceneGraph): StatusWorkflow {\n return (\n readPluginData(graph.getNode(graph.rootId)?.pluginData, statuses) ??\n STATUS_WORKFLOW_PRESETS.handoff\n )\n}\n\n/** Stores the workflow on the document node, as an undoable document change. */\nexport function writeStatusWorkflow(graph: SceneGraph, workflow: StatusWorkflow): void {\n const root = graph.getNode(graph.rootId)\n if (!root) return\n graph.updateNode(root.id, {\n pluginData: withPluginData(root.pluginData, statuses, structuredClone(workflow))\n })\n}\n\n/**\n * The state `stateId` names: the workflow's own, or Figma's when the workflow has no such state,\n * as a `.fig` file's Ready for dev reads in a document whose team removed it.\n */\nexport function findStatusState(\n workflow: StatusWorkflow,\n stateId: string\n): StatusState | undefined {\n return (\n workflow.states.find((state) => state.id === stateId) ??\n STATUS_WORKFLOW_PRESETS.handoff.states.find((state) => state.id === stateId)\n )\n}\n\n/** The Figma status a state shows as in Figma and the Plugin API's `devStatus`, if any. */\nexport function figmaDevStatusOf(stateId: string): FigmaDevStatus | null {\n if (stateId === FIGMA_STATUS_STATE_IDS.READY_FOR_DEV) return 'READY_FOR_DEV'\n if (stateId === FIGMA_STATUS_STATE_IDS.COMPLETED) return 'COMPLETED'\n return null\n}\n\nconst WORKFLOWS = new WeakMap<SceneGraph, { entries: unknown; workflow: StatusWorkflow }>()\n\n/**\n * The document's statuses, read once per change to the document node: canvas labels ask for\n * them on every frame.\n */\nexport function cachedStatusWorkflow(graph: SceneGraph): StatusWorkflow {\n const entries = graph.getNode(graph.rootId)?.pluginData\n const known = WORKFLOWS.get(graph)\n if (known && known.entries === entries) return known.workflow\n const workflow = readStatusWorkflow(graph)\n WORKFLOWS.set(graph, { entries, workflow })\n return workflow\n}\n\n/** The state a layer shows, if any. */\nexport function shownStatusState(graph: SceneGraph, node: SceneNode): StatusState | null {\n const id = effectiveStatus(graph, node)\n return id === null ? null : (findStatusState(cachedStatusWorkflow(graph), id) ?? null)\n}\n"],"mappings":";;;;;AAQA,MAAM,EAAE,aAAa;;;;;AAMrB,MAAa,yBAAyB;CACpC,eAAe;CACf,WAAW;AACb;AAEA,MAAM,gBAA6B;CACjC,IAAI,uBAAuB;CAC3B,MAAM;CACN,OAAO,W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;AAE/E;;AAGA,SAAgB,iBAAiB,SAAwC;CACvE,IAAI,YAAY,uBAAuB,eAAe,OAAO;CAC7D,IAAI,YAAY,uBAAuB,WAAW,OAAO;CACzD,OAAO;AACT;AAEA,MAAM,4BAAY,IAAI,QAAoE;;;;;AAM1F,SAAgB,qBAAqB,OAAmC;CACtE,MAAM,UAAU,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE;CAC7C,MAAM,QAAQ,UAAU,IAAI,KAAK;CACjC,IAAI,SAAS,MAAM,YAAY,SAAS,OAAO,MAAM;CACrD,MAAM,WAAW,mBAAmB,KAAK;CACzC,UAAU,IAAI,OAAO;EAAE;EAAS;CAAS,CAAC;CAC1C,OAAO;AACT;;AAGA,SAAgB,iBAAiB,OAAmB,MAAqC;CACvF,MAAM,KAAK,gBAAgB,OAAO,IAAI;CACtC,OAAO,OAAO,OAAO,OAAQ,gBAAgB,qBAAqB,KAAK,GAAG,EAAE,KAAK;AACnF"}
1
+ {"version":3,"file":"workflow.js","names":[],"sources":["../../src/statuses/workflow.ts"],"sourcesContent":["import { parseColor } from '../color'\nimport type { SceneGraph } from '../graph'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { SceneNode } from '../types'\nimport { effectiveStatus } from './node'\nimport type { FigmaDevStatus, StatusState, StatusWorkflow } from './schema'\n\nconst { statuses } = PAIRDRAW_PLUGIN_DATA\n\n/**\n * The states Figma shows, by fixed id. Teams rename them as they like, but a `.fig` file's\n * Ready for dev and Completed always read back as these, without the document's workflow.\n */\nexport const FIGMA_STATUS_STATE_IDS = {\n READY_FOR_DEV: 'ready-for-dev',\n COMPLETED: 'completed'\n} as const satisfies Record<FigmaDevStatus, string>\n\nconst READY_FOR_DEV: StatusState = {\n id: FIGMA_STATUS_STATE_IDS.READY_FOR_DEV,\n name: 'Ready for dev',\n color: parseColor('#14ae5c')\n}\n\nconst COMPLETED: StatusState = {\n id: FIGMA_STATUS_STATE_IDS.COMPLETED,\n name: 'Completed',\n color: parseColor('#8a8a8a')\n}\n\n/**\n * Workflows to start from. Their states keep fixed ids, so a document using a preset, or no\n * workflow of its own, reads the same states back.\n */\nexport const STATUS_WORKFLOW_PRESETS = {\n handoff: { preset: 'handoff', states: [READY_FOR_DEV, COMPLETED] },\n simple: {\n preset: 'simple',\n states: [\n { id: 'draft', name: 'Draft', color: parseColor('#b3b3b3') },\n { id: 'in-progress', name: 'In progress', color: parseColor('#0d99ff') },\n { ...COMPLETED, name: 'Done', color: parseColor('#14ae5c') }\n ]\n },\n review: {\n preset: 'review',\n states: [\n { id: 'draft', name: 'Draft', color: parseColor('#b3b3b3') },\n { id: 'in-review', name: 'In review', color: parseColor('#9747ff') },\n { id: 'changes-requested', name: 'Changes requested', color: parseColor('#f24822') },\n { id: 'approved', name: 'Approved', color: parseColor('#0d99ff') },\n READY_FOR_DEV,\n { ...COMPLETED, name: 'Shipped' }\n ]\n }\n} as const satisfies Record<string, StatusWorkflow>\n\nexport type StatusWorkflowPreset = keyof typeof STATUS_WORKFLOW_PRESETS\n\n/**\n * The document's statuses. A document that never chose any has Figma's own, so a `.fig` file's\n * Ready for dev and Completed read as statuses without setup.\n */\nexport function readStatusWorkflow(graph: SceneGraph): StatusWorkflow {\n return readStoredStatusWorkflow(graph) ?? STATUS_WORKFLOW_PRESETS.handoff\n}\n\n/** The workflow the document stored, or `undefined` when it never chose one. */\nexport function readStoredStatusWorkflow(graph: SceneGraph): StatusWorkflow | undefined {\n return readPluginData(graph.getNode(graph.rootId)?.pluginData, statuses)\n}\n\n/** Stores the workflow on the document node, as an undoable document change. */\nexport function writeStatusWorkflow(graph: SceneGraph, workflow: StatusWorkflow): void {\n const root = graph.getNode(graph.rootId)\n if (!root) return\n graph.updateNode(root.id, {\n pluginData: withPluginData(root.pluginData, statuses, structuredClone(workflow))\n })\n}\n\n/**\n * The state `stateId` names: the workflow's own, or Figma's when the workflow has no such state,\n * as a `.fig` file's Ready for dev reads in a document whose team removed it.\n */\nexport function findStatusState(\n workflow: StatusWorkflow,\n stateId: string\n): StatusState | undefined {\n return (\n workflow.states.find((state) => state.id === stateId) ??\n STATUS_WORKFLOW_PRESETS.handoff.states.find((state) => state.id === stateId)\n )\n}\n\n/** The Figma status a state shows as in Figma and the Plugin API's `devStatus`, if any. */\nexport function figmaDevStatusOf(stateId: string): FigmaDevStatus | null {\n if (stateId === FIGMA_STATUS_STATE_IDS.READY_FOR_DEV) return 'READY_FOR_DEV'\n if (stateId === FIGMA_STATUS_STATE_IDS.COMPLETED) return 'COMPLETED'\n return null\n}\n\nconst WORKFLOWS = new WeakMap<SceneGraph, { entries: unknown; workflow: StatusWorkflow }>()\n\n/**\n * The document's statuses, read once per change to the document node: canvas labels ask for\n * them on every frame.\n */\nexport function cachedStatusWorkflow(graph: SceneGraph): StatusWorkflow {\n const entries = graph.getNode(graph.rootId)?.pluginData\n const known = WORKFLOWS.get(graph)\n if (known && known.entries === entries) return known.workflow\n const workflow = readStatusWorkflow(graph)\n WORKFLOWS.set(graph, { entries, workflow })\n return workflow\n}\n\n/** The state a layer shows, if any. */\nexport function shownStatusState(graph: SceneGraph, node: SceneNode): StatusState | null {\n const id = effectiveStatus(graph, node)\n return id === null ? null : (findStatusState(cachedStatusWorkflow(graph), id) ?? null)\n}\n"],"mappings":";;;;;AAQA,MAAM,EAAE,aAAa;;;;;AAMrB,MAAa,yBAAyB;CACpC,eAAe;CACf,WAAW;AACb;AAEA,MAAM,gBAA6B;CACjC,IAAI,uBAAuB;CAC3B,MAAM;CACN,OAAO,WAAW,SAAS;AAC7B;AAEA,MAAM,YAAyB;CAC7B,IAAI,uBAAuB;CAC3B,MAAM;CACN,OAAO,WAAW,SAAS;AAC7B;;;;;AAMA,MAAa,0BAA0B;CACrC,SAAS;EAAE,QAAQ;EAAW,QAAQ,CAAC,eAAe,SAAS;CAAE;CACjE,QAAQ;EACN,QAAQ;EACR,QAAQ;GACN;IAAE,IAAI;IAAS,MAAM;IAA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mC;CACtE,MAAM,UAAU,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE;CAC7C,MAAM,QAAQ,UAAU,IAAI,KAAK;CACjC,IAAI,SAAS,MAAM,YAAY,SAAS,OAAO,MAAM;CACrD,MAAM,WAAW,mBAAmB,KAAK;CACzC,UAAU,IAAI,OAAO;EAAE;EAAS;CAAS,CAAC;CAC1C,OAAO;AACT;;AAGA,SAAgB,iBAAiB,OAAmB,MAAqC;CACvF,MAAM,KAAK,gBAAgB,OAAO,IAAI;CACtC,OAAO,OAAO,OAAO,OAAQ,gBAAgB,qBAAqB,KAAK,GAAG,EAAE,KAAK;AACnF"}
@@ -0,0 +1,26 @@
1
+ import { SceneGraph } from "../graph.js";
2
+ import { PluginDataEntry } from "../types.js";
3
+ import { TokenSource } from "./schema.js";
4
+ //#region src/token-sources/document.d.ts
5
+ /**
6
+ * The code a document's variables are linked to, with what it held at the last sync. The links
7
+ * live in Pairdraw's plugin data on the document node, so they travel with the `.fig` file and
8
+ * Figma ignores them; where each file is on this computer stays with the app, not the document.
9
+ */
10
+ declare function readTokenSources(graph: SceneGraph): TokenSource[];
11
+ /**
12
+ * The links with their snapshots keyed by the graph's variable and mode ids. A format that keys
13
+ * variables and modes by name, such as `.pen`, gives them new ids when it reads them back; the
14
+ * names the file stored when it was saved, or the last sync's where the file recorded none, find
15
+ * them again. `names` and the snapshot's token identities are kept as they were. Links whose
16
+ * variables are all gone are left as they are.
17
+ */
18
+ declare function rekeyTokenSources(graph: SceneGraph, sources: readonly TokenSource[]): TokenSource[];
19
+ /**
20
+ * The document node's plugin data holding `sources` in place of its links, for an edit that
21
+ * writes them, undoably or not, as one change to the node.
22
+ */
23
+ declare function tokenSourcesPluginData(graph: SceneGraph, sources: readonly TokenSource[]): PluginDataEntry[];
24
+ //#endregion
25
+ export { readTokenSources, rekeyTokenSources, tokenSourcesPluginData };
26
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","names":[],"sources":["../../src/token-sources/document.ts"],"mappings":";;;;;;;;;iBAegB,iBAAiB,OAAO,aAAa;;;;;;;;iBAWrC,kBACd,OAAO,YACP,kBAAkB,gBACjB;;;;;iBA4Da,uBACd,OAAO,YACP,kBAAkB,gBACjB"}
@@ -0,0 +1,80 @@
1
+ import { readPluginData, withPluginData } from "../plugin-data/field.js";
2
+ import { relativeTokenPathSchema } from "./schema.js";
3
+ import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
4
+ import * as v from "valibot";
5
+ //#region src/token-sources/document.ts
6
+ const { tokenSources } = PAIRDRAW_PLUGIN_DATA;
7
+ /**
8
+ * The code a document's variables are linked to, with what it held at the last sync. The links
9
+ * live in Pairdraw's plugin data on the document node, so they travel with the `.fig` file and
10
+ * Figma ignores them; where each file is on this computer stays with the app, not the document.
11
+ */
12
+ function readTokenSources(graph) {
13
+ return readPluginData(graph.getNode(graph.rootId)?.pluginData, tokenSources) ?? [];
14
+ }
15
+ /**
16
+ * The links with their snapshots keyed by the graph's variable and mode ids. A format that keys
17
+ * variables and modes by name, such as `.pen`, gives them new ids when it reads them back; the
18
+ * names the file stored when it was saved, or the last sync's where the file recorded none, find
19
+ * them again. `names` and the snapshot's token identities are kept as they were. Links whose
20
+ * variables are all gone are left as they are.
21
+ */
22
+ function rekeyTokenSources(graph, sources) {
23
+ const collectionsByName = new Map([...graph.variableCollections.values()].map((collection) => [collection.name, collection]));
24
+ const variablesByKey = /* @__PURE__ */ new Map();
25
+ for (const variable of graph.variables.values()) {
26
+ const collection = graph.variableCollections.get(variable.collectionId);
27
+ if (collection) variablesByKey.set(`${collection.name}/${variable.name}`, variable.id);
28
+ }
29
+ const currentModeId = (collectionName, modeId, modes) => {
30
+ const name = modes?.[collectionName]?.[modeId];
31
+ if (name === void 0) return modeId;
32
+ return (collectionsByName.get(collectionName)?.modes.find((entry) => entry.name === name))?.modeId ?? modeId;
33
+ };
34
+ return sources.map((source) => {
35
+ const ids = /* @__PURE__ */ new Map();
36
+ for (const [id, key] of Object.entries(source.currentNames ?? source.names ?? {})) {
37
+ const current = variablesByKey.get(key);
38
+ if (current !== void 0) ids.set(id, current);
39
+ }
40
+ if (ids.size === 0) return source;
41
+ const collectionOf = (id) => {
42
+ const variable = graph.variables.get(id);
43
+ return variable ? graph.variableCollections.get(variable.collectionId)?.name : void 0;
44
+ };
45
+ const snapshot = {};
46
+ for (const [oldId, values] of Object.entries(source.snapshot)) {
47
+ const id = ids.get(oldId) ?? oldId;
48
+ const collection = collectionOf(id);
49
+ const entry = {};
50
+ for (const [modeId, signature] of Object.entries(values)) entry[collection ? currentModeId(collection, modeId, source.modes) : modeId] = signature;
51
+ snapshot[id] = {
52
+ ...snapshot[id],
53
+ ...entry
54
+ };
55
+ }
56
+ const names = Object.fromEntries(Object.entries(source.names ?? {}).map(([id, key]) => [ids.get(id) ?? id, key]));
57
+ const modes = source.modes ? Object.fromEntries(Object.entries(source.modes).map(([collectionName, byMode]) => [collectionName, Object.fromEntries(Object.entries(byMode).map(([modeId, name]) => [currentModeId(collectionName, modeId, source.modes), name]))])) : void 0;
58
+ return {
59
+ ...source,
60
+ snapshot,
61
+ names,
62
+ ...modes ? { modes } : {}
63
+ };
64
+ });
65
+ }
66
+ /**
67
+ * The document node's plugin data holding `sources` in place of its links, for an edit that
68
+ * writes them, undoably or not, as one change to the node.
69
+ */
70
+ function tokenSourcesPluginData(graph, sources) {
71
+ const stored = sources.map(({ path, ...source }) => path !== void 0 && v.is(relativeTokenPathSchema, path) ? {
72
+ ...source,
73
+ path
74
+ } : source);
75
+ return withPluginData(graph.getNode(graph.rootId)?.pluginData ?? [], tokenSources, stored.length > 0 ? stored : void 0);
76
+ }
77
+ //#endregion
78
+ export { readTokenSources, rekeyTokenSources, tokenSourcesPluginData };
79
+
80
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.js","names":[],"sources":["../../src/token-sources/document.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneGraph } from '../graph'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { PluginDataEntry } from '../types'\nimport { relativeTokenPathSchema, type TokenSource } from './schema'\n\nconst { tokenSources } = PAIRDRAW_PLUGIN_DATA\n\n/**\n * The code a document's variables are linked to, with what it held at the last sync. The links\n * live in Pairdraw's plugin data on the document node, so they travel with the `.fig` file and\n * Figma ignores them; where each file is on this computer stays with the app, not the document.\n */\nexport function readTokenSources(graph: SceneGraph): TokenSource[] {\n return readPluginData(graph.getNode(graph.rootId)?.pluginData, tokenSources) ?? []\n}\n\n/**\n * The links with their snapshots keyed by the graph's variable and mode ids. A format that keys\n * variables and modes by name, such as `.pen`, gives them new ids when it reads them back; the\n * names the file stored when it was saved, or the last sync's where the file recorded none, find\n * them again. `names` and the snapshot's token identities are kept as they were. Links whose\n * variables are all gone are left as they are.\n */\nexport function rekeyTokenSources(\n graph: SceneGraph,\n sources: readonly TokenSource[]\n): TokenSource[] {\n const collectionsByName = new Map(\n [...graph.variableCollections.values()].map((collection) => [collection.name, collection])\n )\n const variablesByKey = new Map<string, string>()\n for (const variable of graph.variables.values()) {\n const collection = graph.variableCollections.get(variable.collectionId)\n if (collection) variablesByKey.set(`${collection.name}/${variable.name}`, variable.id)\n }\n const currentModeId = (collectionName: string, modeId: string, modes: TokenSource['modes']) => {\n const name = modes?.[collectionName]?.[modeId]\n if (name === undefined) return modeId\n const mode = collectionsByName.get(collectionName)?.modes.find((entry) => entry.name === name)\n return mode?.modeId ?? modeId\n }\n return sources.map((source) => {\n const ids = new Map<string, string>()\n for (const [id, key] of Object.entries(source.currentNames ?? source.names ?? {})) {\n const current = variablesByKey.get(key)\n if (current !== undefined) ids.set(id, current)\n }\n if (ids.size === 0) return source\n const collectionOf = (id: string) => {\n const variable = graph.variables.get(id)\n return variable ? graph.variableCollections.get(variable.collectionId)?.name : undefined\n }\n const snapshot: TokenSource['snapshot'] = {}\n for (const [oldId, values] of Object.entries(source.snapshot)) {\n const id = ids.get(oldId) ?? oldId\n const collection = collectionOf(id)\n const entry: Record<string, string> = {}\n for (const [modeId, signature] of Object.entries(values)) {\n entry[collection ? currentModeId(collection, modeId, source.modes) : modeId] = signature\n }\n snapshot[id] = { ...snapshot[id], ...entry }\n }\n const names = Object.fromEntries(\n Object.entries(source.names ?? {}).map(([id, key]) => [ids.get(id) ?? id, key])\n )\n const modes = source.modes\n ? Object.fromEntries(\n Object.entries(source.modes).map(([collectionName, byMode]) => [\n collectionName,\n Object.fromEntries(\n Object.entries(byMode).map(([modeId, name]) => [\n currentModeId(collectionName, modeId, source.modes),\n name\n ])\n )\n ])\n )\n : undefined\n return { ...source, snapshot, names, ...(modes ? { modes } : {}) }\n })\n}\n\n/**\n * The document node's plugin data holding `sources` in place of its links, for an edit that\n * writes them, undoably or not, as one change to the node.\n */\nexport function tokenSourcesPluginData(\n graph: SceneGraph,\n sources: readonly TokenSource[]\n): PluginDataEntry[] {\n // A path that is not relative would make the reader drop the whole link; the link keeps going\n // by its name instead.\n const stored = sources.map(({ path, ...source }) =>\n path !== undefined && v.is(relativeTokenPathSchema, path) ? { ...source, path } : source\n )\n return withPluginData(\n graph.getNode(graph.rootId)?.pluginData ?? [],\n tokenSources,\n stored.length > 0 ? stored : undefined\n )\n}\n"],"mappings":";;;;;AAQA,MAAM,EAAE,iBAAiB;;;;;;AAOzB,SAAgB,iBAAiB,OAAkC;CACjE,OAAO,eAAe,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE,YAAY,YAAY,KAAK,CAAC;AACnF;;;;;;;;AASA,SAAgB,kBACd,OACA,SACe;CACf,MAAM,oBAAoB,IAAI,IAC5B,CAAC,GAAG,MAAM,oBAAoB,OAAO,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,WAAW,MAAM,UAAU,CAAC,CAC3F;CACA,MAAM,iCAAiB,IAAI,IAAoB;CAC/C,KAAK,MAAM,YAAY,MAAM,UAAU,OAAO,GA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CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,IAAI,IAAI,EAAE,KAAK,IAAI,GAAG,CAAC,CAChF;EACA,MAAM,QAAQ,OAAO,QACjB,OAAO,YACL,OAAO,QAAQ,OAAO,KAAK,CAAC,CAAC,KAAK,CAAC,gBAAgB,YAAY,CAC7D,gBACA,OAAO,YACL,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,QAAQ,UAAU,CAC7C,cAAc,gBAAgB,QAAQ,OAAO,KAAK,GAClD,IACF,CAAC,CACH,CACF,CAAC,CACH,IACA,KAAA;EACJ,OAAO;GAAE,GAAG;GAAQ;GAAU;GAAO,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;EAAG;CACnE,CAAC;AACH;;;;;AAMA,SAAgB,uBACd,OACA,SACmB;CAGnB,MAAM,SAAS,QAAQ,KAAK,EAAE,MAAM,GAAG,aACrC,SAAS,KAAA,KAAa,EAAE,GAAG,yBAAyB,IAAI,IAAI;EAAE,GAAG;EAAQ;CAAK,IAAI,MACpF;CACA,OAAO,eACL,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE,cAAc,CAAC,GAC5C,cACA,OAAO,SAAS,IAAI,SAAS,KAAA,CAC/B;AACF"}
@@ -0,0 +1,3 @@
1
+ import { TokenSource, relativeTokenPathSchema, tokenSourcesSchema } from "./schema.js";
2
+ import { readTokenSources, rekeyTokenSources, tokenSourcesPluginData } from "./document.js";
3
+ export { TokenSource, readTokenSources, rekeyTokenSources, relativeTokenPathSchema, tokenSourcesPluginData, tokenSourcesSchema };
@@ -0,0 +1,3 @@
1
+ import { relativeTokenPathSchema, tokenSourcesSchema } from "./schema.js";
2
+ import { readTokenSources, rekeyTokenSources, tokenSourcesPluginData } from "./document.js";
3
+ export { readTokenSources, rekeyTokenSources, relativeTokenPathSchema, tokenSourcesPluginData, tokenSourcesSchema };
@@ -0,0 +1,43 @@
1
+ import * as v from "valibot";
2
+ //#region src/token-sources/schema.d.ts
3
+ /**
4
+ * A path from the document's folder, never one that names a place on its own: no leading `/` or
5
+ * `\\` (POSIX roots, UNC shares), no `~` (a home folder), and no drive letter or URL scheme such
6
+ * as `C:` or `file:`.
7
+ */
8
+ declare const relativeTokenPathSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, 1024, undefined>, v.CheckAction<string, "A linked path is relative to the document">]>;
9
+ declare const tokenSourceSchema: v.ObjectSchema<{
10
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, 64, undefined>]>;
11
+ /** A stylesheet, a project folder, or W3C design token files. */
12
+ readonly kind: v.PicklistSchema<["css", "folder", "dtcg"], undefined>;
13
+ /** The file or folder name, for people. */
14
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>]>;
15
+ /** Where it is from the document's folder, when the document has one. */
16
+ readonly path: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, 1024, undefined>, v.CheckAction<string, "A linked path is relative to the document">]>, undefined>;
17
+ readonly syncedAt: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, undefined>]>, undefined>;
18
+ /** What the code held at the last sync: a value signature by variable id and mode id. */
19
+ readonly snapshot: v.RecordSchema<v.StringSchema<undefined>, v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
20
+ /**
21
+ * The token each variable was at the last sync, `Collection/name` by variable id, so a variable
22
+ * deleted on the canvas is known when the code still has it.
23
+ */
24
+ readonly names: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
25
+ /**
26
+ * The names the document held when it was saved, `Collection/name` by variable id. A format that
27
+ * keys variables by name gives them new ids when it reads them back; this finds a renamed
28
+ * variable's new id while `names` keeps the token it was at the last sync.
29
+ */
30
+ readonly currentNames: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
31
+ /**
32
+ * The mode names the document holds, by collection name and mode id. A format that keys variables
33
+ * and modes by name gives them new ids when it reads them back, and this maps the snapshot onto
34
+ * those.
35
+ */
36
+ readonly modes: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>, undefined>;
37
+ }, undefined>;
38
+ type TokenSource = v.InferOutput<typeof tokenSourceSchema>;
39
+ /** The code a document's variables are linked to; entries that cannot be read are left out. */
40
+ declare const tokenSourcesSchema: v.GenericSchema<unknown, TokenSource[]>;
41
+ //#endregion
42
+ export { TokenSource, relativeTokenPathSchema, tokenSourcesSchema };
43
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/token-sources/schema.ts"],"mappings":";;;;;;;cAOa,yBAAuB,EAAA,yBAAA,EAAA,yBAAA,EAAA,mCAAA,EAAA,0CAAA,EAAA;cAU9B,mBAAiB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BX,cAAc,EAAE,mBAAmB;;cAGlC,oBAAoB,EAAE,uBAAuB"}
@@ -0,0 +1,50 @@
1
+ import * as v from "valibot";
2
+ //#region src/token-sources/schema.ts
3
+ /**
4
+ * A path from the document's folder, never one that names a place on its own: no leading `/` or
5
+ * `\\` (POSIX roots, UNC shares), no `~` (a home folder), and no drive letter or URL scheme such
6
+ * as `C:` or `file:`.
7
+ */
8
+ const relativeTokenPathSchema = v.pipe(v.string(), v.nonEmpty(), v.maxLength(1024), v.check((path) => !/^(?:[/\\~]|[a-z][\w+.-]*:)/i.test(path), "A linked path is relative to the document"));
9
+ const tokenSourceSchema = v.object({
10
+ id: v.pipe(v.string(), v.nonEmpty(), v.maxLength(64)),
11
+ /** A stylesheet, a project folder, or W3C design token files. */
12
+ kind: v.picklist([
13
+ "css",
14
+ "folder",
15
+ "dtcg"
16
+ ]),
17
+ /** The file or folder name, for people. */
18
+ name: v.pipe(v.string(), v.maxLength(256)),
19
+ /** Where it is from the document's folder, when the document has one. */
20
+ path: v.optional(relativeTokenPathSchema),
21
+ syncedAt: v.optional(v.pipe(v.string(), v.isoTimestamp())),
22
+ /** What the code held at the last sync: a value signature by variable id and mode id. */
23
+ snapshot: v.record(v.string(), v.record(v.string(), v.string())),
24
+ /**
25
+ * The token each variable was at the last sync, `Collection/name` by variable id, so a variable
26
+ * deleted on the canvas is known when the code still has it.
27
+ */
28
+ names: v.optional(v.record(v.string(), v.string())),
29
+ /**
30
+ * The names the document held when it was saved, `Collection/name` by variable id. A format that
31
+ * keys variables by name gives them new ids when it reads them back; this finds a renamed
32
+ * variable's new id while `names` keeps the token it was at the last sync.
33
+ */
34
+ currentNames: v.optional(v.record(v.string(), v.string())),
35
+ /**
36
+ * The mode names the document holds, by collection name and mode id. A format that keys variables
37
+ * and modes by name gives them new ids when it reads them back, and this maps the snapshot onto
38
+ * those.
39
+ */
40
+ modes: v.optional(v.record(v.string(), v.record(v.string(), v.string())))
41
+ });
42
+ /** The code a document's variables are linked to; entries that cannot be read are left out. */
43
+ const tokenSourcesSchema = v.pipe(v.array(v.unknown()), v.transform((items) => items.flatMap((item) => {
44
+ const parsed = v.safeParse(tokenSourceSchema, item);
45
+ return parsed.success ? [parsed.output] : [];
46
+ })));
47
+ //#endregion
48
+ export { relativeTokenPathSchema, tokenSourcesSchema };
49
+
50
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../../src/token-sources/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\n/**\n * A path from the document's folder, never one that names a place on its own: no leading `/` or\n * `\\\\` (POSIX roots, UNC shares), no `~` (a home folder), and no drive letter or URL scheme such\n * as `C:` or `file:`.\n */\nexport const relativeTokenPathSchema = v.pipe(\n v.string(),\n v.nonEmpty(),\n v.maxLength(1024),\n v.check(\n (path) => !/^(?:[/\\\\~]|[a-z][\\w+.-]*:)/i.test(path),\n 'A linked path is relative to the document'\n )\n)\n\nconst tokenSourceSchema = v.object({\n id: v.pipe(v.string(), v.nonEmpty(), v.maxLength(64)),\n /** A stylesheet, a project folder, or W3C design token files. */\n kind: v.picklist(['css', 'folder', 'dtcg']),\n /** The file or folder name, for people. */\n name: v.pipe(v.string(), v.maxLength(256)),\n /** Where it is from the document's folder, when the document has one. */\n path: v.optional(relativeTokenPathSchema),\n syncedAt: v.optional(v.pipe(v.string(), v.isoTimestamp())),\n /** What the code held at the last sync: a value signature by variable id and mode id. */\n snapshot: v.record(v.string(), v.record(v.string(), v.string())),\n /**\n * The token each variable was at the last sync, `Collection/name` by variable id, so a variable\n * deleted on the canvas is known when the code still has it.\n */\n names: v.optional(v.record(v.string(), v.string())),\n /**\n * The names the document held when it was saved, `Collection/name` by variable id. A format that\n * keys variables by name gives them new ids when it reads them back; this finds a renamed\n * variable's new id while `names` keeps the token it was at the last sync.\n */\n currentNames: v.optional(v.record(v.string(), v.string())),\n /**\n * The mode names the document holds, by collection name and mode id. A format that keys variables\n * and modes by name gives them new ids when it reads them back, and this maps the snapshot onto\n * those.\n */\n modes: v.optional(v.record(v.string(), v.record(v.string(), v.string())))\n})\n\nexport type TokenSource = v.InferOutput<typeof tokenSourceSchema>\n\n/** The code a document's variables are linked to; entries that cannot be read are left out. */\nexport const tokenSourcesSchema: v.GenericSchema<unknown, TokenSource[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(tokenSourceSchema, item)\n return parsed.success ? [parsed.output] : []\n })\n )\n)\n"],"mappings":";;;;;;;AAOA,MAAa,0BAA0B,EAAE,KACvC,EAAE,OAAO,GACT,EAAE,SAAS,GACX,EAAE,UAAU,IAAI,GAChB,EAAE,OACC,SAAS,CAAC,8BAA8B,K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d.ts","names":[],"sources":["../../src/transfer/variables.ts"],"mappings":";;UAIiB;EACf,WAAW;EACX,aAAa;EACb,OAAO;;;iBAsCO,wBACd,oBAAoB,YACpB,sBAAsB,sBACtB,YAAY;EACT,WAAW;EAAY,aAAa"}
@@ -15,7 +15,7 @@ function assertResourceOwnership(variables, collections) {
15
15
  }
16
16
  for (const variable of variables) {
17
17
  const collection = sets.get(variable.collectionId);
18
- if (!collection?.variableIds.includes(variable.id)) throw new Error(`Missing collection membership for ${variable.id}`);
18
+ if (!collection || !variable.deleted && !collection.variableIds.includes(variable.id)) throw new Error(`Missing collection membership for ${variable.id}`);
19
19
  const modes = new Set(collection.modes.map((mode) => mode.modeId));
20
20
  for (const mode of Object.keys(variable.valuesByMode)) if (!modes.has(mode)) throw new Error(`Unknown mode ${mode} for ${variable.id}`);
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"variables.js","names":["mapped"],"sources":["../../src/transfer/variables.ts"],"sourcesContent":["import type { Variable, VariableCollection, VariableValue } from '../types'\nimport { mapVariableValueReferences } from '../variables/value'\nimport { requireTransferReference as mapped } from './references'\n\nexport interface VariableTransferReferences {\n variables: ReadonlyMap<string, string>\n collections: ReadonlyMap<string, string>\n modes: ReadonlyMap<string, string>\n}\n\nfunction assertUniqueMappings(ids: ReadonlyMap<string, string>, kind: string): void {\n if (new Set(ids.values()).size !== ids.size)\n throw new Error(`Colliding ${kind} transfer mappings`)\n}\n\nfunction assertResourceOwnership(\n variables: readonly Variable[],\n collections: readonly VariableCollection[]\n): void {\n const sets = new Map(collections.map((collection) => [collection.id, collection]))\n const tokens = new Map(variables.map((variable) => [variable.id, variable]))\n if (sets.size !== collections.length || tokens.size !== variables.length)\n throw new Error('Duplicate source variable resource')\n for (const collection of collections) {\n const modes = new Set(collection.modes.map((mode) => mode.modeId))\n if (!modes.has(collection.defaultModeId) || modes.size !== collection.modes.length)\n throw new Error(`Invalid modes for collection ${collection.id}`)\n for (const id of collection.variableIds) {\n if (tokens.get(id)?.collectionId !== collection.id)\n throw new Error(`Invalid variable membership ${id} in ${collection.id}`)\n }\n }\n for (const variable of variables) {\n const collection = sets.get(variable.collectionId)\n if (!collection?.variableIds.includes(variable.id))\n throw new Error(`Missing collection membership for ${variable.id}`)\n const modes = new Set(collection.modes.map((mode) => mode.modeId))\n for (const mode of Object.keys(variable.valuesByMode)) {\n if (!modes.has(mode)) throw new Error(`Unknown mode ${mode} for ${variable.id}`)\n }\n }\n}\n\n/** Prepare isolated resource copies; never mutate the source or destination graph. */\nexport function prepareVariableTransfer(\n variables: readonly Variable[],\n collections: readonly VariableCollection[],\n references: VariableTransferReferences\n): { variables: Variable[]; collections: VariableCollection[] } {\n assertResourceOwnership(variables, collections)\n assertUniqueMappings(references.variables, 'variable')\n assertUniqueMappings(references.collections, 'collection')\n assertUniqueMappings(references.modes, 'mode')\n const value = (input: VariableValue): VariableValue =>\n mapVariableValueReferences(\n input,\n (id) => mapped(references.variables, id, 'variable alias'),\n (id) => references.modes.get(id) ?? id\n )\n return {\n collections: collections.map((collection) => ({\n ...structuredClone(collection),\n id: mapped(references.collections, collection.id, 'collection'),\n defaultModeId: mapped(references.modes, collection.defaultModeId, 'mode'),\n modes: collection.modes.map((mode) => ({\n ...mode,\n modeId: mapped(references.modes, mode.modeId, 'mode')\n })),\n variableIds: collection.variableIds.map((id) => mapped(references.variables, id, 'variable'))\n })),\n variables: variables.map((variable) => ({\n ...structuredClone(variable),\n id: mapped(references.variables, variable.id, 'variable'),\n collectionId: mapped(references.collections, variable.collectionId, 'collection'),\n valuesByMode: Object.fromEntries(\n Object.entries(variable.valuesByMode).map(([mode, input]) => [\n mapped(references.modes, mode, 'mode'),\n value(input)\n ])\n )\n }))\n }\n}\n"],"mappings":";;;AAUA,SAAS,qBAAqB,KAAkC,MAAoB;CAClF,IAAI,IAAI,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,MACrC,MAAM,IAAI,MAAM,aAAa,KAAK,mBAAmB;AACzD;AAEA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,2BACE,QACC,OAAOA,yBAAO,WAAW,WAAW,IAAI,gBAAgB,IACxD,OAAO,WAAW,MAAM,IAAI,EAAE,KAAK,EACtC;CACF,OAAO;EACL,aAAa,YAAY,KAAK,gBAAgB;GAC5C,GAAG,gBAAgB,UAAU;GAC7B,IAAIA,yBAAO,WAAW,aAAa,WAAW,IAAI,YAAY;GAC9D,eAAeA,yBAAO,WAAW,OAAO,WAAW,eAAe,MAAM;GACxE,OAAO,WAAW,MAAM,KAAK,UAAU;IACrC,GAAG;IACH,QAAQA,yBAAO,WAAW,OAAO,KAAK,QAAQ,MAAM;GACtD,EAAE;GACF,aAAa,WAAW,YAAY,KAAK,OAAOA,yBAAO,WAAW,WAAW,IAAI,UAAU,CAAC;EAC9F,EAAE;EACF,WAAW,UAAU,KAAK,cAAc;GACtC,GAAG,gBAAgB,QAAQ;GAC3B,IAAIA,yBAAO,WAAW,WAAW,SAAS,IAAI,UAAU;GACxD,cAAcA,yBAAO,WAAW,aAAa,SAAS,cAAc,YAAY;GAChF,cAAc,OAAO,YACnB,OAAO,QAAQ,SAAS,YAAY,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAC3DA,yBAAO,WAAW,OAAO,MAAM,MAAM,GACrC,MAAM,KAAK,CACb,CAAC,CACH;EACF,EAAE;CACJ;AACF"}
1
+ {"version":3,"file":"variables.js","names":["mapped"],"sources":["../../src/transfer/variables.ts"],"sourcesContent":["import type { Variable, VariableCollection, VariableValue } from '../types'\nimport { mapVariableValueReferences } from '../variables/value'\nimport { requireTransferReference as mapped } from './references'\n\nexport interface VariableTransferReferences {\n variables: ReadonlyMap<string, string>\n collections: ReadonlyMap<string, string>\n modes: ReadonlyMap<string, string>\n}\n\nfunction assertUniqueMappings(ids: ReadonlyMap<string, string>, kind: string): void {\n if (new Set(ids.values()).size !== ids.size)\n throw new Error(`Colliding ${kind} transfer mappings`)\n}\n\nfunction assertResourceOwnership(\n variables: readonly Variable[],\n collections: readonly VariableCollection[]\n): void {\n const sets = new Map(collections.map((collection) => [collection.id, collection]))\n const tokens = new Map(variables.map((variable) => [variable.id, variable]))\n if (sets.size !== collections.length || tokens.size !== variables.length)\n throw new Error('Duplicate source variable resource')\n for (const collection of collections) {\n const modes = new Set(collection.modes.map((mode) => mode.modeId))\n if (!modes.has(collection.defaultModeId) || modes.size !== collection.modes.length)\n throw new Error(`Invalid modes for collection ${collection.id}`)\n for (const id of collection.variableIds) {\n if (tokens.get(id)?.collectionId !== collection.id)\n throw new Error(`Invalid variable membership ${id} in ${collection.id}`)\n }\n }\n for (const variable of variables) {\n const collection = sets.get(variable.collectionId)\n // A collection lists its live variables: a deleted one is kept out of the list (addVariable).\n if (!collection || (!variable.deleted && !collection.variableIds.includes(variable.id)))\n throw new Error(`Missing collection membership for ${variable.id}`)\n const modes = new Set(collection.modes.map((mode) => mode.modeId))\n for (const mode of Object.keys(variable.valuesByMode)) {\n if (!modes.has(mode)) throw new Error(`Unknown mode ${mode} for ${variable.id}`)\n }\n }\n}\n\n/** Prepare isolated resource copies; never mutate the source or destination graph. */\nexport function prepareVariableTransfer(\n variables: readonly Variable[],\n collections: readonly VariableCollection[],\n references: VariableTransferReferences\n): { variables: Variable[]; collections: VariableCollection[] } {\n assertResourceOwnership(variables, collections)\n assertUniqueMappings(references.variables, 'variable')\n assertUniqueMappings(references.collections, 'collection')\n assertUniqueMappings(references.modes, 'mode')\n const value = (input: VariableValue): VariableValue =>\n mapVariableValueReferences(\n input,\n (id) => mapped(references.variables, id, 'variable alias'),\n (id) => references.modes.get(id) ?? id\n )\n return {\n collections: collections.map((collection) => ({\n ...structuredClone(collection),\n id: mapped(references.collections, collection.id, 'collection'),\n defaultModeId: mapped(references.modes, collection.defaultModeId, 'mode'),\n modes: collection.modes.map((mode) => ({\n ...mode,\n modeId: mapped(references.modes, mode.modeId, 'mode')\n })),\n variableIds: collection.variableIds.map((id) => mapped(references.variables, id, 'variable'))\n })),\n variables: variables.map((variable) => ({\n ...structuredClone(variable),\n id: mapped(references.variables, variable.id, 'variable'),\n collectionId: mapped(references.collections, variable.collectionId, 'collection'),\n valuesByMode: Object.fromEntries(\n Object.entries(variable.valuesByMode).map(([mode, input]) => [\n mapped(references.modes, mode, 'mode'),\n value(input)\n ])\n )\n }))\n }\n}\n"],"mappings":";;;AAUA,SAAS,qBAAqB,KAAkC,MAAoB;CAClF,IAAI,IAAI,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,MACrC,MAAM,IAAI,MAAM,aAAa,KAAK,mBAAmB;AACzD;AAEA,SAAS,wBACP,WACA,aACM;CACN,MAAM,OAAO,IAAI,IAAI,YAAY,KAAK,eAAe,CAAC,WAAW,IAAI,UAAU,CAAC,CAAC;CACjF,MAAM,SAAS,IAAI,IAAI,UAAU,KAAK,aAAa,CAAC,SAAS,IAAI,QAAQ,CAAC,CAAC;CAC3E,IAAI,KAAK,SAAS,YAAY,UAAU,OAAO,SAAS,UAAU,QAChE,MAAM,IAAI,MAAM,oCAAoC;CACtD,KAAK,MAAM,cAAc,aAAa;EACpC,MAAM,QAAQ,IAAI,IAAI,WAAW,MAAM,KAAK,SAAS,KAAK,MAAM,CAAC;EACjE,IAAI,CAAC,MAAM,IAAI,WAAW,aAAa,KAAK,MAAM,SAAS,WAAW,MAAM,QAC1E,MAAM,IAAI,MAAM,gCAAgC,WAAW,IAAI;EACjE,KAAK,MAAM,MAAM,WAAW,aAC1B,IAAI,OAAO,IAAI,EAAE,CAAC,EAAE,iBAAiB,WAAW,IAC9C,MAAM,IAAI,MAAM,+BAA+B,GAAG,MAAM,WAAW,IAAI;CAE7E;CACA,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,aAAa,KAAK,IAAI,SAAS,YAAY;EAEjD,IAAI,CAAC,cAAe,CAAC,SAAS,WAAW,CAAC,WAAW,YAAY,SAAS,SAAS,EAAE,GACnF,MAAM,IAAI,MAAM,qCAAqC,SAAS,IAAI;EACpE,MAAM,QAAQ,IAAI,IAAI,WAAW,MAAM,KAAK,SAA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