@peteai/presentation-editor 0.0.2 → 0.0.4

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 (211) hide show
  1. package/README.md +2 -2
  2. package/dist/components/presentation-editor/active-layers-buttons.svelte +53 -0
  3. package/dist/components/presentation-editor/active-layers-buttons.svelte.d.ts +3 -0
  4. package/dist/components/presentation-editor/active-layers.svelte +181 -0
  5. package/dist/components/presentation-editor/active-layers.svelte.d.ts +3 -0
  6. package/dist/components/presentation-editor/color-indicator/color-indicator-gradient-def.svelte +81 -0
  7. package/dist/components/presentation-editor/color-indicator/color-indicator-gradient-def.svelte.d.ts +9 -0
  8. package/dist/components/presentation-editor/color-indicator/color-indicator-gradient.svelte +21 -0
  9. package/dist/components/presentation-editor/color-indicator/color-indicator-gradient.svelte.d.ts +8 -0
  10. package/dist/components/presentation-editor/color-indicator/color-indicator.svelte +23 -0
  11. package/dist/components/presentation-editor/color-indicator/color-indicator.svelte.d.ts +6 -0
  12. package/dist/components/presentation-editor/color-indicator/index.d.ts +4 -0
  13. package/dist/components/presentation-editor/color-indicator/index.js +6 -0
  14. package/dist/components/presentation-editor/cursor-tooltip.svelte +1 -1
  15. package/dist/components/presentation-editor/dragged.svelte +21 -11
  16. package/dist/components/presentation-editor/fonts.d.ts +3 -0
  17. package/dist/components/presentation-editor/fonts.js +1278 -0
  18. package/dist/components/presentation-editor/header.svelte +21 -33
  19. package/dist/components/presentation-editor/header.svelte.d.ts +16 -6
  20. package/dist/components/presentation-editor/hotkeys.svelte +85 -0
  21. package/dist/components/presentation-editor/{sidebar/layers.svelte.d.ts → hotkeys.svelte.d.ts} +3 -3
  22. package/dist/components/presentation-editor/layers/active-background-border.svelte +3 -7
  23. package/dist/components/presentation-editor/layers/active-layer-border.svelte +2 -5
  24. package/dist/components/presentation-editor/layers/active-layer-border.svelte.d.ts +0 -1
  25. package/dist/components/presentation-editor/layers/buttons/border-button/border-button.svelte +113 -129
  26. package/dist/components/presentation-editor/layers/buttons/border-button/border-button.svelte.d.ts +2 -2
  27. package/dist/components/presentation-editor/layers/buttons/corner-radius-button/corner-radius-button.svelte +51 -32
  28. package/dist/components/presentation-editor/layers/buttons/corner-radius-button/corner-radius-button.svelte.d.ts +2 -2
  29. package/dist/components/presentation-editor/layers/buttons/flip-button/flip-button.svelte +30 -7
  30. package/dist/components/presentation-editor/layers/buttons/flip-button/flip-button.svelte.d.ts +3 -3
  31. package/dist/components/presentation-editor/layers/buttons/opacity-button/opacity-button.svelte +76 -33
  32. package/dist/components/presentation-editor/layers/buttons/opacity-button/opacity-button.svelte.d.ts +3 -3
  33. package/dist/components/presentation-editor/layers/controls/corner-scale-control/corner-scale-control.svelte +89 -59
  34. package/dist/components/presentation-editor/layers/controls/corner-scale-control/corner-scale-control.svelte.d.ts +5 -100
  35. package/dist/components/presentation-editor/layers/controls/group-resize-control/group-resize-control.svelte +337 -0
  36. package/dist/components/presentation-editor/layers/controls/group-resize-control/group-resize-control.svelte.d.ts +104 -0
  37. package/dist/components/presentation-editor/layers/controls/group-resize-control/index.d.ts +2 -0
  38. package/dist/components/presentation-editor/layers/controls/group-resize-control/index.js +4 -0
  39. package/dist/components/presentation-editor/layers/controls/rotate-control/rotate-control.svelte +128 -43
  40. package/dist/components/presentation-editor/layers/controls/rotate-control/rotate-control.svelte.d.ts +1 -5
  41. package/dist/components/presentation-editor/layers/controls/side-resize-control/side-resize-control.svelte +68 -57
  42. package/dist/components/presentation-editor/layers/controls/side-resize-control/side-resize-control.svelte.d.ts +2 -110
  43. package/dist/components/presentation-editor/layers/controls/side-scale-control/side-scale-control.svelte +45 -32
  44. package/dist/components/presentation-editor/layers/controls/side-scale-control/side-scale-control.svelte.d.ts +2 -54
  45. package/dist/components/presentation-editor/layers/index.d.ts +4 -5
  46. package/dist/components/presentation-editor/layers/index.js +7 -8
  47. package/dist/components/presentation-editor/layers/layer-button.svelte +25 -7
  48. package/dist/components/presentation-editor/layers/layer-wrapper.svelte +212 -162
  49. package/dist/components/presentation-editor/layers/layer-wrapper.svelte.d.ts +2 -2
  50. package/dist/components/presentation-editor/layers/types/background/background-content-image.svelte +41 -0
  51. package/dist/components/presentation-editor/layers/types/background/background-content-image.svelte.d.ts +8 -0
  52. package/dist/components/presentation-editor/layers/types/background/background-layer-buttons.svelte +28 -74
  53. package/dist/components/presentation-editor/layers/types/background/background-layer-buttons.svelte.d.ts +2 -17
  54. package/dist/components/presentation-editor/layers/types/background/background-layer-content.svelte +19 -0
  55. package/dist/components/presentation-editor/layers/types/background/background-layer-content.svelte.d.ts +8 -0
  56. package/dist/components/presentation-editor/layers/types/background/background-layer.svelte +69 -61
  57. package/dist/components/presentation-editor/layers/types/background/background-layer.svelte.d.ts +2 -3
  58. package/dist/components/presentation-editor/layers/types/background/index.d.ts +2 -3
  59. package/dist/components/presentation-editor/layers/types/background/index.js +2 -3
  60. package/dist/components/presentation-editor/layers/types/html/buttons/alignment-button/alignment-button.svelte +55 -12
  61. package/dist/components/presentation-editor/layers/types/html/buttons/alignment-button/alignment-button.svelte.d.ts +3 -3
  62. package/dist/components/presentation-editor/layers/types/html/buttons/bold-button/bold-button.svelte +60 -8
  63. package/dist/components/presentation-editor/layers/types/html/buttons/bold-button/bold-button.svelte.d.ts +3 -3
  64. package/dist/components/presentation-editor/layers/types/html/buttons/case-button/case-button.svelte +59 -24
  65. package/dist/components/presentation-editor/layers/types/html/buttons/case-button/case-button.svelte.d.ts +3 -3
  66. package/dist/components/presentation-editor/layers/types/html/buttons/color-button/color-button.svelte +27 -76
  67. package/dist/components/presentation-editor/layers/types/html/buttons/color-button/color-button.svelte.d.ts +3 -3
  68. package/dist/components/presentation-editor/layers/types/html/buttons/font-family-button/font-family-button.svelte +36 -0
  69. package/dist/components/presentation-editor/layers/types/html/buttons/font-family-button/font-family-button.svelte.d.ts +7 -0
  70. package/dist/components/presentation-editor/layers/types/html/buttons/font-family-button/index.d.ts +2 -0
  71. package/dist/components/presentation-editor/layers/types/html/buttons/font-family-button/index.js +2 -0
  72. package/dist/components/presentation-editor/layers/types/html/buttons/font-size-button/font-size-button.svelte +72 -29
  73. package/dist/components/presentation-editor/layers/types/html/buttons/font-size-button/font-size-button.svelte.d.ts +3 -5
  74. package/dist/components/presentation-editor/layers/types/html/buttons/italic-button/italic-button.svelte +60 -8
  75. package/dist/components/presentation-editor/layers/types/html/buttons/italic-button/italic-button.svelte.d.ts +3 -3
  76. package/dist/components/presentation-editor/layers/types/html/buttons/list-button/list-button.svelte +71 -18
  77. package/dist/components/presentation-editor/layers/types/html/buttons/list-button/list-button.svelte.d.ts +3 -3
  78. package/dist/components/presentation-editor/layers/types/html/buttons/strikethrough-button/strikethrough-button.svelte +54 -8
  79. package/dist/components/presentation-editor/layers/types/html/buttons/strikethrough-button/strikethrough-button.svelte.d.ts +3 -3
  80. package/dist/components/presentation-editor/layers/types/html/buttons/underline-button/underline-button.svelte +54 -9
  81. package/dist/components/presentation-editor/layers/types/html/buttons/underline-button/underline-button.svelte.d.ts +3 -3
  82. package/dist/components/presentation-editor/layers/types/html/editor/createEditor.js +2 -2
  83. package/dist/components/presentation-editor/layers/types/html/editor/utils.d.ts +11 -0
  84. package/dist/components/presentation-editor/layers/types/html/editor/utils.js +88 -0
  85. package/dist/components/presentation-editor/layers/types/html/extensions/font-family/font-family.d.ts +27 -0
  86. package/dist/components/presentation-editor/layers/types/html/extensions/font-family/font-family.js +40 -0
  87. package/dist/components/presentation-editor/layers/types/html/extensions/font-family/index.d.ts +3 -0
  88. package/dist/components/presentation-editor/layers/types/html/extensions/font-family/index.js +3 -0
  89. package/dist/components/presentation-editor/layers/types/html/extensions/font-size/font-size.d.ts +5 -1
  90. package/dist/components/presentation-editor/layers/types/html/extensions/font-size/font-size.js +3 -7
  91. package/dist/components/presentation-editor/layers/types/html/extensions.d.ts +1 -0
  92. package/dist/components/presentation-editor/layers/types/html/extensions.js +56 -0
  93. package/dist/components/presentation-editor/layers/types/html/html-content.svelte +26 -5
  94. package/dist/components/presentation-editor/layers/types/html/html-layer-content.svelte +26 -0
  95. package/dist/components/presentation-editor/layers/types/html/html-layer-content.svelte.d.ts +9 -0
  96. package/dist/components/presentation-editor/layers/types/html/html-layer-edit.svelte +103 -0
  97. package/dist/components/presentation-editor/layers/types/html/html-layer-edit.svelte.d.ts +8 -0
  98. package/dist/components/presentation-editor/layers/types/html/html-layer.svelte +61 -53
  99. package/dist/components/presentation-editor/layers/types/html/index.d.ts +3 -5
  100. package/dist/components/presentation-editor/layers/types/html/index.js +3 -56
  101. package/dist/components/presentation-editor/layers/types/image/{image-content.svelte → image-layer-content.svelte} +11 -3
  102. package/dist/components/presentation-editor/layers/types/image/image-layer-content.svelte.d.ts +8 -0
  103. package/dist/components/presentation-editor/layers/types/image/image-layer.svelte +51 -21
  104. package/dist/components/presentation-editor/layers/types/image/index.d.ts +2 -4
  105. package/dist/components/presentation-editor/layers/types/image/index.js +2 -4
  106. package/dist/components/presentation-editor/layers/utils.d.ts +68 -9
  107. package/dist/components/presentation-editor/layers/utils.js +260 -25
  108. package/dist/components/presentation-editor/menu/background-menu-content.svelte +80 -0
  109. package/dist/components/presentation-editor/menu/background-menu-content.svelte.d.ts +9 -0
  110. package/dist/components/presentation-editor/menu/layer-menu-content.svelte +183 -0
  111. package/dist/components/presentation-editor/menu/layer-menu-content.svelte.d.ts +3 -0
  112. package/dist/components/presentation-editor/menu/slide-menu-content.svelte +67 -0
  113. package/dist/components/presentation-editor/menu/slide-menu-content.svelte.d.ts +9 -0
  114. package/dist/components/presentation-editor/presentation-editor.svelte +119 -175
  115. package/dist/components/presentation-editor/presentation-editor.svelte.js +597 -136
  116. package/dist/components/presentation-editor/sidebar/color-sidebar/color-sidebar-color.svelte +58 -0
  117. package/dist/components/presentation-editor/sidebar/color-sidebar/color-sidebar-color.svelte.d.ts +10 -0
  118. package/dist/components/presentation-editor/sidebar/color-sidebar/color-sidebar-gradient-picker.svelte +144 -0
  119. package/dist/components/presentation-editor/sidebar/color-sidebar/color-sidebar-gradient-picker.svelte.d.ts +7 -0
  120. package/dist/components/presentation-editor/sidebar/color-sidebar/color-sidebar.svelte +404 -0
  121. package/dist/components/presentation-editor/sidebar/color-sidebar/color-sidebar.svelte.d.ts +3 -0
  122. package/dist/components/presentation-editor/sidebar/color-sidebar/index.d.ts +2 -0
  123. package/dist/components/presentation-editor/sidebar/color-sidebar/index.js +2 -0
  124. package/dist/components/presentation-editor/sidebar/font-sidebar/font-sidebar-button.svelte +26 -0
  125. package/dist/components/presentation-editor/sidebar/font-sidebar/font-sidebar-button.svelte.d.ts +8 -0
  126. package/dist/components/presentation-editor/sidebar/font-sidebar/font-sidebar.svelte +216 -0
  127. package/dist/components/presentation-editor/sidebar/font-sidebar/font-sidebar.svelte.d.ts +3 -0
  128. package/dist/components/presentation-editor/sidebar/font-sidebar/index.d.ts +2 -0
  129. package/dist/components/presentation-editor/sidebar/font-sidebar/index.js +2 -0
  130. package/dist/components/presentation-editor/sidebar/position-slidebar.svelte +130 -0
  131. package/dist/components/presentation-editor/sidebar/position-slidebar.svelte.d.ts +18 -0
  132. package/dist/components/presentation-editor/sidebar/sidebar-text-tab-button.svelte +90 -0
  133. package/dist/components/presentation-editor/sidebar/sidebar-text-tab-button.svelte.d.ts +7 -0
  134. package/dist/components/presentation-editor/sidebar/sidebar-text-tab.svelte +82 -0
  135. package/dist/components/presentation-editor/sidebar/sidebar-text-tab.svelte.d.ts +18 -0
  136. package/dist/components/presentation-editor/sidebar/{images-library.svelte → sidebar-uploads-tab.svelte} +0 -1
  137. package/dist/components/presentation-editor/sidebar/sidebar-uploads-tab.svelte.d.ts +3 -0
  138. package/dist/components/presentation-editor/sidebar/sidebar-wrapper.svelte +25 -0
  139. package/dist/components/presentation-editor/sidebar/sidebar-wrapper.svelte.d.ts +7 -0
  140. package/dist/components/presentation-editor/sidebar/sidebar.svelte +71 -15
  141. package/dist/components/presentation-editor/sidebar/sidebar.svelte.d.ts +16 -5
  142. package/dist/components/presentation-editor/sidebar/uploads-image.svelte +28 -11
  143. package/dist/components/presentation-editor/slide-editor.svelte +20 -22
  144. package/dist/components/presentation-editor/slide-inner.svelte +19 -18
  145. package/dist/components/presentation-editor/slides-navigation/slide-preview.svelte +61 -52
  146. package/dist/components/presentation-editor/slides-navigation/slides-navigation.svelte +6 -8
  147. package/dist/components/presentation-editor/snapping-guides.svelte +3 -3
  148. package/dist/components/presentation-editor/types.d.ts +67 -27
  149. package/dist/components/presentation-editor/utils.d.ts +50 -1
  150. package/dist/components/presentation-editor/utils.js +101 -6
  151. package/dist/components/ui/button/button.svelte +3 -2
  152. package/dist/components/ui/button/button.svelte.d.ts +5 -82
  153. package/dist/components/ui/color-picker/color-picker-alpha-grid.svelte +43 -0
  154. package/dist/components/ui/color-picker/color-picker-alpha-grid.svelte.d.ts +8 -0
  155. package/dist/components/ui/color-picker/color-picker.svelte +344 -0
  156. package/dist/components/ui/color-picker/color-picker.svelte.d.ts +13 -0
  157. package/dist/components/ui/color-picker/index.d.ts +3 -0
  158. package/dist/components/ui/color-picker/index.js +5 -0
  159. package/dist/components/ui/context-menu/context-menu-shortcut.svelte +6 -3
  160. package/dist/components/ui/context-menu/context-menu-sub-trigger.svelte +1 -1
  161. package/dist/components/ui/dropdown-menu/dropdown-menu-item.svelte +1 -1
  162. package/dist/components/ui/dropdown-menu/dropdown-menu-shortcut.svelte +6 -3
  163. package/dist/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte +1 -1
  164. package/dist/components/ui/infinite-loader/index.d.ts +4 -0
  165. package/dist/components/ui/infinite-loader/index.js +4 -0
  166. package/dist/components/ui/infinite-loader/infinite-loader-loop-tracker.d.ts +13 -0
  167. package/dist/components/ui/infinite-loader/infinite-loader-loop-tracker.js +44 -0
  168. package/dist/components/ui/infinite-loader/infinite-loader-state.svelte.d.ts +15 -0
  169. package/dist/components/ui/infinite-loader/infinite-loader-state.svelte.js +28 -0
  170. package/dist/components/ui/infinite-loader/infinite-loader.svelte +149 -0
  171. package/dist/components/ui/infinite-loader/infinite-loader.svelte.d.ts +17 -0
  172. package/dist/components/ui/input/input.svelte +1 -1
  173. package/dist/components/ui/slider/slider.svelte +20 -18
  174. package/dist/components/ui/tabs/index.d.ts +6 -0
  175. package/dist/components/ui/tabs/index.js +8 -0
  176. package/dist/components/ui/tabs/tabs-content.svelte +19 -0
  177. package/dist/components/ui/tabs/tabs-content.svelte.d.ts +4 -0
  178. package/dist/components/ui/tabs/tabs-list.svelte +19 -0
  179. package/dist/components/ui/tabs/tabs-list.svelte.d.ts +4 -0
  180. package/dist/components/ui/tabs/tabs-trigger.svelte +19 -0
  181. package/dist/components/ui/tabs/tabs-trigger.svelte.d.ts +4 -0
  182. package/dist/components/ui/toggle/toggle.svelte +3 -2
  183. package/dist/components/ui/toggle/toggle.svelte.d.ts +2 -46
  184. package/dist/plugin.js +3 -2
  185. package/dist/utils.d.ts +1 -0
  186. package/dist/utils.js +1 -0
  187. package/package.json +28 -25
  188. package/dist/components/presentation-editor/app.css +0 -12
  189. package/dist/components/presentation-editor/layers/hovered-layer.svelte +0 -34
  190. package/dist/components/presentation-editor/layers/hovered-layer.svelte.d.ts +0 -7
  191. package/dist/components/presentation-editor/layers/types/background/background-content.svelte +0 -11
  192. package/dist/components/presentation-editor/layers/types/background/background-content.svelte.d.ts +0 -7
  193. package/dist/components/presentation-editor/layers/types/background/background-layer-thumb.svelte +0 -12
  194. package/dist/components/presentation-editor/layers/types/background/background-layer-thumb.svelte.d.ts +0 -7
  195. package/dist/components/presentation-editor/layers/types/html/html-layer-active.svelte +0 -159
  196. package/dist/components/presentation-editor/layers/types/html/html-layer-active.svelte.d.ts +0 -8
  197. package/dist/components/presentation-editor/layers/types/html/html-layer-buttons.svelte +0 -42
  198. package/dist/components/presentation-editor/layers/types/html/html-layer-buttons.svelte.d.ts +0 -10
  199. package/dist/components/presentation-editor/layers/types/html/html-layer-thumb.svelte +0 -24
  200. package/dist/components/presentation-editor/layers/types/html/html-layer-thumb.svelte.d.ts +0 -8
  201. package/dist/components/presentation-editor/layers/types/image/image-content.svelte.d.ts +0 -8
  202. package/dist/components/presentation-editor/layers/types/image/image-layer-buttons.svelte +0 -21
  203. package/dist/components/presentation-editor/layers/types/image/image-layer-buttons.svelte.d.ts +0 -7
  204. package/dist/components/presentation-editor/layers/types/image/image-layer-thumb.svelte +0 -13
  205. package/dist/components/presentation-editor/layers/types/image/image-layer-thumb.svelte.d.ts +0 -8
  206. package/dist/components/presentation-editor/sidebar/images-library.svelte.d.ts +0 -3
  207. package/dist/components/presentation-editor/sidebar/layers.svelte +0 -94
  208. package/dist/components/presentation-editor/slides-navigation/buttons/slide-delete-button.svelte +0 -32
  209. package/dist/components/presentation-editor/slides-navigation/buttons/slide-delete-button.svelte.d.ts +0 -10
  210. package/dist/components/presentation-editor/slides-navigation/buttons/slide-duplicate-button.svelte +0 -34
  211. package/dist/components/presentation-editor/slides-navigation/buttons/slide-duplicate-button.svelte.d.ts +0 -10
