@embedpdf/svelte 0.0.0-stage → 3.0.0-next.16

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 (269) hide show
  1. package/LICENSE +192 -0
  2. package/README.md +312 -2
  3. package/dist/actions/readers.svelte.d.ts +29 -0
  4. package/dist/actions/readers.svelte.js +55 -0
  5. package/dist/actions.d.ts +13 -0
  6. package/dist/actions.js +13 -0
  7. package/dist/anchored/Anchored.svelte +24 -0
  8. package/dist/anchored/Anchored.svelte.d.ts +4 -0
  9. package/dist/anchored/PlacedAnchored.svelte +97 -0
  10. package/dist/anchored/PlacedAnchored.svelte.d.ts +4 -0
  11. package/dist/anchored/context.d.ts +31 -0
  12. package/dist/anchored/context.js +36 -0
  13. package/dist/anchored/props.d.ts +29 -0
  14. package/dist/anchored/props.js +1 -0
  15. package/dist/anchored.d.ts +12 -0
  16. package/dist/anchored.js +2 -0
  17. package/dist/annotation/AnnotationChrome.svelte +173 -0
  18. package/dist/annotation/AnnotationChrome.svelte.d.ts +11 -0
  19. package/dist/annotation/AnnotationDraftMenu.svelte +27 -0
  20. package/dist/annotation/AnnotationDraftMenu.svelte.d.ts +4 -0
  21. package/dist/annotation/AnnotationFrame.svelte +46 -0
  22. package/dist/annotation/AnnotationFrame.svelte.d.ts +15 -0
  23. package/dist/annotation/AnnotationLayer.svelte +241 -0
  24. package/dist/annotation/AnnotationLayer.svelte.d.ts +4 -0
  25. package/dist/annotation/AnnotationLook.svelte +67 -0
  26. package/dist/annotation/AnnotationLook.svelte.d.ts +21 -0
  27. package/dist/annotation/AnnotationMenu.svelte +47 -0
  28. package/dist/annotation/AnnotationMenu.svelte.d.ts +4 -0
  29. package/dist/annotation/AnnotationRotationBadge.svelte +52 -0
  30. package/dist/annotation/AnnotationRotationBadge.svelte.d.ts +4 -0
  31. package/dist/annotation/AnnotationScene.svelte +27 -0
  32. package/dist/annotation/AnnotationScene.svelte.d.ts +7 -0
  33. package/dist/annotation/FreeTextBox.svelte +51 -0
  34. package/dist/annotation/FreeTextBox.svelte.d.ts +9 -0
  35. package/dist/annotation/NativeDrawing.svelte +61 -0
  36. package/dist/annotation/NativeDrawing.svelte.d.ts +10 -0
  37. package/dist/annotation/StampGhost.svelte +79 -0
  38. package/dist/annotation/StampGhost.svelte.d.ts +7 -0
  39. package/dist/annotation/chrome-paint.svelte.d.ts +30 -0
  40. package/dist/annotation/chrome-paint.svelte.js +27 -0
  41. package/dist/annotation/props.d.ts +181 -0
  42. package/dist/annotation/props.js +1 -0
  43. package/dist/annotation/readers.svelte.d.ts +59 -0
  44. package/dist/annotation/readers.svelte.js +136 -0
  45. package/dist/annotation/state.d.ts +18 -0
  46. package/dist/annotation/state.js +20 -0
  47. package/dist/annotation/text-box.svelte.d.ts +28 -0
  48. package/dist/annotation/text-box.svelte.js +87 -0
  49. package/dist/annotation.d.ts +32 -0
  50. package/dist/annotation.js +31 -0
  51. package/dist/attachment/readers.d.ts +23 -0
  52. package/dist/attachment/readers.js +21 -0
  53. package/dist/attachment.d.ts +13 -0
  54. package/dist/attachment.js +14 -0
  55. package/dist/commands/readers.svelte.d.ts +50 -0
  56. package/dist/commands/readers.svelte.js +83 -0
  57. package/dist/commands.d.ts +9 -0
  58. package/dist/commands.js +9 -0
  59. package/dist/form/ButtonControl.svelte +38 -0
  60. package/dist/form/ButtonControl.svelte.d.ts +11 -0
  61. package/dist/form/ComboControl.svelte +52 -0
  62. package/dist/form/ComboControl.svelte.d.ts +11 -0
  63. package/dist/form/FieldPictures.svelte +145 -0
  64. package/dist/form/FieldPictures.svelte.d.ts +3 -0
  65. package/dist/form/FormFocusRing.svelte +25 -0
  66. package/dist/form/FormFocusRing.svelte.d.ts +8 -0
  67. package/dist/form/FormLayer.svelte +98 -0
  68. package/dist/form/FormLayer.svelte.d.ts +3 -0
  69. package/dist/form/ListControl.svelte +49 -0
  70. package/dist/form/ListControl.svelte.d.ts +11 -0
  71. package/dist/form/NativeListBox.svelte +57 -0
  72. package/dist/form/NativeListBox.svelte.d.ts +4 -0
  73. package/dist/form/SignatureControl.svelte +53 -0
  74. package/dist/form/SignatureControl.svelte.d.ts +11 -0
  75. package/dist/form/TextControl.svelte +107 -0
  76. package/dist/form/TextControl.svelte.d.ts +11 -0
  77. package/dist/form/ToggleControl.svelte +50 -0
  78. package/dist/form/ToggleControl.svelte.d.ts +11 -0
  79. package/dist/form/WidgetBox.svelte +82 -0
  80. package/dist/form/WidgetBox.svelte.d.ts +15 -0
  81. package/dist/form/props.d.ts +21 -0
  82. package/dist/form/props.js +1 -0
  83. package/dist/form/readers.svelte.d.ts +46 -0
  84. package/dist/form/readers.svelte.js +52 -0
  85. package/dist/form/widget.d.ts +16 -0
  86. package/dist/form/widget.js +20 -0
  87. package/dist/form.d.ts +11 -0
  88. package/dist/form.js +12 -0
  89. package/dist/history/readers.d.ts +22 -0
  90. package/dist/history/readers.js +21 -0
  91. package/dist/history.d.ts +10 -0
  92. package/dist/history.js +11 -0
  93. package/dist/i18n/readers.svelte.d.ts +32 -0
  94. package/dist/i18n/readers.svelte.js +30 -0
  95. package/dist/i18n.d.ts +8 -0
  96. package/dist/i18n.js +9 -0
  97. package/dist/index.d.ts +30 -0
  98. package/dist/index.js +30 -0
  99. package/dist/interaction/PagePointerSource.svelte +37 -0
  100. package/dist/interaction/PagePointerSource.svelte.d.ts +3 -0
  101. package/dist/interaction/readers.svelte.d.ts +26 -0
  102. package/dist/interaction/readers.svelte.js +47 -0
  103. package/dist/interaction.d.ts +11 -0
  104. package/dist/interaction.js +13 -0
  105. package/dist/link/LinkLayer.svelte +164 -0
  106. package/dist/link/LinkLayer.svelte.d.ts +4 -0
  107. package/dist/link/props.d.ts +17 -0
  108. package/dist/link/props.js +1 -0
  109. package/dist/link/readers.svelte.d.ts +18 -0
  110. package/dist/link/readers.svelte.js +38 -0
  111. package/dist/link.d.ts +11 -0
  112. package/dist/link.js +11 -0
  113. package/dist/measurement/readers.d.ts +44 -0
  114. package/dist/measurement/readers.js +46 -0
  115. package/dist/measurement.d.ts +12 -0
  116. package/dist/measurement.js +13 -0
  117. package/dist/metadata/readers.d.ts +22 -0
  118. package/dist/metadata/readers.js +22 -0
  119. package/dist/metadata.d.ts +12 -0
  120. package/dist/metadata.js +13 -0
  121. package/dist/outline/readers.d.ts +26 -0
  122. package/dist/outline/readers.js +22 -0
  123. package/dist/outline.d.ts +12 -0
  124. package/dist/outline.js +13 -0
  125. package/dist/page-edit/readers.d.ts +17 -0
  126. package/dist/page-edit/readers.js +18 -0
  127. package/dist/page-edit.d.ts +12 -0
  128. package/dist/page-edit.js +13 -0
  129. package/dist/page-view/PageView.svelte +192 -0
  130. package/dist/page-view/PageView.svelte.d.ts +4 -0
  131. package/dist/page-view/props.d.ts +32 -0
  132. package/dist/page-view/props.js +1 -0
  133. package/dist/page-view.d.ts +8 -0
  134. package/dist/page-view.js +7 -0
  135. package/dist/redaction/readers.d.ts +37 -0
  136. package/dist/redaction/readers.js +38 -0
  137. package/dist/redaction.d.ts +12 -0
  138. package/dist/redaction.js +13 -0
  139. package/dist/render/RenderLayer.svelte +116 -0
  140. package/dist/render/RenderLayer.svelte.d.ts +4 -0
  141. package/dist/render/TileImage.svelte +65 -0
  142. package/dist/render/TileImage.svelte.d.ts +11 -0
  143. package/dist/render/TilePlane.svelte +88 -0
  144. package/dist/render/TilePlane.svelte.d.ts +7 -0
  145. package/dist/render/props.d.ts +16 -0
  146. package/dist/render/props.js +1 -0
  147. package/dist/render/readers.svelte.d.ts +9 -0
  148. package/dist/render/readers.svelte.js +13 -0
  149. package/dist/render.d.ts +10 -0
  150. package/dist/render.js +10 -0
  151. package/dist/runtime/DocumentGate.svelte +26 -0
  152. package/dist/runtime/DocumentGate.svelte.d.ts +4 -0
  153. package/dist/runtime/DocumentScope.svelte +14 -0
  154. package/dist/runtime/DocumentScope.svelte.d.ts +4 -0
  155. package/dist/runtime/KernelProvider.svelte +33 -0
  156. package/dist/runtime/KernelProvider.svelte.d.ts +4 -0
  157. package/dist/runtime/SvgShapes.svelte +30 -0
  158. package/dist/runtime/SvgShapes.svelte.d.ts +8 -0
  159. package/dist/runtime/Viewer.svelte +130 -0
  160. package/dist/runtime/Viewer.svelte.d.ts +4 -0
  161. package/dist/runtime/binding.svelte.d.ts +33 -0
  162. package/dist/runtime/binding.svelte.js +71 -0
  163. package/dist/runtime/capability-handle.d.ts +6 -0
  164. package/dist/runtime/capability-handle.js +71 -0
  165. package/dist/runtime/dev.d.ts +10 -0
  166. package/dist/runtime/dev.js +23 -0
  167. package/dist/runtime/documents.svelte.d.ts +34 -0
  168. package/dist/runtime/documents.svelte.js +49 -0
  169. package/dist/runtime/page-layers.svelte.d.ts +20 -0
  170. package/dist/runtime/page-layers.svelte.js +40 -0
  171. package/dist/runtime/page.d.ts +10 -0
  172. package/dist/runtime/page.js +23 -0
  173. package/dist/runtime/props.d.ts +63 -0
  174. package/dist/runtime/props.js +1 -0
  175. package/dist/runtime/readers.svelte.d.ts +47 -0
  176. package/dist/runtime/readers.svelte.js +122 -0
  177. package/dist/runtime/state.svelte.d.ts +35 -0
  178. package/dist/runtime/state.svelte.js +90 -0
  179. package/dist/runtime/theme.d.ts +12 -0
  180. package/dist/runtime/theme.js +15 -0
  181. package/dist/runtime/values.svelte.d.ts +28 -0
  182. package/dist/runtime/values.svelte.js +51 -0
  183. package/dist/runtime.d.ts +26 -0
  184. package/dist/runtime.js +25 -0
  185. package/dist/search/SearchLayer.svelte +94 -0
  186. package/dist/search/SearchLayer.svelte.d.ts +4 -0
  187. package/dist/search/props.d.ts +11 -0
  188. package/dist/search/props.js +1 -0
  189. package/dist/search/readers.svelte.d.ts +41 -0
  190. package/dist/search/readers.svelte.js +40 -0
  191. package/dist/search.d.ts +11 -0
  192. package/dist/search.js +11 -0
  193. package/dist/selection/SelectionClipboard.svelte +35 -0
  194. package/dist/selection/SelectionClipboard.svelte.d.ts +4 -0
  195. package/dist/selection/SelectionHandles.svelte +192 -0
  196. package/dist/selection/SelectionHandles.svelte.d.ts +4 -0
  197. package/dist/selection/SelectionLayer.svelte +67 -0
  198. package/dist/selection/SelectionLayer.svelte.d.ts +3 -0
  199. package/dist/selection/SelectionMenu.svelte +36 -0
  200. package/dist/selection/SelectionMenu.svelte.d.ts +4 -0
  201. package/dist/selection/props.d.ts +26 -0
  202. package/dist/selection/props.js +1 -0
  203. package/dist/selection/readers.svelte.d.ts +31 -0
  204. package/dist/selection/readers.svelte.js +26 -0
  205. package/dist/selection.d.ts +16 -0
  206. package/dist/selection.js +18 -0
  207. package/dist/shell/readers.svelte.d.ts +40 -0
  208. package/dist/shell/readers.svelte.js +40 -0
  209. package/dist/shell/surface-focus.svelte.d.ts +16 -0
  210. package/dist/shell/surface-focus.svelte.js +33 -0
  211. package/dist/shell.d.ts +12 -0
  212. package/dist/shell.js +11 -0
  213. package/dist/signature/readers.svelte.d.ts +43 -0
  214. package/dist/signature/readers.svelte.js +46 -0
  215. package/dist/signature.d.ts +15 -0
  216. package/dist/signature.js +16 -0
  217. package/dist/stage/PageSurface.svelte +126 -0
  218. package/dist/stage/PageSurface.svelte.d.ts +18 -0
  219. package/dist/stage/Scrollbar.svelte +148 -0
  220. package/dist/stage/Scrollbar.svelte.d.ts +4 -0
  221. package/dist/stage/Stage.svelte +181 -0
  222. package/dist/stage/Stage.svelte.d.ts +4 -0
  223. package/dist/stage/StageScope.svelte +14 -0
  224. package/dist/stage/StageScope.svelte.d.ts +9 -0
  225. package/dist/stage/props.d.ts +71 -0
  226. package/dist/stage/props.js +1 -0
  227. package/dist/stage/readers.svelte.d.ts +39 -0
  228. package/dist/stage/readers.svelte.js +84 -0
  229. package/dist/stage/stage-scope.d.ts +18 -0
  230. package/dist/stage/stage-scope.js +35 -0
  231. package/dist/stage/two-way.svelte.d.ts +13 -0
  232. package/dist/stage/two-way.svelte.js +26 -0
  233. package/dist/stage.d.ts +17 -0
  234. package/dist/stage.js +15 -0
  235. package/dist/stamp/readers.svelte.d.ts +50 -0
  236. package/dist/stamp/readers.svelte.js +76 -0
  237. package/dist/stamp.d.ts +16 -0
  238. package/dist/stamp.js +18 -0
  239. package/dist/toolbar/DefaultCollapsed.svelte +39 -0
  240. package/dist/toolbar/DefaultCollapsed.svelte.d.ts +9 -0
  241. package/dist/toolbar/DefaultCommand.svelte +33 -0
  242. package/dist/toolbar/DefaultCommand.svelte.d.ts +8 -0
  243. package/dist/toolbar/DefaultGroupTrigger.svelte +39 -0
  244. package/dist/toolbar/DefaultGroupTrigger.svelte.d.ts +9 -0
  245. package/dist/toolbar/DefaultOverflowMenu.svelte +106 -0
  246. package/dist/toolbar/DefaultOverflowMenu.svelte.d.ts +9 -0
  247. package/dist/toolbar/DefaultOverflowTrigger.svelte +25 -0
  248. package/dist/toolbar/DefaultOverflowTrigger.svelte.d.ts +7 -0
  249. package/dist/toolbar/Measured.svelte +46 -0
  250. package/dist/toolbar/Measured.svelte.d.ts +11 -0
  251. package/dist/toolbar/NativeSlotSocket.svelte +43 -0
  252. package/dist/toolbar/NativeSlotSocket.svelte.d.ts +11 -0
  253. package/dist/toolbar/Toolbar.svelte +314 -0
  254. package/dist/toolbar/Toolbar.svelte.d.ts +4 -0
  255. package/dist/toolbar/paint.d.ts +3 -0
  256. package/dist/toolbar/paint.js +9 -0
  257. package/dist/toolbar/props.d.ts +48 -0
  258. package/dist/toolbar/props.js +1 -0
  259. package/dist/toolbar/strip.svelte.d.ts +14 -0
  260. package/dist/toolbar/strip.svelte.js +35 -0
  261. package/dist/toolbar/views.d.ts +14 -0
  262. package/dist/toolbar/views.js +1 -0
  263. package/dist/toolbar.d.ts +16 -0
  264. package/dist/toolbar.js +12 -0
  265. package/dist/view-manager/readers.d.ts +19 -0
  266. package/dist/view-manager/readers.js +17 -0
  267. package/dist/view-manager.d.ts +11 -0
  268. package/dist/view-manager.js +12 -0
  269. package/package.json +207 -3
