@snowcone-app/canvas 0.1.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 (370) hide show
  1. package/LICENSE.txt +70 -0
  2. package/README.md +357 -0
  3. package/dist/CanvasStateV1-D5GzvmnY.cjs +65 -0
  4. package/dist/CanvasStateV1-D5GzvmnY.cjs.map +1 -0
  5. package/dist/CanvasStateV1-ejb4d_LM.js +3692 -0
  6. package/dist/CanvasStateV1-ejb4d_LM.js.map +1 -0
  7. package/dist/ElementFactory-B7UOaJSD.cjs +23865 -0
  8. package/dist/ElementFactory-B7UOaJSD.cjs.map +1 -0
  9. package/dist/ElementFactory-uJTXU-nP.js +29615 -0
  10. package/dist/ElementFactory-uJTXU-nP.js.map +1 -0
  11. package/dist/HybridHistoryManager-BV6XV0nD.js +8048 -0
  12. package/dist/HybridHistoryManager-BV6XV0nD.js.map +1 -0
  13. package/dist/HybridHistoryManager-BXD93pp8.cjs +8 -0
  14. package/dist/HybridHistoryManager-BXD93pp8.cjs.map +1 -0
  15. package/dist/ImportManager-BYwuK6n4.cjs +2 -0
  16. package/dist/ImportManager-BYwuK6n4.cjs.map +1 -0
  17. package/dist/ImportManager-CxiaRg1N.js +222 -0
  18. package/dist/ImportManager-CxiaRg1N.js.map +1 -0
  19. package/dist/ThemeContext-4mJ_y0Me.cjs +2 -0
  20. package/dist/ThemeContext-4mJ_y0Me.cjs.map +1 -0
  21. package/dist/ThemeContext-H0Z-MqqR.js +1077 -0
  22. package/dist/ThemeContext-H0Z-MqqR.js.map +1 -0
  23. package/dist/advanced.d.ts +2 -0
  24. package/dist/advanced.js +48 -0
  25. package/dist/advanced.js.map +1 -0
  26. package/dist/advanced.mjs +15679 -0
  27. package/dist/advanced.mjs.map +1 -0
  28. package/dist/api/advanced.d.ts +110 -0
  29. package/dist/api/internals.d.ts +39 -0
  30. package/dist/api/stable.d.ts +44 -0
  31. package/dist/api/testing.d.ts +25 -0
  32. package/dist/browser-module-D0gHY9rY.cjs +9 -0
  33. package/dist/browser-module-D0gHY9rY.cjs.map +1 -0
  34. package/dist/browser-module-DFvKXBUE.js +15474 -0
  35. package/dist/browser-module-DFvKXBUE.js.map +1 -0
  36. package/dist/components/ArtboardDistressPanel.d.ts +7 -0
  37. package/dist/components/ArtboardImageMaskPanel.d.ts +7 -0
  38. package/dist/components/ArtboardPropertiesToolbar.d.ts +19 -0
  39. package/dist/components/ArtboardToolbar.d.ts +10 -0
  40. package/dist/components/BackButton.d.ts +7 -0
  41. package/dist/components/BackgroundPickerDropdown.d.ts +11 -0
  42. package/dist/components/BackgroundSwitcher.d.ts +7 -0
  43. package/dist/components/CanvasA11yFallback.d.ts +62 -0
  44. package/dist/components/CanvasEditor/CanvasRendererComponent.d.ts +51 -0
  45. package/dist/components/CanvasEditor/handlers/cropModeHandlers.d.ts +114 -0
  46. package/dist/components/CanvasEditor/handlers/groupChildHandlers.d.ts +65 -0
  47. package/dist/components/CanvasEditor/handlers/index.d.ts +10 -0
  48. package/dist/components/CanvasEditor/handlers/multiSelectionHandlers.d.ts +86 -0
  49. package/dist/components/CanvasEditor/hooks/buildSpreadClipShape.d.ts +20 -0
  50. package/dist/components/CanvasEditor/hooks/index.d.ts +24 -0
  51. package/dist/components/CanvasEditor/hooks/useActiveChild.d.ts +23 -0
  52. package/dist/components/CanvasEditor/hooks/useAnimatedFocusRect.d.ts +17 -0
  53. package/dist/components/CanvasEditor/hooks/useCanvasInteraction.d.ts +284 -0
  54. package/dist/components/CanvasEditor/hooks/useCanvasLayout.d.ts +50 -0
  55. package/dist/components/CanvasEditor/hooks/useCanvasRenderLoop.d.ts +140 -0
  56. package/dist/components/CanvasEditor/hooks/useCropMode.d.ts +4 -0
  57. package/dist/components/CanvasEditor/hooks/useHoverState.d.ts +9 -0
  58. package/dist/components/CanvasEditor/hooks/useInteractionState.d.ts +23 -0
  59. package/dist/components/CanvasEditor/hooks/useKeyboardHandlers.d.ts +16 -0
  60. package/dist/components/CanvasEditor/hooks/useMarqueeSelection.d.ts +22 -0
  61. package/dist/components/CanvasEditor/hooks/useMultiSelection.d.ts +5 -0
  62. package/dist/components/CanvasEditor/hooks/usePenTool.d.ts +10 -0
  63. package/dist/components/CanvasEditor/hooks/useRenderState.d.ts +31 -0
  64. package/dist/components/CanvasEditor/hooks/useSnapAndSpacing.d.ts +42 -0
  65. package/dist/components/CanvasEditor/hooks/useTextEditing.d.ts +56 -0
  66. package/dist/components/CanvasEditor/hooks/useTextEditingHandlers.d.ts +75 -0
  67. package/dist/components/CanvasEditor/renderers/hoverRenderer.d.ts +12 -0
  68. package/dist/components/CanvasEditor/renderers/index.d.ts +10 -0
  69. package/dist/components/CanvasEditor/renderers/marqueeRenderer.d.ts +21 -0
  70. package/dist/components/CanvasEditor/renderers/multiSelectionRenderer.d.ts +52 -0
  71. package/dist/components/CanvasEditor/renderers/renderingConstants.d.ts +59 -0
  72. package/dist/components/CanvasEditor/types/index.d.ts +11 -0
  73. package/dist/components/CanvasEditor.d.ts +102 -0
  74. package/dist/components/ColorPickerDropdown.d.ts +29 -0
  75. package/dist/components/CompositingPanel.d.ts +8 -0
  76. package/dist/components/ContextualToolbars.d.ts +150 -0
  77. package/dist/components/CropPanel.d.ts +20 -0
  78. package/dist/components/DistressPanel.d.ts +7 -0
  79. package/dist/components/DocsPage.d.ts +6 -0
  80. package/dist/components/Drawer.d.ts +39 -0
  81. package/dist/components/EffectsPanel.d.ts +14 -0
  82. package/dist/components/ExportTestPanel.d.ts +16 -0
  83. package/dist/components/FontBrowserDrawer.d.ts +20 -0
  84. package/dist/components/FontSizeDropdown.d.ts +12 -0
  85. package/dist/components/GlyphBrowserDrawer.d.ts +13 -0
  86. package/dist/components/GlyphPicker.d.ts +14 -0
  87. package/dist/components/IconMatchTest.d.ts +3 -0
  88. package/dist/components/IconSizeTest.d.ts +3 -0
  89. package/dist/components/ImageBrowserDrawer.d.ts +27 -0
  90. package/dist/components/ImageToolbar.d.ts +47 -0
  91. package/dist/components/LayerEffects.d.ts +11 -0
  92. package/dist/components/LayerLeadingChip.d.ts +9 -0
  93. package/dist/components/LayersPanel.d.ts +30 -0
  94. package/dist/components/MaskItem.d.ts +12 -0
  95. package/dist/components/MasksPanel.d.ts +7 -0
  96. package/dist/components/MonotypeDemoPage.d.ts +2 -0
  97. package/dist/components/MoreMenu.d.ts +15 -0
  98. package/dist/components/OpenTypeFeaturesPanel.d.ts +12 -0
  99. package/dist/components/PathToolbar.d.ts +10 -0
  100. package/dist/components/PenToolDemo.d.ts +3 -0
  101. package/dist/components/ProgressiveBlur.d.ts +25 -0
  102. package/dist/components/RotationHandle.d.ts +47 -0
  103. package/dist/components/SaveLoadMenu.d.ts +15 -0
  104. package/dist/components/ShapeToolbar.d.ts +71 -0
  105. package/dist/components/ShapeTypeDrawer.d.ts +10 -0
  106. package/dist/components/StrokePanel.d.ts +7 -0
  107. package/dist/components/TailwindDemo.d.ts +3 -0
  108. package/dist/components/TextEffectsDropdown.d.ts +14 -0
  109. package/dist/components/TextToolbar.d.ts +47 -0
  110. package/dist/components/TextTypeDrawer.d.ts +8 -0
  111. package/dist/components/ThemeToggle.d.ts +2 -0
  112. package/dist/components/TransformControlPanel.d.ts +12 -0
  113. package/dist/components/VisualGuideOverlay.d.ts +156 -0
  114. package/dist/components/embed/ArtboardTabs.d.ts +74 -0
  115. package/dist/components/embed/Canvas.d.ts +72 -0
  116. package/dist/components/embed/EffectsPanel.d.ts +76 -0
  117. package/dist/components/embed/ErrorBoundary.d.ts +34 -0
  118. package/dist/components/embed/ExportPanel.d.ts +51 -0
  119. package/dist/components/embed/GlyphPanel.d.ts +70 -0
  120. package/dist/components/embed/ImagePanel.d.ts +58 -0
  121. package/dist/components/embed/LayersPanel.d.ts +13 -0
  122. package/dist/components/embed/LoadingStates.d.ts +32 -0
  123. package/dist/components/embed/MenuButton.d.ts +47 -0
  124. package/dist/components/embed/SnowconeCanvas.d.ts +844 -0
  125. package/dist/components/embed/ZoomControls.d.ts +16 -0
  126. package/dist/components/embed/index.d.ts +129 -0
  127. package/dist/components/embed/primitives/index.d.ts +42 -0
  128. package/dist/components/embed/ui/index.d.ts +52 -0
  129. package/dist/components/embed/utils/index.d.ts +31 -0
  130. package/dist/components/embedded/ArtboardEmbed.d.ts +70 -0
  131. package/dist/components/embedded/MerchifyThemeWrapper.d.ts +30 -0
  132. package/dist/components/embedded/ProductPreviewCard.d.ts +8 -0
  133. package/dist/components/embedded/index.d.ts +7 -0
  134. package/dist/components/primitives/ButtonGroup.d.ts +27 -0
  135. package/dist/components/primitives/ControlGroup.d.ts +15 -0
  136. package/dist/components/primitives/Dropdown.d.ts +27 -0
  137. package/dist/components/primitives/DropdownMenu.d.ts +9 -0
  138. package/dist/components/primitives/MenuItem.d.ts +13 -0
  139. package/dist/components/primitives/Panel.d.ts +25 -0
  140. package/dist/components/primitives/SecondaryToolbar.d.ts +9 -0
  141. package/dist/components/primitives/Switch.d.ts +10 -0
  142. package/dist/components/primitives/Toggle.d.ts +17 -0
  143. package/dist/components/primitives/index.d.ts +22 -0
  144. package/dist/components/stories/utils/MockEditorProvider.d.ts +32 -0
  145. package/dist/components/stories/utils/QACanvasCard.d.ts +41 -0
  146. package/dist/components/stories/utils/VisualQACard.d.ts +24 -0
  147. package/dist/components/stories/utils/element-factories.d.ts +188 -0
  148. package/dist/components/stories/utils/spec-to-elements.d.ts +74 -0
  149. package/dist/components/stories/utils/themeDecorator.d.ts +45 -0
  150. package/dist/components/stories/utils/unified-test-cases.d.ts +27 -0
  151. package/dist/components/text-toolbar/BoldButton.d.ts +5 -0
  152. package/dist/components/text-toolbar/FontColorButton.d.ts +6 -0
  153. package/dist/components/text-toolbar/FontSizeGroup.d.ts +5 -0
  154. package/dist/components/text-toolbar/ItalicButton.d.ts +5 -0
  155. package/dist/components/text-toolbar/TextAlignButton.d.ts +5 -0
  156. package/dist/components/text-toolbar/TextMoreMenu.d.ts +7 -0
  157. package/dist/components/text-toolbar/UnderlineButton.d.ts +5 -0
  158. package/dist/components/text-toolbar/UppercaseButton.d.ts +5 -0
  159. package/dist/components/text-toolbar/index.d.ts +25 -0
  160. package/dist/components/toolbars/EmbeddedToolbarLayout.d.ts +49 -0
  161. package/dist/components/toolbars/ExpandedPanelIcon.d.ts +13 -0
  162. package/dist/components/toolbars/FloatingPanels.d.ts +23 -0
  163. package/dist/components/toolbars/GroupElementToolbar.d.ts +35 -0
  164. package/dist/components/toolbars/SecondaryPanels.d.ts +125 -0
  165. package/dist/components/toolbars/index.d.ts +18 -0
  166. package/dist/components/toolbars/shared/ColorPanelWrapper.d.ts +9 -0
  167. package/dist/components/toolbars/shared/SecondaryPanelWrapper.d.ts +9 -0
  168. package/dist/components/ui/PresetCarousel.d.ts +21 -0
  169. package/dist/components/ui/SecondaryPanel.d.ts +28 -0
  170. package/dist/components/ui/SliderRow.d.ts +30 -0
  171. package/dist/components/ui/collapsed-toolbar-header.d.ts +14 -0
  172. package/dist/components/ui/custom-icons.d.ts +25 -0
  173. package/dist/components/ui/icons.d.ts +100 -0
  174. package/dist/components/ui/index.d.ts +48 -0
  175. package/dist/components/ui/normalized-icon.d.ts +63 -0
  176. package/dist/components/ui/toolbar-button.d.ts +24 -0
  177. package/dist/compose-Bo108juW.cjs +33 -0
  178. package/dist/compose-Bo108juW.cjs.map +1 -0
  179. package/dist/compose-DQ1FZS3O.js +7690 -0
  180. package/dist/compose-DQ1FZS3O.js.map +1 -0
  181. package/dist/constants.d.ts +121 -0
  182. package/dist/contexts/CommandContext.d.ts +87 -0
  183. package/dist/contexts/EditorContext.d.ts +190 -0
  184. package/dist/contexts/ElementsContext.d.ts +104 -0
  185. package/dist/contexts/HistoryContext.d.ts +60 -0
  186. package/dist/contexts/KitContext.d.ts +50 -0
  187. package/dist/contexts/SelectionContext.d.ts +51 -0
  188. package/dist/contexts/ThemeContext.d.ts +55 -0
  189. package/dist/contexts/ToolStateContext.d.ts +60 -0
  190. package/dist/contexts/ViewportContext.d.ts +87 -0
  191. package/dist/core/AlignmentSnapSystem.d.ts +270 -0
  192. package/dist/core/ArtboardElement.d.ts +106 -0
  193. package/dist/core/ArtboardManager.d.ts +130 -0
  194. package/dist/core/ArtboardRenderer.d.ts +97 -0
  195. package/dist/core/BaseElement.d.ts +94 -0
  196. package/dist/core/CanvasRenderer.d.ts +237 -0
  197. package/dist/core/CommandHistory.d.ts +173 -0
  198. package/dist/core/CoordinateTransform.d.ts +69 -0
  199. package/dist/core/CropModeController.d.ts +90 -0
  200. package/dist/core/EditModeRenderer.d.ts +51 -0
  201. package/dist/core/ElementFactory.d.ts +73 -0
  202. package/dist/core/ElementStore.d.ts +69 -0
  203. package/dist/core/EventBus.d.ts +163 -0
  204. package/dist/core/GeometryUtils.d.ts +247 -0
  205. package/dist/core/GroupElement.d.ts +134 -0
  206. package/dist/core/HoverRenderer.d.ts +103 -0
  207. package/dist/core/HybridHistoryManager.d.ts +137 -0
  208. package/dist/core/ImageCache.d.ts +63 -0
  209. package/dist/core/ImageElement.d.ts +226 -0
  210. package/dist/core/ImageLoadEvents.d.ts +23 -0
  211. package/dist/core/InteractionFeedbackRenderer.d.ts +15 -0
  212. package/dist/core/InteractionStateMachine.d.ts +199 -0
  213. package/dist/core/PathElement.d.ts +84 -0
  214. package/dist/core/PenToolManager.d.ts +112 -0
  215. package/dist/core/PinchHandler.d.ts +32 -0
  216. package/dist/core/ResizeHandler.d.ts +51 -0
  217. package/dist/core/ResizePipeline.d.ts +83 -0
  218. package/dist/core/ResizeUtils.d.ts +17 -0
  219. package/dist/core/RotationAnchorResolver.d.ts +60 -0
  220. package/dist/core/RotationUtils.d.ts +28 -0
  221. package/dist/core/SelectionRenderer.d.ts +24 -0
  222. package/dist/core/ShapeElement.d.ts +121 -0
  223. package/dist/core/SpacingSystem.d.ts +73 -0
  224. package/dist/core/SpatialGrid.d.ts +53 -0
  225. package/dist/core/TextElement.d.ts +80 -0
  226. package/dist/core/TextMetrics.d.ts +117 -0
  227. package/dist/core/Transform.d.ts +158 -0
  228. package/dist/core/TransformConverter.d.ts +16 -0
  229. package/dist/core/TransformHandles.d.ts +55 -0
  230. package/dist/core/artboardReducer.d.ts +46 -0
  231. package/dist/effects/DistressGenerator.d.ts +26 -0
  232. package/dist/effects/DistressTextureCache.d.ts +49 -0
  233. package/dist/effects/distress-presets.d.ts +86 -0
  234. package/dist/effects/distress-textures.d.ts +34 -0
  235. package/dist/effects/distress-utils.d.ts +39 -0
  236. package/dist/effects/mask-presets.d.ts +36 -0
  237. package/dist/fonts/google-fonts.d.ts +48 -0
  238. package/dist/google-fonts.json +1 -0
  239. package/dist/hooks/index.d.ts +42 -0
  240. package/dist/hooks/useArtboards.d.ts +71 -0
  241. package/dist/hooks/useAutoExport.d.ts +66 -0
  242. package/dist/hooks/useBreakpoint.d.ts +53 -0
  243. package/dist/hooks/useCanvasEvents.d.ts +8 -0
  244. package/dist/hooks/useCanvasReady.d.ts +22 -0
  245. package/dist/hooks/useClickOutside.d.ts +3 -0
  246. package/dist/hooks/useCommandHistory.d.ts +39 -0
  247. package/dist/hooks/useCommands.d.ts +47 -0
  248. package/dist/hooks/useContentReady.d.ts +18 -0
  249. package/dist/hooks/useElementById.d.ts +20 -0
  250. package/dist/hooks/useElementByName.d.ts +10 -0
  251. package/dist/hooks/useElementProperties.d.ts +29 -0
  252. package/dist/hooks/useExport.d.ts +89 -0
  253. package/dist/hooks/useImageBinding.d.ts +34 -0
  254. package/dist/hooks/useKeyboardShortcuts.d.ts +13 -0
  255. package/dist/hooks/useLayerDndKit.d.ts +24 -0
  256. package/dist/hooks/useLayerDragDrop.d.ts +58 -0
  257. package/dist/hooks/useLayerPreview.d.ts +31 -0
  258. package/dist/hooks/useLayerSelection.d.ts +76 -0
  259. package/dist/hooks/useLayers.d.ts +91 -0
  260. package/dist/hooks/usePerformance.d.ts +48 -0
  261. package/dist/hooks/useProjectLoader.d.ts +64 -0
  262. package/dist/hooks/useSelectedElement.d.ts +17 -0
  263. package/dist/hooks/useTextBinding.d.ts +26 -0
  264. package/dist/hooks/useTextToolbar.d.ts +61 -0
  265. package/dist/hooks/useViewport.d.ts +46 -0
  266. package/dist/icons/icon-data.d.ts +2 -0
  267. package/dist/icons/registry.d.ts +28 -0
  268. package/dist/index.d.ts +6 -0
  269. package/dist/index.js +2 -0
  270. package/dist/index.js.map +1 -0
  271. package/dist/index.mjs +1138 -0
  272. package/dist/index.mjs.map +1 -0
  273. package/dist/internals.d.ts +2 -0
  274. package/dist/internals.js +2 -0
  275. package/dist/internals.js.map +1 -0
  276. package/dist/internals.mjs +219 -0
  277. package/dist/internals.mjs.map +1 -0
  278. package/dist/kits/compose.d.ts +69 -0
  279. package/dist/kits/index.d.ts +21 -0
  280. package/dist/kits/presets.d.ts +40 -0
  281. package/dist/kits/registry.d.ts +33 -0
  282. package/dist/kits/sections.d.ts +119 -0
  283. package/dist/kits/serialization.d.ts +78 -0
  284. package/dist/kits/types.d.ts +129 -0
  285. package/dist/kits/validation.d.ts +36 -0
  286. package/dist/lib/utils.d.ts +2 -0
  287. package/dist/plugins/ElementTypePlugin.d.ts +90 -0
  288. package/dist/presets/artboard-color-presets.d.ts +22 -0
  289. package/dist/presets/tshirt-presets.d.ts +60 -0
  290. package/dist/rendering/CompositingRenderer.d.ts +33 -0
  291. package/dist/rendering/DistressTextureRenderer.d.ts +39 -0
  292. package/dist/rendering/ElementRenderUtils.d.ts +17 -0
  293. package/dist/rendering/MaskRenderer.d.ts +41 -0
  294. package/dist/rendering/PieceGuideRenderer.d.ts +177 -0
  295. package/dist/rendering/StrokeRenderer.d.ts +24 -0
  296. package/dist/rendering/canvas-renderer.d.ts +18 -0
  297. package/dist/rendering/element-serializer.d.ts +143 -0
  298. package/dist/rendering/image-renderer.d.ts +6 -0
  299. package/dist/rendering/knockout-utils.d.ts +48 -0
  300. package/dist/rendering/mask-utils.d.ts +65 -0
  301. package/dist/rendering/renderer-types.d.ts +79 -0
  302. package/dist/rendering/rich-text-renderer.d.ts +43 -0
  303. package/dist/rendering/serialize-for-server.d.ts +45 -0
  304. package/dist/rendering/shape-renderer.d.ts +6 -0
  305. package/dist/rendering/stroke-utils.d.ts +18 -0
  306. package/dist/rendering/text-renderer.d.ts +71 -0
  307. package/dist/rendering/transform-renderer.d.ts +33 -0
  308. package/dist/services/AutoExportManager.d.ts +107 -0
  309. package/dist/services/falApi.d.ts +63 -0
  310. package/dist/services/nounProjectApi.d.ts +90 -0
  311. package/dist/services/recraftApi.d.ts +65 -0
  312. package/dist/services/runwareApi.d.ts +69 -0
  313. package/dist/state/CanvasStateV1.d.ts +373 -0
  314. package/dist/state/index.d.ts +10 -0
  315. package/dist/style.css +1 -0
  316. package/dist/taco-reference-cropped.jpg +0 -0
  317. package/dist/testing/MockEditorProvider.d.ts +49 -0
  318. package/dist/testing/index.d.ts +25 -0
  319. package/dist/testing/utils.d.ts +128 -0
  320. package/dist/testing.d.ts +2 -0
  321. package/dist/testing.js +2 -0
  322. package/dist/testing.js.map +1 -0
  323. package/dist/testing.mjs +140 -0
  324. package/dist/testing.mjs.map +1 -0
  325. package/dist/textures/glass-frame.svg +32 -0
  326. package/dist/theme.d.ts +99 -0
  327. package/dist/themes/index.d.ts +23 -0
  328. package/dist/transforms/ArchTransform.d.ts +14 -0
  329. package/dist/transforms/AscendTransform.d.ts +14 -0
  330. package/dist/transforms/CircleTransform.d.ts +51 -0
  331. package/dist/transforms/CustomTransform.d.ts +81 -0
  332. package/dist/transforms/FlagTransform.d.ts +14 -0
  333. package/dist/transforms/LeanTransform.d.ts +14 -0
  334. package/dist/transforms/WaveTransform.d.ts +16 -0
  335. package/dist/transforms/defaults.d.ts +33 -0
  336. package/dist/transforms/index.d.ts +10 -0
  337. package/dist/transforms/registry.d.ts +51 -0
  338. package/dist/types/capabilities.d.ts +50 -0
  339. package/dist/types/guards.d.ts +31 -0
  340. package/dist/types/index.d.ts +765 -0
  341. package/dist/types/public.d.ts +31 -0
  342. package/dist/types/react.d.ts +132 -0
  343. package/dist/utils/ArtworkPlacement.d.ts +97 -0
  344. package/dist/utils/ElementPreviewRenderer.d.ts +19 -0
  345. package/dist/utils/ExportManager.d.ts +208 -0
  346. package/dist/utils/FontAnalyzer.d.ts +137 -0
  347. package/dist/utils/GlyphRenderer.d.ts +55 -0
  348. package/dist/utils/GoogleFontsService.d.ts +37 -0
  349. package/dist/utils/ImageLoader.d.ts +124 -0
  350. package/dist/utils/ImportManager.d.ts +72 -0
  351. package/dist/utils/MonotypeCategoryMapping.d.ts +36 -0
  352. package/dist/utils/MonotypeService.d.ts +148 -0
  353. package/dist/utils/PerformanceMonitor.d.ts +54 -0
  354. package/dist/utils/TextureManager.d.ts +60 -0
  355. package/dist/utils/UnifiedFontService.d.ts +117 -0
  356. package/dist/utils/WorkerExportManager.d.ts +185 -0
  357. package/dist/utils/clickProtection.d.ts +39 -0
  358. package/dist/utils/cn.d.ts +4 -0
  359. package/dist/utils/colorConversion.d.ts +101 -0
  360. package/dist/utils/documentColors.d.ts +108 -0
  361. package/dist/utils/featureApplied.d.ts +14 -0
  362. package/dist/utils/google-fonts-loader.d.ts +67 -0
  363. package/dist/utils/logger.d.ts +66 -0
  364. package/dist/utils/selectionPreservation.d.ts +42 -0
  365. package/dist/utils/textCursorUtils.d.ts +39 -0
  366. package/dist/utils/textUtils.d.ts +11 -0
  367. package/dist/workers/export-protocol.d.ts +119 -0
  368. package/dist/workers/export-worker.bundle.string.d.ts +2 -0
  369. package/dist/workers/export-worker.d.ts +5 -0
  370. package/package.json +201 -0