@@ -1,19 +1,65 @@
1
1
  <script lang="ts">
2
2
  import StrikethroughIcon from 'lucide-svelte/icons/strikethrough';
3
- import type { Editor } from '../../editor/Editor.js';
4
3
  import { Toggle } from '../../../../../../ui/toggle/index.js';
4
+ import type { HtmlLayer } from '../../../../../types.js';
5
+ import { getPresentationEditorContext } from '../../../../../presentation-editor.svelte.js';
6
+ import { createEditorNotReactive } from '../../editor/utils.js';
5
7
 
6
8
  interface Props {
7
- editor: Editor;
9
+ layers: HtmlLayer[];
8
10
  }
9
11
 
10
- let { editor }: Props = $props();
12
+ let { layers = $bindable() }: Props = $props();
13
+
14
+ const editor = getPresentationEditorContext();
15
+
16
+ const { htmlEditor } = editor;
17
+
18
+ const editorNotReactive = createEditorNotReactive();
19
+
20
+ const isActive = $derived.by(() => {
21
+ if (editor.activeAction?.type === 'edit') {
22
+ return $htmlEditor.isActive('strike');
23
+ } else {
24
+ return layers.every((layer) => {
25
+ editorNotReactive.chain().setContent(layer.html).selectAll().run();
26
+ return editorNotReactive.isActive('strike');
27
+ });
28
+ }
29
+ });
30
+
31
+ const setValue = async (value: boolean) => {
32
+ if (editor.activeAction?.type === 'edit') {
33
+ if (value) {
34
+ $htmlEditor.chain().focus().setStrike().run();
35
+ } else {
36
+ $htmlEditor.chain().focus().unsetStrike().run();
37
+ }
38
+ } else {
39
+ editor.historyPush({
40
+ type: 'layersGroup',
41
+ actions: layers.map((layer) => {
42
+ let chain = editorNotReactive.chain().setContent(layer.html).selectAll();
43
+ if (value) {
44
+ chain = chain.setStrike();
45
+ } else {
46
+ chain = chain.unsetStrike();
47
+ }
48
+ chain.run();
49
+
50
+ return {
51
+ type: 'layer',
52
+ slideId: editor.activeSlide.id,
53
+ layer: { id: layer.id, type: layer.type },
54
+ undo: { html: layer.html },
55
+ redo: { html: editorNotReactive.getJSON() },
56
+ };
57
+ }),
58
+ });
59
+ }
60
+ };
11
61
  </script>
