@manifest-editor/shell 2.0.3-next.0.f58cbd8 → 2.1.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.
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuButton as r,BackgroundActionMenuDivider as i,BackgroundActionMenuInfoButton as a,BackgroundActionMenuInlineAction as o,BackgroundActionMenuItem as s,BackgroundActionMenuLabel as c,BackgroundActionMenuMeta as l,BackgroundActionMenuPanel as u,BackgroundActionMenuProgressBar as d,BackgroundActionMenuRoot as f,BackgroundActionMenuSection as p,BackgroundActionMenuText as m,BackgroundActionMenuTrigger as h,CheckIcon as g,CreatorGrid as _,DefaultTooltipContent as v,DownloadButton as y,EmptyState as b,ErrorMessage as x,Form as S,GridIcon as C,IconButton as w,IconHandle as T,ManifestEditorLogo as E,Modal as ee,ModalBackSlot as te,PaddedSidebarContainer as ne,PanelSideMenu as re,ResetIcon as ie,ResizeHandle as ae,Sidebar as oe,SidebarContent as D,SidebarHeader as se,SidebarTabs as ce,Spinner as le,Tab as ue,TabList as de,TabPanel as fe,Tabs as pe,ToastRegion as me,Tooltip as he,TooltipTrigger as ge,useLocalStorage as _e,useOptionalLocalStorage as ve,useOptionalLocalStorage as ye}from"@manifest-editor/components";import{Component as be,Fragment as xe,Suspense as Se,createContext as O,createElement as Ce,createRef as we,forwardRef as Te,memo as Ee,useCallback as k,useContext as A,useEffect as j,useImperativeHandle as De,useLayoutEffect as M,useMemo as N,useReducer as Oe,useRef as P,useState as F}from"react";import{Fragment as I,jsx as L,jsxs as R}from"react/jsx-runtime";import{create as ke,createStore as Ae,useStore as je}from"zustand";import Me from"localforage";import{AtlasStoreProvider as Ne,AtlasStoreProvider as Pe,AtlasStoreReactContext as Fe,CollectionContext as Ie,ImageServiceLoaderContext as Le,ManifestContext as Re,ReactVaultContext as ze,ResourceReactContext as Be,VaultProvider as Ve,useAtlasStore as He,useCurrentAnnotationMetadata as Ue,useExistingVault as We,useManifest as Ge,useResourceContext as Ke,useVault as z,useVaultSelector as qe}from"react-iiif-vault";import{isSpecificResource as Je,toRef as B}from"@iiif/parser";import V,{ThemeProvider as Ye,css as H}from"styled-components";import Xe from"react-accessible-dropdown-menu-hook";import{original as Ze,produce as Qe}from"immer";import{EditorInstance as $e}from"@manifest-editor/editor-api";import{useToastState as et}from"@react-stately/toast";import{getValue as tt}from"@iiif/helpers";import*as nt from"@iiif/helpers/vault";import{Vault as rt}from"@iiif/helpers/vault";import{Creator as it,matchBasedOnResource as at}from"@manifest-editor/creator-api";import{ErrorBoundary as ot}from"react-error-boundary";import{addReference as st,batchActions as ct,modifyEntityField as lt,reorderEntityField as ut,requestResource as dt}from"@iiif/helpers/vault/actions";import{actionListFromResource as ft}from"@iiif/helpers/vault/utility";import pt from"mitt";import{useDebounce as mt}from"tiny-use-debounce";import{Transition as ht}from"react-transition-group";import gt from"shallowequal";import{ImageServiceLoader as _t}from"@atlas-viewer/iiif-image-api";import{MessagePortClientVault as vt}from"@manifest-editor/client-vault";var yt=!0,bt=`Invariant failed`;function U(e,t){if(!e){if(yt)throw Error(bt);var n=typeof t==`function`?t():t,r=n?`${bt}: ${n}`:bt;throw Error(r)}}const xt={previews:[],behaviorPresets:[`auto-advance`,`no-auto-advance`,`repeat`,`no-repeat`,`unordered`,`individuals`,`continuous`,`paged`,`non-paged`,`facing-pages`,`multi-part`,`together`,`sequence`,`thumbnail-nav`,`no-nav`,`hidden`],defaultPreview:null,editorConfig:{},newTemplates:null,i18n:{advancedLanguageMode:!1,availableLanguages:[`en`,`cy`,`nl`,`fr`],defaultLanguage:`en`},editorFeatureFlags:{enableMultiImageCanvases:!0,enableMultiMediaCanvases:!0,annotationPopups:!1,rememberCanvasId:!0,manifestGridOptions:!1,rememberLeftPanelId:!1},uploadBackends:[],plugins:{apps:{}},export:{baseIdentifier:null,version:3}};function St(e,t){if(!e&&!t)return;let n={...e||{}};for(let[e,r]of Object.entries(t||{}))n[e]={...n[e]||{},...r||{}};return n}function Ct(e,t){if(!e&&!t)return;let n={...e?.apps||{}};for(let[e,r]of Object.entries(t?.apps||{})){let t=n[e]||{};n[e]={...t,...r,settings:{...t.settings||{},...r.settings||{}}}}return{apps:n}}function wt(...e){let t={};for(let n of e)n&&(t={...t,...n,editorConfig:St(t.editorConfig,n.editorConfig),editorFeatureFlags:t.editorFeatureFlags||n.editorFeatureFlags?{...t.editorFeatureFlags||{},...n.editorFeatureFlags||{}}:void 0,i18n:t.i18n||n.i18n?{...t.i18n||{},...n.i18n||{}}:void 0,export:t.export||n.export?{...t.export||{},...n.export||{}}:void 0,plugins:Ct(t.plugins,n.plugins)});return t}function Tt(...e){return wt(xt,...e)}const Et=O(xt),Dt=O(()=>{});function Ot(){return A(Et)}function kt(){return A(Dt)}function At({children:e,config:t,saveConfig:n}){let[r,i]=F(null),a=N(()=>Tt(t,r),[t,r]),o=k(e=>{i(t=>wt(t,e)),n&&n(e)},[n]);return L(Dt.Provider,{value:o,children:L(Et.Provider,{value:a,children:e})})}const jt=`@manifest-editor/canvas-progress`,Mt=`status`,Nt=new Set([`queued`,`pending`,`done`]);function Pt(e){return typeof e==`string`?e:e?.id||null}function Ft(e){return typeof e==`string`&&Nt.has(e)?e:`none`}function It(e){return typeof e==`string`&&Nt.has(e)}function Lt(e,t){let n=Pt(t);return n?Ft(e.getResourceMeta(n,jt)?.[Mt]):`none`}function Rt(e,t){let n=Pt(t);return n?Ft(e?.iiif?.meta?.[n]?.[jt]?.[Mt]):`none`}function zt(e,t,n){let r=Pt(t);if(!r)return`none`;let i=It(n)?n:void 0;return e.setMetaValue([r,jt,Mt],i),i||`none`}function Bt(e,t){return zt(e,t,`none`)}function Vt(e,t,n){let r={};for(let i of t){let t=Pt(i);t&&(r[t]=zt(e,i,n))}return r}function Ht(e,t){return Vt(e,t,`none`)}function Ut(e){return{getStatus(t){return Lt(e,t)},setStatus(t,n){return zt(e,t,n)},clearStatus(t){return Bt(e,t)},setStatuses(t,n){return Vt(e,t,n)},clearStatuses(t){return Ht(e,t)}}}function Wt(e,t=new Set){function n(e){let n=Pt(e);n&&t.add(n)}function r(e){for(let t of e)n(t)}return{trackedResourceIds:t,getStatus(t){return e.getStatus(t)},setStatus(t,r){return n(t),e.setStatus(t,r)},clearStatus(t){return n(t),e.clearStatus(t)},setStatuses(t,n){return r(t),e.setStatuses(t,n)},clearStatuses(t){return r(t),e.clearStatuses(t)},clearTrackedStatuses(){e.clearStatuses(Array.from(t).map(e=>({id:e,type:`Canvas`}))),t.clear()}}}function Gt(e){let t=Pt(e);return qe(e=>t?Rt(e,t):`none`,[t])}function Kt(e){let t=z(),n=Pt(e),r=N(()=>Ut(t),[t]);return N(()=>({setStatus(e){return r.setStatus(n,e)},clearStatus(){return r.clearStatus(n)},getStatus(){return r.getStatus(n)}}),[r,n])}const qt={queued:{label:`Queued`,stripClass:`bg-zinc-400/80`,badgeClass:`bg-zinc-500`,dimOverlay:!0},pending:{label:`In progress`,stripClass:`bg-amber-400/90 animate-pulse`,badgeClass:`bg-amber-500`},done:{label:`Done`,stripClass:`bg-me-primary-500`,badgeClass:`bg-me-primary-500`}};function Jt({className:e}){return R(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[L(`circle`,{cx:`12`,cy:`12`,r:`9`}),L(`path`,{d:`M12 7v5l2.5 2.5`})]})}function Yt({className:e}){return R(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,children:[L(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:`currentColor`,strokeWidth:`2.5`,strokeOpacity:`0.3`}),L(`path`,{d:`M12 3a9 9 0 0 1 9 9`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`})]})}function Xt({className:e}){return L(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:L(`path`,{d:`M5 12l4 4 8-8`})})}function Zt({resource:e,status:t,className:n}){return t?L($t,{status:t,className:n}):L(Qt,{resource:e,className:n})}function Qt({resource:e,className:t}){return L($t,{status:Gt(e),className:t})}function $t({status:e,className:t}){if(e===`none`)return null;let n=qt[e];return R(I,{children:[n.dimOverlay&&L(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 z-10 bg-white/40`}),L(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-0 z-10 h-[3px] rounded-t-sm ${n.stripClass} ${t||``}`}),R(`div`,{className:`pointer-events-none absolute right-1.5 top-1.5 z-10 flex h-[18px] w-[18px] items-center justify-center rounded-full ${n.badgeClass} shadow-md ring-2 ring-white/70`,title:n.label,children:[L(`span`,{className:`sr-only`,children:n.label}),e===`queued`&&L(Jt,{className:`h-2.5 w-2.5 text-white`}),e===`pending`&&L(Yt,{className:`h-2.5 w-2.5 animate-spin text-white`}),e===`done`&&L(Xt,{className:`h-2.5 w-2.5 text-white`})]})]})}function en(e,t){return`${e}::${t.type}::${t.id}`}function tn(e=[],t=[]){let n=[],r=new Set;for(let e=t.length-1;e>=0;--e){let i=t[e];i&&!r.has(i.id)&&(r.add(i.id),n.unshift(i))}return[...e.filter(e=>!r.has(e.id)),...n]}function nn(e){return[...e].sort((e,t)=>{let n=(e.section||``).localeCompare(t.section||``);if(n!==0)return n;let r=(e.order||0)-(t.order||0);if(r!==0)return r;let i=e.label.localeCompare(t.label);return i===0?e.id.localeCompare(t.id):i})}function rn(e){return e instanceof Error?{message:e.message,stack:e.stack,detail:e}:{message:typeof e==`string`?e:`Background action failed`,detail:e}}function an(e){return e&&typeof e==`object`&&typeof e.message==`string`?{message:e.message,stack:typeof e.stack==`string`?e.stack:void 0,detail:e.detail}:rn(e)}function on(e,t){return e.resourceTypes?.length?e.resourceTypes.includes(t.type):!0}function sn({definitions:e,instances:t,systemContext:n,targets:r,onSupportsError:i}){let a=nn(e),o=[];for(let e of r){let r=[];for(let o of a){if(!on(o,e))continue;let a=en(o.id,e),s={...n,definition:o,target:e,instanceKey:a,instance:t[a]};try{if(o.supports&&!o.supports(s))continue}catch(e){i?.(o,e);continue}r.push({definition:o,target:e,instanceKey:a,instance:t[a],context:s})}r.length&&o.push({id:`${e.scope}:${e.type}:${e.id}`,label:e.label,target:e,actions:r})}return o}let cn=0;function ln(e){return cn+=1,`${e}-${Date.now()}-${cn}`}function un(e,t,n,r=Date.now()){return{id:ln(`event`),createdAt:r,type:e,message:t,data:n}}function W(e,t,n,r,i=Date.now()){return{...e,events:[...e.events,un(t,n,r,i)]}}function dn(e){return e.filter(e=>String(e.type)!==`progress`)}function fn(e){return{...e,logs:[...e.logs],events:dn(e.events),progress:e.progress?{...e.progress}:void 0}}function pn(e,t,n){if(!_n(n.status))return e;let r=e[t]||[],i=fn(n),a=r.findIndex(e=>e.runId===n.runId),o=a>=0?r.map((e,t)=>t===a?i:e):[...r,i];return{...e,[t]:o}}function G(e,t,n){let r=e.instances[t];if(!r)return{instances:e.instances,histories:e.histories};let i=n(r);return{instances:{...e.instances,[t]:i},histories:pn(e.histories,t,i)}}function mn(e){return Number.isFinite(e)?Math.min(100,Math.max(0,e)):0}function hn(e){let t=e,n=typeof t.current==`number`&&Number.isFinite(t.current)?t.current:void 0,r=typeof t.total==`number`&&Number.isFinite(t.total)?t.total:void 0;return{percent:mn(typeof t.percent==`number`&&Number.isFinite(t.percent)?t.percent:typeof n==`number`&&typeof r==`number`&&r>0?n/r*100:0),current:n,total:r,label:t.label}}function gn(e){return e===`preparing`||e===`running`}function _n(e){return e===`complete`||e===`error`||e===`cancelled`}function vn(e){return e===`queued`||e===`running`||e===`complete`||e===`skipped`||e===`error`||e===`cancelled`}function yn(e){return!e||e===`queued`||e===`running`}function bn(e){return e===`complete`||e===`skipped`||e===`error`||e===`cancelled`}function xn(e){if(e!==void 0)try{return JSON.parse(JSON.stringify(e))}catch{return}}function Sn(e){return e&&{message:e.message,stack:e.stack,detail:xn(e.detail)}}function Cn(e){return{...e,error:Sn(e.error)||null,result:xn(e.result),logs:e.logs.map(e=>({...e,data:xn(e.data)})),events:dn(e.events).map(e=>({...e,data:xn(e.data)})),progress:e.progress?{...e.progress}:void 0}}function wn(e){return{...e,status:On(e.status),input:xn(e.input),result:xn(e.result),error:Sn(e.error)||null}}function Tn(e){return{version:1,data:xn(e.data),tasks:e.tasks.map(wn)}}function En(e){return{version:1,savedAt:Date.now(),instances:Object.fromEntries(Object.entries(e.instances).map(([e,t])=>[e,Cn(t)])),histories:Object.fromEntries(Object.entries(e.histories).map(([e,t])=>[e,t.map(Cn)])),plans:Object.fromEntries(Object.entries(e.plans).map(([e,t])=>[e,Tn(t)]))}}function Dn(e){return!Object.keys(e.instances).length&&!Object.keys(e.histories).length&&!Object.keys(e.plans).length}function On(e){return vn(e)?e:`queued`}function kn(e,t){let n=Date.now(),r=typeof e.id==`string`&&e.id?e.id:`task-${t+1}`;return{...e,id:r,label:typeof e.label==`string`&&e.label?e.label:r,status:On(e.status),error:e.error?an(e.error):null,createdAt:typeof e.createdAt==`number`?e.createdAt:n}}function An(e){return!e||e.version!==1||!Array.isArray(e.tasks)?null:{version:1,data:e.data,tasks:e.tasks.map(kn)}}function jn(e){return{...e,tasks:e.tasks.map(e=>e.status===`running`?{...e,status:`queued`,statusText:`Queued after reload`,startedAt:void 0}:e)}}function Mn(e,t=Date.now()){return{...e,tasks:e.tasks.map(e=>yn(e.status)?{...e,status:`cancelled`,statusText:`Cancelled`,error:null,completedAt:t}:e)}}function Nn(e){return{...e,error:e.error?an(e.error):null,logs:Array.isArray(e.logs)?e.logs:[],events:dn(Array.isArray(e.events)?e.events:[]),resultsAvailable:e.resultsAvailable===!0}}function Pn(e){return!e||e.version!==1?{version:1,savedAt:Date.now(),instances:{},histories:{},plans:{}}:{version:1,savedAt:typeof e.savedAt==`number`?e.savedAt:Date.now(),instances:e.instances||{},histories:e.histories||{},plans:e.plans||{}}}function Fn(e,t){let n=e.tasks.length;if(!n)return;let r=e.tasks.filter(e=>bn(e.status)).length;return hn({current:r,total:n,label:t})}function In(e){return e&&typeof e==`object`&&`taskStatus`in e&&(e.taskStatus===`complete`||e.taskStatus===`skipped`)?{taskStatus:e.taskStatus,result:e.result,statusText:e.statusText}:{taskStatus:`complete`,result:e}}function Ln(e,t){for(let n of t.tasks)!n.target||n.target.type!==`Canvas`||(n.status===`running`?e.setStatus(n.target,`pending`):n.status===`queued`&&e.setStatus(n.target,`queued`))}function Rn(e,t,n){let{store:r,context:i}=e,{instanceKey:a}=i;function o(){return r.getState().plans[a]}function s(){return o()?.tasks||[]}function c(e=[`queued`,`running`]){let t=new Set(e);return s().filter(e=>t.has(On(e.status)))}function l(e,t,n=!1){r.getState().updateActionTask(a,e,t,n)}async function u(e,i={}){let u=c(i.statuses||[`queued`,`running`]),d=s().length,f=u.length,p=i.yieldEveryMs===!1?!1:i.yieldEveryMs??16,m=0;for(let[c,h]of u.entries()){if(t.aborted||zn(m,p)&&(await Bn(),m=Date.now(),t.aborted))throw Error(`Background action cancelled.`);let u=s().find(e=>e.id===h.id)||h,g=s().findIndex(e=>e.id===u.id),_=i.progressLabel?.(u,g,d)||u.label||`Task ${g+1}/${d}`;u.target?.type===`Canvas`&&n.setStatus(u.target,`pending`),l(u.id,{status:`running`,statusText:_,error:null,startedAt:Date.now(),completedAt:void 0},!0),r.getState().setActionStatus(a,`running`,_),r.getState().setActionProgress(a,{current:s().filter(e=>bn(e.status)).length,total:d,label:_});try{let r=await e(u,{index:g,total:d,pendingIndex:c,pendingTotal:f});if(t.aborted)throw Error(`Background action cancelled.`);let i=In(r);l(u.id,{status:i.taskStatus,statusText:i.statusText||(i.taskStatus===`skipped`?`Skipped`:`Complete`),result:i.result,error:null,completedAt:Date.now()},!0),u.target?.type===`Canvas`&&n.setStatus(u.target,`done`)}catch(e){if(t.aborted||Gn(e))throw l(u.id,{status:`cancelled`,statusText:`Cancelled`,error:null,completedAt:Date.now()},!0),e;let n=rn(e);l(u.id,{status:`error`,statusText:n.message,error:n,completedAt:Date.now()},!0),r.getState().appendActionLog(a,`Task failed: ${u.label}`,`warn`,{taskId:u.id,error:n.message})}finally{let e=o();e&&r.getState().setActionProgress(a,{current:e.tasks.filter(e=>bn(e.status)).length,total:d,label:_})}}return s()}return{getAll:s,getPending:()=>c(),update:l,runEach:u}}function zn(e,t){return t!==!1&&(!e||Date.now()-e>=t)}function Bn(){return new Promise(e=>{setTimeout(e,0)})}function Vn(e=[]){let t=null,n=null,r=null;return Ae((i,a)=>{async function o(){if(r&&(clearTimeout(r),r=null),!t||!n||!a().hasHydrated)return;let e=En(a());if(Dn(e)){await t.clear(n);return}await t.save(n,e)}function s(e=!1){if(!(!t||!n||!a().hasHydrated)){if(e){o();return}r&&clearTimeout(r),r=setTimeout(()=>{o()},300)}}return{definitions:tn([],e),instances:{},histories:{},plans:{},controllers:{},hasHydrated:!0,setDefinitions(e){i(t=>{let n=tn([],e),r=new Set(n.map(e=>e.id)),i={},a={},o={};for(let[e,n]of Object.entries(t.instances))r.has(n.actionId)&&(i[e]=n);for(let[e,n]of Object.entries(t.histories)){let t=n.filter(e=>r.has(e.actionId));t.length&&(a[e]=t)}for(let[e,n]of Object.entries(t.plans))i[e]&&(o[e]=n);return{definitions:n,instances:i,histories:a,plans:o,controllers:Object.fromEntries(Object.entries(t.controllers).filter(([e])=>i[e]?.status&&gn(i[e].status)))}}),s()},setPersistence(e,r){t=e,n=e&&r?r:null,i({hasHydrated:!t})},hydrate(e){let t=Pn(e),n=new Map(a().definitions.map(e=>[e.id,e])),r={},o={},c={};for(let[e,r]of Object.entries(t.histories)){let t=(Array.isArray(r)?r:[]).map(Nn).filter(e=>n.has(e.actionId));t.length&&(o[e]=t)}for(let[e,i]of Object.entries(t.instances)){let a=Nn(i),s=n.get(a.actionId);if(!s)continue;let l=a,u=An(t.plans[e]);if(gn(a.status))if(a.cancelRequestedAt){let e=Date.now();u=u&&Mn(u,e),l=W({...a,status:`cancelled`,statusText:`Cancelled`,completedAt:e,cancelledAt:e},`status`,`Cancelled`,{status:`cancelled`},e)}else if(s.resumable&&u)u=jn(u),l=W({...a,status:`running`,statusText:`Resuming`,completedAt:void 0,cancelledAt:void 0},`status`,`Resuming`,{status:`running`});else{let e=Date.now();l=W({...a,status:`cancelled`,statusText:`Interrupted by page reload`,completedAt:e,cancelledAt:e},`status`,`Interrupted by page reload`,{status:`cancelled`},e)}r[e]=l,o=pn(o,e,l),u&&(c[e]=u)}i({instances:r,histories:o,plans:c,controllers:{},hasHydrated:!0}),s(!0)},persist(e=!1){s(e)},flushPersistence:o,registerAction(e){return i(t=>({definitions:tn(t.definitions,[e])})),s(),()=>a().unregisterAction(e.id)},unregisterAction(e){i(t=>{let n={};for(let[r,i]of Object.entries(t.instances))i.actionId!==e&&(n[r]=i);let r={};for(let[n,i]of Object.entries(t.histories)){let t=i.filter(t=>t.actionId!==e);t.length&&(r[n]=t)}let i={...t.plans},a={...t.controllers};for(let[n,r]of Object.entries(t.instances))r.actionId===e&&(a[n]?.abort(),delete a[n],delete i[n]);return{definitions:t.definitions.filter(t=>t.id!==e),instances:n,histories:r,plans:i,controllers:a}}),s(!0)},resetAction(e){i(t=>{t.controllers[e]?.abort();let n={...t.instances},r={...t.histories},i={...t.plans},a={...t.controllers};return delete n[e],delete r[e],delete i[e],delete a[e],{instances:n,histories:r,plans:i,controllers:a}}),s(!0)},startAction(e,t,n,r){let a=Date.now();i(i=>{let o={...i.plans};return delete o[e],{instances:{...i.instances,[e]:{id:e,runId:ln(`run`),actionId:t.id,target:n,label:t.label,status:`preparing`,statusText:`Preparing`,error:null,result:void 0,resultsAvailable:!1,logs:[],events:[un(`started`,`Preparing`,{status:`preparing`},a)],progress:void 0,startedAt:a,completedAt:void 0,cancelRequestedAt:void 0,cancelledAt:void 0}},plans:o,controllers:r?{...i.controllers,[e]:r}:i.controllers}}),s(!0)},resumeAction(e,t){let n=Date.now();i(r=>({...G(r,e,e=>W({...e,status:`running`,statusText:`Resuming`,completedAt:void 0,cancelledAt:void 0},`status`,`Resuming`,{status:`running`},n)),controllers:{...r.controllers,[e]:t}})),s(!0)},cancelAction(e){let t=a().controllers[e],n=a().instances[e];if(!n||!gn(n.status))return;let r=Date.now();i(t=>{let n=G(t,e,e=>W(W({...e,status:`cancelled`,statusText:`Cancelled`,completedAt:r,cancelledAt:r,cancelRequestedAt:e.cancelRequestedAt||r},`cancel-requested`,`Cancelling`,void 0,r),`status`,`Cancelled`,{status:`cancelled`},r)),i=t.plans[e];return{...n,plans:i?{...t.plans,[e]:Mn(i,r)}:t.plans,controllers:Object.fromEntries(Object.entries(t.controllers).filter(([t])=>t!==e))}}),s(!0),t?.abort()},setActionLabel(e,t){let n=Date.now();i(r=>({...G(r,e,e=>W({...e,label:t},`label`,t,{label:t},n))})),s()},setActionStatus(e,t,n){let r=Date.now(),a=_n(t)?r:void 0;i(i=>({...G(i,e,e=>W({...e,status:t,statusText:n,completedAt:a,cancelledAt:t===`cancelled`?r:void 0},`status`,n||t,{status:t},r)),controllers:gn(t)?i.controllers:Object.fromEntries(Object.entries(i.controllers).filter(([t])=>t!==e))})),s(_n(t))},setActionError(e,t,n){let r=Date.now(),a=rn(t);i(t=>({...G(t,e,e=>W({...e,status:`error`,statusText:n,error:a,completedAt:r,cancelledAt:void 0},`error`,n||a.message,a,r)),controllers:Object.fromEntries(Object.entries(t.controllers).filter(([t])=>t!==e))})),s(!0)},appendActionLog(e,t,n=`info`,r){let a=Date.now(),o={id:ln(`log`),createdAt:a,level:n,message:t,data:r};i(i=>({...G(i,e,e=>W({...e,logs:[...e.logs,o]},`log`,t,{level:n,data:r},a))})),s()},setActionProgress(e,t){let n=t?hn(t):void 0;i(t=>({...G(t,e,e=>({...e,progress:n}))}))},setResult(e,t){let n=Date.now();i(r=>({...G(r,e,e=>W({...e,result:t},`result`,`Result recorded`,void 0,n))})),s(!0)},setResultsAvailable(e,t){let n=Date.now();i(r=>({...G(r,e,e=>W({...e,resultsAvailable:t},`results-available`,t?`Results available`:`Results hidden`,{available:t},n))})),s(!0)},setActionPlan(e,t){let n=An(t);n&&(i(t=>({...G(t,e,e=>({...e,progress:Fn(n,`Queued`)})),plans:{...t.plans,[e]:n}})),s(!0))},updateActionTask(e,t,n,r=!1){i(r=>{let i=r.plans[e];if(!i)return r;let a=i.tasks.map(e=>e.id===t?kn({...e,...n,status:n.status?On(n.status):e.status,error:n.error?an(n.error):n.error===null?null:e.error},0):e),o={...i,tasks:a};return{...G(r,e,e=>({...e,progress:Fn(o,n.statusText||n.label)})),plans:{...r.plans,[e]:o}}}),s(r)}}})}function Hn(e,t,n){let{store:r,context:i}=e,{instanceKey:a}=i,o=Rn(e,t,n);return{...i,canvasProgress:n,instance:r.getState().instances[a],plan:r.getState().plans[a],tasks:o,signal:t,prepareData:e.prepareData,setActionLabel(e){r.getState().setActionLabel(a,e)},setActionStatus(e,t){r.getState().setActionStatus(a,e,t)},setActionError(e,t){r.getState().setActionError(a,e,t)},appendActionLog(e,t,n){r.getState().appendActionLog(a,e,t,n)},setActionProgress(e){r.getState().setActionProgress(a,e)},setResult(e){r.getState().setResult(a,e)},setResultsAvailable(e){r.getState().setResultsAvailable(a,e)}}}function Un(e){return!!e&&typeof e==`object`&&e.version===1&&Array.isArray(e.tasks)}async function Wn(e){let{store:t,context:n}=e,{definition:r,instanceKey:i,target:a}=n,o=t.getState().instances[i],s=t.getState().controllers[i];if((o?.status===`preparing`||o?.status===`running`)&&(!e.resume||s))return o;let c=new AbortController,l=c.signal,u=Wt(n.canvasProgress),d=()=>c.abort();e.signal&&(e.signal.aborted?c.abort():e.signal.addEventListener(`abort`,d,{once:!0})),e.resume&&o&&gn(o.status)?t.getState().resumeAction(i,c):t.getState().startAction(i,r,a,c);let f=()=>{let e=t.getState().instances[i];e&&!_n(e.status)&&t.getState().setActionStatus(i,`cancelled`,`Cancelled`)};try{if(!e.resume&&r.prepare){let n=await r.prepare(Hn(e,l,u));if(l.aborted)return f(),t.getState().instances[i];if(n===!1)return t.getState().setActionStatus(i,`idle`),t.getState().instances[i];Un(n)&&t.getState().setActionPlan(i,n)}if(l.aborted)return f(),t.getState().instances[i];let n=t.getState().plans[i];n&&Ln(u,n),t.getState().setActionStatus(i,`running`,e.resume?`Resuming`:`Running`);let a=await r.run(Hn(e,l,u));if(l.aborted)return f(),t.getState().instances[i];let o=t.getState().instances[i];a!==void 0&&o&&!_n(o.status)&&t.getState().setResult(i,a),o=t.getState().instances[i],o&&gn(o.status)&&((a!==void 0||o?.resultsAvailable)&&t.getState().setResultsAvailable(i,!0),t.getState().setActionStatus(i,`complete`,`Complete`))}catch(e){l.aborted||Gn(e)?f():t.getState().setActionError(i,e,`Error`)}finally{u.clearTrackedStatuses(),e.signal?.removeEventListener(`abort`,d),await t.getState().flushPersistence()}return t.getState().instances[i]}function Gn(e){return e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))}function Kn(e){return JSON.stringify([e.appId,e.instanceId,e.rootResource.type,e.rootResource.id])}let qn;function Jn(){if(typeof window>`u`)return null;let e=Me.createInstance({name:`manifest-editor-background-actions-v1`,storeName:`background-actions`});return{async load(t){return e.getItem(Kn(t))},async save(t,n){await e.setItem(Kn(t),n)},async clear(t){await e.removeItem(Kn(t))}}}function Yn(){return qn===void 0&&(qn=Jn()),qn}const Xn=O(null);function Zn({children:e,persistence:t,persistenceKey:n}){let r=q(),i=ii(),a=N(()=>Vn(),[]),o=r.layout.backgroundActions||[],s=N(()=>t===!1?null:t||Yn(),[t]),c=N(()=>n||null,[n]);return j(()=>{a.getState().setDefinitions(o)},[a,o]),j(()=>{let e=c||{appId:i.appId,instanceId:i.instanceId,rootResource:{id:`global`,type:`Manifest`}},t=!1;return a.getState().setPersistence(s,e),s?(s.load(e).then(e=>{t||a.getState().hydrate(e)}).catch(e=>{console.warn(`[manifest-editor/background-actions] Failed to load persisted actions`,e),t||a.getState().hydrate(null)}),()=>{t=!0,a.getState().flushPersistence()}):(a.getState().hydrate(null),()=>void 0)},[i.appId,i.instanceId,s,c?.appId,c?.instanceId,c?.rootResource.id,c?.rootResource.type,a]),j(()=>{let e=()=>{a.getState().flushPersistence()};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[a]),Ce(Xn.Provider,{value:a},e)}function Qn(){let e=A(Xn);if(!e)throw Error(`useBackgroundActionsStore must be used within a BackgroundActionsProvider`);return e}function K(e=e=>e){return je(Qn(),e)}function $n(e){return K(t=>t.instances[e])}function er(e){return K(t=>t.histories[e]||[])}async function tr(e){let t;try{await fetch(e).then(e=>e.json().catch(e=>{console.error(`'${e}' happened!`)})).then(e=>{t={...e}})}catch(e){console.log(e)}return t}function nr(e,t,n){return`create_${e}_${t}_${B(n)?.type||`unknown`}`}function rr(e,t,n=`text/json`){let r=e instanceof Blob?e:new Blob([e],{type:n}),i=document.createElement(`a`);i.download=t,i.href=window.URL.createObjectURL(r);let a=new MouseEvent(`click`,{view:window,bubbles:!0,cancelable:!0});i.dispatchEvent(a),i.remove()}async function ir(e){return navigator.clipboard.writeText(typeof e==`string`?e:JSON.stringify(e,null,2))}function ar(){return`${Math.random().toString(36).substr(2)}-${Date.now().toString(36)}`}function or(e,t){let{default:n,config:r,...i}=e,a={metadata:n,layout:{leftPanels:[],rightPanels:[],centerPanels:[],...i},config:r};return t?t(a):a}function sr(e,t,n){return{...e,metadata:t,config:wt(e.config||{},n.config||{}),layout:{...e.layout,leftPanels:[...(e.layout.leftPanels||[]).filter(e=>n?.leftPanelIds?n.leftPanelIds.includes(e.id):!0),...n?.leftPanels||[]],annotations:[...n?.annotations||[],...e.layout.annotations||[]],canvasEditors:[...n?.canvasEditors||[],...e.layout.canvasEditors||[]],creators:[...n?.creators||[],...e.layout.creators||[]],background:[...e.layout?.background||[],...n?.background||[]],backgroundActions:tn(e.layout?.backgroundActions||[],n?.backgroundActions||[]),editors:[...n?.editors||[],...e.layout.editors||[]],rightPanels:[...e.layout.rightPanels||[],...n?.rightPanels||[]],centerPanels:[...e.layout.centerPanels||[],...n?.centerPanels||[]],modals:[...e.layout.modals||[],...n?.modalPanels||[]]}}}const cr=[`leftPanels`,`centerPanels`,`rightPanels`,`modalPanels`,`annotations`,`canvasEditors`,`editors`,`creators`,`background`,`backgroundActions`],lr={plugins:[],enabled:[],disabled:[],globalApps:{},apps:{}};function ur(){return lr}function dr(e=[]){return Array.from(new Set(e.filter(Boolean)))}function fr(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function pr(e={}){return{...e,enabled:dr(e.enabled||[]),disabled:dr(e.disabled||[]),settings:e.settings?{...e.settings}:void 0}}function mr(e){let t={};for(let[n,r]of Object.entries(e?.apps||{}))t[n]=pr(r);return t}function hr(e={},t){return{...e,enabled:dr([...(e.enabled||[]).filter(e=>e!==t),t]),disabled:(e.disabled||[]).filter(e=>e!==t)}}function gr(e={},t){return{...e,enabled:(e.enabled||[]).filter(e=>e!==t),disabled:dr([...(e.disabled||[]).filter(e=>e!==t),t])}}function _r(e={},t){return{...e,enabled:(e.enabled||[]).filter(e=>e!==t),disabled:(e.disabled||[]).filter(e=>e!==t)}}function vr(e={},t={}){let n=e.enabled||[],r=t.enabled||[],i=e.disabled||[],a=t.disabled||[];return n.length===r.length&&n.every((e,t)=>e===r[t])&&i.length===a.length&&i.every((e,t)=>e===a[t])&&JSON.stringify(e.settings||{})===JSON.stringify(t.settings||{})}function yr(e,t){let{default:n,config:r,settings:i,...a}=e,o={metadata:n,extension:{...a,config:r},settings:i};return t?t(o):o}function br(e){return!!e&&`metadata`in e&&`extension`in e}function xr(e){return br(e)?e:yr(e)}function Sr(e=[]){return e.map(xr)}function Cr(e,t,n){let r=e.metadata.supports;if(!r)return!0;if(r.apps?.length){let e=new Set([n,t?.metadata.id].filter(Boolean));if(!r.apps.some(t=>e.has(t)))return!1}if(r.projectTypes?.length){let e=t?.metadata.projectType;if(!e||!r.projectTypes.includes(e))return!1}return!0}function wr(e,t,n){let r=e.metadata.supports;if(!r)return null;if(r.apps?.length){let e=new Set([n,t?.metadata.id].filter(Boolean));if(!r.apps.some(t=>e.has(t)))return`This plugin does not support the current app.`}if(r.projectTypes?.length){let e=t?.metadata.projectType;if(!e||!r.projectTypes.includes(e))return`This plugin does not support the current project type.`}return null}function Tr(e,t,n){let r=n?t.apps[n]:void 0,i=n?t.globalApps[n]:void 0,a=e.metadata.id;return r?.disabled?.includes(a)?!1:r?.enabled?.includes(a)?!0:i?.disabled?.includes(a)?!1:i?.enabled?.includes(a)?!0:t.disabled.includes(a)?!1:t.enabled.includes(a)?!0:e.metadata.defaultEnabled===!0}function Er(e,t,n){let r=n?t.apps[n]:void 0,i=n?t.globalApps[n]:void 0,a=e.metadata.id;return r?.disabled?.includes(a)||r?.enabled?.includes(a)?`workspace`:i?.disabled?.includes(a)||i?.enabled?.includes(a)?`global`:t.disabled.includes(a)||t.enabled.includes(a)?`provider`:`default`}function Dr(e,t,n){let r=[],i=new Set,a=new Set,o=new Set(e.plugins.filter(r=>Cr(r,t,n)&&Tr(r,e,n)).map(e=>e.metadata.id)),s=new Map(e.plugins.map(e=>[e.metadata.id,e])),c=new Set;function l(e){let u=e.metadata.id;if(i.has(u))return!0;if(a.has(u))return!1;if(c.has(u))return Ir(`Plugin "${u}" was not enabled because its dependency graph contains a cycle.`),a.add(u),!1;c.add(u);for(let r of e.metadata.dependencies||[]){let e=s.get(r);if(!e||!o.has(r))return Ir(`Plugin "${u}" was not enabled because dependency "${r}" is not enabled.`),c.delete(u),a.add(u),!1;if(!Cr(e,t,n))return Ir(`Plugin "${u}" was not enabled because dependency "${r}" is not compatible.`),c.delete(u),a.add(u),!1;if(!l(e))return c.delete(u),a.add(u),!1}return c.delete(u),r.push(e),i.add(u),!0}for(let r of e.plugins)Cr(r,t,n)&&Tr(r,e,n)&&l(r);return r}function Or(e,t){let n=e?.settings?.[t];return fr(n)?n:{}}function kr(e={},t,n){return{...e,settings:{...e.settings||{},[t]:n}}}function Ar(e={},t){let n={...e.settings||{}};return delete n[t],{...e,settings:n}}function jr(e){return{...e?.settings?.defaults||{}}}function Mr(e,t,n){let r=e.plugins.find(e=>e.metadata.id===t),i=n?e.globalApps[n]:void 0,a=n?e.apps[n]:void 0;return{...jr(r),...Or(i,t),...Or(a,t)}}function Nr(e,t){return{getSettings(n){return Mr(e,n,t)}}}function Pr(e,t,n,r,i){let a=new Map(t.plugins.map(e=>[e.metadata.id,e])),o=[],s=[],c=new Set,l=e;function u(e){let t=e.metadata.id;if(!o.includes(t)){if(c.has(t)){s.push(`${t} has a circular dependency`);return}c.add(t);for(let t of e.metadata.dependencies||[]){let e=a.get(t);if(!e){s.push(`${t} is not available`);continue}if(!Cr(e,r,i)){s.push(`${e.metadata.label} is not compatible`);continue}u(e)}c.delete(t),l=hr(l,t),o.push(t)}}return u(n),s.length?{config:e,enabledIds:[],blocked:s}:{config:l,enabledIds:o,blocked:s}}function Fr(e,t){return t===`modalPanels`?e.layout.modals||[]:e.layout[t]||[]}function Ir(e){globalThis.process?.env?.NODE_ENV!==`production`&&console.warn(`[manifest-editor/plugin] ${e}`)}function Lr(e,t,n,r){if(!r?.length)return;let i=[];for(let a of r){if(n.has(a.id)){Ir(`Plugin "${e.metadata.id}" contribution "${a.id}" for "${t}" was skipped because that id already exists.`);continue}n.add(a.id),i.push(a)}return i.length?i:void 0}function Rr(e,t){let n=t.extension,r={config:n.config,disableSideEffects:n.disableSideEffects};for(let i of cr){let a=Lr(t,i,new Set(Fr(e,i).map(e=>e.id)),n[i]);a&&(r[i]=a)}return r}function zr(e,t,n){if(!t.length)return e;let r=e,i=new Set;for(let a of t){if(!Cr(a,e,n))continue;let t=(a.metadata.dependencies||[]).filter(e=>!i.has(e));if(t.length){Ir(`Plugin "${a.metadata.id}" was not applied because dependencies are missing or later in the plugin order: ${t.join(`, `)}`);continue}let o=Rr(r,a);r=sr(r,r.metadata,o),i.add(a.metadata.id)}let a=new Set(e.layout.leftPanels.map(e=>e.id)),o=r.layout.leftPanels.filter(e=>e.divide),s=r.layout.leftPanels.filter(e=>!e.divide),c=!1,l=s.map(e=>!c&&!a.has(e.id)?(c=!0,{...e,separator:!0}):e);return{...r,config:wt(e.config||{},...t.filter(e=>i.has(e.metadata.id)).map(e=>e.extension.config||{}),r.config||{}),layout:{...r.layout,leftPanels:[...l,...o],backgroundActions:tn([],r.layout.backgroundActions||[])}}}function Br({plugins:e=[],enabled:t=[],disabled:n=[],globalPluginConfig:r}={}){let i=(e=[])=>Array.from(new Set(e.filter(Boolean)));return Ae(a=>({plugins:e,enabled:i(t),disabled:i(n),globalApps:mr(r),apps:{},setProviderState(e){a(t=>({...t,plugins:e.plugins||[],enabled:i(e.enabled||[]),disabled:i(e.disabled||[]),globalApps:mr(e.globalPluginConfig)}))},setAppConfig(e,t){let n=pr(t);a(t=>vr(t.apps[e],n)?t:{...t,apps:{...t.apps,[e]:n}})},setGlobalConfig(e){a(t=>({...t,globalApps:mr(e)}))},setGlobalAppConfig(e,t){let n=pr(t);a(t=>vr(t.globalApps[e],n)?t:{...t,globalApps:{...t.globalApps,[e]:n}})},enable(e,t,n=`workspace`){a(r=>({...r,...n===`global`?{globalApps:{...r.globalApps,[e]:hr(r.globalApps[e],t)}}:{apps:{...r.apps,[e]:hr(r.apps[e],t)}}}))},disable(e,t,n=`workspace`){a(r=>({...r,...n===`global`?{globalApps:{...r.globalApps,[e]:gr(r.globalApps[e],t)}}:{apps:{...r.apps,[e]:gr(r.apps[e],t)}}}))}}))}const Vr=O(null),Hr=O({});function Ur({plugins:e,enabled:t,disabled:n,globalPluginConfig:r,saveGlobalPluginConfig:i,children:a}){let o=N(()=>Sr(e),[e]),s=N(()=>Br({plugins:o,enabled:t,disabled:n,globalPluginConfig:r}),[]);j(()=>{s.getState().setProviderState({plugins:o,enabled:t,disabled:n,globalPluginConfig:r})},[s,o,t,n,r]);let c=N(()=>({globalPluginConfig:r,saveGlobalPluginConfig:i}),[r,i]);return Ce(Hr.Provider,{value:c},Ce(Vr.Provider,{value:s},a))}function Wr(){return A(Vr)}function Gr(){let e=Wr();if(!e)throw Error(`usePluginStoreApi must be used within <PluginProvider />`);return e}function Kr(e){let t=Wr();return t?je(t,e):e(ur())}function qr(){return Kr(e=>({plugins:e.plugins,enabled:e.enabled,disabled:e.disabled,globalApps:e.globalApps,apps:e.apps}))}function Jr(e){let t=A(ni),n=A(ti),r=qr(),i=e||t?.appId;return N(()=>Dr(r,n,i),[r,n,i])}function Yr(){let e=Wr();return N(()=>e?{enable(t,n,r){e.getState().enable(t,n,r||`workspace`)},disable(t,n,r){e.getState().disable(t,n,r||`workspace`)},setAppConfig(t,n){e.getState().setAppConfig(t,n)},setGlobalAppConfig(t,n){e.getState().setGlobalAppConfig(t,n)}}:{enable(){},disable(){},setAppConfig(){},setGlobalAppConfig(){}},[e])}function Xr(e){let t=A(ni),n=qr(),r=e||t?.appId;return N(()=>Nr(n,r),[n,r])}function Zr(e,t){let n=A(ni),r=qr(),i=t||n?.appId;return N(()=>Mr(r,e,i),[r,e,i])}function Qr(e,t){let n=A(ni),r=Wr(),i=qr(),a=Ot(),o=kt(),{saveGlobalPluginConfig:s}=A(Hr),c=t||n?.appId||``,l=i.plugins.find(t=>t.metadata.id===e)||null,u=c?i.globalApps[c]:void 0,d=c?i.apps[c]:void 0,f=N(()=>jr(l||void 0),[l]),p=N(()=>Or(u,e),[u,e]),m=N(()=>Or(d,e),[d,e]),h=N(()=>Mr(i,e,c),[i,e,c]),g=k(e=>{c&&(r?.getState().setAppConfig(c,e),o({plugins:{...a.plugins||{},apps:{...a.plugins?.apps||{},[c]:e}}}))},[a.plugins,c,o,r]),_=k(t=>{g(kr(d||{},e,t))},[g,e,d]),v=k(()=>{g(Ar(d||{},e))},[g,e,d]),y=k(async e=>{if(!c||!s)return;let t=i.globalApps[c]||{},n={apps:{...i.globalApps,[c]:e}};r?.getState().setGlobalAppConfig(c,e);try{await s(n)}catch(e){throw r?.getState().setGlobalAppConfig(c,t),e}},[c,s,i.globalApps,r]),b=k(async t=>{await y(kr(u||{},e,t))},[u,y,e]),x=k(async()=>{await y(Ar(u||{},e))},[u,y,e]);return{plugin:l,appId:c,defaults:f,global:p,workspace:m,effective:h,canSaveGlobal:!!s,setWorkspaceSettings:_,resetWorkspaceSettings:v,setGlobalSettings:b,resetGlobalSettings:x}}function $r(e,t){let n=qr(),r=N(()=>Dr(n,e,t),[n,e,t]);return N(()=>zr(e,r,t),[e,r,t])}function ei({config:e}){let t=A(ni),n=Wr(),r=t?.appId,i=r?e?.plugins?.apps?.[r]:void 0;return j(()=>{!n||!r||n.getState().setAppConfig(r,i||{})},[n,r,i]),null}const ti=O(null),ni=O(null),ri=O({state:null,setState:()=>{}});function ii(){let e=A(ni);return U(e,`Hook useAppInstance must be used inside <AppProvider />`),e}function q(){let e=A(ti);return U(e,`Hook useApp must be used inside <AppProvider />`),e}function ai(){return A(ri)}function oi(e){let[t,n,r]=_e(`app-state/${e.appId}/${e.instanceId}`,e.initialState||{}),i=k(e=>{let t=r.current?JSON.parse(r.current||`{}`):{},i=(typeof e==`function`?e(t):e)||{};n({...t,...i})},[]);j(()=>{e.args&&i(e.args)},[e.appId]);let a=N(()=>({state:t||{},setState:i}),[i,t]);return L(ri.Provider,{value:a,children:e.children})}function si({instanceId:e,appId:t,args:n,definition:r,children:i,initialState:a}){let o=N(()=>({instanceId:e,appId:t,args:n}),[e,t,n]),s=N(()=>a||{},[e]),c=$r(r,t);return L(At,{config:c.config||{},children:L(ti.Provider,{value:c,children:L(ni.Provider,{value:o,children:L(oi,{instanceId:o.instanceId,appId:o.appId,args:o.args,initialState:s,children:i})})})})}const ci=O(null);function li(){let e=A(ci);return U(e,`Hook useApps must be used inside <MultiAppProvider />`),e}function ui(e,t=!1){let[n,r]=ye(`SelectedApplication`,e||{id:`splash`},!t);return[n,r]}function di({apps:e,initialApp:t,saveCurrentApp:n=!0,instanceId:r,children:i,config:a={}}){let{defaultApp:o=`splash`,collectionApp:s=`collection-editor`,manifestApp:c=`manifest-editor`}=a,[l,u]=ui(t,n),d=e=>{e===`Manifest`&&u({id:c}),e===`Collection`&&u({id:s})},f=N(()=>({currentApp:l||{id:o},initialApp:t||{id:o},apps:e,changeApp:u,changeProjectType:d}),[t,e,l]),p=e[f.currentApp.id];return!l||!p?null:L(si,{appId:l.id,definition:p,instanceId:l.id+r,args:l.args,children:L(ci.Provider,{value:f,children:i})})}const fi=V.div`
1
+ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuButton as r,BackgroundActionMenuDivider as i,BackgroundActionMenuInfoButton as a,BackgroundActionMenuInlineAction as o,BackgroundActionMenuItem as s,BackgroundActionMenuLabel as c,BackgroundActionMenuMeta as l,BackgroundActionMenuPanel as u,BackgroundActionMenuProgressBar as d,BackgroundActionMenuRoot as f,BackgroundActionMenuSection as p,BackgroundActionMenuText as m,BackgroundActionMenuTrigger as h,CheckIcon as g,CreatorGrid as _,DefaultTooltipContent as v,DownloadButton as y,EmptyState as b,ErrorMessage as x,Form as S,GridIcon as C,IconButton as w,IconHandle as T,ManifestEditorLogo as E,Modal as ee,ModalBackSlot as te,PaddedSidebarContainer as ne,PanelSideMenu as re,ResetIcon as ie,ResizeHandle as ae,Sidebar as oe,SidebarContent as D,SidebarHeader as se,SidebarTabs as ce,Spinner as le,Tab as ue,TabList as de,TabPanel as fe,Tabs as pe,ToastRegion as me,Tooltip as he,TooltipTrigger as ge,useLocalStorage as _e,useOptionalLocalStorage as ve,useOptionalLocalStorage as ye}from"@manifest-editor/components";import{Component as be,Fragment as xe,Suspense as Se,createContext as O,createElement as Ce,createRef as we,forwardRef as Te,memo as Ee,useCallback as k,useContext as A,useEffect as j,useImperativeHandle as De,useLayoutEffect as M,useMemo as N,useReducer as Oe,useRef as P,useState as F}from"react";import{Fragment as I,jsx as L,jsxs as R}from"react/jsx-runtime";import{create as ke,createStore as Ae,useStore as je}from"zustand";import Me from"localforage";import{AtlasStoreProvider as Ne,AtlasStoreProvider as Pe,AtlasStoreReactContext as Fe,CollectionContext as Ie,ImageServiceLoaderContext as Le,ManifestContext as Re,ReactVaultContext as ze,ResourceReactContext as Be,VaultProvider as Ve,useAtlasStore as He,useCurrentAnnotationMetadata as Ue,useExistingVault as We,useManifest as Ge,useResourceContext as Ke,useVault as z,useVaultSelector as qe}from"react-iiif-vault";import{isSpecificResource as Je,toRef as B}from"@iiif/parser";import V,{ThemeProvider as Ye,css as H}from"styled-components";import Xe from"react-accessible-dropdown-menu-hook";import{original as Ze,produce as Qe}from"immer";import{EditorInstance as $e}from"@manifest-editor/editor-api";import{useToastState as et}from"@react-stately/toast";import{getValue as tt}from"@iiif/helpers";import*as nt from"@iiif/helpers/vault";import{Vault as rt}from"@iiif/helpers/vault";import{Creator as it,matchBasedOnResource as at}from"@manifest-editor/creator-api";import{ErrorBoundary as ot}from"react-error-boundary";import{addReference as st,batchActions as ct,modifyEntityField as lt,reorderEntityField as ut,requestResource as dt}from"@iiif/helpers/vault/actions";import{actionListFromResource as ft}from"@iiif/helpers/vault/utility";import pt from"mitt";import{useDebounce as mt}from"tiny-use-debounce";import{Transition as ht}from"react-transition-group";import gt from"shallowequal";import{ImageServiceLoader as _t}from"@atlas-viewer/iiif-image-api";import{MessagePortClientVault as vt}from"@manifest-editor/client-vault";var yt=!0,bt=`Invariant failed`;function U(e,t){if(!e){if(yt)throw Error(bt);var n=typeof t==`function`?t():t,r=n?`${bt}: ${n}`:bt;throw Error(r)}}const xt={previews:[],behaviorPresets:[`auto-advance`,`no-auto-advance`,`repeat`,`no-repeat`,`unordered`,`individuals`,`continuous`,`paged`,`non-paged`,`facing-pages`,`multi-part`,`together`,`sequence`,`thumbnail-nav`,`no-nav`,`hidden`],defaultPreview:null,editorConfig:{},newTemplates:null,i18n:{advancedLanguageMode:!1,availableLanguages:[`en`,`cy`,`nl`,`fr`],defaultLanguage:`en`},editorFeatureFlags:{enableMultiImageCanvases:!0,enableMultiMediaCanvases:!0,annotationPopups:!1,rememberCanvasId:!0,manifestGridOptions:!1,rememberLeftPanelId:!1},uploadBackends:[],plugins:{apps:{}},export:{baseIdentifier:null,version:3}};function St(e,t){if(!e&&!t)return;let n={...e||{}};for(let[e,r]of Object.entries(t||{}))n[e]={...n[e]||{},...r||{}};return n}function Ct(e,t){if(!e&&!t)return;let n={...e?.apps||{}};for(let[e,r]of Object.entries(t?.apps||{})){let t=n[e]||{};n[e]={...t,...r,settings:{...t.settings||{},...r.settings||{}}}}return{apps:n}}function wt(...e){let t={};for(let n of e)n&&(t={...t,...n,editorConfig:St(t.editorConfig,n.editorConfig),editorFeatureFlags:t.editorFeatureFlags||n.editorFeatureFlags?{...t.editorFeatureFlags||{},...n.editorFeatureFlags||{}}:void 0,i18n:t.i18n||n.i18n?{...t.i18n||{},...n.i18n||{}}:void 0,export:t.export||n.export?{...t.export||{},...n.export||{}}:void 0,plugins:Ct(t.plugins,n.plugins)});return t}function Tt(...e){return wt(xt,...e)}const Et=O(xt),Dt=O(()=>{});function Ot(){return A(Et)}function kt(){return A(Dt)}function At({children:e,config:t,saveConfig:n}){let[r,i]=F(null),a=N(()=>Tt(t,r),[t,r]),o=k(e=>{i(t=>wt(t,e)),n&&n(e)},[n]);return L(Dt.Provider,{value:o,children:L(Et.Provider,{value:a,children:e})})}const jt=`@manifest-editor/canvas-progress`,Mt=`status`,Nt=new Set([`queued`,`pending`,`done`]);function Pt(e){return typeof e==`string`?e:e?.id||null}function Ft(e){return typeof e==`string`&&Nt.has(e)?e:`none`}function It(e){return typeof e==`string`&&Nt.has(e)}function Lt(e,t){let n=Pt(t);return n?Ft(e.getResourceMeta(n,jt)?.[Mt]):`none`}function Rt(e,t){let n=Pt(t);return n?Ft(e?.iiif?.meta?.[n]?.[jt]?.[Mt]):`none`}function zt(e,t,n){let r=Pt(t);if(!r)return`none`;let i=It(n)?n:void 0;return e.setMetaValue([r,jt,Mt],i),i||`none`}function Bt(e,t){return zt(e,t,`none`)}function Vt(e,t,n){let r={};for(let i of t){let t=Pt(i);t&&(r[t]=zt(e,i,n))}return r}function Ht(e,t){return Vt(e,t,`none`)}function Ut(e){return{getStatus(t){return Lt(e,t)},setStatus(t,n){return zt(e,t,n)},clearStatus(t){return Bt(e,t)},setStatuses(t,n){return Vt(e,t,n)},clearStatuses(t){return Ht(e,t)}}}function Wt(e,t=new Set){function n(e){let n=Pt(e);n&&t.add(n)}function r(e){for(let t of e)n(t)}return{trackedResourceIds:t,getStatus(t){return e.getStatus(t)},setStatus(t,r){return n(t),e.setStatus(t,r)},clearStatus(t){return n(t),e.clearStatus(t)},setStatuses(t,n){return r(t),e.setStatuses(t,n)},clearStatuses(t){return r(t),e.clearStatuses(t)},clearTrackedStatuses(){e.clearStatuses(Array.from(t).map(e=>({id:e,type:`Canvas`}))),t.clear()}}}function Gt(e){let t=Pt(e);return qe(e=>t?Rt(e,t):`none`,[t])}function Kt(e){let t=z(),n=Pt(e),r=N(()=>Ut(t),[t]);return N(()=>({setStatus(e){return r.setStatus(n,e)},clearStatus(){return r.clearStatus(n)},getStatus(){return r.getStatus(n)}}),[r,n])}const qt={queued:{label:`Queued`,stripClass:`bg-zinc-400/80`,badgeClass:`bg-zinc-500`,dimOverlay:!0},pending:{label:`In progress`,stripClass:`bg-amber-400/90 animate-pulse`,badgeClass:`bg-amber-500`},done:{label:`Done`,stripClass:`bg-me-primary-500`,badgeClass:`bg-me-primary-500`}};function Jt({className:e}){return R(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[L(`circle`,{cx:`12`,cy:`12`,r:`9`}),L(`path`,{d:`M12 7v5l2.5 2.5`})]})}function Yt({className:e}){return R(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,children:[L(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:`currentColor`,strokeWidth:`2.5`,strokeOpacity:`0.3`}),L(`path`,{d:`M12 3a9 9 0 0 1 9 9`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`})]})}function Xt({className:e}){return L(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:L(`path`,{d:`M5 12l4 4 8-8`})})}function Zt({resource:e,status:t,className:n}){return t?L($t,{status:t,className:n}):L(Qt,{resource:e,className:n})}function Qt({resource:e,className:t}){return L($t,{status:Gt(e),className:t})}function $t({status:e,className:t}){if(e===`none`)return null;let n=qt[e];return R(I,{children:[n.dimOverlay&&L(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 z-10 bg-white/40`}),L(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-0 z-10 h-[3px] rounded-t-sm ${n.stripClass} ${t||``}`}),R(`div`,{className:`pointer-events-none absolute right-1.5 top-1.5 z-10 flex h-[18px] w-[18px] items-center justify-center rounded-full ${n.badgeClass} shadow-md ring-2 ring-white/70`,title:n.label,children:[L(`span`,{className:`sr-only`,children:n.label}),e===`queued`&&L(Jt,{className:`h-2.5 w-2.5 text-white`}),e===`pending`&&L(Yt,{className:`h-2.5 w-2.5 animate-spin text-white`}),e===`done`&&L(Xt,{className:`h-2.5 w-2.5 text-white`})]})]})}function en(e,t){return`${e}::${t.type}::${t.id}`}function tn(e=[],t=[]){let n=[],r=new Set;for(let e=t.length-1;e>=0;--e){let i=t[e];i&&!r.has(i.id)&&(r.add(i.id),n.unshift(i))}return[...e.filter(e=>!r.has(e.id)),...n]}function nn(e){return[...e].sort((e,t)=>{let n=(e.section||``).localeCompare(t.section||``);if(n!==0)return n;let r=(e.order||0)-(t.order||0);if(r!==0)return r;let i=e.label.localeCompare(t.label);return i===0?e.id.localeCompare(t.id):i})}function rn(e){return e instanceof Error?{message:e.message,stack:e.stack,detail:e}:{message:typeof e==`string`?e:`Background action failed`,detail:e}}function an(e){return e&&typeof e==`object`&&typeof e.message==`string`?{message:e.message,stack:typeof e.stack==`string`?e.stack:void 0,detail:e.detail}:rn(e)}function on(e,t){return e.resourceTypes?.length?e.resourceTypes.includes(t.type):!0}function sn({definitions:e,instances:t,systemContext:n,targets:r,onSupportsError:i}){let a=nn(e),o=[];for(let e of r){let r=[];for(let o of a){if(!on(o,e))continue;let a=en(o.id,e),s={...n,definition:o,target:e,instanceKey:a,instance:t[a]};try{if(o.supports&&!o.supports(s))continue}catch(e){i?.(o,e);continue}r.push({definition:o,target:e,instanceKey:a,instance:t[a],context:s})}r.length&&o.push({id:`${e.scope}:${e.type}:${e.id}`,label:e.label,target:e,actions:r})}return o}let cn=0;function ln(e){return cn+=1,`${e}-${Date.now()}-${cn}`}function un(e,t,n,r=Date.now()){return{id:ln(`event`),createdAt:r,type:e,message:t,data:n}}function W(e,t,n,r,i=Date.now()){return{...e,events:[...e.events,un(t,n,r,i)]}}function dn(e){return e.filter(e=>String(e.type)!==`progress`)}function fn(e){return{...e,logs:[...e.logs],events:dn(e.events),progress:e.progress?{...e.progress}:void 0}}function pn(e,t,n){if(!_n(n.status))return e;let r=e[t]||[],i=fn(n),a=r.findIndex(e=>e.runId===n.runId),o=a>=0?r.map((e,t)=>t===a?i:e):[...r,i];return{...e,[t]:o}}function G(e,t,n){let r=e.instances[t];if(!r)return{instances:e.instances,histories:e.histories};let i=n(r);return{instances:{...e.instances,[t]:i},histories:pn(e.histories,t,i)}}function mn(e){return Number.isFinite(e)?Math.min(100,Math.max(0,e)):0}function hn(e){let t=e,n=typeof t.current==`number`&&Number.isFinite(t.current)?t.current:void 0,r=typeof t.total==`number`&&Number.isFinite(t.total)?t.total:void 0;return{percent:mn(typeof t.percent==`number`&&Number.isFinite(t.percent)?t.percent:typeof n==`number`&&typeof r==`number`&&r>0?n/r*100:0),current:n,total:r,label:t.label}}function gn(e){return e===`preparing`||e===`running`}function _n(e){return e===`complete`||e===`error`||e===`cancelled`}function vn(e){return e===`queued`||e===`running`||e===`complete`||e===`skipped`||e===`error`||e===`cancelled`}function yn(e){return!e||e===`queued`||e===`running`}function bn(e){return e===`complete`||e===`skipped`||e===`error`||e===`cancelled`}function xn(e){if(e!==void 0)try{return JSON.parse(JSON.stringify(e))}catch{return}}function Sn(e){return e&&{message:e.message,stack:e.stack,detail:xn(e.detail)}}function Cn(e){return{...e,error:Sn(e.error)||null,result:xn(e.result),logs:e.logs.map(e=>({...e,data:xn(e.data)})),events:dn(e.events).map(e=>({...e,data:xn(e.data)})),progress:e.progress?{...e.progress}:void 0}}function wn(e){return{...e,status:An(e.status),input:xn(e.input),result:xn(e.result),error:Sn(e.error)||null}}function Tn(e){return{version:1,data:xn(e.data),tasks:e.tasks.map(wn)}}function En(e){return{version:1,savedAt:Date.now(),instances:Object.fromEntries(Object.entries(e.instances).map(([e,t])=>[e,Cn(t)])),histories:Object.fromEntries(Object.entries(e.histories).map(([e,t])=>[e,t.map(Cn)])),plans:Object.fromEntries(Object.entries(e.plans).map(([e,t])=>[e,Tn(t)]))}}function Dn(){return{version:1,savedAt:Date.now(),instances:{},histories:{},plans:{}}}function On(e,t){return{version:1,savedAt:t.savedAt,instances:{...e.instances,...t.instances},histories:{...e.histories,...t.histories},plans:{...e.plans,...t.plans}}}function kn(e){return!Object.keys(e.instances).length&&!Object.keys(e.histories).length&&!Object.keys(e.plans).length}function An(e){return vn(e)?e:`queued`}function jn(e,t){let n=Date.now(),r=typeof e.id==`string`&&e.id?e.id:`task-${t+1}`;return{...e,id:r,label:typeof e.label==`string`&&e.label?e.label:r,status:An(e.status),error:e.error?an(e.error):null,createdAt:typeof e.createdAt==`number`?e.createdAt:n}}function Mn(e){return!e||e.version!==1||!Array.isArray(e.tasks)?null:{version:1,data:e.data,tasks:e.tasks.map(jn)}}function Nn(e){return{...e,tasks:e.tasks.map(e=>e.status===`running`?{...e,status:`queued`,statusText:`Queued after reload`,startedAt:void 0}:e)}}function Pn(e,t=Date.now()){return{...e,tasks:e.tasks.map(e=>yn(e.status)?{...e,status:`cancelled`,statusText:`Cancelled`,error:null,completedAt:t}:e)}}function Fn(e){return{...e,error:e.error?an(e.error):null,logs:Array.isArray(e.logs)?e.logs:[],events:dn(Array.isArray(e.events)?e.events:[]),resultsAvailable:e.resultsAvailable===!0}}function In(e){return!e||e.version!==1?Dn():{version:1,savedAt:typeof e.savedAt==`number`?e.savedAt:Date.now(),instances:e.instances||{},histories:e.histories||{},plans:e.plans||{}}}function Ln(e,t,n){let r=e,i=t;if(gn(e.status))if(e.cancelRequestedAt){let t=Date.now();i=i&&Pn(i,t),r=W({...e,status:`cancelled`,statusText:`Cancelled`,completedAt:t,cancelledAt:t},`status`,`Cancelled`,{status:`cancelled`},t)}else if(n.resumable&&i)i=Nn(i),r=W({...e,status:`running`,statusText:`Resuming`,completedAt:void 0,cancelledAt:void 0},`status`,`Resuming`,{status:`running`});else{let t=Date.now();r=W({...e,status:`cancelled`,statusText:`Interrupted by page reload`,completedAt:t,cancelledAt:t},`status`,`Interrupted by page reload`,{status:`cancelled`},t)}return{instance:r,plan:i}}function Rn(e,t){let n=In(e),r=new Map(t.map(e=>[e.id,e])),i={},a={},o={},s=Dn();for(let[e,t]of Object.entries(n.histories)){let n=(Array.isArray(t)?t:[]).map(Fn),i=n.filter(e=>r.has(e.actionId)),o=n.filter(e=>!r.has(e.actionId));i.length&&(a[e]=i),o.length&&(s.histories[e]=o)}for(let[e,t]of Object.entries(n.instances)){let c=Fn(t),l=Mn(n.plans[e]),u=r.get(c.actionId);if(!u){s.instances[e]=Cn(c),l&&(s.plans[e]=Tn(l));continue}let d=Ln(c,l,u);i[e]=d.instance,a=pn(a,e,d.instance),d.plan&&(o[e]=d.plan)}return{instances:i,histories:a,plans:o,deferred:s}}function zn(e,t){let n=e.tasks.length;if(!n)return;let r=e.tasks.filter(e=>bn(e.status)).length;return hn({current:r,total:n,label:t})}function Bn(e){return e&&typeof e==`object`&&`taskStatus`in e&&(e.taskStatus===`complete`||e.taskStatus===`skipped`)?{taskStatus:e.taskStatus,result:e.result,statusText:e.statusText}:{taskStatus:`complete`,result:e}}function Vn(e,t){for(let n of t.tasks)!n.target||n.target.type!==`Canvas`||(n.status===`running`?e.setStatus(n.target,`pending`):n.status===`queued`&&e.setStatus(n.target,`queued`))}function Hn(e,t,n){let{store:r,context:i}=e,{instanceKey:a}=i;function o(){return r.getState().plans[a]}function s(){return o()?.tasks||[]}function c(e=[`queued`,`running`]){let t=new Set(e);return s().filter(e=>t.has(An(e.status)))}function l(e,t,n=!1){r.getState().updateActionTask(a,e,t,n)}async function u(e,i={}){let u=c(i.statuses||[`queued`,`running`]),d=s().length,f=u.length,p=i.yieldEveryMs===!1?!1:i.yieldEveryMs??16,m=0;for(let[c,h]of u.entries()){if(t.aborted||Un(m,p)&&(await Wn(),m=Date.now(),t.aborted))throw Error(`Background action cancelled.`);let u=s().find(e=>e.id===h.id)||h,g=s().findIndex(e=>e.id===u.id),_=i.progressLabel?.(u,g,d)||u.label||`Task ${g+1}/${d}`;u.target?.type===`Canvas`&&n.setStatus(u.target,`pending`),l(u.id,{status:`running`,statusText:_,error:null,startedAt:Date.now(),completedAt:void 0},!0),r.getState().setActionStatus(a,`running`,_),r.getState().setActionProgress(a,{current:s().filter(e=>bn(e.status)).length,total:d,label:_});try{let r=await e(u,{index:g,total:d,pendingIndex:c,pendingTotal:f});if(t.aborted)throw Error(`Background action cancelled.`);let i=Bn(r);l(u.id,{status:i.taskStatus,statusText:i.statusText||(i.taskStatus===`skipped`?`Skipped`:`Complete`),result:i.result,error:null,completedAt:Date.now()},!0),u.target?.type===`Canvas`&&n.setStatus(u.target,`done`)}catch(e){if(t.aborted||Yn(e))throw l(u.id,{status:`cancelled`,statusText:`Cancelled`,error:null,completedAt:Date.now()},!0),e;let n=rn(e);l(u.id,{status:`error`,statusText:n.message,error:n,completedAt:Date.now()},!0),r.getState().appendActionLog(a,`Task failed: ${u.label}`,`warn`,{taskId:u.id,error:n.message})}finally{let e=o();e&&r.getState().setActionProgress(a,{current:e.tasks.filter(e=>bn(e.status)).length,total:d,label:_})}}return s()}return{getAll:s,getPending:()=>c(),update:l,runEach:u}}function Un(e,t){return t!==!1&&(!e||Date.now()-e>=t)}function Wn(){return new Promise(e=>{setTimeout(e,0)})}function Gn(e=[]){let t=null,n=null,r=null,i=Dn();return Ae((a,o)=>{function s(e,t){let n=tn([],t),r=Rn(i,n);return i=r.deferred,{definitions:n,instances:{...e.instances,...r.instances},histories:{...e.histories,...r.histories},plans:{...e.plans,...r.plans},controllers:Object.fromEntries(Object.entries(e.controllers).filter(([t,n])=>n&&e.instances[t]?.status&&gn(e.instances[t].status)))}}async function c(){if(r&&(clearTimeout(r),r=null),!t||!n||!o().hasHydrated)return;let e=On(i,En(o()));if(kn(e)){await t.clear(n);return}await t.save(n,e)}function l(e=!1){if(!(!t||!n||!o().hasHydrated)){if(e){c();return}r&&clearTimeout(r),r=setTimeout(()=>{c()},300)}}return{definitions:tn([],e),instances:{},histories:{},plans:{},controllers:{},hasHydrated:!0,setDefinitions(e){a(t=>s(t,e)),l()},setPersistence(e,r){t=e,n=e&&r?r:null,a({hasHydrated:!t})},hydrate(e){let t=Rn(In(e),o().definitions);i=t.deferred,a({instances:t.instances,histories:t.histories,plans:t.plans,controllers:{},hasHydrated:!0}),l(!0)},persist(e=!1){l(e)},flushPersistence:c,registerAction(e){return a(t=>s(t,tn(t.definitions,[e]))),l(),()=>o().unregisterAction(e.id)},unregisterAction(e){a(t=>{let n={};for(let[r,i]of Object.entries(t.instances))i.actionId!==e&&(n[r]=i);let r={};for(let[n,i]of Object.entries(t.histories)){let t=i.filter(t=>t.actionId!==e);t.length&&(r[n]=t)}let i={...t.plans},a={...t.controllers};for(let[n,r]of Object.entries(t.instances))r.actionId===e&&(a[n]?.abort(),delete a[n],delete i[n]);return{definitions:t.definitions.filter(t=>t.id!==e),instances:n,histories:r,plans:i,controllers:a}}),l(!0)},resetAction(e){a(t=>{t.controllers[e]?.abort();let n={...t.instances},r={...t.histories},i={...t.plans},a={...t.controllers};return delete n[e],delete r[e],delete i[e],delete a[e],{instances:n,histories:r,plans:i,controllers:a}}),l(!0)},startAction(e,t,n,r){let i=Date.now();a(a=>{let o={...a.plans};return delete o[e],{instances:{...a.instances,[e]:{id:e,runId:ln(`run`),actionId:t.id,target:n,label:t.label,status:`preparing`,statusText:`Preparing`,error:null,result:void 0,resultsAvailable:!1,logs:[],events:[un(`started`,`Preparing`,{status:`preparing`},i)],progress:void 0,startedAt:i,completedAt:void 0,cancelRequestedAt:void 0,cancelledAt:void 0}},plans:o,controllers:r?{...a.controllers,[e]:r}:a.controllers}}),l(!0)},resumeAction(e,t){let n=Date.now();a(r=>({...G(r,e,e=>W({...e,status:`running`,statusText:`Resuming`,completedAt:void 0,cancelledAt:void 0},`status`,`Resuming`,{status:`running`},n)),controllers:{...r.controllers,[e]:t}})),l(!0)},cancelAction(e){let t=o().controllers[e],n=o().instances[e];if(!n||!gn(n.status))return;let r=Date.now();a(t=>{let n=G(t,e,e=>W(W({...e,status:`cancelled`,statusText:`Cancelled`,completedAt:r,cancelledAt:r,cancelRequestedAt:e.cancelRequestedAt||r},`cancel-requested`,`Cancelling`,void 0,r),`status`,`Cancelled`,{status:`cancelled`},r)),i=t.plans[e];return{...n,plans:i?{...t.plans,[e]:Pn(i,r)}:t.plans,controllers:Object.fromEntries(Object.entries(t.controllers).filter(([t])=>t!==e))}}),l(!0),t?.abort()},setActionLabel(e,t){let n=Date.now();a(r=>({...G(r,e,e=>W({...e,label:t},`label`,t,{label:t},n))})),l()},setActionStatus(e,t,n){let r=Date.now(),i=_n(t)?r:void 0;a(a=>({...G(a,e,e=>W({...e,status:t,statusText:n,completedAt:i,cancelledAt:t===`cancelled`?r:void 0},`status`,n||t,{status:t},r)),controllers:gn(t)?a.controllers:Object.fromEntries(Object.entries(a.controllers).filter(([t])=>t!==e))})),l(_n(t))},setActionError(e,t,n){let r=Date.now(),i=rn(t);a(t=>({...G(t,e,e=>W({...e,status:`error`,statusText:n,error:i,completedAt:r,cancelledAt:void 0},`error`,n||i.message,i,r)),controllers:Object.fromEntries(Object.entries(t.controllers).filter(([t])=>t!==e))})),l(!0)},appendActionLog(e,t,n=`info`,r){let i=Date.now(),o={id:ln(`log`),createdAt:i,level:n,message:t,data:r};a(a=>({...G(a,e,e=>W({...e,logs:[...e.logs,o]},`log`,t,{level:n,data:r},i))})),l()},setActionProgress(e,t){let n=t?hn(t):void 0;a(t=>({...G(t,e,e=>({...e,progress:n}))}))},setResult(e,t){let n=Date.now();a(r=>({...G(r,e,e=>W({...e,result:t},`result`,`Result recorded`,void 0,n))})),l(!0)},setResultsAvailable(e,t){let n=Date.now();a(r=>({...G(r,e,e=>W({...e,resultsAvailable:t},`results-available`,t?`Results available`:`Results hidden`,{available:t},n))})),l(!0)},setActionPlan(e,t){let n=Mn(t);n&&(a(t=>({...G(t,e,e=>({...e,progress:zn(n,`Queued`)})),plans:{...t.plans,[e]:n}})),l(!0))},updateActionTask(e,t,n,r=!1){a(r=>{let i=r.plans[e];if(!i)return r;let a=i.tasks.map(e=>e.id===t?jn({...e,...n,status:n.status?An(n.status):e.status,error:n.error?an(n.error):n.error===null?null:e.error},0):e),o={...i,tasks:a};return{...G(r,e,e=>({...e,progress:zn(o,n.statusText||n.label)})),plans:{...r.plans,[e]:o}}}),l(r)}}})}function Kn(e,t,n){let{store:r,context:i}=e,{instanceKey:a}=i,o=Hn(e,t,n);return{...i,canvasProgress:n,instance:r.getState().instances[a],plan:r.getState().plans[a],tasks:o,signal:t,prepareData:e.prepareData,setActionLabel(e){r.getState().setActionLabel(a,e)},setActionStatus(e,t){r.getState().setActionStatus(a,e,t)},setActionError(e,t){r.getState().setActionError(a,e,t)},appendActionLog(e,t,n){r.getState().appendActionLog(a,e,t,n)},setActionProgress(e){r.getState().setActionProgress(a,e)},setResult(e){r.getState().setResult(a,e)},setResultsAvailable(e){r.getState().setResultsAvailable(a,e)}}}function qn(e){return!!e&&typeof e==`object`&&e.version===1&&Array.isArray(e.tasks)}async function Jn(e){let{store:t,context:n}=e,{definition:r,instanceKey:i,target:a}=n,o=t.getState().instances[i],s=t.getState().controllers[i];if((o?.status===`preparing`||o?.status===`running`)&&(!e.resume||s))return o;let c=new AbortController,l=c.signal,u=Wt(n.canvasProgress),d=()=>c.abort();e.signal&&(e.signal.aborted?c.abort():e.signal.addEventListener(`abort`,d,{once:!0})),e.resume&&o&&gn(o.status)?t.getState().resumeAction(i,c):t.getState().startAction(i,r,a,c);let f=()=>{let e=t.getState().instances[i];e&&!_n(e.status)&&t.getState().setActionStatus(i,`cancelled`,`Cancelled`)};try{if(!e.resume&&r.prepare){let n=await r.prepare(Kn(e,l,u));if(l.aborted)return f(),t.getState().instances[i];if(n===!1)return t.getState().setActionStatus(i,`idle`),t.getState().instances[i];qn(n)&&t.getState().setActionPlan(i,n)}if(l.aborted)return f(),t.getState().instances[i];let n=t.getState().plans[i];n&&Vn(u,n),t.getState().setActionStatus(i,`running`,e.resume?`Resuming`:`Running`);let a=await r.run(Kn(e,l,u));if(l.aborted)return f(),t.getState().instances[i];let o=t.getState().instances[i];a!==void 0&&o&&!_n(o.status)&&t.getState().setResult(i,a),o=t.getState().instances[i],o&&gn(o.status)&&((a!==void 0||o?.resultsAvailable)&&t.getState().setResultsAvailable(i,!0),t.getState().setActionStatus(i,`complete`,`Complete`))}catch(e){l.aborted||Yn(e)?f():t.getState().setActionError(i,e,`Error`)}finally{u.clearTrackedStatuses(),e.signal?.removeEventListener(`abort`,d),await t.getState().flushPersistence()}return t.getState().instances[i]}function Yn(e){return e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))}function Xn(e){return JSON.stringify([e.appId,e.instanceId,e.rootResource.type,e.rootResource.id])}let Zn;function Qn(){if(typeof window>`u`)return null;let e=Me.createInstance({name:`manifest-editor-background-actions-v1`,storeName:`background-actions`});return{async load(t){return e.getItem(Xn(t))},async save(t,n){await e.setItem(Xn(t),n)},async clear(t){await e.removeItem(Xn(t))}}}function $n(){return Zn===void 0&&(Zn=Qn()),Zn}const er=O(null);function tr({children:e,persistence:t,persistenceKey:n}){let r=q(),i=fi(),a=N(()=>Gn(),[]),o=r.layout.backgroundActions||[],s=N(()=>t===!1?null:t||$n(),[t]),c=N(()=>n||null,[n]);return j(()=>{a.getState().setDefinitions(o)},[a,o]),j(()=>{let e=c||{appId:i.appId,instanceId:i.instanceId,rootResource:{id:`global`,type:`Manifest`}},t=!1;return a.getState().setPersistence(s,e),s?(s.load(e).then(e=>{t||a.getState().hydrate(e)}).catch(e=>{console.warn(`[manifest-editor/background-actions] Failed to load persisted actions`,e),t||a.getState().hydrate(null)}),()=>{t=!0,a.getState().flushPersistence()}):(a.getState().hydrate(null),()=>void 0)},[i.appId,i.instanceId,s,c?.appId,c?.instanceId,c?.rootResource.id,c?.rootResource.type,a]),j(()=>{let e=()=>{a.getState().flushPersistence()};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[a]),Ce(er.Provider,{value:a},e)}function nr(){let e=A(er);if(!e)throw Error(`useBackgroundActionsStore must be used within a BackgroundActionsProvider`);return e}function K(e=e=>e){return je(nr(),e)}function rr(e){return K(t=>t.instances[e])}function ir(e){return K(t=>t.histories[e]||[])}async function ar(e){let t;try{await fetch(e).then(e=>e.json().catch(e=>{console.error(`'${e}' happened!`)})).then(e=>{t={...e}})}catch(e){console.log(e)}return t}function or(e,t,n){return`create_${e}_${t}_${B(n)?.type||`unknown`}`}function sr(e,t,n=`text/json`){let r=e instanceof Blob?e:new Blob([e],{type:n}),i=document.createElement(`a`);i.download=t,i.href=window.URL.createObjectURL(r);let a=new MouseEvent(`click`,{view:window,bubbles:!0,cancelable:!0});i.dispatchEvent(a),i.remove()}async function cr(e){return navigator.clipboard.writeText(typeof e==`string`?e:JSON.stringify(e,null,2))}function lr(){return`${Math.random().toString(36).substr(2)}-${Date.now().toString(36)}`}function ur(e,t){let{default:n,config:r,...i}=e,a={metadata:n,layout:{leftPanels:[],rightPanels:[],centerPanels:[],...i},config:r};return t?t(a):a}function dr(e,t,n){return{...e,metadata:t,config:wt(e.config||{},n.config||{}),layout:{...e.layout,leftPanels:[...(e.layout.leftPanels||[]).filter(e=>n?.leftPanelIds?n.leftPanelIds.includes(e.id):!0),...n?.leftPanels||[]],annotations:[...n?.annotations||[],...e.layout.annotations||[]],canvasEditors:[...n?.canvasEditors||[],...e.layout.canvasEditors||[]],creators:[...n?.creators||[],...e.layout.creators||[]],background:[...e.layout?.background||[],...n?.background||[]],backgroundActions:tn(e.layout?.backgroundActions||[],n?.backgroundActions||[]),editors:[...n?.editors||[],...e.layout.editors||[]],rightPanels:[...e.layout.rightPanels||[],...n?.rightPanels||[]],centerPanels:[...e.layout.centerPanels||[],...n?.centerPanels||[]],modals:[...e.layout.modals||[],...n?.modalPanels||[]]}}}const fr=[`leftPanels`,`centerPanels`,`rightPanels`,`modalPanels`,`annotations`,`canvasEditors`,`editors`,`creators`,`background`,`backgroundActions`],pr={plugins:[],enabled:[],disabled:[],globalApps:{},apps:{}};function mr(){return pr}function hr(e=[]){return Array.from(new Set(e.filter(Boolean)))}function gr(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function _r(e={}){return{...e,enabled:hr(e.enabled||[]),disabled:hr(e.disabled||[]),settings:e.settings?{...e.settings}:void 0}}function vr(e){let t={};for(let[n,r]of Object.entries(e?.apps||{}))t[n]=_r(r);return t}function yr(e={},t){return{...e,enabled:hr([...(e.enabled||[]).filter(e=>e!==t),t]),disabled:(e.disabled||[]).filter(e=>e!==t)}}function br(e={},t){return{...e,enabled:(e.enabled||[]).filter(e=>e!==t),disabled:hr([...(e.disabled||[]).filter(e=>e!==t),t])}}function xr(e={},t){return{...e,enabled:(e.enabled||[]).filter(e=>e!==t),disabled:(e.disabled||[]).filter(e=>e!==t)}}function Sr(e={},t={}){let n=e.enabled||[],r=t.enabled||[],i=e.disabled||[],a=t.disabled||[];return n.length===r.length&&n.every((e,t)=>e===r[t])&&i.length===a.length&&i.every((e,t)=>e===a[t])&&JSON.stringify(e.settings||{})===JSON.stringify(t.settings||{})}function Cr(e,t){let{default:n,config:r,settings:i,...a}=e,o={metadata:n,extension:{...a,config:r},settings:i};return t?t(o):o}function wr(e){return{metadata:e.default,extension:{},settings:e.settings,load:e.load,loadStatus:`idle`}}function Tr(e){return!!e&&`metadata`in e&&`extension`in e}function Er(e){return!!e&&`load`in e&&`default`in e}function Dr(e){return Tr(e)?e:Er(e)?wr(e):Cr(e)}function Or(e=[]){return e.map(Dr)}function kr(e,t){let n=new Map(e.map(e=>[e.metadata.id,e]));return t.map(e=>{let t=n.get(e.metadata.id);return t?t.loadStatus===`loaded`&&e.load?{...t,metadata:e.metadata,load:e.load}:t.loadStatus===`loading`&&e.load?{...e,loadStatus:`loading`}:t.loadStatus===`error`&&e.load?{...e,loadStatus:`error`,loadError:t.loadError}:e:e})}function Ar(e,t,n){let r=e.metadata.supports;if(!r)return!0;if(r.apps?.length){let e=new Set([n,t?.metadata.id].filter(Boolean));if(!r.apps.some(t=>e.has(t)))return!1}if(r.projectTypes?.length){let e=t?.metadata.projectType;if(!e||!r.projectTypes.includes(e))return!1}return!0}function jr(e,t,n){let r=e.metadata.supports;if(!r)return null;if(r.apps?.length){let e=new Set([n,t?.metadata.id].filter(Boolean));if(!r.apps.some(t=>e.has(t)))return`This plugin does not support the current app.`}if(r.projectTypes?.length){let e=t?.metadata.projectType;if(!e||!r.projectTypes.includes(e))return`This plugin does not support the current project type.`}return null}function Mr(e,t,n){let r=n?t.apps[n]:void 0,i=n?t.globalApps[n]:void 0,a=e.metadata.id;return r?.disabled?.includes(a)?!1:r?.enabled?.includes(a)?!0:i?.disabled?.includes(a)?!1:i?.enabled?.includes(a)?!0:t.disabled.includes(a)?!1:t.enabled.includes(a)?!0:e.metadata.defaultEnabled===!0}function Nr(e,t,n){let r=n?t.apps[n]:void 0,i=n?t.globalApps[n]:void 0,a=e.metadata.id;return r?.disabled?.includes(a)||r?.enabled?.includes(a)?`workspace`:i?.disabled?.includes(a)||i?.enabled?.includes(a)?`global`:t.disabled.includes(a)||t.enabled.includes(a)?`provider`:`default`}function Pr(e,t,n){let r=[],i=new Set,a=new Set,o=new Set(e.plugins.filter(r=>Ar(r,t,n)&&Mr(r,e,n)).map(e=>e.metadata.id)),s=new Map(e.plugins.map(e=>[e.metadata.id,e])),c=new Set;function l(e){let u=e.metadata.id;if(i.has(u))return!0;if(a.has(u))return!1;if(c.has(u))return Ur(`Plugin "${u}" was not enabled because its dependency graph contains a cycle.`),a.add(u),!1;c.add(u);for(let r of e.metadata.dependencies||[]){let e=s.get(r);if(!e||!o.has(r))return Ur(`Plugin "${u}" was not enabled because dependency "${r}" is not enabled.`),c.delete(u),a.add(u),!1;if(!Ar(e,t,n))return Ur(`Plugin "${u}" was not enabled because dependency "${r}" is not compatible.`),c.delete(u),a.add(u),!1;if(!l(e))return c.delete(u),a.add(u),!1}return c.delete(u),r.push(e),i.add(u),!0}for(let r of e.plugins)Ar(r,t,n)&&Mr(r,e,n)&&l(r);return r}function Fr(e,t){let n=e?.settings?.[t];return gr(n)?n:{}}function Ir(e={},t,n){return{...e,settings:{...e.settings||{},[t]:n}}}function Lr(e={},t){let n={...e.settings||{}};return delete n[t],{...e,settings:n}}function Rr(e){return{...e?.settings?.defaults||{}}}function zr(e,t,n){let r=e.plugins.find(e=>e.metadata.id===t),i=n?e.globalApps[n]:void 0,a=n?e.apps[n]:void 0;return{...Rr(r),...Fr(i,t),...Fr(a,t)}}function Br(e,t){return{getSettings(n){return zr(e,n,t)}}}function Vr(e,t,n,r,i){let a=new Map(t.plugins.map(e=>[e.metadata.id,e])),o=[],s=[],c=new Set,l=e;function u(e){let t=e.metadata.id;if(!o.includes(t)){if(c.has(t)){s.push(`${t} has a circular dependency`);return}c.add(t);for(let t of e.metadata.dependencies||[]){let e=a.get(t);if(!e){s.push(`${t} is not available`);continue}if(!Ar(e,r,i)){s.push(`${e.metadata.label} is not compatible`);continue}u(e)}c.delete(t),l=yr(l,t),o.push(t)}}return u(n),s.length?{config:e,enabledIds:[],blocked:s}:{config:l,enabledIds:o,blocked:s}}function Hr(e,t){return t===`modalPanels`?e.layout.modals||[]:e.layout[t]||[]}function Ur(e){globalThis.process?.env?.NODE_ENV!==`production`&&console.warn(`[manifest-editor/plugin] ${e}`)}function Wr(e,t,n,r){if(!r?.length)return;let i=[];for(let a of r){if(n.has(a.id)){Ur(`Plugin "${e.metadata.id}" contribution "${a.id}" for "${t}" was skipped because that id already exists.`);continue}n.add(a.id),i.push(a)}return i.length?i:void 0}function Gr(e,t){let n=t.extension,r={config:n.config,disableSideEffects:n.disableSideEffects};for(let i of fr){let a=Wr(t,i,new Set(Hr(e,i).map(e=>e.id)),n[i]);a&&(r[i]=a)}return r}function Kr(e,t,n){if(!t.length)return e;let r=e,i=new Set;for(let a of t){if(!Ar(a,e,n))continue;let t=(a.metadata.dependencies||[]).filter(e=>!i.has(e));if(t.length){Ur(`Plugin "${a.metadata.id}" was not applied because dependencies are missing or later in the plugin order: ${t.join(`, `)}`);continue}let o=Gr(r,a);r=dr(r,r.metadata,o),i.add(a.metadata.id)}let a=new Set(e.layout.leftPanels.map(e=>e.id)),o=r.layout.leftPanels.filter(e=>e.divide),s=r.layout.leftPanels.filter(e=>!e.divide),c=!1,l=s.map(e=>!c&&!a.has(e.id)?(c=!0,{...e,separator:!0}):e);return{...r,config:wt(e.config||{},...t.filter(e=>i.has(e.metadata.id)).map(e=>e.extension.config||{}),r.config||{}),layout:{...r.layout,leftPanels:[...l,...o],backgroundActions:tn([],r.layout.backgroundActions||[])}}}function qr({plugins:e=[],enabled:t=[],disabled:n=[],globalPluginConfig:r}={}){let i=(e=[])=>Array.from(new Set(e.filter(Boolean)));return Ae(a=>({plugins:e,enabled:i(t),disabled:i(n),globalApps:vr(r),apps:{},setProviderState(e){a(t=>({...t,plugins:kr(t.plugins,e.plugins||[]),enabled:i(e.enabled||[]),disabled:i(e.disabled||[]),globalApps:vr(e.globalPluginConfig)}))},setPluginLoading(e){a(t=>({...t,plugins:t.plugins.map(t=>t.metadata.id===e?{...t,loadStatus:`loading`,loadError:void 0}:t)}))},setPluginLoaded(e,t){a(n=>({...n,plugins:n.plugins.map(n=>n.metadata.id===e?{...t,metadata:{...n.metadata,...t.metadata},settings:t.settings||n.settings,load:n.load,loadStatus:`loaded`,loadError:void 0}:n)}))},setPluginLoadError(e,t){a(n=>({...n,plugins:n.plugins.map(n=>n.metadata.id===e?{...n,loadStatus:`error`,loadError:t}:n)}))},setAppConfig(e,t){let n=_r(t);a(t=>Sr(t.apps[e],n)?t:{...t,apps:{...t.apps,[e]:n}})},setGlobalConfig(e){a(t=>({...t,globalApps:vr(e)}))},setGlobalAppConfig(e,t){let n=_r(t);a(t=>Sr(t.globalApps[e],n)?t:{...t,globalApps:{...t.globalApps,[e]:n}})},enable(e,t,n=`workspace`){a(r=>({...r,plugins:r.plugins.map(e=>e.metadata.id===t&&e.loadStatus===`error`?{...e,loadStatus:`idle`,loadError:void 0}:e),...n===`global`?{globalApps:{...r.globalApps,[e]:yr(r.globalApps[e],t)}}:{apps:{...r.apps,[e]:yr(r.apps[e],t)}}}))},disable(e,t,n=`workspace`){a(r=>({...r,...n===`global`?{globalApps:{...r.globalApps,[e]:br(r.globalApps[e],t)}}:{apps:{...r.apps,[e]:br(r.apps[e],t)}}}))}}))}const Jr=O(null),Yr=O({});function Xr({plugins:e,enabled:t,disabled:n,globalPluginConfig:r,saveGlobalPluginConfig:i,children:a}){let o=N(()=>Or(e),[e]),s=N(()=>qr({plugins:o,enabled:t,disabled:n,globalPluginConfig:r}),[]);j(()=>{s.getState().setProviderState({plugins:o,enabled:t,disabled:n,globalPluginConfig:r})},[s,o,t,n,r]);let c=N(()=>({globalPluginConfig:r,saveGlobalPluginConfig:i}),[r,i]);return Ce(Yr.Provider,{value:c},Ce(Jr.Provider,{value:s},a))}function Zr(){return A(Jr)}function Qr(){let e=Zr();if(!e)throw Error(`usePluginStoreApi must be used within <PluginProvider />`);return e}function $r(e){let t=Zr();return t?je(t,e):e(mr())}function ei(){return $r(e=>({plugins:e.plugins,enabled:e.enabled,disabled:e.disabled,globalApps:e.globalApps,apps:e.apps}))}function ti(e){let t=A(ui),n=A(li),r=ei(),i=e||t?.appId;return N(()=>Pr(r,n,i),[r,n,i])}function ni(){let e=Zr();return N(()=>e?{enable(t,n,r){e.getState().enable(t,n,r||`workspace`)},disable(t,n,r){e.getState().disable(t,n,r||`workspace`)},setAppConfig(t,n){e.getState().setAppConfig(t,n)},setGlobalAppConfig(t,n){e.getState().setGlobalAppConfig(t,n)}}:{enable(){},disable(){},setAppConfig(){},setGlobalAppConfig(){}},[e])}function ri(e){let t=A(ui),n=ei(),r=e||t?.appId;return N(()=>Br(n,r),[n,r])}function ii(e,t){let n=A(ui),r=ei(),i=t||n?.appId;return N(()=>zr(r,e,i),[r,e,i])}function ai(e,t){let n=A(ui),r=Zr(),i=ei(),a=Ot(),o=kt(),{saveGlobalPluginConfig:s}=A(Yr),c=t||n?.appId||``,l=i.plugins.find(t=>t.metadata.id===e)||null,u=c?i.globalApps[c]:void 0,d=c?i.apps[c]:void 0,f=N(()=>Rr(l||void 0),[l]),p=N(()=>Fr(u,e),[u,e]),m=N(()=>Fr(d,e),[d,e]),h=N(()=>zr(i,e,c),[i,e,c]),g=k(e=>{c&&(r?.getState().setAppConfig(c,e),o({plugins:{...a.plugins||{},apps:{...a.plugins?.apps||{},[c]:e}}}))},[a.plugins,c,o,r]),_=k(t=>{g(Ir(d||{},e,t))},[g,e,d]),v=k(()=>{g(Lr(d||{},e))},[g,e,d]),y=k(async e=>{if(!c||!s)return;let t=i.globalApps[c]||{},n={apps:{...i.globalApps,[c]:e}};r?.getState().setGlobalAppConfig(c,e);try{await s(n)}catch(e){throw r?.getState().setGlobalAppConfig(c,t),e}},[c,s,i.globalApps,r]),b=k(async t=>{await y(Ir(u||{},e,t))},[u,y,e]),x=k(async()=>{await y(Lr(u||{},e))},[u,y,e]);return{plugin:l,appId:c,defaults:f,global:p,workspace:m,effective:h,canSaveGlobal:!!s,setWorkspaceSettings:_,resetWorkspaceSettings:v,setGlobalSettings:b,resetGlobalSettings:x}}function oi(e,t){let n=ei(),r=Zr(),i=N(()=>Pr(n,e,t),[n,e,t]);return j(()=>{if(r)for(let e of i)!e.load||e.loadStatus===`loading`||e.loadStatus===`loaded`||e.loadStatus===`error`||(r.getState().setPluginLoading(e.metadata.id),e.load().then(t=>{r.getState().setPluginLoaded(e.metadata.id,Dr(t))}).catch(t=>{r.getState().setPluginLoadError(e.metadata.id,si(t))}))},[r,i]),N(()=>Kr(e,i.filter(e=>!e.load||e.loadStatus===`loaded`),t),[e,i,t])}function si(e){return e instanceof Error?e.message:typeof e==`string`?e:`Plugin failed to load.`}function ci({config:e}){let t=A(ui),n=Zr(),r=t?.appId,i=r?e?.plugins?.apps?.[r]:void 0;return j(()=>{!n||!r||n.getState().setAppConfig(r,i||{})},[n,r,i]),null}const li=O(null),ui=O(null),di=O({state:null,setState:()=>{}});function fi(){let e=A(ui);return U(e,`Hook useAppInstance must be used inside <AppProvider />`),e}function q(){let e=A(li);return U(e,`Hook useApp must be used inside <AppProvider />`),e}function pi(){return A(di)}function mi(e){let[t,n,r]=_e(`app-state/${e.appId}/${e.instanceId}`,e.initialState||{}),i=k(e=>{let t=r.current?JSON.parse(r.current||`{}`):{},i=(typeof e==`function`?e(t):e)||{};n({...t,...i})},[]);j(()=>{e.args&&i(e.args)},[e.appId]);let a=N(()=>({state:t||{},setState:i}),[i,t]);return L(di.Provider,{value:a,children:e.children})}function hi({instanceId:e,appId:t,args:n,definition:r,children:i,initialState:a}){let o=N(()=>({instanceId:e,appId:t,args:n}),[e,t,n]),s=N(()=>a||{},[e]),c=oi(r,t);return L(At,{config:c.config||{},children:L(li.Provider,{value:c,children:L(ui.Provider,{value:o,children:L(mi,{instanceId:o.instanceId,appId:o.appId,args:o.args,initialState:s,children:i})})})})}const gi=O(null);function _i(){let e=A(gi);return U(e,`Hook useApps must be used inside <MultiAppProvider />`),e}function vi(e,t=!1){let[n,r]=ye(`SelectedApplication`,e||{id:`splash`},!t);return[n,r]}function yi({apps:e,initialApp:t,saveCurrentApp:n=!0,instanceId:r,children:i,config:a={}}){let{defaultApp:o=`splash`,collectionApp:s=`collection-editor`,manifestApp:c=`manifest-editor`}=a,[l,u]=vi(t,n),d=e=>{e===`Manifest`&&u({id:c}),e===`Collection`&&u({id:s})},f=N(()=>({currentApp:l||{id:o},initialApp:t||{id:o},apps:e,changeApp:u,changeProjectType:d}),[t,e,l]),p=e[f.currentApp.id];return!l||!p?null:L(hi,{appId:l.id,definition:p,instanceId:l.id+r,args:l.args,children:L(gi.Provider,{value:f,children:i})})}const bi=V.div`
2
2
  display: flex;
3
3
  align-items: center;
4
4
  height: 3em;
5
5
  padding: 0.5em;
6
- `,pi=V.div`
6
+ `,xi=V.div`
7
7
  display: flex;
8
8
  padding: 0.25em;
9
9
  flex-direction: column;
@@ -28,7 +28,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
28
28
  }
29
29
  `,V.div`
30
30
  flex: 1;
31
- `;const mi=V.div`
31
+ `;const Si=V.div`
32
32
  color: #6e6e6e;
33
33
  display: flex;
34
34
  align-items: center;
@@ -60,7 +60,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
60
60
  color: #666666;
61
61
  padding: 0.35em 0.7em;
62
62
  letter-spacing: -0.42px;
63
- `;const hi=({height:e=16})=>R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:e,viewBox:`0 0 24 24`,width:`24px`,fill:`currentColor`,children:[L(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),L(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})]}),gi=({rotate:e=0,...t})=>L(`svg`,{version:`1.2`,xmlns:`http://www.w3.org/2000/svg`,overflow:`visible`,preserveAspectRatio:`none`,viewBox:`0 0 24 24`,width:`1em`,height:`1em`,style:{fill:`rgba(0, 0, 0, 0.6)`,transform:`rotate(${e}deg)`,transition:`transform 0.2s`},...t,children:L(`path`,{d:`M8.12 9.29 12 13.17l3.88-3.88a.996.996 0 1 1 1.41 1.41l-4.59 4.59a.996.996 0 0 1-1.41 0L6.7 10.7a.996.996 0 0 1 0-1.41c.39-.38 1.03-.39 1.42 0z`,fill:`currentColor`})}),_i=O(null),vi=O(null);function yi(){let e=A(vi),t=A(_i),n=e||t?.id;return U(n,`useResourceInstance can only be called from inside <ResourceProvider />`),n}function bi(){let e=A(_i);return U(e,`useResource can only be called from inside <ResourceProvider />`),e}function xi({id:e,children:t}){return e?L(vi.Provider,{value:e,children:t}):t}function Si({resource:e,children:t}){let n=We(),r=t;return e&&e.type===`Manifest`&&(r=L(Ve,{vault:n||void 0,children:L(Re,{manifest:e.id||``,children:t})})),e&&e.type===`Collection`&&(r=L(Ve,{vault:n||void 0,children:L(Ie,{collection:e.id||``,children:t})})),L(_i.Provider,{value:e,children:r})}function Ci(e){"@babel/helpers - typeof";return Ci=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Ci(e)}function wi(e,t){if(Ci(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Ci(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ti(e){var t=wi(e,`string`);return Ci(t)==`symbol`?t:t+``}function J(e,t,n){return(t=Ti(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Ei=class{constructor({id:e,config:t,label:n}){J(this,`id`,void 0),J(this,`label`,void 0),J(this,`type`,`external-manifest-preview`),J(this,`focusable`,!0),J(this,`serviceUrl`,void 0),J(this,`windows`,{}),this.id=e,this.label=n,this.serviceUrl=t.url}isPreviewValid(e){let t=this.windows[e];return!!(t&&t.window&&!t.window.closed)}getRequires(){return[`readOnlyManifest`]}getProvides(){return[]}async createPreview(e,t,n,r){let i=`${this.serviceUrl}`.replace(/\{manifestId}/,r.readOnlyManifest).replace(/\{time}/,`${Date.now()}`),a=window.open(i,this.id);return this.windows[e]={location:i,window:a},{id:this.id,type:`external-manifest-preview`,data:{url:i}}}async focus(e){let t=this.windows[e];t&&t.window&&t.window.focus()}async updatePreview(e,t,n,r){let i=this.windows[e];if(i)try{i.window?.close()}catch{}return this.createPreview(e,t,n,r)}async deletePreview(e){let t=this.windows[e];t&&t.window&&(t.window.close(),delete this.windows[e])}},Di=class{constructor({id:e,config:t,label:n}){J(this,`id`,void 0),J(this,`label`,void 0),J(this,`type`,`iiif-preview-service`),J(this,`focusable`,!1),J(this,`serviceUrl`,void 0),J(this,`cache`,{}),this.id=e,this.label=n,this.serviceUrl=t.url}getRequires(){return[]}getProvides(){return[`readOnlyManifest`]}async isPreviewValid(e,t){if(this.cache[e])return!0;if(!t||!t.data||!t.data.readOnlyManifest)return!1;let n=t.data.readOnlyManifest;try{return(await fetch(n,{cache:`no-cache`})).ok}catch{return!1}}async createPreview(e,t,n){let r=n.toPresentation3(t),i=await fetch(this.serviceUrl,{method:`POST`,headers:{"Content-Type":`application/json`,Origin:`*`},body:JSON.stringify(r)});U(i.ok,`Unknown error creating preview`);let a=await i.json();return U(a.location,`Missing IIIF location while creating preview`),this.cache[e]={...a,time:Date.now()},{id:this.id,type:`external-manifest-preview`,data:{readOnlyManifest:`${a.location}/${Date.now()}`}}}async focus(){}async updatePreview(e,t,n){let r=this.cache[e];if(!r||Date.now()>r.expirationTtl+r.time||!r.updateLocation)return this.createPreview(e,t,n);let i=r.updateLocation,a=n.toPresentation3(t),o=await fetch(i,{method:`PUT`,headers:{"Content-Type":`application/json`,Origin:`*`},body:JSON.stringify(a)});U(o.ok,`Unknown error updating preview`);let s=await o.json();U(s.location),s.updateLocation&&(r.updateLocation=s.updateLocation);let c=`${s.location}/${Date.now()}`;return await fetch(c,{cache:`no-cache`}),{id:this.id,type:`external-manifest-preview`,data:{readOnlyManifest:`${s.location}/${Date.now()}`}}}async deletePreview(e){let t=this.cache[e];if(t&&t.deleteLocation)try{await fetch(t.deleteLocation,{method:`DELETE`,headers:{"Content-Type":`application/json`,Origin:`*`}})}catch{}}};function Oi(e,t,n,r,i){let a=bi(),o=yi(),s=z(),c=N(()=>({setPreview:e=>{e&&i(t=>[...t.filter(t=>t.id!==e.id),e])},removePreview:e=>{i(t=>t.filter(t=>t.id!==e))}}),[i,o]),[l,u]=N(()=>{let e={},t={};for(let r of n){e[r.id]=r;let n=r.getProvides();if(n.length)for(let e of n)t[e]||(t[e]=r.id)}return[e,t]},[n]);async function d(){let n=e.selected,i=r.find(e=>e.id===n);if(r&&r.length&&i){let e=l[i.id].getRequires(),n={};for(let i of r){let r=l[i.id];if(r){let i=r.getProvides();for(let l of i)if(e.indexOf(l)!==-1){let e=await r.updatePreview(o,a,s,n);e&&(c.setPreview(e),t({type:`activatePreview`,payload:e.id}),Object.assign(n,e.data||{}))}}}let u=l[i.id];if(u){let e=await u.updatePreview(o,a,s,n);e?c.setPreview(e):(c.removePreview(i.id),await u.deletePreview(o))}}}async function f(e){l[e]&&o&&(t({type:`selectPreview`,payload:e}),await g(e))}async function p(){let e=u.readOnlyManifest,t=e?l[e]:null;if(t&&o){let e=r.find(e=>e.type===`iiif-preview-service`);if(!e||!await t.isPreviewValid(o,e)){let e=await t.createPreview(o,a,s,{});if(e)return e.data.readOnlyManifest}}return null}function m(e){let n=l[e];n&&o&&(c.removePreview(e),n.deletePreview(o).then(()=>{t({type:`deletePreview`,payload:e})}))}async function h(e){let n=l[e];l[e]&&o&&n&&(await n.focus(o),t({type:`focusPreview`,payload:e}))}async function g(n){let i=l[n];if(i&&o){let d=r.find(e=>e.id===n);if(!d||!i.isPreviewValid(o,d)){let n={},d=i.getRequires();for(let i of d){let d=u[i],f=d?l[d]:null;U(f,`Missing handler for Preview requirement "${i}"`),r.find(e=>e.id===d),e.active.find(e=>e===d);{let e=await f.createPreview(o,a,s,n);Object.assign(n,e?.data||{}),c.setPreview(e),t({type:`activatePreview`,payload:e.id})}}let f=await i.createPreview(o,a,s,n);f&&(c.setPreview(f),t({type:`activatePreview`,payload:f.id}))}}}return N(()=>({selectPreview:f,deletePreview:m,focusPreview:h,activatePreview:g,updatePreviews:d,getPreviewLink:p}),[l,o,s,e.selected,e.active,r])}function ki(e){return N(()=>{let t=[];for(let n of e)switch(n.type){case`iiif-preview-service`:t.push(new Di(n));break;case`external-manifest-preview`:t.push(new Ei(n));break}return t},[])}const Ai=Qe(function(e,t){switch(t.type){case`focusPreview`:break;case`deletePreview`:e.selected===t.payload&&(e.selected=null),e.active=e.active.filter(e=>e!==t.payload);break;case`activatePreview`:e.active.indexOf(t.payload)===-1&&e.active.push(t.payload);break;case`selectPreview`:e.selected=t.payload,e.active.indexOf(t.payload)===-1&&e.active.push(t.payload);break}});function ji(){return{active:[],selected:null}}const Mi=O(null),Ni=O([]),Pi=Ee(function({children:e,configs:t=[]}){let n=yi(),r=ki(t),[i,a]=_e(`preview-${n}`,[]),[o,s]=Oe(Ai,void 0,ji),c=Oi(o,s,r,i,a),l=N(()=>({configs:t,actions:c,handlers:r,...o}),[c,t,r,o]);return j(()=>{for(let e of i)if(!o.active.includes(e.id)){let t=r.find(t=>t.id===e.id);t&&Promise.resolve(t.isPreviewValid(n,e)).then(t=>{t?s({type:`activatePreview`,payload:e.id}):a(t=>t.filter(t=>t.id!==e.id))})}},[n]),L(Ni.Provider,{value:i,children:L(Mi.Provider,{value:l,children:e})})});function Fi(){return A(Ni)}function Ii(){let e=A(Mi);return U(e,`usePreviewContext() can only be called from inside <PreviewProvider />`),e}const Li=V.button`
63
+ `;const Ci=({height:e=16})=>R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:e,viewBox:`0 0 24 24`,width:`24px`,fill:`currentColor`,children:[L(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),L(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})]}),wi=({rotate:e=0,...t})=>L(`svg`,{version:`1.2`,xmlns:`http://www.w3.org/2000/svg`,overflow:`visible`,preserveAspectRatio:`none`,viewBox:`0 0 24 24`,width:`1em`,height:`1em`,style:{fill:`rgba(0, 0, 0, 0.6)`,transform:`rotate(${e}deg)`,transition:`transform 0.2s`},...t,children:L(`path`,{d:`M8.12 9.29 12 13.17l3.88-3.88a.996.996 0 1 1 1.41 1.41l-4.59 4.59a.996.996 0 0 1-1.41 0L6.7 10.7a.996.996 0 0 1 0-1.41c.39-.38 1.03-.39 1.42 0z`,fill:`currentColor`})}),Ti=O(null),Ei=O(null);function Di(){let e=A(Ei),t=A(Ti),n=e||t?.id;return U(n,`useResourceInstance can only be called from inside <ResourceProvider />`),n}function Oi(){let e=A(Ti);return U(e,`useResource can only be called from inside <ResourceProvider />`),e}function ki({id:e,children:t}){return e?L(Ei.Provider,{value:e,children:t}):t}function Ai({resource:e,children:t}){let n=We(),r=t;return e&&e.type===`Manifest`&&(r=L(Ve,{vault:n||void 0,children:L(Re,{manifest:e.id||``,children:t})})),e&&e.type===`Collection`&&(r=L(Ve,{vault:n||void 0,children:L(Ie,{collection:e.id||``,children:t})})),L(Ti.Provider,{value:e,children:r})}function ji(e){"@babel/helpers - typeof";return ji=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},ji(e)}function Mi(e,t){if(ji(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(ji(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ni(e){var t=Mi(e,`string`);return ji(t)==`symbol`?t:t+``}function J(e,t,n){return(t=Ni(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Pi=class{constructor({id:e,config:t,label:n}){J(this,`id`,void 0),J(this,`label`,void 0),J(this,`type`,`external-manifest-preview`),J(this,`focusable`,!0),J(this,`serviceUrl`,void 0),J(this,`windows`,{}),this.id=e,this.label=n,this.serviceUrl=t.url}isPreviewValid(e){let t=this.windows[e];return!!(t&&t.window&&!t.window.closed)}getRequires(){return[`readOnlyManifest`]}getProvides(){return[]}async createPreview(e,t,n,r){let i=`${this.serviceUrl}`.replace(/\{manifestId}/,r.readOnlyManifest).replace(/\{time}/,`${Date.now()}`),a=window.open(i,this.id);return this.windows[e]={location:i,window:a},{id:this.id,type:`external-manifest-preview`,data:{url:i}}}async focus(e){let t=this.windows[e];t&&t.window&&t.window.focus()}async updatePreview(e,t,n,r){let i=this.windows[e];if(i)try{i.window?.close()}catch{}return this.createPreview(e,t,n,r)}async deletePreview(e){let t=this.windows[e];t&&t.window&&(t.window.close(),delete this.windows[e])}},Fi=class{constructor({id:e,config:t,label:n}){J(this,`id`,void 0),J(this,`label`,void 0),J(this,`type`,`iiif-preview-service`),J(this,`focusable`,!1),J(this,`serviceUrl`,void 0),J(this,`cache`,{}),this.id=e,this.label=n,this.serviceUrl=t.url}getRequires(){return[]}getProvides(){return[`readOnlyManifest`]}async isPreviewValid(e,t){if(this.cache[e])return!0;if(!t||!t.data||!t.data.readOnlyManifest)return!1;let n=t.data.readOnlyManifest;try{return(await fetch(n,{cache:`no-cache`})).ok}catch{return!1}}async createPreview(e,t,n){let r=n.toPresentation3(t),i=await fetch(this.serviceUrl,{method:`POST`,headers:{"Content-Type":`application/json`,Origin:`*`},body:JSON.stringify(r)});U(i.ok,`Unknown error creating preview`);let a=await i.json();return U(a.location,`Missing IIIF location while creating preview`),this.cache[e]={...a,time:Date.now()},{id:this.id,type:`external-manifest-preview`,data:{readOnlyManifest:`${a.location}/${Date.now()}`}}}async focus(){}async updatePreview(e,t,n){let r=this.cache[e];if(!r||Date.now()>r.expirationTtl+r.time||!r.updateLocation)return this.createPreview(e,t,n);let i=r.updateLocation,a=n.toPresentation3(t),o=await fetch(i,{method:`PUT`,headers:{"Content-Type":`application/json`,Origin:`*`},body:JSON.stringify(a)});U(o.ok,`Unknown error updating preview`);let s=await o.json();U(s.location),s.updateLocation&&(r.updateLocation=s.updateLocation);let c=`${s.location}/${Date.now()}`;return await fetch(c,{cache:`no-cache`}),{id:this.id,type:`external-manifest-preview`,data:{readOnlyManifest:`${s.location}/${Date.now()}`}}}async deletePreview(e){let t=this.cache[e];if(t&&t.deleteLocation)try{await fetch(t.deleteLocation,{method:`DELETE`,headers:{"Content-Type":`application/json`,Origin:`*`}})}catch{}}};function Ii(e,t,n,r,i){let a=Oi(),o=Di(),s=z(),c=N(()=>({setPreview:e=>{e&&i(t=>[...t.filter(t=>t.id!==e.id),e])},removePreview:e=>{i(t=>t.filter(t=>t.id!==e))}}),[i,o]),[l,u]=N(()=>{let e={},t={};for(let r of n){e[r.id]=r;let n=r.getProvides();if(n.length)for(let e of n)t[e]||(t[e]=r.id)}return[e,t]},[n]);async function d(){let n=e.selected,i=r.find(e=>e.id===n);if(r&&r.length&&i){let e=l[i.id].getRequires(),n={};for(let i of r){let r=l[i.id];if(r){let i=r.getProvides();for(let l of i)if(e.indexOf(l)!==-1){let e=await r.updatePreview(o,a,s,n);e&&(c.setPreview(e),t({type:`activatePreview`,payload:e.id}),Object.assign(n,e.data||{}))}}}let u=l[i.id];if(u){let e=await u.updatePreview(o,a,s,n);e?c.setPreview(e):(c.removePreview(i.id),await u.deletePreview(o))}}}async function f(e){l[e]&&o&&(t({type:`selectPreview`,payload:e}),await g(e))}async function p(){let e=u.readOnlyManifest,t=e?l[e]:null;if(t&&o){let e=r.find(e=>e.type===`iiif-preview-service`);if(!e||!await t.isPreviewValid(o,e)){let e=await t.createPreview(o,a,s,{});if(e)return e.data.readOnlyManifest}}return null}function m(e){let n=l[e];n&&o&&(c.removePreview(e),n.deletePreview(o).then(()=>{t({type:`deletePreview`,payload:e})}))}async function h(e){let n=l[e];l[e]&&o&&n&&(await n.focus(o),t({type:`focusPreview`,payload:e}))}async function g(n){let i=l[n];if(i&&o){let d=r.find(e=>e.id===n);if(!d||!i.isPreviewValid(o,d)){let n={},d=i.getRequires();for(let i of d){let d=u[i],f=d?l[d]:null;U(f,`Missing handler for Preview requirement "${i}"`),r.find(e=>e.id===d),e.active.find(e=>e===d);{let e=await f.createPreview(o,a,s,n);Object.assign(n,e?.data||{}),c.setPreview(e),t({type:`activatePreview`,payload:e.id})}}let f=await i.createPreview(o,a,s,n);f&&(c.setPreview(f),t({type:`activatePreview`,payload:f.id}))}}}return N(()=>({selectPreview:f,deletePreview:m,focusPreview:h,activatePreview:g,updatePreviews:d,getPreviewLink:p}),[l,o,s,e.selected,e.active,r])}function Li(e){return N(()=>{let t=[];for(let n of e)switch(n.type){case`iiif-preview-service`:t.push(new Fi(n));break;case`external-manifest-preview`:t.push(new Pi(n));break}return t},[])}const Ri=Qe(function(e,t){switch(t.type){case`focusPreview`:break;case`deletePreview`:e.selected===t.payload&&(e.selected=null),e.active=e.active.filter(e=>e!==t.payload);break;case`activatePreview`:e.active.indexOf(t.payload)===-1&&e.active.push(t.payload);break;case`selectPreview`:e.selected=t.payload,e.active.indexOf(t.payload)===-1&&e.active.push(t.payload);break}});function zi(){return{active:[],selected:null}}const Bi=O(null),Vi=O([]),Hi=Ee(function({children:e,configs:t=[]}){let n=Di(),r=Li(t),[i,a]=_e(`preview-${n}`,[]),[o,s]=Oe(Ri,void 0,zi),c=Ii(o,s,r,i,a),l=N(()=>({configs:t,actions:c,handlers:r,...o}),[c,t,r,o]);return j(()=>{for(let e of i)if(!o.active.includes(e.id)){let t=r.find(t=>t.id===e.id);t&&Promise.resolve(t.isPreviewValid(n,e)).then(t=>{t?s({type:`activatePreview`,payload:e.id}):a(t=>t.filter(t=>t.id!==e.id))})}},[n]),L(Vi.Provider,{value:i,children:L(Bi.Provider,{value:l,children:e})})});function Ui(){return A(Vi)}function Wi(){let e=A(Bi);return U(e,`usePreviewContext() can only be called from inside <PreviewProvider />`),e}const Gi=V.button`
64
64
  border: none;
65
65
  outline: none;
66
66
  background-color: transparent;
@@ -113,7 +113,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
113
113
  cursor: not-allowed;
114
114
  }
115
115
  }
116
- `;const Ri=V(Y)`
116
+ `;const Ki=V(Y)`
117
117
  padding: 0 ${e=>e.theme.padding.medium||`1rem`};
118
118
  color: ${e=>e.theme.color.white||`white`};
119
119
  background-color: ${e=>e.theme.color.main||`#B84C74;`};
@@ -132,11 +132,11 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
132
132
  flex-wrap: wrap;
133
133
  align-items: flex-start;
134
134
  justify-content: ${e=>e.$right?`flex-end`:`flex-start`};
135
- `;const zi=V.div`
135
+ `;const qi=V.div`
136
136
  display: flex;
137
137
  position: relative;
138
138
  width: 10em;
139
- `,Bi=V(Li)`
139
+ `,Ji=V(Gi)`
140
140
  flex: 1;
141
141
  padding: 0.5em 0.8em;
142
142
  background: #b84c74;
@@ -157,7 +157,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
157
157
  background: #892c4e;
158
158
  box-shadow: inset 0 2px 8px 0 rgba(0, 0, 0, 0.15);
159
159
  }
160
- `,Vi=V(Li)`
160
+ `,Yi=V(Gi)`
161
161
  background: #b84c74;
162
162
  border-top-right-radius: 5px;
163
163
  border-bottom-right-radius: 5px;
@@ -182,7 +182,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
182
182
  background: #892c4e;
183
183
  box-shadow: inset 0 2px 8px 0 rgba(0, 0, 0, 0.15);
184
184
  `}
185
- `,Hi=V.div`
185
+ `,Xi=V.div`
186
186
  position: absolute;
187
187
  opacity: 0;
188
188
  top: 100%;
@@ -203,7 +203,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
203
203
  opacity: 1;
204
204
  pointer-events: visible;
205
205
  `}
206
- `,Ui=V.div`
206
+ `,Zi=V.div`
207
207
  display: flex;
208
208
  background: #fff;
209
209
  color: #25211f;
@@ -213,13 +213,13 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
213
213
  &:hover {
214
214
  background: #f9f9f9;
215
215
  }
216
- `,Wi={available:`#ddd`,configured:`#e37266`,active:`#4cb235`},Gi=V.div`
216
+ `,Qi={available:`#ddd`,configured:`#e37266`,active:`#4cb235`},$i=V.div`
217
217
  margin: 0.2em 0.5em;
218
218
  width: 8px;
219
219
  height: 8px;
220
220
  border-radius: 50%;
221
- background-color: ${e=>Wi[e.$status]};
222
- `,Ki=V.div`
221
+ background-color: ${e=>Qi[e.$status]};
222
+ `,ea=V.div`
223
223
  flex: 1;
224
224
  font-size: 0.925em;
225
225
  color: #25211f;
@@ -228,10 +228,10 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
228
228
  cursor: pointer;
229
229
  white-space: nowrap;
230
230
  overflow: hidden;
231
- `,qi=V.div`
231
+ `,ta=V.div`
232
232
  background: #f9f9f9;
233
233
  font-size: 0.8em;
234
- `,Ji=V.div`
234
+ `,na=V.div`
235
235
  color: #999;
236
236
  font-size: 0.8em;
237
237
  padding: 0.6em 0.8em;
@@ -239,7 +239,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
239
239
  border-radius: 5px;
240
240
  user-select: none;
241
241
  cursor: not-allowed;
242
- `;function Yi({downloadEnabled:e,fileName:t}){let{active:n,configs:r,actions:i,selected:a}=Ii(),o=z(),s=Ot(),c=bi(),l=r.filter(e=>e.type===`external-manifest-preview`),{isOpen:u,buttonProps:d,itemProps:f}=Xe(l.length);return l.length===0?L(Ji,{children:`Preview not available`}):R(I,{children:[e?L(`div`,{className:`mr-4`,children:L(y,{fileName:t||`manifest.json`,label:`Download manifest`,getData:()=>s.export&&s.export.version===2?JSON.stringify(o.toPresentation2(c),null,2):JSON.stringify(o.toPresentation3(c),null,2)})}):null,R(zi,{children:[L(Bi,{onClick:()=>{if(!a){let e=s.defaultPreview;if(e){let t=r.find(t=>t.id===e);if(t){i.selectPreview(t.id);return}}i.selectPreview(r[0].id)}i.updatePreviews()},children:`Preview`}),L(Vi,{$open:u,...d,children:L(gi,{})}),L(Hi,{$open:u,children:l.map((e,t)=>{let r=n.indexOf(e.id)===-1;return R(Ui,{...f[t],children:[L(Gi,{$status:r?`available`:e.id===a?`active`:`configured`}),L(Ki,{onClick:()=>{i.selectPreview(e.id)},children:e.label}),r?null:L(qi,{onClick:()=>i.deletePreview(e.id),children:L(hi,{})})]},e.id)})})]})]})}function Xi(e,t){switch(t.type){case`setStack`:return{...e,stack:t.payload.resources,current:t.payload.resources[0]||null};case`edit`:{let n=t.payload.reset;return(t.payload.resource?.resource.source?.type===`Manifest`||t.payload.resource?.resource.source?.type===`Canvas`)&&(n=!0),e.current?.resource.source.id===t.payload.resource?.resource.source.id?{...e,current:t.payload.resource}:{...e,current:t.payload.resource,stack:n?[]:e.current?[e.current,...e.stack]:e.stack}}case`syncRemoval`:{let n=B(t.payload.resource.resource);if(!n||!e.stack.find(e=>B(e.resource)?.id===n.id))return e;let r=e.current?.resource.id===n.id?null:e.current,i=Zi(e.stack.filter(e=>B(e.resource)?.id!==n.id),r);return{...e,stack:i,current:r}}case`updateCurrent`:return{...e,current:t.payload.resource};case`back`:{let t=e.stack[0];return{...e,stack:e.stack.slice(1),current:t||null}}case`close`:return{...e,stack:[],current:null};case`create`:return t.payload.resource===null?{...e,create:null}:{...e,create:t.payload}}return e}function Zi(e,t){let n=[],r=null;for(let t of e)r?.resource.id!==t.resource.id&&(n.push(t),r=t);return r&&r.resource.id===t?.resource.id?n.slice(0,n.length-1):n}const Qi={stack:[],current:null,create:null},$i=O(Qi),ea=O({edit(){},close(){},back(){},setStack(){},updateCurrent(){},create(){return()=>{}}});function ta(){return A(ea)}function na(){return A($i).current}function ra(){return A($i).stack}function ia(){return A($i).create}function aa(){let{manifest:e}=Ke(),t=z(),[n,r]=Oe(e=>e+1,0);U(e,`Manifest not found`);let i=N(()=>new $e({reference:{id:e,type:`Manifest`},vault:t}),[e,t]);return j(()=>i.observe.start(r),[i]),i.observe.key=`${n}`,i.observe.reset(),i}function oa(){let{collection:e}=Ke(),t=z(),[n,r]=Oe(e=>e+1,0);U(e,`Collection not found`);let i=N(()=>new $e({reference:{id:e,type:`Collection`},vault:t}),[e,t]);return j(()=>i.observe.start(r),[i]),i.observe.key=`${n}`,i.observe.reset(),i}function sa(e,t={}){let n=z(),[r,i]=Oe(e=>e+1,0);!t.allowNull&&U(e,`Resource not found`);let a=N(()=>t.allowNull&&!e?null:new $e({reference:B(e),vault:n,context:{resource:e,parent:t.parent,index:t.index,parentProperty:t.parentProperty}}),[e,n]);return j(()=>a?.observe.start(i),[a]),a&&(a.observe.key=`${r}`,a.observe.reset()),a}function ca(){let{annotationPage:e}=Ke();return U(e,`Annotation page not found`),sa({id:e,type:`AnnotationPage`})}function la(){let e=na(),t=z(),[n,r]=Oe(e=>e+1,0);U(e,`No resource selected`);let i=N(()=>new $e({reference:e.resource.source||e.resource,vault:t}),[e,t]);return j(()=>i.observe.start(r),[i]),i.observe.key=`${n}`,i.observe.reset(),i}function ua(e){let t=z(),[n,r]=Oe(Xi,e),i=k(e=>{r(e)},[]);j(()=>t.on(`@iiif/REMOVE_REFERENCE`,e=>{let t=e.action,n={id:t.payload.id,type:t.payload.type},i=t.payload.reference;r({type:`syncRemoval`,payload:{resource:{parent:n,resource:i}}})}),[t]);let a=k((e,t=!1)=>i({type:`edit`,payload:{resource:e,reset:t}}),[]),o=k(e=>i({type:`setStack`,payload:{resources:e}}),[]),s=k(e=>i({type:`updateCurrent`,payload:{resource:e}}),[]),c=k(()=>i({type:`close`}),[]),l=k(()=>i({type:`back`}),[]),u=k((e,t)=>(i({type:`create`,payload:{resource:e,options:t}}),()=>{i({type:`create`,payload:{resource:null}})}),[]);return[n,N(()=>({edit:a,updateCurrent:s,close:c,back:l,create:u,setStack:o}),[])]}function da(e){let{instanceId:t}=ii(),[n,r]=ua(e.initialState||Qi);return L(ea.Provider,{value:r,children:L($i.Provider,{value:n,children:e.children})},t)}function fa({resource:e,children:t}){let{instanceId:n}=ii(),[r,i]=ua(N(()=>({create:null,stack:[],current:{resource:{type:`SpecificResource`,source:{id:e.id,type:e.type}}}}),[]));return L(ea.Provider,{value:i,children:L($i.Provider,{value:r,children:t})},n)}const pa=O(null),ma=O(null),ha=O(`default`);function ga(){return A(ma)}function _a(){return A(pa)}function va(){return A(ha)}function ya(){return q().layout}function ba(){let e=q(),t=e.layout,n=A(pa),r=A(ma);return N(()=>({actions:n,state:r,...t}),[e,r])}const xa=`@manifest-editor/tags`,Sa=`tags`,Ca={type:`flag`,id:`flag`,label:`Flag`,backgroundColor:`#b91c1c`,textColor:`#ffffff`,icon:`flag`},wa=[];function Ta(e){return typeof e==`string`?e:e?.id||null}function Ea(e){return e.type||e.id}function Da(e){return`${e.type}:${e.id}`}function Oa(e){if(!Array.isArray(e))return wa;let t=new Map;for(let n of e){if(!n?.id)continue;let e=Ea(n);t.set(e,{...n,type:e})}return Array.from(t.values())}function ka(e){return e.label||e.id||e.type}function Aa(e,t){return e===Ca.type&&(!t||t===Ca.id)}function ja(e,t){return Aa(e.type,e.id)?-1:Aa(t.type,t.id)?1:ka(e.tag).localeCompare(ka(t.tag))||e.type.localeCompare(t.type)||e.id.localeCompare(t.id)}function Ma(e,t){return Aa(e.type)?-1:Aa(t.type)?1:e.type.localeCompare(t.type)}function Na(e,t){let n=Ta(t);return n?Oa(e.getResourceMeta(n,xa)?.[Sa]):wa}function Pa(e,t){let n=Ta(t);return n?Oa(e?.iiif?.meta?.[n]?.[xa]?.[Sa]):wa}function Fa(e,t,n){let r=Ta(t);if(!r)return wa;let i=Oa(n);return e.setMetaValue([r,xa,Sa],i),i}function Ia(e,t,n){return Fa(e,t,[...Na(e,t),n])}function La(e,t,n){return Na(e,t).find(e=>e.type===n)}function Ra(e,t,n,r){return Fa(e,t,Na(e,t).filter(e=>e.type!==n||(r?e.id!==r:!1)))}function za(e,t){let n=new Map;for(let r of t){let t=Ta(r);if(t)for(let i of Na(e,r)){let e=i.type,r=Da(i),a=n.get(e);a||(a={key:e,type:i.type,rows:[],canvasIds:[],canvasCount:0,tagCount:0},n.set(e,a));let o=a.rows.find(e=>e.key===r);o||(o={key:r,type:i.type,id:i.id,tag:i,canvasIds:[],canvasCount:0},a.rows.push(o)),o.canvasIds.push(t),o.canvasCount=o.canvasIds.length,a.tagCount+=1}}for(let e of n.values())e.rows.sort(ja),e.canvasIds=Array.from(new Set(e.rows.flatMap(e=>e.canvasIds))),e.canvasCount=e.canvasIds.length;return Array.from(n.values()).sort(Ma)}function Ba(e,t,n,r){let i=La(e,t,n);return r?i?.id===r:!!i}function Va(e,t,n){return Ba(e,t,n.type,n.id)?Ra(e,t,n.type):Ia(e,t,n)}function Ha(e){return{getTags(t){return Na(e,t)},setTags(t,n){return Fa(e,t,n)},addTag(t,n){return Ia(e,t,n)},upsertTag(t,n){return Ia(e,t,n)},getTag(t,n){return La(e,t,n)},removeTag(t,n,r){return Ra(e,t,n,r)},hasTag(t,n,r){return Ba(e,t,n,r)},toggleTag(t,n){return Va(e,t,n)}}}function Ua(e){let t=Ta(e);return qe(e=>t?Pa(e,t):wa,[t])}function Wa(e){let t=z(),n=Ta(e),r=N(()=>Ha(t),[t]);return N(()=>({setTags(e){return r.setTags(n,e)},addTag(e){return r.addTag(n,e)},getTag(e){return r.getTag(n,e)},removeTag(e,t){return r.removeTag(n,e,t)},toggleTag(e){return r.toggleTag(n,e)},hasTag(e,t){return r.hasTag(n,e,t)}}),[r,n])}function Ga({icon:e,title:t,...n}){return e===`flag`?R(`svg`,{viewBox:`0 0 24 24`,width:`1em`,height:`1em`,"aria-hidden":t?void 0:!0,...n,children:[t?L(`title`,{children:t}):null,L(`path`,{fill:`currentColor`,d:`M5 21a1 1 0 0 1-1-1V5.6c0-.42.26-.8.65-.94C6.7 3.9 8.65 4 10.5 4.7c1.55.58 3.05.7 4.5.36l3.75-.88A1 1 0 0 1 20 5.15v9.25c0 .46-.31.86-.75.97l-3.79.9c-1.85.43-3.76.28-5.66-.43-1.28-.48-2.55-.59-3.8-.33V20a1 1 0 0 1-1 1Z`})]}):null}function Ka({tag:e,showIcon:t=!0,className:n,style:r}){return R(`span`,{className:`inline-flex max-w-full items-center gap-0.5 rounded px-1 py-0.5 font-medium shadow-sm ${n||``}`,style:{backgroundColor:e.backgroundColor||`#e5e7eb`,color:e.textColor||`#111827`,fontSize:9,lineHeight:`11px`,...r},children:[t&&e.icon?L(Ga,{icon:e.icon,className:`h-2.5 w-2.5 flex-shrink-0`}):null,L(`span`,{className:`min-w-0 truncate`,children:ka(e)})]})}function qa({resource:e,tags:t,className:n}){return t?L(Ya,{tags:t,className:n}):L(Ja,{resource:e,className:n})}function Ja({resource:e,className:t}){return L(Ya,{tags:Ua(e),className:t})}function Ya({tags:e,className:t}){let n=e;return n.length?L(`div`,{className:`pointer-events-none absolute bottom-1 right-1 z-10 flex max-w-full flex-wrap justify-end gap-0.5 ${t||``}`,children:n.map(e=>L(Ka,{tag:e},e.type))}):null}const Xa=O(null);function Za(e){return e===`error`?8e3:5e3}function Qa({children:e,maxVisibleToasts:t=3}){let n=et({maxVisibleToasts:t}),r=N(()=>{let e=(e,t)=>n.add(e,{...t,timeout:t?.timeout??Za(e.variant)}),t=(t,n,r)=>e({...n,variant:t},r);return{add:e,info:(e,n)=>t(`info`,e,n),success:(e,n)=>t(`success`,e,n),warning:(e,n)=>t(`warning`,e,n),error:(e,n)=>t(`error`,e,n),close:n.close}},[n]);return R(Xa.Provider,{value:r,children:[e,L(me,{state:n})]})}function $a(){let e=A(Xa);if(!e)throw Error(`useToasts must be used within a ToastProvider`);return e}function eo(e){return e.status!==`complete`&&e.status!==`error`||!e.completedAt?null:`${e.id}:${e.status}:${e.completedAt}`}function to(e,t,n){let r=t.label||e.label;return t.status===`complete`?{variant:`success`,title:`${r} complete`,description:t.resultsAvailable?`Results are ready.`:void 0,action:t.resultsAvailable&&n?{label:`Results`,onPress:n}:void 0}:t.status===`error`?{variant:`error`,title:`${r} failed`,description:t.error?.message||t.statusText||`Action failed`}:null}function no(e){return{id:e.id,type:e.type,label:e.type,scope:`root`}}function ro(e){if(!(!e||!e.id||e.type!==`Canvas`))return{id:e.id,type:`Canvas`,label:`Current canvas`,scope:`canvas`}}function io(){let e=na(),t=ra();return N(()=>ro([e,...t].find(e=>e?.resource?.source?.type===`Canvas`)?.resource?.source),[e,t])}function ao(){let e=bi(),t=io(),n=z(),r=N(()=>Ha(n),[n]),i=N(()=>Ut(n),[n]),a=Xr(),o=Ot(),s=ga(),c=_a();return N(()=>({rootResource:e,currentCanvas:t,vault:n,tags:r,canvasProgress:i,plugins:a,config:o,layoutState:s,layoutActions:c}),[e,t,n,r,i,a,o,s,c])}function oo(){let e=K(e=>e.definitions),t=K(e=>e.instances),n=ao(),r=N(()=>no(n.rootResource),[n.rootResource]);return N(()=>sn({definitions:e,instances:t,systemContext:n,targets:[r,...n.currentCanvas?[n.currentCanvas]:[]],onSupportsError:(e,t)=>{console.error(`Background action "${e.id}" failed support check`,t)}}),[e,t,r,n])}function so(){let e=Qn(),t=K(e=>e.definitions),n=K(e=>e.instances),r=K(e=>e.plans),i=K(e=>e.controllers),a=K(e=>e.hasHydrated),o=ao(),s=P(new Set);return j(()=>{if(!a)return;let c=new Map(t.map(e=>[e.id,e]));for(let[t,a]of Object.entries(n)){let n=c.get(a.actionId),l=`${t}:${a.runId}`;!n?.resumable||!lo(a)||!r[t]||i[t]||s.current.has(l)||(s.current.add(l),Wn({store:e,resume:!0,context:{...o,definition:n,target:a.target,instanceKey:t,instance:a}}))}},[i,t,a,n,r,e,o]),L(I,{children:t.map(e=>e.render?L(xe,{children:e.render({...o,definition:e})},e.id):null)})}function co(){let e=K(e=>e.definitions),t=K(e=>e.instances),n=ao(),r=$a(),i=P(new Set),a=N(()=>new Map(e.map(e=>[e.id,e])),[e]);return j(()=>{for(let e of Object.values(t)){let t=eo(e);if(!t||i.current.has(t))continue;let o=a.get(e.actionId);if(!o)continue;let s={...n,definition:o,target:e.target,instanceKey:e.id,instance:e},c=to(o,e,e.resultsAvailable&&o.onResults?()=>{o.onResults?.(s)}:void 0);c&&(r.add(c),i.current.add(t))}},[a,t,n,r]),null}function lo(e){return e?.status===`preparing`||e?.status===`running`}function uo(e){return!e||e.status===`idle`?``:e.status===`error`?e.error?.message||e.statusText||`Error`:e.status===`complete`&&e.resultsAvailable?`Results ready`:e.status===`cancelled`?`Cancelled`:e.statusText||e.status}function fo(e){return e?new Date(e).toLocaleString():`Not recorded`}function po(e){return e?new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):`--:--:--`}function mo(e){if(!e.startedAt)return`Not recorded`;let t=e.completedAt||Date.now(),n=Math.max(0,Math.round((t-e.startedAt)/1e3)),r=Math.floor(n/60),i=n%60;return r?`${r}m ${i}s`:`${i}s`}function ho(e){if(e===void 0)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function go({label:e,value:t}){return R(`div`,{className:`min-w-0`,children:[L(`dt`,{className:`text-[10px] font-semibold uppercase tracking-widest text-zinc-400`,children:e}),L(`dd`,{className:`mt-1 break-words text-sm text-zinc-800`,children:t})]})}const _o={debug:{label:`DBG`,className:`text-zinc-500`},verbose:{label:`VRB`,className:`text-zinc-500`},info:{label:`INF`,className:`text-sky-400`},log:{label:`LOG`,className:`text-zinc-300`},warn:{label:`WRN`,className:`text-amber-400`},warning:{label:`WRN`,className:`text-amber-400`},error:{label:`ERR`,className:`text-red-400`}};function vo(e){return _o[e?.toLowerCase()]??{label:e?.toUpperCase().slice(0,3)??`LOG`,className:`text-zinc-300`}}const yo={error:`bg-red-100 text-red-700`,failed:`bg-red-100 text-red-700`,completed:`bg-green-100 text-green-700`,success:`bg-green-100 text-green-700`,started:`bg-sky-100 text-sky-700`,cancelled:`bg-zinc-100 text-zinc-600`,warning:`bg-amber-100 text-amber-700`,warn:`bg-amber-100 text-amber-700`};function bo(e){return yo[e?.toLowerCase()]??`bg-zinc-100 text-zinc-600`}function xo(e){return e?.toLowerCase()in yo}function So({definition:e,instance:t,onClose:n}){let[r,i]=F(`overview`),a=P(null),o=t.logs.length;j(()=>{r===`logs`&&a.current?.scrollIntoView({behavior:`instant`})},[r]);let s={idle:`bg-zinc-100 text-zinc-600`,preparing:`bg-orange-100 text-orange-700`,running:`bg-orange-100 text-orange-700`,complete:`bg-green-100 text-green-700`,error:`bg-red-100 text-red-700`,cancelled:`bg-zinc-100 text-zinc-500`},c=t.events.filter(e=>xo(e.type)),l=[{id:`overview`,label:`Overview`},{id:`logs`,label:`Logs`,count:o}];return R(ee,{title:t.label||e.label,onClose:n,className:`max-w-3xl`,children:[L(`div`,{className:`sticky top-0 z-10 border-b border-zinc-200 bg-white px-2`,children:L(`div`,{className:`flex gap-0.5`,children:l.map(e=>R(`button`,{type:`button`,onClick:()=>i(e.id),className:[`flex items-center gap-1.5 border-b-2 px-3 py-2.5 text-sm transition-colors -mb-px`,r===e.id?`border-me-primary-500 font-semibold text-me-primary-600`:`border-transparent text-zinc-500 hover:text-zinc-800`].join(` `),children:[e.label,e.count?L(`span`,{className:`rounded-full bg-zinc-100 px-1.5 py-0.5 text-[10px] font-medium text-zinc-500`,children:e.count}):null]},e.id))})}),r===`overview`&&R(`div`,{className:`flex flex-col gap-5 p-5`,children:[R(`div`,{className:`flex flex-wrap items-center gap-2`,children:[L(`span`,{className:[`inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-semibold uppercase tracking-wide`,s[t.status]??`bg-zinc-100 text-zinc-600`].join(` `),children:t.status}),t.statusText?L(`span`,{className:`text-sm text-zinc-500`,children:t.statusText}):null]}),R(`dl`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[L(go,{label:`Target`,value:`${t.target.label} (${t.target.type})`}),L(go,{label:`Run ID`,value:t.runId}),L(go,{label:`Started`,value:fo(t.startedAt)}),L(go,{label:`Finished`,value:fo(t.completedAt)}),L(go,{label:`Duration`,value:mo(t)}),t.progress?L(go,{label:`Progress`,value:`${Math.round(t.progress.percent)}%${t.progress.label?` — ${t.progress.label}`:``}`}):null]}),t.progress?R(`div`,{children:[L(d,{percent:t.progress.percent,label:t.progress.label||`Background action progress`}),typeof t.progress.current==`number`&&typeof t.progress.total==`number`?R(`div`,{className:`mt-1 text-xs text-zinc-500`,children:[t.progress.current,` of `,t.progress.total,` items`]}):null]}):null,t.error?R(`div`,{className:`rounded-lg border border-red-200 bg-red-50`,children:[L(`div`,{className:`border-b border-red-200 px-4 py-2.5`,children:L(`span`,{className:`text-xs font-semibold uppercase tracking-widest text-red-600`,children:`Error`})}),R(`div`,{className:`p-4`,children:[L(`div`,{className:`text-sm font-medium text-red-800`,children:t.error.message}),t.error.stack?L(`pre`,{className:`mt-3 max-h-40 overflow-auto rounded bg-red-100 p-3 text-xs text-red-700 leading-relaxed whitespace-pre-wrap`,children:t.error.stack}):null]})]}):null,c.length>0?R(`div`,{children:[L(`h3`,{className:`mb-2 text-[10px] font-semibold uppercase tracking-widest text-zinc-400`,children:`Key events`}),L(`div`,{className:`divide-y divide-zinc-100 rounded-lg border border-zinc-200`,children:c.map(e=>R(`div`,{className:`flex items-baseline gap-3 px-3 py-2`,children:[L(`span`,{className:[`shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide`,bo(e.type)].join(` `),children:e.type}),L(`span`,{className:`min-w-0 flex-1 truncate text-sm text-zinc-700`,children:e.message||e.type}),L(`time`,{className:`shrink-0 text-xs text-zinc-400`,children:po(e.createdAt)})]},e.id))})]}):null]}),r===`logs`&&L(`div`,{className:`p-5`,children:o===0?L(`div`,{className:`rounded-lg border border-zinc-200 p-6 text-center text-sm text-zinc-400`,children:`No logs recorded.`}):R(`div`,{className:`overflow-hidden rounded-lg bg-zinc-950 shadow-inner`,children:[R(`div`,{className:`flex items-center gap-1.5 border-b border-white/10 px-3 py-2`,children:[L(`div`,{className:`h-2.5 w-2.5 rounded-full bg-zinc-700`}),L(`div`,{className:`h-2.5 w-2.5 rounded-full bg-zinc-700`}),L(`div`,{className:`h-2.5 w-2.5 rounded-full bg-zinc-700`}),R(`span`,{className:`ml-2 text-[10px] text-zinc-500 font-mono`,children:[o,` `,o===1?`entry`:`entries`]})]}),R(`div`,{className:`max-h-[50vh] overflow-y-auto p-1 font-mono text-xs`,children:[t.logs.map(e=>{let t=vo(e.level);return R(`div`,{className:`group flex gap-0 hover:bg-white/5 rounded px-2 py-1 leading-relaxed`,children:[L(`time`,{className:`w-20 shrink-0 text-zinc-600 select-none pr-2`,children:po(e.createdAt)}),L(`span`,{className:[`w-10 shrink-0 select-none font-bold pr-2`,t.className].join(` `),children:t.label}),R(`span`,{className:`min-w-0 flex-1 text-zinc-200 break-words`,children:[e.message,e.data===void 0?null:L(`span`,{className:`block mt-0.5 text-zinc-500 whitespace-pre-wrap`,children:ho(e.data)})]})]},e.id)}),L(`div`,{ref:a})]})]})})]})}function Co(){let e=Qn(),t=oo(),[n,g]=F(null),_=t.reduce((e,t)=>e+t.actions.length,0),v=t.reduce((e,t)=>e+t.actions.filter(e=>lo(e.instance)).length,0),y=t.reduce((e,t)=>e+t.actions.filter(e=>e.instance?.status===`error`).length,0),{isOpen:b,buttonProps:x,itemProps:S,setIsOpen:C}=Xe(_);if(!_)return null;let w=n?t.flatMap(e=>e.actions).find(e=>e.instanceKey===n):void 0,T=0;return R(f,{children:[L(r,{active:b,runningCount:v,errorCount:y,"aria-label":`Actions menu`,...x}),L(u,{open:b,role:`menu`,children:L(`div`,{className:`py-1.5`,children:t.map((t,n)=>R(xe,{children:[n?L(i,{}):null,L(p,{children:t.label}),t.actions.map(t=>{let{onKeyDown:n,...r}=S[T++]||{},i=uo(t.instance),u=lo(t.instance),f=()=>{u||(Wn({store:e,context:t.context}),C(!0))},p=()=>{u&&(e.getState().cancelAction(t.instanceKey),C(!0))};return R(s,{status:t.instance?.status||`idle`,children:[L(h,{running:u,...r,"aria-label":u?`Cancel ${t.definition.label}`:`Run ${t.definition.label}`,onMouseDown:e=>{e.preventDefault()},onClick:e=>{e.stopPropagation(),u?p():f()},onKeyDown:e=>{e.key===`Enter`||e.key===` `?(e.preventDefault(),e.stopPropagation(),u?p():f()):n?.(e)},children:R(m,{children:[L(c,{running:u,children:t.instance?.label||t.definition.label}),i?L(l,{variant:t.instance?.status===`error`?`error`:`default`,children:i}):null,t.definition.summary&&!i?L(l,{children:t.definition.summary}):null,u&&t.instance?.progress?L(d,{percent:t.instance.progress.percent,label:t.instance.progress.label||i||t.definition.label}):null]})}),t.instance?.resultsAvailable&&t.definition.onResults?L(o,{onClick:e=>{e.stopPropagation(),t.definition.onResults?.(t.context)},children:`Results`}):null,t.instance?L(a,{"aria-label":`View ${t.definition.label} details`,onClick:e=>{e.preventDefault(),e.stopPropagation(),g(t.instanceKey),C(!0)}}):null]},t.instanceKey)})]},t.id))})}),w?.instance?L(So,{definition:w.definition,instance:w.instance,onClose:()=>g(null)}):null]})}const wo=Ee(function(e){let[t]=_e(`menu-hidden`);return L(pi,{children:R(fi,{children:[L(mi,{onClick:e.onClickLogo,children:L(E,{})}),L(Yi,{}),L(Co,{})]})})}),To=O(null);function Eo(){return A(To)||null}function Do(e,t){let n=Eo();return n?n[e][t]:null}function Oo({children:e,menu:t}){return L(To.Provider,{value:t,children:e})}function ko(){return A(Fe)}function Ao(e){if(!e)return null;if(e.points.length>2){let t=Math.min(...e.points.map(e=>e[0])),n=Math.min(...e.points.map(e=>e[1])),r=Math.max(0,...e.points.map(e=>e[0])),i=Math.max(0,...e.points.map(e=>e[1]));return{x:t,y:n,width:r-t,height:i-n}}return null}const jo=async e=>new Promise((t,n)=>{let r=document.createElement(`img`);r.onload=()=>t(r),r.onerror=()=>n(),r.src=e,r.complete&&t(r)}),Mo=async e=>new Promise((t,n)=>{let r=document.createElement(`video`);r.onloadedmetadata=()=>t(r),r.onerror=()=>n(),r.preload=`metadata`,r.src=e});async function No(){}async function Po(e,...t){if(!e)return;if(e.endsWith(`.mp3`)||e.endsWith(`.mp4`)||e.endsWith(`.m4a`)||e.endsWith(`.m4v`))try{let t=await Mo(e);if(t){let n=t.videoWidth===0;return{id:e,type:t.videoWidth===0?`Sound`:`Video`,width:t.videoWidth||void 0,height:t.videoHeight||void 0,duration:t.duration,format:n?`audio/mp4`:`video/mp4`}}}catch{}let n=null;try{n=await fetch(e)}catch{return Lo(e)}if(!n.ok&&(n=await fetch(e+`/info.json`),!n.ok))return Lo(e);let r=n.headers.get(`Content-Type`);if(r?.includes(`image/`))return Lo(e,r);let i=null;try{i=await n.json()}catch{return null}return await Io(i,e)}function Fo(e){return e.protocol&&e.protocol===`http://iiif.io/api/image`?(e.type||(e.type=`ImageService`),e):null}async function Io(e,t){let n=Fo(e);if(n)return n;if(!(e.id||e[`@id`]))return null;let r=await new nt.Vault().load(t,e);if(r&&(r&&r?.type===`Manifest`||r?.type===`Collection`))return{id:t,type:r.type,label:tt(r.label)}}async function Lo(e,t){let n=e.split(`/`);if(n.length>=8){let e=n.slice(-4);if(e[3].split(`.`).length===2&&(e[2][0]===`!`||e[2]===e[2])){let e=await Ro(n.slice(0,n.length-4).join(`/`)+`/info.json`);if(e&&e?.type&&e?.type?.startsWith(`ImageService`))return e}}try{let n=await jo(e);return{id:e,type:`Image`,width:n.width,height:n.height,format:await zo(e,t)}}catch{}return null}async function Ro(e){try{let t=await fetch(e);return t.ok?await Io(await t.json(),e):null}catch(e){return console.log(e),null}}async function zo(e,t){if(t)return t;try{let t=(await fetch(e,{method:`HEAD`,mode:`no-cors`})).headers.get(`Content-type`);if(t)return t}catch{}let n=e.toLowerCase();return n.endsWith(`jpg`)||n.endsWith(`jpeg`)?`image/jpeg`:n.endsWith(`png`)?`image/png`:`image/jpeg`}async function Bo(e){try{let t=await jo(e);if(t)return{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}}catch{return null}return null}const Vo=ke(e=>({regions:{},resources:[],setRegion:(t,n)=>{e(e=>({...e.regions,regions:{[t]:n||null}}))},setHighlight:t=>{e({resources:Array.isArray(t)?t:[t]})},highlight:t=>{e(e=>e.resources.indexOf(t)===-1?{resources:[...e.resources,t]}:e)},clearHighlight:t=>{e(e=>({resources:e.resources.filter(e=>e!==t)}))}}));function Ho(e){let t=N(()=>ar(),[]),n=Vo(e=>e.regions[t]),r=Vo(e=>e.setRegion);j(()=>{n&&e?n!==e&&(n.x!==e.x||n.y!==e.y||n.width!==e.width||n.height!==e.height)&&r(t,e||null):r(t,e||null)},[n]),j(()=>()=>r(t,null),[])}function Uo(e){let t=Vo(e=>e.highlight),n=Vo(e=>e.clearHighlight);return j(()=>()=>{e&&n(e)},[n,e]),N(()=>({onMouseEnter(){e&&t(e)},onMouseLeave(){e&&n(e)}}),[e,t,n])}const Wo=e=>R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,viewBox:`0 0 24 24`,...e,children:[L(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),L(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),L(`path`,{d:`M12 17.27 18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z`,fill:`currentColor`})]}),Go=({style:e})=>R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`1rem`,viewBox:`0 0 24 24`,width:`1rem`,fill:`#000000`,style:e,children:[L(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),L(`path`,{d:`M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z`})]});function Ko(e){let t=e.error.toString(),[n,r]=F(!1);return R(ne,{children:[L(x,{className:`mb-2`,children:t}),L(Ri,{onClick:e.resetErrorBoundary,children:`Try again`})]})}function qo(e){return e&&e.pinnable}function Jo({initial:e,fallback:t,options:n={}}){return Math.max(n.minWidth||0,Math.min(n.maxWidth||1/0,e||t))}function Yo(e){return typeof e==`string`?Ce(`div`,{dangerouslySetInnerHTML:{__html:e}}):e}const Xo=V.div`
242
+ `;function ra({downloadEnabled:e,fileName:t}){let{active:n,configs:r,actions:i,selected:a}=Wi(),o=z(),s=Ot(),c=Oi(),l=r.filter(e=>e.type===`external-manifest-preview`),{isOpen:u,buttonProps:d,itemProps:f}=Xe(l.length);return l.length===0?L(na,{children:`Preview not available`}):R(I,{children:[e?L(`div`,{className:`mr-4`,children:L(y,{fileName:t||`manifest.json`,label:`Download manifest`,getData:()=>s.export&&s.export.version===2?JSON.stringify(o.toPresentation2(c),null,2):JSON.stringify(o.toPresentation3(c),null,2)})}):null,R(qi,{children:[L(Ji,{onClick:()=>{if(!a){let e=s.defaultPreview;if(e){let t=r.find(t=>t.id===e);if(t){i.selectPreview(t.id);return}}i.selectPreview(r[0].id)}i.updatePreviews()},children:`Preview`}),L(Yi,{$open:u,...d,children:L(wi,{})}),L(Xi,{$open:u,children:l.map((e,t)=>{let r=n.indexOf(e.id)===-1;return R(Zi,{...f[t],children:[L($i,{$status:r?`available`:e.id===a?`active`:`configured`}),L(ea,{onClick:()=>{i.selectPreview(e.id)},children:e.label}),r?null:L(ta,{onClick:()=>i.deletePreview(e.id),children:L(Ci,{})})]},e.id)})})]})]})}function ia(e,t){switch(t.type){case`setStack`:return{...e,stack:t.payload.resources,current:t.payload.resources[0]||null};case`edit`:{let n=t.payload.reset;return(t.payload.resource?.resource.source?.type===`Manifest`||t.payload.resource?.resource.source?.type===`Canvas`)&&(n=!0),e.current?.resource.source.id===t.payload.resource?.resource.source.id?{...e,current:t.payload.resource}:{...e,current:t.payload.resource,stack:n?[]:e.current?[e.current,...e.stack]:e.stack}}case`syncRemoval`:{let n=B(t.payload.resource.resource);if(!n||!e.stack.find(e=>B(e.resource)?.id===n.id))return e;let r=e.current?.resource.id===n.id?null:e.current,i=aa(e.stack.filter(e=>B(e.resource)?.id!==n.id),r);return{...e,stack:i,current:r}}case`updateCurrent`:return{...e,current:t.payload.resource};case`back`:{let t=e.stack[0];return{...e,stack:e.stack.slice(1),current:t||null}}case`close`:return{...e,stack:[],current:null};case`create`:return t.payload.resource===null?{...e,create:null}:{...e,create:t.payload}}return e}function aa(e,t){let n=[],r=null;for(let t of e)r?.resource.id!==t.resource.id&&(n.push(t),r=t);return r&&r.resource.id===t?.resource.id?n.slice(0,n.length-1):n}const oa={stack:[],current:null,create:null},sa=O(oa),ca=O({edit(){},close(){},back(){},setStack(){},updateCurrent(){},create(){return()=>{}}});function la(){return A(ca)}function ua(){return A(sa).current}function da(){return A(sa).stack}function fa(){return A(sa).create}function pa(){let{manifest:e}=Ke(),t=z(),[n,r]=Oe(e=>e+1,0);U(e,`Manifest not found`);let i=N(()=>new $e({reference:{id:e,type:`Manifest`},vault:t}),[e,t]);return j(()=>i.observe.start(r),[i]),i.observe.key=`${n}`,i.observe.reset(),i}function ma(){let{collection:e}=Ke(),t=z(),[n,r]=Oe(e=>e+1,0);U(e,`Collection not found`);let i=N(()=>new $e({reference:{id:e,type:`Collection`},vault:t}),[e,t]);return j(()=>i.observe.start(r),[i]),i.observe.key=`${n}`,i.observe.reset(),i}function ha(e,t={}){let n=z(),[r,i]=Oe(e=>e+1,0);!t.allowNull&&U(e,`Resource not found`);let a=N(()=>t.allowNull&&!e?null:new $e({reference:B(e),vault:n,context:{resource:e,parent:t.parent,index:t.index,parentProperty:t.parentProperty}}),[e,n]);return j(()=>a?.observe.start(i),[a]),a&&(a.observe.key=`${r}`,a.observe.reset()),a}function ga(){let{annotationPage:e}=Ke();return U(e,`Annotation page not found`),ha({id:e,type:`AnnotationPage`})}function _a(){let e=ua(),t=z(),[n,r]=Oe(e=>e+1,0);U(e,`No resource selected`);let i=N(()=>new $e({reference:e.resource.source||e.resource,vault:t}),[e,t]);return j(()=>i.observe.start(r),[i]),i.observe.key=`${n}`,i.observe.reset(),i}function va(e){let t=z(),[n,r]=Oe(ia,e),i=k(e=>{r(e)},[]);j(()=>t.on(`@iiif/REMOVE_REFERENCE`,e=>{let t=e.action,n={id:t.payload.id,type:t.payload.type},i=t.payload.reference;r({type:`syncRemoval`,payload:{resource:{parent:n,resource:i}}})}),[t]);let a=k((e,t=!1)=>i({type:`edit`,payload:{resource:e,reset:t}}),[]),o=k(e=>i({type:`setStack`,payload:{resources:e}}),[]),s=k(e=>i({type:`updateCurrent`,payload:{resource:e}}),[]),c=k(()=>i({type:`close`}),[]),l=k(()=>i({type:`back`}),[]),u=k((e,t)=>(i({type:`create`,payload:{resource:e,options:t}}),()=>{i({type:`create`,payload:{resource:null}})}),[]);return[n,N(()=>({edit:a,updateCurrent:s,close:c,back:l,create:u,setStack:o}),[])]}function ya(e){let{instanceId:t}=fi(),[n,r]=va(e.initialState||oa);return L(ca.Provider,{value:r,children:L(sa.Provider,{value:n,children:e.children})},t)}function ba({resource:e,children:t}){let{instanceId:n}=fi(),[r,i]=va(N(()=>({create:null,stack:[],current:{resource:{type:`SpecificResource`,source:{id:e.id,type:e.type}}}}),[]));return L(ca.Provider,{value:i,children:L(sa.Provider,{value:r,children:t})},n)}const xa=O(null),Sa=O(null),Ca=O(`default`);function wa(){return A(Sa)}function Ta(){return A(xa)}function Ea(){return A(Ca)}function Da(){return q().layout}function Oa(){let e=q(),t=e.layout,n=A(xa),r=A(Sa);return N(()=>({actions:n,state:r,...t}),[e,r])}const ka=`@manifest-editor/tags`,Aa=`tags`,ja={type:`flag`,id:`flag`,label:`Flag`,backgroundColor:`#b91c1c`,textColor:`#ffffff`,icon:`flag`},Ma=[];function Na(e){return typeof e==`string`?e:e?.id||null}function Pa(e){return e.type||e.id}function Fa(e){return`${e.type}:${e.id}`}function Ia(e){if(!Array.isArray(e))return Ma;let t=new Map;for(let n of e){if(!n?.id)continue;let e=Pa(n);t.set(e,{...n,type:e})}return Array.from(t.values())}function La(e){return e.label||e.id||e.type}function Ra(e,t){return e===ja.type&&(!t||t===ja.id)}function za(e,t){return Ra(e.type,e.id)?-1:Ra(t.type,t.id)?1:La(e.tag).localeCompare(La(t.tag))||e.type.localeCompare(t.type)||e.id.localeCompare(t.id)}function Ba(e,t){return Ra(e.type)?-1:Ra(t.type)?1:e.type.localeCompare(t.type)}function Va(e,t){let n=Na(t);return n?Ia(e.getResourceMeta(n,ka)?.[Aa]):Ma}function Ha(e,t){let n=Na(t);return n?Ia(e?.iiif?.meta?.[n]?.[ka]?.[Aa]):Ma}function Ua(e,t,n){let r=Na(t);if(!r)return Ma;let i=Ia(n);return e.setMetaValue([r,ka,Aa],i),i}function Wa(e,t,n){return Ua(e,t,[...Va(e,t),n])}function Ga(e,t,n){return Va(e,t).find(e=>e.type===n)}function Ka(e,t,n,r){return Ua(e,t,Va(e,t).filter(e=>e.type!==n||(r?e.id!==r:!1)))}function qa(e,t){let n=new Map;for(let r of t){let t=Na(r);if(t)for(let i of Va(e,r)){let e=i.type,r=Fa(i),a=n.get(e);a||(a={key:e,type:i.type,rows:[],canvasIds:[],canvasCount:0,tagCount:0},n.set(e,a));let o=a.rows.find(e=>e.key===r);o||(o={key:r,type:i.type,id:i.id,tag:i,canvasIds:[],canvasCount:0},a.rows.push(o)),o.canvasIds.push(t),o.canvasCount=o.canvasIds.length,a.tagCount+=1}}for(let e of n.values())e.rows.sort(za),e.canvasIds=Array.from(new Set(e.rows.flatMap(e=>e.canvasIds))),e.canvasCount=e.canvasIds.length;return Array.from(n.values()).sort(Ba)}function Ja(e,t,n,r){let i=Ga(e,t,n);return r?i?.id===r:!!i}function Ya(e,t,n){return Ja(e,t,n.type,n.id)?Ka(e,t,n.type):Wa(e,t,n)}function Xa(e){return{getTags(t){return Va(e,t)},setTags(t,n){return Ua(e,t,n)},addTag(t,n){return Wa(e,t,n)},upsertTag(t,n){return Wa(e,t,n)},getTag(t,n){return Ga(e,t,n)},removeTag(t,n,r){return Ka(e,t,n,r)},hasTag(t,n,r){return Ja(e,t,n,r)},toggleTag(t,n){return Ya(e,t,n)}}}function Za(e){let t=Na(e);return qe(e=>t?Ha(e,t):Ma,[t])}function Qa(e){let t=z(),n=Na(e),r=N(()=>Xa(t),[t]);return N(()=>({setTags(e){return r.setTags(n,e)},addTag(e){return r.addTag(n,e)},getTag(e){return r.getTag(n,e)},removeTag(e,t){return r.removeTag(n,e,t)},toggleTag(e){return r.toggleTag(n,e)},hasTag(e,t){return r.hasTag(n,e,t)}}),[r,n])}function $a({icon:e,title:t,...n}){return e===`flag`?R(`svg`,{viewBox:`0 0 24 24`,width:`1em`,height:`1em`,"aria-hidden":t?void 0:!0,...n,children:[t?L(`title`,{children:t}):null,L(`path`,{fill:`currentColor`,d:`M5 21a1 1 0 0 1-1-1V5.6c0-.42.26-.8.65-.94C6.7 3.9 8.65 4 10.5 4.7c1.55.58 3.05.7 4.5.36l3.75-.88A1 1 0 0 1 20 5.15v9.25c0 .46-.31.86-.75.97l-3.79.9c-1.85.43-3.76.28-5.66-.43-1.28-.48-2.55-.59-3.8-.33V20a1 1 0 0 1-1 1Z`})]}):null}function eo({tag:e,showIcon:t=!0,className:n,style:r}){return R(`span`,{className:`inline-flex max-w-full items-center gap-0.5 rounded px-1 py-0.5 font-medium shadow-sm ${n||``}`,style:{backgroundColor:e.backgroundColor||`#e5e7eb`,color:e.textColor||`#111827`,fontSize:9,lineHeight:`11px`,...r},children:[t&&e.icon?L($a,{icon:e.icon,className:`h-2.5 w-2.5 flex-shrink-0`}):null,L(`span`,{className:`min-w-0 truncate`,children:La(e)})]})}function to({resource:e,tags:t,className:n}){return t?L(ro,{tags:t,className:n}):L(no,{resource:e,className:n})}function no({resource:e,className:t}){return L(ro,{tags:Za(e),className:t})}function ro({tags:e,className:t}){let n=e;return n.length?L(`div`,{className:`pointer-events-none absolute bottom-1 right-1 z-10 flex max-w-full flex-wrap justify-end gap-0.5 ${t||``}`,children:n.map(e=>L(eo,{tag:e},e.type))}):null}const io=O(null);function ao(e){return e===`error`?8e3:5e3}function oo({children:e,maxVisibleToasts:t=3}){let n=et({maxVisibleToasts:t}),r=N(()=>{let e=(e,t)=>n.add(e,{...t,timeout:t?.timeout??ao(e.variant)}),t=(t,n,r)=>e({...n,variant:t},r);return{add:e,info:(e,n)=>t(`info`,e,n),success:(e,n)=>t(`success`,e,n),warning:(e,n)=>t(`warning`,e,n),error:(e,n)=>t(`error`,e,n),close:n.close}},[n]);return R(io.Provider,{value:r,children:[e,L(me,{state:n})]})}function so(){let e=A(io);if(!e)throw Error(`useToasts must be used within a ToastProvider`);return e}function co(e){return e.status!==`complete`&&e.status!==`error`||!e.completedAt?null:`${e.id}:${e.status}:${e.completedAt}`}function lo(e,t,n){let r=t.label||e.label;return t.status===`complete`?{variant:`success`,title:`${r} complete`,description:t.resultsAvailable?`Results are ready.`:void 0,action:t.resultsAvailable&&n?{label:`Results`,onPress:n}:void 0}:t.status===`error`?{variant:`error`,title:`${r} failed`,description:t.error?.message||t.statusText||`Action failed`}:null}function uo(e){return{id:e.id,type:e.type,label:e.type,scope:`root`}}function fo(e){if(!(!e||!e.id||e.type!==`Canvas`))return{id:e.id,type:`Canvas`,label:`Current canvas`,scope:`canvas`}}function po(){let e=ua(),t=da();return N(()=>fo([e,...t].find(e=>e?.resource?.source?.type===`Canvas`)?.resource?.source),[e,t])}function mo(){let e=Oi(),t=po(),n=z(),r=N(()=>Xa(n),[n]),i=N(()=>Ut(n),[n]),a=ri(),o=Ot(),s=wa(),c=Ta();return N(()=>({rootResource:e,currentCanvas:t,vault:n,tags:r,canvasProgress:i,plugins:a,config:o,layoutState:s,layoutActions:c}),[e,t,n,r,i,a,o,s,c])}function ho(){let e=K(e=>e.definitions),t=K(e=>e.instances),n=mo(),r=N(()=>uo(n.rootResource),[n.rootResource]);return N(()=>sn({definitions:e,instances:t,systemContext:n,targets:[r,...n.currentCanvas?[n.currentCanvas]:[]],onSupportsError:(e,t)=>{console.error(`Background action "${e.id}" failed support check`,t)}}),[e,t,r,n])}function go(){let e=nr(),t=K(e=>e.definitions),n=K(e=>e.instances),r=K(e=>e.plans),i=K(e=>e.controllers),a=K(e=>e.hasHydrated),o=mo(),s=P(new Set);return j(()=>{if(!a)return;let c=new Map(t.map(e=>[e.id,e]));for(let[t,a]of Object.entries(n)){let n=c.get(a.actionId),l=`${t}:${a.runId}`;!n?.resumable||!vo(a)||!r[t]||i[t]||s.current.has(l)||(s.current.add(l),Jn({store:e,resume:!0,context:{...o,definition:n,target:a.target,instanceKey:t,instance:a}}))}},[i,t,a,n,r,e,o]),L(I,{children:t.map(e=>e.render?L(xe,{children:e.render({...o,definition:e})},e.id):null)})}function _o(){let e=K(e=>e.definitions),t=K(e=>e.instances),n=mo(),r=so(),i=P(new Set),a=N(()=>new Map(e.map(e=>[e.id,e])),[e]);return j(()=>{for(let e of Object.values(t)){let t=co(e);if(!t||i.current.has(t))continue;let o=a.get(e.actionId);if(!o)continue;let s={...n,definition:o,target:e.target,instanceKey:e.id,instance:e},c=lo(o,e,e.resultsAvailable&&o.onResults?()=>{o.onResults?.(s)}:void 0);c&&(r.add(c),i.current.add(t))}},[a,t,n,r]),null}function vo(e){return e?.status===`preparing`||e?.status===`running`}function yo(e){return!e||e.status===`idle`?``:e.status===`error`?e.error?.message||e.statusText||`Error`:e.status===`complete`&&e.resultsAvailable?`Results ready`:e.status===`cancelled`?`Cancelled`:e.statusText||e.status}function bo(e){return e?new Date(e).toLocaleString():`Not recorded`}function xo(e){return e?new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):`--:--:--`}function So(e){if(!e.startedAt)return`Not recorded`;let t=e.completedAt||Date.now(),n=Math.max(0,Math.round((t-e.startedAt)/1e3)),r=Math.floor(n/60),i=n%60;return r?`${r}m ${i}s`:`${i}s`}function Co(e){if(e===void 0)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function wo({label:e,value:t}){return R(`div`,{className:`min-w-0`,children:[L(`dt`,{className:`text-[10px] font-semibold uppercase tracking-widest text-zinc-400`,children:e}),L(`dd`,{className:`mt-1 break-words text-sm text-zinc-800`,children:t})]})}const To={debug:{label:`DBG`,className:`text-zinc-500`},verbose:{label:`VRB`,className:`text-zinc-500`},info:{label:`INF`,className:`text-sky-400`},log:{label:`LOG`,className:`text-zinc-300`},warn:{label:`WRN`,className:`text-amber-400`},warning:{label:`WRN`,className:`text-amber-400`},error:{label:`ERR`,className:`text-red-400`}};function Eo(e){return To[e?.toLowerCase()]??{label:e?.toUpperCase().slice(0,3)??`LOG`,className:`text-zinc-300`}}const Do={error:`bg-red-100 text-red-700`,failed:`bg-red-100 text-red-700`,completed:`bg-green-100 text-green-700`,success:`bg-green-100 text-green-700`,started:`bg-sky-100 text-sky-700`,cancelled:`bg-zinc-100 text-zinc-600`,warning:`bg-amber-100 text-amber-700`,warn:`bg-amber-100 text-amber-700`};function Oo(e){return Do[e?.toLowerCase()]??`bg-zinc-100 text-zinc-600`}function ko(e){return e?.toLowerCase()in Do}function Ao({definition:e,instance:t,onClose:n}){let[r,i]=F(`overview`),a=P(null),o=t.logs.length;j(()=>{r===`logs`&&a.current?.scrollIntoView({behavior:`instant`})},[r]);let s={idle:`bg-zinc-100 text-zinc-600`,preparing:`bg-orange-100 text-orange-700`,running:`bg-orange-100 text-orange-700`,complete:`bg-green-100 text-green-700`,error:`bg-red-100 text-red-700`,cancelled:`bg-zinc-100 text-zinc-500`},c=t.events.filter(e=>ko(e.type)),l=[{id:`overview`,label:`Overview`},{id:`logs`,label:`Logs`,count:o}];return R(ee,{title:t.label||e.label,onClose:n,className:`max-w-3xl`,children:[L(`div`,{className:`sticky top-0 z-10 border-b border-zinc-200 bg-white px-2`,children:L(`div`,{className:`flex gap-0.5`,children:l.map(e=>R(`button`,{type:`button`,onClick:()=>i(e.id),className:[`flex items-center gap-1.5 border-b-2 px-3 py-2.5 text-sm transition-colors -mb-px`,r===e.id?`border-me-primary-500 font-semibold text-me-primary-600`:`border-transparent text-zinc-500 hover:text-zinc-800`].join(` `),children:[e.label,e.count?L(`span`,{className:`rounded-full bg-zinc-100 px-1.5 py-0.5 text-[10px] font-medium text-zinc-500`,children:e.count}):null]},e.id))})}),r===`overview`&&R(`div`,{className:`flex flex-col gap-5 p-5`,children:[R(`div`,{className:`flex flex-wrap items-center gap-2`,children:[L(`span`,{className:[`inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-semibold uppercase tracking-wide`,s[t.status]??`bg-zinc-100 text-zinc-600`].join(` `),children:t.status}),t.statusText?L(`span`,{className:`text-sm text-zinc-500`,children:t.statusText}):null]}),R(`dl`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[L(wo,{label:`Target`,value:`${t.target.label} (${t.target.type})`}),L(wo,{label:`Run ID`,value:t.runId}),L(wo,{label:`Started`,value:bo(t.startedAt)}),L(wo,{label:`Finished`,value:bo(t.completedAt)}),L(wo,{label:`Duration`,value:So(t)}),t.progress?L(wo,{label:`Progress`,value:`${Math.round(t.progress.percent)}%${t.progress.label?` — ${t.progress.label}`:``}`}):null]}),t.progress?R(`div`,{children:[L(d,{percent:t.progress.percent,label:t.progress.label||`Background action progress`}),typeof t.progress.current==`number`&&typeof t.progress.total==`number`?R(`div`,{className:`mt-1 text-xs text-zinc-500`,children:[t.progress.current,` of `,t.progress.total,` items`]}):null]}):null,t.error?R(`div`,{className:`rounded-lg border border-red-200 bg-red-50`,children:[L(`div`,{className:`border-b border-red-200 px-4 py-2.5`,children:L(`span`,{className:`text-xs font-semibold uppercase tracking-widest text-red-600`,children:`Error`})}),R(`div`,{className:`p-4`,children:[L(`div`,{className:`text-sm font-medium text-red-800`,children:t.error.message}),t.error.stack?L(`pre`,{className:`mt-3 max-h-40 overflow-auto rounded bg-red-100 p-3 text-xs text-red-700 leading-relaxed whitespace-pre-wrap`,children:t.error.stack}):null]})]}):null,c.length>0?R(`div`,{children:[L(`h3`,{className:`mb-2 text-[10px] font-semibold uppercase tracking-widest text-zinc-400`,children:`Key events`}),L(`div`,{className:`divide-y divide-zinc-100 rounded-lg border border-zinc-200`,children:c.map(e=>R(`div`,{className:`flex items-baseline gap-3 px-3 py-2`,children:[L(`span`,{className:[`shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide`,Oo(e.type)].join(` `),children:e.type}),L(`span`,{className:`min-w-0 flex-1 truncate text-sm text-zinc-700`,children:e.message||e.type}),L(`time`,{className:`shrink-0 text-xs text-zinc-400`,children:xo(e.createdAt)})]},e.id))})]}):null]}),r===`logs`&&L(`div`,{className:`p-5`,children:o===0?L(`div`,{className:`rounded-lg border border-zinc-200 p-6 text-center text-sm text-zinc-400`,children:`No logs recorded.`}):R(`div`,{className:`overflow-hidden rounded-lg bg-zinc-950 shadow-inner`,children:[R(`div`,{className:`flex items-center gap-1.5 border-b border-white/10 px-3 py-2`,children:[L(`div`,{className:`h-2.5 w-2.5 rounded-full bg-zinc-700`}),L(`div`,{className:`h-2.5 w-2.5 rounded-full bg-zinc-700`}),L(`div`,{className:`h-2.5 w-2.5 rounded-full bg-zinc-700`}),R(`span`,{className:`ml-2 text-[10px] text-zinc-500 font-mono`,children:[o,` `,o===1?`entry`:`entries`]})]}),R(`div`,{className:`max-h-[50vh] overflow-y-auto p-1 font-mono text-xs`,children:[t.logs.map(e=>{let t=Eo(e.level);return R(`div`,{className:`group flex gap-0 hover:bg-white/5 rounded px-2 py-1 leading-relaxed`,children:[L(`time`,{className:`w-20 shrink-0 text-zinc-600 select-none pr-2`,children:xo(e.createdAt)}),L(`span`,{className:[`w-10 shrink-0 select-none font-bold pr-2`,t.className].join(` `),children:t.label}),R(`span`,{className:`min-w-0 flex-1 text-zinc-200 break-words`,children:[e.message,e.data===void 0?null:L(`span`,{className:`block mt-0.5 text-zinc-500 whitespace-pre-wrap`,children:Co(e.data)})]})]},e.id)}),L(`div`,{ref:a})]})]})})]})}function jo(){let e=nr(),t=ho(),[n,g]=F(null),_=t.reduce((e,t)=>e+t.actions.length,0),v=t.reduce((e,t)=>e+t.actions.filter(e=>vo(e.instance)).length,0),y=t.reduce((e,t)=>e+t.actions.filter(e=>e.instance?.status===`error`).length,0),{isOpen:b,buttonProps:x,itemProps:S,setIsOpen:C}=Xe(_);if(!_)return null;let w=n?t.flatMap(e=>e.actions).find(e=>e.instanceKey===n):void 0,T=0;return R(f,{children:[L(r,{active:b,runningCount:v,errorCount:y,"aria-label":`Actions menu`,...x}),L(u,{open:b,role:`menu`,children:L(`div`,{className:`py-1.5`,children:t.map((t,n)=>R(xe,{children:[n?L(i,{}):null,L(p,{children:t.label}),t.actions.map(t=>{let{onKeyDown:n,...r}=S[T++]||{},i=yo(t.instance),u=vo(t.instance),f=()=>{u||(Jn({store:e,context:t.context}),C(!0))},p=()=>{u&&(e.getState().cancelAction(t.instanceKey),C(!0))};return R(s,{status:t.instance?.status||`idle`,children:[L(h,{running:u,...r,"aria-label":u?`Cancel ${t.definition.label}`:`Run ${t.definition.label}`,onMouseDown:e=>{e.preventDefault()},onClick:e=>{e.stopPropagation(),u?p():f()},onKeyDown:e=>{e.key===`Enter`||e.key===` `?(e.preventDefault(),e.stopPropagation(),u?p():f()):n?.(e)},children:R(m,{children:[L(c,{running:u,children:t.instance?.label||t.definition.label}),i?L(l,{variant:t.instance?.status===`error`?`error`:`default`,children:i}):null,t.definition.summary&&!i?L(l,{children:t.definition.summary}):null,u&&t.instance?.progress?L(d,{percent:t.instance.progress.percent,label:t.instance.progress.label||i||t.definition.label}):null]})}),t.instance?.resultsAvailable&&t.definition.onResults?L(o,{onClick:e=>{e.stopPropagation(),t.definition.onResults?.(t.context)},children:`Results`}):null,t.instance?L(a,{"aria-label":`View ${t.definition.label} details`,onClick:e=>{e.preventDefault(),e.stopPropagation(),g(t.instanceKey),C(!0)}}):null]},t.instanceKey)})]},t.id))})}),w?.instance?L(Ao,{definition:w.definition,instance:w.instance,onClose:()=>g(null)}):null]})}const Mo=Ee(function(e){let[t]=_e(`menu-hidden`);return L(xi,{children:R(bi,{children:[L(Si,{onClick:e.onClickLogo,children:L(E,{})}),L(ra,{}),L(jo,{})]})})}),No=O(null);function Po(){return A(No)||null}function Fo(e,t){let n=Po();return n?n[e][t]:null}function Io({children:e,menu:t}){return L(No.Provider,{value:t,children:e})}function Lo(){return A(Fe)}function Ro(e){if(!e)return null;if(e.points.length>2){let t=Math.min(...e.points.map(e=>e[0])),n=Math.min(...e.points.map(e=>e[1])),r=Math.max(0,...e.points.map(e=>e[0])),i=Math.max(0,...e.points.map(e=>e[1]));return{x:t,y:n,width:r-t,height:i-n}}return null}const zo=async e=>new Promise((t,n)=>{let r=document.createElement(`img`);r.onload=()=>t(r),r.onerror=()=>n(),r.src=e,r.complete&&t(r)}),Bo=async e=>new Promise((t,n)=>{let r=document.createElement(`video`);r.onloadedmetadata=()=>t(r),r.onerror=()=>n(),r.preload=`metadata`,r.src=e});async function Vo(){}async function Ho(e,...t){if(!e)return;if(e.endsWith(`.mp3`)||e.endsWith(`.mp4`)||e.endsWith(`.m4a`)||e.endsWith(`.m4v`))try{let t=await Bo(e);if(t){let n=t.videoWidth===0;return{id:e,type:t.videoWidth===0?`Sound`:`Video`,width:t.videoWidth||void 0,height:t.videoHeight||void 0,duration:t.duration,format:n?`audio/mp4`:`video/mp4`}}}catch{}let n=null;try{n=await fetch(e)}catch{return Go(e)}if(!n.ok&&(n=await fetch(e+`/info.json`),!n.ok))return Go(e);let r=n.headers.get(`Content-Type`);if(r?.includes(`image/`))return Go(e,r);let i=null;try{i=await n.json()}catch{return null}return await Wo(i,e)}function Uo(e){return e.protocol&&e.protocol===`http://iiif.io/api/image`?(e.type||(e.type=`ImageService`),e):null}async function Wo(e,t){let n=Uo(e);if(n)return n;if(!(e.id||e[`@id`]))return null;let r=await new nt.Vault().load(t,e);if(r&&(r&&r?.type===`Manifest`||r?.type===`Collection`))return{id:t,type:r.type,label:tt(r.label)}}async function Go(e,t){let n=e.split(`/`);if(n.length>=8){let e=n.slice(-4);if(e[3].split(`.`).length===2&&(e[2][0]===`!`||e[2]===e[2])){let e=await Ko(n.slice(0,n.length-4).join(`/`)+`/info.json`);if(e&&e?.type&&e?.type?.startsWith(`ImageService`))return e}}try{let n=await zo(e);return{id:e,type:`Image`,width:n.width,height:n.height,format:await qo(e,t)}}catch{}return null}async function Ko(e){try{let t=await fetch(e);return t.ok?await Wo(await t.json(),e):null}catch(e){return console.log(e),null}}async function qo(e,t){if(t)return t;try{let t=(await fetch(e,{method:`HEAD`,mode:`no-cors`})).headers.get(`Content-type`);if(t)return t}catch{}let n=e.toLowerCase();return n.endsWith(`jpg`)||n.endsWith(`jpeg`)?`image/jpeg`:n.endsWith(`png`)?`image/png`:`image/jpeg`}async function Jo(e){try{let t=await zo(e);if(t)return{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}}catch{return null}return null}const Yo=ke(e=>({regions:{},resources:[],setRegion:(t,n)=>{e(e=>({...e.regions,regions:{[t]:n||null}}))},setHighlight:t=>{e({resources:Array.isArray(t)?t:[t]})},highlight:t=>{e(e=>e.resources.indexOf(t)===-1?{resources:[...e.resources,t]}:e)},clearHighlight:t=>{e(e=>({resources:e.resources.filter(e=>e!==t)}))}}));function Xo(e){let t=N(()=>lr(),[]),n=Yo(e=>e.regions[t]),r=Yo(e=>e.setRegion);j(()=>{n&&e?n!==e&&(n.x!==e.x||n.y!==e.y||n.width!==e.width||n.height!==e.height)&&r(t,e||null):r(t,e||null)},[n]),j(()=>()=>r(t,null),[])}function Zo(e){let t=Yo(e=>e.highlight),n=Yo(e=>e.clearHighlight);return j(()=>()=>{e&&n(e)},[n,e]),N(()=>({onMouseEnter(){e&&t(e)},onMouseLeave(){e&&n(e)}}),[e,t,n])}const Qo=e=>R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,viewBox:`0 0 24 24`,...e,children:[L(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),L(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),L(`path`,{d:`M12 17.27 18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z`,fill:`currentColor`})]}),$o=({style:e})=>R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`1rem`,viewBox:`0 0 24 24`,width:`1rem`,fill:`#000000`,style:e,children:[L(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),L(`path`,{d:`M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z`})]});function es(e){let t=e.error.toString(),[n,r]=F(!1);return R(ne,{children:[L(x,{className:`mb-2`,children:t}),L(Ki,{onClick:e.resetErrorBoundary,children:`Try again`})]})}function ts(e){return e&&e.pinnable}function ns({initial:e,fallback:t,options:n={}}){return Math.max(n.minWidth||0,Math.min(n.maxWidth||1/0,e||t))}function rs(e){return typeof e==`string`?Ce(`div`,{dangerouslySetInnerHTML:{__html:e}}):e}const is=V.div`
243
243
  position: relative;
244
244
  display: inline-block;
245
245
  `;V.div`
@@ -257,7 +257,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
257
257
  background-color: ${e=>e.theme.color.lightgrey||`lightgrey`};
258
258
  }
259
259
  }
260
- `;const Zo=V.button`
260
+ `;const as=V.button`
261
261
  padding: 0 ${e=>e.theme.padding.small||`0.5rem`};
262
262
  color: ${e=>e.theme.color.main||`none`};
263
263
  background-color: ${e=>e.theme.color.white||`white`};
@@ -284,7 +284,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
284
284
  color: #fff;
285
285
  }
286
286
  `}
287
- `,Qo=V.div`
287
+ `,os=V.div`
288
288
  display: none;
289
289
  flex-direction: column;
290
290
  position: absolute;
@@ -311,17 +311,17 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
311
311
  ${e=>e.$open&&H`
312
312
  display: flex;
313
313
  `}
314
- `,$o=V.div`
314
+ `,ss=V.div`
315
315
  color: #999;
316
316
  text-transform: uppercase;
317
317
  font-weight: 600;
318
318
  padding: 0.7em;
319
319
  font-size: 0.875em;
320
- `,es=V.div`
320
+ `,cs=V.div`
321
321
  height: 1px;
322
322
  margin: 0 0.5em;
323
323
  background: #eee;
324
- `,ts=O(null);function ns(){return A(ts)}const rs=V.div`
324
+ `,ls=O(null);function us(){return A(ls)}const ds=V.div`
325
325
  display: flex;
326
326
  flex-direction: column;
327
327
  position: relative;
@@ -373,7 +373,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
373
373
  &[data-state="unmounted"] {
374
374
  transform: translateX(100%);
375
375
  }
376
- `,is=V.div`
376
+ `,fs=V.div`
377
377
  background: #fff;
378
378
  display: flex;
379
379
  height: 2.8em;
@@ -395,7 +395,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
395
395
  background: #ffc2d2;
396
396
  box-shadow: inset 0 -5px 10px 0 rgba(255, 255, 255, 0.5);
397
397
  }
398
- `,as=V.button`
398
+ `,ps=V.button`
399
399
  border: none;
400
400
  background: transparent;
401
401
  padding: 0 0.4em;
@@ -407,15 +407,15 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
407
407
  svg {
408
408
  font-size: 1.2em;
409
409
  }
410
- `,os=V.div`
410
+ `,ms=V.div`
411
411
  flex: 1 1 0px;
412
- `,ss=V.div`
412
+ `,hs=V.div`
413
413
  font-size: 0.875em;
414
414
  flex: 1 1 0px;
415
415
  padding-left: 1em;
416
416
  text-align: center;
417
417
  align-self: center;
418
- `,cs=V.div`
418
+ `,gs=V.div`
419
419
  flex: 1 1 0px;
420
420
  display: flex;
421
421
 
@@ -426,13 +426,13 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
426
426
  > * {
427
427
  min-width: 0;
428
428
  }
429
- `;function ls({panel:e,state:t,actions:n,isLeft:r,pinActions:i=n,transition:a,close:o,available:s=[],style:c,noHeader:l}){let u=A(ze)||null,[d,f]=F(!1),p=ai(),m=ba(),{tabs:h,pinnable:g,hideHeader:_}=e?.options||{},v=[p.state.canvasId,e?.id],y=N(()=>(s||[]).filter(e=>!e.requiresState),[s]),{itemProps:b,isOpen:x,setIsOpen:S}=Xe(y.length),[C,w]=F(``),T=P(void 0);j(()=>f(!1),v),j(()=>w(``),[e]),j(()=>(T.current=w,()=>{T.current=void 0}),[]);let E=k(e=>{T.current&&T.current(e)},[]),ee=k(r=>{let i=e?t.stack.length?n.popStack:e.backAction?()=>e&&e.backAction&&e.backAction(t,{...m,current:n},p):null:null;r&&(!i||r.metaKey)&&y.length?(r.preventDefault(),S(!0)):i&&i()},[n,p,m,e,S,t,y.length]),te=r=>{n.change({id:r.id,state:r.defaultState,stacked:!!(t.stack.length||e?.backAction)})};if(!e||!t.current)return null;let ne=e.backAction||t.stack.length?L(as,{onClick:ee,children:L(Go,{})}):null,re=L(as,{onClick:o||n.close,children:L(hi,{})});return L(ts.Provider,{value:E,children:R(rs,{"data-state":a,"data-flipped":r,style:c,"data-header":!l,children:[l?null:R(is,{"data-tabs":!!h,"data-error":d,children:[R(Xo,{style:{display:`flex`,height:`100%`},children:[e.renderBackAction?e.renderBackAction({backAction:ee,fallback:ne}):ne,y.length?R(Qo,{$open:x,style:{left:`0.5em`},children:[L($o,{children:`All panels`}),L(es,{}),y.map((t,n)=>L(Zo,{...b[n],onClick:()=>te(t),$active:e.id===t.id,children:t.label},n))]}):null]}),C?L(ss,{children:C}):_?L(os,{}):L(ss,{children:e.label}),g?t.pinned?L(as,{onClick:i.unpin,children:L(Wo,{fill:`orange`})}):L(as,{onClick:()=>i.pin({id:e.id,state:t.state}),children:L(Wo,{fill:`#ddd`})}):null,e.renderCloseAction?e.renderCloseAction({closeAction:o||n.close,fallback:re}):re]}),L(cs,{className:`OverrideScrollbar`,children:L(ot,{onError:()=>f(!0),FallbackComponent:Ko,resetKeys:v,onReset:()=>f(!1),children:Yo(e.render(t.state||e.defaultState||{},{...m,current:n,vault:u,transition:a},p))})})]})})}function us(e=`vault://homepage-collection.json`){let t=new rt,n=window.localStorage.getItem(`preview-vault-collection`),r=!1;if(n)try{let i=JSON.parse(n);if(i.id&&i.id===e){t.dispatch(dt({id:i.id}));let e=ft(i.id,i);t.dispatch(ct({actions:e})),r=!0}}catch{}if(!r){let n=ft(e,{"@context":`http://iiif.io/api/presentation/3/context.json`,id:e,type:`Collection`,label:{en:[`Recent items`]},items:[]});t.dispatch(dt({id:e})),t.dispatch(ct({actions:n}))}return t.on(`after:@iiif/REMOVE_REFERENCE`,n=>{n.action.payload.id===e&&window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}),{vault:t,unsubscribe:()=>{},addHistory:(n,r)=>{let i=t.getState();if(n&&r&&(r===`Collection`||r===`Manifest`)){let a=i.iiif.entities.Collection[e];if(a){let i=a.items.findIndex(e=>e.id===n);i===-1?t.dispatch(st({id:e,type:`Collection`,reference:{id:n,type:r},key:`items`,index:0})):t.dispatch(ut({id:e,type:`Collection`,key:`items`,startIndex:i,endIndex:0})),window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}}},clearHistory:()=>{t.dispatch(lt({id:e,type:`Collection`,key:`items`,value:[]})),window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}}}function ds(){return A(fs)}const fs=O(new rt),ps=O({addHistory:(e,t)=>{},clearHistory:()=>{}}),ms=`manifest-editor://homepage-collection.json`;function hs(){return A(ps)}function gs(e){let{vault:t,unsubscribe:n,addHistory:r,clearHistory:i}=N(()=>us(ms),[]);return j(()=>n,[]),L(ps.Provider,{value:{addHistory:r,clearHistory:i},children:L(fs.Provider,{value:t,children:e.children})})}function _s({children:e}){return L(Ve,{vault:ds(),children:e})}function vs(e,t,n,r,i){let a=z(),o=q(),{create:s,edit:c}=_a(),l=N(()=>at({type:n,parent:e,index:0,property:t},o.layout.creators||[],{vault:a}),[e,t,o.layout.creators,n,a]),u=e&&l.length!==0,d=k((a,o)=>{if(e)return s({type:n,parent:B(e),property:t,index:a,target:r,initialData:o,...i||{}})},[s,e,t,n,i,r]),f=k((a,o,c)=>{if(e)return s({type:n,filter:a,parent:B(e),property:t,index:o,target:r,initialData:c,...i||{}})},[s,e,t,n,i,r]);return[u,{create:d,edit:k((n,r)=>{c(n,e?{parent:B(e),property:t,index:r}:void 0)},[c,e,t]),createFiltered:f,creator:k((a,o)=>{if(e)return s({type:n,initialCreator:a,parent:B(e),property:t,target:r,initialData:o,...i||{}})},[n,t,e,r,s,i]),buttonProps:N(()=>({"data-action-id":nr(n,t,e)}),[n,t,e])}]}function ys(){let e=z(),t=ds(),n=q();return N(()=>new it(e,n.layout.creators||[],t),[n.layout.creators,e])}const bs=O({});function xs(e){return A(bs)[e]||{}}function Ss(e){let t=A(bs),n=N(()=>({...t,[e.id]:e.data}),[t,e.id,e.data]);return L(bs.Provider,{value:n,children:e.children})}const Cs=Ee(function(t){let n=z(),{edit:r,modal:i}=_a(),[a,o]=F(!1),[s,c]=F(null),l=ys(),u=P(!1),d=t.resource.initialData?.selector;Ho(d);let f=xs(t.creator.id),p={targetType:t.resource.type,parent:t.resource.parent?{property:t.resource.property,atIndex:t.resource.index,resource:t.resource.parent}:void 0,target:t.resource.target,initialData:{...f,...t.resource.initialData||{}}},m=e=>{try{if(a||u.current)return;o(!0),u.current=!0,l.create(t.creator.id,e,p).catch(e=>(c(e?.message||`Unknown error`),null)).then(async e=>{if(t.onCreate?.(),t.resource.initialData?.skipEditingOnCreate){o(!1),i.popStack(),i.close();return}if(t.skipEditingOnCreate||!e)return;let n=Array.isArray(e)?e[0]:e;o(!1),i.popStack(),i.close(),n&&r(n,{parent:B(t.resource.parent),property:t.resource.property,index:t.resource.index})})}catch(e){c(e?.message||`Unknown error`)}},h=async()=>!0;if(j(()=>{t.resource.initialData?.showEmptyForm||!t.creator.render&&!a&&m({})},[t.creator]),s)return L(`div`,{className:`flex flex-col items-center p-4`,children:L(x,{children:s})});let g=L(`div`,{className:`flex flex-col items-center py-8`,children:R(`div`,{className:`flex gap-2 items-center`,children:[L(le,{}),` `,L(`span`,{children:`Loading`})]})});return a?g:t.creator.render?L(I,{children:L(Se,{fallback:g,children:t.creator.render({vault:n,runCreate:m,validate:h,options:p})})}):R(I,{children:[L(b,{children:`No options available`}),L(e,{primary:!0,onPress:()=>m({}),children:t.creator.actionButton||`Create`})]})});function ws(e){let t=q(),n=z(),[r,i]=F(e.resource.initialCreator||``),a=ns(),o=N(()=>at(e.resource,t.layout.creators||[],{vault:n}),[e.resource,t.layout.creators,n]);o.length===1&&!r&&i(o[0].id);let s=o.find(e=>e.id===r);if(j(()=>{s&&a?.(s.label)}),o.length===0)return L(b,{children:`Not currently supported`});let c=L(te,{children:L(w,{root:document.getElementById(`headlessui-portal-root`)||void 0,label:`Back to Add content options`,className:`group`,placement:`right`,onPress:()=>i(``),children:L(C,{className:`text-2xl opacity-50 group-hover:opacity-70`})})});return s?s.hiddenModal?R(I,{children:[c,L(Cs,{creator:s,resource:e.resource})]}):R(`div`,{children:[c,L(`div`,{className:`p-2 py-6`,children:L(Cs,{creator:s,resource:e.resource})})]}):L(_,{label:`Select a type`,items:o.map(e=>({id:e.id,title:e.label,description:e.summary||``,icon:e.icon,onClick:()=>i(e.id)}))})}const Ts={id:`@manifest-editor/creator`,label:`Add content`,options:{hideHeader:!0,tabs:!1},render(e){return L(ws,{resource:e})}},Es={color:{main:`#B84C74`,mainHover:`#4a89ff`,logoPink:`#E94581`,white:`white`,grey:`grey`,black:`black`,lightgrey:`#F8F9FA`,mediumgrey:`#dddddd`,danger:`#a90e21`,warning:`#e38627`,lightdanger:`#ffeaea`,lightsuccess:`#c5e8c5`,success:`#6ccd55`,greyOverlay:`rgba(0, 0, 0, 0.2)`,highlight:`#faeed7`},iiifColor:{manifest:`rgba(0, 0, 0, 0.2)`,canvas:`rgba(255, 222, 219, 0.8)`,service:`rgba(13, 110, 253, 0.8)`,annotation:`rgba(247, 226, 173, 0.8)`,contentResource:`rgba(207, 247, 255, 0.8)`,ranges:`rgba(144, 213, 157, 0.8)`},padding:{xs:`0.25rem`,small:`0.5rem`,medium:`1rem`,large:`2rem`},device:{mobile:`375px`,tablet:`768px`,laptop:`992px`,desktop:`1200px`},shadows:{standard:`rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.05) 0px 5px 15px 0px`,bottom:`rgba(0, 0, 0, 0.1) 0px 4px 2px -2px`}};function Ds(e){let{}=e,t=z(),n=q(),r=N(()=>at(e.resource,n.layout.creators||[],{vault:t}),[e.resource,n.layout.creators,t]);return r.length===0?L(`div`,{children:`No supported creators found`}):L(`div`,{children:R(pe,{className:`w-full flex-1 overflow-hidden flex flex-col`,children:[L(de,{className:`flex-1 overflow-hidden w-full flex text-sm whitespace-nowrap`,items:r,children:e=>L(ue,{id:e.id,children:e.label})}),r.map(t=>L(fe,{id:t.id,className:`p-2`,children:L(Ye,{theme:Es,children:L(Cs,{creator:t,resource:e.resource,onCreate:e.onCreate,skipEditingOnCreate:!0})})},t.id))]})})}function Os({fallback:e,backAction:t}){let n=ra(),{back:r}=ta();return n.length?L(as,{onClick:r,children:L(Go,{})}):e}function ks({closeAction:e,fallback:t}){let n=ra();return na()||n.length?L(as,{onClick:()=>{e()},children:L(hi,{})}):t}function As(e,t,n,r){let i=t.filter(t=>t.resourceType===e.resource.source.type);if(i.length===0)return null;for(let t of i){let i=[],a={},o=(t.editors||[]).filter(t=>{if(r.hideTabs&&r.hideTabs.includes(t.id)||r.onlyTabs&&!r.onlyTabs.includes(t.id))return!1;if(t.supports.sortKey){if(i.includes(t.supports.sortKey))return!1;t.supports.sortFallback&&(a[t.supports.sortKey]=t)}return n.edit&&!t.supports.edit||t.supports.custom&&t.supports.custom(e,n.vault)===!1?!1:(t.supports.sortKey&&i.push(t.supports.sortKey),!0)}),s=Object.keys(a);for(let e of s)!i.includes(e)&&a[e]&&!o.includes(a[e])&&o.push(a[e]);if(o.length)return{...t,editors:o}}return null}function js({currentTab:e=void 0}){let t=na(),n=A(Be),r=q(),i=bi(),a=z(),{change:o}=_a(),s=ns(),{editorConfig:c}=Ot(),l=t?.resource.source?.id,u=t?.resource.source?.type,d=l!==i.id;l&&d&&i.type===`Collection`&&u===`Collection`&&(u=`EmbeddedCollection`);let f=(u?c[u]:c.All)||{},p=N(()=>{let e={...n},r=t?.resource.source.id,i=t?.resource.source.type,a={Collection:`collection`,Manifest:`manifest`,Range:`range`,Canvas:`canvas`,Annotation:`annotation`,AnnotationPage:`annotationPage`};return i&&a[i]&&(e[a[i]]=r),e},[t,n]);function m(e){return t?L(Be.Provider,{value:p,children:e}):e}let h=N(()=>{if(!t)return null;let e=r.layout.editors||[];return As(t,(r.layout.resources||[]).map(t=>typeof t==`string`?{id:`@default/`+t,label:t,resourceType:t,auto:!0,editors:e.filter(e=>e.supports.resourceTypes.includes(t))}:t),{edit:!0,vault:a},f)},[t,r]);j(()=>{s(h?.label||``)},[h]),j(()=>{let t=h?.editors.map(e=>e.id)||[];t.find(t=>t===e)||o(`@manifest-editor/editor`,{currentTab:t[0]})},[h?.editors,e,o]);let g=N(()=>(h?.editors||[]).map(e=>({id:e.id,label:e.label,renderComponent:()=>e.component(f)})),[h?.editors,f]);if(!t||!h)return null;if(f.singleTab){let e=(h?.editors||[]).find(e=>e.id===f.singleTab);if(e)return m(L(`div`,{className:`w-full`,children:e.component(f)},t.resource.source?.id))}return m(L(ce,{isNested:d,rootResource:i,menuId:t.resource.source.id,menu:g,selectedKey:e,onSelectionChange:e=>{o(`@manifest-editor/editor`,{currentTab:e})}},t.resource.source?.id))}const Ms={id:`@manifest-editor/editor`,label:`Editor`,options:{hideHeader:!0,tabs:!0,minWidth:400},renderBackAction:({backAction:e,fallback:t})=>L(Os,{backAction:e,fallback:t}),renderCloseAction:({closeAction:e,fallback:t})=>L(ks,{closeAction:e,fallback:t}),render({currentTab:e}){return L(js,{currentTab:e})}};function Ns(e){let[t,n]=F(!1),r=P(null),i=P(0);function a(t){i.current--,!(t&&i.current!==0)&&(r.current&&(clearTimeout(r.current),r.current=0),r.current=setTimeout(()=>{n(!1)},e))}function o(){i.current++,r.current&&clearTimeout(r.current),n(!0)}return N(()=>[t,{set:o,clear:a}],[t])}function Ps(e){return e?typeof e==`string`?{src:e,alt:``}:e:null}function Fs(e){return e?typeof e==`string`?e:e.name:null}function Is(e){let t=e.extension,n=t.leftPanels?.[0]||t.centerPanels?.[0]||t.rightPanels?.[0]||t.modalPanels?.[0];return n?{id:n.id,label:n.label||`Open plugin`,modal:t.modalPanels?.some(e=>e.id===n.id)||!1}:null}function Ls(e){return e instanceof Error?e.message:`Plugin configuration could not be saved.`}function Rs(e){return R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:[L(`path`,{d:`M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z`}),L(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}function zs(e){return R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:[L(`path`,{d:`M7 7h10v10`}),L(`path`,{d:`M7 17 17 7`})]})}function Bs(){let e=q(),{appId:t}=ii(),n=Ot(),r=kt(),i=qr(),a=Yr(),o=_a(),{saveGlobalPluginConfig:s}=A(Hr),[c,l]=F(!1),[u,d]=F(``),[f,p]=F(null),[m,h]=F(null),[_,v]=F(null),y=N(()=>new Set(Dr(i,e,t).map(e=>e.metadata.id)),[i,e,t]),b=N(()=>{let n=u.trim().toLowerCase();return i.plugins.filter(r=>{let i=Cr(r,e,t);return!c&&!i?!1:n?[r.metadata.label,r.metadata.id,r.metadata.description,Fs(r.metadata.author),...r.metadata.tags||[]].filter(Boolean).join(` `).toLowerCase().includes(n):!0})},[e,t,i.plugins,u,c]),x=f&&i.plugins.find(e=>e.metadata.id===f)||null;if(!i.plugins.length)return null;function S(e){a.setAppConfig(t,e),r({plugins:{...n.plugins||{},apps:{...n.plugins?.apps||{},[t]:e}}})}async function C(e){if(!s){v(`Global plugin settings are not available in this host.`);return}let n=i.globalApps[t]||{},r={apps:{...i.globalApps,[t]:e}};a.setGlobalAppConfig(t,e);try{await s(r)}catch(e){a.setGlobalAppConfig(t,n),v(Ls(e))}}async function w(n,r,a){v(null),h(`${a}:${n.metadata.id}`);let o=a===`global`?i.globalApps[t]||{}:i.apps[t]||{},s=r?Pr(o,i,n,e,t):{config:gr(o,n.metadata.id),blocked:[]};if(s.blocked.length){h(null),v(`Cannot enable ${n.metadata.label}: ${s.blocked.join(`, `)}.`);return}a===`global`?await C(s.config):S(s.config),h(null)}function T(e){let t=Is(e);if(t){if(t.modal){o.modal.open({id:t.id});return}o.open(t.id)}}return R(`section`,{className:`flex flex-col gap-3 border-t border-gray-200 pt-4 mt-4`,children:[R(`div`,{className:`flex items-center gap-2`,children:[L(`div`,{className:`min-w-0 flex-1`,children:L(`h3`,{className:`font-semibold text-sm text-gray-900`,children:`Plugins`})}),L(`button`,{type:`button`,className:`rounded border border-gray-200 bg-white px-2 py-1 text-xs text-gray-500 hover:text-gray-700 hover:border-gray-300 transition-colors`,onClick:()=>l(e=>!e),children:c?`Compatible only`:`Show all`})]}),L(`input`,{className:`rounded border border-gray-200 px-2.5 py-1.5 text-xs focus:border-me-primary-500 focus:ring-2 focus:ring-me-primary-500/20 focus:outline-none`,type:`search`,placeholder:`Search plugins…`,value:u,onChange:e=>d(e.currentTarget.value)}),_?L(`div`,{className:`rounded border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700`,children:_}):null,L(`div`,{className:`flex flex-col gap-2`,children:b.map(n=>{let r=Tr(n,i,t),a=y.has(n.metadata.id),o=Ps(n.metadata.image),s=r&&!a,c=Cr(n,e,t),l=wr(n,e,t),u=Is(n),d=!!n.settings,f=m===`workspace:${n.metadata.id}`;return R(`article`,{className:`flex gap-2.5 rounded-lg border bg-white p-3 text-sm transition-colors ${a?`border-gray-200`:`border-gray-100 opacity-60`} ${c?``:`opacity-40`}`,children:[o?L(`img`,{className:`h-9 w-9 rounded object-cover flex-none mt-0.5`,src:o.src,alt:o.alt||n.metadata.label}):L(`div`,{className:`h-9 w-9 rounded flex items-center justify-center flex-none mt-0.5 text-lg ${a?`bg-me-primary-50 text-me-primary-500`:`bg-gray-100 text-gray-400`}`,children:L(Rs,{className:`w-4 h-4`})}),R(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[R(`div`,{className:`flex items-start justify-between gap-1`,children:[R(`div`,{className:`flex flex-wrap items-center gap-1.5 min-w-0`,children:[L(`span`,{className:`font-medium text-gray-900 text-xs`,children:n.metadata.label}),n.metadata.official?R(`span`,{className:`rounded-full text-me-primary-500 px-1.5 py-0 text-[9px] font-bold inline-flex items-center gap-1`,children:[L(g,{className:`w-3 h-3`}),` Verified`]}):null,n.metadata.version?L(`span`,{className:`text-[10px] text-gray-400`,children:n.metadata.version}):null]}),R(`div`,{className:`flex items-center gap-1 flex-none`,children:[d?L(`button`,{type:`button`,title:`Configure plugin`,className:`rounded p-1 text-gray-400 hover:text-gray-700 hover:bg-gray-100 transition-colors`,onClick:()=>p(n.metadata.id),children:L(Rs,{className:`w-3.5 h-3.5`})}):null,a&&u?L(`button`,{type:`button`,title:`Open ${u.label}`,className:`rounded p-1 text-me-primary-500 hover:bg-me-primary-50 transition-colors`,onClick:()=>T(n),children:L(zs,{className:`w-3.5 h-3.5`})}):null,L(`button`,{type:`button`,disabled:!c||f,onClick:()=>w(n,!r,`workspace`),className:`relative inline-flex h-5 w-9 flex-none items-center rounded-full transition-colors disabled:opacity-40 focus:outline-none focus:ring-2 focus:ring-me-primary-500/30 ${r?`bg-me-primary-500`:`bg-gray-200`}`,title:r?`Disable plugin`:`Enable plugin`,"aria-label":r?`Disable plugin`:`Enable plugin`,children:L(`span`,{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white shadow transition-transform ${r?`translate-x-4`:`translate-x-0.5`}`})})]})]}),n.metadata.description?L(`p`,{className:`text-xs text-gray-500 leading-relaxed`,children:n.metadata.description}):null,s?L(`span`,{className:`text-xs text-amber-600`,children:`Waiting for required dependencies`}):null,!c&&l?L(`span`,{className:`text-xs text-gray-400`,children:l}):null]})]},n.metadata.id)})}),b.length?null:L(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 p-4 text-center text-xs text-gray-500`,children:`No plugins found.`}),x?L(ee,{title:`Configure ${x.metadata.label}`,onClose:()=>p(null),width:`560px`,children:L(Vs,{plugin:x,onClose:()=>p(null),canSaveGlobal:!!s})}):null]})}function Vs({plugin:e,onClose:t,canSaveGlobal:n}){let r=Qr(e.metadata.id),[i,a]=F(`workspace`),[o,s]=F({}),[c,l]=F(!1),[u,d]=F(!1),[f,p]=F(null),m=i===`global`?r.global:r.workspace;j(()=>{s({...m}),p(null),d(!1)},[e.metadata.id,i]);async function h(){let t=e.settings?.validate?.(o);if(t){p(t);return}l(!0),p(null);try{i===`global`?await r.setGlobalSettings(o):r.setWorkspaceSettings(o),d(!0),setTimeout(()=>d(!1),2e3)}catch(e){p(Ls(e))}finally{l(!1)}}async function g(){l(!0),p(null);try{i===`global`?await r.resetGlobalSettings():r.resetWorkspaceSettings(),s({})}catch(e){p(Ls(e))}finally{l(!1)}}return R(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[n&&r.canSaveGlobal?R(`div`,{className:`flex items-center gap-1 px-5 pt-4 pb-3 border-b border-gray-100`,children:[L(`span`,{className:`text-xs text-gray-500 mr-2`,children:`Scope:`}),L(`button`,{type:`button`,className:`rounded-full px-3 py-1 text-xs font-medium transition-colors ${i===`workspace`?`bg-me-primary-500 text-white`:`bg-gray-100 text-gray-600 hover:bg-gray-200`}`,onClick:()=>a(`workspace`),children:`This workspace`}),L(`button`,{type:`button`,className:`rounded-full px-3 py-1 text-xs font-medium transition-colors ${i===`global`?`bg-me-primary-500 text-white`:`bg-gray-100 text-gray-600 hover:bg-gray-200`}`,onClick:()=>a(`global`),children:`All workspaces`})]}):null,f?L(`div`,{className:`mx-5 mt-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700`,children:f}):null,L(`div`,{className:`flex-1 overflow-y-auto p-5`,children:L(`div`,{className:`flex flex-col gap-3`,children:e.settings?.render?e.settings.render({plugin:e,appId:r.appId,scope:i,value:o,defaults:r.defaults,effective:r.effective,onChange:s}):e.settings?.fields?.length?e.settings.fields.map(e=>L(Hs,{field:e,draft:o,setDraft:s},e.id)):L(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 p-4 text-center text-sm text-gray-500`,children:`This plugin has no configurable settings.`})})}),R(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-100 px-5 py-4`,children:[L(`button`,{type:`button`,className:`text-xs text-gray-400 hover:text-gray-600 transition-colors disabled:opacity-40`,disabled:c,onClick:g,children:`Reset to defaults`}),R(`div`,{className:`flex items-center gap-2`,children:[u?L(`span`,{className:`text-xs text-green-600`,children:`✓ Saved`}):null,L(`button`,{type:`button`,className:`rounded-lg bg-me-primary-500 px-4 py-2 text-sm font-medium text-white hover:bg-me-primary-600 disabled:opacity-50 transition-colors`,disabled:c,onClick:h,children:c?`Saving…`:`Save ${i}`})]})]})]})}function Hs({field:e,draft:t,setDraft:n}){let r=t[e.id],i=`plugin-setting-${e.id}`;function a(r){n({...t,[e.id]:r})}let o=L(`label`,{className:`text-sm font-medium text-gray-900`,htmlFor:i,children:e.label}),s=`rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:ring-2 focus:ring-me-primary-500/20 focus:outline-none`;return e.type===`boolean`?R(`div`,{className:`flex items-center justify-between rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[R(`div`,{className:`flex flex-col gap-0.5`,children:[o,e.description?L(`span`,{className:`text-xs text-gray-500`,children:e.description}):null]}),L(`input`,{id:i,type:`checkbox`,checked:r===!0,onChange:e=>a(e.currentTarget.checked),className:`h-4 w-4 rounded border-gray-300 text-me-primary-500 focus:ring-me-primary-500`})]}):e.type===`textarea`?R(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?L(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,L(`textarea`,{id:i,className:`${s} min-h-24 resize-y`,value:typeof r==`string`?r:``,placeholder:e.placeholder,onChange:e=>a(e.currentTarget.value)})]}):e.type===`select`?R(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?L(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,R(`select`,{id:i,className:s,value:r===void 0?``:String(r),onChange:t=>{let n=e.options?.find(e=>String(e.value)===t.currentTarget.value);a(n?n.value:t.currentTarget.value)},children:[L(`option`,{value:``,children:`Default`}),(e.options||[]).map(e=>L(`option`,{value:String(e.value),children:e.label},String(e.value)))]})]}):R(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?L(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,L(`input`,{id:i,className:s,type:e.type===`number`?`number`:`text`,value:typeof r==`string`||typeof r==`number`?r:``,placeholder:e.placeholder,onChange:t=>{a(e.type===`number`?Number(t.currentTarget.value):t.currentTarget.value)}})]})}function Us(){let t=Ii(),n=bi(),r=Ot(),i=kt(),[a,o]=Ns(2e3);function s(e){e.preventDefault();let t=new FormData(e.target);i({defaultPreview:t.get(`defaultPreview`),i18n:{...r.i18n||{},advancedLanguageMode:t.get(`advancedLanguageMode`)===`on`,availableLanguages:(t.get(`availableLanguages`)||``).split(`,`).map(e=>e.trim()),defaultLanguage:t.get(`defaultLanguage`)},export:{...r.export||{},version:t.get(`isVersion2`)===`on`?2:3,baseIdentifier:t.get(`base`)||null},plugins:r.plugins,editorFeatureFlags:{...r.editorFeatureFlags||{},rememberCanvasId:t.get(`rememberCanvasId`)===`on`,rememberLeftPanelId:t.get(`rememberLeftPanelId`)===`on`,annotationPopups:t.get(`annotationPopups`)===`on`,manifestGridOptions:t.get(`manifestGridOptions`)===`on`,enableMultiImageCanvases:t.get(`enableMultiImageCanvases`)===`on`,enableMultiMediaCanvases:t.get(`enableMultiMediaCanvases`)===`on`}}),o.set(),o.clear()}return R(oe,{children:[L(se,{title:`Workspace configuration`}),a?L(`div`,{className:`bg-me-primary-500 text-white p-3 text-sm`,children:`Changes saved`}):null,L(D,{className:`p-4`,children:R(S.Form,{onSubmit:s,className:`flex flex-col gap-3`,children:[R(S.InputContainer,{children:[L(S.Label,{htmlFor:`defaultLanguage`,children:`Default Language`}),L(S.Input,{type:`text`,name:`defaultLanguage`,id:`defaultLanguage`,defaultValue:r.i18n?.defaultLanguage||``})]}),R(S.InputContainer,{children:[L(S.Label,{htmlFor:`availableLanguages`,children:`Available Languages`}),L(S.Input,{type:`text`,name:`availableLanguages`,id:`availableLanguages`,defaultValue:(r.i18n?.availableLanguages||[]).join(`, `)})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`advancedLanguageMode`,id:`advancedLanguageMode`,defaultChecked:r.i18n?.advancedLanguageMode||!1}),L(S.Label,{htmlFor:`advancedLanguageMode`,children:`Advanced Language Mode`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`textGranularityEnabled`,id:`textGranularityEnabled`,defaultChecked:r.i18n?.textGranularityEnabled||!1}),L(S.Label,{htmlFor:`textGranularityEnabled`,children:`Enable text granularity`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`rememberCanvasId`,id:`rememberCanvasId`,defaultChecked:r.editorFeatureFlags?.rememberCanvasId||!1}),L(S.Label,{htmlFor:`rememberCanvasId`,children:`Remember Canvas ID`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`rememberLeftPanelId`,id:`rememberLeftPanelId`,defaultChecked:r.editorFeatureFlags?.rememberLeftPanelId||!1}),L(S.Label,{htmlFor:`rememberLeftPanelId`,children:`Remember Left panel`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`manifestGridOptions`,id:`manifestGridOptions`,defaultChecked:r.editorFeatureFlags?.manifestGridOptions||!1}),L(S.Label,{htmlFor:`manifestGridOptions`,children:`Manifest Grid Options`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`isVersion2`,id:`isVersion2`,defaultChecked:r.export?.version===2}),R(S.Label,{htmlFor:`isVersion2`,children:[`Export Presentation 2 `,n.type,`s`]})]}),R(S.InputContainer,{children:[L(S.Label,{htmlFor:`defaultPreview`,children:`Default preview`}),L(`div`,{children:t.configs.map((e,t)=>e.type===`iiif-preview-service`?null:R(S.InputContainer,{horizontal:!0,children:[L(S.Input,{type:`radio`,id:e.id,name:`defaultPreview`,value:e.id,defaultChecked:r.defaultPreview?r.defaultPreview===e.id:t===0}),L(`label`,{htmlFor:e.id,children:e.label})]},e.id))})]}),n.type===`Manifest`?L(`a`,{className:`text-sm text-me-primary-500 hover:underline hover:text-me-primary-600`,href:window.location.pathname.includes(`/exhibition`)?window.location.pathname.replace(`/exhibition`,``)||`/`:`${window.location.pathname}/exhibition`,children:window.location.pathname.includes(`/exhibition`)?`Return to Manifest Editor`:`Go to Exhibition Editor`}):null,L(Bs,{}),L(`div`,{className:`mt-5`,children:L(e,{type:`submit`,children:`Save changes`})})]})})]})}function Ws(){return Ae((e,t)=>({specificMenus:{},resourceMenus:{},hookMenuItem(t){let n=ar(),r=t.resource?.id||``,i=t.resource?.type;return i?r?(e(e=>({specificMenus:{...e.specificMenus,[r]:{...e.specificMenus[r]||{},menus:{...e.specificMenus[r]?.menus||{},[n]:{sectionTitle:t.sectionTitle,items:t.items}}}}})),()=>{e(e=>({specificMenus:{...e.specificMenus,[r]:{...e.specificMenus[r]||{},menus:{...e.specificMenus[r]?.menus||{},[n]:void 0}}}}))}):(e(e=>({resourceMenus:{...e.resourceMenus,[i]:{...e.resourceMenus[i]||{},menus:{...e.resourceMenus[i]?.menus||{},[n]:{sectionTitle:t.sectionTitle,items:t.items}}}}})),()=>{e(e=>({resourceMenus:{...e.resourceMenus,[i]:{...e.resourceMenus[i]||{},menus:{...e.resourceMenus[i]?.menus||{},[n]:void 0}}}}))}):()=>{}}}))}const Gs=O(null);function Ks({children:e}){let t=N(()=>Ws(),[]);return L(Gs.Provider,{value:t,children:e})}function qs(){let e=A(Gs);if(!e)throw Error(`useContextMenuStore must be used within a ContextMenuProvider`);return e}function Js(e){let t=qs(),n=je(t,e=>e.resourceMenus),r=je(t,e=>e.specificMenus);return N(()=>{let t=r[e.id||``]?.menus||{},i=n[e.type]?.menus||{},a=Object.values(t).flat(),o=[...Object.values(i).flat(),...a].filter(e=>e!==void 0),s=[],c=[];for(let e of o){let t=[];for(let n of e.items||[])n.id&&s.includes(n.id)||(s.push(n.id),t.push(n));t.length&&c.push({...e,items:t})}return Ys(c)},[r,n,e.id,e.type])}function Ys(e){let t={},n=[];e.forEach(e=>{if(!e)return;let r=e.sectionTitle;if(!r){n.push(...e.items||[]);return}t[r]||(t[r]=[]),t[r].push(...e.items)});let r=Object.entries(t).map(([e,t])=>({sectionTitle:e,items:t}));return n.length&&r.push({items:n}),r}function Xs(e,t=[]){let n=je(qs(),e=>e.hookMenuItem);j(()=>n(e),[n,e.resource?.id,e.resource?.type,...t])}var Zs={};function Qs(e){return R(`div`,{className:Zs.CenterPanelContainer,children:[e.title||e.close?R(`div`,{className:Zs.CenterPanelHeader,children:[e.title?L(`h2`,{className:Zs.CenterPanelTitle,children:e.title}):null,e.close?L(Y,{className:Zs.CenterPanelClose,onClick:e.close,children:L(hi,{})}):null]}):null,e.children]})}const $s=V.div`
429
+ `;function _s({panel:e,state:t,actions:n,isLeft:r,pinActions:i=n,transition:a,close:o,available:s=[],style:c,noHeader:l}){let u=A(ze)||null,[d,f]=F(!1),p=pi(),m=Oa(),{tabs:h,pinnable:g,hideHeader:_}=e?.options||{},v=[p.state.canvasId,e?.id],y=N(()=>(s||[]).filter(e=>!e.requiresState),[s]),{itemProps:b,isOpen:x,setIsOpen:S}=Xe(y.length),[C,w]=F(``),T=P(void 0);j(()=>f(!1),v),j(()=>w(``),[e]),j(()=>(T.current=w,()=>{T.current=void 0}),[]);let E=k(e=>{T.current&&T.current(e)},[]),ee=k(r=>{let i=e?t.stack.length?n.popStack:e.backAction?()=>e&&e.backAction&&e.backAction(t,{...m,current:n},p):null:null;r&&(!i||r.metaKey)&&y.length?(r.preventDefault(),S(!0)):i&&i()},[n,p,m,e,S,t,y.length]),te=r=>{n.change({id:r.id,state:r.defaultState,stacked:!!(t.stack.length||e?.backAction)})};if(!e||!t.current)return null;let ne=e.backAction||t.stack.length?L(ps,{onClick:ee,children:L($o,{})}):null,re=L(ps,{onClick:o||n.close,children:L(Ci,{})});return L(ls.Provider,{value:E,children:R(ds,{"data-state":a,"data-flipped":r,style:c,"data-header":!l,children:[l?null:R(fs,{"data-tabs":!!h,"data-error":d,children:[R(is,{style:{display:`flex`,height:`100%`},children:[e.renderBackAction?e.renderBackAction({backAction:ee,fallback:ne}):ne,y.length?R(os,{$open:x,style:{left:`0.5em`},children:[L(ss,{children:`All panels`}),L(cs,{}),y.map((t,n)=>L(as,{...b[n],onClick:()=>te(t),$active:e.id===t.id,children:t.label},n))]}):null]}),C?L(hs,{children:C}):_?L(ms,{}):L(hs,{children:e.label}),g?t.pinned?L(ps,{onClick:i.unpin,children:L(Qo,{fill:`orange`})}):L(ps,{onClick:()=>i.pin({id:e.id,state:t.state}),children:L(Qo,{fill:`#ddd`})}):null,e.renderCloseAction?e.renderCloseAction({closeAction:o||n.close,fallback:re}):re]}),L(gs,{className:`OverrideScrollbar`,children:L(ot,{onError:()=>f(!0),FallbackComponent:es,resetKeys:v,onReset:()=>f(!1),children:rs(e.render(t.state||e.defaultState||{},{...m,current:n,vault:u,transition:a},p))})})]})})}function vs(e=`vault://homepage-collection.json`){let t=new rt,n=window.localStorage.getItem(`preview-vault-collection`),r=!1;if(n)try{let i=JSON.parse(n);if(i.id&&i.id===e){t.dispatch(dt({id:i.id}));let e=ft(i.id,i);t.dispatch(ct({actions:e})),r=!0}}catch{}if(!r){let n=ft(e,{"@context":`http://iiif.io/api/presentation/3/context.json`,id:e,type:`Collection`,label:{en:[`Recent items`]},items:[]});t.dispatch(dt({id:e})),t.dispatch(ct({actions:n}))}return t.on(`after:@iiif/REMOVE_REFERENCE`,n=>{n.action.payload.id===e&&window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}),{vault:t,unsubscribe:()=>{},addHistory:(n,r)=>{let i=t.getState();if(n&&r&&(r===`Collection`||r===`Manifest`)){let a=i.iiif.entities.Collection[e];if(a){let i=a.items.findIndex(e=>e.id===n);i===-1?t.dispatch(st({id:e,type:`Collection`,reference:{id:n,type:r},key:`items`,index:0})):t.dispatch(ut({id:e,type:`Collection`,key:`items`,startIndex:i,endIndex:0})),window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}}},clearHistory:()=>{t.dispatch(lt({id:e,type:`Collection`,key:`items`,value:[]})),window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}}}function ys(){return A(bs)}const bs=O(new rt),xs=O({addHistory:(e,t)=>{},clearHistory:()=>{}}),Ss=`manifest-editor://homepage-collection.json`;function Cs(){return A(xs)}function ws(e){let{vault:t,unsubscribe:n,addHistory:r,clearHistory:i}=N(()=>vs(Ss),[]);return j(()=>n,[]),L(xs.Provider,{value:{addHistory:r,clearHistory:i},children:L(bs.Provider,{value:t,children:e.children})})}function Ts({children:e}){return L(Ve,{vault:ys(),children:e})}function Es(e,t,n,r,i){let a=z(),o=q(),{create:s,edit:c}=Ta(),l=N(()=>at({type:n,parent:e,index:0,property:t},o.layout.creators||[],{vault:a}),[e,t,o.layout.creators,n,a]),u=e&&l.length!==0,d=k((a,o)=>{if(e)return s({type:n,parent:B(e),property:t,index:a,target:r,initialData:o,...i||{}})},[s,e,t,n,i,r]),f=k((a,o,c)=>{if(e)return s({type:n,filter:a,parent:B(e),property:t,index:o,target:r,initialData:c,...i||{}})},[s,e,t,n,i,r]);return[u,{create:d,edit:k((n,r)=>{c(n,e?{parent:B(e),property:t,index:r}:void 0)},[c,e,t]),createFiltered:f,creator:k((a,o)=>{if(e)return s({type:n,initialCreator:a,parent:B(e),property:t,target:r,initialData:o,...i||{}})},[n,t,e,r,s,i]),buttonProps:N(()=>({"data-action-id":or(n,t,e)}),[n,t,e])}]}function Ds(){let e=z(),t=ys(),n=q();return N(()=>new it(e,n.layout.creators||[],t),[n.layout.creators,e])}const Os=O({});function ks(e){return A(Os)[e]||{}}function As(e){let t=A(Os),n=N(()=>({...t,[e.id]:e.data}),[t,e.id,e.data]);return L(Os.Provider,{value:n,children:e.children})}const js=Ee(function(t){let n=z(),{edit:r,modal:i}=Ta(),[a,o]=F(!1),[s,c]=F(null),l=Ds(),u=P(!1),d=t.resource.initialData?.selector;Xo(d);let f=ks(t.creator.id),p={targetType:t.resource.type,parent:t.resource.parent?{property:t.resource.property,atIndex:t.resource.index,resource:t.resource.parent}:void 0,target:t.resource.target,initialData:{...f,...t.resource.initialData||{}}},m=e=>{try{if(a||u.current)return;o(!0),u.current=!0,l.create(t.creator.id,e,p).catch(e=>(c(e?.message||`Unknown error`),null)).then(async e=>{if(t.onCreate?.(),t.resource.initialData?.skipEditingOnCreate){o(!1),i.popStack(),i.close();return}if(t.skipEditingOnCreate||!e)return;let n=Array.isArray(e)?e[0]:e;o(!1),i.popStack(),i.close(),n&&r(n,{parent:B(t.resource.parent),property:t.resource.property,index:t.resource.index})})}catch(e){c(e?.message||`Unknown error`)}},h=async()=>!0;if(j(()=>{t.resource.initialData?.showEmptyForm||!t.creator.render&&!a&&m({})},[t.creator]),s)return L(`div`,{className:`flex flex-col items-center p-4`,children:L(x,{children:s})});let g=L(`div`,{className:`flex flex-col items-center py-8`,children:R(`div`,{className:`flex gap-2 items-center`,children:[L(le,{}),` `,L(`span`,{children:`Loading`})]})});return a?g:t.creator.render?L(I,{children:L(Se,{fallback:g,children:t.creator.render({vault:n,runCreate:m,validate:h,options:p})})}):R(I,{children:[L(b,{children:`No options available`}),L(e,{primary:!0,onPress:()=>m({}),children:t.creator.actionButton||`Create`})]})});function Ms(e){let t=q(),n=z(),[r,i]=F(e.resource.initialCreator||``),a=us(),o=N(()=>at(e.resource,t.layout.creators||[],{vault:n}),[e.resource,t.layout.creators,n]);o.length===1&&!r&&i(o[0].id);let s=o.find(e=>e.id===r);if(j(()=>{s&&a?.(s.label)}),o.length===0)return L(b,{children:`Not currently supported`});let c=L(te,{children:L(w,{root:document.getElementById(`headlessui-portal-root`)||void 0,label:`Back to Add content options`,className:`group`,placement:`right`,onPress:()=>i(``),children:L(C,{className:`text-2xl opacity-50 group-hover:opacity-70`})})});return s?s.hiddenModal?R(I,{children:[c,L(js,{creator:s,resource:e.resource})]}):R(`div`,{children:[c,L(`div`,{className:`p-2 py-6`,children:L(js,{creator:s,resource:e.resource})})]}):L(_,{label:`Select a type`,items:o.map(e=>({id:e.id,title:e.label,description:e.summary||``,icon:e.icon,onClick:()=>i(e.id)}))})}const Ns={id:`@manifest-editor/creator`,label:`Add content`,options:{hideHeader:!0,tabs:!1},render(e){return L(Ms,{resource:e})}},Ps={color:{main:`#B84C74`,mainHover:`#4a89ff`,logoPink:`#E94581`,white:`white`,grey:`grey`,black:`black`,lightgrey:`#F8F9FA`,mediumgrey:`#dddddd`,danger:`#a90e21`,warning:`#e38627`,lightdanger:`#ffeaea`,lightsuccess:`#c5e8c5`,success:`#6ccd55`,greyOverlay:`rgba(0, 0, 0, 0.2)`,highlight:`#faeed7`},iiifColor:{manifest:`rgba(0, 0, 0, 0.2)`,canvas:`rgba(255, 222, 219, 0.8)`,service:`rgba(13, 110, 253, 0.8)`,annotation:`rgba(247, 226, 173, 0.8)`,contentResource:`rgba(207, 247, 255, 0.8)`,ranges:`rgba(144, 213, 157, 0.8)`},padding:{xs:`0.25rem`,small:`0.5rem`,medium:`1rem`,large:`2rem`},device:{mobile:`375px`,tablet:`768px`,laptop:`992px`,desktop:`1200px`},shadows:{standard:`rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.05) 0px 5px 15px 0px`,bottom:`rgba(0, 0, 0, 0.1) 0px 4px 2px -2px`}};function Fs(e){let{}=e,t=z(),n=q(),r=N(()=>at(e.resource,n.layout.creators||[],{vault:t}),[e.resource,n.layout.creators,t]);return r.length===0?L(`div`,{children:`No supported creators found`}):L(`div`,{children:R(pe,{className:`w-full flex-1 overflow-hidden flex flex-col`,children:[L(de,{className:`flex-1 overflow-hidden w-full flex text-sm whitespace-nowrap`,items:r,children:e=>L(ue,{id:e.id,children:e.label})}),r.map(t=>L(fe,{id:t.id,className:`p-2`,children:L(Ye,{theme:Ps,children:L(js,{creator:t,resource:e.resource,onCreate:e.onCreate,skipEditingOnCreate:!0})})},t.id))]})})}function Is({fallback:e,backAction:t}){let n=da(),{back:r}=la();return n.length?L(ps,{onClick:r,children:L($o,{})}):e}function Ls({closeAction:e,fallback:t}){let n=da();return ua()||n.length?L(ps,{onClick:()=>{e()},children:L(Ci,{})}):t}function Rs(e,t,n,r){let i=t.filter(t=>t.resourceType===e.resource.source.type);if(i.length===0)return null;for(let t of i){let i=[],a={},o=(t.editors||[]).filter(t=>{if(r.hideTabs&&r.hideTabs.includes(t.id)||r.onlyTabs&&!r.onlyTabs.includes(t.id))return!1;if(t.supports.sortKey){if(i.includes(t.supports.sortKey))return!1;t.supports.sortFallback&&(a[t.supports.sortKey]=t)}return n.edit&&!t.supports.edit||t.supports.custom&&t.supports.custom(e,n.vault)===!1?!1:(t.supports.sortKey&&i.push(t.supports.sortKey),!0)}),s=Object.keys(a);for(let e of s)!i.includes(e)&&a[e]&&!o.includes(a[e])&&o.push(a[e]);if(o.length)return{...t,editors:o}}return null}function zs({currentTab:e=void 0}){let t=ua(),n=A(Be),r=q(),i=Oi(),a=z(),{change:o}=Ta(),s=us(),{editorConfig:c}=Ot(),l=t?.resource.source?.id,u=t?.resource.source?.type,d=l!==i.id;l&&d&&i.type===`Collection`&&u===`Collection`&&(u=`EmbeddedCollection`);let f=(u?c[u]:c.All)||{},p=N(()=>{let e={...n},r=t?.resource.source.id,i=t?.resource.source.type,a={Collection:`collection`,Manifest:`manifest`,Range:`range`,Canvas:`canvas`,Annotation:`annotation`,AnnotationPage:`annotationPage`};return i&&a[i]&&(e[a[i]]=r),e},[t,n]);function m(e){return t?L(Be.Provider,{value:p,children:e}):e}let h=N(()=>{if(!t)return null;let e=r.layout.editors||[];return Rs(t,(r.layout.resources||[]).map(t=>typeof t==`string`?{id:`@default/`+t,label:t,resourceType:t,auto:!0,editors:e.filter(e=>e.supports.resourceTypes.includes(t))}:t),{edit:!0,vault:a},f)},[t,r]);j(()=>{s(h?.label||``)},[h]),j(()=>{let t=h?.editors.map(e=>e.id)||[];t.find(t=>t===e)||o(`@manifest-editor/editor`,{currentTab:t[0]})},[h?.editors,e,o]);let g=N(()=>(h?.editors||[]).map(e=>({id:e.id,label:e.label,renderComponent:()=>e.component(f)})),[h?.editors,f]);if(!t||!h)return null;if(f.singleTab){let e=(h?.editors||[]).find(e=>e.id===f.singleTab);if(e)return m(L(`div`,{className:`w-full`,children:e.component(f)},t.resource.source?.id))}return m(L(ce,{isNested:d,rootResource:i,menuId:t.resource.source.id,menu:g,selectedKey:e,onSelectionChange:e=>{o(`@manifest-editor/editor`,{currentTab:e})}},t.resource.source?.id))}const Bs={id:`@manifest-editor/editor`,label:`Editor`,options:{hideHeader:!0,tabs:!0,minWidth:400},renderBackAction:({backAction:e,fallback:t})=>L(Is,{backAction:e,fallback:t}),renderCloseAction:({closeAction:e,fallback:t})=>L(Ls,{closeAction:e,fallback:t}),render({currentTab:e}){return L(zs,{currentTab:e})}};function Vs(e){let[t,n]=F(!1),r=P(null),i=P(0);function a(t){i.current--,!(t&&i.current!==0)&&(r.current&&(clearTimeout(r.current),r.current=0),r.current=setTimeout(()=>{n(!1)},e))}function o(){i.current++,r.current&&clearTimeout(r.current),n(!0)}return N(()=>[t,{set:o,clear:a}],[t])}function Hs(e){return e?typeof e==`string`?{src:e,alt:``}:e:null}function Us(e){return e?typeof e==`string`?e:e.name:null}function Ws(e){let t=e.extension,n=t.leftPanels?.[0]||t.centerPanels?.[0]||t.rightPanels?.[0]||t.modalPanels?.[0];return n?{id:n.id,label:n.label||`Open plugin`,modal:t.modalPanels?.some(e=>e.id===n.id)||!1}:null}function Gs(e){return e instanceof Error?e.message:`Plugin configuration could not be saved.`}function Ks(e){return R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:[L(`path`,{d:`M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z`}),L(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}function qs(e){return R(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:[L(`path`,{d:`M7 7h10v10`}),L(`path`,{d:`M7 17 17 7`})]})}function Js(){let e=q(),{appId:t}=fi(),n=Ot(),r=kt(),i=ei(),a=ni(),o=Ta(),{saveGlobalPluginConfig:s}=A(Yr),[c,l]=F(!1),[u,d]=F(``),[f,p]=F(null),[m,h]=F(null),[_,v]=F(null),y=N(()=>new Set(Pr(i,e,t).map(e=>e.metadata.id)),[i,e,t]),b=N(()=>{let n=u.trim().toLowerCase();return i.plugins.filter(r=>{let i=Ar(r,e,t);return!c&&!i?!1:n?[r.metadata.label,r.metadata.id,r.metadata.description,Us(r.metadata.author),...r.metadata.tags||[]].filter(Boolean).join(` `).toLowerCase().includes(n):!0})},[e,t,i.plugins,u,c]),x=f&&i.plugins.find(e=>e.metadata.id===f)||null;if(!i.plugins.length)return null;function S(e){a.setAppConfig(t,e),r({plugins:{...n.plugins||{},apps:{...n.plugins?.apps||{},[t]:e}}})}async function C(e){if(!s){v(`Global plugin settings are not available in this host.`);return}let n=i.globalApps[t]||{},r={apps:{...i.globalApps,[t]:e}};a.setGlobalAppConfig(t,e);try{await s(r)}catch(e){a.setGlobalAppConfig(t,n),v(Gs(e))}}async function w(n,r,a){v(null),h(`${a}:${n.metadata.id}`);let o=a===`global`?i.globalApps[t]||{}:i.apps[t]||{},s=r?Vr(o,i,n,e,t):{config:br(o,n.metadata.id),blocked:[]};if(s.blocked.length){h(null),v(`Cannot enable ${n.metadata.label}: ${s.blocked.join(`, `)}.`);return}a===`global`?await C(s.config):S(s.config),h(null)}function T(e){let t=Ws(e);if(t){if(t.modal){o.modal.open({id:t.id});return}o.open(t.id)}}return R(`section`,{className:`flex flex-col gap-3 border-t border-gray-200 pt-4 mt-4`,children:[R(`div`,{className:`flex items-center gap-2`,children:[L(`div`,{className:`min-w-0 flex-1`,children:L(`h3`,{className:`font-semibold text-sm text-gray-900`,children:`Plugins`})}),L(`button`,{type:`button`,className:`rounded border border-gray-200 bg-white px-2 py-1 text-xs text-gray-500 hover:text-gray-700 hover:border-gray-300 transition-colors`,onClick:()=>l(e=>!e),children:c?`Compatible only`:`Show all`})]}),L(`input`,{className:`rounded border border-gray-200 px-2.5 py-1.5 text-xs focus:border-me-primary-500 focus:ring-2 focus:ring-me-primary-500/20 focus:outline-none`,type:`search`,placeholder:`Search plugins…`,value:u,onChange:e=>d(e.currentTarget.value)}),_?L(`div`,{className:`rounded border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700`,children:_}):null,L(`div`,{className:`flex flex-col gap-2`,children:b.map(n=>{let r=Mr(n,i,t),a=y.has(n.metadata.id),o=r&&n.loadStatus===`loading`,s=r&&n.loadStatus===`error`?n.loadError:null,c=Hs(n.metadata.image),l=r&&!a&&!o&&!s,u=Ar(n,e,t),d=jr(n,e,t),f=Ws(n),h=!!n.settings,_=m===`workspace:${n.metadata.id}`;return R(`article`,{className:`flex gap-2.5 rounded-lg border bg-white p-3 text-sm transition-colors ${a?`border-gray-200`:`border-gray-100 opacity-60`} ${u?``:`opacity-40`}`,children:[c?L(`img`,{className:`h-9 w-9 rounded object-cover flex-none mt-0.5`,src:c.src,alt:c.alt||n.metadata.label}):L(`div`,{className:`h-9 w-9 rounded flex items-center justify-center flex-none mt-0.5 text-lg ${a?`bg-me-primary-50 text-me-primary-500`:`bg-gray-100 text-gray-400`}`,children:L(Ks,{className:`w-4 h-4`})}),R(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[R(`div`,{className:`flex items-start justify-between gap-1`,children:[R(`div`,{className:`flex flex-wrap items-center gap-1.5 min-w-0`,children:[L(`span`,{className:`font-medium text-gray-900 text-xs`,children:n.metadata.label}),n.metadata.official?R(`span`,{className:`rounded-full text-me-primary-500 px-1.5 py-0 text-[9px] font-bold inline-flex items-center gap-1`,children:[L(g,{className:`w-3 h-3`}),` Verified`]}):null,n.metadata.version?L(`span`,{className:`text-[10px] text-gray-400`,children:n.metadata.version}):null]}),R(`div`,{className:`flex items-center gap-1 flex-none`,children:[h?L(`button`,{type:`button`,title:`Configure plugin`,className:`rounded p-1 text-gray-400 hover:text-gray-700 hover:bg-gray-100 transition-colors`,onClick:()=>p(n.metadata.id),children:L(Ks,{className:`w-3.5 h-3.5`})}):null,a&&f?L(`button`,{type:`button`,title:`Open ${f.label}`,className:`rounded p-1 text-me-primary-500 hover:bg-me-primary-50 transition-colors`,onClick:()=>T(n),children:L(qs,{className:`w-3.5 h-3.5`})}):null,L(`button`,{type:`button`,disabled:!u||_,onClick:()=>w(n,!r,`workspace`),className:`relative inline-flex h-5 w-9 flex-none items-center rounded-full transition-colors disabled:opacity-40 focus:outline-none focus:ring-2 focus:ring-me-primary-500/30 ${r?`bg-me-primary-500`:`bg-gray-200`}`,title:r?`Disable plugin`:`Enable plugin`,"aria-label":r?`Disable plugin`:`Enable plugin`,children:L(`span`,{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white shadow transition-transform ${r?`translate-x-4`:`translate-x-0.5`}`})})]})]}),n.metadata.description?L(`p`,{className:`text-xs text-gray-500 leading-relaxed`,children:n.metadata.description}):null,o?L(`span`,{className:`text-xs text-gray-500`,children:`Loading plugin…`}):null,s?L(`span`,{className:`text-xs text-red-600`,children:s}):null,l?L(`span`,{className:`text-xs text-amber-600`,children:`Waiting for required dependencies`}):null,!u&&d?L(`span`,{className:`text-xs text-gray-400`,children:d}):null]})]},n.metadata.id)})}),b.length?null:L(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 p-4 text-center text-xs text-gray-500`,children:`No plugins found.`}),x?L(ee,{title:`Configure ${x.metadata.label}`,onClose:()=>p(null),width:`560px`,children:L(Ys,{plugin:x,onClose:()=>p(null),canSaveGlobal:!!s})}):null]})}function Ys({plugin:e,onClose:t,canSaveGlobal:n}){let r=ai(e.metadata.id),[i,a]=F(`workspace`),[o,s]=F({}),[c,l]=F(!1),[u,d]=F(!1),[f,p]=F(null),m=i===`global`?r.global:r.workspace;j(()=>{s({...m}),p(null),d(!1)},[e.metadata.id,i]);async function h(){let t=e.settings?.validate?.(o);if(t){p(t);return}l(!0),p(null);try{i===`global`?await r.setGlobalSettings(o):r.setWorkspaceSettings(o),d(!0),setTimeout(()=>d(!1),2e3)}catch(e){p(Gs(e))}finally{l(!1)}}async function g(){l(!0),p(null);try{i===`global`?await r.resetGlobalSettings():r.resetWorkspaceSettings(),s({})}catch(e){p(Gs(e))}finally{l(!1)}}return R(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[n&&r.canSaveGlobal?R(`div`,{className:`flex items-center gap-1 px-5 pt-4 pb-3 border-b border-gray-100`,children:[L(`span`,{className:`text-xs text-gray-500 mr-2`,children:`Scope:`}),L(`button`,{type:`button`,className:`rounded-full px-3 py-1 text-xs font-medium transition-colors ${i===`workspace`?`bg-me-primary-500 text-white`:`bg-gray-100 text-gray-600 hover:bg-gray-200`}`,onClick:()=>a(`workspace`),children:`This workspace`}),L(`button`,{type:`button`,className:`rounded-full px-3 py-1 text-xs font-medium transition-colors ${i===`global`?`bg-me-primary-500 text-white`:`bg-gray-100 text-gray-600 hover:bg-gray-200`}`,onClick:()=>a(`global`),children:`All workspaces`})]}):null,f?L(`div`,{className:`mx-5 mt-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700`,children:f}):null,L(`div`,{className:`flex-1 overflow-y-auto p-5`,children:L(`div`,{className:`flex flex-col gap-3`,children:e.settings?.render?e.settings.render({plugin:e,appId:r.appId,scope:i,value:o,defaults:r.defaults,effective:r.effective,onChange:s}):e.settings?.fields?.length?e.settings.fields.map(e=>L(Xs,{field:e,draft:o,setDraft:s},e.id)):L(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 p-4 text-center text-sm text-gray-500`,children:`This plugin has no configurable settings.`})})}),R(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-100 px-5 py-4`,children:[L(`button`,{type:`button`,className:`text-xs text-gray-400 hover:text-gray-600 transition-colors disabled:opacity-40`,disabled:c,onClick:g,children:`Reset to defaults`}),R(`div`,{className:`flex items-center gap-2`,children:[u?L(`span`,{className:`text-xs text-green-600`,children:`✓ Saved`}):null,L(`button`,{type:`button`,className:`rounded-lg bg-me-primary-500 px-4 py-2 text-sm font-medium text-white hover:bg-me-primary-600 disabled:opacity-50 transition-colors`,disabled:c,onClick:h,children:c?`Saving…`:`Save ${i}`})]})]})]})}function Xs({field:e,draft:t,setDraft:n}){let r=t[e.id],i=`plugin-setting-${e.id}`;function a(r){n({...t,[e.id]:r})}let o=L(`label`,{className:`text-sm font-medium text-gray-900`,htmlFor:i,children:e.label}),s=`rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:ring-2 focus:ring-me-primary-500/20 focus:outline-none`;return e.type===`boolean`?R(`div`,{className:`flex items-center justify-between rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[R(`div`,{className:`flex flex-col gap-0.5`,children:[o,e.description?L(`span`,{className:`text-xs text-gray-500`,children:e.description}):null]}),L(`input`,{id:i,type:`checkbox`,checked:r===!0,onChange:e=>a(e.currentTarget.checked),className:`h-4 w-4 rounded border-gray-300 text-me-primary-500 focus:ring-me-primary-500`})]}):e.type===`textarea`?R(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?L(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,L(`textarea`,{id:i,className:`${s} min-h-24 resize-y`,value:typeof r==`string`?r:``,placeholder:e.placeholder,onChange:e=>a(e.currentTarget.value)})]}):e.type===`select`?R(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?L(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,R(`select`,{id:i,className:s,value:r===void 0?``:String(r),onChange:t=>{let n=e.options?.find(e=>String(e.value)===t.currentTarget.value);a(n?n.value:t.currentTarget.value)},children:[L(`option`,{value:``,children:`Default`}),(e.options||[]).map(e=>L(`option`,{value:String(e.value),children:e.label},String(e.value)))]})]}):R(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?L(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,L(`input`,{id:i,className:s,type:e.type===`number`?`number`:`text`,value:typeof r==`string`||typeof r==`number`?r:``,placeholder:e.placeholder,onChange:t=>{a(e.type===`number`?Number(t.currentTarget.value):t.currentTarget.value)}})]})}function Zs(){let t=Wi(),n=Oi(),r=Ot(),i=kt(),[a,o]=Vs(2e3);function s(e){e.preventDefault();let t=new FormData(e.target);i({defaultPreview:t.get(`defaultPreview`),i18n:{...r.i18n||{},advancedLanguageMode:t.get(`advancedLanguageMode`)===`on`,availableLanguages:(t.get(`availableLanguages`)||``).split(`,`).map(e=>e.trim()),defaultLanguage:t.get(`defaultLanguage`)},export:{...r.export||{},version:t.get(`isVersion2`)===`on`?2:3,baseIdentifier:t.get(`base`)||null},plugins:r.plugins,editorFeatureFlags:{...r.editorFeatureFlags||{},rememberCanvasId:t.get(`rememberCanvasId`)===`on`,rememberLeftPanelId:t.get(`rememberLeftPanelId`)===`on`,annotationPopups:t.get(`annotationPopups`)===`on`,manifestGridOptions:t.get(`manifestGridOptions`)===`on`,enableMultiImageCanvases:t.get(`enableMultiImageCanvases`)===`on`,enableMultiMediaCanvases:t.get(`enableMultiMediaCanvases`)===`on`}}),o.set(),o.clear()}return R(oe,{children:[L(se,{title:`Workspace configuration`}),a?L(`div`,{className:`bg-me-primary-500 text-white p-3 text-sm`,children:`Changes saved`}):null,L(D,{className:`p-4`,children:R(S.Form,{onSubmit:s,className:`flex flex-col gap-3`,children:[R(S.InputContainer,{children:[L(S.Label,{htmlFor:`defaultLanguage`,children:`Default Language`}),L(S.Input,{type:`text`,name:`defaultLanguage`,id:`defaultLanguage`,defaultValue:r.i18n?.defaultLanguage||``})]}),R(S.InputContainer,{children:[L(S.Label,{htmlFor:`availableLanguages`,children:`Available Languages`}),L(S.Input,{type:`text`,name:`availableLanguages`,id:`availableLanguages`,defaultValue:(r.i18n?.availableLanguages||[]).join(`, `)})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`advancedLanguageMode`,id:`advancedLanguageMode`,defaultChecked:r.i18n?.advancedLanguageMode||!1}),L(S.Label,{htmlFor:`advancedLanguageMode`,children:`Advanced Language Mode`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`textGranularityEnabled`,id:`textGranularityEnabled`,defaultChecked:r.i18n?.textGranularityEnabled||!1}),L(S.Label,{htmlFor:`textGranularityEnabled`,children:`Enable text granularity`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`rememberCanvasId`,id:`rememberCanvasId`,defaultChecked:r.editorFeatureFlags?.rememberCanvasId||!1}),L(S.Label,{htmlFor:`rememberCanvasId`,children:`Remember Canvas ID`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`rememberLeftPanelId`,id:`rememberLeftPanelId`,defaultChecked:r.editorFeatureFlags?.rememberLeftPanelId||!1}),L(S.Label,{htmlFor:`rememberLeftPanelId`,children:`Remember Left panel`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`manifestGridOptions`,id:`manifestGridOptions`,defaultChecked:r.editorFeatureFlags?.manifestGridOptions||!1}),L(S.Label,{htmlFor:`manifestGridOptions`,children:`Manifest Grid Options`})]}),R(S.InputContainer,{horizontal:!0,className:`my-3`,children:[L(S.Input,{type:`checkbox`,name:`isVersion2`,id:`isVersion2`,defaultChecked:r.export?.version===2}),R(S.Label,{htmlFor:`isVersion2`,children:[`Export Presentation 2 `,n.type,`s`]})]}),R(S.InputContainer,{children:[L(S.Label,{htmlFor:`defaultPreview`,children:`Default preview`}),L(`div`,{children:t.configs.map((e,t)=>e.type===`iiif-preview-service`?null:R(S.InputContainer,{horizontal:!0,children:[L(S.Input,{type:`radio`,id:e.id,name:`defaultPreview`,value:e.id,defaultChecked:r.defaultPreview?r.defaultPreview===e.id:t===0}),L(`label`,{htmlFor:e.id,children:e.label})]},e.id))})]}),n.type===`Manifest`?L(`a`,{className:`text-sm text-me-primary-500 hover:underline hover:text-me-primary-600`,href:window.location.pathname.includes(`/exhibition`)?window.location.pathname.replace(`/exhibition`,``)||`/`:`${window.location.pathname}/exhibition`,children:window.location.pathname.includes(`/exhibition`)?`Return to Manifest Editor`:`Go to Exhibition Editor`}):null,L(Js,{}),L(`div`,{className:`mt-5`,children:L(e,{type:`submit`,children:`Save changes`})})]})})]})}function Qs(){return Ae((e,t)=>({specificMenus:{},resourceMenus:{},hookMenuItem(t){let n=lr(),r=t.resource?.id||``,i=t.resource?.type;return i?r?(e(e=>({specificMenus:{...e.specificMenus,[r]:{...e.specificMenus[r]||{},menus:{...e.specificMenus[r]?.menus||{},[n]:{sectionTitle:t.sectionTitle,items:t.items}}}}})),()=>{e(e=>({specificMenus:{...e.specificMenus,[r]:{...e.specificMenus[r]||{},menus:{...e.specificMenus[r]?.menus||{},[n]:void 0}}}}))}):(e(e=>({resourceMenus:{...e.resourceMenus,[i]:{...e.resourceMenus[i]||{},menus:{...e.resourceMenus[i]?.menus||{},[n]:{sectionTitle:t.sectionTitle,items:t.items}}}}})),()=>{e(e=>({resourceMenus:{...e.resourceMenus,[i]:{...e.resourceMenus[i]||{},menus:{...e.resourceMenus[i]?.menus||{},[n]:void 0}}}}))}):()=>{}}}))}const $s=O(null);function ec({children:e}){let t=N(()=>Qs(),[]);return L($s.Provider,{value:t,children:e})}function tc(){let e=A($s);if(!e)throw Error(`useContextMenuStore must be used within a ContextMenuProvider`);return e}function nc(e){let t=tc(),n=je(t,e=>e.resourceMenus),r=je(t,e=>e.specificMenus);return N(()=>{let t=r[e.id||``]?.menus||{},i=n[e.type]?.menus||{},a=Object.values(t).flat(),o=[...Object.values(i).flat(),...a].filter(e=>e!==void 0),s=[],c=[];for(let e of o){let t=[];for(let n of e.items||[])n.id&&s.includes(n.id)||(s.push(n.id),t.push(n));t.length&&c.push({...e,items:t})}return rc(c)},[r,n,e.id,e.type])}function rc(e){let t={},n=[];e.forEach(e=>{if(!e)return;let r=e.sectionTitle;if(!r){n.push(...e.items||[]);return}t[r]||(t[r]=[]),t[r].push(...e.items)});let r=Object.entries(t).map(([e,t])=>({sectionTitle:e,items:t}));return n.length&&r.push({items:n}),r}function ic(e,t=[]){let n=je(tc(),e=>e.hookMenuItem);j(()=>n(e),[n,e.resource?.id,e.resource?.type,...t])}var ac={};function oc(e){return R(`div`,{className:ac.CenterPanelContainer,children:[e.title||e.close?R(`div`,{className:ac.CenterPanelHeader,children:[e.title?L(`h2`,{className:ac.CenterPanelTitle,children:e.title}):null,e.close?L(Y,{className:ac.CenterPanelClose,onClick:e.close,children:L(Ci,{})}):null]}):null,e.children]})}const sc=V.div`
430
430
  flex: 1;
431
431
  display: flex;
432
432
  width: 100%;
433
433
  flex-direction: column;
434
434
  position: relative;
435
- `,ec=V.div`
435
+ `,cc=V.div`
436
436
  background: #fff;
437
437
  position: relative;
438
438
  border-bottom: 1px solid #d0d0d0;
@@ -450,11 +450,11 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
450
450
  //flex-direction: column;
451
451
  //justify-content: center;
452
452
  }
453
- `,tc=V.p`
453
+ `,lc=V.p`
454
454
  font-size: 0.9em;
455
455
  color: #777;
456
456
  font-weight: 400;
457
- `,nc=V.button`
457
+ `,uc=V.button`
458
458
  color: inherit;
459
459
  text-rendering: geometricPrecision;
460
460
  border: none;
@@ -496,7 +496,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
496
496
  margin-top: 0.5em;
497
497
  }
498
498
  }
499
- `,rc=V.div`
499
+ `,dc=V.div`
500
500
  font-size: 1.4em;
501
501
  padding-right: 0.3em;
502
502
  display: flex;
@@ -505,7 +505,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
505
505
  [data-large="true"] & {
506
506
  font-size: 2em;
507
507
  }
508
- `,ic=V.div`
508
+ `,fc=V.div`
509
509
  width: 2em;
510
510
  align-items: center;
511
511
  //padding-top: 0.5em;
@@ -518,11 +518,11 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
518
518
  fill: #999;
519
519
  color: #999;
520
520
  }
521
- `,ac=V.div`
521
+ `,pc=V.div`
522
522
  min-height: 0;
523
523
  overflow: visible;
524
524
  display: flex;
525
- `,oc=V.div`
525
+ `,mc=V.div`
526
526
  min-height: 0;
527
527
  overflow: visible;
528
528
  flex: 1;
@@ -535,7 +535,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
535
535
  &[data-max-height="true"] {
536
536
  overflow-y: auto;
537
537
  }
538
- `,sc=V.section`
538
+ `,hc=V.section`
539
539
  display: grid;
540
540
  grid-template-rows: 0fr;
541
541
  overflow: hidden;
@@ -563,7 +563,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
563
563
  &[data-scrolled="true"] {
564
564
  box-shadow: inset 0px 2px 0px 0 rgba(0, 0, 0, 0.1);
565
565
  }
566
- `,cc=V.div`
566
+ `,gc=V.div`
567
567
  position: sticky;
568
568
  display: flex;
569
569
  top: 0;
@@ -599,7 +599,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
599
599
  right: 0.5em;
600
600
  }
601
601
  }
602
- `,lc=(()=>void 0);let uc=0;function dc(){return N(()=>uc++,[])}function fc(e,t=!1){let[n,r]=F([]),i=P(-1),a=t=>{let r=document.activeElement,i=n.findIndex(e=>e.current?.button?.current===r);if(i!==-1)switch(t.code){case`Home`:n[0]&&n[0].current?.focus();break;case`End`:{let t=e-1;n[t]&&n[t].current?.focus();break}case`ArrowDown`:if(i!==e-1){let e=i+1;n[e]&&n[e].current?.focus()}break;case`ArrowUp`:if(i!==0){let e=i-1;n[e]&&n[e].current?.focus()}break;case`ArrowLeft`:{let e=n[i];e&&e.current&&e.current.close();break}case`ArrowRight`:{let e=n[i];e&&e.current&&e.current.open();break}}},o=(e,r)=>{if(t&&r&&e!==i.current){i.current=e;for(let t=0;t<n.length;t++){let r=n[t];t!==e&&r.current?.close()}}};return j(()=>{r(t=>Array(e).fill(0).map((e,n)=>t[n]||we()))},[e]),{open:e=>{let t=n[e];t&&t.current&&t.current.open()},close:e=>{let t=n[e];t&&t.current&&t.current.close()},toggle:e=>{let t=n[e];t&&t.current&&t.current.toggle()},focus:e=>{let t=n[e];t&&t.current&&t.current.focus()},openAll:()=>{for(let e=0;e<n.length;e++)n[e].current?.open()},closeAll:()=>{for(let e=0;e<n.length;e++)n[e].current?.close()},onKeyDown:a,getItemProps:e=>({ref:n[e],onChange:t=>o(e,t)})}}const pc=Te(function(e,t){let n=P(null),r=P(null),i=dc(),[a,o]=F(e.initialOpen||!1),s=e.onChange||lc,c=()=>{s(!a),o(e=>!e)},l=e.maxHeight,[u,d]=F(!1);De(t,()=>({open(){s(!0),o(!0)},close(){s(!1),o(!1)},toggle(){c()},focus(){r.current&&r.current.focus()},button:r}));let f=e=>{e.target.scrollTop>0?d(!0):d(!1)};return R(ec,{"data-large":e.large,"data-open":a,children:[R(cc,{"data-open":a,children:[e.icon?L(ic,{onClick:c,children:e.icon}):null,R(nc,{ref:r,onClick:c,"aria-expanded":a,"aria-controls":`accordion-${i}`,children:[e.label,e.description?L(tc,{children:e.description}):null]}),L(rc,{onClick:c,children:L(gi,{width:`1em`,height:`1em`,rotate:a?0:180})})]}),L(sc,{"aria-labelledby":`accordion-${i}`,"aria-hidden":!a,"data-overflow":!!e.overflow,"data-has-icon":!!e.icon,onScroll:f,ref:n,$initial:!a,"data-scrolled":u,hidden:!a,children:L(ac,{children:L(oc,{"data-max-height":!!l,"data-full":e.fullWidth,style:{maxHeight:l||void 0},children:e.children})})})]})});function mc(e){let{getItemProps:t,onKeyDown:n}=fc(e.items.length,e.singleMode);return L($s,{onKeyDown:n,children:e.items.map((n,r)=>L(pc,{overflow:e.overflow,maxHeight:e.maxHeight,...n,...t(r),children:n.children},r))})}function hc(){return L(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`48`,viewBox:`0 -960 960 960`,width:`48`,children:L(`path`,{d:`M220-160q-24 0-42-18t-18-42v-143h60v143h520v-143h60v143q0 24-18 42t-42 18H220Zm260-153L287-506l43-43 120 120v-371h60v371l120-120 43 43-193 193Z`})})}const gc=V.div`
602
+ `,_c=(()=>void 0);let vc=0;function yc(){return N(()=>vc++,[])}function bc(e,t=!1){let[n,r]=F([]),i=P(-1),a=t=>{let r=document.activeElement,i=n.findIndex(e=>e.current?.button?.current===r);if(i!==-1)switch(t.code){case`Home`:n[0]&&n[0].current?.focus();break;case`End`:{let t=e-1;n[t]&&n[t].current?.focus();break}case`ArrowDown`:if(i!==e-1){let e=i+1;n[e]&&n[e].current?.focus()}break;case`ArrowUp`:if(i!==0){let e=i-1;n[e]&&n[e].current?.focus()}break;case`ArrowLeft`:{let e=n[i];e&&e.current&&e.current.close();break}case`ArrowRight`:{let e=n[i];e&&e.current&&e.current.open();break}}},o=(e,r)=>{if(t&&r&&e!==i.current){i.current=e;for(let t=0;t<n.length;t++){let r=n[t];t!==e&&r.current?.close()}}};return j(()=>{r(t=>Array(e).fill(0).map((e,n)=>t[n]||we()))},[e]),{open:e=>{let t=n[e];t&&t.current&&t.current.open()},close:e=>{let t=n[e];t&&t.current&&t.current.close()},toggle:e=>{let t=n[e];t&&t.current&&t.current.toggle()},focus:e=>{let t=n[e];t&&t.current&&t.current.focus()},openAll:()=>{for(let e=0;e<n.length;e++)n[e].current?.open()},closeAll:()=>{for(let e=0;e<n.length;e++)n[e].current?.close()},onKeyDown:a,getItemProps:e=>({ref:n[e],onChange:t=>o(e,t)})}}const xc=Te(function(e,t){let n=P(null),r=P(null),i=yc(),[a,o]=F(e.initialOpen||!1),s=e.onChange||_c,c=()=>{s(!a),o(e=>!e)},l=e.maxHeight,[u,d]=F(!1);De(t,()=>({open(){s(!0),o(!0)},close(){s(!1),o(!1)},toggle(){c()},focus(){r.current&&r.current.focus()},button:r}));let f=e=>{e.target.scrollTop>0?d(!0):d(!1)};return R(cc,{"data-large":e.large,"data-open":a,children:[R(gc,{"data-open":a,children:[e.icon?L(fc,{onClick:c,children:e.icon}):null,R(uc,{ref:r,onClick:c,"aria-expanded":a,"aria-controls":`accordion-${i}`,children:[e.label,e.description?L(lc,{children:e.description}):null]}),L(dc,{onClick:c,children:L(wi,{width:`1em`,height:`1em`,rotate:a?0:180})})]}),L(hc,{"aria-labelledby":`accordion-${i}`,"aria-hidden":!a,"data-overflow":!!e.overflow,"data-has-icon":!!e.icon,onScroll:f,ref:n,$initial:!a,"data-scrolled":u,hidden:!a,children:L(pc,{children:L(mc,{"data-max-height":!!l,"data-full":e.fullWidth,style:{maxHeight:l||void 0},children:e.children})})})]})});function Sc(e){let{getItemProps:t,onKeyDown:n}=bc(e.items.length,e.singleMode);return L(sc,{onKeyDown:n,children:e.items.map((n,r)=>L(xc,{overflow:e.overflow,maxHeight:e.maxHeight,...n,...t(r),children:n.children},r))})}function Cc(){return L(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`48`,viewBox:`0 -960 960 960`,width:`48`,children:L(`path`,{d:`M220-160q-24 0-42-18t-18-42v-143h60v143h520v-143h60v143q0 24-18 42t-42 18H220Zm260-153L287-506l43-43 120 120v-371h60v371l120-120 43 43-193 193Z`})})}const wc=V.div`
603
603
  padding: 0.3em;
604
604
 
605
605
  display: flex;
@@ -621,12 +621,12 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
621
621
  position: sticky;
622
622
  bottom: 0;
623
623
  }
624
- `;function _c(e){let t=Ge(),n=z(),r=_a(),i=N(()=>JSON.stringify(n.toPresentation3(t),null,2),[t,n]),a=N(()=>JSON.stringify(n.toPresentation2(t),null,2),[t,n]);return L(Qs,{title:`Export manifest`,close:r.centerPanel.popStack,children:L(`div`,{style:{flex:1,overflowY:`auto`},children:L(mc,{items:[{label:`Presentation 3`,description:`Download this version by clicking the "Download" button.`,maxHeight:400,large:!0,initialOpen:!0,overflow:!0,icon:L(Y,{onClick:()=>rr(i,`manifest.json`),children:L(hc,{})}),children:R(`div`,{style:{maxWidth:`100%`},children:[L(`pre`,{style:{whiteSpace:`pre-wrap`},children:JSON.stringify(n.toPresentation3(t),null,2)}),R(gc,{"data-sticky":`true`,children:[L(Y,{onClick:()=>ir(i),children:`Copy to clipboard`}),L(Y,{onClick:()=>rr(i,`manifest.json`),children:`Download`})]})]})},{label:`Presentation 2`,description:`Download this version by clicking the "Download" button.`,maxHeight:400,large:!0,icon:L(Y,{onClick:()=>rr(a,`manifest.json`),children:L(hc,{})}),children:R(`div`,{style:{maxWidth:`100%`},children:[L(`pre`,{style:{whiteSpace:`pre-wrap`},children:JSON.stringify(n.toPresentation2(t),null,2)}),R(gc,{"data-sticky":`true`,children:[L(Y,{onClick:()=>ir(a),children:`Copy to clipboard`}),L(Y,{onClick:()=>rr(a,`manifest.json`),children:`Download`})]})]})}]})})})}function vc({key:e,initialValue:t,requestId:n,getInitialValue:r}){let[i,a]=Ue({requestId:n}),[o,s]=F(r&&r(i)||i[e]||t);return[o,k(t=>{a({[e]:t}),s(t)},[])]}const yc=O(pt());function bc({children:e,emitter:t}){return L(yc.Provider,{value:t,children:e})}function xc(){return A(yc)}function Sc(e,t,n=[]){let r=A(yc);j(()=>{let n=e=>{t(e)};return r.on(e,n),()=>{r.off(e,n)}},[r,e,...n])}function Cc(e,t=[]){let n=t.length?t:Array(e.length).fill(!1);if(typeof window>`u`)return n;let r=e.map(e=>window.matchMedia(e)),i=()=>r.map(e=>e.matches),[a,o]=F(i);return M(()=>{let e=()=>o(i);return r.forEach(t=>t.addListener(e)),()=>r.forEach(t=>t.removeListener(e))},[]),a}function wc(e,t,n,r=!0){let i=mt(t,n);j(()=>typeof window>`u`?()=>void 0:(window.addEventListener(`beforeunload`,t,!1),()=>{t(),window.removeEventListener(`beforeunload`,t)}),[t]),j(()=>{if(e&&r)return e.subscribe(i,!0)},[i,e,r])}function Tc(){let e=He(),t=je(e,e=>e.switchTool),n=je(e,e=>e.polygonState.currentTool),r=je(e,e=>e.polygonState.selectedStamp),i=je(e,e=>e.polygonState.showBoundingBox);return N(()=>({currentTool:n,selectedStamp:r,draw:{active:n===`pencil`,enable:t.draw},polygon:{active:n===`pen`,enable:t.pen},line:{active:n===`line`,enable:t.line},lineBox:{active:n===`lineBox`,enable:t.lineBox},square:{active:n===`box`,enable:t.box},triangle:{active:r?.id===`triangle`,enable:t.triangle},hexagon:{active:r?.id===`hexagon`,enable:t.hexagon},circle:{active:r?.id===`circle`,enable:t.circle},remove:{active:i,enable:t.remove}}),[i,r,n,t])}const Ec=V.div`
624
+ `;function Tc(e){let t=Ge(),n=z(),r=Ta(),i=N(()=>JSON.stringify(n.toPresentation3(t),null,2),[t,n]),a=N(()=>JSON.stringify(n.toPresentation2(t),null,2),[t,n]);return L(oc,{title:`Export manifest`,close:r.centerPanel.popStack,children:L(`div`,{style:{flex:1,overflowY:`auto`},children:L(Sc,{items:[{label:`Presentation 3`,description:`Download this version by clicking the "Download" button.`,maxHeight:400,large:!0,initialOpen:!0,overflow:!0,icon:L(Y,{onClick:()=>sr(i,`manifest.json`),children:L(Cc,{})}),children:R(`div`,{style:{maxWidth:`100%`},children:[L(`pre`,{style:{whiteSpace:`pre-wrap`},children:JSON.stringify(n.toPresentation3(t),null,2)}),R(wc,{"data-sticky":`true`,children:[L(Y,{onClick:()=>cr(i),children:`Copy to clipboard`}),L(Y,{onClick:()=>sr(i,`manifest.json`),children:`Download`})]})]})},{label:`Presentation 2`,description:`Download this version by clicking the "Download" button.`,maxHeight:400,large:!0,icon:L(Y,{onClick:()=>sr(a,`manifest.json`),children:L(Cc,{})}),children:R(`div`,{style:{maxWidth:`100%`},children:[L(`pre`,{style:{whiteSpace:`pre-wrap`},children:JSON.stringify(n.toPresentation2(t),null,2)}),R(wc,{"data-sticky":`true`,children:[L(Y,{onClick:()=>cr(a),children:`Copy to clipboard`}),L(Y,{onClick:()=>sr(a,`manifest.json`),children:`Download`})]})]})}]})})})}function Ec({key:e,initialValue:t,requestId:n,getInitialValue:r}){let[i,a]=Ue({requestId:n}),[o,s]=F(r&&r(i)||i[e]||t);return[o,k(t=>{a({[e]:t}),s(t)},[])]}const Dc=O(pt());function Oc({children:e,emitter:t}){return L(Dc.Provider,{value:t,children:e})}function kc(){return A(Dc)}function Ac(e,t,n=[]){let r=A(Dc);j(()=>{let n=e=>{t(e)};return r.on(e,n),()=>{r.off(e,n)}},[r,e,...n])}function jc(e,t=[]){let n=t.length?t:Array(e.length).fill(!1);if(typeof window>`u`)return n;let r=e.map(e=>window.matchMedia(e)),i=()=>r.map(e=>e.matches),[a,o]=F(i);return M(()=>{let e=()=>o(i);return r.forEach(t=>t.addListener(e)),()=>r.forEach(t=>t.removeListener(e))},[]),a}function Mc(e,t,n,r=!0){let i=mt(t,n);j(()=>typeof window>`u`?()=>void 0:(window.addEventListener(`beforeunload`,t,!1),()=>{t(),window.removeEventListener(`beforeunload`,t)}),[t]),j(()=>{if(e&&r)return e.subscribe(i,!0)},[i,e,r])}function Nc(){let e=He(),t=je(e,e=>e.switchTool),n=je(e,e=>e.polygonState.currentTool),r=je(e,e=>e.polygonState.selectedStamp),i=je(e,e=>e.polygonState.showBoundingBox);return N(()=>({currentTool:n,selectedStamp:r,draw:{active:n===`pencil`,enable:t.draw},polygon:{active:n===`pen`,enable:t.pen},line:{active:n===`line`,enable:t.line},lineBox:{active:n===`lineBox`,enable:t.lineBox},square:{active:n===`box`,enable:t.box},triangle:{active:r?.id===`triangle`,enable:t.triangle},hexagon:{active:r?.id===`hexagon`,enable:t.hexagon},circle:{active:r?.id===`circle`,enable:t.circle},remove:{active:i,enable:t.remove}}),[i,r,n,t])}const Pc=V.div`
625
625
  position: relative;
626
626
  width: 1px;
627
627
  background: rgba(0, 0, 0, 0.2);
628
628
  z-index: 50;
629
- `,Dc=V(Li)`
629
+ `,Fc=V(Gi)`
630
630
  transition:
631
631
  opacity 300ms,
632
632
  transform 300ms;
@@ -638,7 +638,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
638
638
  &:focus {
639
639
  outline: 2px solid salmon;
640
640
  }
641
- `;V(Dc)`
641
+ `;V(Fc)`
642
642
  background: #fff;
643
643
  width: 30px;
644
644
  height: 30px;
@@ -652,7 +652,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
652
652
  svg {
653
653
  fill: #9999;
654
654
  }
655
- `;const Oc=V(Dc)`
655
+ `;const Ic=V(Fc)`
656
656
  position: relative;
657
657
  display: flex;
658
658
  opacity: 1;
@@ -679,7 +679,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
679
679
  svg {
680
680
  font-size: 1.5em;
681
681
  }
682
- `,kc=V.div`
682
+ `,Lc=V.div`
683
683
  background: rgba(0, 0, 0, 0);
684
684
  position: absolute;
685
685
  width: 16px;
@@ -702,12 +702,12 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
702
702
  &:hover {
703
703
  transform: scaleX(100%);
704
704
  background: rgba(0, 0, 0, 0.1);
705
- ${Dc} {
705
+ ${Fc} {
706
706
  transform: scaleX(100%);
707
707
  opacity: 1;
708
708
  }
709
709
  }
710
- `,Ac=V.div`
710
+ `,Rc=V.div`
711
711
  background: rgba(0, 0, 0, 0);
712
712
  position: absolute;
713
713
  pointer-events: none;
@@ -716,7 +716,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
716
716
  top: 0;
717
717
  bottom: 0;
718
718
  z-index: 51; // This will always be quite high.
719
- `,jc=Te(function({dir:e,open:t,actions:n,reset:r},i){let[a,o]=F(!0),s=`mt-[calc(50vh+8px)]`,c=e===`left`?`${s} ml-[13px]`:`${s} ml-[3px]`;return R(Ec,{onClick:()=>n.open(),children:[L(Ac,{$open:t,$dir:e,className:`group`,children:t?null:R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{as:Oc,$dir:e,onClick:e=>n.open(),children:L(gi,{className:`text-2xl`,rotate:e===`right`?90:270})}),L(v,{children:`Open`})]})}),R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{"aria-label":`Resize panel`,asChild:!0,children:L(`div`,{children:R(kc,{ref:i,$open:t,$dir:e,className:`group`,children:[t?R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{as:T,onPress:()=>n.close(),children:L(`div`,{onMouseOut:()=>{o(!0)},onMouseOver:()=>{o(!1)},children:L(hi,{})})}),L(v,{children:`Close`})]}):null,r&&t?R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{as:T,onPress:()=>r(),children:L(`div`,{onMouseOut:()=>{o(!0)},onMouseOver:()=>{o(!1)},children:L(ie,{})})}),L(v,{children:`Reset`})]}):null,t?R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{asChild:!0,"aria-label":`Resize panel`,children:L(`div`,{onMouseOut:()=>{o(!0)},onMouseOver:()=>{o(!1)},children:L(ae,{"aria-label":`Resize panel`})})}),L(v,{children:`Resize panel`})]}):null]})})}),a&&L(v,{className:c,children:`Resize panel`})]})]})});function Mc(e){return L(`svg`,{width:`1em`,height:`1em`,viewBox:`0 0 42 42`,xmlns:`http://www.w3.org/2000/svg`,stroke:`currentColor`,...e,children:R(`g`,{transform:`translate(2 2)`,strokeWidth:5,fill:`none`,fillRule:`evenodd`,children:[L(`circle`,{strokeOpacity:.5,cx:18,cy:18,r:18}),L(`path`,{d:`M36 18c0-9.94-8.06-18-18-18`,children:L(`animateTransform`,{attributeName:`transform`,type:`rotate`,from:`0 18 18`,to:`360 18 18`,dur:`1s`,repeatCount:`indefinite`})})]})})}var Nc={};function Pc(){return R(I,{children:[L(`div`,{"data-header":`true`,className:Nc.ghostLoadingBlock}),R(`div`,{className:Nc.ghostBlockList,children:[L(`div`,{className:Nc.ghostLoadingBlock}),L(`div`,{className:Nc.ghostLoadingBlock}),L(`div`,{className:Nc.ghostLoadingBlock}),L(`div`,{className:Nc.ghostLoadingBlock})]})]})}function Fc(e,t,n,r=[]){M(()=>{let r=e.current;if(r)return r.addEventListener(t,n),()=>{r.removeEventListener(t,n)}},[t,...r])}function Ic(e,t,n,r){return Math.sqrt(Math.abs(n-e)**2+Math.abs(r-t)**2)}function Lc(e,t,n,r){return n||(r?r/e:t)}function Rc(e,t={}){let n=P(null),r=P(null),i=P(null),a=P(null),o=P(.5),[s,c]=F(!1),l=P(!1),u=P(0),d=P({x:0,y:0}),[{widthA:f,widthB:p},m]=_e(`resize-layout/${e}`,{widthA:`auto`,widthB:`${Jo({initial:t.widthA,fallback:320,options:{minWidth:t.minWidthPx,maxWidth:t.maxWidthPx}})}px`}),{loading:h=!1}=t;return Fc(a,`mousedown`,e=>{d.current.x=e.pageX,d.current.y=e.pageY,u.current&&(clearTimeout(u.current),u.current=0),u.current=setTimeout(()=>{c(!0),l.current=!0},350)},[h]),Fc({current:typeof window<`u`?window:void 0},`mouseup`,()=>{let e=n.current;if(e&&l.current){let{x:n,width:r}=e.getBoundingClientRect(),i=t.marginLeft||0,a=Lc(r,.8,t.maxWidthPct,t.maxWidthPx)*r,s=Lc(r,.2,t.minWidthPct,t.minWidthPx)*r;if(t.left){let e=o.current*r-i;m({widthA:`${(1-o.current)*r-i}`,widthB:`${e>a?a:e<s?s:e}px`})}else{let e=1-o.current*r-i;m({widthA:`${e>a?a:e<s?s:e}px`,widthB:`${o.current*r-i}px`})}c(!1),l.current=!1,t.onDragEnd&&t.onDragEnd()}clearTimeout(u.current),u.current=0},[h]),Fc(n,`mousemove`,e=>{if(!l.current&&u.current&&Ic(d.current.x,d.current.y,e.pageX,e.pageY)>20&&(c(!0),l.current=!0,clearTimeout(u.current),u.current=0),l.current&&r.current){let i=n.current;if(i){let{x:n,width:a}=i.getBoundingClientRect(),s=t.marginLeft||0,c=t.left||!1,l=Lc(a,.8,t.maxWidthPct,t.maxWidthPx),u=Lc(a,.2,t.minWidthPct,t.minWidthPx);o.current=(a+n-e.pageX-5)/a,c&&(o.current=1-o.current),o.current=o.current<u?u:o.current,o.current=o.current>l?l:o.current,r.current.style.width=`${o.current*a-s}px`}}},[s,h]),{refs:{container:n,resizer:a,resizableDiv:r,otherDiv:i},setWidths:m,isDragging:s,widthA:f,widthB:p}}function zc(e,t,n){return e.filter(e=>{if(!e.supports)return!0;try{return e.supports(t)}catch(t){return n?.(e,t),!1}})}function Bc(e,t){return t?e.some(e=>e.id===t)?t:e[0]?.id||null:null}function X(e){return e.map(e=>e.id).join(`,`)}const Z=`.manifest-editor.exhibition-focused &`,Q=`[data-exhibition-theme="dark"] ${Z}`,$={pink:`#b84c74`,pinkHover:`#9f3f64`,lightApp:`#f4f1ec`,lightStage:`#dfdbd4`,lightPanel:`#fff`,lightPanelSoft:`#f8f6f3`,lightBorder:`#dcd5ce`,lightPanelBorder:`#ddd5ce`,lightText:`#25211f`,lightMuted:`#6a625c`,darkApp:`#18161d`,darkStage:`#0e0d12`,darkPanel:`#28222d`,darkPanelSoft:`#2f2934`,darkPanelHeader:`#25222b`,darkHover:`#312c34`,darkSelected:`#3a3440`,darkText:`#f6f1f4`,darkMuted:`#c8c0c6`,darkSubtle:`#999088`,darkLabel:`#d9d1da`,darkWarning:`#4a2636`,darkWarningBorder:`#7a3f59`,darkBorder:`rgba(246, 241, 244, 0.16)`,darkBorderSoft:`rgba(246, 241, 244, 0.14)`},Vc=V.div`
719
+ `,zc=Te(function({dir:e,open:t,actions:n,reset:r},i){let[a,o]=F(!0),s=`mt-[calc(50vh+8px)]`,c=e===`left`?`${s} ml-[13px]`:`${s} ml-[3px]`;return R(Pc,{onClick:()=>n.open(),children:[L(Rc,{$open:t,$dir:e,className:`group`,children:t?null:R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{as:Ic,$dir:e,onClick:e=>n.open(),children:L(wi,{className:`text-2xl`,rotate:e===`right`?90:270})}),L(v,{children:`Open`})]})}),R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{"aria-label":`Resize panel`,asChild:!0,children:L(`div`,{children:R(Lc,{ref:i,$open:t,$dir:e,className:`group`,children:[t?R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{as:T,onPress:()=>n.close(),children:L(`div`,{onMouseOut:()=>{o(!0)},onMouseOver:()=>{o(!1)},children:L(Ci,{})})}),L(v,{children:`Close`})]}):null,r&&t?R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{as:T,onPress:()=>r(),children:L(`div`,{onMouseOut:()=>{o(!0)},onMouseOver:()=>{o(!1)},children:L(ie,{})})}),L(v,{children:`Reset`})]}):null,t?R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{asChild:!0,"aria-label":`Resize panel`,children:L(`div`,{onMouseOut:()=>{o(!0)},onMouseOver:()=>{o(!1)},children:L(ae,{"aria-label":`Resize panel`})})}),L(v,{children:`Resize panel`})]}):null]})})}),a&&L(v,{className:c,children:`Resize panel`})]})]})});function Bc(e){return L(`svg`,{width:`1em`,height:`1em`,viewBox:`0 0 42 42`,xmlns:`http://www.w3.org/2000/svg`,stroke:`currentColor`,...e,children:R(`g`,{transform:`translate(2 2)`,strokeWidth:5,fill:`none`,fillRule:`evenodd`,children:[L(`circle`,{strokeOpacity:.5,cx:18,cy:18,r:18}),L(`path`,{d:`M36 18c0-9.94-8.06-18-18-18`,children:L(`animateTransform`,{attributeName:`transform`,type:`rotate`,from:`0 18 18`,to:`360 18 18`,dur:`1s`,repeatCount:`indefinite`})})]})})}var Vc={};function Hc(){return R(I,{children:[L(`div`,{"data-header":`true`,className:Vc.ghostLoadingBlock}),R(`div`,{className:Vc.ghostBlockList,children:[L(`div`,{className:Vc.ghostLoadingBlock}),L(`div`,{className:Vc.ghostLoadingBlock}),L(`div`,{className:Vc.ghostLoadingBlock}),L(`div`,{className:Vc.ghostLoadingBlock})]})]})}function Uc(e,t,n,r=[]){M(()=>{let r=e.current;if(r)return r.addEventListener(t,n),()=>{r.removeEventListener(t,n)}},[t,...r])}function Wc(e,t,n,r){return Math.sqrt(Math.abs(n-e)**2+Math.abs(r-t)**2)}function Gc(e,t,n,r){return n||(r?r/e:t)}function Kc(e,t={}){let n=P(null),r=P(null),i=P(null),a=P(null),o=P(.5),[s,c]=F(!1),l=P(!1),u=P(0),d=P({x:0,y:0}),[{widthA:f,widthB:p},m]=_e(`resize-layout/${e}`,{widthA:`auto`,widthB:`${ns({initial:t.widthA,fallback:320,options:{minWidth:t.minWidthPx,maxWidth:t.maxWidthPx}})}px`}),{loading:h=!1}=t;return Uc(a,`mousedown`,e=>{d.current.x=e.pageX,d.current.y=e.pageY,u.current&&(clearTimeout(u.current),u.current=0),u.current=setTimeout(()=>{c(!0),l.current=!0},350)},[h]),Uc({current:typeof window<`u`?window:void 0},`mouseup`,()=>{let e=n.current;if(e&&l.current){let{x:n,width:r}=e.getBoundingClientRect(),i=t.marginLeft||0,a=Gc(r,.8,t.maxWidthPct,t.maxWidthPx)*r,s=Gc(r,.2,t.minWidthPct,t.minWidthPx)*r;if(t.left){let e=o.current*r-i;m({widthA:`${(1-o.current)*r-i}`,widthB:`${e>a?a:e<s?s:e}px`})}else{let e=1-o.current*r-i;m({widthA:`${e>a?a:e<s?s:e}px`,widthB:`${o.current*r-i}px`})}c(!1),l.current=!1,t.onDragEnd&&t.onDragEnd()}clearTimeout(u.current),u.current=0},[h]),Uc(n,`mousemove`,e=>{if(!l.current&&u.current&&Wc(d.current.x,d.current.y,e.pageX,e.pageY)>20&&(c(!0),l.current=!0,clearTimeout(u.current),u.current=0),l.current&&r.current){let i=n.current;if(i){let{x:n,width:a}=i.getBoundingClientRect(),s=t.marginLeft||0,c=t.left||!1,l=Gc(a,.8,t.maxWidthPct,t.maxWidthPx),u=Gc(a,.2,t.minWidthPct,t.minWidthPx);o.current=(a+n-e.pageX-5)/a,c&&(o.current=1-o.current),o.current=o.current<u?u:o.current,o.current=o.current>l?l:o.current,r.current.style.width=`${o.current*a-s}px`}}},[s,h]),{refs:{container:n,resizer:a,resizableDiv:r,otherDiv:i},setWidths:m,isDragging:s,widthA:f,widthB:p}}function qc(e,t,n){return e.filter(e=>{if(!e.supports)return!0;try{return e.supports(t)}catch(t){return n?.(e,t),!1}})}function Jc(e,t){return t?e.some(e=>e.id===t)?t:e[0]?.id||null:null}function X(e){return e.map(e=>e.id).join(`,`)}const Z=`.manifest-editor.exhibition-focused &`,Q=`[data-exhibition-theme="dark"] ${Z}`,$={pink:`#b84c74`,pinkHover:`#9f3f64`,lightApp:`#f4f1ec`,lightStage:`#dfdbd4`,lightPanel:`#fff`,lightPanelSoft:`#f8f6f3`,lightBorder:`#dcd5ce`,lightPanelBorder:`#ddd5ce`,lightText:`#25211f`,lightMuted:`#6a625c`,darkApp:`#18161d`,darkStage:`#0e0d12`,darkPanel:`#28222d`,darkPanelSoft:`#2f2934`,darkPanelHeader:`#25222b`,darkHover:`#312c34`,darkSelected:`#3a3440`,darkText:`#f6f1f4`,darkMuted:`#c8c0c6`,darkSubtle:`#999088`,darkLabel:`#d9d1da`,darkWarning:`#4a2636`,darkWarningBorder:`#7a3f59`,darkBorder:`rgba(246, 241, 244, 0.16)`,darkBorderSoft:`rgba(246, 241, 244, 0.14)`},Yc=V.div`
720
720
  display: flex;
721
721
  flex: 1 1 0;
722
722
  min-height: 0;
@@ -730,7 +730,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
730
730
  ${Q} {
731
731
  background: ${$.darkApp};
732
732
  }
733
- `,Hc=V.div`
733
+ `,Xc=V.div`
734
734
  flex: 1 1 0;
735
735
  min-width: 0;
736
736
  min-height: 0;
@@ -846,12 +846,12 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
846
846
  background: ${$.darkHover} !important;
847
847
  color: #fff !important;
848
848
  }
849
- `,Uc=V.div`
849
+ `,Zc=V.div`
850
850
  display: flex;
851
851
  flex: 1;
852
852
  justify-content: center;
853
853
  align-items: center;
854
- `,Wc=V.div`
854
+ `,Qc=V.div`
855
855
  position: absolute;
856
856
  top: 3rem;
857
857
  z-index: 40;
@@ -881,7 +881,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
881
881
  `:H`
882
882
  right: 1rem;
883
883
  `}
884
- `,Gc=V.button`
884
+ `,$c=V.button`
885
885
  width: 2.35rem;
886
886
  height: 2.35rem;
887
887
  border: 0;
@@ -936,16 +936,16 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
936
936
  width: 1.25em;
937
937
  height: 1.25em;
938
938
  }
939
- `,Kc=V.div`
939
+ `,el=V.div`
940
940
  display: flex;
941
941
  flex-direction: column;
942
942
  gap: 0.25rem;
943
- `,qc=V.div`
943
+ `,tl=V.div`
944
944
  width: 100%;
945
945
  height: 1px;
946
946
  margin: 0.25rem 0;
947
947
  background: rgba(15, 23, 42, 0.14);
948
- `,Jc=V.aside`
948
+ `,nl=V.aside`
949
949
  position: absolute;
950
950
  top: 3rem;
951
951
  bottom: 1rem;
@@ -1000,7 +1000,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1000
1000
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.42);
1001
1001
  }
1002
1002
 
1003
- ${Q} ${is} {
1003
+ ${Q} ${fs} {
1004
1004
  background: ${$.darkPanelHeader} !important;
1005
1005
  border-color: ${$.darkBorder} !important;
1006
1006
  color: ${$.darkText} !important;
@@ -1009,11 +1009,11 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1009
1009
  inset 0 1px 0 0 ${$.darkBorder} !important;
1010
1010
  }
1011
1011
 
1012
- ${Q} ${as} {
1012
+ ${Q} ${ps} {
1013
1013
  color: ${$.darkText} !important;
1014
1014
  }
1015
1015
 
1016
- ${Q} ${as}:hover {
1016
+ ${Q} ${ps}:hover {
1017
1017
  background: ${$.darkHover} !important;
1018
1018
  color: #fff !important;
1019
1019
  }
@@ -1230,13 +1230,13 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1230
1230
  min-width: 0;
1231
1231
  transform: translateY(${e=>e.$open?`0`:`0.75rem`});
1232
1232
  }
1233
- `,Yc=V.div`
1233
+ `,rl=V.div`
1234
1234
  display: flex;
1235
1235
  flex: 1;
1236
1236
  min-width: 0;
1237
1237
  height: 100%;
1238
1238
  overflow: hidden;
1239
- `,Xc=V.div`
1239
+ `,il=V.div`
1240
1240
  display: flex;
1241
1241
  flex-direction: column;
1242
1242
  flex: 1;
@@ -1245,16 +1245,16 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1245
1245
  max-width: 100%;
1246
1246
  min-width: 0;
1247
1247
  overflow: hidden;
1248
- `,Zc=V.header`
1248
+ `,al=V.header`
1249
1249
  //box-shadow: 0 3px 2px 0 rgba(0, 0, 0, 0.04), 0 1px 0 0 rgba(0, 0, 0, 0.17);
1250
1250
  z-index: 200;
1251
- `,Qc=V.div`
1251
+ `,ol=V.div`
1252
1252
  background: #fff;
1253
- `,$c=V.div`
1253
+ `,sl=V.div`
1254
1254
  display: flex;
1255
1255
  flex: 1 1 0;
1256
1256
  min-height: 0;
1257
- `,el=V.div`
1257
+ `,cl=V.div`
1258
1258
  background: #fff;
1259
1259
  display: flex;
1260
1260
  flex-direction: column;
@@ -1273,7 +1273,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1273
1273
  `;case`unmounted`:case`exited`:return H`
1274
1274
  max-width: 0;
1275
1275
  `}}}
1276
- `,tl=V.div`
1276
+ `,ll=V.div`
1277
1277
  flex: 1 1 0;
1278
1278
  background: #e3e7f0;
1279
1279
  // background: #efefef;
@@ -1292,7 +1292,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1292
1292
  > * {
1293
1293
  min-width: 0;
1294
1294
  }
1295
- `,nl=V.div`
1295
+ `,ul=V.div`
1296
1296
  background: #fff;
1297
1297
  display: flex;
1298
1298
  flex-direction: column;
@@ -1308,7 +1308,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1308
1308
  `;case`unmounted`:case`exited`:return H`
1309
1309
  max-width: 0;
1310
1310
  `}}}
1311
- `,rl=V.div`
1311
+ `,dl=V.div`
1312
1312
  display: flex;
1313
1313
  flex: 1;
1314
1314
  height: 100%;
@@ -1318,22 +1318,22 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1318
1318
 
1319
1319
  ${e=>{switch(e.$menu){case`top`:return H`
1320
1320
  flex-direction: column;
1321
- ${il} {
1321
+ ${fl} {
1322
1322
  flex-direction: column;
1323
1323
  }
1324
1324
  `;case`left`:return H`
1325
1325
  flex-direction: row;
1326
- ${il} {
1326
+ ${fl} {
1327
1327
  flex-direction: row;
1328
1328
  }
1329
1329
  `;default:case`bottom`:return H`
1330
1330
  flex-direction: column-reverse;
1331
- ${il} {
1331
+ ${fl} {
1332
1332
  flex-direction: column;
1333
1333
  }
1334
1334
  `;case`right`:return H`
1335
1335
  flex-direction: row-reverse;
1336
- ${il} {
1336
+ ${fl} {
1337
1337
  flex-direction: row;
1338
1338
  }
1339
1339
  `}}}
@@ -1374,7 +1374,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1374
1374
  font-size: 1.5em;
1375
1375
  color: #999;
1376
1376
  }
1377
- `;const il=V.div`
1377
+ `;const fl=V.div`
1378
1378
  display: flex;
1379
1379
  box-shadow:
1380
1380
  0 -3px 2px 0 rgba(0, 0, 0, 0.04),
@@ -1383,23 +1383,23 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1383
1383
  ${e=>!e.$open&&(e.$position===`top`||e.$position===`bottom`)?H`
1384
1384
  display: none;
1385
1385
  `:``}
1386
- `,al=V.div`
1386
+ `,pl=V.div`
1387
1387
  display: flex;
1388
1388
  flex-direction: column;
1389
1389
  flex: 1;
1390
1390
  min-width: 0;
1391
1391
  overflow: hidden;
1392
- `;function ol(e){let t=e?.resource;return t?.source?.type||t?.type||null}const sl=Ee(function(e){let t=q(),n=ai(),r=bi(),i=ba(),{vault:a}=A(ze),o=a||void 0,s=qe(e=>e.iiif),{loading:c,state:l,leftPanels:u,centerPanels:d,rightPanels:f,modals:p=[],actions:m}=i,h=e.isLoading||!1,g=N(()=>({rootResource:r,vault:o,app:t,layoutState:l,appState:n}),[r,o,t,l,n,s]),_=N(()=>zc(u,g,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}).filter(e=>!e.focusedMode?.hide),[u,g]),y=N(()=>zc(d,g,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[d,g]),b=N(()=>zc(f,g,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}).filter(e=>!e.focusedMode?.hide),[f,g]),x=N(()=>zc(p,g,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[p,g]),S=N(()=>({...i,leftPanels:_,centerPanels:y,rightPanels:b,modals:x}),[i,_,y,b,x]),C=_.find(e=>e.id===l.leftPanel.current),w=b.find(e=>e.id===l.rightPanel.current),T=y.find(e=>e.id===l.centerPanel.current),E=x.find(e=>e.id===l.modal.current),te=l.pinnedRightPanel.pinned?b.find(e=>e.id===l.pinnedRightPanel.current):void 0,ne=w&&(te?.id!==w.id||!gt(l.pinnedRightPanel.state,l.rightPanel.state)),re=N(()=>({rootResource:r,vault:o,app:t,layoutState:l,appState:n,actions:m}),[r,o,t,l,n,m]),ie=e=>{e.focusedMode?.onSelect?.(re)},ae=!C||C.focusedMode?.closeOnMainPanelClick!==!1,oe=N(()=>(i.background||[]).map((e,t)=>L(xe,{children:e.render()},t)),[i.background]);M(()=>{b.length&&m.rightPanel.change({id:b[0].id}),_.length&&m.leftPanel.change({id:_[0].id}),y.length&&m.centerPanel.change({id:y[0].id}),m.leftPanel.close(),m.rightPanel.close()},[]),M(()=>{if(T&&T.onMount)return T.onMount(l.centerPanel.state||T.defaultState||{},{...S,current:m.centerPanel,vault:o},n)},[l.centerPanel.current,T?.id]),M(()=>{if(!l.leftPanel.open||!l.leftPanel.current)return;let e=_.find(e=>e.id===l.leftPanel.current);e?.focusedMode?.onSelect&&ie(e)},[l.leftPanel.open,l.leftPanel.current,X(_)]),M(()=>{if(l.leftPanel.current&&!C){let e=Bc(_,l.leftPanel.current);e?m.leftPanel.change({id:e}):m.leftPanel.close()}if(l.centerPanel.current&&!T){let e=Bc(y,l.centerPanel.current);e?m.centerPanel.change({id:e}):m.centerPanel.close()}if(l.rightPanel.current&&!w){let e=Bc(b,l.rightPanel.current);e?m.rightPanel.change({id:e}):m.rightPanel.close()}if(l.modal.current&&!E){let e=Bc(x,l.modal.current);e?m.modal.change({id:e}):m.modal.close()}},[l.leftPanel.current,l.centerPanel.current,l.rightPanel.current,l.modal.current,C?.id,T?.id,w?.id,E?.id,X(_),X(y),X(b),X(x)]),Sc(`layout.edit`,e=>{ol(e)===`Canvas`&&!l.rightPanel.open||(b.find(e=>e.id===`@manifest-editor/editor`)?m.rightPanel.open({id:`@manifest-editor/editor`,stacked:!0}):w&&m.rightPanel.open())},[X(b),w?.id,l.rightPanel.open]);let D=`4.5rem`,se=`${Jo({options:C?.options,fallback:340})}px`,ce=`${Jo({options:w?.options,fallback:420})}px`,le={"--manifest-editor-layout-left-sidebar-small":D,"--manifest-editor-layout-left-sidebar-large":l.leftPanel.open?`calc(${D} + ${se})`:D,"--manifest-editor-layout-right-sidebar-small":D,"--manifest-editor-layout-right-sidebar-large":l.rightPanel.open?`calc(${D} + ${ce})`:D};if(M(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=Object.keys(le).map(t=>[t,e.style.getPropertyValue(t)]);for(let[t,n]of Object.entries(le))e.style.setProperty(t,n);return()=>{for(let[n,r]of t)r?e.style.setProperty(n,r):e.style.removeProperty(n)}},[se,ce,l.leftPanel.open,l.rightPanel.open]),c)return null;let ue=(e,t,n)=>{if(!t.length)return null;let r=e===`left`?m.leftPanel:m.rightPanel;return L(Wc,{$side:e,"aria-label":`${e} panels`,children:t.map(t=>R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{asChild:!0,children:L(Gc,{type:`button`,"aria-label":t.label,"data-selected":n===t.id,onClick:()=>{n===t.id?r.toggle():r.open({id:t.id})},children:t.icon||t.label.slice(0,1)})}),L(v,{children:t.label})]},t.id))})},de=()=>!y.length&&!_.length?null:R(Wc,{$side:`left`,"aria-label":`Main and left panels`,children:[y.length?L(Kc,{"aria-label":`Main panels`,children:y.filter(e=>!e.focusedMode?.hide).map(e=>R(he,{placement:`right`,children:[L(ge,{asChild:!0,children:L(Gc,{type:`button`,"aria-label":e.label,"data-selected":l.centerPanel.current===e.id,onClick:()=>{m.centerPanel.open({id:e.id}),m.leftPanel.close(),m.rightPanel.close(),ie(e)},children:e.icon||e.label.slice(0,1)})}),L(v,{children:e.label})]},e.id))}):null,y.length&&_.length?L(qc,{}):null,_.length?L(Kc,{"aria-label":`Left panels`,children:_.map(e=>R(he,{placement:`right`,children:[L(ge,{asChild:!0,children:L(Gc,{type:`button`,"aria-label":e.label,"data-selected":l.leftPanel.current===e.id,onClick:()=>{l.leftPanel.current===e.id?m.leftPanel.toggle():m.leftPanel.open({id:e.id})},children:e.icon||e.label.slice(0,1)})}),L(v,{children:e.label})]},e.id))}):null]}),fe=()=>!E||l.modal.open===!1?null:L(ee,{title:E.label,onClose:()=>m.modal.close(),children:Yo(E.render(l.modal.state||E.defaultState||{},{...S,current:m.modal,vault:o},n))}),pe=()=>R(rl,{$menu:e.centerPanelMenuPosition||`top`,children:[e.centerPanelMenu?L(il,{$open:l.centerPanel.open,$position:e.centerPanelMenuPosition||`top`,children:e.centerPanelMenu}):null,L(al,{children:L(ot,{resetKeys:[T?.id],FallbackComponent:Ko,children:h?L(Uc,{children:L(Mc,{stroke:`rgba(0,0,0,.3)`,fontSize:`2em`})}):l.centerPanel.open&&T?Yo(T.render(l.centerPanel.state||T.defaultState||{},{...S,current:m.centerPanel,vault:o},n)):null})})]}),me=()=>L(Yc,{children:h?L(al,{children:L(Pc,{})}):R(I,{children:[e.leftPanelMenu?L(il,{$open:l.leftPanel.open,$position:e.leftPanelMenuPosition||`bottom`,children:e.leftPanelMenu}):null,L(al,{children:C?L(ls,{isLeft:!0,panel:C,state:l.leftPanel,actions:m.leftPanel}):null})]})}),_e=()=>L(Yc,{children:h?L(al,{children:L(Pc,{})}):R(I,{children:[e.rightPanelMenu?L(il,{$open:l.rightPanel.open,$position:e.rightPanelMenuPosition||`bottom`,children:e.rightPanelMenu}):null,R(al,{children:[ne?L(ls,{panel:w,state:l.rightPanel,actions:m.rightPanel,pinActions:m.pinnedRightPanel,available:b}):null,te?L(ls,{panel:te,state:l.pinnedRightPanel,actions:m.pinnedRightPanel,close:m.rightPanel.close}):null]})]})});return L(ha.Provider,{value:`focused`,children:R(Xc,{id:e.htmlId||`manifest-editor-container`,className:`manifest-editor ${e.className||``}`,"data-layout-mode":`focused`,style:le,children:[e.hideHeader?null:R(Zc,{children:[e.header||null,e.menu?L(`menu`,{children:e.menu}):null]}),R(Vc,{children:[L(Hc,{onClick:()=>{ae&&m.leftPanel.close()},children:pe()}),de(),ue(`right`,b,l.rightPanel.current),_.length>0?L(Jc,{$side:`left`,$open:l.leftPanel.open,style:{width:se,minWidth:C?.options?.minWidth,maxWidth:C?.options?.maxWidth},children:me()}):null,b.length>0?L(Jc,{$side:`right`,$open:l.rightPanel.open,style:{width:ce,minWidth:w?.options?.minWidth,maxWidth:w?.options?.maxWidth},children:_e()}):null]}),L(Qc,{children:e.footer||null}),L(`div`,{className:`hidden`,children:oe}),L(so,{}),L(co,{}),L(I,{children:fe()})]})})}),cl=V.div`
1392
+ `;function ml(e){let t=e?.resource;return t?.source?.type||t?.type||null}const hl=Ee(function(e){let t=q(),n=pi(),r=Oi(),i=Oa(),{vault:a}=A(ze),o=a||void 0,s=qe(e=>e.iiif),{loading:c,state:l,leftPanels:u,centerPanels:d,rightPanels:f,modals:p=[],actions:m}=i,h=e.isLoading||!1,g=N(()=>({rootResource:r,vault:o,app:t,layoutState:l,appState:n}),[r,o,t,l,n,s]),_=N(()=>qc(u,g,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}).filter(e=>!e.focusedMode?.hide),[u,g]),y=N(()=>qc(d,g,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[d,g]),b=N(()=>qc(f,g,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}).filter(e=>!e.focusedMode?.hide),[f,g]),x=N(()=>qc(p,g,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[p,g]),S=N(()=>({...i,leftPanels:_,centerPanels:y,rightPanels:b,modals:x}),[i,_,y,b,x]),C=_.find(e=>e.id===l.leftPanel.current),w=b.find(e=>e.id===l.rightPanel.current),T=y.find(e=>e.id===l.centerPanel.current),E=x.find(e=>e.id===l.modal.current),te=l.pinnedRightPanel.pinned?b.find(e=>e.id===l.pinnedRightPanel.current):void 0,ne=w&&(te?.id!==w.id||!gt(l.pinnedRightPanel.state,l.rightPanel.state)),re=N(()=>({rootResource:r,vault:o,app:t,layoutState:l,appState:n,actions:m}),[r,o,t,l,n,m]),ie=e=>{e.focusedMode?.onSelect?.(re)},ae=!C||C.focusedMode?.closeOnMainPanelClick!==!1,oe=N(()=>(i.background||[]).map((e,t)=>L(xe,{children:e.render()},t)),[i.background]);M(()=>{b.length&&m.rightPanel.change({id:b[0].id}),_.length&&m.leftPanel.change({id:_[0].id}),y.length&&m.centerPanel.change({id:y[0].id}),m.leftPanel.close(),m.rightPanel.close()},[]),M(()=>{if(T&&T.onMount)return T.onMount(l.centerPanel.state||T.defaultState||{},{...S,current:m.centerPanel,vault:o},n)},[l.centerPanel.current,T?.id]),M(()=>{if(!l.leftPanel.open||!l.leftPanel.current)return;let e=_.find(e=>e.id===l.leftPanel.current);e?.focusedMode?.onSelect&&ie(e)},[l.leftPanel.open,l.leftPanel.current,X(_)]),M(()=>{if(l.leftPanel.current&&!C){let e=Jc(_,l.leftPanel.current);e?m.leftPanel.change({id:e}):m.leftPanel.close()}if(l.centerPanel.current&&!T){let e=Jc(y,l.centerPanel.current);e?m.centerPanel.change({id:e}):m.centerPanel.close()}if(l.rightPanel.current&&!w){let e=Jc(b,l.rightPanel.current);e?m.rightPanel.change({id:e}):m.rightPanel.close()}if(l.modal.current&&!E){let e=Jc(x,l.modal.current);e?m.modal.change({id:e}):m.modal.close()}},[l.leftPanel.current,l.centerPanel.current,l.rightPanel.current,l.modal.current,C?.id,T?.id,w?.id,E?.id,X(_),X(y),X(b),X(x)]),Ac(`layout.edit`,e=>{ml(e)===`Canvas`&&!l.rightPanel.open||(b.find(e=>e.id===`@manifest-editor/editor`)?m.rightPanel.open({id:`@manifest-editor/editor`,stacked:!0}):w&&m.rightPanel.open())},[X(b),w?.id,l.rightPanel.open]);let D=`4.5rem`,se=`${ns({options:C?.options,fallback:340})}px`,ce=`${ns({options:w?.options,fallback:420})}px`,le={"--manifest-editor-layout-left-sidebar-small":D,"--manifest-editor-layout-left-sidebar-large":l.leftPanel.open?`calc(${D} + ${se})`:D,"--manifest-editor-layout-right-sidebar-small":D,"--manifest-editor-layout-right-sidebar-large":l.rightPanel.open?`calc(${D} + ${ce})`:D};if(M(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=Object.keys(le).map(t=>[t,e.style.getPropertyValue(t)]);for(let[t,n]of Object.entries(le))e.style.setProperty(t,n);return()=>{for(let[n,r]of t)r?e.style.setProperty(n,r):e.style.removeProperty(n)}},[se,ce,l.leftPanel.open,l.rightPanel.open]),c)return null;let ue=(e,t,n)=>{if(!t.length)return null;let r=e===`left`?m.leftPanel:m.rightPanel;return L(Qc,{$side:e,"aria-label":`${e} panels`,children:t.map(t=>R(he,{placement:e===`left`?`right`:`left`,children:[L(ge,{asChild:!0,children:L($c,{type:`button`,"aria-label":t.label,"data-selected":n===t.id,onClick:()=>{n===t.id?r.toggle():r.open({id:t.id})},children:t.icon||t.label.slice(0,1)})}),L(v,{children:t.label})]},t.id))})},de=()=>!y.length&&!_.length?null:R(Qc,{$side:`left`,"aria-label":`Main and left panels`,children:[y.length?L(el,{"aria-label":`Main panels`,children:y.filter(e=>!e.focusedMode?.hide).map(e=>R(he,{placement:`right`,children:[L(ge,{asChild:!0,children:L($c,{type:`button`,"aria-label":e.label,"data-selected":l.centerPanel.current===e.id,onClick:()=>{m.centerPanel.open({id:e.id}),m.leftPanel.close(),m.rightPanel.close(),ie(e)},children:e.icon||e.label.slice(0,1)})}),L(v,{children:e.label})]},e.id))}):null,y.length&&_.length?L(tl,{}):null,_.length?L(el,{"aria-label":`Left panels`,children:_.map(e=>R(he,{placement:`right`,children:[L(ge,{asChild:!0,children:L($c,{type:`button`,"aria-label":e.label,"data-selected":l.leftPanel.current===e.id,onClick:()=>{l.leftPanel.current===e.id?m.leftPanel.toggle():m.leftPanel.open({id:e.id})},children:e.icon||e.label.slice(0,1)})}),L(v,{children:e.label})]},e.id))}):null]}),fe=()=>!E||l.modal.open===!1?null:L(ee,{title:E.label,onClose:()=>m.modal.close(),children:rs(E.render(l.modal.state||E.defaultState||{},{...S,current:m.modal,vault:o},n))}),pe=()=>R(dl,{$menu:e.centerPanelMenuPosition||`top`,children:[e.centerPanelMenu?L(fl,{$open:l.centerPanel.open,$position:e.centerPanelMenuPosition||`top`,children:e.centerPanelMenu}):null,L(pl,{children:L(ot,{resetKeys:[T?.id],FallbackComponent:es,children:h?L(Zc,{children:L(Bc,{stroke:`rgba(0,0,0,.3)`,fontSize:`2em`})}):l.centerPanel.open&&T?rs(T.render(l.centerPanel.state||T.defaultState||{},{...S,current:m.centerPanel,vault:o},n)):null})})]}),me=()=>L(rl,{children:h?L(pl,{children:L(Hc,{})}):R(I,{children:[e.leftPanelMenu?L(fl,{$open:l.leftPanel.open,$position:e.leftPanelMenuPosition||`bottom`,children:e.leftPanelMenu}):null,L(pl,{children:C?L(_s,{isLeft:!0,panel:C,state:l.leftPanel,actions:m.leftPanel}):null})]})}),_e=()=>L(rl,{children:h?L(pl,{children:L(Hc,{})}):R(I,{children:[e.rightPanelMenu?L(fl,{$open:l.rightPanel.open,$position:e.rightPanelMenuPosition||`bottom`,children:e.rightPanelMenu}):null,R(pl,{children:[ne?L(_s,{panel:w,state:l.rightPanel,actions:m.rightPanel,pinActions:m.pinnedRightPanel,available:b}):null,te?L(_s,{panel:te,state:l.pinnedRightPanel,actions:m.pinnedRightPanel,close:m.rightPanel.close}):null]})]})});return L(Ca.Provider,{value:`focused`,children:R(il,{id:e.htmlId||`manifest-editor-container`,className:`manifest-editor ${e.className||``}`,"data-layout-mode":`focused`,style:le,children:[e.hideHeader?null:R(al,{children:[e.header||null,e.menu?L(`menu`,{children:e.menu}):null]}),R(Yc,{children:[L(Xc,{onClick:()=>{ae&&m.leftPanel.close()},children:pe()}),de(),ue(`right`,b,l.rightPanel.current),_.length>0?L(nl,{$side:`left`,$open:l.leftPanel.open,style:{width:se,minWidth:C?.options?.minWidth,maxWidth:C?.options?.maxWidth},children:me()}):null,b.length>0?L(nl,{$side:`right`,$open:l.rightPanel.open,style:{width:ce,minWidth:w?.options?.minWidth,maxWidth:w?.options?.maxWidth},children:_e()}):null]}),L(ol,{children:e.footer||null}),L(`div`,{className:`hidden`,children:oe}),L(go,{}),L(_o,{}),L(I,{children:fe()})]})})}),gl=V.div`
1393
1393
  position: relative;
1394
1394
  display: flex;
1395
1395
  flex: 1;
1396
1396
  overflow: hidden;
1397
1397
  flex-direction: column;
1398
- `,ll=V.div`
1398
+ `,_l=V.div`
1399
1399
  flex: 1;
1400
1400
  position: relative;
1401
1401
  z-index: 7;
1402
- `,ul=V.div`
1402
+ `,vl=V.div`
1403
1403
  display: flex;
1404
1404
  justify-content: space-around;
1405
1405
  width: 100%;
@@ -1407,7 +1407,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1407
1407
  border-top: 1px solid #cbcbcb;
1408
1408
  padding: 0.5em;
1409
1409
  height: 3.4rem;
1410
- `,dl=V.button`
1410
+ `,yl=V.button`
1411
1411
  //background: red;
1412
1412
  padding: 0.5em 1em;
1413
1413
  width: 32%;
@@ -1415,7 +1415,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1415
1415
  border-radius: 5px;
1416
1416
  border: none;
1417
1417
  background: #ffffff;
1418
- `,fl=V.button`
1418
+ `,bl=V.button`
1419
1419
  padding: 0.5em 1em;
1420
1420
  width: 32%;
1421
1421
 
@@ -1424,12 +1424,12 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1424
1424
  background: #5e59c2;
1425
1425
  border: 1px solid rgba(0, 0, 0, 0.21);
1426
1426
  color: #ffffff;
1427
- `,pl=V.div`
1427
+ `,xl=V.div`
1428
1428
  position: relative;
1429
1429
  width: 32%;
1430
1430
  margin: 0 0.75em;
1431
1431
  z-index: 9;
1432
- `,ml=V.button`
1432
+ `,Sl=V.button`
1433
1433
  padding: 0.4em 1em 0.65em;
1434
1434
  position: absolute;
1435
1435
  width: 100%;
@@ -1448,7 +1448,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1448
1448
  margin: auto;
1449
1449
  font-size: 1.8em;
1450
1450
  }
1451
- `,hl=V.div`
1451
+ `,Cl=V.div`
1452
1452
  background: #fff;
1453
1453
  display: flex;
1454
1454
  position: absolute;
@@ -1472,13 +1472,13 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1472
1472
  transform: translateY(0);
1473
1473
  `}
1474
1474
 
1475
- ${is} {
1475
+ ${fs} {
1476
1476
  box-shadow: none;
1477
1477
  padding-left: 0.5em;
1478
1478
  padding-right: 0.5em;
1479
1479
  font-size: 1.1em;
1480
1480
  }
1481
- `,gl=V.div`
1481
+ `,wl=V.div`
1482
1482
  position: absolute;
1483
1483
  transform: translateX(-100%);
1484
1484
  background: #fff;
@@ -1491,7 +1491,7 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1491
1491
  ${e=>e.$open&&H`
1492
1492
  transform: translateX(0);
1493
1493
  `}
1494
- `,_l=V.div`
1494
+ `,Tl=V.div`
1495
1495
  background: rgba(0, 0, 0, 0.4);
1496
1496
  pointer-events: none;
1497
1497
  position: absolute;
@@ -1507,6 +1507,6 @@ import{ActionButton as e,ArrowRightIcon as t,BackIcon as n,BackgroundActionMenuB
1507
1507
  pointer-events: visible;
1508
1508
  opacity: 1;
1509
1509
  `}
1510
- `,vl=Ee(function(e){if(e.layoutMode===`focused`)return L(sl,{...e});let t=q(),n=ai(),r=bi(),i=ba(),{vault:a}=A(ze),o=a||void 0,s=qe(e=>e.iiif),c=P(null),l=P(null),{loading:u,state:d,leftPanels:f,centerPanels:p,rightPanels:m,modals:h=[],actions:g}=i,_=N(()=>({rootResource:r,vault:o,app:t,layoutState:d,appState:n}),[r,o,t,d,n,s]),v=N(()=>zc(f,_,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[f,_]),y=N(()=>zc(p,_,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[p,_]),b=N(()=>zc(m,_,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[m,_]),x=N(()=>zc(h,_,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[h,_]),S=N(()=>({...i,leftPanels:v,centerPanels:y,rightPanels:b,modals:x}),[i,v,y,b,x]),C=v.find(e=>e.id===d.leftPanel.current),w=b.find(e=>e.id===d.rightPanel.current),T=y.find(e=>e.id===d.centerPanel.current),E=x.find(e=>e.id===d.modal.current),te=d.pinnedRightPanel.pinned?b.find(e=>e.id===d.pinnedRightPanel.current):void 0,[ne]=Cc([`(max-width: 1020px)`]),ie=e.isLoading||!1,ae=N(()=>(i.background||[]).map((e,t)=>L(xe,{children:e.render()},t)),[i.background]),oe=Rc(`left-panel/${C?.id}`,{left:!0,marginLeft:60,minWidthPx:C?.options?.minWidth||200,maxWidthPx:C?.options?.maxWidth||720,loading:u}),D=Rc(`right-panel/${w?.id}`,{left:!1,minWidthPx:w?.options?.minWidth||320,maxWidthPx:w?.options?.maxWidth||720,loading:u}),se=w&&(te?.id!==w.id||!gt(d.pinnedRightPanel.state,d.rightPanel.state)),ce=oe.widthB===`auto`?void 0:()=>oe.setWidths({widthA:`auto`,widthB:Jo({options:C?.options,fallback:320})}),le=D.widthB===`auto`?void 0:()=>D.setWidths({widthA:`auto`,widthB:Jo({options:w?.options,fallback:320})});if(M(()=>{ne&&d.leftPanel.open&&d.rightPanel.open&&(g.leftPanel.close(),g.rightPanel.close())},[ne]),M(()=>{if(T&&T.onMount)return T.onMount(d.centerPanel.state||T.defaultState||{},{...S,current:g.centerPanel,vault:o},n)},[d.centerPanel.current,T?.id]),M(()=>{if(d.leftPanel.current&&!C){let e=Bc(v,d.leftPanel.current);e?g.leftPanel.change({id:e}):g.leftPanel.close()}if(d.centerPanel.current&&!T){let e=Bc(y,d.centerPanel.current);e?g.centerPanel.change({id:e}):g.centerPanel.close()}if(d.rightPanel.current&&!w){let e=Bc(b,d.rightPanel.current);e?g.rightPanel.change({id:e}):g.rightPanel.close()}if(d.modal.current&&!E){let e=Bc(x,d.modal.current);e?g.modal.change({id:e}):g.modal.close()}},[d.leftPanel.current,d.centerPanel.current,d.rightPanel.current,d.modal.current,C?.id,T?.id,w?.id,E?.id,X(v),X(y),X(b),X(x)]),M(()=>{b.length&&g.rightPanel.change({id:b[0].id}),v.length&&g.leftPanel.change({id:v[0].id}),y.length&&g.centerPanel.change({id:y[0].id})},[]),u)return null;let ue=t=>L(rl,{$menu:e.leftPanelMenuPosition||`bottom`,ref:oe.refs.resizableDiv,className:[`manifest-editor`,t?`transition transition-${t}`:``].join(` `),style:{width:d.leftPanel.open||t!==`exited`?oe.widthB:void 0,minWidth:C?.options?.minWidth},children:ie?L(al,{children:L(Pc,{})}):R(I,{children:[e.leftPanelMenu?L(il,{$open:d.leftPanel.open&&t!==`exited`,$position:e.leftPanelMenuPosition||`bottom`,children:e.leftPanelMenu}):null,L(al,{children:d.leftPanel.open||t!==`exited`?L(I,{children:C?L(ls,{isLeft:!0,noHeader:!0,transition:t,panel:C,state:d.leftPanel,actions:g.leftPanel}):null}):null})]})}),de=()=>!E||d.modal.open===!1?null:L(ee,{title:E.label,onClose:()=>g.modal.close(),children:Yo(E.render(d.modal.state||E.defaultState||{},{...S,current:g.modal,vault:o},n))}),fe=()=>R(rl,{$menu:e.centerPanelMenuPosition||`top`,children:[e.centerPanelMenu?L(il,{$open:d.centerPanel.open,$position:e.centerPanelMenuPosition||`top`,children:e.centerPanelMenu}):null,L(al,{children:L(ot,{resetKeys:[T?.id],FallbackComponent:Ko,children:ie?L(`div`,{style:{display:`flex`,flex:1,justifyContent:`center`,alignItems:`center`},children:L(Mc,{stroke:`rgba(0,0,0,.3)`,fontSize:`2em`})}):d.centerPanel.open&&T?Yo(T.render(d.centerPanel.state||T.defaultState||{},{...S,current:g.centerPanel,vault:o},n)):null})})]}),pe=t=>L(rl,{$menu:e.rightPanelMenuPosition||`bottom`,ref:D.refs.resizableDiv,className:t?`transition transition-${t}`:``,style:{width:d.rightPanel.open||t!==`exited`?D.widthB:void 0,minWidth:w?.options?.minWidth},children:ie?L(al,{children:L(Pc,{})}):R(I,{children:[e.rightPanelMenu?L(il,{$open:d.rightPanel.open,$position:e.rightPanelMenuPosition||`bottom`,children:e.rightPanelMenu}):null,L(al,{children:d.rightPanel.open||t!==`exited`?R(I,{children:[se?L(ls,{panel:w,state:d.rightPanel,actions:g.rightPanel,pinActions:g.pinnedRightPanel,available:b}):null,te?L(ls,{panel:te,state:d.pinnedRightPanel,actions:g.pinnedRightPanel,close:g.rightPanel.close}):null]}):null})]})});return ne?R(Xc,{children:[e.hideHeader?null:R(Zc,{children:[e.header||null,e.menu?L(`menu`,{children:e.menu}):null]}),L($c,{children:R(cl,{children:[L(ll,{children:fe()}),R(ul,{children:[v.length>0?L(dl,{onClick:g.leftPanel.toggle,children:C?.label}):null,b.length>0?L(pl,{children:R(ml,{onClick:g.rightPanel.toggle,children:[L(gi,{rotate:180}),w?.label]})}):null,L(fl,{children:`Preview`})]}),b.length>0?L(hl,{$open:d.rightPanel.open,children:pe()}):null,v.length>0?L(gl,{$open:d.leftPanel.open,children:ue()}):null,v.length>0||b.length>0?L(_l,{$open:d.leftPanel.open||d.rightPanel.open,onClick:()=>{g.leftPanel.close(),g.rightPanel.close()}}):null]})})]}):R(Xc,{id:e.htmlId||`manifest-editor-container`,className:`manifest-editor ${e.className||``}`,children:[e.hideHeader?null:R(Zc,{children:[e.header||null,e.menu?L(`menu`,{children:e.menu}):null]}),R($c,{ref:e=>{oe.refs.container.current=e,D.refs.container.current=e},children:[v.length>0?L(re,{current:d.leftPanel.current,items:v.map(e=>({id:e.id,label:e.label,icon:e.icon,divide:e.divide,separator:e.separator,onClick:()=>{d.leftPanel.current===e.id?g.leftPanel.toggle():g.leftPanel.change({id:e.id})}})),open:d.leftPanel.open}):null,v.length>0?L(ht,{nodeRef:c,in:d.leftPanel.open,timeout:400,unmountOnExit:!1,children:e=>R(I,{children:[L(el,{ref:c,$width:oe.widthB,$state:e,$motion:!0,children:ue(e)}),L(jc,{ref:oe.refs.resizer,reset:ce,dir:`left`,transition:e,open:d.leftPanel.open||e!==`exited`,actions:g.leftPanel})]})}):null,L(tl,{children:fe()}),b.length>0?L(ht,{nodeRef:l,in:d.rightPanel.open,timeout:400,unmountOnExit:!1,children:e=>R(I,{children:[L(jc,{ref:D.refs.resizer,dir:`right`,reset:le,open:d.rightPanel.open,actions:g.rightPanel}),L(nl,{ref:l,$width:D.widthB,$state:e,$motion:!0,children:pe(e)})]})}):null]}),L(Qc,{children:e.footer||null}),L(`div`,{className:`hidden`,children:ae}),L(so,{}),L(co,{}),L(I,{children:de()})]})});function yl(e,t){function n(){t({type:`popStack`,panel:e,payload:void 0})}function r(n){t({type:`change`,panel:e,payload:n})}function i(n){t({type:`open`,panel:e,payload:n})}function a(){t({type:`close`,panel:e,payload:void 0})}function o(){t({type:`toggle`,panel:e,payload:void 0})}function s(){t({type:`minimise`,panel:e,payload:void 0})}function c(n){t({type:`maximise`,panel:e,payload:n})}function l(n){t({type:`setCustomWidth`,panel:e,payload:n})}function u(){t({type:`resetSize`,panel:e,payload:void 0})}function d(n){t({type:`pin`,panel:e,payload:n})}function f(){t({type:`unpin`,panel:e,payload:void 0})}return N(()=>({popStack:n,change:r,open:i,close:a,toggle:o,minimise:s,maximise:c,setCustomWidth:l,resetSize:u,pin:d,unpin:f}),[])}function bl(e,t){if(t.payload&&t.payload.stacked){if(e.current){let n=e.stack[e.stack.length-1];if(n&&n.id===e.current)return;t.payload.unique&&(e.stack=e.stack.filter(t=>t.id!==e.current)),e.stack.push({id:e.current,state:e.state?{...Ze(e.state)}:{}})}}else e.stack=[]}function xl(e,t){switch(t.type){case`popStack`:if(e.stack.length){let t=e.stack[e.stack.length-1];t&&(e.current=t.id,e.state=t.state),e.stack=e.stack.slice(0,-1)}break;case`change`:t.payload.id!==e.current&&bl(e,t),e.state=t.payload.state,e.current=t.payload.id;break;case`close`:e.open=!1;break;case`open`:e.open=!0,t.payload&&(t.payload.id!==e.current&&bl(e,t),e.state=t.payload.state,e.current=t.payload.id);break;case`toggle`:e.open=!e.open;break;case`maximise`:e.minimised=!1,t.payload&&(e.state=t.payload.state,e.current=t.payload.id);break;case`minimise`:e.minimised=!0;break;case`setCustomWidth`:e.customWidth=t.payload;break;case`resetSize`:e.customWidth=void 0}if(qo(e))switch(t.type){case`pin`:e.pinned=!0,e.state=t.payload.state,e.current=t.payload.id;break;case`unpin`:e.pinned=!1,e.state=void 0;break}}const Sl=Qe((e,t)=>{switch(t.panel){case`centerPanel`:xl(e.centerPanel,t);break;case`leftPanel`:xl(e.leftPanel,t);break;case`rightPanel`:xl(e.rightPanel,t);break;case`modal`:xl(e.modal,t);break;case`pinnedRightPanel`:xl(e.pinnedRightPanel,t);break}});function Cl(){return{customWidth:void 0,minimised:!1,open:!0,current:null,state:null,stack:[]}}function wl(){return{leftPanel:Cl(),centerPanel:Cl(),rightPanel:Cl(),modal:Cl(),pinnedRightPanel:{...Cl(),pinnable:!0,pinned:!1}}}function Tl({className:e,variant:t=`light`}){let n=Ge(),r=z(),{edit:i}=_a(),a=na(),o=ra(),s=n?.items||[],c=n?.viewingDirection===`right-to-left`||n?.viewingDirection===`bottom-to-top`,l=n?.viewingDirection===`top-to-bottom`||n?.viewingDirection===`bottom-to-top`,u=El(a)||o.map(El).find(Boolean)||s[0]?.id||``,d=Math.max(0,s.findIndex(e=>e.id===u)),f=s[d]?.id||``,p=d+1,m=N(()=>s.map((e,t)=>{let n=r.get({id:e.id,type:`Canvas`});return{id:e.id,pageNumber:t+1,labelText:tt(n?.label)||`Page ${t+1}`}}),[s,r]),h=e=>{let t=s.findIndex(t=>t.id===e),r=s[t];!r||!n||i({id:r.id,type:`Canvas`},{parent:{id:n.id,type:`Manifest`},property:`items`,index:t},{forceOpen:!1})};if(!n||s.length<2)return L(`div`,{});let g=s[d-1],_=s[d+1],v=t===`dark`;return R(`nav`,{"aria-label":`Manifest pagination`,className:Al(`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-1`,`focus-within:ring-2 focus-within:ring-me-primary-500/40`,c&&`flex-row-reverse`,v?`border-white/20 bg-white/10 text-white`:`border-me-gray-300 bg-white text-me-gray-900`,e),children:[L(Dl,{ariaLabel:`Previous canvas`,disabled:!g,onClick:()=>g&&h(g.id),dark:v,children:L(Ol,{reverse:c,vertical:l})}),R(`label`,{htmlFor:`manifest-pagination-page-select`,"aria-label":`Page ${p} of ${s.length}`,className:Al(`relative inline-flex min-h-8 cursor-pointer select-none items-center gap-0.5`,`whitespace-nowrap rounded-full border px-2.5 text-xs font-semibold leading-none`,`focus-within:outline-none focus-within:ring-2 focus-within:ring-me-primary-500/40`,v?`border-white/20 bg-white/10 text-white hover:bg-white/15`:`border-me-gray-300 bg-me-gray-100 text-me-gray-900 hover:bg-me-primary-50`),children:[R(`span`,{children:[p,` / `,s.length]}),L(kl,{className:Al(`shrink-0 text-base`,v?`text-white/60`:`text-me-gray-500`)}),L(`select`,{id:`manifest-pagination-page-select`,"aria-label":`Jump to canvas`,value:f,onChange:e=>h(e.target.value),className:`absolute inset-0 cursor-pointer appearance-none border-0 bg-white opacity-0`,children:m.map(e=>R(`option`,{value:e.id,children:[`Page `,e.pageNumber,` - `,e.labelText]},e.id))})]}),L(Dl,{ariaLabel:`Next canvas`,disabled:!_,onClick:()=>_&&h(_.id),dark:v,children:L(Ol,{reverse:!c,vertical:l})})]})}function El(e){let t=e?.resource?.source;return t?.type===`Canvas`?t.id:null}function Dl({ariaLabel:e,children:t,dark:n,disabled:r,onClick:i}){return L(`button`,{type:`button`,"aria-label":e,disabled:r,onClick:i,className:Al(`inline-flex h-8 w-8 items-center justify-center rounded-full border-0 bg-transparent p-0`,`text-lg transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-me-primary-500/50`,n?`text-white hover:bg-white/15 disabled:text-white/40 disabled:hover:bg-transparent`:`text-me-gray-900 hover:bg-me-primary-50 disabled:text-me-gray-500 disabled:hover:bg-transparent`,`disabled:cursor-not-allowed`),children:t})}function Ol({reverse:e,vertical:r}){return L(e?t:n,{"aria-hidden":!0,className:Al(`block`,r&&`rotate-90`)})}function kl(e){return L(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,"aria-hidden":!0,...e,children:L(`path`,{fill:`currentColor`,d:`m7 10l5 5l5-5z`})})}function Al(...e){return e.filter(Boolean).join(` `)}const jl=new WeakMap;function Ml(e,t){let n={port:t,lastActionId:`@genesis`},r=Nl(e);function i(e){t.postMessage(typeof e==`string`?e:JSON.stringify(e))}function a(){i({_id:ar(),_type:`init-response`,_lastActionId:n.lastActionId,data:e.getState()})}function o(e){i({_id:e,_type:`vault-action-rejection`,_lastActionId:n.lastActionId,action:e})}function s(e){let t=Fl(e.data);if(t){if(t._type===`init-request`){a();return}t._type===`vault-action`&&o(t._id)}}return r.targets.add(n),t.addEventListener(`message`,s),t.start(),()=>{t.removeEventListener(`message`,s),r.targets.delete(n),r.targets.size===0&&e.dispatch===r.patchedDispatch&&(e.dispatch=r.originalDispatch,jl.delete(e)),t.close()}}function Nl(e){let t=jl.get(e);if(t)return t;let n=e.dispatch.bind(e),r=new Set,i=(e=>{let t=n(e);for(let t of r)Pl(t,e);return t}),a={originalDispatch:n,patchedDispatch:i,targets:r};return e.dispatch=i,jl.set(e,a),a}function Pl(e,t){let n={_id:ar(),_type:`vault-action`,_lastActionId:e.lastActionId,action:t};e.lastActionId=n._id,e.port.postMessage(JSON.stringify(n))}function Fl(e){try{if(typeof e==`string`)return JSON.parse(e);if(typeof e==`object`&&e)return e}catch{return null}return null}const Il=O({resource:null});function Ll(){return A(Il)}function Rl(){let e=z(),{resource:t}=Ll();U(t,`Nothing selected`);let{id:n,type:r}=t;return qe(()=>e.get({id:n,type:r}),[n,r])}function zl(){let{resource:e}=Ll();return e}function Bl({resource:e,children:t}){let{id:n,type:r}=e||{};return L(Il.Provider,{value:N(()=>({resource:n&&r?{id:n,type:r}:null}),[n,r]),children:t})}var Vl=class extends be{constructor(...e){super(...e),J(this,`state`,{hasError:!1})}static getDerivedStateFromError(e){return console.error(e),{hasError:!0}}componentDidCatch(e,t){console.error(`Uncaught error:`,e,t)}render(){return this.state.hasError?L(`h1`,{children:`Sorry.. there was an error`}):this.props.children}};function Hl(e,t){return typeof e==`string`?{id:e,state:t}:e}const Ul=Ee(function(e){let t=q(),n=xc(),r=t.layout,[i,a]=Oe(Sl,void 0,wl),o={centerPanel:yl(`centerPanel`,a),leftPanel:yl(`leftPanel`,a),rightPanel:yl(`rightPanel`,a),pinnedRightPanel:yl(`pinnedRightPanel`,a),modal:yl(`modal`,a),editingStack:ta()};function s(e){let t=r.rightPanels.find(t=>t.id===e);if(t)return[t,o.rightPanel,o.pinnedRightPanel];let n=r.centerPanels.find(t=>t.id===e);if(n)return[n,o.centerPanel];let i=r.leftPanels.find(t=>t.id===e);if(i)return[i,o.leftPanel];U(!1,`Was not able to find panel with id "${e}"`)}function c(e,t){let{id:r,state:i,stacked:a}=Hl(e,t),[o,c,l]=s(r);if(l&&o.options?.openPinned)l.pin({id:r,state:{...o.defaultState||{},...i||{}}});else{let e={id:r,state:{...o.defaultState||{},...i||{}},stacked:a};n.emit(`layout.open`,e),c.open(e)}}function l(e,t){let{id:r,state:i}=Hl(e,t),[a,o]=s(r),c={id:r,state:{...a.defaultState||{},...i||{}},stacked:!0};n.emit(`layout.open`,c),o.open(c)}function u(e,t){let{id:r,state:i,stacked:a}=Hl(e,t),[o,c]=s(r),l={id:r,state:{...o.defaultState||{},...i||{}},stacked:a};n.emit(`layout.change`,l),c.change(l)}function d(e,t){let{id:r}=Hl(e,t),[,i]=s(r);n.emit(`layout.close`,{id:r}),i.close()}function f(e,t){let{id:r}=Hl(e,t),[,i]=s(r);n.emit(`layout.toggle`,{id:r}),i.toggle()}function p(e,t={},{reset:i,property:a,stacked:s,forceOpen:c,selectedTab:l}={}){let u={resource:Je(e)?e:{type:`SpecificResource`,source:e},...t};n.emit(`layout.edit`,u),o.editingStack.edit(u,i),r.rightPanels.find(e=>e.id===`@manifest-editor/editor`)&&(c?o.rightPanel.open({id:`@manifest-editor/editor`,stacked:s!==!1,state:{property:a,currentTab:l},unique:!0}):o.rightPanel.change({id:`@manifest-editor/editor`,stacked:s!==!1,state:{property:a,currentTab:l},unique:!0}))}async function m(e){o.editingStack.create(e,{}),n.emit(`layout.create`,e),r.modals?.find(e=>e.id===`@manifest-editor/creator`)?o.modal.open({id:`@manifest-editor/creator`,stacked:!0,unique:!0,state:e}):r.rightPanels.find(e=>e.id===`@manifest-editor/creator`)&&o.rightPanel.open({id:`@manifest-editor/creator`,stacked:!0,unique:!0,state:e})}let h={open:c,change:u,close:d,toggle:f,stack:l,edit:p,create:m};return L(pa.Provider,{value:N(()=>({...o,...h}),[r]),children:L(ma.Provider,{value:i,children:e.children})})}),Wl=[{id:`universal-viewer`,config:{url:`https://universalviewer.dev/#?iiifManifestId={manifestId}`},type:`external-manifest-preview`,label:`Universal viewer`},{id:`mirador-3`,type:`external-manifest-preview`,label:`Mirador 3`,config:{url:`https://tomcrane.github.io/scratch/mirador3/?iiif-content={manifestId}`}},{id:`annona`,type:`external-manifest-preview`,label:`Annona`,config:{url:`https://ncsu-libraries.github.io/annona/tools/#/display?url={manifestId}&viewtype=iiif-storyboard&settings=%7B%22fullpage%22%3Atrue%7D`}},{id:`iiif-preview`,config:{url:`https://iiif-preview.digirati.services/store`},type:`iiif-preview-service`,label:`IIIF Preview`}],Gl=new _t({approximateServices:!0,verificationsRequired:8,enableFetching:!0});function Kl({config:e,saveConfig:t,children:n,theme:r,previews:i,resource:a,editing:o,backgroundActionPersistence:s}){let c=ii(),l=Ot(),u=N(()=>Tt(l,{previews:e?.previews||(l.previews?.length?l.previews:Wl)},e),[l,e]),d=N(()=>({appId:c.appId,instanceId:c.instanceId,rootResource:{id:a.id,type:a.type}}),[c.appId,c.instanceId,a.id,a.type]);return L(Vl,{children:L(Le.Provider,{value:Gl,children:L(Si,{resource:a,children:L(gs,{children:L(Ye,{theme:r||Es,children:R(At,{config:u,saveConfig:t,children:[L(ei,{config:u}),L(da,{children:L(Ul,{children:L(Zn,{persistence:s,persistenceKey:d,children:L(Ks,{children:L(Qa,{children:L(Pi,{previews:i||[],configs:u.previews,children:L(Pe,{children:n})})})})})})})]})})})})})})}const ql=new Set([`Collection`,`Manifest`,`Canvas`,`Range`,`AnnotationPage`,`Annotation`,`ContentResource`,`Agent`]),Jl={satisfied:0,missing:0,invalid:0,disallowed:0,"not-applicable":0},Yl=new Set([`label`,`summary`,`language`,`navDate`,`provider`,`requiredStatement`,`rights`,`thumbnail`]);function Xl(e){return e?Array.isArray(e)?e.filter(Boolean):e.split(`.`).filter(Boolean):[]}function Zl(e,t){let n=Xl(e),r=Xl(t);return n.length===r.length&&n.every((e,t)=>e===r[t])}function Ql(e,t){let n=e;for(let e of Xl(t)){if(n==null)return;n=n[e]}return n}function $l(e,t,n){let r=Xl(t);if(!r.length)return n;let i=Array.isArray(e)?[...e]:{...e||{}},a=i;return r.forEach((e,t)=>{if(t===r.length-1){a[e]=n;return}let i=a[e];a[e]=Array.isArray(i)?[...i]:{...i||{}},a=a[e]}),i}function eu(e){if(e==null)return!1;if(typeof e==`string`)return e.trim().length>0;if(typeof e==`number`||typeof e==`boolean`)return!0;if(Array.isArray(e))return e.some(e=>eu(e));if(typeof e!=`object`)return!1;let t=Object.entries(e);return t.length?t.every(([,e])=>typeof e==`string`||Array.isArray(e)&&e.every(e=>typeof e==`string`))?t.some(([,e])=>eu(e)):!0:!1}function tu(e){return Array.isArray(e)?e.map(tu):e&&typeof e==`object`?Object.keys(e).sort().reduce((t,n)=>(t[n]=tu(e[n]),t),{}):e}function nu(e,t){return JSON.stringify(tu(e))===JSON.stringify(tu(t))}function ru(e,t,n,r){let i=Xl(n);for(let n of e||[])for(let e of n.terminology?.properties||[])if(!(e.entityType&&e.entityType!==t)&&Zl(e.path,i))return e.label;return r||ju(i)}function iu(e,t,n){let r=Xl(n),i=[],a,o,s=!1,c=!1;if(!t||!ql.has(t.type))return{entityType:t?.type,path:r,label:ru(e,t?.type,r),disallowed:!1,required:!1,rules:i};for(let n of e||[])for(let e of n.rules||[])!(`entityType`in e)||!(`path`in e)||e.entityType===t.type&&Zl(e.path,r)&&(i.push(e),e.type===`disallow-property`&&(s=!0),e.type===`require-non-empty`&&(c=!0),e.type===`fixed-value`&&!o&&(a=e.value,o=e,c=!0));return{entityType:t.type,path:r,label:ru(e,t.type,r),disallowed:s,required:c,fixedValue:a,fixedValueRule:o,rules:i}}function au(e,t,n){let r=e||[],i=ou(t,n),a=[];for(let e of r)for(let[n,r]of(e.rules||[]).entries())a.push(...su(e,r,n,i,t));return{specifications:r,results:a,counts:gu(a)}}function ou(e,t){let n=[],r=new Set;function i(t){let a=vu(t);if(!a)return;if(a.type===`SpecificResource`){i(t?.source);return}let o=_u(e,t)||_u(e,a);if(!o||!o.type)return;let s=`${o.type}:${o.id||JSON.stringify(a)}`;if(!r.has(s)){r.add(s),ql.has(o.type)&&n.push({ref:{id:o.id,type:o.type},resource:o});for(let e of yu(o))i(e)}}return i(t),n}function su(e,t,n,r,i){switch(t.type){case`disallow-property`:case`require-non-empty`:case`fixed-value`:return cu(e,t,n,r);case`iiif:canvas-with-image-service`:return[lu(e,t,n,r,i)];case`iiif:thumbnail-from-body-service`:return uu(e,t,n,r,i);case`iiif:valid-rights`:return du(e,t,n,r);case`iiif:required-statement`:return fu(e,t,n,r);case`iiif:metadata-template`:return pu(e,t,n,r);default:return[]}}function cu(e,t,n,r){let i=r.filter(e=>e.ref.type===t.entityType),a=ru(e?[e]:[],t.entityType,t.path);return i.length?i.map(({ref:r,resource:i})=>{let o=Ql(i,t.path),s=eu(o);if(t.type===`disallow-property`)return mu(e,t,n,{target:r,path:t.path,status:s?`disallowed`:`satisfied`,displayLabel:a,actual:o,message:s?`${a} is present but is not allowed.`:`${a} is not present.`,editorTarget:hu(r,t.path)});if(t.type===`require-non-empty`)return mu(e,t,n,{target:r,path:t.path,status:s?`satisfied`:`missing`,displayLabel:a,actual:o,message:s?`${a} has a value.`:`${a} must be filled in.`,editorTarget:hu(r,t.path)});let c=nu(o,t.value);return mu(e,t,n,{target:r,path:t.path,status:c?`satisfied`:s?`invalid`:`missing`,displayLabel:a,expected:t.value,actual:o,message:c?`${a} matches the required value.`:s?`${a} does not match the required value.`:`${a} must use the required value.`,editorTarget:hu(r,t.path)})}):[mu(e,t,n,{status:`not-applicable`,displayLabel:a,message:`No ${t.entityType} resources were found for ${a}.`,path:t.path})]}function lu(e,t,n,r,i){let a=r.filter(e=>e.ref.type===`Canvas`),o=bu(t),s=a.find(({resource:e})=>xu(Su(e,i),o));return mu(e,t,n,{target:s?.ref,status:s?`satisfied`:`missing`,displayLabel:t.label||`Canvas image service`,expected:o,message:s?`A canvas contains the required image service.`:o.length?`A canvas must contain one of the required image services: ${o.join(`, `)}.`:`A canvas must contain a painting body with an image service.`,editorTarget:s?hu(s.ref,[`items`]):void 0})}function uu(e,t,n,r,i){let a=t.entityType||`Canvas`,o=r.filter(e=>e.ref.type===a);return o.length?o.map(({ref:o,resource:s})=>{let c=a===`Manifest`?r.filter(e=>e.ref.type===`Canvas`).flatMap(e=>Su(e.resource,i)):Su(s,i),l=Cu(s,c,i),u=eu(s.thumbnail);return mu(e,t,n,{target:o,path:[`thumbnail`],status:l?`satisfied`:c.length?u?`invalid`:t.requireThumbnail===!1?`not-applicable`:`missing`:`not-applicable`,displayLabel:ru([e],o.type,[`thumbnail`],`Thumbnail`),expected:c,actual:s.thumbnail,message:l?`Thumbnail uses the same image service as the painting content.`:c.length?u?`Thumbnail does not use the same image service as the painting content.`:`Thumbnail must be created from the painting image service.`:`No painting image service was found to compare against.`,editorTarget:hu(o,[`thumbnail`])})}):[mu(e,t,n,{status:`not-applicable`,displayLabel:`Thumbnail`,message:`No ${a} resources were found for thumbnail checks.`})]}function du(e,t,n,r){let i=t.entityType||`Manifest`,a=r.filter(e=>e.ref.type===i),o=t.allowed||[];return a.map(({ref:r,resource:i})=>{let a=i.rights,s=eu(a),c=typeof a==`string`&&o.map(Du).includes(Du(a));return mu(e,t,n,{target:r,path:[`rights`],status:c?`satisfied`:!s&&t.required!==!1?`missing`:`invalid`,displayLabel:ru([e],r.type,[`rights`],`Rights`),expected:o,actual:a,message:c?`Rights uses an allowed URI.`:!s&&t.required!==!1?`Rights must use an allowed URI.`:`Rights is not one of the allowed URIs.`,editorTarget:hu(r,[`rights`])})})}function fu(e,t,n,r){let i=t.entityType||`Manifest`;return r.filter(e=>e.ref.type===i).map(({ref:r,resource:i})=>{let a=i.requiredStatement,o=t.label?Ou(a?.label,t.label):eu(a?.label),s=t.value||t.valueRequired!==!1,c=t.value?Ou(a?.value,t.value):!s||eu(a?.value),l=eu(a);return mu(e,t,n,{target:r,path:[`requiredStatement`],status:o&&c?`satisfied`:l?`invalid`:`missing`,displayLabel:ru([e],r.type,[`requiredStatement`],`Required statement`),expected:t.value||t.label,actual:a,message:o&&c?`Required statement is complete.`:l?`Required statement does not match the specification.`:`Required statement must be filled in.`,editorTarget:hu(r,[`requiredStatement`])})})}function pu(e,t,n,r){let i=t.entityType||`Manifest`,a=r.filter(e=>e.ref.type===i),o=[];for(let{ref:r,resource:i}of a){let a=Array.isArray(i.metadata)?i.metadata:[];t.items.forEach((i,s)=>{let c=a.find(e=>Ou(e?.label,i.label)),l=i.value?Ou(c?.value,i.value):i.valueRequired?eu(c?.value):!0,u=c&&l?`satisfied`:c&&i.value?`invalid`:`missing`,d=Au(i.label);o.push(mu(e,t,n,{idSuffix:`metadata-${s}`,target:r,path:[`metadata`],status:u,displayLabel:d||`Metadata`,expected:i.value||i.label,actual:c,message:c&&l?`${d||`Metadata`} is present.`:c?`${d||`Metadata`} needs a value.`:`${d||`Metadata`} metadata must be added.`,editorTarget:hu(r,[`metadata`])}))})}return o}function mu(e,t,n,r){let i=t.id||`${t.type}-${n}`,a=r.idSuffix?`-${r.idSuffix}`:``;return{id:`${e.id}-${i}-${r.target?.type||`root`}-${r.target?.id||`none`}${a}`,specificationId:e.id,specificationLabel:e.label,ruleId:i,ruleType:t.type,ruleLabel:t.label||r.displayLabel,ruleIndex:n,target:r.target,path:r.path,status:r.status,displayLabel:r.displayLabel,message:t.message||r.message,expected:r.expected,actual:r.actual,editorTarget:r.editorTarget}}function hu(e,t){let n=t[0];return{resource:e,propertyPath:t,selectedTab:n===`metadata`?`@manifest-editor/metadata`:n&&Yl.has(n)?`@manifest-editor/descriptive-properties`:void 0}}function gu(e){let t={...Jl};for(let n of e)t[n.status]+=1;return t}function _u(e,t){let n=vu(t);if(!n)return t;try{return e.get(n,{skipSelfReturn:!1})||t}catch{try{return e.get(n)||t}catch{return t}}}function vu(e){return!e||typeof e!=`object`?null:e.type===`SpecificResource`?{id:e.id||e.source?.id||``,type:`SpecificResource`}:typeof e.id==`string`&&typeof e.type==`string`?{id:e.id,type:e.type}:null}function yu(e){if(!e||typeof e!=`object`)return[];let t=[];for(let n of[`items`,`structures`,`annotations`,`thumbnail`,`provider`,`homepage`,`rendering`,`seeAlso`,`body`,`target`,`source`]){let r=e[n];Array.isArray(r)?t.push(...r):r&&t.push(r)}return t}function bu(e){return[...e.serviceIds||[],...e.serviceId?[e.serviceId]:[]].filter(Boolean)}function xu(e,t){let n=new Set(e.filter(Boolean));return t.length?t.some(e=>n.has(e)):n.size>0}function Su(e,t){let n=Eu(t,e?.items),r=[];for(let e of n){let n=Eu(t,e?.items);for(let e of n)if((Array.isArray(e?.motivation)?e.motivation:[e?.motivation]).includes(`painting`))for(let n of wu(e?.body,t))r.push(...Tu(n))}return Array.from(new Set(r))}function Cu(e,t,n){let r=Eu(n,e?.thumbnail);if(!r.length||!t.length)return!1;for(let e of r){let n=Tu(e),r=typeof e?.id==`string`?e.id:``;if(n.some(e=>t.includes(e))||t.some(e=>r.startsWith(e)))return!0}return!1}function wu(e,t){let n=_u(t,e);return n?Array.isArray(n)?n.flatMap(e=>wu(e,t)):n.type===`SpecificResource`?wu(n.source,t):n.type===`Choice`?n.items?.flatMap(e=>wu(e,t))||[]:[n]:[]}function Tu(e){let t=e?.service||e?.services,n=Array.isArray(t)?t:t?[t]:[],r=[];for(let e of n){let t=typeof e==`string`?e:e?.id||e?.[`@id`];typeof t==`string`&&t&&r.push(t)}return Array.from(new Set(r))}function Eu(e,t){if(!t)return[];let n=Array.isArray(t)?t:[t];try{let t=e.get(n);if(Array.isArray(t))return t.filter(Boolean)}catch{}return n.map(t=>_u(e,t)).filter(Boolean)}function Du(e){return e.replace(/^https:/,`http:`).replace(/\/?$/,`/`)}function Ou(e,t){return typeof t==`string`?ku(e).some(e=>e===t):nu(e,t)}function ku(e){return e?typeof e==`string`?[e.trim()].filter(Boolean):Array.isArray(e)?e.flatMap(ku):typeof e==`object`?Object.values(e).flatMap(ku):[]:[]}function Au(e){return typeof e==`string`?e:ku(e)[0]||``}function ju(e){return(e[e.length-1]||`Property`).replace(/([A-Z])/g,` $1`).replace(/[-_]/g,` `).replace(/^./,e=>e.toUpperCase())}const Mu=O([]);function Nu({children:e,specifications:t}){let n=N(()=>t||[],[t]);return L(Mu.Provider,{value:n,children:e})}function Pu(){return A(Mu)}function Fu(e){let t=bi(),n=Pu(),r=e||t;return qe((e,t)=>au(n,t,r),[n,r.id,r.type])}function Iu(){let e=Pu();return N(()=>({getLabel(t,n,r){return ru(e,t,n,r)}}),[e])}function Lu(e,t){let n=Pu();return N(()=>iu(n,e,t),[n,e?.id,e?.type,JSON.stringify(t)])}const Ru={},zu=O(`global`);function Bu(){return A(zu)}function Vu(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function Hu(e){let t=Bu(),[,n]=Oe(e=>e+1,0),r=N(()=>(Ru[t]||(Ru[t]={}),Ru[t][e]||(Ru[t][e]={name:e,emitter:pt(),status:`idle`,promise:Promise.resolve(),abort:new AbortController,reject:()=>void 0,resolve:()=>void 0}),Ru[t][e]),[t,e]);return Uu(r,`abort`,n),Uu(r,`error`,n),Uu(r,`complete`,n),Uu(r,`running`,n),r}function Uu(e,t,n){let r=k(()=>n(e),[n]);j(()=>{let n=e.emitter;return n.on(t,r),()=>n.off(t,r)},[t,r,e.emitter])}const Wu=()=>void 0;function Gu(e,t){let n=Hu(e);return Uu(n,`complete`,t||Wu),[e=>{n.status===`running`&&(n.abort.abort(),n.emitter.emit(`abort`)),n.error&&(n.error=``);let t=Vu();t.promise.then(()=>n.emitter.emit(`complete`)).catch(()=>n.emitter.emit(`error`)),n.status=`running`,n.request=e,n.promise=t.promise,n.resolve=t.resolve,n.reject=t.reject,n.emitter.emit(`running`)},n]}function Ku(e,t){let n=Hu(e);return Uu(n,`running`,t),[e=>{n.status===`running`&&(n.response=e,n.status=`complete`,n.resolve())},n,(e,t)=>{n.status===`running`&&(n.error=t||e,n.status=`error`,n.reject(e))}]}function qu({children:e}){return L(zu.Provider,{value:N(()=>`id-${Date.now()}`,[]),children:e})}function Ju(e){return!1}function Yu({as:e,reference:t,onReference:n,onLink:r,onAnalysis:i,onDropReference:a,onDropLink:o,onDropAnalysis:s,onPasteReference:c,onPasteLink:l,onPasteAnalysis:u,...d}){let f=e||`div`,p=a||n,m=c||n,h=l||r,g=u||i,_=N(()=>t,[t?.id,t?.type]),v=k(function(e){e.defaultPrevented||(e.preventDefault(),e.clipboardData&&_&&_.id&&_.type&&e.clipboardData.setData(`application/json+vault`,JSON.stringify({id:_.id,type:_.type})))},[_]),y=k(async function(e){if(!e.defaultPrevented&&(e.preventDefault(),e.clipboardData)){if(d.onLoading&&d.onLoading(),m){let t=e.clipboardData.getData(`application/json+vault`);if(t)try{let e=JSON.parse(t);e&&e.id&&e.type&&m(e)}catch{}}if(h||g){let t=e.clipboardData.getData(`text`);if(t.startsWith(`http`)){let e=t.split(`
1511
- `);for(let t of e){if(g)try{let e=await Ju(t);if(e){g(e);continue}}catch{}h&&h(t)}}}d.onComplete&&d.onComplete()}},[]),b=k(function(e){e.defaultPrevented||(e.preventDefault(),e.dataTransfer&&d.draggable&&(e.dataTransfer.effectAllowed=`all`,_&&_.id&&_.type&&e.dataTransfer.setData(`application/json+vault`,JSON.stringify({id:_.id,type:_.type}))))},[]);return L(f,{onCopy:v,onPaste:y,onDrop:k(async function(e){if(e.preventDefault(),e.dataTransfer){if(p){let t=e.dataTransfer.getData(`application/json+vault`);if(t)try{let n=JSON.parse(t);n&&n.id&&n.type&&p(n,e)}catch{return}}let t=e.dataTransfer.getData(`application/json`);if(t){JSON.parse(t);return}if(e.dataTransfer.getData(`text/plain`))return}},[]),onDragOver:k(e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`)},[]),onDragStart:b,tabIndex:-1,...d})}export{wo as AppHeader,Oo as AppMenuProvider,si as AppProvider,ni as AppReactContext,xi as AppResourceInstanceProvider,Si as AppResourceProvider,ri as AppStateReactContext,Ne as AtlasStoreProvider,Fe as AtlasStoreReactContext,co as BackgroundActionToasts,Co as BackgroundActionsMenu,so as BackgroundActionsMount,Zn as BackgroundActionsProvider,Xn as BackgroundActionsReactContext,Ds as BaseAnnotationCreator,js as BaseEditor,Os as BaseEditorBackButton,ks as BaseEditorCloseButton,jt as CANVAS_PROGRESS_META_NAMESPACE,Mt as CANVAS_PROGRESS_STATUS_META_KEY,Us as ConfigEditor,At as ConfigProvider,Et as ConfigReactContext,Ks as ContextMenuProvider,Gs as ContextMenuReactContext,Ss as CreatorInitialData,da as EditingStack,$i as EditingStackContext,bc as EventEmitterProvider,_c as ExportPanel,Ca as FLAG_TAG,ms as HOMEPAGE_COLLECTION,Ec as HandleContainer,jc as HandleControls,fa as InlineEditingStack,vl as Layout,pa as LayoutActionsReactContext,ha as LayoutModeReactContext,ma as LayoutStateReactContext,Zt as ManifestEditorCanvasProgressOverlay,Ka as ManifestEditorTagBadge,Ga as ManifestEditorTagIcon,qa as ManifestEditorTagOverlay,Tl as ManifestPaginationNavigation,vt as MessagePortClientVault,ls as ModularPanel,is as ModularPanelHeader,as as ModulePanelButton,di as MultiAppProvider,Ko as PanelError,ei as PluginConfigBridge,Hr as PluginGlobalConfigReactContext,Bs as PluginManager,Ur as PluginProvider,Vr as PluginReactContext,Yi as PreviewButton,Pi as PreviewProvider,_s as PreviewVaultBoundary,gs as PreviewVaultContext,ti as PrimeAppReactContext,yc as ReactEmitterContext,Bl as ResourceEditingProvider,Il as ResourceEditingReactContext,Dt as SaveConfigReactContext,Kl as ShellProvider,Nu as SpecificationProvider,Sa as TAGS_META_KEY,xa as TAGS_META_NAMESPACE,qu as TaskBridge,Qa as ToastProvider,Yu as UniversalCopyTarget,Ia as addResourceTag,Po as analyse,Io as analyseJson,zr as applyPlugins,Ts as baseCreator,Ms as baseEditor,Bt as clearCanvasProgressStatus,Ht as clearCanvasProgressStatuses,ou as collectSpecificationResources,ir as copyToClipboard,nr as createActionIdentity,Vn as createBackgroundActionsStore,rr as createDownload,Ml as createIframeVaultBridge,Jn as createLocalForageBackgroundActionPersistence,Ut as createManifestEditorCanvasProgressApi,Ha as createManifestEditorTagsApi,Nr as createPluginRuntimeApi,Br as createPluginStore,us as createPreviewVault,Wt as createTrackingCanvasProgressApi,No as detectMedia,gr as disablePluginInConfig,As as editBasedOnResource,Pr as enablePluginAndDependenciesInConfig,hr as enablePluginInConfig,au as evaluateSpecifications,sr as extendApp,zc as filterSupportedPanels,sn as getAvailableBackgroundActionGroups,en as getBackgroundActionInstanceKey,Lt as getCanvasProgressStatus,Rt as getCanvasProgressStatusFromState,wl as getDefaultLayoutState,Cl as getDefaultPanelState,Mr as getEffectivePluginSettings,ur as getEmptyPluginState,Dr as getEnabledPluginsForApp,zo as getFormat,Bo as getImageDimensions,tr as getManifestNomalized,wr as getPluginCompatibilityReason,jr as getPluginDefaultSettings,Er as getPluginSelectionSource,Or as getPluginSettingsFromConfig,iu as getPropertyPolicy,La as getResourceTag,za as getResourceTagGroups,Na as getResourceTags,Pa as getResourceTagsFromState,Bc as getSupportedPanelFallback,ru as getTerminologyLabel,Ql as getValueAtPath,eu as hasMeaningfulValue,Ba as hasResourceTag,br as isMappedPlugin,qo as isPinnableState,Cr as isPluginCompatible,Tr as isPluginSelected,Sl as layoutReducer,or as mapApp,yr as mapPlugin,tn as mergeBackgroundActionDefinitions,Tt as mergeConfig,wt as mergePartialConfig,rn as normaliseBackgroundActionError,tu as normaliseJsonValue,xr as normalisePlugin,pr as normalisePluginAppConfig,mr as normalisePluginAppsConfig,Sr as normalisePlugins,Xl as normaliseSpecificationPath,X as panelIds,Jo as panelSizing,vr as pluginAppConfigEquals,Ao as polygonToBoundingBox,ar as randomId,Ra as removeResourceTag,Yo as renderHelper,_r as resetPluginInConfig,Ar as resetPluginSettingsInConfig,Wn as runBackgroundAction,zt as setCanvasProgressStatus,Vt as setCanvasProgressStatuses,kr as setPluginSettingsInConfig,Fa as setResourceTags,$l as setValueAtPath,nn as sortBackgroundActionDefinitions,nu as specificationJsonEquals,Zl as specificationPathEquals,Va as toggleResourceTag,vc as useAnnotationCreatorState,ca as useAnnotationPageEditor,q as useApp,ii as useAppInstance,Eo as useAppMenu,Do as useAppMenuItem,bi as useAppResource,yi as useAppResourceInstance,ai as useAppState,li as useApps,ko as useAtlasStore,oo as useAvailableBackgroundActions,ya as useAvailableLayouts,er as useBackgroundActionHistory,$n as useBackgroundActionInstance,K as useBackgroundActionsStore,Qn as useBackgroundActionsStoreApi,Kt as useCanvasProgressActions,Gt as useCanvasProgressStatus,oa as useCollectionEditor,Ot as useConfig,ia as useCreatingResource,vs as useCreator,Xs as useCustomContextMenu,Ns as useDecayState,Ll as useEditingContext,na as useEditingResource,ra as useEditingResourceStack,ta as useEditingStack,la as useEditor,xc as useEmitter,Jr as useEnabledPlugins,Sc as useEvent,sa as useGenericEditor,Vo as useHighlightedImageResource,Uo as useHoverHighlightImageResource,xs as useInitialData,ys as useInlineCreator,_a as useLayoutActions,va as useLayoutMode,ba as useLayoutProvider,ga as useLayoutState,_e as useLocalStorage,aa as useManifestEditor,Cc as useMatchMedia,ve as useOptionalLocalStorage,Wr as useOptionalPluginStoreApi,zl as useOptionalResource,yl as usePanelActions,Yr as usePluginActions,Qr as usePluginConfigApi,Xr as usePluginRuntimeApi,Zr as usePluginSettings,Gr as usePluginStoreApi,qr as usePlugins,Ii as usePreviewContext,hs as usePreviewHistory,ds as usePreviewVault,Fi as usePreviews,$r as useResolvedPluginApp,Rl as useResource,Js as useResourceContextMenuItems,Wa as useResourceTagActions,Ua as useResourceTags,kt as useSaveConfig,wc as useSaveVault,ns as useSetCustomTitle,Lu as useSpecificationPropertyPolicy,Fu as useSpecificationReport,Iu as useSpecificationTerminology,Pu as useSpecifications,Tc as useSvgTools,Hu as useTask,Gu as useTaskDispatch,Uu as useTaskEvent,Ku as useTaskRunner,Ho as useTemporaryHighlight,$a as useToasts};
1510
+ `,El=Ee(function(e){if(e.layoutMode===`focused`)return L(hl,{...e});let t=q(),n=pi(),r=Oi(),i=Oa(),{vault:a}=A(ze),o=a||void 0,s=qe(e=>e.iiif),c=P(null),l=P(null),{loading:u,state:d,leftPanels:f,centerPanels:p,rightPanels:m,modals:h=[],actions:g}=i,_=N(()=>({rootResource:r,vault:o,app:t,layoutState:d,appState:n}),[r,o,t,d,n,s]),v=N(()=>qc(f,_,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[f,_]),y=N(()=>qc(p,_,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[p,_]),b=N(()=>qc(m,_,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[m,_]),x=N(()=>qc(h,_,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[h,_]),S=N(()=>({...i,leftPanels:v,centerPanels:y,rightPanels:b,modals:x}),[i,v,y,b,x]),C=v.find(e=>e.id===d.leftPanel.current),w=b.find(e=>e.id===d.rightPanel.current),T=y.find(e=>e.id===d.centerPanel.current),E=x.find(e=>e.id===d.modal.current),te=d.pinnedRightPanel.pinned?b.find(e=>e.id===d.pinnedRightPanel.current):void 0,[ne]=jc([`(max-width: 1020px)`]),ie=e.isLoading||!1,ae=N(()=>(i.background||[]).map((e,t)=>L(xe,{children:e.render()},t)),[i.background]),oe=Kc(`left-panel/${C?.id}`,{left:!0,marginLeft:60,minWidthPx:C?.options?.minWidth||200,maxWidthPx:C?.options?.maxWidth||720,loading:u}),D=Kc(`right-panel/${w?.id}`,{left:!1,minWidthPx:w?.options?.minWidth||320,maxWidthPx:w?.options?.maxWidth||720,loading:u}),se=w&&(te?.id!==w.id||!gt(d.pinnedRightPanel.state,d.rightPanel.state)),ce=oe.widthB===`auto`?void 0:()=>oe.setWidths({widthA:`auto`,widthB:ns({options:C?.options,fallback:320})}),le=D.widthB===`auto`?void 0:()=>D.setWidths({widthA:`auto`,widthB:ns({options:w?.options,fallback:320})});if(M(()=>{ne&&d.leftPanel.open&&d.rightPanel.open&&(g.leftPanel.close(),g.rightPanel.close())},[ne]),M(()=>{if(T&&T.onMount)return T.onMount(d.centerPanel.state||T.defaultState||{},{...S,current:g.centerPanel,vault:o},n)},[d.centerPanel.current,T?.id]),M(()=>{if(d.leftPanel.current&&!C){let e=Jc(v,d.leftPanel.current);e?g.leftPanel.change({id:e}):g.leftPanel.close()}if(d.centerPanel.current&&!T){let e=Jc(y,d.centerPanel.current);e?g.centerPanel.change({id:e}):g.centerPanel.close()}if(d.rightPanel.current&&!w){let e=Jc(b,d.rightPanel.current);e?g.rightPanel.change({id:e}):g.rightPanel.close()}if(d.modal.current&&!E){let e=Jc(x,d.modal.current);e?g.modal.change({id:e}):g.modal.close()}},[d.leftPanel.current,d.centerPanel.current,d.rightPanel.current,d.modal.current,C?.id,T?.id,w?.id,E?.id,X(v),X(y),X(b),X(x)]),M(()=>{b.length&&g.rightPanel.change({id:b[0].id}),v.length&&g.leftPanel.change({id:v[0].id}),y.length&&g.centerPanel.change({id:y[0].id})},[]),u)return null;let ue=t=>L(dl,{$menu:e.leftPanelMenuPosition||`bottom`,ref:oe.refs.resizableDiv,className:[`manifest-editor`,t?`transition transition-${t}`:``].join(` `),style:{width:d.leftPanel.open||t!==`exited`?oe.widthB:void 0,minWidth:C?.options?.minWidth},children:ie?L(pl,{children:L(Hc,{})}):R(I,{children:[e.leftPanelMenu?L(fl,{$open:d.leftPanel.open&&t!==`exited`,$position:e.leftPanelMenuPosition||`bottom`,children:e.leftPanelMenu}):null,L(pl,{children:d.leftPanel.open||t!==`exited`?L(I,{children:C?L(_s,{isLeft:!0,noHeader:!0,transition:t,panel:C,state:d.leftPanel,actions:g.leftPanel}):null}):null})]})}),de=()=>!E||d.modal.open===!1?null:L(ee,{title:E.label,onClose:()=>g.modal.close(),children:rs(E.render(d.modal.state||E.defaultState||{},{...S,current:g.modal,vault:o},n))}),fe=()=>R(dl,{$menu:e.centerPanelMenuPosition||`top`,children:[e.centerPanelMenu?L(fl,{$open:d.centerPanel.open,$position:e.centerPanelMenuPosition||`top`,children:e.centerPanelMenu}):null,L(pl,{children:L(ot,{resetKeys:[T?.id],FallbackComponent:es,children:ie?L(`div`,{style:{display:`flex`,flex:1,justifyContent:`center`,alignItems:`center`},children:L(Bc,{stroke:`rgba(0,0,0,.3)`,fontSize:`2em`})}):d.centerPanel.open&&T?rs(T.render(d.centerPanel.state||T.defaultState||{},{...S,current:g.centerPanel,vault:o},n)):null})})]}),pe=t=>L(dl,{$menu:e.rightPanelMenuPosition||`bottom`,ref:D.refs.resizableDiv,className:t?`transition transition-${t}`:``,style:{width:d.rightPanel.open||t!==`exited`?D.widthB:void 0,minWidth:w?.options?.minWidth},children:ie?L(pl,{children:L(Hc,{})}):R(I,{children:[e.rightPanelMenu?L(fl,{$open:d.rightPanel.open,$position:e.rightPanelMenuPosition||`bottom`,children:e.rightPanelMenu}):null,L(pl,{children:d.rightPanel.open||t!==`exited`?R(I,{children:[se?L(_s,{panel:w,state:d.rightPanel,actions:g.rightPanel,pinActions:g.pinnedRightPanel,available:b}):null,te?L(_s,{panel:te,state:d.pinnedRightPanel,actions:g.pinnedRightPanel,close:g.rightPanel.close}):null]}):null})]})});return ne?R(il,{children:[e.hideHeader?null:R(al,{children:[e.header||null,e.menu?L(`menu`,{children:e.menu}):null]}),L(sl,{children:R(gl,{children:[L(_l,{children:fe()}),R(vl,{children:[v.length>0?L(yl,{onClick:g.leftPanel.toggle,children:C?.label}):null,b.length>0?L(xl,{children:R(Sl,{onClick:g.rightPanel.toggle,children:[L(wi,{rotate:180}),w?.label]})}):null,L(bl,{children:`Preview`})]}),b.length>0?L(Cl,{$open:d.rightPanel.open,children:pe()}):null,v.length>0?L(wl,{$open:d.leftPanel.open,children:ue()}):null,v.length>0||b.length>0?L(Tl,{$open:d.leftPanel.open||d.rightPanel.open,onClick:()=>{g.leftPanel.close(),g.rightPanel.close()}}):null]})})]}):R(il,{id:e.htmlId||`manifest-editor-container`,className:`manifest-editor ${e.className||``}`,children:[e.hideHeader?null:R(al,{children:[e.header||null,e.menu?L(`menu`,{children:e.menu}):null]}),R(sl,{ref:e=>{oe.refs.container.current=e,D.refs.container.current=e},children:[v.length>0?L(re,{current:d.leftPanel.current,items:v.map(e=>({id:e.id,label:e.label,icon:e.icon,divide:e.divide,separator:e.separator,onClick:()=>{d.leftPanel.current===e.id?g.leftPanel.toggle():g.leftPanel.change({id:e.id})}})),open:d.leftPanel.open}):null,v.length>0?L(ht,{nodeRef:c,in:d.leftPanel.open,timeout:400,unmountOnExit:!1,children:e=>R(I,{children:[L(cl,{ref:c,$width:oe.widthB,$state:e,$motion:!0,children:ue(e)}),L(zc,{ref:oe.refs.resizer,reset:ce,dir:`left`,transition:e,open:d.leftPanel.open||e!==`exited`,actions:g.leftPanel})]})}):null,L(ll,{children:fe()}),b.length>0?L(ht,{nodeRef:l,in:d.rightPanel.open,timeout:400,unmountOnExit:!1,children:e=>R(I,{children:[L(zc,{ref:D.refs.resizer,dir:`right`,reset:le,open:d.rightPanel.open,actions:g.rightPanel}),L(ul,{ref:l,$width:D.widthB,$state:e,$motion:!0,children:pe(e)})]})}):null]}),L(ol,{children:e.footer||null}),L(`div`,{className:`hidden`,children:ae}),L(go,{}),L(_o,{}),L(I,{children:de()})]})});function Dl(e,t){function n(){t({type:`popStack`,panel:e,payload:void 0})}function r(n){t({type:`change`,panel:e,payload:n})}function i(n){t({type:`open`,panel:e,payload:n})}function a(){t({type:`close`,panel:e,payload:void 0})}function o(){t({type:`toggle`,panel:e,payload:void 0})}function s(){t({type:`minimise`,panel:e,payload:void 0})}function c(n){t({type:`maximise`,panel:e,payload:n})}function l(n){t({type:`setCustomWidth`,panel:e,payload:n})}function u(){t({type:`resetSize`,panel:e,payload:void 0})}function d(n){t({type:`pin`,panel:e,payload:n})}function f(){t({type:`unpin`,panel:e,payload:void 0})}return N(()=>({popStack:n,change:r,open:i,close:a,toggle:o,minimise:s,maximise:c,setCustomWidth:l,resetSize:u,pin:d,unpin:f}),[])}function Ol(e,t){if(t.payload&&t.payload.stacked){if(e.current){let n=e.stack[e.stack.length-1];if(n&&n.id===e.current)return;t.payload.unique&&(e.stack=e.stack.filter(t=>t.id!==e.current)),e.stack.push({id:e.current,state:e.state?{...Ze(e.state)}:{}})}}else e.stack=[]}function kl(e,t){switch(t.type){case`popStack`:if(e.stack.length){let t=e.stack[e.stack.length-1];t&&(e.current=t.id,e.state=t.state),e.stack=e.stack.slice(0,-1)}break;case`change`:t.payload.id!==e.current&&Ol(e,t),e.state=t.payload.state,e.current=t.payload.id;break;case`close`:e.open=!1;break;case`open`:e.open=!0,t.payload&&(t.payload.id!==e.current&&Ol(e,t),e.state=t.payload.state,e.current=t.payload.id);break;case`toggle`:e.open=!e.open;break;case`maximise`:e.minimised=!1,t.payload&&(e.state=t.payload.state,e.current=t.payload.id);break;case`minimise`:e.minimised=!0;break;case`setCustomWidth`:e.customWidth=t.payload;break;case`resetSize`:e.customWidth=void 0}if(ts(e))switch(t.type){case`pin`:e.pinned=!0,e.state=t.payload.state,e.current=t.payload.id;break;case`unpin`:e.pinned=!1,e.state=void 0;break}}const Al=Qe((e,t)=>{switch(t.panel){case`centerPanel`:kl(e.centerPanel,t);break;case`leftPanel`:kl(e.leftPanel,t);break;case`rightPanel`:kl(e.rightPanel,t);break;case`modal`:kl(e.modal,t);break;case`pinnedRightPanel`:kl(e.pinnedRightPanel,t);break}});function jl(){return{customWidth:void 0,minimised:!1,open:!0,current:null,state:null,stack:[]}}function Ml(){return{leftPanel:jl(),centerPanel:jl(),rightPanel:jl(),modal:jl(),pinnedRightPanel:{...jl(),pinnable:!0,pinned:!1}}}function Nl({className:e,variant:t=`light`}){let n=Ge(),r=z(),{edit:i}=Ta(),a=ua(),o=da(),s=n?.items||[],c=n?.viewingDirection===`right-to-left`||n?.viewingDirection===`bottom-to-top`,l=n?.viewingDirection===`top-to-bottom`||n?.viewingDirection===`bottom-to-top`,u=Pl(a)||o.map(Pl).find(Boolean)||s[0]?.id||``,d=Math.max(0,s.findIndex(e=>e.id===u)),f=s[d]?.id||``,p=d+1,m=N(()=>s.map((e,t)=>{let n=r.get({id:e.id,type:`Canvas`});return{id:e.id,pageNumber:t+1,labelText:tt(n?.label)||`Page ${t+1}`}}),[s,r]),h=e=>{let t=s.findIndex(t=>t.id===e),r=s[t];!r||!n||i({id:r.id,type:`Canvas`},{parent:{id:n.id,type:`Manifest`},property:`items`,index:t},{forceOpen:!1})};if(!n||s.length<2)return L(`div`,{});let g=s[d-1],_=s[d+1],v=t===`dark`;return R(`nav`,{"aria-label":`Manifest pagination`,className:Rl(`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-1`,`focus-within:ring-2 focus-within:ring-me-primary-500/40`,c&&`flex-row-reverse`,v?`border-white/20 bg-white/10 text-white`:`border-me-gray-300 bg-white text-me-gray-900`,e),children:[L(Fl,{ariaLabel:`Previous canvas`,disabled:!g,onClick:()=>g&&h(g.id),dark:v,children:L(Il,{reverse:c,vertical:l})}),R(`label`,{htmlFor:`manifest-pagination-page-select`,"aria-label":`Page ${p} of ${s.length}`,className:Rl(`relative inline-flex min-h-8 cursor-pointer select-none items-center gap-0.5`,`whitespace-nowrap rounded-full border px-2.5 text-xs font-semibold leading-none`,`focus-within:outline-none focus-within:ring-2 focus-within:ring-me-primary-500/40`,v?`border-white/20 bg-white/10 text-white hover:bg-white/15`:`border-me-gray-300 bg-me-gray-100 text-me-gray-900 hover:bg-me-primary-50`),children:[R(`span`,{children:[p,` / `,s.length]}),L(Ll,{className:Rl(`shrink-0 text-base`,v?`text-white/60`:`text-me-gray-500`)}),L(`select`,{id:`manifest-pagination-page-select`,"aria-label":`Jump to canvas`,value:f,onChange:e=>h(e.target.value),className:`absolute inset-0 cursor-pointer appearance-none border-0 bg-white opacity-0`,children:m.map(e=>R(`option`,{value:e.id,children:[`Page `,e.pageNumber,` - `,e.labelText]},e.id))})]}),L(Fl,{ariaLabel:`Next canvas`,disabled:!_,onClick:()=>_&&h(_.id),dark:v,children:L(Il,{reverse:!c,vertical:l})})]})}function Pl(e){let t=e?.resource?.source;return t?.type===`Canvas`?t.id:null}function Fl({ariaLabel:e,children:t,dark:n,disabled:r,onClick:i}){return L(`button`,{type:`button`,"aria-label":e,disabled:r,onClick:i,className:Rl(`inline-flex h-8 w-8 items-center justify-center rounded-full border-0 bg-transparent p-0`,`text-lg transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-me-primary-500/50`,n?`text-white hover:bg-white/15 disabled:text-white/40 disabled:hover:bg-transparent`:`text-me-gray-900 hover:bg-me-primary-50 disabled:text-me-gray-500 disabled:hover:bg-transparent`,`disabled:cursor-not-allowed`),children:t})}function Il({reverse:e,vertical:r}){return L(e?t:n,{"aria-hidden":!0,className:Rl(`block`,r&&`rotate-90`)})}function Ll(e){return L(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,"aria-hidden":!0,...e,children:L(`path`,{fill:`currentColor`,d:`m7 10l5 5l5-5z`})})}function Rl(...e){return e.filter(Boolean).join(` `)}const zl=new WeakMap;function Bl(e,t){let n={port:t,lastActionId:`@genesis`},r=Vl(e);function i(e){t.postMessage(typeof e==`string`?e:JSON.stringify(e))}function a(){i({_id:lr(),_type:`init-response`,_lastActionId:n.lastActionId,data:e.getState()})}function o(e){i({_id:e,_type:`vault-action-rejection`,_lastActionId:n.lastActionId,action:e})}function s(e){let t=Ul(e.data);if(t){if(t._type===`init-request`){a();return}t._type===`vault-action`&&o(t._id)}}return r.targets.add(n),t.addEventListener(`message`,s),t.start(),()=>{t.removeEventListener(`message`,s),r.targets.delete(n),r.targets.size===0&&e.dispatch===r.patchedDispatch&&(e.dispatch=r.originalDispatch,zl.delete(e)),t.close()}}function Vl(e){let t=zl.get(e);if(t)return t;let n=e.dispatch.bind(e),r=new Set,i=(e=>{let t=n(e);for(let t of r)Hl(t,e);return t}),a={originalDispatch:n,patchedDispatch:i,targets:r};return e.dispatch=i,zl.set(e,a),a}function Hl(e,t){let n={_id:lr(),_type:`vault-action`,_lastActionId:e.lastActionId,action:t};e.lastActionId=n._id,e.port.postMessage(JSON.stringify(n))}function Ul(e){try{if(typeof e==`string`)return JSON.parse(e);if(typeof e==`object`&&e)return e}catch{return null}return null}const Wl=O({resource:null});function Gl(){return A(Wl)}function Kl(){let e=z(),{resource:t}=Gl();U(t,`Nothing selected`);let{id:n,type:r}=t;return qe(()=>e.get({id:n,type:r}),[n,r])}function ql(){let{resource:e}=Gl();return e}function Jl({resource:e,children:t}){let{id:n,type:r}=e||{};return L(Wl.Provider,{value:N(()=>({resource:n&&r?{id:n,type:r}:null}),[n,r]),children:t})}var Yl=class extends be{constructor(...e){super(...e),J(this,`state`,{hasError:!1})}static getDerivedStateFromError(e){return console.error(e),{hasError:!0}}componentDidCatch(e,t){console.error(`Uncaught error:`,e,t)}render(){return this.state.hasError?L(`h1`,{children:`Sorry.. there was an error`}):this.props.children}};function Xl(e,t){return typeof e==`string`?{id:e,state:t}:e}const Zl=Ee(function(e){let t=q(),n=kc(),r=t.layout,[i,a]=Oe(Al,void 0,Ml),o={centerPanel:Dl(`centerPanel`,a),leftPanel:Dl(`leftPanel`,a),rightPanel:Dl(`rightPanel`,a),pinnedRightPanel:Dl(`pinnedRightPanel`,a),modal:Dl(`modal`,a),editingStack:la()};function s(e){let t=r.rightPanels.find(t=>t.id===e);if(t)return[t,o.rightPanel,o.pinnedRightPanel];let n=r.centerPanels.find(t=>t.id===e);if(n)return[n,o.centerPanel];let i=r.leftPanels.find(t=>t.id===e);if(i)return[i,o.leftPanel];U(!1,`Was not able to find panel with id "${e}"`)}function c(e,t){let{id:r,state:i,stacked:a}=Xl(e,t),[o,c,l]=s(r);if(l&&o.options?.openPinned)l.pin({id:r,state:{...o.defaultState||{},...i||{}}});else{let e={id:r,state:{...o.defaultState||{},...i||{}},stacked:a};n.emit(`layout.open`,e),c.open(e)}}function l(e,t){let{id:r,state:i}=Xl(e,t),[a,o]=s(r),c={id:r,state:{...a.defaultState||{},...i||{}},stacked:!0};n.emit(`layout.open`,c),o.open(c)}function u(e,t){let{id:r,state:i,stacked:a}=Xl(e,t),[o,c]=s(r),l={id:r,state:{...o.defaultState||{},...i||{}},stacked:a};n.emit(`layout.change`,l),c.change(l)}function d(e,t){let{id:r}=Xl(e,t),[,i]=s(r);n.emit(`layout.close`,{id:r}),i.close()}function f(e,t){let{id:r}=Xl(e,t),[,i]=s(r);n.emit(`layout.toggle`,{id:r}),i.toggle()}function p(e,t={},{reset:i,property:a,stacked:s,forceOpen:c,selectedTab:l}={}){let u={resource:Je(e)?e:{type:`SpecificResource`,source:e},...t};n.emit(`layout.edit`,u),o.editingStack.edit(u,i),r.rightPanels.find(e=>e.id===`@manifest-editor/editor`)&&(c?o.rightPanel.open({id:`@manifest-editor/editor`,stacked:s!==!1,state:{property:a,currentTab:l},unique:!0}):o.rightPanel.change({id:`@manifest-editor/editor`,stacked:s!==!1,state:{property:a,currentTab:l},unique:!0}))}async function m(e){o.editingStack.create(e,{}),n.emit(`layout.create`,e),r.modals?.find(e=>e.id===`@manifest-editor/creator`)?o.modal.open({id:`@manifest-editor/creator`,stacked:!0,unique:!0,state:e}):r.rightPanels.find(e=>e.id===`@manifest-editor/creator`)&&o.rightPanel.open({id:`@manifest-editor/creator`,stacked:!0,unique:!0,state:e})}let h={open:c,change:u,close:d,toggle:f,stack:l,edit:p,create:m};return L(xa.Provider,{value:N(()=>({...o,...h}),[r]),children:L(Sa.Provider,{value:i,children:e.children})})}),Ql=[{id:`universal-viewer`,config:{url:`https://universalviewer.dev/#?iiifManifestId={manifestId}`},type:`external-manifest-preview`,label:`Universal viewer`},{id:`mirador-3`,type:`external-manifest-preview`,label:`Mirador 3`,config:{url:`https://tomcrane.github.io/scratch/mirador3/?iiif-content={manifestId}`}},{id:`annona`,type:`external-manifest-preview`,label:`Annona`,config:{url:`https://ncsu-libraries.github.io/annona/tools/#/display?url={manifestId}&viewtype=iiif-storyboard&settings=%7B%22fullpage%22%3Atrue%7D`}},{id:`iiif-preview`,config:{url:`https://iiif-preview.digirati.services/store`},type:`iiif-preview-service`,label:`IIIF Preview`}],$l=new _t({approximateServices:!0,verificationsRequired:8,enableFetching:!0});function eu({config:e,saveConfig:t,children:n,theme:r,previews:i,resource:a,editing:o,backgroundActionPersistence:s}){let c=fi(),l=Ot(),u=N(()=>Tt(l,{previews:e?.previews||(l.previews?.length?l.previews:Ql)},e),[l,e]),d=N(()=>({appId:c.appId,instanceId:c.instanceId,rootResource:{id:a.id,type:a.type}}),[c.appId,c.instanceId,a.id,a.type]);return L(Yl,{children:L(Le.Provider,{value:$l,children:L(Ai,{resource:a,children:L(ws,{children:L(Ye,{theme:r||Ps,children:R(At,{config:u,saveConfig:t,children:[L(ci,{config:u}),L(ya,{children:L(Zl,{children:L(tr,{persistence:s,persistenceKey:d,children:L(ec,{children:L(oo,{children:L(Hi,{previews:i||[],configs:u.previews,children:L(Pe,{children:n})})})})})})})]})})})})})})}const tu=new Set([`Collection`,`Manifest`,`Canvas`,`Range`,`AnnotationPage`,`Annotation`,`ContentResource`,`Agent`]),nu={satisfied:0,missing:0,invalid:0,disallowed:0,"not-applicable":0},ru=new Set([`label`,`summary`,`language`,`navDate`,`provider`,`requiredStatement`,`rights`,`thumbnail`]);function iu(e){return e?Array.isArray(e)?e.filter(Boolean):e.split(`.`).filter(Boolean):[]}function au(e,t){let n=iu(e),r=iu(t);return n.length===r.length&&n.every((e,t)=>e===r[t])}function ou(e,t){let n=e;for(let e of iu(t)){if(n==null)return;n=n[e]}return n}function su(e,t,n){let r=iu(t);if(!r.length)return n;let i=Array.isArray(e)?[...e]:{...e||{}},a=i;return r.forEach((e,t)=>{if(t===r.length-1){a[e]=n;return}let i=a[e];a[e]=Array.isArray(i)?[...i]:{...i||{}},a=a[e]}),i}function cu(e){if(e==null)return!1;if(typeof e==`string`)return e.trim().length>0;if(typeof e==`number`||typeof e==`boolean`)return!0;if(Array.isArray(e))return e.some(e=>cu(e));if(typeof e!=`object`)return!1;let t=Object.entries(e);return t.length?t.every(([,e])=>typeof e==`string`||Array.isArray(e)&&e.every(e=>typeof e==`string`))?t.some(([,e])=>cu(e)):!0:!1}function lu(e){return Array.isArray(e)?e.map(lu):e&&typeof e==`object`?Object.keys(e).sort().reduce((t,n)=>(t[n]=lu(e[n]),t),{}):e}function uu(e,t){return JSON.stringify(lu(e))===JSON.stringify(lu(t))}function du(e,t,n,r){let i=iu(n);for(let n of e||[])for(let e of n.terminology?.properties||[])if(!(e.entityType&&e.entityType!==t)&&au(e.path,i))return e.label;return r||zu(i)}function fu(e,t,n){let r=iu(n),i=[],a,o,s=!1,c=!1;if(!t||!tu.has(t.type))return{entityType:t?.type,path:r,label:du(e,t?.type,r),disallowed:!1,required:!1,rules:i};for(let n of e||[])for(let e of n.rules||[])!(`entityType`in e)||!(`path`in e)||e.entityType===t.type&&au(e.path,r)&&(i.push(e),e.type===`disallow-property`&&(s=!0),e.type===`require-non-empty`&&(c=!0),e.type===`fixed-value`&&!o&&(a=e.value,o=e,c=!0));return{entityType:t.type,path:r,label:du(e,t.type,r),disallowed:s,required:c,fixedValue:a,fixedValueRule:o,rules:i}}function pu(e,t,n){let r=e||[],i=mu(t,n),a=[];for(let e of r)for(let[n,r]of(e.rules||[]).entries())a.push(...hu(e,r,n,i,t));return{specifications:r,results:a,counts:wu(a)}}function mu(e,t){let n=[],r=new Set;function i(t){let a=Eu(t);if(!a)return;if(a.type===`SpecificResource`){i(t?.source);return}let o=Tu(e,t)||Tu(e,a);if(!o||!o.type)return;let s=`${o.type}:${o.id||JSON.stringify(a)}`;if(!r.has(s)){r.add(s),tu.has(o.type)&&n.push({ref:{id:o.id,type:o.type},resource:o});for(let e of Du(o))i(e)}}return i(t),n}function hu(e,t,n,r,i){switch(t.type){case`disallow-property`:case`require-non-empty`:case`fixed-value`:return gu(e,t,n,r);case`iiif:canvas-with-image-service`:return[_u(e,t,n,r,i)];case`iiif:thumbnail-from-body-service`:return vu(e,t,n,r,i);case`iiif:valid-rights`:return yu(e,t,n,r);case`iiif:required-statement`:return bu(e,t,n,r);case`iiif:metadata-template`:return xu(e,t,n,r);default:return[]}}function gu(e,t,n,r){let i=r.filter(e=>e.ref.type===t.entityType),a=du(e?[e]:[],t.entityType,t.path);return i.length?i.map(({ref:r,resource:i})=>{let o=ou(i,t.path),s=cu(o);if(t.type===`disallow-property`)return Su(e,t,n,{target:r,path:t.path,status:s?`disallowed`:`satisfied`,displayLabel:a,actual:o,message:s?`${a} is present but is not allowed.`:`${a} is not present.`,editorTarget:Cu(r,t.path)});if(t.type===`require-non-empty`)return Su(e,t,n,{target:r,path:t.path,status:s?`satisfied`:`missing`,displayLabel:a,actual:o,message:s?`${a} has a value.`:`${a} must be filled in.`,editorTarget:Cu(r,t.path)});let c=uu(o,t.value);return Su(e,t,n,{target:r,path:t.path,status:c?`satisfied`:s?`invalid`:`missing`,displayLabel:a,expected:t.value,actual:o,message:c?`${a} matches the required value.`:s?`${a} does not match the required value.`:`${a} must use the required value.`,editorTarget:Cu(r,t.path)})}):[Su(e,t,n,{status:`not-applicable`,displayLabel:a,message:`No ${t.entityType} resources were found for ${a}.`,path:t.path})]}function _u(e,t,n,r,i){let a=r.filter(e=>e.ref.type===`Canvas`),o=Ou(t),s=a.find(({resource:e})=>ku(Au(e,i),o));return Su(e,t,n,{target:s?.ref,status:s?`satisfied`:`missing`,displayLabel:t.label||`Canvas image service`,expected:o,message:s?`A canvas contains the required image service.`:o.length?`A canvas must contain one of the required image services: ${o.join(`, `)}.`:`A canvas must contain a painting body with an image service.`,editorTarget:s?Cu(s.ref,[`items`]):void 0})}function vu(e,t,n,r,i){let a=t.entityType||`Canvas`,o=r.filter(e=>e.ref.type===a);return o.length?o.map(({ref:o,resource:s})=>{let c=a===`Manifest`?r.filter(e=>e.ref.type===`Canvas`).flatMap(e=>Au(e.resource,i)):Au(s,i),l=ju(s,c,i),u=cu(s.thumbnail);return Su(e,t,n,{target:o,path:[`thumbnail`],status:l?`satisfied`:c.length?u?`invalid`:t.requireThumbnail===!1?`not-applicable`:`missing`:`not-applicable`,displayLabel:du([e],o.type,[`thumbnail`],`Thumbnail`),expected:c,actual:s.thumbnail,message:l?`Thumbnail uses the same image service as the painting content.`:c.length?u?`Thumbnail does not use the same image service as the painting content.`:`Thumbnail must be created from the painting image service.`:`No painting image service was found to compare against.`,editorTarget:Cu(o,[`thumbnail`])})}):[Su(e,t,n,{status:`not-applicable`,displayLabel:`Thumbnail`,message:`No ${a} resources were found for thumbnail checks.`})]}function yu(e,t,n,r){let i=t.entityType||`Manifest`,a=r.filter(e=>e.ref.type===i),o=t.allowed||[];return a.map(({ref:r,resource:i})=>{let a=i.rights,s=cu(a),c=typeof a==`string`&&o.map(Fu).includes(Fu(a));return Su(e,t,n,{target:r,path:[`rights`],status:c?`satisfied`:!s&&t.required!==!1?`missing`:`invalid`,displayLabel:du([e],r.type,[`rights`],`Rights`),expected:o,actual:a,message:c?`Rights uses an allowed URI.`:!s&&t.required!==!1?`Rights must use an allowed URI.`:`Rights is not one of the allowed URIs.`,editorTarget:Cu(r,[`rights`])})})}function bu(e,t,n,r){let i=t.entityType||`Manifest`;return r.filter(e=>e.ref.type===i).map(({ref:r,resource:i})=>{let a=i.requiredStatement,o=t.label?Iu(a?.label,t.label):cu(a?.label),s=t.value||t.valueRequired!==!1,c=t.value?Iu(a?.value,t.value):!s||cu(a?.value),l=cu(a);return Su(e,t,n,{target:r,path:[`requiredStatement`],status:o&&c?`satisfied`:l?`invalid`:`missing`,displayLabel:du([e],r.type,[`requiredStatement`],`Required statement`),expected:t.value||t.label,actual:a,message:o&&c?`Required statement is complete.`:l?`Required statement does not match the specification.`:`Required statement must be filled in.`,editorTarget:Cu(r,[`requiredStatement`])})})}function xu(e,t,n,r){let i=t.entityType||`Manifest`,a=r.filter(e=>e.ref.type===i),o=[];for(let{ref:r,resource:i}of a){let a=Array.isArray(i.metadata)?i.metadata:[];t.items.forEach((i,s)=>{let c=a.find(e=>Iu(e?.label,i.label)),l=i.value?Iu(c?.value,i.value):i.valueRequired?cu(c?.value):!0,u=c&&l?`satisfied`:c&&i.value?`invalid`:`missing`,d=Ru(i.label);o.push(Su(e,t,n,{idSuffix:`metadata-${s}`,target:r,path:[`metadata`],status:u,displayLabel:d||`Metadata`,expected:i.value||i.label,actual:c,message:c&&l?`${d||`Metadata`} is present.`:c?`${d||`Metadata`} needs a value.`:`${d||`Metadata`} metadata must be added.`,editorTarget:Cu(r,[`metadata`])}))})}return o}function Su(e,t,n,r){let i=t.id||`${t.type}-${n}`,a=r.idSuffix?`-${r.idSuffix}`:``;return{id:`${e.id}-${i}-${r.target?.type||`root`}-${r.target?.id||`none`}${a}`,specificationId:e.id,specificationLabel:e.label,ruleId:i,ruleType:t.type,ruleLabel:t.label||r.displayLabel,ruleIndex:n,target:r.target,path:r.path,status:r.status,displayLabel:r.displayLabel,message:t.message||r.message,expected:r.expected,actual:r.actual,editorTarget:r.editorTarget}}function Cu(e,t){let n=t[0];return{resource:e,propertyPath:t,selectedTab:n===`metadata`?`@manifest-editor/metadata`:n&&ru.has(n)?`@manifest-editor/descriptive-properties`:void 0}}function wu(e){let t={...nu};for(let n of e)t[n.status]+=1;return t}function Tu(e,t){let n=Eu(t);if(!n)return t;try{return e.get(n,{skipSelfReturn:!1})||t}catch{try{return e.get(n)||t}catch{return t}}}function Eu(e){return!e||typeof e!=`object`?null:e.type===`SpecificResource`?{id:e.id||e.source?.id||``,type:`SpecificResource`}:typeof e.id==`string`&&typeof e.type==`string`?{id:e.id,type:e.type}:null}function Du(e){if(!e||typeof e!=`object`)return[];let t=[];for(let n of[`items`,`structures`,`annotations`,`thumbnail`,`provider`,`homepage`,`rendering`,`seeAlso`,`body`,`target`,`source`]){let r=e[n];Array.isArray(r)?t.push(...r):r&&t.push(r)}return t}function Ou(e){return[...e.serviceIds||[],...e.serviceId?[e.serviceId]:[]].filter(Boolean)}function ku(e,t){let n=new Set(e.filter(Boolean));return t.length?t.some(e=>n.has(e)):n.size>0}function Au(e,t){let n=Pu(t,e?.items),r=[];for(let e of n){let n=Pu(t,e?.items);for(let e of n)if((Array.isArray(e?.motivation)?e.motivation:[e?.motivation]).includes(`painting`))for(let n of Mu(e?.body,t))r.push(...Nu(n))}return Array.from(new Set(r))}function ju(e,t,n){let r=Pu(n,e?.thumbnail);if(!r.length||!t.length)return!1;for(let e of r){let n=Nu(e),r=typeof e?.id==`string`?e.id:``;if(n.some(e=>t.includes(e))||t.some(e=>r.startsWith(e)))return!0}return!1}function Mu(e,t){let n=Tu(t,e);return n?Array.isArray(n)?n.flatMap(e=>Mu(e,t)):n.type===`SpecificResource`?Mu(n.source,t):n.type===`Choice`?n.items?.flatMap(e=>Mu(e,t))||[]:[n]:[]}function Nu(e){let t=e?.service||e?.services,n=Array.isArray(t)?t:t?[t]:[],r=[];for(let e of n){let t=typeof e==`string`?e:e?.id||e?.[`@id`];typeof t==`string`&&t&&r.push(t)}return Array.from(new Set(r))}function Pu(e,t){if(!t)return[];let n=Array.isArray(t)?t:[t];try{let t=e.get(n);if(Array.isArray(t))return t.filter(Boolean)}catch{}return n.map(t=>Tu(e,t)).filter(Boolean)}function Fu(e){return e.replace(/^https:/,`http:`).replace(/\/?$/,`/`)}function Iu(e,t){return typeof t==`string`?Lu(e).some(e=>e===t):uu(e,t)}function Lu(e){return e?typeof e==`string`?[e.trim()].filter(Boolean):Array.isArray(e)?e.flatMap(Lu):typeof e==`object`?Object.values(e).flatMap(Lu):[]:[]}function Ru(e){return typeof e==`string`?e:Lu(e)[0]||``}function zu(e){return(e[e.length-1]||`Property`).replace(/([A-Z])/g,` $1`).replace(/[-_]/g,` `).replace(/^./,e=>e.toUpperCase())}const Bu=O([]);function Vu({children:e,specifications:t}){let n=N(()=>t||[],[t]);return L(Bu.Provider,{value:n,children:e})}function Hu(){return A(Bu)}function Uu(e){let t=Oi(),n=Hu(),r=e||t;return qe((e,t)=>pu(n,t,r),[n,r.id,r.type])}function Wu(){let e=Hu();return N(()=>({getLabel(t,n,r){return du(e,t,n,r)}}),[e])}function Gu(e,t){let n=Hu();return N(()=>fu(n,e,t),[n,e?.id,e?.type,JSON.stringify(t)])}const Ku={},qu=O(`global`);function Ju(){return A(qu)}function Yu(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function Xu(e){let t=Ju(),[,n]=Oe(e=>e+1,0),r=N(()=>(Ku[t]||(Ku[t]={}),Ku[t][e]||(Ku[t][e]={name:e,emitter:pt(),status:`idle`,promise:Promise.resolve(),abort:new AbortController,reject:()=>void 0,resolve:()=>void 0}),Ku[t][e]),[t,e]);return Zu(r,`abort`,n),Zu(r,`error`,n),Zu(r,`complete`,n),Zu(r,`running`,n),r}function Zu(e,t,n){let r=k(()=>n(e),[n]);j(()=>{let n=e.emitter;return n.on(t,r),()=>n.off(t,r)},[t,r,e.emitter])}const Qu=()=>void 0;function $u(e,t){let n=Xu(e);return Zu(n,`complete`,t||Qu),[e=>{n.status===`running`&&(n.abort.abort(),n.emitter.emit(`abort`)),n.error&&(n.error=``);let t=Yu();t.promise.then(()=>n.emitter.emit(`complete`)).catch(()=>n.emitter.emit(`error`)),n.status=`running`,n.request=e,n.promise=t.promise,n.resolve=t.resolve,n.reject=t.reject,n.emitter.emit(`running`)},n]}function ed(e,t){let n=Xu(e);return Zu(n,`running`,t),[e=>{n.status===`running`&&(n.response=e,n.status=`complete`,n.resolve())},n,(e,t)=>{n.status===`running`&&(n.error=t||e,n.status=`error`,n.reject(e))}]}function td({children:e}){return L(qu.Provider,{value:N(()=>`id-${Date.now()}`,[]),children:e})}function nd(e){return!1}function rd({as:e,reference:t,onReference:n,onLink:r,onAnalysis:i,onDropReference:a,onDropLink:o,onDropAnalysis:s,onPasteReference:c,onPasteLink:l,onPasteAnalysis:u,...d}){let f=e||`div`,p=a||n,m=c||n,h=l||r,g=u||i,_=N(()=>t,[t?.id,t?.type]),v=k(function(e){e.defaultPrevented||(e.preventDefault(),e.clipboardData&&_&&_.id&&_.type&&e.clipboardData.setData(`application/json+vault`,JSON.stringify({id:_.id,type:_.type})))},[_]),y=k(async function(e){if(!e.defaultPrevented&&(e.preventDefault(),e.clipboardData)){if(d.onLoading&&d.onLoading(),m){let t=e.clipboardData.getData(`application/json+vault`);if(t)try{let e=JSON.parse(t);e&&e.id&&e.type&&m(e)}catch{}}if(h||g){let t=e.clipboardData.getData(`text`);if(t.startsWith(`http`)){let e=t.split(`
1511
+ `);for(let t of e){if(g)try{let e=await nd(t);if(e){g(e);continue}}catch{}h&&h(t)}}}d.onComplete&&d.onComplete()}},[]),b=k(function(e){e.defaultPrevented||(e.preventDefault(),e.dataTransfer&&d.draggable&&(e.dataTransfer.effectAllowed=`all`,_&&_.id&&_.type&&e.dataTransfer.setData(`application/json+vault`,JSON.stringify({id:_.id,type:_.type}))))},[]);return L(f,{onCopy:v,onPaste:y,onDrop:k(async function(e){if(e.preventDefault(),e.dataTransfer){if(p){let t=e.dataTransfer.getData(`application/json+vault`);if(t)try{let n=JSON.parse(t);n&&n.id&&n.type&&p(n,e)}catch{return}}let t=e.dataTransfer.getData(`application/json`);if(t){JSON.parse(t);return}if(e.dataTransfer.getData(`text/plain`))return}},[]),onDragOver:k(e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`)},[]),onDragStart:b,tabIndex:-1,...d})}export{Mo as AppHeader,Io as AppMenuProvider,hi as AppProvider,ui as AppReactContext,ki as AppResourceInstanceProvider,Ai as AppResourceProvider,di as AppStateReactContext,Ne as AtlasStoreProvider,Fe as AtlasStoreReactContext,_o as BackgroundActionToasts,jo as BackgroundActionsMenu,go as BackgroundActionsMount,tr as BackgroundActionsProvider,er as BackgroundActionsReactContext,Fs as BaseAnnotationCreator,zs as BaseEditor,Is as BaseEditorBackButton,Ls as BaseEditorCloseButton,jt as CANVAS_PROGRESS_META_NAMESPACE,Mt as CANVAS_PROGRESS_STATUS_META_KEY,Zs as ConfigEditor,At as ConfigProvider,Et as ConfigReactContext,ec as ContextMenuProvider,$s as ContextMenuReactContext,As as CreatorInitialData,ya as EditingStack,sa as EditingStackContext,Oc as EventEmitterProvider,Tc as ExportPanel,ja as FLAG_TAG,Ss as HOMEPAGE_COLLECTION,Pc as HandleContainer,zc as HandleControls,ba as InlineEditingStack,El as Layout,xa as LayoutActionsReactContext,Ca as LayoutModeReactContext,Sa as LayoutStateReactContext,Zt as ManifestEditorCanvasProgressOverlay,eo as ManifestEditorTagBadge,$a as ManifestEditorTagIcon,to as ManifestEditorTagOverlay,Nl as ManifestPaginationNavigation,vt as MessagePortClientVault,_s as ModularPanel,fs as ModularPanelHeader,ps as ModulePanelButton,yi as MultiAppProvider,es as PanelError,ci as PluginConfigBridge,Yr as PluginGlobalConfigReactContext,Js as PluginManager,Xr as PluginProvider,Jr as PluginReactContext,ra as PreviewButton,Hi as PreviewProvider,Ts as PreviewVaultBoundary,ws as PreviewVaultContext,li as PrimeAppReactContext,Dc as ReactEmitterContext,Jl as ResourceEditingProvider,Wl as ResourceEditingReactContext,Dt as SaveConfigReactContext,eu as ShellProvider,Vu as SpecificationProvider,Aa as TAGS_META_KEY,ka as TAGS_META_NAMESPACE,td as TaskBridge,oo as ToastProvider,rd as UniversalCopyTarget,Wa as addResourceTag,Ho as analyse,Wo as analyseJson,Kr as applyPlugins,Ns as baseCreator,Bs as baseEditor,Bt as clearCanvasProgressStatus,Ht as clearCanvasProgressStatuses,mu as collectSpecificationResources,cr as copyToClipboard,or as createActionIdentity,Gn as createBackgroundActionsStore,sr as createDownload,Bl as createIframeVaultBridge,Qn as createLocalForageBackgroundActionPersistence,Ut as createManifestEditorCanvasProgressApi,Xa as createManifestEditorTagsApi,Br as createPluginRuntimeApi,qr as createPluginStore,vs as createPreviewVault,Wt as createTrackingCanvasProgressApi,Vo as detectMedia,br as disablePluginInConfig,Rs as editBasedOnResource,Vr as enablePluginAndDependenciesInConfig,yr as enablePluginInConfig,pu as evaluateSpecifications,dr as extendApp,qc as filterSupportedPanels,sn as getAvailableBackgroundActionGroups,en as getBackgroundActionInstanceKey,Lt as getCanvasProgressStatus,Rt as getCanvasProgressStatusFromState,Ml as getDefaultLayoutState,jl as getDefaultPanelState,zr as getEffectivePluginSettings,mr as getEmptyPluginState,Pr as getEnabledPluginsForApp,qo as getFormat,Jo as getImageDimensions,ar as getManifestNomalized,jr as getPluginCompatibilityReason,Rr as getPluginDefaultSettings,Nr as getPluginSelectionSource,Fr as getPluginSettingsFromConfig,fu as getPropertyPolicy,Ga as getResourceTag,qa as getResourceTagGroups,Va as getResourceTags,Ha as getResourceTagsFromState,Jc as getSupportedPanelFallback,du as getTerminologyLabel,ou as getValueAtPath,cu as hasMeaningfulValue,Ja as hasResourceTag,Er as isLazyPlugin,Tr as isMappedPlugin,ts as isPinnableState,Ar as isPluginCompatible,Mr as isPluginSelected,Al as layoutReducer,ur as mapApp,wr as mapLazyPlugin,Cr as mapPlugin,tn as mergeBackgroundActionDefinitions,Tt as mergeConfig,wt as mergePartialConfig,kr as mergeProviderPlugins,rn as normaliseBackgroundActionError,lu as normaliseJsonValue,Dr as normalisePlugin,_r as normalisePluginAppConfig,vr as normalisePluginAppsConfig,Or as normalisePlugins,iu as normaliseSpecificationPath,X as panelIds,ns as panelSizing,Sr as pluginAppConfigEquals,Ro as polygonToBoundingBox,lr as randomId,Ka as removeResourceTag,rs as renderHelper,xr as resetPluginInConfig,Lr as resetPluginSettingsInConfig,Jn as runBackgroundAction,zt as setCanvasProgressStatus,Vt as setCanvasProgressStatuses,Ir as setPluginSettingsInConfig,Ua as setResourceTags,su as setValueAtPath,nn as sortBackgroundActionDefinitions,uu as specificationJsonEquals,au as specificationPathEquals,Ya as toggleResourceTag,Ec as useAnnotationCreatorState,ga as useAnnotationPageEditor,q as useApp,fi as useAppInstance,Po as useAppMenu,Fo as useAppMenuItem,Oi as useAppResource,Di as useAppResourceInstance,pi as useAppState,_i as useApps,Lo as useAtlasStore,ho as useAvailableBackgroundActions,Da as useAvailableLayouts,ir as useBackgroundActionHistory,rr as useBackgroundActionInstance,K as useBackgroundActionsStore,nr as useBackgroundActionsStoreApi,Kt as useCanvasProgressActions,Gt as useCanvasProgressStatus,ma as useCollectionEditor,Ot as useConfig,fa as useCreatingResource,Es as useCreator,ic as useCustomContextMenu,Vs as useDecayState,Gl as useEditingContext,ua as useEditingResource,da as useEditingResourceStack,la as useEditingStack,_a as useEditor,kc as useEmitter,ti as useEnabledPlugins,Ac as useEvent,ha as useGenericEditor,Yo as useHighlightedImageResource,Zo as useHoverHighlightImageResource,ks as useInitialData,Ds as useInlineCreator,Ta as useLayoutActions,Ea as useLayoutMode,Oa as useLayoutProvider,wa as useLayoutState,_e as useLocalStorage,pa as useManifestEditor,jc as useMatchMedia,ve as useOptionalLocalStorage,Zr as useOptionalPluginStoreApi,ql as useOptionalResource,Dl as usePanelActions,ni as usePluginActions,ai as usePluginConfigApi,ri as usePluginRuntimeApi,ii as usePluginSettings,Qr as usePluginStoreApi,ei as usePlugins,Wi as usePreviewContext,Cs as usePreviewHistory,ys as usePreviewVault,Ui as usePreviews,oi as useResolvedPluginApp,Kl as useResource,nc as useResourceContextMenuItems,Qa as useResourceTagActions,Za as useResourceTags,kt as useSaveConfig,Mc as useSaveVault,us as useSetCustomTitle,Gu as useSpecificationPropertyPolicy,Uu as useSpecificationReport,Wu as useSpecificationTerminology,Hu as useSpecifications,Nc as useSvgTools,Xu as useTask,$u as useTaskDispatch,Zu as useTaskEvent,ed as useTaskRunner,Xo as useTemporaryHighlight,so as useToasts};
1512
1512
  //# sourceMappingURL=index.js.map