@peteai/presentation-editor 0.0.6 → 0.0.8
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.
- package/README.md +38 -38
- package/dist/components/editor/active-layers-buttons.svelte +56 -0
- package/dist/components/editor/active-layers.svelte +237 -0
- package/dist/components/editor/active-layers.svelte.d.ts +8 -0
- package/dist/components/{presentation-editor/cognition-slides.d.ts → editor/cognition-pages.d.ts} +1 -1
- package/dist/components/{presentation-editor/cognition-slides.js → editor/cognition-pages.js} +1 -1
- package/dist/components/{presentation-editor → editor}/cursor-tooltip.svelte +6 -2
- package/dist/components/editor/cursor-tooltip.svelte.d.ts +7 -0
- package/dist/components/{presentation-editor → editor}/dragged.svelte +7 -3
- package/dist/components/editor/dragged.svelte.d.ts +7 -0
- package/dist/components/{presentation-editor/presentation-editor.svelte → editor/editor.svelte} +64 -61
- package/dist/components/editor/editor.svelte.d.ts +4 -0
- package/dist/components/editor/editor.svelte.js +1169 -0
- package/dist/components/editor/header.svelte +62 -0
- package/dist/components/editor/header.svelte.d.ts +7 -0
- package/dist/components/{presentation-editor → editor}/hotkeys.svelte +48 -16
- package/dist/components/editor/index.d.ts +3 -0
- package/dist/components/editor/index.js +3 -0
- package/dist/components/{presentation-editor → editor}/layers/active-background-border.svelte +2 -2
- package/dist/components/{presentation-editor → editor}/layers/active-layer-border.svelte +5 -8
- package/dist/components/editor/layers/buttons/border-button/border-button-colors.svelte +59 -0
- package/dist/components/editor/layers/buttons/border-button/border-button-colors.svelte.d.ts +9 -0
- package/dist/components/{presentation-editor → editor}/layers/buttons/border-button/border-button.svelte +47 -65
- package/dist/components/{presentation-editor → editor}/layers/buttons/corner-radius-button/corner-radius-button.svelte +24 -28
- package/dist/components/{presentation-editor → editor}/layers/buttons/flip-button/flip-button.svelte +11 -12
- package/dist/components/{presentation-editor → editor}/layers/buttons/opacity-button/opacity-button.svelte +33 -44
- package/dist/components/{presentation-editor → editor}/layers/controls/corner-scale-control/corner-scale-control.svelte +27 -32
- package/dist/components/editor/layers/controls/group-resize-control/group-resize-control.svelte +418 -0
- package/dist/components/{presentation-editor → editor}/layers/controls/rotate-control/rotate-control.svelte +33 -34
- package/dist/components/editor/layers/controls/rotate-control/rotate-control.svelte.d.ts +6 -0
- package/dist/components/{presentation-editor → editor}/layers/controls/side-resize-control/side-resize-control.svelte +22 -26
- package/dist/components/{presentation-editor → editor}/layers/controls/side-scale-control/side-scale-control.svelte +13 -15
- package/dist/components/{presentation-editor → editor}/layers/controls/side-scale-control/side-scale-control.svelte.d.ts +2 -2
- package/dist/components/editor/layers/index.d.ts +10 -0
- package/dist/components/{presentation-editor → editor}/layers/index.js +8 -5
- package/dist/components/{presentation-editor → editor}/layers/layer-button.svelte +14 -8
- package/dist/components/{presentation-editor → editor}/layers/layer-thumb-wrapper.svelte +5 -6
- package/dist/components/{presentation-editor → editor}/layers/layer-wrapper.svelte +46 -57
- package/dist/components/editor/layers/types/background/background-content-image.svelte +36 -0
- package/dist/components/{presentation-editor → editor}/layers/types/background/background-layer-buttons.svelte +6 -6
- package/dist/components/editor/layers/types/background/background-layer-content.svelte +21 -0
- package/dist/components/{presentation-editor → editor}/layers/types/background/background-layer-content.svelte.d.ts +2 -2
- package/dist/components/{presentation-editor → editor}/layers/types/background/background-layer.svelte +7 -9
- package/dist/components/editor/layers/types/group/group-child-wrapper.svelte +44 -0
- package/dist/components/editor/layers/types/group/group-child-wrapper.svelte.d.ts +9 -0
- package/dist/components/editor/layers/types/group/group-layer-content.svelte +45 -0
- package/dist/components/editor/layers/types/group/group-layer-content.svelte.d.ts +9 -0
- package/dist/components/editor/layers/types/group/group-layer.svelte +33 -0
- package/dist/components/editor/layers/types/group/group-layer.svelte.d.ts +8 -0
- package/dist/components/editor/layers/types/group/index.d.ts +3 -0
- package/dist/components/editor/layers/types/group/index.js +3 -0
- package/dist/components/editor/layers/types/image/controls/image-rotate-control/image-rotate-control.svelte +120 -0
- package/dist/components/editor/layers/types/image/controls/image-rotate-control/image-rotate-control.svelte.d.ts +8 -0
- package/dist/components/editor/layers/types/image/controls/image-rotate-control/index.d.ts +2 -0
- package/dist/components/editor/layers/types/image/controls/image-rotate-control/index.js +4 -0
- package/dist/components/editor/layers/types/image/controls/image-scale-control/image-scale-control.svelte +154 -0
- package/dist/components/editor/layers/types/image/controls/image-scale-control/image-scale-control.svelte.d.ts +91 -0
- package/dist/components/editor/layers/types/image/controls/image-scale-control/index.d.ts +2 -0
- package/dist/components/editor/layers/types/image/controls/image-scale-control/index.js +4 -0
- package/dist/components/{presentation-editor → editor}/layers/types/image/image-layer-active.svelte +10 -13
- package/dist/components/{presentation-editor → editor}/layers/types/image/image-layer-content.svelte +15 -12
- package/dist/components/editor/layers/types/image/image-layer-crop.svelte +182 -0
- package/dist/components/editor/layers/types/image/image-layer-crop.svelte.d.ts +10 -0
- package/dist/components/{presentation-editor → editor}/layers/types/image/image-layer.svelte +24 -14
- package/dist/components/editor/layers/types/image/index.d.ts +4 -0
- package/dist/components/editor/layers/types/image/index.js +4 -0
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/alignment-button/alignment-button.svelte +13 -14
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/alignment-button/alignment-button.svelte.d.ts +2 -2
- package/dist/components/editor/layers/types/text/buttons/bold-button/bold-button.svelte +65 -0
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/bold-button/bold-button.svelte.d.ts +2 -2
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/case-button/case-button.svelte +24 -30
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/case-button/case-button.svelte.d.ts +2 -2
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/color-button/color-button.svelte +4 -4
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/color-button/color-button.svelte.d.ts +2 -2
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/font-family-button/font-family-button.svelte +4 -4
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/font-family-button/font-family-button.svelte.d.ts +2 -2
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/font-size-button/font-size-button.svelte +33 -40
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/font-size-button/font-size-button.svelte.d.ts +2 -2
- package/dist/components/editor/layers/types/text/buttons/italic-button/italic-button.svelte +65 -0
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/italic-button/italic-button.svelte.d.ts +2 -2
- package/dist/components/editor/layers/types/text/buttons/list-button/list-button.svelte +113 -0
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/list-button/list-button.svelte.d.ts +2 -2
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/strikethrough-button/strikethrough-button.svelte +10 -11
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/strikethrough-button/strikethrough-button.svelte.d.ts +2 -2
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/underline-button/underline-button.svelte +10 -11
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/underline-button/underline-button.svelte.d.ts +2 -2
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/utils.d.ts +2 -0
- package/dist/components/editor/layers/types/text/editor/utils.js +166 -0
- package/dist/components/editor/layers/types/text/extensions/list/index.d.ts +3 -0
- package/dist/components/editor/layers/types/text/extensions/list/index.js +3 -0
- package/dist/components/editor/layers/types/text/extensions/list/list.d.ts +67 -0
- package/dist/components/editor/layers/types/text/extensions/list/list.js +237 -0
- package/dist/components/editor/layers/types/text/extensions/list-item/index.d.ts +3 -0
- package/dist/components/editor/layers/types/text/extensions/list-item/index.js +3 -0
- package/dist/components/editor/layers/types/text/extensions/list-item/list-item.d.ts +13 -0
- package/dist/components/editor/layers/types/text/extensions/list-item/list-item.js +262 -0
- package/dist/components/editor/layers/types/text/extensions/list-item-paragraph/index.d.ts +3 -0
- package/dist/components/editor/layers/types/text/extensions/list-item-paragraph/index.js +3 -0
- package/dist/components/editor/layers/types/text/extensions/list-item-paragraph/list-item-paragraph.d.ts +14 -0
- package/dist/components/editor/layers/types/text/extensions/list-item-paragraph/list-item-paragraph.js +27 -0
- package/dist/components/editor/layers/types/text/extensions/paragraph/index.d.ts +3 -0
- package/dist/components/editor/layers/types/text/extensions/paragraph/index.js +3 -0
- package/dist/components/editor/layers/types/text/extensions/paragraph/paragraph.d.ts +6 -0
- package/dist/components/editor/layers/types/text/extensions/paragraph/paragraph.js +28 -0
- package/dist/components/editor/layers/types/text/extensions/preserve-formatting-on-clear/index.d.ts +3 -0
- package/dist/components/editor/layers/types/text/extensions/preserve-formatting-on-clear/index.js +3 -0
- package/dist/components/editor/layers/types/text/extensions/preserve-formatting-on-clear/preserve-formatting-on-clear.d.ts +2 -0
- package/dist/components/editor/layers/types/text/extensions/preserve-formatting-on-clear/preserve-formatting-on-clear.js +74 -0
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/text-transform/text-transform.js +1 -4
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions.js +13 -23
- package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/html-content.svelte +0 -9
- package/dist/components/editor/layers/types/text/index.d.ts +5 -0
- package/dist/components/editor/layers/types/text/index.js +5 -0
- package/dist/components/{presentation-editor/layers/types/html/html-layer-content.svelte → editor/layers/types/text/text-layer-content.svelte} +2 -2
- package/dist/components/editor/layers/types/text/text-layer-content.svelte.d.ts +9 -0
- package/dist/components/editor/layers/types/text/text-layer-edit.svelte +114 -0
- package/dist/components/editor/layers/types/text/text-layer-edit.svelte.d.ts +9 -0
- package/dist/components/editor/layers/types/text/text-layer.svelte +125 -0
- package/dist/components/editor/layers/types/text/text-layer.svelte.d.ts +7 -0
- package/dist/components/{presentation-editor → editor}/layers/utils.d.ts +32 -24
- package/dist/components/{presentation-editor → editor}/layers/utils.js +152 -102
- package/dist/components/{presentation-editor → editor}/menu/background-menu-content.svelte +24 -24
- package/dist/components/{presentation-editor → editor}/menu/background-menu-content.svelte.d.ts +4 -4
- package/dist/components/{presentation-editor → editor}/menu/layer-menu-content.svelte +62 -38
- package/dist/components/{presentation-editor/menu/slide-menu-content.svelte → editor/menu/page-menu-content.svelte} +19 -19
- package/dist/components/editor/menu/page-menu-content.svelte.d.ts +9 -0
- package/dist/components/{presentation-editor/slide-editor.svelte → editor/page-editor.svelte} +30 -25
- package/dist/components/editor/page-editor.svelte.d.ts +7 -0
- package/dist/components/{presentation-editor/slide-inner.svelte → editor/page-inner.svelte} +5 -5
- package/dist/components/{presentation-editor/sidebar/sidebar.svelte.d.ts → editor/page-inner.svelte.d.ts} +3 -3
- package/dist/components/editor/page.svelte +69 -0
- package/dist/components/editor/page.svelte.d.ts +4 -0
- package/dist/components/editor/pages-navigation/page-preview.svelte +36 -0
- package/dist/components/editor/pages-navigation/page-preview.svelte.d.ts +8 -0
- package/dist/components/{presentation-editor/slides-navigation/slide-preview.svelte → editor/pages-navigation/pages-navigation-item.svelte} +21 -41
- package/dist/components/editor/pages-navigation/pages-navigation-item.svelte.d.ts +11 -0
- package/dist/components/{presentation-editor/slides-navigation/slides-navigation.svelte → editor/pages-navigation/pages-navigation.svelte} +26 -21
- package/dist/components/editor/pages-navigation/pages-navigation.svelte.d.ts +7 -0
- package/dist/components/{presentation-editor → editor}/sidebar/color-sidebar/color-sidebar-color.svelte +1 -1
- package/dist/components/{presentation-editor → editor}/sidebar/color-sidebar/color-sidebar-gradient-picker.svelte +2 -2
- package/dist/components/{presentation-editor → editor}/sidebar/color-sidebar/color-sidebar.svelte +92 -89
- package/dist/components/{presentation-editor → editor}/sidebar/font-sidebar/font-sidebar-button.svelte +3 -3
- package/dist/components/{presentation-editor → editor}/sidebar/font-sidebar/font-sidebar.svelte +34 -39
- package/dist/components/editor/sidebar/image-crop-sidebar.svelte +112 -0
- package/dist/components/editor/sidebar/image-crop-sidebar.svelte.d.ts +7 -0
- package/dist/components/{presentation-editor/sidebar/position-slidebar.svelte → editor/sidebar/position-sidebar.svelte} +26 -20
- package/dist/components/editor/sidebar/position-sidebar.svelte.d.ts +3 -0
- package/dist/components/{presentation-editor → editor}/sidebar/sidebar-text-tab-button.svelte +5 -5
- package/dist/components/{presentation-editor → editor}/sidebar/sidebar-text-tab.svelte +5 -5
- package/dist/components/{presentation-editor → editor}/sidebar/sidebar-uploads-tab.svelte +4 -4
- package/dist/components/{presentation-editor → editor}/sidebar/sidebar-wrapper.svelte +6 -4
- package/dist/components/{presentation-editor → editor}/sidebar/sidebar.svelte +17 -10
- package/dist/components/editor/sidebar/sidebar.svelte.d.ts +7 -0
- package/dist/components/{presentation-editor → editor}/sidebar/uploads-image.svelte +3 -3
- package/dist/components/editor/types.d.ts +283 -0
- package/dist/components/{presentation-editor → editor}/utils.d.ts +14 -6
- package/dist/components/{presentation-editor → editor}/utils.js +98 -63
- package/dist/components/ui/color-picker/color-picker.svelte +2 -2
- package/dist/components/ui/context-menu/context-menu-checkbox-item.svelte +2 -2
- package/dist/components/ui/context-menu/context-menu-radio-item.svelte +1 -1
- package/dist/components/ui/context-menu/context-menu-sub-trigger.svelte +1 -1
- package/dist/components/ui/dialog/dialog-content.svelte +3 -3
- package/dist/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte +3 -3
- package/dist/components/ui/dropdown-menu/dropdown-menu-radio-item.svelte +2 -2
- package/dist/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte +1 -1
- package/dist/components/ui/dropdown-menu/index.d.ts +1 -0
- package/dist/components/ui/slider/slider.svelte +28 -20
- package/dist/index.d.ts +12 -6
- package/dist/index.js +5 -3
- package/package.json +42 -38
- package/dist/components/presentation-editor/active-layers-buttons.svelte +0 -53
- package/dist/components/presentation-editor/active-layers.svelte +0 -181
- package/dist/components/presentation-editor/active-layers.svelte.d.ts +0 -3
- package/dist/components/presentation-editor/cursor-tooltip.svelte.d.ts +0 -18
- package/dist/components/presentation-editor/dragged.svelte.d.ts +0 -18
- package/dist/components/presentation-editor/header.svelte +0 -54
- package/dist/components/presentation-editor/header.svelte.d.ts +0 -18
- package/dist/components/presentation-editor/index.d.ts +0 -2
- package/dist/components/presentation-editor/index.js +0 -2
- package/dist/components/presentation-editor/layers/controls/group-resize-control/group-resize-control.svelte +0 -337
- package/dist/components/presentation-editor/layers/controls/rotate-control/rotate-control.svelte.d.ts +0 -3
- package/dist/components/presentation-editor/layers/index.d.ts +0 -9
- package/dist/components/presentation-editor/layers/types/background/background-content-image.svelte +0 -41
- package/dist/components/presentation-editor/layers/types/background/background-layer-content.svelte +0 -19
- package/dist/components/presentation-editor/layers/types/html/buttons/bold-button/bold-button.svelte +0 -71
- package/dist/components/presentation-editor/layers/types/html/buttons/italic-button/italic-button.svelte +0 -71
- package/dist/components/presentation-editor/layers/types/html/buttons/list-button/list-button.svelte +0 -90
- package/dist/components/presentation-editor/layers/types/html/editor/utils.js +0 -88
- package/dist/components/presentation-editor/layers/types/html/extensions/unstyled-list/index.d.ts +0 -3
- package/dist/components/presentation-editor/layers/types/html/extensions/unstyled-list/index.js +0 -3
- package/dist/components/presentation-editor/layers/types/html/extensions/unstyled-list/unstyled-list.d.ts +0 -47
- package/dist/components/presentation-editor/layers/types/html/extensions/unstyled-list/unstyled-list.js +0 -74
- package/dist/components/presentation-editor/layers/types/html/html-layer-content.svelte.d.ts +0 -9
- package/dist/components/presentation-editor/layers/types/html/html-layer-edit.svelte +0 -103
- package/dist/components/presentation-editor/layers/types/html/html-layer-edit.svelte.d.ts +0 -8
- package/dist/components/presentation-editor/layers/types/html/html-layer.svelte +0 -105
- package/dist/components/presentation-editor/layers/types/html/html-layer.svelte.d.ts +0 -7
- package/dist/components/presentation-editor/layers/types/html/index.d.ts +0 -5
- package/dist/components/presentation-editor/layers/types/html/index.js +0 -5
- package/dist/components/presentation-editor/layers/types/image/index.d.ts +0 -3
- package/dist/components/presentation-editor/layers/types/image/index.js +0 -3
- package/dist/components/presentation-editor/menu/slide-menu-content.svelte.d.ts +0 -9
- package/dist/components/presentation-editor/presentation-editor.svelte.d.ts +0 -4
- package/dist/components/presentation-editor/presentation-editor.svelte.js +0 -813
- package/dist/components/presentation-editor/sidebar/position-slidebar.svelte.d.ts +0 -18
- package/dist/components/presentation-editor/slide-editor.svelte.d.ts +0 -7
- package/dist/components/presentation-editor/slide-inner.svelte.d.ts +0 -18
- package/dist/components/presentation-editor/slides-navigation/slide-preview.svelte.d.ts +0 -11
- package/dist/components/presentation-editor/slides-navigation/slides-navigation.svelte.d.ts +0 -3
- package/dist/components/presentation-editor/types.d.ts +0 -158
- /package/dist/components/{presentation-editor → editor}/active-layers-buttons.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/color-indicator/color-indicator-gradient-def.svelte +0 -0
- /package/dist/components/{presentation-editor → editor}/color-indicator/color-indicator-gradient-def.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/color-indicator/color-indicator-gradient.svelte +0 -0
- /package/dist/components/{presentation-editor → editor}/color-indicator/color-indicator-gradient.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/color-indicator/color-indicator.svelte +0 -0
- /package/dist/components/{presentation-editor → editor}/color-indicator/color-indicator.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/color-indicator/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/color-indicator/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/fonts.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/fonts.js +0 -0
- /package/dist/components/{presentation-editor → editor}/hotkeys.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/active-background-border.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/active-layer-border.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/border-button/border-button.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/border-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/border-button/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/corner-radius-button/corner-radius-button.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/corner-radius-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/corner-radius-button/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/flip-button/flip-button.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/flip-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/flip-button/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/opacity-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/opacity-button/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/buttons/opacity-button/opacity-button.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/corner-scale-control/corner-scale-control.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/corner-scale-control/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/corner-scale-control/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/group-resize-control/group-resize-control.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/group-resize-control/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/group-resize-control/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/rotate-control/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/rotate-control/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/side-resize-control/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/side-resize-control/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/side-resize-control/side-resize-control.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/side-scale-control/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/controls/side-scale-control/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/layer-button.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/layer-thumb-wrapper.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/layer-wrapper.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/types/background/background-content-image.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/types/background/background-layer-buttons.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/types/background/background-layer.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/types/background/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/types/background/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/types/image/image-layer-active.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/types/image/image-layer-content.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/layers/types/image/image-layer.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/alignment-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/alignment-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/bold-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/bold-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/case-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/case-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/color-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/color-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/font-family-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/font-family-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/font-size-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/font-size-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/italic-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/italic-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/list-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/list-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/strikethrough-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/strikethrough-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/underline-button/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/buttons/underline-button/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/Editor.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/Editor.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/createEditor.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/createEditor.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/editor-content.svelte +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/editor-content.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/types.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor/types.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/editor.css +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/font-family/font-family.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/font-family/font-family.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/font-family/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/font-family/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/font-size/font-size.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/font-size/font-size.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/font-size/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/font-size/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/line-height/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/line-height/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/line-height/line-height.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/line-height/line-height.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/selection/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/selection/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/selection/selection.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/selection/selection.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/text-transform/index.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/text-transform/index.js +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions/text-transform/text-transform.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/extensions.d.ts +0 -0
- /package/dist/components/{presentation-editor/layers/types/html → editor/layers/types/text}/html-content.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/menu/layer-menu-content.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/color-sidebar/color-sidebar-color.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/color-sidebar/color-sidebar-gradient-picker.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/color-sidebar/color-sidebar.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/color-sidebar/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/color-sidebar/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/font-sidebar/font-sidebar-button.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/font-sidebar/font-sidebar.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/font-sidebar/index.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/font-sidebar/index.js +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/sidebar-text-tab-button.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/sidebar-text-tab.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/sidebar-uploads-tab.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/sidebar-wrapper.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/sidebar/uploads-image.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/snapping-guides.svelte +0 -0
- /package/dist/components/{presentation-editor → editor}/snapping-guides.svelte.d.ts +0 -0
- /package/dist/components/{presentation-editor → editor}/types.js +0 -0
|
@@ -0,0 +1,1169 @@
|
|
|
1
|
+
import uniqid from 'uniqid';
|
|
2
|
+
import { getContext, setContext, tick } from 'svelte';
|
|
3
|
+
import { defaultFonts } from './fonts.js';
|
|
4
|
+
import { cognitionImages, cognitionPages } from './cognition-pages.js';
|
|
5
|
+
import { cognitionPageToJson } from './utils.js';
|
|
6
|
+
import { calculateBoundingBox, calculateImageCover, checkPolygonsIntersect, getRotatedCorners, calculateGroupBoundingBox, calculateGroupRotatedBoundingBox, calculateRelativeRects, calculateNewPosition, degToRad, rotatePoint, } from './layers/utils.js';
|
|
7
|
+
import createEditor from './layers/types/text/editor/createEditor.js';
|
|
8
|
+
import { extensions } from './layers/types/text/extensions.js';
|
|
9
|
+
import { SvelteSet } from 'svelte/reactivity';
|
|
10
|
+
export class Editor {
|
|
11
|
+
mode = 'multiple';
|
|
12
|
+
fonts = defaultFonts;
|
|
13
|
+
images = $state(cognitionImages);
|
|
14
|
+
pages = $state(cognitionPages.map(cognitionPageToJson)); // getPages()
|
|
15
|
+
width = 1920;
|
|
16
|
+
height = 1080;
|
|
17
|
+
zoom = $state(0.4);
|
|
18
|
+
generateId = () => uniqid();
|
|
19
|
+
loadFont = async (family) => {
|
|
20
|
+
const font = this.fonts[family];
|
|
21
|
+
if (!font)
|
|
22
|
+
return;
|
|
23
|
+
const WebFont = await import('webfontloader');
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
WebFont.load({
|
|
26
|
+
[font.type]: { families: [family] },
|
|
27
|
+
fontactive: () => resolve(null),
|
|
28
|
+
fontinactive: reject,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
searchFonts = (q, limit) => {
|
|
33
|
+
const terms = q
|
|
34
|
+
.trim()
|
|
35
|
+
.split(/\W/g)
|
|
36
|
+
.map((term) => term.toLowerCase());
|
|
37
|
+
return Object.keys(this.fonts)
|
|
38
|
+
.filter((family) => terms.some((term) => ~family.toLowerCase().indexOf(term)))
|
|
39
|
+
.slice(0, limit);
|
|
40
|
+
};
|
|
41
|
+
onImageUpload;
|
|
42
|
+
onUpdate;
|
|
43
|
+
activeSidebarTab = $state(null);
|
|
44
|
+
activeSidebarPopup = $state(null);
|
|
45
|
+
imageCropLayer = $state(null);
|
|
46
|
+
toggleActiveSidebarTab(tab) {
|
|
47
|
+
this.activeSidebarTab = !this.activeSidebarPopup && this.activeSidebarTab === tab ? null : tab;
|
|
48
|
+
if (this.activeSidebarTab) {
|
|
49
|
+
this.activeSidebarPopup = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
toggleActiveSidebarPopup(popup) {
|
|
53
|
+
this.activeSidebarPopup = this.activeSidebarPopup === popup ? null : popup;
|
|
54
|
+
}
|
|
55
|
+
zoomSnapping = $state(null);
|
|
56
|
+
findPage(pageId) {
|
|
57
|
+
return this.pages.find((p) => p.id === pageId);
|
|
58
|
+
}
|
|
59
|
+
getRootLayers(page) {
|
|
60
|
+
return page.layers.filter((l) => l.type === 'group' || !l.groupId);
|
|
61
|
+
}
|
|
62
|
+
findLayer(page, layerId) {
|
|
63
|
+
return page.layers.find((l) => l.id === layerId);
|
|
64
|
+
}
|
|
65
|
+
findGroupChildren(page, groupId) {
|
|
66
|
+
return page.layers
|
|
67
|
+
.filter((l) => l.type !== 'group')
|
|
68
|
+
.filter((l) => l.groupId === groupId)
|
|
69
|
+
.toSorted((a, b) => a.sortOrder - b.sortOrder);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Finds root layers in a page based on their IDs.
|
|
73
|
+
*
|
|
74
|
+
* @param page The page to search for layers.
|
|
75
|
+
* @param layerIds The IDs of the layers to find. Can be a single ID or an array of IDs.
|
|
76
|
+
* @returns An array of layers that match the provided IDs.
|
|
77
|
+
*/
|
|
78
|
+
findRootLayers(page, layerIds) {
|
|
79
|
+
// Normalize the input to ensure it's always an array of IDs
|
|
80
|
+
const ids = Array.isArray(layerIds) ? layerIds : [layerIds];
|
|
81
|
+
// Filter the page's layers to only include those with IDs in the provided list
|
|
82
|
+
return this.getRootLayers(page).filter((l) => ids.includes(l.id));
|
|
83
|
+
}
|
|
84
|
+
sortedPages = $derived(this.pages.toSorted((a, b) => a.sortOrder - b.sortOrder));
|
|
85
|
+
activePage = $state();
|
|
86
|
+
rootLayers = $derived(this.activePage.layers
|
|
87
|
+
.filter((l) => l.type === 'group' || !l.groupId)
|
|
88
|
+
.toSorted((a, b) => a.sortOrder - b.sortOrder));
|
|
89
|
+
activeSelection = $state({ type: 'empty' });
|
|
90
|
+
activeGroupAndChild = $derived.by(() => {
|
|
91
|
+
if (this.activeSelection.type === 'child-layer') {
|
|
92
|
+
const childLayer = this.findLayer(this.activePage, this.activeSelection.childId);
|
|
93
|
+
if (!childLayer)
|
|
94
|
+
return;
|
|
95
|
+
if (childLayer.type === 'group' || !childLayer.groupId)
|
|
96
|
+
return;
|
|
97
|
+
const groupLayer = this.findLayer(this.activePage, childLayer.groupId);
|
|
98
|
+
if (!groupLayer)
|
|
99
|
+
return;
|
|
100
|
+
if (groupLayer.type !== 'group')
|
|
101
|
+
return;
|
|
102
|
+
return { groupLayer, childLayer };
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
activeLayers = $derived.by(() => {
|
|
106
|
+
if (this.activeSelection.type === 'root-layers') {
|
|
107
|
+
const layerIds = this.activeSelection.layerIds;
|
|
108
|
+
return this.rootLayers.filter((l) => layerIds.has(l.id));
|
|
109
|
+
}
|
|
110
|
+
else if (this.activeSelection.type === 'child-layer' && this.activeGroupAndChild) {
|
|
111
|
+
return [this.activeGroupAndChild.groupLayer];
|
|
112
|
+
}
|
|
113
|
+
return [];
|
|
114
|
+
});
|
|
115
|
+
selectedLayers = $derived.by(() => {
|
|
116
|
+
if (this.activeSelection.type === 'root-layers') {
|
|
117
|
+
const layerIds = this.activeSelection.layerIds;
|
|
118
|
+
return this.rootLayers.filter((l) => layerIds.has(l.id));
|
|
119
|
+
}
|
|
120
|
+
else if (this.activeSelection.type === 'child-layer' && this.activeGroupAndChild) {
|
|
121
|
+
return [this.activeGroupAndChild.childLayer];
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
});
|
|
125
|
+
selectedLayersNotLocked = $derived(this.selectedLayers.filter((layer) => !layer.locked));
|
|
126
|
+
selectedSimpleLayersNotLocked = $derived(this.selectedLayersNotLocked.flatMap((l) => l.type === 'group' ? this.findGroupChildren(this.activePage, l.id) : l));
|
|
127
|
+
activeGroupRotate = $state(0);
|
|
128
|
+
pageSelected = $state(false);
|
|
129
|
+
clipboard = null;
|
|
130
|
+
htmlEditor = createEditor({
|
|
131
|
+
extensions,
|
|
132
|
+
injectCSS: false,
|
|
133
|
+
editorProps: { attributes: { class: 'whitespace-pre-wrap focus:outline-none' } },
|
|
134
|
+
});
|
|
135
|
+
activeAction = $state(null);
|
|
136
|
+
historyActions = $state([]);
|
|
137
|
+
historyIndex = $state(-1);
|
|
138
|
+
dragged = $state();
|
|
139
|
+
fileDragged = $state(false);
|
|
140
|
+
constructor(options = {}) {
|
|
141
|
+
if (options.mode === 'single') {
|
|
142
|
+
const { page, ...rest } = options;
|
|
143
|
+
Object.assign(this, { ...rest });
|
|
144
|
+
if (page) {
|
|
145
|
+
Object.assign(this, { pages: [page] });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
Object.assign(this, options);
|
|
150
|
+
}
|
|
151
|
+
if (!this.pages.length) {
|
|
152
|
+
this.addPage();
|
|
153
|
+
}
|
|
154
|
+
this.activePage = this.pages[0];
|
|
155
|
+
setEditorContext(this);
|
|
156
|
+
}
|
|
157
|
+
buildEmptyPage(sortOrder = 1) {
|
|
158
|
+
return {
|
|
159
|
+
id: this.generateId(),
|
|
160
|
+
sortOrder,
|
|
161
|
+
locked: false,
|
|
162
|
+
backgroundColor: null,
|
|
163
|
+
backgroundImage: null,
|
|
164
|
+
backgroundLocked: false,
|
|
165
|
+
layers: [],
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
addPage({ page, index } = {}) {
|
|
169
|
+
if (this.mode !== 'multiple')
|
|
170
|
+
return false;
|
|
171
|
+
index ??= this.sortedPages.findIndex((l) => l.id === this.activePage.id) + 1;
|
|
172
|
+
console.log('index', index);
|
|
173
|
+
if (!page) {
|
|
174
|
+
page = this.buildEmptyPage();
|
|
175
|
+
const inheritedPage = this.sortedPages[index > 0 ? index - 1 : 0];
|
|
176
|
+
if (inheritedPage) {
|
|
177
|
+
Object.assign(page, { backgroundColor: inheritedPage.backgroundColor });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const prevPage = this.sortedPages[index - 1];
|
|
181
|
+
const nextPage = this.sortedPages[index];
|
|
182
|
+
if (!prevPage && !nextPage)
|
|
183
|
+
return false;
|
|
184
|
+
const sortOrder = nextPage && prevPage
|
|
185
|
+
? (prevPage.sortOrder + nextPage.sortOrder) / 2
|
|
186
|
+
: prevPage
|
|
187
|
+
? prevPage.sortOrder + 1
|
|
188
|
+
: nextPage.sortOrder - 1;
|
|
189
|
+
return this.historyPush({ type: 'pageAdd', page: { ...page, sortOrder } });
|
|
190
|
+
}
|
|
191
|
+
removePage(pageId) {
|
|
192
|
+
if (this.mode !== 'multiple')
|
|
193
|
+
return false;
|
|
194
|
+
const page = this.findPage(pageId);
|
|
195
|
+
if (!page || page.locked)
|
|
196
|
+
return false;
|
|
197
|
+
this.historyPush({ type: 'pageRemove', page });
|
|
198
|
+
}
|
|
199
|
+
copyPage(pageId) {
|
|
200
|
+
const page = this.findPage(pageId);
|
|
201
|
+
if (!page)
|
|
202
|
+
return;
|
|
203
|
+
this.clipboard = $state.snapshot(page);
|
|
204
|
+
}
|
|
205
|
+
togglePageLocked(pageId) {
|
|
206
|
+
if (this.mode !== 'multiple')
|
|
207
|
+
return false;
|
|
208
|
+
const page = this.findPage(pageId);
|
|
209
|
+
if (!page)
|
|
210
|
+
return false;
|
|
211
|
+
return this.historyPush({
|
|
212
|
+
type: 'pageUpdate',
|
|
213
|
+
pageId,
|
|
214
|
+
undo: { locked: page.locked },
|
|
215
|
+
redo: { locked: !page.locked },
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
removeBackground(pageId) {
|
|
219
|
+
const page = this.findPage(pageId);
|
|
220
|
+
if (!page || page.locked)
|
|
221
|
+
return;
|
|
222
|
+
this.historyPush({
|
|
223
|
+
pageId: page.id,
|
|
224
|
+
type: 'pageUpdate',
|
|
225
|
+
...(page.backgroundImage
|
|
226
|
+
? { undo: { backgroundImage: page.backgroundImage }, redo: { backgroundImage: null } }
|
|
227
|
+
: { undo: { backgroundColor: page.backgroundColor }, redo: { backgroundColor: null } }),
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
backgroundImageToLayer(pageId) {
|
|
231
|
+
const page = this.findPage(pageId);
|
|
232
|
+
if (!page || page.locked)
|
|
233
|
+
return;
|
|
234
|
+
if (!page.backgroundImage)
|
|
235
|
+
return;
|
|
236
|
+
this.historyPush([
|
|
237
|
+
{
|
|
238
|
+
type: 'backgroundImageRemove',
|
|
239
|
+
pageId: page.id,
|
|
240
|
+
previousBackgroundImage: page.backgroundImage,
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
type: 'layerAdd',
|
|
244
|
+
pageId: page.id,
|
|
245
|
+
layer: this.buildImageLayer({
|
|
246
|
+
...page.backgroundImage,
|
|
247
|
+
sortOrder: this.generateLayersSortOrder()[0],
|
|
248
|
+
// clean some background props
|
|
249
|
+
scale: 1,
|
|
250
|
+
opacity: 1,
|
|
251
|
+
// clean offset to avoid wrong positioning
|
|
252
|
+
offsetX: 0,
|
|
253
|
+
offsetY: 0,
|
|
254
|
+
}),
|
|
255
|
+
},
|
|
256
|
+
]);
|
|
257
|
+
}
|
|
258
|
+
backgroundToggleLocked(pageId) {
|
|
259
|
+
const page = this.findPage(pageId);
|
|
260
|
+
if (!page || page.locked)
|
|
261
|
+
return false;
|
|
262
|
+
return this.historyPush({
|
|
263
|
+
type: 'pageUpdate',
|
|
264
|
+
pageId,
|
|
265
|
+
undo: { backgroundLocked: page.backgroundLocked },
|
|
266
|
+
redo: { backgroundLocked: !page.backgroundLocked },
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
buildLayerDuplicate(layer, groupId) {
|
|
270
|
+
return {
|
|
271
|
+
...layer,
|
|
272
|
+
id: this.generateId(),
|
|
273
|
+
...(groupId && { groupId }),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
duplicatePage(page) {
|
|
277
|
+
if (this.mode !== 'multiple')
|
|
278
|
+
return false;
|
|
279
|
+
const { layers, ...rest } = page;
|
|
280
|
+
const duplicates = this.buildLayersDuplicates(layers);
|
|
281
|
+
const duplicate = {
|
|
282
|
+
...rest,
|
|
283
|
+
id: this.generateId(),
|
|
284
|
+
layers: duplicates,
|
|
285
|
+
};
|
|
286
|
+
return this.addPage({
|
|
287
|
+
page: duplicate,
|
|
288
|
+
index: this.sortedPages.findIndex((l) => l.id === page.id) + 1,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
generateLayersSortOrder(amount = 1, index) {
|
|
292
|
+
const rootLayers = this.getRootLayers(this.activePage);
|
|
293
|
+
index ??= rootLayers.length;
|
|
294
|
+
index = Math.min(index, rootLayers.length);
|
|
295
|
+
const prev = rootLayers[index - 1];
|
|
296
|
+
const next = rootLayers[index];
|
|
297
|
+
let startingOrder = 0;
|
|
298
|
+
let increment = 1;
|
|
299
|
+
if (next && prev) {
|
|
300
|
+
increment = (next.sortOrder - prev.sortOrder) / (amount + 1);
|
|
301
|
+
startingOrder = prev.sortOrder;
|
|
302
|
+
}
|
|
303
|
+
else if (prev) {
|
|
304
|
+
startingOrder = prev.sortOrder;
|
|
305
|
+
}
|
|
306
|
+
else if (next) {
|
|
307
|
+
startingOrder = next.sortOrder - (amount + 1);
|
|
308
|
+
}
|
|
309
|
+
return Array.from({ length: amount }, (_, i) => startingOrder + increment * (i + 1));
|
|
310
|
+
}
|
|
311
|
+
buildTextLayer({ html, width, height, ...rest }) {
|
|
312
|
+
const scale = rest.scale ?? 1;
|
|
313
|
+
const x = rest.x ?? (this.width - width * scale) / 2;
|
|
314
|
+
const y = rest.y ?? (this.height - height * scale) / 2;
|
|
315
|
+
const layer = {
|
|
316
|
+
id: this.generateId(),
|
|
317
|
+
groupId: null,
|
|
318
|
+
type: 'text',
|
|
319
|
+
x,
|
|
320
|
+
y,
|
|
321
|
+
width,
|
|
322
|
+
height,
|
|
323
|
+
html,
|
|
324
|
+
sortOrder: 1,
|
|
325
|
+
locked: false,
|
|
326
|
+
rotate: 0,
|
|
327
|
+
opacity: 1,
|
|
328
|
+
scale,
|
|
329
|
+
...rest,
|
|
330
|
+
};
|
|
331
|
+
console.log('textLayer', layer);
|
|
332
|
+
return layer;
|
|
333
|
+
}
|
|
334
|
+
getMaxScale({ width, height }) {
|
|
335
|
+
return Math.min(this.width / 2 / width, this.height / 2 / height);
|
|
336
|
+
}
|
|
337
|
+
buildImageLayer({ image, ...rest }) {
|
|
338
|
+
const width = rest.width ?? image.width;
|
|
339
|
+
const height = rest.height ?? image.height;
|
|
340
|
+
const inputScale = rest.scale ?? 1;
|
|
341
|
+
const scale = rest.scale ?? Math.min(this.getMaxScale({ width, height }), 1);
|
|
342
|
+
if (scale !== 1) {
|
|
343
|
+
rest.scale = scale;
|
|
344
|
+
}
|
|
345
|
+
// adjust x and y according to scale if set or center image
|
|
346
|
+
const x = rest.x == null
|
|
347
|
+
? (this.width - width * scale) / 2
|
|
348
|
+
: rest.x + (width * inputScale - width * scale) / 2;
|
|
349
|
+
const y = rest.y == null
|
|
350
|
+
? (this.height - height * scale) / 2
|
|
351
|
+
: rest.y + (height * inputScale - height * scale) / 2;
|
|
352
|
+
const layer = {
|
|
353
|
+
id: this.generateId(),
|
|
354
|
+
groupId: null,
|
|
355
|
+
type: 'image',
|
|
356
|
+
width,
|
|
357
|
+
height,
|
|
358
|
+
image: { ...image },
|
|
359
|
+
sortOrder: 1,
|
|
360
|
+
locked: false,
|
|
361
|
+
rotate: 0,
|
|
362
|
+
opacity: 1,
|
|
363
|
+
scale: 1,
|
|
364
|
+
imageRotate: 0,
|
|
365
|
+
offsetX: 0,
|
|
366
|
+
offsetY: 0,
|
|
367
|
+
cornerRadius: 0,
|
|
368
|
+
flipX: false,
|
|
369
|
+
flipY: false,
|
|
370
|
+
borderStyle: 'solid',
|
|
371
|
+
borderWidth: 0,
|
|
372
|
+
borderColor: '#000000',
|
|
373
|
+
...rest,
|
|
374
|
+
x,
|
|
375
|
+
y,
|
|
376
|
+
};
|
|
377
|
+
console.log('imageLayer', layer);
|
|
378
|
+
return layer;
|
|
379
|
+
}
|
|
380
|
+
addLayers(pageId, layers, index) {
|
|
381
|
+
const page = this.findPage(pageId);
|
|
382
|
+
if (!page || page.locked)
|
|
383
|
+
return;
|
|
384
|
+
layers = Array.isArray(layers) ? layers : [layers];
|
|
385
|
+
const layersSortOrder = this.generateLayersSortOrder(layers.length, index);
|
|
386
|
+
this.historyPush(layers.map((layer, i) => ({
|
|
387
|
+
type: 'layerAdd',
|
|
388
|
+
pageId: page.id,
|
|
389
|
+
layer: { ...layer, sortOrder: layersSortOrder[i] },
|
|
390
|
+
})));
|
|
391
|
+
this.setActiveLayers(layers.map((l) => l.id));
|
|
392
|
+
}
|
|
393
|
+
copyLayers(pageId, layerIds) {
|
|
394
|
+
const page = this.findPage(pageId);
|
|
395
|
+
if (!page || page.locked)
|
|
396
|
+
return;
|
|
397
|
+
const layers = this.findRootLayers(page, layerIds);
|
|
398
|
+
if (!layers.length)
|
|
399
|
+
return;
|
|
400
|
+
this.clipboard = $state.snapshot([
|
|
401
|
+
...layers,
|
|
402
|
+
...layers
|
|
403
|
+
.filter((l) => l.type === 'group')
|
|
404
|
+
.flatMap((g) => this.findGroupChildren(page, g.id)),
|
|
405
|
+
]);
|
|
406
|
+
}
|
|
407
|
+
buildGroupChildrenDuplicates(layers, oldGroupId, newGroupId) {
|
|
408
|
+
return layers
|
|
409
|
+
.filter((l) => l.type !== 'group' && l.groupId === oldGroupId)
|
|
410
|
+
.map((l) => this.buildLayerDuplicate(l, newGroupId));
|
|
411
|
+
}
|
|
412
|
+
buildLayersDuplicates(layers) {
|
|
413
|
+
const rootLayers = layers.filter((l) => l.type === 'group' || !l.groupId);
|
|
414
|
+
const duplicates = rootLayers.flatMap((l) => {
|
|
415
|
+
const duplicate = this.buildLayerDuplicate(l);
|
|
416
|
+
return l.type === 'group'
|
|
417
|
+
? [duplicate, ...this.buildGroupChildrenDuplicates(layers, l.id, duplicate.id)]
|
|
418
|
+
: duplicate;
|
|
419
|
+
});
|
|
420
|
+
return duplicates;
|
|
421
|
+
}
|
|
422
|
+
duplicateLayers(layers) {
|
|
423
|
+
const duplicates = this.buildLayersDuplicates(layers);
|
|
424
|
+
const rootDuplicates = duplicates.filter((l) => l.type === 'group' || !l.groupId);
|
|
425
|
+
const increment = 50;
|
|
426
|
+
const groupBbox = calculateGroupBoundingBox(layers);
|
|
427
|
+
const xIncrement = groupBbox.x + groupBbox.width / 2 > this.width / 2 ? -increment : increment;
|
|
428
|
+
const yIncrement = groupBbox.y + groupBbox.height / 2 > this.height / 2 ? -increment : increment;
|
|
429
|
+
let xAdjust = 0;
|
|
430
|
+
let iteration = 0;
|
|
431
|
+
const tryToDuplicate = () => {
|
|
432
|
+
rootDuplicates.forEach((duplicate, i) => {
|
|
433
|
+
const layer = layers[i];
|
|
434
|
+
Object.assign(duplicate, {
|
|
435
|
+
x: layer.x + xAdjust + xIncrement * iteration,
|
|
436
|
+
y: layer.y + yIncrement * iteration,
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
const occupied = rootDuplicates.every((duplicate) => this.activePage.layers.some((l) => l.type === duplicate.type &&
|
|
440
|
+
l.x === duplicate.x &&
|
|
441
|
+
l.y === duplicate.y &&
|
|
442
|
+
l.scale === duplicate.scale &&
|
|
443
|
+
l.rotate === duplicate.rotate));
|
|
444
|
+
if (occupied) {
|
|
445
|
+
iteration++;
|
|
446
|
+
tryToDuplicate();
|
|
447
|
+
}
|
|
448
|
+
else if (!rootDuplicates.some((duplicate) => this.isLayerOutOfBounds(duplicate))) {
|
|
449
|
+
this.addLayers(this.activePage.id, duplicates);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
xAdjust += xIncrement;
|
|
453
|
+
iteration = 0;
|
|
454
|
+
const newX = groupBbox.x + xAdjust;
|
|
455
|
+
if (newX >= 0 && newX < this.width) {
|
|
456
|
+
tryToDuplicate();
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
tryToDuplicate();
|
|
461
|
+
}
|
|
462
|
+
getAbsoluteGroupLayers(groupLayer, children) {
|
|
463
|
+
const rad = degToRad(groupLayer.rotate);
|
|
464
|
+
const groupCenter = {
|
|
465
|
+
x: groupLayer.x + (groupLayer.width * groupLayer.scale) / 2,
|
|
466
|
+
y: groupLayer.y + (groupLayer.height * groupLayer.scale) / 2,
|
|
467
|
+
};
|
|
468
|
+
return children.map((l) => {
|
|
469
|
+
const relativeCenter = {
|
|
470
|
+
x: groupLayer.x + (l.x + (l.width * l.scale) / 2) * groupLayer.scale,
|
|
471
|
+
y: groupLayer.y + (l.y + (l.height * l.scale) / 2) * groupLayer.scale,
|
|
472
|
+
};
|
|
473
|
+
const center = rotatePoint(rad, relativeCenter, groupCenter);
|
|
474
|
+
return {
|
|
475
|
+
...l,
|
|
476
|
+
x: center.x - (l.width * l.scale * groupLayer.scale) / 2,
|
|
477
|
+
y: center.y - (l.height * l.scale * groupLayer.scale) / 2,
|
|
478
|
+
rotate: l.rotate + groupLayer.rotate,
|
|
479
|
+
scale: l.scale * groupLayer.scale,
|
|
480
|
+
opacity: l.opacity * groupLayer.opacity,
|
|
481
|
+
};
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
groupLayers(pageId, layerIds) {
|
|
485
|
+
const page = this.findPage(pageId);
|
|
486
|
+
if (!page || page.locked)
|
|
487
|
+
return;
|
|
488
|
+
const layers = this.findRootLayers(page, layerIds);
|
|
489
|
+
if (layers.length < 2 || layers.some(({ locked }) => locked))
|
|
490
|
+
return;
|
|
491
|
+
const absoluteLayers = layers.flatMap((layer) => layer.type === 'group'
|
|
492
|
+
? this.getAbsoluteGroupLayers(layer, this.findGroupChildren(page, layer.id))
|
|
493
|
+
: layer);
|
|
494
|
+
const bbox = calculateGroupRotatedBoundingBox(absoluteLayers, this.activeGroupRotate);
|
|
495
|
+
const relativeRects = calculateRelativeRects(bbox, absoluteLayers);
|
|
496
|
+
const groupLayer = {
|
|
497
|
+
id: this.generateId(),
|
|
498
|
+
type: 'group',
|
|
499
|
+
...bbox,
|
|
500
|
+
opacity: 1,
|
|
501
|
+
sortOrder: Math.max(...layers.map(({ sortOrder }) => sortOrder)),
|
|
502
|
+
locked: false,
|
|
503
|
+
};
|
|
504
|
+
const groupLayers = absoluteLayers.map((l, i) => {
|
|
505
|
+
return {
|
|
506
|
+
...l,
|
|
507
|
+
id: this.generateId(),
|
|
508
|
+
groupId: groupLayer.id,
|
|
509
|
+
x: relativeRects[i].x,
|
|
510
|
+
y: relativeRects[i].y,
|
|
511
|
+
rotate: relativeRects[i].rotate,
|
|
512
|
+
};
|
|
513
|
+
});
|
|
514
|
+
this.historyPush([
|
|
515
|
+
...$state.snapshot(layers).map((layer) => ({
|
|
516
|
+
type: 'layerRemove',
|
|
517
|
+
pageId,
|
|
518
|
+
layer,
|
|
519
|
+
})),
|
|
520
|
+
{
|
|
521
|
+
type: 'layerAdd',
|
|
522
|
+
pageId,
|
|
523
|
+
layer: groupLayer,
|
|
524
|
+
},
|
|
525
|
+
...groupLayers.map((layer) => ({
|
|
526
|
+
type: 'layerAdd',
|
|
527
|
+
pageId,
|
|
528
|
+
layer,
|
|
529
|
+
})),
|
|
530
|
+
]);
|
|
531
|
+
this.setActiveLayers(groupLayer.id);
|
|
532
|
+
}
|
|
533
|
+
ungroupLayers(pageId, layerIds) {
|
|
534
|
+
const page = this.findPage(pageId);
|
|
535
|
+
if (!page || page.locked)
|
|
536
|
+
return;
|
|
537
|
+
const layers = this.findRootLayers(page, layerIds);
|
|
538
|
+
if (!layers.length || layers.some(({ locked }) => locked))
|
|
539
|
+
return;
|
|
540
|
+
if (!layers.every((layer) => layer.type === 'group'))
|
|
541
|
+
return;
|
|
542
|
+
const absoluteLayers = layers
|
|
543
|
+
.flatMap((l) => this.getAbsoluteGroupLayers(l, this.findGroupChildren(page, l.id)))
|
|
544
|
+
.map((l) => ({
|
|
545
|
+
...l,
|
|
546
|
+
id: this.generateId(),
|
|
547
|
+
groupId: null,
|
|
548
|
+
}));
|
|
549
|
+
this.historyPush([
|
|
550
|
+
...$state.snapshot(layers).map((layer) => ({
|
|
551
|
+
type: 'layerRemove',
|
|
552
|
+
pageId,
|
|
553
|
+
layer,
|
|
554
|
+
})),
|
|
555
|
+
...absoluteLayers.map((layer) => ({
|
|
556
|
+
type: 'layerAdd',
|
|
557
|
+
pageId,
|
|
558
|
+
layer,
|
|
559
|
+
})),
|
|
560
|
+
]);
|
|
561
|
+
this.setActiveLayers(absoluteLayers.map((l) => l.id));
|
|
562
|
+
}
|
|
563
|
+
removeRootLayers(pageId, layerIds) {
|
|
564
|
+
const page = this.findPage(pageId);
|
|
565
|
+
if (!page || page.locked)
|
|
566
|
+
return;
|
|
567
|
+
const layers = this.findRootLayers(page, layerIds).filter(({ locked }) => !locked);
|
|
568
|
+
if (!layers.length)
|
|
569
|
+
return;
|
|
570
|
+
this.historyPush($state.snapshot(layers).map((layer) => ({
|
|
571
|
+
type: 'layerRemove',
|
|
572
|
+
pageId,
|
|
573
|
+
layer,
|
|
574
|
+
})));
|
|
575
|
+
}
|
|
576
|
+
removeLayers(pageId, layerIds) {
|
|
577
|
+
const page = this.findPage(pageId);
|
|
578
|
+
if (!page || page.locked)
|
|
579
|
+
return;
|
|
580
|
+
const layers = this.findRootLayers(page, layerIds).filter(({ locked }) => !locked);
|
|
581
|
+
if (layers.length) {
|
|
582
|
+
this.removeRootLayers(pageId, layers.map((l) => l.id));
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
const layerId = Array.isArray(layerIds) ? layerIds[0] : layerIds;
|
|
586
|
+
const layer = this.findLayer(this.activePage, layerId);
|
|
587
|
+
if (!layer || layer.type === 'group' || !layer.groupId)
|
|
588
|
+
return;
|
|
589
|
+
const groupLayer = this.findLayer(this.activePage, layer.groupId);
|
|
590
|
+
if (!groupLayer || groupLayer.type !== 'group')
|
|
591
|
+
return;
|
|
592
|
+
const children = this.findGroupChildren(page, groupLayer.id);
|
|
593
|
+
const restChildren = children.filter((l) => l.id !== layer.id);
|
|
594
|
+
const restAbsoluteChildren = this.getAbsoluteGroupLayers(groupLayer, restChildren);
|
|
595
|
+
if (children.length <= 2) {
|
|
596
|
+
const newLayers = restAbsoluteChildren.map((l) => ({
|
|
597
|
+
...l,
|
|
598
|
+
id: this.generateId(),
|
|
599
|
+
groupId: null,
|
|
600
|
+
}));
|
|
601
|
+
this.historyPush([
|
|
602
|
+
{
|
|
603
|
+
type: 'layerRemove',
|
|
604
|
+
pageId,
|
|
605
|
+
layer: groupLayer,
|
|
606
|
+
},
|
|
607
|
+
...newLayers.map((layer) => ({
|
|
608
|
+
type: 'layerAdd',
|
|
609
|
+
pageId,
|
|
610
|
+
layer,
|
|
611
|
+
})),
|
|
612
|
+
]);
|
|
613
|
+
this.setActiveLayers(newLayers.map((l) => l.id));
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
const newGroupBbox = calculateGroupRotatedBoundingBox(restAbsoluteChildren, groupLayer.rotate);
|
|
617
|
+
const relativeLayers = calculateRelativeRects(newGroupBbox, restAbsoluteChildren);
|
|
618
|
+
this.historyPush([
|
|
619
|
+
{
|
|
620
|
+
type: 'layerUpdate',
|
|
621
|
+
pageId,
|
|
622
|
+
layer: { id: groupLayer.id, type: groupLayer.type },
|
|
623
|
+
undo: {
|
|
624
|
+
x: groupLayer.x,
|
|
625
|
+
y: groupLayer.y,
|
|
626
|
+
width: groupLayer.width,
|
|
627
|
+
height: groupLayer.height,
|
|
628
|
+
},
|
|
629
|
+
redo: {
|
|
630
|
+
x: newGroupBbox.x,
|
|
631
|
+
y: newGroupBbox.y,
|
|
632
|
+
width: newGroupBbox.width / groupLayer.scale,
|
|
633
|
+
height: newGroupBbox.height / groupLayer.scale,
|
|
634
|
+
},
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
type: 'layerRemove',
|
|
638
|
+
pageId,
|
|
639
|
+
layer: $state.snapshot(layer),
|
|
640
|
+
},
|
|
641
|
+
...restChildren.map((layer, i) => {
|
|
642
|
+
return {
|
|
643
|
+
type: 'layerUpdate',
|
|
644
|
+
pageId,
|
|
645
|
+
layer: { id: layer.id, type: layer.type },
|
|
646
|
+
undo: { x: layer.x, y: layer.y },
|
|
647
|
+
redo: {
|
|
648
|
+
x: relativeLayers[i].x / groupLayer.scale,
|
|
649
|
+
y: relativeLayers[i].y / groupLayer.scale,
|
|
650
|
+
},
|
|
651
|
+
};
|
|
652
|
+
}),
|
|
653
|
+
]);
|
|
654
|
+
if (this.activePage.id === pageId) {
|
|
655
|
+
this.setActiveLayers(groupLayer.id);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
checkOverlap(corners, layer) {
|
|
661
|
+
const layerCorners = getRotatedCorners(layer);
|
|
662
|
+
return checkPolygonsIntersect(corners, layerCorners);
|
|
663
|
+
}
|
|
664
|
+
getLayerOverlaps(page, layers) {
|
|
665
|
+
const rootLayers = this.getRootLayers(page);
|
|
666
|
+
const indexes = layers.map((layer) => rootLayers.findIndex(({ id }) => id === layer.id));
|
|
667
|
+
const minIndex = Math.min(...indexes);
|
|
668
|
+
const maxIndex = Math.max(...indexes);
|
|
669
|
+
const corners = getRotatedCorners(layers.length === 1 ? layers[0] : calculateGroupBoundingBox(layers));
|
|
670
|
+
const overlapsIndexes = rootLayers
|
|
671
|
+
.map((l, i) => ({ l, i }))
|
|
672
|
+
.filter(({ l }) => !layers.includes(l) && this.checkOverlap(corners, l))
|
|
673
|
+
.map(({ i }) => i);
|
|
674
|
+
const overlaps = {
|
|
675
|
+
forward: overlapsIndexes.find((i) => i > maxIndex),
|
|
676
|
+
front: overlapsIndexes.findLast((i) => i > maxIndex),
|
|
677
|
+
backward: overlapsIndexes.findLast((i) => i < minIndex),
|
|
678
|
+
back: overlapsIndexes.find((i) => i < minIndex),
|
|
679
|
+
};
|
|
680
|
+
if (overlaps.forward === undefined) {
|
|
681
|
+
const forwardIndex = overlapsIndexes.findLast((i) => i > minIndex);
|
|
682
|
+
overlaps.forward = forwardIndex;
|
|
683
|
+
overlaps.front = forwardIndex;
|
|
684
|
+
}
|
|
685
|
+
if (overlaps.backward === undefined) {
|
|
686
|
+
const backwardIndex = overlapsIndexes.find((i) => i < maxIndex);
|
|
687
|
+
overlaps.backward = backwardIndex;
|
|
688
|
+
overlaps.back = backwardIndex;
|
|
689
|
+
}
|
|
690
|
+
return overlaps.backward !== undefined || overlaps.forward !== undefined ? overlaps : null;
|
|
691
|
+
}
|
|
692
|
+
moveLayers(pageId, layerIds, direction) {
|
|
693
|
+
const page = this.findPage(pageId);
|
|
694
|
+
if (!page || page.locked)
|
|
695
|
+
return;
|
|
696
|
+
const layers = this.findRootLayers(page, layerIds);
|
|
697
|
+
if (!layers.length || layers.some(({ locked }) => locked))
|
|
698
|
+
return;
|
|
699
|
+
const overlaps = this.getLayerOverlaps(page, layers);
|
|
700
|
+
if (!overlaps)
|
|
701
|
+
return;
|
|
702
|
+
const newIndex = overlaps[direction];
|
|
703
|
+
if (newIndex === undefined)
|
|
704
|
+
return;
|
|
705
|
+
const sortOrders = this.generateLayersSortOrder(layers.length, ['forward', 'front'].includes(direction) ? newIndex + 1 : newIndex);
|
|
706
|
+
this.historyPush(layers.map((layer, i) => {
|
|
707
|
+
return {
|
|
708
|
+
type: 'layerUpdate',
|
|
709
|
+
pageId,
|
|
710
|
+
layer: { id: layer.id, type: layer.type },
|
|
711
|
+
undo: { sortOrder: layer.sortOrder },
|
|
712
|
+
redo: { sortOrder: sortOrders[i] },
|
|
713
|
+
};
|
|
714
|
+
}));
|
|
715
|
+
}
|
|
716
|
+
alignLayers(pageId, layerIds, origin) {
|
|
717
|
+
const page = this.findPage(pageId);
|
|
718
|
+
if (!page || page.locked)
|
|
719
|
+
return;
|
|
720
|
+
const layers = this.findRootLayers(page, layerIds);
|
|
721
|
+
if (!layers.length || layers.some(({ locked }) => locked))
|
|
722
|
+
return;
|
|
723
|
+
const bbox = layers.length === 1
|
|
724
|
+
? { x: 0, y: 0, width: this.width, height: this.height }
|
|
725
|
+
: calculateBoundingBox(calculateGroupRotatedBoundingBox(layers, this.activeGroupRotate));
|
|
726
|
+
this.historyPush(layers.map((layer) => {
|
|
727
|
+
const layerBbox = calculateBoundingBox(layer);
|
|
728
|
+
const { x, y, width, height, scale } = layer;
|
|
729
|
+
const alignment = {
|
|
730
|
+
left: {
|
|
731
|
+
undo: { x },
|
|
732
|
+
redo: { x: bbox.x + (layerBbox.width - width * scale) / 2 },
|
|
733
|
+
},
|
|
734
|
+
center: {
|
|
735
|
+
undo: { x },
|
|
736
|
+
redo: { x: bbox.x + (bbox.width - width * scale) / 2 },
|
|
737
|
+
},
|
|
738
|
+
right: {
|
|
739
|
+
undo: { x },
|
|
740
|
+
redo: {
|
|
741
|
+
x: bbox.x + bbox.width - width * scale - (layerBbox.width - width * scale) / 2,
|
|
742
|
+
},
|
|
743
|
+
},
|
|
744
|
+
top: {
|
|
745
|
+
undo: { y },
|
|
746
|
+
redo: { y: bbox.y + (layerBbox.height - height * scale) / 2 },
|
|
747
|
+
},
|
|
748
|
+
middle: {
|
|
749
|
+
undo: { y },
|
|
750
|
+
redo: { y: bbox.y + (bbox.height - height * scale) / 2 },
|
|
751
|
+
},
|
|
752
|
+
bottom: {
|
|
753
|
+
undo: { y },
|
|
754
|
+
redo: {
|
|
755
|
+
y: bbox.y + bbox.height - height * scale - (layerBbox.height - height * scale) / 2,
|
|
756
|
+
},
|
|
757
|
+
},
|
|
758
|
+
}[origin];
|
|
759
|
+
return {
|
|
760
|
+
type: 'layerUpdate',
|
|
761
|
+
pageId,
|
|
762
|
+
layer: { id: layer.id, type: layer.type },
|
|
763
|
+
...alignment,
|
|
764
|
+
};
|
|
765
|
+
}));
|
|
766
|
+
}
|
|
767
|
+
imageLayerToBackground(pageId, layerId) {
|
|
768
|
+
const page = this.findPage(pageId);
|
|
769
|
+
if (!page || page.locked)
|
|
770
|
+
return false;
|
|
771
|
+
if (page.backgroundLocked)
|
|
772
|
+
return false;
|
|
773
|
+
const layer = this.findLayer(page, layerId);
|
|
774
|
+
if (!layer || layer.locked)
|
|
775
|
+
return false;
|
|
776
|
+
if (layer.type !== 'image')
|
|
777
|
+
return false;
|
|
778
|
+
const { width, height, rotate, image, opacity, flipX, flipY, imageRotate, offsetX, offsetY } = $state.snapshot(layer);
|
|
779
|
+
const cover = calculateImageCover({ width, height, rotate, imageRotate }, { width: this.width, height: this.height });
|
|
780
|
+
const backgroundImage = {
|
|
781
|
+
image,
|
|
782
|
+
scale: cover.scale,
|
|
783
|
+
offsetX: offsetX + cover.offsetX,
|
|
784
|
+
offsetY: offsetY + cover.offsetY,
|
|
785
|
+
imageRotate: rotate + imageRotate,
|
|
786
|
+
opacity,
|
|
787
|
+
flipX,
|
|
788
|
+
flipY,
|
|
789
|
+
};
|
|
790
|
+
return this.historyPush([
|
|
791
|
+
{
|
|
792
|
+
type: 'layerRemove',
|
|
793
|
+
pageId: page.id,
|
|
794
|
+
layer: layer,
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
type: 'backgroundImageAdd',
|
|
798
|
+
pageId: page.id,
|
|
799
|
+
backgroundImage,
|
|
800
|
+
previousBackgroundImage: $state.snapshot(page.backgroundImage),
|
|
801
|
+
},
|
|
802
|
+
]);
|
|
803
|
+
}
|
|
804
|
+
toggleLayersLocked(pageId, layerIds, locked) {
|
|
805
|
+
const page = this.findPage(pageId);
|
|
806
|
+
if (!page || page.locked)
|
|
807
|
+
return false;
|
|
808
|
+
const layers = this.findRootLayers(page, layerIds);
|
|
809
|
+
if (!layers.length)
|
|
810
|
+
return false;
|
|
811
|
+
return this.historyPush(layers.map((layer) => ({
|
|
812
|
+
type: 'layerUpdate',
|
|
813
|
+
pageId,
|
|
814
|
+
layer: { id: layer.id, type: layer.type },
|
|
815
|
+
undo: { locked: layer.locked },
|
|
816
|
+
redo: { locked },
|
|
817
|
+
})));
|
|
818
|
+
}
|
|
819
|
+
clipboardPaste() {
|
|
820
|
+
if (this.clipboard) {
|
|
821
|
+
if (Array.isArray(this.clipboard)) {
|
|
822
|
+
this.duplicateLayers(this.clipboard);
|
|
823
|
+
}
|
|
824
|
+
else if ('layers' in this.clipboard) {
|
|
825
|
+
this.duplicatePage(this.clipboard);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
dropDragged(x, y, index) {
|
|
830
|
+
if (this.dragged) {
|
|
831
|
+
if ('image' in this.dragged) {
|
|
832
|
+
const { image, scale } = this.dragged;
|
|
833
|
+
const { width, height } = image;
|
|
834
|
+
const layer = this.buildImageLayer({ x, y, width, height, image, scale });
|
|
835
|
+
this.addLayers(this.activePage.id, layer, index);
|
|
836
|
+
}
|
|
837
|
+
else if (this.dragged?.ref) {
|
|
838
|
+
const { ref, html, scale } = this.dragged;
|
|
839
|
+
const rect = ref.getBoundingClientRect();
|
|
840
|
+
const width = rect.width / scale / this.zoom;
|
|
841
|
+
const height = rect.height / scale / this.zoom;
|
|
842
|
+
const layer = this.buildTextLayer({ x, y, width, height, scale, html });
|
|
843
|
+
this.addLayers(this.activePage.id, layer, index);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
setActivePage(pageId) {
|
|
848
|
+
if (this.mode !== 'multiple')
|
|
849
|
+
return;
|
|
850
|
+
const page = this.findPage(pageId);
|
|
851
|
+
if (!page)
|
|
852
|
+
return;
|
|
853
|
+
this.clearActiveLayer();
|
|
854
|
+
// this.historyReset();
|
|
855
|
+
this.activePage = page;
|
|
856
|
+
this.pageSelected = true;
|
|
857
|
+
return page;
|
|
858
|
+
}
|
|
859
|
+
setActiveLayers(layerIds, action) {
|
|
860
|
+
layerIds = Array.isArray(layerIds) ? layerIds : [layerIds];
|
|
861
|
+
// Reset the active action, background, and page selection
|
|
862
|
+
this.activeAction = null;
|
|
863
|
+
if (this.activeSelection.type !== 'root-layers') {
|
|
864
|
+
const set = new SvelteSet(layerIds);
|
|
865
|
+
if (this.activeSelection.type === 'child-layer' && this.activeGroupAndChild) {
|
|
866
|
+
set.add(this.activeGroupAndChild.groupLayer.id);
|
|
867
|
+
}
|
|
868
|
+
this.activeSelection = { type: 'root-layers', layerIds: set };
|
|
869
|
+
}
|
|
870
|
+
this.pageSelected = false;
|
|
871
|
+
const ids = this.activeSelection.layerIds;
|
|
872
|
+
// If the action is 'delete', remove the layer from the active layer ids
|
|
873
|
+
if (action === 'delete') {
|
|
874
|
+
layerIds.forEach((layerId) => ids.delete(layerId));
|
|
875
|
+
}
|
|
876
|
+
else {
|
|
877
|
+
// If no action is provided, clear the active layer ids
|
|
878
|
+
if (!action) {
|
|
879
|
+
ids.clear();
|
|
880
|
+
this.activeGroupRotate = 0;
|
|
881
|
+
}
|
|
882
|
+
// Add the layers to the active layer ids
|
|
883
|
+
layerIds.forEach((layerId) => ids.add(layerId));
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
setActiveGroupChild(childId) {
|
|
887
|
+
this.activeAction = null;
|
|
888
|
+
this.activeSelection = { type: 'child-layer', childId };
|
|
889
|
+
this.pageSelected = false;
|
|
890
|
+
this.activeGroupRotate = 0;
|
|
891
|
+
}
|
|
892
|
+
clearActiveLayer() {
|
|
893
|
+
this.activeAction = null;
|
|
894
|
+
this.activeSelection = { type: 'empty' };
|
|
895
|
+
this.pageSelected = false;
|
|
896
|
+
this.activeGroupRotate = 0;
|
|
897
|
+
}
|
|
898
|
+
setActiveBackground(value) {
|
|
899
|
+
this.activeAction = null;
|
|
900
|
+
this.activeSelection = { type: value ? 'background' : 'empty' };
|
|
901
|
+
this.pageSelected = false;
|
|
902
|
+
this.activeGroupRotate = 0;
|
|
903
|
+
}
|
|
904
|
+
applyChanges(actions, type) {
|
|
905
|
+
console.log('applyChanges', $state.snapshot(actions), type);
|
|
906
|
+
const events = [];
|
|
907
|
+
(type === 'undo' ? actions.reverse() : actions).forEach((action) => {
|
|
908
|
+
if (this.mode === 'multiple' && (action.type === 'pageAdd' || action.type === 'pageRemove')) {
|
|
909
|
+
if ((action.type === 'pageAdd' && type === 'redo') ||
|
|
910
|
+
(action.type === 'pageRemove' && type === 'undo')) {
|
|
911
|
+
let page = { ...action.page };
|
|
912
|
+
events.push({ type: 'pageAdd', data: { page } });
|
|
913
|
+
this.pages.push(page);
|
|
914
|
+
this.setActivePage(page.id);
|
|
915
|
+
if (action.type === 'pageRemove' && action.newPage) {
|
|
916
|
+
const pageId = action.newPage.id;
|
|
917
|
+
const index = this.pages.findIndex(({ id }) => id === pageId);
|
|
918
|
+
if (~index) {
|
|
919
|
+
this.pages.splice(index, 1);
|
|
920
|
+
events.push({ type: 'pageRemove', data: { pageId } });
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
else {
|
|
925
|
+
const index = this.pages.findIndex(({ id }) => id === action.page.id);
|
|
926
|
+
if (~index) {
|
|
927
|
+
this.pages.splice(index, 1);
|
|
928
|
+
events.push({ type: 'pageRemove', data: { pageId: action.page.id } });
|
|
929
|
+
if (!this.pages.length && action.type === 'pageRemove') {
|
|
930
|
+
let page = this.buildEmptyPage();
|
|
931
|
+
events.push({ type: 'pageAdd', data: { page } });
|
|
932
|
+
this.pages.push(page);
|
|
933
|
+
this.setActivePage(page.id);
|
|
934
|
+
action.newPage = page;
|
|
935
|
+
}
|
|
936
|
+
else {
|
|
937
|
+
const prevPage = this.sortedPages.findLast((l) => l.sortOrder < action.page.sortOrder);
|
|
938
|
+
this.setActivePage((prevPage ?? this.pages[0]).id);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
else if ('pageId' in action) {
|
|
944
|
+
const page = this.pages.find(({ id }) => id === action.pageId);
|
|
945
|
+
if (!page)
|
|
946
|
+
return false;
|
|
947
|
+
if (action.type === 'pageUpdate') {
|
|
948
|
+
Object.assign(page, action[type]);
|
|
949
|
+
events.push({ type: 'pageUpdate', data: { pageId: page.id, diff: action[type] } });
|
|
950
|
+
}
|
|
951
|
+
else if (action.type === 'layerAdd' || action.type === 'layerRemove') {
|
|
952
|
+
if ((action.type === 'layerAdd' && type === 'redo') ||
|
|
953
|
+
(action.type === 'layerRemove' && type === 'undo')) {
|
|
954
|
+
page.layers.push(action.layer);
|
|
955
|
+
events.push({ type: 'layerAdd', data: { pageId: page.id, layer: action.layer } });
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
const index = page.layers.findIndex(({ id }) => id === action.layer.id);
|
|
959
|
+
if (!~index)
|
|
960
|
+
return;
|
|
961
|
+
page.layers.splice(index, 1);
|
|
962
|
+
events.push({
|
|
963
|
+
type: 'layerRemove',
|
|
964
|
+
data: {
|
|
965
|
+
pageId: page.id,
|
|
966
|
+
layerId: action.layer.id,
|
|
967
|
+
layerType: action.layer.type,
|
|
968
|
+
},
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
else if (action.type === 'layerUpdate') {
|
|
973
|
+
const layer = this.findLayer(page, action.layer.id);
|
|
974
|
+
if (!layer)
|
|
975
|
+
return false;
|
|
976
|
+
Object.assign(layer, action[type]);
|
|
977
|
+
events.push({
|
|
978
|
+
type: 'layerUpdate',
|
|
979
|
+
data: {
|
|
980
|
+
pageId: page.id,
|
|
981
|
+
layerId: layer.id,
|
|
982
|
+
layerType: layer.type,
|
|
983
|
+
diff: action[type],
|
|
984
|
+
},
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
else if (action.type === 'backgroundImageAdd' ||
|
|
988
|
+
action.type === 'backgroundImageRemove') {
|
|
989
|
+
if (action.type === 'backgroundImageAdd' && type === 'redo') {
|
|
990
|
+
Object.assign(page, { backgroundImage: action.backgroundImage });
|
|
991
|
+
events.push({
|
|
992
|
+
type: 'backgroundImageAdd',
|
|
993
|
+
data: { pageId: page.id, backgroundImage: action.backgroundImage },
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
Object.assign(page, { backgroundImage: action.previousBackgroundImage });
|
|
998
|
+
events.push({
|
|
999
|
+
type: 'backgroundImageRemove',
|
|
1000
|
+
data: { pageId: page.id },
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
else if (action.type === 'backgroundImageUpdate') {
|
|
1005
|
+
if (!page.backgroundImage)
|
|
1006
|
+
return;
|
|
1007
|
+
Object.assign(page.backgroundImage, action[type]);
|
|
1008
|
+
events.push({
|
|
1009
|
+
type: 'backgroundImageUpdate',
|
|
1010
|
+
data: { pageId: page.id, diff: action[type] },
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
console.log('events', events);
|
|
1016
|
+
this.onUpdate?.(events, this.pages);
|
|
1017
|
+
return true;
|
|
1018
|
+
}
|
|
1019
|
+
historyReset() {
|
|
1020
|
+
this.historyActions = [];
|
|
1021
|
+
this.historyIndex = -1;
|
|
1022
|
+
}
|
|
1023
|
+
historyPush(actions) {
|
|
1024
|
+
actions = Array.isArray(actions) ? actions : [actions];
|
|
1025
|
+
const done = this.applyChanges(actions, 'redo');
|
|
1026
|
+
if (done) {
|
|
1027
|
+
this.historyActions = [...this.historyActions.slice(0, this.historyIndex + 1), actions];
|
|
1028
|
+
this.historyIndex = this.historyActions.length - 1;
|
|
1029
|
+
}
|
|
1030
|
+
return done;
|
|
1031
|
+
}
|
|
1032
|
+
historyUndo() {
|
|
1033
|
+
if (this.historyIndex >= 0) {
|
|
1034
|
+
const action = this.historyActions[this.historyIndex];
|
|
1035
|
+
this.historyIndex--;
|
|
1036
|
+
this.applyChanges(action, 'undo');
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
historyRedo() {
|
|
1040
|
+
if (this.historyIndex < this.historyActions.length - 1) {
|
|
1041
|
+
this.historyIndex++;
|
|
1042
|
+
const action = this.historyActions[this.historyIndex];
|
|
1043
|
+
this.applyChanges(action, 'redo');
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
isLayerOutOfBounds(layer) {
|
|
1047
|
+
const bbox = calculateBoundingBox(layer);
|
|
1048
|
+
return (bbox.x > this.width ||
|
|
1049
|
+
bbox.y > this.height ||
|
|
1050
|
+
bbox.x + bbox.width < 0 ||
|
|
1051
|
+
bbox.y + bbox.height < 0);
|
|
1052
|
+
}
|
|
1053
|
+
createTextLayerInitial(page, layer) {
|
|
1054
|
+
if (layer.groupId) {
|
|
1055
|
+
const groupLayer = this.findLayer(page, layer.groupId);
|
|
1056
|
+
const children = this.findGroupChildren(page, layer.groupId);
|
|
1057
|
+
return {
|
|
1058
|
+
layer: { initial: $state.snapshot(layer), state: layer },
|
|
1059
|
+
groupLayer: {
|
|
1060
|
+
initial: $state.snapshot(groupLayer),
|
|
1061
|
+
state: groupLayer,
|
|
1062
|
+
childrenInitial: $state.snapshot(children),
|
|
1063
|
+
childrenState: children,
|
|
1064
|
+
},
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
return {
|
|
1068
|
+
layer: { initial: $state.snapshot(layer), state: layer },
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
async applyHtmlToLayer(initial, html) {
|
|
1072
|
+
const { layer, groupLayer } = initial;
|
|
1073
|
+
layer.state.html = html;
|
|
1074
|
+
await tick();
|
|
1075
|
+
const layerContent = document.getElementById(`layer-content-${layer.initial.id}`);
|
|
1076
|
+
if (layerContent && layerContent.offsetHeight !== layer.initial.height) {
|
|
1077
|
+
const newHeight = layerContent.offsetHeight;
|
|
1078
|
+
if (groupLayer) {
|
|
1079
|
+
const absoluteChildren = this.getAbsoluteGroupLayers(groupLayer.initial, groupLayer.childrenInitial);
|
|
1080
|
+
const absoluteLayer = absoluteChildren.find((l) => l.id === layer.initial.id);
|
|
1081
|
+
const { newX, newY } = calculateNewPosition(`top-left`, absoluteLayer, absoluteLayer.width * absoluteLayer.scale, newHeight * absoluteLayer.scale);
|
|
1082
|
+
Object.assign(absoluteLayer, { x: newX, y: newY, height: newHeight });
|
|
1083
|
+
const groupScale = groupLayer.initial.scale;
|
|
1084
|
+
const groupRotate = groupLayer.initial.rotate;
|
|
1085
|
+
const newGroupBbox = calculateGroupRotatedBoundingBox(absoluteChildren, groupRotate);
|
|
1086
|
+
const groupAction = {
|
|
1087
|
+
type: 'layerUpdate',
|
|
1088
|
+
pageId: this.activePage.id,
|
|
1089
|
+
layer: { id: groupLayer.initial.id, type: groupLayer.initial.type },
|
|
1090
|
+
undo: {
|
|
1091
|
+
x: groupLayer.initial.x,
|
|
1092
|
+
y: groupLayer.initial.y,
|
|
1093
|
+
width: groupLayer.initial.width,
|
|
1094
|
+
height: groupLayer.initial.height,
|
|
1095
|
+
},
|
|
1096
|
+
redo: {
|
|
1097
|
+
x: newGroupBbox.x,
|
|
1098
|
+
y: newGroupBbox.y,
|
|
1099
|
+
width: newGroupBbox.width / groupScale,
|
|
1100
|
+
height: newGroupBbox.height / groupScale,
|
|
1101
|
+
},
|
|
1102
|
+
};
|
|
1103
|
+
Object.assign(groupLayer.state, groupAction.redo);
|
|
1104
|
+
Object.assign(layer.state, { height: newHeight });
|
|
1105
|
+
const relativeLayers = calculateRelativeRects(newGroupBbox, absoluteChildren);
|
|
1106
|
+
return [
|
|
1107
|
+
groupAction,
|
|
1108
|
+
...groupLayer.childrenState.map((state, i) => {
|
|
1109
|
+
const initialChild = groupLayer.childrenInitial[i];
|
|
1110
|
+
const isCurrentLayer = state.id === layer.initial.id;
|
|
1111
|
+
const relativeLayer = relativeLayers[i];
|
|
1112
|
+
const action = {
|
|
1113
|
+
type: 'layerUpdate',
|
|
1114
|
+
pageId: this.activePage.id,
|
|
1115
|
+
layer: { id: state.id, type: state.type },
|
|
1116
|
+
undo: {
|
|
1117
|
+
x: initialChild.x,
|
|
1118
|
+
y: initialChild.y,
|
|
1119
|
+
...(isCurrentLayer && { html: layer.initial.html, height: layer.initial.height }),
|
|
1120
|
+
},
|
|
1121
|
+
redo: {
|
|
1122
|
+
x: relativeLayer.x / groupScale,
|
|
1123
|
+
y: relativeLayer.y / groupScale,
|
|
1124
|
+
...(isCurrentLayer && { html, height: newHeight }),
|
|
1125
|
+
},
|
|
1126
|
+
};
|
|
1127
|
+
Object.assign(state, action.redo);
|
|
1128
|
+
return action;
|
|
1129
|
+
}),
|
|
1130
|
+
];
|
|
1131
|
+
}
|
|
1132
|
+
else {
|
|
1133
|
+
const { newX, newY } = calculateNewPosition(`top-left`, layer.initial, layer.initial.width * layer.initial.scale, newHeight * layer.initial.scale);
|
|
1134
|
+
const redo = { html, x: newX, y: newY, height: newHeight };
|
|
1135
|
+
Object.assign(layer.state, redo);
|
|
1136
|
+
return [
|
|
1137
|
+
{
|
|
1138
|
+
type: 'layerUpdate',
|
|
1139
|
+
pageId: this.activePage.id,
|
|
1140
|
+
layer: { id: layer.initial.id, type: layer.initial.type },
|
|
1141
|
+
undo: {
|
|
1142
|
+
html: layer.initial.html,
|
|
1143
|
+
x: layer.initial.x,
|
|
1144
|
+
y: layer.initial.y,
|
|
1145
|
+
height: layer.initial.height,
|
|
1146
|
+
},
|
|
1147
|
+
redo,
|
|
1148
|
+
},
|
|
1149
|
+
];
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
return [
|
|
1153
|
+
{
|
|
1154
|
+
type: 'layerUpdate',
|
|
1155
|
+
pageId: this.activePage.id,
|
|
1156
|
+
layer: { id: layer.initial.id, type: layer.initial.type },
|
|
1157
|
+
undo: { html: layer.initial.html },
|
|
1158
|
+
redo: { html },
|
|
1159
|
+
},
|
|
1160
|
+
];
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
const editorKey = {};
|
|
1164
|
+
export function setEditorContext(editor) {
|
|
1165
|
+
return setContext(editorKey, editor);
|
|
1166
|
+
}
|
|
1167
|
+
export function getEditorContext() {
|
|
1168
|
+
return getContext(editorKey);
|
|
1169
|
+
}
|