12
62
 
13
- <Toggle
14
- size="xs"
15
- pressed={editor.isActive('strike')}
16
- onPressedChange={(val) => (val ? editor.commands.setStrike() : editor.commands.unsetStrike())}
17
- >
63
+ <Toggle size="xs" pressed={isActive} onPressedChange={(val) => setValue(val)}>
18
64
  <StrikethroughIcon class="h-6 w-6" />
19
65
  </Toggle>
@@ -1,7 +1,7 @@
1
- import type { Editor } from '../../editor/Editor.js';
1
+ import type { HtmlLayer } from '../../../../../types.js';
2
2
  interface Props {
3
- editor: Editor;
3
+ layers: HtmlLayer[];
4
4
  }
5
- declare const StrikethroughButton: import("svelte").Component<Props, {}, "">;
5
+ declare const StrikethroughButton: import("svelte").Component<Props, {}, "layers">;
6
6
  type StrikethroughButton = ReturnType<typeof StrikethroughButton>;
7
7
  export default StrikethroughButton;
@@ -1,20 +1,65 @@
1
1
  <script lang="ts">
2
- import type { Editor } from '../../editor/index.js';
3
2
  import UnderlineIcon from 'lucide-svelte/icons/underline';
4
3
  import { Toggle } from '../../../../../../ui/toggle/index.js';