@@ -0,0 +1,76 @@
1
+ import { StampToken, stampState } from '@embedpdf/plugin-stamp';
2
+ import { objectUrlOf } from '@embedpdf/web';
3
+ import { shallowArray, useCapability, useCapabilityEvent, useOptionalSelector, useSelector, } from '../runtime/readers.svelte.js';
4
+ import { settingsReader, stateReader } from '../runtime/state.svelte.js';
5
+ import { valueOf } from '../runtime/values.svelte.js';
6
+ /**
7
+ * The stamp API. Libraries are shared by every document; the placing verbs (`armAsset`,
8
+ * `placeAsset`, …) act on the nearest `<DocumentScope>`'s document, else the active one. A handle:
9
+ * keep it whole and call through it, `stamp.armAsset(id)`.
10
+ */
11
+ export function useStamp() {
12
+ return useCapability(StampToken);
13
+ }
14
+ /** Subscribe to one stamp event while the component lives: `useStampEvent((stamp) => stamp.onLibraryChanged, handler)`. */
15
+ export function useStampEvent(select, handler) {
16
+ useCapabilityEvent(StampToken, select, handler);
17
+ }
18
+ /**
19
+ * The stamps' state for this component's document: the armed stamp (the page's State table,
20
+ * declared once in `stampState`), as a reactive object (`stampState.armedAsset`). With a
21
+ * selector, the value it picks as `{ current }`.
22
+ */
23
+ export const useStampState = stateReader(stampState);
24
+ /** The stamp settings (`assetEngine`, `previewWidth`, `dynamic`), with or without a document. */
25
+ export const useStampSettings = settingsReader(StampToken);
26
+ /**
27
+ * The libraries as `{ current }`, optionally of one kind or several (`{ kind: 'stamps' }`,
28
+ * `{ kind: ['stamps', 'legal-seals'] }`; a function to follow a prop). Every read is a new array,
29
+ * compared item by item, so the value changes only when a library is added, renamed or removed.
30
+ */
31
+ export function useStampLibraries(filter) {
32
+ return useSelector(StampToken, (stamp) => stamp.listLibraries(valueOf(filter)), shallowArray);
33
+ }
34
+ /**
35
+ * The stamps as `{ current }`: one library's (`{ libraryId }`), one kind's or category's, or every
36
+ * stamp, in the order a picker shows them. A filter that changes is a function:
37
+ * `useStampAssets(() => ({ libraryId }))`.
38
+ */
39
+ export function useStampAssets(filter) {
40
+ return useSelector(StampToken, (stamp) => stamp.listAssets(valueOf(filter)), shallowArray);
41
+ }
42
+ /**
43
+ * An image URL for a stamp's cached preview (a gallery thumbnail) as `{ current }`, or null while
44
+ * there is none. An id that changes is a function: `useStampAssetPreviewUrl(() => assetId)`.
45
+ *
46
+ * The plugin holds the preview's bytes; the URL is a DOM resource, so it is made here and revoked
47
+ * when the preview changes or the component goes away, the rule `<AnnotationLayer>` follows for
48
+ * the pictures it shows.
49
+ */
50
+ export function useStampAssetPreviewUrl(assetId) {
51
+ // The preview itself, read on every change: it follows the id, and a preview that arrives
52
+ // after the stamp does.
53
+ const preview = useOptionalSelector(StampToken, (stamp) => {
54
+ const id = valueOf(assetId);
55
+ return id ? stamp.getAssetPreview(id) : null;
56
+ }, null);
57
+ let url = $state(null);
58
+ $effect(() => {
59
+ const current = preview.current;
60
+ if (!current) {
61
+ url = null;
62
+ return;
63
+ }
64
+ const objectUrl = objectUrlOf(current);
65
+ url = objectUrl.url;
66
+ return () => {
67
+ objectUrl.revoke();
68
+ url = null;
69
+ };
70
+ });
71
+ return {
72
+ get current() {
73
+ return url;
74
+ },
75
+ };
76
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @embedpdf/svelte/stamp — stamps: libraries of marks you pick from and place.
3
+ *
4
+ * Thin by design: the plugin owns the libraries, their stamps and the cached previews. Placing
5
+ * needs no component here: an armed stamp rides the annotation plugin, whose `<AnnotationLayer>`
6
+ * draws the ghost under the pointer.
7
+ *
8
+ * const stamp = useStamp();
9
+ * const assets = useStampAssets(() => ({ libraryId })); // assets.current
10
+ * const stampState = useStampState(); // stampState.armedAsset
11
+ * await stamp.armAsset(assetId); // the next click places it
12
+ */
13
+ export * from '@embedpdf/plugin-stamp';
14
+ export { indexedDbByteStore } from '@embedpdf/web';
15
+ export type { ByteStore } from '@embedpdf/web';
16
+ export { useStamp, useStampAssetPreviewUrl, useStampAssets, useStampEvent, useStampLibraries, useStampSettings, useStampState, } from './stamp/readers.svelte.js';
package/dist/stamp.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @embedpdf/svelte/stamp — stamps: libraries of marks you pick from and place.
3
+ *
4
+ * Thin by design: the plugin owns the libraries, their stamps and the cached previews. Placing
5
+ * needs no component here: an armed stamp rides the annotation plugin, whose `<AnnotationLayer>`
6
+ * draws the ghost under the pointer.
7
+ *
8
+ * const stamp = useStamp();
9
+ * const assets = useStampAssets(() => ({ libraryId })); // assets.current
10
+ * const stampState = useStampState(); // stampState.armedAsset
11
+ * await stamp.armAsset(assetId); // the next click places it
12
+ */
13
+ // Registration travels with the UI.
14
+ export * from '@embedpdf/plugin-stamp';
15
+ // The browser store for `persistStampLibraries` / `restoreStampLibraries` (structurally the
16
+ // plugin's `StampLibraryStore`), written once in `@embedpdf/web`.
17
+ export { indexedDbByteStore } from '@embedpdf/web';
18
+ export { useStamp, useStampAssetPreviewUrl, useStampAssets, useStampEvent, useStampLibraries, useStampSettings, useStampState, } from './stamp/readers.svelte.js';
@@ -0,0 +1,39 @@
1
+ <!--
2
+ The default folded group: a <select> for `collapse: 'select'`, else a "More"-style button with a
3
+ menu of the group's commands.
4
+ -->
5
+ <script lang="ts">
6
+ import DefaultOverflowMenu from './DefaultOverflowMenu.svelte';
7
+ import DefaultOverflowTrigger from './DefaultOverflowTrigger.svelte';
8
+ import { groupMenuView } from '@embedpdf/core-ui';
9
+ import type { Orientation } from '@embedpdf/web';
10
+ import type { CollapsedGroupView } from './views.js';
11
+ import { BORDER, SURFACE } from './paint.js';
12
+
13
+ let { view, orientation }: { view: CollapsedGroupView; orientation: Orientation } = $props();
14
+
15
+ let isOpen = $state(false);
16
+ const active = $derived(view.commands.find((command) => command.active)?.id ?? '');
17
+ const menu = $derived(groupMenuView(view, isOpen, () => (isOpen = false)));
18
+ </script>
19
+
20
+ {#if view.collapse === 'select'}
21
+ <select
22
+ value={active}
23
+ onchange={(event) => view.execute(event.currentTarget.value)}
24
+ style:padding="4px 6px"
25
+ style:font="inherit"
26
+ style:border-radius="4px"
27
+ style:border="1px solid {BORDER}"
28
+ style:background={SURFACE}
29
+ >
30
+ {#each view.commands as command (command.id)}
31
+ <option value={command.id} disabled={!command.enabled}>{command.label}</option>
32
+ {/each}
33
+ </select>
34
+ {:else}
35
+ <span style="position: relative; display: inline-flex">
36
+ <DefaultOverflowTrigger {isOpen} toggle={() => (isOpen = !isOpen)} />
37
+ <DefaultOverflowMenu view={menu} {orientation} />
38
+ </span>
39
+ {/if}
@@ -0,0 +1,9 @@
1
+ import type { Orientation } from '@embedpdf/web';
2
+ import type { CollapsedGroupView } from './views.js';
3
+ type $$ComponentProps = {
4
+ view: CollapsedGroupView;
5
+ orientation: Orientation;
6
+ };
7
+ declare const DefaultCollapsed: import("svelte").Component<$$ComponentProps, {}, "">;
8
+ type DefaultCollapsed = ReturnType<typeof DefaultCollapsed>;
9
+ export default DefaultCollapsed;
@@ -0,0 +1,33 @@
1
+ <!--
2
+ The default command button: the command's label in every variant (icons are the app's), pressed
3
+ when the command is active.
4
+ -->
5
+ <script lang="ts">
6
+ import type { ResolvedCommand } from '@embedpdf/plugin-commands/contract';
7
+ import { ACTIVE, BORDER } from './paint.js';
8
+
9
+ let { command, run }: { command: ResolvedCommand; run: () => void } = $props();
10
+ </script>
11
+
12
+ <button
13
+ type="button"
14
+ onclick={run}
15
+ disabled={!command.enabled}
16
+ aria-pressed={command.active || undefined}
17
+ aria-haspopup={command.menu ? 'menu' : undefined}
18
+ title={command.label}
19
+ style:display="inline-flex"
20
+ style:align-items="center"
21
+ style:gap="4px"
22
+ style:padding="4px 8px"
23
+ style:white-space="nowrap"
24
+ style:color="inherit"
25
+ style:font="inherit"
26
+ style:background={command.active ? ACTIVE : 'transparent'}
27
+ style:border="1px solid {BORDER}"
28
+ style:border-radius="4px"
29
+ style:cursor={command.enabled ? 'pointer' : 'default'}
30
+ style:opacity={command.enabled ? 1 : 0.4}
31
+ >
32
+ {command.label}
33
+ </button>
@@ -0,0 +1,8 @@
1
+ import type { ResolvedCommand } from '@embedpdf/plugin-commands/contract';
2
+ type $$ComponentProps = {
3
+ command: ResolvedCommand;
4
+ run: () => void;
5
+ };
6
+ declare const DefaultCommand: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type DefaultCommand = ReturnType<typeof DefaultCommand>;
8
+ export default DefaultCommand;
@@ -0,0 +1,39 @@
1
+ <!--
2
+ The default button of a group that shed items: a chevron opening a menu of what it shed, lit
3
+ while the active item is in there.
4
+ -->
5
+ <script lang="ts">
6
+ import DefaultOverflowMenu from './DefaultOverflowMenu.svelte';
7
+ import { groupMenuView } from '@embedpdf/core-ui';
8
+ import type { Orientation } from '@embedpdf/web';
9
+ import type { GroupDisclosureView } from './views.js';
10
+ import { ACTIVE, BORDER } from './paint.js';
11
+
12
+ let { view, orientation }: { view: GroupDisclosureView; orientation: Orientation } = $props();
13
+
14
+ let isOpen = $state(false);
15
+ const someActive = $derived(view.commands.some((command) => command.active));
16
+ const menu = $derived(groupMenuView(view, isOpen, () => (isOpen = false)));
17
+ </script>
18
+
19
+ <span style="position: relative; display: inline-flex">
20
+ <button
21
+ type="button"
22
+ onclick={() => (isOpen = !isOpen)}
23
+ aria-haspopup="menu"
24
+ aria-expanded={isOpen}
25
+ title="More"
26
+ style:display="inline-flex"
27
+ style:align-items="center"
28
+ style:padding="4px 6px"
29
+ style:color="inherit"
30
+ style:font="inherit"
31
+ style:border="1px solid {BORDER}"
32
+ style:border-radius="4px"
33
+ style:background={isOpen || someActive ? ACTIVE : 'transparent'}
34
+ style:cursor="pointer"
35
+ >
36
+ ▾
37
+ </button>
38
+ <DefaultOverflowMenu view={menu} {orientation} />
39
+ </span>
@@ -0,0 +1,9 @@
1
+ import type { Orientation } from '@embedpdf/web';
2
+ import type { GroupDisclosureView } from './views.js';
3
+ type $$ComponentProps = {
4
+ view: GroupDisclosureView;
5
+ orientation: Orientation;
6
+ };
7
+ declare const DefaultGroupTrigger: import("svelte").Component<$$ComponentProps, {}, "">;
8
+ type DefaultGroupTrigger = ReturnType<typeof DefaultGroupTrigger>;
9
+ export default DefaultGroupTrigger;
@@ -0,0 +1,106 @@
1
+ <!--
2
+ The default "More" menu: a minimal popover under its button in a horizontal toolbar and beside
3
+ it in a vertical one, one section after another. A press anywhere outside it closes it, and
4
+ while it's open it takes the menu keys (`attachMenuKeys`): focus on its first row, the arrows,
5
+ typeahead, Enter, and Escape back to its button. A row that opens a submenu keeps the menu
6
+ open; every other row closes it after running.
7
+ -->
8
+ <script lang="ts">
9
+ import { untrack } from 'svelte';
10
+ import type { OverflowRow } from '@embedpdf/core-ui';
11
+ import {
12
+ attachMenuKeys,
13
+ focusablesIn,
14
+ observeOutsidePress,
15
+ type Orientation,
16
+ } from '@embedpdf/web';
17
+ import type { OverflowMenuView } from './views.js';
18
+ import { BORDER, SURFACE } from './paint.js';
19
+
20
+ let { view, orientation }: { view: OverflowMenuView; orientation: Orientation } = $props();
21
+ let menu = $state<HTMLElement | null>(null);
22
+
23
+ // Whether it's open, apart from the view: the toolbar hands a new view on every change, and
24
+ // attaching again would put focus back on the first row.
25
+ const isOpen = $derived(view.isOpen);
26
+
27
+ $effect(() => {
28
+ const element = menu;
29
+ if (!isOpen || !element) return;
30
+ return untrack(() => {
31
+ // The menu's parent holds its button too: a press on it is the button's own toggle.
32
+ const container = element.parentElement ?? element;
33
+ const trigger =
34
+ focusablesIn(container).find((candidate) => !element.contains(candidate)) ?? null;
35
+ const close = () => view.close();
36
+ const stopOutside = observeOutsidePress(container, close);
37
+ const detachKeys = attachMenuKeys(element, { trigger, close });
38
+ return () => {
39
+ stopOutside();
40
+ detachKeys();
41
+ };
42
+ });
43
+ });
44
+
45
+ /** Under a horizontal toolbar's button, beside a vertical one's. */
46
+ const placement = $derived(
47
+ orientation === 'vertical'
48
+ ? 'top: 0; inset-inline-start: 100%;'
49
+ : 'top: 100%; inset-inline-end: 0;',
50
+ );
51
+
52
+ function choose(row: OverflowRow) {
53
+ view.execute(row.command);
54
+ if (row.type !== 'submenu') view.close();
55
+ }
56
+ </script>
57
+
58
+ {#if isOpen}
59
+ <div
60
+ bind:this={menu}
61
+ role="menu"
62
+ style="position: absolute; {placement}"
63
+ style:z-index="41"
64
+ style:min-width="200px"
65
+ style:padding="4px"
66
+ style:background={SURFACE}
67
+ style:border="1px solid {BORDER}"
68
+ style:border-radius="6px"
69
+ style:box-shadow="0 4px 16px rgba(0,0,0,0.15)"
70
+ >
71
+ {#each view.sections as section, index (index)}
72
+ {#if index > 0}
73
+ <div style:height="1px" style:background={BORDER} style:margin="4px 0"></div>
74
+ {/if}
75
+ {#each section.rows as row (row.command)}
76
+ {@const command = view.resolve(row.command)}
77
+ {#if command}
78
+ <button
79
+ type="button"
80
+ role={section.role === 'radio' ? 'menuitemradio' : 'menuitem'}
81
+ aria-checked={section.role === 'radio' ? command.active : undefined}
82
+ disabled={!command.enabled}
83
+ tabindex="-1"
84
+ onclick={() => choose(row)}
85
+ style:display="flex"
86
+ style:width="100%"
87
+ style:align-items="center"
88
+ style:justify-content="space-between"
89
+ style:gap="16px"
90
+ style:padding="6px 8px"
91
+ style:border="none"
92
+ style:color="inherit"
93
+ style:font="inherit"
94
+ style:background="transparent"
95
+ style:cursor={command.enabled ? 'pointer' : 'default'}
96
+ style:opacity={command.enabled ? 1 : 0.4}
97
+ style:white-space="nowrap"
98
+ >
99
+ <span>{command.active && section.role === 'radio' ? '• ' : ''}{command.label}</span>
100
+ {#if row.type === 'submenu'}<span>▸</span>{/if}
101
+ </button>
102
+ {/if}
103
+ {/each}
104
+ {/each}
105
+ </div>
106
+ {/if}
@@ -0,0 +1,9 @@
1
+ import { type Orientation } from '@embedpdf/web';
2
+ import type { OverflowMenuView } from './views.js';
3
+ type $$ComponentProps = {
4
+ view: OverflowMenuView;
5
+ orientation: Orientation;
6
+ };
7
+ declare const DefaultOverflowMenu: import("svelte").Component<$$ComponentProps, {}, "">;
8
+ type DefaultOverflowMenu = ReturnType<typeof DefaultOverflowMenu>;
9
+ export default DefaultOverflowMenu;
@@ -0,0 +1,25 @@
1
+ <!-- The default "More" button: a plain ⋯ that shows whether its menu is open. -->
2
+ <script lang="ts">
3
+ import { ACTIVE, BORDER } from './paint.js';
4
+
5
+ let { isOpen, toggle }: { isOpen: boolean; toggle: () => void } = $props();
6
+ </script>
7
+
8
+ <button
9
+ type="button"
10
+ onclick={toggle}
11
+ aria-haspopup="menu"
12
+ aria-expanded={isOpen}
13
+ title="More"
14
+ style:display="inline-flex"
15
+ style:align-items="center"
16
+ style:padding="4px 8px"
17
+ style:color="inherit"
18
+ style:font="inherit"
19
+ style:border="1px solid {BORDER}"
20
+ style:border-radius="4px"
21
+ style:background={isOpen ? ACTIVE : 'transparent'}
22
+ style:cursor="pointer"
23
+ >
24
+ ⋯
25
+ </button>
@@ -0,0 +1,7 @@
1
+ type $$ComponentProps = {
2
+ isOpen: boolean;
3
+ toggle: () => void;
4
+ };
5
+ declare const DefaultOverflowTrigger: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type DefaultOverflowTrigger = ReturnType<typeof DefaultOverflowTrigger>;
7
+ export default DefaultOverflowTrigger;
@@ -0,0 +1,46 @@
1
+ <!--
2
+ One element of the toolbar's measurement layer: reports its length along the toolbar (its width,
3
+ or its height in a vertical one) now and whenever it resizes (a new language, a font loading,
4
+ your CSS). With `onlyWhenDrawn` it reports only while it holds something: a custom item that
5
+ draws nothing here is measured where it renders, by the `ctx.measure` it reports to.
6
+ -->
7
+ <script lang="ts">
8
+ import { untrack, type Snippet } from 'svelte';
9
+ import { observeLength, type Orientation } from '@embedpdf/web';
10
+
11
+ let {
12
+ orientation,
13
+ onLength,
14
+ onlyWhenDrawn = false,
15
+ children,
16
+ }: {
17
+ orientation: Orientation;
18
+ onLength: (length: number) => void;
19
+ onlyWhenDrawn?: boolean;
20
+ children?: Snippet;
21
+ } = $props();
22
+
23
+ let element: HTMLSpanElement | undefined = $state();
24
+
25
+ /** Whether `element` holds an element or text: a snippet that drew nothing leaves only anchors. */
26
+ const drewSomething = (measured: Element): boolean =>
27
+ [...measured.childNodes].some(
28
+ (node) =>
29
+ node.nodeType === Node.ELEMENT_NODE ||
30
+ (node.nodeType === Node.TEXT_NODE && (node.textContent ?? '').trim() !== ''),
31
+ );
32
+
33
+ $effect(() => {
34
+ const measured = element;
35
+ const along = orientation;
36
+ if (!measured) return;
37
+ // The report writes the toolbar's lengths, which this effect must not depend on.
38
+ return untrack(() =>
39
+ observeLength(measured, along, (length) => {
40
+ if (!onlyWhenDrawn || drewSomething(measured)) onLength(length);
41
+ }),
42
+ );
43
+ });
44
+ </script>
45
+
46
+ <span bind:this={element} style="display: inline-flex; flex-shrink: 0">{@render children?.()}</span>
@@ -0,0 +1,11 @@
1
+ import { type Snippet } from 'svelte';
2
+ import { type Orientation } from '@embedpdf/web';
3
+ type $$ComponentProps = {
4
+ orientation: Orientation;
5
+ onLength: (length: number) => void;
6
+ onlyWhenDrawn?: boolean;
7
+ children?: Snippet;
8
+ };
9
+ declare const Measured: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type Measured = ReturnType<typeof Measured>;
11
+ export default Measured;
@@ -0,0 +1,43 @@
1
+ <!--
2
+ The socket for a custom item when no `custom` snippet draws it: a real, native <slot> element.
3
+ Inside a shadow root (a custom element that renders the toolbar) the browser projects the
4
+ host's same-named children into it; anywhere else it shows its own content, the item's
5
+ command. It is measured where it renders, never in the measurement layer: only the first
6
+ <slot> of a name gets the projected children.
7
+ -->
8
+ <script lang="ts">
9
+ import { untrack, type Snippet } from 'svelte';
10
+ import { observeLength, type Orientation } from '@embedpdf/web';
11
+
12
+ let {
13
+ name,
14
+ orientation,
15
+ onLength,
16
+ children,
17
+ }: {
18
+ name: string;
19
+ orientation: Orientation;
20
+ onLength: (length: number) => void;
21
+ children?: Snippet;
22
+ } = $props();
23
+
24
+ let socket: HTMLElement | undefined = $state();
25
+
26
+ // A child slotted in or out resizes the socket's box, so one observer covers both.
27
+ $effect(() => {
28
+ const element = socket;
29
+ const along = orientation;
30
+ if (!element) return;
31
+ return untrack(() => observeLength(element, along, (length) => onLength(length)));
32
+ });
33
+ </script>
34
+
35
+ <!-- `svelte:element` makes the element itself: Svelte reads a <slot> tag as its own syntax. -->
36
+ <svelte:element
37
+ this={'slot'}
38
+ bind:this={socket}
39
+ {name}
40
+ style="display: inline-flex; align-items: center; flex-shrink: 0"
41
+ >
42
+ {@render children?.()}
43
+ </svelte:element>
@@ -0,0 +1,11 @@
1
+ import { type Snippet } from 'svelte';
2
+ import { type Orientation } from '@embedpdf/web';
3
+ type $$ComponentProps = {
4
+ name: string;
5
+ orientation: Orientation;
6
+ onLength: (length: number) => void;
7
+ children?: Snippet;
8
+ };
9
+ declare const NativeSlotSocket: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type NativeSlotSocket = ReturnType<typeof NativeSlotSocket>;
11
+ export default NativeSlotSocket;