@manifest-editor/manifest-preset 2.1.0 → 2.2.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/components-Bl3IFBTG.js +24 -0
- package/dist/components-Bl3IFBTG.js.map +1 -0
- package/dist/components-CoVIXUVJ.cjs +24 -0
- package/dist/components-CoVIXUVJ.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +18 -37
- package/dist/components.d.cts.map +1 -1
- package/dist/components.d.ts +18 -37
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +1 -1
- package/dist/index.cjs +12 -19
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +21 -2
- package/dist/index.d.cts +14 -19
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +13 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -21
- package/dist/index.js.map +1 -1
- package/dist/rolldown-runtime-DK3Fl9T5.js +1 -0
- package/package.json +23 -23
- package/dist/chunk-rxeKSoNa.js +0 -1
- package/dist/components-CPY_Y0GC.js +0 -24
- package/dist/components-CPY_Y0GC.js.map +0 -1
- package/dist/components-D_51CKYD.cjs +0 -23
- package/dist/index.css.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./components-D_51CKYD.cjs`);let t=require(`@manifest-editor/annotations`);t=e.h(t);let n=require(`@manifest-editor/canvas-label-generator`);n=e.h(n);let r=require(`@manifest-editor/creators`),i=require(`@manifest-editor/editors`),a=require(`@manifest-editor/shell`),o=require(`@iiif/helpers`),s=require(`@iiif/helpers/vault/actions`),c=require(`@iiif/parser/image-3`),l=require(`@manifest-editor/components`),u=require(`react`);u=e.h(u);let d=require(`react-iiif-vault`),f=require(`react/jsx-runtime`),p=require(`styled-components`);p=e.h(p);let m=require(`@iiif/parser`),h=require(`react-aria-components`),g=require(`zustand`),_=require(`@manifest-editor/editor-api`),v=require(`react-aria`),y=require(`tailwind-merge`),b=require(`react-dom`),x=require(`@manifest-editor/creator-api`);const S=`@manifest-editor/manifest-preset/bulk-thumbnail-builder`,C=`manifest-preset:bulk-thumbnail-builder-config`,w=`manifest-preset:bulk-thumbnail-builder-results`,T=[256,384,512,768,1024,1536,2048];function E(e={}){let t=e.requestConfig||be;return{id:`@manifest-editor/manifest-preset/bulk-thumbnail-builder`,label:`Bulk Thumbnail Builder`,summary:`Generate missing manifest and canvas thumbnails from painting annotations`,section:`Thumbnails`,order:10,resourceTypes:[`Manifest`],render:e=>(0,f.jsxs)(f.Fragment,{children:[Se(e.definition.id),De(e.definition.id)]}),onResults:e=>Ee(e.definition.id,e.instance?.result),supports:e=>e.vault.get(e.target)?.type===`Manifest`,prepare:async e=>{e.setActionLabel(`Preparing thumbnails`),e.setActionStatus(`preparing`,`Scanning canvases`);let n=O(e),r=await k(e,n),i=r.sizes.length?r.sizes:ce(),a=await t(e,n,q({requestedWidth:i[0]?.width||256,multiImageMode:(n.multiImageCanvases,`first`),selectedLayerIndex:0,replaceExisting:!1}),i,r);return a===!1?!1:D(n,a,i,r)},run:async e=>{let t=q(_e(e.plan)?.options||{}),n=ae(e.plan),r=new Map;if(e.setActionLabel(`Building thumbnails`),!e.plan?.tasks.length)return e.setActionStatus(`running`,`No thumbnail changes found`),e.setActionProgress({current:0,total:0,label:`No thumbnails`}),n;e.canvasProgress.setStatuses(e.plan.tasks.map(e=>e.target).filter(e=>!!e&&e.type===`Canvas`),`queued`),await e.tasks.runEach(async i=>{let a=i.input;if(!a)return n.skippedTargets.push({targetId:i.id,targetType:`Unknown`,reason:`Missing thumbnail task input`}),G(`Missing thumbnail task input`);let o=e.vault.get({id:a.targetId,type:a.targetType});if(!o)return n.skippedTargets.push({targetId:a.targetId,targetType:a.targetType,reason:`Target resource no longer exists`}),G(`Target missing`);if(oe(o)&&!t.replaceExisting)return n.skippedTargets.push({targetId:a.targetId,targetType:a.targetType,reason:`Thumbnail already exists`}),G(`Already has thumbnail`);let s=H(e,a);if(!s)return n.skippedTargets.push({targetId:a.targetId,targetType:a.targetType,reason:`No source canvas with painting annotations found`}),G(`No source canvas`);let c=await P(e,s,t,r);return c?(V(e,a,c),n.added+=1,a.kind===`manifest`?n.manifestAdded=!0:n.canvasAdded+=1,c.verified&&(n.verified+=1),c.usedConfiguredSize&&(n.usedConfiguredSizes+=1),c.composite&&(n.composites+=1),n.changes.push({targetId:a.targetId,targetType:a.targetType,thumbnailId:c.id,width:c.width,height:c.height}),e.appendActionLog(`Added thumbnail`,`info`,{targetId:a.targetId,targetType:a.targetType,thumbnailId:c.id}),{result:{thumbnailId:c.id,width:c.width,height:c.height},statusText:`Thumbnail added`}):(n.skippedTargets.push({targetId:a.targetId,targetType:a.targetType,reason:`No thumbnail image could be generated`}),G(`No thumbnail image`))},{progressLabel:(e,t,n)=>`Building thumbnails ${t+1}/${n}`});let i=e.tasks.getAll();return n.failed=i.filter(e=>e.status===`error`).length,n.skipped=i.filter(e=>e.status===`skipped`).length,e.setActionStatus(`running`,`Added ${n.added}/${n.total} thumbnails`),e.setActionProgress({current:n.total,total:n.total,label:`Thumbnails complete`}),n}}}function D(e,t,n,r){let i=q(t),a=[];(!e.manifestHasThumbnail||i.replaceExisting)&&e.manifestSourceCanvasId&&a.push({id:`${e.manifestId}#thumbnail`,label:`Manifest thumbnail`,target:{id:e.manifestId,type:`Manifest`,label:`Manifest`,scope:`root`},input:{kind:`manifest`,targetId:e.manifestId,targetType:`Manifest`,canvasId:e.manifestSourceCanvasId},status:`queued`});for(let t of e.canvases)t.hasThumbnail&&!i.replaceExisting||a.push({id:`${t.id}#thumbnail`,label:t.label||`Canvas thumbnail`,target:{id:t.id,type:`Canvas`,label:t.label||`Canvas`,scope:`canvas`},input:{kind:`canvas`,targetId:t.id,targetType:`Canvas`,canvasId:t.id},status:`queued`});return{version:1,data:{options:i,preview:e,sizeChoices:n,firstServiceProbe:r},tasks:a}}function O(e){let t=e.vault.get(e.target),n=M(e,t),r=[],i=0,a=0,o=0,s;for(let t of n){let n=N(e,t),c=oe(t);c||(i+=1),n.length>1&&(a+=1),n.length>o&&(o=n.length),!s&&n.length&&(s=t.id),r.push({id:t.id,label:se(t,`Canvas`),hasThumbnail:c,paintingLayerCount:n.length})}return{manifestId:t?.id||e.target.id,manifestHasThumbnail:oe(t),manifestSourceCanvasId:s,totalCanvases:n.length,missingCanvasThumbnails:i,multiImageCanvases:a,maxLayerCount:o,canvases:r}}async function k(e,t){let n=j(e,t),r=n?.service,i=n?.imageUrl;if(!r&&!i)return{status:`not-found`,message:`No IIIF image service found in the painting annotations.`,sizes:[]};let a=r?pe(r):``;if(r&&!a)return{status:`error`,message:`The first IIIF image service has no id.`,sizes:le(r)};let o=r?me(a):he(i||``);return o?A(e,o,a||o.replace(/\/info\.json$/,``),r):{status:`error`,message:`The first IIIF image service could not be resolved.`,sizes:[]}}async function A(e,t,n,r){try{e.setActionStatus(`preparing`,`Loading first image service`);let i=await fetch(t,{signal:e.signal});return i.ok?{status:`loaded`,serviceId:n,infoUrl:t,sizes:le(K(await i.json(),n))}:{status:`error`,serviceId:n,infoUrl:t,message:`Unable to load info.json (${i.status}).`,sizes:r?le(r):[]}}catch(e){if(ye(e))throw e;return{status:`error`,serviceId:n,infoUrl:t,message:e instanceof Error?e.message:`Unable to load info.json.`,sizes:r?le(r):[]}}}function j(e,t){for(let n of t.canvases){let t=N(e,e.vault.get({id:n.id,type:`Canvas`}));for(let n of t){let t=R(e,n.resource);if(t)return{service:t};if(he(n.resource?.id))return{imageUrl:n.resource.id}}}return null}function M(e,t){return t?.items?.length?e.vault.get(t.items).filter(e=>e?.type===`Canvas`):[]}function N(e,t){if(!t)return[];let n=(0,o.createPaintingAnnotationsHelper)(e.vault).getPaintables(t),r=[];for(let[e,i]of n.items.entries()){if(i.type!==`image`||!i.resource)continue;let n=te(i.target,t);n&&r.push({annotationId:i.annotationId,label:se(i.resource,`Layer ${e+1}`),resource:i.resource,target:n,sourceSelector:i.selector||null})}return r}async function P(e,t,n,r){let i=N(e,t);if(!i.length)return null;if(i.length>1&&n.multiImageMode===`composite`)return I(e,t,i,n.requestedWidth,r);let a=i[i.length>1&&n.multiImageMode===`layer`?n.selectedLayerIndex:0];return a?F(e,a,n.requestedWidth,r):null}async function F(e,t,n,r){let i=await L(e,t,n,r);return i?{id:i.id,width:i.width,height:i.height,format:i.format,usedConfiguredSize:i.usedConfiguredSize,verified:i.verified,composite:!1}:null}async function I(e,t,n,r,i){if(typeof document>`u`)return null;let a=re({width:t.width||r,height:t.height||r},r),o=J(t.width)||a.width,s=J(t.height)||a.height,c=document.createElement(`canvas`);c.width=a.width,c.height=a.height;let l=c.getContext(`2d`);if(!l)return null;l.fillStyle=`#fff`,l.fillRect(0,0,a.width,a.height);let u=0,d=!1,f=!1;for(let t of n){let n=await L(e,t,Math.max(1,Math.round(t.target.width/o*a.width)),i);if(!n)continue;let r=await ie(n.id,e.signal);if(!r)continue;let c={x:t.target.x/o*a.width,y:t.target.y/s*a.height,width:t.target.width/o*a.width,height:t.target.height/s*a.height};l.drawImage(r,c.x,c.y,c.width,c.height),r.close?.(),u+=1,d=d||n.usedConfiguredSize,f=!0}return u?{id:c.toDataURL(`image/jpeg`,.86),width:a.width,height:a.height,format:`image/jpeg`,usedConfiguredSize:d,verified:f,composite:!0}:null}async function L(e,t,n,r){let i=U(t.sourceSelector),a=R(e,t.resource),o=a?await z(e,a,r):await ee(e,t.resource?.id,r);if(o?.service){let r=i?null:de(o.sizes,n);if(r)return{id:B(o.service,r,i||{full:!0}),width:r.width,height:r.height,format:`image/jpeg`,usedConfiguredSize:!0,verified:!1};let a={width:n,height:void 0},s=B(o.service,a,i||{full:!0});return await W(s,e.signal)?{id:s,width:a.width,height:fe(t.resource,o.service,i,a.width),format:`image/jpeg`,usedConfiguredSize:!1,verified:!0}:null}return typeof t.resource?.id!=`string`||!await W(t.resource.id,e.signal)?null:{id:t.resource.id,width:J(t.resource.width),height:J(t.resource.height),format:typeof t.resource.format==`string`?t.resource.format:`image/jpeg`,usedConfiguredSize:!1,verified:!0}}function R(e,t){return ve(t?.service).map(t=>e.vault.get(t)||t).filter(ge)[0]||null}async function z(e,t,n){let r=pe(t);if(!r)return{service:t,sizes:ue(t)};let i=me(r),a=n.get(i);if(a)return a;let o=(async()=>{let n=ue(t);if(n.length)return{service:K(t,r),sizes:n};try{let a=await fetch(i,{signal:e.signal});if(!a.ok)return{service:K(t,r),sizes:n};let o=K(await a.json(),r);return{service:o,sizes:ue(o)}}catch(e){if(ye(e))throw e;return{service:K(t,r),sizes:n}}})();return n.set(i,o),o}async function ee(e,t,n){if(typeof t!=`string`)return null;let r=he(t);if(!r)return null;let i=n.get(r);if(i)return i;let a=(async()=>{try{let t=await fetch(r,{signal:e.signal});if(!t.ok)return{service:null,sizes:[]};let n=K(await t.json(),r.replace(/\/info\.json$/,``));return{service:n,sizes:ue(n)}}catch(e){if(ye(e))throw e;return{service:null,sizes:[]}}})();return n.set(r,a),a}function B(e,t,n){let r=(0,c.createImageServiceRequest)(e);return(0,c.imageServiceRequestToString)({identifier:r.identifier,server:r.server,scheme:r.scheme,type:`image`,size:{max:!t.width&&!t.height,confined:!1,upscaled:!1,width:t.width,height:t.height},format:`jpg`,region:n,rotation:{angle:0},quality:`default`,prefix:r.prefix,originalPath:r.originalPath})}function V(e,t,n){let r={id:n.id,type:`Image`,format:n.format,width:n.width,height:n.height};e.vault.dispatch((0,s.batchActions)({actions:[(0,s.importEntities)({entities:{ContentResource:{[n.id]:r}}}),(0,s.addMappings)({mapping:{[n.id]:`ContentResource`}}),(0,s.modifyEntityField)({id:t.targetId,type:t.targetType,key:`thumbnail`,value:[{id:n.id,type:`ContentResource`}]})]}))}function H(e,t){if(t.canvasId){let n=e.vault.get({id:t.canvasId,type:`Canvas`});if(n&&N(e,n).length)return n}return M(e,e.vault.get(e.target)).find(t=>N(e,t).length)||null}function te(e,t){let n={x:0,y:0,width:J(t?.width)||1,height:J(t?.height)||1};try{let t=(0,o.expandTarget)(e).selector;if(t?.type===`BoxSelector`||t?.type===`TemporalBoxSelector`)return ne(t,n)}catch{}return n}function ne(e,t){let n=e.spatial;return n.unit===`percent`?{x:n.x/100*t.width,y:n.y/100*t.height,width:n.width/100*t.width,height:n.height/100*t.height}:{x:n.x,y:n.y,width:n.width,height:n.height}}function U(e){if(!e||e.type!==`BoxSelector`&&e.type!==`TemporalBoxSelector`)return null;let t=e.spatial;return{x:t.x,y:t.y,w:t.width,h:t.height,percent:t.unit===`percent`}}function re(e,t){let n=e.width>e.height?t/e.width:t/e.height;return{width:Math.max(1,Math.round(e.width*n)),height:Math.max(1,Math.round(e.height*n))}}async function W(e,t){try{let n=await fetch(e,{signal:t});return n.body?.cancel().catch(()=>void 0),n.ok}catch(e){if(ye(e))throw e;return!1}}async function ie(e,t){try{let n=await fetch(e,{signal:t});if(!n.ok)return null;let r=await n.blob();return createImageBitmap(r)}catch(e){if(ye(e))throw e;return null}}function ae(e){return{total:e?.tasks.length||0,added:0,skipped:0,failed:0,manifestAdded:!1,canvasAdded:0,verified:0,usedConfiguredSizes:0,composites:0,changes:[],skippedTargets:[]}}function G(e){return{taskStatus:`skipped`,result:{reason:e},statusText:e}}function oe(e){return Array.isArray(e?.thumbnail)&&e.thumbnail.length>0}function se(e,t){return(0,o.getValue)(e?.label,{defaultText:t})||t}function ce(){return T.map(e=>({width:e,label:`${e}px`,source:`standard`}))}function le(e){return ue(e).map(e=>({...e,label:e.height?`${e.width} x ${e.height}`:`${e.width}px`,source:`configured`}))}function ue(e){let t=J(e?.width),n=J(e?.height),r=[];for(let i of ve(e?.sizes)){let e=J(i?.width),a=J(i?.height)||(e&&t&&n?Math.round(e/t*n):void 0);e&&r.push({width:e,height:a})}return r.sort((e,t)=>e.width-t.width)}function de(e,t){let n=null;for(let r of e)(!n||Math.abs(r.width-t)<Math.abs(n.width-t))&&(n=r);return n}function fe(e,t,n,r){if(n?.w&&n?.h)return Math.round(r/n.w*n.h);let i=J(t.width)||J(e?.width),a=J(t.height)||J(e?.height);if(!(!i||!a))return Math.round(r/i*a)}function K(e,t){let n={...e};return n.id=n.id||n[`@id`]||t,n.type=n.type||n[`@type`]||`ImageService3`,n}function pe(e){let t=e?.id||e?.[`@id`];return typeof t==`string`?t:``}function me(e){try{if(e.endsWith(`default.jpg`)||e.endsWith(`default.png`))return(0,c.imageServiceRequestToString)({...(0,c.parseImageServiceRequest)(e),type:`info`})}catch{}return(0,c.canonicalServiceUrl)(e)}function he(e){if(typeof e!=`string`)return``;try{let t=(0,c.parseImageServiceRequest)(e);return t.type===`image`?(0,c.imageServiceRequestToString)({...t,type:`info`}):``}catch{return``}}function ge(e){if(!e||typeof e!=`object`)return!1;let t=e.type||e[`@type`];return String(t||``).startsWith(`ImageService`)||e.protocol===`http://iiif.io/api/image`||Array.isArray(e.sizes)||Array.isArray(e.tiles)}function q(e){let t=J(e.requestedWidth)||256,n=Math.max(0,Math.floor(J(e.selectedLayerIndex)||0));return{requestedWidth:t,multiImageMode:e.multiImageMode===`composite`||e.multiImageMode===`layer`?e.multiImageMode:`first`,selectedLayerIndex:n,replaceExisting:e.replaceExisting===!0}}function _e(e){return!e?.data||typeof e.data!=`object`?null:e.data}function J(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:void 0}function ve(e){return Array.isArray(e)?e:e?[e]:[]}function ye(e){return e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))}function be(e,t,n,r,i){return xe({actionId:e.definition.id,preview:t,defaults:n,sizeChoices:r,firstServiceProbe:i,signal:e.signal})}function xe(e){return new Promise(t=>{if(e.signal?.aborted||typeof window>`u`){t(!1);return}let n=!1,r=r=>{n||(n=!0,e.signal?.removeEventListener(`abort`,i),t(r))},i=()=>r(!1);e.signal?.addEventListener(`abort`,i,{once:!0}),window.dispatchEvent(new CustomEvent(C,{detail:{...e,resolve:r}}))})}function Se(e){return(0,f.jsx)(Ce,{actionId:e})}function Ce({actionId:e}){let[t,n]=(0,u.useState)(null),[r,i]=(0,u.useState)(q({}));(0,u.useEffect)(()=>{let t=t=>{let r=t.detail;r?.actionId===e&&(n(r),i(q(r.defaults)))};return window.addEventListener(C,t),()=>window.removeEventListener(C,t)},[e]),(0,u.useEffect)(()=>{if(!t?.signal)return;if(t.signal.aborted){n(null);return}let e=()=>n(null);return t.signal.addEventListener(`abort`,e,{once:!0}),()=>t.signal?.removeEventListener(`abort`,e)},[t]);let a=(0,u.useMemo)(()=>t?.sizeChoices.find(e=>e.width===r.requestedWidth),[t?.sizeChoices,r.requestedWidth]);if(!t)return null;let o=((!t.preview.manifestHasThumbnail||r.replaceExisting)&&t.preview.manifestSourceCanvasId?1:0)+(r.replaceExisting?t.preview.totalCanvases:t.preview.missingCanvasThumbnails),s=e=>{t.resolve(e===!1?!1:q(e)),n(null)},c=t.preview.multiImageCanvases>0;return(0,f.jsx)(l.Modal,{title:`Bulk Thumbnail Builder`,onClose:()=>s(!1),className:`max-w-4xl`,actions:(0,f.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,f.jsx)(`span`,{className:`text-sm text-zinc-400`,children:o===0?`All thumbnails up to date`:`${o} thumbnail${o===1?``:`s`} to ${r.replaceExisting?`add or replace`:`add`}`}),(0,f.jsx)(`button`,{type:`button`,className:`rounded-lg border border-zinc-200 bg-white px-4 py-2 text-sm text-zinc-700 hover:bg-zinc-50`,onClick:()=>s(!1),children:`Cancel`}),(0,f.jsx)(`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:cursor-not-allowed disabled:opacity-40`,disabled:o===0,onClick:()=>s(r),children:`Build thumbnails`})]}),children:(0,f.jsxs)(`div`,{className:`grid grid-cols-[220px_minmax(0,1fr)] h-[58vh]`,children:[(0,f.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto border-r border-zinc-100 p-5 text-sm text-zinc-700`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsxs)(`div`,{className:`mb-3 text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:[t.preview.totalCanvases,` canvas`,t.preview.totalCanvases===1?``:`es`]}),(0,f.jsx)(`div`,{className:`rounded-lg border border-zinc-100 bg-zinc-50 px-3 py-2.5 text-xs text-zinc-500 leading-relaxed`,children:a?.source===`configured`?(0,f.jsxs)(f.Fragment,{children:[`Sizes from image service · `,(0,f.jsxs)(`span`,{className:`font-mono text-zinc-700`,children:[a.width,`px`]})]}):`Using standard sizes — no image service detected`})]}),(0,f.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Thumbnail size`}),(0,f.jsx)(`select`,{className:`rounded-lg border border-zinc-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:outline-none`,value:r.requestedWidth,onChange:e=>i(t=>({...t,requestedWidth:Number(e.target.value)})),children:t.sizeChoices.map(e=>(0,f.jsx)(`option`,{value:e.width,children:e.label},`${e.source}-${e.width}-${e.height||0}`))})]}),(0,f.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2.5 rounded-lg border border-zinc-100 bg-zinc-50 px-3 py-2.5 hover:bg-zinc-100`,children:[(0,f.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 rounded border-zinc-300 text-me-primary-500 focus:ring-me-primary-500`,checked:r.replaceExisting,onChange:e=>i(t=>({...t,replaceExisting:e.currentTarget.checked}))}),(0,f.jsx)(`span`,{className:`text-sm font-medium text-zinc-700`,children:`Replace existing`})]}),c?(0,f.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Multi-image canvases`}),(0,f.jsxs)(`select`,{className:`rounded-lg border border-zinc-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:outline-none`,value:r.multiImageMode,onChange:e=>i(t=>({...t,multiImageMode:e.target.value})),children:[(0,f.jsx)(`option`,{value:`first`,children:`First image`}),(0,f.jsx)(`option`,{value:`composite`,children:`Full composite`}),(0,f.jsx)(`option`,{value:`layer`,children:`Specific layer`})]})]}):null,r.multiImageMode===`layer`&&c?(0,f.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Layer`}),(0,f.jsx)(`select`,{className:`rounded-lg border border-zinc-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:outline-none`,value:r.selectedLayerIndex,onChange:e=>i(t=>({...t,selectedLayerIndex:Number(e.target.value)})),children:Array.from({length:Math.max(t.preview.maxLayerCount,1)},(e,t)=>(0,f.jsxs)(`option`,{value:t,children:[`Layer `,t+1]},t))})]}):null]}),(0,f.jsxs)(`div`,{className:`flex min-w-0 flex-col`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between border-b border-zinc-100 px-4 py-2.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Canvas preview`}),(0,f.jsx)(`span`,{className:`text-xs text-zinc-400`,children:o>0?(0,f.jsxs)(`span`,{className:`font-medium text-me-primary-500`,children:[o,` will be built`]}):`All up to date`})]}),(0,f.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,f.jsx)(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4`,children:t.preview.canvases.map(e=>{let t=r.replaceExisting||!e.hasThumbnail;return(0,f.jsx)(we,{canvasId:e.id,label:e.label,willBuild:t,hasExisting:e.hasThumbnail,replacing:e.hasThumbnail&&r.replaceExisting,requestedWidth:r.requestedWidth},e.id)})})})]})]})})}function we({canvasId:e,label:t,willBuild:n,hasExisting:r,replacing:i,requestedWidth:a}){return(0,f.jsx)(d.CanvasContext,{canvas:e,children:(0,f.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,f.jsxs)(`div`,{className:[`relative aspect-square w-full overflow-hidden rounded-lg bg-zinc-100`,n?i?`ring-2 ring-me-primary-300`:`ring-2 ring-me-primary-500`:`opacity-40`].join(` `),children:[(0,f.jsx)(Te,{width:a},a),n?(0,f.jsx)(`span`,{className:[`absolute bottom-1 right-1 rounded px-1.5 py-0.5 text-[9px] font-bold uppercase leading-none tracking-wide`,i?`bg-me-primary-100 text-me-primary-600`:`bg-me-primary-500 text-white`].join(` `),children:i?`Replace`:`Add`}):null]}),(0,f.jsx)(`span`,{className:`truncate text-center text-[11px] leading-tight text-zinc-500`,children:t})]})})}function Te({width:e}){let t=(0,d.useThumbnail)({width:e},!0),[n,r]=(0,u.useState)(!1);return t?.id?(0,f.jsxs)(f.Fragment,{children:[n?null:(0,f.jsx)(`div`,{className:`absolute inset-0 animate-pulse bg-zinc-200`}),(0,f.jsx)(`img`,{src:t.id,alt:``,loading:`lazy`,className:[`absolute inset-0 h-full w-full object-contain transition-opacity duration-300`,n?`opacity-100`:`opacity-0`].join(` `),onLoad:()=>r(!0)})]}):(0,f.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-zinc-100`,children:(0,f.jsx)(`span`,{className:`text-[10px] text-zinc-300`,children:`No image`})})}function Ee(e,t){typeof window>`u`||window.dispatchEvent(new CustomEvent(w,{detail:{actionId:e,result:t}}))}function De(e){return(0,f.jsx)(Oe,{actionId:e})}function Oe({actionId:e}){let[t,n]=(0,u.useState)(null);return(0,u.useEffect)(()=>{let t=t=>{let r=t.detail;r?.actionId===e&&r.result&&n(r.result)};return window.addEventListener(w,t),()=>window.removeEventListener(w,t)},[e]),t?(0,f.jsx)(l.Modal,{title:`Thumbnail results`,onClose:()=>n(null),className:`max-w-2xl`,children:(0,f.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-0 text-sm text-zinc-700`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-6 border-b border-zinc-100 px-5 py-4`,children:[(0,f.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5`,children:[(0,f.jsx)(`span`,{className:`text-2xl font-semibold leading-none text-zinc-900`,children:t.added}),(0,f.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-zinc-400`,children:`Added`})]}),t.skipped>0?(0,f.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5`,children:[(0,f.jsx)(`span`,{className:`text-2xl font-semibold leading-none text-zinc-500`,children:t.skipped}),(0,f.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-zinc-400`,children:`Skipped`})]}):null,t.failed>0?(0,f.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5`,children:[(0,f.jsx)(`span`,{className:`text-2xl font-semibold leading-none text-red-500`,children:t.failed}),(0,f.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-zinc-400`,children:`Failed`})]}):null,(0,f.jsx)(`div`,{className:`ml-auto text-xs text-zinc-400`,children:t.verified>0?`${t.verified} verified`:null})]}),(0,f.jsxs)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto`,style:{maxHeight:`52vh`},children:[t.changes.length?(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-zinc-100 bg-zinc-50 px-5 py-2 text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Added thumbnails`}),t.changes.map(e=>(0,f.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-3 border-b border-zinc-50 px-5 py-2.5 last:border-0 hover:bg-zinc-50`,children:[(0,f.jsxs)(`div`,{className:`min-w-0`,children:[(0,f.jsx)(`div`,{className:`truncate text-xs font-medium text-zinc-700`,children:e.targetId}),(0,f.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[10px] text-zinc-400`,children:e.thumbnailId})]}),(0,f.jsx)(`div`,{className:`flex-none self-center rounded bg-green-50 px-2 py-0.5 text-xs font-medium text-green-700`,children:e.width?`${e.width}${e.height?`×${e.height}`:`px`}`:e.targetType})]},`${e.targetType}-${e.targetId}`))]}):null,t.skippedTargets.length?(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-zinc-100 bg-zinc-50 px-5 py-2 text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Skipped`}),t.skippedTargets.map(e=>(0,f.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-3 border-b border-zinc-50 px-5 py-2.5 last:border-0 hover:bg-zinc-50`,children:[(0,f.jsx)(`div`,{className:`min-w-0`,children:(0,f.jsx)(`div`,{className:`truncate text-xs font-medium text-zinc-700`,children:e.targetId})}),(0,f.jsx)(`div`,{className:`flex-none self-center text-xs text-zinc-400`,children:e.reason})]},`${e.targetType}-${e.targetId}-${e.reason}`))]}):null]})]})}):null}const ke=({title:e,...t})=>(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,height:`1em`,width:`1em`,...t,children:[(0,f.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,f.jsx)(`path`,{d:`M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z`}),e?(0,f.jsx)(`title`,{children:e}):null]});function Ae(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M18 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2m0 18H6V4h5v7l2.5-1.5L16 11V4h2zm-4.38-6.5L17 18H7l2.38-3.17L11 17z`})})}function je(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M17 4v16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m-4-2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h9c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2m0 18H4V4h9zm8-14v12c.83 0 1.5-.67 1.5-1.5v-9c0-.83-.67-1.5-1.5-1.5`})})}function Me(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M4 18V6zm2-2v-5h9v5zm-2 4q-.825 0-1.412-.587T2 18V6q0-.825.588-1.412T4 4h16q.825 0 1.413.588T22 6v6h-2V6H4v12h9v2zm12.5-8V9.5H9V8h9v4zM18 22v-3h-3v-2h3v-3h2v3h3v2h-3v3z`})})}function Ne(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M20 11H7.83l5.59-5.59L12 4l-8 8l8 8l1.41-1.41L7.83 13H20z`})})}function Pe(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`m12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z`})})}function Fe(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M21 3H3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2m0 16H3V5h18zM5 10h9v2H5zm0-3h9v2H5z`})})}function Ie(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M11.95 18q.525 0 .888-.363t.362-.887t-.362-.888t-.888-.362t-.887.363t-.363.887t.363.888t.887.362m.05 4q-2.075 0-3.9-.788t-3.175-2.137T2.788 15.9T2 12t.788-3.9t2.137-3.175T8.1 2.788T12 2t3.9.788t3.175 2.137T21.213 8.1T22 12t-.788 3.9t-2.137 3.175t-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12t-2.325-5.675T12 4T6.325 6.325T4 12t2.325 5.675T12 20m.1-12.3q.625 0 1.088.4t.462 1q0 .55-.337.975t-.763.8q-.575.5-1.012 1.1t-.438 1.35q0 .35.263.588t.612.237q.375 0 .638-.25t.337-.625q.1-.525.45-.937t.75-.788q.575-.55.988-1.2t.412-1.45q0-1.275-1.037-2.087T12.1 6q-.95 0-1.812.4T8.975 7.625q-.175.3-.112.638t.337.512q.35.2.725.125t.625-.425q.275-.375.688-.575t.862-.2`})})}function Le(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M11 16.175V5q0-.425.288-.712T12 4t.713.288T13 5v11.175l4.9-4.9q.3-.3.7-.288t.7.313q.275.3.287.7t-.287.7l-6.6 6.6q-.15.15-.325.213t-.375.062t-.375-.062t-.325-.213l-6.6-6.6q-.275-.275-.275-.687T4.7 11.3q.3-.3.713-.3t.712.3z`})})}function Re(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`m11 7.825l-4.9 4.9q-.3.3-.7.288t-.7-.313q-.275-.3-.288-.7t.288-.7l6.6-6.6q.15-.15.325-.212T12 4.425t.375.063t.325.212l6.6 6.6q.275.275.275.688t-.275.712q-.3.3-.712.3t-.713-.3L13 7.825V19q0 .425-.288.713T12 20t-.712-.288T11 19z`})})}const ze=(0,g.create)(e=>({isSplitting:!1,setIsSplitting:t=>e({isSplitting:t}),splitEffect:()=>()=>{e({isSplitting:!1})}})),Be=(0,u.memo)(function(e){let t=(0,d.useRange)({id:e.range.id}),{dragProps:n}=(0,v.useDrag)({isDisabled:!e.dragState,getItems(){return[{"text/plain":JSON.stringify(e.dragState)}]}}),r=(0,d.useVault)(),i=(0,u.useMemo)(()=>{if(!t)return[];let e=(0,o.createRangeHelper)(r).findAllCanvasesInRange(t),n=[],i=[];for(let t of e)n.includes(t.id)||(n.push(t.id),i.push(t));return i},[t,r]);return i.length===0?(0,f.jsx)(`div`,{children:`EMPTY`}):(0,f.jsxs)(`div`,{...n,className:(0,y.twMerge)(`grid relative grid-cols-2 grid-rows-2 aspect-square overflow-hidden w-full gap-1 p-1 bg-gray-300 rounded-md`,i.length===1&&`grid-cols-1 grid-rows-1`,i.length===2&&`grid-cols-1 grid-rows-2`,i.length===3&&`grid-cols-2 grid-rows-2`,i.length===4&&`grid-cols-2 grid-rows-2`),children:[(0,f.jsx)(`div`,{className:`absolute bottom-2 left-2 bg-white/80 p-1 rounded z-20 flex items-center justify-center text-black/50`,children:(0,f.jsx)(l.RangesIcon,{className:`w-5 h-5`})}),i.slice(0,4).map((t,n)=>(0,f.jsx)(l.CanvasThumbnailGridItem,{className:(0,y.twMerge)(`rounded`,i.length===3&&n===2&&`col-span-2`),hideLabel:!0,id:t.id,onClick:e.onClick},n))]})});function Ve(){let e=(0,d.useRange)(),t=(0,d.useVault)(),n=(0,a.useInlineCreator)();return e?(0,f.jsxs)(`div`,{className:`p-5 `,style:{paddingInlineStart:`calc(1.25rem + var(--manifest-editor-layout-left-sidebar-small, 0px))`,paddingInlineEnd:`calc(1.25rem + var(--manifest-editor-layout-right-sidebar-small, 0px))`},children:[(0,f.jsxs)(`div`,{className:`flex gap-5 items-baseline`,children:[(0,f.jsxs)(`div`,{className:`flex items-baseline gap-3 mb-3`,children:[(0,f.jsx)(`h3`,{className:`text-xl font-bold `,children:`Canvases at this level`}),(0,f.jsxs)(`span`,{children:[`(`,e.items?.length||0,` `,e.items?.length>1?`canvases`:`canvas`,`)`]})]}),(0,f.jsx)(`div`,{className:`flex gap-2 mb-8`,children:(0,f.jsx)(l.ActionButton,{onPress:async()=>{let r=new _.EditorInstance({reference:{id:e.id,type:`Range`},vault:t}).structural.items.getWithoutTracking(),i=await n.create(`@manifest-editor/range-with-items`,{type:`Range`,label:{en:[`Range 1`]},items:[]},{parent:{property:`items`,resource:{id:e.id,type:`Range`},atIndex:0}});t.dispatch((0,s.moveEntities)({subjects:{type:`slice`,startIndex:1,length:r.length},from:{id:e.id,type:`Range`,key:`items`},to:{id:i.id,type:`Range`,key:`items`}}))},children:`Move into new sub-range`})})]}),(0,f.jsx)(`div`,{className:`grid grid-md gap-3`,children:(e.items||[]).map(t=>{let n=(0,m.toRef)(t);return n.type===`Range`?(0,f.jsx)(Be,{range:n},n.id):(0,f.jsx)(d.CanvasContext,{canvas:n.id,children:(0,f.jsx)(l.CanvasThumbnailGridItem,{dragState:{item:n.id,parent:{id:e.id}},id:n.id})},n.id)})})]}):null}function He({extraClasses:e}){return(0,f.jsxs)(`div`,{className:(0,y.twMerge)(`rounded p-4 bg-white/40 text-sm text-gray-700 flex flex-row gap-5 items-center`,e),children:[(0,f.jsx)(`div`,{className:`opacity-30`,children:(0,f.jsx)(je,{className:`h-24 w-24`})}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h3`,{className:`text-xl mb-3`,children:`Empty range`}),(0,f.jsxs)(`p`,{children:[`This range does not yet have any canvases. `,(0,f.jsx)(`br`,{}),`If you want to offer navigation to canvases, you can edit the range and add content.`]})]})]})}const Ue=[{placement:`center`,title:`Working with IIIF ranges`,content:`IIIF uses Ranges to represent logical structure in a digitised object. The range or Table of Contents can then aid users in navigating that content. This short tour shows you the main tools for creating and managing ranges in the Manifest Editor.`,target:`body`},{target:`#range-listing-sidebar`,title:`Range structure`,content:`Browse and navigate your range. Use Edit mode to add more range items, drag to reorder or use the ••• menu to insert empty range items or to delete from the range.`,placement:`right-start`},{target:`#split-range`,title:`Split a range`,content:`Using the splittling mode, you can build and manage the contents of your range. Hover over a canvas to preview, then click to create a new range with canvases from that point onward move into the new range.`},{target:`#edit-ranges`,title:`Edit or reorder ranges`,content:`Toggle Edit to reveal the ••• menu and drag handles for each item in range. Insert an empty range, expand or collapse the structure or delete items. Drag to reorder or move content between range items.`},{target:`#card-view`,title:`Switch view`,content:`Card view provides a simple visual overview of the range. Tree view shows the full hierarchy and allows precise drag and drop options.`},{target:`#grid-options`,title:`Adjust grid size`,content:`Change the canvas thumbnail size to suit your workflow.`},{target:`#launch_range_tour`,title:`That’s it!`,content:(0,f.jsxs)(f.Fragment,{children:[`Now you know the basics of working with ranges. You can restart this tour anytime from the Help menu. Alternatively, you can view the`,` `,(0,f.jsx)(`a`,{className:`text-me-600 underline`,href:`https://manifest-editor-docs.netlify.app/docs/creating-ranges`,target:`_blank`,rel:`noopener noreferrer`,children:`Creating Ranges guide`})]})}];function We(){let[e,t]=(0,u.useState)(!1);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(l.ActionButton,{id:`launch_range_tour`,primary:e,onPress:()=>{t(!0)},children:(0,f.jsx)(Ie,{className:`text-xl`})}),(0,f.jsx)(l.OnboardingTour,{forceStart:e,onClose:()=>t(!1),id:`range-listing-tour`,steps:Ue},e?`range-listing-tour`:`default`)]})}const Ge=({title:e,...t})=>(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,viewBox:`0 0 24 24`,...t,children:[(0,f.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,f.jsx)(`path`,{d:`M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z`,fill:`currentColor`}),e?(0,f.jsx)(`title`,{children:e}):null]}),Ke=({title:e,...t})=>(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,viewBox:`0 0 24 24`,...t,children:[(0,f.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,f.jsx)(`path`,{d:`M19 13H5v-2h14v2z`,fill:`currentColor`}),e?(0,f.jsx)(`title`,{children:e}):null]}),qe=({title:e,...t})=>(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,viewBox:`0 0 24 24`,...t,children:[(0,f.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,f.jsx)(`path`,{d:`M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z`,fill:`currentColor`}),e?(0,f.jsx)(`title`,{children:e}):null]}),Je=p.default.button`
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./components-CoVIXUVJ.cjs");let t=require("@manifest-editor/annotations");t=e.h(t,1);let n=require("@manifest-editor/canvas-label-generator");n=e.h(n,1);let r=require("@manifest-editor/creators"),i=require("@manifest-editor/editors"),a=require("@manifest-editor/shell"),o=require("@iiif/helpers"),s=require("@iiif/helpers/vault/actions"),c=require("@iiif/parser/image-3"),l=require("@manifest-editor/components"),u=require("react");u=e.h(u,1);let d=require("react-iiif-vault"),f=require("react/jsx-runtime"),p=require("styled-components");p=e.h(p,1);let m=require("@iiif/parser"),h=require("react-aria-components"),g=require("zustand"),_=require("@manifest-editor/editor-api"),v=require("react-aria"),y=require("tailwind-merge"),b=require("react-dom"),x=require("@manifest-editor/creator-api");const S=`manifest-preset:bulk-thumbnail-builder-config`,C=`manifest-preset:bulk-thumbnail-builder-results`,w=[256,384,512,768,1024,1536,2048];function T(e={}){let t=e.requestConfig||Se;return{id:`@manifest-editor/manifest-preset/bulk-thumbnail-builder`,label:`Bulk Thumbnail Builder`,summary:`Generate missing manifest and canvas thumbnails from painting annotations`,section:`Thumbnails`,order:10,resourceTypes:[`Manifest`],render:e=>(0,f.jsxs)(f.Fragment,{children:[we(e.definition.id),ke(e.definition.id)]}),onResults:e=>Oe(e.definition.id,e.instance?.result),supports:e=>e.vault.get(e.target)?.type===`Manifest`,prepare:async e=>{e.setActionLabel(`Preparing thumbnails`),e.setActionStatus(`preparing`,`Scanning canvases`);let n=D(e),r=await O(e,n),i=r.sizes.length?r.sizes:ce(),a=ve({requestedWidth:i[0]?.width||256,multiImageMode:(n.multiImageCanvases,`first`),selectedLayerIndex:0,replaceExisting:!1}),o=await t(e,n,a,i,r);return o!==!1&&E(n,o,i,r)},run:async e=>{let t=ve(ye(e.plan)?.options||{}),n=ie(e.plan),r=new Map;if(e.setActionLabel(`Building thumbnails`),!e.plan?.tasks.length)return e.setActionStatus(`running`,`No thumbnail changes found`),e.setActionProgress({current:0,total:0,label:`No thumbnails`}),n;e.canvasProgress.setStatuses(e.plan.tasks.map(e=>e.target).filter(e=>!!e&&e.type===`Canvas`),`queued`),await e.tasks.runEach(async i=>{let a=i.input;if(!a)return n.skippedTargets.push({targetId:i.id,targetType:`Unknown`,reason:`Missing thumbnail task input`}),ae(`Missing thumbnail task input`);let o=e.vault.get({id:a.targetId,type:a.targetType});if(!o)return n.skippedTargets.push({targetId:a.targetId,targetType:a.targetType,reason:`Target resource no longer exists`}),ae(`Target missing`);if(oe(o)&&!t.replaceExisting)return n.skippedTargets.push({targetId:a.targetId,targetType:a.targetType,reason:`Thumbnail already exists`}),ae(`Already has thumbnail`);let s=V(e,a);if(!s)return n.skippedTargets.push({targetId:a.targetId,targetType:a.targetType,reason:`No source canvas with painting annotations found`}),ae(`No source canvas`);let c=await N(e,s,t,r);return c?(B(e,a,c),n.added+=1,a.kind===`manifest`?n.manifestAdded=!0:n.canvasAdded+=1,c.verified&&(n.verified+=1),c.usedConfiguredSize&&(n.usedConfiguredSizes+=1),c.composite&&(n.composites+=1),n.changes.push({targetId:a.targetId,targetType:a.targetType,thumbnailId:c.id,width:c.width,height:c.height}),e.appendActionLog(`Added thumbnail`,`info`,{targetId:a.targetId,targetType:a.targetType,thumbnailId:c.id}),{result:{thumbnailId:c.id,width:c.width,height:c.height},statusText:`Thumbnail added`}):(n.skippedTargets.push({targetId:a.targetId,targetType:a.targetType,reason:`No thumbnail image could be generated`}),ae(`No thumbnail image`))},{progressLabel:(e,t,n)=>`Building thumbnails ${t+1}/${n}`});let i=e.tasks.getAll();return n.failed=i.filter(e=>e.status===`error`).length,n.skipped=i.filter(e=>e.status===`skipped`).length,e.setActionStatus(`running`,`Added ${n.added}/${n.total} thumbnails`),e.setActionProgress({current:n.total,total:n.total,label:`Thumbnails complete`}),n}}}function E(e,t,n,r){let i=ve(t),a=[];(!e.manifestHasThumbnail||i.replaceExisting)&&e.manifestSourceCanvasId&&a.push({id:`${e.manifestId}#thumbnail`,label:`Manifest thumbnail`,target:{id:e.manifestId,type:`Manifest`,label:`Manifest`,scope:`root`},input:{kind:`manifest`,targetId:e.manifestId,targetType:`Manifest`,canvasId:e.manifestSourceCanvasId},status:`queued`});for(let t of e.canvases)t.hasThumbnail&&!i.replaceExisting||a.push({id:`${t.id}#thumbnail`,label:t.label||`Canvas thumbnail`,target:{id:t.id,type:`Canvas`,label:t.label||`Canvas`,scope:`canvas`},input:{kind:`canvas`,targetId:t.id,targetType:`Canvas`,canvasId:t.id},status:`queued`});return{version:1,data:{options:i,preview:e,sizeChoices:n,firstServiceProbe:r},tasks:a}}function D(e){let t=e.vault.get(e.target),n=j(e,t),r=[],i=0,a=0,o=0,s;for(let t of n){let n=M(e,t),c=oe(t);c||(i+=1),n.length>1&&(a+=1),n.length>o&&(o=n.length),!s&&n.length&&(s=t.id),r.push({id:t.id,label:se(t,`Canvas`),hasThumbnail:c,paintingLayerCount:n.length})}return{manifestId:t?.id||e.target.id,manifestHasThumbnail:oe(t),manifestSourceCanvasId:s,totalCanvases:n.length,missingCanvasThumbnails:i,multiImageCanvases:a,maxLayerCount:o,canvases:r}}async function O(e,t){let n=A(e,t),r=n?.service,i=n?.imageUrl;if(!r&&!i)return{status:`not-found`,message:`No IIIF image service found in the painting annotations.`,sizes:[]};let a=r?me(r):``;if(r&&!a)return{status:`error`,message:`The first IIIF image service has no id.`,sizes:le(r)};let o=r?he(a):ge(i||``);return o?k(e,o,a||o.replace(/\/info\.json$/,``),r):{status:`error`,message:`The first IIIF image service could not be resolved.`,sizes:[]}}async function k(e,t,n,r){try{e.setActionStatus(`preparing`,`Loading first image service`);let i=await fetch(t,{signal:e.signal});return i.ok?{status:`loaded`,serviceId:n,infoUrl:t,sizes:le(pe(await i.json(),n))}:{status:`error`,serviceId:n,infoUrl:t,message:`Unable to load info.json (${i.status}).`,sizes:r?le(r):[]}}catch(e){if(xe(e))throw e;return{status:`error`,serviceId:n,infoUrl:t,message:e instanceof Error?e.message:`Unable to load info.json.`,sizes:r?le(r):[]}}}function A(e,t){for(let n of t.canvases){let t=M(e,e.vault.get({id:n.id,type:`Canvas`}));for(let n of t){let t=L(e,n.resource);if(t)return{service:t};if(ge(n.resource?.id))return{imageUrl:n.resource.id}}}return null}function j(e,t){return t?.items?.length?e.vault.get(t.items).filter(e=>e?.type===`Canvas`):[]}function M(e,t){if(!t)return[];let n=(0,o.createPaintingAnnotationsHelper)(e.vault).getPaintables(t),r=[];for(let[e,i]of n.items.entries()){if(i.type!==`image`||!i.resource)continue;let n=H(i.target,t);n&&r.push({annotationId:i.annotationId,label:se(i.resource,`Layer ${e+1}`),resource:i.resource,target:n,sourceSelector:i.selector||null})}return r}async function N(e,t,n,r){let i=M(e,t);if(!i.length)return null;if(i.length>1&&n.multiImageMode===`composite`)return F(e,t,i,n.requestedWidth,r);let a=i[i.length>1&&n.multiImageMode===`layer`?n.selectedLayerIndex:0];return a?P(e,a,n.requestedWidth,r):null}async function P(e,t,n,r){let i=await I(e,t,n,r);return i?{id:i.id,width:i.width,height:i.height,format:i.format,usedConfiguredSize:i.usedConfiguredSize,verified:i.verified,composite:!1}:null}async function F(e,t,n,r,i){if(typeof document>`u`)return null;let a=U({width:t.width||r,height:t.height||r},r),o=G(t.width)||a.width,s=G(t.height)||a.height,c=document.createElement(`canvas`);c.width=a.width,c.height=a.height;let l=c.getContext(`2d`);if(!l)return null;l.fillStyle=`#fff`,l.fillRect(0,0,a.width,a.height);let u=0,d=!1,f=!1;for(let t of n){let n=await I(e,t,Math.max(1,Math.round(t.target.width/o*a.width)),i);if(!n)continue;let r=await W(n.id,e.signal);if(!r)continue;let c={x:t.target.x/o*a.width,y:t.target.y/s*a.height,width:t.target.width/o*a.width,height:t.target.height/s*a.height};l.drawImage(r,c.x,c.y,c.width,c.height),r.close?.(),u+=1,d=d||n.usedConfiguredSize,f=!0}return u?{id:c.toDataURL(`image/jpeg`,.86),width:a.width,height:a.height,format:`image/jpeg`,usedConfiguredSize:d,verified:f,composite:!0}:null}async function I(e,t,n,r){let i=ne(t.sourceSelector),a=L(e,t.resource),o=a?await R(e,a,r):await z(e,t.resource?.id,r);if(o?.service){let r=i?null:de(o.sizes,n);if(r)return{id:ee(o.service,r,i||{full:!0}),width:r.width,height:r.height,format:`image/jpeg`,usedConfiguredSize:!0,verified:!1};let a={width:n,height:void 0},s=ee(o.service,a,i||{full:!0});return await re(s,e.signal)?{id:s,width:a.width,height:fe(t.resource,o.service,i,a.width),format:`image/jpeg`,usedConfiguredSize:!1,verified:!0}:null}return typeof t.resource?.id!=`string`||!await re(t.resource.id,e.signal)?null:{id:t.resource.id,width:G(t.resource.width),height:G(t.resource.height),format:typeof t.resource.format==`string`?t.resource.format:`image/jpeg`,usedConfiguredSize:!1,verified:!0}}function L(e,t){return be(t?.service).map(t=>e.vault.get(t)||t).filter(_e)[0]||null}async function R(e,t,n){let r=me(t);if(!r)return{service:t,sizes:ue(t)};let i=he(r),a=n.get(i);if(a)return a;let o=(async()=>{let n=ue(t);if(n.length)return{service:pe(t,r),sizes:n};try{let a=await fetch(i,{signal:e.signal});if(!a.ok)return{service:pe(t,r),sizes:n};let o=pe(await a.json(),r);return{service:o,sizes:ue(o)}}catch(e){if(xe(e))throw e;return{service:pe(t,r),sizes:n}}})();return n.set(i,o),o}async function z(e,t,n){if(typeof t!=`string`)return null;let r=ge(t);if(!r)return null;let i=n.get(r);if(i)return i;let a=(async()=>{try{let t=await fetch(r,{signal:e.signal});if(!t.ok)return{service:null,sizes:[]};let n=pe(await t.json(),r.replace(/\/info\.json$/,``));return{service:n,sizes:ue(n)}}catch(e){if(xe(e))throw e;return{service:null,sizes:[]}}})();return n.set(r,a),a}function ee(e,t,n){let r=(0,c.createImageServiceRequest)(e);return(0,c.imageServiceRequestToString)({identifier:r.identifier,server:r.server,scheme:r.scheme,type:`image`,size:{max:!t.width&&!t.height,confined:!1,upscaled:!1,width:t.width,height:t.height},format:`jpg`,region:n,rotation:{angle:0},quality:`default`,prefix:r.prefix,originalPath:r.originalPath})}function B(e,t,n){let r={id:n.id,type:`Image`,format:n.format,width:n.width,height:n.height};e.vault.dispatch((0,s.batchActions)({actions:[(0,s.importEntities)({entities:{ContentResource:{[n.id]:r}}}),(0,s.addMappings)({mapping:{[n.id]:`ContentResource`}}),(0,s.modifyEntityField)({id:t.targetId,type:t.targetType,key:`thumbnail`,value:[{id:n.id,type:`ContentResource`}]})]}))}function V(e,t){if(t.canvasId){let n=e.vault.get({id:t.canvasId,type:`Canvas`});if(n&&M(e,n).length)return n}return j(e,e.vault.get(e.target)).find(t=>M(e,t).length)||null}function H(e,t){let n={x:0,y:0,width:G(t?.width)||1,height:G(t?.height)||1};try{let t=(0,o.expandTarget)(e).selector;if(t?.type===`BoxSelector`||t?.type===`TemporalBoxSelector`)return te(t,n)}catch{}return n}function te(e,t){let n=e.spatial;return n.unit===`percent`?{x:n.x/100*t.width,y:n.y/100*t.height,width:n.width/100*t.width,height:n.height/100*t.height}:{x:n.x,y:n.y,width:n.width,height:n.height}}function ne(e){if(!e||e.type!==`BoxSelector`&&e.type!==`TemporalBoxSelector`)return null;let t=e.spatial;return{x:t.x,y:t.y,w:t.width,h:t.height,percent:t.unit===`percent`}}function U(e,t){let n=e.width>e.height?t/e.width:t/e.height;return{width:Math.max(1,Math.round(e.width*n)),height:Math.max(1,Math.round(e.height*n))}}async function re(e,t){try{let n=await fetch(e,{signal:t});return n.body?.cancel().catch(()=>void 0),n.ok}catch(e){if(xe(e))throw e;return!1}}async function W(e,t){try{let n=await fetch(e,{signal:t});if(!n.ok)return null;let r=await n.blob();return createImageBitmap(r)}catch(e){if(xe(e))throw e;return null}}function ie(e){return{total:e?.tasks.length||0,added:0,skipped:0,failed:0,manifestAdded:!1,canvasAdded:0,verified:0,usedConfiguredSizes:0,composites:0,changes:[],skippedTargets:[]}}function ae(e){return{taskStatus:`skipped`,result:{reason:e},statusText:e}}function oe(e){return Array.isArray(e?.thumbnail)&&e.thumbnail.length>0}function se(e,t){return(0,o.getValue)(e?.label,{defaultText:t})||t}function ce(){return w.map(e=>({width:e,label:`${e}px`,source:`standard`}))}function le(e){return ue(e).map(e=>({...e,label:e.height?`${e.width} x ${e.height}`:`${e.width}px`,source:`configured`}))}function ue(e){let t=G(e?.width),n=G(e?.height),r=[];for(let i of be(e?.sizes)){let e=G(i?.width),a=G(i?.height)||(e&&t&&n?Math.round(e/t*n):void 0);e&&r.push({width:e,height:a})}return r.sort((e,t)=>e.width-t.width)}function de(e,t){let n=null;for(let r of e)(!n||Math.abs(r.width-t)<Math.abs(n.width-t))&&(n=r);return n}function fe(e,t,n,r){if(n?.w&&n?.h)return Math.round(r/n.w*n.h);let i=G(t.width)||G(e?.width),a=G(t.height)||G(e?.height);if(!(!i||!a))return Math.round(r/i*a)}function pe(e,t){let n={...e};return n.id=n.id||n[`@id`]||t,n.type=n.type||n[`@type`]||`ImageService3`,n}function me(e){let t=e?.id||e?.[`@id`];return typeof t==`string`?t:``}function he(e){try{if(e.endsWith(`default.jpg`)||e.endsWith(`default.png`))return(0,c.imageServiceRequestToString)({...(0,c.parseImageServiceRequest)(e),type:`info`})}catch{}return(0,c.canonicalServiceUrl)(e)}function ge(e){if(typeof e!=`string`)return``;try{let t=(0,c.parseImageServiceRequest)(e);return t.type===`image`?(0,c.imageServiceRequestToString)({...t,type:`info`}):``}catch{return``}}function _e(e){if(!e||typeof e!=`object`)return!1;let t=e.type||e[`@type`];return String(t||``).startsWith(`ImageService`)||e.protocol===`http://iiif.io/api/image`||Array.isArray(e.sizes)||Array.isArray(e.tiles)}function ve(e){let t=G(e.requestedWidth)||256,n=Math.max(0,Math.floor(G(e.selectedLayerIndex)||0));return{requestedWidth:t,multiImageMode:e.multiImageMode===`composite`||e.multiImageMode===`layer`?e.multiImageMode:`first`,selectedLayerIndex:n,replaceExisting:e.replaceExisting===!0}}function ye(e){return!e?.data||typeof e.data!=`object`?null:e.data}function G(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:void 0}function be(e){return Array.isArray(e)?e:e?[e]:[]}function xe(e){return e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))}function Se(e,t,n,r,i){return Ce({actionId:e.definition.id,preview:t,defaults:n,sizeChoices:r,firstServiceProbe:i,signal:e.signal})}function Ce(e){return new Promise(t=>{if(e.signal?.aborted||typeof window>`u`){t(!1);return}let n=!1,r=r=>{n||(n=!0,e.signal?.removeEventListener(`abort`,i),t(r))},i=()=>r(!1);e.signal?.addEventListener(`abort`,i,{once:!0}),window.dispatchEvent(new CustomEvent(S,{detail:{...e,resolve:r}}))})}function we(e){return(0,f.jsx)(Te,{actionId:e})}function Te({actionId:e}){let[t,n]=(0,u.useState)(null),[r,i]=(0,u.useState)(ve({}));(0,u.useEffect)(()=>{let t=t=>{let r=t.detail;r?.actionId===e&&(n(r),i(ve(r.defaults)))};return window.addEventListener(S,t),()=>window.removeEventListener(S,t)},[e]),(0,u.useEffect)(()=>{if(!t?.signal)return;if(t.signal.aborted){n(null);return}let e=()=>n(null);return t.signal.addEventListener(`abort`,e,{once:!0}),()=>t.signal?.removeEventListener(`abort`,e)},[t]);let a=(0,u.useMemo)(()=>t?.sizeChoices.find(e=>e.width===r.requestedWidth),[t?.sizeChoices,r.requestedWidth]);if(!t)return null;let o=((!t.preview.manifestHasThumbnail||r.replaceExisting)&&t.preview.manifestSourceCanvasId?1:0)+(r.replaceExisting?t.preview.totalCanvases:t.preview.missingCanvasThumbnails),s=e=>{t.resolve(e!==!1&&ve(e)),n(null)},c=t.preview.multiImageCanvases>0;return(0,f.jsx)(l.Modal,{title:`Bulk Thumbnail Builder`,onClose:()=>s(!1),className:`max-w-4xl`,actions:(0,f.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,f.jsx)(`span`,{className:`text-sm text-zinc-400`,children:o===0?`All thumbnails up to date`:`${o} thumbnail${o===1?``:`s`} to ${r.replaceExisting?`add or replace`:`add`}`}),(0,f.jsx)(`button`,{type:`button`,className:`rounded-lg border border-zinc-200 bg-white px-4 py-2 text-sm text-zinc-700 hover:bg-zinc-50`,onClick:()=>s(!1),children:`Cancel`}),(0,f.jsx)(`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:cursor-not-allowed disabled:opacity-40`,disabled:o===0,onClick:()=>s(r),children:`Build thumbnails`})]}),children:(0,f.jsxs)(`div`,{className:`grid grid-cols-[220px_minmax(0,1fr)] h-[58vh]`,children:[(0,f.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto border-r border-zinc-100 p-5 text-sm text-zinc-700`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsxs)(`div`,{className:`mb-3 text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:[t.preview.totalCanvases,` canvas`,t.preview.totalCanvases===1?``:`es`]}),(0,f.jsx)(`div`,{className:`rounded-lg border border-zinc-100 bg-zinc-50 px-3 py-2.5 text-xs text-zinc-500 leading-relaxed`,children:a?.source===`configured`?(0,f.jsxs)(f.Fragment,{children:[`Sizes from image service · `,(0,f.jsxs)(`span`,{className:`font-mono text-zinc-700`,children:[a.width,`px`]})]}):`Using standard sizes — no image service detected`})]}),(0,f.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Thumbnail size`}),(0,f.jsx)(`select`,{className:`rounded-lg border border-zinc-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:outline-none`,value:r.requestedWidth,onChange:e=>i(t=>({...t,requestedWidth:Number(e.target.value)})),children:t.sizeChoices.map(e=>(0,f.jsx)(`option`,{value:e.width,children:e.label},`${e.source}-${e.width}-${e.height||0}`))})]}),(0,f.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2.5 rounded-lg border border-zinc-100 bg-zinc-50 px-3 py-2.5 hover:bg-zinc-100`,children:[(0,f.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 rounded border-zinc-300 text-me-primary-500 focus:ring-me-primary-500`,checked:r.replaceExisting,onChange:e=>i(t=>({...t,replaceExisting:e.currentTarget.checked}))}),(0,f.jsx)(`span`,{className:`text-sm font-medium text-zinc-700`,children:`Replace existing`})]}),c?(0,f.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Multi-image canvases`}),(0,f.jsxs)(`select`,{className:`rounded-lg border border-zinc-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:outline-none`,value:r.multiImageMode,onChange:e=>i(t=>({...t,multiImageMode:e.target.value})),children:[(0,f.jsx)(`option`,{value:`first`,children:`First image`}),(0,f.jsx)(`option`,{value:`composite`,children:`Full composite`}),(0,f.jsx)(`option`,{value:`layer`,children:`Specific layer`})]})]}):null,r.multiImageMode===`layer`&&c?(0,f.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Layer`}),(0,f.jsx)(`select`,{className:`rounded-lg border border-zinc-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:outline-none`,value:r.selectedLayerIndex,onChange:e=>i(t=>({...t,selectedLayerIndex:Number(e.target.value)})),children:Array.from({length:Math.max(t.preview.maxLayerCount,1)},(e,t)=>(0,f.jsxs)(`option`,{value:t,children:[`Layer `,t+1]},t))})]}):null]}),(0,f.jsxs)(`div`,{className:`flex min-w-0 flex-col`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between border-b border-zinc-100 px-4 py-2.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Canvas preview`}),(0,f.jsx)(`span`,{className:`text-xs text-zinc-400`,children:o>0?(0,f.jsxs)(`span`,{className:`font-medium text-me-primary-500`,children:[o,` will be built`]}):`All up to date`})]}),(0,f.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,f.jsx)(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4`,children:t.preview.canvases.map(e=>{let t=r.replaceExisting||!e.hasThumbnail;return(0,f.jsx)(Ee,{canvasId:e.id,label:e.label,willBuild:t,hasExisting:e.hasThumbnail,replacing:e.hasThumbnail&&r.replaceExisting,requestedWidth:r.requestedWidth},e.id)})})})]})]})})}function Ee({canvasId:e,label:t,willBuild:n,hasExisting:r,replacing:i,requestedWidth:a}){return(0,f.jsx)(d.CanvasContext,{canvas:e,children:(0,f.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,f.jsxs)(`div`,{className:[`relative aspect-square w-full overflow-hidden rounded-lg bg-zinc-100`,n?i?`ring-2 ring-me-primary-300`:`ring-2 ring-me-primary-500`:`opacity-40`].join(` `),children:[(0,f.jsx)(De,{width:a},a),n?(0,f.jsx)(`span`,{className:[`absolute bottom-1 right-1 rounded px-1.5 py-0.5 text-[9px] font-bold uppercase leading-none tracking-wide`,i?`bg-me-primary-100 text-me-primary-600`:`bg-me-primary-500 text-white`].join(` `),children:i?`Replace`:`Add`}):null]}),(0,f.jsx)(`span`,{className:`truncate text-center text-[11px] leading-tight text-zinc-500`,children:t})]})})}function De({width:e}){let t=(0,d.useThumbnail)({width:e},!0),[n,r]=(0,u.useState)(!1);return t?.id?(0,f.jsxs)(f.Fragment,{children:[n?null:(0,f.jsx)(`div`,{className:`absolute inset-0 animate-pulse bg-zinc-200`}),(0,f.jsx)(`img`,{src:t.id,alt:``,loading:`lazy`,className:[`absolute inset-0 h-full w-full object-contain transition-opacity duration-300`,n?`opacity-100`:`opacity-0`].join(` `),onLoad:()=>r(!0)})]}):(0,f.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-zinc-100`,children:(0,f.jsx)(`span`,{className:`text-[10px] text-zinc-300`,children:`No image`})})}function Oe(e,t){typeof window>`u`||window.dispatchEvent(new CustomEvent(C,{detail:{actionId:e,result:t}}))}function ke(e){return(0,f.jsx)(Ae,{actionId:e})}function Ae({actionId:e}){let[t,n]=(0,u.useState)(null);return(0,u.useEffect)(()=>{let t=t=>{let r=t.detail;r?.actionId===e&&r.result&&n(r.result)};return window.addEventListener(C,t),()=>window.removeEventListener(C,t)},[e]),t?(0,f.jsx)(l.Modal,{title:`Thumbnail results`,onClose:()=>n(null),className:`max-w-2xl`,children:(0,f.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-0 text-sm text-zinc-700`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-6 border-b border-zinc-100 px-5 py-4`,children:[(0,f.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5`,children:[(0,f.jsx)(`span`,{className:`text-2xl font-semibold leading-none text-zinc-900`,children:t.added}),(0,f.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-zinc-400`,children:`Added`})]}),t.skipped>0?(0,f.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5`,children:[(0,f.jsx)(`span`,{className:`text-2xl font-semibold leading-none text-zinc-500`,children:t.skipped}),(0,f.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-zinc-400`,children:`Skipped`})]}):null,t.failed>0?(0,f.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5`,children:[(0,f.jsx)(`span`,{className:`text-2xl font-semibold leading-none text-red-500`,children:t.failed}),(0,f.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wider text-zinc-400`,children:`Failed`})]}):null,(0,f.jsx)(`div`,{className:`ml-auto text-xs text-zinc-400`,children:t.verified>0?`${t.verified} verified`:null})]}),(0,f.jsxs)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto`,style:{maxHeight:`52vh`},children:[t.changes.length?(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-zinc-100 bg-zinc-50 px-5 py-2 text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Added thumbnails`}),t.changes.map(e=>(0,f.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-3 border-b border-zinc-50 px-5 py-2.5 last:border-0 hover:bg-zinc-50`,children:[(0,f.jsxs)(`div`,{className:`min-w-0`,children:[(0,f.jsx)(`div`,{className:`truncate text-xs font-medium text-zinc-700`,children:e.targetId}),(0,f.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[10px] text-zinc-400`,children:e.thumbnailId})]}),(0,f.jsx)(`div`,{className:`flex-none self-center rounded bg-green-50 px-2 py-0.5 text-xs font-medium text-green-700`,children:e.width?`${e.width}${e.height?`×${e.height}`:`px`}`:e.targetType})]},`${e.targetType}-${e.targetId}`))]}):null,t.skippedTargets.length?(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-zinc-100 bg-zinc-50 px-5 py-2 text-xs font-semibold uppercase tracking-wider text-zinc-400`,children:`Skipped`}),t.skippedTargets.map(e=>(0,f.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-3 border-b border-zinc-50 px-5 py-2.5 last:border-0 hover:bg-zinc-50`,children:[(0,f.jsx)(`div`,{className:`min-w-0`,children:(0,f.jsx)(`div`,{className:`truncate text-xs font-medium text-zinc-700`,children:e.targetId})}),(0,f.jsx)(`div`,{className:`flex-none self-center text-xs text-zinc-400`,children:e.reason})]},`${e.targetType}-${e.targetId}-${e.reason}`))]}):null]})]})}):null}const je=({title:e,...t})=>(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,height:`1em`,width:`1em`,...t,children:[(0,f.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,f.jsx)(`path`,{d:`M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z`}),e?(0,f.jsx)(`title`,{children:e}):null]});function Me(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M18 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2m0 18H6V4h5v7l2.5-1.5L16 11V4h2zm-4.38-6.5L17 18H7l2.38-3.17L11 17z`})})}function Ne(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M17 4v16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m-4-2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h9c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2m0 18H4V4h9zm8-14v12c.83 0 1.5-.67 1.5-1.5v-9c0-.83-.67-1.5-1.5-1.5`})})}function Pe(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M4 18V6zm2-2v-5h9v5zm-2 4q-.825 0-1.412-.587T2 18V6q0-.825.588-1.412T4 4h16q.825 0 1.413.588T22 6v6h-2V6H4v12h9v2zm12.5-8V9.5H9V8h9v4zM18 22v-3h-3v-2h3v-3h2v3h3v2h-3v3z`})})}function Fe(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M20 11H7.83l5.59-5.59L12 4l-8 8l8 8l1.41-1.41L7.83 13H20z`})})}function Ie(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`m12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z`})})}function Le(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M21 3H3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2m0 16H3V5h18zM5 10h9v2H5zm0-3h9v2H5z`})})}function Re(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M11.95 18q.525 0 .888-.363t.362-.887t-.362-.888t-.888-.362t-.887.363t-.363.887t.363.888t.887.362m.05 4q-2.075 0-3.9-.788t-3.175-2.137T2.788 15.9T2 12t.788-3.9t2.137-3.175T8.1 2.788T12 2t3.9.788t3.175 2.137T21.213 8.1T22 12t-.788 3.9t-2.137 3.175t-3.175 2.138T12 22m0-2q3.35 0 5.675-2.325T20 12t-2.325-5.675T12 4T6.325 6.325T4 12t2.325 5.675T12 20m.1-12.3q.625 0 1.088.4t.462 1q0 .55-.337.975t-.763.8q-.575.5-1.012 1.1t-.438 1.35q0 .35.263.588t.612.237q.375 0 .638-.25t.337-.625q.1-.525.45-.937t.75-.788q.575-.55.988-1.2t.412-1.45q0-1.275-1.037-2.087T12.1 6q-.95 0-1.812.4T8.975 7.625q-.175.3-.112.638t.337.512q.35.2.725.125t.625-.425q.275-.375.688-.575t.862-.2`})})}function ze(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M11 16.175V5q0-.425.288-.712T12 4t.713.288T13 5v11.175l4.9-4.9q.3-.3.7-.288t.7.313q.275.3.287.7t-.287.7l-6.6 6.6q-.15.15-.325.213t-.375.062t-.375-.062t-.325-.213l-6.6-6.6q-.275-.275-.275-.687T4.7 11.3q.3-.3.713-.3t.712.3z`})})}function Be(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`m11 7.825l-4.9 4.9q-.3.3-.7.288t-.7-.313q-.275-.3-.288-.7t.288-.7l6.6-6.6q.15-.15.325-.212T12 4.425t.375.063t.325.212l6.6 6.6q.275.275.275.688t-.275.712q-.3.3-.712.3t-.713-.3L13 7.825V19q0 .425-.288.713T12 20t-.712-.288T11 19z`})})}const Ve=(0,g.create)(e=>({isSplitting:!1,setIsSplitting:t=>e({isSplitting:t}),splitEffect:()=>()=>{e({isSplitting:!1})}})),He=(0,u.memo)(function(e){let t=(0,d.useRange)({id:e.range.id}),{dragProps:n}=(0,v.useDrag)({isDisabled:!e.dragState,getItems(){return[{"text/plain":JSON.stringify(e.dragState)}]}}),r=(0,d.useVault)(),i=(0,u.useMemo)(()=>{if(!t)return[];let e=(0,o.createRangeHelper)(r).findAllCanvasesInRange(t),n=[],i=[];for(let t of e)n.includes(t.id)||(n.push(t.id),i.push(t));return i},[t,r]);return i.length===0?(0,f.jsx)(`div`,{children:`EMPTY`}):(0,f.jsxs)(`div`,{...n,className:(0,y.twMerge)(`grid relative grid-cols-2 grid-rows-2 aspect-square overflow-hidden w-full gap-1 p-1 bg-gray-300 rounded-md`,i.length===1&&`grid-cols-1 grid-rows-1`,i.length===2&&`grid-cols-1 grid-rows-2`,i.length===3&&`grid-cols-2 grid-rows-2`,i.length===4&&`grid-cols-2 grid-rows-2`),children:[(0,f.jsx)(`div`,{className:`absolute bottom-2 left-2 bg-white/80 p-1 rounded z-20 flex items-center justify-center text-black/50`,children:(0,f.jsx)(l.RangesIcon,{className:`w-5 h-5`})}),i.slice(0,4).map((t,n)=>(0,f.jsx)(l.CanvasThumbnailGridItem,{className:(0,y.twMerge)(`rounded`,i.length===3&&n===2&&`col-span-2`),hideLabel:!0,id:t.id,onClick:e.onClick},n))]})});function Ue(){let e=(0,d.useRange)(),t=(0,d.useVault)(),n=(0,a.useInlineCreator)();return e?(0,f.jsxs)(`div`,{className:`p-5 `,style:{paddingInlineStart:`calc(1.25rem + var(--manifest-editor-layout-left-sidebar-small, 0px))`,paddingInlineEnd:`calc(1.25rem + var(--manifest-editor-layout-right-sidebar-small, 0px))`},children:[(0,f.jsxs)(`div`,{className:`flex gap-5 items-baseline`,children:[(0,f.jsxs)(`div`,{className:`flex items-baseline gap-3 mb-3`,children:[(0,f.jsx)(`h3`,{className:`text-xl font-bold `,children:`Canvases at this level`}),(0,f.jsxs)(`span`,{children:[`(`,e.items?.length||0,` `,e.items?.length>1?`canvases`:`canvas`,`)`]})]}),(0,f.jsx)(`div`,{className:`flex gap-2 mb-8`,children:(0,f.jsx)(l.ActionButton,{onPress:async()=>{let r=new _.EditorInstance({reference:{id:e.id,type:`Range`},vault:t}).structural.items.getWithoutTracking(),i=await n.create(`@manifest-editor/range-with-items`,{type:`Range`,label:{en:[`Range 1`]},items:[]},{parent:{property:`items`,resource:{id:e.id,type:`Range`},atIndex:0}});t.dispatch((0,s.moveEntities)({subjects:{type:`slice`,startIndex:1,length:r.length},from:{id:e.id,type:`Range`,key:`items`},to:{id:i.id,type:`Range`,key:`items`}}))},children:`Move into new sub-range`})})]}),(0,f.jsx)(`div`,{className:`grid grid-md gap-3`,children:(e.items||[]).map(t=>{let n=(0,m.toRef)(t);return n.type===`Range`?(0,f.jsx)(He,{range:n},n.id):(0,f.jsx)(d.CanvasContext,{canvas:n.id,children:(0,f.jsx)(l.CanvasThumbnailGridItem,{dragState:{item:n.id,parent:{id:e.id}},id:n.id})},n.id)})})]}):null}function We({extraClasses:e}){return(0,f.jsxs)(`div`,{className:(0,y.twMerge)(`rounded p-4 bg-white/40 text-sm text-gray-700 flex flex-row gap-5 items-center`,e),children:[(0,f.jsx)(`div`,{className:`opacity-30`,children:(0,f.jsx)(Ne,{className:`h-24 w-24`})}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h3`,{className:`text-xl mb-3`,children:`Empty range`}),(0,f.jsxs)(`p`,{children:[`This range does not yet have any canvases. `,(0,f.jsx)(`br`,{}),`If you want to offer navigation to canvases, you can edit the range and add content.`]})]})]})}const Ge=[{placement:`center`,title:`Working with IIIF ranges`,content:`IIIF uses Ranges to represent logical structure in a digitised object. The range or Table of Contents can then aid users in navigating that content. This short tour shows you the main tools for creating and managing ranges in the Manifest Editor.`,target:`body`},{target:`#range-listing-sidebar`,title:`Range structure`,content:`Browse and navigate your range. Use Edit mode to add more range items, drag to reorder or use the ••• menu to insert empty range items or to delete from the range.`,placement:`right-start`},{target:`#split-range`,title:`Split a range`,content:`Using the splittling mode, you can build and manage the contents of your range. Hover over a canvas to preview, then click to create a new range with canvases from that point onward move into the new range.`},{target:`#edit-ranges`,title:`Edit or reorder ranges`,content:`Toggle Edit to reveal the ••• menu and drag handles for each item in range. Insert an empty range, expand or collapse the structure or delete items. Drag to reorder or move content between range items.`},{target:`#card-view`,title:`Switch view`,content:`Card view provides a simple visual overview of the range. Tree view shows the full hierarchy and allows precise drag and drop options.`},{target:`#grid-options`,title:`Adjust grid size`,content:`Change the canvas thumbnail size to suit your workflow.`},{target:`#launch_range_tour`,title:`That’s it!`,content:(0,f.jsxs)(f.Fragment,{children:[`Now you know the basics of working with ranges. You can restart this tour anytime from the Help menu. Alternatively, you can view the`,` `,(0,f.jsx)(`a`,{className:`text-me-600 underline`,href:`https://manifest-editor-docs.netlify.app/docs/creating-ranges`,target:`_blank`,rel:`noopener noreferrer`,children:`Creating Ranges guide`})]})}];function Ke(){let[e,t]=(0,u.useState)(!1);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(l.ActionButton,{id:`launch_range_tour`,"aria-label":`Range help`,primary:e,onPress:()=>{t(!0)},children:(0,f.jsx)(Re,{"aria-hidden":`true`,className:`text-xl`})}),(0,f.jsx)(l.OnboardingTour,{forceStart:e,onClose:()=>t(!1),id:`range-listing-tour`,steps:Ge},e?`range-listing-tour`:`default`)]})}const qe=({title:e,...t})=>(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,viewBox:`0 0 24 24`,...t,children:[(0,f.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,f.jsx)(`path`,{d:`M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z`,fill:`currentColor`}),e?(0,f.jsx)(`title`,{children:e}):null]}),Je=({title:e,...t})=>(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,viewBox:`0 0 24 24`,...t,children:[(0,f.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,f.jsx)(`path`,{d:`M19 13H5v-2h14v2z`,fill:`currentColor`}),e?(0,f.jsx)(`title`,{children:e}):null]}),Ye=({title:e,...t})=>(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,viewBox:`0 0 24 24`,...t,children:[(0,f.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,f.jsx)(`path`,{d:`M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z`,fill:`currentColor`}),e?(0,f.jsx)(`title`,{children:e}):null]}),Xe=p.default.button`
|
|
2
2
|
padding: 0.8em;
|
|
3
3
|
font-size: 1em;
|
|
4
4
|
line-height: 1em;
|
|
@@ -28,7 +28,7 @@ Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./compon
|
|
|
28
28
|
color: #fff;
|
|
29
29
|
}
|
|
30
30
|
`}
|
|
31
|
-
`,
|
|
31
|
+
`,Ze=p.default.div`
|
|
32
32
|
display: flex;
|
|
33
33
|
position: absolute;
|
|
34
34
|
top: 1em;
|
|
@@ -38,26 +38,19 @@ Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./compon
|
|
|
38
38
|
& > * ~ * {
|
|
39
39
|
margin-left: 0.5em;
|
|
40
40
|
}
|
|
41
|
-
`;function Xe({refresh:e,toggleEditMode:t,editMode:n,createMode:r,onNext:i,onPrevious:a,editIcon:o,clearSelection:s,enableNavigation:c,style:l,creatingAnnotation:u,toggleCreateAnnotation:p,extraControls:m}){let h=(0,d.useViewerPreset)();return(0,f.jsxs)(Ye,{style:l,children:[(0,f.jsx)(Je,{onDoubleClick:e,"data-control":`home`,onClick:()=>h?.runtime.world.goHome(),children:(0,f.jsx)(Ge,{title:`Home`})}),(0,f.jsx)(Je,{"data-control":`zoom-out`,onClick:()=>h?.runtime.world.zoomTo(1/.75),children:(0,f.jsx)(Ke,{title:`Zoom out`})}),(0,f.jsx)(Je,{"data-control":`zoom-in`,onClick:()=>h?.runtime.world.zoomTo(.75),children:(0,f.jsx)(qe,{title:`Zoom in`})}),m]})}function Ze(e){let t=(0,m.toRef)(e.canvas.resource),n=e.canvas.id??t?.id??null,r=e.range.items||[],i=(0,u.useMemo)(()=>n?r.findIndex(e=>e.id===n):-1,[r,n]),a=(0,u.useMemo)(()=>{if(i===-1)return null;for(let e=i+1;e<r.length;e++){let t=r[e];if(t?.type===`Canvas`)return t}return null},[r,i]),o=(0,u.useMemo)(()=>{if(i<=0)return null;for(let e=i-1;e>=0;e--){let t=r[e];if(t?.type===`Canvas`)return t}return null},[r,i]),s=a?()=>e.setCanvas(a):void 0,c=o?()=>e.setCanvas(o):void 0;return!t&&!n?(0,f.jsx)(`div`,{children:`No canvas preview available`}):(0,f.jsx)(`div`,{className:`relative w-full flex-1 flex flex-col pr-3`,children:(0,f.jsx)(d.CanvasContext,{canvas:t?.id??n,children:(0,f.jsx)(d.CanvasPanel.Viewer,{className:`h-[85vh]`,children:(0,f.jsx)(d.CanvasPanel.RenderCanvas,{renderViewerControls:()=>(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(Xe,{editIcon:!0}),(0,f.jsx)(Qe,{enableNavigation:!0,onNext:s,onPrevious:c})]}),viewControlsDeps:[s,c]})})})})}function Qe(e){let t=(0,d.useCanvas)();return e.enableNavigation?(0,f.jsx)(`div`,{className:`bg-transparent absolute bottom-4 left-4 right-4 pointer-events-none flex items-center justify-center z-50`,children:(0,f.jsxs)(`div`,{className:`bg-white/90 gap-2 inline-flex mx-auto pointer-events-auto items-center gap-4 rounded overflow-hidden shadow-md`,children:[(0,f.jsxs)(h.Button,{isDisabled:!e.onPrevious,onClick:e.onPrevious,className:`p-2 hover:bg-gray-200 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent`,children:[(0,f.jsx)(Ne,{className:`text-2xl`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Previous`})]}),(0,f.jsx)(d.LocaleString,{className:`text-center w-[120px] text-sm truncate overflow-ellipsis`,children:t?.label}),(0,f.jsxs)(h.Button,{isDisabled:!e.onNext,onClick:e.onNext,className:`p-2 hover:bg-gray-200 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent`,children:[(0,f.jsx)(Pe,{className:`text-2xl`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Next`})]})]})}):null}function $e(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6l-6-6z`})})}function et(){let e=(0,d.useCanvas)(),{dragProps:t,isDragging:n}=(0,v.useDrag)({getItems(){return[{"text/plain":JSON.stringify({item:e?.id})}]}});return e?(0,f.jsx)(`div`,{className:`flex items-center`,...t,children:(0,f.jsxs)(`div`,{className:(0,y.twMerge)(`flex flex-1 min-w-0 truncate whitespace-nowrap items-center gap-2 flex-shrink-0 pl-4`,n?`cursor-grabbing opacity-50`:`cursor-pointer`),children:[(0,f.jsx)(l.AddImageIcon,{className:`text-xl flex-shrink-0 text-gray-400`}),(0,f.jsx)(d.LocaleString,{defaultText:(0,f.jsx)(`span`,{className:`text-gray-500`,children:`Untitled canvas`}),children:e.label})]})}):null}function tt(e){let t=(0,d.useCanvas)(),n=(0,d.useVault)(),r=(0,a.useManifestEditor)(),[i,s]=(0,u.useState)(!1),{isEditing:c,showCanvases:p}=ot(),g=(0,u.useRef)(null),[v,x]=(0,u.useState)(!1),S=()=>{if(e.parent){let r=new _.EditorInstance({reference:{id:e.parent.id,type:`Range`},vault:n}),i=r.structural.items.getWithoutTracking().findIndex(e=>(0,m.toRef)(e)?.id===t?.id);i!==-1&&r.structural.items.deleteAtIndex(i)}else{let e=r.structural.structures.getWithoutTracking().findIndex(e=>(0,m.toRef)(e)?.id===t?.id);e!==-1&&r.structural.structures.deleteAtIndex(e)}};if(!t)return null;let C=e?.parent?.resource?`${e.parent.resource.id}$__$${e.rangeItem.id}`:e.rangeItem.id;return(0,f.jsxs)(h.TreeItem,{onContextMenu:e=>{c||e.button===2&&(e.preventDefault(),(0,b.flushSync)(()=>{x(!0)}),g.current&&(g.current.style.transform=`translate(${e.clientX}px, ${e.clientY}px)`))},className:(0,y.twMerge)(`react-aria-TreeItem relative hover:bg-gray-100 flex items-center gap-2 overflow-x-clip px-1.5`,`data-[dragging]:opacity-50`,i&&`pt-8 react-aria-TreeItem-active`),textValue:(0,o.getValue)(t.label),id:C,...e,value:e.rangeItem,children:[(0,f.jsx)(h.TreeItemContent,{children:({allowsDragging:e,isDragging:n,selectionBehavior:r,selectionMode:a})=>(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:(0,y.twMerge)(`flex flex-1 min-w-0 truncate whitespace-nowrap items-center gap-2 flex-shrink-0 pl-4`,i&&`pl-4`,n?`cursor-grabbing opacity-50`:`cursor-pointer`),children:[a===`multiple`&&(0,f.jsx)(l.SelectionCheckbox,{alwaysVisible:!0}),(0,f.jsx)(l.AddImageIcon,{className:`text-xl flex-shrink-0 text-gray-400`}),(0,f.jsx)(d.LocaleString,{defaultText:(0,f.jsx)(`span`,{className:`text-gray-500`,children:`Untitled canvas`}),children:t.label})]}),(0,f.jsxs)(h.MenuTrigger,{isOpen:v,onOpenChange:x,children:[c?(0,f.jsx)(l.MoreMenuButton,{}):null,(0,f.jsx)(h.Popover,{ref:g,className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsx)(h.Menu,{children:(0,f.jsxs)(h.MenuItem,{onAction:()=>window.confirm(`Are you sure you want to remove this canvas?`)&&S(),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex text-red-500 gap-2 items-center`,children:[(0,f.jsx)(l.DeleteForeverIcon,{}),` Remove canvas`]})})})]}),c?(0,f.jsx)(l.ListResizeDragHandle,{}):null]})}),e.children]})}function nt(e){let t=(0,a.useManifestEditor)(),n=(0,i.useInStack)(`Range`),r=(0,a.useInlineCreator)(),{back:s}=(0,a.useEditingStack)(),{edit:c}=(0,a.useLayoutActions)(),p=(0,u.useRef)(null),[m,g]=(0,u.useState)(!1),v=(0,d.useVault)(),x=e.range.id===n?.resource.source?.id,S=n?.resource.source?.id,C=e.range.isNoNav,w=(0,u.useCallback)(()=>{if(e.range.parent||document.getElementById(`range-workbench-scroll`)?.scrollTo({top:0,behavior:`smooth`}),e.range.isRangeLeaf&&e.parentId){S!==e.parentId&&(0,b.flushSync)(()=>{c({id:e.parentId,type:`Range`})}),document.getElementById(`workbench-${String(e.range.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`,inline:`start`,container:`nearest`});return}c({id:e.range.id,type:`Range`})},[S,e.parentId,c,e.range.isRangeLeaf,e.range.id]),T=e.range.items??[],E=T.some(e=>e.type===`Range`),D=T.some(e=>e.type===`Canvas`),O=(0,u.useCallback)(n=>{if(e.parentId){let t=new _.EditorInstance({reference:{id:e.parentId,type:`Range`},vault:v}),r=t.structural.items.getWithoutTracking().findIndex(e=>e.id===n.id);r!==-1&&t.structural.items.deleteAtIndex(r)}else{let e=t.structural.structures.getWithoutTracking().findIndex(e=>e.id===n.id);e!==-1&&t.structural.structures.deleteAtIndex(e)}requestAnimationFrame(()=>{S&&(document.getElementById(`workbench-${S}`)||s())})},[e.parentId,t,v,S,s]),k=(0,u.useCallback)(e=>{r.create(`@manifest-editor/range-with-items`,{type:`Range`,label:{en:[`Untitled range`]},items:[]},{parent:{property:`items`,resource:{id:e.id,type:`Range`}}})},[r]);(0,u.useCallback)(e=>{r.create(`@manifest-editor/range-with-items`,{type:`Range`,label:{en:[`Untitled sequence`]},items:t.structural.items.getWithoutTracking().map(e=>({type:`Canvas`,id:e.id}))},{parent:{property:`items`,resource:{id:e.id,type:`Range`}}})},[r,t]);let{isEditing:A,showCanvases:j}=ot(),M=E||j&&D;return(0,f.jsxs)(h.TreeItem,{onContextMenu:e=>{A||e.button===2&&(e.preventDefault(),(0,b.flushSync)(()=>{g(!0)}),p.current&&(p.current.style.transform=`translate(${e.clientX}px, ${e.clientY}px)`))},className:(0,y.twMerge)(`react-aria-TreeItem hover:bg-gray-100 flex items-center gap-2 p-1.5`,`data-[dragging]:opacity-50 data-[drop-target]:bg-me-primary-500 data-[drop-target]:text-white`,m?`bg-me-200`:``,x?`bg-me-primary-500 hover:bg-me-primary-600 text-white`:``,C?`opacity-40`:``),"data-menu-open":m,"data-active":x,"data-parent-active":e.parentId===S,textValue:(0,o.getValue)(e.range.label),id:e.range.id,onAction:w,...e,children:[(0,f.jsx)(h.TreeItemContent,{children:({isExpanded:t,selectionBehavior:n,selectionMode:r})=>(0,f.jsxs)(f.Fragment,{children:[M?(0,f.jsx)(h.Button,{slot:`chevron`,className:(0,y.twJoin)(`rounded`,x?`hover:bg-me-500`:`hover:bg-gray-300`),children:(0,f.jsx)($e,{className:`text-xl`,style:{transition:`transform .2s`,transform:`rotate(${t?`0deg`:`-90deg`})`}})}):(0,f.jsx)(`span`,{slot:`chevron`,"aria-hidden":!0,tabIndex:-1,className:`pointer-events-none`,children:(0,f.jsx)($e,{className:(0,y.twMerge)(`text-xl`,`opacity-20 cursor-not-allowed`),style:{transition:`transform .2s`,transform:`rotate(${t?`0deg`:`-90deg`})`}})}),r===`multiple`&&(0,f.jsx)(l.SelectionCheckbox,{alwaysVisible:!0}),(0,f.jsxs)(`div`,{className:(0,y.twMerge)(`flex items-center gap-2 flex-1 min-w-0`,!j&&e.range.isRangeLeaf&&`border-transparent`),children:[(0,f.jsx)(d.LocaleString,{className:(0,y.twMerge)(`truncate whitespace-nowrap flex-1 min-w-0 border-b border-gray-200`,(m||x)&&`border-transparent`),children:e.range.label||`Untitled range`}),!A&&e.range.isRangeLeaf?(0,f.jsx)(`div`,{className:`text-right bg-gray-100 py-0.5 px-2 text-xs rounded text-black/70`,children:e.range.items?.length}):null,(0,f.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,f.jsxs)(h.MenuTrigger,{isOpen:m,onOpenChange:g,children:[A?(0,f.jsx)(l.MoreMenuButton,{}):null,(0,f.jsx)(h.Popover,{ref:p,className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsxs)(h.Menu,{children:[(0,f.jsxs)(h.MenuItem,{onAction:()=>k(e.range),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(je,{}),` Insert empty range`]}),(0,f.jsxs)(h.MenuItem,{onAction:()=>e.expandRangeItem(e.range,!1),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(qe,{}),` Expand all`]}),(0,f.jsxs)(h.MenuItem,{onAction:()=>e.expandRangeItem(e.range,!0),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(Ke,{}),` Collapse all`]}),(0,f.jsxs)(h.MenuItem,{onAction:()=>window.confirm(`Are you sure you want to delete this range?`)&&O(e.range),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex text-red-500 gap-2 items-center`,children:[(0,f.jsx)(l.DeleteForeverIcon,{}),` Delete range item`]})]})})]}),A&&!!e.parentId&&(0,f.jsx)(l.ListResizeDragHandle,{})]})]})]})}),e.children]})}function rt(e){let t=[];t.push({item:e,parent:null});for(let n of e.items||[])t.push({item:n,parent:e}),n.type===`Range`&&t.push(...rt(n));return t}function it(e,t){let n=new Set(e.filter(e=>e.item.type===`Canvas`).map(e=>e.item.id));return t.filter(e=>!n.has(e.id))}async function at(e){return Promise.all(e.map(async e=>{if(e.kind===`text`){let t=await e.getText(`text/plain`);return t?JSON.parse(t):null}return null}))}const ot=(0,g.create)()((e,t)=>({showCanvases:!0,toggleShowCanvases(){e(e=>({showCanvases:!e.showCanvases}))},isEditing:!1,toggleIsEditing(){e(e=>({isEditing:!e.isEditing}))}}));function st(e){let t=(0,d.useVault)(),n=(0,d.useManifest)(),r=(0,u.useMemo)(()=>(0,o.createRangeHelper)(t),[t]),{isEditing:i,showCanvases:a,toggleShowCanvases:c}=ot(),{range:l,flatItems:p,canvasesNotInRanges:g}=(0,d.useVaultSelector)((t,i)=>{let a=e.selectedTopLevelRange?[i.get(e.selectedTopLevelRange)]:i.get(n.structures||[]),o=r.rangesToTableOfContentsTree(a,void 0,{showNoNav:!0})||{},s=rt(o);return{structures:a,range:o,flatItems:s,canvasesNotInRanges:it(s,n?.items||[])}}),v=(0,u.useMemo)(()=>p.filter(({item:e})=>e.type===`Range`&&e.items?.length).filter(({item:e})=>(e.items?.length||0)<500).filter(({item:e})=>!e.isRangeLeaf&&!e.isCanvasLeaf).map(({item:e})=>e.id),[p]),y=(0,u.useMemo)(()=>[l],[l]),[b,x]=(0,u.useState)(v),{dragAndDropHooks:S}=(0,h.useDragAndDrop)({isDisabled:!1,getItems:(e,t)=>[...e].map(e=>{let t=p.find(t=>t.item.id===e);return t?{"text/plain":JSON.stringify({item:t.item.id,parent:t.parent})}:{"text/plain":e.toString()}}),renderDragPreview(e){return(0,f.jsx)(`div`,{className:`opacity-50 bg-gray-200 rounded p-1`,children:(0,f.jsxs)(`span`,{className:``,children:[e.length,` items`]})})},onDrop:async e=>{let n=await at(e.items),r=null;if(r=e.target.type===`root`?l.id:e.target.key,!r){console.log(`[error] No valid target found`);return}let i=p.find(t=>e.target.key===t.item.id);if(e.target.type===`item`&&e.target.dropPosition===`on`&&i?.item.type===`Canvas`||!i)return;let a=r.toString();if(e.dropOperation===`move`&&e.target.type===`item`&&(e.target.dropPosition===`before`||e.target.dropPosition===`after`?a=i?.parent?.id:e.target.dropPosition===`on`&&(a=r.toString())),!a){console.log(`[error] No valid target parent found`);return}if(!t.get({id:a,type:`Range`})){console.log(`[error] No valid target range found in Vault`);return}let o=n.map(e=>{let t=p.findIndex(t=>e.item===t.item.id);if(t===-1)return null;let n=p[t];return{id:n?.item.id,type:n?.item.type,order:t}}).filter(e=>e!==null).sort((e,t)=>e.order-t.order).map(e=>({id:e.id,type:e.type})),c=n[0],u=p.find(e=>c.item===e.item.id);if(!u){let n=t.get(c.item);if(!n?.id||!n?.type){console.log(`[error] No valid item found in Vault`);return}let i=t.get({id:a,type:`Range`}).items.findIndex(e=>(0,m.toRef)(e)?.id===r),o={type:`SpecificResource`,source:{id:n.id,type:n.type}},s=new _.EditorInstance({reference:{id:a,type:`Range`},vault:t});e.target.type===`item`&&(e.target.dropPosition===`on`&&s.structural.items.add(o),e.target.dropPosition===`after`&&s.structural.items.addAfter(i,o),e.target.dropPosition===`before`&&s.structural.items.addBefore(i,o));return}if(!u.parent){console.log(`[error] No valid parent found for item to move`);return}let d=t.get({id:u.parent.id,type:`Range`});if(e.target.type===`root`||e.target.type===`item`&&e.target.dropPosition===`on`){t.dispatch((0,s.moveEntities)({subjects:{type:`list`,items:o},from:{id:u.parent.id,type:`Range`,key:`items`},to:{id:a,type:`Range`,key:`items`}}));return}if(u.parent.id===a&&e.dropOperation===`move`){let n=d.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===u.item.id),i=d.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===r);if(n===i){console.log(`[error] No valid index found for item to move`);return}if(n===-1||i===-1){console.log(`[error] Invalid index found for item to move`);return}n>i&&e.target.dropPosition===`after`&&(i+=1),n<i&&e.target.dropPosition===`after`&&(i-=o.length-1),t.dispatch((0,s.moveEntities)({subjects:{type:`list`,items:o},from:{id:a,type:`Range`,key:`items`},to:{id:a,type:`Range`,key:`items`,index:i}}));return}let f=d.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===u.item.id);if(f===-1){console.log(`[error] Invalid index found for item to move`);return}if(!d.items[f]){console.log(`[error] Invalid reference found for item to move`);return}let h=t.get({id:a,type:`Range`});if(!h){console.log(`[error] Invalid target parent found`);return}let g=h.items.findIndex(e=>(0,m.toRef)(e)?.id===r);if(g===-1){console.log(`[error] Invalid target item found`);return}t.dispatch((0,s.moveEntities)({subjects:{type:`list`,items:o},from:{id:u.parent.id,type:`Range`,key:`items`},to:{id:a,type:`Range`,key:`items`,index:e.target.dropPosition===`after`?g+1:g}}))}}),C=(0,u.useCallback)((e,t)=>{if(e.isCanvasLeaf)return;let n=(e.items||[]).map(e=>e.id);if(t){x(e=>Array.from(e).filter(e=>!n.includes(e.toString())));return}x(t=>Array.from(new Set([...t,e.id,...n])))},[]);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tree,{"aria-label":(0,o.getValue)(l.label),items:y,expandedKeys:b,dragAndDropHooks:S,onExpandedChange:x,selectionMode:i?`multiple`:`single`,selectionBehavior:`toggle`,children:function(e){return(0,f.jsx)(lt,{item:e,expandRangeItem:C})}}),g.length===0?null:(0,f.jsxs)(h.Disclosure,{className:`w-full`,children:[(0,f.jsx)(h.Heading,{children:(0,f.jsxs)(h.Button,{slot:`trigger`,className:`group flex items-center hover:bg-gray-100 px-2 py-1.5 gap-3 w-full text-gray-500`,children:[(0,f.jsx)($e,{className:`text-xl group-[&[aria-expanded="true"]]:rotate-0 -rotate-90 transition-transform`}),(0,f.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,f.jsx)(ct,{className:`text-xl`}),`Canvases without a range`]})]})}),(0,f.jsx)(h.DisclosurePanel,{children:g.map(e=>(0,f.jsx)(d.CanvasContext,{canvas:e.id,children:(0,f.jsx)(et,{})},e.id))})]})]})}function ct(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M1 21h22L12 2zm3.47-2L12 5.99L19.53 19zM11 16h2v2h-2zm0-6h2v4h-2z`})})}function lt({item:e,parent:t,expandRangeItem:n}){let{showCanvases:r}=ot();return e.type===`Canvas`?!e.resource||!r?null:(0,f.jsx)(d.CanvasContext,{canvas:e.resource?.source.id,children:(0,f.jsx)(tt,{rangeItem:e,parent:t})}):(0,f.jsx)(nt,{range:e,hasChildItems:!!e.items,parentId:t?.id,expandRangeItem:n,children:(0,f.jsx)(h.Collection,{items:e.items||[],children:t=>(0,f.jsx)(lt,{item:t,parent:e,expandRangeItem:n})})})}function ut({range:e,isSplitting:t,onSplit:n,onMergeDown:r,onMergeUp:c,mergeDownLabel:p,mergeUpLabel:m,nextRangeLabel:g,onPreviewCanvas:x,onClosePreview:S}){let[{size:C}]=(0,l.useGridOptions)(`default-grid-size`,{defaultGridSize:`grid-sm`}),{edit:w}=(0,a.useLayoutActions)(),[T,E]=(0,u.useState)(!0),[D,O]=(0,u.useState)(!1),[k,{intersector:A,isFullyLoaded:j,loadMore:M,reset:N}]=(0,l.useLoadMoreItems)(e.items||[],{batchSize:32}),P=(0,d.useVault)(),F=(0,u.useRef)(null),{isDropTarget:I,dropProps:L}=(0,v.useDrop)({ref:F,async onDrop(t){let n=await at(t.items),r=n[0];if(!r)return;let i=r.parent?.id;if(!i&&t.type===`drop`){let t=P.get(r.item);if(!t?.id||!t?.type){console.log(`[error] No valid item found in Vault`);return}let n=e.id,i={type:`SpecificResource`,source:{id:t.id,type:t.type}};new _.EditorInstance({reference:{id:n,type:`Range`},vault:P}).structural.items.add(i)}let a=n.map(e=>{let t=P.get(e.item);return t?.type?{id:t.id,type:t.type}:null}).filter(e=>e!==null);a.length&&i!==e.id&&P.dispatch((0,s.moveEntities)({subjects:{type:`list`,items:a},from:{id:i,type:`Range`,key:`items`},to:{id:e.id,type:`Range`,key:`items`}}))}}),R=!e.items||e.items?.length===0,z=(e.items??[]).find(e=>e.type===`Canvas`)?.id;return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{ref:F,...L,"data-drop-target":I,style:{paddingInlineStart:`calc(1rem + var(--manifest-editor-layout-left-sidebar-small, 0px))`,paddingInlineEnd:`calc(1rem + var(--manifest-editor-layout-right-sidebar-small, 0px))`},className:(0,y.twMerge)(`w-full border-b border-b-gray-500/20 p-4 relative`,I&&`bg-me-primary-100`),children:[(0,f.jsx)(`div`,{id:`workbench-${e.id}`,className:`absolute -top-16`}),(0,f.jsxs)(`div`,{className:`flex items-center gap-4 max-w-full`,children:[(0,f.jsxs)(h.Button,{className:`flex items-center gap-2 min-w-0`,onPress:()=>{T&&N(),E(!T)},children:[(0,f.jsx)($e,{className:`text-xl`,style:{transition:`transform .2s`,transform:`rotate(${T?`0deg`:`-90deg`})`}}),D?null:(0,f.jsx)(d.LocaleString,{className:`text-xl text-left truncate overflow-ellipsis min-w-0 flex-1`,children:e.label||`Untitled range`})]}),D?(0,f.jsx)(i.InlineLabelEditor,{resource:{id:e.id,type:`Range`},onSubmit:()=>O(!1)}):null,(0,f.jsxs)(h.MenuTrigger,{children:[(0,f.jsx)(l.ActionButton,{children:(0,f.jsx)(l.MoreMenuIcon,{className:`text-xl`})}),(0,f.jsx)(h.Popover,{className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsxs)(h.Menu,{children:[(0,f.jsxs)(h.MenuItem,{className:`hover:bg-me-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,onAction:()=>O(!0),children:[(0,f.jsx)(ke,{}),`Edit range label`]}),(0,f.jsxs)(h.MenuItem,{className:`hover:bg-me-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,onAction:()=>w(e,{property:`metadata`},{forceOpen:!0,selectedTab:`@manifest-editor/metadata`}),children:[(0,f.jsx)(l.ListingIcon,{}),`Edit range metadata`]}),!R&&c&&(0,f.jsxs)(h.MenuItem,{onPress:()=>c(e,!0),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(ft,{className:`text-md`}),` Empty contents into`,(0,f.jsx)(d.LocaleString,{className:`font-semibold`,children:m})]}),!R&&r&&(0,f.jsxs)(h.MenuItem,{onPress:()=>r(e,!0),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(pt,{className:`text-md`}),` Empty contents into`,(0,f.jsx)(d.LocaleString,{className:`font-semibold`,children:p})]}),!R&&(0,f.jsx)(h.Separator,{className:`h-0.5 bg-gray-200`}),!R&&c&&(0,f.jsxs)(h.MenuItem,{onPress:()=>window.confirm(`This range will be removed and the items will be merged into the previous range.`)&&c(e),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center text-red-500`,children:[(0,f.jsx)(ft,{className:`text-md`}),` Merge into`,(0,f.jsx)(d.LocaleString,{className:`font-semibold`,children:m})]}),!R&&r&&(0,f.jsxs)(h.MenuItem,{onPress:()=>{window.confirm(`This range will be removed and the items will be merged into the next range.`)&&r(e)},className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center text-red-500`,children:[(0,f.jsx)(pt,{className:`text-md`}),` Merge into`,(0,f.jsx)(d.LocaleString,{className:`font-semibold`,children:p})]})]})})]}),(0,f.jsxs)(l.ActionButton,{onPress:()=>w({id:e.id,type:`Range`}),children:[e.isRangeLeaf?`View range item`:`Edit range item`,(0,f.jsx)(Pe,{className:`text-xl`})]})]}),T?(0,f.jsxs)(f.Fragment,{children:[(k||[]).length===0&&(0,f.jsx)(He,{extraClasses:`mt-4`}),(0,f.jsx)(`div`,{className:`grid pt-4 gap-3 ${C}`,children:(k||[]).map(r=>{let i=r.id===z;return r.type===`Canvas`?(0,f.jsx)(d.CanvasContext,{canvas:r.resource.source.id,children:(0,f.jsx)(l.CanvasThumbnailGridItem,{"aria-disabled":r.id===z,onClick:()=>{t&&!i&&n(e,r),t||x?.(e,r)},dragState:{item:r.id,parent:{id:e.id}},containerProps:{"data-range1-label":(0,o.getValue)(e.label),"data-range2-label":g||`Untitled range`,...i?{"data-split-first":`true`}:{}},className:t?`split-range-highlight`:``,id:r.resource.source.id,icon:(0,f.jsx)(l.ActionButton,{className:`absolute top-2 right-2 hidden group-hover:block`,onPress:()=>x?.(e,r),children:(0,f.jsx)(dt,{className:`text-2xl`})})})},r.id):(0,f.jsxs)(`div`,{className:`items-center justify-center flex flex-col`,children:[(0,f.jsx)(Be,{range:r,dragState:{item:r.id,parent:{id:e.id}},onClick:()=>{if(r.isRangeLeaf&&r.parent?.id){(0,b.flushSync)(()=>{w({id:r.parent?.id,type:`Range`})}),document.getElementById(`workbench-${String(r.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`,inline:`start`,container:`nearest`});return}w({id:r.id,type:`Range`})}}),(0,f.jsx)(d.LocaleString,{className:`truncate overflow-ellipsis max-w-full text-sm`,children:r.label||`Untitled range`})]},r.id)})}),j?null:(0,f.jsx)(l.ActionButton,{onPress:M,children:`Load more`})]}):null]},e.id),A]})}function dt(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M21 8.59V4c0-.55-.45-1-1-1h-4.59c-.89 0-1.34 1.08-.71 1.71l1.59 1.59l-10 10l-1.59-1.59c-.62-.63-1.7-.19-1.7.7V20c0 .55.45 1 1 1h4.59c.89 0 1.34-1.08.71-1.71L7.71 17.7l10-10l1.59 1.59c.62.63 1.7.19 1.7-.7`})})}function ft(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`m4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8z`})})}function pt(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`m20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8z`})})}const mt={id:`range-workbench`,label:`Range Workbench`,icon:(0,f.jsx)(je,{}),focusedMode:{hide:!0},render:()=>(0,f.jsx)(bt,{})},ht=p.default.div`
|
|
41
|
+
`;function Qe({refresh:e,toggleEditMode:t,editMode:n,createMode:r,onNext:i,onPrevious:a,editIcon:o,clearSelection:s,enableNavigation:c,style:l,creatingAnnotation:u,toggleCreateAnnotation:p,extraControls:m}){let h=(0,d.useViewerPreset)();return(0,f.jsxs)(Ze,{style:l,children:[(0,f.jsx)(Xe,{onDoubleClick:e,"data-control":`home`,onClick:()=>h?.runtime.world.goHome(),children:(0,f.jsx)(qe,{title:`Home`})}),(0,f.jsx)(Xe,{"data-control":`zoom-out`,onClick:()=>h?.runtime.world.zoomTo(1/.75),children:(0,f.jsx)(Je,{title:`Zoom out`})}),(0,f.jsx)(Xe,{"data-control":`zoom-in`,onClick:()=>h?.runtime.world.zoomTo(.75),children:(0,f.jsx)(Ye,{title:`Zoom in`})}),m]})}function $e(e){let t=(0,m.toRef)(e.canvas.resource),n=e.canvas.id??t?.id??null,r=e.range.items||[],i=(0,u.useMemo)(()=>n?r.findIndex(e=>e.id===n):-1,[r,n]),a=(0,u.useMemo)(()=>{if(i===-1)return null;for(let e=i+1;e<r.length;e++){let t=r[e];if(t?.type===`Canvas`)return t}return null},[r,i]),o=(0,u.useMemo)(()=>{if(i<=0)return null;for(let e=i-1;e>=0;e--){let t=r[e];if(t?.type===`Canvas`)return t}return null},[r,i]),s=a?()=>e.setCanvas(a):void 0,c=o?()=>e.setCanvas(o):void 0;if(!t&&!n)return(0,f.jsx)(`div`,{children:`No canvas preview available`});let l=t?.id??n;return(0,f.jsx)(`div`,{className:`relative w-full flex-1 flex flex-col pr-3`,children:(0,f.jsx)(d.CanvasContext,{canvas:l,children:(0,f.jsx)(d.CanvasPanel.Viewer,{className:`h-[85vh]`,children:(0,f.jsx)(d.CanvasPanel.RenderCanvas,{renderViewerControls:()=>(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(Qe,{editIcon:!0}),(0,f.jsx)(et,{enableNavigation:!0,onNext:s,onPrevious:c})]}),viewControlsDeps:[s,c]})})})})}function et(e){let t=(0,d.useCanvas)();return e.enableNavigation?(0,f.jsx)(`div`,{className:`bg-transparent absolute bottom-4 left-4 right-4 pointer-events-none flex items-center justify-center z-50`,children:(0,f.jsxs)(`div`,{className:`bg-white/90 gap-2 inline-flex mx-auto pointer-events-auto items-center gap-4 rounded overflow-hidden shadow-md`,children:[(0,f.jsxs)(h.Button,{isDisabled:!e.onPrevious,onClick:e.onPrevious,className:`p-2 hover:bg-gray-200 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent`,children:[(0,f.jsx)(Fe,{className:`text-2xl`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Previous`})]}),(0,f.jsx)(d.LocaleString,{className:`text-center w-[120px] text-sm truncate overflow-ellipsis`,children:t?.label}),(0,f.jsxs)(h.Button,{isDisabled:!e.onNext,onClick:e.onNext,className:`p-2 hover:bg-gray-200 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent`,children:[(0,f.jsx)(Ie,{className:`text-2xl`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Next`})]})]})}):null}function tt(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6l-6-6z`})})}function nt(){let e=(0,d.useCanvas)(),{dragProps:t,isDragging:n}=(0,v.useDrag)({getItems(){return[{"text/plain":JSON.stringify({item:e?.id})}]}});return e?(0,f.jsx)(`div`,{className:`flex items-center`,...t,children:(0,f.jsxs)(`div`,{className:(0,y.twMerge)(`flex flex-1 min-w-0 truncate whitespace-nowrap items-center gap-2 flex-shrink-0 pl-4`,n?`cursor-grabbing opacity-50`:`cursor-pointer`),children:[(0,f.jsx)(l.AddImageIcon,{className:`text-xl flex-shrink-0 text-gray-400`}),(0,f.jsx)(d.LocaleString,{defaultText:(0,f.jsx)(`span`,{className:`text-gray-500`,children:`Untitled canvas`}),children:e.label})]})}):null}function rt(e){let t=(0,d.useCanvas)(),n=(0,d.useVault)(),r=(0,a.useManifestEditor)(),[i,s]=(0,u.useState)(!1),{isEditing:c,showCanvases:p}=ct(),g=(0,u.useRef)(null),[v,x]=(0,u.useState)(!1),S=()=>{if(e.parent){let r=new _.EditorInstance({reference:{id:e.parent.id,type:`Range`},vault:n}),i=r.structural.items.getWithoutTracking().findIndex(e=>(0,m.toRef)(e)?.id===t?.id);i!==-1&&r.structural.items.deleteAtIndex(i)}else{let e=r.structural.structures.getWithoutTracking().findIndex(e=>(0,m.toRef)(e)?.id===t?.id);e!==-1&&r.structural.structures.deleteAtIndex(e)}};if(!t)return null;let C=e?.parent?.resource?`${e.parent.resource.id}$__$${e.rangeItem.id}`:e.rangeItem.id;return(0,f.jsxs)(h.TreeItem,{onContextMenu:e=>{c||e.button===2&&(e.preventDefault(),(0,b.flushSync)(()=>{x(!0)}),g.current&&(g.current.style.transform=`translate(${e.clientX}px, ${e.clientY}px)`))},className:(0,y.twMerge)(`react-aria-TreeItem relative hover:bg-gray-100 flex items-center gap-2 overflow-x-clip px-1.5`,`data-[dragging]:opacity-50`,i&&`pt-8 react-aria-TreeItem-active`),textValue:(0,o.getValue)(t.label),id:C,...e,value:e.rangeItem,children:[(0,f.jsx)(h.TreeItemContent,{children:({allowsDragging:e,isDragging:n,selectionBehavior:r,selectionMode:a})=>(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:(0,y.twMerge)(`flex flex-1 min-w-0 truncate whitespace-nowrap items-center gap-2 flex-shrink-0 pl-4`,i&&`pl-4`,n?`cursor-grabbing opacity-50`:`cursor-pointer`),children:[a===`multiple`&&(0,f.jsx)(l.SelectionCheckbox,{alwaysVisible:!0}),(0,f.jsx)(l.AddImageIcon,{className:`text-xl flex-shrink-0 text-gray-400`}),(0,f.jsx)(d.LocaleString,{defaultText:(0,f.jsx)(`span`,{className:`text-gray-500`,children:`Untitled canvas`}),children:t.label})]}),(0,f.jsxs)(h.MenuTrigger,{isOpen:v,onOpenChange:x,children:[c?(0,f.jsx)(l.MoreMenuButton,{}):null,(0,f.jsx)(h.Popover,{ref:g,className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsx)(h.Menu,{children:(0,f.jsxs)(h.MenuItem,{onAction:()=>window.confirm(`Are you sure you want to remove this canvas?`)&&S(),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex text-red-500 gap-2 items-center`,children:[(0,f.jsx)(l.DeleteForeverIcon,{}),` Remove canvas`]})})})]}),c?(0,f.jsx)(l.ListResizeDragHandle,{}):null]})}),e.children]})}function it(e){let t=(0,a.useManifestEditor)(),n=(0,i.useInStack)(`Range`),r=(0,a.useInlineCreator)(),{back:s}=(0,a.useEditingStack)(),{edit:c}=(0,a.useLayoutActions)(),p=(0,u.useRef)(null),[m,g]=(0,u.useState)(!1),v=(0,d.useVault)(),x=e.range.id===n?.resource.source?.id,S=n?.resource.source?.id,C=e.range.isNoNav,w=(0,u.useCallback)(()=>{if(e.range.parent||document.getElementById(`range-workbench-scroll`)?.scrollTo({top:0,behavior:`smooth`}),e.range.isRangeLeaf&&e.parentId){S!==e.parentId&&(0,b.flushSync)(()=>{c({id:e.parentId,type:`Range`})}),document.getElementById(`workbench-${String(e.range.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`,inline:`start`,container:`nearest`});return}c({id:e.range.id,type:`Range`})},[S,e.parentId,c,e.range.isRangeLeaf,e.range.id]),T=e.range.items??[],E=T.some(e=>e.type===`Range`),D=T.some(e=>e.type===`Canvas`),O=(0,u.useCallback)(n=>{if(e.parentId){let t=new _.EditorInstance({reference:{id:e.parentId,type:`Range`},vault:v}),r=t.structural.items.getWithoutTracking().findIndex(e=>e.id===n.id);r!==-1&&t.structural.items.deleteAtIndex(r)}else{let e=t.structural.structures.getWithoutTracking().findIndex(e=>e.id===n.id);e!==-1&&t.structural.structures.deleteAtIndex(e)}requestAnimationFrame(()=>{S&&(document.getElementById(`workbench-${S}`)||s())})},[e.parentId,t,v,S,s]),k=(0,u.useCallback)(e=>{r.create(`@manifest-editor/range-with-items`,{type:`Range`,label:{en:[`Untitled range`]},items:[]},{parent:{property:`items`,resource:{id:e.id,type:`Range`}}})},[r]);(0,u.useCallback)(e=>{r.create(`@manifest-editor/range-with-items`,{type:`Range`,label:{en:[`Untitled sequence`]},items:t.structural.items.getWithoutTracking().map(e=>({type:`Canvas`,id:e.id}))},{parent:{property:`items`,resource:{id:e.id,type:`Range`}}})},[r,t]);let{isEditing:A,showCanvases:j}=ct(),M=E||j&&D;return(0,f.jsxs)(h.TreeItem,{onContextMenu:e=>{A||e.button===2&&(e.preventDefault(),(0,b.flushSync)(()=>{g(!0)}),p.current&&(p.current.style.transform=`translate(${e.clientX}px, ${e.clientY}px)`))},className:(0,y.twMerge)(`react-aria-TreeItem hover:bg-gray-100 flex items-center gap-2 p-1.5`,`data-[dragging]:opacity-50 data-[drop-target]:bg-me-primary-500 data-[drop-target]:text-white`,m?`bg-me-200`:``,x?`bg-me-primary-500 hover:bg-me-primary-600 text-white`:``,C?`opacity-40`:``),"data-menu-open":m,"data-active":x,"data-parent-active":e.parentId===S,textValue:(0,o.getValue)(e.range.label),id:e.range.id,onAction:w,...e,children:[(0,f.jsx)(h.TreeItemContent,{children:({isExpanded:t,selectionBehavior:n,selectionMode:r})=>(0,f.jsxs)(f.Fragment,{children:[M?(0,f.jsx)(h.Button,{slot:`chevron`,className:(0,y.twJoin)(`rounded`,x?`hover:bg-me-500`:`hover:bg-gray-300`),children:(0,f.jsx)(tt,{className:`text-xl`,style:{transition:`transform .2s`,transform:`rotate(${t?`0deg`:`-90deg`})`}})}):(0,f.jsx)(`span`,{slot:`chevron`,"aria-hidden":!0,tabIndex:-1,className:`pointer-events-none`,children:(0,f.jsx)(tt,{className:(0,y.twMerge)(`text-xl`,`opacity-20 cursor-not-allowed`),style:{transition:`transform .2s`,transform:`rotate(${t?`0deg`:`-90deg`})`}})}),r===`multiple`&&(0,f.jsx)(l.SelectionCheckbox,{alwaysVisible:!0}),(0,f.jsxs)(`div`,{className:(0,y.twMerge)(`flex items-center gap-2 flex-1 min-w-0`,!j&&e.range.isRangeLeaf&&`border-transparent`),children:[(0,f.jsx)(d.LocaleString,{className:(0,y.twMerge)(`truncate whitespace-nowrap flex-1 min-w-0 border-b border-gray-200`,(m||x)&&`border-transparent`),children:e.range.label||`Untitled range`}),!A&&e.range.isRangeLeaf?(0,f.jsx)(`div`,{className:`text-right bg-gray-100 py-0.5 px-2 text-xs rounded text-black/70`,children:e.range.items?.length}):null,(0,f.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,f.jsxs)(h.MenuTrigger,{isOpen:m,onOpenChange:g,children:[A?(0,f.jsx)(l.MoreMenuButton,{}):null,(0,f.jsx)(h.Popover,{ref:p,className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsxs)(h.Menu,{children:[(0,f.jsxs)(h.MenuItem,{onAction:()=>k(e.range),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(Ne,{}),` Insert empty range`]}),(0,f.jsxs)(h.MenuItem,{onAction:()=>e.expandRangeItem(e.range,!1),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(Ye,{}),` Expand all`]}),(0,f.jsxs)(h.MenuItem,{onAction:()=>e.expandRangeItem(e.range,!0),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(Je,{}),` Collapse all`]}),(0,f.jsxs)(h.MenuItem,{onAction:()=>window.confirm(`Are you sure you want to delete this range?`)&&O(e.range),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex text-red-500 gap-2 items-center`,children:[(0,f.jsx)(l.DeleteForeverIcon,{}),` Delete range item`]})]})})]}),A&&!!e.parentId&&(0,f.jsx)(l.ListResizeDragHandle,{})]})]})]})}),e.children]})}function at(e){let t=[];t.push({item:e,parent:null});for(let n of e.items||[])t.push({item:n,parent:e}),n.type===`Range`&&t.push(...at(n));return t}function ot(e,t){let n=new Set(e.filter(e=>e.item.type===`Canvas`).map(e=>e.item.id));return t.filter(e=>!n.has(e.id))}async function st(e){return Promise.all(e.map(async e=>{if(e.kind===`text`){let t=await e.getText(`text/plain`);return t?JSON.parse(t):null}return null}))}const ct=(0,g.create)()((e,t)=>({showCanvases:!0,toggleShowCanvases(){e(e=>({showCanvases:!e.showCanvases}))},isEditing:!1,toggleIsEditing(){e(e=>({isEditing:!e.isEditing}))}}));function lt(e){let t=(0,d.useVault)(),n=(0,d.useManifest)(),r=(0,u.useMemo)(()=>(0,o.createRangeHelper)(t),[t]),{isEditing:i,showCanvases:a,toggleShowCanvases:c}=ct(),{range:l,flatItems:p,canvasesNotInRanges:g}=(0,d.useVaultSelector)((t,i)=>{let a=e.selectedTopLevelRange?[i.get(e.selectedTopLevelRange)]:i.get(n.structures||[]),o=r.rangesToTableOfContentsTree(a,void 0,{showNoNav:!0})||{},s=at(o);return{structures:a,range:o,flatItems:s,canvasesNotInRanges:ot(s,n?.items||[])}}),v=(0,u.useMemo)(()=>p.filter(({item:e})=>e.type===`Range`&&e.items?.length).filter(({item:e})=>(e.items?.length||0)<500).filter(({item:e})=>!e.isRangeLeaf&&!e.isCanvasLeaf).map(({item:e})=>e.id),[p]),y=(0,u.useMemo)(()=>[l],[l]),[b,x]=(0,u.useState)(v),{dragAndDropHooks:S}=(0,h.useDragAndDrop)({isDisabled:!1,getItems:(e,t)=>[...e].map(e=>{let t=p.find(t=>t.item.id===e);return t?{"text/plain":JSON.stringify({item:t.item.id,parent:t.parent})}:{"text/plain":e.toString()}}),renderDragPreview(e){return(0,f.jsx)(`div`,{className:`opacity-50 bg-gray-200 rounded p-1`,children:(0,f.jsxs)(`span`,{className:``,children:[e.length,` items`]})})},onDrop:async e=>{let n=await st(e.items),r=null;if(r=e.target.type===`root`?l.id:e.target.key,!r){console.log(`[error] No valid target found`);return}let i=p.find(t=>e.target.key===t.item.id);if(e.target.type===`item`&&e.target.dropPosition===`on`&&i?.item.type===`Canvas`||!i)return;let a=r.toString();if(e.dropOperation===`move`&&e.target.type===`item`&&(e.target.dropPosition===`before`||e.target.dropPosition===`after`?a=i?.parent?.id:e.target.dropPosition===`on`&&(a=r.toString())),!a){console.log(`[error] No valid target parent found`);return}if(!t.get({id:a,type:`Range`})){console.log(`[error] No valid target range found in Vault`);return}let o=n.map(e=>{let t=p.findIndex(t=>e.item===t.item.id);if(t===-1)return null;let n=p[t];return{id:n?.item.id,type:n?.item.type,order:t}}).filter(e=>e!==null).sort((e,t)=>e.order-t.order).map(e=>({id:e.id,type:e.type})),c=n[0],u=p.find(e=>c.item===e.item.id);if(!u){let n=t.get(c.item);if(!n?.id||!n?.type){console.log(`[error] No valid item found in Vault`);return}let i=t.get({id:a,type:`Range`}).items.findIndex(e=>(0,m.toRef)(e)?.id===r),o={type:`SpecificResource`,source:{id:n.id,type:n.type}},s=new _.EditorInstance({reference:{id:a,type:`Range`},vault:t});e.target.type===`item`&&(e.target.dropPosition===`on`&&s.structural.items.add(o),e.target.dropPosition===`after`&&s.structural.items.addAfter(i,o),e.target.dropPosition===`before`&&s.structural.items.addBefore(i,o));return}if(!u.parent){console.log(`[error] No valid parent found for item to move`);return}let d=t.get({id:u.parent.id,type:`Range`});if(e.target.type===`root`||e.target.type===`item`&&e.target.dropPosition===`on`){t.dispatch((0,s.moveEntities)({subjects:{type:`list`,items:o},from:{id:u.parent.id,type:`Range`,key:`items`},to:{id:a,type:`Range`,key:`items`}}));return}if(u.parent.id===a&&e.dropOperation===`move`){let n=d.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===u.item.id),i=d.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===r);if(n===i){console.log(`[error] No valid index found for item to move`);return}if(n===-1||i===-1){console.log(`[error] Invalid index found for item to move`);return}n>i&&e.target.dropPosition===`after`&&(i+=1),n<i&&e.target.dropPosition===`after`&&(i-=o.length-1),t.dispatch((0,s.moveEntities)({subjects:{type:`list`,items:o},from:{id:a,type:`Range`,key:`items`},to:{id:a,type:`Range`,key:`items`,index:i}}));return}let f=d.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===u.item.id);if(f===-1){console.log(`[error] Invalid index found for item to move`);return}if(!d.items[f]){console.log(`[error] Invalid reference found for item to move`);return}let h=t.get({id:a,type:`Range`});if(!h){console.log(`[error] Invalid target parent found`);return}let g=h.items.findIndex(e=>(0,m.toRef)(e)?.id===r);if(g===-1){console.log(`[error] Invalid target item found`);return}t.dispatch((0,s.moveEntities)({subjects:{type:`list`,items:o},from:{id:u.parent.id,type:`Range`,key:`items`},to:{id:a,type:`Range`,key:`items`,index:e.target.dropPosition===`after`?g+1:g}}))}}),C=(0,u.useCallback)((e,t)=>{if(e.isCanvasLeaf)return;let n=(e.items||[]).map(e=>e.id);if(t){x(e=>Array.from(e).filter(e=>!n.includes(e.toString())));return}x(t=>Array.from(new Set([...t,e.id,...n])))},[]);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(h.Tree,{"aria-label":(0,o.getValue)(l.label),items:y,expandedKeys:b,dragAndDropHooks:S,onExpandedChange:x,selectionMode:i?`multiple`:`single`,selectionBehavior:`toggle`,children:function(e){return(0,f.jsx)(dt,{item:e,expandRangeItem:C})}}),g.length===0?null:(0,f.jsxs)(h.Disclosure,{className:`w-full`,children:[(0,f.jsx)(h.Heading,{children:(0,f.jsxs)(h.Button,{slot:`trigger`,className:`group flex items-center hover:bg-gray-100 px-2 py-1.5 gap-3 w-full text-gray-500`,children:[(0,f.jsx)(tt,{className:`text-xl group-[&[aria-expanded="true"]]:rotate-0 -rotate-90 transition-transform`}),(0,f.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,f.jsx)(ut,{className:`text-xl`}),`Canvases without a range`]})]})}),(0,f.jsx)(h.DisclosurePanel,{children:g.map(e=>(0,f.jsx)(d.CanvasContext,{canvas:e.id,children:(0,f.jsx)(nt,{})},e.id))})]})]})}function ut(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M1 21h22L12 2zm3.47-2L12 5.99L19.53 19zM11 16h2v2h-2zm0-6h2v4h-2z`})})}function dt({item:e,parent:t,expandRangeItem:n}){let{showCanvases:r}=ct();return e.type===`Canvas`?!e.resource||!r?null:(0,f.jsx)(d.CanvasContext,{canvas:e.resource?.source.id,children:(0,f.jsx)(rt,{rangeItem:e,parent:t})}):(0,f.jsx)(it,{range:e,hasChildItems:!!e.items,parentId:t?.id,expandRangeItem:n,children:(0,f.jsx)(h.Collection,{items:e.items||[],children:t=>(0,f.jsx)(dt,{item:t,parent:e,expandRangeItem:n})})})}function ft({range:e,isSplitting:t,onSplit:n,onMergeDown:r,onMergeUp:c,mergeDownLabel:p,mergeUpLabel:m,nextRangeLabel:g,onPreviewCanvas:x,onClosePreview:S}){let[{size:C}]=(0,l.useGridOptions)(`default-grid-size`,{defaultGridSize:`grid-sm`}),{edit:w}=(0,a.useLayoutActions)(),[T,E]=(0,u.useState)(!0),[D,O]=(0,u.useState)(!1),[k,{intersector:A,isFullyLoaded:j,loadMore:M,reset:N}]=(0,l.useLoadMoreItems)(e.items||[],{batchSize:32}),P=(0,d.useVault)(),F=(0,u.useRef)(null),{isDropTarget:I,dropProps:L}=(0,v.useDrop)({ref:F,async onDrop(t){let n=await st(t.items),r=n[0];if(!r)return;let i=r.parent?.id;if(!i&&t.type===`drop`){let t=P.get(r.item);if(!t?.id||!t?.type){console.log(`[error] No valid item found in Vault`);return}let n=e.id,i={type:`SpecificResource`,source:{id:t.id,type:t.type}};new _.EditorInstance({reference:{id:n,type:`Range`},vault:P}).structural.items.add(i)}let a=n.map(e=>{let t=P.get(e.item);return t?.type?{id:t.id,type:t.type}:null}).filter(e=>e!==null);a.length&&i!==e.id&&P.dispatch((0,s.moveEntities)({subjects:{type:`list`,items:a},from:{id:i,type:`Range`,key:`items`},to:{id:e.id,type:`Range`,key:`items`}}))}}),R=!e.items||e.items?.length===0,z=(e.items??[]).find(e=>e.type===`Canvas`)?.id;return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{ref:F,...L,"data-drop-target":I,style:{paddingInlineStart:`calc(1rem + var(--manifest-editor-layout-left-sidebar-small, 0px))`,paddingInlineEnd:`calc(1rem + var(--manifest-editor-layout-right-sidebar-small, 0px))`},className:(0,y.twMerge)(`w-full border-b border-b-gray-500/20 p-4 relative`,I&&`bg-me-primary-100`),children:[(0,f.jsx)(`div`,{id:`workbench-${e.id}`,className:`absolute -top-16`}),(0,f.jsxs)(`div`,{className:`flex items-center gap-4 max-w-full`,children:[(0,f.jsxs)(h.Button,{"aria-label":`${T?`Collapse`:`Expand`} ${(0,o.getValue)(e.label)||`untitled range`}`,className:`flex items-center gap-2 min-w-0`,onPress:()=>{T&&N(),E(!T)},children:[(0,f.jsx)(tt,{className:`text-xl`,style:{transition:`transform .2s`,transform:`rotate(${T?`0deg`:`-90deg`})`}}),D?null:(0,f.jsx)(d.LocaleString,{className:`text-xl text-left truncate overflow-ellipsis min-w-0 flex-1`,children:e.label||`Untitled range`})]}),D?(0,f.jsx)(i.InlineLabelEditor,{resource:{id:e.id,type:`Range`},onSubmit:()=>O(!1)}):null,(0,f.jsxs)(h.MenuTrigger,{children:[(0,f.jsx)(l.ActionButton,{"aria-label":`Actions for ${(0,o.getValue)(e.label)||`untitled range`}`,children:(0,f.jsx)(l.MoreMenuIcon,{"aria-hidden":`true`,className:`text-xl`})}),(0,f.jsx)(h.Popover,{className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsxs)(h.Menu,{children:[(0,f.jsxs)(h.MenuItem,{className:`hover:bg-me-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,onAction:()=>O(!0),children:[(0,f.jsx)(je,{}),`Edit range label`]}),(0,f.jsxs)(h.MenuItem,{className:`hover:bg-me-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,onAction:()=>w(e,{property:`metadata`},{forceOpen:!0,selectedTab:`@manifest-editor/metadata`}),children:[(0,f.jsx)(l.ListingIcon,{}),`Edit range metadata`]}),!R&&c&&(0,f.jsxs)(h.MenuItem,{onPress:()=>c(e,!0),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(mt,{className:`text-md`}),` Empty contents into`,(0,f.jsx)(d.LocaleString,{className:`font-semibold`,children:m})]}),!R&&r&&(0,f.jsxs)(h.MenuItem,{onPress:()=>r(e,!0),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,children:[(0,f.jsx)(ht,{className:`text-md`}),` Empty contents into`,(0,f.jsx)(d.LocaleString,{className:`font-semibold`,children:p})]}),!R&&(0,f.jsx)(h.Separator,{className:`h-0.5 bg-gray-200`}),!R&&c&&(0,f.jsxs)(h.MenuItem,{onPress:()=>window.confirm(`This range will be removed and the items will be merged into the previous range.`)&&c(e),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center text-red-500`,children:[(0,f.jsx)(mt,{className:`text-md`}),` Merge into`,(0,f.jsx)(d.LocaleString,{className:`font-semibold`,children:m})]}),!R&&r&&(0,f.jsxs)(h.MenuItem,{onPress:()=>{window.confirm(`This range will be removed and the items will be merged into the next range.`)&&r(e)},className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center text-red-500`,children:[(0,f.jsx)(ht,{className:`text-md`}),` Merge into`,(0,f.jsx)(d.LocaleString,{className:`font-semibold`,children:p})]})]})})]}),(0,f.jsxs)(l.ActionButton,{onPress:()=>w({id:e.id,type:`Range`}),children:[e.isRangeLeaf?`View range item`:`Edit range item`,(0,f.jsx)(Ie,{className:`text-xl`})]})]}),T?(0,f.jsxs)(f.Fragment,{children:[(k||[]).length===0&&(0,f.jsx)(We,{extraClasses:`mt-4`}),(0,f.jsx)(`div`,{className:`grid pt-4 gap-3 ${C}`,children:(k||[]).map(r=>{let i=r.id===z;return r.type===`Canvas`?(0,f.jsx)(d.CanvasContext,{canvas:r.resource.source.id,children:(0,f.jsx)(l.CanvasThumbnailGridItem,{"aria-disabled":r.id===z,onClick:()=>{t&&!i&&n(e,r),t||x?.(e,r)},dragState:{item:r.id,parent:{id:e.id}},containerProps:{"aria-label":`Preview ${(0,o.getValue)(r.label)||`canvas`}`,"data-range1-label":(0,o.getValue)(e.label),"data-range2-label":g||`Untitled range`,...i?{"data-split-first":`true`}:{}},className:t?`split-range-highlight`:``,id:r.resource.source.id,icon:(0,f.jsx)(pt,{"aria-hidden":`true`,className:`absolute top-2 right-2 hidden text-2xl group-hover:block`})})},r.id):(0,f.jsxs)(`div`,{className:`items-center justify-center flex flex-col`,children:[(0,f.jsx)(He,{range:r,dragState:{item:r.id,parent:{id:e.id}},onClick:()=>{if(r.isRangeLeaf&&r.parent?.id){(0,b.flushSync)(()=>{w({id:r.parent?.id,type:`Range`})}),document.getElementById(`workbench-${String(r.id)}`)?.scrollIntoView({behavior:`smooth`,block:`start`,inline:`start`,container:`nearest`});return}w({id:r.id,type:`Range`})}}),(0,f.jsx)(d.LocaleString,{className:`truncate overflow-ellipsis max-w-full text-sm`,children:r.label||`Untitled range`})]},r.id)})}),j?null:(0,f.jsx)(l.ActionButton,{onPress:M,children:`Load more`})]}):null]},e.id),A]})}function pt(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M21 8.59V4c0-.55-.45-1-1-1h-4.59c-.89 0-1.34 1.08-.71 1.71l1.59 1.59l-10 10l-1.59-1.59c-.62-.63-1.7-.19-1.7.7V20c0 .55.45 1 1 1h4.59c.89 0 1.34-1.08.71-1.71L7.71 17.7l10-10l1.59 1.59c.62.63 1.7.19 1.7-.7`})})}function mt(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`m4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8z`})})}function ht(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`m20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8z`})})}const gt={id:`range-workbench`,label:`Range Workbench`,icon:(0,f.jsx)(Ne,{}),focusedMode:{hide:!0},render:()=>(0,f.jsx)(St,{})},_t=p.default.div`
|
|
42
42
|
flex: 1 1 0;
|
|
43
43
|
min-height: 0;
|
|
44
44
|
overflow-y: auto;
|
|
45
|
-
`,gt=p.default.div`
|
|
46
|
-
padding-inline-start: calc(
|
|
47
|
-
1rem + var(--manifest-editor-layout-left-sidebar-small, 0px)
|
|
48
|
-
);
|
|
49
|
-
padding-inline-end: calc(
|
|
50
|
-
1rem + var(--manifest-editor-layout-right-sidebar-small, 0px)
|
|
51
|
-
);
|
|
52
|
-
`,_t=(0,p.default)(l.InfoMessage)`
|
|
53
|
-
padding-inline-start: calc(
|
|
54
|
-
1rem + var(--manifest-editor-layout-left-sidebar-small, 0px)
|
|
55
|
-
);
|
|
56
|
-
padding-inline-end: calc(
|
|
57
|
-
1rem + var(--manifest-editor-layout-right-sidebar-small, 0px)
|
|
58
|
-
);
|
|
59
45
|
`,vt=p.default.div`
|
|
46
|
+
padding-inline-start: calc(1rem + var(--manifest-editor-layout-left-sidebar-small, 0px));
|
|
47
|
+
padding-inline-end: calc(1rem + var(--manifest-editor-layout-right-sidebar-small, 0px));
|
|
48
|
+
`,yt=(0,p.default)(l.InfoMessage)`
|
|
49
|
+
padding-inline-start: calc(1rem + var(--manifest-editor-layout-left-sidebar-small, 0px));
|
|
50
|
+
padding-inline-end: calc(1rem + var(--manifest-editor-layout-right-sidebar-small, 0px));
|
|
51
|
+
`,bt=p.default.div`
|
|
60
52
|
padding-inline-start: var(--manifest-editor-layout-left-sidebar-small, 0px);
|
|
61
53
|
padding-inline-end: var(--manifest-editor-layout-right-sidebar-small, 0px);
|
|
62
|
-
`;function yt(e){let t=(0,o.getValue)(e);if(!t)return`Untitled range`;let n=t.match(/(.+)(\d+)/);if(!n)return`Untitled range`;let r=n?.[2]?parseInt(n[2],10):1;return`${n?n[1]:``}${r+1}`}function bt(){let e=(0,i.useInStack)(`Range`),[{size:t},n]=(0,l.useGridOptions)(`default-grid-size`,{defaultGridSize:`grid-sm`,onDark:!0}),r=(0,d.useVault)(),s=(0,d.useManifest)(),c=(0,u.useMemo)(()=>(0,o.createRangeHelper)(r),[r]),p=(0,a.useInlineCreator)(),[g,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(null),b=(0,u.useCallback)((e,t)=>{I.current&&(R.current=I.current.scrollTop),y({range:e,canvas:t})},[]),x=(0,u.useCallback)(()=>{y(null),requestAnimationFrame(()=>{I.current&&(I.current.scrollTop=R.current)})},[]),{isSplitting:S,setIsSplitting:C,splitEffect:w}=ze();(0,u.useEffect)(w,[e]);let T=(0,d.useVaultSelector)((t,n)=>{let r=(0,m.toRef)(e?.resource);if(r)return c.rangeToTableOfContentsTree(n.get(r),{showNoNav:!0});if(!s.structures)return null;let i=n.get(s.structures||[]);return c.rangesToTableOfContentsTree(i,void 0,{showNoNav:!0})||null},[s,e]);(0,u.useEffect)(()=>{if(!T){y(null);return}y(e=>{if(e===null)return null;let t=(T.items||[]).find(e=>e.type===`Canvas`);return t?e?.range.id===T.id?e:{range:T,canvas:t}:null})},[T?.id]);let E=(0,a.useGenericEditor)(T?.id?{id:T?.id,type:`Range`}:void 0,{allowNull:!0}),D=(0,u.useCallback)((e,t,n)=>{E.structural.ranges.mergeRanges(e,t,n)},[E]),O=(0,u.useCallback)(async e=>{e!==-1&&E.structural.items.deleteAtIndex(e)},[E]),k=(0,u.useCallback)(async(e,t)=>{T&&await E.structural.ranges.splitRange(T,e,t,t=>p.create(`@manifest-editor/range-with-items`,{type:`Range`,label:{en:[yt(e.label)]},items:[]},{parent:{property:`items`,resource:{id:T.id,type:`Range`},atIndex:t}}))},[T,E,p]),{edit:A}=(0,a.useLayoutActions)(),{back:j}=(0,a.useEditingStack)(),[M,N]=(0,u.useState)(!1),[P,F]=(0,u.useState)(!1),I=(0,u.useRef)(null),L=(0,u.useRef)(null),R=(0,u.useRef)(0),[z,ee]=(0,u.useState)(!1),B=(T?.items??[]).filter(e=>e.type===`Range`),V=B.length;(0,u.useEffect)(()=>{if(typeof window>`u`||V===0){N(!1);return}let e=document.getElementById(`range-workbench-scroll`),t=B[B.length-1]?.id,n=t?document.getElementById(`workbench-${t}`):null;if(!e||!n)return;let r=new IntersectionObserver(([e])=>N(e.isIntersecting),{root:e,threshold:0,rootMargin:`0px 0px -1px 0px`});r.observe(n);let i=n.getBoundingClientRect(),a=e.getBoundingClientRect();return N(i.top<a.bottom&&i.bottom>a.top),()=>r.disconnect()},[V,B]),(0,u.useEffect)(()=>{let e=document.getElementById(`range-workbench-scroll`);if(!e)return;let t=()=>{let{scrollTop:t,clientHeight:n,scrollHeight:r}=e;F(t+n>=r-2)};t(),e.addEventListener(`scroll`,t);let n=new ResizeObserver(t);return n.observe(e),window.addEventListener(`resize`,t),()=>{e.removeEventListener(`scroll`,t),window.removeEventListener(`resize`,t),n.disconnect()}},[T?.id,V,S,t]),(0,u.useEffect)(()=>{let e=I.current,t=L.current;if(!e||!t)return;let n=new IntersectionObserver(([e])=>{e&&ee(e.isIntersecting)},{root:e,threshold:.01});return n.observe(t),()=>{n.disconnect()}},[V,S,v]);let H=(T?.items||[]).filter(e=>e.type===`Canvas`),te=(0,u.useCallback)(()=>{I.current?.scrollTo({top:0,behavior:`smooth`})},[]),ne=(0,u.useCallback)(()=>{let e=L.current,t=I.current;e&&t?e.scrollIntoView({behavior:`smooth`,block:`end`,inline:`end`}):t&&t.scrollTo({top:t.scrollHeight,behavior:`smooth`})},[]),U=(0,d.useVaultSelector)((e,t)=>{if(!s?.structures)return null;let n=t.get(s.structures||[]);return c.rangesToTableOfContentsTree(n,void 0,{showNoNav:!0})||null},[s]),re=(0,u.useMemo)(()=>{let e=new Map,t=n=>{if(n?.items)for(let r of n.items)r?.type===`Range`&&(e.set(r.id,n.id),t(r))};return U&&t(U),e},[U]),W=(0,m.toRef)(e?.resource)?.id??e?.resource?.id??null,ie=(0,u.useCallback)(()=>{if(!W){j();return}let e=re.get(W);e?A({id:e,type:`Range`}):j()},[W,re,A,j]),ae=(0,u.useMemo)(()=>!!(W&&re.has(W)),[W,re]),G=(0,d.useVaultSelector)((e,t)=>{if(!v?.range?.id)return null;let n=t.get(v.range.id);return n?.label?(0,o.getValue)(n.label):(0,o.getValue)(v.range.label)},[v?.range?.id]);return T?(0,f.jsxs)(ht,{id:`range-workbench-scroll`,ref:I,children:[!v&&(0,f.jsxs)(gt,{className:`flex flex-row justify-between bg-me-primary-500 sticky top-0 h-16 z-30 border-me-400 border-b`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-4`,children:[ae?(0,f.jsx)(l.ActionButton,{onPress:()=>ie(),children:(0,f.jsx)(Re,{className:`text-xl`})}):null,g&&!T.isVirtual?(0,f.jsx)(i.InlineLabelEditor,{className:``,resource:T,onSubmit:()=>_(!1)}):(0,f.jsx)(i.InlineLocaleStringEditor,{editor:E.descriptive.label,as:`h3`,className:`text-xl text-white`,children:T.label},T.id),(0,f.jsxs)(h.MenuTrigger,{children:[(0,f.jsx)(l.ActionButton,{children:(0,f.jsx)(l.MoreMenuIcon,{className:`text-xl`})}),(0,f.jsx)(h.Popover,{className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsx)(h.Menu,{children:(0,f.jsxs)(h.MenuItem,{className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,onAction:()=>_(!0),children:[(0,f.jsx)(ke,{}),`Edit range label`]})})})]}),!S&&(T?.items?.length??0)>0&&!T.isRangeLeaf&&(0,f.jsxs)(l.ActionButton,{onPress:()=>C(!0),children:[(0,f.jsx)(Me,{className:`text-xl`}),` Split range`]}),(0,f.jsx)(We,{})]}),n]}),S&&!v?(0,f.jsxs)(_t,{className:`mb-4 flex gap-4 sticky top-16 rounded-none z-30`,children:[`Splitting range, click to confirm the the new range item`,(0,f.jsx)(l.ActionButton,{onPress:()=>C(!1),children:`Exit splitting mode`})]}):null,v&&(0,f.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,f.jsxs)(gt,{className:`flex bg-me-primary-500 sticky top-0 h-16 z-20 border-b-white border-b items-center gap-4`,children:[(0,f.jsx)(l.ActionButton,{onPress:x,children:(0,f.jsx)(Ne,{className:`text-xl`})}),g&&!T.isVirtual?(0,f.jsx)(i.InlineLabelEditor,{className:`text-base font-normal mt-1`,resource:v.range,onSubmit:()=>_(!1)}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(d.LocaleString,{className:`text-xl text-left truncate overflow-ellipsis min-w-0 text-white`,children:G}),(0,f.jsxs)(h.MenuTrigger,{children:[(0,f.jsx)(l.ActionButton,{children:(0,f.jsx)(l.MoreMenuIcon,{className:`text-xl`})}),(0,f.jsx)(h.Popover,{className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsx)(h.Menu,{children:(0,f.jsxs)(h.MenuItem,{className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,onAction:()=>_(!0),children:[(0,f.jsx)(ke,{}),`Edit range label`]})})})]})]})]}),(0,f.jsx)(Ze,{range:v.range,canvas:v.canvas,onBack:()=>y(null),setCanvas:e=>y(t=>t&&{...t,canvas:e})})]}),!v&&(T.items||[]).map((e,t)=>{if(e.type===`Canvas`)return null;let n=t-1,r=t+1,i=r!==T.items?.length&&T.items?.[r]?.items?.length===0?(0,o.getValue)(T.items?.[r]?.label):yt(e.label);return(0,f.jsx)(ut,{idx:t,isSplitting:S,onSplit:k,range:e,onMergeUp:t===0?void 0:(t,r)=>D(e,T.items?.[n],r),onMergeDown:T.items?.[r]?(t,n)=>D(e,T.items?.[r],n):void 0,nextRangeLabel:i,onDelete:()=>O(t),mergeUpLabel:n===-1?``:T.items?.[n]?.label,mergeDownLabel:r===T.items?.length?``:T.items?.[r]?.label,onPreviewCanvas:b,onClosePreview:()=>y(null)},e.id)}),!v&&H.length?(0,f.jsx)(d.RangeContext,{range:T.id,children:(0,f.jsx)(Ve,{})}):null,H.length===0&&B.length===0&&(0,f.jsx)(vt,{children:(0,f.jsx)(He,{extraClasses:`my-4`})}),!v&&B.length>0?(0,f.jsx)(`div`,{className:`sticky bottom-5 float-right right-5`,children:z?(0,f.jsxs)(l.ActionButton,{primary:!0,onPress:te,children:[`Scroll to top `,(0,f.jsx)(Re,{})]}):(0,f.jsxs)(l.ActionButton,{primary:!0,onPress:ne,children:[`Scroll to bottom `,(0,f.jsx)(Le,{})]})}):null,(0,f.jsx)(`div`,{id:`workbench-bottom`,ref:L})]}):null}const xt={id:`manifest-context-menus`,label:`Context menus`,render:()=>(0,f.jsx)(St,{})};function St(){return(0,f.jsx)(Ct,{})}function Ct(){let e=(0,i.useInStack)(`Canvas`),t=e?.resource.source,n=(0,a.useEditingResource)()?.resource?.source?.id,r=(0,d.useCanvas)(t||void 0),{edit:o}=(0,a.useLayoutActions)(),s=r?.items?.[0]?.id,[c,l]=(0,a.useCreator)({id:s,type:`AnnotationPage`},`items`,`Annotation`,t,{isPainting:!0});return(0,a.useCustomContextMenu)({sectionTitle:`Canvas`,resource:{type:`Canvas`},items:[{id:`edit-canvas`,label:`Edit metadata`,enabled:!0,onAction:()=>o({id:e?.resource?.source?.id,type:`Canvas`},void 0,{forceOpen:!0})},{id:`add-media`,label:`Add media...`,enabled:!0,onAction:({resource:e})=>{n!==e.id&&o(e),l.create()}},{id:`add-browser`,label:`Add from IIIF Browser`,enabled:!0,onAction:({resource:e})=>{n!==e.id&&o(e),l.creator(`@manifest-editor/iiif-browser-creator`)}}]},[t,n,c]),null}function wt({title:e,...t}){return(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,height:`1em`,width:`1em`,...t,children:[(0,f.jsx)(`path`,{fill:`none`,d:`M0 0h24v24H0z`}),(0,f.jsx)(`path`,{d:`M20 9H4v2h16V9zM4 15h16v-2H4v2z`}),e?(0,f.jsx)(`title`,{children:e}):null]})}function Tt(){let e=(0,d.useVault)(),t=(0,d.useManifest)(),n=(0,a.useManifestEditor)(),r=(0,i.useInStack)(`Range`),s=(0,u.useMemo)(()=>(0,o.createRangeHelper)(e),[e]),{edit:c}=(0,a.useLayoutActions)(),{back:p}=(0,a.useEditingStack)(),{isEditing:g,showCanvases:v,toggleShowCanvases:y}=ot(),b=(0,d.useVaultSelector)((e,n)=>{if(r)return s.rangeToTableOfContentsTree(n.get(r.resource),{showNoNav:!0});let i=n.get(t.structures||[]);return s.rangesToTableOfContentsTree(i,void 0,{showNoNav:!0})||{}},[e,t,r]),x=(0,u.useMemo)(()=>(b.items||[]).filter(e=>e.type===`Range`),[b]),S=rt(b);async function C(e){return Promise.all(e.map(async e=>e.kind===`text`?JSON.parse(await e.getText(`text/plain`)):null))}let{dragAndDropHooks:w}=(0,h.useDragAndDrop)({isDisabled:!g,getItems:(e,t)=>[...e].map(e=>{let t=S.find(t=>t.item.id===e);return t?{"text/plain":JSON.stringify({item:t.item.id,parent:t.parent?{id:t.parent.id}:void 0})}:{"text/plain":e.toString()}}),renderDragPreview(e){return(0,f.jsx)(`div`,{className:`opacity-50 bg-gray-200 rounded p-1`,children:(0,f.jsxs)(`span`,{className:``,children:[e.length,` items`]})})},onDrop:async t=>{let n=await C(t.items),r=null;if(r=t.target.type===`root`?b.id:t.target.key,!r){console.log(`[error] No valid target found`);return}let i=S.find(e=>t.target.key===e.item.id);if(t.target.type===`item`&&t.target.dropPosition===`on`&&i?.item.type===`Canvas`)return;let a=r.toString();if(t.dropOperation===`move`&&t.target.type===`item`&&(t.target.dropPosition===`before`||t.target.dropPosition===`after`?a=i?.parent?.id:t.target.dropPosition===`on`&&(a=r.toString())),!a){console.log(`[error] No valid target parent found`);return}if(!e.get({id:a,type:`Range`})){console.log(`[error] No valid target range found in Vault`);return}let o=new _.EditorInstance({reference:{id:a,type:`Range`},vault:e}),s=n[0],c=S.find(e=>s.item===e.item.id);if(!c){console.log(`[error] No valid item found for item to move`);return}if(!c.parent){console.log(`[error] No valid parent found for item to move`);return}let l=e.get({id:c.parent.id,type:`Range`}),u=new _.EditorInstance({reference:{id:c.parent.id,type:`Range`},vault:e});if(t.target.type===`root`||t.target.type===`item`&&t.target.dropPosition===`on`){let e=l.items.find(e=>(0,m.toRef)(e,`Canvas`)?.id===c.item.id);if(!e){console.log(`[error] No valid reference found for item to move`);return}let t=l.items.indexOf(e);if(t===-1){console.log(`[error] No valid index found for item to move`);return}o.structural.items.add(e),u.structural.items.deleteAtIndex(t);return}if(c.parent.id===a){let e=l.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===c.item.id),t=l.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===r);if(e===t){console.log(`[error] No valid index found for item to move`);return}if(e===-1||t===-1){console.log(`[error] Invalid index found for item to move`);return}u.structural.items.reorder(e,t);return}let d=l.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===c.item.id);if(d===-1){console.log(`[error] Invalid index found for item to move`);return}let f=l.items[d];if(!f){console.log(`[error] Invalid reference found for item to move`);return}let p=e.get({id:a,type:`Range`});if(!p){console.log(`[error] Invalid target parent found`);return}let h=p.items.findIndex(e=>(0,m.toRef)(e)?.id===r);if(h===-1){console.log(`[error] Invalid target item found`);return}let g=!1;if(t.target.dropPosition===`after`&&(g=o.structural.items.addAfter(h,f)),t.target.dropPosition===`before`&&(g=o.structural.items.addBefore(h,f)),g){let e=l.items.indexOf(f);e!==-1&&u.structural.items.deleteAtIndex(e)}}}),T=(0,u.useCallback)(t=>{if(b.isVirtual){let e=n.structural.structures.getWithoutTracking().findIndex(e=>e.id===t.id);e!==-1&&n.structural.structures.deleteAtIndex(e);return}let r=new _.EditorInstance({reference:{id:b.id,type:`Range`},vault:e}),i=r.structural.items.getWithoutTracking().findIndex(e=>e.id===t.id);i!==-1&&r.structural.items.deleteAtIndex(i)},[b.id,b.isVirtual,n,e]),E=(0,f.jsx)(`div`,{className:`flex items-center gap-4 mb-4`,children:r?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(l.ActionButton,{onPress:()=>p(),children:(0,f.jsx)(l.BackIcon,{className:`text-xl`})}),(0,f.jsx)(d.LocaleString,{as:`h3`,children:b.label})]}):null});return b.isRangeLeaf?(0,f.jsxs)(f.Fragment,{children:[E,(0,f.jsx)(l.EmptyState,{children:`This Range only contains canvases.`})]}):x.length===0?(0,f.jsxs)(f.Fragment,{children:[E,(0,f.jsx)(l.EmptyState,{children:`No ranges found`})]}):(0,f.jsxs)(f.Fragment,{children:[E,(0,f.jsx)(h.GridList,{className:`w-full flex flex-col gap-2`,items:x,dragAndDropHooks:w,dependencies:[g],children:e=>(0,f.jsx)(h.GridListItem,{id:e.id,onAction:()=>{g||c(e)},className:`border border-gray-300 hover:border-me-500 shadow-sm rounded bg-white relative p-4`,children:(0,f.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(d.LocaleString,{className:`text-lg mb-4`,children:e.label}),(0,f.jsxs)(`div`,{className:`text-sm text-me-primary-600`,children:[e.items?.length,` `,e.isRangeLeaf?`Canvases`:`Ranges`]})]}),g?(0,f.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,f.jsxs)(h.MenuTrigger,{children:[(0,f.jsx)(l.ActionButton,{children:(0,f.jsx)(l.MoreMenuIcon,{className:`text-lg`})}),(0,f.jsx)(h.Popover,{className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsx)(h.Menu,{children:(0,f.jsxs)(h.MenuItem,{onAction:()=>window.confirm(`Are you sure you want to delete this range?`)&&T(e),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex text-red-500 gap-2 items-center`,children:[(0,f.jsx)(l.DeleteForeverIcon,{}),` Delete range item`]})})})]}),(0,f.jsx)(h.Button,{slot:`drag`,children:(0,f.jsx)(wt,{className:`text-xl`})})]}):null]})})})]})}function Et(){let{setIsSplitting:e}=ze();return(0,f.jsxs)(l.SidebarContent,{children:[(0,f.jsx)(l.ActionButton,{onPress:()=>e(!1),children:`Exit splitting mode`}),(0,f.jsxs)(`div`,{className:`flex flex-col justify-center items-center px-4 gap-4`,children:[(0,f.jsx)(Me,{className:`w-32 h-32 text-gray-300`}),(0,f.jsx)(`div`,{className:`text-center text-black/80`,children:`Hover over the Canvases to select where you want to add a new range item. Click to select that Canvas. Note the first canvas can’t be split.`}),(0,f.jsxs)(`div`,{style:{background:`#EFF6FF`,padding:`1em`,border:`1px solid #1E40AF`,borderRadius:`4px`},children:[(0,f.jsx)(l.InfoIcon,{fontSize:`18px`,height:30,fill:`#31539F`,style:{float:`right`}}),`Creating your first range adds one range called “Range 1” that contains every canvas. You can rename it, split it, or move canvases into sub-ranges.`]})]})]})}function Dt(){let{ref:e,structural:t}=(0,a.useManifestEditor)(),n=(0,a.useInlineCreator)(),r=async()=>{if(!e)return;let r=await n.create(`@manifest-editor/range-top-level`,{label:{en:[`Range 1`]},type:`Range`,items:t.items.getWithoutTracking().map(e=>e)},{rootId:e().id});n.create(`@manifest-editor/range-top-level`,{type:`Range`,label:{en:[`Table of contents`]},items:[r]},{parent:{property:`structures`,resource:e()}})};return(0,f.jsxs)(l.Sidebar,{children:[(0,f.jsx)(l.SidebarHeader,{title:`Ranges`,actions:[{icon:(0,f.jsx)(l.AddIcon,{className:`text-2xl`}),title:`Add range`,disabled:!0,onClick:()=>void 0}]}),(0,f.jsx)(l.SidebarContent,{children:(0,f.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4`,children:[(0,f.jsx)(`div`,{className:`p-4 opacity-50 text-center`,children:`This manifest does not yet have a range(s). If you want to offer navigation, such as a table of contents, you can create a range.`}),(0,f.jsxs)(l.ActionButton,{large:!0,primary:!0,onPress:()=>r(),children:[(0,f.jsx)(l.AddIcon,{className:`text-xl`}),` Create new range`]})]})})]})}function Ot({range:e,setSelectedTopLevelRange:t}){let n=(0,a.useManifestEditor)(),r=(0,d.useVault)(),i=(0,a.useInlineCreator)(),o=(0,u.useCallback)(async()=>{new _.EditorInstance({reference:{id:e.id,type:`Range`},vault:r});let t=e.items||[],a=await i.create(`@manifest-editor/range-top-level`,{type:`Range`,label:{en:[`Range 1`]},items:[]},{parent:{property:`structures`,resource:{id:n.technical.id.getWithoutTracking(),type:`Manifest`},atIndex:0}});r.dispatch((0,s.moveEntities)({subjects:{type:`slice`,startIndex:1,length:t.length},from:{id:n.technical.id.getWithoutTracking(),type:`Manifest`,key:`structures`},to:{id:a.id,type:`Range`,key:`items`}}))},[]),c=(0,u.useCallback)(()=>{n.structural.ranges.empty()},[]);return(0,f.jsxs)(`div`,{children:[(0,f.jsx)(l.InfoMessage,{className:`mb-2 leading-tight text-sm`,children:`This manifests contains multiple top-level ranges. You can either merge them together into a single range or select a range to edit.`}),(0,f.jsx)(`h3`,{className:`mb-2 text-black/40`,children:`Choose an option`}),(0,f.jsxs)(`ul`,{className:`mb-4`,children:[(0,f.jsx)(`li`,{className:`px-2 py-1`,children:(0,f.jsxs)(l.ActionButton,{onClick:o,children:[(0,f.jsx)(qe,{}),`Combine into single range`]})}),(0,f.jsx)(`li`,{className:`px-2 py-1`,children:(0,f.jsxs)(l.ActionButton,{onClick:c,children:[(0,f.jsx)(l.DeleteForeverIcon,{}),`Delete ranges and start again`]})})]}),(0,f.jsx)(`h3`,{className:`mb-2 text-black/40`,children:`Choose a range to edit`}),(0,f.jsx)(`ul`,{children:(e.items||[]).map(e=>(0,f.jsx)(`li`,{className:`mb-1 bg-gray-100 hover:bg-gray-200 rounded px-2 py-1`,children:(0,f.jsx)(`button`,{onClick:()=>t({id:e.id,type:`Range`}),children:(0,f.jsx)(d.LocaleString,{children:e.label})})},e.id))})]})}const kt={id:`@manifest-editor/ranges-listing`,label:`Ranges`,icon:(0,f.jsx)(je,{}),focusedMode:{onSelect:({actions:e})=>{e.centerPanel.open({id:`range-workbench`})}},render:()=>(0,f.jsx)(At,{})};function At(){let t=(0,d.useVault)(),n=(0,d.useManifest)(),{edit:r}=(0,a.useLayoutActions)(),i=(0,u.useMemo)(()=>(0,o.createRangeHelper)(t),[t]),[s,c]=(0,l.useLocalStorage)(`isCardView`,!1),[p,m]=(0,u.useState)(null),h=(0,u.useMemo)(()=>i.rangesToTableOfContentsTree(p?[t.get(p)]:t.get(n.structures||[]),void 0,{showNoNav:!0}),[p,n?.structures]),{isSplitting:g,splitEffect:_,setIsSplitting:v}=ze(),{showCanvases:y,toggleShowCanvases:b,isEditing:x,toggleIsEditing:S}=ot();(0,u.useEffect)(()=>_(),[_]);let C=(0,u.useMemo)(()=>n?.structures?.[0]?i.isContiguous((n.structures||[])[0],n.items,{detail:!0}):null,[n,i]);return h?(0,f.jsxs)(l.Sidebar,{children:[(0,f.jsx)(l.SidebarHeader,{title:h.label||`Untitled range`,actions:[{id:`card-view`,title:s?`Tree view`:`Card view`,icon:s?(0,f.jsx)(e.s,{className:`text-xl`}):(0,f.jsx)(Fe,{className:`text-xl`}),onClick:()=>{c(!s)}},{id:`edit-ranges`,title:`Edit range`,icon:(0,f.jsx)(l.ListEditIcon,{className:`text-xl`}),toggled:x,onClick:S,disabled:h?.isVirtual},{id:`split-range`,title:`Split range`,icon:(0,f.jsx)(Me,{className:`text-xl`}),onClick:()=>v(!g),toggled:g,disabled:h?.isVirtual||(h?.items?.length??0)<=1}]}),(0,f.jsxs)(l.SidebarContent,{className:`p-2`,id:`range-listing-sidebar`,children:[p?(0,f.jsxs)(l.ActionButton,{className:`mb-4`,onClick:()=>m(null),children:[(0,f.jsx)(Ne,{}),` Back to Range List`]}):null,h.isVirtual?(0,f.jsx)(Ot,{range:h,setSelectedTopLevelRange:e=>{r(e),m(e)}}):(0,f.jsxs)(f.Fragment,{children:[C?null:(0,f.jsx)(l.WarningMessage,{className:`mb-2`,children:`Warning: Non-contiguous range`}),g?(0,f.jsx)(Et,{}):s?(0,f.jsx)(Tt,{}):(0,f.jsx)(st,{selectedTopLevelRange:p,hideCanvases:!y})]})]})]}):(0,f.jsx)(Dt,{})}const jt={id:`@manifest-editor/tags`,label:`Tags`,icon:(0,f.jsx)(zt,{}),supports:({vault:e,rootResource:t})=>Mt(e,t),render:()=>(0,f.jsx)(Nt,{})};function Mt(e,t){return!e||t?.type!==`Manifest`||!t.id?!1:(0,a.getResourceTagGroups)(e,(e.get(t,{skipSelfReturn:!1})?.items||[]).map(e=>e?.id).filter(e=>!!e).map(e=>({id:e,type:`Canvas`}))).length>0}function Nt(){let e=(0,d.useVault)(),{structural:t}=(0,a.useManifestEditor)(),n=t.items.get()||[],r=(0,u.useMemo)(()=>n.map(e=>e?.id).filter(e=>!!e).map(e=>({id:e,type:`Canvas`})),[n]),i=(0,d.useVaultSelector)(()=>(0,a.getResourceTagGroups)(e,r),[(0,u.useMemo)(()=>r.map(e=>e.id).join(`|`),[r])]),o=(0,u.useMemo)(()=>i.flatMap(e=>e.rows),[i]),s=(0,u.useMemo)(()=>o.map(e=>e.key).join(`|`),[o]),[c,p]=(0,u.useState)(()=>new Set),m=(0,u.useMemo)(()=>(0,a.createManifestEditorTagsApi)(e),[e]),h=(0,u.useMemo)(()=>o.filter(e=>c.has(e.key)),[o,c]),g=(0,u.useMemo)(()=>i.reduce((e,t)=>e+t.tagCount,0),[i]),_=(0,u.useMemo)(()=>new Set(i.flatMap(e=>e.canvasIds)).size,[i]);(0,u.useEffect)(()=>{let e=new Set(o.map(e=>e.key));p(t=>{let n=new Set(Array.from(t).filter(t=>e.has(t)));return n.size===t.size?t:n})},[s,o]);function v(e,t){if(!e.length)return;let n=e.reduce((e,t)=>e+t.canvasCount,0),r=new Set(e.flatMap(e=>e.canvasIds)).size;if(window.confirm(`Delete ${Y(n,`tag application`)} from ${Y(r,`canvas`)}?\n\n${t}`)){for(let t of e)for(let e of t.canvasIds)m.removeTag({id:e,type:`Canvas`},t.type,t.id);p(t=>{let n=new Set(t);for(let t of e)n.delete(t.key);return n})}}function y(e){v(e.rows,`Type: ${e.type}`)}function b(){v(h,`${Y(h.length,`tag`)} selected.`)}function x(){if(g&&window.confirm(`Delete all ${Y(g,`tag application`)} from ${Y(_,`canvas`)}?`)){for(let e of r)m.setTags(e,[]);p(new Set)}}return(0,f.jsxs)(l.Sidebar,{children:[(0,f.jsx)(l.SidebarHeader,{title:`Tags`,actions:[{icon:(0,f.jsx)(Bt,{className:`text-xl`}),title:`Delete all tags`,disabled:g===0,onClick:x}]}),(0,f.jsxs)(l.SidebarContent,{className:`p-3`,children:[(0,f.jsx)(Pt,{totalTagApplications:g,taggedCanvasCount:_,totalCanvasCount:r.length}),r.length?i.length?(0,f.jsx)(`div`,{className:`grid gap-3 pb-4`,children:i.map(e=>(0,f.jsx)(It,{group:e,selectedRows:c,onToggleRow:(e,t)=>{p(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},onRemoveGroup:()=>y(e)},e.key))}):(0,f.jsx)(Ft,{title:`No canvas tags`,message:`Canvas tags added by editor tools and background actions will appear here.`}):(0,f.jsx)(Ft,{title:`No canvases`,message:`Canvas tags will appear here after canvases are added.`})]}),(0,f.jsx)(`div`,{className:`border-t border-me-gray-200 bg-white p-3`,children:(0,f.jsxs)(l.ActionButton,{primary:!0,center:!0,className:`w-full justify-center`,isDisabled:!h.length,onPress:b,children:[(0,f.jsx)(Bt,{className:`text-xl`}),`Delete selected (`,h.length,`)`]})})]})}function Pt({totalTagApplications:e,taggedCanvasCount:t,totalCanvasCount:n}){return(0,f.jsxs)(`div`,{className:`mb-3 grid grid-cols-2 gap-2 text-xs`,children:[(0,f.jsxs)(`div`,{className:`rounded border border-me-gray-200 bg-me-gray-50 p-2`,children:[(0,f.jsx)(`div`,{className:`font-medium text-me-gray-600`,children:`Tag applications`}),(0,f.jsx)(`div`,{className:`text-lg font-semibold text-me-gray-900`,children:e})]}),(0,f.jsxs)(`div`,{className:`rounded border border-me-gray-200 bg-me-gray-50 p-2`,children:[(0,f.jsx)(`div`,{className:`font-medium text-me-gray-600`,children:`Tagged canvases`}),(0,f.jsxs)(`div`,{className:`text-lg font-semibold text-me-gray-900`,children:[t,`/`,n]})]})]})}function Ft({title:e,message:t}){return(0,f.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-10 text-center`,children:[(0,f.jsx)(zt,{className:`h-16 w-16 text-me-gray-300`}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h2`,{className:`text-sm font-semibold text-me-gray-900`,children:e}),(0,f.jsx)(`p`,{className:`mt-1 text-sm text-me-gray-500`,children:t})]})]})}function It({group:e,selectedRows:t,onToggleRow:n,onRemoveGroup:r}){return(0,f.jsxs)(`section`,{className:`overflow-hidden rounded border border-me-gray-200 bg-white`,children:[(0,f.jsxs)(`div`,{className:`flex items-start justify-between gap-2 border-b border-me-gray-200 bg-me-gray-50 px-3 py-2`,children:[(0,f.jsxs)(`div`,{className:`min-w-0`,children:[(0,f.jsx)(`h2`,{className:`truncate text-sm font-semibold text-me-gray-900`,children:e.type}),(0,f.jsxs)(`p`,{className:`text-xs text-me-gray-600`,children:[Y(e.tagCount,`tag application`),` on `,Y(e.canvasCount,`canvas`)]})]}),(0,f.jsx)(`button`,{type:`button`,className:`flex h-7 w-7 flex-shrink-0 items-center justify-center rounded text-me-gray-500 hover:bg-red-100 hover:text-red-700`,"aria-label":`Delete ${e.type} tags`,title:`Delete ${e.type} tags`,onClick:r,children:(0,f.jsx)(Bt,{className:`text-lg`})})]}),(0,f.jsx)(`div`,{className:`divide-y divide-me-gray-100`,children:e.rows.map(e=>(0,f.jsx)(Lt,{row:e,selected:t.has(e.key),onToggle:t=>n(e.key,t)},e.key))})]})}function Lt({row:e,selected:t,onToggle:n}){let r=Rt(e);return(0,f.jsxs)(`label`,{className:`flex min-w-0 cursor-pointer items-center gap-2 px-3 py-2 hover:bg-me-gray-50`,children:[(0,f.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 flex-shrink-0`,checked:t,onChange:e=>n(e.currentTarget.checked)}),(0,f.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,f.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,f.jsx)(a.ManifestEditorTagBadge,{tag:r,style:{fontSize:11,lineHeight:`14px`}}),(0,f.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium text-me-gray-900`,children:r.label})]}),(0,f.jsx)(`div`,{className:`mt-1 truncate text-xs text-me-gray-500`,children:e.id})]}),(0,f.jsx)(`div`,{className:`flex-shrink-0 rounded bg-me-gray-100 px-2 py-1 text-xs font-medium text-me-gray-700`,children:e.canvasCount})]})}function Rt(e){let t=e.tag;return{type:e.type,id:e.id,label:t.label||e.id||e.type,backgroundColor:t.backgroundColor||`#e5e7eb`,textColor:t.textColor||`#111827`,icon:t.icon}}function Y(e,t){return`${e} ${t}${e===1?``:`s`}`}function zt(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M20.59 13.41 12.58 5.4A2 2 0 0 0 11.17 4H5a1 1 0 0 0-1 1v6.17a2 2 0 0 0 .59 1.41l8.01 8.01a2 2 0 0 0 2.82 0l5.17-5.17a2 2 0 0 0 0-2.82ZM7.5 8.5a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z`})})}function Bt(e){return(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,"aria-hidden":`true`,...e,children:[(0,f.jsx)(`path`,{fill:`none`,d:`M0 0h24v24H0z`}),(0,f.jsx)(`path`,{fill:`currentColor`,d:`M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12Zm2-10h8v10H8V9Zm7.5-5-1-1h-5l-1 1H5v2h14V4h-3.5Z`})]})}const Vt=/(?:^|[&#])t=(?:npt:)?([0-9]+(?:\.[0-9]+)?)?(?:,([0-9]+(?:\.[0-9]+)?))?/;function X(e){return Number.isFinite(e)?Math.max(0,Math.round(e*1e3)/1e3):0}function Ht(e,t){return`t=${Ut(e)},${Ut(t)}`}function Ut(e){return X(e).toFixed(3).replace(/\.?0+$/,``)}function Wt(e,t,n){return{type:`SpecificResource`,source:{id:e,type:`Canvas`},selector:{type:`FragmentSelector`,value:Ht(t,n)}}}function Gt(e){if(!e||typeof e!=`object`||!(0,m.isSpecificResource)(e))return null;let t=e.source,n=typeof t==`string`?t:t?.id,r=typeof t==`string`?`Canvas`:t?.type;if(!n||r!==`Canvas`)return null;let i=nn(e.selector),a=rn(n),o=i.map(rn).find(Boolean)||a;return o?{canvasId:n.split(`#`)[0]||n,start:o.start,end:o.end}:null}function Kt(e,t){let n=[];return(t?.structures||[]).forEach((r,i)=>{tn(e,r,{id:t.id,type:`Manifest`},`structures`,i,n)}),qt(n)}function qt(e){return[...e].sort((e,t)=>e.canvasId.localeCompare(t.canvasId)||e.start-t.start||e.end-t.end)}function Jt(e,t){return e.filter(e=>e.canvasId===t).sort((e,t)=>e.start-t.start||e.end-t.end)}function Yt(e,t){let n=[],r=[...e].sort((e,t)=>e.start-t.start),i=0;for(let e of r)e.start>i&&n.push({start:i,end:e.start,duration:e.start-i}),i=Math.max(i,e.end);return t>i&&n.push({start:i,end:t,duration:t-i}),n}function Xt(e,t,n={}){let r=[],i=[...e].sort((e,t)=>e.start-t.start||e.end-t.end);for(let e of i)e.end<=e.start&&r.push({code:`invalid-time`,rangeId:e.id,message:`End time must be after start time.`}),(e.start<0||e.end>t)&&r.push({code:`out-of-bounds`,rangeId:e.id,message:`Range must stay within the canvas duration.`}),n.requireTitle&&!e.title.trim()&&r.push({code:`blank-title`,rangeId:e.id,message:`Title is required.`});for(let e=1;e<i.length;e++){let t=i[e-1],n=i[e];n.start<t.end&&r.push({code:`overlap`,rangeId:n.id,message:`Ranges cannot overlap.`})}return{valid:r.length===0,issues:r}}function Zt(e,t,n,r){let i=[...t].filter(e=>e.id!==r).sort((e,t)=>e.start-t.start),a=[...i].reverse().find(t=>t.end<=e.start||t.start<e.start),o=i.find(t=>t.start>=e.end||t.end>e.start),s=a?a.end:0,c=o?o.start:n,l=Math.min(Math.max(X(e.start),s),c);return{start:l,end:Math.max(l,Math.min(Math.max(X(e.end),s),c))}}function Qt(e){let t=Math.round(X(e)*1e3),n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4),i=Math.floor(t%6e4/1e3),a=t%1e3;return`${n>0?`${n.toString().padStart(2,`0`)}:`:``}${r.toString().padStart(2,`0`)}:${i.toString().padStart(2,`0`)}.${a.toString().padStart(3,`0`)}`}function Z(e){let t=Math.floor(X(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return`${n>0?`${n.toString().padStart(2,`0`)}:`:``}${r.toString().padStart(2,`0`)}:${i.toString().padStart(2,`0`)}`}function $t(e){let t=e.trim();if(!t)return null;if(/^\d+(?:\.\d+)?$/.test(t))return Number.parseFloat(t);let n=t.split(`:`);if(n.length<2||n.length>3)return null;let r=n.map(e=>Number.parseFloat(e));return r.some(e=>Number.isNaN(e))?null:r.length===2?r[0]*60+r[1]:r[0]*3600+r[1]*60+r[2]}function en(e){return`${e}/range/${Math.random().toString(36).slice(2,10)}`}function tn(e,t,n,r,i,a){let s=e.get(t,{skipSelfReturn:!1});s?.items&&s.items.forEach((t,c)=>{if(t?.type===`Range`){tn(e,t,{id:s.id,type:`Range`},`items`,c,a);return}let l=Gt(t);l&&a.push({id:s.id,type:`Range`,canvasId:l.canvasId,title:(0,o.getValue)(s.label)||`Untitled range`,label:s.label,start:l.start,end:l.end,duration:l.end-l.start,behavior:s.behavior,range:s,rangeRef:{id:s.id,type:`Range`},parentRef:n,parentKey:r,parentIndex:i,item:t,itemIndex:c})})}function nn(e){return e?(Array.isArray(e)?e:[e]).map(e=>typeof e==`string`?e:e?.type===`FragmentSelector`&&typeof e.value==`string`||typeof e?.value==`string`?e.value:``).filter(Boolean):[]}function rn(e){let t=Vt.exec(e);if(!t)return null;let n=t[1]?Number.parseFloat(t[1]):0,r=t[2]?Number.parseFloat(t[2]):NaN;return!Number.isFinite(n)||!Number.isFinite(r)?null:{start:X(n),end:X(r)}}function an(e,t,n){let r=en(t.id),i={id:r,type:`Range`,label:n.label,behavior:n.behavior?.length?n.behavior:void 0,items:[Wt(n.canvasId,n.start,n.end)]},a={id:r,type:`Range`};return e.dispatch((0,s.batchActions)({actions:[(0,s.importEntities)({entities:{Range:{[r]:i}}}),(0,s.addMappings)({mapping:{[r]:`Range`}}),s.entityActions.addReference({id:t.id,type:`Manifest`,key:`structures`,reference:a,index:n.atIndex})]})),a}function Q(e,t,n){let r=n.start??t.start,i=n.end??t.end,a=Wt(t.canvasId,r,i);e.batch(()=>{n.label&&e.modifyEntityField(t.rangeRef,`label`,n.label),n.behavior&&e.modifyEntityField(t.rangeRef,`behavior`,n.behavior.length?n.behavior:void 0),e.dispatch(s.entityActions.updateReference({id:t.rangeRef.id,type:`Range`,key:`items`,index:t.itemIndex,reference:a}))})}function on(e,t){e.dispatch(s.entityActions.removeReference({id:t.parentRef.id,type:t.parentRef.type,key:t.parentKey,index:t.parentIndex,reference:t.rangeRef}))}const sn=(0,g.create)(e=>({canvasId:null,selectedRangeId:null,draft:null,markStart:null,setCanvasId:t=>e({canvasId:t,selectedRangeId:null,draft:null,markStart:null}),setSelectedRangeId:t=>e({selectedRangeId:t}),setDraft:t=>e({draft:t}),setMarkStart:t=>e({markStart:t})}));function cn(e,t){return(t?.items||[]).map(t=>{let n=e.get(t,{skipSelfReturn:!1});return n?ln(e,n):null}).filter(e=>!!e)}function ln(e,t){let n=un(e,t),r=Number(t?.duration||n?.duration||0);return!n||!r?null:{id:t.id,label:t.label,title:(0,o.getValue)(t.label)||`Untitled canvas`,duration:r,media:{id:n.id,type:n.type,format:n.format,width:n.width,height:n.height},captions:dn(e,t)}}function un(e,t){for(let n of fn(e,t))if((Array.isArray(n?.motivation)?n.motivation:[n?.motivation]).includes(`painting`))for(let t of mn(n.body)){let n=pn(e,t);if(n?.type===`Sound`||n?.type===`Video`)return n}return null}function dn(e,t){let n=[];for(let r of fn(e,t))if((Array.isArray(r?.motivation)?r.motivation:[r?.motivation]).some(e=>e===`supplementing`||e===`captioning`||e===`transcribing`))for(let t of mn(r.body)){let r=pn(e,t);if(!r?.id)continue;let i=r.format||r.type;(i===`text/vtt`||i===`text/plain`||String(r.id).endsWith(`.vtt`))&&n.push({id:r.id,label:r.label,language:r.language,format:i})}return n}function fn(e,t){let n=[];for(let r of t?.items||[]){let t=e.get(r,{skipSelfReturn:!1});for(let r of t?.items||[]){let t=e.get(r,{skipSelfReturn:!1});t&&n.push(t)}}return n}function pn(e,t){let n=(0,m.isSpecificResource)(t)?t.source:t;return n?e.get(n,{skipSelfReturn:!1})||n:null}function mn(e){return e?Array.isArray(e)?e:[e]:[]}const hn=`@manifest-editor/av-temporal-range`;async function gn(e,t){let n=t.generateId(`range`,t.getParent());return t.embed({id:n,type:`Range`,label:e.label,behavior:e.behavior?.length?e.behavior:void 0,items:[Wt(e.canvasId,e.start,e.end)]})}function _n(e){let t=e.options.initialData||{},n=t.canvas,r=t.canvasId||n?.id,i=t.segments||[],a=(0,u.useRef)(null),[o,s]=(0,u.useState)(t.title||`Untitled range`),[c,d]=(0,u.useState)(Qt(t.start||0)),[p,m]=(0,u.useState)(Qt(t.end||Math.min(n?.duration||0,30))),[h,g]=(0,u.useState)(!1),_=(0,u.useMemo)(()=>{let e=$t(c),t=$t(p),a=[];if(e===null||t===null)a.push(`Enter readable start and end times.`);else if(n){let r=Xt([...i,{id:`__draft__`,title:o,start:e,end:t}],n.duration,{requireTitle:!0});r.valid||a.push(r.issues[0]?.message||`Range is invalid.`)}else t<=e&&a.push(`End time must be after start time.`);return r||a.push(`Canvas is missing.`),{startTime:e,endTime:t,errors:a}},[c,p,o,n,r,i]),v=t=>{t.preventDefault(),!(_.startTime===null||_.endTime===null||_.errors.length||!r)&&e.runCreate({type:`Range`,label:{en:[o.trim()]},canvasId:r,start:_.startTime,end:_.endTime,behavior:h?[`no-nav`]:[]})},y=()=>{!a.current||_.startTime===null||_.endTime===null||(a.current.currentTime=_.startTime,a.current.play())},b=e=>{_.startTime===null||_.endTime===null||_.endTime<=_.startTime||(e.currentTime<_.startTime||e.currentTime>=_.endTime)&&(e.currentTime=_.startTime)},x=e=>{_.endTime!==null&&e.currentTarget.currentTime>=_.endTime&&(e.currentTarget.pause(),e.currentTarget.currentTime=_.endTime)};return(0,u.useEffect)(()=>{!a.current||_.startTime===null||_.endTime===null||_.endTime<=_.startTime||(a.current.currentTime=_.startTime)},[_.startTime,_.endTime]),(0,f.jsxs)(l.Form.Form,{className:`flex flex-col gap-4`,onSubmit:v,children:[(0,f.jsxs)(`div`,{className:`flex items-start gap-3`,children:[n?.media.type===`Video`?(0,f.jsx)(l.VideoIcon,{className:`text-2xl`}):(0,f.jsx)(l.AudioIcon,{className:`text-2xl`}),(0,f.jsxs)(`div`,{className:`min-w-0`,children:[(0,f.jsx)(`h3`,{className:`font-semibold text-lg`,children:`Create A/V range`}),(0,f.jsx)(`p`,{className:`text-sm text-me-gray-700 truncate`,children:n?.title||t.canvasId})]})]}),n?(0,f.jsx)(`div`,{className:`rounded border border-me-gray-300 bg-me-gray-50 p-2`,children:n.media.type===`Video`?(0,f.jsx)(`video`,{ref:a,src:n.media.id,controls:!0,className:`max-h-64 w-full bg-black object-contain`,onPlay:e=>b(e.currentTarget),onSeeking:e=>b(e.currentTarget),onTimeUpdate:x}):(0,f.jsx)(`audio`,{ref:a,src:n.media.id,controls:!0,className:`w-full`,onPlay:e=>b(e.currentTarget),onSeeking:e=>b(e.currentTarget),onTimeUpdate:x})}):null,(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-create-title`,children:`Title`}),(0,f.jsx)(l.Form.Input,{id:`av-create-title`,value:o,onChange:e=>s(e.currentTarget.value)})]}),(0,f.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-create-start`,children:`Start`}),(0,f.jsx)(l.Form.Input,{id:`av-create-start`,value:c,onChange:e=>d(e.currentTarget.value)})]}),(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-create-end`,children:`End`}),(0,f.jsx)(l.Form.Input,{id:`av-create-end`,value:p,onChange:e=>m(e.currentTarget.value)})]})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,f.jsxs)(`span`,{children:[`Duration:`,` `,_.startTime!==null&&_.endTime!==null?Qt(Math.max(0,_.endTime-_.startTime)):`Invalid`]}),(0,f.jsx)(l.ActionButton,{type:`button`,onPress:y,children:`Preview selection`})]}),(0,f.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.currentTarget.checked)}),`Hidden from navigation`]}),_.errors[0]?(0,f.jsx)(l.WarningMessage,{children:_.errors[0]}):null,(0,f.jsx)(l.ActionButton,{primary:!0,type:`submit`,isDisabled:!!_.errors.length,children:`Create range`})]})}const vn=(0,x.defineCreator)({id:hn,create:gn,label:`A/V temporal range`,summary:`Create a temporal range on an audio or video canvas`,icon:(0,f.jsx)(l.AudioIcon,{}),resourceType:`Range`,resourceFields:[`id`,`label`,`type`,`items`,`behavior`],supports:{initialData:!0,parentTypes:[`Manifest`],parentFields:[`structures`]},staticFields:{type:`Range`},render(e){return(0,f.jsx)(_n,{...e})}}),yn={id:`@manifest-editor/av-ranges-listing`,label:`A/V Ranges`,icon:(0,f.jsx)(l.AudioIcon,{}),options:{minWidth:300,maxWidth:360},render:()=>(0,f.jsx)(bn,{})};function bn(){(0,d.useVault)();let e=(0,d.useManifest)(),{create:t}=(0,a.useLayoutActions)(),{canvasId:n,selectedRangeId:r,draft:i,setCanvasId:o,setSelectedRangeId:s,setDraft:c}=sn(),[p,m]=(0,u.useState)(``),h=(0,u.useRef)(null),{canvases:g,segments:_}=(0,d.useVaultSelector)((t,n)=>({canvases:cn(n,e),segments:Kt(n,e)}),[e]),v=(0,u.useMemo)(()=>g.length?g.find(e=>e.id===n)||g[0]:null,[g,n]);(0,u.useEffect)(()=>{!n&&v&&o(v.id)},[v?.id,n,o]);let y=(0,u.useMemo)(()=>v?Jt(_,v.id):[],[_,v?.id]),b=y.find(e=>e.id===r)||null,x=y.filter(e=>e.title.toLocaleLowerCase().includes(p.toLocaleLowerCase()));(0,u.useEffect)(()=>{b&&h.current&&h.current.scrollIntoView({behavior:`smooth`,block:`nearest`})},[b?.id]);let S=(n,r=`Untitled range`)=>{if(!e||!v)return;let i=Zt(n,y,v.duration);i.end<=i.start||(t({type:`Range`,parent:{id:e.id,type:`Manifest`},property:`structures`,initialCreator:hn,initialData:{canvas:v,canvasId:v.id,segments:y,title:r,start:i.start,end:i.end}}),c(null))},C=v?Yt(y,v.duration):[];return(0,f.jsxs)(l.Sidebar,{children:[(0,f.jsx)(l.SidebarHeader,{title:`A/V Ranges`,actions:v?[{icon:(0,f.jsx)(l.AddIcon,{color:`currentColor`,height:16}),title:`New range`,onClick:()=>{if(!v)return;let e=C.find(e=>e.duration>.25)||{start:0,end:Math.min(30,v.duration)};c({start:e.start,end:e.end})}}]:[]}),(0,f.jsxs)(l.SidebarContent,{className:`p-3 flex flex-col gap-3`,children:[g.length?null:(0,f.jsx)(l.WarningMessage,{children:`No audio or video canvases are available for temporal range editing.`}),v?(0,f.jsxs)(f.Fragment,{children:[g.length>1?(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-canvas-select`,children:`Canvas`}),(0,f.jsx)(`select`,{id:`av-canvas-select`,className:`p-2 bg-me-gray-100 border-b border-b-me-gray-500 text-sm`,value:v.id,onChange:e=>o(e.currentTarget.value),children:g.map(e=>(0,f.jsx)(`option`,{value:e.id,children:e.title},e.id))})]}):null,i?(0,f.jsxs)(`div`,{className:`rounded-lg border border-me-primary-300 bg-me-primary-50 p-3 flex flex-col gap-2`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,f.jsx)(`div`,{className:`text-sm font-semibold text-me-primary-900`,children:`Draft range`}),(0,f.jsx)(`button`,{type:`button`,className:`text-me-gray-500 hover:text-me-gray-700 p-0.5 rounded hover:bg-white/50`,"aria-label":`Discard draft`,onClick:()=>c(null),children:(0,f.jsx)(l.CloseIcon,{width:14,height:14})})]}),(0,f.jsxs)(`div`,{className:`text-sm tabular-nums text-me-primary-700`,children:[Z(i.start),` → `,Z(i.end),(0,f.jsxs)(`span`,{className:`text-me-primary-500 ml-2`,children:[`(`,Z(i.end-i.start),`)`]})]}),(0,f.jsx)(l.ActionButton,{primary:!0,center:!0,onPress:()=>S(i),children:`Create range from selection`})]}):null,b?(0,f.jsx)(`div`,{ref:h,children:(0,f.jsx)(xn,{segment:b,canvasDuration:v.duration,segments:y},b.id)}):null,!b&&!i&&y.length===0?(0,f.jsx)(l.InfoMessage,{children:`Create the first range by dragging on the timeline, using Mark in/out, or pressing New range.`}):null,y.length>0?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,f.jsx)(l.Form.InputContainer,{className:`flex-1 min-w-0`,children:(0,f.jsx)(l.Form.Input,{id:`av-range-search`,value:p,placeholder:`Search ranges…`,onChange:e=>m(e.currentTarget.value),"aria-label":`Search ranges`})}),(0,f.jsxs)(`span`,{className:`text-xs text-me-gray-500 tabular-nums flex-shrink-0`,children:[x.length,`/`,y.length]})]}),(0,f.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:x.map((e,t)=>(0,f.jsx)(`button`,{type:`button`,className:[`text-left rounded-md border px-3 py-2 transition-colors`,r===e.id?`border-me-primary-400 bg-me-primary-50`:`border-me-gray-200 bg-white hover:bg-me-gray-50`].join(` `),onClick:()=>s(e.id),children:(0,f.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,f.jsx)(`span`,{className:`text-[10px] font-mono text-me-gray-400 w-4 text-right shrink-0 mt-0.5 leading-tight`,children:t+1}),(0,f.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,f.jsx)(`div`,{className:[`text-sm font-medium truncate leading-tight`,r===e.id?`text-me-primary-900`:`text-me-gray-900`].join(` `),children:e.title}),(0,f.jsxs)(`div`,{className:`text-xs text-me-gray-500 tabular-nums mt-0.5`,children:[Z(e.start),` – `,Z(e.end),` `,(0,f.jsxs)(`span`,{className:`text-me-gray-400`,children:[`· `,Z(e.duration)]})]})]}),r===e.id?(0,f.jsx)(`span`,{className:`w-1 h-4 rounded-full bg-me-primary-500 shrink-0 mt-0.5`}):null]})},e.id))})]}):null]}):null]})]})}function xn({segment:e,canvasDuration:t,segments:n}){let r=(0,d.useVault)(),{setSelectedRangeId:i}=sn(),[a,o]=(0,u.useState)(e.title),[s,c]=(0,u.useState)(Qt(e.start)),[p,m]=(0,u.useState)(Qt(e.end)),[h,g]=(0,u.useState)(!1),[_,v]=(0,u.useState)(e.behavior?.includes(`no-nav`)||!1),y=$t(s),b=$t(p),x=y===null||b===null?{valid:!1,issues:[{message:`Enter readable start and end times.`}]}:Xt([...n.filter(t=>t.id!==e.id),{id:e.id,title:a,start:y,end:b}],t,{requireTitle:!0}),S=n.findIndex(t=>t.id===e.id),C=S>0?n[S-1]:null,w=S>=0?n[S+1]:null;return(0,f.jsxs)(`div`,{className:`rounded-lg border border-me-gray-200 bg-white overflow-hidden`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-me-gray-50 border-b border-me-gray-200`,children:[(0,f.jsx)(`div`,{className:`text-xs font-semibold text-me-gray-600 uppercase tracking-wide flex-1`,children:`Edit range`}),(0,f.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 text-xs text-me-gray-500 hover:text-me-gray-700 px-1.5 py-0.5 rounded hover:bg-me-gray-200 transition-colors`,onClick:()=>i(null),children:[(0,f.jsx)(l.CloseIcon,{width:12,height:12}),`Deselect`]})]}),(0,f.jsxs)(`div`,{className:`p-3 flex flex-col gap-3`,children:[(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-range-title`,children:`Title`}),(0,f.jsx)(l.Form.Input,{id:`av-range-title`,value:a,onChange:e=>o(e.currentTarget.value)})]}),(0,f.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-range-start`,children:`Start`}),(0,f.jsx)(l.Form.Input,{id:`av-range-start`,value:s,onChange:e=>c(e.currentTarget.value)})]}),(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-range-end`,children:`End`}),(0,f.jsx)(l.Form.Input,{id:`av-range-end`,value:p,onChange:e=>m(e.currentTarget.value)})]})]}),(0,f.jsxs)(`div`,{className:`text-xs text-me-gray-500 tabular-nums`,children:[`Duration:`,` `,(0,f.jsx)(`span`,{className:`font-medium text-me-gray-700`,children:y!==null&&b!==null?Z(Math.max(0,b-y)):`—`})]}),x.valid?null:(0,f.jsx)(l.WarningMessage,{children:x.issues[0]?.message||`Range is invalid.`}),(0,f.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,f.jsx)(l.ActionButton,{primary:!0,isDisabled:!x.valid,onPress:()=>{if(y===null||b===null||!x.valid)return;let i=Zt({start:y,end:b},n,t,e.id);Q(r,e,{label:{en:[a.trim()]},start:i.start,end:i.end,behavior:_?[`no-nav`]:[]})},children:`Save`}),(0,f.jsx)(l.ActionButton,{className:`text-red-700 hover:bg-red-50`,onPress:()=>{on(r,e),i(null)},children:`Delete`})]}),C||w?(0,f.jsxs)(`div`,{className:`flex flex-wrap gap-2 border-t border-me-gray-100 pt-2.5`,children:[C?(0,f.jsx)(l.ActionButton,{onPress:()=>{Q(r,C,{end:e.end}),on(r,e),i(C.id)},children:`← Merge with previous`}):null,w?(0,f.jsx)(l.ActionButton,{onPress:()=>{Q(r,e,{end:w.end}),on(r,w),i(e.id)},children:`Merge with next →`}):null]}):null,(0,f.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left text-xs font-medium text-me-gray-500 hover:text-me-gray-700 py-0.5 transition-colors`,onClick:()=>g(e=>!e),children:[(0,f.jsx)(Sn,{open:h}),`Advanced options`]}),h?(0,f.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-me-gray-700 pl-5`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.currentTarget.checked)}),`Hidden from navigation`]}):null]})]})}function Sn({open:e}){return(0,f.jsx)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 16 16`,className:`h-3.5 w-3.5 shrink-0 transition-transform`,style:{transform:e?`rotate(90deg)`:`rotate(0deg)`},fill:`currentColor`,children:(0,f.jsx)(`path`,{d:`M5.5 3.5 10 8l-4.5 4.5`,stroke:`currentColor`,strokeWidth:`1.5`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`})})}const Cn={id:`av-ranges-workbench`,label:`A/V Range Workbench`,icon:``,render:()=>(0,f.jsx)(On,{})},wn=.75;function Tn(e,t,n){let r=[0,n,...t.flatMap(e=>[e.start,e.end])],i=r.reduce((t,n)=>Math.abs(n-e)<Math.abs(t-e)?n:t,r[0]||0);return Math.abs(i-e)<=wn?i:e}function En(e,t,n){return{start:Tn(e.start,t,n),end:Tn(e.end,t,n)}}function Dn(e,t,n,r){let i=t.end-t.start,a=[0,Math.max(0,r-i),...n.filter(e=>e.id!==t.id).flatMap(e=>[e.end,e.start-i])].filter(e=>e>=0&&e<=r-i),o=a.reduce((t,n)=>Math.abs(n-e)<Math.abs(t-e)?n:t,a[0]||0);return Math.abs(o-e)<=wn?o:e}function On(){let e=(0,d.useVault)(),t=(0,d.useManifest)(),{create:n}=(0,a.useLayoutActions)(),r=(0,u.useRef)(null),i=(0,u.useRef)(null),{canvasId:o,selectedRangeId:s,draft:c,markStart:p,setCanvasId:m,setSelectedRangeId:h,setDraft:g,setMarkStart:_}=sn(),[v,y]=(0,u.useState)(0),[b,x]=(0,u.useState)(!1),[S,C]=(0,u.useState)(1),[w,T]=(0,u.useState)(1),[E,D]=(0,u.useState)(!1),[O,k]=(0,u.useState)(1),[A,j]=(0,u.useState)(!1),{canvases:M,segments:N}=(0,d.useVaultSelector)((e,n)=>({canvases:cn(n,t),segments:Kt(n,t)}),[t]),P=(0,u.useMemo)(()=>M.length?M.find(e=>e.id===o)||M[0]:null,[M,o]);(0,u.useEffect)(()=>{!o&&P&&m(P.id)},[P?.id,o,m]);let F=(0,u.useMemo)(()=>P?Jt(N,P.id):[],[N,P?.id]),I=F.find(e=>e.id===s)||null,L=P?Yt(F,P.duration):[];(0,u.useEffect)(()=>{let e=r.current;!e||!I||(e.currentTime=I.start,y(I.start))},[I?.id]),(0,u.useEffect)(()=>{let e=r.current;e&&(e.playbackRate=S)},[S]),(0,u.useEffect)(()=>{let e=r.current;e&&(e.volume=w)},[w]);let R=(0,u.useCallback)(e=>{let t=r.current,n=Math.max(0,Math.min(e,P?.duration||0));t&&(t.currentTime=n),y(n)},[P?.duration]),z=(0,u.useCallback)(()=>{let e=r.current;e&&(e.paused?e.play():e.pause())},[]),ee=(0,u.useCallback)(()=>{I&&(R(I.start),r.current?.play())},[I,R]),B=(0,u.useCallback)(()=>{if(!t||!P||!c)return;let e=Zt(c,F,P.duration);e.end<=e.start||(n({type:`Range`,parent:{id:t.id,type:`Manifest`},property:`structures`,initialCreator:hn,initialData:{canvas:P,canvasId:P.id,segments:F,title:`Untitled range`,start:e.start,end:e.end}}),g(null))},[t,P,c,F,n,g]),V=(0,u.useCallback)(()=>{if(!t||!P||!I)return;let n=v;n<=I.start||n>=I.end||(Q(e,I,{end:n}),h(an(e,t,{canvasId:P.id,start:n,end:I.end,label:{en:[`${I.title} 2`]},atIndex:I.parentKey===`structures`?I.parentIndex+1:void 0}).id))},[t,P,I,v,e,h]),H=(0,u.useCallback)(()=>{I&&(on(e,I),h(null))},[I,e,h]),te=(0,u.useCallback)((t,n)=>{if(!P)return null;let r=F.find(e=>e.id===t);if(!r)return null;let i=Zt(n,F,P.duration,r.id);return i.end<=i.start?null:(Q(e,r,i),i)},[P,F,e]),ne=(0,u.useCallback)((t,n)=>{if(!P)return;let r=F.slice().sort((e,t)=>e.start-t.start),i=r.findIndex(e=>e.id===t),a=r[i];if(!a)return;let o=a.end-a.start,s=i>0?r[i-1]:null,c=i>=0&&i<r.length-1?r[i+1]:null,l=s?s.end:0,u=(c?c.start:P.duration)-o,d=Math.max(l,Math.min(n,u));Q(e,a,{start:d,end:d+o})},[P,F,e]);if((0,u.useEffect)(()=>{let t=t=>{if(!(t.target instanceof HTMLInputElement||t.target instanceof HTMLTextAreaElement||t.target instanceof HTMLSelectElement)&&P){if(t.key===` `)t.preventDefault(),z();else if(t.key===`ArrowLeft`||t.key.toLowerCase()===`j`)R(v-5);else if(t.key===`ArrowRight`||t.key.toLowerCase()===`l`)R(v+5);else if(t.key.toLowerCase()===`i`)_(v);else if(t.key.toLowerCase()===`o`&&p!==null)g(En({start:Math.min(p,v),end:Math.max(p,v)},F,P.duration)),_(null);else if(t.key===`Enter`&&c)B();else if(t.key===`Escape`)g(null),_(null);else if(t.key.toLowerCase()===`s`)V();else if(t.key===`Delete`||t.key===`Backspace`)H();else if(t.key===`ArrowUp`||t.key===`ArrowDown`){t.preventDefault();let e=F.findIndex(e=>e.id===s),n=t.key===`ArrowUp`?Math.max(0,e-1):Math.min(F.length-1,e+1),r=F[e===-1?0:n];r&&h(r.id)}else if((t.key===`[`||t.key===`]`)&&I){let n=t.shiftKey?1:.1;Q(e,I,Zt(t.key===`[`?{start:I.start+(t.altKey?n:-n),end:I.end}:{start:I.start,end:I.end+(t.altKey?-n:n)},F,P.duration,I.id))}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[P,v,p,c,I,s,F,z,R,B,V,H,g,_,h,e]),!M.length)return(0,f.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,f.jsx)(l.WarningMessage,{children:`No audio or video canvases are available for temporal range editing.`})});if(!P)return null;let U=P.media.type===`Video`;return(0,f.jsxs)(`div`,{className:`h-full min-h-0 flex flex-col overflow-hidden bg-me-gray-50`,children:[(0,f.jsxs)(`div`,{className:`bg-white border-b border-me-gray-200 px-4 py-2.5 flex items-center gap-3 flex-shrink-0`,children:[(0,f.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,f.jsx)(`h2`,{className:`font-semibold truncate leading-tight`,children:P.title}),(0,f.jsxs)(`div`,{className:`text-xs text-me-gray-500 mt-0.5`,children:[U?`Video`:`Audio`,` ·`,` `,(0,f.jsx)(`span`,{className:`tabular-nums`,children:Z(P.duration)})]})]}),p===null?null:(0,f.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-full bg-amber-50 border border-amber-200 px-3 py-1 text-xs text-amber-700 font-medium flex-shrink-0`,children:[(0,f.jsx)(Fn,{}),(0,f.jsxs)(`span`,{children:[`Mark in: `,Z(p),` · press `,(0,f.jsx)(`kbd`,{className:`font-mono`,children:`O`}),` to mark end`]})]})]}),(0,f.jsxs)(`div`,{className:`flex-shrink-0 bg-white border-b border-me-gray-200`,children:[U?(0,f.jsx)(`div`,{className:`bg-black`,children:(0,f.jsx)(`video`,{ref:r,className:`block w-full max-h-[38vh] object-contain`,src:P.media.id,preload:`metadata`,playsInline:!0,onTimeUpdate:e=>{let t=e.currentTarget.currentTime;y(t),E&&I&&t>=I.end&&R(I.start)},onPlay:()=>x(!0),onPause:()=>x(!1),onEnded:()=>x(!1),children:P.captions.map(e=>(0,f.jsx)(`track`,{src:e.id,kind:`subtitles`,srcLang:e.language||`en`,label:e.language||`Captions`},e.id))})}):(0,f.jsx)(`audio`,{ref:r,src:P.media.id,preload:`metadata`,className:`hidden`,onTimeUpdate:e=>{let t=e.currentTarget.currentTime;y(t),E&&I&&t>=I.end&&R(I.start)},onPlay:()=>x(!0),onPause:()=>x(!1),onEnded:()=>x(!1),children:P.captions.map(e=>(0,f.jsx)(`track`,{src:e.id,kind:`subtitles`,srcLang:e.language||`en`,label:e.language||`Captions`},e.id))}),(0,f.jsx)(kn,{isVideo:U,isPlaying:b,currentTime:v,duration:P.duration,speed:S,volume:w,loopSelection:E,hasSelection:!!I,onTogglePlay:z,onSeek:R,onSpeed:C,onVolume:T,onPlaySelection:ee,onLoopSelection:D,onMarkStart:()=>_(v),onMarkEnd:()=>{p!==null&&(g(En({start:Math.min(p,v),end:Math.max(p,v)},F,P.duration)),_(null))},canMarkEnd:p!==null})]}),(0,f.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[(0,f.jsx)(Vn,{canvas:P,segments:F,gaps:L,currentTime:v,selectedRangeId:s,draft:c,scale:O,dragRef:i,onSeek:R,onSelectRange:h,onDraft:g,onCreateDraft:B,onResizeRange:te,onMoveRange:ne,onScale:k}),(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,f.jsxs)(l.ActionButton,{isDisabled:!I,onPress:ee,children:[(0,f.jsx)(Bn,{}),`Play selection`]}),(0,f.jsxs)(l.ActionButton,{isDisabled:!I,onPress:V,children:[(0,f.jsx)(Ln,{}),`Split at playhead`]}),(0,f.jsxs)(l.ActionButton,{isDisabled:!I,onPress:H,children:[(0,f.jsx)(Rn,{}),`Delete range`]}),P.captions.length?(0,f.jsxs)(l.ActionButton,{onPress:()=>j(e=>!e),children:[(0,f.jsx)(zn,{}),A?`Hide captions`:`Show captions`]}):null]}),A&&P.captions[0]?(0,f.jsx)(qn,{captionUrl:P.captions[0].id,currentTime:v,onSeek:R,onDraft:g}):null]})]})}function kn(e){return(0,f.jsxs)(`div`,{className:[`flex flex-col gap-2 px-3 py-2.5`,e.isVideo?`border-t border-me-gray-200 bg-me-gray-50`:``].join(` `),children:[(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,f.jsxs)(l.ActionButton,{primary:!0,large:!0,className:`min-w-[92px]`,onPress:e.onTogglePlay,children:[e.isPlaying?(0,f.jsx)(jn,{}):(0,f.jsx)(An,{}),e.isPlaying?`Pause`:`Play`]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,f.jsxs)(l.ActionButton,{onPress:()=>e.onSeek(e.currentTime-5),children:[(0,f.jsx)(Mn,{}),(0,f.jsx)(`span`,{children:`-5s`})]}),(0,f.jsxs)(l.ActionButton,{onPress:()=>e.onSeek(e.currentTime+5),children:[(0,f.jsx)(Nn,{}),(0,f.jsx)(`span`,{children:`+5s`})]})]}),(0,f.jsxs)(`div`,{className:`rounded bg-me-gray-100 border border-me-gray-200 px-2.5 py-1 text-sm tabular-nums text-me-gray-700`,children:[Z(e.currentTime),` / `,Z(e.duration)]})]}),(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,f.jsxs)(`label`,{className:`text-sm flex items-center gap-1.5 text-me-gray-600`,children:[(0,f.jsx)(`span`,{className:`text-xs`,children:`Speed`}),(0,f.jsx)(`select`,{value:e.speed,onChange:t=>e.onSpeed(Number(t.currentTarget.value)),className:`bg-white border border-me-gray-300 rounded px-1 py-0.5 text-xs`,children:[.5,.75,1,1.25,1.5,2].map(e=>(0,f.jsxs)(`option`,{value:e,children:[e,`x`]},e))})]}),(0,f.jsxs)(`label`,{className:`text-sm flex items-center gap-1.5 text-me-gray-600`,children:[(0,f.jsx)(Pn,{}),(0,f.jsx)(`input`,{"aria-label":`Volume`,type:`range`,min:0,max:1,step:.05,value:e.volume,onChange:t=>e.onVolume(Number(t.currentTarget.value)),className:`w-20`})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,f.jsxs)(l.ActionButton,{onPress:e.onMarkStart,children:[(0,f.jsx)(Fn,{}),`Mark in`]}),(0,f.jsxs)(l.ActionButton,{isDisabled:!e.canMarkEnd,onPress:e.onMarkEnd,children:[(0,f.jsx)(In,{}),`Mark out`]})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,f.jsxs)(l.ActionButton,{isDisabled:!e.hasSelection,onPress:e.onPlaySelection,children:[(0,f.jsx)(Bn,{}),`Play selection`]}),(0,f.jsxs)(`label`,{className:`text-xs flex items-center gap-1.5 px-2 py-1 text-me-gray-600`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:e.loopSelection,disabled:!e.hasSelection,onChange:t=>e.onLoopSelection(t.currentTarget.checked)}),`Loop`]})]})]})]})}function $({children:e}){return(0,f.jsx)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 20 20`,className:`h-4 w-4 shrink-0`,fill:`currentColor`,children:e})}function An(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M6 4.5v11l9-5.5-9-5.5Z`})})}function jn(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M5 4h3v12H5V4Zm7 0h3v12h-3V4Z`})})}function Mn(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M5 4h2v12H5V4Zm10.5 1v10L8 10l7.5-5Z`})})}function Nn(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M13 4h2v12h-2V4ZM4.5 5 12 10l-7.5 5V5Z`})})}function Pn(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M3 7.5h3L10 4v12l-4-3.5H3v-5Zm10.2-.7 1.2-1.2A6 6 0 0 1 16 10a6 6 0 0 1-1.6 4.4l-1.2-1.2A4.2 4.2 0 0 0 14.3 10c0-1.2-.4-2.3-1.1-3.2Z`})})}function Fn(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M5 4h2v12H5V4Zm5 3h6v2h-6V7Zm0 4h4v2h-4v-2Z`})})}function In(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M13 4h2v12h-2V4ZM4 7h6v2H4V7Zm2 4h4v2H6v-2Z`})})}function Ln(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M10 4h2v5.5l3-3 1.4 1.4L12 12.3l4.4 4.4-1.4 1.4-3-3V20h-2v-5.7l-3 3-1.4-1.4L9.9 12 6.5 8.7l1.4-1.4 2.1 2.1V4Z`})})}function Rn(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M6 15h3L4.5 19 0 15h3V5h3v10Zm4-9h7v2h-7V6Zm0 4h5v2h-5v-2Zm0 4h3v2h-3v-2Z`})})}function zn(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M2 4a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2H2Zm2 5h2v1H4V9Zm0 2h6v1H4v-1Zm7 0h5v1h-5v-1Zm1-2h4v1h-4V9ZM4 7h12v1H4V7Z`})})}function Bn(){return(0,f.jsx)($,{children:(0,f.jsx)(`path`,{d:`M4 5h2v10H4V5Zm10 0h2v10h-2V5ZM8 6.5l5 3.5-5 3.5v-7Z`})})}function Vn({canvas:e,segments:t,gaps:n,currentTime:r,selectedRangeId:i,draft:a,scale:o,dragRef:s,onSeek:c,onSelectRange:d,onDraft:p,onCreateDraft:m,onResizeRange:h,onMoveRange:g,onScale:_}){let v=(0,u.useRef)(null),y=(0,u.useRef)(null),b=(0,u.useRef)(null),x=(0,u.useRef)(null),S=(0,u.useRef)(!1),[C,w]=(0,u.useState)(null),[T,E]=(0,u.useState)(null),[D,O]=(0,u.useState)(null),{major:k,minor:A}=(0,u.useMemo)(()=>Hn(e.duration,o),[e.duration,o]),j=t=>`${Math.max(0,Math.min(100,t/e.duration*100))}%`,M=t=>{let n=t.currentTarget.getBoundingClientRect();return Math.max(0,Math.min(e.duration,(t.clientX-n.left)/n.width*e.duration))},N=t=>{let n=y.current?.getBoundingClientRect();return n?Math.max(0,Math.min(e.duration,(t-n.left)/n.width*e.duration)):0};return(0,f.jsxs)(`div`,{className:`rounded-lg border border-me-gray-200 bg-white p-4 flex flex-col gap-3`,children:[(0,f.jsx)(`div`,{className:`flex items-center justify-end gap-3`,children:(0,f.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-me-gray-500`,children:[`Zoom`,(0,f.jsx)(`input`,{"aria-label":`Timeline zoom`,type:`range`,min:1,max:8,step:1,value:o,onChange:e=>_(Number(e.currentTarget.value))}),(0,f.jsxs)(`span`,{className:`w-6 tabular-nums`,children:[o,`x`]})]})}),(0,f.jsx)(`div`,{className:`overflow-x-auto pb-2`,children:(0,f.jsxs)(`div`,{className:`min-w-full`,style:{width:`${Math.max(1,o)*100}%`},children:[(0,f.jsx)(Un,{duration:e.duration,major:k,toPercent:j}),(0,f.jsx)(`div`,{className:`text-[10px] font-medium text-me-gray-400 uppercase tracking-wider mb-1`,children:`Overview`}),(0,f.jsxs)(`div`,{ref:v,className:`relative h-8 rounded bg-me-gray-100 border border-me-gray-300 overflow-hidden`,style:{height:32,minHeight:32},onPointerDown:n=>c(Tn(M(n),t,e.duration)),onPointerMove:e=>w(M(e)),onPointerLeave:()=>w(null),children:[(0,f.jsx)(Wn,{major:k,minor:A,toPercent:j}),t.map(e=>(0,f.jsx)(`div`,{className:`absolute top-1 bottom-1 rounded-sm bg-me-primary-300`,style:{left:j(e.start),width:j(e.end-e.start)}},e.id)),C===null?null:(0,f.jsx)(Gn,{time:C,duration:e.duration}),(0,f.jsx)(Kn,{currentTime:r,duration:e.duration})]}),(0,f.jsx)(`div`,{className:`mt-3 text-[10px] font-medium text-me-gray-400 uppercase tracking-wider mb-1`,children:`Ranges`}),(0,f.jsxs)(`div`,{ref:y,className:`relative h-28 rounded bg-me-gray-50 border border-me-gray-300 select-none overflow-hidden`,style:{height:112,minHeight:112},onPointerDown:n=>{let r=Tn(M(n),t,e.duration);s.current={start:r,end:r},n.currentTarget.setPointerCapture(n.pointerId),p({start:r,end:r})},onPointerMove:n=>{w(M(n));let r=b.current;if(r){let i=Tn(M(n),t.filter(e=>e.id!==r.segment.id),e.duration),a=h(r.segment.id,r.edge===`start`?{start:i,end:r.segment.end}:{start:r.segment.start,end:i});a&&c(r.edge===`start`?a.start:a.end);return}let i=x.current;if(i){let r=Dn(N(n.clientX)-i.offset,i.segment,t,e.duration);i.moved=!0,g(i.segment.id,r);return}if(!s.current)return;let a=Tn(M(n),t,e.duration);s.current.end=a,p(En({start:Math.min(s.current.start,a),end:Math.max(s.current.start,a)},t,e.duration))},onPointerLeave:()=>{!b.current&&!x.current&&!s.current&&w(null)},onPointerUp:e=>{if(b.current){let t=b.current.pointerId;b.current=null,E(null),e.currentTarget.hasPointerCapture(t)&&e.currentTarget.releasePointerCapture(t);return}if(x.current){let t=x.current.pointerId;S.current=x.current.moved,x.current=null,O(null),e.currentTarget.hasPointerCapture(t)&&e.currentTarget.releasePointerCapture(t);return}let t=s.current;if(s.current=null,!t)return;let r=Math.min(t.start,t.end);if(Math.max(t.start,t.end)-r<.15){let e=n.find(e=>r>=e.start&&r<=e.end);p(e?{start:e.start,end:e.end}:null)}e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)},children:[(0,f.jsx)(Wn,{major:k,minor:A,toPercent:j}),n.map(e=>(0,f.jsx)(`button`,{type:`button`,className:`absolute top-0 h-full bg-white/50 hover:bg-me-primary-50 border-x border-dashed border-me-gray-300`,style:{left:j(e.start),width:j(e.end-e.start)},onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),p({start:e.start,end:e.end})},"aria-label":`Create range from gap ${Z(e.start)} to ${Z(e.end)}`},`${e.start}-${e.end}`)),t.map(e=>(0,f.jsxs)(`button`,{type:`button`,className:[`absolute top-5 bottom-5 rounded-sm px-2 text-left overflow-hidden border shadow-sm group`,i===e.id||T===e.id||D===e.id?`bg-me-primary-500 text-white border-me-primary-700`:`bg-me-primary-200 border-me-primary-400 text-me-gray-900`].join(` `),style:{left:j(e.start),width:j(e.end-e.start),minWidth:54,cursor:i===e.id?`move`:`pointer`},onPointerDown:t=>{if(t.stopPropagation(),d(e.id),i!==e.id)return;let n=N(t.clientX)-e.start;x.current={pointerId:t.pointerId,segment:e,offset:n,moved:!1},O(e.id),y.current?.setPointerCapture(t.pointerId)},onClick:t=>{if(t.stopPropagation(),S.current){S.current=!1;return}d(e.id),c(e.start)},title:`${e.title}: ${Z(e.start)} to ${Z(e.end)}`,children:[(0,f.jsx)(`span`,{className:`absolute left-0 top-0 bottom-0 w-2 cursor-ew-resize bg-black/10 hover:bg-black/25`,"aria-hidden":`true`,style:{cursor:`ew-resize`},onPointerDown:t=>{t.stopPropagation(),d(e.id),b.current={edge:`start`,pointerId:t.pointerId,segment:e},E(e.id),y.current?.setPointerCapture(t.pointerId)}}),(0,f.jsx)(`span`,{className:`absolute right-0 top-0 bottom-0 w-2 cursor-ew-resize bg-black/10 hover:bg-black/25`,"aria-hidden":`true`,style:{cursor:`ew-resize`},onPointerDown:t=>{t.stopPropagation(),d(e.id),b.current={edge:`end`,pointerId:t.pointerId,segment:e},E(e.id),y.current?.setPointerCapture(t.pointerId)}}),(0,f.jsx)(`span`,{className:`block truncate text-xs font-semibold leading-4`,children:e.title}),(0,f.jsxs)(`span`,{className:`block truncate text-[10px] leading-4 opacity-80 tabular-nums`,children:[Z(e.start),` - `,Z(e.end)]})]},e.id)),a?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:`absolute top-3 bottom-3 border-2 border-me-primary-700 bg-me-primary-200/70 pointer-events-none rounded-sm`,style:{left:j(a.start),width:j(a.end-a.start),minWidth:4}}),(0,f.jsxs)(`div`,{className:`absolute top-1 z-20 rounded bg-white border border-me-primary-500 shadow-md p-1 flex gap-1 items-center`,style:{left:j((a.start+a.end)/2),transform:`translateX(-50%)`},onPointerDown:e=>e.stopPropagation(),children:[(0,f.jsxs)(`span`,{className:`text-xs tabular-nums whitespace-nowrap`,children:[Z(a.start),` - `,Z(a.end)]}),(0,f.jsx)(l.ActionButton,{primary:!0,onPress:m,children:`Create`})]})]}):null,(0,f.jsx)(Kn,{currentTime:r,duration:e.duration})]})]})})]})}function Hn(e,t=1){let n=[.25,.5,1,2,5,10,15,30,60,120,300,600,900,1800,3600],r=Math.round(14*t),i=Math.round(60*t),a=e/r,o=n.find(e=>e>=a)??n[n.length-1],s=o;for(let t of n){if(t>=o)break;let n=o/t;if(Math.abs(Math.round(n)-n)<.001&&e/t<=i){s=t;break}}let c=[],l=[],u=Math.round(o/s),d=s*.01;for(let t=0;t*s<=e+d;t++){let n=Math.round(Math.min(t*s,e)*1e3)/1e3;if(l.length>0&&n===l[l.length-1]||(l.push(n),t%u===0&&c.push(n),n>=e))break}return(l[l.length-1]??-1)<e&&(l.push(e),c.push(e)),c.length>=2&&c[c.length-1]===e&&e-(c[c.length-2]??0)<o*.55&&c.pop(),{major:c,minor:l}}function Un({duration:e,major:t,toPercent:n}){return(0,f.jsx)(`div`,{className:`relative h-5 text-[11px] text-me-gray-700 select-none`,children:t.map(t=>{let r=t===0?`translateX(0)`:t===e?`translateX(-100%)`:`translateX(-50%)`;return(0,f.jsx)(`span`,{className:`absolute top-0 tabular-nums`,style:{left:n(t),transform:r},children:Z(t)},t)})})}function Wn({major:e,minor:t,toPercent:n}){let r=new Set(e);return(0,f.jsx)(f.Fragment,{children:t.map(e=>r.has(e)?(0,f.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-me-gray-300/80`,style:{left:n(e)}},e):(0,f.jsx)(`div`,{className:`absolute top-1/4 bottom-0 border-l border-me-gray-200/70`,style:{left:n(e)}},e))})}function Gn({time:e,duration:t}){let n=`${Math.max(0,Math.min(100,e/t*100))}%`;return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px pointer-events-none z-20`,style:{left:n,backgroundColor:`#111827`}}),(0,f.jsx)(`div`,{className:`absolute top-0 z-30 -translate-x-1/2 rounded px-1.5 py-0.5 text-[11px] tabular-nums pointer-events-none shadow`,style:{left:n,backgroundColor:`#111827`,color:`#ffffff`},children:Z(e)})]})}function Kn({currentTime:e,duration:t}){return(0,f.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-600 pointer-events-none`,style:{left:`${Math.max(0,Math.min(100,e/t*100))}%`}})}function qn({captionUrl:e,currentTime:t,onSeek:n,onDraft:r}){let[i,a]=(0,u.useState)([]),o=(0,u.useRef)(null);return(0,u.useEffect)(()=>{let t=!1;return fetch(e).then(e=>e.text()).then(e=>{t||a(Jn(e))}).catch(()=>{t||a([])}),()=>{t=!0}},[e]),i.length?(0,f.jsx)(`div`,{className:`rounded border border-me-gray-300 bg-white p-3 max-h-72 overflow-y-auto`,children:i.map((e,i)=>(0,f.jsxs)(`button`,{type:`button`,className:[`block w-full text-left rounded p-2 text-sm`,t>=e.start&&t<=e.end?`bg-me-primary-100`:`hover:bg-me-gray-100`].join(` `),onClick:()=>n(e.start),onPointerDown:()=>{o.current=e.start},onPointerUp:()=>{o.current!==null&&o.current!==e.start&&r({start:Math.min(o.current,e.start),end:Math.max(o.current,e.end)}),o.current=null},children:[(0,f.jsx)(`span`,{className:`text-xs text-me-gray-600 mr-2`,children:Z(e.start)}),e.text]},`${e.start}-${i}`))}):(0,f.jsx)(l.InfoMessage,{children:`Transcript could not be loaded.`})}function Jn(e){let t=e.replace(/\r/g,``).split(/\n\n+/),n=[];for(let e of t){let t=e.split(`
|
|
63
|
-
`).filter(Boolean),r=t.findIndex(e=>e.includes(`-->`));if(r===-1)continue;let[i,a]=t[r].split(`-->`).map(e=>e.trim().split(/\s+/)[0]),o=Yn(i||``),s=Yn(a||``);o===null||s===null||n.push({start:o,end:s,text:t.slice(r+1).join(` `)})}return n}function Yn(e){let t=e.split(`:`);if(t.length===2){let e=Number.parseFloat(t[0]),n=Number.parseFloat(t[1]);return Number.isFinite(e)&&Number.isFinite(n)?e*60+n:null}if(t.length===3){let e=Number.parseFloat(t[0]),n=Number.parseFloat(t[1]),r=Number.parseFloat(t[2]);return Number.isFinite(e)&&Number.isFinite(n)&&Number.isFinite(r)?e*3600+n*60+r:null}return null}var Xn=e.m({background:()=>nr,centerPanels:()=>er,creators:()=>tr,default:()=>Zn,leftPanels:()=>$n}),Zn={id:`@manifest-editor/av-ranges`,label:`A/V Ranges`,description:`Create and edit temporal ranges for audio and video canvases.`,author:`Digirati`,official:!0,defaultEnabled:!1,tags:[`audio`,`video`,`ranges`,`chaptering`],supports:{projectTypes:[`Manifest`]}};function Qn(e){if(!e.rootResource||e.rootResource.type!==`Manifest`||!e.vault)return!1;let t=e.vault.get(e.rootResource,{skipSelfReturn:!1});return cn(e.vault,t).length>0}const $n=[{...yn,supports:Qn}],er=[{...Cn,supports:Qn}],tr=[vn],nr=[{id:`av-ranges-plugin-sync`,label:`A/V ranges plugin sync`,render:()=>(0,f.jsx)(rr,{})}];function rr(){let{leftPanel:e,rightPanel:t}=(0,a.useLayoutState)(),{open:n,rightPanel:r}=(0,a.useLayoutActions)(),[i,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{if(e.current===yn.id){n({id:Cn.id}),t.open&&(r.close(),o(!0));return}!t.open&&i&&(r.open(),o(!1))},[e.current,t.open,i,n,r]),null}const ir={id:`manifest-query-string`,label:`Query string`,render:()=>(0,f.jsx)(cr,{})};function ar(e,t){let n=new URLSearchParams(window.location.search),r=new URLSearchParams(n);t?r.set(e,t):r.delete(e),window.history.replaceState(null,``,`?${r.toString()}`)}function or(e){ar(`canvas`,e)}function sr(e){ar(`leftPanel`,e)}function cr(){let t=(0,d.useManifest)(),n=(0,i.useInStack)(`Canvas`),{leftPanel:r,rightPanel:o}=(0,a.useLayoutState)(),{edit:s,leftPanel:c,rightPanel:l}=(0,a.useLayoutActions)(),{leftPanels:f}=(0,a.useAvailableLayouts)(),{canvasActions:p,open:m}=e.d(),{editorFeatureFlags:{rememberCanvasId:h=!0,rememberLeftPanelId:g=!1}={}}=(0,a.useConfig)(),_=(0,u.useRef)(null),v=(0,u.useRef)(null),y=r.open,[b,x]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{y&&x(!1)},[y]),(0,u.useEffect)(()=>{let t=new URLSearchParams(window.location.search),n=t.get(`canvas`);_.current=n,n&&(m({id:e.u.id}),m({id:`current-canvas`}),p.edit({id:n,type:`Canvas`}));let r=t.get(`leftPanel`);v.current=r,r&&f.some(e=>e.id===r)&&c.open({id:r})},[]),(0,u.useEffect)(()=>{g&&sr(r.current)},[r.current]),(0,u.useEffect)(()=>{let e=n?.resource?.source?.id;e&&(_.current=e),h&&or(e)},[n?.resource?.source?.id]),(0,u.useEffect)(()=>{if(r.current===e.r.id&&(or(null),t&&s(t),m({id:e.p.id})),r.current===kt.id&&m({id:mt.id}),r.current===e.u.id){let e=_.current||t?.items?.[0]?.id;e&&(m({id:`current-canvas`}),p.edit({id:e,type:`Canvas`}))}if(r.current===kt.id){let e=t?.structures?.[0]?.id;e&&t?.structures?.length===1&&s({id:e,type:`Range`})}r.current===kt.id&&o.open&&(l.close(),x(!0));let n=r.current!==kt.id;!o.open&&n&&b&&(l.open(),x(!1))},[r.current]),null}var lr={id:`manifest-editor`,title:`Manifest Editor`,project:!0,projectType:`Manifest`};const ur=[e.p,{id:`current-canvas`,label:`Current canvas`,icon:(0,f.jsx)(Ae,{}),render:(e,{actions:t})=>(0,f.jsx)(i.CanvasPanelEditor,{})},mt],dr=[e.r,e.u,jt,kt],fr=[xt,ir],pr=[E()],mr=[a.baseEditor],hr=[a.baseCreator],gr=i.allEditors,_r=r.allCreators,vr=[`Manifest`,`Canvas`,`ContentResource`,`Agent`,`AnnotationPage`,`Annotation`,`Range`],yr=[t,Xn,n];Object.defineProperty(exports,`annotationsPlugin`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`avRangesPlugin`,{enumerable:!0,get:function(){return Xn}}),exports.background=fr,exports.backgroundActions=pr,Object.defineProperty(exports,`canvasLabelGeneratorPlugin`,{enumerable:!0,get:function(){return n}}),exports.centerPanels=ur,exports.creators=_r,exports.default=lr,exports.editors=gr,exports.leftPanels=dr,exports.modals=hr,exports.plugins=yr,exports.resources=vr,exports.rightPanels=mr;
|
|
54
|
+
`;function xt(e){let t=(0,o.getValue)(e);if(!t)return`Untitled range`;let n=t.match(/(.+)(\d+)/);if(!n)return`Untitled range`;let r=n?.[2]?parseInt(n[2],10):1;return`${n?n[1]:``}${r+1}`}function St(){let e=(0,i.useInStack)(`Range`),[{size:t},n]=(0,l.useGridOptions)(`default-grid-size`,{defaultGridSize:`grid-sm`,onDark:!0}),r=(0,d.useVault)(),s=(0,d.useManifest)(),c=(0,u.useMemo)(()=>(0,o.createRangeHelper)(r),[r]),p=(0,a.useInlineCreator)(),[g,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(null),b=(0,u.useCallback)((e,t)=>{I.current&&(R.current=I.current.scrollTop),y({range:e,canvas:t})},[]),x=(0,u.useCallback)(()=>{y(null),requestAnimationFrame(()=>{I.current&&(I.current.scrollTop=R.current)})},[]),{isSplitting:S,setIsSplitting:C,splitEffect:w}=Ve();(0,u.useEffect)(w,[e]);let T=(0,d.useVaultSelector)((t,n)=>{let r=(0,m.toRef)(e?.resource);if(r)return c.rangeToTableOfContentsTree(n.get(r),{showNoNav:!0});if(!s.structures)return null;let i=n.get(s.structures||[]);return c.rangesToTableOfContentsTree(i,void 0,{showNoNav:!0})||null},[s,e]);(0,u.useEffect)(()=>{if(!T){y(null);return}y(e=>{if(e===null)return null;let t=(T.items||[]).find(e=>e.type===`Canvas`);return t?e?.range.id===T.id?e:{range:T,canvas:t}:null})},[T?.id]);let E=(0,a.useGenericEditor)(T?.id?{id:T?.id,type:`Range`}:void 0,{allowNull:!0}),D=(0,u.useCallback)((e,t,n)=>{E.structural.ranges.mergeRanges(e,t,n)},[E]),O=(0,u.useCallback)(async e=>{e!==-1&&E.structural.items.deleteAtIndex(e)},[E]),k=(0,u.useCallback)(async(e,t)=>{T&&await E.structural.ranges.splitRange(T,e,t,t=>p.create(`@manifest-editor/range-with-items`,{type:`Range`,label:{en:[xt(e.label)]},items:[]},{parent:{property:`items`,resource:{id:T.id,type:`Range`},atIndex:t}}))},[T,E,p]),{edit:A}=(0,a.useLayoutActions)(),{back:j}=(0,a.useEditingStack)(),[M,N]=(0,u.useState)(!1),[P,F]=(0,u.useState)(!1),I=(0,u.useRef)(null),L=(0,u.useRef)(null),R=(0,u.useRef)(0),[z,ee]=(0,u.useState)(!1),B=(T?.items??[]).filter(e=>e.type===`Range`),V=B.length;(0,u.useEffect)(()=>{if(typeof window>`u`||V===0){N(!1);return}let e=document.getElementById(`range-workbench-scroll`),t=B[B.length-1]?.id,n=t?document.getElementById(`workbench-${t}`):null;if(!e||!n)return;let r=new IntersectionObserver(([e])=>N(e.isIntersecting),{root:e,threshold:0,rootMargin:`0px 0px -1px 0px`});r.observe(n);let i=n.getBoundingClientRect(),a=e.getBoundingClientRect(),o=i.top<a.bottom&&i.bottom>a.top;return N(!!o),()=>r.disconnect()},[V,B]),(0,u.useEffect)(()=>{let e=document.getElementById(`range-workbench-scroll`);if(!e)return;let t=()=>{let{scrollTop:t,clientHeight:n,scrollHeight:r}=e;F(t+n>=r-2)};t(),e.addEventListener(`scroll`,t);let n=new ResizeObserver(t);return n.observe(e),window.addEventListener(`resize`,t),()=>{e.removeEventListener(`scroll`,t),window.removeEventListener(`resize`,t),n.disconnect()}},[T?.id,V,S,t]),(0,u.useEffect)(()=>{let e=I.current,t=L.current;if(!e||!t)return;let n=new IntersectionObserver(([e])=>{e&&ee(e.isIntersecting)},{root:e,threshold:.01});return n.observe(t),()=>{n.disconnect()}},[V,S,v]);let H=(T?.items||[]).filter(e=>e.type===`Canvas`),te=(0,u.useCallback)(()=>{I.current?.scrollTo({top:0,behavior:`smooth`})},[]),ne=(0,u.useCallback)(()=>{let e=L.current,t=I.current;e&&t?e.scrollIntoView({behavior:`smooth`,block:`end`,inline:`end`}):t&&t.scrollTo({top:t.scrollHeight,behavior:`smooth`})},[]),U=(0,d.useVaultSelector)((e,t)=>{if(!s?.structures)return null;let n=t.get(s.structures||[]);return c.rangesToTableOfContentsTree(n,void 0,{showNoNav:!0})||null},[s]),re=(0,u.useMemo)(()=>{let e=new Map,t=n=>{if(n?.items)for(let r of n.items)r?.type===`Range`&&(e.set(r.id,n.id),t(r))};return U&&t(U),e},[U]),W=(0,m.toRef)(e?.resource)?.id??e?.resource?.id??null,ie=(0,u.useCallback)(()=>{if(!W){j();return}let e=re.get(W);e?A({id:e,type:`Range`}):j()},[W,re,A,j]),ae=(0,u.useMemo)(()=>!!(W&&re.has(W)),[W,re]),oe=(0,d.useVaultSelector)((e,t)=>{if(!v?.range?.id)return null;let n=t.get(v.range.id);return n?.label?(0,o.getValue)(n.label):(0,o.getValue)(v.range.label)},[v?.range?.id]);return T?(0,f.jsxs)(_t,{id:`range-workbench-scroll`,ref:I,children:[!v&&(0,f.jsxs)(vt,{className:`flex flex-row justify-between bg-me-primary-500 sticky top-0 h-16 z-30 border-me-400 border-b`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-4`,children:[ae?(0,f.jsx)(l.ActionButton,{"aria-label":`Go to parent range`,onPress:()=>ie(),children:(0,f.jsx)(Be,{"aria-hidden":`true`,className:`text-xl`})}):null,g&&!T.isVirtual?(0,f.jsx)(i.InlineLabelEditor,{className:``,resource:T,onSubmit:()=>_(!1)}):(0,f.jsx)(i.InlineLocaleStringEditor,{editor:E.descriptive.label,as:`h2`,placeholder:`Untitled range`,className:`text-xl text-white`,children:T.label},T.id),(0,f.jsxs)(h.MenuTrigger,{children:[(0,f.jsx)(l.ActionButton,{"aria-label":`Range actions`,children:(0,f.jsx)(l.MoreMenuIcon,{"aria-hidden":`true`,className:`text-xl`})}),(0,f.jsx)(h.Popover,{className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsx)(h.Menu,{children:(0,f.jsxs)(h.MenuItem,{className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,onAction:()=>_(!0),children:[(0,f.jsx)(je,{}),`Edit range label`]})})})]}),!S&&(T?.items?.length??0)>0&&!T.isRangeLeaf&&(0,f.jsxs)(l.ActionButton,{onPress:()=>C(!0),children:[(0,f.jsx)(Pe,{className:`text-xl`}),` Split range`]}),(0,f.jsx)(Ke,{})]}),n]}),S&&!v?(0,f.jsxs)(yt,{className:`mb-4 flex gap-4 sticky top-16 rounded-none bg-me-primary-600 z-30`,children:[`Splitting range, click to confirm the the new range item`,(0,f.jsx)(l.ActionButton,{onPress:()=>C(!1),children:`Exit splitting mode`})]}):null,v&&(0,f.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,f.jsxs)(vt,{className:`flex bg-me-primary-500 sticky top-0 h-16 z-20 border-b-white border-b items-center gap-4`,children:[(0,f.jsx)(l.ActionButton,{"aria-label":`Back to range`,onPress:x,children:(0,f.jsx)(Fe,{"aria-hidden":`true`,className:`text-xl`})}),g&&!T.isVirtual?(0,f.jsx)(i.InlineLabelEditor,{className:`text-base font-normal mt-1`,resource:v.range,onSubmit:()=>_(!1)}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(d.LocaleString,{className:`text-xl text-left truncate overflow-ellipsis min-w-0 text-white`,children:oe}),(0,f.jsxs)(h.MenuTrigger,{children:[(0,f.jsx)(l.ActionButton,{"aria-label":`Range actions`,children:(0,f.jsx)(l.MoreMenuIcon,{"aria-hidden":`true`,className:`text-xl`})}),(0,f.jsx)(h.Popover,{className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsx)(h.Menu,{children:(0,f.jsxs)(h.MenuItem,{className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex gap-2 items-center`,onAction:()=>_(!0),children:[(0,f.jsx)(je,{}),`Edit range label`]})})})]})]})]}),(0,f.jsx)($e,{range:v.range,canvas:v.canvas,onBack:()=>y(null),setCanvas:e=>y(t=>t&&{...t,canvas:e})})]}),!v&&(T.items||[]).map((e,t)=>{if(e.type===`Canvas`)return null;let n=t-1,r=t+1,i=r!==T.items?.length&&T.items?.[r]?.items?.length===0?(0,o.getValue)(T.items?.[r]?.label):xt(e.label);return(0,f.jsx)(ft,{idx:t,isSplitting:S,onSplit:k,range:e,onMergeUp:t===0?void 0:(t,r)=>D(e,T.items?.[n],r),onMergeDown:T.items?.[r]?(t,n)=>D(e,T.items?.[r],n):void 0,nextRangeLabel:i,onDelete:()=>O(t),mergeUpLabel:n===-1?``:T.items?.[n]?.label,mergeDownLabel:r===T.items?.length?``:T.items?.[r]?.label,onPreviewCanvas:b,onClosePreview:()=>y(null)},e.id)}),!v&&H.length?(0,f.jsx)(d.RangeContext,{range:T.id,children:(0,f.jsx)(Ue,{})}):null,H.length===0&&B.length===0&&(0,f.jsx)(bt,{children:(0,f.jsx)(We,{extraClasses:`my-4`})}),!v&&B.length>0?(0,f.jsx)(`div`,{className:`sticky bottom-5 float-right right-5`,children:z?(0,f.jsxs)(l.ActionButton,{primary:!0,onPress:te,children:[`Scroll to top `,(0,f.jsx)(Be,{})]}):(0,f.jsxs)(l.ActionButton,{primary:!0,onPress:ne,children:[`Scroll to bottom `,(0,f.jsx)(ze,{})]})}):null,(0,f.jsx)(`div`,{id:`workbench-bottom`,ref:L})]}):null}const Ct={id:`manifest-context-menus`,label:`Context menus`,render:()=>(0,f.jsx)(wt,{})};function wt(){return(0,f.jsx)(Tt,{})}function Tt(){let e=(0,i.useInStack)(`Canvas`),t=e?.resource.source,n=(0,a.useEditingResource)()?.resource?.source?.id,r=(0,d.useCanvas)(t||void 0),{edit:o}=(0,a.useLayoutActions)(),s=r?.items?.[0]?.id,[c,l]=(0,a.useCreator)({id:s,type:`AnnotationPage`},`items`,`Annotation`,t,{isPainting:!0});return(0,a.useCustomContextMenu)({sectionTitle:`Canvas`,resource:{type:`Canvas`},items:[{id:`edit-canvas`,label:`Edit metadata`,enabled:!0,onAction:()=>o({id:e?.resource?.source?.id,type:`Canvas`},void 0,{forceOpen:!0})},{id:`add-media`,label:`Add media...`,enabled:!0,onAction:({resource:e})=>{n!==e.id&&o(e),l.create()}},{id:`add-browser`,label:`Add from IIIF Browser`,enabled:!0,onAction:({resource:e})=>{n!==e.id&&o(e),l.creator(`@manifest-editor/iiif-browser-creator`)}}]},[t,n,c]),null}function Et({title:e,...t}){return(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,height:`1em`,width:`1em`,...t,children:[(0,f.jsx)(`path`,{fill:`none`,d:`M0 0h24v24H0z`}),(0,f.jsx)(`path`,{d:`M20 9H4v2h16V9zM4 15h16v-2H4v2z`}),e?(0,f.jsx)(`title`,{children:e}):null]})}function Dt(){let e=(0,d.useVault)(),t=(0,d.useManifest)(),n=(0,a.useManifestEditor)(),r=(0,i.useInStack)(`Range`),s=(0,u.useMemo)(()=>(0,o.createRangeHelper)(e),[e]),{edit:c}=(0,a.useLayoutActions)(),{back:p}=(0,a.useEditingStack)(),{isEditing:g,showCanvases:v,toggleShowCanvases:y}=ct(),b=(0,d.useVaultSelector)((e,n)=>{if(r)return s.rangeToTableOfContentsTree(n.get(r.resource),{showNoNav:!0});let i=n.get(t.structures||[]);return s.rangesToTableOfContentsTree(i,void 0,{showNoNav:!0})||{}},[e,t,r]),x=(0,u.useMemo)(()=>(b.items||[]).filter(e=>e.type===`Range`),[b]),S=at(b);async function C(e){return Promise.all(e.map(async e=>e.kind===`text`?JSON.parse(await e.getText(`text/plain`)):null))}let{dragAndDropHooks:w}=(0,h.useDragAndDrop)({isDisabled:!g,getItems:(e,t)=>[...e].map(e=>{let t=S.find(t=>t.item.id===e);return t?{"text/plain":JSON.stringify({item:t.item.id,parent:t.parent?{id:t.parent.id}:void 0})}:{"text/plain":e.toString()}}),renderDragPreview(e){return(0,f.jsx)(`div`,{className:`opacity-50 bg-gray-200 rounded p-1`,children:(0,f.jsxs)(`span`,{className:``,children:[e.length,` items`]})})},onDrop:async t=>{let n=await C(t.items),r=null;if(r=t.target.type===`root`?b.id:t.target.key,!r){console.log(`[error] No valid target found`);return}let i=S.find(e=>t.target.key===e.item.id);if(t.target.type===`item`&&t.target.dropPosition===`on`&&i?.item.type===`Canvas`)return;let a=r.toString();if(t.dropOperation===`move`&&t.target.type===`item`&&(t.target.dropPosition===`before`||t.target.dropPosition===`after`?a=i?.parent?.id:t.target.dropPosition===`on`&&(a=r.toString())),!a){console.log(`[error] No valid target parent found`);return}if(!e.get({id:a,type:`Range`})){console.log(`[error] No valid target range found in Vault`);return}let o=new _.EditorInstance({reference:{id:a,type:`Range`},vault:e}),s=n[0],c=S.find(e=>s.item===e.item.id);if(!c){console.log(`[error] No valid item found for item to move`);return}if(!c.parent){console.log(`[error] No valid parent found for item to move`);return}let l=e.get({id:c.parent.id,type:`Range`}),u=new _.EditorInstance({reference:{id:c.parent.id,type:`Range`},vault:e});if(t.target.type===`root`||t.target.type===`item`&&t.target.dropPosition===`on`){let e=l.items.find(e=>(0,m.toRef)(e,`Canvas`)?.id===c.item.id);if(!e){console.log(`[error] No valid reference found for item to move`);return}let t=l.items.indexOf(e);if(t===-1){console.log(`[error] No valid index found for item to move`);return}o.structural.items.add(e),u.structural.items.deleteAtIndex(t);return}if(c.parent.id===a){let e=l.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===c.item.id),t=l.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===r);if(e===t){console.log(`[error] No valid index found for item to move`);return}if(e===-1||t===-1){console.log(`[error] Invalid index found for item to move`);return}u.structural.items.reorder(e,t);return}let d=l.items.findIndex(e=>(0,m.toRef)(e,`Canvas`)?.id===c.item.id);if(d===-1){console.log(`[error] Invalid index found for item to move`);return}let f=l.items[d];if(!f){console.log(`[error] Invalid reference found for item to move`);return}let p=e.get({id:a,type:`Range`});if(!p){console.log(`[error] Invalid target parent found`);return}let h=p.items.findIndex(e=>(0,m.toRef)(e)?.id===r);if(h===-1){console.log(`[error] Invalid target item found`);return}let g=!1;if(t.target.dropPosition===`after`&&(g=o.structural.items.addAfter(h,f)),t.target.dropPosition===`before`&&(g=o.structural.items.addBefore(h,f)),g){let e=l.items.indexOf(f);e!==-1&&u.structural.items.deleteAtIndex(e)}}}),T=(0,u.useCallback)(t=>{if(b.isVirtual){let e=n.structural.structures.getWithoutTracking().findIndex(e=>e.id===t.id);e!==-1&&n.structural.structures.deleteAtIndex(e);return}let r=new _.EditorInstance({reference:{id:b.id,type:`Range`},vault:e}),i=r.structural.items.getWithoutTracking().findIndex(e=>e.id===t.id);i!==-1&&r.structural.items.deleteAtIndex(i)},[b.id,b.isVirtual,n,e]),E=(0,f.jsx)(`div`,{className:`flex items-center gap-4 mb-4`,children:r?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(l.ActionButton,{"aria-label":`Back to parent range`,onPress:()=>p(),children:(0,f.jsx)(l.BackIcon,{"aria-hidden":`true`,className:`text-xl`})}),(0,f.jsx)(d.LocaleString,{as:`h3`,children:b.label})]}):null});return b.isRangeLeaf?(0,f.jsxs)(f.Fragment,{children:[E,(0,f.jsx)(l.EmptyState,{children:`This Range only contains canvases.`})]}):x.length===0?(0,f.jsxs)(f.Fragment,{children:[E,(0,f.jsx)(l.EmptyState,{children:`No ranges found`})]}):(0,f.jsxs)(f.Fragment,{children:[E,(0,f.jsx)(h.GridList,{className:`w-full flex flex-col gap-2`,items:x,dragAndDropHooks:w,dependencies:[g],children:e=>(0,f.jsx)(h.GridListItem,{id:e.id,onAction:()=>{g||c(e)},className:`border border-gray-300 hover:border-me-500 shadow-sm rounded bg-white relative p-4`,children:(0,f.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(d.LocaleString,{className:`text-lg mb-4`,children:e.label}),(0,f.jsxs)(`div`,{className:`text-sm text-me-primary-600`,children:[e.items?.length,` `,e.isRangeLeaf?`Canvases`:`Ranges`]})]}),g?(0,f.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,f.jsxs)(h.MenuTrigger,{children:[(0,f.jsx)(l.ActionButton,{"aria-label":`Actions for ${(0,o.getValue)(e.label)||`untitled range`}`,children:(0,f.jsx)(l.MoreMenuIcon,{"aria-hidden":`true`,className:`text-lg`})}),(0,f.jsx)(h.Popover,{className:`bg-white shadow-md rounded-md p-1`,children:(0,f.jsx)(h.Menu,{children:(0,f.jsxs)(h.MenuItem,{onAction:()=>window.confirm(`Are you sure you want to delete this range?`)&&T(e),className:`hover:bg-gray-100 px-2 py-1 text-sm m-0.5 flex text-red-500 gap-2 items-center`,children:[(0,f.jsx)(l.DeleteForeverIcon,{}),` Delete range item`]})})})]}),(0,f.jsx)(h.Button,{"aria-label":`Reorder ${(0,o.getValue)(e.label)||`untitled range`}`,slot:`drag`,children:(0,f.jsx)(Et,{"aria-hidden":`true`,className:`text-xl`})})]}):null]})})})]})}function Ot(){let{setIsSplitting:e}=Ve();return(0,f.jsxs)(l.SidebarContent,{children:[(0,f.jsx)(l.ActionButton,{onPress:()=>e(!1),children:`Exit splitting mode`}),(0,f.jsxs)(`div`,{className:`flex flex-col justify-center items-center px-4 gap-4`,children:[(0,f.jsx)(Pe,{className:`w-32 h-32 text-gray-300`}),(0,f.jsx)(`div`,{className:`text-center text-black/80`,children:`Hover over the Canvases to select where you want to add a new range item. Click to select that Canvas. Note the first canvas can’t be split.`}),(0,f.jsxs)(`div`,{style:{background:`#EFF6FF`,padding:`1em`,border:`1px solid #1E40AF`,borderRadius:`4px`},children:[(0,f.jsx)(l.InfoIcon,{fontSize:`18px`,height:30,fill:`#31539F`,style:{float:`right`}}),`Creating your first range adds one range called “Range 1” that contains every canvas. You can rename it, split it, or move canvases into sub-ranges.`]})]})]})}function kt(){let{ref:e,structural:t}=(0,a.useManifestEditor)(),n=(0,a.useInlineCreator)(),r=async()=>{if(!e)return;let r=await n.create(`@manifest-editor/range-top-level`,{label:{en:[`Range 1`]},type:`Range`,items:t.items.getWithoutTracking().map(e=>e)},{rootId:e().id});n.create(`@manifest-editor/range-top-level`,{type:`Range`,label:{en:[`Table of contents`]},items:[r]},{parent:{property:`structures`,resource:e()}})};return(0,f.jsxs)(l.Sidebar,{children:[(0,f.jsx)(l.SidebarHeader,{title:`Ranges`,actions:[{icon:(0,f.jsx)(l.AddIcon,{className:`text-2xl`}),title:`Add range`,disabled:!0,onClick:()=>void 0}]}),(0,f.jsx)(l.SidebarContent,{children:(0,f.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4`,children:[(0,f.jsx)(`div`,{className:`p-4 opacity-50 text-center`,children:`This manifest does not yet have a range(s). If you want to offer navigation, such as a table of contents, you can create a range.`}),(0,f.jsxs)(l.ActionButton,{large:!0,primary:!0,onPress:()=>r(),children:[(0,f.jsx)(l.AddIcon,{className:`text-xl`}),` Create new range`]})]})})]})}function At({range:e,setSelectedTopLevelRange:t}){let n=(0,a.useManifestEditor)(),r=(0,d.useVault)(),i=(0,a.useInlineCreator)(),o=(0,u.useCallback)(async()=>{new _.EditorInstance({reference:{id:e.id,type:`Range`},vault:r});let t=e.items||[],a=await i.create(`@manifest-editor/range-top-level`,{type:`Range`,label:{en:[`Range 1`]},items:[]},{parent:{property:`structures`,resource:{id:n.technical.id.getWithoutTracking(),type:`Manifest`},atIndex:0}});r.dispatch((0,s.moveEntities)({subjects:{type:`slice`,startIndex:1,length:t.length},from:{id:n.technical.id.getWithoutTracking(),type:`Manifest`,key:`structures`},to:{id:a.id,type:`Range`,key:`items`}}))},[]),c=(0,u.useCallback)(()=>{n.structural.ranges.empty()},[]);return(0,f.jsxs)(`div`,{children:[(0,f.jsx)(l.InfoMessage,{className:`mb-2 leading-tight text-sm`,children:`This manifests contains multiple top-level ranges. You can either merge them together into a single range or select a range to edit.`}),(0,f.jsx)(`h3`,{className:`mb-2 text-black/40`,children:`Choose an option`}),(0,f.jsxs)(`ul`,{className:`mb-4`,children:[(0,f.jsx)(`li`,{className:`px-2 py-1`,children:(0,f.jsxs)(l.ActionButton,{onClick:o,children:[(0,f.jsx)(Ye,{}),`Combine into single range`]})}),(0,f.jsx)(`li`,{className:`px-2 py-1`,children:(0,f.jsxs)(l.ActionButton,{onClick:c,children:[(0,f.jsx)(l.DeleteForeverIcon,{}),`Delete ranges and start again`]})})]}),(0,f.jsx)(`h3`,{className:`mb-2 text-black/40`,children:`Choose a range to edit`}),(0,f.jsx)(`ul`,{children:(e.items||[]).map(e=>(0,f.jsx)(`li`,{className:`mb-1 bg-gray-100 hover:bg-gray-200 rounded px-2 py-1`,children:(0,f.jsx)(`button`,{onClick:()=>t({id:e.id,type:`Range`}),children:(0,f.jsx)(d.LocaleString,{children:e.label})})},e.id))})]})}const jt={id:`@manifest-editor/ranges-listing`,label:`Ranges`,icon:(0,f.jsx)(Ne,{}),focusedMode:{onSelect:({actions:e})=>{e.centerPanel.open({id:`range-workbench`})}},render:()=>(0,f.jsx)(Mt,{})};function Mt(){let t=(0,d.useVault)(),n=(0,d.useManifest)(),{edit:r}=(0,a.useLayoutActions)(),i=(0,u.useMemo)(()=>(0,o.createRangeHelper)(t),[t]),[s,c]=(0,l.useLocalStorage)(`isCardView`,!1),[p,m]=(0,u.useState)(null),h=(0,u.useMemo)(()=>i.rangesToTableOfContentsTree(p?[t.get(p)]:t.get(n.structures||[]),void 0,{showNoNav:!0}),[p,n?.structures]),{isSplitting:g,splitEffect:_,setIsSplitting:v}=Ve(),{showCanvases:y,toggleShowCanvases:b,isEditing:x,toggleIsEditing:S}=ct();(0,u.useEffect)(()=>_(),[_]);let C=(0,u.useMemo)(()=>n?.structures?.[0]?i.isContiguous((n.structures||[])[0],n.items,{detail:!0}):null,[n,i]);return h?(0,f.jsxs)(l.Sidebar,{children:[(0,f.jsx)(l.SidebarHeader,{title:h.label||`Untitled range`,actions:[{id:`card-view`,title:s?`Tree view`:`Card view`,icon:s?(0,f.jsx)(e.s,{className:`text-xl`}):(0,f.jsx)(Le,{className:`text-xl`}),onClick:()=>{c(!s)}},{id:`edit-ranges`,title:`Edit range`,icon:(0,f.jsx)(l.ListEditIcon,{className:`text-xl`}),toggled:x,onClick:S,disabled:h?.isVirtual},{id:`split-range`,title:`Split range`,icon:(0,f.jsx)(Pe,{className:`text-xl`}),onClick:()=>v(!g),toggled:g,disabled:h?.isVirtual||(h?.items?.length??0)<=1}]}),(0,f.jsxs)(l.SidebarContent,{className:`p-2`,id:`range-listing-sidebar`,children:[p?(0,f.jsxs)(l.ActionButton,{className:`mb-4`,onClick:()=>m(null),children:[(0,f.jsx)(Fe,{}),` Back to Range List`]}):null,h.isVirtual?(0,f.jsx)(At,{range:h,setSelectedTopLevelRange:e=>{r(e),m(e)}}):(0,f.jsxs)(f.Fragment,{children:[C?null:(0,f.jsx)(l.WarningMessage,{className:`mb-2`,children:`Warning: Non-contiguous range`}),g?(0,f.jsx)(Ot,{}):s?(0,f.jsx)(Dt,{}):(0,f.jsx)(lt,{selectedTopLevelRange:p,hideCanvases:!y})]})]})]}):(0,f.jsx)(kt,{})}const Nt={id:`@manifest-editor/tags`,label:`Tags`,icon:(0,f.jsx)(Vt,{}),supports:({vault:e,rootResource:t})=>Pt(e,t),render:()=>(0,f.jsx)(Ft,{})};function Pt(e,t){if(!e||t?.type!==`Manifest`||!t.id)return!1;let n=(e.get(t,{skipSelfReturn:!1})?.items||[]).map(e=>e?.id).filter(e=>!!e).map(e=>({id:e,type:`Canvas`}));return(0,a.getResourceTagGroups)(e,n).length>0}function Ft(){let e=(0,d.useVault)(),{structural:t}=(0,a.useManifestEditor)(),n=t.items.get()||[],r=(0,u.useMemo)(()=>n.map(e=>e?.id).filter(e=>!!e).map(e=>({id:e,type:`Canvas`})),[n]),i=(0,u.useMemo)(()=>r.map(e=>e.id).join(`|`),[r]),o=(0,d.useVaultSelector)(()=>(0,a.getResourceTagGroups)(e,r),[i]),s=(0,u.useMemo)(()=>o.flatMap(e=>e.rows),[o]),c=(0,u.useMemo)(()=>s.map(e=>e.key).join(`|`),[s]),[p,m]=(0,u.useState)(()=>new Set),h=(0,u.useMemo)(()=>(0,a.createManifestEditorTagsApi)(e),[e]),g=(0,u.useMemo)(()=>s.filter(e=>p.has(e.key)),[s,p]),_=(0,u.useMemo)(()=>o.reduce((e,t)=>e+t.tagCount,0),[o]),v=(0,u.useMemo)(()=>new Set(o.flatMap(e=>e.canvasIds)).size,[o]);(0,u.useEffect)(()=>{let e=new Set(s.map(e=>e.key));m(t=>{let n=new Set(Array.from(t).filter(t=>e.has(t)));return n.size===t.size?t:n})},[c,s]);function y(e,t){if(!e.length)return;let n=e.reduce((e,t)=>e+t.canvasCount,0),r=new Set(e.flatMap(e=>e.canvasIds)).size;if(window.confirm(`Delete ${K(n,`tag application`)} from ${K(r,`canvas`)}?\n\n${t}`)){for(let t of e)for(let e of t.canvasIds)h.removeTag({id:e,type:`Canvas`},t.type,t.id);m(t=>{let n=new Set(t);for(let t of e)n.delete(t.key);return n})}}function b(e){y(e.rows,`Type: ${e.type}`)}function x(){y(g,`${K(g.length,`tag`)} selected.`)}function S(){if(_&&window.confirm(`Delete all ${K(_,`tag application`)} from ${K(v,`canvas`)}?`)){for(let e of r)h.setTags(e,[]);m(new Set)}}return(0,f.jsxs)(l.Sidebar,{children:[(0,f.jsx)(l.SidebarHeader,{title:`Tags`,actions:[{icon:(0,f.jsx)(Ht,{className:`text-xl`}),title:`Delete all tags`,disabled:_===0,onClick:S}]}),(0,f.jsxs)(l.SidebarContent,{className:`p-3`,children:[(0,f.jsx)(It,{totalTagApplications:_,taggedCanvasCount:v,totalCanvasCount:r.length}),r.length?o.length?(0,f.jsx)(`div`,{className:`grid gap-3 pb-4`,children:o.map(e=>(0,f.jsx)(Rt,{group:e,selectedRows:p,onToggleRow:(e,t)=>{m(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},onRemoveGroup:()=>b(e)},e.key))}):(0,f.jsx)(Lt,{title:`No canvas tags`,message:`Canvas tags added by editor tools and background actions will appear here.`}):(0,f.jsx)(Lt,{title:`No canvases`,message:`Canvas tags will appear here after canvases are added.`})]}),(0,f.jsx)(`div`,{className:`border-t border-me-gray-200 bg-white p-3`,children:(0,f.jsxs)(l.ActionButton,{primary:!0,center:!0,className:`w-full justify-center`,isDisabled:!g.length,onPress:x,children:[(0,f.jsx)(Ht,{className:`text-xl`}),`Delete selected (`,g.length,`)`]})})]})}function It({totalTagApplications:e,taggedCanvasCount:t,totalCanvasCount:n}){return(0,f.jsxs)(`div`,{className:`mb-3 grid grid-cols-2 gap-2 text-xs`,children:[(0,f.jsxs)(`div`,{className:`rounded border border-me-gray-200 bg-me-gray-50 p-2`,children:[(0,f.jsx)(`div`,{className:`font-medium text-me-gray-600`,children:`Tag applications`}),(0,f.jsx)(`div`,{className:`text-lg font-semibold text-me-gray-900`,children:e})]}),(0,f.jsxs)(`div`,{className:`rounded border border-me-gray-200 bg-me-gray-50 p-2`,children:[(0,f.jsx)(`div`,{className:`font-medium text-me-gray-600`,children:`Tagged canvases`}),(0,f.jsxs)(`div`,{className:`text-lg font-semibold text-me-gray-900`,children:[t,`/`,n]})]})]})}function Lt({title:e,message:t}){return(0,f.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-10 text-center`,children:[(0,f.jsx)(Vt,{className:`h-16 w-16 text-me-gray-300`}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h2`,{className:`text-sm font-semibold text-me-gray-900`,children:e}),(0,f.jsx)(`p`,{className:`mt-1 text-sm text-me-gray-500`,children:t})]})]})}function Rt({group:e,selectedRows:t,onToggleRow:n,onRemoveGroup:r}){return(0,f.jsxs)(`section`,{className:`overflow-hidden rounded border border-me-gray-200 bg-white`,children:[(0,f.jsxs)(`div`,{className:`flex items-start justify-between gap-2 border-b border-me-gray-200 bg-me-gray-50 px-3 py-2`,children:[(0,f.jsxs)(`div`,{className:`min-w-0`,children:[(0,f.jsx)(`h2`,{className:`truncate text-sm font-semibold text-me-gray-900`,children:e.type}),(0,f.jsxs)(`p`,{className:`text-xs text-me-gray-600`,children:[K(e.tagCount,`tag application`),` on `,K(e.canvasCount,`canvas`)]})]}),(0,f.jsx)(`button`,{type:`button`,className:`flex h-7 w-7 flex-shrink-0 items-center justify-center rounded text-me-gray-500 hover:bg-red-100 hover:text-red-700`,"aria-label":`Delete ${e.type} tags`,title:`Delete ${e.type} tags`,onClick:r,children:(0,f.jsx)(Ht,{className:`text-lg`})})]}),(0,f.jsx)(`div`,{className:`divide-y divide-me-gray-100`,children:e.rows.map(e=>(0,f.jsx)(zt,{row:e,selected:t.has(e.key),onToggle:t=>n(e.key,t)},e.key))})]})}function zt({row:e,selected:t,onToggle:n}){let r=Bt(e);return(0,f.jsxs)(`label`,{className:`flex min-w-0 cursor-pointer items-center gap-2 px-3 py-2 hover:bg-me-gray-50`,children:[(0,f.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 flex-shrink-0`,checked:t,onChange:e=>n(e.currentTarget.checked)}),(0,f.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,f.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,f.jsx)(a.ManifestEditorTagBadge,{tag:r,style:{fontSize:11,lineHeight:`14px`}}),(0,f.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium text-me-gray-900`,children:r.label})]}),(0,f.jsx)(`div`,{className:`mt-1 truncate text-xs text-me-gray-500`,children:e.id})]}),(0,f.jsx)(`div`,{className:`flex-shrink-0 rounded bg-me-gray-100 px-2 py-1 text-xs font-medium text-me-gray-700`,children:e.canvasCount})]})}function Bt(e){let t=e.tag;return{type:e.type,id:e.id,label:t.label||e.id||e.type,backgroundColor:t.backgroundColor||`#e5e7eb`,textColor:t.textColor||`#111827`,icon:t.icon}}function K(e,t){return`${e} ${t}${e===1?``:`s`}`}function Vt(e){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,...e,children:(0,f.jsx)(`path`,{fill:`currentColor`,d:`M20.59 13.41 12.58 5.4A2 2 0 0 0 11.17 4H5a1 1 0 0 0-1 1v6.17a2 2 0 0 0 .59 1.41l8.01 8.01a2 2 0 0 0 2.82 0l5.17-5.17a2 2 0 0 0 0-2.82ZM7.5 8.5a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z`})})}function Ht(e){return(0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,"aria-hidden":`true`,...e,children:[(0,f.jsx)(`path`,{fill:`none`,d:`M0 0h24v24H0z`}),(0,f.jsx)(`path`,{fill:`currentColor`,d:`M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12Zm2-10h8v10H8V9Zm7.5-5-1-1h-5l-1 1H5v2h14V4h-3.5Z`})]})}const Ut=/(?:^|[&#])t=(?:npt:)?([0-9]+(?:\.[0-9]+)?)?(?:,([0-9]+(?:\.[0-9]+)?))?/;function q(e){return Number.isFinite(e)?Math.max(0,Math.round(e*1e3)/1e3):0}function Wt(e,t){return`t=${Gt(e)},${Gt(t)}`}function Gt(e){return q(e).toFixed(3).replace(/\.?0+$/,``)}function Kt(e,t,n){return{type:`SpecificResource`,source:{id:e,type:`Canvas`},selector:{type:`FragmentSelector`,value:Wt(t,n)}}}function qt(e){if(!e||typeof e!=`object`||!(0,m.isSpecificResource)(e))return null;let t=e.source,n=typeof t==`string`?t:t?.id,r=typeof t==`string`?`Canvas`:t?.type;if(!n||r!==`Canvas`)return null;let i=an(e.selector),a=on(n),o=i.map(on).find(Boolean)||a;return o?{canvasId:n.split(`#`)[0]||n,start:o.start,end:o.end}:null}function Jt(e,t){let n=[];return(t?.structures||[]).forEach((r,i)=>{rn(e,r,{id:t.id,type:`Manifest`},`structures`,i,n)}),Yt(n)}function Yt(e){return[...e].sort((e,t)=>e.canvasId.localeCompare(t.canvasId)||e.start-t.start||e.end-t.end)}function Xt(e,t){return e.filter(e=>e.canvasId===t).sort((e,t)=>e.start-t.start||e.end-t.end)}function Zt(e,t){let n=[],r=[...e].sort((e,t)=>e.start-t.start),i=0;for(let e of r)e.start>i&&n.push({start:i,end:e.start,duration:e.start-i}),i=Math.max(i,e.end);return t>i&&n.push({start:i,end:t,duration:t-i}),n}function Qt(e,t,n={}){let r=[],i=[...e].sort((e,t)=>e.start-t.start||e.end-t.end);for(let e of i)e.end<=e.start&&r.push({code:`invalid-time`,rangeId:e.id,message:`End time must be after start time.`}),(e.start<0||e.end>t)&&r.push({code:`out-of-bounds`,rangeId:e.id,message:`Range must stay within the canvas duration.`}),n.requireTitle&&!e.title.trim()&&r.push({code:`blank-title`,rangeId:e.id,message:`Title is required.`});for(let e=1;e<i.length;e++){let t=i[e-1],n=i[e];n.start<t.end&&r.push({code:`overlap`,rangeId:n.id,message:`Ranges cannot overlap.`})}return{valid:r.length===0,issues:r}}function $t(e,t,n,r){let i=[...t].filter(e=>e.id!==r).sort((e,t)=>e.start-t.start),a=[...i].reverse().find(t=>t.end<=e.start||t.start<e.start),o=i.find(t=>t.start>=e.end||t.end>e.start),s=a?a.end:0,c=o?o.start:n,l=Math.min(Math.max(q(e.start),s),c);return{start:l,end:Math.max(l,Math.min(Math.max(q(e.end),s),c))}}function en(e){let t=Math.round(q(e)*1e3),n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4),i=Math.floor(t%6e4/1e3),a=t%1e3;return`${n>0?`${n.toString().padStart(2,`0`)}:`:``}${r.toString().padStart(2,`0`)}:${i.toString().padStart(2,`0`)}.${a.toString().padStart(3,`0`)}`}function J(e){let t=Math.floor(q(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return`${n>0?`${n.toString().padStart(2,`0`)}:`:``}${r.toString().padStart(2,`0`)}:${i.toString().padStart(2,`0`)}`}function tn(e){let t=e.trim();if(!t)return null;if(/^\d+(?:\.\d+)?$/.test(t))return Number.parseFloat(t);let n=t.split(`:`);if(n.length<2||n.length>3)return null;let r=n.map(e=>Number.parseFloat(e));return r.some(e=>Number.isNaN(e))?null:r.length===2?r[0]*60+r[1]:r[0]*3600+r[1]*60+r[2]}function nn(e){return`${e}/range/${Math.random().toString(36).slice(2,10)}`}function rn(e,t,n,r,i,a){let s=e.get(t,{skipSelfReturn:!1});s?.items&&s.items.forEach((t,c)=>{if(t?.type===`Range`){rn(e,t,{id:s.id,type:`Range`},`items`,c,a);return}let l=qt(t);l&&a.push({id:s.id,type:`Range`,canvasId:l.canvasId,title:(0,o.getValue)(s.label)||`Untitled range`,label:s.label,start:l.start,end:l.end,duration:l.end-l.start,behavior:s.behavior,range:s,rangeRef:{id:s.id,type:`Range`},parentRef:n,parentKey:r,parentIndex:i,item:t,itemIndex:c})})}function an(e){return e?(Array.isArray(e)?e:[e]).map(e=>typeof e==`string`?e:e?.type===`FragmentSelector`&&typeof e.value==`string`||typeof e?.value==`string`?e.value:``).filter(Boolean):[]}function on(e){let t=Ut.exec(e);if(!t)return null;let n=t[1]?Number.parseFloat(t[1]):0,r=t[2]?Number.parseFloat(t[2]):NaN;return!Number.isFinite(n)||!Number.isFinite(r)?null:{start:q(n),end:q(r)}}function sn(e,t,n){let r=nn(t.id),i={id:r,type:`Range`,label:n.label,behavior:n.behavior?.length?n.behavior:void 0,items:[Kt(n.canvasId,n.start,n.end)]},a={id:r,type:`Range`};return e.dispatch((0,s.batchActions)({actions:[(0,s.importEntities)({entities:{Range:{[r]:i}}}),(0,s.addMappings)({mapping:{[r]:`Range`}}),s.entityActions.addReference({id:t.id,type:`Manifest`,key:`structures`,reference:a,index:n.atIndex})]})),a}function Y(e,t,n){let r=n.start??t.start,i=n.end??t.end,a=Kt(t.canvasId,r,i);e.batch(()=>{n.label&&e.modifyEntityField(t.rangeRef,`label`,n.label),n.behavior&&e.modifyEntityField(t.rangeRef,`behavior`,n.behavior.length?n.behavior:void 0),e.dispatch(s.entityActions.updateReference({id:t.rangeRef.id,type:`Range`,key:`items`,index:t.itemIndex,reference:a}))})}function cn(e,t){e.dispatch(s.entityActions.removeReference({id:t.parentRef.id,type:t.parentRef.type,key:t.parentKey,index:t.parentIndex,reference:t.rangeRef}))}const ln=(0,g.create)(e=>({canvasId:null,selectedRangeId:null,draft:null,markStart:null,setCanvasId:t=>e({canvasId:t,selectedRangeId:null,draft:null,markStart:null}),setSelectedRangeId:t=>e({selectedRangeId:t}),setDraft:t=>e({draft:t}),setMarkStart:t=>e({markStart:t})}));function un(e,t){return(t?.items||[]).map(t=>{let n=e.get(t,{skipSelfReturn:!1});return n?dn(e,n):null}).filter(e=>!!e)}function dn(e,t){let n=fn(e,t),r=Number(t?.duration||n?.duration||0);return!n||!r?null:{id:t.id,label:t.label,title:(0,o.getValue)(t.label)||`Untitled canvas`,duration:r,media:{id:n.id,type:n.type,format:n.format,width:n.width,height:n.height},captions:pn(e,t)}}function fn(e,t){for(let n of mn(e,t))if((Array.isArray(n?.motivation)?n.motivation:[n?.motivation]).includes(`painting`))for(let t of gn(n.body)){let n=hn(e,t);if(n?.type===`Sound`||n?.type===`Video`)return n}return null}function pn(e,t){let n=[];for(let r of mn(e,t))if((Array.isArray(r?.motivation)?r.motivation:[r?.motivation]).some(e=>e===`supplementing`||e===`captioning`||e===`transcribing`))for(let t of gn(r.body)){let r=hn(e,t);if(!r?.id)continue;let i=r.format||r.type;(i===`text/vtt`||i===`text/plain`||String(r.id).endsWith(`.vtt`))&&n.push({id:r.id,label:r.label,language:r.language,format:i})}return n}function mn(e,t){let n=[];for(let r of t?.items||[]){let t=e.get(r,{skipSelfReturn:!1});for(let r of t?.items||[]){let t=e.get(r,{skipSelfReturn:!1});t&&n.push(t)}}return n}function hn(e,t){let n=(0,m.isSpecificResource)(t)?t.source:t;return n?e.get(n,{skipSelfReturn:!1})||n:null}function gn(e){return e?Array.isArray(e)?e:[e]:[]}const _n=`@manifest-editor/av-temporal-range`;async function vn(e,t){let n=t.generateId(`range`,t.getParent());return t.embed({id:n,type:`Range`,label:e.label,behavior:e.behavior?.length?e.behavior:void 0,items:[Kt(e.canvasId,e.start,e.end)]})}function yn(e){let t=e.options.initialData||{},n=t.canvas,r=t.canvasId||n?.id,i=t.segments||[],a=(0,u.useRef)(null),[o,s]=(0,u.useState)(t.title||`Untitled range`),[c,d]=(0,u.useState)(en(t.start||0)),[p,m]=(0,u.useState)(en(t.end||Math.min(n?.duration||0,30))),[h,g]=(0,u.useState)(!1),_=(0,u.useMemo)(()=>{let e=tn(c),t=tn(p),a=[];if(e===null||t===null)a.push(`Enter readable start and end times.`);else if(n){let r=Qt([...i,{id:`__draft__`,title:o,start:e,end:t}],n.duration,{requireTitle:!0});r.valid||a.push(r.issues[0]?.message||`Range is invalid.`)}else t<=e&&a.push(`End time must be after start time.`);return r||a.push(`Canvas is missing.`),{startTime:e,endTime:t,errors:a}},[c,p,o,n,r,i]),v=t=>{t.preventDefault(),!(_.startTime===null||_.endTime===null||_.errors.length||!r)&&e.runCreate({type:`Range`,label:{en:[o.trim()]},canvasId:r,start:_.startTime,end:_.endTime,behavior:h?[`no-nav`]:[]})},y=()=>{!a.current||_.startTime===null||_.endTime===null||(a.current.currentTime=_.startTime,a.current.play())},b=e=>{_.startTime===null||_.endTime===null||_.endTime<=_.startTime||(e.currentTime<_.startTime||e.currentTime>=_.endTime)&&(e.currentTime=_.startTime)},x=e=>{_.endTime!==null&&e.currentTarget.currentTime>=_.endTime&&(e.currentTarget.pause(),e.currentTarget.currentTime=_.endTime)};return(0,u.useEffect)(()=>{!a.current||_.startTime===null||_.endTime===null||_.endTime<=_.startTime||(a.current.currentTime=_.startTime)},[_.startTime,_.endTime]),(0,f.jsxs)(l.Form.Form,{className:`flex flex-col gap-4`,onSubmit:v,children:[(0,f.jsxs)(`div`,{className:`flex items-start gap-3`,children:[n?.media.type===`Video`?(0,f.jsx)(l.VideoIcon,{className:`text-2xl`}):(0,f.jsx)(l.AudioIcon,{className:`text-2xl`}),(0,f.jsxs)(`div`,{className:`min-w-0`,children:[(0,f.jsx)(`h3`,{className:`font-semibold text-lg`,children:`Create A/V range`}),(0,f.jsx)(`p`,{className:`text-sm text-me-gray-700 truncate`,children:n?.title||t.canvasId})]})]}),n?(0,f.jsx)(`div`,{className:`rounded border border-me-gray-300 bg-me-gray-50 p-2`,children:n.media.type===`Video`?(0,f.jsx)(`video`,{ref:a,src:n.media.id,controls:!0,className:`max-h-64 w-full bg-black object-contain`,onPlay:e=>b(e.currentTarget),onSeeking:e=>b(e.currentTarget),onTimeUpdate:x}):(0,f.jsx)(`audio`,{ref:a,src:n.media.id,controls:!0,className:`w-full`,onPlay:e=>b(e.currentTarget),onSeeking:e=>b(e.currentTarget),onTimeUpdate:x})}):null,(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-create-title`,children:`Title`}),(0,f.jsx)(l.Form.Input,{id:`av-create-title`,value:o,onChange:e=>s(e.currentTarget.value)})]}),(0,f.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-create-start`,children:`Start`}),(0,f.jsx)(l.Form.Input,{id:`av-create-start`,value:c,onChange:e=>d(e.currentTarget.value)})]}),(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-create-end`,children:`End`}),(0,f.jsx)(l.Form.Input,{id:`av-create-end`,value:p,onChange:e=>m(e.currentTarget.value)})]})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,f.jsxs)(`span`,{children:[`Duration:`,` `,_.startTime!==null&&_.endTime!==null?en(Math.max(0,_.endTime-_.startTime)):`Invalid`]}),(0,f.jsx)(l.ActionButton,{type:`button`,onPress:y,children:`Preview selection`})]}),(0,f.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.currentTarget.checked)}),`Hidden from navigation`]}),_.errors[0]?(0,f.jsx)(l.WarningMessage,{children:_.errors[0]}):null,(0,f.jsx)(l.ActionButton,{primary:!0,type:`submit`,isDisabled:!!_.errors.length,children:`Create range`})]})}const bn=(0,x.defineCreator)({id:_n,create:vn,label:`A/V temporal range`,summary:`Create a temporal range on an audio or video canvas`,icon:(0,f.jsx)(l.AudioIcon,{}),resourceType:`Range`,resourceFields:[`id`,`label`,`type`,`items`,`behavior`],supports:{initialData:!0,parentTypes:[`Manifest`],parentFields:[`structures`]},staticFields:{type:`Range`},render(e){return(0,f.jsx)(yn,{...e})}}),xn={id:`@manifest-editor/av-ranges-listing`,label:`A/V Ranges`,icon:(0,f.jsx)(l.AudioIcon,{}),options:{minWidth:300,maxWidth:360},render:()=>(0,f.jsx)(Sn,{})};function Sn(){(0,d.useVault)();let e=(0,d.useManifest)(),{create:t}=(0,a.useLayoutActions)(),{canvasId:n,selectedRangeId:r,draft:i,setCanvasId:o,setSelectedRangeId:s,setDraft:c}=ln(),[p,m]=(0,u.useState)(``),h=(0,u.useRef)(null),{canvases:g,segments:_}=(0,d.useVaultSelector)((t,n)=>({canvases:un(n,e),segments:Jt(n,e)}),[e]),v=(0,u.useMemo)(()=>g.length?g.find(e=>e.id===n)||g[0]:null,[g,n]);(0,u.useEffect)(()=>{!n&&v&&o(v.id)},[v?.id,n,o]);let y=(0,u.useMemo)(()=>v?Xt(_,v.id):[],[_,v?.id]),b=y.find(e=>e.id===r)||null,x=y.filter(e=>e.title.toLocaleLowerCase().includes(p.toLocaleLowerCase()));(0,u.useEffect)(()=>{b&&h.current&&h.current.scrollIntoView({behavior:`smooth`,block:`nearest`})},[b?.id]);let S=(n,r=`Untitled range`)=>{if(!e||!v)return;let i=$t(n,y,v.duration);i.end<=i.start||(t({type:`Range`,parent:{id:e.id,type:`Manifest`},property:`structures`,initialCreator:_n,initialData:{canvas:v,canvasId:v.id,segments:y,title:r,start:i.start,end:i.end}}),c(null))},C=v?Zt(y,v.duration):[];return(0,f.jsxs)(l.Sidebar,{children:[(0,f.jsx)(l.SidebarHeader,{title:`A/V Ranges`,actions:v?[{icon:(0,f.jsx)(l.AddIcon,{color:`currentColor`,height:16}),title:`New range`,onClick:()=>{if(!v)return;let e=C.find(e=>e.duration>.25)||{start:0,end:Math.min(30,v.duration)};c({start:e.start,end:e.end})}}]:[]}),(0,f.jsxs)(l.SidebarContent,{className:`p-3 flex flex-col gap-3`,children:[g.length?null:(0,f.jsx)(l.WarningMessage,{children:`No audio or video canvases are available for temporal range editing.`}),v?(0,f.jsxs)(f.Fragment,{children:[g.length>1?(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-canvas-select`,children:`Canvas`}),(0,f.jsx)(`select`,{id:`av-canvas-select`,className:`p-2 bg-me-gray-100 border-b border-b-me-gray-500 text-sm`,value:v.id,onChange:e=>o(e.currentTarget.value),children:g.map(e=>(0,f.jsx)(`option`,{value:e.id,children:e.title},e.id))})]}):null,i?(0,f.jsxs)(`div`,{className:`rounded-lg border border-me-primary-300 bg-me-primary-50 p-3 flex flex-col gap-2`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,f.jsx)(`div`,{className:`text-sm font-semibold text-me-primary-900`,children:`Draft range`}),(0,f.jsx)(`button`,{type:`button`,className:`text-me-gray-500 hover:text-me-gray-700 p-0.5 rounded hover:bg-white/50`,"aria-label":`Discard draft`,onClick:()=>c(null),children:(0,f.jsx)(l.CloseIcon,{width:14,height:14})})]}),(0,f.jsxs)(`div`,{className:`text-sm tabular-nums text-me-primary-700`,children:[J(i.start),` → `,J(i.end),(0,f.jsxs)(`span`,{className:`text-me-primary-500 ml-2`,children:[`(`,J(i.end-i.start),`)`]})]}),(0,f.jsx)(l.ActionButton,{primary:!0,center:!0,onPress:()=>S(i),children:`Create range from selection`})]}):null,b?(0,f.jsx)(`div`,{ref:h,children:(0,f.jsx)(Cn,{segment:b,canvasDuration:v.duration,segments:y},b.id)}):null,!b&&!i&&y.length===0?(0,f.jsx)(l.InfoMessage,{children:`Create the first range by dragging on the timeline, using Mark in/out, or pressing New range.`}):null,y.length>0?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,f.jsx)(l.Form.InputContainer,{className:`flex-1 min-w-0`,children:(0,f.jsx)(l.Form.Input,{id:`av-range-search`,value:p,placeholder:`Search ranges…`,onChange:e=>m(e.currentTarget.value),"aria-label":`Search ranges`})}),(0,f.jsxs)(`span`,{className:`text-xs text-me-gray-500 tabular-nums flex-shrink-0`,children:[x.length,`/`,y.length]})]}),(0,f.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:x.map((e,t)=>(0,f.jsx)(`button`,{type:`button`,className:[`text-left rounded-md border px-3 py-2 transition-colors`,r===e.id?`border-me-primary-400 bg-me-primary-50`:`border-me-gray-200 bg-white hover:bg-me-gray-50`].join(` `),onClick:()=>s(e.id),children:(0,f.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,f.jsx)(`span`,{className:`text-[10px] font-mono text-me-gray-400 w-4 text-right shrink-0 mt-0.5 leading-tight`,children:t+1}),(0,f.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,f.jsx)(`div`,{className:[`text-sm font-medium truncate leading-tight`,r===e.id?`text-me-primary-900`:`text-me-gray-900`].join(` `),children:e.title}),(0,f.jsxs)(`div`,{className:`text-xs text-me-gray-500 tabular-nums mt-0.5`,children:[J(e.start),` – `,J(e.end),` `,(0,f.jsxs)(`span`,{className:`text-me-gray-400`,children:[`· `,J(e.duration)]})]})]}),r===e.id?(0,f.jsx)(`span`,{className:`w-1 h-4 rounded-full bg-me-primary-500 shrink-0 mt-0.5`}):null]})},e.id))})]}):null]}):null]})]})}function Cn({segment:e,canvasDuration:t,segments:n}){let r=(0,d.useVault)(),{setSelectedRangeId:i}=ln(),[a,o]=(0,u.useState)(e.title),[s,c]=(0,u.useState)(en(e.start)),[p,m]=(0,u.useState)(en(e.end)),[h,g]=(0,u.useState)(!1),[_,v]=(0,u.useState)(e.behavior?.includes(`no-nav`)||!1),y=tn(s),b=tn(p),x=y===null||b===null?{valid:!1,issues:[{message:`Enter readable start and end times.`}]}:Qt([...n.filter(t=>t.id!==e.id),{id:e.id,title:a,start:y,end:b}],t,{requireTitle:!0}),S=n.findIndex(t=>t.id===e.id),C=S>0?n[S-1]:null,w=S>=0?n[S+1]:null;return(0,f.jsxs)(`div`,{className:`rounded-lg border border-me-gray-200 bg-white overflow-hidden`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-me-gray-50 border-b border-me-gray-200`,children:[(0,f.jsx)(`div`,{className:`text-xs font-semibold text-me-gray-600 uppercase tracking-wide flex-1`,children:`Edit range`}),(0,f.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 text-xs text-me-gray-500 hover:text-me-gray-700 px-1.5 py-0.5 rounded hover:bg-me-gray-200 transition-colors`,onClick:()=>i(null),children:[(0,f.jsx)(l.CloseIcon,{width:12,height:12}),`Deselect`]})]}),(0,f.jsxs)(`div`,{className:`p-3 flex flex-col gap-3`,children:[(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-range-title`,children:`Title`}),(0,f.jsx)(l.Form.Input,{id:`av-range-title`,value:a,onChange:e=>o(e.currentTarget.value)})]}),(0,f.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-range-start`,children:`Start`}),(0,f.jsx)(l.Form.Input,{id:`av-range-start`,value:s,onChange:e=>c(e.currentTarget.value)})]}),(0,f.jsxs)(l.Form.InputContainer,{children:[(0,f.jsx)(l.Form.Label,{htmlFor:`av-range-end`,children:`End`}),(0,f.jsx)(l.Form.Input,{id:`av-range-end`,value:p,onChange:e=>m(e.currentTarget.value)})]})]}),(0,f.jsxs)(`div`,{className:`text-xs text-me-gray-500 tabular-nums`,children:[`Duration:`,` `,(0,f.jsx)(`span`,{className:`font-medium text-me-gray-700`,children:y!==null&&b!==null?J(Math.max(0,b-y)):`—`})]}),x.valid?null:(0,f.jsx)(l.WarningMessage,{children:x.issues[0]?.message||`Range is invalid.`}),(0,f.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,f.jsx)(l.ActionButton,{primary:!0,isDisabled:!x.valid,onPress:()=>{if(y===null||b===null||!x.valid)return;let i=$t({start:y,end:b},n,t,e.id);Y(r,e,{label:{en:[a.trim()]},start:i.start,end:i.end,behavior:_?[`no-nav`]:[]})},children:`Save`}),(0,f.jsx)(l.ActionButton,{className:`text-red-700 hover:bg-red-50`,onPress:()=>{cn(r,e),i(null)},children:`Delete`})]}),C||w?(0,f.jsxs)(`div`,{className:`flex flex-wrap gap-2 border-t border-me-gray-100 pt-2.5`,children:[C?(0,f.jsx)(l.ActionButton,{onPress:()=>{Y(r,C,{end:e.end}),cn(r,e),i(C.id)},children:`← Merge with previous`}):null,w?(0,f.jsx)(l.ActionButton,{onPress:()=>{Y(r,e,{end:w.end}),cn(r,w),i(e.id)},children:`Merge with next →`}):null]}):null,(0,f.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left text-xs font-medium text-me-gray-500 hover:text-me-gray-700 py-0.5 transition-colors`,onClick:()=>g(e=>!e),children:[(0,f.jsx)(wn,{open:h}),`Advanced options`]}),h?(0,f.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-me-gray-700 pl-5`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.currentTarget.checked)}),`Hidden from navigation`]}):null]})]})}function wn({open:e}){return(0,f.jsx)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 16 16`,className:`h-3.5 w-3.5 shrink-0 transition-transform`,style:{transform:e?`rotate(90deg)`:`rotate(0deg)`},fill:`currentColor`,children:(0,f.jsx)(`path`,{d:`M5.5 3.5 10 8l-4.5 4.5`,stroke:`currentColor`,strokeWidth:`1.5`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`})})}const Tn={id:`av-ranges-workbench`,label:`A/V Range Workbench`,icon:``,render:()=>(0,f.jsx)(An,{})},En=.75;function Dn(e,t,n){let r=[0,n,...t.flatMap(e=>[e.start,e.end])],i=r.reduce((t,n)=>Math.abs(n-e)<Math.abs(t-e)?n:t,r[0]||0);return Math.abs(i-e)<=En?i:e}function On(e,t,n){return{start:Dn(e.start,t,n),end:Dn(e.end,t,n)}}function kn(e,t,n,r){let i=t.end-t.start,a=[0,Math.max(0,r-i),...n.filter(e=>e.id!==t.id).flatMap(e=>[e.end,e.start-i])].filter(e=>e>=0&&e<=r-i),o=a.reduce((t,n)=>Math.abs(n-e)<Math.abs(t-e)?n:t,a[0]||0);return Math.abs(o-e)<=En?o:e}function An(){let e=(0,d.useVault)(),t=(0,d.useManifest)(),{create:n}=(0,a.useLayoutActions)(),r=(0,u.useRef)(null),i=(0,u.useRef)(null),{canvasId:o,selectedRangeId:s,draft:c,markStart:p,setCanvasId:m,setSelectedRangeId:h,setDraft:g,setMarkStart:_}=ln(),[v,y]=(0,u.useState)(0),[b,x]=(0,u.useState)(!1),[S,C]=(0,u.useState)(1),[w,T]=(0,u.useState)(1),[E,D]=(0,u.useState)(!1),[O,k]=(0,u.useState)(1),[A,j]=(0,u.useState)(!1),{canvases:M,segments:N}=(0,d.useVaultSelector)((e,n)=>({canvases:un(n,t),segments:Jt(n,t)}),[t]),P=(0,u.useMemo)(()=>M.length?M.find(e=>e.id===o)||M[0]:null,[M,o]);(0,u.useEffect)(()=>{!o&&P&&m(P.id)},[P?.id,o,m]);let F=(0,u.useMemo)(()=>P?Xt(N,P.id):[],[N,P?.id]),I=F.find(e=>e.id===s)||null,L=P?Zt(F,P.duration):[];(0,u.useEffect)(()=>{let e=r.current;!e||!I||(e.currentTime=I.start,y(I.start))},[I?.id]),(0,u.useEffect)(()=>{let e=r.current;e&&(e.playbackRate=S)},[S]),(0,u.useEffect)(()=>{let e=r.current;e&&(e.volume=w)},[w]);let R=(0,u.useCallback)(e=>{let t=r.current,n=Math.max(0,Math.min(e,P?.duration||0));t&&(t.currentTime=n),y(n)},[P?.duration]),z=(0,u.useCallback)(()=>{let e=r.current;e&&(e.paused?e.play():e.pause())},[]),ee=(0,u.useCallback)(()=>{I&&(R(I.start),r.current?.play())},[I,R]),B=(0,u.useCallback)(()=>{if(!t||!P||!c)return;let e=$t(c,F,P.duration);e.end<=e.start||(n({type:`Range`,parent:{id:t.id,type:`Manifest`},property:`structures`,initialCreator:_n,initialData:{canvas:P,canvasId:P.id,segments:F,title:`Untitled range`,start:e.start,end:e.end}}),g(null))},[t,P,c,F,n,g]),V=(0,u.useCallback)(()=>{if(!t||!P||!I)return;let n=v;if(n<=I.start||n>=I.end)return;Y(e,I,{end:n});let r=sn(e,t,{canvasId:P.id,start:n,end:I.end,label:{en:[`${I.title} 2`]},atIndex:I.parentKey===`structures`?I.parentIndex+1:void 0});h(r.id)},[t,P,I,v,e,h]),H=(0,u.useCallback)(()=>{I&&(cn(e,I),h(null))},[I,e,h]),te=(0,u.useCallback)((t,n)=>{if(!P)return null;let r=F.find(e=>e.id===t);if(!r)return null;let i=$t(n,F,P.duration,r.id);return i.end<=i.start?null:(Y(e,r,i),i)},[P,F,e]),ne=(0,u.useCallback)((t,n)=>{if(!P)return;let r=F.slice().sort((e,t)=>e.start-t.start),i=r.findIndex(e=>e.id===t),a=r[i];if(!a)return;let o=a.end-a.start,s=i>0?r[i-1]:null,c=i>=0&&i<r.length-1?r[i+1]:null,l=s?s.end:0,u=(c?c.start:P.duration)-o,d=Math.max(l,Math.min(n,u));Y(e,a,{start:d,end:d+o})},[P,F,e]);if((0,u.useEffect)(()=>{let t=t=>{if(!(t.target instanceof HTMLInputElement||t.target instanceof HTMLTextAreaElement||t.target instanceof HTMLSelectElement)&&P){if(t.key===` `)t.preventDefault(),z();else if(t.key===`ArrowLeft`||t.key.toLowerCase()===`j`)R(v-5);else if(t.key===`ArrowRight`||t.key.toLowerCase()===`l`)R(v+5);else if(t.key.toLowerCase()===`i`)_(v);else if(t.key.toLowerCase()===`o`&&p!==null)g(On({start:Math.min(p,v),end:Math.max(p,v)},F,P.duration)),_(null);else if(t.key===`Enter`&&c)B();else if(t.key===`Escape`)g(null),_(null);else if(t.key.toLowerCase()===`s`)V();else if(t.key===`Delete`||t.key===`Backspace`)H();else if(t.key===`ArrowUp`||t.key===`ArrowDown`){t.preventDefault();let e=F.findIndex(e=>e.id===s),n=t.key===`ArrowUp`?Math.max(0,e-1):Math.min(F.length-1,e+1),r=F[e===-1?0:n];r&&h(r.id)}else if((t.key===`[`||t.key===`]`)&&I){let n=t.shiftKey?1:.1,r=$t(t.key===`[`?{start:I.start+(t.altKey?n:-n),end:I.end}:{start:I.start,end:I.end+(t.altKey?-n:n)},F,P.duration,I.id);Y(e,I,r)}}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[P,v,p,c,I,s,F,z,R,B,V,H,g,_,h,e]),!M.length)return(0,f.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,f.jsx)(l.WarningMessage,{children:`No audio or video canvases are available for temporal range editing.`})});if(!P)return null;let U=P.media.type===`Video`;return(0,f.jsxs)(`div`,{className:`h-full min-h-0 flex flex-col overflow-hidden bg-me-gray-50`,children:[(0,f.jsxs)(`div`,{className:`bg-white border-b border-me-gray-200 px-4 py-2.5 flex items-center gap-3 flex-shrink-0`,children:[(0,f.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,f.jsx)(`h2`,{className:`font-semibold truncate leading-tight`,children:P.title}),(0,f.jsxs)(`div`,{className:`text-xs text-me-gray-500 mt-0.5`,children:[U?`Video`:`Audio`,` ·`,` `,(0,f.jsx)(`span`,{className:`tabular-nums`,children:J(P.duration)})]})]}),p===null?null:(0,f.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-full bg-amber-50 border border-amber-200 px-3 py-1 text-xs text-amber-700 font-medium flex-shrink-0`,children:[(0,f.jsx)(Ln,{}),(0,f.jsxs)(`span`,{children:[`Mark in: `,J(p),` · press `,(0,f.jsx)(`kbd`,{className:`font-mono`,children:`O`}),` to mark end`]})]})]}),(0,f.jsxs)(`div`,{className:`flex-shrink-0 bg-white border-b border-me-gray-200`,children:[U?(0,f.jsx)(`div`,{className:`bg-black`,children:(0,f.jsx)(`video`,{ref:r,className:`block w-full max-h-[38vh] object-contain`,src:P.media.id,preload:`metadata`,playsInline:!0,onTimeUpdate:e=>{let t=e.currentTarget.currentTime;y(t),E&&I&&t>=I.end&&R(I.start)},onPlay:()=>x(!0),onPause:()=>x(!1),onEnded:()=>x(!1),children:P.captions.map(e=>(0,f.jsx)(`track`,{src:e.id,kind:`subtitles`,srcLang:e.language||`en`,label:e.language||`Captions`},e.id))})}):(0,f.jsx)(`audio`,{ref:r,src:P.media.id,preload:`metadata`,className:`hidden`,onTimeUpdate:e=>{let t=e.currentTarget.currentTime;y(t),E&&I&&t>=I.end&&R(I.start)},onPlay:()=>x(!0),onPause:()=>x(!1),onEnded:()=>x(!1),children:P.captions.map(e=>(0,f.jsx)(`track`,{src:e.id,kind:`subtitles`,srcLang:e.language||`en`,label:e.language||`Captions`},e.id))}),(0,f.jsx)(jn,{isVideo:U,isPlaying:b,currentTime:v,duration:P.duration,speed:S,volume:w,loopSelection:E,hasSelection:!!I,onTogglePlay:z,onSeek:R,onSpeed:C,onVolume:T,onPlaySelection:ee,onLoopSelection:D,onMarkStart:()=>_(v),onMarkEnd:()=>{p!==null&&(g(On({start:Math.min(p,v),end:Math.max(p,v)},F,P.duration)),_(null))},canMarkEnd:p!==null})]}),(0,f.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[(0,f.jsx)(Un,{canvas:P,segments:F,gaps:L,currentTime:v,selectedRangeId:s,draft:c,scale:O,dragRef:i,onSeek:R,onSelectRange:h,onDraft:g,onCreateDraft:B,onResizeRange:te,onMoveRange:ne,onScale:k}),(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,f.jsxs)(l.ActionButton,{isDisabled:!I,onPress:ee,children:[(0,f.jsx)(Hn,{}),`Play selection`]}),(0,f.jsxs)(l.ActionButton,{isDisabled:!I,onPress:V,children:[(0,f.jsx)(zn,{}),`Split at playhead`]}),(0,f.jsxs)(l.ActionButton,{isDisabled:!I,onPress:H,children:[(0,f.jsx)(Bn,{}),`Delete range`]}),P.captions.length?(0,f.jsxs)(l.ActionButton,{onPress:()=>j(e=>!e),children:[(0,f.jsx)(Vn,{}),A?`Hide captions`:`Show captions`]}):null]}),A&&P.captions[0]?(0,f.jsx)(Yn,{captionUrl:P.captions[0].id,currentTime:v,onSeek:R,onDraft:g}):null]})]})}function jn(e){return(0,f.jsxs)(`div`,{className:[`flex flex-col gap-2 px-3 py-2.5`,e.isVideo?`border-t border-me-gray-200 bg-me-gray-50`:``].join(` `),children:[(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,f.jsxs)(l.ActionButton,{primary:!0,large:!0,className:`min-w-[92px]`,onPress:e.onTogglePlay,children:[e.isPlaying?(0,f.jsx)(Nn,{}):(0,f.jsx)(Mn,{}),e.isPlaying?`Pause`:`Play`]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,f.jsxs)(l.ActionButton,{onPress:()=>e.onSeek(e.currentTime-5),children:[(0,f.jsx)(Pn,{}),(0,f.jsx)(`span`,{children:`-5s`})]}),(0,f.jsxs)(l.ActionButton,{onPress:()=>e.onSeek(e.currentTime+5),children:[(0,f.jsx)(Fn,{}),(0,f.jsx)(`span`,{children:`+5s`})]})]}),(0,f.jsxs)(`div`,{className:`rounded bg-me-gray-100 border border-me-gray-200 px-2.5 py-1 text-sm tabular-nums text-me-gray-700`,children:[J(e.currentTime),` / `,J(e.duration)]})]}),(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,f.jsxs)(`label`,{className:`text-sm flex items-center gap-1.5 text-me-gray-600`,children:[(0,f.jsx)(`span`,{className:`text-xs`,children:`Speed`}),(0,f.jsx)(`select`,{value:e.speed,onChange:t=>e.onSpeed(Number(t.currentTarget.value)),className:`bg-white border border-me-gray-300 rounded px-1 py-0.5 text-xs`,children:[.5,.75,1,1.25,1.5,2].map(e=>(0,f.jsxs)(`option`,{value:e,children:[e,`x`]},e))})]}),(0,f.jsxs)(`label`,{className:`text-sm flex items-center gap-1.5 text-me-gray-600`,children:[(0,f.jsx)(In,{}),(0,f.jsx)(`input`,{"aria-label":`Volume`,type:`range`,min:0,max:1,step:.05,value:e.volume,onChange:t=>e.onVolume(Number(t.currentTarget.value)),className:`w-20`})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,f.jsxs)(l.ActionButton,{onPress:e.onMarkStart,children:[(0,f.jsx)(Ln,{}),`Mark in`]}),(0,f.jsxs)(l.ActionButton,{isDisabled:!e.canMarkEnd,onPress:e.onMarkEnd,children:[(0,f.jsx)(Rn,{}),`Mark out`]})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,f.jsxs)(l.ActionButton,{isDisabled:!e.hasSelection,onPress:e.onPlaySelection,children:[(0,f.jsx)(Hn,{}),`Play selection`]}),(0,f.jsxs)(`label`,{className:`text-xs flex items-center gap-1.5 px-2 py-1 text-me-gray-600`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:e.loopSelection,disabled:!e.hasSelection,onChange:t=>e.onLoopSelection(t.currentTarget.checked)}),`Loop`]})]})]})]})}function X({children:e}){return(0,f.jsx)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 20 20`,className:`h-4 w-4 shrink-0`,fill:`currentColor`,children:e})}function Mn(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M6 4.5v11l9-5.5-9-5.5Z`})})}function Nn(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M5 4h3v12H5V4Zm7 0h3v12h-3V4Z`})})}function Pn(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M5 4h2v12H5V4Zm10.5 1v10L8 10l7.5-5Z`})})}function Fn(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M13 4h2v12h-2V4ZM4.5 5 12 10l-7.5 5V5Z`})})}function In(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M3 7.5h3L10 4v12l-4-3.5H3v-5Zm10.2-.7 1.2-1.2A6 6 0 0 1 16 10a6 6 0 0 1-1.6 4.4l-1.2-1.2A4.2 4.2 0 0 0 14.3 10c0-1.2-.4-2.3-1.1-3.2Z`})})}function Ln(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M5 4h2v12H5V4Zm5 3h6v2h-6V7Zm0 4h4v2h-4v-2Z`})})}function Rn(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M13 4h2v12h-2V4ZM4 7h6v2H4V7Zm2 4h4v2H6v-2Z`})})}function zn(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M10 4h2v5.5l3-3 1.4 1.4L12 12.3l4.4 4.4-1.4 1.4-3-3V20h-2v-5.7l-3 3-1.4-1.4L9.9 12 6.5 8.7l1.4-1.4 2.1 2.1V4Z`})})}function Bn(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M6 15h3L4.5 19 0 15h3V5h3v10Zm4-9h7v2h-7V6Zm0 4h5v2h-5v-2Zm0 4h3v2h-3v-2Z`})})}function Vn(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M2 4a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2H2Zm2 5h2v1H4V9Zm0 2h6v1H4v-1Zm7 0h5v1h-5v-1Zm1-2h4v1h-4V9ZM4 7h12v1H4V7Z`})})}function Hn(){return(0,f.jsx)(X,{children:(0,f.jsx)(`path`,{d:`M4 5h2v10H4V5Zm10 0h2v10h-2V5ZM8 6.5l5 3.5-5 3.5v-7Z`})})}function Un({canvas:e,segments:t,gaps:n,currentTime:r,selectedRangeId:i,draft:a,scale:o,dragRef:s,onSeek:c,onSelectRange:d,onDraft:p,onCreateDraft:m,onResizeRange:h,onMoveRange:g,onScale:_}){let v=(0,u.useRef)(null),y=(0,u.useRef)(null),b=(0,u.useRef)(null),x=(0,u.useRef)(null),S=(0,u.useRef)(!1),[C,w]=(0,u.useState)(null),[T,E]=(0,u.useState)(null),[D,O]=(0,u.useState)(null),{major:k,minor:A}=(0,u.useMemo)(()=>Wn(e.duration,o),[e.duration,o]),j=t=>`${Math.max(0,Math.min(100,t/e.duration*100))}%`,M=t=>{let n=t.currentTarget.getBoundingClientRect();return Math.max(0,Math.min(e.duration,(t.clientX-n.left)/n.width*e.duration))},N=t=>{let n=y.current?.getBoundingClientRect();return n?Math.max(0,Math.min(e.duration,(t-n.left)/n.width*e.duration)):0};return(0,f.jsxs)(`div`,{className:`rounded-lg border border-me-gray-200 bg-white p-4 flex flex-col gap-3`,children:[(0,f.jsx)(`div`,{className:`flex items-center justify-end gap-3`,children:(0,f.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-me-gray-500`,children:[`Zoom`,(0,f.jsx)(`input`,{"aria-label":`Timeline zoom`,type:`range`,min:1,max:8,step:1,value:o,onChange:e=>_(Number(e.currentTarget.value))}),(0,f.jsxs)(`span`,{className:`w-6 tabular-nums`,children:[o,`x`]})]})}),(0,f.jsx)(`div`,{className:`overflow-x-auto pb-2`,children:(0,f.jsxs)(`div`,{className:`min-w-full`,style:{width:`${Math.max(1,o)*100}%`},children:[(0,f.jsx)(Gn,{duration:e.duration,major:k,toPercent:j}),(0,f.jsx)(`div`,{className:`text-[10px] font-medium text-me-gray-400 uppercase tracking-wider mb-1`,children:`Overview`}),(0,f.jsxs)(`div`,{ref:v,className:`relative h-8 rounded bg-me-gray-100 border border-me-gray-300 overflow-hidden`,style:{height:32,minHeight:32},onPointerDown:n=>c(Dn(M(n),t,e.duration)),onPointerMove:e=>w(M(e)),onPointerLeave:()=>w(null),children:[(0,f.jsx)(Kn,{major:k,minor:A,toPercent:j}),t.map(e=>(0,f.jsx)(`div`,{className:`absolute top-1 bottom-1 rounded-sm bg-me-primary-300`,style:{left:j(e.start),width:j(e.end-e.start)}},e.id)),C===null?null:(0,f.jsx)(qn,{time:C,duration:e.duration}),(0,f.jsx)(Jn,{currentTime:r,duration:e.duration})]}),(0,f.jsx)(`div`,{className:`mt-3 text-[10px] font-medium text-me-gray-400 uppercase tracking-wider mb-1`,children:`Ranges`}),(0,f.jsxs)(`div`,{ref:y,className:`relative h-28 rounded bg-me-gray-50 border border-me-gray-300 select-none overflow-hidden`,style:{height:112,minHeight:112},onPointerDown:n=>{let r=Dn(M(n),t,e.duration);s.current={start:r,end:r},n.currentTarget.setPointerCapture(n.pointerId),p({start:r,end:r})},onPointerMove:n=>{w(M(n));let r=b.current;if(r){let i=Dn(M(n),t.filter(e=>e.id!==r.segment.id),e.duration),a=h(r.segment.id,r.edge===`start`?{start:i,end:r.segment.end}:{start:r.segment.start,end:i});a&&c(r.edge===`start`?a.start:a.end);return}let i=x.current;if(i){let r=kn(N(n.clientX)-i.offset,i.segment,t,e.duration);i.moved=!0,g(i.segment.id,r);return}if(!s.current)return;let a=Dn(M(n),t,e.duration);s.current.end=a,p(On({start:Math.min(s.current.start,a),end:Math.max(s.current.start,a)},t,e.duration))},onPointerLeave:()=>{!b.current&&!x.current&&!s.current&&w(null)},onPointerUp:e=>{if(b.current){let t=b.current.pointerId;b.current=null,E(null),e.currentTarget.hasPointerCapture(t)&&e.currentTarget.releasePointerCapture(t);return}if(x.current){let t=x.current.pointerId;S.current=x.current.moved,x.current=null,O(null),e.currentTarget.hasPointerCapture(t)&&e.currentTarget.releasePointerCapture(t);return}let t=s.current;if(s.current=null,!t)return;let r=Math.min(t.start,t.end);if(Math.max(t.start,t.end)-r<.15){let e=n.find(e=>r>=e.start&&r<=e.end);p(e?{start:e.start,end:e.end}:null)}e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)},children:[(0,f.jsx)(Kn,{major:k,minor:A,toPercent:j}),n.map(e=>(0,f.jsx)(`button`,{type:`button`,className:`absolute top-0 h-full bg-white/50 hover:bg-me-primary-50 border-x border-dashed border-me-gray-300`,style:{left:j(e.start),width:j(e.end-e.start)},onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),p({start:e.start,end:e.end})},"aria-label":`Create range from gap ${J(e.start)} to ${J(e.end)}`},`${e.start}-${e.end}`)),t.map(e=>(0,f.jsxs)(`button`,{type:`button`,className:[`absolute top-5 bottom-5 rounded-sm px-2 text-left overflow-hidden border shadow-sm group`,i===e.id||T===e.id||D===e.id?`bg-me-primary-500 text-white border-me-primary-700`:`bg-me-primary-200 border-me-primary-400 text-me-gray-900`].join(` `),style:{left:j(e.start),width:j(e.end-e.start),minWidth:54,cursor:i===e.id?`move`:`pointer`},onPointerDown:t=>{if(t.stopPropagation(),d(e.id),i!==e.id)return;let n=N(t.clientX)-e.start;x.current={pointerId:t.pointerId,segment:e,offset:n,moved:!1},O(e.id),y.current?.setPointerCapture(t.pointerId)},onClick:t=>{if(t.stopPropagation(),S.current){S.current=!1;return}d(e.id),c(e.start)},title:`${e.title}: ${J(e.start)} to ${J(e.end)}`,children:[(0,f.jsx)(`span`,{className:`absolute left-0 top-0 bottom-0 w-2 cursor-ew-resize bg-black/10 hover:bg-black/25`,"aria-hidden":`true`,style:{cursor:`ew-resize`},onPointerDown:t=>{t.stopPropagation(),d(e.id),b.current={edge:`start`,pointerId:t.pointerId,segment:e},E(e.id),y.current?.setPointerCapture(t.pointerId)}}),(0,f.jsx)(`span`,{className:`absolute right-0 top-0 bottom-0 w-2 cursor-ew-resize bg-black/10 hover:bg-black/25`,"aria-hidden":`true`,style:{cursor:`ew-resize`},onPointerDown:t=>{t.stopPropagation(),d(e.id),b.current={edge:`end`,pointerId:t.pointerId,segment:e},E(e.id),y.current?.setPointerCapture(t.pointerId)}}),(0,f.jsx)(`span`,{className:`block truncate text-xs font-semibold leading-4`,children:e.title}),(0,f.jsxs)(`span`,{className:`block truncate text-[10px] leading-4 opacity-80 tabular-nums`,children:[J(e.start),` - `,J(e.end)]})]},e.id)),a?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:`absolute top-3 bottom-3 border-2 border-me-primary-700 bg-me-primary-200/70 pointer-events-none rounded-sm`,style:{left:j(a.start),width:j(a.end-a.start),minWidth:4}}),(0,f.jsxs)(`div`,{className:`absolute top-1 z-20 rounded bg-white border border-me-primary-500 shadow-md p-1 flex gap-1 items-center`,style:{left:j((a.start+a.end)/2),transform:`translateX(-50%)`},onPointerDown:e=>e.stopPropagation(),children:[(0,f.jsxs)(`span`,{className:`text-xs tabular-nums whitespace-nowrap`,children:[J(a.start),` - `,J(a.end)]}),(0,f.jsx)(l.ActionButton,{primary:!0,onPress:m,children:`Create`})]})]}):null,(0,f.jsx)(Jn,{currentTime:r,duration:e.duration})]})]})})]})}function Wn(e,t=1){let n=[.25,.5,1,2,5,10,15,30,60,120,300,600,900,1800,3600],r=Math.round(14*t),i=Math.round(60*t),a=e/r,o=n.find(e=>e>=a)??n[n.length-1],s=o;for(let t of n){if(t>=o)break;let n=o/t;if(Math.abs(Math.round(n)-n)<.001&&e/t<=i){s=t;break}}let c=[],l=[],u=Math.round(o/s),d=s*.01;for(let t=0;t*s<=e+d;t++){let n=Math.round(Math.min(t*s,e)*1e3)/1e3;if(l.length>0&&n===l[l.length-1]||(l.push(n),t%u===0&&c.push(n),n>=e))break}return(l[l.length-1]??-1)<e&&(l.push(e),c.push(e)),c.length>=2&&c[c.length-1]===e&&e-(c[c.length-2]??0)<o*.55&&c.pop(),{major:c,minor:l}}function Gn({duration:e,major:t,toPercent:n}){return(0,f.jsx)(`div`,{className:`relative h-5 text-[11px] text-me-gray-700 select-none`,children:t.map(t=>{let r=t===0?`translateX(0)`:t===e?`translateX(-100%)`:`translateX(-50%)`;return(0,f.jsx)(`span`,{className:`absolute top-0 tabular-nums`,style:{left:n(t),transform:r},children:J(t)},t)})})}function Kn({major:e,minor:t,toPercent:n}){let r=new Set(e);return(0,f.jsx)(f.Fragment,{children:t.map(e=>r.has(e)?(0,f.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-me-gray-300/80`,style:{left:n(e)}},e):(0,f.jsx)(`div`,{className:`absolute top-1/4 bottom-0 border-l border-me-gray-200/70`,style:{left:n(e)}},e))})}function qn({time:e,duration:t}){let n=`${Math.max(0,Math.min(100,e/t*100))}%`;return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px pointer-events-none z-20`,style:{left:n,backgroundColor:`#111827`}}),(0,f.jsx)(`div`,{className:`absolute top-0 z-30 -translate-x-1/2 rounded px-1.5 py-0.5 text-[11px] tabular-nums pointer-events-none shadow`,style:{left:n,backgroundColor:`#111827`,color:`#ffffff`},children:J(e)})]})}function Jn({currentTime:e,duration:t}){return(0,f.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-600 pointer-events-none`,style:{left:`${Math.max(0,Math.min(100,e/t*100))}%`}})}function Yn({captionUrl:e,currentTime:t,onSeek:n,onDraft:r}){let[i,a]=(0,u.useState)([]),o=(0,u.useRef)(null);return(0,u.useEffect)(()=>{let t=!1;return fetch(e).then(e=>e.text()).then(e=>{t||a(Xn(e))}).catch(()=>{t||a([])}),()=>{t=!0}},[e]),i.length?(0,f.jsx)(`div`,{className:`rounded border border-me-gray-300 bg-white p-3 max-h-72 overflow-y-auto`,children:i.map((e,i)=>{let a=t>=e.start&&t<=e.end;return(0,f.jsxs)(`button`,{type:`button`,className:[`block w-full text-left rounded p-2 text-sm`,a?`bg-me-primary-100`:`hover:bg-me-gray-100`].join(` `),onClick:()=>n(e.start),onPointerDown:()=>{o.current=e.start},onPointerUp:()=>{o.current!==null&&o.current!==e.start&&r({start:Math.min(o.current,e.start),end:Math.max(o.current,e.end)}),o.current=null},children:[(0,f.jsx)(`span`,{className:`text-xs text-me-gray-600 mr-2`,children:J(e.start)}),e.text]},`${e.start}-${i}`)})}):(0,f.jsx)(l.InfoMessage,{children:`Transcript could not be loaded.`})}function Xn(e){let t=e.replace(/\r/g,``).split(/\n\n+/),n=[];for(let e of t){let t=e.split(`
|
|
55
|
+
`).filter(Boolean),r=t.findIndex(e=>e.includes(`-->`));if(r===-1)continue;let[i,a]=t[r].split(`-->`).map(e=>e.trim().split(/\s+/)[0]),o=Zn(i||``),s=Zn(a||``);o!==null&&s!==null&&n.push({start:o,end:s,text:t.slice(r+1).join(` `)})}return n}function Zn(e){let t=e.split(`:`);if(t.length===2){let e=Number.parseFloat(t[0]),n=Number.parseFloat(t[1]);return Number.isFinite(e)&&Number.isFinite(n)?e*60+n:null}if(t.length===3){let e=Number.parseFloat(t[0]),n=Number.parseFloat(t[1]),r=Number.parseFloat(t[2]);return Number.isFinite(e)&&Number.isFinite(n)&&Number.isFinite(r)?e*3600+n*60+r:null}return null}var Qn=e.m({background:()=>ir,centerPanels:()=>nr,creators:()=>rr,default:()=>$n,leftPanels:()=>tr}),$n={id:`@manifest-editor/av-ranges`,label:`A/V Ranges`,description:`Create and edit temporal ranges for audio and video canvases.`,author:`Digirati`,official:!0,defaultEnabled:!1,tags:[`audio`,`video`,`ranges`,`chaptering`],supports:{projectTypes:[`Manifest`]}};function er(e){if(!e.rootResource||e.rootResource.type!==`Manifest`||!e.vault)return!1;let t=e.vault.get(e.rootResource,{skipSelfReturn:!1});return un(e.vault,t).length>0}const tr=[{...xn,supports:er}],nr=[{...Tn,supports:er}],rr=[bn],ir=[{id:`av-ranges-plugin-sync`,label:`A/V ranges plugin sync`,render:()=>(0,f.jsx)(ar,{})}];function ar(){let{leftPanel:e,rightPanel:t}=(0,a.useLayoutState)(),{open:n,rightPanel:r}=(0,a.useLayoutActions)(),[i,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{if(e.current===xn.id){n({id:Tn.id}),t.open&&(r.close(),o(!0));return}!t.open&&i&&(r.open(),o(!1))},[e.current,t.open,i,n,r]),null}const or={id:`manifest-query-string`,label:`Query string`,render:()=>(0,f.jsx)(ur,{})};function sr(e,t){let n=new URLSearchParams(window.location.search),r=new URLSearchParams(n);t?r.set(e,t):r.delete(e),window.history.replaceState(null,``,`?${r.toString()}`)}function cr(e){sr(`canvas`,e)}function lr(e){sr(`leftPanel`,e)}function ur(){let t=(0,d.useManifest)(),n=(0,i.useInStack)(`Canvas`),{leftPanel:r,rightPanel:o}=(0,a.useLayoutState)(),{edit:s,leftPanel:c,rightPanel:l}=(0,a.useLayoutActions)(),{centerPanels:f,leftPanels:p}=(0,a.useAvailableLayouts)(),{canvasActions:m,open:h}=e.d(),{editorFeatureFlags:{rememberCanvasId:g=!0,rememberLeftPanelId:_=!1}={}}=(0,a.useConfig)(),v=(0,u.useRef)(null),y=(0,u.useRef)(null),b=r.open,[x,S]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{b&&S(!1)},[b]),(0,u.useEffect)(()=>{let t=new URLSearchParams(window.location.search),n=t.get(`canvas`);v.current=n,n&&(h({id:e.u.id}),h({id:`current-canvas`}),m.edit({id:n,type:`Canvas`}));let r=t.get(`leftPanel`);y.current=r,r&&p.some(e=>e.id===r)&&c.open({id:r})},[]),(0,u.useEffect)(()=>{_&&lr(r.current)},[r.current]),(0,u.useEffect)(()=>{let e=n?.resource?.source?.id;e&&(v.current=e),g&&cr(e)},[n?.resource?.source?.id]),(0,u.useEffect)(()=>{if(r.current===e.r.id&&(cr(null),t&&s(t,void 0,{forceOpen:!0,selectedTab:`@manifest-editor/descriptive-properties`}),f.some(t=>t.id===e.p.id)&&h({id:e.p.id})),r.current===jt.id&&h({id:gt.id}),r.current===e.u.id){let e=v.current||t?.items?.[0]?.id;e&&(h({id:`current-canvas`}),m.edit({id:e,type:`Canvas`}))}if(r.current===jt.id){let e=t?.structures?.[0]?.id;e&&t?.structures?.length===1&&s({id:e,type:`Range`})}r.current===jt.id&&o.open&&(l.close(),S(!0));let n=r.current!==jt.id;!o.open&&n&&x&&(l.open(),S(!1))},[r.current]),null}const Z=[{key:`glm-ocr`,label:`GLM OCR (1B)`},{key:`qwen-ocr`,label:`Qwen 3.6 (9B)`},{key:`gemma-ocr-large`,label:`Gemma 4 (31B)`},{key:`qwen-ocr-large`,label:`Qwen 3.6 (35B)`}];function dr(e){return Array.isArray(e)?e.filter(e=>typeof e?.key==`string`&&!!e.key.trim()&&typeof e?.label==`string`&&!!e.label.trim()).map(e=>({key:e.key.trim(),label:e.label.trim()})):[]}function fr(e){let t=dr(e),n=new Set(Z.map(e=>e.key));return[...Z,...t.filter(e=>!n.has(e.key)&&(n.add(e.key),!0))]}var pr=e.m({REMOTE_INFERENCE_ACTION_ID:()=>gr,REMOTE_INFERENCE_IMAGE_SIZES:()=>wr,STRUCTURED_OUTPUT_ACTION_ID:()=>_r,backgroundActions:()=>Oi,default:()=>hr,settings:()=>Dr});const mr=`@manifest-editor/remote-inference`;var hr={id:mr,label:`Remote Inference`,description:`Run remote OCR/HTR inference jobs against a configurable server`,author:`Digirati`,official:!0,defaultEnabled:!1,tags:[`ocr`],supports:{projectTypes:[`Manifest`]}};const gr=`@manifest-editor/remote-inference/action`,_r=`@manifest-editor/remote-inference/structured-output`,vr=`/remote-inference/`,yr=`@manifest-editor/remote-inference/serverUrl`,br=`@manifest-editor/remote-inference/apiKey`,xr=`@manifest-editor/remote-inference/model`,Sr=`@manifest-editor/remote-inference/structuredFields`,Q=`http://localhost:8000`,Cr=`qwen-structure`,wr=[768,1024,1536,2048],Tr=`glm-ocr`;function Er({value:e,onChange:t}){let n=dr(e.models),[r,i]=(0,u.useState)(``),[a,o]=(0,u.useState)(``),s=new Set([...Z,...n].map(e=>e.key)),c=!!r.trim()&&!!a.trim()&&!s.has(r.trim());return(0,f.jsxs)(`div`,{className:`grid gap-3`,children:[(0,f.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] gap-2 text-xs font-medium text-zinc-500`,children:[(0,f.jsx)(`span`,{children:`Key`}),(0,f.jsx)(`span`,{children:`Label`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Actions`})]}),[...Z,...n].map((r,i)=>{let a=i<Z.length;return(0,f.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2`,children:[(0,f.jsx)(`input`,{"aria-label":`${r.label} key`,className:`min-w-0 rounded border border-zinc-200 bg-zinc-50 p-2 text-sm`,value:r.key,readOnly:!0}),(0,f.jsx)(`input`,{"aria-label":`${r.key} label`,className:`min-w-0 rounded border border-zinc-200 bg-zinc-50 p-2 text-sm`,value:r.label,readOnly:!0}),a?(0,f.jsx)(`span`,{className:`w-16 text-center text-xs text-zinc-400`,children:`Built in`}):(0,f.jsx)(`button`,{type:`button`,className:`w-16 text-xs text-red-600 hover:text-red-700`,onClick:()=>t({...e,models:n.filter(e=>e.key!==r.key)}),children:`Remove`})]},`${a?`built-in`:`custom`}-${r.key}`)}),(0,f.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] items-center gap-2 border-t border-zinc-100 pt-3`,children:[(0,f.jsx)(`input`,{"aria-label":`Custom model key`,className:`min-w-0 rounded border border-zinc-300 p-2 text-sm`,value:r,placeholder:`model-key`,onChange:e=>i(e.target.value)}),(0,f.jsx)(`input`,{"aria-label":`Custom model label`,className:`min-w-0 rounded border border-zinc-300 p-2 text-sm`,value:a,placeholder:`Model label`,onChange:e=>o(e.target.value)}),(0,f.jsx)(`button`,{type:`button`,className:`w-16 rounded bg-zinc-100 px-2 py-2 text-xs text-zinc-700 disabled:opacity-40`,disabled:!c,onClick:()=>{t({...e,models:[...n,{key:r.trim(),label:a.trim()}]}),i(``),o(``)},children:`Add`})]}),r.trim()&&s.has(r.trim())?(0,f.jsx)(`span`,{className:`text-xs text-red-600`,children:`Model keys must be unique.`}):null]})}const Dr={defaults:{models:[]},render:e=>(0,f.jsx)(Er,{...e})};function Or(e){return`${e.type}:${e.id}`}function kr(e){let t=e.indexOf(`:`);return t===-1?null:{type:e.slice(0,t),id:e.slice(t+1)}}function Ar(e,t){let n=new Map;n.set(Or(a.FLAG_TAG),{...a.FLAG_TAG,key:Or(a.FLAG_TAG),canvasCount:0,annotatedCanvasCount:0});for(let r of t){if(!r?.id)continue;let t=Hr(e,r);for(let i of e.tags.getTags({id:r.id,type:`Canvas`})){let e=Or(i),r=n.get(e);r?(r.canvasCount+=1,t&&(r.annotatedCanvasCount+=1)):n.set(e,{...i,key:e,canvasCount:1,annotatedCanvasCount:+!!t})}}return Array.from(n.values()).sort((e,t)=>e.type===a.FLAG_TAG.type&&e.id===a.FLAG_TAG.id?-1:t.type===a.FLAG_TAG.type&&t.id===a.FLAG_TAG.id?1:e.label.localeCompare(t.label)||e.type.localeCompare(t.type)||e.id.localeCompare(t.id))}function jr(e){let t={...e};return t.annotations=[],t}function Mr(e=Z){return{serverUrl:typeof localStorage<`u`?localStorage.getItem(yr)??Q:Q,apiKey:typeof localStorage<`u`&&localStorage.getItem(br)||``,model:(typeof localStorage<`u`?Vr(localStorage.getItem(xr),e):null)||Tr,scope:`all`,skipAnnotatedCanvases:!0,resolution:1024}}function Nr(){return typeof localStorage<`u`?localStorage.getItem(yr)??Q:Q}function Pr(){return typeof localStorage<`u`&&localStorage.getItem(br)||``}function $(e=``,t=``){return{id:`${Date.now()}-${Math.random().toString(36).slice(2)}`,label:e,description:t}}function Fr(){if(typeof localStorage>`u`)return[$()];try{let e=localStorage.getItem(Sr),t=e?JSON.parse(e):null;if(!Array.isArray(t))return[$()];let n=t.map(e=>$(typeof e?.label==`string`?e.label:``,typeof e?.description==`string`?e.description:``)).filter(e=>e.label.trim()||e.description.trim());return n.length?n:[$()]}catch{return[$()]}}function Ir(){return{serverUrl:Nr(),apiKey:Pr(),scope:`all`,fields:Fr()}}function Lr(e){return e.map(e=>({label:e.label.trim(),description:e.description.trim()})).filter(e=>e.label&&e.description)}function Rr(e){return Object.fromEntries(Lr(e).map(e=>[e.label,e.description]))}function zr(e){let t=e?.fields;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function Br(e){return(e?.annotations||[]).filter(e=>typeof e?.id==`string`&&e.id.includes(`/annotations/qwen-structure/`))}function Vr(e,t=Z){return t.some(t=>t.key===e)&&e||null}function Hr(e,t){let n=t?.annotations&&e.vault.get(t.annotations)||[];for(let e of n)if(e?.items?.length)return!0;return!1}function Ur(e){return e.endsWith(`/`)?e.slice(0,-1):e}function Wr(e){return!!e&&e.includes(vr)}function Gr(e,t){return t?.startsWith(`${Ur(e)}${vr}`)?/\/remote-inference\/\d+\/annotation$/.test(t):!1}function Kr(e,t){let n=t?.annotations?.[0];return n?e.vault.get(n):null}function qr(e,t,n,r,i){let a=i?`/${i}`:``;return`${Ur(e)}${vr}${t}${a}/${n+1}/${r+1}/annotation`}function Jr(e,t,n,r,i,a){return`${qr(e,t,n,r,a)}/body/${i+1}`}function Yr(e,t){return t?.annotations&&e.vault.get(t.annotations)||[]}function Xr(e,t,n,r,i,a){let o=Array.isArray(e?.body)?e.body:e?.body?[e.body]:[];return!o.length&&typeof e?.bodyValue==`string`&&o.push({type:`TextualBody`,value:e.bodyValue,format:`text/plain`}),o.map((e,o)=>{let s=e?.id&&typeof e.id==`string`?e.id:Jr(t,n,r,i,o,a);return{id:s,entity:{...e,id:s,type:e?.type||`TextualBody`,format:e?.format||`text/plain`,value:e?.value||``},reference:{id:s,type:`ContentResource`}}})}function Zr(e,t,n,r,i={}){let a=e.vault.get({id:t,type:`Canvas`});if(!a?.id)return 0;let o=0,c=Yr(e,a),l=Kr(e,a),u=l?.id||`${Ur(t)}/annotations`,d=(l?.items||[]).filter(e=>Wr(e?.id)||Gr(t,e?.id)),f=[],p=i.mode||`replace`;if(l||(f.push((0,s.importEntities)({entities:{AnnotationPage:{[u]:{id:u,type:`AnnotationPage`,label:{en:[`Inline annotations`]},items:[]}}}})),f.push((0,s.addReference)({id:a.id,type:`Canvas`,key:`annotations`,reference:{id:u,type:`AnnotationPage`}}))),p===`replace`){for(let e of d)f.push((0,s.removeReference)({id:u,type:`AnnotationPage`,key:`items`,reference:{id:e.id,type:`Annotation`}}));for(let e of c){if(e?.id===u)continue;let t=(e?.items||[]).filter(e=>Wr(e?.id));for(let n of t)f.push((0,s.removeReference)({id:e.id,type:`AnnotationPage`,key:`items`,reference:{id:n.id,type:`Annotation`}}))}}let m={},h={},g=[];for(let e=0;e<r.length;e++){let a=r[e];if(a?.items?.length)for(let r=0;r<a.items.length;r++){let s=a.items[r];if(!s)continue;let c=qr(t,n,e,r,i.runId),l=Xr(s,t,n,e,r,i.runId);for(let e of l)h[e.id]=e.entity;m[c]={id:c,type:`Annotation`,motivation:s.motivation||`supplementing`,body:l.map(e=>e.reference),target:s.target||t},g.push(c),o+=1}}if(o){f.push((0,s.importEntities)({entities:{Annotation:m,ContentResource:h}}));for(let e of g)f.push((0,s.addReference)({id:u,type:`AnnotationPage`,key:`items`,reference:{id:e,type:`Annotation`}}))}return f.length&&e.vault.dispatch((0,s.batchActions)({actions:f})),o}const Qr=`@manifest-editor/remote-inference:config`;function $r(e){return new Promise(t=>{if(e.signal?.aborted){t(!1);return}let n=!1,r=r=>{n||(n=!0,e.signal?.removeEventListener(`abort`,i),t(r))},i=()=>r(!1);e.signal?.addEventListener(`abort`,i,{once:!0}),window.dispatchEvent(new CustomEvent(Qr,{detail:{...e,resolve:r}}))})}function ei({actionId:e,models:t}){let[n,r]=(0,u.useState)(null),[i,a]=(0,u.useState)(()=>Mr(t));(0,u.useEffect)(()=>{let n=n=>{let i=n.detail;i?.actionId===e&&(r(i),a(ti(i.defaults,i.tags,t)))};return window.addEventListener(Qr,n),()=>window.removeEventListener(Qr,n)},[e,t]),(0,u.useEffect)(()=>{if(!n?.signal)return;if(n.signal.aborted){r(null);return}let e=()=>r(null);return n.signal.addEventListener(`abort`,e,{once:!0}),()=>n.signal?.removeEventListener(`abort`,e)},[n]);let o=(0,u.useMemo)(()=>n?.tags.find(e=>e.key===i.tagKey),[n?.tags,i.tagKey]),s=i.scope===`selected`?+!!n?.selectedCanvas:i.scope===`tag`?o?.canvasCount||0:n?.totalCanvases||0,c=i.scope===`selected`?+!!n?.selectedCanvas?.annotated:i.scope===`tag`?o?.annotatedCanvasCount||0:n?.annotatedCanvases||0,d=i.skipAnnotatedCanvases===!1?0:c,p=Math.max(0,s-d),m=i.serverUrl.trim(),h=p>0&&!!m&&!!i.model;if(!n)return null;let g=e=>{if(e&&typeof e!=`boolean`)try{localStorage.setItem(yr,e.serverUrl.trim()),localStorage.setItem(br,e.apiKey?.trim()||``),localStorage.setItem(xr,e.model)}catch{}n.resolve(e),r(null)},_=n.tags,v=!_.length,y=!n.selectedCanvas;return(0,f.jsx)(l.Modal,{title:`Run Remote Inference`,onClose:()=>g(!1),className:`max-w-2xl`,actions:(0,f.jsxs)(`div`,{className:`flex gap-2`,children:[(0,f.jsx)(`button`,{type:`button`,className:`rounded border border-zinc-300 bg-white px-3 py-2 text-sm text-zinc-700`,onClick:()=>g(!1),children:`Cancel`}),(0,f.jsx)(`button`,{type:`button`,className:`rounded border border-me-primary-500 bg-me-primary-500 px-3 py-2 text-sm text-white disabled:cursor-not-allowed disabled:opacity-50`,disabled:!h,onClick:()=>g({...i,serverUrl:m,apiKey:i.apiKey?.trim()||``}),children:`Run`})]}),children:(0,f.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-4 p-4 text-sm text-zinc-700`,children:[(0,f.jsxs)(`label`,{className:`grid gap-1`,children:[(0,f.jsx)(`span`,{className:`font-medium text-zinc-900`,children:`Server URL`}),(0,f.jsx)(`input`,{type:`text`,className:`rounded border border-zinc-300 p-2 text-sm`,value:i.serverUrl,placeholder:Q,onChange:e=>a(t=>({...t,serverUrl:e.target.value}))}),(0,f.jsxs)(`span`,{className:`text-xs text-zinc-500`,children:[`POST requests will be sent to `,(0,f.jsxs)(`code`,{children:[i.serverUrl,`/enrich-canvas`]})]})]}),(0,f.jsxs)(`label`,{className:`grid gap-1`,children:[(0,f.jsx)(`span`,{className:`font-medium text-zinc-900`,children:`API key`}),(0,f.jsx)(`input`,{type:`password`,className:`rounded border border-zinc-300 p-2 text-sm`,value:i.apiKey||``,autoComplete:`off`,placeholder:`Optional`,onChange:e=>a(t=>({...t,apiKey:e.target.value}))}),(0,f.jsxs)(`span`,{className:`text-xs text-zinc-500`,children:[`When provided, requests include `,(0,f.jsx)(`code`,{children:`X-API-KEY`}),`.`]})]}),(0,f.jsxs)(`label`,{className:`grid gap-1`,children:[(0,f.jsx)(`span`,{className:`font-medium text-zinc-900`,children:`Model`}),(0,f.jsx)(`select`,{className:`rounded border border-zinc-300 bg-white p-2`,value:i.model,onChange:e=>a(n=>({...n,model:Vr(e.target.value,t)||Tr})),children:t.map(e=>(0,f.jsx)(`option`,{value:e.key,children:e.label},e.key))})]}),(0,f.jsxs)(`label`,{className:`grid gap-1`,children:[(0,f.jsx)(`span`,{className:`font-medium text-zinc-900`,children:`Image size`}),(0,f.jsx)(`select`,{className:`rounded border border-zinc-300 bg-white p-2`,value:i.resolution,onChange:e=>a(t=>({...t,resolution:Number(e.target.value)})),children:wr.map(e=>(0,f.jsxs)(`option`,{value:e,children:[e,`px long edge`]},e))})]}),(0,f.jsxs)(`fieldset`,{className:`grid gap-2`,children:[(0,f.jsx)(`legend`,{className:`font-medium text-zinc-900`,children:`Canvases`}),(0,f.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,f.jsx)(`input`,{type:`radio`,checked:i.scope===`all`,onChange:()=>a(e=>({...e,scope:`all`}))}),(0,f.jsxs)(`span`,{children:[`All canvases (`,n.totalCanvases,`)`]})]}),(0,f.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,f.jsx)(`input`,{type:`radio`,checked:i.scope===`selected`,disabled:y,onChange:()=>a(e=>({...e,scope:`selected`}))}),(0,f.jsxs)(`span`,{children:[`Selected canvas`,n.selectedCanvas?.label?` (${n.selectedCanvas.label})`:``]})]}),(0,f.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,f.jsx)(`input`,{type:`radio`,checked:i.scope===`tag`,disabled:v,onChange:()=>a(e=>({...e,scope:`tag`,tagKey:e.tagKey||_[0]?.key}))}),(0,f.jsx)(`span`,{children:`Only canvases with tag`})]}),(0,f.jsx)(`select`,{className:`rounded border border-zinc-300 bg-white p-2 disabled:bg-zinc-100`,disabled:i.scope!==`tag`||v,value:i.tagKey||``,onChange:e=>a(t=>({...t,tagKey:e.target.value})),children:_.map(e=>(0,f.jsxs)(`option`,{value:e.key,children:[e.label,` (`,e.canvasCount,`)`]},e.key))})]}),(0,f.jsxs)(`label`,{className:`flex items-start gap-2 rounded border border-zinc-200 bg-white p-3`,children:[(0,f.jsx)(`input`,{type:`checkbox`,className:`mt-1`,checked:i.skipAnnotatedCanvases!==!1,onChange:e=>a(t=>({...t,skipAnnotatedCanvases:e.target.checked}))}),(0,f.jsxs)(`span`,{className:`grid gap-1`,children:[(0,f.jsx)(`span`,{className:`font-medium text-zinc-900`,children:`Skip canvases with existing annotations`}),(0,f.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`Do not run inference on canvases where a canvas annotation page already contains an annotation.`})]})]}),(0,f.jsxs)(`div`,{className:`rounded border border-zinc-200 bg-white p-3 text-zinc-600`,children:[p,` canvas`,p===1?``:`es`,` will run remote inference.`,d?(0,f.jsxs)(f.Fragment,{children:[` `,d,` canvas`,d===1?``:`es`,` will be skipped because they already have annotations.`]}):null]})]})})}function ti(e,t,n=Z){let r=t[0]?Or(t[0]):void 0,i=e.tagKey?t.some(t=>t.key===e.tagKey):!1;return{...e,serverUrl:e.serverUrl||Q,apiKey:e.apiKey||``,model:Vr(e.model,n)||Tr,scope:e.scope===`tag`&&t.length?`tag`:e.scope===`selected`?`selected`:`all`,tagKey:i?e.tagKey:r,skipAnnotatedCanvases:e.skipAnnotatedCanvases!==!1}}const ni=`@manifest-editor/remote-inference:structured-config`;function ri(e){return new Promise(t=>{if(e.signal?.aborted){t(!1);return}let n=!1,r=r=>{n||(n=!0,e.signal?.removeEventListener(`abort`,i),t(r))},i=()=>r(!1);e.signal?.addEventListener(`abort`,i,{once:!0}),window.dispatchEvent(new CustomEvent(ni,{detail:{...e,resolve:r}}))})}function ii({actionId:e}){let[t,n]=(0,u.useState)(null),[r,i]=(0,u.useState)(Ir());(0,u.useEffect)(()=>{let t=t=>{let r=t.detail;r?.actionId===e&&(n(r),i(ai(r.defaults,r.tags)))};return window.addEventListener(ni,t),()=>window.removeEventListener(ni,t)},[e]),(0,u.useEffect)(()=>{if(!t?.signal)return;if(t.signal.aborted){n(null);return}let e=()=>n(null);return t.signal.addEventListener(`abort`,e,{once:!0}),()=>t.signal?.removeEventListener(`abort`,e)},[t]);let a=(0,u.useMemo)(()=>t?.tags.find(e=>e.key===r.tagKey),[t?.tags,r.tagKey]),o=r.scope===`selected`?+!!t?.selectedCanvas:r.scope===`tag`?a?.canvasCount||0:t?.totalCanvases||0,s=r.serverUrl.trim(),c=Lr(r.fields),d=o>0&&!!s&&c.length>0;if(!t)return null;let p=t.tags,m=!p.length,h=!t.selectedCanvas,g=(e,t,n)=>{i(r=>({...r,fields:r.fields.map(r=>r.id===e?{...r,[t]:n}:r)}))},_=e=>{if(e&&typeof e!=`boolean`){let t=Lr(e.fields);try{localStorage.setItem(yr,e.serverUrl.trim()),localStorage.setItem(br,e.apiKey?.trim()||``),localStorage.setItem(Sr,JSON.stringify(t))}catch{}}t.resolve(e),n(null)};return(0,f.jsx)(l.Modal,{title:`Run Structured Output`,onClose:()=>_(!1),className:`max-w-2xl`,actions:(0,f.jsxs)(`div`,{className:`flex gap-2`,children:[(0,f.jsx)(`button`,{type:`button`,className:`rounded border border-zinc-300 bg-white px-3 py-2 text-sm text-zinc-700`,onClick:()=>_(!1),children:`Cancel`}),(0,f.jsx)(`button`,{type:`button`,className:`rounded border border-me-primary-500 bg-me-primary-500 px-3 py-2 text-sm text-white disabled:cursor-not-allowed disabled:opacity-50`,disabled:!d,onClick:()=>_({...r,serverUrl:s,apiKey:r.apiKey?.trim()||``,fields:r.fields.map(e=>({...e,label:e.label.trim(),description:e.description.trim()}))}),children:`Run`})]}),children:(0,f.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-4 p-4 text-sm text-zinc-700`,children:[(0,f.jsxs)(`label`,{className:`grid gap-1`,children:[(0,f.jsx)(`span`,{className:`font-medium text-zinc-900`,children:`Server URL`}),(0,f.jsx)(`input`,{type:`text`,className:`rounded border border-zinc-300 p-2 text-sm`,value:r.serverUrl,placeholder:Q,onChange:e=>i(t=>({...t,serverUrl:e.target.value}))}),(0,f.jsxs)(`span`,{className:`text-xs text-zinc-500`,children:[`POST requests will be sent to `,(0,f.jsxs)(`code`,{children:[r.serverUrl,`/enrich-canvas`]})]})]}),(0,f.jsxs)(`label`,{className:`grid gap-1`,children:[(0,f.jsx)(`span`,{className:`font-medium text-zinc-900`,children:`API key`}),(0,f.jsx)(`input`,{type:`password`,className:`rounded border border-zinc-300 p-2 text-sm`,value:r.apiKey||``,autoComplete:`off`,placeholder:`Optional`,onChange:e=>i(t=>({...t,apiKey:e.target.value}))}),(0,f.jsxs)(`span`,{className:`text-xs text-zinc-500`,children:[`When provided, requests include `,(0,f.jsx)(`code`,{children:`X-API-KEY`}),`.`]})]}),(0,f.jsxs)(`fieldset`,{className:`grid gap-2`,children:[(0,f.jsx)(`legend`,{className:`font-medium text-zinc-900`,children:`Canvases`}),(0,f.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,f.jsx)(`input`,{type:`radio`,checked:r.scope===`all`,onChange:()=>i(e=>({...e,scope:`all`}))}),(0,f.jsxs)(`span`,{children:[`All canvases (`,t.totalCanvases,`)`]})]}),(0,f.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,f.jsx)(`input`,{type:`radio`,checked:r.scope===`selected`,disabled:h,onChange:()=>i(e=>({...e,scope:`selected`}))}),(0,f.jsxs)(`span`,{children:[`Selected canvas`,t.selectedCanvas?.label?` (${t.selectedCanvas.label})`:``]})]}),(0,f.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,f.jsx)(`input`,{type:`radio`,checked:r.scope===`tag`,disabled:m,onChange:()=>i(e=>({...e,scope:`tag`,tagKey:e.tagKey||p[0]?.key}))}),(0,f.jsx)(`span`,{children:`Only canvases with tag`})]}),(0,f.jsx)(`select`,{className:`rounded border border-zinc-300 bg-white p-2 disabled:bg-zinc-100`,disabled:r.scope!==`tag`||m,value:r.tagKey||``,onChange:e=>i(t=>({...t,tagKey:e.target.value})),children:p.map(e=>(0,f.jsxs)(`option`,{value:e.key,children:[e.label,` (`,e.canvasCount,`)`]},e.key))})]}),(0,f.jsxs)(`fieldset`,{className:`grid gap-2`,children:[(0,f.jsx)(`legend`,{className:`font-medium text-zinc-900`,children:`Structured fields`}),r.fields.map((e,t)=>(0,f.jsxs)(`div`,{className:`grid gap-2 rounded border border-zinc-200 bg-white p-3`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,f.jsxs)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-zinc-500`,children:[`Field `,t+1]}),(0,f.jsx)(`button`,{type:`button`,className:`text-xs text-zinc-500 disabled:opacity-50`,disabled:r.fields.length===1,onClick:()=>i(t=>({...t,fields:t.fields.filter(t=>t.id!==e.id)})),children:`Remove`})]}),(0,f.jsx)(`input`,{type:`text`,className:`rounded border border-zinc-300 p-2 text-sm`,value:e.label,placeholder:`Label, e.g. Title`,onChange:t=>g(e.id,`label`,t.target.value)}),(0,f.jsx)(`textarea`,{className:`min-h-20 rounded border border-zinc-300 p-2 text-sm`,value:e.description,placeholder:`Description or extraction instructions`,onChange:t=>g(e.id,`description`,t.target.value)})]},e.id)),(0,f.jsx)(`button`,{type:`button`,className:`rounded border border-zinc-300 bg-white px-3 py-2 text-sm text-zinc-700`,onClick:()=>i(e=>({...e,fields:[...e.fields,$()]})),children:`Add field`})]}),(0,f.jsxs)(`div`,{className:`rounded border border-zinc-200 bg-white p-3 text-zinc-600`,children:[o,` canvas`,o===1?``:`es`,` will run structured output. Existing annotations will be kept.`]})]})})}function ai(e,t){let n=t[0]?Or(t[0]):void 0,r=e.tagKey?t.some(t=>t.key===e.tagKey):!1;return{...e,serverUrl:e.serverUrl||Q,apiKey:e.apiKey||``,scope:e.scope===`tag`&&t.length?`tag`:e.scope===`selected`?`selected`:`all`,tagKey:r?e.tagKey:n,fields:e.fields?.length?e.fields:[$()]}}const oi=`@manifest-editor/remote-inference:results`;function si(e,t){window.dispatchEvent(new CustomEvent(oi,{detail:{actionId:e,result:t}}))}function ci({actionId:e}){let[t,n]=(0,u.useState)(null);return(0,u.useEffect)(()=>{let t=t=>{let r=t.detail;r?.actionId===e&&r.result&&n(r.result)};return window.addEventListener(oi,t),()=>window.removeEventListener(oi,t)},[e]),t?(0,f.jsx)(l.Modal,{title:`Remote inference results`,onClose:()=>n(null),className:`max-w-3xl`,children:(0,f.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-4 p-4 text-sm text-zinc-700`,children:[(0,f.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,f.jsx)(li,{label:`Selected`,value:t.selected}),(0,f.jsx)(li,{label:`Processed`,value:t.processed}),(0,f.jsx)(li,{label:`Annotations`,value:t.annotations}),(0,f.jsx)(li,{label:`Skipped`,value:t.skipped})]}),t.canvases.length?(0,f.jsxs)(`div`,{className:`rounded border border-zinc-200`,children:[(0,f.jsx)(`div`,{className:`border-b border-zinc-200 bg-zinc-50 px-3 py-2 font-medium`,children:`Processed canvases`}),(0,f.jsx)(`div`,{className:`max-h-72 overflow-auto`,children:t.canvases.map(e=>(0,f.jsxs)(`div`,{className:`grid gap-2 border-b border-zinc-100 px-3 py-2 last:border-0`,children:[(0,f.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,f.jsx)(`div`,{className:`truncate font-medium text-zinc-900`,children:e.canvasId}),(0,f.jsx)(`div`,{className:`shrink-0 text-xs text-zinc-500`,children:e.model})]}),e.message?(0,f.jsx)(`div`,{className:`text-zinc-500`,children:e.message}):null,e.sourceImage?(0,f.jsx)(`div`,{className:`truncate text-xs text-zinc-500`,children:e.sourceImage}):null,e.palette?.length?(0,f.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.palette.map(e=>(0,f.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-zinc-200 bg-white px-2 py-1 text-xs text-zinc-700`,children:[(0,f.jsx)(`span`,{className:`h-4 w-4 rounded border border-zinc-200`,style:{backgroundColor:e}}),e]},e))}):null,e.fields&&Object.keys(e.fields).length?(0,f.jsx)(`div`,{className:`grid gap-1 rounded border border-zinc-200 bg-white p-2`,children:Object.entries(e.fields).map(([e,t])=>(0,f.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,10rem)_minmax(0,1fr)] gap-2 text-xs`,children:[(0,f.jsx)(`span`,{className:`truncate font-medium text-zinc-700`,children:e}),(0,f.jsx)(`span`,{className:`text-zinc-600`,children:t})]},e))}):null]},`${e.model}:${e.canvasId}`))})]}):null,t.skippedCanvases.length?(0,f.jsxs)(`div`,{className:`rounded border border-zinc-200`,children:[(0,f.jsx)(`div`,{className:`border-b border-zinc-200 bg-zinc-50 px-3 py-2 font-medium`,children:`Skipped canvases`}),(0,f.jsx)(`div`,{className:`max-h-64 overflow-auto`,children:t.skippedCanvases.map(e=>(0,f.jsxs)(`div`,{className:`grid gap-1 border-b border-zinc-100 px-3 py-2 last:border-0`,children:[(0,f.jsx)(`div`,{className:`truncate font-medium text-zinc-900`,children:e.canvasId}),(0,f.jsx)(`div`,{className:`text-zinc-500`,children:e.reason})]},e.canvasId))})]}):null]})}):null}function li({label:e,value:t}){return(0,f.jsxs)(`div`,{className:`rounded border border-zinc-200 bg-zinc-50 p-3`,children:[(0,f.jsx)(`div`,{className:`text-xl font-semibold text-zinc-900`,children:t}),(0,f.jsx)(`div`,{className:`text-xs uppercase tracking-wide text-zinc-500`,children:e})]})}function ui(e){let t=e.vault.get(e.target);return t?.items?(e.vault.get(t.items)||[]).filter(Boolean):[]}function di(e,t,n){if(n.scope===`selected`){let n=e.currentCanvas?.id;return n?t.filter(e=>e?.id===n):[]}if(n.scope!==`tag`||!n.tagKey)return t;let r=kr(n.tagKey);return r?t.filter(t=>e.tags.hasTag({id:t.id,type:`Canvas`},r.type,r.id)):[]}function fi(e,t){let n=e.currentCanvas?.id;if(!n)return;let r=t.find(e=>e?.id===n);if(r)return{id:n,label:pi(r),annotated:Hr(e,r)}}function pi(e){let t=e?.label;if(!t)return e?.id||``;if(typeof t==`string`)return t;let n=Object.keys(t)[0];return(n?t[n]?.[0]:void 0)||e?.id||``}function mi(e,t,n,r){let i=(r?r.vault.get(r.target):null)?.id||``;return{version:1,data:{options:n,total:e},tasks:t.map((e,t)=>{let a=e?.id||`canvas-${t+1}`,o=pi(e)||a,s=n.skipAnnotatedCanvases!==!1&&r&&Hr(r,e)?{canvasId:a,reason:`Canvas already has annotations`}:null;return{id:`canvas:${a}`,label:o,target:{id:a,type:`Canvas`,label:o,scope:`canvas`},input:{canvasId:a,manifestId:i},status:s?`skipped`:`queued`,statusText:s?`Skipped: canvas already has annotations`:void 0,result:s?{type:`skipped`,skip:s}:void 0,completedAt:s?Date.now():void 0}})}}function hi(e,t,n,r){let i=(r?r.vault.get(r.target):null)?.id||``;return{version:1,data:{options:n,total:e},tasks:t.map((e,t)=>{let n=e?.id||`canvas-${t+1}`,r=pi(e)||n;return{id:`canvas:${n}`,label:r,target:{id:n,type:`Canvas`,label:r,scope:`canvas`},input:{canvasId:n,manifestId:i},status:`queued`}})}}function gi(e){return e.data?.options||null}function _i(e){return e.data?.options||null}function vi(e){let t=e.data;return typeof t?.total==`number`?t.total:e.tasks.length}function yi(e,t){return{total:e,selected:t,processed:0,annotations:0,skipped:0,canvases:[],skippedCanvases:[]}}function bi(e,t){let n=yi(e,t.length);for(let e of t){let t=e.result;if(t?.type===`processed`){n.canvases.push(t.canvas);continue}if(t?.type===`skipped`){n.skippedCanvases.push(t.skip);continue}e.status===`error`&&e.error&&n.skippedCanvases.push({canvasId:e.target?.id||e.id,reason:e.error.message})}return n.processed=n.canvases.length,n.annotations=n.canvases.reduce((e,t)=>e+t.annotations,0),n.skipped=n.skippedCanvases.length,n}function xi(e){return e instanceof Error?e.message:`Canvas inference failed`}function Si(e){return`${Ur(e)}/enrich-canvas`}function Ci(e){return typeof e?.error==`string`&&e.error.trim()?e.error:null}function wi(e,t){let n=t?.[e];return typeof n==`string`?n:void 0}function Ti(e){let t={"Content-Type":`application/json`,Accept:`application/json`},n=e.apiKey?.trim();return n&&(t[`X-API-KEY`]=n),t}function Ei(e){if(e.aborted)throw Error(`Remote inference cancelled.`)}function Di({actionId:e}){let t=(0,a.usePluginSettings)(mr),n=(0,u.useMemo)(()=>fr(t.models),[t.models]);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(ei,{actionId:e,models:n}),(0,f.jsx)(ci,{actionId:e})]})}const Oi=[{id:gr,label:`Run remote inference`,summary:`Run remote inference on canvas images via a configurable server`,section:`OCR`,order:21,resourceTypes:[`Manifest`],resumable:!0,render:e=>(0,f.jsx)(Di,{actionId:e.definition.id}),onResults:e=>si(e.definition.id,e.instance?.result),supports:e=>!!e.vault.get(e.target)?.items?.length,prepare:async e=>{let t=ui(e),n=e.prepareData,r=Mr(fr(e.plugins.getSettings(mr).models)),i=n?.scope===`selected`?{...r,scope:`selected`}:r,a=await $r({actionId:e.definition.id,instanceKey:e.instanceKey,totalCanvases:t.length,annotatedCanvases:t.filter(t=>Hr(e,t)).length,selectedCanvas:fi(e,t),tags:Ar(e,t),defaults:i,signal:e.signal});if(a===!1)return!1;let o=di(e,t,a);return mi(t.length,o,a,e)},run:async e=>{let t=e.plan||mi(0,[],Mr()),n=gi(t)||Mr(),r=e.tasks.getAll(),i=e.tasks.getPending(),a=vi(t),o=Si(n.serverUrl.trim()||Q),s=n.model.trim()||Tr;if(e.setActionLabel(`Running remote inference`),!r.length)return e.setActionStatus(`running`,`No canvases selected`),yi(a,0);i.length&&(e.canvasProgress.setStatuses(i.map(e=>e.target).filter(e=>!!e&&e.type===`Canvas`),`queued`),await e.tasks.runEach(async(t,{index:r,total:i})=>{Ei(e.signal);let a=t.input,c=t.target?.id||a.canvasId||t.id,l=a.manifestId||``;e.appendActionLog(`Inference ${r+1}/${i}`,`info`,{canvasId:c,current:r+1,total:i});try{let t=performance.now();e.setActionStatus(`running`,`Sending canvas ${r+1}/${i} to server`);let a=e.vault.toPresentation3({id:c,type:`Canvas`}),u=n.resolution||1024,d={canvas:jr(a),config:{type:s,resolution:u}};a||(d={manifest_url:l,canvas_id:c,config:{type:s,resolution:u}});let f=await fetch(o,{method:`POST`,headers:Ti(n),body:JSON.stringify(d),signal:e.signal});if(!f.ok){let t=await f.text().catch(()=>f.statusText),n={canvasId:c,reason:`Server responded with ${f.status}: ${t}`};return e.appendActionLog(`Skipped canvas`,`warn`,{canvasId:c,reason:n.reason}),{taskStatus:`skipped`,result:{type:`skipped`,skip:n}}}let p=await f.json(),m=Ci(p?.results);if(m){let t={canvasId:c,reason:m};return e.appendActionLog(`Skipped canvas`,`warn`,{canvasId:c,reason:t.reason}),{taskStatus:`skipped`,result:{type:`skipped`,skip:t}}}let h=performance.now()-t;if(s===`palette`){let t=Array.isArray(p?.results?.palette)?p.results.palette:[];return e.appendActionLog(`Read palette`,`info`,{canvasId:c,colours:t.length}),{taskStatus:`complete`,result:{type:`processed`,canvas:{canvasId:c,model:s,annotations:0,durationMs:h,palette:t,sourceImage:p?.results?.source_image,message:t.length?`Found ${t.length} colours`:`No palette colours returned`}}}}let g=p?.canvas?.annotations||[];if(!g.length){let t={canvasId:c,reason:`Server returned no annotation pages for this model.`};return e.appendActionLog(`Skipped canvas`,`warn`,{canvasId:c,reason:t.reason}),{taskStatus:`skipped`,result:{type:`skipped`,skip:t}}}let _=Zr(e,c,s,g);return e.appendActionLog(`Wrote annotations`,`info`,{canvasId:c,annotations:_}),{taskStatus:`complete`,result:{type:`processed`,canvas:{canvasId:c,model:s,annotations:_,durationMs:h,sourceImage:p?.results?.source_image,message:wi(s,p?.results)}}}}catch(t){if(e.signal.aborted)throw t;let n={canvasId:c,reason:xi(t)};return e.appendActionLog(`Skipped canvas`,`warn`,{canvasId:c,reason:n.reason}),{taskStatus:`skipped`,result:{type:`skipped`,skip:n}}}},{progressLabel:(e,t,n)=>`Inference ${t+1}/${n}`}));let c=bi(a,e.tasks.getAll());return e.setActionStatus(`running`,`Processed ${c.processed} canvases and created ${c.annotations} annotations`),e.setActionProgress({current:c.selected,total:c.selected,label:`Inference complete`}),c}},{id:_r,label:`Run structured output`,summary:`Extract configured structured fields from canvas images`,section:`OCR`,order:22,resourceTypes:[`Manifest`],resumable:!0,render:e=>(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(ii,{actionId:e.definition.id}),(0,f.jsx)(ci,{actionId:e.definition.id})]}),onResults:e=>si(e.definition.id,e.instance?.result),supports:e=>!!e.vault.get(e.target)?.items?.length,prepare:async e=>{let t=ui(e),n=e.prepareData,r=Ir(),i=n?.scope===`selected`?{...r,scope:`selected`}:r,a=await ri({actionId:e.definition.id,instanceKey:e.instanceKey,totalCanvases:t.length,selectedCanvas:fi(e,t),tags:Ar(e,t),defaults:i,signal:e.signal});if(a===!1)return!1;let o=di(e,t,a);return hi(t.length,o,a,e)},run:async e=>{let t=e.plan||hi(0,[],Ir()),n=_i(t)||Ir(),r=e.tasks.getAll(),i=e.tasks.getPending(),a=vi(t),o=Si(n.serverUrl.trim()||Q),s=Rr(n.fields);if(e.setActionLabel(`Running structured output`),!r.length)return e.setActionStatus(`running`,`No canvases selected`),yi(a,0);if(!Object.keys(s).length)return e.setActionStatus(`error`,`No structured fields configured`),yi(a,r.length);i.length&&(e.canvasProgress.setStatuses(i.map(e=>e.target).filter(e=>!!e&&e.type===`Canvas`),`queued`),await e.tasks.runEach(async(t,{index:r,total:i})=>{Ei(e.signal);let a=t.input,c=t.target?.id||a.canvasId||t.id,l=a.manifestId||``;e.appendActionLog(`Structured output ${r+1}/${i}`,`info`,{canvasId:c,current:r+1,total:i});try{let t=performance.now();e.setActionStatus(`running`,`Sending canvas ${r+1}/${i} to server`);let a=await fetch(o,{method:`POST`,headers:Ti(n),body:JSON.stringify({manifest_url:l,canvas_id:c,config:{type:Cr,fields:s}}),signal:e.signal});if(!a.ok){let t=await a.text().catch(()=>a.statusText),n={canvasId:c,reason:`Server responded with ${a.status}: ${t}`};return e.appendActionLog(`Skipped canvas`,`warn`,{canvasId:c,reason:n.reason}),{taskStatus:`skipped`,result:{type:`skipped`,skip:n}}}let u=await a.json(),d=Ci(u?.results);if(d){let t={canvasId:c,reason:d};return e.appendActionLog(`Skipped canvas`,`warn`,{canvasId:c,reason:t.reason}),{taskStatus:`skipped`,result:{type:`skipped`,skip:t}}}let f=u?.canvas,p=Br(f);if(!p.length){let t={canvasId:c,reason:`Server returned no structured annotation pages.`};return e.appendActionLog(`Skipped canvas`,`warn`,{canvasId:c,reason:t.reason}),{taskStatus:`skipped`,result:{type:`skipped`,skip:t}}}let m=performance.now()-t,h=`${Date.now()}-${r+1}`,g=Zr(e,c,Cr,p,{mode:`append`,runId:h}),_=zr(u?.results);return e.appendActionLog(`Wrote structured annotations`,`info`,{canvasId:c,annotations:g}),{taskStatus:`complete`,result:{type:`processed`,canvas:{canvasId:c,model:Cr,annotations:g,durationMs:m,fields:_,sourceImage:u?.results?.source_image,message:wi(Cr,u?.results)}}}}catch(t){if(e.signal.aborted)throw t;let n={canvasId:c,reason:xi(t)};return e.appendActionLog(`Skipped canvas`,`warn`,{canvasId:c,reason:n.reason}),{taskStatus:`skipped`,result:{type:`skipped`,skip:n}}}},{progressLabel:(e,t,n)=>`Structured output ${t+1}/${n}`}));let c=bi(a,e.tasks.getAll());return e.setActionStatus(`running`,`Processed ${c.processed} canvases and created ${c.annotations} annotations`),e.setActionProgress({current:c.selected,total:c.selected,label:`Structured output complete`}),c}}];var ki={id:`manifest-editor`,title:`Manifest Editor`,project:!0,projectType:`Manifest`};const Ai=[e.p,{id:`current-canvas`,label:`Current canvas`,icon:(0,f.jsx)(Me,{}),render:(e,{actions:t})=>(0,f.jsx)(i.CanvasPanelEditor,{})},gt],ji=[e.r,e.u,Nt,jt],Mi=[Ct,or],Ni=[T()],Pi=[a.baseEditor],Fi=[a.baseCreator],Ii=i.allEditors,Li=r.allCreators,Ri=[`Manifest`,`Canvas`,`ContentResource`,`Agent`,`AnnotationPage`,`Annotation`,`Range`],zi=[t,Qn,n,pr];Object.defineProperty(exports,"annotationsPlugin",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"avRangesPlugin",{enumerable:!0,get:function(){return Qn}}),exports.background=Mi,exports.backgroundActions=Ni,Object.defineProperty(exports,"canvasLabelGeneratorPlugin",{enumerable:!0,get:function(){return n}}),exports.centerPanels=Ai,exports.creators=Li,exports.default=ki,exports.editors=Ii,exports.leftPanels=ji,exports.modals=Fi,exports.plugins=zi,exports.resources=Ri,exports.rightPanels=Pi;
|
|
56
|
+
//# sourceMappingURL=index.cjs.map
|