@embedpdf/plugin-ui 2.0.0-next.1 → 2.0.0-next.3

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 (56) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +235 -146
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +31 -15
  6. package/dist/lib/schema.d.ts +51 -10
  7. package/dist/lib/selectors.d.ts +5 -5
  8. package/dist/lib/types.d.ts +39 -23
  9. package/dist/lib/ui-plugin.d.ts +11 -8
  10. package/dist/lib/utils/consts.d.ts +3 -0
  11. package/dist/lib/utils/schema-merger.d.ts +1 -1
  12. package/dist/lib/utils/stylesheet-generator.d.ts +17 -0
  13. package/dist/preact/adapter.d.ts +1 -1
  14. package/dist/preact/index.cjs +1 -1
  15. package/dist/preact/index.cjs.map +1 -1
  16. package/dist/preact/index.js +143 -38
  17. package/dist/preact/index.js.map +1 -1
  18. package/dist/react/adapter.d.ts +1 -1
  19. package/dist/react/index.cjs +1 -1
  20. package/dist/react/index.cjs.map +1 -1
  21. package/dist/react/index.js +143 -38
  22. package/dist/react/index.js.map +1 -1
  23. package/dist/shared/hooks/index.d.ts +1 -0
  24. package/dist/shared/hooks/use-schema-renderer.d.ts +41 -9
  25. package/dist/shared/hooks/use-ui-container.d.ts +39 -0
  26. package/dist/shared/root.d.ts +1 -1
  27. package/dist/shared/types.d.ts +31 -6
  28. package/dist/shared-preact/hooks/index.d.ts +1 -0
  29. package/dist/shared-preact/hooks/use-schema-renderer.d.ts +41 -9
  30. package/dist/shared-preact/hooks/use-ui-container.d.ts +39 -0
  31. package/dist/shared-preact/root.d.ts +1 -1
  32. package/dist/shared-preact/types.d.ts +31 -6
  33. package/dist/shared-react/hooks/index.d.ts +1 -0
  34. package/dist/shared-react/hooks/use-schema-renderer.d.ts +41 -9
  35. package/dist/shared-react/hooks/use-ui-container.d.ts +39 -0
  36. package/dist/shared-react/root.d.ts +1 -1
  37. package/dist/shared-react/types.d.ts +31 -6
  38. package/dist/svelte/hooks/index.d.ts +1 -0
  39. package/dist/svelte/hooks/use-schema-renderer.svelte.d.ts +55 -12
  40. package/dist/svelte/hooks/use-ui-container.svelte.d.ts +41 -0
  41. package/dist/svelte/hooks/use-ui.svelte.d.ts +2 -2
  42. package/dist/svelte/index.cjs +1 -1
  43. package/dist/svelte/index.cjs.map +1 -1
  44. package/dist/svelte/index.js +112 -20
  45. package/dist/svelte/index.js.map +1 -1
  46. package/dist/svelte/types.d.ts +31 -6
  47. package/dist/vue/hooks/index.d.ts +1 -0
  48. package/dist/vue/hooks/use-schema-renderer.d.ts +41 -9
  49. package/dist/vue/hooks/use-ui-container.d.ts +39 -0
  50. package/dist/vue/hooks/use-ui.d.ts +148 -20
  51. package/dist/vue/index.cjs +1 -1
  52. package/dist/vue/index.cjs.map +1 -1
  53. package/dist/vue/index.js +126 -25
  54. package/dist/vue/index.js.map +1 -1
  55. package/dist/vue/types.d.ts +31 -6
  56. package/package.json +12 -12
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t="ui",n={id:t,name:"UI Plugin",version:"1.0.0",provides:["ui"],requires:["commands"],optional:["i18n"],defaultConfig:{enabled:!0,schema:{id:"empty",version:"1.0.0",toolbars:{},menus:{},panels:{},selectionMenus:{}}}},o="UI/INIT_STATE",s="UI/CLEANUP_STATE",i="UI/SET_ACTIVE_TOOLBAR",a="UI/CLOSE_TOOLBAR_SLOT",c="UI/SET_ACTIVE_PANEL",r="UI/CLOSE_PANEL_SLOT",l="UI/SET_PANEL_TAB",d="UI/OPEN_MODAL",u="UI/CLOSE_MODAL",h="UI/OPEN_MENU",m="UI/CLOSE_MENU",p="UI/CLOSE_ALL_MENUS",g="UI/SET_DISABLED_CATEGORIES",I=(e,t)=>({type:o,payload:{documentId:e,schema:t}}),f=e=>({type:s,payload:{documentId:e}}),b=(e,t,n,o)=>({type:i,payload:{documentId:e,placement:t,slot:n,toolbarId:o}}),y=(e,t,n)=>({type:a,payload:{documentId:e,placement:t,slot:n}}),v=(e,t,n,o,s)=>({type:c,payload:{documentId:e,placement:t,slot:n,panelId:o,activeTab:s}}),C=(e,t,n)=>({type:r,payload:{documentId:e,placement:t,slot:n}}),O=(e,t,n)=>({type:l,payload:{documentId:e,panelId:t,tabId:n}}),S=(e,t)=>({type:d,payload:{documentId:e,modalId:t}}),T=e=>({type:u,payload:{documentId:e}}),D=(e,t)=>({type:h,payload:{documentId:e,menuState:t}}),E=(e,t)=>({type:m,payload:{documentId:e,menuId:t}}),$=e=>({type:p,payload:{documentId:e}}),A=e=>({type:g,payload:{categories:e}});function M(e,t){return{...e,...t,toolbars:x(e.toolbars,t.toolbars),menus:L(e.menus,t.menus),panels:P(e.panels,t.panels)}}function x(e,t){if(!t)return e;const n={...e};for(const[o,s]of Object.entries(t))n[o]?n[o]={...n[o],...s,items:s.items??n[o].items,responsive:s.responsive??n[o].responsive}:n[o]=s;return n}function L(e,t){if(!t)return e;const n={...e};for(const[o,s]of Object.entries(t))n[o]?n[o]={...n[o],...s,items:s.items??n[o].items}:n[o]=s;return n}function P(e,t){if(!t)return e;const n={...e};for(const[o,s]of Object.entries(t))n[o]?n[o]={...n[o],...s,content:s.content??n[o].content}:n[o]=s;return n}function _(e,t){var n;if(!(null==(n=e.responsive)?void 0:n.breakpoints))return null;const o=function(e,t,n){if(!n||!(null==t?void 0:t.groups))return e;const o=t.groups.find(e=>e.locales.includes(n));if(!o)return e;const s={};for(const[i,a]of Object.entries(e)){const e=o.breakpoints[i];e?s[i]={minWidth:a.minWidth,maxWidth:a.maxWidth,hide:e.replaceHide?e.replaceHide:[...a.hide||[],...e.hide||[]],show:e.replaceShow?e.replaceShow:[...a.show||[],...e.show||[]]}:s[i]=a}return s}(e.responsive.breakpoints,e.responsive.localeOverrides,t),s=new Map,i=new Map;for(const[r,l]of Object.entries(o))i.set(r,{minWidth:l.minWidth,maxWidth:l.maxWidth});const a=new Set,c=e=>{e.forEach(e=>{a.add(e.id),"group"===e.type&&e.items&&c(e.items),"tab-group"===e.type&&e.tabs&&c(e.tabs),"section"===e.type&&e.items&&c(e.items)})};c(e.items);for(const r of a){const e=[];let t=!0;Array.from(Object.entries(o)).sort((e,t)=>(e[1].minWidth??0)-(t[1].minWidth??0)).forEach(([n,o],s)=>{var i,a;const c=null==(i=o.hide)?void 0:i.includes(r),l=null==(a=o.show)?void 0:a.includes(r);(c||l)&&(e.push({breakpointId:n,minWidth:o.minWidth,maxWidth:o.maxWidth,visible:l||!c,priority:s}),0===s&&(t=l||!c))}),e.length>0&&s.set(r,{itemId:r,shouldRender:!0,visibilityRules:e,defaultVisible:t})}return{items:s,breakpoints:i}}const F={ROOT:"data-epdf",STYLES:"data-epdf-s",ITEM:"data-epdf-i",CATEGORIES:"data-epdf-cat",DISABLED_CATEGORIES:"data-epdf-dis"},U={ROOT:`[${F.ROOT}]`,STYLES:`[${F.STYLES}]`,ITEM:e=>`[${F.ITEM}="${e}"]`,CATEGORIES:e=>`[${F.CATEGORIES}~="${e}"]`,DISABLED_CATEGORY:e=>`[${F.DISABLED_CATEGORIES}~="${e}"]`},w={useContainerQueries:!0};function R(e,t={}){const n={...w,...t.config},o=t.locale,s=W(e,o),i=[];i.push(function(e){const t=e?` (locale: ${e})`:"";return`/* ═══════════════════════════════════════════════════════════════════════════ */\n/* EmbedPDF UI Stylesheet - Auto-generated${t} */\n/* DO NOT EDIT MANUALLY - This file is generated from your UI schema */\n/* ═══════════════════════════════════════════════════════════════════════════ */`}(o));const a=function(e,t){const n=[],o=t.useContainerQueries?"@container":"@media",s=new Set;return e.responsiveItems.forEach((e,t)=>{if(s.has(t))return;s.add(t);const i=function(e,t,n){if(0===t.visibilityRules.length)return null;const o=[],s=U.ITEM(e);t.defaultVisible||o.push(`${s} { display: none; }`);for(const i of t.visibilityRules){const e=[];if(void 0!==i.minWidth&&e.push(`(min-width: ${i.minWidth}px)`),void 0!==i.maxWidth&&e.push(`(max-width: ${i.maxWidth}px)`),e.length>0){const t=i.visible?"flex":"none";o.push(`${n} ${e.join(" and ")} {\n ${s} { display: ${t}; }\n}`)}}return o.length>0?o.join("\n"):null}(t,e,o);i&&n.push(i)}),0===n.length?"":`/* ─── Responsive Visibility Rules ─── */\n/* Items show/hide based on container width */\n\n${n.join("\n\n")}`}(s,n);a&&i.push(a);const c=function(e){if(0===e.categories.size)return"";const t=[],n=Array.from(e.categories).sort();for(const o of n)t.push(`${U.ROOT}[${F.DISABLED_CATEGORIES}~="${o}"] [${F.CATEGORIES}~="${o}"] {\n display: none !important;\n}`);return`/* ─── Category Visibility Rules ─── */\n/* Items hide when ANY of their categories is disabled */\n/* Use: data-disabled-categories="category1 category2" on root element */\n\n${t.join("\n\n")}`}(s);c&&i.push(c);const r=function(e,t){if(0===e.dependencies.length)return"";const n=[],o=t.useContainerQueries?"@container":"@media";for(const s of e.dependencies){const t=J(s,e,o);t.length>0&&n.push(...t)}return 0===n.length?"":`/* ─── Dependency Visibility Rules ─── */\n/* Container elements hide when all their dependencies are hidden */\n\n${n.join("\n\n")}`}(s,n);return r&&i.push(r),i.filter(e=>e.trim()).join("\n\n")}function W(e,t){const n=new Set,o=new Map,s=[],i=new Map,a=new Map;for(const[c,r]of Object.entries(e.menus))j(c,r,n,o,s,i,a,t);for(const[c,r]of Object.entries(e.toolbars))k(c,r,n,o,s,a,t);for(const[c,r]of Object.entries(e.panels))z(c,r,n,o,s);for(const[c,r]of Object.entries(e.selectionMenus||{}))Q(c,r,n,o,s,a,t);return{categories:n,itemCategories:o,dependencies:s,menuBreakpoints:i,responsiveItems:a}}function j(e,t,n,o,s,i,a,c){H(e,t.categories,t.visibilityDependsOn,n,o,s),N(t.items,n,o,s);const r=_(t,c);r&&r.items.forEach((e,t)=>{a.set(t,e)});const l=function(e,t,n){var o;const s=[],i=_(e,n);if((null==(o=e.responsive)?void 0:o.breakpoints)&&i){const e=Array.from(i.breakpoints.entries()).sort((e,t)=>(e[1].minWidth??0)-(t[1].minWidth??0));for(const[n,o]of e){const e=G(i,o),n=new Set;for(const o of e){const e=t.get(o);e&&e.forEach(e=>n.add(e))}s.push({minWidth:o.minWidth,maxWidth:o.maxWidth,visibleCategories:n})}}else{const n=new Set;B(e.items,t,n),s.push({visibleCategories:n})}return s}(t,o,c);i.set(e,l)}function N(e,t,n,o){for(const s of e)H(s.id,s.categories,s.visibilityDependsOn,t,n,o),"section"===s.type&&N(s.items,t,n,o)}function B(e,t,n){for(const o of e){const e=t.get(o.id);e&&e.forEach(e=>n.add(e)),"section"===o.type&&B(o.items,t,n)}}function G(e,t){const n=[];return e.items.forEach((e,o)=>{let s=e.defaultVisible;for(const n of e.visibilityRules){(void 0===n.minWidth||void 0!==t.minWidth&&t.minWidth>=n.minWidth)&&(void 0===n.maxWidth||void 0!==t.maxWidth&&t.maxWidth<=n.maxWidth)&&(s=n.visible)}s&&n.push(o)}),n}function k(e,t,n,o,s,i,a){H(e,t.categories,t.visibilityDependsOn,n,o,s);const c=_(t,a);c&&c.items.forEach((e,t)=>{i.set(t,e)}),V(t.items,n,o,s)}function V(e,t,n,o){for(const s of e)H(s.id,s.categories,s.visibilityDependsOn,t,n,o),"group"===s.type&&s.items&&V(s.items,t,n,o),"tab-group"===s.type&&s.tabs&&Y(s.tabs,t,n,o)}function Y(e,t,n,o){for(const s of e)H(s.id,s.categories,s.visibilityDependsOn,t,n,o)}function z(e,t,n,o,s){if(H(e,t.categories,t.visibilityDependsOn,n,o,s),"tabs"===t.content.type)for(const i of t.content.tabs)H(i.id,i.categories,i.visibilityDependsOn,n,o,s)}function Q(e,t,n,o,s,i,a){if(H(e,t.categories,t.visibilityDependsOn,n,o,s),t.responsive){const e=_(t,a);e&&e.items.forEach((e,t)=>{i.set(t,e)})}q(t.items,n,o,s)}function q(e,t,n,o){for(const s of e)H(s.id,s.categories,s.visibilityDependsOn,t,n,o),"group"===s.type&&s.items&&q(s.items,t,n,o)}function H(e,t,n,o,s,i){var a;(null==t?void 0:t.length)&&(t.forEach(e=>o.add(e)),s.set(e,t)),n&&(n.menuId||(null==(a=n.itemIds)?void 0:a.length))&&i.push({itemId:e,dependsOnMenuId:n.menuId,dependsOnItemIds:n.itemIds})}function J(e,t,n,o){var s;const i=[];if(e.dependsOnMenuId){const o=t.menuBreakpoints.get(e.dependsOnMenuId);if(o&&o.length>0){i.push(`/* "${e.itemId}" depends on menu "${e.dependsOnMenuId}" */`);for(const t of o){if(0===t.visibleCategories.size)continue;const o=Array.from(t.visibleCategories).sort().map(e=>U.DISABLED_CATEGORY(e)).join(""),s=`${U.ROOT}${o} ${U.ITEM(e.itemId)} {\n display: none !important;\n}`,a=[];void 0!==t.minWidth&&a.push(`(min-width: ${t.minWidth}px)`),void 0!==t.maxWidth&&a.push(`(max-width: ${t.maxWidth}px)`),a.length>0?i.push(`${n} ${a.join(" and ")} {\n ${s}\n}`):i.push(s)}}}if(null==(s=e.dependsOnItemIds)?void 0:s.length){const n=new Set;for(const o of e.dependsOnItemIds){const e=t.itemCategories.get(o);e&&e.forEach(e=>n.add(e))}if(n.size>0){const t=Array.from(n).sort().map(e=>U.DISABLED_CATEGORY(e)).join("");i.push(`/* "${e.itemId}" depends on items: ${e.dependsOnItemIds.join(", ")} */\n${U.ROOT}${t} ${U.ITEM(e.itemId)} {\n display: none !important;\n}`)}}return i}const K=class extends e.BasePlugin{constructor(t,n,o){var s,i;super(t,n),this.cachedStylesheet=null,this.cachedLocale=null,this.i18n=null,this.i18nCleanup=null,this.categoryChanged$=e.createBehaviorEmitter(),this.stylesheetInvalidated$=e.createEmitter(),this.toolbarChanged$=e.createScopedEmitter((e,t)=>({documentId:e,...t}),{cache:!1}),this.panelChanged$=e.createScopedEmitter((e,t)=>({documentId:e,...t}),{cache:!1}),this.modalChanged$=e.createScopedEmitter((e,t)=>({documentId:e,...t}),{cache:!1}),this.menuChanged$=e.createScopedEmitter((e,t)=>({documentId:e,...t}),{cache:!1}),this.schema=o.schema,this.stylesheetConfig=o.stylesheetConfig||{},(null==(s=o.disabledCategories)?void 0:s.length)&&this.dispatch(A(o.disabledCategories)),this.i18n=(null==(i=n.getPlugin("i18n"))?void 0:i.provides())??null,this.i18n&&(this.i18nCleanup=this.i18n.onLocaleChange(({currentLocale:e})=>{this.handleLocaleChange(e)}),this.cachedLocale=this.i18n.getLocale())}async initialize(){this.logger.info("UIPlugin","Initialize","UI plugin initialized")}async destroy(){this.i18nCleanup&&(this.i18nCleanup(),this.i18nCleanup=null),this.toolbarChanged$.clear(),this.panelChanged$.clear(),this.modalChanged$.clear(),this.menuChanged$.clear(),this.stylesheetInvalidated$.clear(),super.destroy()}onDocumentLoadingStarted(e){this.dispatch(I(e,this.schema))}onDocumentClosed(e){this.dispatch(f(e)),this.toolbarChanged$.clearScope(e),this.panelChanged$.clearScope(e),this.modalChanged$.clearScope(e),this.menuChanged$.clearScope(e)}handleLocaleChange(e){this.cachedLocale!==e&&(this.logger.debug("UIPlugin","LocaleChange",`Locale changed: ${this.cachedLocale} -> ${e}`),this.cachedLocale=e,this.invalidateStylesheet(),this.stylesheetInvalidated$.emit())}getStylesheet(){var e;const t=(null==(e=this.i18n)?void 0:e.getLocale())??null;return this.cachedStylesheet&&this.cachedLocale===t||(this.cachedStylesheet=R(this.schema,{config:this.stylesheetConfig,locale:t??void 0}),this.cachedLocale=t),this.cachedStylesheet}getLocale(){var e;return(null==(e=this.i18n)?void 0:e.getLocale())??null}invalidateStylesheet(){this.cachedStylesheet=null}onStylesheetInvalidated(e){return this.stylesheetInvalidated$.on(e)}disableCategoryImpl(e){const t=new Set(this.state.disabledCategories);t.has(e)||(t.add(e),this.dispatch(A(Array.from(t))),this.categoryChanged$.emit({disabledCategories:Array.from(t)}))}enableCategoryImpl(e){const t=new Set(this.state.disabledCategories);t.has(e)&&(t.delete(e),this.dispatch(A(Array.from(t))),this.categoryChanged$.emit({disabledCategories:Array.from(t)}))}toggleCategoryImpl(e){this.state.disabledCategories.includes(e)?this.enableCategoryImpl(e):this.disableCategoryImpl(e)}setDisabledCategoriesImpl(e){this.dispatch(A(e)),this.categoryChanged$.emit({disabledCategories:e})}buildCapability(){return{setActiveToolbar:(e,t,n,o)=>this.setToolbarForDocument(e,t,n,o),setActivePanel:(e,t,n,o,s)=>this.setPanelForDocument(e,t,n,o,s),togglePanel:(e,t,n,o,s)=>this.togglePanelForDocument(e,t,n,o,s),openModal:(e,t)=>this.openModalForDocument(e,t),openMenu:(e,t,n,o)=>this.openMenuForDocument(e,t,n,o),toggleMenu:(e,t,n,o)=>this.toggleMenuForDocument(e,t,n,o),forDocument:e=>this.createUIScope(e),getSchema:()=>this.schema,mergeSchema:e=>{this.schema=M(this.schema,e)},disableCategory:e=>this.disableCategoryImpl(e),enableCategory:e=>this.enableCategoryImpl(e),toggleCategory:e=>this.toggleCategoryImpl(e),setDisabledCategories:e=>this.setDisabledCategoriesImpl(e),getDisabledCategories:()=>this.state.disabledCategories,isCategoryDisabled:e=>this.state.disabledCategories.includes(e),onToolbarChanged:this.toolbarChanged$.onGlobal,onPanelChanged:this.panelChanged$.onGlobal,onModalChanged:this.modalChanged$.onGlobal,onMenuChanged:this.menuChanged$.onGlobal,onCategoryChanged:this.categoryChanged$.on}}createUIScope(e){return{setActiveToolbar:(t,n,o)=>this.setToolbarForDocument(t,n,o,e),getActiveToolbar:(t,n)=>this.getToolbarForDocument(t,n,e),closeToolbarSlot:(t,n)=>this.closeToolbarForDocument(t,n,e),isToolbarOpen:(t,n,o)=>this.isToolbarOpenForDocument(t,n,o,e),setActivePanel:(t,n,o,s)=>this.setPanelForDocument(t,n,o,e,s),getActivePanel:(t,n)=>this.getPanelForDocument(t,n,e),closePanelSlot:(t,n)=>this.closePanelForDocument(t,n,e),togglePanel:(t,n,o,s)=>this.togglePanelForDocument(t,n,o,e,s),isPanelOpen:(t,n,o)=>this.isPanelOpenForDocument(t,n,o,e),setPanelTab:(t,n)=>this.setPanelTabForDocument(t,n,e),getPanelTab:t=>this.getPanelTabForDocument(t,e),openModal:t=>this.openModalForDocument(t,e),closeModal:()=>this.closeModalForDocument(e),getActiveModal:()=>this.getActiveModalForDocument(e),openMenu:(t,n,o)=>this.openMenuForDocument(t,n,o,e),closeMenu:t=>this.closeMenuForDocument(t,e),toggleMenu:(t,n,o)=>this.toggleMenuForDocument(t,n,o,e),closeAllMenus:()=>this.closeAllMenusForDocument(e),isMenuOpen:t=>this.isMenuOpenForDocument(t,e),getOpenMenus:()=>this.getOpenMenusForDocument(e),getSchema:()=>this.schema,getState:()=>this.getDocumentStateOrThrow(e),onToolbarChanged:this.toolbarChanged$.forScope(e),onPanelChanged:this.panelChanged$.forScope(e),onModalChanged:this.modalChanged$.forScope(e),onMenuChanged:this.menuChanged$.forScope(e)}}getDocumentState(e){const t=e??this.getActiveDocumentId();return this.state.documents[t]??null}getDocumentStateOrThrow(e){const t=this.getDocumentState(e);if(!t)throw new Error(`UI state not found for document: ${e??"active"}`);return t}setToolbarForDocument(e,t,n,o){const s=o??this.getActiveDocumentId();this.dispatch(b(s,e,t,n)),this.toolbarChanged$.emit(s,{placement:e,slot:t,toolbarId:n})}getToolbarForDocument(e,t,n){const o=`${e}-${t}`,s=this.getDocumentStateOrThrow(n).activeToolbars[o];return(null==s?void 0:s.isOpen)?s.toolbarId:null}closeToolbarForDocument(e,t,n){const o=n??this.getActiveDocumentId();this.dispatch(y(o,e,t)),this.toolbarChanged$.emit(o,{placement:e,slot:t,toolbarId:""})}isToolbarOpenForDocument(e,t,n,o){const s=`${e}-${t}`,i=this.getDocumentStateOrThrow(o).activeToolbars[s];return!(!i||!i.isOpen)&&(!n||i.toolbarId===n)}setPanelForDocument(e,t,n,o,s){const i=o??this.getActiveDocumentId();this.dispatch(v(i,e,t,n,s)),this.panelChanged$.emit(i,{placement:e,slot:t,panelId:n})}getPanelForDocument(e,t,n){const o=`${e}-${t}`,s=this.getDocumentStateOrThrow(n).activePanels[o];return(null==s?void 0:s.isOpen)?s.panelId:null}closePanelForDocument(e,t,n){const o=n??this.getActiveDocumentId();this.dispatch(C(o,e,t)),this.panelChanged$.emit(o,{placement:e,slot:t,panelId:""})}togglePanelForDocument(e,t,n,o,s){const i=o??this.getActiveDocumentId(),a=`${e}-${t}`,c=this.getDocumentStateOrThrow(i).activePanels[a];(null==c?void 0:c.panelId)===n&&(null==c?void 0:c.isOpen)?(this.dispatch(C(i,e,t)),this.panelChanged$.emit(i,{placement:e,slot:t,panelId:""})):(this.dispatch(v(i,e,t,n,s)),this.panelChanged$.emit(i,{placement:e,slot:t,panelId:n}))}isPanelOpenForDocument(e,t,n,o){const s=`${e}-${t}`,i=this.getDocumentStateOrThrow(o).activePanels[s];return!(!i||!i.isOpen)&&(!n||i.panelId===n)}setPanelTabForDocument(e,t,n){const o=n??this.getActiveDocumentId();this.dispatch(O(o,e,t))}getPanelTabForDocument(e,t){return this.getDocumentStateOrThrow(t).panelTabs[e]??null}openModalForDocument(e,t){const n=t??this.getActiveDocumentId();this.dispatch(S(n,e)),this.modalChanged$.emit(n,{modalId:e})}closeModalForDocument(e){const t=e??this.getActiveDocumentId();this.dispatch(T(t)),this.modalChanged$.emit(t,{modalId:null})}getActiveModalForDocument(e){return this.getDocumentStateOrThrow(e).activeModal}openMenuForDocument(e,t,n,o){const s=o??this.getActiveDocumentId();this.dispatch(D(s,{menuId:e,triggeredByCommandId:t,triggeredByItemId:n})),this.menuChanged$.emit(s,{menuId:e,isOpen:!0})}closeMenuForDocument(e,t){const n=t??this.getActiveDocumentId();this.dispatch(E(n,e)),this.menuChanged$.emit(n,{menuId:e,isOpen:!1})}toggleMenuForDocument(e,t,n,o){const s=o??this.getActiveDocumentId();!!this.getDocumentStateOrThrow(s).openMenus[e]?(this.dispatch(E(s,e)),this.menuChanged$.emit(s,{menuId:e,isOpen:!1})):(this.dispatch(D(s,{menuId:e,triggeredByCommandId:t,triggeredByItemId:n})),this.menuChanged$.emit(s,{menuId:e,isOpen:!0}))}closeAllMenusForDocument(e){const t=e??this.getActiveDocumentId();this.dispatch($(t))}isMenuOpenForDocument(e,t){return!!this.getDocumentStateOrThrow(t).openMenus[e]}getOpenMenusForDocument(e){return Object.values(this.getDocumentStateOrThrow(e).openMenus)}};K.id="ui";let X=K;const Z={activeToolbars:{},activePanels:{},activeModal:null,openMenus:{},panelTabs:{}},ee={documents:{},disabledCategories:[]};function te(e){return e.ui??null}function ne(e,t){const n=te(e);return(null==n?void 0:n.documents[t])??null}function oe(e,t){return`${e}-${t}`}function se(e,t,n,o){const s=ne(e,t);return s?s.activeToolbars[oe(n,o)]??null:null}function ie(e,t,n,o){const s=ne(e,t);return s?s.activePanels[oe(n,o)]??null:null}const ae={manifest:n,create:(e,n)=>new X(t,e,n),reducer:(e=ee,t)=>{switch(t.type){case o:{const{documentId:n,schema:o}=t.payload,s={};return Object.values(o.toolbars).forEach(e=>{if(e.permanent&&e.position){const t=`${e.position.placement}-${e.position.slot}`;s[t]={toolbarId:e.id,isOpen:!0}}}),{...e,documents:{...e.documents,[n]:{...Z,activeToolbars:s}}}}case s:{const{documentId:n}=t.payload,{[n]:o,...s}=e.documents;return{...e,documents:s}}case i:{const{documentId:n,placement:o,slot:s,toolbarId:i}=t.payload,a=e.documents[n]||Z,c=`${o}-${s}`;return{...e,documents:{...e.documents,[n]:{...a,activeToolbars:{...a.activeToolbars,[c]:{toolbarId:i,isOpen:!0}}}}}}case c:{const{documentId:n,placement:o,slot:s,panelId:i,activeTab:a}=t.payload,c=e.documents[n]||Z,r=`${o}-${s}`;return{...e,documents:{...e.documents,[n]:{...c,activePanels:{...c.activePanels,[r]:{panelId:i,isOpen:!0}},...a&&{panelTabs:{...c.panelTabs,[i]:a}}}}}}case r:{const{documentId:n,placement:o,slot:s}=t.payload,i=e.documents[n];if(!i)return e;const a=`${o}-${s}`,c=i.activePanels[a];return c?{...e,documents:{...e.documents,[n]:{...i,activePanels:{...i.activePanels,[a]:{...c,isOpen:!1}}}}}:e}case a:{const{documentId:n,placement:o,slot:s}=t.payload,i=e.documents[n];if(!i)return e;const a=`${o}-${s}`,c=i.activeToolbars[a];return c?{...e,documents:{...e.documents,[n]:{...i,activeToolbars:{...i.activeToolbars,[a]:{...c,isOpen:!1}}}}}:e}case l:{const{documentId:n,panelId:o,tabId:s}=t.payload,i=e.documents[n]||Z;return{...e,documents:{...e.documents,[n]:{...i,panelTabs:{...i.panelTabs,[o]:s}}}}}case d:{const{documentId:n,modalId:o}=t.payload,s=e.documents[n]||Z;return{...e,documents:{...e.documents,[n]:{...s,activeModal:o,openMenus:{}}}}}case u:{const{documentId:n}=t.payload,o=e.documents[n];return o?{...e,documents:{...e.documents,[n]:{...o,activeModal:null}}}:e}case h:{const{documentId:n,menuState:o}=t.payload,s=e.documents[n]||Z;return{...e,documents:{...e.documents,[n]:{...s,openMenus:{[o.menuId]:o}}}}}case m:{const{documentId:n,menuId:o}=t.payload,s=e.documents[n];if(!s)return e;const{[o]:i,...a}=s.openMenus;return{...e,documents:{...e.documents,[n]:{...s,openMenus:a}}}}case p:{const{documentId:n}=t.payload,o=e.documents[n];return o?{...e,documents:{...e.documents,[n]:{...o,openMenus:{}}}}:e}case g:return{...e,disabledCategories:t.payload.categories};default:return e}},initialState:ee};exports.CLEANUP_UI_STATE=s,exports.CLOSE_ALL_MENUS=p,exports.CLOSE_MENU=m,exports.CLOSE_MODAL=u,exports.CLOSE_PANEL_SLOT=r,exports.CLOSE_TOOLBAR_SLOT=a,exports.INIT_UI_STATE=o,exports.OPEN_MENU=h,exports.OPEN_MODAL=d,exports.SET_ACTIVE_PANEL=c,exports.SET_ACTIVE_TOOLBAR=i,exports.SET_DISABLED_CATEGORIES=g,exports.SET_PANEL_TAB=l,exports.UIPlugin=X,exports.UIPluginPackage=ae,exports.UI_ATTRIBUTES=F,exports.UI_PLUGIN_ID=t,exports.UI_SELECTORS=U,exports.cleanupUIState=f,exports.closeAllMenus=$,exports.closeMenu=E,exports.closeModal=T,exports.closePanelSlot=C,exports.closeToolbarSlot=y,exports.extractCategories=function(e){const t=W(e);return Array.from(t.categories).sort()},exports.generateUIStylesheet=R,exports.getItemResponsiveMetadata=function(e,t,n){const o=_(t,n);return(null==o?void 0:o.items.get(e))??null},exports.getStylesheetConfig=function(e={}){return{...w,...e}},exports.getUIItemProps=function(e,t){var n;return{[F.ITEM]:e.id,[F.CATEGORIES]:(null==(n=e.categories)?void 0:n.join(" "))||void 0,...t}},exports.initUIState=I,exports.isPanelOpen=function(e,t,n,o,s){const i=ie(e,t,n,o);return!(!i||!i.isOpen)&&(!s||i.panelId===s)},exports.isToolbarOpen=function(e,t,n,o,s){const i=se(e,t,n,o);return!(!i||!i.isOpen)&&(!s||i.toolbarId===s)},exports.manifest=n,exports.mergeUISchema=M,exports.openMenu=D,exports.openModal=S,exports.removeFromSchema=function(e,t){const n={...e};return t.toolbars&&(n.toolbars={...n.toolbars},t.toolbars.forEach(e=>delete n.toolbars[e])),t.menus&&(n.menus={...n.menus},t.menus.forEach(e=>delete n.menus[e])),t.panels&&(n.panels={...n.panels},t.panels.forEach(e=>delete n.panels[e])),t.commands&&(n.toolbars=function(e,t){const n={};for(const[o,s]of Object.entries(e))n[o]={...s,items:s.items.filter(e=>"command-button"===e.type?!t.includes(e.commandId):"group"===e.type?e.items.some(e=>"command-button"!==e.type||!t.includes(e.commandId)):"tab-group"!==e.type||e.tabs.some(e=>!t.includes(e.commandId)))};return n}(n.toolbars,t.commands),n.menus=function(e,t){const n={};for(const[o,s]of Object.entries(e))n[o]={...s,items:s.items.filter(e=>"command"===e.type?!t.includes(e.commandId):"section"!==e.type||e.items.some(e=>"command"!==e.type||!t.includes(e.commandId)))};return n}(n.menus,t.commands)),n},exports.resolveResponsiveMetadata=_,exports.selectPanelSlot=ie,exports.selectToolbarSlot=se,exports.selectUIDocumentState=ne,exports.selectUIState=te,exports.setActivePanel=v,exports.setActiveToolbar=b,exports.setDisabledCategories=A,exports.setPanelTab=O;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t="ui",o={id:t,name:"UI Plugin",version:"1.0.0",provides:["ui"],requires:["commands"],optional:["i18n"],defaultConfig:{schema:{id:"empty",version:"1.0.0",toolbars:{},menus:{},sidebars:{},modals:{},selectionMenus:{}}}},s="UI/INIT_STATE",n="UI/CLEANUP_STATE",i="UI/SET_ACTIVE_TOOLBAR",a="UI/CLOSE_TOOLBAR_SLOT",d="UI/SET_ACTIVE_SIDEBAR",r="UI/CLOSE_SIDEBAR_SLOT",c="UI/SET_SIDEBAR_TAB",l="UI/OPEN_MODAL",u="UI/CLOSE_MODAL",h="UI/CLEAR_MODAL",m="UI/OPEN_MENU",p="UI/CLOSE_MENU",g="UI/CLOSE_ALL_MENUS",b="UI/SET_DISABLED_CATEGORIES",I="UI/SET_HIDDEN_ITEMS",S=(e,t)=>({type:s,payload:{documentId:e,schema:t}}),f=e=>({type:n,payload:{documentId:e}}),v=(e,t,o,s)=>({type:i,payload:{documentId:e,placement:t,slot:o,toolbarId:s}}),y=(e,t,o)=>({type:a,payload:{documentId:e,placement:t,slot:o}}),O=(e,t,o,s,n)=>({type:d,payload:{documentId:e,placement:t,slot:o,sidebarId:s,activeTab:n}}),D=(e,t,o)=>({type:r,payload:{documentId:e,placement:t,slot:o}}),C=(e,t,o)=>({type:c,payload:{documentId:e,sidebarId:t,tabId:o}}),T=(e,t)=>({type:l,payload:{documentId:e,modalId:t}}),E=e=>({type:u,payload:{documentId:e}}),M=e=>({type:h,payload:{documentId:e}}),$=(e,t)=>({type:m,payload:{documentId:e,menuState:t}}),A=(e,t)=>({type:p,payload:{documentId:e,menuId:t}}),x=e=>({type:g,payload:{documentId:e}}),L=e=>({type:b,payload:{categories:e}}),_=e=>({type:I,payload:{hiddenItems:e}});function F(e,t){return{...e,...t,toolbars:U(e.toolbars,t.toolbars),menus:w(e.menus,t.menus),sidebars:R(e.sidebars,t.sidebars)}}function U(e,t){if(!t)return e;const o={...e};for(const[s,n]of Object.entries(t))o[s]?o[s]={...o[s],...n,items:n.items??o[s].items,responsive:n.responsive??o[s].responsive}:o[s]=n;return o}function w(e,t){if(!t)return e;const o={...e};for(const[s,n]of Object.entries(t))o[s]?o[s]={...o[s],...n,items:n.items??o[s].items}:o[s]=n;return o}function R(e,t){if(!t)return e;const o={...e};for(const[s,n]of Object.entries(t))o[s]?o[s]={...o[s],...n,content:n.content??o[s].content}:o[s]=n;return o}function W(e,t){var o;if(!(null==(o=e.responsive)?void 0:o.breakpoints))return null;const s=function(e,t,o){if(!o||!(null==t?void 0:t.groups))return e;const s=t.groups.find(e=>e.locales.includes(o));if(!s)return e;const n={};for(const[i,a]of Object.entries(e)){const e=s.breakpoints[i];e?n[i]={minWidth:a.minWidth,maxWidth:a.maxWidth,hide:e.replaceHide?e.replaceHide:[...a.hide||[],...e.hide||[]],show:e.replaceShow?e.replaceShow:[...a.show||[],...e.show||[]]}:n[i]=a}return n}(e.responsive.breakpoints,e.responsive.localeOverrides,t),n=new Map,i=new Map;for(const[r,c]of Object.entries(s))i.set(r,{minWidth:c.minWidth,maxWidth:c.maxWidth});const a=new Set,d=e=>{e.forEach(e=>{a.add(e.id),"group"===e.type&&e.items&&d(e.items),"tab-group"===e.type&&e.tabs&&d(e.tabs),"section"===e.type&&e.items&&d(e.items)})};d(e.items);for(const r of a){const e=[];let t=!0;Array.from(Object.entries(s)).sort((e,t)=>(e[1].minWidth??0)-(t[1].minWidth??0)).forEach(([o,s],n)=>{var i,a;const d=null==(i=s.hide)?void 0:i.includes(r),c=null==(a=s.show)?void 0:a.includes(r);(d||c)&&(e.push({breakpointId:o,minWidth:s.minWidth,maxWidth:s.maxWidth,visible:c||!d,priority:n}),0===n&&(t=c||!d))}),e.length>0&&n.set(r,{itemId:r,shouldRender:!0,visibilityRules:e,defaultVisible:t})}return{items:n,breakpoints:i}}const B={ROOT:"data-epdf",STYLES:"data-epdf-s",ITEM:"data-epdf-i",CATEGORIES:"data-epdf-cat",DISABLED_CATEGORIES:"data-epdf-dis",HIDDEN_ITEMS:"data-epdf-hid"},j={ROOT:`[${B.ROOT}]`,STYLES:`[${B.STYLES}]`,ITEM:e=>`[${B.ITEM}="${e}"]`,CATEGORIES:e=>`[${B.CATEGORIES}~="${e}"]`,DISABLED_CATEGORY:e=>`[${B.DISABLED_CATEGORIES}~="${e}"]`,HIDDEN_ITEM:e=>`[${B.HIDDEN_ITEMS}~="${e}"]`},N={useContainerQueries:!0};function P(e,t={}){const o={...N,...t.config},s=t.locale,n=k(e,s),i=[];i.push(function(e){const t=e?` (locale: ${e})`:"";return`/* ═══════════════════════════════════════════════════════════════════════════ */\n/* EmbedPDF UI Stylesheet - Auto-generated${t} */\n/* DO NOT EDIT MANUALLY - This file is generated from your UI schema */\n/* ═══════════════════════════════════════════════════════════════════════════ */`}(s));const a=function(e,t){const o=[],s=t.useContainerQueries?"@container":"@media",n=new Set;return e.responsiveItems.forEach((e,t)=>{if(n.has(t))return;n.add(t);const i=function(e,t,o){if(0===t.visibilityRules.length)return null;const s=[],n=j.ITEM(e);t.defaultVisible||s.push(`${n} { display: none; }`);for(const i of t.visibilityRules){const e=[];if(void 0!==i.minWidth&&e.push(`(min-width: ${i.minWidth}px)`),void 0!==i.maxWidth&&e.push(`(max-width: ${i.maxWidth}px)`),e.length>0){const t=i.visible?"flex":"none";s.push(`${o} ${e.join(" and ")} {\n ${n} { display: ${t}; }\n}`)}}return s.length>0?s.join("\n"):null}(t,e,s);i&&o.push(i)}),0===o.length?"":`/* ─── Responsive Visibility Rules ─── */\n/* Items show/hide based on container width */\n\n${o.join("\n\n")}`}(n,o);a&&i.push(a);const d=function(e){if(0===e.categories.size)return"";const t=[],o=Array.from(e.categories).sort();for(const s of o)t.push(`${j.ROOT}[${B.DISABLED_CATEGORIES}~="${s}"] [${B.CATEGORIES}~="${s}"] {\n display: none !important;\n}`);return`/* ─── Category Visibility Rules ─── */\n/* Items hide when ANY of their categories is disabled */\n/* Use: data-disabled-categories="category1 category2" on root element */\n\n${t.join("\n\n")}`}(n);d&&i.push(d);const r=function(e,t){if(0===e.dependencies.length)return"";const o=[],s=t.useContainerQueries?"@container":"@media";for(const n of e.dependencies){const t=oe(n,e,s);t.length>0&&o.push(...t)}return 0===o.length?"":`/* ─── Dependency Visibility Rules ─── */\n/* Container elements hide when all their dependencies are hidden */\n\n${o.join("\n\n")}`}(n,o);return r&&i.push(r),i.filter(e=>e.trim()).join("\n\n")}function G(e){return k(e).itemCategories}function H(e,t){const o=new Set(t),s=[];return e.forEach((e,t)=>{e.some(e=>o.has(e))&&s.push(t)}),s}function k(e,t){const o=new Set,s=new Map,n=[],i=new Map,a=new Map;for(const[d,r]of Object.entries(e.menus))V(d,r,o,s,n,i,a,t);for(const[d,r]of Object.entries(e.toolbars))q(d,r,o,s,n,a,t);for(const[d,r]of Object.entries(e.sidebars))X(d,r,o,s,n);for(const[d,r]of Object.entries(e.selectionMenus||{}))Z(d,r,o,s,n,a,t);return{categories:o,itemCategories:s,dependencies:n,menuBreakpoints:i,responsiveItems:a}}function V(e,t,o,s,n,i,a,d){te(e,t.categories,t.visibilityDependsOn,o,s,n),Y(t.items,o,s,n);const r=W(t,d);r&&r.items.forEach((e,t)=>{a.set(t,e)});const c=function(e,t,o){var s;const n=[],i=W(e,o);if((null==(s=e.responsive)?void 0:s.breakpoints)&&i){const e=Array.from(i.breakpoints.entries()).sort((e,t)=>(e[1].minWidth??0)-(t[1].minWidth??0));for(const[o,s]of e){const e=Q(i,s),o=new Set;for(const s of e){const e=t.get(s);e&&e.forEach(e=>o.add(e))}n.push({minWidth:s.minWidth,maxWidth:s.maxWidth,visibleItemIds:e,visibleCategories:o})}}else{const o=[],s=new Set;z(e.items,t,o,s),n.push({visibleItemIds:o,visibleCategories:s})}return n}(t,s,d);i.set(e,c)}function Y(e,t,o,s){for(const n of e)te(n.id,n.categories,n.visibilityDependsOn,t,o,s),"section"===n.type&&Y(n.items,t,o,s)}function z(e,t,o,s){for(const n of e){o.push(n.id);const e=t.get(n.id);e&&e.forEach(e=>s.add(e)),"section"===n.type&&z(n.items,t,o,s)}}function Q(e,t){const o=[];return e.items.forEach((e,s)=>{let n=e.defaultVisible;for(const o of e.visibilityRules){(void 0===o.minWidth||void 0!==t.minWidth&&t.minWidth>=o.minWidth)&&(void 0===o.maxWidth||void 0!==t.maxWidth&&t.maxWidth<=o.maxWidth)&&(n=o.visible)}n&&o.push(s)}),o}function q(e,t,o,s,n,i,a){te(e,t.categories,t.visibilityDependsOn,o,s,n);const d=W(t,a);d&&d.items.forEach((e,t)=>{i.set(t,e)}),J(t.items,o,s,n)}function J(e,t,o,s){for(const n of e)te(n.id,n.categories,n.visibilityDependsOn,t,o,s),"group"===n.type&&n.items&&J(n.items,t,o,s),"tab-group"===n.type&&n.tabs&&K(n.tabs,t,o,s)}function K(e,t,o,s){for(const n of e)te(n.id,n.categories,n.visibilityDependsOn,t,o,s)}function X(e,t,o,s,n){if(te(e,t.categories,t.visibilityDependsOn,o,s,n),"tabs"===t.content.type)for(const i of t.content.tabs)te(i.id,i.categories,i.visibilityDependsOn,o,s,n)}function Z(e,t,o,s,n,i,a){if(te(e,t.categories,t.visibilityDependsOn,o,s,n),t.responsive){const e=W(t,a);e&&e.items.forEach((e,t)=>{i.set(t,e)})}ee(t.items,o,s,n)}function ee(e,t,o,s){for(const n of e)te(n.id,n.categories,n.visibilityDependsOn,t,o,s),"group"===n.type&&n.items&&ee(n.items,t,o,s)}function te(e,t,o,s,n,i){var a;(null==t?void 0:t.length)&&(t.forEach(e=>s.add(e)),n.set(e,t)),o&&(o.menuId||(null==(a=o.itemIds)?void 0:a.length))&&i.push({itemId:e,dependsOnMenuId:o.menuId,dependsOnItemIds:o.itemIds})}function oe(e,t,o,s){var n;const i=[];if(e.dependsOnMenuId){const s=t.menuBreakpoints.get(e.dependsOnMenuId);if(s&&s.length>0){i.push(`/* "${e.itemId}" depends on menu "${e.dependsOnMenuId}" */`);for(const t of s){if(0===t.visibleItemIds.length)continue;const s=t.visibleItemIds.sort().map(e=>j.HIDDEN_ITEM(e)).join(""),n=`${j.ROOT}${s} ${j.ITEM(e.itemId)} {\n display: none !important;\n}`,a=[];void 0!==t.minWidth&&a.push(`(min-width: ${t.minWidth}px)`),void 0!==t.maxWidth&&a.push(`(max-width: ${t.maxWidth}px)`),a.length>0?i.push(`${o} ${a.join(" and ")} {\n ${n}\n}`):i.push(n)}}}if(null==(n=e.dependsOnItemIds)?void 0:n.length){i.push(`/* "${e.itemId}" depends on items: ${e.dependsOnItemIds.join(", ")} */`);const t=e.dependsOnItemIds.sort().map(e=>j.HIDDEN_ITEM(e)).join("");i.push(`${j.ROOT}${t} ${j.ITEM(e.itemId)} {\n display: none !important;\n}`)}return i}const se=class extends e.BasePlugin{constructor(t,o,s){var n,i;if(super(t,o),this.cachedStylesheet=null,this.cachedLocale=null,this.i18n=null,this.i18nCleanup=null,this.categoryChanged$=e.createBehaviorEmitter(),this.stylesheetInvalidated$=e.createEmitter(),this.toolbarChanged$=e.createScopedEmitter((e,t)=>({documentId:e,...t}),{cache:!1}),this.sidebarChanged$=e.createScopedEmitter((e,t)=>({documentId:e,...t}),{cache:!1}),this.modalChanged$=e.createScopedEmitter((e,t)=>({documentId:e,...t}),{cache:!1}),this.menuChanged$=e.createScopedEmitter((e,t)=>({documentId:e,...t}),{cache:!1}),this.schema=s.schema,this.stylesheetConfig=s.stylesheetConfig||{},this.itemCategories=G(this.schema),null==(n=s.disabledCategories)?void 0:n.length){this.dispatch(L(s.disabledCategories));const e=H(this.itemCategories,s.disabledCategories);this.dispatch(_(e))}this.i18n=(null==(i=o.getPlugin("i18n"))?void 0:i.provides())??null,this.i18n&&(this.i18nCleanup=this.i18n.onLocaleChange(({currentLocale:e})=>{this.handleLocaleChange(e)}),this.cachedLocale=this.i18n.getLocale())}async initialize(){this.logger.info("UIPlugin","Initialize","UI plugin initialized")}async destroy(){this.i18nCleanup&&(this.i18nCleanup(),this.i18nCleanup=null),this.toolbarChanged$.clear(),this.sidebarChanged$.clear(),this.modalChanged$.clear(),this.menuChanged$.clear(),this.stylesheetInvalidated$.clear(),super.destroy()}onDocumentLoadingStarted(e){this.dispatch(S(e,this.schema))}onDocumentClosed(e){this.dispatch(f(e)),this.toolbarChanged$.clearScope(e),this.sidebarChanged$.clearScope(e),this.modalChanged$.clearScope(e),this.menuChanged$.clearScope(e)}handleLocaleChange(e){this.cachedLocale!==e&&(this.logger.debug("UIPlugin","LocaleChange",`Locale changed: ${this.cachedLocale} -> ${e}`),this.cachedLocale=e,this.invalidateStylesheet(),this.stylesheetInvalidated$.emit())}getStylesheet(){var e;const t=(null==(e=this.i18n)?void 0:e.getLocale())??null;return this.cachedStylesheet&&this.cachedLocale===t||(this.cachedStylesheet=P(this.schema,{config:this.stylesheetConfig,locale:t??void 0}),this.cachedLocale=t),this.cachedStylesheet}getLocale(){var e;return(null==(e=this.i18n)?void 0:e.getLocale())??null}invalidateStylesheet(){this.cachedStylesheet=null}onStylesheetInvalidated(e){return this.stylesheetInvalidated$.on(e)}disableCategoryImpl(e){const t=new Set(this.state.disabledCategories);if(!t.has(e)){t.add(e);const o=Array.from(t);this.dispatch(L(o));const s=H(this.itemCategories,o);this.dispatch(_(s)),this.categoryChanged$.emit({disabledCategories:o,hiddenItems:s})}}enableCategoryImpl(e){const t=new Set(this.state.disabledCategories);if(t.has(e)){t.delete(e);const o=Array.from(t);this.dispatch(L(o));const s=H(this.itemCategories,o);this.dispatch(_(s)),this.categoryChanged$.emit({disabledCategories:o,hiddenItems:s})}}toggleCategoryImpl(e){this.state.disabledCategories.includes(e)?this.enableCategoryImpl(e):this.disableCategoryImpl(e)}setDisabledCategoriesImpl(e){this.dispatch(L(e));const t=H(this.itemCategories,e);this.dispatch(_(t)),this.categoryChanged$.emit({disabledCategories:e,hiddenItems:t})}buildCapability(){return{setActiveToolbar:(e,t,o,s)=>this.setToolbarForDocument(e,t,o,s),setActiveSidebar:(e,t,o,s,n)=>this.setSidebarForDocument(e,t,o,s,n),toggleSidebar:(e,t,o,s,n)=>this.toggleSidebarForDocument(e,t,o,s,n),openModal:(e,t)=>this.openModalForDocument(e,t),openMenu:(e,t,o,s)=>this.openMenuForDocument(e,t,o,s),toggleMenu:(e,t,o,s)=>this.toggleMenuForDocument(e,t,o,s),forDocument:e=>this.createUIScope(e),getSchema:()=>this.schema,mergeSchema:e=>{this.schema=F(this.schema,e)},disableCategory:e=>this.disableCategoryImpl(e),enableCategory:e=>this.enableCategoryImpl(e),toggleCategory:e=>this.toggleCategoryImpl(e),setDisabledCategories:e=>this.setDisabledCategoriesImpl(e),getDisabledCategories:()=>this.state.disabledCategories,isCategoryDisabled:e=>this.state.disabledCategories.includes(e),getHiddenItems:()=>this.state.hiddenItems,onToolbarChanged:this.toolbarChanged$.onGlobal,onSidebarChanged:this.sidebarChanged$.onGlobal,onModalChanged:this.modalChanged$.onGlobal,onMenuChanged:this.menuChanged$.onGlobal,onCategoryChanged:this.categoryChanged$.on}}createUIScope(e){return{setActiveToolbar:(t,o,s)=>this.setToolbarForDocument(t,o,s,e),getActiveToolbar:(t,o)=>this.getToolbarForDocument(t,o,e),closeToolbarSlot:(t,o)=>this.closeToolbarForDocument(t,o,e),isToolbarOpen:(t,o,s)=>this.isToolbarOpenForDocument(t,o,s,e),setActiveSidebar:(t,o,s,n)=>this.setSidebarForDocument(t,o,s,e,n),getActiveSidebar:(t,o)=>this.getSidebarForDocument(t,o,e),closeSidebarSlot:(t,o)=>this.closeSidebarForDocument(t,o,e),toggleSidebar:(t,o,s,n)=>this.toggleSidebarForDocument(t,o,s,e,n),isSidebarOpen:(t,o,s)=>this.isSidebarOpenForDocument(t,o,s,e),setSidebarTab:(t,o)=>this.setSidebarTabForDocument(t,o,e),getSidebarTab:t=>this.getSidebarTabForDocument(t,e),openModal:t=>this.openModalForDocument(t,e),closeModal:()=>this.closeModalForDocument(e),clearModal:()=>this.clearModalForDocument(e),getActiveModal:()=>this.getActiveModalForDocument(e),isModalOpen:()=>this.isModalOpenForDocument(e),openMenu:(t,o,s)=>this.openMenuForDocument(t,o,s,e),closeMenu:t=>this.closeMenuForDocument(t,e),toggleMenu:(t,o,s)=>this.toggleMenuForDocument(t,o,s,e),closeAllMenus:()=>this.closeAllMenusForDocument(e),isMenuOpen:t=>this.isMenuOpenForDocument(t,e),getOpenMenus:()=>this.getOpenMenusForDocument(e),getSchema:()=>this.schema,getState:()=>this.getDocumentStateOrThrow(e),onToolbarChanged:this.toolbarChanged$.forScope(e),onSidebarChanged:this.sidebarChanged$.forScope(e),onModalChanged:this.modalChanged$.forScope(e),onMenuChanged:this.menuChanged$.forScope(e)}}getDocumentState(e){const t=e??this.getActiveDocumentId();return this.state.documents[t]??null}getDocumentStateOrThrow(e){const t=this.getDocumentState(e);if(!t)throw new Error(`UI state not found for document: ${e??"active"}`);return t}setToolbarForDocument(e,t,o,s){const n=s??this.getActiveDocumentId();this.dispatch(v(n,e,t,o)),this.toolbarChanged$.emit(n,{placement:e,slot:t,toolbarId:o})}getToolbarForDocument(e,t,o){const s=`${e}-${t}`,n=this.getDocumentStateOrThrow(o).activeToolbars[s];return(null==n?void 0:n.isOpen)?n.toolbarId:null}closeToolbarForDocument(e,t,o){const s=o??this.getActiveDocumentId();this.dispatch(y(s,e,t)),this.toolbarChanged$.emit(s,{placement:e,slot:t,toolbarId:""})}isToolbarOpenForDocument(e,t,o,s){const n=`${e}-${t}`,i=this.getDocumentStateOrThrow(s).activeToolbars[n];return!(!i||!i.isOpen)&&(!o||i.toolbarId===o)}setSidebarForDocument(e,t,o,s,n){const i=s??this.getActiveDocumentId();this.dispatch(O(i,e,t,o,n)),this.sidebarChanged$.emit(i,{placement:e,slot:t,sidebarId:o})}getSidebarForDocument(e,t,o){const s=`${e}-${t}`,n=this.getDocumentStateOrThrow(o).activeSidebars[s];return(null==n?void 0:n.isOpen)?n.sidebarId:null}closeSidebarForDocument(e,t,o){const s=o??this.getActiveDocumentId();this.dispatch(D(s,e,t)),this.sidebarChanged$.emit(s,{placement:e,slot:t,sidebarId:""})}toggleSidebarForDocument(e,t,o,s,n){const i=s??this.getActiveDocumentId(),a=`${e}-${t}`,d=this.getDocumentStateOrThrow(i).activeSidebars[a];(null==d?void 0:d.sidebarId)===o&&(null==d?void 0:d.isOpen)?(this.dispatch(D(i,e,t)),this.sidebarChanged$.emit(i,{placement:e,slot:t,sidebarId:""})):(this.dispatch(O(i,e,t,o,n)),this.sidebarChanged$.emit(i,{placement:e,slot:t,sidebarId:o}))}isSidebarOpenForDocument(e,t,o,s){const n=`${e}-${t}`,i=this.getDocumentStateOrThrow(s).activeSidebars[n];return!(!i||!i.isOpen)&&(!o||i.sidebarId===o)}setSidebarTabForDocument(e,t,o){const s=o??this.getActiveDocumentId();this.dispatch(C(s,e,t))}getSidebarTabForDocument(e,t){return this.getDocumentStateOrThrow(t).sidebarTabs[e]??null}openModalForDocument(e,t){const o=t??this.getActiveDocumentId();this.dispatch(T(o,e)),this.modalChanged$.emit(o,{modalId:e,isOpen:!0})}closeModalForDocument(e){const t=e??this.getActiveDocumentId(),o=this.getDocumentStateOrThrow(t).activeModal;this.dispatch(E(t)),this.modalChanged$.emit(t,{modalId:(null==o?void 0:o.modalId)??null,isOpen:!1})}clearModalForDocument(e){const t=e??this.getActiveDocumentId();this.dispatch(M(t))}getActiveModalForDocument(e){return this.getDocumentStateOrThrow(e).activeModal}isModalOpenForDocument(e){const t=this.getDocumentStateOrThrow(e).activeModal;return(null==t?void 0:t.isOpen)??!1}openMenuForDocument(e,t,o,s){const n=s??this.getActiveDocumentId();this.dispatch($(n,{menuId:e,triggeredByCommandId:t,triggeredByItemId:o})),this.menuChanged$.emit(n,{menuId:e,isOpen:!0})}closeMenuForDocument(e,t){const o=t??this.getActiveDocumentId();this.dispatch(A(o,e)),this.menuChanged$.emit(o,{menuId:e,isOpen:!1})}toggleMenuForDocument(e,t,o,s){const n=s??this.getActiveDocumentId();!!this.getDocumentStateOrThrow(n).openMenus[e]?(this.dispatch(A(n,e)),this.menuChanged$.emit(n,{menuId:e,isOpen:!1})):(this.dispatch($(n,{menuId:e,triggeredByCommandId:t,triggeredByItemId:o})),this.menuChanged$.emit(n,{menuId:e,isOpen:!0}))}closeAllMenusForDocument(e){const t=e??this.getActiveDocumentId();this.dispatch(x(t))}isMenuOpenForDocument(e,t){return!!this.getDocumentStateOrThrow(t).openMenus[e]}getOpenMenusForDocument(e){return Object.values(this.getDocumentStateOrThrow(e).openMenus)}};se.id="ui";let ne=se;const ie={activeToolbars:{},activeSidebars:{},activeModal:null,openMenus:{},sidebarTabs:{}},ae={documents:{},disabledCategories:[],hiddenItems:[]};function de(e){return e.ui??null}function re(e,t){const o=de(e);return(null==o?void 0:o.documents[t])??null}function ce(e,t){return`${e}-${t}`}function le(e,t,o,s){const n=re(e,t);return n?n.activeToolbars[ce(o,s)]??null:null}function ue(e,t,o,s){const n=re(e,t);return n?n.activeSidebars[ce(o,s)]??null:null}const he={manifest:o,create:(e,o)=>new ne(t,e,o),reducer:(e=ae,t)=>{var o;switch(t.type){case s:{const{documentId:o,schema:s}=t.payload,n={};return Object.values(s.toolbars).forEach(e=>{if(e.permanent&&e.position){const t=`${e.position.placement}-${e.position.slot}`;n[t]={toolbarId:e.id,isOpen:!0}}}),{...e,documents:{...e.documents,[o]:{...ie,activeToolbars:n}}}}case n:{const{documentId:o}=t.payload,{[o]:s,...n}=e.documents;return{...e,documents:n}}case i:{const{documentId:o,placement:s,slot:n,toolbarId:i}=t.payload,a=e.documents[o]||ie,d=`${s}-${n}`;return{...e,documents:{...e.documents,[o]:{...a,activeToolbars:{...a.activeToolbars,[d]:{toolbarId:i,isOpen:!0}}}}}}case a:{const{documentId:o,placement:s,slot:n}=t.payload,i=e.documents[o];if(!i)return e;const a=`${s}-${n}`,d=i.activeToolbars[a];return d?{...e,documents:{...e.documents,[o]:{...i,activeToolbars:{...i.activeToolbars,[a]:{...d,isOpen:!1}}}}}:e}case d:{const{documentId:o,placement:s,slot:n,sidebarId:i,activeTab:a}=t.payload,d=e.documents[o]||ie,r=`${s}-${n}`;return{...e,documents:{...e.documents,[o]:{...d,activeSidebars:{...d.activeSidebars,[r]:{sidebarId:i,isOpen:!0}},...a&&{sidebarTabs:{...d.sidebarTabs,[i]:a}}}}}}case r:{const{documentId:o,placement:s,slot:n}=t.payload,i=e.documents[o];if(!i)return e;const a=`${s}-${n}`,d=i.activeSidebars[a];return d?{...e,documents:{...e.documents,[o]:{...i,activeSidebars:{...i.activeSidebars,[a]:{...d,isOpen:!1}}}}}:e}case c:{const{documentId:o,sidebarId:s,tabId:n}=t.payload,i=e.documents[o]||ie;return{...e,documents:{...e.documents,[o]:{...i,sidebarTabs:{...i.sidebarTabs,[s]:n}}}}}case l:{const{documentId:o,modalId:s}=t.payload,n=e.documents[o]||ie;return{...e,documents:{...e.documents,[o]:{...n,activeModal:{modalId:s,isOpen:!0},openMenus:{}}}}}case u:{const{documentId:o}=t.payload,s=e.documents[o];return(null==s?void 0:s.activeModal)?{...e,documents:{...e.documents,[o]:{...s,activeModal:{...s.activeModal,isOpen:!1}}}}:e}case h:{const{documentId:s}=t.payload,n=e.documents[s];return n?(null==(o=n.activeModal)?void 0:o.isOpen)?e:{...e,documents:{...e.documents,[s]:{...n,activeModal:null}}}:e}case m:{const{documentId:o,menuState:s}=t.payload,n=e.documents[o]||ie;return{...e,documents:{...e.documents,[o]:{...n,openMenus:{[s.menuId]:s}}}}}case p:{const{documentId:o,menuId:s}=t.payload,n=e.documents[o];if(!n)return e;const{[s]:i,...a}=n.openMenus;return{...e,documents:{...e.documents,[o]:{...n,openMenus:a}}}}case g:{const{documentId:o}=t.payload,s=e.documents[o];return s?{...e,documents:{...e.documents,[o]:{...s,openMenus:{}}}}:e}case b:return{...e,disabledCategories:t.payload.categories};case I:return{...e,hiddenItems:t.payload.hiddenItems};default:return e}},initialState:ae};exports.CLEANUP_UI_STATE=n,exports.CLEAR_MODAL=h,exports.CLOSE_ALL_MENUS=g,exports.CLOSE_MENU=p,exports.CLOSE_MODAL=u,exports.CLOSE_SIDEBAR_SLOT=r,exports.CLOSE_TOOLBAR_SLOT=a,exports.INIT_UI_STATE=s,exports.OPEN_MENU=m,exports.OPEN_MODAL=l,exports.SET_ACTIVE_SIDEBAR=d,exports.SET_ACTIVE_TOOLBAR=i,exports.SET_DISABLED_CATEGORIES=b,exports.SET_HIDDEN_ITEMS=I,exports.SET_SIDEBAR_TAB=c,exports.UIPlugin=ne,exports.UIPluginPackage=he,exports.UI_ATTRIBUTES=B,exports.UI_PLUGIN_ID=t,exports.UI_SELECTORS=j,exports.cleanupUIState=f,exports.clearModal=M,exports.closeAllMenus=x,exports.closeMenu=A,exports.closeModal=E,exports.closeSidebarSlot=D,exports.closeToolbarSlot=y,exports.computeHiddenItems=H,exports.extractCategories=function(e){const t=k(e);return Array.from(t.categories).sort()},exports.extractItemCategories=G,exports.generateUIStylesheet=P,exports.getItemResponsiveMetadata=function(e,t,o){const s=W(t,o);return(null==s?void 0:s.items.get(e))??null},exports.getStylesheetConfig=function(e={}){return{...N,...e}},exports.getUIItemProps=function(e,t){var o;return{[B.ITEM]:e.id,[B.CATEGORIES]:(null==(o=e.categories)?void 0:o.join(" "))||void 0,...t}},exports.initUIState=S,exports.isSidebarOpen=function(e,t,o,s,n){const i=ue(e,t,o,s);return!(!i||!i.isOpen)&&(!n||i.sidebarId===n)},exports.isToolbarOpen=function(e,t,o,s,n){const i=le(e,t,o,s);return!(!i||!i.isOpen)&&(!n||i.toolbarId===n)},exports.manifest=o,exports.mergeUISchema=F,exports.openMenu=$,exports.openModal=T,exports.removeFromSchema=function(e,t){const o={...e};return t.toolbars&&(o.toolbars={...o.toolbars},t.toolbars.forEach(e=>delete o.toolbars[e])),t.menus&&(o.menus={...o.menus},t.menus.forEach(e=>delete o.menus[e])),t.sidebars&&(o.sidebars={...o.sidebars},t.sidebars.forEach(e=>delete o.sidebars[e])),t.commands&&(o.toolbars=function(e,t){const o={};for(const[s,n]of Object.entries(e))o[s]={...n,items:n.items.filter(e=>"command-button"===e.type?!t.includes(e.commandId):"group"===e.type?e.items.some(e=>"command-button"!==e.type||!t.includes(e.commandId)):"tab-group"!==e.type||e.tabs.some(e=>!t.includes(e.commandId)))};return o}(o.toolbars,t.commands),o.menus=function(e,t){const o={};for(const[s,n]of Object.entries(e))o[s]={...n,items:n.items.filter(e=>"command"===e.type?!t.includes(e.commandId):"section"!==e.type||e.items.some(e=>"command"!==e.type||!t.includes(e.commandId)))};return o}(o.menus,t.commands)),o},exports.resolveResponsiveMetadata=W,exports.selectSidebarSlot=ue,exports.selectToolbarSlot=le,exports.selectUIDocumentState=re,exports.selectUIState=de,exports.setActiveSidebar=O,exports.setActiveToolbar=v,exports.setDisabledCategories=L,exports.setHiddenItems=_,exports.setSidebarTab=C;
2
2
  //# sourceMappingURL=index.cjs.map