@moondraft/import 0.0.0-stage → 0.2.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 (337) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +394 -0
  5. package/dist/adapter/convert.d.ts +144 -0
  6. package/dist/adapter/convert.js +2811 -0
  7. package/dist/adapter/figma-descriptions.d.ts +7 -0
  8. package/dist/adapter/figma-descriptions.js +34 -0
  9. package/dist/adapter/figma-grids.d.ts +12 -0
  10. package/dist/adapter/figma-grids.js +175 -0
  11. package/dist/adapter/figma-handoff.d.ts +12 -0
  12. package/dist/adapter/figma-handoff.js +167 -0
  13. package/dist/adapter/figma-hyperlinks.d.ts +13 -0
  14. package/dist/adapter/figma-hyperlinks.js +77 -0
  15. package/dist/adapter/figma.d.ts +12 -0
  16. package/dist/adapter/figma.js +40 -0
  17. package/dist/adapter/file-components.d.ts +20 -0
  18. package/dist/adapter/file-components.js +352 -0
  19. package/dist/adapter/file-resources.d.ts +29 -0
  20. package/dist/adapter/file-resources.js +851 -0
  21. package/dist/adapter/image-crop.d.ts +18 -0
  22. package/dist/adapter/image-crop.js +30 -0
  23. package/dist/adapter/index.d.ts +6 -0
  24. package/dist/adapter/index.js +9 -0
  25. package/dist/adapter/link.d.ts +49 -0
  26. package/dist/adapter/link.js +892 -0
  27. package/dist/adapter/payload.d.ts +31 -0
  28. package/dist/adapter/payload.js +78 -0
  29. package/dist/adapter/shapes.d.ts +31 -0
  30. package/dist/adapter/shapes.js +75 -0
  31. package/dist/adapter/variables.d.ts +45 -0
  32. package/dist/adapter/variables.js +106 -0
  33. package/dist/figma-file.d.ts +38 -0
  34. package/dist/figma-file.js +97 -0
  35. package/dist/figma-worker.d.ts +11 -0
  36. package/dist/figma-worker.js +12 -0
  37. package/dist/figma.d.ts +26 -0
  38. package/dist/figma.js +230 -0
  39. package/dist/index.d.ts +29 -0
  40. package/dist/index.js +50 -0
  41. package/dist/report.d.ts +42 -0
  42. package/dist/report.js +142 -0
  43. package/dist/serialize.d.ts +7 -0
  44. package/dist/serialize.js +79 -0
  45. package/dist/svg.d.ts +33 -0
  46. package/dist/svg.js +44 -0
  47. package/dist/syntax.d.ts +8 -0
  48. package/dist/syntax.js +19 -0
  49. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  50. package/dist/taco/figma-import/clipboard.js +87 -0
  51. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  52. package/dist/taco/figma-import/clipboardSize.js +107 -0
  53. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  54. package/dist/taco/figma-import/container/compression.js +174 -0
  55. package/dist/taco/figma-import/container/error.d.ts +15 -0
  56. package/dist/taco/figma-import/container/error.js +19 -0
  57. package/dist/taco/figma-import/container/kiwiContainer.d.ts +41 -0
  58. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  59. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  60. package/dist/taco/figma-import/container/limits.js +22 -0
  61. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  62. package/dist/taco/figma-import/container/zip.js +154 -0
  63. package/dist/taco/figma-import/figFile.d.ts +34 -0
  64. package/dist/taco/figma-import/figFile.js +91 -0
  65. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  66. package/dist/taco/figma-import/figFileDocument.js +100 -0
  67. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  68. package/dist/taco/figma-import/import/blobs.js +23 -0
  69. package/dist/taco/figma-import/import/carry.d.ts +24 -0
  70. package/dist/taco/figma-import/import/carry.js +66 -0
  71. package/dist/taco/figma-import/import/componentProps.d.ts +90 -0
  72. package/dist/taco/figma-import/import/componentProps.js +329 -0
  73. package/dist/taco/figma-import/import/componentSets.d.ts +85 -0
  74. package/dist/taco/figma-import/import/componentSets.js +647 -0
  75. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  76. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  77. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  78. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  79. package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
  80. package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
  81. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  82. package/dist/taco/figma-import/import/converters/frame.js +63 -0
  83. package/dist/taco/figma-import/import/converters/gradient.d.ts +74 -0
  84. package/dist/taco/figma-import/import/converters/gradient.js +108 -0
  85. package/dist/taco/figma-import/import/converters/group.d.ts +19 -0
  86. package/dist/taco/figma-import/import/converters/group.js +30 -0
  87. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  88. package/dist/taco/figma-import/import/converters/image.js +94 -0
  89. package/dist/taco/figma-import/import/converters/layout.d.ts +33 -0
  90. package/dist/taco/figma-import/import/converters/layout.js +187 -0
  91. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  92. package/dist/taco/figma-import/import/converters/line.js +40 -0
  93. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  94. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  95. package/dist/taco/figma-import/import/converters/section.d.ts +8 -0
  96. package/dist/taco/figma-import/import/converters/section.js +29 -0
  97. package/dist/taco/figma-import/import/converters/shared.d.ts +71 -0
  98. package/dist/taco/figma-import/import/converters/shared.js +372 -0
  99. package/dist/taco/figma-import/import/converters/text.d.ts +54 -0
  100. package/dist/taco/figma-import/import/converters/text.js +707 -0
  101. package/dist/taco/figma-import/import/converters/vector.d.ts +105 -0
  102. package/dist/taco/figma-import/import/converters/vector.js +609 -0
  103. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +114 -0
  104. package/dist/taco/figma-import/import/converters/vectorNetwork.js +503 -0
  105. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  106. package/dist/taco/figma-import/import/fields.js +29 -0
  107. package/dist/taco/figma-import/import/instances.d.ts +184 -0
  108. package/dist/taco/figma-import/import/instances.js +1530 -0
  109. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  110. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  111. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  112. package/dist/taco/figma-import/import/slots.js +96 -0
  113. package/dist/taco/figma-import/import/styles.d.ts +48 -0
  114. package/dist/taco/figma-import/import/styles.js +48 -0
  115. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  116. package/dist/taco/figma-import/import/tree.js +194 -0
  117. package/dist/taco/figma-import/import/types.d.ts +232 -0
  118. package/dist/taco/figma-import/import/types.js +33 -0
  119. package/dist/taco/figma-import/import/variables.d.ts +137 -0
  120. package/dist/taco/figma-import/import/variables.js +769 -0
  121. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  122. package/dist/taco/figma-import/import/variantTrees.js +520 -0
  123. package/dist/taco/figma-import/import/walk.d.ts +207 -0
  124. package/dist/taco/figma-import/import/walk.js +1464 -0
  125. package/dist/taco/figma-import/index.d.ts +22 -0
  126. package/dist/taco/figma-import/index.js +13 -0
  127. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  128. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  129. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  130. package/dist/taco/figma-import/kiwi/error.js +29 -0
  131. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  132. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  133. package/dist/taco/figma-import/kiwi/message.d.ts +12 -0
  134. package/dist/taco/figma-import/kiwi/message.js +147 -0
  135. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  136. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  137. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  138. package/dist/taco/figma-import/kiwi/types.js +18 -0
  139. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  140. package/dist/taco/model/agent-hidden-fields.js +29 -0
  141. package/dist/taco/model/asset-users.d.ts +23 -0
  142. package/dist/taco/model/asset-users.js +128 -0
  143. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  144. package/dist/taco/model/auto-layout-lines.js +70 -0
  145. package/dist/taco/model/codec.d.ts +444 -0
  146. package/dist/taco/model/codec.js +5665 -0
  147. package/dist/taco/model/color.d.ts +11 -0
  148. package/dist/taco/model/color.js +61 -0
  149. package/dist/taco/model/comment-operations.d.ts +102 -0
  150. package/dist/taco/model/comment-operations.js +227 -0
  151. package/dist/taco/model/component-evaluation.d.ts +96 -0
  152. package/dist/taco/model/component-evaluation.js +555 -0
  153. package/dist/taco/model/component-expressions.d.ts +242 -0
  154. package/dist/taco/model/component-expressions.js +1082 -0
  155. package/dist/taco/model/component-properties.d.ts +111 -0
  156. package/dist/taco/model/component-properties.js +339 -0
  157. package/dist/taco/model/component-samples.d.ts +83 -0
  158. package/dist/taco/model/component-samples.js +290 -0
  159. package/dist/taco/model/component-validity.d.ts +85 -0
  160. package/dist/taco/model/component-validity.js +397 -0
  161. package/dist/taco/model/components.d.ts +155 -0
  162. package/dist/taco/model/components.js +505 -0
  163. package/dist/taco/model/connector-ends.d.ts +20 -0
  164. package/dist/taco/model/connector-ends.js +188 -0
  165. package/dist/taco/model/connector-geometry.d.ts +74 -0
  166. package/dist/taco/model/connector-geometry.js +293 -0
  167. package/dist/taco/model/corner-radii.d.ts +26 -0
  168. package/dist/taco/model/corner-radii.js +47 -0
  169. package/dist/taco/model/derivations.d.ts +81 -0
  170. package/dist/taco/model/derivations.js +151 -0
  171. package/dist/taco/model/export-settings.d.ts +53 -0
  172. package/dist/taco/model/export-settings.js +156 -0
  173. package/dist/taco/model/expressions/ast.d.ts +153 -0
  174. package/dist/taco/model/expressions/ast.js +6 -0
  175. package/dist/taco/model/expressions/cache.d.ts +23 -0
  176. package/dist/taco/model/expressions/cache.js +43 -0
  177. package/dist/taco/model/expressions/check.d.ts +72 -0
  178. package/dist/taco/model/expressions/check.js +517 -0
  179. package/dist/taco/model/expressions/completion.d.ts +61 -0
  180. package/dist/taco/model/expressions/completion.js +421 -0
  181. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  182. package/dist/taco/model/expressions/evaluate.js +519 -0
  183. package/dist/taco/model/expressions/forms.d.ts +84 -0
  184. package/dist/taco/model/expressions/forms.js +200 -0
  185. package/dist/taco/model/expressions/index.d.ts +14 -0
  186. package/dist/taco/model/expressions/index.js +17 -0
  187. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  188. package/dist/taco/model/expressions/lexer.js +213 -0
  189. package/dist/taco/model/expressions/library.d.ts +33 -0
  190. package/dist/taco/model/expressions/library.js +117 -0
  191. package/dist/taco/model/expressions/names.d.ts +43 -0
  192. package/dist/taco/model/expressions/names.js +99 -0
  193. package/dist/taco/model/expressions/parser.d.ts +15 -0
  194. package/dist/taco/model/expressions/parser.js +438 -0
  195. package/dist/taco/model/expressions/rename.d.ts +34 -0
  196. package/dist/taco/model/expressions/rename.js +46 -0
  197. package/dist/taco/model/expressions/source.d.ts +15 -0
  198. package/dist/taco/model/expressions/source.js +161 -0
  199. package/dist/taco/model/expressions/types.d.ts +119 -0
  200. package/dist/taco/model/expressions/types.js +102 -0
  201. package/dist/taco/model/expressions/values.d.ts +97 -0
  202. package/dist/taco/model/expressions/values.js +160 -0
  203. package/dist/taco/model/geometry-limits.d.ts +16 -0
  204. package/dist/taco/model/geometry-limits.js +67 -0
  205. package/dist/taco/model/geometry.d.ts +47 -0
  206. package/dist/taco/model/geometry.js +193 -0
  207. package/dist/taco/model/group-bounds.d.ts +38 -0
  208. package/dist/taco/model/group-bounds.js +144 -0
  209. package/dist/taco/model/id-table.d.ts +37 -0
  210. package/dist/taco/model/id-table.js +80 -0
  211. package/dist/taco/model/index.d.ts +25 -0
  212. package/dist/taco/model/index.js +27 -0
  213. package/dist/taco/model/instance-resolver.d.ts +376 -0
  214. package/dist/taco/model/instance-resolver.js +1778 -0
  215. package/dist/taco/model/layer-syntax.d.ts +340 -0
  216. package/dist/taco/model/layer-syntax.js +3506 -0
  217. package/dist/taco/model/layout/constraints.d.ts +84 -0
  218. package/dist/taco/model/layout/constraints.js +445 -0
  219. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  220. package/dist/taco/model/layout/frame-layout.js +618 -0
  221. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  222. package/dist/taco/model/layout/node-sizing.js +486 -0
  223. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  224. package/dist/taco/model/legacy-connector-caps.js +70 -0
  225. package/dist/taco/model/linear-call.d.ts +48 -0
  226. package/dist/taco/model/linear-call.js +58 -0
  227. package/dist/taco/model/new-nodes.d.ts +145 -0
  228. package/dist/taco/model/new-nodes.js +277 -0
  229. package/dist/taco/model/node-builder.d.ts +449 -0
  230. package/dist/taco/model/node-builder.js +2294 -0
  231. package/dist/taco/model/node-table-watch.d.ts +36 -0
  232. package/dist/taco/model/node-table-watch.js +63 -0
  233. package/dist/taco/model/node-transform.d.ts +39 -0
  234. package/dist/taco/model/node-transform.js +79 -0
  235. package/dist/taco/model/node-users-index.d.ts +10 -0
  236. package/dist/taco/model/node-users-index.js +82 -0
  237. package/dist/taco/model/operation-references.d.ts +80 -0
  238. package/dist/taco/model/operation-references.js +399 -0
  239. package/dist/taco/model/operations.d.ts +610 -0
  240. package/dist/taco/model/operations.js +2882 -0
  241. package/dist/taco/model/overlay-table.d.ts +71 -0
  242. package/dist/taco/model/overlay-table.js +171 -0
  243. package/dist/taco/model/override-remap.d.ts +69 -0
  244. package/dist/taco/model/override-remap.js +230 -0
  245. package/dist/taco/model/parent-table.d.ts +53 -0
  246. package/dist/taco/model/parent-table.js +193 -0
  247. package/dist/taco/model/problem-collector.d.ts +27 -0
  248. package/dist/taco/model/problem-collector.js +101 -0
  249. package/dist/taco/model/sha256.d.ts +10 -0
  250. package/dist/taco/model/sha256.js +79 -0
  251. package/dist/taco/model/shape-geometry.d.ts +96 -0
  252. package/dist/taco/model/shape-geometry.js +368 -0
  253. package/dist/taco/model/shared-node-table.d.ts +97 -0
  254. package/dist/taco/model/shared-node-table.js +546 -0
  255. package/dist/taco/model/slots.d.ts +113 -0
  256. package/dist/taco/model/slots.js +281 -0
  257. package/dist/taco/model/stroke-settings.d.ts +37 -0
  258. package/dist/taco/model/stroke-settings.js +90 -0
  259. package/dist/taco/model/svg-path-import.d.ts +89 -0
  260. package/dist/taco/model/svg-path-import.js +219 -0
  261. package/dist/taco/model/text-measurement.d.ts +142 -0
  262. package/dist/taco/model/text-measurement.js +846 -0
  263. package/dist/taco/model/text-reads.d.ts +66 -0
  264. package/dist/taco/model/text-reads.js +128 -0
  265. package/dist/taco/model/text-sizer.d.ts +358 -0
  266. package/dist/taco/model/text-sizer.js +996 -0
  267. package/dist/taco/model/theme-users.d.ts +59 -0
  268. package/dist/taco/model/theme-users.js +312 -0
  269. package/dist/taco/model/thumbnail.d.ts +15 -0
  270. package/dist/taco/model/thumbnail.js +34 -0
  271. package/dist/taco/model/types.d.ts +2369 -0
  272. package/dist/taco/model/types.js +366 -0
  273. package/dist/taco/model/unknown-property.d.ts +5 -0
  274. package/dist/taco/model/unknown-property.js +7 -0
  275. package/dist/taco/model/validated-documents.d.ts +22 -0
  276. package/dist/taco/model/validated-documents.js +22 -0
  277. package/dist/taco/model/variable-modes.d.ts +61 -0
  278. package/dist/taco/model/variable-modes.js +438 -0
  279. package/dist/taco/model/variable-references.d.ts +54 -0
  280. package/dist/taco/model/variable-references.js +183 -0
  281. package/dist/taco/model/variables.d.ts +24 -0
  282. package/dist/taco/model/variables.js +151 -0
  283. package/dist/taco/model/vector-network.d.ts +34 -0
  284. package/dist/taco/model/vector-network.js +411 -0
  285. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  286. package/dist/taco/svg-import/import-svg.js +729 -0
  287. package/dist/taco/svg-import/index.d.ts +3 -0
  288. package/dist/taco/svg-import/index.js +3 -0
  289. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  290. package/dist/taco/svg-import/limits/limits.js +160 -0
  291. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  292. package/dist/taco/svg-import/paint/gradients.js +429 -0
  293. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  294. package/dist/taco/svg-import/paint/paint.js +162 -0
  295. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  296. package/dist/taco/svg-import/paths/paths.js +205 -0
  297. package/dist/taco/svg-import/public-types.d.ts +279 -0
  298. package/dist/taco/svg-import/public-types.js +56 -0
  299. package/dist/taco/svg-import/report/report.d.ts +44 -0
  300. package/dist/taco/svg-import/report/report.js +79 -0
  301. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  302. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  303. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  304. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  305. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  306. package/dist/taco/svg-import/structure/effects.js +618 -0
  307. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  308. package/dist/taco/svg-import/structure/image.js +495 -0
  309. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  310. package/dist/taco/svg-import/structure/walk.js +544 -0
  311. package/dist/taco/svg-import/style/color.d.ts +40 -0
  312. package/dist/taco/svg-import/style/color.js +275 -0
  313. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  314. package/dist/taco/svg-import/style/computed.js +1534 -0
  315. package/dist/taco/svg-import/style/css.d.ts +127 -0
  316. package/dist/taco/svg-import/style/css.js +541 -0
  317. package/dist/taco/svg-import/style/media.d.ts +25 -0
  318. package/dist/taco/svg-import/style/media.js +307 -0
  319. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  320. package/dist/taco/svg-import/style/properties.js +135 -0
  321. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  322. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  323. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  324. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  325. package/dist/taco/svg-import/text/text.d.ts +29 -0
  326. package/dist/taco/svg-import/text/text.js +545 -0
  327. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  328. package/dist/taco/svg-import/transform/matrix.js +229 -0
  329. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  330. package/dist/taco/svg-import/tree/element-data.js +155 -0
  331. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  332. package/dist/taco/svg-import/tree/elements.js +121 -0
  333. package/dist/taco/svg-import/units/length.d.ts +43 -0
  334. package/dist/taco/svg-import/units/length.js +125 -0
  335. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  336. package/dist/taco/svg-import/units/viewbox.js +77 -0
  337. package/package.json +55 -4
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The table `overlayTable` wrote over, the entries written to it since, and
3
+ * the key of each write in the order they came (a key once per write), so a
4
+ * reader can look at only the writes since it last looked.
5
+ */
6
+ export interface OverlayParts<Value> {
7
+ readonly base: Readonly<Record<string, Value>>;
8
+ readonly written: ReadonlyMap<string, Value>;
9
+ readonly writes: readonly string[];
10
+ }
11
+ /**
12
+ * Counts of the work done here, for tests that check what an edit costs:
13
+ * how often every entry of an overlay table was listed (`tableValues`, or
14
+ * `Object.keys` and the like through the Proxy).
15
+ */
16
+ export declare const overlayTableStats: {
17
+ wholeListings: number;
18
+ };
19
+ /**
20
+ * Entries read by key, for `overlayTableReading`: `get` gives undefined for
21
+ * a key it lacks, and `keys` lists each key it has once.
22
+ */
23
+ export interface EntryLookup<Value> {
24
+ get(key: string): Value | undefined;
25
+ keys(): Iterable<string>;
26
+ }
27
+ /**
28
+ * A table that reads as `source` with the entries written to it since, and
29
+ * keeps those writes to itself: what `copyTable(source)` gives, without
30
+ * copying `source`. Reading or writing an entry costs the same at any size
31
+ * of `source`;
32
+ * listing the entries (`Object.keys`, `Object.values`, a spread) goes
33
+ * through the Proxy one entry at a time, so a pass that lists every entry
34
+ * should use `tableValues`. Meant for a short-lived working table, such as the
35
+ * nodes a layout pass writes, over a document table of many thousands of
36
+ * nodes. An entry cannot be deleted from it.
37
+ *
38
+ * Over a table `overlayTable` made, it is written over that table's own
39
+ * `base` and starts with that table's writes, in their order: a chain of
40
+ * such tables reads one table deep, and its cost grows with the writes, not
41
+ * with the base.
42
+ */
43
+ export declare function overlayTable<Value>(source: Readonly<Record<string, Value>>): Record<string, Value>;
44
+ /**
45
+ * The values of `table` in the order `Object.values` lists them. For a table
46
+ * `overlayTable` made, they are read from its table and its writes directly,
47
+ * not one entry at a time through the Proxy, which costs about twice as much
48
+ * as listing a plain table of the same size.
49
+ */
50
+ export declare function tableValues<Value>(table: Readonly<Record<string, Value>>): Value[];
51
+ /** The parts behind a table `overlayTable` made, or undefined for any other table. */
52
+ export declare function overlayParts<Value>(table: Readonly<Record<string, Value>>): OverlayParts<Value> | undefined;
53
+ /**
54
+ * Closes `table`, made by `overlayTable`, to writes, as `Object.freeze`
55
+ * closes a plain table: from then on a write to it throws a `TypeError` in
56
+ * strict code. A Proxy cannot be frozen while it lists entries its target
57
+ * does not have, so `Object.isFrozen` stays false for it; `isSealedOverlay`
58
+ * tells such a table apart.
59
+ */
60
+ export declare function sealOverlay<Value>(table: Record<string, Value>): Readonly<Record<string, Value>>;
61
+ /**
62
+ * A sealed table that reads as `source` with the entries of `written` over
63
+ * it, and reads `written` itself instead of a copy, so making one costs the
64
+ * same at any size of either: a view that keeps most of its entries from one
65
+ * update to the next passes the same `written` again. `written` must not
66
+ * change once passed; it may find its entries as they are asked for. It reads as a sealed overlay (`isSealedOverlay`) but
67
+ * has no `overlayParts`: a table written over it reads it as its base.
68
+ */
69
+ export declare function overlayTableReading<Value>(source: Readonly<Record<string, Value>>, written: EntryLookup<Value>): Readonly<Record<string, Value>>;
70
+ /** Whether `table` is a table `overlayTable` made that `sealOverlay` has closed. */
71
+ export declare function isSealedOverlay(table: object): boolean;
@@ -0,0 +1,171 @@
1
+ /**
2
+ * A working node table written over a document's table without copying it.
3
+ * Internal: the package does not export this module.
4
+ */
5
+ import { noteListing, tableKeys, tableValues as sharedTableValues } from "./shared-node-table.js";
6
+ /**
7
+ * Counts of the work done here, for tests that check what an edit costs:
8
+ * how often every entry of an overlay table was listed (`tableValues`, or
9
+ * `Object.keys` and the like through the Proxy).
10
+ */
11
+ export const overlayTableStats = { wholeListings: 0 };
12
+ /** The parts behind each table `overlayTable` made. */
13
+ const overlays = new WeakMap();
14
+ /** The table and the entries each table `overlayTableReading` made reads. */
15
+ const readingTables = new WeakMap();
16
+ /** The tables `overlayTable` made that `sealOverlay` has closed to writes. */
17
+ const sealedOverlays = new WeakSet();
18
+ /**
19
+ * A table that reads as `source` with the entries written to it since, and
20
+ * keeps those writes to itself: what `copyTable(source)` gives, without
21
+ * copying `source`. Reading or writing an entry costs the same at any size
22
+ * of `source`;
23
+ * listing the entries (`Object.keys`, `Object.values`, a spread) goes
24
+ * through the Proxy one entry at a time, so a pass that lists every entry
25
+ * should use `tableValues`. Meant for a short-lived working table, such as the
26
+ * nodes a layout pass writes, over a document table of many thousands of
27
+ * nodes. An entry cannot be deleted from it.
28
+ *
29
+ * Over a table `overlayTable` made, it is written over that table's own
30
+ * `base` and starts with that table's writes, in their order: a chain of
31
+ * such tables reads one table deep, and its cost grows with the writes, not
32
+ * with the base.
33
+ */
34
+ export function overlayTable(source) {
35
+ const under = overlays.get(source);
36
+ const base = under?.base ?? source;
37
+ const written = new Map(under?.written);
38
+ const writes = under === undefined ? [] : [...under.writes];
39
+ const has = (key) => (typeof key === "string" && (written.has(key) || Object.hasOwn(base, key)));
40
+ const read = (key) => (written.has(key) ? written.get(key) : base[key]);
41
+ const write = (key, value) => {
42
+ if (typeof key !== "string" || sealedOverlays.has(table))
43
+ return false;
44
+ written.set(key, value);
45
+ writes.push(key);
46
+ return true;
47
+ };
48
+ const table = new Proxy({}, {
49
+ // Only the table's own entries: no inherited member is read through it.
50
+ get: (_target, key) => (has(key) ? read(key) : undefined),
51
+ has: (_target, key) => has(key),
52
+ set: (_target, key, value) => write(key, value),
53
+ defineProperty: (_target, key, descriptor) => "value" in descriptor && write(key, descriptor.value),
54
+ deleteProperty: () => false,
55
+ // A Proxy that lists entries its target lacks cannot be made
56
+ // non-extensible: `Object.freeze`, `Object.seal` and
57
+ // `Object.preventExtensions` throw a `TypeError` and leave the table as
58
+ // it was, instead of leaving the target closed and every later listing
59
+ // broken. `sealOverlay` closes it to writes.
60
+ preventExtensions: () => false,
61
+ ownKeys: () => {
62
+ overlayTableStats.wholeListings += 1;
63
+ const keys = tableKeys(base);
64
+ for (const key of written.keys())
65
+ if (!Object.hasOwn(base, key))
66
+ keys.push(key);
67
+ noteListing(keys.length);
68
+ return keys;
69
+ },
70
+ getOwnPropertyDescriptor: (_target, key) => (has(key) ? { value: read(key), writable: true, enumerable: true, configurable: true } : undefined),
71
+ });
72
+ overlays.set(table, { base, written, writes });
73
+ return table;
74
+ }
75
+ /**
76
+ * The values of `table` in the order `Object.values` lists them. For a table
77
+ * `overlayTable` made, they are read from its table and its writes directly,
78
+ * not one entry at a time through the Proxy, which costs about twice as much
79
+ * as listing a plain table of the same size.
80
+ */
81
+ export function tableValues(table) {
82
+ const reading = readingTables.get(table);
83
+ if (reading !== undefined) {
84
+ overlayTableStats.wholeListings += 1;
85
+ const source = reading.source;
86
+ const written = reading.written;
87
+ const values = tableKeys(source).map((key) => written.get(key) ?? source[key]);
88
+ for (const key of written.keys())
89
+ if (!Object.hasOwn(source, key))
90
+ values.push(written.get(key));
91
+ noteListing(values.length);
92
+ return values;
93
+ }
94
+ const overlay = overlays.get(table);
95
+ if (overlay === undefined)
96
+ return sharedTableValues(table);
97
+ overlayTableStats.wholeListings += 1;
98
+ const base = overlay.base;
99
+ const written = overlay.written;
100
+ if (written.size === 0)
101
+ return sharedTableValues(base);
102
+ const values = tableKeys(base).map((key) => (written.has(key) ? written.get(key) : base[key]));
103
+ for (const [key, value] of written)
104
+ if (!Object.hasOwn(base, key))
105
+ values.push(value);
106
+ noteListing(values.length);
107
+ return values;
108
+ }
109
+ /** The parts behind a table `overlayTable` made, or undefined for any other table. */
110
+ export function overlayParts(table) {
111
+ return overlays.get(table);
112
+ }
113
+ /**
114
+ * Closes `table`, made by `overlayTable`, to writes, as `Object.freeze`
115
+ * closes a plain table: from then on a write to it throws a `TypeError` in
116
+ * strict code. A Proxy cannot be frozen while it lists entries its target
117
+ * does not have, so `Object.isFrozen` stays false for it; `isSealedOverlay`
118
+ * tells such a table apart.
119
+ */
120
+ export function sealOverlay(table) {
121
+ if (!overlays.has(table))
122
+ throw new TypeError("sealOverlay needs a table that overlayTable made");
123
+ sealedOverlays.add(table);
124
+ return table;
125
+ }
126
+ /**
127
+ * A sealed table that reads as `source` with the entries of `written` over
128
+ * it, and reads `written` itself instead of a copy, so making one costs the
129
+ * same at any size of either: a view that keeps most of its entries from one
130
+ * update to the next passes the same `written` again. `written` must not
131
+ * change once passed; it may find its entries as they are asked for. It reads as a sealed overlay (`isSealedOverlay`) but
132
+ * has no `overlayParts`: a table written over it reads it as its base.
133
+ */
134
+ export function overlayTableReading(source, written) {
135
+ const read = (key) => {
136
+ if (typeof key !== "string")
137
+ return undefined;
138
+ const value = written.get(key);
139
+ if (value !== undefined)
140
+ return value;
141
+ return Object.hasOwn(source, key) ? source[key] : undefined;
142
+ };
143
+ const table = new Proxy({}, {
144
+ get: (_target, key) => read(key),
145
+ has: (_target, key) => read(key) !== undefined,
146
+ set: () => false,
147
+ defineProperty: () => false,
148
+ deleteProperty: () => false,
149
+ preventExtensions: () => false,
150
+ ownKeys: () => {
151
+ overlayTableStats.wholeListings += 1;
152
+ const keys = tableKeys(source);
153
+ for (const key of written.keys())
154
+ if (!Object.hasOwn(source, key))
155
+ keys.push(key);
156
+ noteListing(keys.length);
157
+ return keys;
158
+ },
159
+ getOwnPropertyDescriptor: (_target, key) => {
160
+ const value = read(key);
161
+ return value === undefined ? undefined : { value, writable: true, enumerable: true, configurable: true };
162
+ },
163
+ });
164
+ sealedOverlays.add(table);
165
+ readingTables.set(table, { source, written });
166
+ return table;
167
+ }
168
+ /** Whether `table` is a table `overlayTable` made that `sealOverlay` has closed. */
169
+ export function isSealedOverlay(table) {
170
+ return sealedOverlays.has(table);
171
+ }
@@ -0,0 +1,69 @@
1
+ import { type ComponentId, type DesignDocument, type InstanceNode, type LayerOverride, type NodeId } from "./types.ts";
2
+ /**
3
+ * One component's layer tree as a remap or prune reads it: the document
4
+ * that holds the nodes and the component's root. Swap passes one document
5
+ * with two roots; redefine and paste pass the old and the new document.
6
+ * @since 0.23.0
7
+ */
8
+ export interface OverrideRemapTree {
9
+ readonly document: DesignDocument;
10
+ readonly rootId: NodeId;
11
+ /**
12
+ * The component the nested instance at a layer path (inside the instance
13
+ * whose overrides are remapped) shows, for when its component is computed
14
+ * from a property value. Without it, or when it returns undefined, the
15
+ * nested instance node's stored component counts. An override swap at the
16
+ * path still wins.
17
+ * @since 0.26.0
18
+ */
19
+ readonly shownComponentAt?: (path: readonly NodeId[]) => ComponentId | undefined;
20
+ }
21
+ /**
22
+ * A `shownComponentAt` for the stored instance `instanceId`: the component
23
+ * each nested instance shows once the instance resolves, so a component an
24
+ * instance swap property selects counts. The instance resolves on the first
25
+ * lookup. A path the resolved tree leaves out (a layer hidden by its
26
+ * condition), or an instance that does not resolve, gives undefined, and the
27
+ * stored component counts.
28
+ * @since 0.26.0
29
+ */
30
+ export declare function resolvedShownComponents(document: DesignDocument, instanceId: NodeId): (path: readonly NodeId[]) => ComponentId | undefined;
31
+ /**
32
+ * Maps a layer path (an override or slot key's node IDs) from the component
33
+ * tree `from` to `to`, as `remapOverrides` maps its keys: each segment by
34
+ * name and position, a nested instance segment continuing into the
35
+ * component it shows on each side (after any swap in `fromOverrides` or
36
+ * `toOverrides`). Undefined when a segment has no match.
37
+ * @since 0.37.0
38
+ */
39
+ export declare function remapLayerPath(path: readonly NodeId[], from: OverrideRemapTree, to: OverrideRemapTree, fromOverrides?: Readonly<Record<string, LayerOverride>>, toOverrides?: Readonly<Record<string, LayerOverride>>): readonly NodeId[] | undefined;
40
+ /**
41
+ * Carries an instance's overrides over to another component tree by layer
42
+ * name and position (design 3.5): each key's layers are matched from the
43
+ * root down by name at the same index among their siblings, else by the
44
+ * first sibling with that name; a nested instance segment continues into
45
+ * the component it shows. Keys with no match are dropped, and a key that is
46
+ * remapped onto another key's target is dropped as well (the earlier key
47
+ * wins). Property values on a nested instance's entry are carried to the
48
+ * component that layer shows on the other side (`carryPropertyValues`, with
49
+ * `mapComponent` for instance swap values). Swap, redefine and paste use
50
+ * this, then store the result.
51
+ * @since 0.23.0
52
+ */
53
+ export declare function remapOverrides(overrides: Readonly<Record<string, LayerOverride>> | undefined, from: OverrideRemapTree, to: OverrideRemapTree, mapComponent?: (id: ComponentId) => ComponentId): Record<string, LayerOverride>;
54
+ /**
55
+ * Whether an override key names a layer the component still has: every
56
+ * segment but the last must be a nested instance node in the tree entered
57
+ * so far (after any swap in `overrides`, else the component
58
+ * `shownComponentAt` gives), and the last a node in that tree.
59
+ * @since 0.23.0
60
+ */
61
+ export declare function overridePathResolves(document: DesignDocument, componentId: ComponentId, path: readonly NodeId[], overrides?: Readonly<Record<string, LayerOverride>>, shownComponentAt?: (path: readonly NodeId[]) => ComponentId | undefined): boolean;
62
+ /**
63
+ * The instance without the override keys that name layers its component no
64
+ * longer has (design 3.5); the same node when every key still resolves.
65
+ * `shown` is the instance's `shownComponentAt` (`resolvedShownComponents`);
66
+ * pass one when the instance is resolved anyway, so it resolves once.
67
+ * @since 0.23.0
68
+ */
69
+ export declare function pruneOverrides(document: DesignDocument, instance: InstanceNode, shown?: (path: readonly NodeId[]) => ComponentId | undefined): InstanceNode;
@@ -0,0 +1,230 @@
1
+ import { carryPropertyValues } from "./component-properties.js";
2
+ import { layerPathKey, parseLayerPath, virtualNodeId } from "./components.js";
3
+ import { resolveInstance } from "./instance-resolver.js";
4
+ import { isContainerNode, } from "./types.js";
5
+ import { entryOf, hasEntry, putEntry } from "./id-table.js";
6
+ function indexTree(document, rootId) {
7
+ const nodes = new Map();
8
+ const visit = (id, parentId, index) => {
9
+ const node = entryOf(document.nodes, id);
10
+ if (node === undefined || nodes.has(id))
11
+ return;
12
+ nodes.set(id, { node, parentId, index });
13
+ if (isContainerNode(node))
14
+ node.children.forEach((childId, childIndex) => visit(childId, id, childIndex));
15
+ };
16
+ visit(rootId, undefined, 0);
17
+ return { nodes };
18
+ }
19
+ /** The places from the component root down to `nodeId`, the root left out. */
20
+ function placesOf(tree, nodeId) {
21
+ const places = [];
22
+ let current = nodeId;
23
+ while (current !== undefined) {
24
+ const entry = tree.nodes.get(current);
25
+ if (entry === undefined)
26
+ return undefined;
27
+ if (entry.parentId !== undefined)
28
+ places.unshift({ name: entry.node.name, index: entry.index });
29
+ current = entry.parentId;
30
+ }
31
+ return places;
32
+ }
33
+ /**
34
+ * Follows `places` down from `rootId`: at each step the child with the same
35
+ * name at the same index, else the first child with that name.
36
+ */
37
+ function findByPlaces(document, rootId, places) {
38
+ let current = entryOf(document.nodes, rootId);
39
+ for (const place of places) {
40
+ if (current === undefined || !isContainerNode(current))
41
+ return undefined;
42
+ const siblings = current.children.map((childId) => entryOf(document.nodes, childId));
43
+ const atIndex = siblings[place.index];
44
+ const match = atIndex !== undefined && atIndex.name === place.name
45
+ ? atIndex
46
+ : siblings.find((sibling) => sibling?.name === place.name);
47
+ if (match === undefined)
48
+ return undefined;
49
+ current = match;
50
+ }
51
+ return current?.id;
52
+ }
53
+ /** The component a nested instance shows once `overrides` are applied. */
54
+ function shownComponentId(node, overrides, path, tree) {
55
+ if (node.type !== "instance")
56
+ return undefined;
57
+ return entryOf(overrides, layerPathKey(path))?.componentId ?? tree.shownComponentAt?.(path) ?? node.componentId;
58
+ }
59
+ /**
60
+ * A `shownComponentAt` for the stored instance `instanceId`: the component
61
+ * each nested instance shows once the instance resolves, so a component an
62
+ * instance swap property selects counts. The instance resolves on the first
63
+ * lookup. A path the resolved tree leaves out (a layer hidden by its
64
+ * condition), or an instance that does not resolve, gives undefined, and the
65
+ * stored component counts.
66
+ * @since 0.26.0
67
+ */
68
+ export function resolvedShownComponents(document, instanceId) {
69
+ let resolved;
70
+ return (path) => {
71
+ if (resolved === undefined) {
72
+ try {
73
+ resolved = resolveInstance(document, instanceId);
74
+ }
75
+ catch {
76
+ // A missing component or a broken tree: the stored components count, as before resolving.
77
+ resolved = null;
78
+ }
79
+ }
80
+ return resolved?.layers.get(virtualNodeId(instanceId, path))?.instance?.componentId;
81
+ };
82
+ }
83
+ /**
84
+ * Remaps one override key from `from` to `to`, segment by segment: a
85
+ * segment inside a component tree is matched by name and position, and a
86
+ * nested instance segment continues into the component that instance shows.
87
+ */
88
+ function remapPath(path, from, to, overrides, mapped) {
89
+ const result = [];
90
+ let fromRoot = from.rootId;
91
+ let toRoot = to.rootId;
92
+ for (let index = 0; index < path.length; index += 1) {
93
+ const segment = path[index];
94
+ const places = placesOf(indexTree(from.document, fromRoot), segment);
95
+ if (places === undefined)
96
+ return undefined;
97
+ // A component root named as the addressed layer maps to the other root.
98
+ const target = places.length === 0 ? toRoot : findByPlaces(to.document, toRoot, places);
99
+ if (target === undefined)
100
+ return undefined;
101
+ result.push(target);
102
+ if (index === path.length - 1)
103
+ break;
104
+ const fromNested = entryOf(from.document.nodes, segment);
105
+ const toNested = entryOf(to.document.nodes, target);
106
+ if (fromNested === undefined || toNested === undefined)
107
+ return undefined;
108
+ const fromComponent = shownComponentId(fromNested, overrides, path.slice(0, index + 1), from);
109
+ const toComponent = shownComponentId(toNested, mapped, result, to);
110
+ const nextFromRoot = fromComponent === undefined ? undefined : entryOf(from.document.components, fromComponent)?.rootId;
111
+ const nextToRoot = toComponent === undefined ? undefined : entryOf(to.document.components, toComponent)?.rootId;
112
+ if (nextFromRoot === undefined || nextToRoot === undefined)
113
+ return undefined;
114
+ fromRoot = nextFromRoot;
115
+ toRoot = nextToRoot;
116
+ }
117
+ return result;
118
+ }
119
+ /**
120
+ * Maps a layer path (an override or slot key's node IDs) from the component
121
+ * tree `from` to `to`, as `remapOverrides` maps its keys: each segment by
122
+ * name and position, a nested instance segment continuing into the
123
+ * component it shows on each side (after any swap in `fromOverrides` or
124
+ * `toOverrides`). Undefined when a segment has no match.
125
+ * @since 0.37.0
126
+ */
127
+ export function remapLayerPath(path, from, to, fromOverrides = {}, toOverrides = {}) {
128
+ return remapPath(path, from, to, fromOverrides, toOverrides);
129
+ }
130
+ /**
131
+ * The override with its property values carried from the component the
132
+ * layer shows on one side (`from`) to the one it shows on the other (`to`).
133
+ */
134
+ function withRemappedValues(override, from, to, mapComponent) {
135
+ if (override.propertyValues === undefined)
136
+ return override;
137
+ const { propertyValues: _old, ...rest } = override;
138
+ const propertyValues = to === undefined ? undefined : carryPropertyValues(from, to, override.propertyValues, mapComponent);
139
+ return propertyValues === undefined ? rest : { ...rest, propertyValues };
140
+ }
141
+ /**
142
+ * Carries an instance's overrides over to another component tree by layer
143
+ * name and position (design 3.5): each key's layers are matched from the
144
+ * root down by name at the same index among their siblings, else by the
145
+ * first sibling with that name; a nested instance segment continues into
146
+ * the component it shows. Keys with no match are dropped, and a key that is
147
+ * remapped onto another key's target is dropped as well (the earlier key
148
+ * wins). Property values on a nested instance's entry are carried to the
149
+ * component that layer shows on the other side (`carryPropertyValues`, with
150
+ * `mapComponent` for instance swap values). Swap, redefine and paste use
151
+ * this, then store the result.
152
+ * @since 0.23.0
153
+ */
154
+ export function remapOverrides(overrides, from, to, mapComponent = (id) => id) {
155
+ const mapped = {};
156
+ if (overrides === undefined)
157
+ return mapped;
158
+ // Shorter keys first, so a nested instance's swap is known before the keys under it.
159
+ const keys = Object.keys(overrides).sort((left, right) => left.length - right.length || left.localeCompare(right));
160
+ for (const key of keys) {
161
+ const path = parseLayerPath(key);
162
+ if (path === null)
163
+ continue;
164
+ const target = remapPath(path, from, to, overrides, mapped);
165
+ if (target === undefined)
166
+ continue;
167
+ const targetKey = layerPathKey(target);
168
+ if (hasEntry(mapped, targetKey))
169
+ continue;
170
+ const override = entryOf(overrides, key);
171
+ const fromNode = entryOf(from.document.nodes, path.at(-1));
172
+ const toNode = entryOf(to.document.nodes, target.at(-1));
173
+ const fromComponent = fromNode === undefined ? undefined : shownComponentId(fromNode, overrides, path, from);
174
+ const toComponent = toNode === undefined ? undefined : shownComponentId(toNode, { [targetKey]: override }, target, to);
175
+ putEntry(mapped, targetKey, withRemappedValues(override, fromComponent === undefined ? undefined : entryOf(from.document.components, fromComponent), toComponent === undefined ? undefined : entryOf(to.document.components, toComponent), mapComponent));
176
+ }
177
+ return mapped;
178
+ }
179
+ /**
180
+ * Whether an override key names a layer the component still has: every
181
+ * segment but the last must be a nested instance node in the tree entered
182
+ * so far (after any swap in `overrides`, else the component
183
+ * `shownComponentAt` gives), and the last a node in that tree.
184
+ * @since 0.23.0
185
+ */
186
+ export function overridePathResolves(document, componentId, path, overrides = {}, shownComponentAt) {
187
+ let component = entryOf(document.components, componentId);
188
+ for (let index = 0; index < path.length; index += 1) {
189
+ if (component === undefined)
190
+ return false;
191
+ const tree = indexTree(document, component.rootId);
192
+ const segment = path[index];
193
+ const entry = tree.nodes.get(segment);
194
+ if (entry === undefined)
195
+ return false;
196
+ if (index === path.length - 1)
197
+ return true;
198
+ const shown = shownComponentId(entry.node, overrides, path.slice(0, index + 1), { document, rootId: component.rootId, ...(shownComponentAt === undefined ? {} : { shownComponentAt }) });
199
+ if (shown === undefined)
200
+ return false;
201
+ component = entryOf(document.components, shown);
202
+ }
203
+ return false;
204
+ }
205
+ /**
206
+ * The instance without the override keys that name layers its component no
207
+ * longer has (design 3.5); the same node when every key still resolves.
208
+ * `shown` is the instance's `shownComponentAt` (`resolvedShownComponents`);
209
+ * pass one when the instance is resolved anyway, so it resolves once.
210
+ * @since 0.23.0
211
+ */
212
+ export function pruneOverrides(document, instance, shown = resolvedShownComponents(document, instance.id)) {
213
+ if (instance.overrides === undefined)
214
+ return instance;
215
+ const kept = {};
216
+ let dropped = false;
217
+ // A nested instance an instance swap property points elsewhere keeps the keys inside what it shows.
218
+ for (const [key, override] of Object.entries(instance.overrides)) {
219
+ const path = parseLayerPath(key);
220
+ if (path !== null && overridePathResolves(document, instance.componentId, path, instance.overrides, shown)) {
221
+ putEntry(kept, key, override);
222
+ }
223
+ else
224
+ dropped = true;
225
+ }
226
+ if (!dropped)
227
+ return instance;
228
+ const { overrides: _overrides, ...rest } = instance;
229
+ return Object.keys(kept).length === 0 ? rest : { ...rest, overrides: kept };
230
+ }
@@ -0,0 +1,53 @@
1
+ import { type NodeId, type SceneNode } from "./types.ts";
2
+ type NodeRecord = Readonly<Record<string, SceneNode>>;
3
+ /** Counts of the work done here, for tests that check what an edit costs. */
4
+ export declare const parentTableStats: {
5
+ /** Parent tables built by reading every node of a record (`buildParentMap`). */
6
+ wholeBuilds: number;
7
+ };
8
+ export declare function buildParentMap(nodes: NodeRecord): Map<NodeId, NodeId>;
9
+ /**
10
+ * The parent ID of each node that has one, read one node at a time: all
11
+ * that the edit code asks of a parent table.
12
+ */
13
+ export type ParentLookup = Pick<ReadonlyMap<NodeId, NodeId>, "get" | "has">;
14
+ /**
15
+ * The parent ID of every node in `nodes`, like `buildParentMap`, but kept for
16
+ * a frozen record: a committed document never changes, so the table is built
17
+ * once per document version instead of once per question. Panels ask for a
18
+ * layer's parent many times per selection, and on a page of thousands of
19
+ * layers each fresh table read every layer. A record that is not frozen can
20
+ * still change, so its table is built again each time. A record that an edit
21
+ * made from another (`applyOperations`) has its table recorded with
22
+ * `recordParents`, derived from the table of the record it came from, so a
23
+ * document of many layers does not pay a pass over every layer per edit.
24
+ */
25
+ export declare function parentMapOf(nodes: NodeRecord): ReadonlyMap<NodeId, NodeId>;
26
+ /**
27
+ * The parent table of `next`, a node record made from `previous` (whose table
28
+ * is `previousParents`) by writing, inserting or removing only the nodes
29
+ * `touched`. Every node whose parent differs between the two is a node in
30
+ * `touched`, a child of one in either record, or one gone from `next`, so
31
+ * only those are read: the work grows with the touched nodes and their
32
+ * children, not with the record. Every few edits the table is built whole
33
+ * instead (`MAX_DERIVED_PARENTS_DEPTH`), so lookups stay short.
34
+ */
35
+ export declare function derivedParents(previous: NodeRecord, previousParents: ReadonlyMap<NodeId, NodeId>, next: NodeRecord, touched: Iterable<NodeId>): ReadonlyMap<NodeId, NodeId>;
36
+ /** The parent table kept for `nodes`, or undefined when none has been built or recorded for it. */
37
+ export declare function keptParents(nodes: NodeRecord): ReadonlyMap<NodeId, NodeId> | undefined;
38
+ /**
39
+ * Keeps `parents` as the parent table of the frozen record `nodes`, for
40
+ * `parentMapOf`. `parents` must be that record's table, such as one
41
+ * `derivedParents` made from the record it came from.
42
+ */
43
+ export declare function recordParents(nodes: NodeRecord, parents: ReadonlyMap<NodeId, NodeId>): void;
44
+ /**
45
+ * Keeps the nodes the edit that made the frozen record `nodes` wrote,
46
+ * inserted or removed, for readers that derive something per edit only when
47
+ * asked (`changedSlotOwners`). Called by `applyOperations`, as
48
+ * `recordParents` is.
49
+ */
50
+ export declare function recordChangedNodes(nodes: NodeRecord, changedNodeIds: readonly NodeId[]): void;
51
+ /** The nodes recorded with `recordChangedNodes` for `nodes`, or undefined when no edit recorded any. */
52
+ export declare function recordedChangedNodes(nodes: NodeRecord): readonly NodeId[] | undefined;
53
+ export {};