@llc3233149/core 0.9.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 (457) hide show
  1. package/dist/canvaskit.d.ts +9 -0
  2. package/dist/canvaskit.d.ts.map +1 -0
  3. package/dist/canvaskit.js +55 -0
  4. package/dist/canvaskit.js.map +1 -0
  5. package/dist/clipboard.d.ts +32 -0
  6. package/dist/clipboard.d.ts.map +1 -0
  7. package/dist/clipboard.js +345 -0
  8. package/dist/clipboard.js.map +1 -0
  9. package/dist/color.d.ts +28 -0
  10. package/dist/color.d.ts.map +1 -0
  11. package/dist/color.js +67 -0
  12. package/dist/color.js.map +1 -0
  13. package/dist/constants.d.ts +159 -0
  14. package/dist/constants.d.ts.map +1 -0
  15. package/dist/constants.js +224 -0
  16. package/dist/constants.js.map +1 -0
  17. package/dist/copy.d.ts +20 -0
  18. package/dist/copy.d.ts.map +1 -0
  19. package/dist/copy.js +64 -0
  20. package/dist/copy.js.map +1 -0
  21. package/dist/fig-export-worker.d.ts +2 -0
  22. package/dist/fig-export-worker.d.ts.map +1 -0
  23. package/dist/fig-export-worker.js +17 -0
  24. package/dist/fig-export-worker.js.map +1 -0
  25. package/dist/fig-export.d.ts +13 -0
  26. package/dist/fig-export.d.ts.map +1 -0
  27. package/dist/fig-export.js +243 -0
  28. package/dist/fig-export.js.map +1 -0
  29. package/dist/figma-api.d.ts +268 -0
  30. package/dist/figma-api.d.ts.map +1 -0
  31. package/dist/figma-api.js +1074 -0
  32. package/dist/figma-api.js.map +1 -0
  33. package/dist/figma-rest-import.d.ts +122 -0
  34. package/dist/figma-rest-import.d.ts.map +1 -0
  35. package/dist/figma-rest-import.js +319 -0
  36. package/dist/figma-rest-import.js.map +1 -0
  37. package/dist/fonts.d.ts +24 -0
  38. package/dist/fonts.d.ts.map +1 -0
  39. package/dist/fonts.js +356 -0
  40. package/dist/fonts.js.map +1 -0
  41. package/dist/geometry.d.ts +14 -0
  42. package/dist/geometry.d.ts.map +1 -0
  43. package/dist/geometry.js +47 -0
  44. package/dist/geometry.js.map +1 -0
  45. package/dist/index.d.ts +38 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +32 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/kiwi/codec.d.ts +292 -0
  50. package/dist/kiwi/codec.d.ts.map +1 -0
  51. package/dist/kiwi/codec.js +340 -0
  52. package/dist/kiwi/codec.js.map +1 -0
  53. package/dist/kiwi/fig-file.d.ts +4 -0
  54. package/dist/kiwi/fig-file.d.ts.map +1 -0
  55. package/dist/kiwi/fig-file.js +236 -0
  56. package/dist/kiwi/fig-file.js.map +1 -0
  57. package/dist/kiwi/fig-import.d.ts +4 -0
  58. package/dist/kiwi/fig-import.d.ts.map +1 -0
  59. package/dist/kiwi/fig-import.js +248 -0
  60. package/dist/kiwi/fig-import.js.map +1 -0
  61. package/dist/kiwi/fig-parse-worker.d.ts +7 -0
  62. package/dist/kiwi/fig-parse-worker.d.ts.map +1 -0
  63. package/dist/kiwi/fig-parse-worker.js +184 -0
  64. package/dist/kiwi/fig-parse-worker.js.map +1 -0
  65. package/dist/kiwi/instance-overrides.d.ts +66 -0
  66. package/dist/kiwi/instance-overrides.d.ts.map +1 -0
  67. package/dist/kiwi/instance-overrides.js +644 -0
  68. package/dist/kiwi/instance-overrides.js.map +1 -0
  69. package/dist/kiwi/kiwi-convert.d.ts +19 -0
  70. package/dist/kiwi/kiwi-convert.d.ts.map +1 -0
  71. package/dist/kiwi/kiwi-convert.js +678 -0
  72. package/dist/kiwi/kiwi-convert.js.map +1 -0
  73. package/dist/kiwi/kiwi-schema/bb.d.ts +25 -0
  74. package/dist/kiwi/kiwi-schema/bb.d.ts.map +1 -0
  75. package/dist/kiwi/kiwi-schema/bb.js +225 -0
  76. package/dist/kiwi/kiwi-schema/bb.js.map +1 -0
  77. package/dist/kiwi/kiwi-schema/binary.d.ts +5 -0
  78. package/dist/kiwi/kiwi-schema/binary.d.ts.map +1 -0
  79. package/dist/kiwi/kiwi-schema/binary.js +86 -0
  80. package/dist/kiwi/kiwi-schema/binary.js.map +1 -0
  81. package/dist/kiwi/kiwi-schema/index.d.ts +6 -0
  82. package/dist/kiwi/kiwi-schema/index.d.ts.map +1 -0
  83. package/dist/kiwi/kiwi-schema/index.js +5 -0
  84. package/dist/kiwi/kiwi-schema/index.js.map +1 -0
  85. package/dist/kiwi/kiwi-schema/js.d.ts +4 -0
  86. package/dist/kiwi/kiwi-schema/js.d.ts.map +1 -0
  87. package/dist/kiwi/kiwi-schema/js.js +282 -0
  88. package/dist/kiwi/kiwi-schema/js.js.map +1 -0
  89. package/dist/kiwi/kiwi-schema/parser.d.ts +5 -0
  90. package/dist/kiwi/kiwi-schema/parser.d.ts.map +1 -0
  91. package/dist/kiwi/kiwi-schema/parser.js +228 -0
  92. package/dist/kiwi/kiwi-schema/parser.js.map +1 -0
  93. package/dist/kiwi/kiwi-schema/schema.d.ts +22 -0
  94. package/dist/kiwi/kiwi-schema/schema.d.ts.map +1 -0
  95. package/dist/kiwi/kiwi-schema/schema.js +2 -0
  96. package/dist/kiwi/kiwi-schema/schema.js.map +1 -0
  97. package/dist/kiwi/kiwi-schema/util.d.ts +3 -0
  98. package/dist/kiwi/kiwi-schema/util.d.ts.map +1 -0
  99. package/dist/kiwi/kiwi-schema/util.js +10 -0
  100. package/dist/kiwi/kiwi-schema/util.js.map +1 -0
  101. package/dist/kiwi/protocol.d.ts +172 -0
  102. package/dist/kiwi/protocol.d.ts.map +1 -0
  103. package/dist/kiwi/protocol.js +214 -0
  104. package/dist/kiwi/protocol.js.map +1 -0
  105. package/dist/kiwi/schema.d.ts +3 -0
  106. package/dist/kiwi/schema.d.ts.map +1 -0
  107. package/dist/kiwi/schema.js +2285 -0
  108. package/dist/kiwi/schema.js.map +1 -0
  109. package/dist/kiwi-serialize.d.ts +17 -0
  110. package/dist/kiwi-serialize.d.ts.map +1 -0
  111. package/dist/kiwi-serialize.js +419 -0
  112. package/dist/kiwi-serialize.js.map +1 -0
  113. package/dist/layout.d.ts +9 -0
  114. package/dist/layout.d.ts.map +1 -0
  115. package/dist/layout.js +533 -0
  116. package/dist/layout.js.map +1 -0
  117. package/dist/profiler/draw-call-counter.d.ts +9 -0
  118. package/dist/profiler/draw-call-counter.d.ts.map +1 -0
  119. package/dist/profiler/draw-call-counter.js +37 -0
  120. package/dist/profiler/draw-call-counter.js.map +1 -0
  121. package/dist/profiler/frame-capture.d.ts +34 -0
  122. package/dist/profiler/frame-capture.d.ts.map +1 -0
  123. package/dist/profiler/frame-capture.js +90 -0
  124. package/dist/profiler/frame-capture.js.map +1 -0
  125. package/dist/profiler/frame-stats.d.ts +33 -0
  126. package/dist/profiler/frame-stats.d.ts.map +1 -0
  127. package/dist/profiler/frame-stats.js +103 -0
  128. package/dist/profiler/frame-stats.js.map +1 -0
  129. package/dist/profiler/gpu-timer.d.ts +15 -0
  130. package/dist/profiler/gpu-timer.d.ts.map +1 -0
  131. package/dist/profiler/gpu-timer.js +77 -0
  132. package/dist/profiler/gpu-timer.js.map +1 -0
  133. package/dist/profiler/hud-renderer.d.ts +22 -0
  134. package/dist/profiler/hud-renderer.d.ts.map +1 -0
  135. package/dist/profiler/hud-renderer.js +200 -0
  136. package/dist/profiler/hud-renderer.js.map +1 -0
  137. package/dist/profiler/index.d.ts +9 -0
  138. package/dist/profiler/index.d.ts.map +1 -0
  139. package/dist/profiler/index.js +8 -0
  140. package/dist/profiler/index.js.map +1 -0
  141. package/dist/profiler/phase-timer.d.ts +9 -0
  142. package/dist/profiler/phase-timer.d.ts.map +1 -0
  143. package/dist/profiler/phase-timer.js +51 -0
  144. package/dist/profiler/phase-timer.js.map +1 -0
  145. package/dist/profiler/render-profiler.d.ts +41 -0
  146. package/dist/profiler/render-profiler.d.ts.map +1 -0
  147. package/dist/profiler/render-profiler.js +142 -0
  148. package/dist/profiler/render-profiler.js.map +1 -0
  149. package/dist/render/components.d.ts +25 -0
  150. package/dist/render/components.d.ts.map +1 -0
  151. package/dist/render/components.js +55 -0
  152. package/dist/render/components.js.map +1 -0
  153. package/dist/render/emoji-icons.d.ts +5 -0
  154. package/dist/render/emoji-icons.d.ts.map +1 -0
  155. package/dist/render/emoji-icons.js +55 -0
  156. package/dist/render/emoji-icons.js.map +1 -0
  157. package/dist/render/export-code.d.ts +9 -0
  158. package/dist/render/export-code.d.ts.map +1 -0
  159. package/dist/render/export-code.js +335 -0
  160. package/dist/render/export-code.js.map +1 -0
  161. package/dist/render/export-jsx.d.ts +5 -0
  162. package/dist/render/export-jsx.d.ts.map +1 -0
  163. package/dist/render/export-jsx.js +621 -0
  164. package/dist/render/export-jsx.js.map +1 -0
  165. package/dist/render/index.d.ts +8 -0
  166. package/dist/render/index.d.ts.map +1 -0
  167. package/dist/render/index.js +8 -0
  168. package/dist/render/index.js.map +1 -0
  169. package/dist/render/jsx-runtime.d.ts +31 -0
  170. package/dist/render/jsx-runtime.d.ts.map +1 -0
  171. package/dist/render/jsx-runtime.js +13 -0
  172. package/dist/render/jsx-runtime.js.map +1 -0
  173. package/dist/render/mini-react.d.ts +14 -0
  174. package/dist/render/mini-react.d.ts.map +1 -0
  175. package/dist/render/mini-react.js +16 -0
  176. package/dist/render/mini-react.js.map +1 -0
  177. package/dist/render/render-jsx.d.ts +24 -0
  178. package/dist/render/render-jsx.d.ts.map +1 -0
  179. package/dist/render/render-jsx.js +51 -0
  180. package/dist/render/render-jsx.js.map +1 -0
  181. package/dist/render/renderer.d.ts +16 -0
  182. package/dist/render/renderer.d.ts.map +1 -0
  183. package/dist/render/renderer.js +437 -0
  184. package/dist/render/renderer.js.map +1 -0
  185. package/dist/render/tailwind.d.ts +20 -0
  186. package/dist/render/tailwind.d.ts.map +1 -0
  187. package/dist/render/tailwind.js +115 -0
  188. package/dist/render/tailwind.js.map +1 -0
  189. package/dist/render/tree.d.ts +72 -0
  190. package/dist/render/tree.d.ts.map +1 -0
  191. package/dist/render/tree.js +63 -0
  192. package/dist/render/tree.js.map +1 -0
  193. package/dist/render-image.d.ts +19 -0
  194. package/dist/render-image.d.ts.map +1 -0
  195. package/dist/render-image.js +84 -0
  196. package/dist/render-image.js.map +1 -0
  197. package/dist/renderer/effects.d.ts +9 -0
  198. package/dist/renderer/effects.d.ts.map +1 -0
  199. package/dist/renderer/effects.js +44 -0
  200. package/dist/renderer/effects.js.map +1 -0
  201. package/dist/renderer/fills.d.ts +9 -0
  202. package/dist/renderer/fills.d.ts.map +1 -0
  203. package/dist/renderer/fills.js +189 -0
  204. package/dist/renderer/fills.js.map +1 -0
  205. package/dist/renderer/index.d.ts +2 -0
  206. package/dist/renderer/index.d.ts.map +1 -0
  207. package/dist/renderer/index.js +2 -0
  208. package/dist/renderer/index.js.map +1 -0
  209. package/dist/renderer/label-cache.d.ts +43 -0
  210. package/dist/renderer/label-cache.d.ts.map +1 -0
  211. package/dist/renderer/label-cache.js +85 -0
  212. package/dist/renderer/label-cache.js.map +1 -0
  213. package/dist/renderer/labels.d.ts +6 -0
  214. package/dist/renderer/labels.d.ts.map +1 -0
  215. package/dist/renderer/labels.js +126 -0
  216. package/dist/renderer/labels.js.map +1 -0
  217. package/dist/renderer/lru-cache.d.ts +20 -0
  218. package/dist/renderer/lru-cache.d.ts.map +1 -0
  219. package/dist/renderer/lru-cache.js +65 -0
  220. package/dist/renderer/lru-cache.js.map +1 -0
  221. package/dist/renderer/overlays.d.ts +25 -0
  222. package/dist/renderer/overlays.d.ts.map +1 -0
  223. package/dist/renderer/overlays.js +783 -0
  224. package/dist/renderer/overlays.js.map +1 -0
  225. package/dist/renderer/renderer.d.ts +229 -0
  226. package/dist/renderer/renderer.d.ts.map +1 -0
  227. package/dist/renderer/renderer.js +909 -0
  228. package/dist/renderer/renderer.js.map +1 -0
  229. package/dist/renderer/rulers.d.ts +8 -0
  230. package/dist/renderer/rulers.d.ts.map +1 -0
  231. package/dist/renderer/rulers.js +147 -0
  232. package/dist/renderer/rulers.js.map +1 -0
  233. package/dist/renderer/scene.d.ts +11 -0
  234. package/dist/renderer/scene.d.ts.map +1 -0
  235. package/dist/renderer/scene.js +392 -0
  236. package/dist/renderer/scene.js.map +1 -0
  237. package/dist/renderer/shapes.d.ts +13 -0
  238. package/dist/renderer/shapes.d.ts.map +1 -0
  239. package/dist/renderer/shapes.js +160 -0
  240. package/dist/renderer/shapes.js.map +1 -0
  241. package/dist/renderer/strokes.d.ts +9 -0
  242. package/dist/renderer/strokes.d.ts.map +1 -0
  243. package/dist/renderer/strokes.js +180 -0
  244. package/dist/renderer/strokes.js.map +1 -0
  245. package/dist/rpc/commands.d.ts +202 -0
  246. package/dist/rpc/commands.d.ts.map +1 -0
  247. package/dist/rpc/commands.js +429 -0
  248. package/dist/rpc/commands.js.map +1 -0
  249. package/dist/rpc/index.d.ts +3 -0
  250. package/dist/rpc/index.d.ts.map +1 -0
  251. package/dist/rpc/index.js +2 -0
  252. package/dist/rpc/index.js.map +1 -0
  253. package/dist/scene-graph.d.ts +318 -0
  254. package/dist/scene-graph.d.ts.map +1 -0
  255. package/dist/scene-graph.js +803 -0
  256. package/dist/scene-graph.js.map +1 -0
  257. package/dist/snap.d.ts +16 -0
  258. package/dist/snap.d.ts.map +1 -0
  259. package/dist/snap.js +97 -0
  260. package/dist/snap.js.map +1 -0
  261. package/dist/style-runs.d.ts +20 -0
  262. package/dist/style-runs.d.ts.map +1 -0
  263. package/dist/style-runs.js +168 -0
  264. package/dist/style-runs.js.map +1 -0
  265. package/dist/svg-export/defs.d.ts +19 -0
  266. package/dist/svg-export/defs.d.ts.map +1 -0
  267. package/dist/svg-export/defs.js +191 -0
  268. package/dist/svg-export/defs.js.map +1 -0
  269. package/dist/svg-export/index.d.ts +8 -0
  270. package/dist/svg-export/index.d.ts.map +1 -0
  271. package/dist/svg-export/index.js +318 -0
  272. package/dist/svg-export/index.js.map +1 -0
  273. package/dist/svg-export/paths.d.ts +9 -0
  274. package/dist/svg-export/paths.d.ts.map +1 -0
  275. package/dist/svg-export/paths.js +189 -0
  276. package/dist/svg-export/paths.js.map +1 -0
  277. package/dist/svg-node.d.ts +8 -0
  278. package/dist/svg-node.d.ts.map +1 -0
  279. package/dist/svg-node.js +48 -0
  280. package/dist/svg-node.js.map +1 -0
  281. package/dist/text-editor.d.ts +57 -0
  282. package/dist/text-editor.d.ts.map +1 -0
  283. package/dist/text-editor.js +337 -0
  284. package/dist/text-editor.js.map +1 -0
  285. package/dist/tools/ai-adapter.d.ts +22 -0
  286. package/dist/tools/ai-adapter.d.ts.map +1 -0
  287. package/dist/tools/ai-adapter.js +121 -0
  288. package/dist/tools/ai-adapter.js.map +1 -0
  289. package/dist/tools/analyze.d.ts +22 -0
  290. package/dist/tools/analyze.d.ts.map +1 -0
  291. package/dist/tools/analyze.js +677 -0
  292. package/dist/tools/analyze.js.map +1 -0
  293. package/dist/tools/create.d.ts +8 -0
  294. package/dist/tools/create.d.ts.map +1 -0
  295. package/dist/tools/create.js +204 -0
  296. package/dist/tools/create.js.map +1 -0
  297. package/dist/tools/describe.d.ts +9 -0
  298. package/dist/tools/describe.d.ts.map +1 -0
  299. package/dist/tools/describe.js +295 -0
  300. package/dist/tools/describe.js.map +1 -0
  301. package/dist/tools/export-code.d.ts +2 -0
  302. package/dist/tools/export-code.d.ts.map +1 -0
  303. package/dist/tools/export-code.js +34 -0
  304. package/dist/tools/export-code.js.map +1 -0
  305. package/dist/tools/export-tailwind-config.d.ts +27 -0
  306. package/dist/tools/export-tailwind-config.d.ts.map +1 -0
  307. package/dist/tools/export-tailwind-config.js +215 -0
  308. package/dist/tools/export-tailwind-config.js.map +1 -0
  309. package/dist/tools/icons.d.ts +5 -0
  310. package/dist/tools/icons.d.ts.map +1 -0
  311. package/dist/tools/icons.js +192 -0
  312. package/dist/tools/icons.js.map +1 -0
  313. package/dist/tools/index.d.ts +7 -0
  314. package/dist/tools/index.d.ts.map +1 -0
  315. package/dist/tools/index.js +6 -0
  316. package/dist/tools/index.js.map +1 -0
  317. package/dist/tools/modify.d.ts +22 -0
  318. package/dist/tools/modify.d.ts.map +1 -0
  319. package/dist/tools/modify.js +653 -0
  320. package/dist/tools/modify.js.map +1 -0
  321. package/dist/tools/patterns.d.ts +2 -0
  322. package/dist/tools/patterns.d.ts.map +1 -0
  323. package/dist/tools/patterns.js +173 -0
  324. package/dist/tools/patterns.js.map +1 -0
  325. package/dist/tools/read.d.ts +17 -0
  326. package/dist/tools/read.d.ts.map +1 -0
  327. package/dist/tools/read.js +379 -0
  328. package/dist/tools/read.js.map +1 -0
  329. package/dist/tools/registry.d.ts +3 -0
  330. package/dist/tools/registry.d.ts.map +1 -0
  331. package/dist/tools/registry.js +124 -0
  332. package/dist/tools/registry.js.map +1 -0
  333. package/dist/tools/schema.d.ts +46 -0
  334. package/dist/tools/schema.d.ts.map +1 -0
  335. package/dist/tools/schema.js +17 -0
  336. package/dist/tools/schema.js.map +1 -0
  337. package/dist/tools/structure.d.ts +18 -0
  338. package/dist/tools/structure.d.ts.map +1 -0
  339. package/dist/tools/structure.js +345 -0
  340. package/dist/tools/structure.js.map +1 -0
  341. package/dist/tools/variables.d.ts +12 -0
  342. package/dist/tools/variables.d.ts.map +1 -0
  343. package/dist/tools/variables.js +190 -0
  344. package/dist/tools/variables.js.map +1 -0
  345. package/dist/tools/vector.d.ts +15 -0
  346. package/dist/tools/vector.d.ts.map +1 -0
  347. package/dist/tools/vector.js +312 -0
  348. package/dist/tools/vector.js.map +1 -0
  349. package/dist/types.d.ts +29 -0
  350. package/dist/types.d.ts.map +1 -0
  351. package/dist/types.js +2 -0
  352. package/dist/types.js.map +1 -0
  353. package/dist/undo.d.ts +33 -0
  354. package/dist/undo.d.ts.map +1 -0
  355. package/dist/undo.js +98 -0
  356. package/dist/undo.js.map +1 -0
  357. package/dist/vector.d.ts +14 -0
  358. package/dist/vector.d.ts.map +1 -0
  359. package/dist/vector.js +334 -0
  360. package/dist/vector.js.map +1 -0
  361. package/dist/xpath.d.ts +8 -0
  362. package/dist/xpath.d.ts.map +1 -0
  363. package/dist/xpath.js +199 -0
  364. package/dist/xpath.js.map +1 -0
  365. package/package.json +54 -0
  366. package/src/canvaskit.ts +66 -0
  367. package/src/clipboard.ts +444 -0
  368. package/src/color.ts +83 -0
  369. package/src/constants.ts +277 -0
  370. package/src/copy.ts +75 -0
  371. package/src/fig-export-worker.ts +28 -0
  372. package/src/fig-export.ts +321 -0
  373. package/src/figma-api.ts +1297 -0
  374. package/src/figma-rest-import.ts +443 -0
  375. package/src/fonts.ts +369 -0
  376. package/src/geometry.ts +73 -0
  377. package/src/global.d.ts +20 -0
  378. package/src/index.ts +247 -0
  379. package/src/kiwi/codec.ts +614 -0
  380. package/src/kiwi/fig-file.ts +248 -0
  381. package/src/kiwi/fig-import.ts +300 -0
  382. package/src/kiwi/fig-parse-worker.ts +213 -0
  383. package/src/kiwi/instance-overrides.ts +682 -0
  384. package/src/kiwi/kiwi-convert.ts +771 -0
  385. package/src/kiwi/kiwi-schema/bb.ts +244 -0
  386. package/src/kiwi/kiwi-schema/binary.ts +102 -0
  387. package/src/kiwi/kiwi-schema/index.ts +5 -0
  388. package/src/kiwi/kiwi-schema/js.ts +339 -0
  389. package/src/kiwi/kiwi-schema/parser.ts +287 -0
  390. package/src/kiwi/kiwi-schema/schema.ts +24 -0
  391. package/src/kiwi/kiwi-schema/util.ts +10 -0
  392. package/src/kiwi/protocol.ts +237 -0
  393. package/src/kiwi/schema.ts +2286 -0
  394. package/src/kiwi-serialize.ts +467 -0
  395. package/src/layout.ts +608 -0
  396. package/src/profiler/draw-call-counter.ts +43 -0
  397. package/src/profiler/frame-capture.ts +139 -0
  398. package/src/profiler/frame-stats.ts +122 -0
  399. package/src/profiler/gpu-timer.ts +93 -0
  400. package/src/profiler/hud-renderer.ts +242 -0
  401. package/src/profiler/index.ts +8 -0
  402. package/src/profiler/phase-timer.ts +62 -0
  403. package/src/profiler/render-profiler.ts +163 -0
  404. package/src/render/components.ts +69 -0
  405. package/src/render/emoji-icons.ts +60 -0
  406. package/src/render/export-code.ts +366 -0
  407. package/src/render/export-jsx.ts +633 -0
  408. package/src/render/index.ts +38 -0
  409. package/src/render/jsx-runtime.ts +36 -0
  410. package/src/render/mini-react.ts +30 -0
  411. package/src/render/render-jsx.ts +74 -0
  412. package/src/render/renderer.ts +508 -0
  413. package/src/render/tailwind.ts +114 -0
  414. package/src/render/tree.ts +137 -0
  415. package/src/render-image.ts +139 -0
  416. package/src/renderer/effects.ts +64 -0
  417. package/src/renderer/fills.ts +248 -0
  418. package/src/renderer/index.ts +1 -0
  419. package/src/renderer/label-cache.ts +114 -0
  420. package/src/renderer/labels.ts +168 -0
  421. package/src/renderer/lru-cache.ts +71 -0
  422. package/src/renderer/overlays.ts +1089 -0
  423. package/src/renderer/renderer.ts +1226 -0
  424. package/src/renderer/rulers.ts +230 -0
  425. package/src/renderer/scene.ts +554 -0
  426. package/src/renderer/shapes.ts +193 -0
  427. package/src/renderer/strokes.ts +221 -0
  428. package/src/rpc/commands.ts +667 -0
  429. package/src/rpc/index.ts +25 -0
  430. package/src/scene-graph.ts +1254 -0
  431. package/src/snap.ts +122 -0
  432. package/src/style-runs.ts +234 -0
  433. package/src/svg-export/defs.ts +255 -0
  434. package/src/svg-export/index.ts +427 -0
  435. package/src/svg-export/paths.ts +212 -0
  436. package/src/svg-node.ts +62 -0
  437. package/src/text-editor.ts +349 -0
  438. package/src/tools/ai-adapter.ts +144 -0
  439. package/src/tools/analyze.ts +786 -0
  440. package/src/tools/create.ts +206 -0
  441. package/src/tools/describe.ts +280 -0
  442. package/src/tools/export-code.ts +41 -0
  443. package/src/tools/export-tailwind-config.ts +266 -0
  444. package/src/tools/icons.ts +213 -0
  445. package/src/tools/index.ts +6 -0
  446. package/src/tools/modify.ts +651 -0
  447. package/src/tools/patterns.ts +189 -0
  448. package/src/tools/read.ts +401 -0
  449. package/src/tools/registry.ts +155 -0
  450. package/src/tools/schema.ts +65 -0
  451. package/src/tools/structure.ts +348 -0
  452. package/src/tools/variables.ts +193 -0
  453. package/src/tools/vector.ts +311 -0
  454. package/src/types.ts +32 -0
  455. package/src/undo.ts +126 -0
  456. package/src/vector.ts +413 -0
  457. package/src/xpath.ts +259 -0
