@pairdraw/vue 0.19.2 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (477) hide show
  1. package/dist/canvas/CanvasRoot.vue.js +5 -0
  2. package/dist/canvas/CanvasRoot.vue.js.map +1 -1
  3. package/dist/canvas/auto-layout/value-edit.js +1 -1
  4. package/dist/canvas/auto-layout/value-edit.js.map +1 -1
  5. package/dist/canvas/eyedropper/index.d.ts +26 -0
  6. package/dist/canvas/eyedropper/index.d.ts.map +1 -0
  7. package/dist/canvas/eyedropper/index.js +62 -0
  8. package/dist/canvas/eyedropper/index.js.map +1 -0
  9. package/dist/canvas/eyedropper/sample.js +13 -0
  10. package/dist/canvas/eyedropper/sample.js.map +1 -0
  11. package/dist/canvas/eyedropper/use.d.ts +33 -0
  12. package/dist/canvas/eyedropper/use.d.ts.map +1 -0
  13. package/dist/canvas/eyedropper/use.js +52 -0
  14. package/dist/canvas/eyedropper/use.js.map +1 -0
  15. package/dist/canvas/pointer/drag-move.js +4 -0
  16. package/dist/canvas/pointer/drag-move.js.map +1 -1
  17. package/dist/canvas/surface/color-space.d.ts +1 -0
  18. package/dist/canvas/surface/color-space.d.ts.map +1 -1
  19. package/dist/canvas/surface/gl-surface.js +5 -1
  20. package/dist/canvas/surface/gl-surface.js.map +1 -1
  21. package/dist/canvas/surface/kit-loader.js +2 -3
  22. package/dist/canvas/surface/kit-loader.js.map +1 -1
  23. package/dist/canvas/surface/lifecycle.js +34 -3
  24. package/dist/canvas/surface/lifecycle.js.map +1 -1
  25. package/dist/canvas/surface/origin.js +14 -0
  26. package/dist/canvas/surface/origin.js.map +1 -0
  27. package/dist/canvas/surface/shader/plan.js +40 -0
  28. package/dist/canvas/surface/shader/plan.js.map +1 -0
  29. package/dist/canvas/surface/shader/playback.js +132 -36
  30. package/dist/canvas/surface/shader/playback.js.map +1 -1
  31. package/dist/canvas/surface/shader/stage.d.ts.map +1 -1
  32. package/dist/canvas/surface/shader/stage.js +42 -5
  33. package/dist/canvas/surface/shader/stage.js.map +1 -1
  34. package/dist/canvas/surface/types.d.ts +25 -0
  35. package/dist/canvas/surface/types.d.ts.map +1 -1
  36. package/dist/canvas/surface/use.js +3 -1
  37. package/dist/canvas/surface/use.js.map +1 -1
  38. package/dist/canvas/text-edit/textarea.d.ts +1 -0
  39. package/dist/canvas/text-edit/textarea.d.ts.map +1 -1
  40. package/dist/canvas/tools/registry.js +5 -1
  41. package/dist/canvas/tools/registry.js.map +1 -1
  42. package/dist/canvas/useCanvasInput.d.ts +144 -2
  43. package/dist/canvas/useCanvasInput.d.ts.map +1 -1
  44. package/dist/canvas/useCanvasInput.js +3 -2
  45. package/dist/canvas/useCanvasInput.js.map +1 -1
  46. package/dist/controls/appearance/use.d.ts +1 -1
  47. package/dist/controls/binding-provider/pairdraw.js +1 -1
  48. package/dist/controls/binding-provider/pairdraw.js.map +1 -1
  49. package/dist/controls/color-model/types.d.ts +6 -0
  50. package/dist/controls/color-model/types.d.ts.map +1 -1
  51. package/dist/controls/color-model/use.d.ts.map +1 -1
  52. package/dist/controls/color-model/use.js +5 -3
  53. package/dist/controls/color-model/use.js.map +1 -1
  54. package/dist/controls/document-colors/index.d.ts +2 -0
  55. package/dist/controls/document-colors/index.js +2 -0
  56. package/dist/controls/document-colors/use.d.ts +20 -0
  57. package/dist/controls/document-colors/use.d.ts.map +1 -0
  58. package/dist/controls/document-colors/use.js +35 -0
  59. package/dist/controls/document-colors/use.js.map +1 -0
  60. package/dist/controls/effects/helpers.d.ts +13 -2
  61. package/dist/controls/effects/helpers.d.ts.map +1 -1
  62. package/dist/controls/effects/helpers.js +89 -34
  63. package/dist/controls/effects/helpers.js.map +1 -1
  64. package/dist/controls/effects/index.d.ts +2 -1
  65. package/dist/controls/effects/index.js +2 -1
  66. package/dist/controls/effects/use.d.ts +9 -7
  67. package/dist/controls/effects/use.d.ts.map +1 -1
  68. package/dist/controls/effects/use.js +6 -3
  69. package/dist/controls/effects/use.js.map +1 -1
  70. package/dist/controls/okhcl/use.d.ts +2 -2
  71. package/dist/controls/shader/catalog.d.ts +11 -0
  72. package/dist/controls/shader/catalog.d.ts.map +1 -1
  73. package/dist/controls/shader/catalog.js +35 -6
  74. package/dist/controls/shader/catalog.js.map +1 -1
  75. package/dist/controls/shader/gallery.d.ts +1 -1
  76. package/dist/controls/shader/gallery.d.ts.map +1 -1
  77. package/dist/controls/shader/gallery.js +292 -0
  78. package/dist/controls/shader/gallery.js.map +1 -1
  79. package/dist/controls/shader/index.d.ts +3 -1
  80. package/dist/controls/shader/index.js +3 -1
  81. package/dist/controls/shader/shapes.d.ts +18 -0
  82. package/dist/controls/shader/shapes.d.ts.map +1 -0
  83. package/dist/controls/shader/shapes.js +227 -0
  84. package/dist/controls/shader/shapes.js.map +1 -0
  85. package/dist/controls/shader/stops.d.ts +22 -0
  86. package/dist/controls/shader/stops.d.ts.map +1 -0
  87. package/dist/controls/shader/stops.js +73 -0
  88. package/dist/controls/shader/stops.js.map +1 -0
  89. package/dist/controls/typography/features.d.ts +24 -0
  90. package/dist/controls/typography/features.d.ts.map +1 -0
  91. package/dist/controls/typography/features.js +130 -0
  92. package/dist/controls/typography/features.js.map +1 -0
  93. package/dist/controls/typography/index.d.ts +2 -1
  94. package/dist/controls/typography/index.js +2 -1
  95. package/dist/controls/typography/use.d.ts +6 -0
  96. package/dist/controls/typography/use.d.ts.map +1 -1
  97. package/dist/controls/typography/use.js +4 -1
  98. package/dist/controls/typography/use.js.map +1 -1
  99. package/dist/controls/variable-modes/helpers.d.ts.map +1 -1
  100. package/dist/controls/variable-modes/helpers.js +4 -2
  101. package/dist/controls/variable-modes/helpers.js.map +1 -1
  102. package/dist/editor/commands/registry.d.ts +4 -0
  103. package/dist/editor/commands/registry.d.ts.map +1 -1
  104. package/dist/editor/commands/registry.js +2 -0
  105. package/dist/editor/commands/registry.js.map +1 -1
  106. package/dist/editor/commands/selection.js +22 -0
  107. package/dist/editor/commands/selection.js.map +1 -1
  108. package/dist/editor/commands/types.d.ts +1 -1
  109. package/dist/editor/commands/types.d.ts.map +1 -1
  110. package/dist/editor/menu-model/canvas.d.ts.map +1 -1
  111. package/dist/editor/menu-model/canvas.js +7 -1
  112. package/dist/editor/menu-model/canvas.js.map +1 -1
  113. package/dist/editor/selection-capabilities/use.d.ts +2 -0
  114. package/dist/editor/selection-capabilities/use.js +5 -0
  115. package/dist/editor/selection-capabilities/use.js.map +1 -1
  116. package/dist/editor/selection-state/use.d.ts +1 -0
  117. package/dist/editor/selection-state/use.js +5 -0
  118. package/dist/editor/selection-state/use.js.map +1 -1
  119. package/dist/editor/tool-cursor/index.d.ts.map +1 -1
  120. package/dist/editor/tool-cursor/index.js +5 -1
  121. package/dist/editor/tool-cursor/index.js.map +1 -1
  122. package/dist/i18n/create.d.ts +1 -1
  123. package/dist/i18n/create.d.ts.map +1 -1
  124. package/dist/i18n/create.js +1 -0
  125. package/dist/i18n/create.js.map +1 -1
  126. package/dist/i18n/index.d.ts +5 -2
  127. package/dist/i18n/index.js +5 -2
  128. package/dist/i18n/locale.d.ts +5 -4
  129. package/dist/i18n/locale.d.ts.map +1 -1
  130. package/dist/i18n/locale.js +4 -0
  131. package/dist/i18n/locale.js.map +1 -1
  132. package/dist/i18n/locales/de/ai.json.js +68 -2
  133. package/dist/i18n/locales/de/commands.json.js +2 -0
  134. package/dist/i18n/locales/de/comments.json.js +1 -1
  135. package/dist/i18n/locales/de/design-check.json.js +13 -1
  136. package/dist/i18n/locales/de/design-memory.json.js +82 -0
  137. package/dist/i18n/locales/de/design-memory.json.js.map +1 -0
  138. package/dist/i18n/locales/de/fonts.json.js +10 -0
  139. package/dist/i18n/locales/de/index.js +5 -1
  140. package/dist/i18n/locales/de/index.js.map +1 -1
  141. package/dist/i18n/locales/de/menu.json.js +2 -0
  142. package/dist/i18n/locales/de/panels.json.js +109 -1
  143. package/dist/i18n/locales/de/settings.json.js +1 -0
  144. package/dist/i18n/locales/de/tools.json.js +3 -1
  145. package/dist/i18n/locales/de/variables/panel.json.js +20 -0
  146. package/dist/i18n/locales/de/variations.json.js +23 -0
  147. package/dist/i18n/locales/de/variations.json.js.map +1 -0
  148. package/dist/i18n/locales/es/ai.json.js +67 -1
  149. package/dist/i18n/locales/es/commands.json.js +2 -0
  150. package/dist/i18n/locales/es/comments.json.js +1 -1
  151. package/dist/i18n/locales/es/design-check.json.js +13 -1
  152. package/dist/i18n/locales/es/design-memory.json.js +82 -0
  153. package/dist/i18n/locales/es/design-memory.json.js.map +1 -0
  154. package/dist/i18n/locales/es/fonts.json.js +10 -0
  155. package/dist/i18n/locales/es/index.js +5 -1
  156. package/dist/i18n/locales/es/index.js.map +1 -1
  157. package/dist/i18n/locales/es/menu.json.js +2 -0
  158. package/dist/i18n/locales/es/panels.json.js +109 -1
  159. package/dist/i18n/locales/es/settings.json.js +1 -0
  160. package/dist/i18n/locales/es/tools.json.js +3 -1
  161. package/dist/i18n/locales/es/variables/panel.json.js +20 -0
  162. package/dist/i18n/locales/es/variations.json.js +23 -0
  163. package/dist/i18n/locales/es/variations.json.js.map +1 -0
  164. package/dist/i18n/locales/fr/ai.json.js +68 -2
  165. package/dist/i18n/locales/fr/commands.json.js +2 -0
  166. package/dist/i18n/locales/fr/comments.json.js +1 -1
  167. package/dist/i18n/locales/fr/design-check.json.js +13 -1
  168. package/dist/i18n/locales/fr/design-memory.json.js +82 -0
  169. package/dist/i18n/locales/fr/design-memory.json.js.map +1 -0
  170. package/dist/i18n/locales/fr/fonts.json.js +10 -0
  171. package/dist/i18n/locales/fr/index.js +5 -1
  172. package/dist/i18n/locales/fr/index.js.map +1 -1
  173. package/dist/i18n/locales/fr/menu.json.js +2 -0
  174. package/dist/i18n/locales/fr/panels.json.js +109 -1
  175. package/dist/i18n/locales/fr/settings.json.js +1 -0
  176. package/dist/i18n/locales/fr/tools.json.js +3 -1
  177. package/dist/i18n/locales/fr/variables/panel.json.js +20 -0
  178. package/dist/i18n/locales/fr/variations.json.js +23 -0
  179. package/dist/i18n/locales/fr/variations.json.js.map +1 -0
  180. package/dist/i18n/locales/id/agents.json.js +31 -0
  181. package/dist/i18n/locales/id/agents.json.js.map +1 -0
  182. package/dist/i18n/locales/id/ai.json.js +608 -0
  183. package/dist/i18n/locales/id/ai.json.js.map +1 -0
  184. package/dist/i18n/locales/id/automation.json.js +150 -0
  185. package/dist/i18n/locales/id/automation.json.js.map +1 -0
  186. package/dist/i18n/locales/id/browser.json.js +50 -0
  187. package/dist/i18n/locales/id/browser.json.js.map +1 -0
  188. package/dist/i18n/locales/id/chat-context.json.js +62 -0
  189. package/dist/i18n/locales/id/chat-context.json.js.map +1 -0
  190. package/dist/i18n/locales/id/cloud/editor.json.js +337 -0
  191. package/dist/i18n/locales/id/cloud/editor.json.js.map +1 -0
  192. package/dist/i18n/locales/id/cloud/portal.json.js +435 -0
  193. package/dist/i18n/locales/id/cloud/portal.json.js.map +1 -0
  194. package/dist/i18n/locales/id/code.json.js +43 -0
  195. package/dist/i18n/locales/id/code.json.js.map +1 -0
  196. package/dist/i18n/locales/id/collaboration.json.js +84 -0
  197. package/dist/i18n/locales/id/collaboration.json.js.map +1 -0
  198. package/dist/i18n/locales/id/commands.json.js +111 -0
  199. package/dist/i18n/locales/id/commands.json.js.map +1 -0
  200. package/dist/i18n/locales/id/comments.json.js +37 -0
  201. package/dist/i18n/locales/id/comments.json.js.map +1 -0
  202. package/dist/i18n/locales/id/common.json.js +51 -0
  203. package/dist/i18n/locales/id/common.json.js.map +1 -0
  204. package/dist/i18n/locales/id/credentials.json.js +21 -0
  205. package/dist/i18n/locales/id/credentials.json.js.map +1 -0
  206. package/dist/i18n/locales/id/design-check.json.js +101 -0
  207. package/dist/i18n/locales/id/design-check.json.js.map +1 -0
  208. package/dist/i18n/locales/id/design-memory.json.js +61 -0
  209. package/dist/i18n/locales/id/design-memory.json.js.map +1 -0
  210. package/dist/i18n/locales/id/diagnostics.json.js +78 -0
  211. package/dist/i18n/locales/id/diagnostics.json.js.map +1 -0
  212. package/dist/i18n/locales/id/editor.json.js +62 -0
  213. package/dist/i18n/locales/id/editor.json.js.map +1 -0
  214. package/dist/i18n/locales/id/explore.json.js +30 -0
  215. package/dist/i18n/locales/id/explore.json.js.map +1 -0
  216. package/dist/i18n/locales/id/figjam.json.js +39 -0
  217. package/dist/i18n/locales/id/figjam.json.js.map +1 -0
  218. package/dist/i18n/locales/id/files.json.js +86 -0
  219. package/dist/i18n/locales/id/files.json.js.map +1 -0
  220. package/dist/i18n/locales/id/fonts.json.js +54 -0
  221. package/dist/i18n/locales/id/fonts.json.js.map +1 -0
  222. package/dist/i18n/locales/id/index.js +85 -0
  223. package/dist/i18n/locales/id/index.js.map +1 -0
  224. package/dist/i18n/locales/id/media.json.js +52 -0
  225. package/dist/i18n/locales/id/media.json.js.map +1 -0
  226. package/dist/i18n/locales/id/menu.json.js +118 -0
  227. package/dist/i18n/locales/id/menu.json.js.map +1 -0
  228. package/dist/i18n/locales/id/pages.json.js +16 -0
  229. package/dist/i18n/locales/id/pages.json.js.map +1 -0
  230. package/dist/i18n/locales/id/panels.json.js +838 -0
  231. package/dist/i18n/locales/id/panels.json.js.map +1 -0
  232. package/dist/i18n/locales/id/recovery.json.js +36 -0
  233. package/dist/i18n/locales/id/recovery.json.js.map +1 -0
  234. package/dist/i18n/locales/id/rename.json.js +19 -0
  235. package/dist/i18n/locales/id/rename.json.js.map +1 -0
  236. package/dist/i18n/locales/id/rendering.json.js +18 -0
  237. package/dist/i18n/locales/id/rendering.json.js.map +1 -0
  238. package/dist/i18n/locales/id/settings.json.js +169 -0
  239. package/dist/i18n/locales/id/settings.json.js.map +1 -0
  240. package/dist/i18n/locales/id/shaders.json.js +24 -0
  241. package/dist/i18n/locales/id/shaders.json.js.map +1 -0
  242. package/dist/i18n/locales/id/shapes.json.js +48 -0
  243. package/dist/i18n/locales/id/shapes.json.js.map +1 -0
  244. package/dist/i18n/locales/id/slides.json.js +27 -0
  245. package/dist/i18n/locales/id/slides.json.js.map +1 -0
  246. package/dist/i18n/locales/id/statuses.json.js +38 -0
  247. package/dist/i18n/locales/id/statuses.json.js.map +1 -0
  248. package/dist/i18n/locales/id/storage.json.js +21 -0
  249. package/dist/i18n/locales/id/storage.json.js.map +1 -0
  250. package/dist/i18n/locales/id/tools.json.js +27 -0
  251. package/dist/i18n/locales/id/tools.json.js.map +1 -0
  252. package/dist/i18n/locales/id/updates.json.js +31 -0
  253. package/dist/i18n/locales/id/updates.json.js.map +1 -0
  254. package/dist/i18n/locales/id/variables/panel.json.js +175 -0
  255. package/dist/i18n/locales/id/variables/panel.json.js.map +1 -0
  256. package/dist/i18n/locales/id/variables/types.json.js +15 -0
  257. package/dist/i18n/locales/id/variables/types.json.js.map +1 -0
  258. package/dist/i18n/locales/id/variations.json.js +23 -0
  259. package/dist/i18n/locales/id/variations.json.js.map +1 -0
  260. package/dist/i18n/locales/it/ai.json.js +68 -2
  261. package/dist/i18n/locales/it/commands.json.js +2 -0
  262. package/dist/i18n/locales/it/comments.json.js +1 -1
  263. package/dist/i18n/locales/it/design-check.json.js +13 -1
  264. package/dist/i18n/locales/it/design-memory.json.js +82 -0
  265. package/dist/i18n/locales/it/design-memory.json.js.map +1 -0
  266. package/dist/i18n/locales/it/fonts.json.js +10 -0
  267. package/dist/i18n/locales/it/index.js +5 -1
  268. package/dist/i18n/locales/it/index.js.map +1 -1
  269. package/dist/i18n/locales/it/menu.json.js +2 -0
  270. package/dist/i18n/locales/it/panels.json.js +109 -1
  271. package/dist/i18n/locales/it/settings.json.js +1 -0
  272. package/dist/i18n/locales/it/tools.json.js +3 -1
  273. package/dist/i18n/locales/it/variables/panel.json.js +20 -0
  274. package/dist/i18n/locales/it/variations.json.js +23 -0
  275. package/dist/i18n/locales/it/variations.json.js.map +1 -0
  276. package/dist/i18n/locales/ja/ai.json.js +68 -2
  277. package/dist/i18n/locales/ja/commands.json.js +2 -0
  278. package/dist/i18n/locales/ja/comments.json.js +1 -1
  279. package/dist/i18n/locales/ja/design-check.json.js +13 -1
  280. package/dist/i18n/locales/ja/design-memory.json.js +61 -0
  281. package/dist/i18n/locales/ja/design-memory.json.js.map +1 -0
  282. package/dist/i18n/locales/ja/fonts.json.js +10 -0
  283. package/dist/i18n/locales/ja/index.js +5 -1
  284. package/dist/i18n/locales/ja/index.js.map +1 -1
  285. package/dist/i18n/locales/ja/menu.json.js +2 -0
  286. package/dist/i18n/locales/ja/panels.json.js +106 -1
  287. package/dist/i18n/locales/ja/settings.json.js +1 -0
  288. package/dist/i18n/locales/ja/tools.json.js +3 -1
  289. package/dist/i18n/locales/ja/variables/panel.json.js +20 -0
  290. package/dist/i18n/locales/ja/variations.json.js +23 -0
  291. package/dist/i18n/locales/ja/variations.json.js.map +1 -0
  292. package/dist/i18n/locales/pl/ai.json.js +68 -2
  293. package/dist/i18n/locales/pl/commands.json.js +2 -0
  294. package/dist/i18n/locales/pl/comments.json.js +1 -1
  295. package/dist/i18n/locales/pl/design-check.json.js +13 -1
  296. package/dist/i18n/locales/pl/design-memory.json.js +89 -0
  297. package/dist/i18n/locales/pl/design-memory.json.js.map +1 -0
  298. package/dist/i18n/locales/pl/fonts.json.js +10 -0
  299. package/dist/i18n/locales/pl/index.js +5 -1
  300. package/dist/i18n/locales/pl/index.js.map +1 -1
  301. package/dist/i18n/locales/pl/menu.json.js +2 -0
  302. package/dist/i18n/locales/pl/panels.json.js +110 -1
  303. package/dist/i18n/locales/pl/settings.json.js +1 -0
  304. package/dist/i18n/locales/pl/tools.json.js +3 -1
  305. package/dist/i18n/locales/pl/variables/panel.json.js +20 -0
  306. package/dist/i18n/locales/pl/variations.json.js +23 -0
  307. package/dist/i18n/locales/pl/variations.json.js.map +1 -0
  308. package/dist/i18n/locales/ru/ai.json.js +68 -2
  309. package/dist/i18n/locales/ru/commands.json.js +3 -1
  310. package/dist/i18n/locales/ru/comments.json.js +1 -1
  311. package/dist/i18n/locales/ru/design-check.json.js +13 -1
  312. package/dist/i18n/locales/ru/design-memory.json.js +89 -0
  313. package/dist/i18n/locales/ru/design-memory.json.js.map +1 -0
  314. package/dist/i18n/locales/ru/fonts.json.js +10 -0
  315. package/dist/i18n/locales/ru/index.js +5 -1
  316. package/dist/i18n/locales/ru/index.js.map +1 -1
  317. package/dist/i18n/locales/ru/menu.json.js +2 -0
  318. package/dist/i18n/locales/ru/panels.json.js +110 -1
  319. package/dist/i18n/locales/ru/settings.json.js +1 -0
  320. package/dist/i18n/locales/ru/tools.json.js +3 -1
  321. package/dist/i18n/locales/ru/variables/panel.json.js +20 -0
  322. package/dist/i18n/locales/ru/variations.json.js +23 -0
  323. package/dist/i18n/locales/ru/variations.json.js.map +1 -0
  324. package/dist/i18n/locales/zh-cn/ai.json.js +68 -2
  325. package/dist/i18n/locales/zh-cn/commands.json.js +2 -0
  326. package/dist/i18n/locales/zh-cn/comments.json.js +1 -1
  327. package/dist/i18n/locales/zh-cn/design-check.json.js +13 -1
  328. package/dist/i18n/locales/zh-cn/design-memory.json.js +61 -0
  329. package/dist/i18n/locales/zh-cn/design-memory.json.js.map +1 -0
  330. package/dist/i18n/locales/zh-cn/fonts.json.js +10 -0
  331. package/dist/i18n/locales/zh-cn/index.js +5 -1
  332. package/dist/i18n/locales/zh-cn/index.js.map +1 -1
  333. package/dist/i18n/locales/zh-cn/menu.json.js +2 -0
  334. package/dist/i18n/locales/zh-cn/panels.json.js +106 -1
  335. package/dist/i18n/locales/zh-cn/settings.json.js +1 -0
  336. package/dist/i18n/locales/zh-cn/tools.json.js +3 -1
  337. package/dist/i18n/locales/zh-cn/variables/panel.json.js +20 -0
  338. package/dist/i18n/locales/zh-cn/variations.json.js +23 -0
  339. package/dist/i18n/locales/zh-cn/variations.json.js.map +1 -0
  340. package/dist/i18n/messages/ai.d.ts +98 -2
  341. package/dist/i18n/messages/ai.d.ts.map +1 -1
  342. package/dist/i18n/messages/ai.js +70 -2
  343. package/dist/i18n/messages/ai.js.map +1 -1
  344. package/dist/i18n/messages/chat-usage.d.ts +34 -0
  345. package/dist/i18n/messages/chat-usage.d.ts.map +1 -0
  346. package/dist/i18n/messages/chat-usage.js +25 -0
  347. package/dist/i18n/messages/chat-usage.js.map +1 -0
  348. package/dist/i18n/messages/commands.d.ts +2 -0
  349. package/dist/i18n/messages/commands.d.ts.map +1 -1
  350. package/dist/i18n/messages/commands.js +2 -0
  351. package/dist/i18n/messages/commands.js.map +1 -1
  352. package/dist/i18n/messages/comments.d.ts +2 -2
  353. package/dist/i18n/messages/comments.js +2 -2
  354. package/dist/i18n/messages/comments.js.map +1 -1
  355. package/dist/i18n/messages/design-check.d.ts +12 -0
  356. package/dist/i18n/messages/design-check.d.ts.map +1 -1
  357. package/dist/i18n/messages/design-check.js +13 -1
  358. package/dist/i18n/messages/design-check.js.map +1 -1
  359. package/dist/i18n/messages/design-memory.d.ts +68 -0
  360. package/dist/i18n/messages/design-memory.d.ts.map +1 -0
  361. package/dist/i18n/messages/design-memory.js +85 -0
  362. package/dist/i18n/messages/design-memory.js.map +1 -0
  363. package/dist/i18n/messages/fonts.d.ts +12 -0
  364. package/dist/i18n/messages/fonts.d.ts.map +1 -1
  365. package/dist/i18n/messages/fonts.js +10 -0
  366. package/dist/i18n/messages/fonts.js.map +1 -1
  367. package/dist/i18n/messages/menu.d.ts +2 -0
  368. package/dist/i18n/messages/menu.d.ts.map +1 -1
  369. package/dist/i18n/messages/menu.js +2 -0
  370. package/dist/i18n/messages/menu.js.map +1 -1
  371. package/dist/i18n/messages/panels.d.ts +131 -0
  372. package/dist/i18n/messages/panels.d.ts.map +1 -1
  373. package/dist/i18n/messages/panels.js +109 -1
  374. package/dist/i18n/messages/panels.js.map +1 -1
  375. package/dist/i18n/messages/settings.d.ts +1 -0
  376. package/dist/i18n/messages/settings.d.ts.map +1 -1
  377. package/dist/i18n/messages/settings.js +1 -0
  378. package/dist/i18n/messages/settings.js.map +1 -1
  379. package/dist/i18n/messages/tools.d.ts +2 -0
  380. package/dist/i18n/messages/tools.d.ts.map +1 -1
  381. package/dist/i18n/messages/tools.js +3 -1
  382. package/dist/i18n/messages/tools.js.map +1 -1
  383. package/dist/i18n/messages/variables/panel.d.ts +24 -0
  384. package/dist/i18n/messages/variables/panel.d.ts.map +1 -1
  385. package/dist/i18n/messages/variables/panel.js +20 -0
  386. package/dist/i18n/messages/variables/panel.js.map +1 -1
  387. package/dist/i18n/messages/variations.d.ts +28 -0
  388. package/dist/i18n/messages/variations.d.ts.map +1 -0
  389. package/dist/i18n/messages/variations.js +26 -0
  390. package/dist/i18n/messages/variations.js.map +1 -0
  391. package/dist/i18n/messages.d.ts +405 -4
  392. package/dist/i18n/messages.d.ts.map +1 -1
  393. package/dist/i18n/messages.js +8 -2
  394. package/dist/i18n/messages.js.map +1 -1
  395. package/dist/i18n/useI18n.d.ts +1389 -13
  396. package/dist/i18n/useI18n.d.ts.map +1 -1
  397. package/dist/i18n/useI18n.js +8 -1
  398. package/dist/i18n/useI18n.js.map +1 -1
  399. package/dist/primitives/ColorPicker/ColorInputRoot.vue.d.ts +6 -0
  400. package/dist/primitives/ColorPicker/ColorInputRoot.vue.d.ts.map +1 -1
  401. package/dist/primitives/ColorPicker/ColorInputRoot.vue.js +3 -1
  402. package/dist/primitives/ColorPicker/ColorInputRoot.vue.js.map +1 -1
  403. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts +11 -2
  404. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts.map +1 -1
  405. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js +15 -5
  406. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js.map +1 -1
  407. package/dist/primitives/ColorPicker/index.d.ts +2 -1
  408. package/dist/primitives/ColorPicker/index.js +2 -1
  409. package/dist/primitives/ColorPicker/outside.d.ts +16 -0
  410. package/dist/primitives/ColorPicker/outside.d.ts.map +1 -0
  411. package/dist/primitives/ColorPicker/outside.js +20 -0
  412. package/dist/primitives/ColorPicker/outside.js.map +1 -0
  413. package/dist/primitives/Fill/FillRoot.vue.d.ts +2 -1
  414. package/dist/primitives/Fill/FillRoot.vue.d.ts.map +1 -1
  415. package/dist/primitives/Fill/FillRoot.vue.js +5 -2
  416. package/dist/primitives/Fill/FillRoot.vue.js.map +1 -1
  417. package/dist/primitives/Fill/FillSwatch.vue.d.ts.map +1 -1
  418. package/dist/primitives/Fill/FillSwatch.vue.js +2 -1
  419. package/dist/primitives/Fill/FillSwatch.vue.js.map +1 -1
  420. package/dist/primitives/Fill/types.d.ts +6 -1
  421. package/dist/primitives/Fill/types.d.ts.map +1 -1
  422. package/dist/primitives/Fill/useFill.d.ts +10 -4
  423. package/dist/primitives/Fill/useFill.d.ts.map +1 -1
  424. package/dist/primitives/Fill/useFill.js +14 -10
  425. package/dist/primitives/Fill/useFill.js.map +1 -1
  426. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts +5 -0
  427. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts.map +1 -1
  428. package/dist/primitives/FontPicker/FontPickerRoot.vue.js +63 -56
  429. package/dist/primitives/FontPicker/FontPickerRoot.vue.js.map +1 -1
  430. package/dist/primitives/GradientEditor/GradientEditorRoot.vue.d.ts +2 -1
  431. package/dist/primitives/GradientEditor/GradientEditorRoot.vue.d.ts.map +1 -1
  432. package/dist/primitives/GradientEditor/GradientEditorRoot.vue.js +5 -2
  433. package/dist/primitives/GradientEditor/GradientEditorRoot.vue.js.map +1 -1
  434. package/dist/primitives/GradientEditor/GradientEditorStop.vue.d.ts.map +1 -1
  435. package/dist/primitives/GradientEditor/GradientEditorStop.vue.js +4 -3
  436. package/dist/primitives/GradientEditor/GradientEditorStop.vue.js.map +1 -1
  437. package/dist/primitives/GradientEditor/types.d.ts +3 -1
  438. package/dist/primitives/GradientEditor/types.d.ts.map +1 -1
  439. package/dist/primitives/GradientEditor/useGradientStops.d.ts +5 -3
  440. package/dist/primitives/GradientEditor/useGradientStops.d.ts.map +1 -1
  441. package/dist/primitives/GradientEditor/useGradientStops.js +9 -4
  442. package/dist/primitives/GradientEditor/useGradientStops.js.map +1 -1
  443. package/dist/primitives/LayerTree/LayerTreeRoot.vue.d.ts +6 -1
  444. package/dist/primitives/LayerTree/LayerTreeRoot.vue.d.ts.map +1 -1
  445. package/dist/primitives/LayerTree/LayerTreeRoot.vue.js +16 -1
  446. package/dist/primitives/LayerTree/LayerTreeRoot.vue.js.map +1 -1
  447. package/dist/primitives/TypographyControls/TypographyControlsRoot.vue.d.ts +3 -0
  448. package/dist/primitives/TypographyControls/TypographyControlsRoot.vue.d.ts.map +1 -1
  449. package/dist/primitives/TypographyControls/TypographyControlsRoot.vue.js +3 -1
  450. package/dist/primitives/TypographyControls/TypographyControlsRoot.vue.js.map +1 -1
  451. package/dist/shared/assets/cursors/eyedropper.svg.js +6 -0
  452. package/dist/shared/assets/cursors/eyedropper.svg.js.map +1 -0
  453. package/dist/shared/frame.d.ts +28 -0
  454. package/dist/shared/frame.d.ts.map +1 -0
  455. package/dist/shared/frame.js +92 -0
  456. package/dist/shared/frame.js.map +1 -0
  457. package/dist/shared/input/auto-layout/drag.js +71 -0
  458. package/dist/shared/input/auto-layout/drag.js.map +1 -0
  459. package/dist/shared/input/{auto-layout-hover.d.ts → auto-layout/hover.d.ts} +3 -3
  460. package/dist/shared/input/auto-layout/hover.d.ts.map +1 -0
  461. package/dist/shared/input/{auto-layout-hover.js → auto-layout/hover.js} +42 -86
  462. package/dist/shared/input/auto-layout/hover.js.map +1 -0
  463. package/dist/shared/input/{auto-layout.js → auto-layout/index.js} +2 -2
  464. package/dist/shared/input/auto-layout/index.js.map +1 -0
  465. package/dist/shared/input/index.d.ts +1 -1
  466. package/dist/shared/input/index.js +1 -1
  467. package/dist/shared/input/move/drag.js +1 -1
  468. package/dist/shared/input/resize.js +1 -1
  469. package/dist/shared/input/select.js +5 -3
  470. package/dist/shared/input/select.js.map +1 -1
  471. package/dist/shared/input/types.d.ts +10 -2
  472. package/dist/shared/input/types.d.ts.map +1 -1
  473. package/dist/shared/input/types.js.map +1 -1
  474. package/package.json +19 -4
  475. package/dist/shared/input/auto-layout-hover.d.ts.map +0 -1
  476. package/dist/shared/input/auto-layout-hover.js.map +0 -1
  477. package/dist/shared/input/auto-layout.js.map +0 -1