4
+ import type { HtmlLayer } from '../../../../../types.js';
5
+ import { getPresentationEditorContext } from '../../../../../presentation-editor.svelte.js';
6
+ import { createEditorNotReactive } from '../../editor/utils.js';
5
7
 
6
8
  interface Props {
7
- editor: Editor;
9
+ layers: HtmlLayer[];
8
10
  }
9
11
 
10
- let { editor }: Props = $props();
12
+ let { layers = $bindable() }: Props = $props();
13
+
14
+ const editor = getPresentationEditorContext();
15
+
16
+ const { htmlEditor } = editor;
17
+
18
+ const editorNotReactive = createEditorNotReactive();
19
+
20
+ const isActive = $derived.by(() => {
21
+ if (editor.activeAction?.type === 'edit') {
22
+ return $htmlEditor.isActive('underline');
23
+ } else {
24
+ return layers.every((layer) => {
25
+ editorNotReactive.chain().setContent(layer.html).selectAll().run();
26
+ return editorNotReactive.isActive('underline');
27
+ });
28
+ }
29
+ });
30
+
31
+ const setValue = async (value: boolean) => {
32
+ if (editor.activeAction?.type === 'edit') {
33
+ if (value) {
34
+ $htmlEditor.chain().focus().setUnderline().run();
35
+ } else {
36
+ $htmlEditor.chain().focus().unsetUnderline().run();
37
+ }
38
+ } else {
39
+ editor.historyPush({
40
+ type: 'layersGroup',
41
+ actions: layers.map((layer) => {
42
+ let chain = editorNotReactive.chain().setContent(layer.html).selectAll();
43
+ if (value) {
44
+ chain = chain.setUnderline();
45
+ } else {
46
+ chain = chain.unsetUnderline();
47
+ }
48
+ chain.run();
49
+
50
+ return {
51
+ type: 'layer',
52
+ slideId: editor.activeSlide.id,
53
+ layer: { id: layer.id, type: layer.type },
54
+ undo: { html: layer.html },
55
+ redo: { html: editorNotReactive.getJSON() },
56
+ };
57
+ }),
58
+ });
59
+ }
60
+ };
11
61
  </script>
