@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
package/src/layout.ts ADDED
@@ -0,0 +1,608 @@
1
+ import Yoga, {
2
+ Align,
3
+ Direction,
4
+ Display,
5
+ FlexDirection,
6
+ GridTrackType,
7
+ Gutter,
8
+ Justify,
9
+ Edge,
10
+ MeasureMode,
11
+ Overflow,
12
+ PositionType,
13
+ Wrap,
14
+ type Node as YogaNode
15
+ } from 'yoga-layout'
16
+
17
+ import type { GridTrack, SceneGraph, SceneNode } from './scene-graph'
18
+
19
+ export type TextMeasurer = (
20
+ node: SceneNode,
21
+ maxWidth?: number
22
+ ) => { width: number; height: number } | null
23
+
24
+ let globalTextMeasurer: TextMeasurer | null = null
25
+
26
+ const GLYPH_WIDTH_FACTOR = 0.6
27
+
28
+ export function setTextMeasurer(measurer: TextMeasurer | null): void {
29
+ globalTextMeasurer = measurer
30
+ }
31
+
32
+ export function computeLayout(graph: SceneGraph, frameId: string): void {
33
+ const frame = graph.getNode(frameId)
34
+ if (!frame || frame.layoutMode === 'NONE') return
35
+
36
+ const yogaRoot =
37
+ frame.layoutMode === 'GRID' ? buildGridTree(graph, frame) : buildYogaTree(graph, frame)
38
+ yogaRoot.calculateLayout(undefined, undefined, Direction.LTR)
39
+ applyYogaLayout(graph, frame, yogaRoot)
40
+ freeYogaTree(yogaRoot)
41
+ }
42
+
43
+ export function computeAllLayouts(graph: SceneGraph, scopeId?: string): void {
44
+ const visited = new Set<string>()
45
+ computeLayoutsBottomUp(graph, scopeId ?? graph.rootId, visited)
46
+ }
47
+
48
+ function computeLayoutsBottomUp(graph: SceneGraph, nodeId: string, visited: Set<string>): void {
49
+ const node = graph.getNode(nodeId)
50
+ if (!node || visited.has(nodeId)) return
51
+ visited.add(nodeId)
52
+
53
+ for (const childId of node.childIds) {
54
+ computeLayoutsBottomUp(graph, childId, visited)
55
+ }
56
+
57
+ if (node.layoutMode !== 'NONE') {
58
+ computeLayout(graph, nodeId)
59
+ }
60
+ }
61
+
62
+ // --- Grid layout ---
63
+
64
+ function mapGridTrack(track: GridTrack): { type: GridTrackType; value: number } {
65
+ switch (track.sizing) {
66
+ case 'FR':
67
+ return { type: GridTrackType.Fr, value: track.value }
68
+ case 'FIXED':
69
+ return { type: GridTrackType.Points, value: track.value }
70
+ default:
71
+ return { type: GridTrackType.Auto, value: 0 }
72
+ }
73
+ }
74
+
75
+ function configureAsGrid(yogaNode: YogaNode, node: SceneNode): void {
76
+ yogaNode.setDisplay(Display.Grid)
77
+ yogaNode.setWidth(node.width)
78
+ if (node.gridTemplateRows.length > 0 || node.height > 0) {
79
+ yogaNode.setHeight(node.height)
80
+ }
81
+
82
+ if (node.gridTemplateColumns.length > 0) {
83
+ yogaNode.setGridTemplateColumns(node.gridTemplateColumns.map(mapGridTrack))
84
+ }
85
+ if (node.gridTemplateRows.length > 0) {
86
+ yogaNode.setGridTemplateRows(node.gridTemplateRows.map(mapGridTrack))
87
+ }
88
+
89
+ yogaNode.setGap(Gutter.Column, node.gridColumnGap)
90
+ yogaNode.setGap(Gutter.Row, node.gridRowGap)
91
+
92
+ yogaNode.setPadding(Edge.Top, node.paddingTop)
93
+ yogaNode.setPadding(Edge.Right, node.paddingRight)
94
+ yogaNode.setPadding(Edge.Bottom, node.paddingBottom)
95
+ yogaNode.setPadding(Edge.Left, node.paddingLeft)
96
+ }
97
+
98
+ function createGridChildNode(child: SceneNode): YogaNode {
99
+ const yogaChild = Yoga.Node.create()
100
+ if (!child.visible) {
101
+ yogaChild.setDisplay(Display.None)
102
+ } else {
103
+ const pos = child.gridPosition
104
+ if (pos) {
105
+ yogaChild.setGridColumnStart(pos.column)
106
+ yogaChild.setGridColumnEndSpan(pos.columnSpan)
107
+ yogaChild.setGridRowStart(pos.row)
108
+ yogaChild.setGridRowEndSpan(pos.rowSpan)
109
+ }
110
+ const hasLayout = child.layoutMode !== 'NONE'
111
+ const explicitStretch = child.layoutGrow > 0 || child.layoutAlignSelf === 'STRETCH'
112
+
113
+ if (explicitStretch || hasLayout) {
114
+ yogaChild.setWidthStretch()
115
+ } else {
116
+ yogaChild.setWidth(child.width)
117
+ }
118
+ if (explicitStretch) {
119
+ yogaChild.setHeightStretch()
120
+ } else {
121
+ yogaChild.setHeight(child.height)
122
+ }
123
+ }
124
+ return yogaChild
125
+ }
126
+
127
+ function buildGridTree(graph: SceneGraph, frame: SceneNode): YogaNode {
128
+ const root = Yoga.Node.create()
129
+ configureAsGrid(root, frame)
130
+
131
+ const children = graph.getChildren(frame.id)
132
+ for (const child of children) {
133
+ if (child.layoutPositioning === 'ABSOLUTE') {
134
+ const yogaChild = Yoga.Node.create()
135
+ configureAbsoluteChild(yogaChild, child)
136
+ root.insertChild(yogaChild, root.getChildCount())
137
+ } else {
138
+ root.insertChild(createGridChildNode(child), root.getChildCount())
139
+ }
140
+ }
141
+
142
+ return root
143
+ }
144
+
145
+ // --- Flex layout ---
146
+
147
+ function buildYogaTree(graph: SceneGraph, frame: SceneNode): YogaNode {
148
+ const root = Yoga.Node.create()
149
+
150
+ if (frame.primaryAxisSizing === 'FIXED') {
151
+ if (frame.layoutMode === 'HORIZONTAL') root.setWidth(frame.width)
152
+ else root.setHeight(frame.height)
153
+ }
154
+ if (frame.counterAxisSizing === 'FIXED') {
155
+ if (frame.layoutMode === 'HORIZONTAL') root.setHeight(frame.height)
156
+ else root.setWidth(frame.width)
157
+ }
158
+
159
+ configureFlexContainer(root, frame)
160
+
161
+ const children = graph.getChildren(frame.id)
162
+ for (const child of children) {
163
+ const yogaChild = Yoga.Node.create()
164
+
165
+ if (child.layoutPositioning === 'ABSOLUTE') {
166
+ configureAbsoluteChild(yogaChild, child)
167
+ } else if (!child.visible) {
168
+ yogaChild.setDisplay(Display.None)
169
+ } else if (child.layoutMode === 'GRID') {
170
+ configureChildAsGrid(yogaChild, child, frame, graph)
171
+ } else if (child.layoutMode !== 'NONE') {
172
+ configureChildAsAutoLayout(yogaChild, child, frame, graph)
173
+ } else {
174
+ configureChildAsLeaf(yogaChild, child, frame)
175
+ }
176
+
177
+ root.insertChild(yogaChild, root.getChildCount())
178
+ }
179
+
180
+ return root
181
+ }
182
+
183
+ function configureAbsoluteChild(yogaChild: YogaNode, child: SceneNode): void {
184
+ yogaChild.setPositionType(PositionType.Absolute)
185
+ yogaChild.setPosition(Edge.Left, child.x)
186
+ yogaChild.setPosition(Edge.Top, child.y)
187
+ yogaChild.setWidth(child.width)
188
+ yogaChild.setHeight(child.height)
189
+ }
190
+
191
+ function configureFlexContainer(yogaNode: YogaNode, node: SceneNode): void {
192
+ yogaNode.setFlexDirection(
193
+ node.layoutMode === 'HORIZONTAL' ? FlexDirection.Row : FlexDirection.Column
194
+ )
195
+ yogaNode.setFlexWrap(node.layoutWrap === 'WRAP' ? Wrap.Wrap : Wrap.NoWrap)
196
+ yogaNode.setJustifyContent(mapJustify(node.primaryAxisAlign))
197
+ yogaNode.setAlignItems(mapAlign(node.counterAxisAlign))
198
+ if (node.clipsContent) yogaNode.setOverflow(Overflow.Hidden)
199
+
200
+ if (node.layoutWrap === 'WRAP' && node.counterAxisAlignContent === 'SPACE_BETWEEN') {
201
+ yogaNode.setAlignContent(Align.SpaceBetween)
202
+ }
203
+
204
+ yogaNode.setPadding(Edge.Top, node.paddingTop)
205
+ yogaNode.setPadding(Edge.Right, node.paddingRight)
206
+ yogaNode.setPadding(Edge.Bottom, node.paddingBottom)
207
+ yogaNode.setPadding(Edge.Left, node.paddingLeft)
208
+
209
+ yogaNode.setGap(
210
+ Gutter.Column,
211
+ node.layoutMode === 'HORIZONTAL' ? node.itemSpacing : node.counterAxisSpacing
212
+ )
213
+ yogaNode.setGap(
214
+ Gutter.Row,
215
+ node.layoutMode === 'HORIZONTAL' ? node.counterAxisSpacing : node.itemSpacing
216
+ )
217
+
218
+ applyMinMaxConstraints(yogaNode, node)
219
+ }
220
+
221
+ function configureChildAsGrid(
222
+ yogaChild: YogaNode,
223
+ child: SceneNode,
224
+ parent: SceneNode,
225
+ graph: SceneGraph
226
+ ): void {
227
+ yogaChild.setDisplay(Display.Grid)
228
+
229
+ if (child.gridTemplateColumns.length > 0) {
230
+ yogaChild.setGridTemplateColumns(child.gridTemplateColumns.map(mapGridTrack))
231
+ }
232
+ if (child.gridTemplateRows.length > 0) {
233
+ yogaChild.setGridTemplateRows(child.gridTemplateRows.map(mapGridTrack))
234
+ }
235
+
236
+ yogaChild.setGap(Gutter.Column, child.gridColumnGap)
237
+ yogaChild.setGap(Gutter.Row, child.gridRowGap)
238
+
239
+ yogaChild.setPadding(Edge.Top, child.paddingTop)
240
+ yogaChild.setPadding(Edge.Right, child.paddingRight)
241
+ yogaChild.setPadding(Edge.Bottom, child.paddingBottom)
242
+ yogaChild.setPadding(Edge.Left, child.paddingLeft)
243
+
244
+ const isParentRow = parent.layoutMode === 'HORIZONTAL'
245
+ const selfOverride = child.layoutAlignSelf !== 'AUTO'
246
+ const stretchCross = selfOverride
247
+ ? child.layoutAlignSelf === 'STRETCH'
248
+ : parent.counterAxisAlign === 'STRETCH'
249
+
250
+ if (child.layoutGrow > 0) {
251
+ yogaChild.setFlexGrow(child.layoutGrow)
252
+ yogaChild.setFlexShrink(1)
253
+ yogaChild.setFlexBasis(0)
254
+ if (!stretchCross) {
255
+ if (isParentRow) yogaChild.setHeight(child.height)
256
+ else yogaChild.setWidth(child.width)
257
+ }
258
+ } else {
259
+ if (isParentRow) {
260
+ yogaChild.setWidth(child.width)
261
+ if (!stretchCross) yogaChild.setHeight(child.height)
262
+ } else {
263
+ if (child.gridTemplateRows.length > 0) yogaChild.setHeight(child.height)
264
+ if (!stretchCross) yogaChild.setWidth(child.width)
265
+ }
266
+ }
267
+
268
+ const selfAlign = mapAlignSelf(child.layoutAlignSelf)
269
+ if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)
270
+
271
+ applyMinMaxConstraints(yogaChild, child)
272
+
273
+ const grandchildren = graph.getChildren(child.id)
274
+ for (const gc of grandchildren) {
275
+ if (gc.layoutPositioning === 'ABSOLUTE') {
276
+ const yogaGC = Yoga.Node.create()
277
+ configureAbsoluteChild(yogaGC, gc)
278
+ yogaChild.insertChild(yogaGC, yogaChild.getChildCount())
279
+ } else {
280
+ yogaChild.insertChild(createGridChildNode(gc), yogaChild.getChildCount())
281
+ }
282
+ }
283
+ }
284
+
285
+ function applyMinMaxConstraints(yogaNode: YogaNode, node: SceneNode): void {
286
+ if (node.minWidth != null) yogaNode.setMinWidth(node.minWidth)
287
+ if (node.maxWidth != null) yogaNode.setMaxWidth(node.maxWidth)
288
+ if (node.minHeight != null) yogaNode.setMinHeight(node.minHeight)
289
+ if (node.maxHeight != null) yogaNode.setMaxHeight(node.maxHeight)
290
+ }
291
+
292
+ function configureChildAsAutoLayout(
293
+ yogaChild: YogaNode,
294
+ child: SceneNode,
295
+ parent: SceneNode,
296
+ graph: SceneGraph
297
+ ): void {
298
+ const isParentRow = parent.layoutMode === 'HORIZONTAL'
299
+ const isChildRow = child.layoutMode === 'HORIZONTAL'
300
+
301
+ const widthSizing = isChildRow ? child.primaryAxisSizing : child.counterAxisSizing
302
+ const heightSizing = isChildRow ? child.counterAxisSizing : child.primaryAxisSizing
303
+
304
+ if (isParentRow) {
305
+ setSizing(yogaChild, 'width', widthSizing, child.width, child.layoutGrow)
306
+ setSizing(yogaChild, 'height', heightSizing, child.height, 0)
307
+ } else {
308
+ setSizing(yogaChild, 'width', widthSizing, child.width, 0)
309
+ setSizing(yogaChild, 'height', heightSizing, child.height, child.layoutGrow)
310
+ }
311
+
312
+ const selfAlign = mapAlignSelf(child.layoutAlignSelf)
313
+ if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)
314
+
315
+ configureFlexContainer(yogaChild, child)
316
+
317
+ const grandchildren = graph.getChildren(child.id)
318
+ for (const gc of grandchildren) {
319
+ const yogaGC = Yoga.Node.create()
320
+ if (gc.layoutPositioning === 'ABSOLUTE') {
321
+ configureAbsoluteChild(yogaGC, gc)
322
+ } else if (!gc.visible) {
323
+ yogaGC.setDisplay(Display.None)
324
+ } else if (gc.layoutMode === 'GRID') {
325
+ configureChildAsGrid(yogaGC, gc, child, graph)
326
+ } else if (gc.layoutMode !== 'NONE') {
327
+ configureChildAsAutoLayout(yogaGC, gc, child, graph)
328
+ } else {
329
+ configureChildAsLeaf(yogaGC, gc, child)
330
+ }
331
+ yogaChild.insertChild(yogaGC, yogaChild.getChildCount())
332
+ }
333
+ }
334
+
335
+ function configureChildAsLeaf(yogaChild: YogaNode, child: SceneNode, parent: SceneNode): void {
336
+ const isRow = parent.layoutMode === 'HORIZONTAL'
337
+ const selfOverride = child.layoutAlignSelf !== 'AUTO'
338
+ const stretchCross = selfOverride
339
+ ? child.layoutAlignSelf === 'STRETCH'
340
+ : parent.counterAxisAlign === 'STRETCH'
341
+
342
+ const isText = child.type === 'TEXT'
343
+ const needsMeasureFunc =
344
+ isText && globalTextMeasurer && child.textAutoResize !== 'NONE'
345
+
346
+ if (needsMeasureFunc) {
347
+ configureTextLeaf(yogaChild, child, parent)
348
+ } else if (isText && !globalTextMeasurer && child.textAutoResize !== 'NONE') {
349
+ const est = estimateTextSize(child)
350
+ if (child.textAutoResize === 'WIDTH_AND_HEIGHT') {
351
+ yogaChild.setWidth(est.width)
352
+ yogaChild.setHeight(est.height)
353
+ } else if (child.textAutoResize === 'HEIGHT') {
354
+ yogaChild.setWidth(child.width)
355
+ yogaChild.setHeight(est.height)
356
+ }
357
+ } else {
358
+ configureNonTextLeaf(yogaChild, child, isRow, stretchCross)
359
+ }
360
+
361
+ const selfAlign = mapAlignSelf(child.layoutAlignSelf)
362
+ if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)
363
+
364
+ applyMinMaxConstraints(yogaChild, child)
365
+ }
366
+
367
+ // Fallback text size estimate when CanvasKit is unavailable (headless/tests).
368
+ // Without this, text nodes keep their 100×100 default and blow up HUG containers.
369
+ function estimateTextSize(node: SceneNode): { width: number; height: number } {
370
+ const fontSize = node.fontSize || 14
371
+ const lineHeight = fontSize * 1.2
372
+ const charWidth = fontSize * GLYPH_WIDTH_FACTOR
373
+ return {
374
+ width: Math.ceil(node.text.length * charWidth),
375
+ height: Math.ceil(lineHeight)
376
+ }
377
+ }
378
+
379
+ function configureTextLeaf(
380
+ yogaChild: YogaNode,
381
+ child: SceneNode,
382
+ _parent: SceneNode
383
+ ): void {
384
+ const autoResize = child.textAutoResize
385
+
386
+ if (child.layoutGrow > 0) {
387
+ yogaChild.setFlexGrow(child.layoutGrow)
388
+ }
389
+
390
+ const cache = new Map<number, { width: number; height: number }>()
391
+ const UNCONSTRAINED_KEY = -1
392
+
393
+ if (autoResize === 'WIDTH_AND_HEIGHT') {
394
+ yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {
395
+ const maxW = widthMode === MeasureMode.Undefined ? undefined : width
396
+ const cacheKey = maxW === undefined ? UNCONSTRAINED_KEY : Math.round(maxW)
397
+ const cached = cache.get(cacheKey)
398
+ if (cached) return cached
399
+
400
+ const measured = globalTextMeasurer?.(child, maxW)
401
+ const result = measured ?? { width: child.width, height: child.height }
402
+ cache.set(cacheKey, result)
403
+ return result
404
+ })
405
+ } else if (autoResize === 'HEIGHT') {
406
+ const fixedWidth = child.width
407
+ if (child.layoutGrow <= 0) {
408
+ yogaChild.setWidth(fixedWidth)
409
+ }
410
+ yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {
411
+ const constraintW =
412
+ widthMode === MeasureMode.Undefined ? fixedWidth : Math.min(width, fixedWidth || width)
413
+ const cacheKey = Math.round(constraintW)
414
+ const cached = cache.get(cacheKey)
415
+ if (cached) return cached
416
+
417
+ const measured = globalTextMeasurer?.(child, constraintW)
418
+ const result = { width: constraintW, height: measured?.height ?? child.height }
419
+ cache.set(cacheKey, result)
420
+ return result
421
+ })
422
+ }
423
+ }
424
+
425
+ function configureNonTextLeaf(
426
+ yogaChild: YogaNode,
427
+ child: SceneNode,
428
+ isRow: boolean,
429
+ stretchCross: boolean
430
+ ): void {
431
+ const w = child.width
432
+ const h = child.height
433
+
434
+ if (child.layoutGrow > 0) {
435
+ yogaChild.setFlexGrow(child.layoutGrow)
436
+ if (!stretchCross) {
437
+ if (isRow) yogaChild.setHeight(h)
438
+ else yogaChild.setWidth(w)
439
+ }
440
+ } else {
441
+ if (isRow) {
442
+ yogaChild.setWidth(w)
443
+ if (!stretchCross) yogaChild.setHeight(h)
444
+ } else {
445
+ yogaChild.setHeight(h)
446
+ if (!stretchCross) yogaChild.setWidth(w)
447
+ }
448
+ }
449
+ }
450
+
451
+ function setSizing(
452
+ yogaNode: YogaNode,
453
+ axis: 'width' | 'height',
454
+ sizing: string,
455
+ fixedValue: number,
456
+ grow: number
457
+ ): void {
458
+ if (grow > 0) {
459
+ yogaNode.setFlexGrow(grow)
460
+ yogaNode.setFlexShrink(1)
461
+ yogaNode.setFlexBasis(0)
462
+ return
463
+ }
464
+
465
+ switch (sizing) {
466
+ case 'FIXED':
467
+ if (axis === 'width') yogaNode.setWidth(fixedValue)
468
+ else yogaNode.setHeight(fixedValue)
469
+ break
470
+ case 'HUG':
471
+ break
472
+ case 'FILL':
473
+ yogaNode.setFlexGrow(1)
474
+ yogaNode.setFlexShrink(1)
475
+ yogaNode.setFlexBasis(0)
476
+ break
477
+ }
478
+ }
479
+
480
+ function applyFrameSize(graph: SceneGraph, frame: SceneNode, yogaNode: YogaNode): void {
481
+ if (frame.layoutMode === 'GRID') {
482
+ if (frame.gridTemplateRows.length === 0) {
483
+ graph.updateNode(frame.id, { height: yogaNode.getComputedHeight() })
484
+ }
485
+ return
486
+ }
487
+
488
+ if (frame.primaryAxisSizing !== 'HUG' && frame.counterAxisSizing !== 'HUG') return
489
+
490
+ const computedW = yogaNode.getComputedWidth()
491
+ const computedH = yogaNode.getComputedHeight()
492
+ const updates: Partial<SceneNode> = {}
493
+
494
+ if (frame.primaryAxisSizing === 'HUG') {
495
+ if (frame.layoutMode === 'HORIZONTAL') updates.width = computedW
496
+ else updates.height = computedH
497
+ }
498
+ if (frame.counterAxisSizing === 'HUG') {
499
+ if (frame.layoutMode === 'HORIZONTAL') updates.height = computedH
500
+ else updates.width = computedW
501
+ }
502
+
503
+ graph.updateNode(frame.id, updates)
504
+ }
505
+
506
+ function applyYogaLayout(graph: SceneGraph, frame: SceneNode, yogaNode: YogaNode): void {
507
+ applyFrameSize(graph, frame, yogaNode)
508
+
509
+ const children = graph.getChildren(frame.id)
510
+ let yogaIndex = 0
511
+ for (const child of children) {
512
+ const yogaChild = yogaNode.getChild(yogaIndex)
513
+ yogaIndex++
514
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
515
+ if (!yogaChild) continue
516
+
517
+ if (child.visible && child.layoutPositioning !== 'ABSOLUTE') {
518
+ graph.updateNode(child.id, {
519
+ x: yogaChild.getComputedLeft(),
520
+ y: yogaChild.getComputedTop(),
521
+ width: yogaChild.getComputedWidth(),
522
+ height: yogaChild.getComputedHeight()
523
+ })
524
+ }
525
+
526
+ if (child.layoutMode !== 'NONE') {
527
+ if (child.layoutMode === 'GRID' && child.visible && child.layoutPositioning !== 'ABSOLUTE') {
528
+ computeLayout(graph, child.id)
529
+ } else if (frame.layoutMode === 'GRID' && child.visible && child.layoutPositioning !== 'ABSOLUTE') {
530
+ recomputeGridChild(graph, child)
531
+ } else {
532
+ applyYogaLayout(graph, child, yogaChild)
533
+ }
534
+ }
535
+ }
536
+ }
537
+
538
+ function recomputeGridChild(graph: SceneGraph, child: SceneNode): void {
539
+ const updated = graph.getNode(child.id)
540
+ if (!updated || updated.layoutMode === 'NONE') return
541
+
542
+ const savedPrimary = updated.primaryAxisSizing
543
+ const savedCounter = updated.counterAxisSizing
544
+ const updates: Partial<SceneNode> = {}
545
+
546
+ if (savedPrimary === 'HUG') updates.primaryAxisSizing = 'FIXED'
547
+ if (savedCounter === 'HUG') updates.counterAxisSizing = 'FIXED'
548
+ if (Object.keys(updates).length > 0) graph.updateNode(child.id, updates)
549
+
550
+ computeLayout(graph, child.id)
551
+
552
+ const restore: Partial<SceneNode> = {}
553
+ if (updates.primaryAxisSizing) restore.primaryAxisSizing = savedPrimary
554
+ if (updates.counterAxisSizing) restore.counterAxisSizing = savedCounter
555
+ if (Object.keys(restore).length > 0) graph.updateNode(child.id, restore)
556
+ }
557
+
558
+ function freeYogaTree(node: YogaNode): void {
559
+ for (let i = node.getChildCount() - 1; i >= 0; i--) {
560
+ freeYogaTree(node.getChild(i))
561
+ }
562
+ if ('free' in node) (node as { free(): void }).free()
563
+ }
564
+
565
+ function mapJustify(align: string): Justify {
566
+ switch (align) {
567
+ case 'CENTER':
568
+ return Justify.Center
569
+ case 'MAX':
570
+ return Justify.FlexEnd
571
+ case 'SPACE_BETWEEN':
572
+ return Justify.SpaceBetween
573
+ default:
574
+ return Justify.FlexStart
575
+ }
576
+ }
577
+
578
+ function mapAlign(align: string): Align {
579
+ switch (align) {
580
+ case 'CENTER':
581
+ return Align.Center
582
+ case 'MAX':
583
+ return Align.FlexEnd
584
+ case 'STRETCH':
585
+ return Align.Stretch
586
+ case 'BASELINE':
587
+ return Align.Baseline
588
+ default:
589
+ return Align.FlexStart
590
+ }
591
+ }
592
+
593
+ function mapAlignSelf(alignSelf: string): Align | null {
594
+ switch (alignSelf) {
595
+ case 'MIN':
596
+ return Align.FlexStart
597
+ case 'CENTER':
598
+ return Align.Center
599
+ case 'MAX':
600
+ return Align.FlexEnd
601
+ case 'STRETCH':
602
+ return Align.Stretch
603
+ case 'BASELINE':
604
+ return Align.Baseline
605
+ default:
606
+ return null
607
+ }
608
+ }
@@ -0,0 +1,43 @@
1
+ const DRAW_METHODS = [
2
+ 'drawArrays',
3
+ 'drawElements',
4
+ 'drawArraysInstanced',
5
+ 'drawElementsInstanced'
6
+ ] as const
7
+
8
+ type DrawMethod = (typeof DRAW_METHODS)[number]
9
+
10
+ export class DrawCallCounter {
11
+ count = 0
12
+
13
+ private originals = new Map<DrawMethod, (...args: unknown[]) => void>()
14
+ private gl: WebGL2RenderingContext | null
15
+
16
+ constructor(gl: WebGL2RenderingContext | null) {
17
+ this.gl = gl
18
+ if (!gl) return
19
+
20
+ for (const method of DRAW_METHODS) {
21
+ const original = gl[method].bind(gl) as (...args: unknown[]) => void
22
+ this.originals.set(method, original)
23
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- monkey-patching overloaded WebGL draw methods
24
+ ;(gl[method] as Function) = (...args: unknown[]) => { this.count++; original(...args) }
25
+ }
26
+ }
27
+
28
+ reset(): number {
29
+ const prev = this.count
30
+ this.count = 0
31
+ return prev
32
+ }
33
+
34
+ destroy(): void {
35
+ const gl = this.gl
36
+ if (!gl) return
37
+
38
+ for (const [method, fn] of this.originals) {
39
+ ;(gl[method] as Function) = fn
40
+ }
41
+ this.originals.clear()
42
+ }
43
+ }