@@ -85,6 +85,8 @@ function createShaderStage(options) {
85
85
  /** Renderers to let go of once the frame being drawn is done with them. */
86
86
  const retired = [];
87
87
  let last = 0;
88
+ /** Whether the backend is asked for display frames, which it is only while something draws. */
89
+ let running = false;
88
90
  function release() {
89
91
  for (const old of retired.splice(0)) old.dispose();
90
92
  }
@@ -102,6 +104,26 @@ function createShaderStage(options) {
102
104
  player = null;
103
105
  status.value = "failed";
104
106
  }
107
+ /**
108
+ * Asks for display frames. A paused stage with nothing stale draws no frames, so it asks for
109
+ * none: the browser then skips the shader's whole frame path until something changes.
110
+ */
111
+ function wake() {
112
+ if (!supported || isDisposed() || running) return;
113
+ running = true;
114
+ last = 0;
115
+ loop.resume();
116
+ }
117
+ /** Stops asking for display frames, which a playing clock or a stale frame starts again. */
118
+ function rest() {
119
+ if (!running) return;
120
+ running = false;
121
+ loop.pause();
122
+ }
123
+ /** Rests the loop when nothing will change the frame: the clock is paused and nothing is stale. */
124
+ function settleLoop() {
125
+ if (!clock.value.playing && !stale && !drawing && !starting) rest();
126
+ }
105
127
  /** Read through calls: a start in flight may be overtaken, or the stage closed, meanwhile. */
106
128
  const isDisposed = () => disposed;
107
129
  const latest = () => wanted;
@@ -137,6 +159,7 @@ function createShaderStage(options) {
137
159
  stale = true;
138
160
  retire(previous);
139
161
  status.value = "ready";
162
+ wake();
140
163
  }
141
164
  } finally {
142
165
  starting = false;
@@ -165,6 +188,7 @@ function createShaderStage(options) {
165
188
  return;
166
189
  }
167
190
  if (!player) status.value = "starting";
191
+ wake();
168
192
  reconcile();
169
193
  }