12
62
 
13
- <Toggle
14
- size="xs"
15
- pressed={editor.isActive('underline')}
16
- onPressedChange={(val) =>
17
- val ? editor.commands.setUnderline() : editor.commands.unsetUnderline()}
18
- >
63
+ <Toggle size="xs" pressed={isActive} onPressedChange={(val) => setValue(val)}>
19
64
  <UnderlineIcon class="h-6 w-6" />
20
65
  </Toggle>
@@ -1,7 +1,7 @@
1
- import type { Editor } from '../../editor/index.js';
1
+ import type { HtmlLayer } from '../../../../../types.js';
2
2
  interface Props {
3
- editor: Editor;
3
+ layers: HtmlLayer[];
4
4
  }
5
- declare const UnderlineButton: import("svelte").Component<Props, {}, "">;
5
+ declare const UnderlineButton: import("svelte").Component<Props, {}, "layers">;
6
6
  type UnderlineButton = ReturnType<typeof UnderlineButton>;
7
7
  export default UnderlineButton;
@@ -1,6 +1,6 @@
1
+ import { tick } from 'svelte';
1
2
  import { readable } from 'svelte/store';
2
3
  import { Editor } from './Editor.js';
3
- import { tick } from 'svelte';
4
4
  const createEditor = (options) => {
5
5
  const editor = new Editor(options);
6
6
  return readable(editor, (set) => {
@@ -11,7 +11,7 @@ const createEditor = (options) => {
11
11
  });
12
12
  return () => {
13
13
  console.log('destroying editor');
14
- editor.destroy();
14
+ // editor.destroy();
15
15
  };
16
16
  });
17
17
  };