@@ -0,0 +1,8 @@
1
+ "use strict";function Ue(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var se={exports:{}},H=se.exports={},$,V;function Wt(){throw new Error("setTimeout has not been defined")}function _t(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?$=setTimeout:$=Wt}catch{$=Wt}try{typeof clearTimeout=="function"?V=clearTimeout:V=_t}catch{V=_t}})();function re(s){if($===setTimeout)return setTimeout(s,0);if(($===Wt||!$)&&setTimeout)return $=setTimeout,setTimeout(s,0);try{return $(s,0)}catch{try{return $.call(null,s,0)}catch{return $.call(this,s,0)}}}function Ge(s){if(V===clearTimeout)return clearTimeout(s);if((V===_t||!V)&&clearTimeout)return V=clearTimeout,clearTimeout(s);try{return V(s)}catch{try{return V.call(null,s)}catch{return V.call(this,s)}}}var q=[],rt=!1,ot,kt=-1;function $e(){!rt||!ot||(rt=!1,ot.length?q=ot.concat(q):kt=-1,q.length&&ne())}function ne(){if(!rt){var s=re($e);rt=!0;for(var t=q.length;t;){for(ot=q,q=[];++kt<t;)ot&&ot[kt].run();kt=-1,t=q.length}ot=null,rt=!1,Ge(s)}}H.nextTick=function(s){var t=new Array(arguments.length-1);if(arguments.length>1)for(var e=1;e<arguments.length;e++)t[e-1]=arguments[e];q.push(new ae(s,t)),q.length===1&&!rt&&re(ne)};function ae(s,t){this.fun=s,this.array=t}ae.prototype.run=function(){this.fun.apply(null,this.array)};H.title="browser";H.browser=!0;H.env={};H.argv=[];H.version="";H.versions={};function j(){}H.on=j;H.addListener=j;H.once=j;H.off=j;H.removeListener=j;H.removeAllListeners=j;H.emit=j;H.prependListener=j;H.prependOnceListener=j;H.listeners=function(s){return[]};H.binding=function(s){throw new Error("process.binding is not supported")};H.cwd=function(){return"/"};H.chdir=function(s){throw new Error("process.chdir is not supported")};H.umask=function(){return 0};var Ve=se.exports;const zt=Ue(Ve);let te=1;class lt{constructor(t={}){this.transformType="artboard",this.id=t.id||`artboard-${te++}`,this.name=t.name||`Artboard ${te}`,this.x=t.x!==void 0?t.x:0,this.y=t.y!==void 0?t.y:0,this.width=t.width||1920,this.height=t.height||1080,this.backgroundColor=t.backgroundColor||"#ffffff",t.backgroundType?this.backgroundType=t.backgroundType:t.backgroundColor==="transparent"?this.backgroundType="transparent":t.backgroundTexture?this.backgroundType="texture":this.backgroundType="color",this.backgroundTexture=t.backgroundTexture,this.exportBackground=t.exportBackground??!1,this.clipShape=t.clipShape,this.previewBackgroundColor=t.previewBackgroundColor,this.distressTexture=t.distressTexture?{...t.distressTexture}:void 0,this.imageMask=t.imageMask?{...t.imageMask}:void 0,this.elementIds=new Set(t.elementIds||[])}getBoundingBox(){return{x:this.x,y:this.y,width:this.width,height:this.height}}getCenter(){return{x:this.x+this.width/2,y:this.y+this.height/2}}containsPoint(t,e){return t>=this.x&&t<=this.x+this.width&&e>=this.y&&e<=this.y+this.height}containsElement(t){const e=t.getBoundingBox();return e.x>=this.x&&e.y>=this.y&&e.x+e.width<=this.x+this.width&&e.y+e.height<=this.y+this.height}addElementId(t){this.elementIds.add(t)}removeElementId(t){this.elementIds.delete(t)}hasElementId(t){return this.elementIds.has(t)}getElementIds(){return Array.from(this.elementIds)}getElementCount(){return this.elementIds.size}clearElementIds(){this.elementIds.clear()}hitTestBorder(t,e,o=5){const i=t>=this.x-o&&t<=this.x+this.width+o,r=e>=this.y-o&&e<=this.y+this.height+o,a=Math.abs(t-this.x)<=o&&r,h=Math.abs(t-(this.x+this.width))<=o&&r,n=Math.abs(e-this.y)<=o&&i,l=Math.abs(e-(this.y+this.height))<=o&&i;return a||h||n||l}clone(){return new lt({id:this.id,name:this.name,x:this.x,y:this.y,width:this.width,height:this.height,backgroundColor:this.backgroundColor,backgroundType:this.backgroundType,backgroundTexture:this.backgroundTexture,exportBackground:this.exportBackground,clipShape:this.clipShape,previewBackgroundColor:this.previewBackgroundColor,distressTexture:this.distressTexture?{...this.distressTexture}:void 0,imageMask:this.imageMask?{...this.imageMask}:void 0,elementIds:Array.from(this.elementIds)})}toJSON(){return{id:this.id,name:this.name,x:this.x,y:this.y,width:this.width,height:this.height,backgroundColor:this.backgroundColor,backgroundType:this.backgroundType,...this.backgroundTexture&&{backgroundTexture:this.backgroundTexture},exportBackground:this.exportBackground,elementIds:Array.from(this.elementIds),transformType:"artboard",...this.clipShape&&{clipShape:this.clipShape},...this.previewBackgroundColor&&{previewBackgroundColor:this.previewBackgroundColor},...this.distressTexture&&{distressTexture:{...this.distressTexture}},...this.imageMask&&{imageMask:{...this.imageMask}}}}static fromJSON(t){return new lt(t)}updateProperties(t){t.name!==void 0&&(this.name=t.name),t.x!==void 0&&(this.x=t.x),t.y!==void 0&&(this.y=t.y),t.width!==void 0&&(this.width=Math.max(100,t.width)),t.height!==void 0&&(this.height=Math.max(100,t.height)),t.backgroundColor!==void 0&&(this.backgroundColor=t.backgroundColor),t.backgroundType!==void 0&&(this.backgroundType=t.backgroundType),t.backgroundTexture!==void 0&&(this.backgroundTexture=t.backgroundTexture),t.exportBackground!==void 0&&(this.exportBackground=t.exportBackground),t.clipShape!==void 0&&(this.clipShape=t.clipShape),"distressTexture"in t&&(this.distressTexture=t.distressTexture?{...t.distressTexture}:void 0),"imageMask"in t&&(this.imageMask=t.imageMask?{...t.imageMask}:void 0)}resize(t,e){this.width=Math.max(100,t),this.height=Math.max(100,e)}move(t,e){this.x=t,this.y=e}}class Je{constructor(){this.artboards=new Map,this.elementToArtboard=new Map,this.activeArtboardId=null}createArtboard(t={}){const e=new lt(t);return this.artboards.set(e.id,e),this.activeArtboardId=e.id,e}deleteArtboard(t){const e=this.artboards.get(t);if(!e)return[];const o=e.getElementIds();if(o.forEach(i=>{this.elementToArtboard.delete(i)}),this.artboards.delete(t),this.activeArtboardId===t){const i=Array.from(this.artboards.keys());this.activeArtboardId=i.length>0?i[0]:null}return o}getArtboard(t){return this.artboards.get(t)}getAllArtboards(){return Array.from(this.artboards.values())}getArtboardIds(){return Array.from(this.artboards.keys())}setActiveArtboard(t){(t===null||this.artboards.has(t))&&(this.activeArtboardId=t)}getActiveArtboard(){return this.activeArtboardId&&this.artboards.get(this.activeArtboardId)||null}getActiveArtboardId(){return this.activeArtboardId}addElementToArtboard(t,e){const o=this.artboards.get(e);if(!o)return!1;const i=this.elementToArtboard.get(t);if(i){const r=this.artboards.get(i);r==null||r.removeElementId(t)}return o.addElementId(t),this.elementToArtboard.set(t,e),!0}removeElementFromArtboard(t){const e=this.elementToArtboard.get(t);if(e){const o=this.artboards.get(e);o==null||o.removeElementId(t),this.elementToArtboard.delete(t)}}getArtboardForElement(t){const e=this.elementToArtboard.get(t);return e&&this.artboards.get(e)||null}getArtboardIdForElement(t){return this.elementToArtboard.get(t)||null}getElementsOnArtboard(t){const e=this.artboards.get(t);return e?e.getElementIds():[]}findArtboardAtPoint(t,e){const o=Array.from(this.artboards.values()).reverse();for(const i of o)if(i.containsPoint(t,e))return i;return null}findArtboardBorderAtPoint(t,e,o=5){const i=Array.from(this.artboards.values()).reverse();for(const r of i)if(r.hitTestBorder(t,e,o))return r;return null}findArtboardForPosition(t,e){return this.findArtboardAtPoint(t,e)}updateArtboard(t,e){const o=this.artboards.get(t);return o?(o.updateProperties(e),!0):!1}renameArtboard(t,e){return this.updateArtboard(t,{name:e})}hasArtboard(t){return this.artboards.has(t)}getArtboardCount(){return this.artboards.size}reorderArtboards(t,e){const o=Array.from(this.artboards.entries());if(t<0||t>=o.length||e<0||e>=o.length||t===e)return;const[i]=o.splice(t,1);o.splice(e,0,i),this.artboards=new Map(o)}clear(){this.artboards.clear(),this.elementToArtboard.clear(),this.activeArtboardId=null}toJSON(){return{artboards:Array.from(this.artboards.values()).map(t=>t.toJSON()),activeArtboardId:this.activeArtboardId}}fromJSON(t){this.clear(),t.artboards.forEach(e=>{const o=lt.fromJSON(e);this.artboards.set(o.id,o),o.getElementIds().forEach(i=>{this.elementToArtboard.set(i,o.id)})}),this.activeArtboardId=t.activeArtboardId}validateMappings(t){const e=new Set(t.map(o=>o.id));for(const[o,i]of this.elementToArtboard.entries())e.has(o)||this.removeElementFromArtboard(o);for(const o of this.artboards.values()){const i=o.getElementIds().filter(r=>e.has(r));o.clearElementIds(),i.forEach(r=>o.addElementId(r))}}}const R={toRadians(s){return-s*Math.PI/180},toRadiansInverse(s){return s*Math.PI/180},normalize(s){let t=(s%360+360)%360;return t>180&&(t-=360),t}};let qe=1;class it{get isClipping(){return this.blendMode==="clip"}set isClipping(t){t?(this.blendMode="clip",this.knockoutParts||(this.knockoutParts={fill:!0,scope:"group"})):this.blendMode==="clip"&&(this.blendMode="normal")}constructor(t={}){this.id=t.id||`element-${qe++}`,this.x=t.x!==void 0?t.x:100,this.y=t.y!==void 0?t.y:100,this.rotation=t.rotation!==void 0?t.rotation:0,this.opacity=t.opacity!==void 0?t.opacity:1,this.transformType=t.transformType||"custom",this.transformData=t.transformData||{},this.blendMode=t.blendMode,this.knockoutParts=t.knockoutParts,this.stroke=t.stroke,this.masks=t.masks,this.distressEffect=t.distressEffect,t.isClipping&&!t.blendMode&&(this.blendMode="clip",this.knockoutParts||(this.knockoutParts={fill:!0,scope:"group"})),this.name=t.name,this.visible=t.visible!==void 0?t.visible:!0,this.locked=t.locked!==void 0?t.locked:!1}getVisualBoundingBox(){return this.getBoundingBox()}getRotationAnchor(){return{x:this.x,y:this.y}}hitTest(t,e){const o=this.getVisualBoundingBox(),i=this.getRotationAnchor(),r=R.toRadiansInverse(this.rotation),a=Math.cos(r),h=Math.sin(r),n=t-i.x,l=e-i.y,c=n*a-l*h,f=n*h+l*a,d=i.x+c,g=i.y+f;return d>=o.x&&d<=o.x+o.width&&g>=o.y&&g<=o.y+o.height}applyCanvasTransform(t){t.translate(this.x,this.y),t.rotate(R.toRadians(this.rotation))}toJSON(){return{id:this.id,x:this.x,y:this.y,rotation:this.rotation,opacity:this.opacity,transformType:this.transformType,transformData:{...this.transformData},...this.blendMode&&{blendMode:this.blendMode},...this.knockoutParts&&{knockoutParts:{...this.knockoutParts}},...this.stroke&&{stroke:{...this.stroke}},...this.masks&&{masks:this.masks.map(t=>({...t}))},...this.distressEffect&&{distressEffect:{...this.distressEffect}},...this.name&&{name:this.name},...this.visible!==void 0&&{visible:this.visible},...this.locked!==void 0&&{locked:this.locked},...this.isClipping&&{isClipping:!0}}}move(t,e){this.x+=t,this.y+=e}setRotation(t){this.rotation=t}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right","middle-left","middle-right","middle-top","middle-bottom"]}getTransformStartData(){var e;const t=this.getBoundingBox();return{id:this.id,x:this.x,y:this.y,width:t.width,height:t.height,rotation:this.rotation,transformData:{...this.transformData},strokeWidth:(e=this.stroke)==null?void 0:e.width}}}class W{constructor(t){this.element=t}worldToLocal(t,e){const o=this.element.rotation*Math.PI/180,i=Math.cos(o),r=Math.sin(o),a=t-this.element.x,h=e-this.element.y;return{x:a*i-h*r,y:a*r+h*i}}localToWorld(t,e){const o=-this.element.rotation*Math.PI/180,i=Math.cos(o),r=Math.sin(o),a=t*i-e*r,h=t*r+e*i;return{x:this.element.x+a,y:this.element.y+h}}worldDeltaToLocal(t,e){const o=this.element.rotation*Math.PI/180,i=Math.cos(o),r=Math.sin(o);return{dx:t*i-e*r,dy:t*r+e*i}}localDeltaToWorld(t,e){const o=-this.element.rotation*Math.PI/180,i=Math.cos(o),r=Math.sin(o);return{dx:t*i-e*r,dy:t*r+e*i}}static rotatePointAroundAnchor(t,e,o,i,r){const a=-r*Math.PI/180,h=Math.cos(a),n=Math.sin(a),l=t-o,c=e-i,f=l*h-c*n,d=l*n+c*h;return{x:o+f,y:i+d}}getRenderingAngle(){return-this.element.rotation*Math.PI/180}getInverseAngle(){return this.element.rotation*Math.PI/180}getRenderingCosSin(){const t=this.getRenderingAngle();return{cos:Math.cos(t),sin:Math.sin(t)}}getInverseCosSin(){const t=this.getInverseAngle();return{cos:Math.cos(t),sin:Math.sin(t)}}static fromSnapshot(t){return new W(t)}}const he=[{name:"Bebas Neue",category:"display",weights:[400],googleFont:!0,description:"Modern condensed display"},{name:"Bevan",category:"display",weights:[400],googleFont:!0,description:"Bold slab serif display"},{name:"Bigshot One",category:"display",weights:[400],googleFont:!0,description:"Bold elegant display"},{name:"Anton",category:"display",weights:[400],googleFont:!0,description:"Super bold display font"},{name:"Oswald",category:"display",weights:[200,300,400,500,600,700],googleFont:!0,description:"Condensed sans-serif"},{name:"Archivo Black",category:"display",weights:[400],googleFont:!0,description:"Heavy weight display"},{name:"Alfa Slab One",category:"display",weights:[400],googleFont:!0,description:"Bold slab serif, varsity style"},{name:"Bowlby One SC",category:"display",weights:[400],googleFont:!0,description:"Blocky display, sports style"},{name:"Black Ops One",category:"display",weights:[400],googleFont:!0,description:"Military/stencil style"},{name:"Abril Fatface",category:"display",weights:[400],googleFont:!0,description:"Bold high-contrast display"},{name:"Bangers",category:"display",weights:[400],googleFont:!0,description:"Comic book style"},{name:"Titan One",category:"display",weights:[400],googleFont:!0,description:"Heavy impactful display"},{name:"Lilita One",category:"display",weights:[400],googleFont:!0,description:"Rounded display font"},{name:"Fugaz One",category:"display",weights:[400],googleFont:!0,description:"Bold geometric display"},{name:"Russo One",category:"display",weights:[400],googleFont:!0,description:"Bold sans display"},{name:"Passion One",category:"display",weights:[400,700,900],googleFont:!0,description:"Condensed bold display"},{name:"Righteous",category:"display",weights:[400],googleFont:!0,description:"1980s-style display"},{name:"Bungee",category:"display",weights:[400],googleFont:!0,description:"Bold urban/street style"},{name:"Barlow Condensed",category:"display",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Condensed sans display"},{name:"Staatliches",category:"display",weights:[400],googleFont:!0,description:"Bold condensed display"},{name:"Rubik Mono One",category:"display",weights:[400],googleFont:!0,description:"Blocky monoline display"},{name:"Ultra",category:"display",weights:[400],googleFont:!0,description:"Ultra bold serif"},{name:"Audiowide",category:"display",weights:[400],googleFont:!0,description:"Tech/futuristic display"},{name:"Changa One",category:"display",weights:[400],googleFont:!0,description:"Rounded bold display"},{name:"Lobster",category:"display",weights:[400],googleFont:!0,description:"Bold script display"},{name:"Coda",category:"display",weights:[400,800],googleFont:!0,description:"Bold humanist sans"},{name:"Teko",category:"display",weights:[300,400,500,600,700],googleFont:!0,description:"Narrow sans display"},{name:"Fredoka One",category:"display",weights:[400],googleFont:!0,description:"Rounded bold display"},{name:"Caprasimo",category:"display",weights:[400],googleFont:!0,description:"Retro rounded display"},{name:"Fjalla One",category:"display",weights:[400],googleFont:!0,description:"Bold condensed sans"},{name:"Secular One",category:"display",weights:[400],googleFont:!0,description:"Hebrew-inspired display"},{name:"Saira",category:"display",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Semi-condensed sans display"},{name:"Barlow Semi Condensed",category:"display",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Semi-condensed low-contrast"},{name:"Exo",category:"display",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Geometric technological display"},{name:"Saira Condensed",category:"display",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Condensed display font"},{name:"Fredoka",category:"display",weights:[300,400,500,600,700],googleFont:!0,description:"Rounded friendly display"},{name:"Comfortaa",category:"display",weights:[300,400,500,600,700],googleFont:!0,description:"Rounded geometric display"},{name:"Questrial",category:"display",weights:[400],googleFont:!0,description:"Simple sans-serif display"},{name:"Lexend",category:"display",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Variable sans for readability"},{name:"Darker Grotesque",category:"display",weights:[300,400,500,600,700,800,900],googleFont:!0,description:"Contemporary grotesque sans"},{name:"Bakbak One",category:"display",weights:[400],googleFont:!0,description:"Heavy condensed display"},{name:"Turret Road",category:"display",weights:[200,300,400,500,700,800],googleFont:!0,description:"Geometric display font"},{name:"Zilla Slab Highlight",category:"display",weights:[400,700],googleFont:!0,description:"Highlighted slab serif"},{name:"Bree Serif",category:"display",weights:[400],googleFont:!0,description:"Upright italic slab"},{name:"Overpass",category:"display",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Highway-inspired sans"},{name:"Archivo",category:"display",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Grotesque sans-serif"},{name:"Chakra Petch",category:"display",weights:[300,400,500,600,700],googleFont:!0,description:"Futuristic Thai-inspired"},{name:"Concert One",category:"display",weights:[400],googleFont:!0,description:"Rounded grotesque display"},{name:"Roboto",category:"sans-serif",weights:[100,300,400,500,700,900],googleFont:!0,description:"Clean, modern sans-serif"},{name:"Montserrat",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Geometric sans-serif"},{name:"Open Sans",category:"sans-serif",weights:[300,400,500,600,700,800],googleFont:!0,description:"Highly readable"},{name:"Poppins",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Geometric with personality"},{name:"Work Sans",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Contemporary sans-serif"},{name:"Raleway",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Elegant sans-serif"},{name:"Lato",category:"sans-serif",weights:[100,300,400,700,900],googleFont:!0,description:"Warm sans-serif"},{name:"Nunito",category:"sans-serif",weights:[200,300,400,500,600,700,800,900],googleFont:!0,description:"Rounded sans-serif"},{name:"Outfit",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Modern geometric sans"},{name:"Inter",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Clean interface font"},{name:"Quicksand",category:"sans-serif",weights:[300,400,500,600,700],googleFont:!0,description:"Friendly rounded sans"},{name:"Rubik",category:"sans-serif",weights:[300,400,500,600,700,800,900],googleFont:!0,description:"Slightly rounded sans"},{name:"Barlow",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Low-contrast sans"},{name:"Josefin Sans",category:"sans-serif",weights:[100,200,300,400,500,600,700],googleFont:!0,description:"Geometric vintage sans"},{name:"Exo 2",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Contemporary geometric"},{name:"Kanit",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Modern loopless Thai"},{name:"Hind",category:"sans-serif",weights:[300,400,500,600,700],googleFont:!0,description:"Clean humanist sans"},{name:"Alata",category:"sans-serif",weights:[400],googleFont:!0,description:"Geometric sans"},{name:"Urbanist",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Geometric low-contrast"},{name:"Manrope",category:"sans-serif",weights:[200,300,400,500,600,700,800],googleFont:!0,description:"Modern geometric sans"},{name:"Be Vietnam Pro",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Modern Vietnamese-optimized sans"},{name:"Belanosima",category:"sans-serif",weights:[400,600,700],googleFont:!0,description:"Contemporary sans-serif"},{name:"DM Sans",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Low-contrast geometric sans"},{name:"Source Sans 3",category:"sans-serif",weights:[200,300,400,500,600,700,800,900],googleFont:!0,description:"Adobe sans-serif family"},{name:"Source Sans Pro",category:"sans-serif",weights:[200,300,400,600,700,900],googleFont:!0,description:"Adobe sans-serif (legacy)"},{name:"IBM Plex Sans",category:"sans-serif",weights:[100,200,300,400,500,600,700],googleFont:!0,description:"IBM corporate sans"},{name:"Karla",category:"sans-serif",weights:[200,300,400,500,600,700,800],googleFont:!0,description:"Grotesque sans-serif"},{name:"PT Sans",category:"sans-serif",weights:[400,700],googleFont:!0,description:"Russian universal sans"},{name:"Fira Sans",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Mozilla humanist sans"},{name:"Space Grotesk",category:"sans-serif",weights:[300,400,500,600,700],googleFont:!0,description:"Proportional space age sans"},{name:"Syne",category:"sans-serif",weights:[400,500,600,700,800],googleFont:!0,description:"Geometric variable sans"},{name:"Libre Franklin",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Interpretation of Franklin Gothic"},{name:"Alegreya Sans",category:"sans-serif",weights:[100,300,400,500,700,800,900],googleFont:!0,description:"Humanist sans companion"},{name:"Archivo Narrow",category:"sans-serif",weights:[400,500,600,700],googleFont:!0,description:"Narrow grotesque sans"},{name:"Chivo",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Grotesque sans-serif"},{name:"Neuton",category:"sans-serif",weights:[200,300,400,700,800],googleFont:!0,description:"Serif-adjacent sans"},{name:"Prompt",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Loopless Thai sans"},{name:"Noto Sans",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Google universal sans"},{name:"Nunito Sans",category:"sans-serif",weights:[200,300,400,600,700,800,900],googleFont:!0,description:"Rounded sans-serif"},{name:"Proza Libre",category:"sans-serif",weights:[400,500,600,700,800],googleFont:!0,description:"Humanist sans-serif"},{name:"Cabin",category:"sans-serif",weights:[400,500,600,700],googleFont:!0,description:"Humanist sans inspired by Edward Johnston"},{name:"Signika",category:"sans-serif",weights:[300,400,500,600,700],googleFont:!0,description:"Sans-serif for signage"},{name:"Public Sans",category:"sans-serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Strong neutral sans"},{name:"Plus Jakarta Sans",category:"sans-serif",weights:[200,300,400,500,600,700,800],googleFont:!0,description:"Geometric neo-grotesque"},{name:"Red Hat Display",category:"sans-serif",weights:[300,400,500,600,700,800,900],googleFont:!0,description:"Display variant of Red Hat sans"},{name:"Pacifico",category:"script",weights:[400],googleFont:!0,description:"Retro surf script"},{name:"Dancing Script",category:"script",weights:[400,500,600,700],googleFont:!0,description:"Elegant handwriting"},{name:"Satisfy",category:"script",weights:[400],googleFont:!0,description:"Casual handwritten"},{name:"Permanent Marker",category:"script",weights:[400],googleFont:!0,description:"Bold marker style"},{name:"Caveat",category:"script",weights:[400,500,600,700],googleFont:!0,description:"Modern handwritten"},{name:"Shadows Into Light",category:"script",weights:[400],googleFont:!0,description:"Friendly handwriting"},{name:"Kaushan Script",category:"script",weights:[400],googleFont:!0,description:"Bold script"},{name:"Amatic SC",category:"script",weights:[400,700],googleFont:!0,description:"Hand-drawn style"},{name:"Indie Flower",category:"script",weights:[400],googleFont:!0,description:"Casual handwriting"},{name:"Cookie",category:"script",weights:[400],googleFont:!0,description:"Brush script"},{name:"Sacramento",category:"script",weights:[400],googleFont:!0,description:"Elegant script"},{name:"Allura",category:"script",weights:[400],googleFont:!0,description:"Formal script"},{name:"Great Vibes",category:"script",weights:[400],googleFont:!0,description:"Elegant calligraphy"},{name:"Yellowtail",category:"script",weights:[400],googleFont:!0,description:"Flat-nib script"},{name:"Courgette",category:"script",weights:[400],googleFont:!0,description:"Casual upright script"},{name:"Beth Ellen",category:"script",weights:[400],googleFont:!0,description:"Handwritten marker style"},{name:"Covered By Your Grace",category:"script",weights:[400],googleFont:!0,description:"Casual handwritten"},{name:"Nothing You Could Do",category:"script",weights:[400],googleFont:!0,description:"Hand-drawn lettering"},{name:"Homemade Apple",category:"script",weights:[400],googleFont:!0,description:"Thin marker handwriting"},{name:"Reenie Beanie",category:"script",weights:[400],googleFont:!0,description:"Casual handwritten note style"},{name:"Patrick Hand",category:"script",weights:[400],googleFont:!0,description:"Handwriting font"},{name:"Architects Daughter",category:"script",weights:[400],googleFont:!0,description:"Architect-style handwriting"},{name:"Handlee",category:"script",weights:[400],googleFont:!0,description:"Casual handwriting"},{name:"Zeyada",category:"script",weights:[400],googleFont:!0,description:"Bouncy handwritten script"},{name:"Gloria Hallelujah",category:"script",weights:[400],googleFont:!0,description:"Comic-style handwriting"},{name:"Bad Script",category:"script",weights:[400],googleFont:!0,description:"Casual Cyrillic script"},{name:"Playfair Display",category:"serif",weights:[400,500,600,700,800,900],googleFont:!0,description:"High-contrast elegant"},{name:"Merriweather",category:"serif",weights:[300,400,700,900],googleFont:!0,description:"Readable serif"},{name:"Lora",category:"serif",weights:[400,500,600,700],googleFont:!0,description:"Contemporary serif"},{name:"Crimson Text",category:"serif",weights:[400,600,700],googleFont:!0,description:"Classic book typography"},{name:"PT Serif",category:"serif",weights:[400,700],googleFont:!0,description:"Transitional serif"},{name:"Libre Baskerville",category:"serif",weights:[400,700],googleFont:!0,description:"Classic serif"},{name:"Bitter",category:"serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Contemporary slab serif"},{name:"Cormorant Garamond",category:"serif",weights:[300,400,500,600,700],googleFont:!0,description:"Display serif"},{name:"Cinzel",category:"serif",weights:[400,500,600,700,800,900],googleFont:!0,description:"Classical serif capitals"},{name:"Zilla Slab",category:"serif",weights:[300,400,500,600,700],googleFont:!0,description:"Contemporary slab serif"},{name:"Cardo",category:"serif",weights:[400,700],googleFont:!0,description:"Large text serif"},{name:"Spectral",category:"serif",weights:[200,300,400,500,600,700,800],googleFont:!0,description:"Efficient serif"},{name:"Literata",category:"serif",weights:[200,300,400,500,600,700,800,900],googleFont:!0,description:"Modern serif"},{name:"Cantata One",category:"serif",weights:[400],googleFont:!0,description:"Humanist slab serif"},{name:"Bellefair",category:"serif",weights:[400],googleFont:!0,description:"Elegant high-contrast serif"},{name:"Source Serif Pro",category:"serif",weights:[200,300,400,600,700,900],googleFont:!0,description:"Adobe serif family"},{name:"Cormorant",category:"serif",weights:[300,400,500,600,700],googleFont:!0,description:"Display serif typeface"},{name:"Eczar",category:"serif",weights:[400,500,600,700,800],googleFont:!0,description:"Hybrid serif for screen"},{name:"Alegreya",category:"serif",weights:[400,500,600,700,800,900],googleFont:!0,description:"Humanist serif"},{name:"Fraunces",category:"serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Variable display serif"},{name:"Inknut Antiqua",category:"serif",weights:[300,400,500,600,700,800,900],googleFont:!0,description:"Display serif"},{name:"BioRhyme",category:"serif",weights:[200,300,400,700,800],googleFont:!0,description:"Rounded slab serif"},{name:"Slabo 27px",category:"serif",weights:[400],googleFont:!0,description:"Display serif at 27px"},{name:"Slabo 13px",category:"serif",weights:[400],googleFont:!0,description:"Text serif at 13px"},{name:"Crimson Pro",category:"serif",weights:[200,300,400,500,600,700,800,900],googleFont:!0,description:"Modern oldstyle serif"},{name:"Noto Serif",category:"serif",weights:[100,200,300,400,500,600,700,800,900],googleFont:!0,description:"Google universal serif"},{name:"EB Garamond",category:"serif",weights:[400,500,600,700,800],googleFont:!0,description:"Classical Garamond revival"},{name:"Vollkorn",category:"serif",weights:[400,500,600,700,800,900],googleFont:!0,description:"Quiet, moderate serif"},{name:"Young Serif",category:"serif",weights:[400,500,600,700],googleFont:!0,description:"Modern retro serif"},{name:"Monoton",category:"vintage",weights:[400],googleFont:!0,description:"Art deco display"},{name:"Limelight",category:"vintage",weights:[400],googleFont:!0,description:"Art deco geometric sans"},{name:"Poiret One",category:"vintage",weights:[400],googleFont:!0,description:"Art deco constructivist"},{name:"Italiana",category:"vintage",weights:[400],googleFont:!0,description:"Art deco calligraphic"},{name:"Federo",category:"vintage",weights:[400],googleFont:!0,description:"Art nouveau geometric"},{name:"Dorsa",category:"vintage",weights:[400],googleFont:!0,description:"Art deco display"},{name:"Boogaloo",category:"vintage",weights:[400],googleFont:!0,description:"Groovy rounded display"},{name:"Gorditas",category:"vintage",weights:[400,700],googleFont:!0,description:"Bubble slab with hearts"},{name:"Shrikhand",category:"vintage",weights:[400],googleFont:!0,description:"Retro curved display"},{name:"Kumar One",category:"vintage",weights:[400],googleFont:!0,description:"Rounded bubble display"},{name:"Chicle",category:"vintage",weights:[400],googleFont:!0,description:"Bubble gum style"},{name:"Flavors",category:"vintage",weights:[400],googleFont:!0,description:"Retro bubble font"},{name:"Chango",category:"vintage",weights:[400],googleFont:!0,description:"Groovy rounded bold"},{name:"Purple Purse",category:"vintage",weights:[400],googleFont:!0,description:"Hippie funky casual"},{name:"Super Dream",category:"vintage",weights:[400],googleFont:!1,description:"70s groovy bubble font"},{name:"Yesteryear",category:"vintage",weights:[400],googleFont:!0,description:"Vintage cursive script"},{name:"Mrs Sheppards",category:"vintage",weights:[400],googleFont:!0,description:"Old American script"},{name:"Condiment",category:"vintage",weights:[400],googleFont:!0,description:"Vintage sign design"},{name:"Rye",category:"vintage",weights:[400],googleFont:!0,description:"Western Victorian"},{name:"Sancreek",category:"vintage",weights:[400],googleFont:!0,description:"Western slab serif"},{name:"Smokum",category:"vintage",weights:[400],googleFont:!0,description:"Western playful slab"},{name:"Diplomata",category:"vintage",weights:[400],googleFont:!0,description:"Bold western display"},{name:"Ewert",category:"vintage",weights:[400],googleFont:!0,description:"Ornamental wood type"},{name:"Macondo",category:"vintage",weights:[400],googleFont:!0,description:"Western carnival style"},{name:"Wellfleet",category:"vintage",weights:[400],googleFont:!0,description:"Vintage slab serif"},{name:"Ranchers",category:"vintage",weights:[400],googleFont:!0,description:"Western slab serif"},{name:"Bungee Shade",category:"vintage",weights:[400],googleFont:!0,description:"Layered circus display"},{name:"Peralta",category:"vintage",weights:[400],googleFont:!0,description:"Rounded circus style"},{name:"Kelly Slab",category:"vintage",weights:[400],googleFont:!0,description:"Retro slab serif"},{name:"Snippet",category:"vintage",weights:[400],googleFont:!0,description:"Vintage condensed"},{name:"Press Start 2P",category:"vintage",weights:[400],googleFont:!0,description:"8-bit retro gaming"},{name:"VT323",category:"vintage",weights:[400],googleFont:!0,description:"Terminal monospace"},{name:"UnifrakturCook",category:"vintage",weights:[700],googleFont:!0,description:"Gothic blackletter"},{name:"Sevillana",category:"vintage",weights:[400],googleFont:!0,description:"Victorian ornate"},{name:"Uncial Antiqua",category:"vintage",weights:[400],googleFont:!0,description:"Medieval uncial"},{name:"Piedra",category:"vintage",weights:[400],googleFont:!0,description:"Stone carved display"},{name:"Creepster",category:"vintage",weights:[400],googleFont:!0,description:"Horror Halloween style"},{name:"Nosifer",category:"vintage",weights:[400],googleFont:!0,description:"Horror dripping"},{name:"Eater",category:"vintage",weights:[400],googleFont:!0,description:"Zombie horror"},{name:"Metal Mania",category:"vintage",weights:[400],googleFont:!0,description:"Heavy metal style"},{name:"Butcherman",category:"vintage",weights:[400],googleFont:!0,description:"Zombified horror"},{name:"Special Elite",category:"vintage",weights:[400],googleFont:!0,description:"Typewriter style"},{name:"Stalinist One",category:"vintage",weights:[400],googleFont:!0,description:"Soviet constructivist"},{name:"Ruslan Display",category:"vintage",weights:[400],googleFont:!0,description:"Russian display style"},{name:"Corben",category:"vintage",weights:[400,700],googleFont:!0,description:"Mid-century rounded"},{name:"Kranky",category:"vintage",weights:[400],googleFont:!0,description:"Quirky handwritten retro"},{name:"Orbitron",category:"decorative",weights:[400,500,600,700,800,900],googleFont:!0,description:"Futuristic geometric"},{name:"Playball",category:"decorative",weights:[400],googleFont:!0,description:"Baseball script"},{name:"Sedgwick Ave Display",category:"decorative",weights:[400],googleFont:!0,description:"Graffiti style"},{name:"Modak",category:"decorative",weights:[400],googleFont:!0,description:"Rounded heavy display"},{name:"Fascinate",category:"decorative",weights:[400],googleFont:!0,description:"Broadway/theater"},{name:"Bungee Inline",category:"decorative",weights:[400],googleFont:!0,description:"Inline display"},{name:"Emblema One",category:"decorative",weights:[400],googleFont:!0,description:"Decorative caps"},{name:"Fascinate Inline",category:"decorative",weights:[400],googleFont:!0,description:"Inline Broadway"},{name:"New Rocker",category:"decorative",weights:[400],googleFont:!0,description:"Rock and roll"},{name:"Bigelow Rules",category:"decorative",weights:[400],googleFont:!0,description:"Playful cursive display"},{name:"Roboto Mono",category:"monospace",weights:[100,200,300,400,500,600,700],googleFont:!0,description:"Modern monospace"},{name:"Courier Prime",category:"monospace",weights:[400,700],googleFont:!0,description:"Typewriter monospace"},{name:"Space Mono",category:"monospace",weights:[400,700],googleFont:!0,description:"Retro-futuristic mono"},{name:"Inconsolata",category:"monospace",weights:[200,300,400,500,600,700,800,900],googleFont:!0,description:"Humanist monospace"}];function je(){return he.map(s=>s.name)}const Ze={system:"System Fonts",display:"Bold & Display","sans-serif":"Sans Serif",serif:"Serif","slab-serif":"Slab Serif",script:"Script & Handwritten",vintage:"Vintage & Retro",decorative:"Decorative & Unique",monospace:"Monospace"};function $t(s){if(typeof window>"u"||typeof document>"u")return"oklch(0% 0 0)";const t=s||document.documentElement;return getComputedStyle(t).getPropertyValue("--accent").trim()||"oklch(0% 0 0)"}function Ke(s){return typeof window>"u"||typeof document>"u"?"light":document.documentElement.getAttribute("data-theme")||"light"}function Vt(){return Ke().includes("dark")?"#60a5fa":"#3b82f6"}function Qe(s){if(typeof window>"u"||typeof document>"u")return"#FF0000";const t=s||document.documentElement;return getComputedStyle(t).getPropertyValue("--color-spacing-indicator").trim()||"#FF0000"}function to(s=.1,t){const e=$t(t);if(e.startsWith("oklch("))return`${e.slice(0,-1)} / ${s})`;if(e.startsWith("#")){const o=e.replace("#",""),i=parseInt(o.substring(0,2),16),r=parseInt(o.substring(2,4),16),a=parseInt(o.substring(4,6),16);return`rgba(${i}, ${r}, ${a}, ${s})`}return e}function eo(s){if(typeof window>"u"||typeof document>"u")return"oklch(0% 0 0 / 0.45)";const t=s||document.documentElement;return getComputedStyle(t).getPropertyValue("--color-text-selection").trim()||"oklch(0% 0 0 / 0.45)"}function oo(s){if(typeof window>"u"||typeof document>"u")return"#b5f747";const t=s||document.documentElement;return getComputedStyle(t).getPropertyValue("--color-accent-hover").trim()||"#b5f747"}function le(s){if(typeof window>"u"||typeof document>"u")return"oklch(0.2103 0.0059 285.89)";const t=s||document.documentElement;return getComputedStyle(t).getPropertyValue("--foreground").trim()||"oklch(0.2103 0.0059 285.89)"}function io(s){if(typeof window>"u"||typeof document>"u")return"oklch(0.9607 0 0)";const t=s||document.documentElement;return getComputedStyle(t).getPropertyValue("--background").trim()||"oklch(0.9607 0 0)"}function so(s){const t=le(s);return t.startsWith("oklch(")?`${t.slice(0,-1)} / 0.2)`:"rgba(0,0,0,0.2)"}function ro(s){if(typeof window>"u"||typeof document>"u")return"oklch(0% 0 0 / 0.2)";const t=document.documentElement;return getComputedStyle(t).getPropertyValue("--divider").trim()||"oklch(0% 0 0 / 0.2)"}function no(s){if(typeof window>"u"||typeof document>"u")return"oklch(0% 0 0 / 0.5)";const t=document.documentElement,e=getComputedStyle(t).getPropertyValue("--foreground").trim();return e.startsWith("oklch(")?`${e.slice(0,-1)} / 0.5)`:e||"oklch(0% 0 0 / 0.5)"}function ao(s){if(typeof window>"u"||typeof document>"u")return"#b5f747";const t=document.documentElement;return getComputedStyle(t).getPropertyValue("--color-accent-hover-border").trim()||"#b5f747"}function ho(s){if(typeof window>"u"||typeof document>"u")return"oklch(0.2103 0.0059 285.89)";const t=document.documentElement;return getComputedStyle(t).getPropertyValue("--foreground").trim()||"oklch(0.2103 0.0059 285.89)"}function lo(s){if(typeof window>"u"||typeof document>"u")return"oklch(1 0 0)";const t=document.documentElement;return getComputedStyle(t).getPropertyValue("--background").trim()||"oklch(1 0 0)"}function co(s){if(typeof window>"u"||typeof document>"u")return"oklch(0.2103 0.0059 285.89 / 0.5)";const t=document.documentElement,e=getComputedStyle(t).getPropertyValue("--foreground").trim();return e.startsWith("oklch(")?`${e.slice(0,-1)} / 0.5)`:e||"oklch(0.2103 0.0059 285.89 / 0.5)"}const fo=1,go="#ffffff",ce=20,uo=6,mo=24,de=16,po=36,yo=24,wo=4,bo="#FFFFFF",So=2,To=.1,xo=je(),Co=[8,10,12,14,16,18,20,24,28,32,36,48,64,72,96,128],N=0,Ct=1.2,fe=50,ge=8,ue=999,vo=new Set(["Arial","Arial Black","Verdana","Tahoma","Trebuchet MS","Impact","Times New Roman","Georgia","Garamond","Courier New","Brush Script MT","Palatino","Baskerville","Helvetica","Helvetica Neue","Comic Sans MS","Lucida Console","Monaco","Consolas","Courier"]),Jt=.3;var me=(s=>(s[s.DEBUG=0]="DEBUG",s[s.INFO=1]="INFO",s[s.WARN=2]="WARN",s[s.ERROR=3]="ERROR",s[s.NONE=4]="NONE",s))(me||{});class Ao{constructor(){var t;this.level=0,this.enabled=typeof zt<"u"&&((t=zt.env)==null?void 0:t.NODE_ENV)!=="production"}setLevel(t){this.level=t}setEnabled(t){this.enabled=t}getLevel(){return this.level}isEnabled(){return this.enabled}debug(t,...e){}info(t,...e){this.enabled&&this.level<=1&&console.info(`[INFO] ${t}`,...e)}warn(t,...e){this.enabled&&this.level<=2&&console.warn(`[WARN] ${t}`,...e)}error(t,...e){this.enabled&&this.level<=3&&console.error(`[ERROR] ${t}`,...e)}scope(t){return new Mo(this,t)}}class Mo{constructor(t,e){this.logger=t,this.scopeName=e}debug(t,...e){this.logger.debug(`[${this.scopeName}] ${t}`,...e)}info(t,...e){this.logger.info(`[${this.scopeName}] ${t}`,...e)}warn(t,...e){this.logger.warn(`[${this.scopeName}] ${t}`,...e)}error(t,...e){this.logger.error(`[${this.scopeName}] ${t}`,...e)}}const pe=new Ao,st=s=>pe.scope(s),Fo=st("ImageLoadEvents"),Xt=new Set;function Io(s){return Xt.add(s),()=>{Xt.delete(s)}}function pt(s){Xt.forEach(t=>{try{t(s)}catch(e){Fo.error("Listener error:",e)}})}class K{constructor(){this.cache=new Map}static getInstance(){return K.instance||(K.instance=new K),K.instance}acquire(t){const e=this.cache.get(t);if(e)return e.refCount++,e.image;const o=new Image;o.crossOrigin="anonymous";const i={image:o,refCount:1,loaded:!1};return o.onload=()=>{i.loaded=!0},o.onerror=()=>{i.loaded=!0},this.cache.set(t,i),(!t.includes(":")||/^https?:\/\/|^data:|^blob:/.test(t))&&(o.src=t),o}release(t){const e=this.cache.get(t);e&&(e.refCount--,e.refCount<=0&&this.cache.delete(t))}get(t){var e;return(e=this.cache.get(t))==null?void 0:e.image}has(t){return this.cache.has(t)}getStats(){let t=0;for(const e of this.cache.values())t+=e.refCount;return{entries:this.cache.size,totalRefs:t}}clear(){this.cache.clear()}}const yt=st("ImageElement"),ee=3e4,oe=3,ko=1e3;function I(s){return s.transformData}class vt extends it{constructor(t={}){var e,o,i,r,a,h,n,l,c,f;super(t),this.svgBlobUrl=null,this.loadTimeoutId=null,this.retryAttempt=0,this.cachedImageUrl=null,this.transformType="image",this.transformData={type:"image",width:((e=t.transformData)==null?void 0:e.width)||200,height:((o=t.transformData)==null?void 0:o.height)||200,cropX:((i=t.transformData)==null?void 0:i.cropX)??0,cropY:((r=t.transformData)==null?void 0:r.cropY)??0,cropWidth:((a=t.transformData)==null?void 0:a.cropWidth)??1,cropHeight:((h=t.transformData)==null?void 0:h.cropHeight)??1,flipHorizontal:((n=t.transformData)==null?void 0:n.flipHorizontal)??!1,flipVertical:((l=t.transformData)==null?void 0:l.flipVertical)??!1,borderRadius:((c=t.transformData)==null?void 0:c.borderRadius)??0},this.imageUrl=t.imageUrl||"",this.imageLoaded=!1,this.imageElement=null,this.imageAspectRatio=t.imageAspectRatio||1,this.isSvg=((f=t.imageUrl)==null?void 0:f.toLowerCase().endsWith(".svg"))||!1,this.preserveDimensions=t.preserveDimensions??!1,this.imageLoadState=t.imageUrl?"loading":"loaded",this.imageLoadError=null,this.isCropping=!1,this.onLoadCallback=t.onLoadCallback||null,this.imageUrl&&this.loadImage(this.imageUrl)}loadImage(t){const e=t.toLowerCase().endsWith(".svg");this.isSvg=e,e?this.loadSvgAsHighDpi(t):this.loadRegularImage(t)}loadRegularImage(t){this.retryAttempt=0,this.imageLoadError=null,this.imageLoadState="loading",this.attemptLoadRegularImage(t)}attemptLoadRegularImage(t){var n;this.clearLoadTimeout(),this.releaseImageCache();const o=K.getInstance().acquire(t);this.cachedImageUrl=t;let i=!1;const r=()=>{i=!0,this.clearLoadTimeout()};if(o.complete&&o.naturalWidth>0){r(),this.imageElement=o,this.imageLoaded=!0,this.imageLoadState="loaded",this.imageLoadError=null,this.imageAspectRatio=o.naturalWidth/o.naturalHeight,this.preserveDimensions||(this.transformData.height=this.transformData.width/this.imageAspectRatio),this.onLoadCallback&&this.onLoadCallback(this.clone()),pt(this.id);return}const a=o.onload,h=o.onerror;o.onload=l=>{i||(r(),this.imageElement=o,this.imageLoaded=!0,this.imageLoadState="loaded",this.imageLoadError=null,this.imageAspectRatio=o.naturalWidth/o.naturalHeight,this.preserveDimensions||(this.transformData.height=this.transformData.width/this.imageAspectRatio),this.onLoadCallback&&this.onLoadCallback(this.clone()),pt(this.id),a&&a!==o.onload&&a(l))},o.onerror=l=>{if(i)return;r();const c=new Error(`Failed to load image: ${t}`);this.handleLoadFailure(t,c),h&&h!==o.onerror&&h(l)},this.loadTimeoutId=setTimeout(()=>{if(i)return;r(),o.src="";const l=new Error(`Image load timed out after ${ee}ms: ${t}`);this.handleLoadFailure(t,l)},ee),(!o.src||o.src!==t)&&(o.src=t),!i&&o.complete&&o.naturalWidth>0&&((n=o.onload)==null||n.call(o,new Event("load")))}handleLoadFailure(t,e){if(this.retryAttempt++,this.retryAttempt<oe){const o=ko*Math.pow(2,this.retryAttempt-1);yt.warn(`Image load attempt ${this.retryAttempt} failed, retrying in ${o}ms:`,t),this.imageLoadState="retrying",this.imageLoadError=e,pt(this.id),this.loadTimeoutId=setTimeout(()=>{this.attemptLoadRegularImage(t)},o)}else yt.error(`Image load failed after ${oe} attempts:`,t),this.imageLoaded=!1,this.imageLoadState="error",this.imageLoadError=e,pt(this.id)}clearLoadTimeout(){this.loadTimeoutId!==null&&(clearTimeout(this.loadTimeoutId),this.loadTimeoutId=null)}releaseImageCache(){this.cachedImageUrl&&(K.getInstance().release(this.cachedImageUrl),this.cachedImageUrl=null)}retryImageLoad(){this.imageUrl&&(yt.info("Manual retry triggered for image:",this.imageUrl),this.clearLoadTimeout(),this.imageLoaded=!1,this.imageElement=null,this.isSvg?(this.imageLoadState="loading",this.imageLoadError=null,this.loadSvgAsHighDpi(this.imageUrl)):this.loadRegularImage(this.imageUrl))}revokeSvgBlobUrl(){this.svgBlobUrl&&(URL.revokeObjectURL(this.svgBlobUrl),this.svgBlobUrl=null)}loadSvgAsHighDpi(t){this.revokeSvgBlobUrl();const e=new Image;e.crossOrigin="anonymous",e.onload=()=>{const i=document.createElement("canvas");i.width=e.width*4,i.height=e.height*4;const r=i.getContext("2d");r.scale(4,4),r.drawImage(e,0,0),i.toBlob(a=>{if(!a){yt.error("Failed to convert SVG to blob"),this.imageLoaded=!1;return}this.svgBlobUrl=URL.createObjectURL(a),this.imageElement=new Image,this.imageElement.crossOrigin="anonymous",this.imageElement.onload=()=>{this.imageLoaded=!0,this.imageAspectRatio=this.imageElement.width/this.imageElement.height,this.preserveDimensions||(this.transformData.height=this.transformData.width/this.imageAspectRatio),this.onLoadCallback&&this.onLoadCallback(this.clone()),pt(this.id)},this.imageElement.src=this.svgBlobUrl},"image/png")},e.onerror=()=>{yt.error("Failed to load SVG:",t),this.imageLoaded=!1},e.src=t}getBoundingBox(){if(this.isCropping){const t=this.transformData.width*this.transformData.cropWidth,e=this.transformData.height*this.transformData.cropHeight;let o=this.transformData.width/2-(this.transformData.cropX*this.transformData.width+t/2),i=this.transformData.height/2-(this.transformData.cropY*this.transformData.height+e/2);const r=this.transformData.flipHorizontal?-1:1,a=this.transformData.flipVertical?-1:1;o*=r,i*=a;const h=Math.cos(R.toRadians(this.rotation)),n=Math.sin(R.toRadians(this.rotation)),l=o*h-i*n,c=o*n+i*h,f=this.x+l,d=this.y+c;return{x:f-this.transformData.width/2,y:d-this.transformData.height/2,width:this.transformData.width,height:this.transformData.height}}else{const t=this.transformData.width*this.transformData.cropWidth,e=this.transformData.height*this.transformData.cropHeight;return{x:this.x-t/2,y:this.y-e/2,width:t,height:e}}}getVisualBoundingBox(){const t=this.transformData.width*this.transformData.cropWidth,e=this.transformData.height*this.transformData.cropHeight;return{x:this.x-t/2,y:this.y-e/2,width:t,height:e}}getRotationAnchor(){if(this.isCropping){const t=this.transformData.width*this.transformData.cropWidth,e=this.transformData.height*this.transformData.cropHeight;let o=this.transformData.width/2-(this.transformData.cropX*this.transformData.width+t/2),i=this.transformData.height/2-(this.transformData.cropY*this.transformData.height+e/2);const r=this.transformData.flipHorizontal?-1:1,a=this.transformData.flipVertical?-1:1;o*=r,i*=a;const h=Math.cos(R.toRadians(this.rotation)),n=Math.sin(R.toRadians(this.rotation)),l=o*h-i*n,c=o*n+i*h;return{x:this.x+l,y:this.y+c}}else return{x:this.x,y:this.y}}hitTest(t,e){const o=this.worldToLocal(t,e);if(this.isCropping){const i=this.transformData.width*this.transformData.cropWidth,r=this.transformData.height*this.transformData.cropHeight,a=this.transformData.width/2-(this.transformData.cropX*this.transformData.width+i/2),h=this.transformData.height/2-(this.transformData.cropY*this.transformData.height+r/2),n=this.transformData.width/2,l=this.transformData.height/2;return o.x>=a-n&&o.x<=a+n&&o.y>=h-l&&o.y<=h+l}else{const i=this.transformData.width*this.transformData.cropWidth,r=this.transformData.height*this.transformData.cropHeight,a=i/2,h=r/2;return o.x>=-a&&o.x<=a&&o.y>=-h&&o.y<=h}}render(t,e=!1,o=!1){if(!this.imageLoaded||!this.imageElement){this.renderPlaceholder(t);return}t.save(),this.opacity!==void 0&&this.opacity!==1&&(t.globalAlpha=this.opacity),t.translate(this.x,this.y),t.rotate(R.toRadians(this.rotation));const i=this.transformData.flipHorizontal?-1:1,r=this.transformData.flipVertical?-1:1;if(t.scale(i,r),this.isCropping){const a=this.transformData.width*this.transformData.cropWidth,h=this.transformData.height*this.transformData.cropHeight,n=this.transformData.width/2-(this.transformData.cropX*this.transformData.width+a/2),l=this.transformData.height/2-(this.transformData.cropY*this.transformData.height+h/2),c=n-this.transformData.width/2,f=l-this.transformData.height/2,d=this.transformData.borderRadius||0;if(d>0){t.save();const g=Math.min(d/100*Math.min(this.transformData.width,this.transformData.height),this.transformData.width/2,this.transformData.height/2);t.beginPath(),t.roundRect(c,f,this.transformData.width,this.transformData.height,g),t.clip()}t.drawImage(this.imageElement,0,0,this.imageElement.width,this.imageElement.height,c,f,this.transformData.width,this.transformData.height),d>0&&t.restore()}else if(this.masks&&this.masks.length>0){const a=this.transformData.width*this.transformData.cropWidth,h=this.transformData.height*this.transformData.cropHeight,n=-a/2,l=-h/2,c=n-this.transformData.cropX*this.transformData.width,f=l-this.transformData.cropY*this.transformData.height;t.drawImage(this.imageElement,0,0,this.imageElement.width,this.imageElement.height,c,f,this.transformData.width,this.transformData.height)}else{const a=this.transformData.width*this.transformData.cropWidth,h=this.transformData.height*this.transformData.cropHeight,n=-a/2,l=-h/2,c=this.transformData.borderRadius||0;t.save();const f=Math.min(c/100*Math.min(a,h),a/2,h/2);t.beginPath(),t.roundRect(n,l,a,h,f),t.clip();const d=n-this.transformData.cropX*this.transformData.width,g=l-this.transformData.cropY*this.transformData.height;t.drawImage(this.imageElement,0,0,this.imageElement.width,this.imageElement.height,d,g,this.transformData.width,this.transformData.height),t.restore()}t.restore()}renderPlaceholder(t){t.save(),t.translate(this.x,this.y),t.rotate(R.toRadians(this.rotation));const e=this.transformData.width*this.transformData.cropWidth,o=this.transformData.height*this.transformData.cropHeight,i=-e/2,r=-o/2;let a,h,n;this.imageLoadState==="error"?(a="#f0e0e0",h="#993333",n="Image failed to load"):this.imageLoadState==="retrying"?(a="#e0e0e0",h="#666",n="Retrying..."):this.imageLoadState==="loading"?(a="#e0e0e0",h="#666",n="Loading..."):(a="#e0e0e0",h="#666",n=this.imageUrl?"Loading...":"No image"),t.fillStyle=a,t.fillRect(i,r,e,o),t.fillStyle=h,t.font="14px system-ui, -apple-system, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(n,0,0),t.restore()}resize(t,e,o,i){let r,a;this.isCropping?(r=e/I(i).width,a=o/I(i).height):(r=e/(i.width??1),a=o/(i.height??1));const h=(r+a)/2;let n=t;this.isCropping&&(n=this.remapAnchorForFlips(t,i));let l=h;if(this.isCropping){const T=this.transformData.width/I(i).width;h<T&&(l=this.calculateMinScaleForCropBounds(n,i,h,T))}this.transformData.width=I(i).width*l,this.transformData.height=this.transformData.width/this.imageAspectRatio,this.rotation=i.rotation;let c,f;if(this.isCropping){const T=(I(i).cropX+I(i).cropWidth/2)*I(i).width-I(i).width/2,E=(I(i).cropY+I(i).cropHeight/2)*I(i).height-I(i).height/2,P=T,D=E,O=W.fromSnapshot(i).localDeltaToWorld(P,D),L=O.dx,z=O.dy;c=i.x-L,f=i.y-z}else{const T=(I(i).cropX+I(i).cropWidth/2)*I(i).width-I(i).width/2,E=(I(i).cropY+I(i).cropHeight/2)*I(i).height-I(i).height/2,P=T,D=E,O=W.fromSnapshot(i).localDeltaToWorld(P,D),L=O.dx,z=O.dy;c=i.x-L,f=i.y-z}let d,g,u=0,p=0;n==="top-left"?(u=I(i).width/2,p=I(i).height/2):n==="top-right"?(u=-I(i).width/2,p=I(i).height/2):n==="bottom-left"?(u=I(i).width/2,p=-I(i).height/2):n==="bottom-right"?(u=-I(i).width/2,p=-I(i).height/2):n==="middle-left"?(u=I(i).width/2,p=0):n==="middle-right"?(u=-I(i).width/2,p=0):n==="middle-top"?(u=0,p=I(i).height/2):n==="middle-bottom"&&(u=0,p=-I(i).height/2);const y=W.fromSnapshot(i).localDeltaToWorld(u,p),S=y.dx,b=y.dy;d=c+S,g=f+b;let w=0,x=0;n==="top-left"?(w=this.transformData.width/2,x=this.transformData.height/2):n==="top-right"?(w=-this.transformData.width/2,x=this.transformData.height/2):n==="bottom-left"?(w=this.transformData.width/2,x=-this.transformData.height/2):n==="bottom-right"?(w=-this.transformData.width/2,x=-this.transformData.height/2):n==="middle-left"?(w=this.transformData.width/2,x=0):n==="middle-right"?(w=-this.transformData.width/2,x=0):n==="middle-top"?(w=0,x=this.transformData.height/2):n==="middle-bottom"&&(w=0,x=-this.transformData.height/2);const A=new W(this).localDeltaToWorld(w,x),M=A.dx,F=A.dy,v=d-M,k=g-F;if(this.isCropping){const T=i.x,E=i.y,P=I(i).cropWidth*I(i).width,D=I(i).cropHeight*I(i).height;this.x=T,this.y=E;const B=P/this.transformData.width,O=D/this.transformData.height,L=T-v,z=E-k,U=new W(this).worldDeltaToLocal(L,z),mt=U.dx,G=U.dy,J=this.transformData.width/2+mt,Lt=this.transformData.height/2+G,Ne=J/this.transformData.width-B/2,Ye=Lt/this.transformData.height-O/2;this.transformData.cropX=Ne,this.transformData.cropY=Ye,this.transformData.cropWidth=B,this.transformData.cropHeight=O}else{const T=(this.transformData.cropX+this.transformData.cropWidth/2)*this.transformData.width-this.transformData.width/2,E=(this.transformData.cropY+this.transformData.cropHeight/2)*this.transformData.height-this.transformData.height/2,P=T,D=E,O=new W(this).localDeltaToWorld(P,D),L=O.dx,z=O.dy;this.x=v+L,this.y=k+z}return!0}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right"]}enterCropMode(){this.isCropping=!0}exitCropMode(){this.isCropping=!1}getCropBoxBounds(){if(!this.isCropping)return null;const t=this.transformData.width*this.transformData.cropWidth,e=this.transformData.height*this.transformData.cropHeight;return{x:-t/2,y:-e/2,width:t,height:e}}getCropBoxWorldCorners(){const t=this.getCropBoxBounds();if(!t)return null;const e=Math.cos(R.toRadians(this.rotation)),o=Math.sin(R.toRadians(this.rotation));return[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x,y:t.y+t.height},{x:t.x+t.width,y:t.y+t.height}].map(r=>({x:this.x+r.x*e-r.y*o,y:this.y+r.x*o+r.y*e}))}worldToLocal(t,e){const o=t-this.x,i=e-this.y,r=Math.cos(R.toRadiansInverse(this.rotation)),a=Math.sin(R.toRadiansInverse(this.rotation));let h=o*r-i*a,n=o*a+i*r;const l=this.transformData.flipHorizontal?-1:1,c=this.transformData.flipVertical?-1:1;return h*=l,n*=c,{x:h,y:n}}localToWorld(t,e){const o=this.transformData.flipHorizontal?-1:1,i=this.transformData.flipVertical?-1:1;let r=t*o,a=e*i;const h=Math.cos(R.toRadians(this.rotation)),n=Math.sin(R.toRadians(this.rotation)),l=r*h-a*n,c=r*n+a*h;return{x:this.x+l,y:this.y+c}}hitTestCropHandle(t,e,o=1){if(!this.isCropping)return null;const i=this.getCropBoxBounds();if(!i)return null;const r=this.worldToLocal(t,e),a=1/o,h=de*a,n=po*a,l=yo*a,c=[{x:i.x,y:i.y,anchor:"top-left"},{x:i.x+i.width,y:i.y,anchor:"top-right"},{x:i.x,y:i.y+i.height,anchor:"bottom-left"},{x:i.x+i.width,y:i.y+i.height,anchor:"bottom-right"}];for(const d of c){const g=r.x-d.x,u=r.y-d.y;if(Math.sqrt(g*g+u*u)<=h){const m=this.localToWorld(d.x,d.y);return{type:"corner",anchor:d.anchor,worldX:m.x,worldY:m.y}}}const f=[{x:i.x+i.width/2,y:i.y,anchor:"top",orientation:"horizontal"},{x:i.x+i.width/2,y:i.y+i.height,anchor:"bottom",orientation:"horizontal"},{x:i.x,y:i.y+i.height/2,anchor:"left",orientation:"vertical"},{x:i.x+i.width,y:i.y+i.height/2,anchor:"right",orientation:"vertical"}];for(const d of f){const g=r.x-d.x,u=r.y-d.y;let p,m;if(d.orientation==="horizontal"?(p=n/2,m=l/2):(p=l/2,m=n/2),Math.abs(g)<=p&&Math.abs(u)<=m){const y=this.localToWorld(d.x,d.y);return{type:"edge",anchor:d.anchor,worldX:y.x,worldY:y.y}}}return null}hitTestCropBox(t,e){if(!this.isCropping)return!1;const o=this.getCropBoxBounds();if(!o)return!1;const i=this.worldToLocal(t,e);return i.x>=o.x&&i.x<=o.x+o.width&&i.y>=o.y&&i.y<=o.y+o.height}updateCrop(t,e,o,i,r=!1){let h=Math.max(.1,Math.min(1,o)),n=Math.max(.1,Math.min(1,i)),l=Math.max(0,Math.min(1-h,t)),c=Math.max(0,Math.min(1-n,e));l+h>1&&(h=1-l),c+n>1&&(n=1-c);let f=0,d=0;if(r){const g=this.transformData.cropX*this.transformData.width+this.transformData.cropWidth*this.transformData.width/2,u=this.transformData.cropY*this.transformData.height+this.transformData.cropHeight*this.transformData.height/2,p=l*this.transformData.width+h*this.transformData.width/2,m=c*this.transformData.height+n*this.transformData.height/2,y=p-g,S=m-u,b=Math.cos(R.toRadians(this.rotation)),w=Math.sin(R.toRadians(this.rotation));f=y*b-S*w,d=y*w+S*b}this.transformData.cropX=l,this.transformData.cropY=c,this.transformData.cropWidth=h,this.transformData.cropHeight=n,r&&(this.x+=f,this.y+=d)}getOppositeCornerLocalPosition(t,e,o){const i=e/2,r=o/2;return{"top-left":{x:i,y:r},"top-right":{x:-i,y:r},"bottom-left":{x:i,y:-r},"bottom-right":{x:-i,y:-r},top:{x:0,y:r},bottom:{x:0,y:-r},left:{x:i,y:0},right:{x:-i,y:0},"middle-top":{x:0,y:r},"middle-bottom":{x:0,y:-r},"middle-left":{x:i,y:0},"middle-right":{x:-i,y:0}}[t]}calculateFrameCenterFromCropCenter(t){const e=I(t).width*I(t).cropWidth,o=I(t).height*I(t).cropHeight,i=I(t).width/2-(I(t).cropX*I(t).width+e/2),r=I(t).height/2-(I(t).cropY*I(t).height+o/2),h=new W(t).localDeltaToWorld(i,r);return{x:t.x+h.dx,y:t.y+h.dy}}getFixedCornerWorldPosition(t,e){const o=this.getOppositeCornerLocalPosition(t,I(e).width,I(e).height),i=this.calculateFrameCenterFromCropCenter(e),a=new W(e).localDeltaToWorld(o.x,o.y);return{x:i.x+a.dx,y:i.y+a.dy}}calculateFrameCenterAfterResize(t,e,o){const i=this.getFixedCornerWorldPosition(e,o),r=I(o).width*t,a=r/this.imageAspectRatio,h=this.getOppositeCornerLocalPosition(e,r,a),l=new W({x:0,y:0,rotation:o.rotation}).localDeltaToWorld(h.x,h.y);return{x:i.x-l.dx,y:i.y-l.dy}}calculateCropStateAtScale(t,e,o){const i=I(o).width*t,r=i/this.imageAspectRatio,a=I(o).cropWidth*I(o).width,h=I(o).cropHeight*I(o).height,n=a/i,l=h/r,c=this.calculateFrameCenterAfterResize(t,e,o),f={x:o.x,y:o.y},d=f.x-c.x,g=f.y-c.y,p=new W({x:c.x,y:c.y,rotation:o.rotation}).worldDeltaToLocal(d,g),m=i/2+p.dx,y=r/2+p.dy,S=m/i-n/2,b=y/r-l/2;return{cropX:S,cropY:b,cropWidth:n,cropHeight:l}}isScaleValidForCropBounds(t,e,o){const r=this.calculateCropStateAtScale(t,e,o);if(r.cropWidth>1+1e-4||r.cropHeight>1+1e-4)return!1;const a=r.cropX,h=r.cropX+r.cropWidth,n=r.cropY,l=r.cropY+r.cropHeight;return a>=-1e-4&&n>=-1e-4&&h<=1+1e-4&&l<=1+1e-4}calculateMinScaleForCropBounds(t,e,o,i){if(this.isScaleValidForCropBounds(o,t,e))return o;let h=o,n=i;for(let l=0;l<20;l++){const c=(h+n)/2;if(this.isScaleValidForCropBounds(c,t,e)?n=c:h=c,Math.abs(n-h)<1e-4)break}return n}remapAnchorForFlips(t,e){let o=t;const i=I(e).flipHorizontal,r=I(e).flipVertical;return i&&(o.includes("left")?o=o.replace("left","right"):o.includes("right")&&(o=o.replace("right","left"))),r&&(o.includes("top")?o=o.replace("top","bottom"):o.includes("bottom")&&(o=o.replace("bottom","top"))),o}clone(){const t=this.toJSON(),{imageUrl:e,...o}=t,i=new vt(o);return i.imageUrl=this.imageUrl,i.imageElement=this.imageElement,i.imageLoaded=this.imageLoaded,i.imageAspectRatio=this.imageAspectRatio,i.isCropping=this.isCropping,i.onLoadCallback=this.onLoadCallback,i.isSvg=this.isSvg,i.imageLoadState=this.imageLoadState,i.imageLoadError=this.imageLoadError,i.preserveDimensions=this.preserveDimensions,i}toJSON(){return{...super.toJSON(),id:this.id,type:"image",transformType:"image",x:this.x,y:this.y,rotation:this.rotation,imageUrl:this.imageUrl,imageAspectRatio:this.imageAspectRatio,transformData:{...this.transformData}}}destroy(){this.clearLoadTimeout(),this.releaseImageCache(),this.revokeSvgBlobUrl(),this.imageElement=null,this.onLoadCallback=null,this.imageLoadError=null}}class Y{constructor(t=[]){this.spans=t.length>0?t:[{text:"",style:{}}],this.normalize()}static fromPlainText(t,e={}){return new Y([{text:t,style:e}])}getText(){return this.spans.map(t=>t.text).join("")}getLength(){return this.getText().length}getStyleAt(t){if(this.spans.length===0)return{};if(t<0)return this.spans[0].style;let e=0;for(const o of this.spans){if(t<e+o.text.length)return o.style;e+=o.text.length}return this.spans[this.spans.length-1].style}applyStyle(t,e,o){if(t>=e||t<0||e>this.getLength())return;const i=[];let r=0;for(const a of this.spans){const h=r,n=r+a.text.length;if(n<=t){i.push(a),r=n;continue}if(h>=e){i.push(a),r=n;continue}const l=Math.max(t,h),c=Math.min(e,n);l>h&&i.push({text:a.text.substring(0,l-h),style:a.style}),i.push({text:a.text.substring(l-h,c-h),style:{...a.style,...o}}),c<n&&i.push({text:a.text.substring(c-h),style:a.style}),r=n}this.spans=i,this.normalize()}insert(t,e,o){if(e.length===0)return;const i=[];let r=0;for(const a of this.spans){const h=r,n=r+a.text.length;if(t<=h&&i.length===0&&i.push({text:e,style:o}),t>h&&t<=n){const l=t-h;i.push({text:a.text.substring(0,l),style:a.style}),i.push({text:e,style:o}),i.push({text:a.text.substring(l),style:a.style}),r=n;continue}i.push(a),r=n}t>=this.getLength()&&!i.some(a=>a.text===e)&&i.push({text:e,style:o}),this.spans=i,this.normalize()}delete(t,e){const o=this.getLength();if(t=Math.max(0,Math.min(t,o)),e=Math.max(0,Math.min(e,o)),t>=e)return;const i=[];let r=0;for(const a of this.spans){const h=r,n=r+a.text.length;if(n<=t){i.push(a),r=n;continue}if(h>=e){i.push(a),r=n;continue}const l=Math.max(t,h),c=Math.min(e,n);l>h&&i.push({text:a.text.substring(0,l-h),style:a.style}),c<n&&i.push({text:a.text.substring(c-h),style:a.style}),r=n}this.spans=i.length>0?i:[{text:"",style:{}}],this.normalize()}normalize(){if(this.spans=this.spans.filter(o=>o.text!==""),this.spans.length===0){this.spans=[{text:"",style:{}}];return}if(this.spans.length<=1)return;const t=[];let e=this.spans[0];for(let o=1;o<this.spans.length;o++){const i=this.spans[o];this.stylesEqual(e.style,i.style)?e={text:e.text+i.text,style:e.style}:(t.push(e),e=i)}t.push(e),this.spans=t}stylesEqual(t,e){return t.color===e.color&&t.fontFamily===e.fontFamily&&t.fontSize===e.fontSize&&t.bold===e.bold&&t.italic===e.italic&&t.underline===e.underline&&t.strikethrough===e.strikethrough}clone(){return new Y(this.spans.map(t=>({text:t.text,style:{...t.style}})))}clearStyleProperty(t){for(const e of this.spans)e.style[t]!==void 0&&delete e.style[t];this.normalize()}toJSON(){return{spans:this.spans}}static fromJSON(t){return new Y(t.spans)}}function Eo(s){return s.type==="custom"}function Oo(s){return s.type==="circle"}function Po(s){return s.type==="arch"}function Bo(s){return s.type==="wave"}function Ro(s){return s.type==="flag"}function Do(s){return s.type==="image"}function Lo(s){return s.type==="group"}function Ho(s){return s.transformType!=="image"&&s.transformType!=="group"}function Wo(s){return s.transformType==="image"}function _o(s){return s.transformType==="custom"}function zo(s){return s.transformType==="circle"}function Xo(s){return s.transformType==="group"}function No(s){return s.transformType==="shape"}function Yo(s){return s.transformType==="path"}function Uo(s){return s.type==="shape"}function Go(s){return s.type==="path"}function $o(s){var t;return((t=s.stroke)==null?void 0:t.enabled)===!0}function Vo(s){return Array.isArray(s.masks)&&s.masks.length>0}function Jo(s){return s.blendMode==="knockout"||s.blendMode==="clip"}function qo(s){var t;return((t=s.distressEffect)==null?void 0:t.enabled)===!0}class Q extends it{constructor(t={}){super(t),this.transformType=t.transformType||"custom",this.fontSize=t.fontSize||72,this.fontFamily=t.fontFamily||"Arial",this.color=t.color||"#333333",this.bold=t.bold!==void 0?t.bold:!1,this.italic=t.italic!==void 0?t.italic:!1,this.underline=t.underline!==void 0?t.underline:!1,this.strikethrough=t.strikethrough!==void 0?t.strikethrough:!1,this.textAlign=t.textAlign||"center",t.richText?(t.richText instanceof Y?this.richText=t.richText:this.richText=Y.fromJSON(t.richText),this.text=this.richText.getText()):t.text!==void 0?(this.text=t.text,this.richText=Y.fromPlainText(t.text,{})):(this.text="Text",this.richText=Y.fromPlainText("Text",{})),this.glyphOverrides=t.glyphOverrides,this.openTypeFeatures=t.openTypeFeatures}getBoundingBox(){throw new Error("getBoundingBox() must be implemented by subclass")}render(t,e=!1,o=!1){throw new Error("render() must be implemented by subclass")}toJSON(){return{...super.toJSON(),...this.richText&&{richText:this.richText.toJSON()},text:this.text,fontSize:this.fontSize,fontFamily:this.fontFamily,color:this.color,textAlign:this.textAlign,bold:this.bold,italic:this.italic,underline:this.underline,strikethrough:this.strikethrough,...this.openTypeFeatures&&{openTypeFeatures:{...this.openTypeFeatures}},...this.glyphOverrides&&{glyphOverrides:this.glyphOverrides.map(e=>({...e}))}}}clone(){const t=this.constructor;return new t(this.toJSON())}setText(t){this.text=t,this.richText=Y.fromPlainText(t,{})}getText(){var t;return((t=this.richText)==null?void 0:t.getText())||this.text}getRichText(){return this.richText||(this.richText=Y.fromPlainText(this.text,{})),this.richText}setRichText(t){this.richText=t,this.text=t.getText()}getDefaultStyle(){return{color:this.color,fontFamily:this.fontFamily,fontSize:this.fontSize,bold:this.bold,italic:this.italic,underline:this.underline,strikethrough:this.strikethrough}}applyFormatting(t,e,o){const i=this.getRichText();i.applyStyle(t,e,o),this.text=i.getText()}setFontSize(t){this.fontSize=Math.max(ge,Math.min(ue,t))}setColor(t){const e=this.color;if(this.color=t,this.richText)for(let o=0;o<this.richText.spans.length;o++){const i=this.richText.spans[o];(i.style.color===void 0||i.style.color===e)&&(i.style.color=t)}}resize(t,e,o,i){throw new Error("resize() must be implemented by subclass")}getTransformStartData(){return{...super.getTransformStartData(),fontSize:this.fontSize,richText:this.richText?this.richText.clone():null}}}let At=null;function Pt(){if(!At)if(typeof document<"u")At=document.createElement("canvas");else if(typeof OffscreenCanvas<"u")At=new OffscreenCanvas(1,1);else throw new Error("No canvas available for text measurement");return At}function ft(s,t,e=!1,o=!1){const i=[];return o&&i.push("italic"),e&&i.push("bold"),i.push(`${s}px`),i.push(t),i.join(" ")}function Bt(s,t,e,o,i=!1,r=!1,a,h=!1){const l=Pt().getContext("2d");if(l.font=ft(e,o,i,r),s.trim().length===0)return[s];if(s.includes(`
2
+ `)){const v=s.split(`
3
+ `),k=[];for(let T=0;T<v.length;T++){const E=v[T],P=Bt(E,t,e,o,i,r,void 0,h);k.push(...P)}return k}const c=s.match(/^\s*/),f=s.match(/\s*$/),d=c?c[0]:"",g=f?f[0]:"",p=s.substring(d.length,s.length-g.length).split(" ");if(a!==void 0&&a>0){if(a===1)return[d+p.join(" ")+g];const v=[],k=Math.ceil(p.length/a);for(let T=0;T<p.length;T+=k){const E=p.slice(T,T+k);v.push(E.join(" "))}return v.length>0&&(v[0]=d+v[0],v[v.length-1]=v[v.length-1]+g),v}const m=p.join(" "),y=d+m+g,S=l.measureText(y).width,b=t<200,x=h?0:Math.max(20,t*(h?0:b?.08:.05));if(S<=t+x)return[y];const C=[];let A="";const F=h?0:Math.max(15,t*(h?0:b?.05:.03));for(let v=0;v<p.length;v++){const k=p[v];if(l.measureText(k).width>t+F){A.length>0&&(C.push(A),A="");const E=Array.from(k);let P="";for(const D of E){const B=P+D;l.measureText(B).width>t+F&&P.length>0?(C.push(P),P=D):P=B}A=P}else{const E=A.length>0?A+" "+k:k;l.measureText(E).width>t+F&&A.length>0?(C.push(A),A=k):A=E}}if(A.length>0&&C.push(A),C.length>0){if(d.length>0){const v=d+C[0];l.measureText(v).width>t+F?C.unshift(d):C[0]=v}if(g.length>0){const v=C.length-1,k=C[v]+g;l.measureText(k).width>t+F?C.push(g):C[v]=k}}return C}function Et(s,t,e,o=!1,i=!1){const a=Pt().getContext("2d");return a.font=ft(t,e,o,i),a.measureText(s).width}function St(s,t,e=!1,o=!1){const r=Pt().getContext("2d");r.font=ft(s,t,e,o);const h=r.measureText("ÁÉÍgjpqy"),n=h.actualBoundingBoxAscent||s*.8,l=h.actualBoundingBoxDescent||s*.2,c=n+l;return{ascent:n,descent:l,height:c}}function Tt(s,t,e,o,i=!1,r=!1,a,h=!1){const n=Bt(s,t,e,o,i,r,a,h),l=s.includes(`
4
+ `),c=n.map((S,b)=>({isParagraphStart:!l&&b===0,isParagraphEnd:!l&&b===n.length-1})),d=Pt().getContext("2d");d.font=ft(e,o,i,r);let g=0;const u=St(e,o,i,r);let p=0;n.forEach((S,b)=>{const w=c[b].isParagraphStart,x=c[b].isParagraphEnd;let C=S;if(!w){const A=S.match(/^ +/),M=A?A[0].length:0;M>0&&(C=C.substring(M))}if(!x){const A=C.match(/ +$/),M=A?A[0].length:0;M>0&&(C=C.substring(0,C.length-M))}if(p++,C.length>0){const A=d.measureText(C).width;g=Math.max(g,A)}});let m;const y=Ct;if(p===1)m=u.height;else if(p===0)m=0;else{const S=e*y;m=(p-1)*S+u.height}return{width:g,height:m,lines:n}}function jo(s,t){if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(s,t);const e=document.createElement("canvas");return e.width=s,e.height=t,e}function ct(s,t,e){if(e!=null&&e.enabled)if(s.strokeStyle=e.color,s.lineWidth=e.width,s.lineCap=e.lineCap||"round",s.lineJoin=e.lineJoin||"round",e.miterLimit!==void 0&&(s.miterLimit=e.miterLimit),e.opacity!==void 0){const o=s.globalAlpha;s.globalAlpha=e.opacity,s.strokeText(t,0,0),s.globalAlpha=o}else s.strokeText(t,0,0)}function gt(s,t,e){const o=t.stroke,i=(o==null?void 0:o.opacity)??1,r=s.globalAlpha,a=(o==null?void 0:o.enabled)&&i<1,h=(o==null?void 0:o.enabled)&&r<1;if(!(a||h)){e(s,t);return}const l=t.fontSize||24,c=o.width||0,f=t.transformData,d=l*t.text.length*.7,g=f.width??(f.radius?f.radius*2:0),u=Math.max(g,d),p=(o.feather||0)*2,m=c*4+p+l+40,y=u+m,S=f.archHeight?Math.abs(f.archHeight)*l*2:0,b=f.radius?f.radius:0,w=l*3+m+S+b,x=s.getTransform(),C=Math.max(Math.abs(x.a),Math.abs(x.d),1),A=Math.ceil(y*C/2)*2,M=Math.ceil(w*C/2)*2;if(A<=0||M<=0){e(s,t);return}const F=jo(A,M),v=F.getContext("2d");if(!v){e(s,t);return}const k=t.x||0,T=t.y||0,E=x.a*k+x.c*T+x.e,P=x.b*k+x.d*T+x.f,D=Math.round(E-A/2),B=Math.round(P-M/2);if(v.setTransform(x.a,x.b,x.c,x.d,A/2-E+x.e,M/2-P+x.f),h){v.globalAlpha=1;const z=o.opacity;a&&(o.opacity=1),e(v,t),a&&(o.opacity=z),s.save(),s.resetTransform(),s.globalAlpha=r,s.drawImage(F,D,B),s.restore();return}const O=o.opacity;o.opacity=1,e(v,t),o.opacity=O;const L=o.enabled;o.enabled=!1,e(s,t),o.enabled=L,s.save(),s.resetTransform(),s.globalAlpha=i,s.drawImage(F,D,B),s.restore()}function ye(s,t){gt(s,t,Zo)}function Zo(s,t){const e=t.transformData;s.save(),s.translate(t.x,t.y),s.rotate(-t.rotation*Math.PI/180),s.scale(e.scale,e.scale);const o=t.bold?"bold":"normal",i=t.italic?"italic":"normal";s.font=`${i} ${o} ${t.fontSize}px ${t.fontFamily}`,s.fillStyle=t.color,s.textAlign="center",s.textBaseline="middle";const r=t.text.split(""),a=r.map(n=>s.measureText(n).width),h=a.reduce((n,l)=>n+l,0);if(e.reverse){let n=Math.PI/2+h/(2*e.radius);r.forEach((l,c)=>{const d=a[c]/e.radius,g=Math.cos(n-d/2)*e.radius,u=Math.sin(n-d/2)*e.radius;s.save(),s.translate(g,u),s.rotate(n-d/2-Math.PI/2),ct(s,l,t.stroke),s.fillText(l,0,0),s.restore(),n-=d})}else{let n=-Math.PI/2-h/(2*e.radius);r.forEach((l,c)=>{const d=a[c]/e.radius,g=Math.cos(n+d/2)*e.radius,u=Math.sin(n+d/2)*e.radius;s.save(),s.translate(g,u),s.rotate(n+d/2+Math.PI/2),ct(s,l,t.stroke),s.fillText(l,0,0),s.restore(),n+=d})}s.restore()}function we(s,t){gt(s,t,Ko)}function Ko(s,t){const e=t.transformData;s.save(),s.translate(t.x,t.y),s.rotate(-t.rotation*Math.PI/180),s.font=_(t.fontSize,t.fontFamily,t.bold,t.italic),s.fillStyle=t.color,s.textAlign="center",s.textBaseline="middle";const o=t.text.split("");let r=-o.reduce((a,h)=>a+s.measureText(h).width,0)/2;o.forEach(a=>{const h=s.measureText(a).width,n=r+h/2,l=n/(e.width/2),c=e.amplitude*t.fontSize*Math.sin(e.frequency*Math.PI*l),f=e.amplitude*e.frequency*Math.PI*Math.cos(e.frequency*Math.PI*l);s.save(),s.translate(n,c),s.transform(1,f*Jt,0,1,0,0),ct(s,a,t.stroke),s.fillText(a,0,0),s.restore(),r+=h}),s.restore()}function be(s,t){gt(s,t,Qo)}function Qo(s,t){const e=t.transformData;s.save(),s.translate(t.x,t.y),s.rotate(-t.rotation*Math.PI/180),s.font=_(t.fontSize,t.fontFamily,t.bold,t.italic),s.fillStyle=t.color,s.textAlign="center",s.textBaseline="middle";const o=t.text.split(""),i=o.reduce((h,n)=>h+s.measureText(n).width,0),r=e.width/2;let a=-i/2;o.forEach(h=>{const n=s.measureText(h).width,l=a+n/2,c=l/r,f=(Math.pow(c,2)-1)*e.archHeight*t.fontSize,d=2*c*e.archHeight;s.save(),s.translate(l,f),s.transform(1,d*.3,0,1,0,0),ct(s,h,t.stroke),s.fillText(h,0,0),s.restore(),a+=n}),s.restore()}function Se(s,t){gt(s,t,ti)}function ti(s,t){const e=t.transformData;s.save(),s.translate(t.x,t.y),s.rotate(-t.rotation*Math.PI/180),s.font=_(t.fontSize,t.fontFamily,t.bold,t.italic),s.fillStyle=t.color,s.textAlign="center",s.textBaseline="middle";const o=t.text.split(""),i=o.reduce((h,n)=>h+s.measureText(n).width,0),r=e.ascendAngle*Math.PI/180;let a=-i/2;o.forEach(h=>{const n=s.measureText(h).width,l=a+n/2,c=l*Math.tan(r),f=Math.tan(r);s.save(),s.translate(l,c),s.transform(1,f*1,0,1,0,0),ct(s,h,t.stroke),s.fillText(h,0,0),s.restore(),a+=n}),s.restore()}function Te(s,t){gt(s,t,ei)}function ei(s,t){var i;const e=t.transformData;s.save(),s.translate(t.x,t.y),s.rotate(-t.rotation*Math.PI/180);const o=-e.leanAmount*Math.PI/4;s.transform(1,0,Math.tan(o),1,0,0),s.font=_(t.fontSize,t.fontFamily,t.bold,t.italic),s.fillStyle=t.color,s.textAlign="center",s.textBaseline="middle",(i=t.stroke)!=null&&i.enabled&&(s.save(),s.strokeStyle=t.stroke.color,s.lineWidth=t.stroke.width,s.lineCap=t.stroke.lineCap||"round",s.lineJoin=t.stroke.lineJoin||"round",t.stroke.opacity!==void 0&&(s.globalAlpha=t.stroke.opacity),s.strokeText(t.text,0,0),s.restore()),s.fillText(t.text,0,0),s.restore()}function xe(s,t){gt(s,t,oi)}function oi(s,t){const e=t.transformData;s.save(),s.translate(t.x,t.y),s.rotate(-t.rotation*Math.PI/180),s.font=_(t.fontSize,t.fontFamily,t.bold,t.italic),s.fillStyle=t.color,s.textAlign="center",s.textBaseline="middle";const o=t.text.split("");let r=-o.reduce((a,h)=>a+s.measureText(h).width,0)/2;o.forEach(a=>{const h=s.measureText(a).width,n=r+h/2,l=n/(e.width/2),c=Math.abs(l),f=e.amplitude*c,d=f*t.fontSize*Math.sin(e.frequency*Math.PI*l),g=f*e.frequency*Math.PI*Math.cos(e.frequency*Math.PI*l),u=e.amplitude*Math.sign(l)*Math.sin(e.frequency*Math.PI*l),p=g+u;s.save(),s.translate(n,d),s.transform(1,p*.3,0,1,0,0),ct(s,a,t.stroke),s.fillText(a,0,0),s.restore(),r+=h}),s.restore()}function ii(s,t,e){var l;s.translate(t.x||0,t.y||0),s.rotate(-(t.rotation||0)*Math.PI/180);const o=t,i=o.fontSize||24,r=o.fontFamily||"Arial",a=o.bold||!1,h=o.italic||!1;s.font=ft(i,r,a,h);const n=o.text||"";if(t.transformType==="custom"){const f=((l=t.transformData)==null?void 0:l.width)||200,d=Et(n,i,r,a,h),g=Math.min(d,f),u=i*1.2;s.rect(-g/2,-u/2,g,u)}else{const c=s.measureText(n).width;s.beginPath(),s.moveTo(-c/2,0),s.lineTo(c/2,0),s.moveTo(-c/2,-i),s.lineTo(c/2,-i),s.moveTo(-c/2,i*.2),s.lineTo(c/2,i*.2)}}function Ce(s,t){if(!t.transformData)return;const{borderRadius:e=0}=t.transformData,o=t.transformData.width??100,i=t.transformData.height??100;if(s.translate(t.x||0,t.y||0),s.rotate(-(t.rotation||0)*Math.PI/180),s.beginPath(),e>0){const r=Math.min(o,i)/2,a=Math.min(e,r),h=-o/2,n=-i/2;s.moveTo(h+a,n),s.lineTo(h+o-a,n),s.arcTo(h+o,n,h+o,n+a,a),s.lineTo(h+o,n+i-a),s.arcTo(h+o,n+i,h+o-a,n+i,a),s.lineTo(h+a,n+i),s.arcTo(h,n+i,h,n+i-a,a),s.lineTo(h,n+a),s.arcTo(h,n,h+a,n,a),s.closePath()}else s.rect(-o/2,-i/2,o,i)}function si(s,t,e,o){s.beginPath(),s.arc(t,e,o,0,Math.PI*2),s.closePath()}function ri(s,t,e,o,i){s.beginPath(),s.rect(t,e,o,i),s.closePath()}function qt(s,t){s.strokeStyle=t.color,s.lineWidth=t.width,s.lineCap=t.lineCap||"butt",s.lineJoin=t.lineJoin||"miter",t.miterLimit!==void 0&&(s.miterLimit=t.miterLimit),t.dashArray&&t.dashArray.length>0?s.setLineDash(t.dashArray):s.setLineDash([]),t.opacity!==void 0&&(s.globalAlpha=t.opacity)}function ni(s,t){if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(s,t);const e=document.createElement("canvas");return e.width=s,e.height=t,e}function ve(s,t,e){var n;if(!((n=t.stroke)!=null&&n.enabled))return;const o=t;if(!(o.text||""))return;const r=(e==null?void 0:e.isKnockout)===!0,a=t.stroke.opacity??1;if(!r&&a<1)try{ai(s,t,o,e,a)}catch{wt(s,t,o,e,!1)}else wt(s,t,o,e,r)}function ai(s,t,e,o,i){var M,F;const r=e.text||"",a=e.fontSize||24,h=t.stroke.width,n=t.stroke.feather||0,l=t.transformType==="custom"&&((M=t.transformData)==null?void 0:M.width),c=l?((F=t.transformData)==null?void 0:F.width)??200:0,f=l?c+h*2+n*2+40:a*r.length*.7+h*2+n*2+40,d=a*3+h*2+n*2+40,g=s.getTransform(),u=Math.max(Math.abs(g.a),Math.abs(g.d),1),p=Math.ceil(f*u/2)*2,m=Math.ceil(d*u/2)*2;if(p<=0||m<=0){wt(s,t,e,o,!1);return}const y=ni(p,m),S=y.getContext("2d");if(!S){wt(s,t,e,o,!1);return}const b=t.x||0,w=t.y||0,x=g.a*b+g.c*w+g.e,C=g.b*b+g.d*w+g.f;S.setTransform(g.a,g.b,g.c,g.d,p/2-x+g.e,m/2-C+g.f);const A=t.stroke.opacity;t.stroke.opacity=1,wt(S,t,e,o,!1),t.stroke.opacity=A,s.save(),s.resetTransform(),s.globalAlpha=i,s.drawImage(y,Math.round(x-p/2),Math.round(C-m/2)),s.restore()}function wt(s,t,e,o,i){var g;const r=e.text||"";s.save(),o!=null&&o.positionApplied||(s.translate(t.x||0,t.y||0),s.rotate(-(t.rotation||0)*Math.PI/180));const a=e.fontSize||24,h=e.fontFamily||"Arial",n=e.bold||!1,l=e.italic||!1,c=e.textAlign||"center";s.font=`${l?"italic ":""}${n?"bold ":""}${a}px ${h}`,s.textAlign=c,s.textBaseline="alphabetic",i?(s.strokeStyle="#000000",s.globalAlpha=1):(s.strokeStyle=t.stroke.color,t.stroke.opacity!==void 0&&(s.globalAlpha=t.stroke.opacity)),s.lineWidth=t.stroke.width,s.lineCap=t.stroke.lineCap||"round",s.lineJoin=t.stroke.lineJoin||"round",t.stroke.miterLimit!==void 0&&(s.miterLimit=t.stroke.miterLimit),!i&&t.stroke.feather&&t.stroke.feather>0&&"filter"in s&&(s.filter=`blur(${t.stroke.feather}px)`);const f=St(a,h,n,l);if(t.transformType==="custom"&&((g=t.transformData)==null?void 0:g.width)){const u=t.transformData,p=(u==null?void 0:u.width)??200,m=p-N*2,{lines:y,height:S}=Tt(r,m,a,h,n,l,void 0,!0),b=-p/2,w=-S/2,x=a*Ct;y.forEach((C,A)=>{const M=A===0,F=A===y.length-1;let v=C;if(!M){const E=C.match(/^ +/),P=E?E[0].length:0;P>0&&(v=v.substring(P))}if(!F){const E=v.match(/ +$/),P=E?E[0].length:0;P>0&&(v=v.substring(0,v.length-P))}let k=b+N;c==="center"?k=b+p/2:c==="right"&&(k=b+p-N);const T=w+f.ascent+A*x;s.strokeText(v,k,T)})}else{const m=-f.height/2+f.ascent;s.strokeText(r,0,m)}s.restore()}function hi(s,t,e){var i;if(!((i=t.stroke)!=null&&i.enabled)||!t.transformData)return;const o=(e==null?void 0:e.isKnockout)===!0;s.save(),o?(s.strokeStyle="#000000",s.lineWidth=t.stroke.width,s.lineCap=t.stroke.lineCap||"butt",s.lineJoin=t.stroke.lineJoin||"miter",s.globalAlpha=1,t.stroke.miterLimit!==void 0&&(s.miterLimit=t.stroke.miterLimit)):qt(s,t.stroke),!o&&t.stroke.feather&&t.stroke.feather>0&&"filter"in s&&(s.filter=`blur(${t.stroke.feather}px)`),Ce(s,t),s.stroke(),s.restore()}function li(s,t,e){t.enabled&&(s.save(),qt(s,t),t.feather&&t.feather>0&&"filter"in s&&(s.filter=`blur(${t.feather}px)`),s.beginPath(),e(),s.stroke(),s.restore())}const Z=st("FontAnalyzer");let Ht=null;async function ci(){return Ht||(Ht=await Promise.resolve().then(()=>require("./browser-module-D0gHY9rY.cjs"))),Ht}class di{constructor(){this.fontCache=new Map,this.failedFonts=new Set,this.CACHE_DURATION=1e3*60*30,this.MAX_CACHE_SIZE=5}evictOldestFont(){if(this.fontCache.size<=this.MAX_CACHE_SIZE)return;let t=null,e=Date.now();this.fontCache.forEach((o,i)=>{o.timestamp<e&&(e=o.timestamp,t=i)}),t&&this.fontCache.delete(t)}isSystemFont(t){return vo.has(t)}getGoogleFontUrl(t,e=400){return`https://fonts.googleapis.com/css2?family=${t.replace(/\s+/g,"+")}:wght@${e}&display=swap`}async extractFontFileUrl(t,e=400){try{const o=this.getGoogleFontUrl(t,e),r=await(await fetch(o)).text(),a=/@font-face\s*{([^}]*)}/g,h=Array.from(r.matchAll(a));if(h.length===0)return Z.warn("No @font-face found in CSS"),null;let n=null,l=-1;for(let c=0;c<h.length;c++){const f=h[c][1],d=f.match(/url\((https:\/\/fonts\.gstatic\.com\/[^)]+)\)/),g=f.includes("unicode-range"),u=f.match(/unicode-range:\s*([^;]+);/);if(!d)continue;const p=d[1];let m=0;g?u&&(m=(u[1].match(/U\+/g)||[]).length):m=1e3,m>l&&(l=m,n=p)}return n||(Z.warn("No font URL found in CSS for",t),null)}catch(o){return Z.error("Error extracting font file URL:",o),null}}async loadFont(t,e=400){if(this.isSystemFont(t))return null;const o=`${t}-${e}`;if(this.failedFonts.has(o))return null;const i=this.fontCache.get(o);if(i&&Date.now()-i.timestamp<this.CACHE_DURATION)return i.timestamp=Date.now(),i.font;try{const r=await this.extractFontFileUrl(t,e);if(!r)return this.failedFonts.add(o),null;const a=await fetch(r);if(!a.ok)return Z.error(`Font fetch failed: ${a.status} ${a.statusText}`),this.failedFonts.add(o),null;const h=await a.arrayBuffer(),n=new Uint8Array(h),c=(await ci()).create(n),f="fonts"in c?c.fonts[0]:c;return this.fontCache.set(o,{font:f,url:r,timestamp:Date.now()}),this.evictOldestFont(),f}catch(r){return Z.error(`Error loading font ${t}:`,r),this.failedFonts.add(o),null}}getFontSync(t,e=400){const o=`${t}-${e}`,i=this.fontCache.get(o);return i&&Date.now()-i.timestamp<this.CACHE_DURATION?(i.timestamp=Date.now(),i.font):null}clearCache(t,e){if(t){const o=`${t}-${e||400}`;this.fontCache.delete(o),this.failedFonts.delete(o)}else this.fontCache.clear(),this.failedFonts.clear()}async getAllGlyphs(t,e=400,o=1500){var h,n;if(this.isSystemFont(t))return[];const i=await this.loadFont(t,e);if(!i)return[];const r=[],a=Math.min(i.numGlyphs,o);for(let l=0;l<a;l++)try{const c=i.getGlyph(l);if(!c||!c.name||c.name===".notdef"||c.name.startsWith(".null"))continue;const f=c.codePoints||[];let d=f.length>0?String.fromCodePoint(f[0]):"";if(!d||d.length===0){const m=c.name.match(/^([A-Za-z0-9])[._]/);m&&(d=m[1])}let g=c.name;if(d&&d.length>0&&/\S/.test(d))if(c.name.includes(".swash"))g=`${d} Swash`;else if(c.name.match(/\.alt(\d+)?/)){const m=((h=c.name.match(/\.alt(\d+)/))==null?void 0:h[1])||"";g=`${d} Alternate${m?" "+m:""}`}else if(c.name.match(/\.ss(\d+)/)){const m=(n=c.name.match(/\.ss(\d+)/))==null?void 0:n[1];g=`${d} Stylistic Set ${m}`}else g=`${d} - ${c.name}`;let u="default";const p=c.name.toLowerCase();if(p.includes("swash")||p.includes("cswh")?u="swash":c.name.match(/\.(alt|ss\d+|cv\d+|salt|ornament)/)||c.name.match(/_\d+$/)?u="stylistic":p.match(/liga|dlig/)&&(u="ligature"),u==="default")continue;d&&d.length>0&&r.push({glyphIndex:c.id,unicode:d,name:g,category:u,previewDataUrl:this.generateGlyphPreview(i,c.id,80)})}catch{}return r}async getGlyphAlternates(t,e,o=400){var l,c,f,d;const i=await this.loadFont(t,o);if(!i)return[];const r=[],a=e.codePointAt(0);if(a===void 0)return[];const h=i.glyphForCodePoint(a);h&&r.push({glyphIndex:h.id,unicode:e,name:h.name||"Default",category:"default",previewDataUrl:this.generateGlyphPreview(i,h.id,80)});const n=h==null?void 0:h.name;if(n){let g=0;for(let u=0;u<i.numGlyphs;u++)try{const p=i.getGlyph(u);if(!p||!p.name)continue;if([new RegExp(`^${n}\\.(swash|alt|ss\\d+|salt|ornament)`,"i"),new RegExp(`^${n}_\\d+$`,"i"),new RegExp(`^${n}\\.\\d+$`,"i")].some(S=>S.test(p.name))&&p.id!==h.id){g++;let S=p.name;if(p.name.includes(".swash"))S=`${e} Swash`;else if(p.name.match(/\.alt(\d+)?/)){const b=((l=p.name.match(/\.alt(\d+)/))==null?void 0:l[1])||"";S=`${e} Alternate${b?" "+b:""}`}else if(p.name.match(/\.ss(\d+)/)){const b=(c=p.name.match(/\.ss(\d+)/))==null?void 0:c[1];S=`${e} Stylistic Set ${b}`}r.push({glyphIndex:p.id,unicode:e,name:S,category:"stylistic",previewDataUrl:this.generateGlyphPreview(i,p.id,80)})}}catch{}}if(i.GSUB){const g=i.GSUB;if(g.featureList)for(const u of g.featureList){const p=u.tag;if(this.isRelevantFeature(p)&&u.feature&&u.feature.lookupListIndexes)for(const m of u.feature.lookupListIndexes){const y=(d=(f=g.lookupList)==null?void 0:f.lookups)==null?void 0:d[m];if(y){if(y.lookupType===1)for(const S of y.subtables||[]){const b=S.coverage;if(!b)continue;if(this.getCoverageIndex(b,h.id)!==-1){const x=this.getSubstituteGlyph(S,h.id);x!==null&&r.push({glyphIndex:x,unicode:e,name:`${e} (${p})`,category:this.categorizeFeature(p),previewDataUrl:this.generateGlyphPreview(i,x,80)})}}else if(y.lookupType===3)for(const S of y.subtables||[]){const b=S.coverage;if(!b)continue;const w=this.getCoverageIndex(b,h.id),x=S;if(w!==-1&&x.alternateSets){const C=x.alternateSets[w];if(C)for(const A of C)r.push({glyphIndex:A,unicode:e,name:`${e} (${p} alt)`,category:this.categorizeFeature(p),previewDataUrl:this.generateGlyphPreview(i,A,80)})}}}}}}return r}async getAvailableFeatures(t,e=400){const o=await this.loadFont(t,e);if(!o)return Z.warn(`Font ${t} failed to load`),[];try{const i=[];if(o.GSUB&&o.GSUB.featureList){const r=new Set;for(const a of o.GSUB.featureList)a.tag&&r.add(a.tag);i.push(...Array.from(r))}if(o.GPOS&&o.GPOS.featureList){const r=new Set;for(const a of o.GPOS.featureList)a.tag&&r.add(a.tag);i.push(...Array.from(r))}return i}catch(i){return Z.error(`Error getting features for ${t}:`,i),[]}}generateGlyphPreview(t,e,o=80){const i=document.createElement("canvas");i.width=o,i.height=o;const r=i.getContext("2d");if(!r)return"";try{const a=t.getGlyph(e);if(!a)return"";r.clearRect(0,0,o,o);const h=a.bbox;if(!h)return"";const n=h.maxX-h.minX,l=h.maxY-h.minY;if(n===0||l===0)return"";const f=Math.min(o/n,o/l)*.6,d=(h.minX+h.maxX)/2,g=(h.minY+h.maxY)/2,u=o/2,p=o/2,m=a.path.toSVG();if(!m)return"";const y=new Path2D(m);return r.save(),r.translate(u,p),r.scale(f,-f),r.translate(-d,-g),r.fillStyle="#000000",r.fill(y),r.restore(),i.toDataURL("image/png")}catch(a){return Z.error("Error generating glyph preview:",a),""}}isRelevantFeature(t){return["swsh","cswh","salt","ss01","ss02","ss03","ss04","ss05","ss06","ss07","ss08","ss09","ss10","ss11","ss12","ss13","ss14","ss15","ss16","ss17","ss18","ss19","ss20","cv01","cv02","cv03","cv04","cv05","cv06","cv07","cv08","cv09","cv10","aalt","dlig","liga"].includes(t)}categorizeFeature(t){return t.startsWith("swsh")||t==="cswh"?"swash":t.startsWith("ss")||t.startsWith("cv")||t==="salt"?"stylistic":t==="liga"||t==="dlig"?"ligature":t==="calt"?"contextual":"stylistic"}getCoverageIndex(t,e){if(!t)return-1;if(t.format===1&&t.glyphs)return t.glyphs.indexOf(e);if(t.format===2&&t.ranges){const o=t.ranges;for(let i=0;i<o.length;i++){const r=o[i];if(e>=r.start&&e<=r.end)return r.index+(e-r.start)}}return-1}getSubstituteGlyph(t,e){if(!t)return null;if(t.substFormat===1&&typeof t.deltaGlyphId=="number")return e+t.deltaGlyphId;if(t.substFormat===2&&t.substitute){const o=this.getCoverageIndex(t.coverage,e),i=t.substitute;if(o!==-1&&i[o]!==void 0)return i[o]}return null}async getAlternateGlyphCount(t,e=400){const o=await this.loadFont(t,e);if(!o)return 0;let i=0;const r=Math.min(o.numGlyphs,1500);for(let a=0;a<r;a++)try{const h=o.getGlyph(a);if(!h||!h.name||h.name===".notdef"||h.name.startsWith(".null"))continue;const n=h.codePoints||[];let l=n.length>0?String.fromCodePoint(n[0]):"";if(!l||l.length===0){const d=h.name.match(/^([A-Za-z0-9])[._]/);d&&(l=d[1])}let c="default";const f=h.name.toLowerCase();f.includes("swash")||f.includes("cswh")?c="swash":h.name.match(/\.(alt|ss\d+|cv\d+|salt|ornament)/)||h.name.match(/_\d+$/)?c="stylistic":f.match(/liga|dlig/)&&(c="ligature"),c!=="default"&&l&&l.length>0&&i++}catch{}return i}getCacheStats(){return{size:this.fontCache.size,entries:Array.from(this.fontCache.keys())}}}const Nt=new di,ie=st("GlyphRenderer");function fi(s,t,e,o,i,r,a,h={}){try{const n=[];Object.entries(a).forEach(([m,y])=>{y&&n.push(m)});const l=[];t.GSUB&&t.GSUB.featureList&&t.GSUB.featureList.forEach(m=>{l.push(m.tag)});const c={};c.ccmp=!0,c.locl=!0,c.kern=!0,n.forEach(m=>{c[m]=!0}),c.calt&&(c.liga=!0,c.init=!0,c.fina=!0);const f=t.layout(e,c,"latn"),d=r/t.unitsPerEm;let g=0;f.glyphs.forEach(m=>{g+=m.advanceWidth*d});let u=o;h.align==="center"?u=o-g/2:h.align==="right"&&(u=o-g),s.save(),s.fillStyle=h.color||"#000000";let p=u;f.glyphs.forEach((m,y)=>{const S=f.positions[y];let b=null;try{if(m.path&&typeof m.path.toPath=="function")b=m.path.toPath();else if(m.path&&typeof m.path.toSVG=="function"){const w=m.path.toSVG();if(w&&/^[MmLlHhVvCcSsQqTtAaZz]/.test(w))b=w;else{const x=w==null?void 0:w.match(/\bd=["']([^"']+)["']/);b=x?x[1]:null}}}catch(w){ie.warn("Error getting path for glyph:",m.name,w)}if(b){const w=new Path2D(b);s.save(),s.translate(p+S.xOffset*d,i+S.yOffset*d),s.scale(d,-d),s.fill(w),s.restore()}p+=m.advanceWidth*d}),s.restore()}catch(n){ie.error("Error rendering with fontkit:",n),s.fillStyle=h.color||"#000000",s.textAlign=h.align||"left",s.fillText(e,o,i)}}function gi(s,t,e,o,i,r,a,h={}){const l=(m=>{for(const y of m){const S=y.codePointAt(0);if(S&&S>=983040&&S<=1048573)return!0}return!1})(e);if((!a||a.length===0)&&!l){s.fillStyle=h.color||"#000000",s.textAlign=h.align||"left",s.fillText(e,o,i);return}const c=new Map;a&&a.forEach(m=>{c.set(m.charIndex,m.glyphIndex)});const f=r/t.unitsPerEm,d=Array.from(e);let g=0;d.forEach((m,y)=>{const S=m.codePointAt(0)||0;let b;if(S>=983040&&S<=1048573)b=S-983040;else if(b=c.get(y),b===void 0){const x=t.glyphForCodePoint(S);b=x?x.id:0}const w=t.getGlyph(b);w&&(g+=w.advanceWidth*f)});let u=o;h.align==="center"?u=o-g/2:h.align==="right"&&(u=o-g),s.save(),s.fillStyle=h.color||"#000000";let p=u;d.forEach((m,y)=>{const S=m.codePointAt(0)||0;let b;if(S>=983040&&S<=1048573)b=S-983040;else if(b=c.get(y),b===void 0){const x=t.glyphForCodePoint(S);b=x?x.id:0}const w=t.getGlyph(b);if(w){const x=w.path.toSVG();if(x){const C=new Path2D(x);s.save(),s.translate(p,i),s.scale(f,-f),s.fill(C),s.restore()}p+=w.advanceWidth*f}}),s.restore()}function jt(s,t,e){const o=ui(),i=[],r=(m,y)=>{const S=y.fontSize||e.fontSize,b=y.fontFamily||e.fontFamily,w=y.bold!==void 0?y.bold:e.bold||!1,x=y.italic!==void 0?y.italic:e.italic||!1;return o.font=_(S,b,w,x),o.measureText(m).width},a=(m,y)=>m.fontSize===y.fontSize&&m.fontFamily===y.fontFamily&&m.color===y.color&&m.bold===y.bold&&m.italic===y.italic&&m.underline===y.underline&&m.strikethrough===y.strikethrough,h=[];s.forEach(m=>{h.length>0&&a(h[h.length-1].style,m.style)?h[h.length-1].text+=m.text:h.push({text:m.text,style:m.style})});let n="";const l=[];h.forEach((m,y)=>{for(let S=0;S<m.text.length;S++)n+=m.text[S],l.push(y)});const c=[];let f="",d=0;for(let m=0;m<n.length;m++){const y=n[m];y===" "?(f.length>0&&(c.push({text:f,startIdx:d,endIdx:m-1}),f=""),c.push({text:" ",startIdx:m,endIdx:m})):(f.length===0&&(d=m),f+=y)}f.length>0&&c.push({text:f,startIdx:d,endIdx:n.length-1});let g=[],u=0;const p=()=>{g.length>0&&(i.push(g),g=[],u=0)};return c.forEach((m,y)=>{const S=[];let b=l[m.startIdx],w="";for(let C=m.startIdx;C<=m.endIdx;C++){const A=l[C];A!==b?(S.push({text:w,style:h[b].style}),w=n[C],b=A):w+=n[C]}w.length>0&&S.push({text:w,style:h[b].style});const x=S.reduce((C,A)=>C+r(A.text,A.style),0);if(m.text===" "){if(g.length>0){const C=g[g.length-1];a(C.style,S[0].style)?C.text+=" ":g.push({text:" ",style:S[0].style})}else g.push({text:" ",style:S[0].style});u+=x}else if(x>t){g.length>0&&p();for(const C of S){const A=Array.from(C.text);let M="";for(const F of A){const v=r(F,C.style);if(u+v>t&&u>0){if(M.length>0){if(g.length>0){const k=g[g.length-1];a(k.style,C.style)?k.text+=M:g.push({text:M,style:C.style})}else g.push({text:M,style:C.style});M=""}p()}M+=F,u+=v}if(M.length>0)if(g.length>0){const F=g[g.length-1];a(F.style,C.style)?F.text+=M:g.push({text:M,style:C.style})}else g.push({text:M,style:C.style})}}else u+x>t&&g.length>0&&p(),S.forEach(C=>{if(g.length>0){const A=g[g.length-1];a(A.style,C.style)?A.text+=C.text:g.push({...C})}else g.push({...C})}),u+=x}),p(),i.length===0&&i.push([]),i}function Zt(s){const t=[];let e=[];return s.spans.forEach(o=>{const i=o.text.split(`
5
+ `);i.forEach((r,a)=>{r.length>0&&e.push({text:r,style:o.style}),a<i.length-1&&(t.push(e),e=[])})}),e.length>0&&t.push(e),t.length===0&&t.push([]),t}function Ae(s,t,e,o,i){s.fillStyle=e.color;const r=e.textAlign||"center",a=Zt(t);let h,n;o!==void 0&&o>0&&!i?(h=[],n=[],a.forEach(u=>{const p=jt(u,o,e);p.forEach((m,y)=>{h.push(m),n.push({isParagraphStart:y===0,isParagraphEnd:y===p.length-1})})})):(h=a,n=a.map(()=>({isParagraphStart:!0,isParagraphEnd:!0})));const l=[];h.forEach((u,p)=>{const m=[];let y=0,S=0;const b=n[p].isParagraphStart,w=n[p].isParagraphEnd;u.forEach(T=>{const E=T.style.fontSize!==void 0?T.style.fontSize:e.fontSize,P=T.style.fontFamily!==void 0?T.style.fontFamily:e.fontFamily,D=T.style.bold!==void 0?T.style.bold:e.bold||!1,B=T.style.italic!==void 0?T.style.italic:e.italic||!1;s.font=_(E,P,D,B);const O=s.measureText(T.text).width;m.push(O);const L=dt(E,P,D,B);y=Math.max(y,L.height),S=Math.max(S,L.ascent)});const x=u.map(T=>T.text).join(""),C=x.match(/^ +/),A=x.match(/ +$/),M=C?C[0].length:0,F=A?A[0].length:0;let v=0,k=0;u.forEach(T=>{const E=T.style.fontSize!==void 0?T.style.fontSize:e.fontSize,P=T.style.fontFamily!==void 0?T.style.fontFamily:e.fontFamily,D=T.style.bold!==void 0?T.style.bold:e.bold||!1,B=T.style.italic!==void 0?T.style.italic:e.italic||!1;let O=T.text;const L=k,z=k+T.text.length;if(!b&&M>0&&L<M){const X=Math.min(M-L,T.text.length);O=O.substring(X)}if(!w&&F>0){const X=x.length-F;if(z>X){const U=!b&&M>0&&L<M?Math.min(M-L,T.text.length):0,mt=Math.max(0,X-L-U);O=O.substring(0,mt)}}k+=T.text.length,O.length>0&&(s.save(),s.font=_(E,P,D,B),v+=s.measureText(O).width,s.restore())}),l.push({spans:u,width:v,height:y,ascent:S,spanWidths:m,isParagraphStart:b,isParagraphEnd:w})});const c=dt(e.fontSize,e.fontFamily,e.bold,e.italic),f=e.fontSize*Ct;let d;l.length===0?d=0:l.length===1?d=c.height:d=(l.length-1)*f+c.height;const g=-d/2;l.forEach((u,p)=>{const{spans:m,width:y,isParagraphStart:S,isParagraphEnd:b}=u;let w;r==="center"?w=-y/2:r==="right"?w=o!==void 0?o/2-y:-y:w=o!==void 0?-o/2:0;const x=g+c.ascent+p*f,C=m.map(T=>T.text).join(""),A=C.match(/^ +/),M=C.match(/ +$/),F=A?A[0].length:0,v=M?M[0].length:0;let k=0;m.forEach(T=>{const E=T.style.fontSize!==void 0?T.style.fontSize:e.fontSize,P=T.style.fontFamily!==void 0?T.style.fontFamily:e.fontFamily,D=T.style.color!==void 0?T.style.color:e.color,B=T.style.bold!==void 0?T.style.bold:e.bold||!1,O=T.style.italic!==void 0?T.style.italic:e.italic||!1,L=T.style.underline!==void 0?T.style.underline:e.underline||!1,z=T.style.strikethrough!==void 0?T.style.strikethrough:e.strikethrough||!1;let X=T.text,U=k,mt=k+T.text.length;if(!S&&F>0&&U<F){const G=Math.min(F-U,T.text.length);X=X.substring(G)}if(!b&&v>0){const G=C.length-v;if(mt>G){const J=!S&&F>0&&U<F?Math.min(F-U,T.text.length):0,Lt=Math.max(0,G-U-J);X=X.substring(0,Lt)}}if(k+=T.text.length,X.length>0){s.font=_(E,P,B,O),s.fillStyle=D,s.textBaseline="alphabetic",s.textAlign="left",s.fillText(X,w,x);const G=s.measureText(X).width;if(L){const J=x+E*.1;s.beginPath(),s.moveTo(w,J),s.lineTo(w+G,J),s.lineWidth=Math.max(1,E*.05),s.strokeStyle=D,s.stroke()}if(z){const J=x-E*.25;s.beginPath(),s.moveTo(w,J),s.lineTo(w+G,J),s.lineWidth=Math.max(1,E*.05),s.strokeStyle=D,s.stroke()}w+=G}})})}let Mt=null;function ui(){if(!Mt)if(typeof OffscreenCanvas<"u")Mt=new OffscreenCanvas(1,1).getContext("2d");else if(typeof document<"u")Mt=document.createElement("canvas").getContext("2d");else throw new Error("No canvas context available");return Mt}const Yt=st("canvas-renderer");let Ft=null;function Kt(){if(!Ft)if(typeof OffscreenCanvas<"u")Ft=new OffscreenCanvas(1,1).getContext("2d");else if(typeof document<"u")Ft=document.createElement("canvas").getContext("2d");else throw new Error("No canvas context available");return Ft}function _(s,t,e=!1,o=!1){const i=[];return o&&i.push("italic"),e&&i.push("bold"),i.push(`${s}px`),i.push(t),i.join(" ")}function Ut(s,t,e,o=!1,i=!1){const r=Kt();return r.font=_(t,e,o,i),r.measureText(s).width}function dt(s,t,e=!1,o=!1){const i=Kt();i.font=_(s,t,e,o);const a=i.measureText("ÁÉÍgjpqy"),h=a.actualBoundingBoxAscent||s*.8,n=a.actualBoundingBoxDescent||s*.2,l=h+n;return{ascent:h,descent:n,height:l}}function mi(s,t){const e=s.map((i,r)=>({isParagraphStart:!t&&r===0,isParagraphEnd:!t&&r===s.length-1}));return s.map((i,r)=>{if(i.trim().length===0)return"";const a=e[r].isParagraphStart,h=e[r].isParagraphEnd;let n=i;return a||(n=n.replace(/^ +/,"")),h||(n=n.replace(/ +$/,"")),n}).filter(i=>i.length>0)}function pi(s,t){const e=t.fontSize,o=t.fontFamily,i=t.bold||!1,r=t.italic||!1,a=t.textAlign||"center",h=t.text;s.font=_(e,o,i,r),s.textAlign=a,s.textBaseline="alphabetic",s.fillStyle=t.color;const n=dt(e,o,i,r),f=-n.height/2+n.ascent;s.fillText(h,0,f)}function Me(s,t,e,o,i=!1,r=!1,a){const h=Kt();if(h.font=_(e,o,i,r),s.trim().length===0)return[s];if(s.includes(`
6
+ `)){const M=s.split(`
7
+ `),F=[];for(let v=0;v<M.length;v++){const k=M[v],T=Me(k,t,e,o,i,r);F.push(...T)}return F}const n=s.match(/^\s*/),l=s.match(/\s*$/),c=n?n[0]:"",f=l?l[0]:"",g=s.substring(c.length,s.length-f.length).split(" ");if(a!==void 0&&a>0){if(a===1)return[c+g.join(" ")+f];const M=[],F=Math.ceil(g.length/a);for(let v=0;v<g.length;v+=F){const T=g.slice(v,v+F).join(" ");v===0&&v+F>=g.length?M.push(c+T+f):v===0?M.push(c+T):v+F>=g.length?M.push(T+f):M.push(T)}return M}const u=g.join(" "),p=c+u+f,m=h.measureText(p).width,y=t<200,b=Math.max(20,t*(y?.08:.05));if(m<=t+b)return[p];const w=[];let x=g[0];const A=Math.max(15,t*(y?.05:.03));for(let M=1;M<g.length;M++){const F=g[M],v=x+" "+F;h.measureText(v).width>t+A?(w.push(x),x=F):x=v}return w.push(x),w.length>0&&(w[0]=c+w[0],w[w.length-1]=w[w.length-1]+f),w}function yi(s,t,e,o,i,r,a="left",h=0,n=0,l=1.2,c=!1,f=!1,d=!1,g=!1,u,p){s.font=_(i,r,c,f),s.textBaseline="alphabetic",s.textAlign=a;const m=v=>{for(const k of v){const T=k.codePointAt(0);if(T&&T>=983040&&T<=1048573)return!0}return!1},y=u&&Object.values(u).some(v=>v),S=p&&p.length>0,b=t.join(" "),w=m(b),x=y||S||w,C=x?Nt.getFontSync(r,c?700:400):null;x&&!C&&(Yt.warn(`[renderMultilineText] Font ${r} not loaded for fontkit rendering. Text may not render correctly. Has PUA: ${w}, Text: "${b}"`),Nt.loadFont(r,c?700:400).catch(v=>{Yt.error("[renderMultilineText] Error loading font:",v)}));const A=dt(i,r,c,f),M=i*l;let F=0;t.forEach((v,k)=>{let T=e+n;a==="center"?T=e+h/2:a==="right"&&(T=e+h-n);const E=o+A.ascent+k*M,P=Array.from(v).length,D=S?p.filter(B=>{const O=B.charIndex-F;return O>=0&&O<P}).map(B=>({...B,charIndex:B.charIndex-F})):[];if(C&&(y||D.length>0||w)?D.length>0||m(v)?gi(s,C,v,T,E,i,D,{color:s.fillStyle,align:a==="start"||a==="end"?"left":a}):u&&fi(s,C,v,T,E,i,u,{color:s.fillStyle,align:a==="start"||a==="end"?"left":a}):s.fillText(v,T,E),F+=P+1,d){const B=Ut(v,i,r,c,f);let O=T;a==="center"?O=T-B/2:a==="right"&&(O=T-B);const L=E+i*.1;s.beginPath(),s.moveTo(O,L),s.lineTo(O+B,L),s.lineWidth=Math.max(1,i*.05),s.strokeStyle=s.fillStyle,s.stroke()}if(g){const B=Ut(v,i,r,c,f);let O=T;a==="center"?O=T-B/2:a==="right"&&(O=T-B);const L=E-i*.25;s.beginPath(),s.moveTo(O,L),s.lineTo(O+B,L),s.lineWidth=Math.max(1,i*.05),s.strokeStyle=s.fillStyle,s.stroke()}})}function nt(s,t){wi(s,t)}function wi(s,t){var i;(i=t.stroke)!=null&&i.enabled&&ve(s,t),s.save(),s.translate(t.x,t.y),s.rotate(-t.rotation*Math.PI/180);const e=t.transformData,o=((e==null?void 0:e.width)??100)-N*2;if(t.richText){const r=Y.fromJSON(t.richText);s.save(),s.translate(0,0);const a=t._lockedLineCount;Ae(s,r,{fontSize:t.fontSize,fontFamily:t.fontFamily,color:t.color,bold:t.bold,italic:t.italic,underline:t.underline,strikethrough:t.strikethrough,textAlign:t.textAlign},o,a),s.restore()}else if(t.text){s.fillStyle=t.color;const r=t._lockedLineCount,{lines:a,height:h}=Tt(t.text,o,t.fontSize,t.fontFamily,t.bold,t.italic,r,!0),n=dt(t.fontSize,t.fontFamily,t.bold,t.italic),l=-((e==null?void 0:e.width)??100)/2,c=-h/2,f=t.fontSize*Ct;s.font=`${t.italic?"italic ":""}${t.bold?"bold ":""}${t.fontSize}px ${t.fontFamily}`,s.textBaseline="alphabetic",s.textAlign=t.textAlign,a.forEach((d,g)=>{const u=g===0,p=g===a.length-1;let m=d;if(!u){const b=d.match(/^ +/),w=b?b[0].length:0;w>0&&(m=m.substring(w))}if(!p){const b=m.match(/ +$/),w=b?b[0].length:0;w>0&&(m=m.substring(0,m.length-w))}let y=l+N;t.textAlign==="center"?y=l+((e==null?void 0:e.width)??100)/2:t.textAlign==="right"&&(y=l+((e==null?void 0:e.width)??100)-N);const S=c+n.ascent+g*f;if(s.fillText(m,y,S),m.length>0){const b=s.measureText(m).width;let w=y;if(t.textAlign==="center"?w-=b/2:t.textAlign==="right"&&(w-=b),t.underline){const x=S+t.fontSize*.1;s.fillRect(w,x,b,Math.max(1,t.fontSize*.05))}if(t.strikethrough){const x=S-n.ascent*.4;s.fillRect(w,x,b,Math.max(1,t.fontSize*.05))}}})}s.restore()}function bi(s,t){var a;const e=t.opacity??1,o=!!((a=t.stroke)!=null&&a.enabled),i=t.type==="custom";if(e<1&&o&&i){Si(s,t,e);return}const r=s.globalAlpha;e!==1&&(s.globalAlpha=e),Gt(s,t),s.globalAlpha=r}function Si(s,t,e){var m;const o=t.transformData,i=t.fontSize||24,r=((m=t.stroke)==null?void 0:m.width)||0,a=((o==null?void 0:o.width)??i*t.text.length*.7)+r*2+40,h=i*3+r*2+40,n=s.getTransform(),l=Math.max(Math.abs(n.a),Math.abs(n.d),1),c=Math.ceil(a*l),f=Math.ceil(h*l);let d;typeof OffscreenCanvas<"u"?d=new OffscreenCanvas(c,f):(d=document.createElement("canvas"),d.width=c,d.height=f);const g=d.getContext("2d");if(!g){const y=s.globalAlpha;s.globalAlpha=e,Gt(s,t),s.globalAlpha=y;return}const u=n.a*t.x+n.e,p=n.d*t.y+n.f;g.setTransform(n.a,n.b,n.c,n.d,n.e-u+c/2,n.f-p+f/2),Gt(g,t),s.save(),s.setTransform(1,0,0,1,0,0),s.globalAlpha=e,s.drawImage(d,u-c/2,p-f/2),s.restore()}function Gt(s,t){switch(t.type){case"custom":nt(s,t);break;case"circle":ye(s,t);break;case"wave":we(s,t);break;case"arch":be(s,t);break;case"ascend":Se(s,t);break;case"lean":Te(s,t);break;case"flag":xe(s,t);break;default:Yt.warn(`[canvas-renderer] Unsupported transform type: ${t.type}`),nt(s,t)}}function bt(s){return typeof s.width=="number"?s.width:void 0}function Fe(s,t){s.width=t}function Ti(s,t,e){const o=e.transformData,i=bt(o),r=i!==void 0?i:e.width??0,a=t/r,h=(e.fontSize??s.fontSize)*a;let n;if(h<16?n=Math.round(h):n=Math.round(h*2)/2,s.setFontSize(n),e.richText&&e.richText instanceof Y&&typeof s.setRichText=="function"){const d=e.richText.clone();for(const g of d.spans)if(g.style.fontSize!==void 0){const u=g.style.fontSize*a;u<16?g.style.fontSize=Math.round(u):g.style.fontSize=Math.round(u*2)/2}s.setRichText(d)}const l=s.transformData;if(bt(l)!==void 0&&i!==void 0){const f=i*a;Fe(l,Math.max(20,Math.round(f)))}}function xi(s,t,e,o){if(t!=="middle-left"&&t!=="middle-right")return;s.fontSize=o.fontSize??s.fontSize;const i=s.transformData;if(bt(i)!==void 0){Fe(i,Math.max(fe,e));const a=R.toRadiansInverse(s.rotation),h=Math.cos(a),n=Math.sin(a),l=o.transformData,f=bt(l)??o.width??0,g=(bt(i)??0)-f;t==="middle-left"?(s.x=o.x-g/2*h,s.y=o.y-g/2*n):t==="middle-right"&&(s.x=o.x+g/2*h,s.y=o.y+g/2*n)}}function Ie(s,t,e,o,i){const r=t.includes("top")||t.includes("bottom"),a=t.includes("middle");r?Ti(s,e,i):a&&xi(s,t,e,i)}class ke extends Q{constructor(t={}){super(t),this.transformType="custom";const e=t.transformData,o=(e==null?void 0:e.width)!==void 0?e.width:Math.max(fe,Et(this.text,this.fontSize,this.fontFamily,this.bold,this.italic)+N*2);this.transformData={type:"custom",controlPoints:(e==null?void 0:e.controlPoints)??[],width:o}}calculateRichTextHeight(){const t=this.getRichText(),e=this.transformData.width-N*2,o=Zt(t),i=[];if(o.forEach(n=>{jt(n,e,{fontSize:this.fontSize,fontFamily:this.fontFamily,bold:this.bold,italic:this.italic}).forEach(c=>{i.push(c)})}),i.length===0)return 0;let r=0,a=0;i.forEach(n=>{n.forEach(l=>{const c=l.style.fontSize!==void 0?l.style.fontSize:this.fontSize,f=l.style.fontFamily!==void 0?l.style.fontFamily:this.fontFamily,d=l.style.bold!==void 0?l.style.bold:this.bold,g=l.style.italic!==void 0?l.style.italic:this.italic,u=St(c,f,d,g);r=Math.max(r,u.height),a=Math.max(a,u.ascent)})});const h=this.fontSize*Ct;if(i.length===1)return r;{const n=St(this.fontSize,this.fontFamily,this.bold,this.italic),l=(i.length-1)*h+n.height,c=Math.max(0,a-n.ascent),f=Math.max(0,r-a-(n.height-n.ascent));return l+c+f}}hasPerCharacterFormatting(){const t=this.getRichText();for(const e of t.spans)if(e.style.fontSize!==void 0&&e.style.fontSize!==this.fontSize||e.style.fontFamily!==void 0&&e.style.fontFamily!==this.fontFamily)return!0;return!1}getBoundingBox(){const t=this.transformData.width-N*2;let e;return this.hasPerCharacterFormatting()?e=this.calculateRichTextHeight():e=Tt(this.text,t,this.fontSize,this.fontFamily,this.bold,this.italic,this._lockedLineCount,!0).height,{x:this.x-this.transformData.width/2,y:this.y-e/2,width:this.transformData.width,height:e}}getVisualBoundingBox(){const t=this.transformData.width-N*2;let e;this.hasPerCharacterFormatting()?e=this.calculateRichTextHeight():e=Tt(this.text,t,this.fontSize,this.fontFamily,this.bold,this.italic,this._lockedLineCount,!0).height;const o=this.transformData.width;return{x:this.x-o/2,y:this.y-e/2,width:o,height:e}}getRotationAnchor(){const t=this.getVisualBoundingBox();return{x:t.x+t.width/2,y:t.y+t.height/2}}render(t,e=!1,o=!1){var n;const i=this.opacity??1,r=!!((n=this.stroke)!=null&&n.enabled);if(i<1&&r){this.renderWithOffscreen(t,i);return}const a=t.globalAlpha;i!==1&&(t.globalAlpha=i);const h=this.toJSON();nt(t,h),t.globalAlpha=a}renderWithOffscreen(t,e){var g;const i=(((g=this.stroke)==null?void 0:g.width)||0)+20,r=this.getVisualBoundingBox(),a=Math.ceil(r.width+i*2),h=Math.ceil(r.height+i*2),n=document.createElement("canvas");n.width=a,n.height=h;const l=n.getContext("2d");if(!l){const u=t.globalAlpha;t.globalAlpha=e;const p=this.toJSON();nt(t,p),t.globalAlpha=u;return}const c=r.x+r.width/2,f=r.y+r.height/2;l.translate(a/2-c,h/2-f);const d=this.toJSON();nt(l,d),t.save(),t.globalAlpha=e,t.drawImage(n,c-a/2,f-h/2),t.restore()}getTransformStartData(){const t=super.getTransformStartData(),e=this.transformData.width-N*2,o=Bt(this.text,e,this.fontSize,this.fontFamily,this.bold,this.italic);return t.lineCount=o.length,t}resize(t,e,o,i){if(t==="top-left"||t==="top-right"||t==="bottom-left"||t==="bottom-right"||(this._lockedLineCount=void 0),Ie(this,t,e,o,i),this._lockedLineCount!==void 0&&this._lockedLineCount>0){const h=Et(this.text,this.fontSize,this.fontFamily,this.bold,this.italic)/this._lockedLineCount+N*2;this.transformData.width<h&&(this.transformData.width=Math.ceil(h))}}setText(t){super.setText(t),this._lockedLineCount=void 0}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right","middle-left","middle-right"]}clone(){const t=super.clone();return this._lockedLineCount!==void 0&&(t._lockedLineCount=this._lockedLineCount),t}toJSON(){return{...super.toJSON(),transformType:"custom",transformData:{type:"custom",controlPoints:this.transformData.controlPoints,width:this.transformData.width}}}}function Ee(s,t,e,o){const i=R.toRadians(o),r=Math.cos(i),a=Math.sin(i);let h=0,n=0;e==="top-left"?(h=s.width,n=s.height):e==="top-right"?(h=0,n=s.height):e==="bottom-left"?(h=s.width,n=0):e==="bottom-right"&&(h=0,n=0);const l=s.x+(h*r-n*a),c=s.y+(h*a+n*r);let f=0,d=0;e==="top-left"?(f=t.width,d=t.height):e==="top-right"?(f=0,d=t.height):e==="bottom-left"?(f=t.width,d=0):e==="bottom-right"&&(f=0,d=0);const g=l-(f*r-d*a),u=c-(f*a+d*r);return{x:g,y:u}}function Ci(s,t,e,o=1){const i=s.width/2,r=s.height+ce/o,a=s.x+i,h=s.y+r,n=R.toRadians(t),l=Math.cos(n),c=Math.sin(n),f=a-e.x,d=h-e.y,g=f*l-d*c,u=f*c+d*l;return{x:e.x+g,y:e.y+u}}function vi(s,t,e){const o=R.toRadians(t),i=Math.cos(o),r=Math.sin(o),a=(c,f)=>{const d=s.x+c,g=s.y+f,u=d-e.x,p=g-e.y,m=u*i-p*r,y=u*r+p*i;return{x:e.x+m,y:e.y+y}},{width:h,height:n}=s,l=(c,f,d,g)=>{const u=a(d,g),p=Oe(u.x,u.y,e.x,e.y,c,t,f);return{type:c,anchor:f,...u,cursor:p}};return[l("corner","top-left",0,0),l("corner","top-right",h,0),l("corner","bottom-left",0,n),l("corner","bottom-right",h,n),l("edge","middle-left",0,n/2),l("edge","middle-right",h,n/2),l("edge","middle-top",h/2,0),l("edge","middle-bottom",h/2,n)]}function Ai(s,t,e,o,i){const r=s-e,a=t-o;return r*r+a*a<=i*i}function Mi(s,t,e,o){const i=R.toRadiansInverse(o),r=Math.cos(i),a=Math.sin(i),h=s-e.x,n=t-e.y,l=h*r-n*a,c=h*a+n*r;return l>=0&&l<=e.width&&c>=0&&c<=e.height}function ut(s,t,e="Arial",o=!1,i=!1){const a=document.createElement("canvas").getContext("2d"),h=o?"bold":"normal",n=i?"italic":"normal";return a.font=`${n} ${h} ${t}px ${e}`,a.measureText(s).width}function Fi(s){return{x:s.x+s.width/2,y:s.y+s.height/2}}function Ii(s,t,e,o){return Math.atan2(o-t,e-s)}function ki(s,t,e){return Math.abs(s-t)<=e}function Oe(s,t,e,o,i,r=0,a=""){const h=s-e,n=t-o;let l=Math.atan2(n,h)*(180/Math.PI);if(l=(l%360+360)%360,i==="corner"){if(Math.abs(r)<.1){if(a==="top-left"||a==="bottom-right")return"nwse-resize";if(a==="top-right"||a==="bottom-left")return"nesw-resize"}const f=l%180;return f>=157.5||f<22.5?"ew-resize":f>=22.5&&f<67.5?"nwse-resize":f>=67.5&&f<112.5?"ns-resize":"nesw-resize"}else{const c=l%180;return c>=45&&c<135?"ns-resize":"ew-resize"}}function Ei(s){if(!s.getTransform)return 1;const t=s.getTransform();return Math.sqrt(t.a*t.a+t.b*t.b)}function Oi(s,t,e=[]){const o=Ei(s);s.lineWidth=o>0?t/o:t,e.length>0&&s.setLineDash(o>0?e.map(i=>i/o):e)}class Pe extends Q{constructor(t={}){super(t),this.transformType="circle";const e=t.transformData;this.transformData={type:"circle",radius:(e==null?void 0:e.radius)??100,scale:(e==null?void 0:e.scale)??1,reverse:(e==null?void 0:e.reverse)??!1}}getBoundingBox(){const t=this.transformData.radius*this.transformData.scale,e=t*2;return{x:this.x-t,y:this.y-t,width:e,height:e}}getVisualBoundingBox(){const t=this.transformData.radius*this.transformData.scale,e=this.fontSize*this.transformData.scale,i=ut(this.text,e,this.fontFamily,this.bold,this.italic)/t,r=-Math.PI/2-i/2,a=-Math.PI/2+i/2,h=t>e/2?t-e/2:t*.1,n=t+e/2;let l=1/0,c=-1/0,f=1/0,d=-1/0;const g=10;for(let u=0;u<=g;u++){const p=r+(a-r)*(u/g),m=this.x+Math.cos(p)*h,y=this.y+Math.sin(p)*h,S=this.x+Math.cos(p)*n,b=this.y+Math.sin(p)*n;l=Math.min(l,m,S),c=Math.max(c,m,S),f=Math.min(f,y,b),d=Math.max(d,y,b)}return{x:l,y:f,width:c-l,height:d-f}}render(t,e=!1,o=!1){const i=t.globalAlpha;this.opacity!==void 0&&this.opacity!==1&&(t.globalAlpha=this.opacity),ye(t,this.toJSON()),t.globalAlpha=i}resize(t,e,o,i){const r=i.transformData,a=(e+o)/2,h=(i.width+i.height)/2,n=a/h,l=r.scale*n,c=Math.max(.1,Math.min(10,l));this.transformData.scale=c;const f=this.getBoundingBox(),d=Ee({x:i.x-r.radius*r.scale,y:i.y-r.radius*r.scale,width:r.radius*2*r.scale,height:r.radius*2*r.scale},{width:f.width,height:f.height},t,this.rotation);d&&(this.x=d.x+f.width/2,this.y=d.y+f.height/2)}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right"]}getEffectiveFontSize(){return Math.round(this.fontSize*this.transformData.scale*10)/10}setEffectiveFontSize(t){if(Math.abs(this.transformData.scale-1)>.01){const e=t/this.transformData.scale;this.setFontSize(e)}else this.setFontSize(t)}toJSON(){return{...super.toJSON(),transformType:"circle",transformData:{type:"circle",radius:this.transformData.radius,scale:this.transformData.scale,reverse:this.transformData.reverse}}}getTransformStartData(){const t=this.getBoundingBox();return{id:this.id,x:this.x,y:this.y,width:t.width,height:t.height,fontSize:this.fontSize,rotation:this.rotation,transformData:{type:"circle",radius:this.transformData.radius,scale:this.transformData.scale,reverse:this.transformData.reverse}}}}class Be extends Q{constructor(t={}){super(t),this.transformType="arch";const e=t.transformData;this.transformData={type:"arch",archHeight:(e==null?void 0:e.archHeight)??.5,width:(e==null?void 0:e.width)??200}}getBoundingBox(){const t=Math.abs(this.transformData.archHeight),e=this.fontSize*(1.2+t),o=this.transformData.archHeight>0?-e:0;return{x:this.x-this.transformData.width/2,y:this.y+o,width:this.transformData.width,height:e}}getVisualBoundingBox(){const t=this.text.split(""),e=t.map(u=>ut(u,this.fontSize,this.fontFamily)),o=e.reduce((u,p)=>u+p,0),i=this.transformData.width/2,r=.3,h=this.fontSize/2;let n=1/0,l=-1/0,c=1/0,f=-1/0,d=-o/2;t.forEach((u,p)=>{const m=e[p],y=d+m/2,S=y/i,b=(Math.pow(S,2)-1)*this.transformData.archHeight*this.fontSize,w=2*S*this.transformData.archHeight;[{x:-m/2,y:-h},{x:m/2,y:-h},{x:-m/2,y:h},{x:m/2,y:h}].forEach(C=>{const A=C.x,M=C.y+w*r*C.x,F=y+A,v=b+M;n=Math.min(n,F),l=Math.max(l,F),c=Math.min(c,v),f=Math.max(f,v)}),d+=m});const g=2;return n-=g,l+=g,c-=g,f+=g,{x:this.x+n,y:this.y+c,width:l-n,height:f-c}}render(t,e=!1,o=!1){const i=t.globalAlpha;this.opacity!==void 0&&this.opacity!==1&&(t.globalAlpha=this.opacity),be(t,this.toJSON()),t.globalAlpha=i}resize(t,e,o,i){const r=t.includes("top")||t.includes("bottom"),a=t.includes("middle"),h=i.transformData;if(r){const n=e/i.width,l=i.fontSize*n;this.setFontSize(l);const c=h.width*n;this.transformData.width=Math.max(50,c)}else if(a&&(t==="middle-left"||t==="middle-right")){this.fontSize=i.fontSize,this.transformData.width=Math.max(50,e);const n=e-i.width,l=this.rotation*Math.PI/180,c=Math.cos(l),f=Math.sin(l);if(t==="middle-left"){const d=-n/2;this.x=i.x+d*c,this.y=i.y+d*f}else if(t==="middle-right"){const d=n/2;this.x=i.x+d*c,this.y=i.y+d*f}}}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right"]}toJSON(){return{...super.toJSON(),transformType:"arch",transformData:{type:"arch",archHeight:this.transformData.archHeight,width:this.transformData.width}}}getTransformStartData(){const t=this.getBoundingBox();return{...super.getTransformStartData(),width:t.width,height:t.height,transformData:{type:"arch",archHeight:this.transformData.archHeight,width:this.transformData.width}}}}const at={amplitude:.2,frequency:1.2,width:200},ht={amplitude:.2,frequency:2,width:200},Re={archHeight:.5},De={leanAmount:0},Pi={ascendAngle:-15};class Le extends Q{constructor(t={}){super(t),this.transformType="wave";const e=t.transformData;this.transformData={type:"wave",amplitude:(e==null?void 0:e.amplitude)??at.amplitude,frequency:(e==null?void 0:e.frequency)??at.frequency,width:(e==null?void 0:e.width)??at.width}}getBoundingBox(){const t=Math.abs(this.transformData.amplitude),e=this.fontSize*(1.2+t*2);return{x:this.x-this.transformData.width/2,y:this.y-e/2,width:this.transformData.width,height:e}}getVisualBoundingBox(){const t=this.text.split(""),e=t.map(d=>ut(d,this.fontSize,this.fontFamily)),o=e.reduce((d,g)=>d+g,0),r=this.fontSize/2;let a=1/0,h=-1/0,n=1/0,l=-1/0,c=-o/2;t.forEach((d,g)=>{const u=e[g],p=c+u/2,m=p/(this.transformData.width/2),y=this.transformData.amplitude*this.fontSize*Math.sin(this.transformData.frequency*Math.PI*m),S=this.transformData.amplitude*this.transformData.frequency*Math.PI*Math.cos(this.transformData.frequency*Math.PI*m);[{x:-u/2,y:-r},{x:u/2,y:-r},{x:-u/2,y:r},{x:u/2,y:r}].forEach(w=>{const x=w.x,C=w.y+S*Jt*w.x,A=p+x,M=y+C;a=Math.min(a,A),h=Math.max(h,A),n=Math.min(n,M),l=Math.max(l,M)}),c+=u});const f=2;return a-=f,h+=f,n-=f,l+=f,{x:this.x+a,y:this.y+n,width:h-a,height:l-n}}render(t,e=!1,o=!1){const i=t.globalAlpha;this.opacity!==void 0&&this.opacity!==1&&(t.globalAlpha=this.opacity),we(t,this.toJSON()),t.globalAlpha=i}resize(t,e,o,i){Ie(this,t,e,o,i)}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right"]}toJSON(){return{...super.toJSON(),transformType:"wave",transformData:{type:"wave",amplitude:this.transformData.amplitude,frequency:this.transformData.frequency,width:this.transformData.width}}}}class He extends Q{constructor(t={}){super(t),this.transformType="flag";const e=t.transformData;this.transformData={type:"flag",amplitude:(e==null?void 0:e.amplitude)??ht.amplitude,frequency:(e==null?void 0:e.frequency)??ht.frequency,width:(e==null?void 0:e.width)??ht.width}}getBoundingBox(){const t=Math.abs(this.transformData.amplitude),e=this.fontSize*(1.2+t*2);return{x:this.x-this.transformData.width/2,y:this.y-e/2,width:this.transformData.width,height:e}}getVisualBoundingBox(){const t=this.text.split(""),e=t.map(g=>ut(g,this.fontSize,this.fontFamily)),o=e.reduce((g,u)=>g+u,0),i=.3,a=this.fontSize/2;let h=1/0,n=-1/0,l=1/0,c=-1/0,f=-o/2;t.forEach((g,u)=>{const p=e[u],m=f+p/2,y=m/(this.transformData.width/2),S=Math.abs(y),b=this.transformData.amplitude*S,w=b*this.fontSize*Math.sin(this.transformData.frequency*Math.PI*y),x=b*this.transformData.frequency*Math.PI*Math.cos(this.transformData.frequency*Math.PI*y),C=this.transformData.amplitude*Math.sign(y)*Math.sin(this.transformData.frequency*Math.PI*y),A=x+C;[{x:-p/2,y:-a},{x:p/2,y:-a},{x:-p/2,y:a},{x:p/2,y:a}].forEach(F=>{const v=F.x,k=F.y+A*i*F.x,T=m+v,E=w+k;h=Math.min(h,T),n=Math.max(n,T),l=Math.min(l,E),c=Math.max(c,E)}),f+=p});const d=2;return h-=d,n+=d,l-=d,c+=d,{x:this.x+h,y:this.y+l,width:n-h,height:c-l}}render(t,e=!1,o=!1){const i=t.globalAlpha;this.opacity!==void 0&&this.opacity!==1&&(t.globalAlpha=this.opacity),xe(t,this.toJSON()),t.globalAlpha=i}resize(t,e,o,i){const r=t.includes("top")||t.includes("bottom"),a=t.includes("middle"),h=i.transformData;if(r){const n=e/i.width,l=i.fontSize*n;this.setFontSize(l);const c=h.width*n;this.transformData.width=Math.max(50,c)}else if(a&&(t==="middle-left"||t==="middle-right")){this.fontSize=i.fontSize,this.transformData.width=Math.max(50,e);const n=e-i.width,l=this.rotation*Math.PI/180,c=Math.cos(l),f=Math.sin(l);if(t==="middle-left"){const d=-n/2;this.x=i.x+d*c,this.y=i.y+d*f}else if(t==="middle-right"){const d=n/2;this.x=i.x+d*c,this.y=i.y+d*f}}}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right"]}toJSON(){return{...super.toJSON(),transformType:"flag",transformData:{type:"flag",amplitude:this.transformData.amplitude,frequency:this.transformData.frequency,width:this.transformData.width}}}getTransformStartData(){const t=this.getBoundingBox();return{...super.getTransformStartData(),width:t.width,height:t.height,transformData:{type:"flag",amplitude:this.transformData.amplitude,frequency:this.transformData.frequency,width:this.transformData.width}}}}class We extends Q{constructor(t={}){super(t),this.transformType="lean";const e=t.transformData;this.transformData={type:"lean",leanAmount:(e==null?void 0:e.leanAmount)??(e==null?void 0:e.angleAmount)??0,width:(e==null?void 0:e.width)??200}}getBoundingBox(){const t=Math.abs(this.transformData.leanAmount),e=this.fontSize*(1.2+t*.5);return{x:this.x-this.transformData.width/2,y:this.y-e/2,width:this.transformData.width,height:e}}getVisualBoundingBox(){const e=ut(this.text,this.fontSize,this.fontFamily),o=this.fontSize*1.2,i=-this.transformData.leanAmount*Math.PI/4,r=Math.tan(i),a=[{x:-e/2,y:-o/2},{x:e/2,y:-o/2},{x:-e/2,y:o/2},{x:e/2,y:o/2}];let h=1/0,n=-1/0,l=1/0,c=-1/0;a.forEach(d=>{const g=d.x+r*d.y,u=d.y;h=Math.min(h,g),n=Math.max(n,g),l=Math.min(l,u),c=Math.max(c,u)});const f=2;return h-=f,n+=f,l-=f,c+=f,{x:this.x+h,y:this.y+l,width:n-h,height:c-l}}render(t,e=!1,o=!1){const i=t.globalAlpha;this.opacity!==void 0&&this.opacity!==1&&(t.globalAlpha=this.opacity),Te(t,this.toJSON()),t.globalAlpha=i}resize(t,e,o,i){const r=t.includes("top")||t.includes("bottom"),a=t.includes("middle"),h=i.transformData;if(r){const n=e/i.width,l=i.fontSize*n;this.setFontSize(l);const c=h.width*n;this.transformData.width=Math.max(50,c)}else if(a&&(t==="middle-left"||t==="middle-right")){this.fontSize=i.fontSize,this.transformData.width=Math.max(50,e);const n=e-h.width,l=this.rotation*Math.PI/180,c=Math.cos(l),f=Math.sin(l);if(t==="middle-left"){const d=-n/2;this.x=i.x+d*c,this.y=i.y+d*f}else if(t==="middle-right"){const d=n/2;this.x=i.x+d*c,this.y=i.y+d*f}}}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right"]}toJSON(){return{...super.toJSON(),transformType:"lean",transformData:{type:"lean",leanAmount:this.transformData.leanAmount,width:this.transformData.width}}}getTransformStartData(){const t=this.getBoundingBox();return{...super.getTransformStartData(),width:t.width,height:t.height,transformData:{type:"lean",leanAmount:this.transformData.leanAmount,width:this.transformData.width}}}}class _e extends Q{constructor(t={}){super(t),this.transformType="ascend";const e=t.transformData;this.transformData={type:"ascend",ascendAngle:(e==null?void 0:e.ascendAngle)??-15,width:(e==null?void 0:e.width)??200}}getBoundingBox(){const t=this.transformData.ascendAngle*Math.PI/180,e=this.transformData.width,o=e*Math.tan(t),i=Math.abs(o)+this.fontSize*1.2,r=o>0?-i:0;return{x:this.x-e/2,y:this.y+r,width:e,height:i}}getVisualBoundingBox(){const t=this.text.split(""),e=t.map(p=>ut(p,this.fontSize,this.fontFamily)),o=e.reduce((p,m)=>p+m,0),i=this.transformData.ascendAngle*Math.PI/180,r=Math.tan(i),a=1,n=this.fontSize/2;let l=1/0,c=-1/0,f=1/0,d=-1/0,g=-o/2;t.forEach((p,m)=>{const y=e[m],S=g+y/2,b=S*r;[{x:-y/2,y:-n},{x:y/2,y:-n},{x:-y/2,y:n},{x:y/2,y:n}].forEach(x=>{const C=x.x,A=x.y+r*a*x.x,M=S+C,F=b+A;l=Math.min(l,M),c=Math.max(c,M),f=Math.min(f,F),d=Math.max(d,F)}),g+=y});const u=2;return l-=u,c+=u,f-=u,d+=u,{x:this.x+l,y:this.y+f,width:c-l,height:d-f}}render(t,e=!1,o=!1){const i=t.globalAlpha;this.opacity!==void 0&&this.opacity!==1&&(t.globalAlpha=this.opacity),Se(t,this.toJSON()),t.globalAlpha=i}resize(t,e,o,i){const r=t.includes("top")||t.includes("bottom"),a=t.includes("middle"),h=i.transformData;if(r){const n=e/i.width,l=i.fontSize*n;this.setFontSize(l);const c=h.width*n;this.transformData.width=Math.max(50,c)}else if(a&&(t==="middle-left"||t==="middle-right")){this.fontSize=i.fontSize,this.transformData.width=Math.max(50,e);const n=e-i.width,l=this.rotation*Math.PI/180,c=Math.cos(l),f=Math.sin(l);if(t==="middle-left"){const d=-n/2;this.x=i.x+d*c,this.y=i.y+d*f}else if(t==="middle-right"){const d=n/2;this.x=i.x+d*c,this.y=i.y+d*f}}}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right"]}toJSON(){return{...super.toJSON(),transformType:"ascend",transformData:{type:"ascend",ascendAngle:this.transformData.ascendAngle,width:this.transformData.width}}}getTransformStartData(){const t=this.getBoundingBox();return{...super.getTransformStartData(),width:t.width,height:t.height,transformData:{type:"ascend",ascendAngle:this.transformData.ascendAngle,width:this.transformData.width}}}}class Rt extends it{constructor(t={}){var o,i,r,a,h,n,l,c,f,d,g;super(t),this.transformType="shape";const e="rectangle";this.transformData={type:"shape",shapeType:((o=t.transformData)==null?void 0:o.shapeType)||e,width:((i=t.transformData)==null?void 0:i.width)||200,height:((r=t.transformData)==null?void 0:r.height)||200,borderRadius:((a=t.transformData)==null?void 0:a.borderRadius)??3,radiusX:(h=t.transformData)==null?void 0:h.radiusX,radiusY:(n=t.transformData)==null?void 0:n.radiusY,sides:((l=t.transformData)==null?void 0:l.sides)??5,points:((c=t.transformData)==null?void 0:c.points)??5,innerRadius:((f=t.transformData)==null?void 0:f.innerRadius)??.4,fillColor:((d=t.transformData)==null?void 0:d.fillColor)||Vt(),fillOpacity:((g=t.transformData)==null?void 0:g.fillOpacity)??1}}getBoundingBox(){return{x:this.x-this.transformData.width/2,y:this.y-this.transformData.height/2,width:this.transformData.width,height:this.transformData.height}}getVisualBoundingBox(){const{shapeType:t,width:e,height:o}=this.transformData;if(t==="circle"){const i=Math.min(e,o)/2;return{x:this.x-i,y:this.y-i,width:i*2,height:i*2}}if(t==="polygon"||t==="star"){const i=Math.min(e,o)/2;let r=1/0,a=1/0,h=-1/0,n=-1/0;if(t==="polygon"){const l=this.transformData.sides||5;for(let c=0;c<l;c++){const f=c*2*Math.PI/l-Math.PI/2,d=i*Math.cos(f),g=i*Math.sin(f);d<r&&(r=d),d>h&&(h=d),g<a&&(a=g),g>n&&(n=g)}}else{const l=this.transformData.points||5,c=i,f=c*(this.transformData.innerRadius??.4);for(let d=0;d<l*2;d++){const g=d*Math.PI/l-Math.PI/2,u=d%2===0?c:f,p=u*Math.cos(g),m=u*Math.sin(g);p<r&&(r=p),p>h&&(h=p),m<a&&(a=m),m>n&&(n=m)}}return{x:this.x+r,y:this.y+a,width:h-r,height:n-a}}return this.getBoundingBox()}getRotationAnchor(){return{x:this.x,y:this.y}}render(t,e=!1,o=!1){var h;const i=this.opacity??1,r=!!((h=this.stroke)!=null&&h.enabled);if(i<1&&r){this.renderWithOffscreen(t,i);return}t.save(),t.translate(this.x,this.y),t.rotate(R.toRadians(this.rotation)),t.fillStyle=this.transformData.fillColor||"#3b82f6";const a=this.transformData.fillOpacity??1;t.globalAlpha=i*a,this.renderShape(t),t.restore(),r&&this.renderStroke(t,i)}renderWithOffscreen(t,e){var g;const{width:o,height:i}=this.transformData,a=(((g=this.stroke)==null?void 0:g.width)||2)+2,h=Math.ceil(o+a*2),n=Math.ceil(i+a*2),l=document.createElement("canvas");l.width=h,l.height=n;const c=l.getContext("2d");if(!c){this.renderDirect(t,e);return}c.save(),c.translate(h/2,n/2),c.fillStyle=this.transformData.fillColor||"#3b82f6";const f=this.transformData.fillOpacity??1;c.globalAlpha=f,c.beginPath(),this.traceShapePath(c),c.fill(),c.restore(),c.save(),c.translate(h/2,n/2);const d=this.stroke;c.strokeStyle=d.color||"#000000",c.lineWidth=d.width||2,c.lineCap=d.lineCap||"round",c.lineJoin=d.lineJoin||"round",c.globalAlpha=d.opacity??1,d.dashArray&&d.dashArray.length>0&&c.setLineDash(d.dashArray),c.beginPath(),this.traceShapePath(c),c.stroke(),c.restore(),t.save(),t.translate(this.x,this.y),t.rotate(R.toRadians(this.rotation)),t.globalAlpha=e,t.drawImage(l,-h/2,-n/2),t.restore()}renderDirect(t,e){var o;t.save(),t.translate(this.x,this.y),t.rotate(R.toRadians(this.rotation)),t.fillStyle=this.transformData.fillColor||"#3b82f6",t.globalAlpha=e*(this.transformData.fillOpacity??1),this.renderShape(t),t.restore(),(o=this.stroke)!=null&&o.enabled&&this.renderStroke(t,e)}traceShapePath(t){const{shapeType:e,width:o,height:i}=this.transformData;switch(e){case"rectangle":{const r=this.transformData.borderRadius||0,a=-o/2,h=-i/2;if(r>0){const n=Math.min(r/100*Math.min(o,i),o/2,i/2);t.roundRect(a,h,o,i,n)}else t.rect(a,h,o,i);break}case"circle":{const r=Math.min(o,i)/2;t.arc(0,0,r,0,Math.PI*2);break}case"ellipse":t.ellipse(0,0,o/2,i/2,0,0,Math.PI*2);break;case"triangle":{const r=o/2,a=i/2;t.moveTo(0,-a),t.lineTo(r,a),t.lineTo(-r,a),t.closePath();break}case"polygon":{const r=this.transformData.sides||5,a=Math.min(o,i)/2;for(let h=0;h<r;h++){const n=h*2*Math.PI/r-Math.PI/2,l=a*Math.cos(n),c=a*Math.sin(n);h===0?t.moveTo(l,c):t.lineTo(l,c)}t.closePath();break}case"star":{const r=this.transformData.points||5,a=Math.min(o,i)/2,h=a*(this.transformData.innerRadius||.4);for(let n=0;n<r*2;n++){const l=n*Math.PI/r-Math.PI/2,c=n%2===0?a:h,f=c*Math.cos(l),d=c*Math.sin(l);n===0?t.moveTo(f,d):t.lineTo(f,d)}t.closePath();break}case"line":{const r=o/2,a=i/2;t.rect(-r,-a,o,i);break}default:t.rect(-o/2,-i/2,o,i)}}renderStroke(t,e){t.save(),t.translate(this.x,this.y),t.rotate(R.toRadians(this.rotation));const o=this.stroke;t.strokeStyle=o.color||"#000000",t.lineWidth=o.width||2,t.lineCap=o.lineCap||"round",t.lineJoin=o.lineJoin||"round",t.globalAlpha=e*(o.opacity??1),o.dashArray&&o.dashArray.length>0&&t.setLineDash(o.dashArray);const{shapeType:i,width:r,height:a}=this.transformData;switch(t.beginPath(),i){case"rectangle":{const h=this.transformData.borderRadius||0,n=-r/2,l=-a/2;if(h>0){const c=Math.min(h/100*Math.min(r,a),r/2,a/2);t.roundRect(n,l,r,a,c)}else t.rect(n,l,r,a);break}case"circle":{const h=Math.min(r,a)/2;t.arc(0,0,h,0,Math.PI*2);break}case"ellipse":t.ellipse(0,0,r/2,a/2,0,0,Math.PI*2);break;case"triangle":{const h=r/2,n=a/2;t.moveTo(0,-n),t.lineTo(h,n),t.lineTo(-h,n),t.closePath();break}case"polygon":{const h=this.transformData.sides||5,n=Math.min(r,a)/2;for(let l=0;l<h;l++){const c=l*2*Math.PI/h-Math.PI/2,f=n*Math.cos(c),d=n*Math.sin(c);l===0?t.moveTo(f,d):t.lineTo(f,d)}t.closePath();break}case"star":{const h=this.transformData.points||5,n=Math.min(r,a)/2,l=n*(this.transformData.innerRadius||.4);for(let c=0;c<h*2;c++){const f=c*Math.PI/h-Math.PI/2,d=c%2===0?n:l,g=d*Math.cos(f),u=d*Math.sin(f);c===0?t.moveTo(g,u):t.lineTo(g,u)}t.closePath();break}case"line":{const h=r/2,n=a/2;t.rect(-h,-n,r,a);break}default:t.rect(-r/2,-a/2,r,a)}t.stroke(),t.restore()}renderShape(t){const{shapeType:e,width:o,height:i}=this.transformData;switch(t.beginPath(),e){case"rectangle":this.renderRectangle(t,o,i);break;case"circle":this.renderCircle(t,Math.min(o,i)/2);break;case"ellipse":this.renderEllipse(t,o/2,i/2);break;case"triangle":this.renderTriangle(t,o,i);break;case"polygon":this.renderPolygon(t,Math.min(o,i)/2);break;case"star":this.renderStar(t,Math.min(o,i)/2);break;case"line":this.renderLine(t,o,i);return;default:this.renderRectangle(t,o,i)}t.fill()}renderRectangle(t,e,o){const i=this.transformData.borderRadius||0,r=-e/2,a=-o/2;if(i>0){const h=Math.min(i/100*Math.min(e,o),e/2,o/2);t.roundRect(r,a,e,o,h)}else t.rect(r,a,e,o)}renderCircle(t,e){t.arc(0,0,e,0,Math.PI*2)}renderEllipse(t,e,o){t.ellipse(0,0,e,o,0,0,Math.PI*2)}renderTriangle(t,e,o){const i=e/2,r=o/2;t.moveTo(0,-r),t.lineTo(i,r),t.lineTo(-i,r),t.closePath()}renderPolygon(t,e){const o=Math.max(3,Math.min(20,this.transformData.sides||5)),i=Math.PI*2/o,r=-Math.PI/2;for(let a=0;a<=o;a++){const h=r+i*a,n=Math.cos(h)*e,l=Math.sin(h)*e;a===0?t.moveTo(n,l):t.lineTo(n,l)}t.closePath()}renderStar(t,e){const o=Math.max(3,Math.min(20,this.transformData.points||5)),i=Math.max(.1,Math.min(.9,this.transformData.innerRadius||.4)),r=e*i,a=Math.PI/o,h=-Math.PI/2;for(let n=0;n<o*2;n++){const l=h+a*n,c=n%2===0?e:r,f=Math.cos(l)*c,d=Math.sin(l)*c;n===0?t.moveTo(f,d):t.lineTo(f,d)}t.closePath()}renderLine(t,e,o){const i=e/2,r=o;t.moveTo(-i,0),t.lineTo(i,0),t.strokeStyle=this.transformData.fillColor||"#3b82f6",t.lineWidth=r,t.lineCap="round",t.stroke()}resize(t,e,o,i){const{shapeType:r}=this.transformData;if(r==="circle"||r==="polygon"||r==="star"){const c=Math.max(e/i.transformData.width,o/i.transformData.height);this.transformData.width=i.transformData.width*c,this.transformData.height=i.transformData.height*c}else r==="line"?(this.transformData.width=e,this.transformData.height=i.transformData.height):(this.transformData.width=e,this.transformData.height=o);this.rotation=i.rotation;const a=this.getFixedCorner(t,i),h=this.getOppositeAnchor(t),n=this.getBoundingBox(),l=this.getCornerOffset(h,n);return this.x=a.x-l.x,this.y=a.y-l.y,!0}getOppositeAnchor(t){return{"top-left":"bottom-right","top-right":"bottom-left","bottom-left":"top-right","bottom-right":"top-left","middle-left":"middle-right","middle-right":"middle-left","middle-top":"middle-bottom","middle-bottom":"middle-top",top:"bottom",bottom:"top",left:"right",right:"left"}[t]}getFixedCorner(t,e){const o={x:e.x-e.transformData.width/2,y:e.y-e.transformData.height/2,width:e.transformData.width,height:e.transformData.height};let i,r;switch(t){case"top-left":i=o.x+o.width,r=o.y+o.height;break;case"top-right":i=o.x,r=o.y+o.height;break;case"bottom-left":i=o.x+o.width,r=o.y;break;case"bottom-right":i=o.x,r=o.y;break;case"middle-left":i=o.x+o.width,r=o.y+o.height/2;break;case"middle-right":i=o.x,r=o.y+o.height/2;break;case"middle-top":i=o.x+o.width/2,r=o.y+o.height;break;case"middle-bottom":i=o.x+o.width/2,r=o.y;break;default:i=o.x+o.width/2,r=o.y+o.height/2}return{x:i,y:r}}getCornerOffset(t,e){let o,i;switch(t){case"top-left":o=-e.width/2,i=-e.height/2;break;case"top-right":o=e.width/2,i=-e.height/2;break;case"bottom-left":o=-e.width/2,i=e.height/2;break;case"bottom-right":o=e.width/2,i=e.height/2;break;case"middle-left":o=-e.width/2,i=0;break;case"middle-right":o=e.width/2,i=0;break;case"middle-top":o=0,i=-e.height/2;break;case"middle-bottom":o=0,i=e.height/2;break;default:o=0,i=0}return{x:o,y:i}}getEnabledAnchors(){const{shapeType:t}=this.transformData;return t==="circle"||t==="polygon"||t==="star"?["top-left","top-right","bottom-left","bottom-right"]:t==="line"?["middle-left","middle-right"]:["top-left","top-right","bottom-left","bottom-right","middle-left","middle-right","middle-top","middle-bottom"]}clone(){return new Rt(this.toJSON())}toJSON(){return{...super.toJSON(),id:this.id,type:"shape",transformType:"shape",x:this.x,y:this.y,rotation:this.rotation,transformData:{...this.transformData}}}}class Dt extends it{constructor(t={}){var e,o,i,r,a,h,n,l,c,f;super(t),this.transformType="path",this.transformData={type:"path",points:((e=t.transformData)==null?void 0:e.points)||[],closed:((o=t.transformData)==null?void 0:o.closed)??!1,width:((i=t.transformData)==null?void 0:i.width)||200,height:((r=t.transformData)==null?void 0:r.height)||200,fillEnabled:((a=t.transformData)==null?void 0:a.fillEnabled)??!1,fillColor:((h=t.transformData)==null?void 0:h.fillColor)||Vt(),fillOpacity:((n=t.transformData)==null?void 0:n.fillOpacity)??1,strokeEnabled:((l=t.transformData)==null?void 0:l.strokeEnabled)??!0,strokeColor:((c=t.transformData)==null?void 0:c.strokeColor)||"#000000",strokeWidth:((f=t.transformData)==null?void 0:f.strokeWidth)||2}}getBoundingBox(){const t=this.calculatePathBounds();return{x:this.x-t.width/2,y:this.y-t.height/2,width:t.width,height:t.height}}getVisualBoundingBox(){return this.getBoundingBox()}getRotationAnchor(){return{x:this.x,y:this.y}}bezierPoint(t,e,o,i,r){const a=1-r,h=a*a,n=h*a,l=r*r,c=l*r;return{x:n*t.x+3*h*r*e.x+3*a*l*o.x+c*i.x,y:n*t.y+3*h*r*e.y+3*a*l*o.y+c*i.y}}calculatePathBounds(){var n,l,c,f;const{points:t}=this.transformData;if(t.length===0)return{x:0,y:0,width:0,height:0};let e=1/0,o=1/0,i=-1/0,r=-1/0;for(let d=0;d<t.length;d++){const g=t[d],u=t[(d+1)%t.length];if(d===t.length-1&&!this.transformData.closed){e=Math.min(e,g.x),o=Math.min(o,g.y),i=Math.max(i,g.x),r=Math.max(r,g.y);break}if(e=Math.min(e,g.x),o=Math.min(o,g.y),i=Math.max(i,g.x),r=Math.max(r,g.y),g.handleOut||u.handleIn){const m={x:g.x,y:g.y},y={x:g.x+(((n=g.handleOut)==null?void 0:n.x)||0),y:g.y+(((l=g.handleOut)==null?void 0:l.y)||0)},S={x:u.x+(((c=u.handleIn)==null?void 0:c.x)||0),y:u.y+(((f=u.handleIn)==null?void 0:f.y)||0)},b={x:u.x,y:u.y},w=20;for(let x=0;x<=w;x++){const C=x/w,A=this.bezierPoint(m,y,S,b,C);e=Math.min(e,A.x),o=Math.min(o,A.y),i=Math.max(i,A.x),r=Math.max(r,A.y)}}}const a=this.transformData.strokeEnabled?this.transformData.strokeWidth||2:0,h=a/2;return{x:e-h,y:o-h,width:i-e+a,height:r-o+a}}updateBounds(){const t=this.calculatePathBounds();this.transformData.width=Math.max(1,t.width),this.transformData.height=Math.max(1,t.height)}render(t,e=!1,o=!1){const{points:i,closed:r,fillEnabled:a,fillColor:h,fillOpacity:n,strokeEnabled:l,strokeColor:c,strokeWidth:f}=this.transformData;if(i.length===0)return;t.save(),t.translate(this.x,this.y),t.rotate(R.toRadians(this.rotation));const d=this.calculatePathBounds(),g=d.x+d.width/2,u=d.y+d.height/2;t.translate(-g,-u),t.beginPath(),this.renderPath(t),a&&r&&h&&(t.fillStyle=h,t.globalAlpha=n??1,t.fill()),l&&c&&f&&(t.strokeStyle=c,t.lineWidth=f,t.lineCap="round",t.lineJoin="round",t.globalAlpha=1,t.stroke()),t.restore()}renderPath(t){var r,a,h,n;const{points:e,closed:o}=this.transformData;if(e.length===0)return;const i=e[0];t.moveTo(i.x,i.y);for(let l=0;l<e.length;l++){const c=e[l],f=e[(l+1)%e.length];if(l===e.length-1&&!o)break;if(c.handleOut||f.handleIn){const g=c.x+(((r=c.handleOut)==null?void 0:r.x)||0),u=c.y+(((a=c.handleOut)==null?void 0:a.y)||0),p=f.x+(((h=f.handleIn)==null?void 0:h.x)||0),m=f.y+(((n=f.handleIn)==null?void 0:n.y)||0);t.bezierCurveTo(g,u,p,m,f.x,f.y)}else t.lineTo(f.x,f.y)}o&&t.closePath()}resize(t,e,o,i){const r=i.transformData.width,a=i.transformData.height;if(r===0||a===0)return!1;const h=e/r,n=o/a,l=i.transformData.points;let c=1/0,f=1/0,d=-1/0,g=-1/0;for(const w of l)c=Math.min(c,w.x),f=Math.min(f,w.y),d=Math.max(d,w.x),g=Math.max(g,w.y);const u=(c+d)/2,p=(f+g)/2;this.transformData.points=l.map(w=>({...w,x:u+(w.x-u)*h,y:p+(w.y-p)*n,handleIn:w.handleIn?{x:w.handleIn.x*h,y:w.handleIn.y*n}:void 0,handleOut:w.handleOut?{x:w.handleOut.x*h,y:w.handleOut.y*n}:void 0})),this.transformData.width=e,this.transformData.height=o,this.rotation=i.rotation;const m=this.getFixedCorner(t,i),y=this.getOppositeAnchor(t),S=this.getBoundingBox(),b=this.getCornerOffset(y,S);return this.x=m.x-b.x,this.y=m.y-b.y,!0}getOppositeAnchor(t){return{"top-left":"bottom-right","top-right":"bottom-left","bottom-left":"top-right","bottom-right":"top-left","middle-left":"middle-right","middle-right":"middle-left","middle-top":"middle-bottom","middle-bottom":"middle-top",top:"bottom",bottom:"top",left:"right",right:"left"}[t]}getFixedCorner(t,e){const o={x:e.x-e.transformData.width/2,y:e.y-e.transformData.height/2,width:e.transformData.width,height:e.transformData.height};let i,r;switch(t){case"top-left":i=o.x+o.width,r=o.y+o.height;break;case"top-right":i=o.x,r=o.y+o.height;break;case"bottom-left":i=o.x+o.width,r=o.y;break;case"bottom-right":i=o.x,r=o.y;break;case"middle-left":i=o.x+o.width,r=o.y+o.height/2;break;case"middle-right":i=o.x,r=o.y+o.height/2;break;case"middle-top":i=o.x+o.width/2,r=o.y+o.height;break;case"middle-bottom":i=o.x+o.width/2,r=o.y;break;default:i=o.x+o.width/2,r=o.y+o.height/2}return{x:i,y:r}}getCornerOffset(t,e){let o,i;switch(t){case"top-left":o=-e.width/2,i=-e.height/2;break;case"top-right":o=e.width/2,i=-e.height/2;break;case"bottom-left":o=-e.width/2,i=e.height/2;break;case"bottom-right":o=e.width/2,i=e.height/2;break;case"middle-left":o=-e.width/2,i=0;break;case"middle-right":o=e.width/2,i=0;break;case"middle-top":o=0,i=-e.height/2;break;case"middle-bottom":o=0,i=e.height/2;break;default:o=0,i=0}return{x:o,y:i}}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right","middle-left","middle-right","middle-top","middle-bottom"]}clone(){return new Dt(this.toJSON())}toJSON(){return{...super.toJSON(),id:this.id,type:"path",transformType:"path",x:this.x,y:this.y,rotation:this.rotation,transformData:{...this.transformData,points:this.transformData.points.map(e=>({...e,handleIn:e.handleIn?{...e.handleIn}:void 0,handleOut:e.handleOut?{...e.handleOut}:void 0}))}}}}const Bi={circle:[{key:"reverse",label:"Reverse Direction",type:"checkbox",defaultValue:!1}],arch:[{key:"archHeight",label:"Arch Height",defaultInternalValue:Re.archHeight,toSlider:s=>(s+1)/2*100,fromSlider:s=>s/100*2-1,toDisplay:s=>`${(s*100).toFixed(0)}%`}],wave:[{key:"amplitude",label:"Wave Amplitude",defaultInternalValue:at.amplitude,toSlider:s=>(s+.5)*100,fromSlider:s=>s/100-.5,toDisplay:s=>`${(s*100).toFixed(0)}%`},{key:"frequency",label:"Wave Frequency",defaultInternalValue:at.frequency,step:5,toSlider:s=>(s-1)/4*100,fromSlider:s=>1+s/100*4,toDisplay:s=>s.toFixed(1)}],flag:[{key:"amplitude",label:"Flag Amplitude",defaultInternalValue:ht.amplitude,toSlider:s=>(s+.5)*100,fromSlider:s=>s/100-.5,toDisplay:s=>`${(s*100).toFixed(0)}%`},{key:"frequency",label:"Flag Frequency",defaultInternalValue:ht.frequency,step:5,toSlider:s=>(s-1)/4*100,fromSlider:s=>1+s/100*4,toDisplay:s=>s.toFixed(1)}],lean:[{key:"leanAmount",label:"Lean Amount",defaultInternalValue:De.leanAmount,toSlider:s=>(s+.5)*100,fromSlider:s=>s/100-.5,toDisplay:s=>`${(s*200).toFixed(0)}%`}],ascend:[{key:"ascendAngle",label:"Ascend Amount",defaultInternalValue:Pi.ascendAngle,toSlider:s=>(30-s)/60*100,fromSlider:s=>30-s/100*60,toDisplay:s=>`${(-s/30*100).toFixed(0)}%`}],shape:[{key:"shapeType",label:"Shape Type",type:"select",options:[{value:"rectangle",label:"Rectangle"},{value:"circle",label:"Circle"},{value:"ellipse",label:"Ellipse"},{value:"triangle",label:"Triangle"},{value:"polygon",label:"Polygon"},{value:"star",label:"Star"},{value:"line",label:"Line"}],defaultValue:"rectangle"},{key:"borderRadius",label:"Border Radius",defaultInternalValue:0,toSlider:s=>s/50*100,fromSlider:s=>s/100*50,toDisplay:s=>`${s.toFixed(0)}%`,visibleWhen:s=>s.shapeType==="rectangle"},{key:"sides",label:"Sides",defaultInternalValue:5,step:1,toSlider:s=>(s-3)/17*100,fromSlider:s=>Math.round(3+s/100*17),toDisplay:s=>s.toFixed(0),visibleWhen:s=>s.shapeType==="polygon"},{key:"points",label:"Points",defaultInternalValue:5,step:1,toSlider:s=>(s-3)/17*100,fromSlider:s=>Math.round(3+s/100*17),toDisplay:s=>s.toFixed(0),visibleWhen:s=>s.shapeType==="star"},{key:"innerRadius",label:"Inner Radius",defaultInternalValue:.4,toSlider:s=>(s-.1)/.8*100,fromSlider:s=>.1+s/100*.8,toDisplay:s=>`${(s*100).toFixed(0)}%`,visibleWhen:s=>s.shapeType==="star"},{key:"fillOpacity",label:"Fill Opacity",defaultInternalValue:1,toSlider:s=>s*100,fromSlider:s=>s/100,toDisplay:s=>`${(s*100).toFixed(0)}%`}]},Qt=[{id:"custom",label:"CUSTOM",Component:ke},{id:"circle",label:"CIRCLE",Component:Pe},{id:"lean",label:"LEAN",Component:We},{id:"arch",label:"ARCH",Component:Be},{id:"ascend",label:"ASCEND",Component:_e},{id:"wave",label:"WAVE",Component:Le},{id:"flag",label:"FLAG",Component:He},{id:"shape",label:"SHAPE",Component:Rt},{id:"path",label:"PATH",Component:Dt},{id:"image",label:"IMAGE",Component:vt},{id:"group",label:"GROUP",get Component(){return xt}}],ze=new Set(Qt.map(s=>s.id)),Ot=new Map;function Ri(s,t){if(ze.has(s))throw new Error(`Cannot register transform type "${s}": conflicts with built-in type`);if(Ot.has(s))throw new Error(`Cannot register transform type "${s}": already registered as a custom type`);Ot.set(s,t)}function Di(s){if(ze.has(s))throw new Error(`Cannot unregister transform type "${s}": built-in types cannot be removed`);return Ot.delete(s)}function Xe(s){const t=Qt.find(e=>e.id===s);return t||Ot.get(s)}function Li(s){return Bi[s]||[]}class xt extends it{constructor(t={}){super(t),this.isGroup=!0,this._baseBBoxWidth=0,this._baseBBoxHeight=0,this._rotationCenterX=0,this._rotationCenterY=0,this.transformType="group";const e=t.children||[];this.children=e.map(o=>o instanceof it?o:this._reconstructChildFromJSON(o)),this.transformData={type:"group"},this.children.length>0&&this.updateBoundsFromChildren(!0)}_reconstructChildFromJSON(t){const e=t.transformType||t.type,o=Xe(e);if(!o||!o.Component)throw new Error(`Unknown transform type: ${e}`);return new o.Component(t)}getBoundingBox(){if(this.children.length===0)return{x:this.x-50,y:this.y-50,width:100,height:100};let t=1/0,e=1/0,o=-1/0,i=-1/0;return this.children.forEach(r=>{const a=r.getVisualBoundingBox();this._getRotatedCorners(r,a).forEach(n=>{t=Math.min(t,n.x),e=Math.min(e,n.y),o=Math.max(o,n.x),i=Math.max(i,n.y)})}),{x:t,y:e,width:o-t,height:i-e}}getVisualBoundingBox(){return this.getOrientedBoundingBox()}getRotationAnchor(){return{x:this._rotationCenterX||this.x,y:this._rotationCenterY||this.y}}_getRotatedCorners(t,e){const o=new W(t),i=e.x+e.width/2,r=e.y+e.height/2,a=i-t.x,h=r-t.y;return[{localX:a-e.width/2,localY:h-e.height/2},{localX:a+e.width/2,localY:h-e.height/2},{localX:a-e.width/2,localY:h+e.height/2},{localX:a+e.width/2,localY:h+e.height/2}].map(l=>o.localToWorld(l.localX,l.localY))}updateBoundsFromChildren(t=!1){const e=this.getBoundingBox();if(this.x=e.x+e.width/2,this.y=e.y+e.height/2,t||this._baseBBoxWidth===0||this._baseBBoxHeight===0){const o=this._calculateInitialDimensions();this._baseBBoxWidth=o.width,this._baseBBoxHeight=o.height,this._rotationCenterX=this.x,this._rotationCenterY=this.y}}_calculateInitialDimensions(){if(this.children.length===0)return{width:100,height:100};const t=this.getBoundingBox();return{width:t.width,height:t.height}}render(t,e=!1,o=!1){const i=this.children.filter(a=>a.visible!==!1);i.some(a=>a.isClipping)?this._renderWithClipping(t,i):i.forEach(a=>{a.render(t,!1)}),e?this._renderGroupOutline(t,1):o&&this._renderGroupOutline(t,.3)}_renderWithClipping(t,e){t.save();const o=t.canvas,i=o.width,r=o.height,a=t.getTransform(),h=[];let n=[];for(const l of e)l.isClipping?n.length>0?(h.push({content:n,mask:l}),n=[]):h.push({content:[l]}):n.push(l);n.length>0&&h.push({content:n});for(const l of h)if(!l.mask)l.content.forEach(c=>c.render(t,!1,!1));else{const c=document.createElement("canvas");c.width=i,c.height=r;const f=c.getContext("2d");if(!f)continue;f.setTransform(a),l.content.forEach(u=>{u.render(f,!1,!1)});const d=document.createElement("canvas");d.width=i,d.height=r;const g=d.getContext("2d");if(!g)continue;if(g.setTransform(a),l.mask.render(g,!1,!1),l.mask.transformType!=="image"&&l.mask.transformType!=="shape"){const u=l.mask.getBoundingBox();g.save(),g.fillStyle="#FFFFFF",g.fillRect(u.x,u.y,u.width,u.height),g.restore()}f.globalCompositeOperation="destination-in",f.setTransform(1,0,0,1,0,0),f.drawImage(d,0,0),t.setTransform(1,0,0,1,0,0),t.drawImage(c,0,0),t.setTransform(a)}t.restore()}_renderGroupOutline(t,e=1){const o=this.getOrientedBoundingBox();t.save(),t.globalAlpha=e,t.strokeStyle=$t(),t.lineWidth=2,t.setLineDash([5,5]);const i=this._rotationCenterX||this.x,r=this._rotationCenterY||this.y;this.rotation!==0&&(t.translate(i,r),t.rotate(-this.rotation*Math.PI/180),t.translate(-i,-r)),t.strokeRect(o.x,o.y,o.width,o.height),t.setLineDash([]),t.restore()}getOrientedBoundingBox(){if(this.children.length===0)return{x:this.x-50,y:this.y-50,width:100,height:100};let t,e;if(this._baseBBoxWidth>0&&this._baseBBoxHeight>0)t=this._baseBBoxWidth,e=this._baseBBoxHeight;else{const r=this.getBoundingBox();t=r.width,e=r.height,this._baseBBoxWidth=t,this._baseBBoxHeight=e}const o=this._rotationCenterX||this.x,i=this._rotationCenterY||this.y;return{x:o-t/2,y:i-e/2,width:t,height:e}}move(t,e){this.x+=t,this.y+=e,this._rotationCenterX+=t,this._rotationCenterY+=e,this.children.forEach(o=>{o.move(t,e)})}setRotation(t){const e=t-this.rotation;this.rotation=t;const o=this._rotationCenterX||this.x,i=this._rotationCenterY||this.y;this.children.forEach(r=>{const a=W.rotatePointAroundAnchor(r.x,r.y,o,i,e);r.x=a.x,r.y=a.y,r.setRotation(r.rotation+e)}),this.x=o,this.y=i}resize(t,e,o,i){if(!i.childrenStartData||!i.width||!i.height)return;const r=e/i.width,a=o/i.height,h=(r+a)/2;let n,l;switch(t){case"top-left":n=i.width/2,l=i.height/2;break;case"top-right":n=-i.width/2,l=i.height/2;break;case"bottom-left":n=i.width/2,l=-i.height/2;break;case"bottom-right":n=-i.width/2,l=-i.height/2;break;default:n=0,l=0}const c=-i.rotation*Math.PI/180,f=Math.cos(c),d=Math.sin(c),g=i.x+(n*f-l*d),u=i.y+(n*d+l*f);this.children.forEach((y,S)=>{const b=i.childrenStartData[S],w=b.x-g,x=b.y-u,C=g+w*h,A=u+x*h;if(y.x=C,y.y=A,y instanceof vt){const M=b.transformData,F=M.width*h,v=M.height*h;y.transformData.width=F,y.transformData.height=v}else if(y instanceof xt){const M=(b.width??0)*h,F=(b.height??0)*h;y.resize(t,M,F,b)}else{const M=(b.width??0)*h,F=(b.height??0)*h;y.resize(t,M,F,b)}}),this._baseBBoxWidth=i.width*h,this._baseBBoxHeight=i.height*h;const p=i.x-g,m=i.y-u;this.x=g+p*h,this.y=u+m*h,this._rotationCenterX=this.x,this._rotationCenterY=this.y}getTransformStartData(){const t=this._baseBBoxWidth>0?this._baseBBoxWidth:this.getBoundingBox().width,e=this._baseBBoxHeight>0?this._baseBBoxHeight:this.getBoundingBox().height,o=this._rotationCenterX||this.x,i=this._rotationCenterY||this.y;return{id:this.id,x:o,y:i,width:t,height:e,rotation:this.rotation,transformData:this.transformData,childrenStartData:this.children.map(r=>r.getTransformStartData())}}hitTest(t,e){const o=this.getOrientedBoundingBox(),i=this._rotationCenterX||this.x,r=this._rotationCenterY||this.y;if(this.rotation===0)return t>=o.x&&t<=o.x+o.width&&e>=o.y&&e<=o.y+o.height;const a=this.rotation*Math.PI/180,h=Math.cos(a),n=Math.sin(a),l=t-i,c=e-r,f=i+(l*h-c*n),d=r+(l*n+c*h);return f>=o.x&&f<=o.x+o.width&&d>=o.y&&d<=o.y+o.height}getEnabledAnchors(){return["top-left","top-right","bottom-left","bottom-right"]}toJSON(){return{...super.toJSON(),transformType:"group",transformData:{type:"group"},children:this.children.map(e=>e.toJSON())}}clone(){const t=this.children.map(o=>o.clone()),e=new xt({id:this.id,x:this.x,y:this.y,rotation:this.rotation,children:t});return e._baseBBoxWidth=this._baseBBoxWidth,e._baseBBoxHeight=this._baseBBoxHeight,e._rotationCenterX=this._rotationCenterX,e._rotationCenterY=this._rotationCenterY,e.opacity=this.opacity,e.name=this.name,e.visible=this.visible,e.locked=this.locked,this.blendMode&&(e.blendMode=this.blendMode),this.knockoutParts&&(e.knockoutParts={...this.knockoutParts}),this.stroke&&(e.stroke={...this.stroke}),this.masks&&(e.masks=this.masks.map(o=>({...o}))),this.distressEffect&&(e.distressEffect={...this.distressEffect}),e}addChild(t){this.children.push(t),this.updateBoundsFromChildren(!0)}removeChild(t){const e=this.children.findIndex(o=>o.id===t);return e>=0?(this.children.splice(e,1),this.updateBoundsFromChildren(!0),!0):!1}getChildren(){return[...this.children]}hitTestChild(t,e){for(let o=this.children.length-1;o>=0;o--){const i=this.children[o];if(i.hitTest(t,e))return i}return null}}class et{constructor(t){if(this._cachedArray=null,this.byId=new Map,this.order=[],t)for(const e of t)this.byId.set(e.id,e),this.order.push(e.id)}get(t){return this.byId.get(t)}has(t){return this.byId.has(t)}getAll(){return this.order.map(t=>this.byId.get(t))}get size(){return this.byId.size}getOrder(){return this.order}getByName(t){for(const e of this.order){const o=this.byId.get(e);if(o&&o.name===t)return o}}getAllByName(t){const e=[];for(const o of this.order){const i=this.byId.get(o);i&&i.name===t&&e.push(i)}return e}update(t){const e=this.clone();return e.byId.set(t.id,t),this.byId.has(t.id)||e.order.push(t.id),e}updateById(t,e){if(!this.byId.has(t))return this;const o=this.clone();if(t!==e.id){o.byId.delete(t);const i=o.order.indexOf(t);i!==-1&&(o.order[i]=e.id)}return o.byId.set(e.id,e),o}add(t){const e=this.clone();return e.byId.set(t.id,t),this.byId.has(t.id)||e.order.push(t.id),e}insertAfter(t,e){const o=this.clone();o.byId.set(t.id,t);const i=o.order.indexOf(e);return i!==-1?o.order.splice(i+1,0,t.id):o.order.push(t.id),o}remove(t){if(!this.byId.has(t))return this;const e=this.clone();return e.byId.delete(t),e.order=e.order.filter(o=>o!==t),e}reorder(t,e){const o=this.clone();return o.order=o.order.filter(i=>i!==t),o.order.splice(e,0,t),o}replaceAll(t){return new et(t)}filter(t){const e=this.getAll().filter(t);return new et(e)}map(t){const e=this.getAll().map(t);return new et(e)}setOrder(t){const e=this.clone();return e.order=t.filter(o=>e.byId.has(o)),e}toArray(){return this._cachedArray===null&&(this._cachedArray=this.getAll()),this._cachedArray}static fromArray(t){return new et(t)}clone(){const t=new et;return t.byId=new Map(this.byId),t.order=[...this.order],t}}class tt{execute(){throw new Error("Command.execute() must be implemented")}undo(){throw new Error("Command.undo() must be implemented")}}class Hi extends tt{constructor(t,e,o,i){super(),this.elementId=t,this.oldElement=e?e.clone():null,this.newElement=o?o.clone():null,this.onUpdate=i}execute(){this.newElement&&this.onUpdate(this.newElement)}undo(){this.oldElement&&this.onUpdate(this.oldElement)}}class Wi extends tt{constructor(t,e,o){super(),this.element=t.clone(),this.onAdd=e,this.onRemove=o}execute(){this.onAdd(this.element)}undo(){this.onRemove(this.element.id)}}class _i extends tt{constructor(t,e,o){super(),this.element=t.clone(),this.onAdd=e,this.onRemove=o}execute(){this.onRemove(this.element.id)}undo(){this.onAdd(this.element)}}class zi extends tt{constructor(t){super(),this.commands=t}execute(){this.commands.forEach(t=>t.execute())}undo(){for(let t=this.commands.length-1;t>=0;t--)this.commands[t].undo()}}class It{constructor(t=50){this.history=[],this.currentIndex=-1,this.maxSize=t}execute(t){t.execute(),this.history=this.history.slice(0,this.currentIndex+1),this.history.push(t),this.currentIndex++,this.history.length>this.maxSize&&(this.history.shift(),this.currentIndex--)}executeBatch(t){if(t.length===0)return;const e=new zi(t);this.execute(e)}undo(){return this.canUndo()?(this.history[this.currentIndex].undo(),this.currentIndex--,!0):!1}redo(){return this.canRedo()?(this.currentIndex++,this.history[this.currentIndex].execute(),!0):!1}canUndo(){return this.currentIndex>=0}canRedo(){return this.currentIndex<this.history.length-1}clear(){this.history=[],this.currentIndex=-1}getState(){return{canUndo:this.canUndo(),canRedo:this.canRedo(),historySize:this.history.length,currentIndex:this.currentIndex}}}class Xi extends tt{constructor(t,e){super(),this.artboard=t.clone(),this.artboardManager=e}execute(){const t=this.artboard.clone();this.artboardManager.createArtboard({id:t.id,name:t.name,x:t.x,y:t.y,width:t.width,height:t.height,backgroundColor:t.backgroundColor})}undo(){this.artboardManager.deleteArtboard(this.artboard.id)}}class Ni extends tt{constructor(t,e){super(),this.artboard=t.clone(),this.artboardManager=e,this.elementsOnArtboard=t.getElementIds()}execute(){this.artboardManager.deleteArtboard(this.artboard.id)}undo(){const t=this.artboard.clone();this.artboardManager.createArtboard({id:t.id,name:t.name,x:t.x,y:t.y,width:t.width,height:t.height,backgroundColor:t.backgroundColor,elementIds:this.elementsOnArtboard}),this.elementsOnArtboard.forEach(e=>{this.artboardManager.addElementToArtboard(e,t.id)})}}class Yi extends tt{constructor(t,e,o,i){super(),this.artboardId=t,this.oldProperties={...e},this.newProperties={...o},this.artboardManager=i}execute(){this.artboardManager.updateArtboard(this.artboardId,this.newProperties)}undo(){this.artboardManager.updateArtboard(this.artboardId,this.oldProperties)}}class Ui extends tt{constructor(t,e,o,i,r){super(),this.draggedId=t,this.targetId=e,this.position=o,this.oldOrder=[...i],this.onReorder=r,this.newOrder=this.calculateNewOrder()}calculateNewOrder(){const t=[...this.oldOrder],e=t.indexOf(this.draggedId);if(e===-1)return t;t.splice(e,1);const o=t.indexOf(this.targetId);if(o===-1)return t;const i=this.position==="before"?o:o+1;return t.splice(i,0,this.draggedId),t}execute(){this.onReorder(this.newOrder)}undo(){this.onReorder(this.oldOrder)}}const Gi=st("HybridHistoryManager");class $i{constructor(t,e=50){this.commandExecutedCallbacks=[],this.globalHistory=new It(e),this.artboardHistories=new Map,this.lastOperation=null,this.artboardManager=t,this.maxHistorySize=e}onCommandExecuted(t){return this.commandExecutedCallbacks.push(t),()=>{const e=this.commandExecutedCallbacks.indexOf(t);e>-1&&this.commandExecutedCallbacks.splice(e,1)}}notifyCommandExecuted(t,e,o){for(const i of this.commandExecutedCallbacks)try{i(t,e,o)}catch(r){Gi.error("Error in command executed callback:",r)}}executeGlobal(t){this.globalHistory.execute(t),this.lastOperation={type:"global",timestamp:Date.now()},this.notifyCommandExecuted(t,"global")}executeBatchGlobal(t){if(t.length===0)return;this.globalHistory.executeBatch(t),this.lastOperation={type:"global",timestamp:Date.now()};const e=this.globalHistory.history[this.globalHistory.currentIndex];this.notifyCommandExecuted(e,"global")}executeBatchOnArtboard(t,e){if(e.length===0)return;let o=this.artboardHistories.get(t);o||(o=new It(this.maxHistorySize),this.artboardHistories.set(t,o)),o.executeBatch(e),this.lastOperation={type:"artboard",artboardId:t,timestamp:Date.now()};const i=o.history[o.currentIndex];this.notifyCommandExecuted(i,"artboard",t)}executeOnArtboard(t,e){let o=this.artboardHistories.get(t);o||(o=new It(this.maxHistorySize),this.artboardHistories.set(t,o)),o.execute(e),this.lastOperation={type:"artboard",artboardId:t,timestamp:Date.now()},this.notifyCommandExecuted(e,"artboard",t)}undo(){if(this.lastOperation){if(this.lastOperation.type==="global")return this.undoGlobal();if(this.lastOperation.artboardId)return this.undoArtboard(this.lastOperation.artboardId)}const t=this.artboardManager.getActiveArtboardId();return t&&this.canUndoArtboard(t)?this.undoArtboard(t):this.canUndoGlobal()?this.undoGlobal():!1}redo(){if(this.lastOperation){if(this.lastOperation.type==="global")return this.redoGlobal();if(this.lastOperation.artboardId)return this.redoArtboard(this.lastOperation.artboardId)}const t=this.artboardManager.getActiveArtboardId();return t&&this.canRedoArtboard(t)?this.redoArtboard(t):this.canRedoGlobal()?this.redoGlobal():!1}undoGlobal(){const t=this.globalHistory.undo();return t&&this.updateLastOperation("global"),t}redoGlobal(){const t=this.globalHistory.redo();return t&&this.updateLastOperation("global"),t}undoArtboard(t){const e=this.artboardHistories.get(t);if(!e)return!1;const o=e.undo();return o&&this.updateLastOperation("artboard",t),o}redoArtboard(t){const e=this.artboardHistories.get(t);if(!e)return!1;const o=e.redo();return o&&this.updateLastOperation("artboard",t),o}canUndoGlobal(){return this.globalHistory.canUndo()}canRedoGlobal(){return this.globalHistory.canRedo()}canUndoArtboard(t){const e=this.artboardHistories.get(t);return e?e.canUndo():!1}canRedoArtboard(t){const e=this.artboardHistories.get(t);return e?e.canRedo():!1}canUndo(){if(this.lastOperation){if(this.lastOperation.type==="global")return this.canUndoGlobal();if(this.lastOperation.artboardId)return this.canUndoArtboard(this.lastOperation.artboardId)}const t=this.artboardManager.getActiveArtboardId();return t&&this.canUndoArtboard(t)?!0:this.canUndoGlobal()}canRedo(){if(this.lastOperation){if(this.lastOperation.type==="global")return this.canRedoGlobal();if(this.lastOperation.artboardId)return this.canRedoArtboard(this.lastOperation.artboardId)}const t=this.artboardManager.getActiveArtboardId();return t&&this.canRedoArtboard(t)?!0:this.canRedoGlobal()}clear(){this.globalHistory.clear(),this.artboardHistories.clear(),this.lastOperation=null}clearArtboardHistory(t){var e;this.artboardHistories.delete(t),((e=this.lastOperation)==null?void 0:e.artboardId)===t&&(this.lastOperation=null)}getArtboardHistory(t){let e=this.artboardHistories.get(t);return e||(e=new It(this.maxHistorySize),this.artboardHistories.set(t,e)),e}getGlobalHistory(){return this.globalHistory}getState(){const t=this.globalHistory.getState(),e=new Map;return this.artboardHistories.forEach((o,i)=>{const r=o.getState();e.set(i,{canUndo:r.canUndo,canRedo:r.canRedo,historySize:r.historySize})}),{global:{canUndo:t.canUndo,canRedo:t.canRedo,historySize:t.historySize},artboards:e,lastOperation:this.lastOperation}}updateLastOperation(t,e){this.lastOperation={type:t,artboardId:e,timestamp:Date.now()}}getUndoDescription(){if(this.lastOperation){if(this.lastOperation.type==="global")return"Undo artboard operation";if(this.lastOperation.artboardId){const e=this.artboardManager.getArtboard(this.lastOperation.artboardId);return e?`Undo in "${e.name}"`:"Undo element operation"}}const t=this.artboardManager.getActiveArtboardId();if(t&&this.canUndoArtboard(t)){const e=this.artboardManager.getArtboard(t);return e?`Undo in "${e.name}"`:"Undo element operation"}return this.canUndoGlobal()?"Undo artboard operation":"Nothing to undo"}getRedoDescription(){if(this.lastOperation){if(this.lastOperation.type==="global")return"Redo artboard operation";if(this.lastOperation.artboardId){const e=this.artboardManager.getArtboard(this.lastOperation.artboardId);return e?`Redo in "${e.name}"`:"Redo element operation"}}const t=this.artboardManager.getActiveArtboardId();if(t&&this.canRedoArtboard(t)){const e=this.artboardManager.getArtboard(t);return e?`Redo in "${e.name}"`:"Redo element operation"}return this.canRedoGlobal()?"Redo artboard operation":"Nothing to redo"}}exports.ARCH_DEFAULTS=Re;exports.AddElementCommand=Wi;exports.ArchTransform=Be;exports.ArtboardElement=lt;exports.ArtboardManager=Je;exports.AscendTransform=_e;exports.BaseElement=it;exports.CATEGORY_LABELS=Ze;exports.CORNER_HANDLE_HIT_RADIUS=de;exports.CORNER_HANDLE_VISUAL_RADIUS=uo;exports.CircleTransform=Pe;exports.CreateArtboardCommand=Xi;exports.CustomTransform=ke;exports.DEFAULT_ARTBOARD_COLOR=go;exports.DeleteArtboardCommand=Ni;exports.EDGE_HANDLE_VISUAL_LENGTH=mo;exports.ElementStore=et;exports.FLAG_DEFAULTS=ht;exports.FONT_FAMILIES=xo;exports.FONT_SIZES=Co;exports.FlagTransform=He;exports.FontAnalyzer=Nt;exports.GroupElement=xt;exports.HORIZONTAL_PADDING=N;exports.HybridHistoryManager=$i;exports.ImageCache=K;exports.ImageElement=vt;exports.LEAN_DEFAULTS=De;exports.LeanTransform=We;exports.LogLevel=me;exports.MAX_FONT_SIZE=ue;exports.MIN_CROP_SIZE=To;exports.MIN_FONT_SIZE=ge;exports.PREVIEW_ELEMENT_OPACITY=fo;exports.PathElement=Dt;exports.ROTATION_HANDLE_DISTANCE=ce;exports.RemoveElementCommand=_i;exports.ReorderElementCommand=Ui;exports.RichText=Y;exports.RotationUtils=R;exports.SPACING_LABEL_BORDER_RADIUS=So;exports.SPACING_LABEL_TEXT_COLOR=bo;exports.SPACING_SNAP_THRESHOLD=wo;exports.ShapeElement=Rt;exports.TRANSFORM_TYPES=Qt;exports.TSHIRT_FONTS=he;exports.TextElement=Q;exports.Transform=W;exports.UpdateArtboardCommand=Yi;exports.UpdateElementCommand=Hi;exports.WAVE_DEFAULTS=at;exports.WAVE_SKEW_FACTOR=Jt;exports.WaveTransform=Le;exports.applySpaceLayoutRules=mi;exports.applyStrokeStyle=qt;exports.buildFontString=_;exports.buildFontString$1=ft;exports.calculateAngle=Ii;exports.calculateFixedCornerPosition=Ee;exports.calculateResizeHandles=vi;exports.calculateRotationHandlePosition=Ci;exports.calculateVisualBoundsWithSpaceCollapsing=Tt;exports.createCirclePath=si;exports.createImagePath=Ce;exports.createLogger=st;exports.createRectPath=ri;exports.createTextPath=ii;exports.getBoundingBoxCenter=Fi;exports.getCursorForWorldPosition=Oe;exports.getFontMetrics=dt;exports.getFontMetrics$1=St;exports.getThemeAccentColor=$t;exports.getThemeAccentColorWithAlpha=to;exports.getThemeAccentHoverColor=oo;exports.getThemeArtboardBorderColor=ro;exports.getThemeArtboardLabelColor=no;exports.getThemeHoverBorderColor=ao;exports.getThemePenAnchorFillColor=lo;exports.getThemePenHandleColor=co;exports.getThemePenPathColor=ho;exports.getThemeShapeFillColor=Vt;exports.getThemeSpacingColor=Qe;exports.getThemeTextSelectionColor=eo;exports.getThemeTooltipBackground=le;exports.getThemeTooltipForeground=io;exports.getThemeTooltipShadowColor=so;exports.getTransformById=Xe;exports.getTransformControls=Li;exports.hasDistressEffect=qo;exports.hasMasks=Vo;exports.hasStroke=$o;exports.hitTestCircle=Ai;exports.hitTestRect=Mi;exports.isArchTransform=Po;exports.isCircleElementConfig=zo;exports.isCircleTransform=Oo;exports.isCustomElementConfig=_o;exports.isCustomTransform=Eo;exports.isFlagTransform=Ro;exports.isGroupElementConfig=Xo;exports.isGroupTransform=Lo;exports.isImageElementConfig=Wo;exports.isImageTransform=Do;exports.isKnockout=Jo;exports.isNear=ki;exports.isPathElementConfig=Yo;exports.isPathTransform=Go;exports.isShapeElementConfig=No;exports.isShapeTransform=Uo;exports.isTextElementConfig=Ho;exports.isWaveTransform=Bo;exports.logger=pe;exports.measureTextWidth=Et;exports.measureTextWidth$1=Ut;exports.process$1=zt;exports.registerTransform=Ri;exports.renderCustomTransform=nt;exports.renderImageStroke=hi;exports.renderMultilineText=yi;exports.renderPathStroke=li;exports.renderRichTextFillOnly=Ae;exports.renderTextElement=bi;exports.renderTextFillOnly=pi;exports.renderTextStroke=ve;exports.setZoomInvariantStroke=Oi;exports.splitRichTextIntoLines=Zt;exports.subscribeToImageLoads=Io;exports.unregisterTransform=Di;exports.wrapRichTextSpans=jt;exports.wrapText=Bt;exports.wrapText$1=Me;
8
+ //# sourceMappingURL=HybridHistoryManager-BXD93pp8.cjs.map