170
194
  /** Sizes the on-screen canvas to the preview's device pixels; a new size clears it. */
@@ -179,6 +203,7 @@ function createShaderStage(options) {
179
203
  canvas.width = deviceWidth;
180
204
  canvas.height = deviceHeight;
181
205
  stale = true;
206
+ wake();
182
207
  }
183
208
  /**
184
209
  * Draws the shader at the clock's time and copies the frame to the target in the same task,
@@ -209,23 +234,32 @@ function createShaderStage(options) {
209
234
  const loop = backend.frames((timestamp) => {
210
235
  const seconds = last === 0 ? 0 : Math.min((timestamp - last) / 1e3, MAX_FRAME_SECONDS);
211
236
  last = timestamp;
212
- clock.value = advanceShaderClock(clock.value, seconds);
237
+ if (clock.value.playing) clock.value = advanceShaderClock(clock.value, seconds);
213
238
  const target = options.target.value;
214
239
  const active = player;
215
- if (drawing || !target || !active) return;
240
+ if (drawing || !target || !active) {
241
+ settleLoop();
242
+ return;
243
+ }
216
244
  sizeTarget(target);
217
- if (!stale && active.rendered === clock.value.time) return;
245
+ if (!stale && active.rendered === clock.value.time) {
246
+ settleLoop();
247
+ return;
248
+ }
218
249
  drawing = true;
219
250
  draw(active, target).catch((error) => console.warn("Could not draw a shader frame", error)).finally(() => {
220
251
  drawing = false;
221
252
  release();
253
+ settleLoop();
222
254
  });
223
255
  });
224
256
  function play() {
225
257
  clock.value = playShaderClock(clock.value, true);
258
+ wake();
226
259
  }
227
260
  function pause() {
228
261
  clock.value = playShaderClock(clock.value, false);
262
+ settleLoop();
229
263
  }
230
264
  function toggle() {
231
265
  clock.value = playShaderClock(clock.value, !clock.value.playing);
@@ -233,6 +267,7 @@ function createShaderStage(options) {
233
267
  /** Shows the shader `time` seconds into its loop, playing on from there if it was playing. */
234
268
  function seek(time) {
235
269
  clock.value = seekShaderClock(clock.value, time);
270
+ wake();
236
271
  }
237
272
  function restart() {
238
273
  seek(0);
@@ -247,9 +282,11 @@ function createShaderStage(options) {
247
282
  });
248
283
  watchDebounced(sizeKey, () => request(options.preset(), options.size()), { debounce: RESIZE_SETTLE_MS });
249
284
  watch(options.target, (canvas) => {
250
- if (canvas) stale = true;
285
+ if (!canvas) return;
286
+ stale = true;
287
+ wake();
251
288
  });