@@ -0,0 +1,11 @@
1
+ import { type JSONContent } from '@tiptap/core';
2
+ import { Editor } from './Editor.js';
3
+ export declare const DEFAULT_COLOR = "#000000";
4
+ export declare const createEditorNotReactive: (content?: JSONContent) => Editor;
5
+ export declare const extractSelectionFonts: (editor: Editor) => string[];
6
+ export declare const extractNodeFonts: (content: JSONContent, set?: Set<string>) => string[];
7
+ export declare const extractSelectionFontSizes: (editor: Editor) => number[];
8
+ export declare const extractNodeFontSizes: (content: JSONContent, set?: Set<number>) => number[];
9
+ export declare const extractSelectionColors: (editor: Editor) => string[];
10
+ export declare const extractNodeColors: (content: JSONContent, set?: Set<string>) => string[];
11
+ export declare const extractUppercase: (editor: Editor) => boolean;
@@ -0,0 +1,88 @@
1
+ import {} from '@tiptap/core';
2
+ import { Editor } from './Editor.js';
3
+ import { extensions } from '../extensions.js';
4
+ export const DEFAULT_COLOR = '#000000';
5
+ export const createEditorNotReactive = (content) => {
6
+ return new Editor({
7
+ extensions,
8
+ injectCSS: false,
9
+ content,
10
+ });
11
+ };
12
+ export const extractSelectionFonts = (editor) => {
13
+ const selection = editor.view.state.selection;
14
+ const set = new Set();
15
+ editor.view.state.doc.nodesBetween(selection.from, selection.to, (node) => {
16
+ if (node.attrs.fontFamily) {
17
+ set.add(node.attrs.fontFamily);
18
+ }
19
+ });
20
+ return Array.from(set);
21
+ };
22
+ export const extractNodeFonts = (content, set = new Set()) => {
23
+ if (content.type !== 'text') {
24
+ if (content.attrs?.fontFamily) {
25
+ set.add(content.attrs.fontFamily);
26
+ }
27
+ content.content?.forEach((content) => extractNodeFonts(content, set));
28
+ }
29
+ return Array.from(set);
30
+ };
31
+ export const extractSelectionFontSizes = (editor) => {
32
+ const selection = editor.view.state.selection;
33
+ const set = new Set();
34
+ editor.view.state.doc.nodesBetween(selection.from, selection.to, (node) => {
35
+ if (node.attrs.fontSize) {
36
+ set.add(node.attrs.fontSize);
37
+ }
38
+ });
39
+ return Array.from(set);
40
+ };
41
+ export const extractNodeFontSizes = (content, set = new Set()) => {
42
+ if (content.type !== 'text') {
43
+ if (content.attrs?.fontSize) {
44
+ set.add(content.attrs.fontSize);
45
+ }
46
+ content.content?.forEach((content) => extractNodeFontSizes(content, set));
47
+ }
48
+ return Array.from(set);
49
+ };
50
+ export const extractSelectionColors = (editor) => {
51
+ const selection = editor.view.state.selection;
52
+ const set = new Set();
53
+ editor.view.state.doc.nodesBetween(selection.from, selection.to, (node) => {
54
+ if (node.isText && node.text?.trim().length) {
55
+ const color = node.marks?.find((mark) => mark.type.name === 'textStyle')?.attrs?.color;
56
+ set.add(color || DEFAULT_COLOR);
57
+ }
58
+ });
59
+ return Array.from(set);
60
+ };
61
+ export const extractNodeColors = (content, set = new Set()) => {
62
+ if (content.type === 'text') {
63
+ const color = content.marks?.find((mark) => mark.type === 'textStyle')?.attrs?.color;
64
+ set.add(color || DEFAULT_COLOR);
65
+ }
66
+ else {
67
+ if (content.attrs?.color) {
68
+ set.add(content.attrs.color);
69
+ }
70
+ }
71
+ content.content?.forEach((content) => extractNodeColors(content, set));
72
+ return Array.from(set);
73
+ };
74
+ export const extractUppercase = (editor) => {
75
+ const selection = editor.view.state.selection;
76
+ let uppercase = null;
77
+ editor.view.state.doc.nodesBetween(selection.from, selection.to, (node) => {
78
+ if (node.type.name !== 'text') {
79
+ if (uppercase !== false && node.attrs.textTransform === 'uppercase') {
80
+ uppercase = true;
81
+ }
82
+ else {
83
+ uppercase = false;
84
+ }
85
+ }
86
+ });
87
+ return !!uppercase;
88
+ };
@@ -0,0 +1,27 @@
1
+ import { Extension } from '@tiptap/core';
2
+ export type FontFamilyOptions = {
3
+ /**
4
+ * A list of node names where the font family can be applied.
5
+ * @default []
6
+ * @example ['paragraph', 'listItem']
7
+ */
8
+ types: string[];
9
+ };
10
+ declare module '@tiptap/core' {
11
+ interface Commands<ReturnType> {
12
+ fontFamily: {
13
+ /**
14
+ * Set the font family
15
+ * @param fontFamily The font family
16
+ * @example editor.commands.setFontFamily('Arial')
17
+ */
18
+ setFontFamily: (fontFamily: string) => ReturnType;
19
+ /**
20
+ * Unset the font family
21
+ * @example editor.commands.unsetFontFamily()
22
+ */
23
+ unsetFontFamily: () => ReturnType;
24
+ };
25
+ }
26
+ }
27
+ export declare const FontFamily: Extension<FontFamilyOptions, any>;
@@ -0,0 +1,40 @@
1
+ import { Extension } from '@tiptap/core';
2
+ export const FontFamily = Extension.create({
3
+ name: 'fontFamily',
4
+ addOptions() {
5
+ return {
6
+ types: [],
7
+ };
8
+ },
9
+ addGlobalAttributes() {
10
+ return [
11
+ {
12
+ types: this.options.types,
13
+ attributes: {
14
+ fontFamily: {
15
+ default: null,
16
+ parseHTML: (element) => element.style.fontFamily,
17
+ renderHTML: (attributes) => {
18
+ if (!attributes.fontFamily) {
19
+ return {};
20
+ }
21
+ return {
22
+ style: `font-family: "${attributes.fontFamily}"`,
23
+ };
24
+ },
25
+ },
26
+ },
27
+ },
28
+ ];
29
+ },
30
+ addCommands() {
31
+ return {
32
+ setFontFamily: (fontFamily) => ({ commands }) => {
33
+ return this.options.types.every((type) => commands.updateAttributes(type, { fontFamily }));
34
+ },
35
+ unsetFontFamily: () => ({ commands }) => {
36
+ return this.options.types.every((type) => commands.resetAttributes(type, 'fontFamily'));
37
+ },
38
+ };
39
+ },
40
+ });
@@ -0,0 +1,3 @@
1
+ import { FontFamily } from './font-family.js';
2
+ export * from './font-family.js';
3
+ export default FontFamily;
@@ -0,0 +1,3 @@
1
+ import { FontFamily } from './font-family.js';
2
+ export * from './font-family.js';
3
+ export default FontFamily;
@@ -1,6 +1,10 @@
1
1
  import { Extension } from '@tiptap/core';
2
- import '@tiptap/extension-text-style';
3
2
  export type FontSizeOptions = {
3
+ /**
4
+ * A list of node names where the font size can be applied.
5
+ * @default []
6
+ * @example ['paragraph', 'listItem']
7
+ */
4
8
  types: string[];
5
9
  };