@@ -0,0 +1,771 @@
1
+ import { normalizeColor } from '../color'
2
+ import { DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT } from '../constants'
3
+ import { styleToWeight } from '../fonts'
4
+ import { decodeVectorNetworkBlob } from '../vector'
5
+ import type { Matrix, Vector } from '../types'
6
+
7
+ import type {
8
+ SceneNode,
9
+ NodeType,
10
+ Fill,
11
+ FillType,
12
+ Stroke,
13
+ Effect,
14
+ BlendMode,
15
+ ImageScaleMode,
16
+ GradientTransform,
17
+ StrokeCap,
18
+ StrokeJoin,
19
+ LayoutMode,
20
+ LayoutSizing,
21
+ LayoutAlign,
22
+ LayoutAlignSelf,
23
+ LayoutCounterAlign,
24
+ ConstraintType,
25
+ TextAutoResize,
26
+ TextAlignVertical,
27
+ TextCase,
28
+ TextDecoration,
29
+ ArcData,
30
+ VectorNetwork,
31
+ GeometryPath,
32
+ StyleRun,
33
+ CharacterStyleOverride,
34
+ WindingRule
35
+ } from '../scene-graph'
36
+ import type { NodeChange, Paint, Effect as KiwiEffect, GUID } from './codec'
37
+
38
+
39
+
40
+ export function guidToString(guid: GUID): string {
41
+ return `${guid.sessionID}:${guid.localID}`
42
+ }
43
+
44
+ export function stringToGuid(str: string): GUID {
45
+ const [session, local] = str.split(':')
46
+ return { sessionID: parseInt(session, 10), localID: parseInt(local, 10) }
47
+ }
48
+
49
+ export const VARIABLE_BINDING_FIELDS: Record<string, string> = {
50
+ cornerRadius: 'CORNER_RADIUS',
51
+ topLeftRadius: 'RECTANGLE_TOP_LEFT_CORNER_RADIUS',
52
+ topRightRadius: 'RECTANGLE_TOP_RIGHT_CORNER_RADIUS',
53
+ bottomLeftRadius: 'RECTANGLE_BOTTOM_LEFT_CORNER_RADIUS',
54
+ bottomRightRadius: 'RECTANGLE_BOTTOM_RIGHT_CORNER_RADIUS',
55
+ strokeWeight: 'STROKE_WEIGHT',
56
+ itemSpacing: 'STACK_SPACING',
57
+ paddingLeft: 'STACK_PADDING_LEFT',
58
+ paddingTop: 'STACK_PADDING_TOP',
59
+ paddingRight: 'STACK_PADDING_RIGHT',
60
+ paddingBottom: 'STACK_PADDING_BOTTOM',
61
+ counterAxisSpacing: 'STACK_COUNTER_SPACING',
62
+ visible: 'VISIBLE',
63
+ opacity: 'OPACITY',
64
+ width: 'WIDTH',
65
+ height: 'HEIGHT',
66
+ fontSize: 'FONT_SIZE',
67
+ letterSpacing: 'LETTER_SPACING',
68
+ lineHeight: 'LINE_HEIGHT'
69
+ }
70
+
71
+ export const VARIABLE_BINDING_FIELDS_INVERSE: Record<string, string> = Object.fromEntries(
72
+ Object.entries(VARIABLE_BINDING_FIELDS).map(([k, v]) => [v, k])
73
+ )
74
+
75
+ const convertColor = normalizeColor
76
+
77
+ function imageHashToString(hash: Record<string, number>): string {
78
+ const bytes = Object.keys(hash)
79
+ .sort((a, b) => Number(a) - Number(b))
80
+ .map((k) => hash[Number(k)])
81
+ return bytes.map((b) => b.toString(16).padStart(2, '0')).join('')
82
+ }
83
+
84
+ function convertGradientTransform(t?: Matrix): GradientTransform | undefined {
85
+ if (!t) return undefined
86
+ return { m00: t.m00, m01: t.m01, m02: t.m02, m10: t.m10, m11: t.m11, m12: t.m12 }
87
+ }
88
+
89
+ export function convertFills(paints?: Paint[]): Fill[] {
90
+ if (!paints) return []
91
+ return paints.map((p) => {
92
+ const base: Fill = {
93
+ type: p.type as FillType,
94
+ color: convertColor(p.color),
95
+ opacity: p.opacity ?? 1,
96
+ visible: p.visible ?? true,
97
+ blendMode: (p.blendMode ?? 'NORMAL') as BlendMode
98
+ }
99
+
100
+ if (p.type.startsWith('GRADIENT') && p.stops) {
101
+ base.gradientStops = p.stops.map((s) => ({
102
+ color: convertColor(s.color),
103
+ position: s.position
104
+ }))
105
+ if (p.transform) {
106
+ base.gradientTransform = convertGradientTransform(p.transform)
107
+ }
108
+ }
109
+
110
+ if (p.type === 'IMAGE') {
111
+ if (p.image && typeof p.image === 'object') {
112
+ const img = p.image as { hash: string | Record<string, number> }
113
+ if (typeof img.hash === 'object') {
114
+ base.imageHash = imageHashToString(img.hash)
115
+ } else if (typeof img.hash === 'string') {
116
+ base.imageHash = img.hash
117
+ }
118
+ }
119
+ base.imageScaleMode = (p.imageScaleMode ?? 'FILL') as ImageScaleMode
120
+ if (p.transform) {
121
+ base.imageTransform = convertGradientTransform(p.transform)
122
+ }
123
+ }
124
+
125
+ return base
126
+ })
127
+ }
128
+
129
+ function convertStrokes(
130
+ paints?: Paint[],
131
+ weight?: number,
132
+ align?: string,
133
+ cap?: string,
134
+ join?: string,
135
+ dashPattern?: number[]
136
+ ): Stroke[] {
137
+ if (!paints) return []
138
+ return paints.map((p) => ({
139
+ color: convertColor(p.color),
140
+ weight: weight ?? 1,
141
+ opacity: p.opacity ?? 1,
142
+ visible: p.visible ?? true,
143
+ align: (align === 'INSIDE'
144
+ ? 'INSIDE'
145
+ : (align === 'OUTSIDE'
146
+ ? 'OUTSIDE'
147
+ : 'CENTER')),
148
+ cap: (cap ?? 'NONE') as StrokeCap,
149
+ join: (join ?? 'MITER') as StrokeJoin,
150
+ dashPattern: dashPattern ?? []
151
+ }))
152
+ }
153
+
154
+ function convertEffects(effects?: KiwiEffect[]): Effect[] {
155
+ if (!effects) return []
156
+ return effects.map((e) => ({
157
+ type: e.type,
158
+ color: convertColor(e.color),
159
+ offset: e.offset ?? { x: 0, y: 0 },
160
+ radius: e.radius ?? 0,
161
+ spread: e.spread ?? 0,
162
+ visible: e.visible ?? true,
163
+ blendMode: (e.blendMode ?? 'NORMAL') as BlendMode
164
+ }))
165
+ }
166
+
167
+ const NODE_TYPE_MAP: Record<string, NodeType | 'DOCUMENT' | 'VARIABLE'> = {
168
+ DOCUMENT: 'DOCUMENT',
169
+ VARIABLE: 'VARIABLE',
170
+ CANVAS: 'CANVAS',
171
+ FRAME: 'FRAME',
172
+ RECTANGLE: 'RECTANGLE',
173
+ ROUNDED_RECTANGLE: 'ROUNDED_RECTANGLE',
174
+ ELLIPSE: 'ELLIPSE',
175
+ TEXT: 'TEXT',
176
+ LINE: 'LINE',
177
+ STAR: 'STAR',
178
+ REGULAR_POLYGON: 'POLYGON',
179
+ VECTOR: 'VECTOR',
180
+ BOOLEAN_OPERATION: 'VECTOR',
181
+ GROUP: 'GROUP',
182
+ SECTION: 'SECTION',
183
+ COMPONENT: 'COMPONENT',
184
+ COMPONENT_SET: 'COMPONENT_SET',
185
+ INSTANCE: 'INSTANCE',
186
+ SYMBOL: 'COMPONENT',
187
+ CONNECTOR: 'CONNECTOR',
188
+ SHAPE_WITH_TEXT: 'SHAPE_WITH_TEXT'
189
+ }
190
+
191
+ function mapNodeType(type?: string): NodeType | 'DOCUMENT' | 'VARIABLE' {
192
+ if (type) return NODE_TYPE_MAP[type] ?? 'RECTANGLE'
193
+ return 'RECTANGLE'
194
+ }
195
+
196
+ function mapStackMode(mode?: string): LayoutMode {
197
+ switch (mode) {
198
+ case 'HORIZONTAL':
199
+ return 'HORIZONTAL'
200
+ case 'VERTICAL':
201
+ return 'VERTICAL'
202
+ default:
203
+ return 'NONE'
204
+ }
205
+ }
206
+
207
+ function mapStackSizing(sizing?: string): LayoutSizing {
208
+ switch (sizing) {
209
+ case 'RESIZE_TO_FIT':
210
+ case 'RESIZE_TO_FIT_WITH_IMPLICIT_SIZE':
211
+ return 'HUG'
212
+ case 'FILL':
213
+ return 'FILL'
214
+ default:
215
+ return 'FIXED'
216
+ }
217
+ }
218
+
219
+ function mapStackJustify(justify?: string): LayoutAlign {
220
+ switch (justify) {
221
+ case 'CENTER':
222
+ return 'CENTER'
223
+ case 'MAX':
224
+ return 'MAX'
225
+ case 'SPACE_BETWEEN':
226
+ return 'SPACE_BETWEEN'
227
+ default:
228
+ return 'MIN'
229
+ }
230
+ }
231
+
232
+ function mapStackCounterAlign(align?: string): LayoutCounterAlign {
233
+ switch (align) {
234
+ case 'CENTER':
235
+ return 'CENTER'
236
+ case 'MAX':
237
+ return 'MAX'
238
+ case 'STRETCH':
239
+ return 'STRETCH'
240
+ case 'BASELINE':
241
+ return 'BASELINE'
242
+ default:
243
+ return 'MIN'
244
+ }
245
+ }
246
+
247
+ function mapAlignSelf(align?: string): LayoutAlignSelf {
248
+ switch (align) {
249
+ case 'MIN':
250
+ return 'MIN'
251
+ case 'CENTER':
252
+ return 'CENTER'
253
+ case 'MAX':
254
+ return 'MAX'
255
+ case 'STRETCH':
256
+ return 'STRETCH'
257
+ case 'BASELINE':
258
+ return 'BASELINE'
259
+ default:
260
+ return 'AUTO'
261
+ }
262
+ }
263
+
264
+ function mapConstraint(c?: string): ConstraintType {
265
+ switch (c) {
266
+ case 'CENTER':
267
+ return 'CENTER'
268
+ case 'MAX':
269
+ return 'MAX'
270
+ case 'STRETCH':
271
+ return 'STRETCH'
272
+ case 'SCALE':
273
+ return 'SCALE'
274
+ default:
275
+ return 'MIN'
276
+ }
277
+ }
278
+
279
+ function mapTextDecoration(d?: string): TextDecoration {
280
+ switch (d) {
281
+ case 'UNDERLINE':
282
+ return 'UNDERLINE'
283
+ case 'STRIKETHROUGH':
284
+ return 'STRIKETHROUGH'
285
+ default:
286
+ return 'NONE'
287
+ }
288
+ }
289
+
290
+ function convertLineHeight(
291
+ lh?: { value: number; units: string },
292
+ fontSize?: number
293
+ ): number | null {
294
+ if (!lh) return null
295
+ if (lh.units === 'PIXELS') return lh.value
296
+ if (lh.units === 'PERCENT') return (lh.value / 100) * (fontSize ?? 14)
297
+ if (lh.units === 'RAW') return lh.value * (fontSize ?? 14)
298
+ return null
299
+ }
300
+
301
+ function convertLetterSpacing(
302
+ ls?: { value: number; units: string },
303
+ fontSize?: number
304
+ ): number {
305
+ if (!ls) return 0
306
+ if (ls.units === 'PIXELS') return ls.value
307
+ if (ls.units === 'PERCENT') return (ls.value / 100) * (fontSize ?? 14)
308
+ return ls.value
309
+ }
310
+
311
+ function mapArcData(data?: Partial<ArcData>): ArcData | null {
312
+ if (!data) return null
313
+ return {
314
+ startingAngle: data.startingAngle ?? 0,
315
+ endingAngle: data.endingAngle ?? 2 * Math.PI,
316
+ innerRadius: data.innerRadius ?? 0
317
+ }
318
+ }
319
+
320
+ function convertStyleOverride(
321
+ override: NodeChange,
322
+ fallbackFontSize: number | undefined
323
+ ): CharacterStyleOverride {
324
+ const style: CharacterStyleOverride = {}
325
+ if (override.fontName) {
326
+ style.fontFamily = override.fontName.family
327
+ style.fontWeight = styleToWeight(override.fontName.style)
328
+ style.italic = override.fontName.style.toLowerCase().includes('italic')
329
+ }
330
+ if (override.fontSize !== undefined) style.fontSize = override.fontSize
331
+ if (override.letterSpacing) {
332
+ style.letterSpacing = convertLetterSpacing(override.letterSpacing, override.fontSize ?? fallbackFontSize)
333
+ }
334
+ if (override.lineHeight) {
335
+ const lh = convertLineHeight(override.lineHeight, override.fontSize ?? fallbackFontSize)
336
+ if (lh != null) style.lineHeight = lh
337
+ }
338
+ const deco = override.textDecoration
339
+ if (deco) style.textDecoration = mapTextDecoration(deco)
340
+ return style
341
+ }
342
+
343
+ function buildStyleMap(
344
+ table: NodeChange[],
345
+ fallbackFontSize: number | undefined
346
+ ): Map<number, CharacterStyleOverride> {
347
+ const styleMap = new Map<number, CharacterStyleOverride>()
348
+ for (const override of table) {
349
+ const id = override.styleID as number | undefined
350
+ if (id === undefined) continue
351
+ const style = convertStyleOverride(override, fallbackFontSize)
352
+ if (Object.keys(style).length > 0) styleMap.set(id, style)
353
+ }
354
+ return styleMap
355
+ }
356
+
357
+ function collectStyleRuns(
358
+ ids: number[],
359
+ styleMap: Map<number, CharacterStyleOverride>
360
+ ): StyleRun[] {
361
+ const runs: StyleRun[] = []
362
+ let currentId = ids[0]
363
+ let start = 0
364
+
365
+ for (let i = 1; i <= ids.length; i++) {
366
+ if (i === ids.length || ids[i] !== currentId) {
367
+ if (currentId !== 0) {
368
+ const style = styleMap.get(currentId)
369
+ if (style) runs.push({ start, length: i - start, style })
370
+ }
371
+ if (i < ids.length) {
372
+ currentId = ids[i]
373
+ start = i
374
+ }
375
+ }
376
+ }
377
+ return runs
378
+ }
379
+
380
+ function importStyleRuns(nc: NodeChange): StyleRun[] {
381
+ const td = nc.textData
382
+ if (!td?.characterStyleIDs || !td.styleOverrideTable) return []
383
+
384
+ const ids = td.characterStyleIDs
385
+ if (ids.length === 0 || td.styleOverrideTable.length === 0) return []
386
+
387
+ const styleMap = buildStyleMap(td.styleOverrideTable, nc.fontSize)
388
+ if (styleMap.size === 0) return []
389
+
390
+ return collectStyleRuns(ids, styleMap)
391
+ }
392
+
393
+ function resolveVectorNetwork(
394
+ nc: NodeChange,
395
+ blobs: Uint8Array[]
396
+ ): VectorNetwork | null {
397
+ const vectorData = nc.vectorData as
398
+ | {
399
+ vectorNetworkBlob?: number
400
+ normalizedSize?: Vector
401
+ styleOverrideTable?: Array<{ styleID: number; handleMirroring?: string }>
402
+ }
403
+ | undefined
404
+
405
+ if (vectorData?.vectorNetworkBlob === undefined) return null
406
+ const idx = vectorData.vectorNetworkBlob
407
+ if (idx < 0 || idx >= blobs.length) return null
408
+
409
+ try {
410
+ const network = decodeVectorNetworkBlob(blobs[idx], vectorData.styleOverrideTable)
411
+
412
+ const ns = vectorData.normalizedSize
413
+ const nodeW = nc.size?.x ?? 0
414
+ const nodeH = nc.size?.y ?? 0
415
+ if (ns && nodeW > 0 && nodeH > 0 && (ns.x !== nodeW || ns.y !== nodeH)) {
416
+ const sx = nodeW / ns.x
417
+ const sy = nodeH / ns.y
418
+ for (const v of network.vertices) {
419
+ v.x *= sx
420
+ v.y *= sy
421
+ }
422
+ for (const seg of network.segments) {
423
+ seg.tangentStart = { x: seg.tangentStart.x * sx, y: seg.tangentStart.y * sy }
424
+ seg.tangentEnd = { x: seg.tangentEnd.x * sx, y: seg.tangentEnd.y * sy }
425
+ }
426
+ }
427
+
428
+ return network
429
+ } catch {
430
+ return null
431
+ }
432
+ }
433
+
434
+ interface KiwiPath {
435
+ windingRule?: string
436
+ commandsBlob?: number
437
+ }
438
+
439
+ export function resolveGeometryPaths(
440
+ paths: KiwiPath[] | undefined,
441
+ blobs: Uint8Array[]
442
+ ): GeometryPath[] {
443
+ if (!paths || paths.length === 0) return []
444
+ const result: GeometryPath[] = []
445
+ for (const p of paths) {
446
+ if (p.commandsBlob === undefined || p.commandsBlob < 0 || p.commandsBlob >= blobs.length)
447
+ continue
448
+ const blob = blobs[p.commandsBlob]
449
+ if (blob.length === 0) continue
450
+ result.push({
451
+ windingRule: (p.windingRule === 'EVENODD' ? 'EVENODD' : 'NONZERO') as WindingRule,
452
+ commandsBlob: blob
453
+ })
454
+ }
455
+ return result
456
+ }
457
+
458
+ function extractBoundVariables(nc: NodeChange): Record<string, string> {
459
+ const bindings: Record<string, string> = {}
460
+ nc.fillPaints?.forEach((paint, i) => {
461
+ if (paint.colorVariableBinding) {
462
+ bindings[`fills/${i}/color`] = guidToString(paint.colorVariableBinding.variableID)
463
+ }
464
+ })
465
+ nc.strokePaints?.forEach((paint, i) => {
466
+ if (paint.colorVariableBinding) {
467
+ bindings[`strokes/${i}/color`] = guidToString(paint.colorVariableBinding.variableID)
468
+ }
469
+ })
470
+ return bindings
471
+ }
472
+
473
+ function convertTransformProps(nc: NodeChange): Pick<SceneNode, 'x' | 'y' | 'width' | 'height' | 'rotation' | 'flipX' | 'flipY'> {
474
+ const x = nc.transform?.m02 ?? 0
475
+ const y = nc.transform?.m12 ?? 0
476
+ const width = nc.size?.x ?? 100
477
+ const height = nc.size?.y ?? 100
478
+
479
+ let rotation = 0
480
+ let flipX = false
481
+ if (nc.transform) {
482
+ const det = nc.transform.m00 * nc.transform.m11 - nc.transform.m01 * nc.transform.m10
483
+ if (det < 0) flipX = true
484
+ const sx = flipX ? -1 : 1
485
+ rotation = Math.atan2(nc.transform.m10 * sx, nc.transform.m00 * sx) * (180 / Math.PI)
486
+ }
487
+
488
+ return { x, y, width, height, rotation, flipX, flipY: false }
489
+ }
490
+
491
+ function convertCornerProps(nc: NodeChange): Pick<SceneNode, 'cornerRadius' | 'topLeftRadius' | 'topRightRadius' | 'bottomRightRadius' | 'bottomLeftRadius' | 'independentCorners' | 'cornerSmoothing'> {
492
+ return {
493
+ cornerRadius: nc.cornerRadius ?? 0,
494
+ topLeftRadius: nc.rectangleTopLeftCornerRadius ?? nc.cornerRadius ?? 0,
495
+ topRightRadius: nc.rectangleTopRightCornerRadius ?? nc.cornerRadius ?? 0,
496
+ bottomRightRadius: nc.rectangleBottomRightCornerRadius ?? nc.cornerRadius ?? 0,
497
+ bottomLeftRadius: nc.rectangleBottomLeftCornerRadius ?? nc.cornerRadius ?? 0,
498
+ independentCorners: nc.rectangleCornerRadiiIndependent ?? false,
499
+ cornerSmoothing: nc.cornerSmoothing ?? 0
500
+ }
501
+ }
502
+
503
+ function convertTextProps(nc: NodeChange): Pick<SceneNode, 'text' | 'fontSize' | 'fontFamily' | 'fontWeight' | 'italic' | 'textAlignHorizontal' | 'textAlignVertical' | 'textAutoResize' | 'textCase' | 'textDecoration' | 'lineHeight' | 'letterSpacing' | 'maxLines' | 'styleRuns' | 'textTruncation'> {
504
+ return {
505
+ text: nc.textData?.characters ?? '',
506
+ fontSize: nc.fontSize ?? 14,
507
+ fontFamily: nc.fontName?.family ?? DEFAULT_FONT_FAMILY,
508
+ fontWeight: styleToWeight(nc.fontName?.style ?? ''),
509
+ italic: nc.fontName?.style.toLowerCase().includes('italic') ?? false,
510
+ textAlignHorizontal: (nc.textAlignHorizontal ?? 'LEFT') as 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFIED',
511
+ textAlignVertical: (nc.textAlignVertical ?? 'TOP') as TextAlignVertical,
512
+ textAutoResize: (nc.textAutoResize ?? 'NONE') as TextAutoResize,
513
+ textCase: (nc.textCase ?? 'ORIGINAL') as TextCase,
514
+ textDecoration: mapTextDecoration(nc.textDecoration as string),
515
+ lineHeight: convertLineHeight(nc.lineHeight, nc.fontSize),
516
+ letterSpacing: convertLetterSpacing(nc.letterSpacing, nc.fontSize),
517
+ maxLines: (nc.maxLines ?? null) as number | null,
518
+ styleRuns: importStyleRuns(nc),
519
+ textTruncation: (nc.textTruncation as string) === 'ENDING' ? 'ENDING' : 'DISABLED'
520
+ }
521
+ }
522
+
523
+ function convertLayoutPadding(nc: NodeChange): Pick<SceneNode, 'paddingTop' | 'paddingBottom' | 'paddingLeft' | 'paddingRight'> {
524
+ return {
525
+ paddingTop: nc.stackVerticalPadding ?? nc.stackPadding ?? 0,
526
+ paddingBottom: nc.stackPaddingBottom ?? nc.stackVerticalPadding ?? nc.stackPadding ?? 0,
527
+ paddingLeft: nc.stackHorizontalPadding ?? nc.stackPadding ?? 0,
528
+ paddingRight: nc.stackPaddingRight ?? nc.stackHorizontalPadding ?? nc.stackPadding ?? 0
529
+ }
530
+ }
531
+
532
+ function convertLayoutProps(nc: NodeChange): Pick<SceneNode, 'layoutMode' | 'itemSpacing' | 'paddingTop' | 'paddingBottom' | 'paddingLeft' | 'paddingRight' | 'primaryAxisSizing' | 'counterAxisSizing' | 'primaryAxisAlign' | 'counterAxisAlign' | 'layoutWrap' | 'counterAxisSpacing' | 'layoutPositioning' | 'layoutGrow' | 'layoutAlignSelf' | 'counterAxisAlignContent' | 'itemReverseZIndex' | 'strokesIncludedInLayout'> {
533
+ return {
534
+ layoutMode: mapStackMode(nc.stackMode),
535
+ itemSpacing: nc.stackSpacing ?? 0,
536
+ ...convertLayoutPadding(nc),
537
+ primaryAxisSizing: mapStackSizing(nc.stackPrimarySizing),
538
+ counterAxisSizing: mapStackSizing(nc.stackCounterSizing),
539
+ primaryAxisAlign: mapStackJustify(nc.stackPrimaryAlignItems ?? nc.stackJustify),
540
+ counterAxisAlign: mapStackCounterAlign(nc.stackCounterAlignItems ?? nc.stackCounterAlign),
541
+ layoutWrap: nc.stackWrap === 'WRAP' ? 'WRAP' : 'NO_WRAP',
542
+ counterAxisSpacing: nc.stackCounterSpacing ?? 0,
543
+ layoutPositioning: nc.stackPositioning === 'ABSOLUTE' ? 'ABSOLUTE' : 'AUTO',
544
+ layoutGrow: nc.stackChildPrimaryGrow ?? 0,
545
+ layoutAlignSelf: mapAlignSelf(nc.stackChildAlignSelf),
546
+ counterAxisAlignContent: (nc.stackCounterAlignContent as string) === 'SPACE_BETWEEN' ? 'SPACE_BETWEEN' : 'AUTO',
547
+ itemReverseZIndex: (nc.stackReverseZIndex ?? false) as boolean,
548
+ strokesIncludedInLayout: (nc.strokesIncludedInLayout ?? false) as boolean
549
+ }
550
+ }
551
+
552
+ function convertVectorAndStrokeProps(nc: NodeChange, blobs: Uint8Array[]): Pick<SceneNode, 'vectorNetwork' | 'fillGeometry' | 'strokeGeometry' | 'arcData' | 'strokeCap' | 'strokeJoin' | 'dashPattern' | 'borderTopWeight' | 'borderRightWeight' | 'borderBottomWeight' | 'borderLeftWeight' | 'independentStrokeWeights' | 'strokeMiterLimit'> {
553
+ return {
554
+ vectorNetwork: resolveVectorNetwork(nc, blobs),
555
+ fillGeometry: resolveGeometryPaths(nc.fillGeometry, blobs),
556
+ strokeGeometry: resolveGeometryPaths(nc.strokeGeometry, blobs),
557
+ arcData: mapArcData(nc.arcData as Partial<ArcData> | undefined),
558
+ strokeCap: (nc.strokeCap ?? 'NONE') as StrokeCap,
559
+ strokeJoin: (nc.strokeJoin ?? 'MITER') as StrokeJoin,
560
+ dashPattern: nc.dashPattern ?? [],
561
+ borderTopWeight: (nc.borderTopWeight ?? 0) as number,
562
+ borderRightWeight: (nc.borderRightWeight ?? 0) as number,
563
+ borderBottomWeight: (nc.borderBottomWeight ?? 0) as number,
564
+ borderLeftWeight: (nc.borderLeftWeight ?? 0) as number,
565
+ independentStrokeWeights: (nc.borderStrokeWeightsIndependent ?? false) as boolean,
566
+ strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT
567
+ }
568
+ }
569
+
570
+ export function nodeChangeToProps(
571
+ nc: NodeChange,
572
+ blobs: Uint8Array[]
573
+ ): Partial<SceneNode> & { nodeType: NodeType | 'DOCUMENT' | 'VARIABLE' } {
574
+ let nodeType = mapNodeType(nc.type)
575
+ if (nodeType === 'FRAME' && isComponentSet(nc)) nodeType = 'COMPONENT_SET'
576
+
577
+ return {
578
+ nodeType,
579
+ name: nc.name ?? nodeType,
580
+ ...convertTransformProps(nc),
581
+ opacity: nc.opacity ?? 1,
582
+ visible: nc.visible ?? true,
583
+ locked: nc.locked ?? false,
584
+ blendMode: (nc.blendMode as Fill['blendMode']) ?? 'PASS_THROUGH',
585
+ fills: convertFills(nc.fillPaints),
586
+ strokes: convertStrokes(nc.strokePaints, nc.strokeWeight, nc.strokeAlign, nc.strokeCap, nc.strokeJoin, nc.dashPattern ?? []),
587
+ effects: convertEffects(nc.effects),
588
+ ...convertCornerProps(nc),
589
+ ...convertTextProps(nc),
590
+ horizontalConstraint: mapConstraint(nc.horizontalConstraint as string),
591
+ verticalConstraint: mapConstraint(nc.verticalConstraint as string),
592
+ ...convertLayoutProps(nc),
593
+ ...convertVectorAndStrokeProps(nc, blobs),
594
+ minWidth: (nc.minWidth ?? null) as number | null,
595
+ maxWidth: (nc.maxWidth ?? null) as number | null,
596
+ minHeight: (nc.minHeight ?? null) as number | null,
597
+ maxHeight: (nc.maxHeight ?? null) as number | null,
598
+ isMask: (nc.isMask ?? false) as boolean,
599
+ maskType: (nc.maskType ?? 'ALPHA') as 'ALPHA' | 'VECTOR' | 'LUMINANCE',
600
+ expanded: true,
601
+ autoRename: (nc.autoRename ?? true) as boolean,
602
+ boundVariables: extractBoundVariables(nc),
603
+ clipsContent: nc.frameMaskDisabled === false,
604
+ componentId: extractSymbolId(nc)
605
+ }
606
+ }
607
+
608
+ function isComponentSet(nc: NodeChange): boolean {
609
+ const defs = nc.componentPropDefs as Array<{ type?: string }> | undefined
610
+ if (!defs?.length) return false
611
+ return defs.some((d) => d.type === 'VARIANT')
612
+ }
613
+
614
+ export function sortChildren(
615
+ children: string[],
616
+ parentNc: NodeChange,
617
+ nodeMap: Map<string, NodeChange>
618
+ ): void {
619
+ const stackMode = parentNc.stackMode as string | undefined
620
+ if (stackMode === 'HORIZONTAL' || stackMode === 'VERTICAL') {
621
+ const axis = stackMode === 'HORIZONTAL' ? 'm02' : 'm12'
622
+ children.sort((a, b) => {
623
+ const aT = nodeMap.get(a)?.transform?.[axis] ?? 0
624
+ const bT = nodeMap.get(b)?.transform?.[axis] ?? 0
625
+ return aT - bT
626
+ })
627
+ } else {
628
+ children.sort((a, b) => {
629
+ const aPos = nodeMap.get(a)?.parentIndex?.position ?? ''
630
+ const bPos = nodeMap.get(b)?.parentIndex?.position ?? ''
631
+ return aPos < bPos ? -1 : (aPos > bPos ? 1 : 0)
632
+ })
633
+ }
634
+ }
635
+
636
+ function extractSymbolId(nc: NodeChange): string {
637
+ const sd = nc.symbolData as
638
+ | { symbolID?: GUID }
639
+ | undefined
640
+ if (!sd?.symbolID) return ''
641
+ return guidToString(sd.symbolID)
642
+ }
643
+
644
+ function applyOverridePaints(ov: Record<string, unknown>, updates: Partial<SceneNode>): void {
645
+ if (ov.textData != null) {
646
+ const td = ov.textData as { characters?: string }
647
+ if (td.characters != null) updates.text = td.characters
648
+ const runs = importStyleRuns(ov as unknown as NodeChange)
649
+ if (runs.length > 0) updates.styleRuns = runs
650
+ }
651
+ if (ov.fillPaints != null) updates.fills = convertFills(ov.fillPaints as Paint[])
652
+ if (ov.strokePaints != null)
653
+ updates.strokes = convertStrokes(
654
+ ov.strokePaints as Paint[],
655
+ ov.strokeWeight as number | undefined,
656
+ ov.strokeAlign as string | undefined
657
+ )
658
+ if (ov.effects != null) updates.effects = convertEffects(ov.effects as KiwiEffect[])
659
+ if (ov.visible != null) updates.visible = ov.visible as boolean
660
+ if (ov.opacity != null) updates.opacity = ov.opacity as number
661
+ if (ov.name != null) updates.name = ov.name as string
662
+ if (ov.locked != null) updates.locked = ov.locked as boolean
663
+ }
664
+
665
+ function applyOverrideGeometry(ov: Record<string, unknown>, updates: Partial<SceneNode>): void {
666
+ if (ov.size != null) {
667
+ const sz = ov.size as { x?: number; y?: number }
668
+ if (sz.x != null) updates.width = sz.x
669
+ if (sz.y != null) updates.height = sz.y
670
+ }
671
+ if (ov.cornerRadius != null) updates.cornerRadius = ov.cornerRadius as number
672
+ if (ov.rectangleTopLeftCornerRadius != null)
673
+ updates.topLeftRadius = ov.rectangleTopLeftCornerRadius as number
674
+ if (ov.rectangleTopRightCornerRadius != null)
675
+ updates.topRightRadius = ov.rectangleTopRightCornerRadius as number
676
+ if (ov.rectangleBottomRightCornerRadius != null)
677
+ updates.bottomRightRadius = ov.rectangleBottomRightCornerRadius as number
678
+ if (ov.rectangleBottomLeftCornerRadius != null)
679
+ updates.bottomLeftRadius = ov.rectangleBottomLeftCornerRadius as number
680
+ if (ov.rectangleCornerRadiiIndependent != null)
681
+ updates.independentCorners = ov.rectangleCornerRadiiIndependent as boolean
682
+ if (ov.arcData != null)
683
+ updates.arcData = mapArcData(ov.arcData as Partial<ArcData> | undefined)
684
+ if (ov.frameMaskDisabled != null) updates.clipsContent = ov.frameMaskDisabled === false
685
+ }
686
+
687
+ function applyOverrideLayout(ov: Record<string, unknown>, updates: Partial<SceneNode>): void {
688
+ if (ov.stackSpacing != null) updates.itemSpacing = ov.stackSpacing as number
689
+ if (ov.stackPrimarySizing != null)
690
+ updates.primaryAxisSizing = mapStackSizing(ov.stackPrimarySizing as string)
691
+ if (ov.stackCounterSizing != null)
692
+ updates.counterAxisSizing = mapStackSizing(ov.stackCounterSizing as string)
693
+ if (ov.stackPrimaryAlignItems != null)
694
+ updates.primaryAxisAlign = mapStackJustify(ov.stackPrimaryAlignItems as string)
695
+ if (ov.stackCounterAlignItems != null)
696
+ updates.counterAxisAlign = mapStackCounterAlign(ov.stackCounterAlignItems as string)
697
+ if (ov.stackChildPrimaryGrow != null) updates.layoutGrow = ov.stackChildPrimaryGrow as number
698
+ if (ov.stackChildAlignSelf != null)
699
+ updates.layoutAlignSelf = mapAlignSelf(ov.stackChildAlignSelf as string)
700
+ if (ov.stackPositioning != null)
701
+ updates.layoutPositioning =
702
+ (ov.stackPositioning as string) === 'ABSOLUTE' ? 'ABSOLUTE' : 'AUTO'
703
+ if (ov.stackVerticalPadding != null) {
704
+ updates.paddingTop = ov.stackVerticalPadding as number
705
+ if (ov.stackPaddingBottom == null) updates.paddingBottom = ov.stackVerticalPadding as number
706
+ }
707
+ if (ov.stackHorizontalPadding != null) {
708
+ updates.paddingLeft = ov.stackHorizontalPadding as number
709
+ if (ov.stackPaddingRight == null) updates.paddingRight = ov.stackHorizontalPadding as number
710
+ }
711
+ if (ov.stackPaddingBottom != null) updates.paddingBottom = ov.stackPaddingBottom as number
712
+ if (ov.stackPaddingRight != null) updates.paddingRight = ov.stackPaddingRight as number
713
+ }
714
+
715
+ function applyOverrideStrokes(ov: Record<string, unknown>, updates: Partial<SceneNode>): void {
716
+ if (ov.strokeWeight != null && !ov.strokePaints) {
717
+ updates.strokes = updates.strokes ?? []
718
+ }
719
+ if (ov.strokeAlign != null && updates.strokes) {
720
+ const align =
721
+ ov.strokeAlign === 'INSIDE' ? 'INSIDE' : (ov.strokeAlign === 'OUTSIDE' ? 'OUTSIDE' : 'CENTER')
722
+ for (const s of updates.strokes) s.align = align
723
+ }
724
+ if (ov.borderTopWeight != null) updates.borderTopWeight = ov.borderTopWeight as number
725
+ if (ov.borderRightWeight != null) updates.borderRightWeight = ov.borderRightWeight as number
726
+ if (ov.borderBottomWeight != null) updates.borderBottomWeight = ov.borderBottomWeight as number
727
+ if (ov.borderLeftWeight != null) updates.borderLeftWeight = ov.borderLeftWeight as number
728
+ if (ov.borderStrokeWeightsIndependent != null)
729
+ updates.independentStrokeWeights = ov.borderStrokeWeightsIndependent as boolean
730
+ }
731
+
732
+ function applyOverrideText(ov: Record<string, unknown>, updates: Partial<SceneNode>): void {
733
+ if (ov.fontName != null) {
734
+ const fn = ov.fontName as { family?: string; style?: string }
735
+ if (fn.family) updates.fontFamily = fn.family
736
+ if (fn.style) {
737
+ updates.fontWeight = styleToWeight(fn.style)
738
+ updates.italic = fn.style.toLowerCase().includes('italic')
739
+ }
740
+ }
741
+ if (ov.fontSize != null) updates.fontSize = ov.fontSize as number
742
+ if (ov.textAlignHorizontal != null)
743
+ updates.textAlignHorizontal = ov.textAlignHorizontal as SceneNode['textAlignHorizontal']
744
+ if (ov.textAutoResize != null) updates.textAutoResize = ov.textAutoResize as TextAutoResize
745
+ if (ov.lineHeight != null)
746
+ updates.lineHeight = convertLineHeight(
747
+ ov.lineHeight as NodeChange['lineHeight'],
748
+ ov.fontSize as number | undefined
749
+ )
750
+ if (ov.letterSpacing != null)
751
+ updates.letterSpacing = convertLetterSpacing(
752
+ ov.letterSpacing as NodeChange['letterSpacing'],
753
+ ov.fontSize as number | undefined
754
+ )
755
+ if (ov.maxLines != null) updates.maxLines = ov.maxLines as number | null
756
+ if (ov.textTruncation != null)
757
+ updates.textTruncation =
758
+ (ov.textTruncation as string) === 'ENDING' ? 'ENDING' : 'DISABLED'
759
+ if (ov.textDecoration != null)
760
+ updates.textDecoration = mapTextDecoration(ov.textDecoration as string)
761
+ }
762
+
763
+ export function convertOverrideToProps(ov: Record<string, unknown>): Partial<SceneNode> {
764
+ const updates: Partial<SceneNode> = {}
765
+ applyOverridePaints(ov, updates)
766
+ applyOverrideGeometry(ov, updates)
767
+ applyOverrideLayout(ov, updates)
768
+ applyOverrideStrokes(ov, updates)
769
+ applyOverrideText(ov, updates)
770
+ return updates
771
+ }