252
- if (supported) loop.resume();
289
+ if (supported) wake();
253
290
  onScopeDispose(() => {
254
291
  disposed = true;
255
292
  loop.pause();
@@ -1 +1 @@
1
- {"version":3,"file":"stage.js","names":[],"sources":["../../../../src/canvas/surface/shader/stage.ts"],"sourcesContent":["import { useRafFn, watchDebounced } from '@vueuse/core'\nimport type { createRendererFromJSON } from 'shaders/core'\nimport { onScopeDispose, readonly, ref, shallowRef, watch, type Ref } from 'vue'\n\nimport type { Size } from '@pairdraw/scene-graph/primitives'\nimport type { ShaderPreset } from '@pairdraw/scene-graph/shaders'\n\nimport {\n advanceShaderClock,\n createShaderClock,\n playShaderClock,\n seekShaderClock,\n type ShaderClock\n} from '#vue/canvas/surface/shader/clock'\nimport { canDrawShaders } from '#vue/canvas/surface/shader/rasterizer'\n\n/** The longest side the preview draws at, in CSS pixels, however large the screen is. */\nconst MAX_STAGE_EDGE = 2048\n/**\n * The most wall time one frame may move the clock by, in seconds, so a tab that was hidden or a\n * frame that stalled resumes where it was rather than leaping ahead.\n */\nconst MAX_FRAME_SECONDS = 0.25\n/** How long the preview's size settles before the shader is drawn at it again, in milliseconds. */\nconst RESIZE_SETTLE_MS = 150\n\n/**\n * What the stage shows: nothing yet while the shader starts, its frames once it plays, or its\n * still where it cannot play, because the browser has no WebGPU or the shader failed to start.\n */\nexport type ShaderStageStatus = 'starting' | 'ready' | 'failed' | 'unsupported'\n\n/** One shader drawing at one preset and size, on a surface of type `Source`. */\nexport interface ShaderStageRenderer<Source> {\n /** What its frames are drawn on, which the stage copies to the screen. */\n source: Source\n renderFrame: (options: { deltaSeconds: number; waitForGpu: boolean }) => Promise<void>\n dispose: () => void\n}\n\n/** The 2D context the stage copies frames with. */\ninterface ShaderStageContext<Source> {\n clearRect(x: number, y: number, width: number, height: number): void\n drawImage(image: Source, dx: number, dy: number, dw: number, dh: number): void\n}\n\n/** The canvas on screen that shows the frames. */\nexport interface ShaderStageTarget<Source> extends Size {\n getContext(contextId: '2d'): ShaderStageContext<Source> | null\n}\n\n/** What the stage draws with: in the browser, the `shaders` library on WebGPU and the display's frames. */\nexport interface ShaderStageBackend<Source> {\n /** Whether shaders can play here at all. */\n supported: () => boolean\n /** A renderer for `preset` drawing at `size`, or null when it cannot start. */\n start: (preset: ShaderPreset, size: Size) => Promise<ShaderStageRenderer<Source> | null>\n /** Calls `frame` once per display frame while resumed. */\n frames: (frame: (timestamp: number) => void) => { pause: () => void; resume: () => void }\n}\n\n/** A shader drawing for the stage, with where in time its last frame was. */\ninterface StagePlayer<Source> {\n key: string\n renderer: ShaderStageRenderer<Source>\n /** The clock time its last frame was drawn at, in seconds. */\n rendered: number\n /** Whether it has drawn a frame yet; its first frame only prepares the effects' pipelines. */\n drawn: boolean\n}\n\ninterface StageRequest {\n key: string\n preset: ShaderPreset\n size: Size\n}\n\n/**\n * The largest box with `layer`'s proportions that fits in `area`, in whole CSS pixels and at\n * least one pixel a side, as the stage frames a layer's shader.\n */\nexport function fitShaderPreview(layer: Size, area: Size): Size {\n const width = Math.max(layer.width, 1)\n const height = Math.max(layer.height, 1)\n const scale = Math.min(area.width / width, area.height / height)\n const fitted = Number.isFinite(scale) && scale > 0 ? scale : 0\n return {\n width: Math.max(1, Math.floor(width * fitted)),\n height: Math.max(1, Math.floor(height * fitted))\n }\n}\n\n/** The size a preview of `size` CSS pixels draws its shader at. */\nfunction drawSize(size: Size): Size {\n const fit = Math.min(1, MAX_STAGE_EDGE / Math.max(size.width, size.height, 1))\n return {\n width: Math.max(1, Math.round(size.width * fit)),\n height: Math.max(1, Math.round(size.height * fit))\n }\n}\n\n/** Starts `preset` on a detached WebGPU canvas, as the `shaders` library's preset renderer. */\nasync function startBrowserRenderer(\n preset: ShaderPreset,\n size: Size\n): Promise<ShaderStageRenderer<HTMLCanvasElement> | null> {\n const canvas = document.createElement('canvas')\n // A detached canvas: the renderer sizes its buffer from these CSS pixels at the display's ratio.\n canvas.width = size.width\n canvas.height = size.height\n let renderer: ReturnType<typeof createRendererFromJSON> | null = null\n try {\n const { createRendererFromJSON } = await import('shaders/core')\n renderer = createRendererFromJSON(structuredClone(preset))\n await renderer.initialize(canvas)\n // Without a usable GPU the renderer draws nothing and says so only here.\n if (renderer.getFailureReason() !== null) throw new Error(String(renderer.getFailureReason()))\n const started = renderer\n return {\n source: canvas,\n renderFrame: (options) => started.renderFrame(options),\n dispose: () => started.dispose()\n }\n } catch (error) {\n console.warn('Could not play a shader in Shader Mode', error)\n renderer?.dispose()\n return null\n }\n}\n\n/** The browser's backend: WebGPU through the `shaders` library, on the display's frames. */\nconst browserShaderStageBackend: ShaderStageBackend<HTMLCanvasElement> = {\n supported: canDrawShaders,\n start: startBrowserRenderer,\n frames: (frame) => useRafFn(({ timestamp }) => frame(timestamp), { immediate: false })\n}\n\n/** Options both the browser's stage and a test's share. */\ninterface ShaderStageOptions<Source> {\n /** The preset to play, or null while there is none. */\n preset: () => ShaderPreset | null\n /** The preview's size on screen, in CSS pixels, or null until it is laid out. */\n size: () => Size | null\n target: Ref<ShaderStageTarget<Source> | null>\n /** Whether the clock starts running; a person who asks for reduced motion starts it paused. */\n autoplay?: boolean\n /** The device pixels per CSS pixel the preview draws at; the display's ratio by default. */\n getPixelRatio?: () => number\n}\n\n/**\n * The stage's player on any backend: {@link useShaderStage} runs it on the browser's, and a test\n * on its own. Call it inside an effect scope, which it stops with.\n */\nexport function createShaderStage<Source>(\n options: ShaderStageOptions<Source> & { backend: ShaderStageBackend<Source> }\n) {\n const { backend } = options\n const pixelRatio = options.getPixelRatio ?? (() => window.devicePixelRatio || 1)\n const supported = backend.supported()\n const clock = shallowRef<ShaderClock>(createShaderClock({ playing: options.autoplay ?? true }))\n const status = ref<ShaderStageStatus>(supported ? 'starting' : 'unsupported')\n\n let player: StagePlayer<Source> | null = null\n let wanted: StageRequest | null = null\n /** The request that failed to start, which is not tried again until the preset or size changes. */\n let failedKey: string | null = null\n let starting = false\n let drawing = false\n let disposed = false\n /** Whether the target was cleared, as by a resize, and needs the frame again though time stood. */\n let stale = true\n /** Renderers to let go of once the frame being drawn is done with them. */\n const retired: ShaderStageRenderer<Source>[] = []\n let last = 0\n\n function release() {\n for (const old of retired.splice(0)) old.dispose()\n }\n\n function retire(old: StagePlayer<Source> | null) {\n if (!old) return\n retired.push(old.renderer)\n if (!drawing) release()\n }\n\n /**\n * The shader asked for cannot play: an older one still showing would pass for it, so it goes,\n * and the stage shows the paint's still and says why.\n */\n function fail() {\n retire(player)\n player = null\n status.value = 'failed'\n }\n\n /** Read through calls: a start in flight may be overtaken, or the stage closed, meanwhile. */\n const isDisposed = () => disposed\n const latest = () => wanted\n\n /** The request still to start: the newest one, unless it already shows or failed. */\n function pending(): StageRequest | null {\n const next = latest()\n if (isDisposed() || !next || next.key === player?.key || next.key === failedKey) return null\n return next\n }\n\n /** Starts the latest request once any start in flight is done, so the newest setting wins. */\n async function reconcile() {\n if (starting || !supported) return\n starting = true\n try {\n for (let request = pending(); request; request = pending()) {\n const next = await backend.start(request.preset, request.size)\n if (isDisposed()) {\n if (next) retired.push(next)\n break\n }\n if (!next) {\n // A newer request may still start; this one is not tried again.\n failedKey = request.key\n if (latest() === request) fail()\n continue\n }\n // It draws its first frame at the clock's time, so the animation goes on from there.\n const previous = player\n player = { key: request.key, renderer: next, rendered: 0, drawn: false }\n stale = true\n retire(previous)\n status.value = 'ready'\n }\n } finally {\n starting = false\n if (isDisposed()) release()\n }\n }\n\n function request(preset: ShaderPreset | null, size: Size | null) {\n if (!preset) {\n wanted = null\n return\n }\n // Nothing is drawn before the preview has a size to draw at.\n if (!size || !supported) return\n const drawn = drawSize(size)\n const key = JSON.stringify([preset, drawn.width, drawn.height])\n wanted = { key, preset, size: drawn }\n if (key === failedKey) {\n // Back to a shader that failed: whatever shows now is another one.\n if (player) fail()\n return\n }\n if (!player) status.value = 'starting'\n void reconcile()\n }\n\n /** Sizes the on-screen canvas to the preview's device pixels; a new size clears it. */\n function sizeTarget(canvas: ShaderStageTarget<Source>) {\n const size = options.size()\n if (!size) return\n const { width, height } = size\n const ratio = pixelRatio()\n const deviceWidth = Math.max(1, Math.round(width * ratio))\n const deviceHeight = Math.max(1, Math.round(height * ratio))\n if (canvas.width === deviceWidth && canvas.height === deviceHeight) return\n canvas.width = deviceWidth\n canvas.height = deviceHeight\n stale = true\n }\n\n /**\n * Draws the shader at the clock's time and copies the frame to the target in the same task,\n * since a WebGPU canvas keeps its frame only until that task ends.\n */\n async function draw(active: StagePlayer<Source>, target: ShaderStageTarget<Source>) {\n const time = clock.value.time\n const { renderer } = active\n // The renderer's clocks only ever add the step they are given; a step back is negative.\n await renderer.renderFrame({ deltaSeconds: time - active.rendered, waitForGpu: false })\n if (!active.drawn) {\n active.drawn = true\n await renderer.renderFrame({ deltaSeconds: 0, waitForGpu: false })\n }\n active.rendered = time\n if (player !== active) return\n const context = target.getContext('2d')\n if (!context) return\n context.clearRect(0, 0, target.width, target.height)\n context.drawImage(renderer.source, 0, 0, target.width, target.height)\n stale = false\n }\n\n const loop = backend.frames((timestamp) => {\n const seconds = last === 0 ? 0 : Math.min((timestamp - last) / 1000, MAX_FRAME_SECONDS)\n last = timestamp\n clock.value = advanceShaderClock(clock.value, seconds)\n const target = options.target.value\n const active = player\n if (drawing || !target || !active) return\n sizeTarget(target)\n if (!stale && active.rendered === clock.value.time) return\n drawing = true\n void draw(active, target)\n .catch((error: unknown) => console.warn('Could not draw a shader frame', error))\n .finally(() => {\n drawing = false\n release()\n })\n })\n\n function play() {\n clock.value = playShaderClock(clock.value, true)\n }\n\n function pause() {\n clock.value = playShaderClock(clock.value, false)\n }\n\n function toggle() {\n clock.value = playShaderClock(clock.value, !clock.value.playing)\n }\n\n /** Shows the shader `time` seconds into its loop, playing on from there if it was playing. */\n function seek(time: number) {\n clock.value = seekShaderClock(clock.value, time)\n }\n\n function restart() {\n seek(0)\n }\n\n const sizeKey = () => {\n const size = options.size()\n return size ? `${size.width}x${size.height}` : ''\n }\n // A preset changes at once, and so does the first size; a later size waits for a resize to\n // settle.\n watch(\n () => JSON.stringify(options.preset()),\n () => request(options.preset(), options.size()),\n { immediate: true }\n )\n watch(sizeKey, () => {\n if (!player && !starting) request(options.preset(), options.size())\n })\n watchDebounced(sizeKey, () => request(options.preset(), options.size()), {\n debounce: RESIZE_SETTLE_MS\n })\n watch(options.target, (canvas) => {\n if (canvas) stale = true\n })\n\n if (supported) loop.resume()\n\n onScopeDispose(() => {\n disposed = true\n loop.pause()\n retire(player)\n player = null\n if (!starting) release()\n })\n\n return {\n clock: readonly(clock),\n status: readonly(status),\n play,\n pause,\n toggle,\n seek,\n restart\n }\n}\n\n/**\n * Plays one shader large, in Shader Mode, on a clock the person controls: it plays, pauses, and\n * jumps to any time in its loop, and its frames are drawn into `target`, a 2D canvas on screen.\n * A preset or size change starts a new renderer beside the one showing, which keeps drawing\n * until the new one is ready and then hands over at the same time in the loop, so tuning a\n * setting neither flashes nor restarts the animation. A shader that fails to start is not\n * covered by the one before it: the status says so. Without WebGPU the status says so too and\n * nothing draws.\n */\nexport function useShaderStage(\n options: ShaderStageOptions<HTMLCanvasElement> & {\n /** What plays the shader: WebGPU through the `shaders` library unless a story hands its own. */\n backend?: ShaderStageBackend<HTMLCanvasElement>\n }\n) {\n return createShaderStage({ ...options, backend: options.backend ?? browserShaderStageBackend })\n}\n"],"mappings":";;;;;;AAiBA,MAAM,iBAAiB;;;;;AAKvB,MAAM,oBAAoB;;AAE1B,MAAM,mBAAmB;;;;;AAyDzB,SAAgB,iBAAiB,OAAa,MAAkB;CAC9D,MAAM,QAAQ,KAAK,IAAI,MAAM,OAAO,CAAC;CACrC,MAAM,SAAS,KAAK,IAAI,MAAM,QAAQ,CAAC;CACvC,MAAM,QAAQ,KAAK,IAAI,KAAK,QAAQ,OAAO,KAAK,SAAS,MAAM;CAC/D,MAAM,SAAS,OAAO,SAAS,KAAK,KAAK,QAAQ,IAAI,QAAQ;CAC7D,OAAO;EACL,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,QAAQ,MAAM,CAAC;EAC7C,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,MAAM,CAAC;CACjD;AACF;;AAGA,SAAS,SAAS,MAAkB;CAClC,MAAM,MAAM,KAAK,IAAI,GAAG,iB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U,iBACZ,CAAC;CACD,MAAM,QAAQ,SAAS,WAAW;EAChC,IAAI,QAAQ,QAAQ;CACtB,CAAC;CAED,IAAI,WAAW,KAAK,OAAO;CAE3B,qBAAqB;EACnB,WAAW;EACX,KAAK,MAAM;EACX,OAAO,MAAM;EACb,SAAS;EACT,IAAI,CAAC,UAAU,QAAQ;CACzB,CAAC;CAED,OAAO;EACL,OAAO,SAAS,KAAK;EACrB,QAAQ,SAAS,MAAM;EACvB;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;;;;AAWA,SAAgB,eACd,SAIA;CACA,OAAO,kBAAkB;EAAE,GAAG;EAAS,SAAS,QAAQ,WAAW;CAA0B,CAAC;AAChG"}
1
+ {"version":3,"file":"stage.js","names":[],"sources":["../../../../src/canvas/surface/shader/stage.ts"],"sourcesContent":["import { useRafFn, watchDebounced } from '@vueuse/core'\nimport type { createRendererFromJSON } from 'shaders/core'\nimport { onScopeDispose, readonly, ref, shallowRef, watch, type Ref } from 'vue'\n\nimport type { Size } from '@pairdraw/scene-graph/primitives'\nimport type { ShaderPreset } from '@pairdraw/scene-graph/shaders'\n\nimport {\n advanceShaderClock,\n createShaderClock,\n playShaderClock,\n seekShaderClock,\n type ShaderClock\n} from '#vue/canvas/surface/shader/clock'\nimport { canDrawShaders } from '#vue/canvas/surface/shader/rasterizer'\n\n/** The longest side the preview draws at, in CSS pixels, however large the screen is. */\nconst MAX_STAGE_EDGE = 2048\n/**\n * The most wall time one frame may move the clock by, in seconds, so a tab that was hidden or a\n * frame that stalled resumes where it was rather than leaping ahead.\n */\nconst MAX_FRAME_SECONDS = 0.25\n/** How long the preview's size settles before the shader is drawn at it again, in milliseconds. */\nconst RESIZE_SETTLE_MS = 150\n\n/**\n * What the stage shows: nothing yet while the shader starts, its frames once it plays, or its\n * still where it cannot play, because the browser has no WebGPU or the shader failed to start.\n */\nexport type ShaderStageStatus = 'starting' | 'ready' | 'failed' | 'unsupported'\n\n/** One shader drawing at one preset and size, on a surface of type `Source`. */\nexport interface ShaderStageRenderer<Source> {\n /** What its frames are drawn on, which the stage copies to the screen. */\n source: Source\n renderFrame: (options: { deltaSeconds: number; waitForGpu: boolean }) => Promise<void>\n dispose: () => void\n}\n\n/** The 2D context the stage copies frames with. */\ninterface ShaderStageContext<Source> {\n clearRect(x: number, y: number, width: number, height: number): void\n drawImage(image: Source, dx: number, dy: number, dw: number, dh: number): void\n}\n\n/** The canvas on screen that shows the frames. */\nexport interface ShaderStageTarget<Source> extends Size {\n getContext(contextId: '2d'): ShaderStageContext<Source> | null\n}\n\n/** What the stage draws with: in the browser, the `shaders` library on WebGPU and the display's frames. */\nexport interface ShaderStageBackend<Source> {\n /** Whether shaders can play here at all. */\n supported: () => boolean\n /** A renderer for `preset` drawing at `size`, or null when it cannot start. */\n start: (preset: ShaderPreset, size: Size) => Promise<ShaderStageRenderer<Source> | null>\n /** Calls `frame` once per display frame while resumed. */\n frames: (frame: (timestamp: number) => void) => { pause: () => void; resume: () => void }\n}\n\n/** A shader drawing for the stage, with where in time its last frame was. */\ninterface StagePlayer<Source> {\n key: string\n renderer: ShaderStageRenderer<Source>\n /** The clock time its last frame was drawn at, in seconds. */\n rendered: number\n /** Whether it has drawn a frame yet; its first frame only prepares the effects' pipelines. */\n drawn: boolean\n}\n\ninterface StageRequest {\n key: string\n preset: ShaderPreset\n size: Size\n}\n\n/**\n * The largest box with `layer`'s proportions that fits in `area`, in whole CSS pixels and at\n * least one pixel a side, as the stage frames a layer's shader.\n */\nexport function fitShaderPreview(layer: Size, area: Size): Size {\n const width = Math.max(layer.width, 1)\n const height = Math.max(layer.height, 1)\n const scale = Math.min(area.width / width, area.height / height)\n const fitted = Number.isFinite(scale) && scale > 0 ? scale : 0\n return {\n width: Math.max(1, Math.floor(width * fitted)),\n height: Math.max(1, Math.floor(height * fitted))\n }\n}\n\n/** The size a preview of `size` CSS pixels draws its shader at. */\nfunction drawSize(size: Size): Size {\n const fit = Math.min(1, MAX_STAGE_EDGE / Math.max(size.width, size.height, 1))\n return {\n width: Math.max(1, Math.round(size.width * fit)),\n height: Math.max(1, Math.round(size.height * fit))\n }\n}\n\n/** Starts `preset` on a detached WebGPU canvas, as the `shaders` library's preset renderer. */\nasync function startBrowserRenderer(\n preset: ShaderPreset,\n size: Size\n): Promise<ShaderStageRenderer<HTMLCanvasElement> | null> {\n const canvas = document.createElement('canvas')\n // A detached canvas: the renderer sizes its buffer from these CSS pixels at the display's ratio.\n canvas.width = size.width\n canvas.height = size.height\n let renderer: ReturnType<typeof createRendererFromJSON> | null = null\n try {\n const { createRendererFromJSON } = await import('shaders/core')\n renderer = createRendererFromJSON(structuredClone(preset))\n await renderer.initialize(canvas)\n // Without a usable GPU the renderer draws nothing and says so only here.\n if (renderer.getFailureReason() !== null) throw new Error(String(renderer.getFailureReason()))\n const started = renderer\n return {\n source: canvas,\n renderFrame: (options) => started.renderFrame(options),\n dispose: () => started.dispose()\n }\n } catch (error) {\n console.warn('Could not play a shader in Shader Mode', error)\n renderer?.dispose()\n return null\n }\n}\n\n/** The browser's backend: WebGPU through the `shaders` library, on the display's frames. */\nconst browserShaderStageBackend: ShaderStageBackend<HTMLCanvasElement> = {\n supported: canDrawShaders,\n start: startBrowserRenderer,\n frames: (frame) => useRafFn(({ timestamp }) => frame(timestamp), { immediate: false })\n}\n\n/** Options both the browser's stage and a test's share. */\ninterface ShaderStageOptions<Source> {\n /** The preset to play, or null while there is none. */\n preset: () => ShaderPreset | null\n /** The preview's size on screen, in CSS pixels, or null until it is laid out. */\n size: () => Size | null\n target: Ref<ShaderStageTarget<Source> | null>\n /** Whether the clock starts running; a person who asks for reduced motion starts it paused. */\n autoplay?: boolean\n /** The device pixels per CSS pixel the preview draws at; the display's ratio by default. */\n getPixelRatio?: () => number\n}\n\n/**\n * The stage's player on any backend: {@link useShaderStage} runs it on the browser's, and a test\n * on its own. Call it inside an effect scope, which it stops with.\n */\nexport function createShaderStage<Source>(\n options: ShaderStageOptions<Source> & { backend: ShaderStageBackend<Source> }\n) {\n const { backend } = options\n const pixelRatio = options.getPixelRatio ?? (() => window.devicePixelRatio || 1)\n const supported = backend.supported()\n const clock = shallowRef<ShaderClock>(createShaderClock({ playing: options.autoplay ?? true }))\n const status = ref<ShaderStageStatus>(supported ? 'starting' : 'unsupported')\n\n let player: StagePlayer<Source> | null = null\n let wanted: StageRequest | null = null\n /** The request that failed to start, which is not tried again until the preset or size changes. */\n let failedKey: string | null = null\n let starting = false\n let drawing = false\n let disposed = false\n /** Whether the target was cleared, as by a resize, and needs the frame again though time stood. */\n let stale = true\n /** Renderers to let go of once the frame being drawn is done with them. */\n const retired: ShaderStageRenderer<Source>[] = []\n let last = 0\n /** Whether the backend is asked for display frames, which it is only while something draws. */\n let running = false\n\n function release() {\n for (const old of retired.splice(0)) old.dispose()\n }\n\n function retire(old: StagePlayer<Source> | null) {\n if (!old) return\n retired.push(old.renderer)\n if (!drawing) release()\n }\n\n /**\n * The shader asked for cannot play: an older one still showing would pass for it, so it goes,\n * and the stage shows the paint's still and says why.\n */\n function fail() {\n retire(player)\n player = null\n status.value = 'failed'\n }\n\n /**\n * Asks for display frames. A paused stage with nothing stale draws no frames, so it asks for\n * none: the browser then skips the shader's whole frame path until something changes.\n */\n function wake() {\n if (!supported || isDisposed() || running) return\n running = true\n // The first frame after a rest starts from where the clock is, not from the gap.\n last = 0\n loop.resume()\n }\n\n /** Stops asking for display frames, which a playing clock or a stale frame starts again. */\n function rest() {\n if (!running) return\n running = false\n loop.pause()\n }\n\n /** Rests the loop when nothing will change the frame: the clock is paused and nothing is stale. */\n function settleLoop() {\n if (!clock.value.playing && !stale && !drawing && !starting) rest()\n }\n\n /** Read through calls: a start in flight may be overtaken, or the stage closed, meanwhile. */\n const isDisposed = () => disposed\n const latest = () => wanted\n\n /** The request still to start: the newest one, unless it already shows or failed. */\n function pending(): StageRequest | null {\n const next = latest()\n if (isDisposed() || !next || next.key === player?.key || next.key === failedKey) return null\n return next\n }\n\n /** Starts the latest request once any start in flight is done, so the newest setting wins. */\n async function reconcile() {\n if (starting || !supported) return\n starting = true\n try {\n for (let request = pending(); request; request = pending()) {\n const next = await backend.start(request.preset, request.size)\n if (isDisposed()) {\n if (next) retired.push(next)\n break\n }\n if (!next) {\n // A newer request may still start; this one is not tried again.\n failedKey = request.key\n if (latest() === request) fail()\n continue\n }\n // It draws its first frame at the clock's time, so the animation goes on from there.\n const previous = player\n player = { key: request.key, renderer: next, rendered: 0, drawn: false }\n stale = true\n retire(previous)\n status.value = 'ready'\n wake()\n }\n } finally {\n starting = false\n if (isDisposed()) release()\n }\n }\n\n function request(preset: ShaderPreset | null, size: Size | null) {\n if (!preset) {\n wanted = null\n return\n }\n // Nothing is drawn before the preview has a size to draw at.\n if (!size || !supported) return\n const drawn = drawSize(size)\n const key = JSON.stringify([preset, drawn.width, drawn.height])\n wanted = { key, preset, size: drawn }\n if (key === failedKey) {\n // Back to a shader that failed: whatever shows now is another one.\n if (player) fail()\n return\n }\n if (!player) status.value = 'starting'\n wake()\n void reconcile()\n }\n\n /** Sizes the on-screen canvas to the preview's device pixels; a new size clears it. */\n function sizeTarget(canvas: ShaderStageTarget<Source>) {\n const size = options.size()\n if (!size) return\n const { width, height } = size\n const ratio = pixelRatio()\n const deviceWidth = Math.max(1, Math.round(width * ratio))\n const deviceHeight = Math.max(1, Math.round(height * ratio))\n if (canvas.width === deviceWidth && canvas.height === deviceHeight) return\n canvas.width = deviceWidth\n canvas.height = deviceHeight\n stale = true\n wake()\n }\n\n /**\n * Draws the shader at the clock's time and copies the frame to the target in the same task,\n * since a WebGPU canvas keeps its frame only until that task ends.\n */\n async function draw(active: StagePlayer<Source>, target: ShaderStageTarget<Source>) {\n const time = clock.value.time\n const { renderer } = active\n // The renderer's clocks only ever add the step they are given; a step back is negative.\n await renderer.renderFrame({ deltaSeconds: time - active.rendered, waitForGpu: false })\n if (!active.drawn) {\n active.drawn = true\n await renderer.renderFrame({ deltaSeconds: 0, waitForGpu: false })\n }\n active.rendered = time\n if (player !== active) return\n const context = target.getContext('2d')\n if (!context) return\n context.clearRect(0, 0, target.width, target.height)\n context.drawImage(renderer.source, 0, 0, target.width, target.height)\n stale = false\n }\n\n const loop = backend.frames((timestamp) => {\n const seconds = last === 0 ? 0 : Math.min((timestamp - last) / 1000, MAX_FRAME_SECONDS)\n last = timestamp\n if (clock.value.playing) clock.value = advanceShaderClock(clock.value, seconds)\n const target = options.target.value\n const active = player\n if (drawing || !target || !active) {\n settleLoop()\n return\n }\n sizeTarget(target)\n if (!stale && active.rendered === clock.value.time) {\n settleLoop()\n return\n }\n drawing = true\n void draw(active, target)\n .catch((error: unknown) => console.warn('Could not draw a shader frame', error))\n .finally(() => {\n drawing = false\n release()\n settleLoop()\n })\n })\n\n function play() {\n clock.value = playShaderClock(clock.value, true)\n wake()\n }\n\n function pause() {\n clock.value = playShaderClock(clock.value, false)\n settleLoop()\n }\n\n function toggle() {\n clock.value = playShaderClock(clock.value, !clock.value.playing)\n }\n\n /** Shows the shader `time` seconds into its loop, playing on from there if it was playing. */\n function seek(time: number) {\n clock.value = seekShaderClock(clock.value, time)\n wake()\n }\n\n function restart() {\n seek(0)\n }\n\n const sizeKey = () => {\n const size = options.size()\n return size ? `${size.width}x${size.height}` : ''\n }\n // A preset changes at once, and so does the first size; a later size waits for a resize to\n // settle.\n watch(\n () => JSON.stringify(options.preset()),\n () => request(options.preset(), options.size()),\n { immediate: true }\n )\n watch(sizeKey, () => {\n if (!player && !starting) request(options.preset(), options.size())\n })\n watchDebounced(sizeKey, () => request(options.preset(), options.size()), {\n debounce: RESIZE_SETTLE_MS\n })\n watch(options.target, (canvas) => {\n if (!canvas) return\n stale = true\n wake()\n })\n\n if (supported) wake()\n\n onScopeDispose(() => {\n disposed = true\n loop.pause()\n retire(player)\n player = null\n if (!starting) release()\n })\n\n return {\n clock: readonly(clock),\n status: readonly(status),\n play,\n pause,\n toggle,\n seek,\n restart\n }\n}\n\n/**\n * Plays one shader large, in Shader Mode, on a clock the person controls: it plays, pauses, and\n * jumps to any time in its loop, and its frames are drawn into `target`, a 2D canvas on screen.\n * A preset or size change starts a new renderer beside the one showing, which keeps drawing\n * until the new one is ready and then hands over at the same time in the loop, so tuning a\n * setting neither flashes nor restarts the animation. A shader that fails to start is not\n * covered by the one before it: the status says so. Without WebGPU the status says so too and\n * nothing draws.\n */\nexport function useShaderStage(\n options: ShaderStageOptions<HTMLCanvasElement> & {\n /** What plays the shader: WebGPU through the `shaders` library unless a story hands its own. */\n backend?: ShaderStageBackend<HTMLCanvasElement>\n }\n) {\n return createShaderStage({ ...options, backend: options.backend ?? browserShaderStageBackend })\n}\n"],"mappings":";;;;;;AAiBA,MAAM,iBAAiB;;;;;AAKvB,MAAM,oBAAoB;;AAE1B,MAAM,mBAAmB;;;;;AAyDzB,SAAgB,iBAAiB,OAAa,MAAkB;CAC9D,MAAM,QAAQ,KAAK,IAAI,MAAM,OAAO,CAAC;CACrC,MAAM,SAAS,KAAK,IAAI,MAAM,QAAQ,CAAC;CACvC,MAAM,QAAQ,KAAK,IAAI,KAAK,QAAQ,OAAO,KAAK,SAAS,MAAM;CAC/D,MAAM,SAAS,OAAO,SAAS,KAAK,KAAK,QAAQ,IAAI,QAAQ;CAC7D,OAAO;EACL,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,QAAQ,MAAM,CAAC;EAC7C,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,MAAM,CAAC;CACjD;AACF;;AAGA,SAAS,SAAS,MAAkB;CAClC,MAAM,MAAM,KAAK,IAAI,GAAG,iBAAiB,KAAK,IAAI,KAAK,OAAO,KAAK,QAAQ,CAAC,CAAC;CAC7E,OAAO;EACL,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,QAAQ,GAAG,CAAC;EAC/C,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,SAAS,GAAG,CAAC;CACnD;AACF;;AAGA,eAAe,qBACb,QACA,MACwD;CACxD,MAAM,SAAS,SAAS,cAAc,QAAQ;CAE9C,OAAO,QA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UAAU,CAAC,UAAU,QAAQ,QAAQ,OAAO,GAAG,QAAQ,KAAK,CAAC;CACpE,CAAC;CACD,eAAe,eAAe,QAAQ,QAAQ,OAAO,GAAG,QAAQ,KAAK,CAAC,GAAG,EACvE,UAAU,iBACZ,CAAC;CACD,MAAM,QAAQ,SAAS,WAAW;EAChC,IAAI,CAAC,QAAQ;EACb,QAAQ;EACR,KAAK;CACP,CAAC;CAED,IAAI,WAAW,KAAK;CAEpB,qBAAqB;EACnB,WAAW;EACX,KAAK,MAAM;EACX,OAAO,MAAM;EACb,SAAS;EACT,IAAI,CAAC,UAAU,QAAQ;CACzB,CAAC;CAED,OAAO;EACL,OAAO,SAAS,KAAK;EACrB,QAAQ,SAAS,MAAM;EACvB;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;;;;AAWA,SAAgB,eACd,SAIA;CACA,OAAO,kBAAkB;EAAE,GAAG;EAAS,SAAS,QAAQ,WAAW;CAA0B,CAAC;AAChG"}
@@ -1,6 +1,8 @@
1
1
  import { PresentationColorSpace } from "./color-space.js";
2
+ import { RenderedPlayScene } from "@pairdraw/core/canvas";
2
3
  import { EditorState } from "@pairdraw/core";
3
4
  import { ViewportTransform } from "@pairdraw/core/geometry";
5
+ import { Vector } from "@pairdraw/scene-graph/primitives";
4
6
  //#region src/canvas/surface/types.d.ts
5
7
  /**
6
8
  * Options for {@link useCanvas}.
@@ -30,6 +32,16 @@ interface UseCanvasOptions {
30
32
  * shadows keep one pixel per unit at any zoom.
31
33
  */
32
34
  reducedEffects?: boolean;
35
+ /**
36
+ * Whether the person allows motion, which shader playback in a preview follows: without it a
37
+ * shader keeps its still frame. Defaults to true.
38
+ */
39
+ animations?: () => boolean;
40
+ /**
41
+ * Told once when a preview already plays the most shaders a page may. The app passes a warning
42
+ * in development builds, so a release stays quiet.
43
+ */
44
+ warnShaderLimit?: (message: string) => void;
33
45
  /**
34
46
  * Forces ruler visibility on or off for this canvas.
35
47
  *
@@ -69,6 +81,13 @@ interface UseCanvasOptions {
69
81
  * presentation shows only its slide. Null draws every layer of the page.
70
82
  */
71
83
  getSceneScope?: () => string | null;
84
+ /**
85
+ * The top-level frames a playing prototype changed, which this canvas draws from their play
86
+ * scenes instead of the document, by frame id. Null or absent draws the document.
87
+ */
88
+ getPlayScenes?: () => ReadonlyMap<string, RenderedPlayScene> | null;
89
+ /** How far a playing prototype scrolled each frame's content, by frame id. */
90
+ getPlayScroll?: () => ReadonlyMap<string, Vector> | null;
72
91
  /**
73
92
  * Called after each frame this canvas draws, with the pan and zoom it was drawn at. DOM laid
74
93
  * over the canvas, such as preview islands, follows these to stay in step with the drawing
@@ -79,6 +98,12 @@ interface UseCanvasOptions {
79
98
  * Receives this canvas surface's CSS viewport size after creation and resize.
80
99
  */
81
100
  onViewportResize?: (width: number, height: number) => void;
101
+ /**
102
+ * Receives how far this canvas moved in the browser viewport when it was resized, as when a
103
+ * panel beside it hides. Pan the view by as much the other way to keep the drawing still on
104
+ * screen. Not called by default; on a page that scrolls, a move measured here includes scroll.
105
+ */
106
+ onViewportMove?: (dx: number, dy: number) => void;
82
107
  /**
83
108
  * Runs when the browser takes this canvas's WebGL context away. A browser may never give a lost
84
109
  * context back, and drawing into the lost one leaves the canvas blank, so the host replaces the
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/canvas/surface/types.ts"],"mappings":";;;;;;;KAQY;UAEK;EACf;EACA,eAAe;IAAY;IAAuB;;;;;EAIlD,QAAQ;;;;EAIR;;;;;EAKA;;;;;EAKA;;;;;;EAMA;;;;;;;EAOA;;;;EAIA;;;;;EAKA,YAAY;;;;;EAKZ,kBAAkB,YAAY;;;;;;;EAO9B,uBAAuB;;;;;EAKvB;;;;;;EAMA,WAAW,MAAM;;;;EAIjB,oBAAoB,eAAe;;;;;;EAMnC;;;;;EAKA,qBAAqB,gBAAgB"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/canvas/surface/types.ts"],"mappings":";;;;;;;;;KAUY;UAEK;EACf;EACA,eAAe;IAAY;IAAuB;;;;;EAIlD,QAAQ;;;;EAIR;;;;;EAKA;;;;;EAKA;;;;;EAKA;;;;;EAKA,mBAAmB;;;;;;EAMnB;;;;;;;EAOA;;;;EAIA;;;;;EAKA,YAAY;;;;;EAKZ,kBAAkB,YAAY;;;;;;;EAO9B,uBAAuB;;;;;EAKvB;;;;;EAKA,sBAAsB,oBAAoB;;EAE1C,sBAAsB,oBAAoB;;;;;;EAM1C,WAAW,MAAM;;;;EAIjB,oBAAoB,eAAe;;;;;;EAMnC,kBAAkB,YAAY;;;;;;EAM9B;;;;;EAKA,qBAAqB,gBAAgB"}
@@ -47,7 +47,9 @@ function useCanvas(canvasRef, editor, options) {
47
47
  height: viewport.height.value
48
48
  }),
49
49
  markDirty: surface.markDirty,
50
- getPixelRatio: () => canvasPixelRatio(options?.maxPixelRatio)
50
+ getAnimations: options?.animations,
51
+ getPixelRatio: () => canvasPixelRatio(options?.maxPixelRatio),
52
+ warn: options?.warnShaderLimit
51
53
  });
52
54
  }
53
55
  const { hitTestSectionTitle, hitTestComponentLabel, hitTestFrameTitle, hitTestStatusLabel } = createCanvasHitTests(editor, surface.getRenderer);
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/canvas/surface/use.ts"],"sourcesContent":["import { useElementSize } from '@vueuse/core'\nimport type { CanvasKit } from 'canvaskit-wasm'\nimport type { Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\n\nimport { canvasPixelRatio } from '#vue/canvas/surface/gl-surface'\nimport {\n createCanvasSurfaceManager,\n useCanvasSurfaceLifecycle\n} from '#vue/canvas/surface/lifecycle'\nimport { createCanvasHitTests, createRulerVisibility } from '#vue/canvas/surface/overlays'\nimport { useShaderPlayback } from '#vue/canvas/surface/shader/playback'\nimport type { UseCanvasOptions } from '#vue/canvas/surface/types'\n\nexport type { UseCanvasOptions } from '#vue/canvas/surface/types'\n\n/**\n * Connects a Pairdraw editor to a real canvas element using CanvasKit.\n *\n * This composable owns renderer creation, surface recreation on resize,\n * render scheduling, and renderer-backed hit testing helpers used by higher-\n * level canvas interaction code.\n */\nexport function useCanvas(\n canvasRef: Ref<HTMLCanvasElement | null>,\n editor: Editor,\n options?: UseCanvasOptions\n) {\n let ck: CanvasKit | null = null\n const lifecycle: { destroyed: boolean } = { destroyed: false }\n const isDestroyed = () => lifecycle.destroyed\n const shouldShowRulers = createRulerVisibility(options)\n\n const surface = createCanvasSurfaceManager({\n editor,\n canvasRef,\n options,\n getCanvasKit: () => ck,\n isDestroyed,\n shouldShowRulers\n })\n\n useCanvasSurfaceLifecycle({\n canvasRef,\n surface,\n lifecycle,\n getCanvasKitValue: () => ck,\n setCanvasKit: (value) => {\n ck = value\n },\n onReady: options?.onReady,\n onFailed: options?.onFailed,\n onContextLost: options?.onContextLost\n })\n\n // The scene surface plays shaders in preview; an overlay surface draws none.\n if (options?.layer !== 'overlays') {\n // The view's size in CSS pixels, which the editor's pan and zoom map the page onto.\n const viewport = useElementSize(canvasRef)\n useShaderPlayback({\n editor,\n getRenderer: surface.getRenderer,\n getView: () => options?.getRenderState?.() ?? editor.state,\n getViewport: () => ({ width: viewport.width.value, height: viewport.height.value }),\n markDirty: surface.markDirty,\n getPixelRatio: () => canvasPixelRatio(options?.maxPixelRatio)\n })\n }\n\n const { hitTestSectionTitle, hitTestComponentLabel, hitTestFrameTitle, hitTestStatusLabel } =\n createCanvasHitTests(editor, surface.getRenderer)\n\n return {\n render: surface.markDirty,\n renderNow: surface.renderNow,\n getRenderer: surface.getRenderer,\n hitTestSectionTitle,\n hitTestComponentLabel,\n hitTestFrameTitle,\n hitTestStatusLabel\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,UACd,WACA,QACA,SACA;CACA,IAAI,KAAuB;CAC3B,MAAM,YAAoC,EAAE,WAAW,MAAM;CAC7D,MAAM,oBAAoB,UAAU;CACpC,MAAM,mBAAmB,sBAAsB,OAAO;CAEtD,MAAM,UAAU,2BAA2B;EACzC;EACA;EACA;EACA,oBAAoB;EACpB;EACA;CACF,CAAC;CAED,0BAA0B;EACxB;EACA;EACA;EACA,yBAAyB;EACzB,eAAe,UAAU;GACvB,KAAK;EACP;EACA,SAAS,SAAS;EAClB,UAAU,SAAS;EACnB,eAAe,SAAS;CAC1B,CAAC;CAGD,IAAI,SAAS,UAAU,YAAY;EAEjC,MAAM,WAAW,eAAe,SAAS;EACzC,kBAAkB;GAChB;GACA,aAAa,QAAQ;GACrB,eAAe,SAAS,iBAAiB,KAAK,OAAO;GACrD,oBAAoB;IAAE,OAAO,SAAS,MAAM;IAAO,QAAQ,SAAS,OAAO;GAAM;GACjF,WAAW,QAAQ;GACnB,qBAAqB,iBAAiB,SAAS,aAAa;EAC9D,CAAC;CACH;CAEA,MAAM,EAAE,qBAAqB,uBAAuB,mBAAmB,uBACrE,qBAAqB,QAAQ,QAAQ,WAAW;CAElD,OAAO;EACL,QAAQ,QAAQ;EAChB,WAAW,QAAQ;EACnB,aAAa,QAAQ;EACrB;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/canvas/surface/use.ts"],"sourcesContent":["import { useElementSize } from '@vueuse/core'\nimport type { CanvasKit } from 'canvaskit-wasm'\nimport type { Ref } from 'vue'\n\nimport type { Editor } from '@pairdraw/core'\n\nimport { canvasPixelRatio } from '#vue/canvas/surface/gl-surface'\nimport {\n createCanvasSurfaceManager,\n useCanvasSurfaceLifecycle\n} from '#vue/canvas/surface/lifecycle'\nimport { createCanvasHitTests, createRulerVisibility } from '#vue/canvas/surface/overlays'\nimport { useShaderPlayback } from '#vue/canvas/surface/shader/playback'\nimport type { UseCanvasOptions } from '#vue/canvas/surface/types'\n\nexport type { UseCanvasOptions } from '#vue/canvas/surface/types'\n\n/**\n * Connects a Pairdraw editor to a real canvas element using CanvasKit.\n *\n * This composable owns renderer creation, surface recreation on resize,\n * render scheduling, and renderer-backed hit testing helpers used by higher-\n * level canvas interaction code.\n */\nexport function useCanvas(\n canvasRef: Ref<HTMLCanvasElement | null>,\n editor: Editor,\n options?: UseCanvasOptions\n) {\n let ck: CanvasKit | null = null\n const lifecycle: { destroyed: boolean } = { destroyed: false }\n const isDestroyed = () => lifecycle.destroyed\n const shouldShowRulers = createRulerVisibility(options)\n\n const surface = createCanvasSurfaceManager({\n editor,\n canvasRef,\n options,\n getCanvasKit: () => ck,\n isDestroyed,\n shouldShowRulers\n })\n\n useCanvasSurfaceLifecycle({\n canvasRef,\n surface,\n lifecycle,\n getCanvasKitValue: () => ck,\n setCanvasKit: (value) => {\n ck = value\n },\n onReady: options?.onReady,\n onFailed: options?.onFailed,\n onContextLost: options?.onContextLost\n })\n\n // The scene surface plays shaders in preview; an overlay surface draws none.\n if (options?.layer !== 'overlays') {\n // The view's size in CSS pixels, which the editor's pan and zoom map the page onto.\n const viewport = useElementSize(canvasRef)\n useShaderPlayback({\n editor,\n getRenderer: surface.getRenderer,\n getView: () => options?.getRenderState?.() ?? editor.state,\n getViewport: () => ({ width: viewport.width.value, height: viewport.height.value }),\n markDirty: surface.markDirty,\n getAnimations: options?.animations,\n getPixelRatio: () => canvasPixelRatio(options?.maxPixelRatio),\n warn: options?.warnShaderLimit\n })\n }\n\n const { hitTestSectionTitle, hitTestComponentLabel, hitTestFrameTitle, hitTestStatusLabel } =\n createCanvasHitTests(editor, surface.getRenderer)\n\n return {\n render: surface.markDirty,\n renderNow: surface.renderNow,\n getRenderer: surface.getRenderer,\n hitTestSectionTitle,\n hitTestComponentLabel,\n hitTestFrameTitle,\n hitTestStatusLabel\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,UACd,WACA,QACA,SACA;CACA,IAAI,KAAuB;CAC3B,MAAM,YAAoC,EAAE,WAAW,MAAM;CAC7D,MAAM,oBAAoB,UAAU;CACpC,MAAM,mBAAmB,sBAAsB,OAAO;CAEtD,MAAM,UAAU,2BAA2B;EACzC;EACA;EACA;EACA,oBAAoB;EACpB;EACA;CACF,CAAC;CAED,0BAA0B;EACxB;EACA;EACA;EACA,yBAAyB;EACzB,eAAe,UAAU;GACvB,KAAK;EACP;EACA,SAAS,SAAS;EAClB,UAAU,SAAS;EACnB,eAAe,SAAS;CAC1B,CAAC;CAGD,IAAI,SAAS,UAAU,YAAY;EAEjC,MAAM,WAAW,eAAe,SAAS;EACzC,kBAAkB;GAChB;GACA,aAAa,QAAQ;GACrB,eAAe,SAAS,iBAAiB,KAAK,OAAO;GACrD,oBAAoB;IAAE,OAAO,SAAS,MAAM;IAAO,QAAQ,SAAS,OAAO;GAAM;GACjF,WAAW,QAAQ;GACnB,eAAe,SAAS;GACxB,qBAAqB,iBAAiB,SAAS,aAAa;GAC5D,MAAM,SAAS;EACjB,CAAC;CACH;CAEA,MAAM,EAAE,qBAAqB,uBAAuB,mBAAmB,uBACrE,qBAAqB,QAAQ,QAAQ,WAAW;CAElD,OAAO;EACL,QAAQ,QAAQ;EAChB,WAAW,QAAQ;EACnB,aAAa,QAAQ;EACrB;EACA;EACA;EACA;CACF;AACF"}
@@ -1,3 +1,4 @@
1
+ import { ShallowRef } from "vue";
1
2
  import { Editor } from "@pairdraw/core";
2
3
  //#region src/canvas/text-edit/textarea.d.ts
3
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"textarea.d.ts","names":[],"sources":["../../../src/canvas/text-edit/textarea.ts"],"mappings":";;;;;;;iBAYgB,kBAAkB,SAAS"}
1
+ {"version":3,"file":"textarea.d.ts","names":[],"sources":["../../../src/canvas/text-edit/textarea.ts"],"mappings":";;;;;;;;iBAYgB,kBAAkB,SAAS"}
@@ -3,6 +3,7 @@ import { HAND_GRAB_CURSOR } from "../../editor/tool-cursor/index.js";
3
3
  import { startPenInput, updatePenHover } from "../pen/input.js";
4
4
  import { attachModifiers, startConnectorDraw } from "../../shared/input/connector/draw.js";
5
5
  import { startShapeDraw, startTextDraw } from "../../shared/input/draw.js";
6
+ import { handleEyedropperDown } from "../eyedropper/index.js";
6
7
  import { onSelectionHandle, scaleHoverCursor, tryStartScaleDrag } from "../scale/input.js";
7
8
  import { startZoomDrag, zoomToolCursor } from "../zoom/input.js";
8
9
  import { startPanDrag } from "../../shared/input/pan/drag.js";
@@ -17,7 +18,7 @@ const pan = { press: ({ event }, { editor, setDrag, cursorOverride }) => {
17
18
  const shape = { press: ({ cx, cy }, { editor, setDrag }) => startShapeDraw(cx, cy, editor, setDrag) };
18
19
  /** Selects, moves, resizes, and turns layers: the Move tool. */
19
20
  const select = {
20
- press: ({ event, cx, cy, sx, sy }, context) => handleSelectDown(event, cx, cy, sx, sy, context.editor, context.hitFns, context.tryStartRotation, context.handleTextEditClick, context.setDrag),
21
+ press: ({ event, cx, cy, sx, sy }, context) => handleSelectDown(event, cx, cy, sx, sy, context.editor, context.hitFns, context.tryStartRotation, context.handleTextEditClick, context.setDrag, context.bigNudge()),
21
22
  hover: (pointer, { hoverLayers }) => hoverLayers(pointer)
22
23
  };
23
24
  /**
@@ -53,6 +54,9 @@ const CANVAS_TOOLS = {
53
54
  },
54
55
  HAND: pan,
55
56
  COMMENT: { press: () => void 0 },
57
+ EYEDROPPER: { press: ({ event, cx, cy }, { editor }) => {
58
+ if (event.button === 0) handleEyedropperDown(editor, cx, cy, event.altKey);
59
+ } },
56
60
  PEN: {
57
61
  press: ({ event, cx, cy }, { editor, setDrag, cursorOverride }) => startPenInput(event, cx, cy, editor, setDrag, cursorOverride),
58
62
  hover: ({ cx, cy }, { editor }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","names":[],"sources":["../../../src/canvas/tools/registry.ts"],"sourcesContent":["import type { Ref } from 'vue'\n\nimport type { Editor, Tool } from '@pairdraw/core'\n\nimport { startPenInput, updatePenHover } from '#vue/canvas/pen/input'\nimport { startPencilInput } from '#vue/canvas/pencil/input'\nimport { onSelectionHandle, scaleHoverCursor, tryStartScaleDrag } from '#vue/canvas/scale/input'\nimport { startZoomDrag, zoomToolCursor } from '#vue/canvas/zoom/input'\nimport { HAND_GRAB_CURSOR } from '#vue/editor/tool-cursor'\nimport { attachModifiers, startConnectorDraw } from '#vue/shared/input/connector/draw'\nimport { startShapeDraw, startTextDraw } from '#vue/shared/input/draw'\nimport { startPanDrag } from '#vue/shared/input/pan/drag'\nimport { handleSelectDown } from '#vue/shared/input/select'\nimport type { HitTestFns } from '#vue/shared/input/select'\nimport { startStickyDraw } from '#vue/shared/input/sticky/draw'\nimport type { DragState } from '#vue/shared/input/types'\n\n/** Where the pointer is, in canvas (`cx`, `cy`) and screen (`sx`, `sy`) coordinates. */\nexport interface CanvasToolPointer {\n event: MouseEvent\n cx: number\n cy: number\n sx: number\n sy: number\n}\n\n/** What a canvas tool works with: the editor and the canvas input's own pieces. */\nexport interface CanvasToolContext {\n editor: Editor\n hitFns: HitTestFns\n cursorOverride: Ref<string | null>\n setDrag: (d: DragState) => void\n tryStartRotation: (cx: number, cy: number) => boolean\n handleTextEditClick: (cx: number, cy: number, shiftKey: boolean) => boolean\n /** Shows what the pointer is over while selecting: the cursor, guides, and auto layout. */\n hoverLayers: (pointer: CanvasToolPointer) => void\n}\n\n/** What a tool does on the canvas: on a press, and while the pointer moves with no drag. */\nexport interface CanvasTool {\n press: (pointer: CanvasToolPointer, context: CanvasToolContext) => void\n hover?: (pointer: CanvasToolPointer, context: CanvasToolContext) => void\n}\n\nconst pan: CanvasTool = {\n press: ({ event }, { editor, setDrag, cursorOverride }) => {\n startPanDrag(event, setDrag, editor)\n cursorOverride.value = HAND_GRAB_CURSOR\n }\n}\n\n/** Draws the layer of the tool's own type, from the press to the release. */\nconst shape: CanvasTool = {\n press: ({ cx, cy }, { editor, setDrag }) => startShapeDraw(cx, cy, editor, setDrag)\n}\n\n/** Selects, moves, resizes, and turns layers: the Move tool. */\nconst select: CanvasTool = {\n press: ({ event, cx, cy, sx, sy }, context) =>\n handleSelectDown(\n event,\n cx,\n cy,\n sx,\n sy,\n context.editor,\n context.hitFns,\n context.tryStartRotation,\n context.handleTextEditClick,\n context.setDrag\n ),\n hover: (pointer, { hoverLayers }) => hoverLayers(pointer)\n}\n\n/**\n * Every tool's canvas behaviour, by id. A tool added to `Tool` needs an entry here, and the\n * editor's profile decides which tools are on offer.\n */\nexport const CANVAS_TOOLS: Readonly<Record<Tool, CanvasTool>> = {\n SELECT: select,\n // Handles scale the selection with its contents, and never resize it as Move's do; elsewhere a\n // press selects as Move does.\n SCALE: {\n press: (pointer, context) => {\n const drag = tryStartScaleDrag(pointer.cx, pointer.cy, context.editor)\n if (drag) {\n context.setDrag(drag)\n context.cursorOverride.value = drag.cursor\n } else if (!onSelectionHandle(pointer.cx, pointer.cy, context.editor)) {\n select.press(pointer, context)\n }\n },\n hover: (pointer, context) => {\n context.hoverLayers(pointer)\n const cursor = scaleHoverCursor(pointer.cx, pointer.cy, context.editor)\n if (cursor) context.cursorOverride.value = cursor\n else if (onSelectionHandle(pointer.cx, pointer.cy, context.editor)) {\n context.cursorOverride.value = null\n }\n }\n },\n ZOOM: {\n press: ({ event, cx, cy, sx, sy }, { editor, setDrag, cursorOverride }) => {\n if (event.button !== 0) return\n setDrag(startZoomDrag(cx, cy, sx, sy, event.altKey, editor))\n cursorOverride.value = zoomToolCursor(event.altKey)\n },\n hover: ({ event }, { cursorOverride }) => {\n cursorOverride.value = zoomToolCursor(event.altKey)\n }\n },\n HAND: pan,\n // Comments are placed by the app's comments layer above the canvas.\n COMMENT: { press: () => undefined },\n PEN: {\n press: ({ event, cx, cy }, { editor, setDrag, cursorOverride }) =>\n startPenInput(event, cx, cy, editor, setDrag, cursorOverride),\n hover: ({ cx, cy }, { editor }) => {\n updatePenHover(cx, cy, editor)\n }\n },\n PENCIL: { press: ({ cx, cy }, { editor, setDrag }) => startPencilInput(cx, cy, editor, setDrag) },\n TEXT: { press: ({ cx, cy }, { editor, setDrag }) => startTextDraw(cx, cy, editor, setDrag) },\n CONNECTOR: {\n press: ({ event, cx, cy, sx, sy }, { editor, setDrag }) =>\n startConnectorDraw(cx, cy, sx, sy, editor, setDrag, attachModifiers(event)),\n hover: ({ event, cx, cy }, { editor }) => editor.connectorHover(cx, cy, attachModifiers(event))\n },\n STICKY: { press: ({ cx, cy }, { editor, setDrag }) => startStickyDraw(cx, cy, editor, setDrag) },\n FRAME: shape,\n SECTION: shape,\n RECTANGLE: shape,\n ELLIPSE: shape,\n LINE: shape,\n POLYGON: shape,\n STAR: shape,\n SHAPE_WITH_TEXT: shape\n}\n"],"mappings":";;;;;;;;;;;AA4CA,MAAM,MAAkB,EACtB,QAAQ,EAAE,SAAS,EAAE,QAAQ,SAAS,qBAAqB;CACzD,aAAa,OAAO,SAAS,MAAM;CACnC,eAAe,QAAQ;AACzB,EACF;;AAGA,MAAM,QAAoB,EACxB,QAAQ,EAAE,IAAI,MAAM,EAAE,QAAQ,cAAc,eAAe,IAAI,IAAI,QAAQ,OAAO,EACpF;;AAGA,MAAM,SAAqB;CACzB,QAAQ,EAAE,OAAO,IAAI,IAAI,IAAI,MAAM,YACjC,iBACE,OACA,IACA,IACA,IACA,IACA,QAAQ,QACR,QAAQ,QACR,QAAQ,kBACR,QAAQ,qBACR,QAAQ,OACV;CACF,QAAQ,SAAS,EAAE,kBAAkB,YAAY,OAAO;AAC1D;;;;;AAMA,MAAa,eAAmD;CAC9D,QAAQ;CAGR,OAAO;EACL,QAAQ,SAAS,YAAY;GAC3B,MAAM,OAAO,kBAAkB,QAAQ,IAAI,QAAQ,IAAI,QAAQ,MAAM;GACrE,IAAI,MAAM;IACR,QAAQ,QAAQ,IAAI;IACpB,QAAQ,eAAe,QAAQ,KAAK;GACtC,OAAO,IAAI,CAAC,kBAAkB,QAAQ,IAAI,QAAQ,IAAI,QAAQ,MAAM,GAClE,OAAO,MAAM,SAAS,OAAO;EAEjC;EACA,QAAQ,SAAS,YAAY;GAC3B,QAAQ,YAAY,OAAO;GAC3B,MAAM,SAAS,iBAAiB,QAAQ,IAAI,QAAQ,IAAI,QAAQ,MAAM;GACtE,IAAI,QAAQ,QAAQ,eAAe,QAAQ;QACtC,IAAI,kBAAkB,QAAQ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;CACX,SAAS;CACT,MAAM;CACN,SAAS;CACT,MAAM;CACN,iBAAiB;AACnB"}
1
+ {"version":3,"file":"registry.js","names":[],"sources":["../../../src/canvas/tools/registry.ts"],"sourcesContent":["import type { Ref } from 'vue'\n\nimport type { Editor, Tool } from '@pairdraw/core'\n\nimport { handleEyedropperDown } from '#vue/canvas/eyedropper'\nimport { startPenInput, updatePenHover } from '#vue/canvas/pen/input'\nimport { startPencilInput } from '#vue/canvas/pencil/input'\nimport { onSelectionHandle, scaleHoverCursor, tryStartScaleDrag } from '#vue/canvas/scale/input'\nimport { startZoomDrag, zoomToolCursor } from '#vue/canvas/zoom/input'\nimport { HAND_GRAB_CURSOR } from '#vue/editor/tool-cursor'\nimport { attachModifiers, startConnectorDraw } from '#vue/shared/input/connector/draw'\nimport { startShapeDraw, startTextDraw } from '#vue/shared/input/draw'\nimport { startPanDrag } from '#vue/shared/input/pan/drag'\nimport { handleSelectDown } from '#vue/shared/input/select'\nimport type { HitTestFns } from '#vue/shared/input/select'\nimport { startStickyDraw } from '#vue/shared/input/sticky/draw'\nimport type { DragState } from '#vue/shared/input/types'\n\n/** Where the pointer is, in canvas (`cx`, `cy`) and screen (`sx`, `sy`) coordinates. */\nexport interface CanvasToolPointer {\n event: MouseEvent\n cx: number\n cy: number\n sx: number\n sy: number\n}\n\n/** What a canvas tool works with: the editor and the canvas input's own pieces. */\nexport interface CanvasToolContext {\n editor: Editor\n hitFns: HitTestFns\n cursorOverride: Ref<string | null>\n setDrag: (d: DragState) => void\n tryStartRotation: (cx: number, cy: number) => boolean\n handleTextEditClick: (cx: number, cy: number, shiftKey: boolean) => boolean\n /** Settings → Editor's large nudge, in pixels. */\n bigNudge: () => number\n /** Shows what the pointer is over while selecting: the cursor, guides, and auto layout. */\n hoverLayers: (pointer: CanvasToolPointer) => void\n}\n\n/** What a tool does on the canvas: on a press, and while the pointer moves with no drag. */\nexport interface CanvasTool {\n press: (pointer: CanvasToolPointer, context: CanvasToolContext) => void\n hover?: (pointer: CanvasToolPointer, context: CanvasToolContext) => void\n}\n\nconst pan: CanvasTool = {\n press: ({ event }, { editor, setDrag, cursorOverride }) => {\n startPanDrag(event, setDrag, editor)\n cursorOverride.value = HAND_GRAB_CURSOR\n }\n}\n\n/** Draws the layer of the tool's own type, from the press to the release. */\nconst shape: CanvasTool = {\n press: ({ cx, cy }, { editor, setDrag }) => startShapeDraw(cx, cy, editor, setDrag)\n}\n\n/** Selects, moves, resizes, and turns layers: the Move tool. */\nconst select: CanvasTool = {\n press: ({ event, cx, cy, sx, sy }, context) =>\n handleSelectDown(\n event,\n cx,\n cy,\n sx,\n sy,\n context.editor,\n context.hitFns,\n context.tryStartRotation,\n context.handleTextEditClick,\n context.setDrag,\n context.bigNudge()\n ),\n hover: (pointer, { hoverLayers }) => hoverLayers(pointer)\n}\n\n/**\n * Every tool's canvas behaviour, by id. A tool added to `Tool` needs an entry here, and the\n * editor's profile decides which tools are on offer.\n */\nexport const CANVAS_TOOLS: Readonly<Record<Tool, CanvasTool>> = {\n SELECT: select,\n // Handles scale the selection with its contents, and never resize it as Move's do; elsewhere a\n // press selects as Move does.\n SCALE: {\n press: (pointer, context) => {\n const drag = tryStartScaleDrag(pointer.cx, pointer.cy, context.editor)\n if (drag) {\n context.setDrag(drag)\n context.cursorOverride.value = drag.cursor\n } else if (!onSelectionHandle(pointer.cx, pointer.cy, context.editor)) {\n select.press(pointer, context)\n }\n },\n hover: (pointer, context) => {\n context.hoverLayers(pointer)\n const cursor = scaleHoverCursor(pointer.cx, pointer.cy, context.editor)\n if (cursor) context.cursorOverride.value = cursor\n else if (onSelectionHandle(pointer.cx, pointer.cy, context.editor)) {\n context.cursorOverride.value = null\n }\n }\n },\n ZOOM: {\n press: ({ event, cx, cy, sx, sy }, { editor, setDrag, cursorOverride }) => {\n if (event.button !== 0) return\n setDrag(startZoomDrag(cx, cy, sx, sy, event.altKey, editor))\n cursorOverride.value = zoomToolCursor(event.altKey)\n },\n hover: ({ event }, { cursorOverride }) => {\n cursorOverride.value = zoomToolCursor(event.altKey)\n }\n },\n HAND: pan,\n // Comments are placed by the app's comments layer above the canvas.\n COMMENT: { press: () => undefined },\n EYEDROPPER: {\n press: ({ event, cx, cy }, { editor }) => {\n if (event.button === 0) handleEyedropperDown(editor, cx, cy, event.altKey)\n }\n },\n PEN: {\n press: ({ event, cx, cy }, { editor, setDrag, cursorOverride }) =>\n startPenInput(event, cx, cy, editor, setDrag, cursorOverride),\n hover: ({ cx, cy }, { editor }) => {\n updatePenHover(cx, cy, editor)\n }\n },\n PENCIL: { press: ({ cx, cy }, { editor, setDrag }) => startPencilInput(cx, cy, editor, setDrag) },\n TEXT: { press: ({ cx, cy }, { editor, setDrag }) => startTextDraw(cx, cy, editor, setDrag) },\n CONNECTOR: {\n press: ({ event, cx, cy, sx, sy }, { editor, setDrag }) =>\n startConnectorDraw(cx, cy, sx, sy, editor, setDrag, attachModifiers(event)),\n hover: ({ event, cx, cy }, { editor }) => editor.connectorHover(cx, cy, attachModifiers(event))\n },\n STICKY: { press: ({ cx, cy }, { editor, setDrag }) => startStickyDraw(cx, cy, editor, setDrag) },\n FRAME: shape,\n SECTION: shape,\n RECTANGLE: shape,\n ELLIPSE: shape,\n LINE: shape,\n POLYGON: shape,\n STAR: shape,\n SHAPE_WITH_TEXT: shape\n}\n"],"mappings":";;;;;;;;;;;;AA+CA,MAAM,MAAkB,EACtB,QAAQ,EAAE,SAAS,EAAE,QAAQ,SAAS,qBAAqB;CACzD,aAAa,OAAO,SAAS,MAAM;CACnC,eAAe,QAAQ;AACzB,EACF;;AAGA,MAAM,QAAoB,EACxB,QAAQ,EAAE,IAAI,MAAM,EAAE,QAAQ,cAAc,eAAe,IAAI,IAAI,QAAQ,OAAO,EACpF;;AAGA,MAAM,SAAqB;CACzB,QAAQ,EAAE,OAAO,IAAI,IAAI,IAAI,MAAM,YACjC,iBACE,OACA,IACA,IACA,IACA,IACA,QAAQ,QACR,QAAQ,QACR,QAAQ,kBACR,QAAQ,qBACR,Q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,SAAS,qBAC5C,cAAc,OAAO,IAAI,IAAI,QAAQ,SAAS,cAAc;EAC9D,QAAQ,EAAE,IAAI,MAAM,EAAE,aAAa;GACjC,eAAe,IAAI,IAAI,MAAM;EAC/B;CACF;CACA,QAAQ,EAAE,QAAQ,EAAE,IAAI,MAAM,EAAE,QAAQ,cAAc,iBAAiB,IAAI,IAAI,QAAQ,OAAO,EAAE;CAChG,MAAM,EAAE,QAAQ,EAAE,IAAI,MAAM,EAAE,QAAQ,cAAc,cAAc,IAAI,IAAI,QAAQ,OAAO,EAAE;CAC3F,WAAW;EACT,QAAQ,EAAE,OAAO,IAAI,IAAI,IAAI,MAAM,EAAE,QAAQ,cAC3C,mBAAmB,IAAI,IAAI,IAAI,IAAI,QAAQ,SAAS,gBAAgB,KAAK,CAAC;EAC5E,QAAQ,EAAE,OAAO,IAAI,MAAM,EAAE,aAAa,OAAO,eAAe,IAAI,IAAI,gBAAgB,KAAK,CAAC;CAChG;CACA,QAAQ,EAAE,QAAQ,EAAE,IAAI,MAAM,EAAE,QAAQ,cAAc,gBAAgB,IAAI,IAAI,QAAQ,OAAO,EAAE;CAC/F,OAAO;CACP,SAAS;CACT,WAAW;CACX,SAAS;CACT,MAAM;CACN,SAAS;CACT,MAAM;CACN,iBAAiB;AACnB"}
@@ -1,5 +1,5 @@
1
1
  import { CanvasLabelEdit } from "./labels/edit.js";
2
- import { AutoLayoutValueField } from "../shared/input/auto-layout-hover.js";
2
+ import { AutoLayoutValueField } from "../shared/input/auto-layout/hover.js";
3
3
  import { DragState } from "../shared/input/types.js";
4
4
  import { WheelZoomOptions } from "../shared/input/wheel.js";
5
5
  import { Ref } from "vue";
@@ -10,8 +10,15 @@ declare function useCanvasInput(canvasRef: Ref<HTMLCanvasElement | null>, editor
10
10
  /** How far wheel and pinch zoom move per event; 1 is the default rate. */
11
11
  zoomSpeed?: () => number,
12
12
  /** Whether a plain wheel zooms and whether a wheel zoom is inverted. */
13
- zoomOptions?: () => WheelZoomOptions): {
13
+ zoomOptions?: () => WheelZoomOptions,
14
+ /** Settings → Editor's large nudge, in pixels, for handle drags with Shift. */
15
+ bigNudge?: () => number): {
14
16
  drag: Ref<{
17
+ type: "auto-layout";
18
+ update: (screenX: number, screenY: number, altKey: boolean, shiftKey: boolean) => void;
19
+ commit: () => void;
20
+ cancel: () => void;
21
+ } | {
15
22
  type: "shape-handle";
16
23
  update: (screenX: number, screenY: number, shiftKey: boolean) => void;
17
24
  commit: () => void;
@@ -1270,6 +1277,23 @@ zoomOptions?: () => WheelZoomOptions): {
1270
1277
  derivedSymbolDataLayoutVersion: number | null;
1271
1278
  uniformScaleFactor: number | null;
1272
1279
  };
1280
+ drawio?: {
1281
+ styleNames: string[];
1282
+ styleValues: Partial<Record<string, string>>;
1283
+ labelX: number;
1284
+ points: {
1285
+ x: number;
1286
+ y: number;
1287
+ }[];
1288
+ sourcePoint: {
1289
+ x: number;
1290
+ y: number;
1291
+ } | null;
1292
+ targetPoint: {
1293
+ x: number;
1294
+ y: number;
1295
+ } | null;
1296
+ } | null | undefined;
1273
1297
  };
1274
1298
  derivedLayout: {
1275
1299
  x?: number | undefined;
@@ -1466,6 +1490,51 @@ zoomOptions?: () => WheelZoomOptions): {
1466
1490
  uniformBindings?: Record<string, string> | undefined;
1467
1491
  visible: boolean;
1468
1492
  blendMode?: import("@pairdraw/scene-graph").BlendMode | undefined;
1493
+ } | {
1494
+ type: "NOISE";
1495
+ color: {
1496
+ r: number;
1497
+ g: number;
1498
+ b: number;
1499
+ a: number;
1500
+ };
1501
+ visible: boolean;
1502
+ blendMode?: import("@pairdraw/scene-graph").BlendMode | undefined;
1503
+ noise: {
1504
+ noiseType: import("@pairdraw/scene-graph").NoiseType;
1505
+ noiseSize: {
1506
+ x: number;
1507
+ y: number;
1508
+ };
1509
+ density: number;
1510
+ secondaryColor?: {
1511
+ r: number;
1512
+ g: number;
1513
+ b: number;
1514
+ a: number;
1515
+ } | undefined;
1516
+ opacity?: number | undefined;
1517
+ seed?: number | undefined;
1518
+ };
1519
+ } | {
1520
+ type: "TEXTURE";
1521
+ color: {
1522
+ r: number;
1523
+ g: number;
1524
+ b: number;
1525
+ a: number;
1526
+ };
1527
+ radius: number;
1528
+ visible: boolean;
1529
+ blendMode?: import("@pairdraw/scene-graph").BlendMode | undefined;
1530
+ texture: {
1531
+ noiseSize: {
1532
+ x: number;
1533
+ y: number;
1534
+ };
1535
+ clipToShape: boolean;
1536
+ seed?: number | undefined;
1537
+ };
1469
1538
  })[];
1470
1539
  layoutGrids: {
1471
1540
  visible?: boolean | undefined;
@@ -1511,6 +1580,8 @@ zoomOptions?: () => WheelZoomOptions): {
1511
1580
  visible: boolean;
1512
1581
  locked: boolean;
1513
1582
  clipsContent: boolean;
1583
+ overflowDirection: import("@pairdraw/scene-graph").OverflowDirection;
1584
+ scrollBehavior: import("@pairdraw/scene-graph").ScrollBehavior;
1514
1585
  blendMode: import("@pairdraw/scene-graph").BlendMode;
1515
1586
  text: string;
1516
1587
  fontSize: number;
@@ -2384,6 +2455,7 @@ zoomOptions?: () => WheelZoomOptions): {
2384
2455
  transition: {
2385
2456
  type: import("@pairdraw/scene-graph").PrototypeTransitionType;
2386
2457
  duration: number;
2458
+ easing?: import("@pairdraw/scene-graph").PrototypeEasingType | undefined;
2387
2459
  };
2388
2460
  overlayPosition: import("@pairdraw/scene-graph").PrototypeOverlayPositionType;
2389
2461
  } | {
@@ -2765,6 +2837,11 @@ zoomOptions?: () => WheelZoomOptions): {
2765
2837
  originalOwnerId?: string | undefined;
2766
2838
  originalPosition?: number | undefined;
2767
2839
  } | null, DragState | {
2840
+ type: "auto-layout";
2841
+ update: (screenX: number, screenY: number, altKey: boolean, shiftKey: boolean) => void;
2842
+ commit: () => void;
2843
+ cancel: () => void;
2844
+ } | {
2768
2845
  type: "shape-handle";
2769
2846
  update: (screenX: number, screenY: number, shiftKey: boolean) => void;
2770
2847
  commit: () => void;
@@ -4023,6 +4100,23 @@ zoomOptions?: () => WheelZoomOptions): {
4023
4100
  derivedSymbolDataLayoutVersion: number | null;
4024
4101
  uniformScaleFactor: number | null;
4025
4102
  };
4103
+ drawio?: {
4104
+ styleNames: string[];
4105
+ styleValues: Partial<Record<string, string>>;
4106
+ labelX: number;
4107
+ points: {
4108
+ x: number;
4109
+ y: number;
4110
+ }[];
4111
+ sourcePoint: {
4112
+ x: number;
4113
+ y: number;
4114
+ } | null;
4115
+ targetPoint: {
4116
+ x: number;
4117
+ y: number;
4118
+ } | null;
4119
+ } | null | undefined;
4026
4120
  };
4027
4121
  derivedLayout: {
4028
4122
  x?: number | undefined;
@@ -4219,6 +4313,51 @@ zoomOptions?: () => WheelZoomOptions): {
4219
4313
  uniformBindings?: Record<string, string> | undefined;
4220
4314
  visible: boolean;
4221
4315
  blendMode?: import("@pairdraw/scene-graph").BlendMode | undefined;
4316
+ } | {
4317
+ type: "NOISE";
4318
+ color: {
4319
+ r: number;
4320
+ g: number;
4321
+ b: number;
4322
+ a: number;
4323
+ };
4324
+ visible: boolean;
4325
+ blendMode?: import("@pairdraw/scene-graph").BlendMode | undefined;
4326
+ noise: {
4327
+ noiseType: import("@pairdraw/scene-graph").NoiseType;
4328
+ noiseSize: {
4329
+ x: number;
4330
+ y: number;
4331
+ };
4332
+ density: number;
4333
+ secondaryColor?: {
4334
+ r: number;
4335
+ g: number;
4336
+ b: number;
4337
+ a: number;
4338
+ } | undefined;
4339
+ opacity?: number | undefined;
4340
+ seed?: number | undefined;
4341
+ };
4342
+ } | {
4343
+ type: "TEXTURE";
4344
+ color: {
4345
+ r: number;
4346
+ g: number;
4347
+ b: number;
4348
+ a: number;
4349
+ };
4350
+ radius: number;
4351
+ visible: boolean;
4352
+ blendMode?: import("@pairdraw/scene-graph").BlendMode | undefined;
4353
+ texture: {
4354
+ noiseSize: {
4355
+ x: number;
4356
+ y: number;
4357
+ };
4358
+ clipToShape: boolean;
4359
+ seed?: number | undefined;
4360
+ };
4222
4361
  })[];
4223
4362
  layoutGrids: {
4224
4363
  visible?: boolean | undefined;
@@ -4264,6 +4403,8 @@ zoomOptions?: () => WheelZoomOptions): {
4264
4403
  visible: boolean;
4265
4404
  locked: boolean;
4266
4405
  clipsContent: boolean;
4406
+ overflowDirection: import("@pairdraw/scene-graph").OverflowDirection;
4407
+ scrollBehavior: import("@pairdraw/scene-graph").ScrollBehavior;
4267
4408
  blendMode: import("@pairdraw/scene-graph").BlendMode;
4268
4409
  text: string;
4269
4410
  fontSize: number;
@@ -5137,6 +5278,7 @@ zoomOptions?: () => WheelZoomOptions): {
5137
5278
  transition: {
5138
5279
  type: import("@pairdraw/scene-graph").PrototypeTransitionType;
5139
5280
  duration: number;
5281
+ easing?: import("@pairdraw/scene-graph").PrototypeEasingType | undefined;
5140
5282
  };
5141
5283
  overlayPosition: import("@pairdraw/scene-graph").PrototypeOverlayPositionType;
5142
5284
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"useCanvasInput.d.ts","names":[],"sources":["../../src/canvas/useCanvasInput.ts"],"mappings":";;;;;;;;iBAwDgB,eACd,WAAW,IAAI,2BACf,QAAQ,QACR,sBAAsB,YAAY,eAAe,kBACjD,wBAAwB,YAAY,eAAe,kBACnD,oBAAoB,YAAY,eAAe,kBAC/C,gBAAgB,YAAY,qBAC5B,yBACA,2BAEA;;AAAA,0BAEA;;AAAA,oBAAmB"}
1
+ {"version":3,"file":"useCanvasInput.d.ts","names":[],"sources":["../../src/canvas/useCanvasInput.ts"],"mappings":";;;;;;;;iBAwDgB,eACd,WAAW,IAAI,2BACf,QAAQ,QACR,sBAAsB,YAAY,eAAe,kBACjD,wBAAwB,YAAY,eAAe,kBACnD,oBAAoB,YAAY,eAAe,kBAC/C,gBAAgB,YAAY,qBAC5B,yBACA,2BAEA;;AAAA,0BAEA;;AAAA,oBAAmB,kBAEnB;;AAAA"}
@@ -1,4 +1,4 @@
1
- import { resolveAutoLayoutHover } from "../shared/input/auto-layout-hover.js";
1
+ import { resolveAutoLayoutHover } from "../shared/input/auto-layout/hover.js";
2
2
  import { createAutoLayoutValueEdit } from "./auto-layout/value-edit.js";
3
3
  import { createGuideInput } from "./guides/input.js";
4
4
  import { createCanvasLabelEdit } from "./labels/edit.js";
@@ -44,7 +44,7 @@ const ESCAPABLE_DRAGS = /* @__PURE__ */ new Set([
44
44
  "zoom",
45
45
  "scale"
46
46
  ]);
47
- function useCanvasInput(canvasRef, editor, hitTestSectionTitle, hitTestComponentLabel, hitTestFrameTitle, onCursorMove, onActivate, isEnabled = () => true, zoomSpeed = () => 1, zoomOptions = () => DEFAULT_WHEEL_ZOOM_OPTIONS) {
47
+ function useCanvasInput(canvasRef, editor, hitTestSectionTitle, hitTestComponentLabel, hitTestFrameTitle, onCursorMove, onActivate, isEnabled = () => true, zoomSpeed = () => 1, zoomOptions = () => DEFAULT_WHEEL_ZOOM_OPTIONS, bigNudge = () => 10) {
48
48
  const drag = ref(null);
49
49
  const profile = () => resolveEditorProfile(editor.state);
50
50
  watch(() => drag.value?.type, (type) => editor.setTransforming(type === "move" || type === "resize" || type === "rotate"));
@@ -155,6 +155,7 @@ function useCanvasInput(canvasRef, editor, hitTestSectionTitle, hitTestComponent
155
155
  setDrag,
156
156
  tryStartRotation,
157
157
  handleTextEditClick,
158
+ bigNudge,
158
159
  hoverLayers
159
160
  };
160
161
  function onMouseDown(e) {