6
10
  declare module '@tiptap/core' {
@@ -1,5 +1,4 @@
1
1
  import { Extension } from '@tiptap/core';
2
- import '@tiptap/extension-text-style';
3
2
  export const FontSize = Extension.create({
4
3
  name: 'fontSize',
5
4
  addOptions() {
@@ -30,14 +29,11 @@ export const FontSize = Extension.create({
30
29
  },
31
30
  addCommands() {
32
31
  return {
33
- setFontSize: (fontSize) => ({
34
- // chain,
35
- commands, }) => {
32
+ setFontSize: (fontSize) => ({ commands }) => {
36
33
  return this.options.types.every((type) => commands.updateAttributes(type, { fontSize }));
37
- // return chain().setMark('textStyle', { fontSize }).run();
38
34
  },
39
- unsetFontSize: () => ({ chain }) => {
40
- return chain().setMark('textStyle', { fontSize: null }).removeEmptyTextStyle().run();
35
+ unsetFontSize: () => ({ commands }) => {
36
+ return this.options.types.every((type) => commands.resetAttributes(type, 'fontSize'));
41
37
  },
42
38
  };
43
39
  },
@@ -0,0 +1 @@
1
+ export declare const extensions: (import("@tiptap/core").Extension<any, any> | import("@tiptap/core").Node<any, any> | import("@tiptap/core").Mark<import("@tiptap/extension-bold").BoldOptions, any>)[];
@@ -0,0 +1,56 @@
1
+ import { Document } from '@tiptap/extension-document';
2
+ import { Paragraph } from '@tiptap/extension-paragraph';
3
+ import { Text } from '@tiptap/extension-text';
4
+ import { ListItem } from '@tiptap/extension-list-item';
5
+ import { BulletList } from '@tiptap/extension-bullet-list';
6
+ import { OrderedList } from '@tiptap/extension-ordered-list';
7
+ import { UnstyledList } from './extensions/unstyled-list/index.js';
8
+ import { ListKeymap } from '@tiptap/extension-list-keymap';
9
+ import { TextStyle } from '@tiptap/extension-text-style';
10
+ import { TextAlign } from '@tiptap/extension-text-align';
11
+ import { LineHeight } from './extensions/line-height/index.js';
12
+ import { TextTransform } from './extensions/text-transform/index.js';
13
+ import { FontFamily } from './extensions/font-family/index.js';
14
+ import { FontSize } from './extensions/font-size/index.js';
15
+ import { Color } from '@tiptap/extension-color';
16
+ import { Bold } from '@tiptap/extension-bold';
17
+ import { Italic } from '@tiptap/extension-italic';
18
+ import { Underline } from '@tiptap/extension-underline';
19
+ import { Strike } from '@tiptap/extension-strike';
20
+ import { Selection } from './extensions/selection/index.js';
21
+ export const extensions = [
22
+ Document,
23
+ Paragraph,
24
+ Text,
25
+ ListItem.configure({
26
+ HTMLAttributes: { style: 'margin-left: calc(var(--list-item-ident)*1em)' },
27
+ }),
28
+ BulletList.configure({
29
+ HTMLAttributes: { class: 'list-disc', style: '--list-item-ident: 1' },
30
+ keepAttributes: true,
31
+ keepMarks: true,
32
+ }),
33
+ OrderedList.configure({
34
+ HTMLAttributes: { class: 'list-decimal', style: '--list-item-ident: 1' },
35
+ keepAttributes: true,
36
+ keepMarks: true,
37
+ }),
38
+ UnstyledList.configure({
39
+ HTMLAttributes: { class: 'list-none', style: '--list-item-ident: 0' },
40
+ keepAttributes: true,
41
+ keepMarks: true,
42
+ }),
43
+ ListKeymap,
44
+ TextStyle,
45
+ FontFamily.configure({ types: ['paragraph', 'listItem'] }),
46
+ TextAlign.configure({ types: ['paragraph', 'listItem'] }),
47
+ LineHeight.configure({ types: ['paragraph', 'listItem'] }),
48
+ TextTransform.configure({ types: ['paragraph', 'listItem'] }),
49
+ FontSize.configure({ types: ['paragraph', 'listItem', 'textStyle'] }),
50
+ Color.configure({ types: ['paragraph', 'listItem', 'textStyle'] }),
51
+ Bold,
52
+ Italic,
53
+ Underline,
54
+ Strike,
55
+ Selection,
56
+ ];
@@ -1,10 +1,19 @@
1
1
  <script lang="ts">
2
2
  import { BROWSER } from 'esm-env';
3
3
  import { generateHTML, type JSONContent } from '@tiptap/core';
4
- import { extensions } from './index.js';
4
+ import { extensions } from './extensions.js';
5
+ import { getPresentationEditorContext } from '../../../presentation-editor.svelte.js';
6
+ import { extractNodeFonts } from './editor/utils.js';
5
7
 
6
8
  let { html } = $props();
7
9
 
10
+ const editor = getPresentationEditorContext();
11
+
12
+ if (BROWSER) {
13
+ const fontFamilies = extractNodeFonts(html);
14
+ Promise.all(fontFamilies.map(editor.loadFont));
15
+ }
16
+
8
17
  const getHtml = (html: JSONContent) => {
9
18
  try {
10
19
  return generateHTML(html, extensions);
@@ -15,7 +24,19 @@
15
24
  };
16
25
  </script>
17
26
 
18
- {#if BROWSER}
19
- <!-- eslint-disable svelte/no-at-html-tags -->
20
- {@html getHtml(html)}
21
- {/if}
27
+ <div
28
+ class="html-content whitespace-pre-wrap break-words p-0 text-left text-base font-normal normal-case not-italic text-black"
29
+ >
30
+ {#if BROWSER}
31
+ <!-- eslint-disable svelte/no-at-html-tags -->
32
+ {@html getHtml(html)}
33
+ {/if}
34
+ </div>
35
+
36
+ <style>
37
+ :global {
38
+ .html-content p:empty::after {
39
+ content: '\00A0';
40
+ }
41
+ }
42
+ </style>
@@ -0,0 +1,26 @@
1
+ <script lang="ts">
2
+ import type { HtmlLayer } from '../../../types.js';
3
+ import { cn } from '../../../../../utils.js';
4
+ import HtmlContent from './html-content.svelte';
5
+
6
+ interface Props {
7
+ layer: HtmlLayer;
8
+ thumbScale?: number;
9
+ ref?: HTMLElement | null;
10
+ }
11
+
12
+ let { layer, thumbScale = 1, ref = $bindable(null) }: Props = $props();
13
+
14
+ let scale = $derived((layer.scale || 1) * thumbScale);
15
+ </script>
16
+
17
+ <div
18
+ class={cn('h-full', { 'origin-top-left': scale !== 1 })}
19
+ style:width="{layer.width}px"
20
+ style:height="{layer.height}px"
21
+ style:transform={scale !== 1 ? `scale(${scale})` : ''}
22
+ >
23
+ <div bind:this={ref} id="layer-content-{layer.id}">
24
+ <HtmlContent html={layer.html} />
25
+ </div>
26
+ </div>
@@ -0,0 +1,9 @@
1
+ import type { HtmlLayer } from '../../../types.js';
2
+ interface Props {
3
+ layer: HtmlLayer;
4
+ thumbScale?: number;
5
+ ref?: HTMLElement | null;
6
+ }
7
+ declare const HtmlLayerContent: import("svelte").Component<Props, {}, "ref">;
8
+ type HtmlLayerContent = ReturnType<typeof HtmlLayerContent>;
9
+ export default HtmlLayerContent;
@@ -0,0 +1,103 @@
1
+ <script lang="ts">
2
+ import { onDestroy, untrack } from 'svelte';
3
+ import type { HtmlLayer, LayerUpdateAction } from '../../../types.js';
4
+ import { getPresentationEditorContext } from '../../../presentation-editor.svelte.js';
5
+ import { EditorContent } from './editor/index.js';
6
+ import { applyHtmlToLayer } from '../../utils.js';
7
+ import { createDebouncedCallback } from '../../../../../utils.js';
8
+
9
+ import './editor.css';
10
+
11
+ interface Props {
12
+ layer: HtmlLayer;
13
+ }
14
+
15
+ let { layer = $bindable() }: Props = $props();
16
+
17
+ const layerId = layer.id;
18
+ const layerRef = layer;
19
+
20
+ const editorState = getPresentationEditorContext();
21
+
22
+ const { htmlEditor } = editorState;
23
+
24
+ let scaleAndZoom = $derived((layer.scale || 1) * editorState.zoom);
25
+ let rotate = $derived(layer.rotate || 0);
26
+
27
+ let undo: Pick<HtmlLayer, 'html' | 'x' | 'y' | 'height'> | null = null;
28
+
29
+ const debouncedUpdates = createDebouncedCallback((action) => {
30
+ console.log('debouncedUpdates', action);
31
+ editorState.historyPush(action);
32
+ undo = null;
33
+ }, 750);
34
+
35
+ const onUpdate = async (e) => {
36
+ console.log('editor update');
37
+ if (!undo) {
38
+ undo = { html: $state.snapshot(layer.html), x: layer.x, y: layer.y, height: layer.height };
39
+ }
40
+ const html = e.editor.getJSON();
41
+ const redo = await applyHtmlToLayer(layer, html);
42
+
43
+ // save update only when there is a content
44
+ if (e.editor.state.doc.textContent.trim().length) {
45
+ const action: LayerUpdateAction = {
46
+ type: 'layer',
47
+ slideId: editorState.activeSlide.id,
48
+ layer: { id: layer.id, type: layer.type },
49
+ undo,
50
+ redo,
51
+ };
52
+ debouncedUpdates(action);
53
+ }
54
+ };
55
+
56
+ const checkIfEmpty = () => {
57
+ if (undo && !$htmlEditor.isFocused && !$htmlEditor.state.doc.textContent.trim().length) {
58
+ Object.assign(layerRef, undo);
59
+ editorState.removeLayers(editorState.activeSlide.id, layerId);
60
+ }
61
+ };
62
+
63
+ $htmlEditor.on('update', onUpdate);
64
+
65
+ onDestroy(() => {
66
+ $htmlEditor.off('update', onUpdate);
67
+ checkIfEmpty();
68
+ });
69
+
70
+ $effect(() => {
71
+ if (editorState.activeAction?.type !== 'edit') {
72
+ checkIfEmpty();
73
+ }
74
+ });
75
+
76
+ $htmlEditor.chain().setContent(layer.html).selectAll().run();
77
+
78
+ // update html when it changes by history undo/redo
79
+ $effect(() => {
80
+ const editor = untrack(() => $htmlEditor);
81
+ if (editorState.activeAction?.type !== 'edit') {
82
+ editor.chain().setContent(layer.html).selectAll().run();
83
+ }
84
+ });
85
+ </script>
86
+
87
+ <div class="absolute origin-top-left select-none">
88
+ <div
89
+ class="pointer-events-auto select-text"
90
+ style:width={`${layer.width * scaleAndZoom}px`}
91
+ style:height={`${layer.height * scaleAndZoom}px`}
92
+ style:transform={`translate(${layer.x * editorState.zoom}px, ${layer.y * editorState.zoom}px) rotate(${rotate}deg)`}
93
+ >
94
+ <div
95
+ class="origin-top-left"
96
+ style:width="{layer.width}px"
97
+ style:height="{layer.height}px"
98
+ style:transform={`scale(${scaleAndZoom})`}
99
+ >
100
+ <EditorContent editor={$htmlEditor} />
101
+ </div>
102
+ </div>
103
+ </div>
@@ -0,0 +1,8 @@
1
+ import type { HtmlLayer } from '../../../types.js';
2
+ import './editor.css';
3
+ interface Props {
4
+ layer: HtmlLayer;
5
+ }
6
+ declare const HtmlLayerEdit: import("svelte").Component<Props, {}, "layer">;
7
+ type HtmlLayerEdit = ReturnType<typeof HtmlLayerEdit>;
8
+ export default HtmlLayerEdit;