@embedpdf/plugin-ui 1.4.1 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +1313 -655
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +110 -74
  6. package/dist/lib/index.d.ts +8 -7
  7. package/dist/lib/reducer.d.ts +5 -5
  8. package/dist/lib/schema.d.ts +257 -0
  9. package/dist/lib/selectors.d.ts +16 -0
  10. package/dist/lib/types.d.ts +185 -202
  11. package/dist/lib/ui-plugin.d.ts +66 -18
  12. package/dist/lib/utils/consts.d.ts +25 -0
  13. package/dist/lib/utils/index.d.ts +5 -0
  14. package/dist/lib/utils/responsive-utils.d.ts +10 -0
  15. package/dist/lib/utils/schema-merger.d.ts +15 -0
  16. package/dist/lib/utils/stylesheet-generator.d.ts +40 -0
  17. package/dist/lib/utils/ui-props.d.ts +14 -0
  18. package/dist/preact/adapter.d.ts +4 -2
  19. package/dist/preact/index.cjs +1 -1
  20. package/dist/preact/index.cjs.map +1 -1
  21. package/dist/preact/index.js +450 -49
  22. package/dist/preact/index.js.map +1 -1
  23. package/dist/preact/utils.d.ts +1 -0
  24. package/dist/react/adapter.d.ts +2 -2
  25. package/dist/react/index.cjs +1 -1
  26. package/dist/react/index.cjs.map +1 -1
  27. package/dist/react/index.js +449 -48
  28. package/dist/react/index.js.map +1 -1
  29. package/dist/react/utils.d.ts +1 -0
  30. package/dist/shared/auto-menu-renderer.d.ts +13 -0
  31. package/dist/shared/hooks/index.d.ts +4 -0
  32. package/dist/shared/hooks/use-item-renderer.d.ts +14 -0
  33. package/dist/shared/hooks/use-register-anchor.d.ts +17 -0
  34. package/dist/shared/hooks/use-schema-renderer.d.ts +61 -0
  35. package/dist/shared/hooks/use-selection-menu.d.ts +11 -0
  36. package/dist/shared/hooks/use-ui.d.ts +13 -5
  37. package/dist/shared/index.d.ts +4 -1
  38. package/dist/shared/provider.d.ts +68 -0
  39. package/dist/shared/registries/anchor-registry.d.ts +16 -0
  40. package/dist/shared/registries/component-registry.d.ts +20 -0
  41. package/dist/shared/registries/index.d.ts +3 -0
  42. package/dist/shared/registries/renderers-registry.d.ts +8 -0
  43. package/dist/shared/root.d.ts +12 -0
  44. package/dist/shared/types.d.ts +67 -0
  45. package/dist/shared-preact/auto-menu-renderer.d.ts +13 -0
  46. package/dist/shared-preact/hooks/index.d.ts +4 -0
  47. package/dist/shared-preact/hooks/use-item-renderer.d.ts +14 -0
  48. package/dist/shared-preact/hooks/use-register-anchor.d.ts +17 -0
  49. package/dist/shared-preact/hooks/use-schema-renderer.d.ts +61 -0
  50. package/dist/shared-preact/hooks/use-selection-menu.d.ts +11 -0
  51. package/dist/shared-preact/hooks/use-ui.d.ts +13 -5
  52. package/dist/shared-preact/index.d.ts +4 -1
  53. package/dist/shared-preact/provider.d.ts +68 -0
  54. package/dist/shared-preact/registries/anchor-registry.d.ts +16 -0
  55. package/dist/shared-preact/registries/component-registry.d.ts +20 -0
  56. package/dist/shared-preact/registries/index.d.ts +3 -0
  57. package/dist/shared-preact/registries/renderers-registry.d.ts +8 -0
  58. package/dist/shared-preact/root.d.ts +12 -0
  59. package/dist/shared-preact/types.d.ts +67 -0
  60. package/dist/shared-react/auto-menu-renderer.d.ts +13 -0
  61. package/dist/shared-react/hooks/index.d.ts +4 -0
  62. package/dist/shared-react/hooks/use-item-renderer.d.ts +14 -0
  63. package/dist/shared-react/hooks/use-register-anchor.d.ts +17 -0
  64. package/dist/shared-react/hooks/use-schema-renderer.d.ts +61 -0
  65. package/dist/shared-react/hooks/use-selection-menu.d.ts +11 -0
  66. package/dist/shared-react/hooks/use-ui.d.ts +13 -5
  67. package/dist/shared-react/index.d.ts +4 -1
  68. package/dist/shared-react/provider.d.ts +68 -0
  69. package/dist/shared-react/registries/anchor-registry.d.ts +16 -0
  70. package/dist/shared-react/registries/component-registry.d.ts +20 -0
  71. package/dist/shared-react/registries/index.d.ts +3 -0
  72. package/dist/shared-react/registries/renderers-registry.d.ts +8 -0
  73. package/dist/shared-react/root.d.ts +12 -0
  74. package/dist/shared-react/types.d.ts +67 -0
  75. package/dist/svelte/auto-menu-renderer.svelte.d.ts +15 -0
  76. package/dist/svelte/hooks/index.d.ts +5 -0
  77. package/dist/svelte/hooks/use-item-renderer.svelte.d.ts +24 -0
  78. package/dist/svelte/hooks/use-register-anchor.svelte.d.ts +18 -0
  79. package/dist/svelte/hooks/use-schema-renderer.svelte.d.ts +78 -0
  80. package/dist/svelte/hooks/use-selection-menu.svelte.d.ts +9 -0
  81. package/dist/svelte/hooks/use-ui.svelte.d.ts +34 -0
  82. package/dist/svelte/index.cjs +2 -0
  83. package/dist/svelte/index.cjs.map +1 -0
  84. package/dist/svelte/index.d.ts +6 -0
  85. package/dist/svelte/index.js +553 -0
  86. package/dist/svelte/index.js.map +1 -0
  87. package/dist/svelte/provider.svelte.d.ts +33 -0
  88. package/dist/svelte/registries/anchor-registry.svelte.d.ts +14 -0
  89. package/dist/svelte/registries/component-registry.svelte.d.ts +17 -0
  90. package/dist/svelte/registries/index.d.ts +3 -0
  91. package/dist/svelte/registries/renderers-registry.svelte.d.ts +3 -0
  92. package/dist/svelte/root.svelte.d.ts +8 -0
  93. package/dist/svelte/types.d.ts +67 -0
  94. package/dist/vue/auto-menu-renderer.vue.d.ts +15 -0
  95. package/dist/vue/hooks/index.d.ts +5 -0
  96. package/dist/vue/hooks/use-item-renderer.d.ts +16 -0
  97. package/dist/vue/hooks/use-register-anchor.d.ts +19 -0
  98. package/dist/vue/hooks/use-schema-renderer.d.ts +63 -0
  99. package/dist/vue/hooks/use-selection-menu.d.ts +28 -0
  100. package/dist/vue/hooks/use-ui.d.ts +940 -0
  101. package/dist/vue/index.cjs +2 -0
  102. package/dist/vue/index.cjs.map +1 -0
  103. package/dist/vue/index.d.ts +6 -0
  104. package/dist/vue/index.js +544 -0
  105. package/dist/vue/index.js.map +1 -0
  106. package/dist/vue/provider.vue.d.ts +43 -0
  107. package/dist/vue/registries/anchor-registry.d.ts +14 -0
  108. package/dist/vue/registries/component-registry.d.ts +17 -0
  109. package/dist/vue/registries/index.d.ts +3 -0
  110. package/dist/vue/registries/renderers-registry.d.ts +3 -0
  111. package/dist/vue/root.vue.d.ts +13 -0
  112. package/dist/vue/types.d.ts +67 -0
  113. package/package.json +32 -9
  114. package/dist/lib/menu/menu-manager.d.ts +0 -98
  115. package/dist/lib/menu/types.d.ts +0 -91
  116. package/dist/lib/menu/utils.d.ts +0 -6
  117. package/dist/lib/ui-component.d.ts +0 -30
  118. package/dist/lib/utils.d.ts +0 -33
  119. package/dist/shared/components/component-wrapper.d.ts +0 -5
  120. package/dist/shared/components/index.d.ts +0 -1
  121. package/dist/shared/components/plugin-ui-provider.d.ts +0 -37
  122. package/dist/shared-preact/components/component-wrapper.d.ts +0 -5
  123. package/dist/shared-preact/components/index.d.ts +0 -1
  124. package/dist/shared-preact/components/plugin-ui-provider.d.ts +0 -37
  125. package/dist/shared-react/components/component-wrapper.d.ts +0 -5
  126. package/dist/shared-react/components/index.d.ts +0 -1
  127. package/dist/shared-react/components/plugin-ui-provider.d.ts +0 -37
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-ui.svelte.ts","../../src/svelte/registries/anchor-registry.svelte.ts","../../src/svelte/registries/component-registry.svelte.ts","../../src/svelte/registries/renderers-registry.svelte.ts","../../src/svelte/auto-menu-renderer.svelte","../../src/svelte/root.svelte","../../src/svelte/provider.svelte","../../src/svelte/hooks/use-item-renderer.svelte.ts","../../src/svelte/hooks/use-register-anchor.svelte.ts","../../src/svelte/hooks/use-schema-renderer.svelte.ts","../../src/svelte/hooks/use-selection-menu.svelte.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { UIPlugin, UIDocumentState, UISchema, UIScope } from '@embedpdf/plugin-ui';\n\n/**\n * Hook to get the raw UI plugin instance.\n */\nexport const useUIPlugin = () => usePlugin<UIPlugin>(UIPlugin.id);\n\n/**\n * Hook to get the UI plugin's capability API.\n */\nexport const useUICapability = () => useCapability<UIPlugin>(UIPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseUIStateReturn {\n provides: UIScope | null;\n state: UIDocumentState | null;\n}\n\n/**\n * Hook for UI state for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const useUIState = (getDocumentId: () => string | null): UseUIStateReturn => {\n const capability = useUICapability();\n\n let state = $state<UIDocumentState | null>(null);\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n // Scoped capability for current docId\n const scopedProvides = $derived(\n capability.provides && documentId ? capability.provides.forDocument(documentId) : null,\n );\n\n $effect(() => {\n const provides = capability.provides;\n const docId = documentId;\n\n if (!provides || !docId) {\n state = null;\n return;\n }\n\n const scope = provides.forDocument(docId);\n\n // Set initial state\n state = scope.getState();\n\n // Subscribe to all changes and update state\n const unsubToolbar = scope.onToolbarChanged(() => {\n state = scope.getState();\n });\n const unsubPanel = scope.onPanelChanged(() => {\n state = scope.getState();\n });\n const unsubModal = scope.onModalChanged(() => {\n state = scope.getState();\n });\n const unsubMenu = scope.onMenuChanged(() => {\n state = scope.getState();\n });\n\n return () => {\n unsubToolbar();\n unsubPanel();\n unsubModal();\n unsubMenu();\n };\n });\n\n return {\n get provides() {\n return scopedProvides;\n },\n get state() {\n return state;\n },\n };\n};\n\n/**\n * Hook to get UI schema\n * Returns an object with a reactive getter for the schema\n */\nexport const useUISchema = () => {\n const capability = useUICapability();\n\n return {\n get schema() {\n return capability.provides?.getSchema() ?? null;\n },\n };\n};\n","import { getContext, setContext } from 'svelte';\n\n/**\n * Anchor Registry\n *\n * Tracks DOM elements for menu positioning.\n * Each anchor is scoped by documentId and itemId.\n */\nexport interface AnchorRegistry {\n register(documentId: string, itemId: string, element: HTMLElement): void;\n unregister(documentId: string, itemId: string): void;\n getAnchor(documentId: string, itemId: string): HTMLElement | null;\n}\n\nconst ANCHOR_REGISTRY_KEY = Symbol('AnchorRegistry');\n\nexport function createAnchorRegistry(): AnchorRegistry {\n const anchors = new Map<string, HTMLElement>();\n\n return {\n register(documentId: string, itemId: string, element: HTMLElement) {\n const key = `${documentId}:${itemId}`;\n anchors.set(key, element);\n },\n\n unregister(documentId: string, itemId: string) {\n const key = `${documentId}:${itemId}`;\n anchors.delete(key);\n },\n\n getAnchor(documentId: string, itemId: string) {\n const key = `${documentId}:${itemId}`;\n return anchors.get(key) || null;\n },\n };\n}\n\nexport function provideAnchorRegistry() {\n const registry = createAnchorRegistry();\n setContext(ANCHOR_REGISTRY_KEY, registry);\n return registry;\n}\n\nexport function useAnchorRegistry(): AnchorRegistry {\n const registry = getContext<AnchorRegistry>(ANCHOR_REGISTRY_KEY);\n if (!registry) {\n throw new Error('useAnchorRegistry must be used within UIProvider');\n }\n return registry;\n}\n","import { getContext, setContext, type Component } from 'svelte';\nimport type { BaseComponentProps } from '../types';\n\n/**\n * Component Registry\n *\n * Stores custom components that can be referenced in the UI schema.\n */\nexport interface ComponentRegistry {\n register(id: string, component: Component<BaseComponentProps>): void;\n unregister(id: string): void;\n get(id: string): Component<BaseComponentProps> | undefined;\n has(id: string): boolean;\n getRegisteredIds(): string[];\n}\n\nconst COMPONENT_REGISTRY_KEY = Symbol('ComponentRegistry');\n\nexport function createComponentRegistry(\n initialComponents: Record<string, Component<BaseComponentProps>> = {},\n): ComponentRegistry {\n const components = new Map<string, Component<BaseComponentProps>>(\n Object.entries(initialComponents),\n );\n\n return {\n register(id: string, component: Component<BaseComponentProps>) {\n components.set(id, component);\n },\n\n unregister(id: string) {\n components.delete(id);\n },\n\n get(id: string) {\n return components.get(id);\n },\n\n has(id: string) {\n return components.has(id);\n },\n\n getRegisteredIds() {\n return Array.from(components.keys());\n },\n };\n}\n\nexport function provideComponentRegistry(\n initialComponents: Record<string, Component<BaseComponentProps>> = {},\n) {\n const registry = createComponentRegistry(initialComponents);\n setContext(COMPONENT_REGISTRY_KEY, registry);\n return registry;\n}\n\nexport function useComponentRegistry(): ComponentRegistry {\n const registry = getContext<ComponentRegistry>(COMPONENT_REGISTRY_KEY);\n if (!registry) {\n throw new Error('useComponentRegistry must be used within UIProvider');\n }\n return registry;\n}\n","import { getContext, setContext } from 'svelte';\nimport type { UIRenderers } from '../types';\n\n/**\n * Renderers Registry\n *\n * Provides access to user-supplied renderers (toolbar, panel, menu).\n */\nconst RENDERERS_KEY = Symbol('Renderers');\n\nexport function provideRenderers(renderers: UIRenderers) {\n setContext(RENDERERS_KEY, renderers);\n}\n\nexport function useRenderers(): UIRenderers {\n const renderers = getContext<UIRenderers>(RENDERERS_KEY);\n if (!renderers) {\n throw new Error('useRenderers must be used within UIProvider');\n }\n return renderers;\n}\n","<script lang=\"ts\">\n import { useUIState, useUICapability } from './hooks/use-ui.svelte';\n import { useAnchorRegistry } from './registries/anchor-registry.svelte';\n import { useRenderers } from './registries/renderers-registry.svelte';\n\n /**\n * Automatically renders menus when opened\n *\n * This component:\n * 1. Listens to UI plugin state for open menus\n * 2. Looks up anchor elements from the anchor registry\n * 3. Renders menus using the user-provided menu renderer\n */\n\n interface Props {\n documentId: string; // Which document's menus to render\n container?: HTMLElement | null;\n }\n\n let { documentId, container = null }: Props = $props();\n\n const uiState = useUIState(() => documentId);\n const capability = useUICapability();\n const anchorRegistry = useAnchorRegistry();\n const renderers = useRenderers();\n\n // Derived state for active menu\n const activeMenu = $derived.by(() => {\n const openMenus = uiState.state?.openMenus || {};\n const openMenuIds = Object.keys(openMenus);\n\n if (openMenuIds.length === 0) return null;\n\n // Show the first open menu (in practice, should only be one)\n const menuId = openMenuIds[0];\n if (!menuId) return null;\n\n const menuState = openMenus[menuId];\n if (!menuState || !menuState.triggeredByItemId) return null;\n\n // Look up anchor with documentId scope\n const anchor = anchorRegistry.getAnchor(documentId, menuState.triggeredByItemId);\n return { menuId, anchorEl: anchor };\n });\n\n const schema = $derived(capability.provides?.getSchema());\n\n const menuSchema = $derived.by(() => {\n if (!activeMenu || !schema) return null;\n\n const menuSchemaValue = schema.menus[activeMenu.menuId];\n if (!menuSchemaValue) {\n console.warn(`Menu \"${activeMenu.menuId}\" not found in schema`);\n return null;\n }\n\n return menuSchemaValue;\n });\n\n const handleClose = () => {\n if (activeMenu) {\n uiState.provides?.closeMenu(activeMenu.menuId);\n }\n };\n\n // Use the user-provided menu renderer\n const MenuRenderer = renderers.menu;\n</script>\n\n{#if activeMenu && menuSchema && MenuRenderer}\n <MenuRenderer\n schema={menuSchema}\n {documentId}\n anchorEl={activeMenu.anchorEl}\n onClose={handleClose}\n {container}\n />\n{/if}\n","<script lang=\"ts\">\n import { UI_ATTRIBUTES, UI_SELECTORS } from '@embedpdf/plugin-ui';\n import { useUIPlugin, useUICapability } from './hooks/use-ui.svelte';\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n\n type Props = HTMLAttributes<HTMLDivElement> & {\n children?: Snippet;\n };\n\n let { children, class: className, ...restProps }: Props = $props();\n\n const { plugin } = useUIPlugin();\n const { provides } = useUICapability();\n\n let disabledCategories = $state<string[]>([]);\n let rootElement: HTMLDivElement | null = $state(null);\n let styleEl: HTMLStyleElement | null = null;\n let styleTarget: HTMLElement | ShadowRoot | null = null;\n\n function getStyleTarget(element: HTMLElement): HTMLElement | ShadowRoot {\n const root = element.getRootNode();\n if (root instanceof ShadowRoot) {\n return root;\n }\n return document.head;\n }\n\n $effect(() => {\n if (!rootElement || !plugin) {\n styleTarget = null;\n return;\n }\n\n styleTarget = getStyleTarget(rootElement);\n\n const existingStyle = styleTarget.querySelector(UI_SELECTORS.STYLES) as HTMLStyleElement | null;\n\n if (existingStyle) {\n styleEl = existingStyle;\n existingStyle.textContent = plugin.getStylesheet();\n return;\n }\n\n const stylesheet = plugin.getStylesheet();\n const newStyleEl = document.createElement('style');\n newStyleEl.setAttribute(UI_ATTRIBUTES.STYLES, '');\n newStyleEl.textContent = stylesheet;\n\n if (styleTarget instanceof ShadowRoot) {\n styleTarget.insertBefore(newStyleEl, styleTarget.firstChild);\n } else {\n styleTarget.appendChild(newStyleEl);\n }\n\n styleEl = newStyleEl;\n\n return () => {\n if (styleEl?.parentNode) {\n styleEl.remove();\n }\n styleEl = null;\n styleTarget = null;\n };\n });\n\n $effect(() => {\n if (!plugin) return;\n\n return plugin.onStylesheetInvalidated(() => {\n if (styleEl) {\n styleEl.textContent = plugin.getStylesheet();\n }\n });\n });\n\n $effect(() => {\n if (!provides) return;\n\n disabledCategories = provides.getDisabledCategories();\n\n return provides.onCategoryChanged((event) => {\n disabledCategories = event.disabledCategories;\n });\n });\n\n const disabledCategoriesAttr = $derived(\n disabledCategories.length > 0 ? disabledCategories.join(' ') : undefined,\n );\n</script>\n\n<div\n bind:this={rootElement}\n {...restProps}\n {...{ [UI_ATTRIBUTES.ROOT]: '' }}\n {...disabledCategoriesAttr ? { [UI_ATTRIBUTES.DISABLED_CATEGORIES]: disabledCategoriesAttr } : {}}\n class={className}\n style:container-type=\"inline-size\"\n>\n {#if children}\n {@render children()}\n {/if}\n</div>\n","<script lang=\"ts\">\n import type { Component, Snippet } from 'svelte';\n import { provideAnchorRegistry } from './registries/anchor-registry.svelte';\n import { provideComponentRegistry } from './registries/component-registry.svelte';\n import { provideRenderers } from './registries/renderers-registry.svelte';\n import type { UIComponents, UIRenderers } from './types';\n import AutoMenuRenderer from './auto-menu-renderer.svelte';\n import UIRoot from './root.svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n\n /**\n * UIProvider Props\n */\n type ProviderProps = HTMLAttributes<HTMLDivElement> & {\n children: Snippet;\n\n /**\n * Document ID for this UI context\n * Required for menu rendering\n */\n documentId: string;\n\n /**\n * Custom component registry\n * Maps component IDs to components\n */\n components?: UIComponents;\n\n /**\n * REQUIRED: User-provided renderers\n * These define how toolbars, panels, and menus are displayed\n */\n renderers: UIRenderers;\n\n /**\n * Optional: Container for menu portal\n * Defaults to document.body\n */\n menuContainer?: HTMLElement | null;\n\n class?: string;\n };\n\n let {\n children,\n documentId,\n components = {},\n renderers,\n menuContainer = null,\n class: className,\n ...restProps\n }: ProviderProps = $props();\n\n /**\n * UIProvider - Single provider for all UI plugin functionality\n *\n * Manages:\n * - Anchor registry for menu positioning\n * - Component registry for custom components\n * - Renderers for toolbars, panels, and menus\n * - Automatic menu rendering\n *\n * @example\n * ```svelte\n * <EmbedPDF {engine} {plugins}>\n * {#snippet children({ pluginsReady, activeDocumentId })}\n * {#if pluginsReady && activeDocumentId}\n * <UIProvider\n * documentId={activeDocumentId}\n * components={{\n * 'thumbnail-panel': ThumbnailPanel,\n * 'bookmark-panel': BookmarkPanel,\n * }}\n * renderers={{\n * toolbar: ToolbarRenderer,\n * panel: PanelRenderer,\n * menu: MenuRenderer,\n * }}\n * >\n * {#snippet children()}\n * <ViewerLayout />\n * {/snippet}\n * </UIProvider>\n * {/if}\n * {/snippet}\n * </EmbedPDF>\n * ```\n */\n\n // Provide all registries\n provideAnchorRegistry();\n provideComponentRegistry(components);\n provideRenderers(renderers);\n</script>\n\n<UIRoot class={className} {...restProps}>\n {@render children()}\n <AutoMenuRenderer {documentId} container={menuContainer} />\n</UIRoot>\n","import { useComponentRegistry } from '../registries/component-registry.svelte';\n\n/**\n * Helper utilities for building renderers\n */\nexport function useItemRenderer() {\n const componentRegistry = useComponentRegistry();\n\n return {\n /**\n * Get a custom component by ID\n *\n * @param componentId - Component ID from schema\n * @returns Component constructor or undefined if not found\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * const { getCustomComponent } = useItemRenderer();\n * const MyComponent = getCustomComponent('my-component-id');\n * </script>\n *\n * {#if MyComponent}\n * <MyComponent {documentId} {...props} />\n * {/if}\n * ```\n */\n getCustomComponent: (componentId: string) => {\n const Component = componentRegistry.get(componentId);\n\n if (!Component) {\n console.error(`Component \"${componentId}\" not found in registry`);\n return undefined;\n }\n\n return Component;\n },\n };\n}\n","import { onDestroy } from 'svelte';\nimport { useAnchorRegistry } from '../registries/anchor-registry.svelte';\n\n/**\n * Register a DOM element as an anchor for menus\n *\n * @param getDocumentId - Function returning document ID\n * @param getItemId - Function returning item ID (typically matches the toolbar/menu item ID)\n * @returns Function to attach to the element via use:action\n *\n * @example\n *\n * <script lang=\"ts\">\n * const registerAnchor = useRegisterAnchor(() => documentId, () => 'zoom-button');\n * </script>\n *\n * <button use:registerAnchor>Zoom</button>\n * */\nexport function useRegisterAnchor(getDocumentId: () => string | null, getItemId: () => string) {\n const registry = useAnchorRegistry();\n let currentElement = $state<HTMLElement | null>(null);\n\n // Reactive values - these update when the functions return different values\n const documentId = $derived(getDocumentId());\n const itemId = $derived(getItemId());\n\n // Re-register anchor when documentId, itemId, or element changes\n $effect(() => {\n const docId = documentId;\n const item = itemId;\n const element = currentElement;\n\n // Only register if we have all required values\n if (element && docId && item) {\n registry.register(docId, item, element);\n\n // Cleanup: unregister when effect re-runs or component unmounts\n return () => {\n registry.unregister(docId, item);\n };\n }\n });\n\n // Svelte action function\n const action = (element: HTMLElement) => {\n currentElement = element;\n\n return {\n destroy() {\n // Clear the element reference when the action is destroyed\n currentElement = null;\n },\n };\n };\n\n return action;\n}\n","import { useUICapability } from './use-ui.svelte';\nimport { useRenderers } from '../registries/renderers-registry.svelte';\n\n/**\n * High-level hook for rendering UI from schema\n *\n * Provides information about active toolbars and panels by placement+slot.\n * Always includes isOpen state so renderers can control animations.\n *\n * Use with Svelte's component binding to render toolbars and panels.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * const { getToolbarInfo, getPanelInfo } = useSchemaRenderer(() => documentId);\n *\n * const topMainToolbar = $derived(getToolbarInfo('top', 'main'));\n * const leftMainPanel = $derived(getPanelInfo('left', 'main'));\n * </script>\n *\n * {#if topMainToolbar}\n * {@const ToolbarRenderer = topMainToolbar.renderer}\n * <ToolbarRenderer\n * schema={topMainToolbar.schema}\n * documentId={topMainToolbar.documentId}\n * isOpen={topMainToolbar.isOpen}\n * onClose={topMainToolbar.onClose}\n * />\n * {/if}\n * ```\n */\nexport function useSchemaRenderer(getDocumentId: () => string | null) {\n const renderers = useRenderers();\n const capability = useUICapability();\n const uiState = useUIState(getDocumentId);\n\n return {\n /**\n * Get toolbar information by placement and slot\n *\n * @param placement - 'top' | 'bottom' | 'left' | 'right'\n * @param slot - Slot name (e.g. 'main', 'secondary')\n * @returns Toolbar info or null if no toolbar in slot\n */\n getToolbarInfo: (placement: 'top' | 'bottom' | 'left' | 'right', slot: string) => {\n const schema = capability.provides?.getSchema();\n const documentId = getDocumentId();\n\n if (!schema || !uiState.provides || !uiState.state || !documentId) return null;\n\n const slotKey = `${placement}-${slot}`;\n const toolbarSlot = uiState.state.activeToolbars[slotKey];\n\n // If no toolbar in this slot, nothing to render\n if (!toolbarSlot) return null;\n\n const toolbarSchema = schema.toolbars[toolbarSlot.toolbarId];\n if (!toolbarSchema) {\n console.warn(`Toolbar \"${toolbarSlot.toolbarId}\" not found in schema`);\n return null;\n }\n\n // Check if toolbar is closable\n const isClosable = !toolbarSchema.permanent;\n\n const handleClose = isClosable\n ? () => {\n uiState.provides?.closeToolbarSlot(placement, slot);\n }\n : undefined;\n\n return {\n renderer: renderers.toolbar,\n schema: toolbarSchema,\n documentId,\n isOpen: toolbarSlot.isOpen,\n onClose: handleClose,\n };\n },\n\n /**\n * Get panel information by placement and slot\n *\n * @param placement - 'left' | 'right' | 'top' | 'bottom'\n * @param slot - Slot name (e.g. 'main', 'secondary', 'inspector')\n * @returns Panel info or null if no panel in slot\n */\n getPanelInfo: (placement: 'left' | 'right' | 'top' | 'bottom', slot: string) => {\n const schema = capability.provides?.getSchema();\n const documentId = getDocumentId();\n\n if (!schema || !uiState.provides || !uiState.state || !documentId) return null;\n\n const slotKey = `${placement}-${slot}`;\n const panelSlot = uiState.state.activePanels[slotKey];\n\n // If no panel in this slot, nothing to render\n if (!panelSlot) return null;\n\n const panelSchema = schema.panels[panelSlot.panelId];\n if (!panelSchema) {\n console.warn(`Panel \"${panelSlot.panelId}\" not found in schema`);\n return null;\n }\n\n const handleClose = () => {\n uiState.provides?.closePanelSlot(placement, slot);\n };\n\n return {\n renderer: renderers.panel,\n schema: panelSchema,\n documentId,\n isOpen: panelSlot.isOpen,\n onClose: handleClose,\n };\n },\n\n /**\n * Helper: Get all active toolbars for this document\n * Useful for batch rendering or debugging\n */\n getActiveToolbars: () => {\n if (!uiState.state) return [];\n return Object.entries(uiState.state.activeToolbars).map(([slotKey, toolbarSlot]) => {\n const [placement, slot] = slotKey.split('-');\n return {\n placement,\n slot,\n toolbarId: toolbarSlot.toolbarId,\n isOpen: toolbarSlot.isOpen,\n };\n });\n },\n\n /**\n * Helper: Get all active panels for this document\n * Useful for batch rendering or debugging\n */\n getActivePanels: () => {\n if (!uiState.state) return [];\n return Object.entries(uiState.state.activePanels).map(([slotKey, panelSlot]) => {\n const [placement, slot] = slotKey.split('-');\n return {\n placement,\n slot,\n panelId: panelSlot.panelId,\n isOpen: panelSlot.isOpen,\n };\n });\n },\n };\n}\n\n// Import after definition to avoid circular dependency\nimport { useUIState } from './use-ui.svelte';\n","import type {\n SelectionMenuPropsBase,\n SelectionMenuRenderFn,\n SelectionMenuRenderResult,\n} from '@embedpdf/utils/svelte';\nimport { useUICapability } from './use-ui.svelte';\nimport { useRenderers } from '../registries/renderers-registry.svelte';\n\n/**\n * Hook for schema-driven selection menus\n */\nexport function useSelectionMenu<TContext extends { type: string }>(\n menuId: string | (() => string),\n getDocumentId: () => string,\n) {\n const uiCapability = useUICapability();\n const renderers = useRenderers();\n\n // Normalize menuId to always be a function, then make it reactive\n const getMenuIdFn = typeof menuId === 'function' ? menuId : () => menuId;\n const menuIdValue = $derived(getMenuIdFn());\n const documentId = $derived(getDocumentId());\n const schema = $derived(uiCapability.provides?.getSchema());\n const menuSchema = $derived(schema?.selectionMenus?.[menuIdValue]);\n\n const renderFn = $derived.by<SelectionMenuRenderFn<TContext> | undefined>(() => {\n if (!menuSchema) return undefined;\n\n const currentMenuSchema = menuSchema;\n const currentDocumentId = documentId;\n const SelectionMenuRenderer = renderers.selectionMenu;\n\n return (props: SelectionMenuPropsBase<TContext>): SelectionMenuRenderResult | null => {\n if (!props.selected) return null;\n\n return {\n component: SelectionMenuRenderer,\n props: {\n schema: currentMenuSchema,\n documentId: currentDocumentId,\n props,\n },\n };\n };\n });\n\n return {\n get renderFn() {\n return renderFn;\n },\n };\n}\n"],"names":["useUIPlugin","usePlugin","UIPlugin","id","useUICapability","useCapability","useUIState","getDocumentId","capability","state","documentId","scopedProvides","$","derived","provides","forDocument","user_effect","docId","set","scope","getState","unsubToolbar","onToolbarChanged","unsubPanel","onPanelChanged","unsubModal","onModalChanged","unsubMenu","onMenuChanged","ANCHOR_REGISTRY_KEY","Symbol","createAnchorRegistry","anchors","Map","register","itemId","element","key","unregister","delete","getAnchor","get","provideAnchorRegistry","registry","setContext","useAnchorRegistry","getContext","Error","COMPONENT_REGISTRY_KEY","createComponentRegistry","initialComponents","components","Object","entries","component","has","getRegisteredIds","Array","from","keys","provideComponentRegistry","useComponentRegistry","RENDERERS_KEY","provideRenderers","renderers","useRenderers","container","uiState","$$props","anchorRegistry","activeMenu","openMenus","_a","openMenuIds","length","menuId","menuState","triggeredByItemId","anchorEl","schema","getSchema","menuSchema","menuSchemaValue","menus","console","warn","handleClose","closeMenu","MenuRenderer","menu","$$render","consequent","restProps","rest_props","plugin","disabledCategories","proxy","rootElement","styleEl","styleTarget","root","getRootNode","ShadowRoot","document","head","getStyleTarget","existingStyle","querySelector","UI_SELECTORS","STYLES","textContent","getStylesheet","stylesheet","newStyleEl","createElement","setAttribute","UI_ATTRIBUTES","insertBefore","firstChild","appendChild","parentNode","remove","onStylesheetInvalidated","getDisabledCategories","onCategoryChanged","event","disabledCategoriesAttr","join","ROOT","DISABLED_CATEGORIES","bind_this","div","$$value","prop","menuContainer","componentRegistry","getCustomComponent","componentId","Component","error","getItemId","currentElement","item","destroy","getToolbarInfo","placement","slot","slotKey","toolbarSlot","activeToolbars","toolbarSchema","toolbars","toolbarId","permanent","closeToolbarSlot","renderer","toolbar","isOpen","onClose","getPanelInfo","panelSlot","activePanels","panelSchema","panels","panelId","panel","closePanelSlot","getActiveToolbars","map","split","getActivePanels","uiCapability","getMenuIdFn","menuIdValue","selectionMenus","renderFn","currentMenuSchema","currentDocumentId","SelectionMenuRenderer","selectionMenu","props","selected"],"mappings":"shBAMaA,EAAA,IAAoBC,YAAoBC,EAAAA,SAASC,IAKjDC,EAAA,IAAwBC,gBAAwBH,EAAAA,SAASC,IAYzDG,EAAcC,IACnB,MAAAC,EAAaJ,IAEf,IAAAK,UAAuC,MAGrC,MAAAC,YAAsBH,GAGtBI,EAAAC,EAAAC,QAAA,IACJL,EAAWM,gBAAYJ,GAAaF,EAAWM,SAASC,kBAAYL,IAAc,aAGpFE,EAAAI,uBACQF,EAAWN,EAAWM,SACtBG,QAAQP,OAETI,IAAaG,cAChBL,EAAAM,IAAAT,EAAQ,MAIJ,MAAAU,EAAQL,EAASC,YAAYE,SAGnCR,EAAQU,EAAMC,YAAA,GAGR,MAAAC,EAAeF,EAAMG,4BACzBb,EAAQU,EAAMC,YAAA,KAEVG,EAAaJ,EAAMK,0BACvBf,EAAQU,EAAMC,YAAA,KAEVK,EAAaN,EAAMO,0BACvBjB,EAAQU,EAAMC,YAAA,KAEVO,EAAYR,EAAMS,yBACtBnB,EAAQU,EAAMC,YAAA,gBAIdC,IACAE,IACAE,IACAE,QAKE,YAAAb,gBACKH,EACT,EACI,SAAAF,gBACKA,EACT,IChEEoB,EAAsBC,OAAO,kBAEnB,SAAAC,IACR,MAAAC,MAAcC,WAGlB,QAAAC,CAASxB,EAAoByB,EAAgBC,SACrCC,EAAA,GAAS3B,KAAcyB,IAC7BH,EAAQd,IAAImB,EAAKD,EACnB,EAEA,UAAAE,CAAW5B,EAAoByB,SACvBE,EAAA,GAAS3B,KAAcyB,IAC7BH,EAAQO,OAAOF,EACjB,EAEA,SAAAG,CAAU9B,EAAoByB,SACtBE,EAAA,GAAS3B,KAAcyB,IACtB,OAAAH,EAAQS,IAAI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b,UAAA2E,SACK,OAAA,OAAAP,EAAAhE,EAAWM,eAAX,EAAA0D,EAAqBQ,cAAe,IAC7C"}
@@ -0,0 +1,6 @@
1
+ export * from '../lib';
2
+ export * from './hooks';
3
+ export * from './registries';
4
+ export * from './types';
5
+ export { default as UIProvider } from './provider.svelte';
6
+ export { default as AutoMenuRenderer } from './auto-menu-renderer.svelte';
@@ -0,0 +1,553 @@
1
+ import { UIPlugin, UI_SELECTORS, UI_ATTRIBUTES } from "@embedpdf/plugin-ui";
2
+ export * from "@embedpdf/plugin-ui";
3
+ import * as $ from "svelte/internal/client";
4
+ import { usePlugin, useCapability } from "@embedpdf/core/svelte";
5
+ import { setContext, getContext } from "svelte";
6
+ import "svelte/internal/disclose-version";
7
+ const useUIPlugin = () => usePlugin(UIPlugin.id);
8
+ const useUICapability = () => useCapability(UIPlugin.id);
9
+ const useUIState = (getDocumentId) => {
10
+ const capability = useUICapability();
11
+ let state = $.state(null);
12
+ const documentId = $.derived(getDocumentId);
13
+ const scopedProvides = $.derived(() => capability.provides && $.get(documentId) ? capability.provides.forDocument($.get(documentId)) : null);
14
+ $.user_effect(() => {
15
+ const provides = capability.provides;
16
+ const docId = $.get(documentId);
17
+ if (!provides || !docId) {
18
+ $.set(state, null);
19
+ return;
20
+ }
21
+ const scope = provides.forDocument(docId);
22
+ $.set(state, scope.getState(), true);
23
+ const unsubToolbar = scope.onToolbarChanged(() => {
24
+ $.set(state, scope.getState(), true);
25
+ });
26
+ const unsubPanel = scope.onPanelChanged(() => {
27
+ $.set(state, scope.getState(), true);
28
+ });
29
+ const unsubModal = scope.onModalChanged(() => {
30
+ $.set(state, scope.getState(), true);
31
+ });
32
+ const unsubMenu = scope.onMenuChanged(() => {
33
+ $.set(state, scope.getState(), true);
34
+ });
35
+ return () => {
36
+ unsubToolbar();
37
+ unsubPanel();
38
+ unsubModal();
39
+ unsubMenu();
40
+ };
41
+ });
42
+ return {
43
+ get provides() {
44
+ return $.get(scopedProvides);
45
+ },
46
+ get state() {
47
+ return $.get(state);
48
+ }
49
+ };
50
+ };
51
+ const useUISchema = () => {
52
+ const capability = useUICapability();
53
+ return {
54
+ get schema() {
55
+ var _a;
56
+ return ((_a = capability.provides) == null ? void 0 : _a.getSchema()) ?? null;
57
+ }
58
+ };
59
+ };
60
+ const ANCHOR_REGISTRY_KEY = Symbol("AnchorRegistry");
61
+ function createAnchorRegistry() {
62
+ const anchors = /* @__PURE__ */ new Map();
63
+ return {
64
+ register(documentId, itemId, element) {
65
+ const key = `${documentId}:${itemId}`;
66
+ anchors.set(key, element);
67
+ },
68
+ unregister(documentId, itemId) {
69
+ const key = `${documentId}:${itemId}`;
70
+ anchors.delete(key);
71
+ },
72
+ getAnchor(documentId, itemId) {
73
+ const key = `${documentId}:${itemId}`;
74
+ return anchors.get(key) || null;
75
+ }
76
+ };
77
+ }
78
+ function provideAnchorRegistry() {
79
+ const registry = createAnchorRegistry();
80
+ setContext(ANCHOR_REGISTRY_KEY, registry);
81
+ return registry;
82
+ }
83
+ function useAnchorRegistry() {
84
+ const registry = getContext(ANCHOR_REGISTRY_KEY);
85
+ if (!registry) {
86
+ throw new Error("useAnchorRegistry must be used within UIProvider");
87
+ }
88
+ return registry;
89
+ }
90
+ function useRegisterAnchor(getDocumentId, getItemId) {
91
+ const registry = useAnchorRegistry();
92
+ let currentElement = $.state(null);
93
+ const documentId = $.derived(getDocumentId);
94
+ const itemId = $.derived(getItemId);
95
+ $.user_effect(() => {
96
+ const docId = $.get(documentId);
97
+ const item = $.get(itemId);
98
+ const element = $.get(currentElement);
99
+ if (element && docId && item) {
100
+ registry.register(docId, item, element);
101
+ return () => {
102
+ registry.unregister(docId, item);
103
+ };
104
+ }
105
+ });
106
+ const action = (element) => {
107
+ $.set(currentElement, element, true);
108
+ return {
109
+ destroy() {
110
+ $.set(currentElement, null);
111
+ }
112
+ };
113
+ };
114
+ return action;
115
+ }
116
+ const COMPONENT_REGISTRY_KEY = Symbol("ComponentRegistry");
117
+ function createComponentRegistry(initialComponents = {}) {
118
+ const components = new Map(Object.entries(initialComponents));
119
+ return {
120
+ register(id, component) {
121
+ components.set(id, component);
122
+ },
123
+ unregister(id) {
124
+ components.delete(id);
125
+ },
126
+ get(id) {
127
+ return components.get(id);
128
+ },
129
+ has(id) {
130
+ return components.has(id);
131
+ },
132
+ getRegisteredIds() {
133
+ return Array.from(components.keys());
134
+ }
135
+ };
136
+ }
137
+ function provideComponentRegistry(initialComponents = {}) {
138
+ const registry = createComponentRegistry(initialComponents);
139
+ setContext(COMPONENT_REGISTRY_KEY, registry);
140
+ return registry;
141
+ }
142
+ function useComponentRegistry() {
143
+ const registry = getContext(COMPONENT_REGISTRY_KEY);
144
+ if (!registry) {
145
+ throw new Error("useComponentRegistry must be used within UIProvider");
146
+ }
147
+ return registry;
148
+ }
149
+ function useItemRenderer() {
150
+ const componentRegistry = useComponentRegistry();
151
+ return {
152
+ /**
153
+ * Get a custom component by ID
154
+ *
155
+ * @param componentId - Component ID from schema
156
+ * @returns Component constructor or undefined if not found
157
+ *
158
+ * @example
159
+ * ```svelte
160
+ * <script lang="ts">
161
+ * const { getCustomComponent } = useItemRenderer();
162
+ * const MyComponent = getCustomComponent('my-component-id');
163
+ * <\/script>
164
+ *
165
+ * {#if MyComponent}
166
+ * <MyComponent {documentId} {...props} />
167
+ * {/if}
168
+ * ```
169
+ */
170
+ getCustomComponent: (componentId) => {
171
+ const Component = componentRegistry.get(componentId);
172
+ if (!Component) {
173
+ console.error(`Component "${componentId}" not found in registry`);
174
+ return void 0;
175
+ }
176
+ return Component;
177
+ }
178
+ };
179
+ }
180
+ const RENDERERS_KEY = Symbol("Renderers");
181
+ function provideRenderers(renderers) {
182
+ setContext(RENDERERS_KEY, renderers);
183
+ }
184
+ function useRenderers() {
185
+ const renderers = getContext(RENDERERS_KEY);
186
+ if (!renderers) {
187
+ throw new Error("useRenderers must be used within UIProvider");
188
+ }
189
+ return renderers;
190
+ }
191
+ function useSchemaRenderer(getDocumentId) {
192
+ const renderers = useRenderers();
193
+ const capability = useUICapability();
194
+ const uiState = useUIState(getDocumentId);
195
+ return {
196
+ /**
197
+ * Get toolbar information by placement and slot
198
+ *
199
+ * @param placement - 'top' | 'bottom' | 'left' | 'right'
200
+ * @param slot - Slot name (e.g. 'main', 'secondary')
201
+ * @returns Toolbar info or null if no toolbar in slot
202
+ */
203
+ getToolbarInfo: (placement, slot) => {
204
+ var _a;
205
+ const schema = (_a = capability.provides) == null ? void 0 : _a.getSchema();
206
+ const documentId = getDocumentId();
207
+ if (!schema || !uiState.provides || !uiState.state || !documentId) return null;
208
+ const slotKey = `${placement}-${slot}`;
209
+ const toolbarSlot = uiState.state.activeToolbars[slotKey];
210
+ if (!toolbarSlot) return null;
211
+ const toolbarSchema = schema.toolbars[toolbarSlot.toolbarId];
212
+ if (!toolbarSchema) {
213
+ console.warn(`Toolbar "${toolbarSlot.toolbarId}" not found in schema`);
214
+ return null;
215
+ }
216
+ const isClosable = !toolbarSchema.permanent;
217
+ const handleClose = isClosable ? () => {
218
+ var _a2;
219
+ (_a2 = uiState.provides) == null ? void 0 : _a2.closeToolbarSlot(placement, slot);
220
+ } : void 0;
221
+ return {
222
+ renderer: renderers.toolbar,
223
+ schema: toolbarSchema,
224
+ documentId,
225
+ isOpen: toolbarSlot.isOpen,
226
+ onClose: handleClose
227
+ };
228
+ },
229
+ /**
230
+ * Get panel information by placement and slot
231
+ *
232
+ * @param placement - 'left' | 'right' | 'top' | 'bottom'
233
+ * @param slot - Slot name (e.g. 'main', 'secondary', 'inspector')
234
+ * @returns Panel info or null if no panel in slot
235
+ */
236
+ getPanelInfo: (placement, slot) => {
237
+ var _a;
238
+ const schema = (_a = capability.provides) == null ? void 0 : _a.getSchema();
239
+ const documentId = getDocumentId();
240
+ if (!schema || !uiState.provides || !uiState.state || !documentId) return null;
241
+ const slotKey = `${placement}-${slot}`;
242
+ const panelSlot = uiState.state.activePanels[slotKey];
243
+ if (!panelSlot) return null;
244
+ const panelSchema = schema.panels[panelSlot.panelId];
245
+ if (!panelSchema) {
246
+ console.warn(`Panel "${panelSlot.panelId}" not found in schema`);
247
+ return null;
248
+ }
249
+ const handleClose = () => {
250
+ var _a2;
251
+ (_a2 = uiState.provides) == null ? void 0 : _a2.closePanelSlot(placement, slot);
252
+ };
253
+ return {
254
+ renderer: renderers.panel,
255
+ schema: panelSchema,
256
+ documentId,
257
+ isOpen: panelSlot.isOpen,
258
+ onClose: handleClose
259
+ };
260
+ },
261
+ /**
262
+ * Helper: Get all active toolbars for this document
263
+ * Useful for batch rendering or debugging
264
+ */
265
+ getActiveToolbars: () => {
266
+ if (!uiState.state) return [];
267
+ return Object.entries(uiState.state.activeToolbars).map(([slotKey, toolbarSlot]) => {
268
+ const [placement, slot] = slotKey.split("-");
269
+ return {
270
+ placement,
271
+ slot,
272
+ toolbarId: toolbarSlot.toolbarId,
273
+ isOpen: toolbarSlot.isOpen
274
+ };
275
+ });
276
+ },
277
+ /**
278
+ * Helper: Get all active panels for this document
279
+ * Useful for batch rendering or debugging
280
+ */
281
+ getActivePanels: () => {
282
+ if (!uiState.state) return [];
283
+ return Object.entries(uiState.state.activePanels).map(([slotKey, panelSlot]) => {
284
+ const [placement, slot] = slotKey.split("-");
285
+ return {
286
+ placement,
287
+ slot,
288
+ panelId: panelSlot.panelId,
289
+ isOpen: panelSlot.isOpen
290
+ };
291
+ });
292
+ }
293
+ };
294
+ }
295
+ function useSelectionMenu(menuId, getDocumentId) {
296
+ const uiCapability = useUICapability();
297
+ const renderers = useRenderers();
298
+ const getMenuIdFn = typeof menuId === "function" ? menuId : () => menuId;
299
+ const menuIdValue = $.derived(getMenuIdFn);
300
+ const documentId = $.derived(getDocumentId);
301
+ const schema = $.derived(() => {
302
+ var _a;
303
+ return (_a = uiCapability.provides) == null ? void 0 : _a.getSchema();
304
+ });
305
+ const menuSchema = $.derived(() => {
306
+ var _a, _b;
307
+ return (_b = (_a = $.get(schema)) == null ? void 0 : _a.selectionMenus) == null ? void 0 : _b[$.get(menuIdValue)];
308
+ });
309
+ const renderFn = $.derived(() => {
310
+ if (!$.get(menuSchema)) return void 0;
311
+ const currentMenuSchema = $.get(menuSchema);
312
+ const currentDocumentId = $.get(documentId);
313
+ const SelectionMenuRenderer = renderers.selectionMenu;
314
+ return (props) => {
315
+ if (!props.selected) return null;
316
+ return {
317
+ component: SelectionMenuRenderer,
318
+ props: {
319
+ schema: currentMenuSchema,
320
+ documentId: currentDocumentId,
321
+ props
322
+ }
323
+ };
324
+ };
325
+ });
326
+ return {
327
+ get renderFn() {
328
+ return $.get(renderFn);
329
+ }
330
+ };
331
+ }
332
+ function Auto_menu_renderer($$anchor, $$props) {
333
+ $.push($$props, true);
334
+ let container = $.prop($$props, "container", 3, null);
335
+ const uiState = useUIState(() => $$props.documentId);
336
+ const capability = useUICapability();
337
+ const anchorRegistry = useAnchorRegistry();
338
+ const renderers = useRenderers();
339
+ const activeMenu = $.derived(() => {
340
+ var _a;
341
+ const openMenus = ((_a = uiState.state) == null ? void 0 : _a.openMenus) || {};
342
+ const openMenuIds = Object.keys(openMenus);
343
+ if (openMenuIds.length === 0) return null;
344
+ const menuId = openMenuIds[0];
345
+ if (!menuId) return null;
346
+ const menuState = openMenus[menuId];
347
+ if (!menuState || !menuState.triggeredByItemId) return null;
348
+ const anchor = anchorRegistry.getAnchor($$props.documentId, menuState.triggeredByItemId);
349
+ return { menuId, anchorEl: anchor };
350
+ });
351
+ const schema = $.derived(() => {
352
+ var _a;
353
+ return (_a = capability.provides) == null ? void 0 : _a.getSchema();
354
+ });
355
+ const menuSchema = $.derived(() => {
356
+ if (!$.get(activeMenu) || !$.get(schema)) return null;
357
+ const menuSchemaValue = $.get(schema).menus[$.get(activeMenu).menuId];
358
+ if (!menuSchemaValue) {
359
+ console.warn(`Menu "${$.get(activeMenu).menuId}" not found in schema`);
360
+ return null;
361
+ }
362
+ return menuSchemaValue;
363
+ });
364
+ const handleClose = () => {
365
+ var _a;
366
+ if ($.get(activeMenu)) {
367
+ (_a = uiState.provides) == null ? void 0 : _a.closeMenu($.get(activeMenu).menuId);
368
+ }
369
+ };
370
+ const MenuRenderer = renderers.menu;
371
+ var fragment = $.comment();
372
+ var node = $.first_child(fragment);
373
+ {
374
+ var consequent = ($$anchor2) => {
375
+ MenuRenderer($$anchor2, {
376
+ get schema() {
377
+ return $.get(menuSchema);
378
+ },
379
+ get documentId() {
380
+ return $$props.documentId;
381
+ },
382
+ get anchorEl() {
383
+ return $.get(activeMenu).anchorEl;
384
+ },
385
+ onClose: handleClose,
386
+ get container() {
387
+ return container();
388
+ }
389
+ });
390
+ };
391
+ $.if(node, ($$render) => {
392
+ if ($.get(activeMenu) && $.get(menuSchema) && MenuRenderer) $$render(consequent);
393
+ });
394
+ }
395
+ $.append($$anchor, fragment);
396
+ $.pop();
397
+ }
398
+ var root_1$1 = $.from_html(`<div><!></div>`);
399
+ function Root($$anchor, $$props) {
400
+ $.push($$props, true);
401
+ let restProps = $.rest_props($$props, ["$$slots", "$$events", "$$legacy", "children", "class"]);
402
+ const { plugin } = useUIPlugin();
403
+ const { provides } = useUICapability();
404
+ let disabledCategories = $.state($.proxy([]));
405
+ let rootElement = $.state(null);
406
+ let styleEl = null;
407
+ let styleTarget = null;
408
+ function getStyleTarget(element) {
409
+ const root = element.getRootNode();
410
+ if (root instanceof ShadowRoot) {
411
+ return root;
412
+ }
413
+ return document.head;
414
+ }
415
+ $.user_effect(() => {
416
+ if (!$.get(rootElement) || !plugin) {
417
+ styleTarget = null;
418
+ return;
419
+ }
420
+ styleTarget = getStyleTarget($.get(rootElement));
421
+ const existingStyle = styleTarget.querySelector(UI_SELECTORS.STYLES);
422
+ if (existingStyle) {
423
+ styleEl = existingStyle;
424
+ existingStyle.textContent = plugin.getStylesheet();
425
+ return;
426
+ }
427
+ const stylesheet = plugin.getStylesheet();
428
+ const newStyleEl = document.createElement("style");
429
+ newStyleEl.setAttribute(UI_ATTRIBUTES.STYLES, "");
430
+ newStyleEl.textContent = stylesheet;
431
+ if (styleTarget instanceof ShadowRoot) {
432
+ styleTarget.insertBefore(newStyleEl, styleTarget.firstChild);
433
+ } else {
434
+ styleTarget.appendChild(newStyleEl);
435
+ }
436
+ styleEl = newStyleEl;
437
+ return () => {
438
+ if (styleEl == null ? void 0 : styleEl.parentNode) {
439
+ styleEl.remove();
440
+ }
441
+ styleEl = null;
442
+ styleTarget = null;
443
+ };
444
+ });
445
+ $.user_effect(() => {
446
+ if (!plugin) return;
447
+ return plugin.onStylesheetInvalidated(() => {
448
+ if (styleEl) {
449
+ styleEl.textContent = plugin.getStylesheet();
450
+ }
451
+ });
452
+ });
453
+ $.user_effect(() => {
454
+ if (!provides) return;
455
+ $.set(disabledCategories, provides.getDisabledCategories(), true);
456
+ return provides.onCategoryChanged((event) => {
457
+ $.set(disabledCategories, event.disabledCategories, true);
458
+ });
459
+ });
460
+ const disabledCategoriesAttr = $.derived(() => $.get(disabledCategories).length > 0 ? $.get(disabledCategories).join(" ") : void 0);
461
+ var div = root_1$1();
462
+ $.attribute_effect(div, () => ({
463
+ ...restProps,
464
+ ...{ [UI_ATTRIBUTES.ROOT]: "" },
465
+ ...$.get(disabledCategoriesAttr) ? {
466
+ [UI_ATTRIBUTES.DISABLED_CATEGORIES]: $.get(disabledCategoriesAttr)
467
+ } : {},
468
+ class: $$props.class,
469
+ [$.STYLE]: { "container-type": "inline-size" }
470
+ }));
471
+ var node = $.child(div);
472
+ {
473
+ var consequent = ($$anchor2) => {
474
+ var fragment = $.comment();
475
+ var node_1 = $.first_child(fragment);
476
+ $.snippet(node_1, () => $$props.children);
477
+ $.append($$anchor2, fragment);
478
+ };
479
+ $.if(node, ($$render) => {
480
+ if ($$props.children) $$render(consequent);
481
+ });
482
+ }
483
+ $.reset(div);
484
+ $.bind_this(div, ($$value) => $.set(rootElement, $$value), () => $.get(rootElement));
485
+ $.append($$anchor, div);
486
+ $.pop();
487
+ }
488
+ var root_1 = $.from_html(`<!> <!>`, 1);
489
+ function Provider($$anchor, $$props) {
490
+ $.push($$props, true);
491
+ let components = $.prop($$props, "components", 19, () => ({})), menuContainer = $.prop($$props, "menuContainer", 3, null), restProps = $.rest_props($$props, [
492
+ "$$slots",
493
+ "$$events",
494
+ "$$legacy",
495
+ "children",
496
+ "documentId",
497
+ "components",
498
+ "renderers",
499
+ "menuContainer",
500
+ "class"
501
+ ]);
502
+ provideAnchorRegistry();
503
+ provideComponentRegistry(components());
504
+ provideRenderers($$props.renderers);
505
+ Root($$anchor, $.spread_props(
506
+ {
507
+ get class() {
508
+ return $$props.class;
509
+ }
510
+ },
511
+ () => restProps,
512
+ {
513
+ children: ($$anchor2, $$slotProps) => {
514
+ var fragment_1 = root_1();
515
+ var node = $.first_child(fragment_1);
516
+ $.snippet(node, () => $$props.children);
517
+ var node_1 = $.sibling(node, 2);
518
+ Auto_menu_renderer(node_1, {
519
+ get documentId() {
520
+ return $$props.documentId;
521
+ },
522
+ get container() {
523
+ return menuContainer();
524
+ }
525
+ });
526
+ $.append($$anchor2, fragment_1);
527
+ },
528
+ $$slots: { default: true }
529
+ }
530
+ ));
531
+ $.pop();
532
+ }
533
+ export {
534
+ Auto_menu_renderer as AutoMenuRenderer,
535
+ Provider as UIProvider,
536
+ createAnchorRegistry,
537
+ createComponentRegistry,
538
+ provideAnchorRegistry,
539
+ provideComponentRegistry,
540
+ provideRenderers,
541
+ useAnchorRegistry,
542
+ useComponentRegistry,
543
+ useItemRenderer,
544
+ useRegisterAnchor,
545
+ useRenderers,
546
+ useSchemaRenderer,
547
+ useSelectionMenu,
548
+ useUICapability,
549
+ useUIPlugin,
550
+ useUISchema,
551
+ useUIState
552
+ };
553
+ //# sourceMappingURL=index.js.map