@manifest-editor/creators 2.2.2-next.0.4041094 → 2.2.2-next.0.a82700e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));const l=require("./iiif-browser-output-IFaBMvwa.cjs");let u=require("@manifest-editor/creator-api"),d=require("@iiif/helpers"),f=require("@manifest-editor/components"),p=require("@manifest-editor/editors"),m=require("react");m=c(m,1);let h=require("react/jsx-runtime"),g=require("iiif-browser/digital-collections"),_=require("react-iiif-vault"),v=require("styled-components");v=c(v,1);let y=require("@manifest-editor/shell"),b=require("@iiif/parser/image-3"),ee=require("@manifest-editor/editor-api"),te=require("react-error-boundary"),ne=require("iiif-browser");async function re(e,t){let n={id:e.url||t.generateId(`provider`),label:e.label,type:`Agent`,homepage:[],logo:[]};return e.homepage&&(n.homepage=[t.embed({id:e.url,label:(0,d.getValue)(e.homepageLabel)?e.homepageLabel:{en:[`Homepage`]},type:`Text`,format:`text/html`,language:[`en`]})]),e.logo&&(n.logo=[t.embed({id:e.logo,type:`Image`})]),t.embed(n)}function ie(e){let t=e.options.initialData,[n,r]=(0,m.useState)(t.url||``),[i,a]=(0,m.useState)(t.label||{en:[``]}),[o,s]=(0,m.useState)(t.homepage||``),[c,l]=(0,m.useState)(t.logo||``),[u,d]=(0,m.useState)(t.homepageLabel||{en:[``]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`div`,{className:`max-w-xl`,children:[(0,h.jsx)(p.LanguageFieldEditor,{containerId:`label`,focusId:`label_`,label:`Label`,fields:i,onSave:e=>a(e.toInternationalString())}),(0,h.jsxs)(p.InputContainer,{$fluid:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`provider-logo`,children:`Logo`}),(0,h.jsx)(p.Input,{placeholder:`https://example.org/logo.png`,type:`text`,id:`provider-logo`,value:c,onChange:e=>l(e.target.value)})]}),(0,h.jsxs)(p.InputContainer,{$fluid:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`provider-homepage`,children:`Homepage`}),(0,h.jsx)(p.Input,{placeholder:`https://example.org/homepage`,type:`text`,id:`provider-homepage`,value:o,onChange:e=>s(e.target.value)})]}),o?(0,h.jsx)(`div`,{children:(0,h.jsx)(p.LanguageFieldEditor,{containerId:`homepageLabel`,focusId:`homepageLabel_`,label:`Homepage label`,fields:u,onSave:e=>d(e.toInternationalString())})}):null,(0,h.jsxs)(p.InputContainer,{$fluid:!0,children:[(0,h.jsx)(p.InputLabel,{$margin:!1,htmlFor:`provider-url`,children:`Provider ID`}),(0,h.jsx)(`span`,{className:`text-gray-500 text-sm mb-2`,children:`Will be generated if not specified, this is not a URL that the user can follow`}),(0,h.jsx)(p.Input,{placeholder:`https://id.loc.gov/authorities/abc123`,type:`text`,id:`provider-url`,value:n,onChange:e=>r(e.target.value)})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`button`,onPress:()=>{e.runCreate({url:n,label:i,homepage:o,homepageLabel:u,logo:c})},children:`Add provider`})]})})}const ae=(0,u.defineCreator)({id:`@manifest-editor/provider`,label:`Provider`,summary:`Create a new provider`,resourceType:`Agent`,resourceFields:[`id`,`type`,`label`],supports:{parentTypes:[`Manifest`,`Collection`],parentFields:[`provider`],initialData:!0},create:re,render(e){return(0,h.jsx)(ie,{...e})}});function x(e){try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}}async function S(e,t){if(!x(e))return null;try{return await t.json(e)}catch{return null}}function C(e){let t=e?.type||e?.[`@type`];return t===`sc:Manifest`?`Manifest`:t===`sc:Collection`?`Collection`:t}function oe(e){let t=C(e);return e?.protocol===`http://iiif.io/api/image`||t===`ImageService`||typeof t==`string`&&t.startsWith(`ImageService`)}async function se(e){return x(e)&&await(0,g.isSupportedDigitalCollectionPage)(e)}async function w(e,t){try{return await t.contentType(e)}catch{return``}}function T(e,t){let n=new URL(e).pathname.toLowerCase();return t.some(e=>n.endsWith(e))}const ce=e=>(0,h.jsxs)(`svg`,{...e,viewBox:`4 4 16 16`,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,children:[e.title?(0,h.jsx)(`title`,{children:e.title}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{d:`M8 5v14l11-7z`,fill:`currentColor`})]}),le=e=>(0,h.jsxs)(`svg`,{...e,viewBox:`4 4 16 16`,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,children:[e.title?(0,h.jsx)(`title`,{children:e.title}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{fill:`currentColor`,d:`M6 19h4V5H6v14zm8-14v14h4V5h-4z`})]}),ue=({title:e,...t})=>(0,h.jsxs)(`svg`,{...t,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,viewBox:`2 2 20 20`,children:[e?(0,h.jsx)(`title`,{children:e}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{fill:`currentColor`,d:`M3 9v6h4l5 5V4L7 9H3zm13.5 3A4.5 4.5 0 0 0 14 7.97v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z`})]}),de=({title:e,...t})=>(0,h.jsxs)(`svg`,{...t,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,viewBox:`2 2 20 20`,children:[e?(0,h.jsx)(`title`,{children:e}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{fill:`currentColor`,d:`M18.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM5 9v6h4l5 5V4L9 9H5z`})]}),fe=({title:e,...t})=>(0,h.jsxs)(`svg`,{...t,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,viewBox:`2 2 20 20`,children:[e?(0,h.jsx)(`title`,{children:e}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{fill:`currentColor`,d:`M16.5 12A4.5 4.5 0 0 0 14 7.97v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51A8.796 8.796 0 0 0 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3 3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06a8.99 8.99 0 0 0 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4 9.91 6.09 12 8.18V4z`})]}),pe=v.default.div`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));const l=require("./iiif-browser-output-IFaBMvwa.cjs");let u=require("@manifest-editor/creator-api"),d=require("@iiif/helpers"),f=require("@manifest-editor/components"),p=require("@manifest-editor/editors"),m=require("react");m=c(m,1);let h=require("react/jsx-runtime"),g=require("iiif-browser/digital-collections"),_=require("react-iiif-vault"),v=require("styled-components");v=c(v,1);let y=require("@manifest-editor/shell"),b=require("@iiif/parser/image-3"),x=require("@manifest-editor/editor-api"),ee=require("react-error-boundary"),te=require("iiif-browser");async function ne(e,t){let n={id:e.url||t.generateId(`provider`),label:e.label,type:`Agent`,homepage:[],logo:[]};return e.homepage&&(n.homepage=[t.embed({id:e.url,label:(0,d.getValue)(e.homepageLabel)?e.homepageLabel:{en:[`Homepage`]},type:`Text`,format:`text/html`,language:[`en`]})]),e.logo&&(n.logo=[t.embed({id:e.logo,type:`Image`})]),t.embed(n)}function re(e){let t=e.options.initialData,[n,r]=(0,m.useState)(t.url||``),[i,a]=(0,m.useState)(t.label||{en:[``]}),[o,s]=(0,m.useState)(t.homepage||``),[c,l]=(0,m.useState)(t.logo||``),[u,d]=(0,m.useState)(t.homepageLabel||{en:[``]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`div`,{className:`max-w-xl`,children:[(0,h.jsx)(p.LanguageFieldEditor,{containerId:`label`,focusId:`label_`,label:`Label`,fields:i,onSave:e=>a(e.toInternationalString())}),(0,h.jsxs)(p.InputContainer,{$fluid:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`provider-logo`,children:`Logo`}),(0,h.jsx)(p.Input,{placeholder:`https://example.org/logo.png`,type:`text`,id:`provider-logo`,value:c,onChange:e=>l(e.target.value)})]}),(0,h.jsxs)(p.InputContainer,{$fluid:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`provider-homepage`,children:`Homepage`}),(0,h.jsx)(p.Input,{placeholder:`https://example.org/homepage`,type:`text`,id:`provider-homepage`,value:o,onChange:e=>s(e.target.value)})]}),o?(0,h.jsx)(`div`,{children:(0,h.jsx)(p.LanguageFieldEditor,{containerId:`homepageLabel`,focusId:`homepageLabel_`,label:`Homepage label`,fields:u,onSave:e=>d(e.toInternationalString())})}):null,(0,h.jsxs)(p.InputContainer,{$fluid:!0,children:[(0,h.jsx)(p.InputLabel,{$margin:!1,htmlFor:`provider-url`,children:`Provider ID`}),(0,h.jsx)(`span`,{className:`text-gray-500 text-sm mb-2`,children:`Will be generated if not specified, this is not a URL that the user can follow`}),(0,h.jsx)(p.Input,{placeholder:`https://id.loc.gov/authorities/abc123`,type:`text`,id:`provider-url`,value:n,onChange:e=>r(e.target.value)})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`button`,onPress:()=>{e.runCreate({url:n,label:i,homepage:o,homepageLabel:u,logo:c})},children:`Add provider`})]})})}const ie=(0,u.defineCreator)({id:`@manifest-editor/provider`,label:`Provider`,summary:`Create a new provider`,resourceType:`Agent`,resourceFields:[`id`,`type`,`label`],supports:{parentTypes:[`Manifest`,`Collection`],parentFields:[`provider`],initialData:!0},create:ne,render(e){return(0,h.jsx)(re,{...e})}});function S(e){try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}}async function C(e,t){if(!S(e))return null;try{return await t.json(e)}catch{return null}}function w(e){let t=e?.type||e?.[`@type`];return t===`sc:Manifest`?`Manifest`:t===`sc:Collection`?`Collection`:t}function ae(e){let t=w(e);return e?.protocol===`http://iiif.io/api/image`||t===`ImageService`||typeof t==`string`&&t.startsWith(`ImageService`)}async function oe(e){return S(e)&&await(0,g.isSupportedDigitalCollectionPage)(e)}async function T(e,t){try{return await t.contentType(e)}catch{return``}}function E(e,t){let n=new URL(e).pathname.toLowerCase();return t.some(e=>n.endsWith(e))}const se=e=>(0,h.jsxs)(`svg`,{...e,viewBox:`4 4 16 16`,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,children:[e.title?(0,h.jsx)(`title`,{children:e.title}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{d:`M8 5v14l11-7z`,fill:`currentColor`})]}),ce=e=>(0,h.jsxs)(`svg`,{...e,viewBox:`4 4 16 16`,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,children:[e.title?(0,h.jsx)(`title`,{children:e.title}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{fill:`currentColor`,d:`M6 19h4V5H6v14zm8-14v14h4V5h-4z`})]}),le=({title:e,...t})=>(0,h.jsxs)(`svg`,{...t,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,viewBox:`2 2 20 20`,children:[e?(0,h.jsx)(`title`,{children:e}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{fill:`currentColor`,d:`M3 9v6h4l5 5V4L7 9H3zm13.5 3A4.5 4.5 0 0 0 14 7.97v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z`})]}),ue=({title:e,...t})=>(0,h.jsxs)(`svg`,{...t,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,viewBox:`2 2 20 20`,children:[e?(0,h.jsx)(`title`,{children:e}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{fill:`currentColor`,d:`M18.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM5 9v6h4l5 5V4L9 9H5z`})]}),de=({title:e,...t})=>(0,h.jsxs)(`svg`,{...t,xmlns:`http://www.w3.org/2000/svg`,height:`1em`,width:`1em`,viewBox:`2 2 20 20`,children:[e?(0,h.jsx)(`title`,{children:e}):null,(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{fill:`currentColor`,d:`M16.5 12A4.5 4.5 0 0 0 14 7.97v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51A8.796 8.796 0 0 0 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3 3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06a8.99 8.99 0 0 0 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4 9.91 6.09 12 8.18V4z`})]}),fe=v.default.div`
2
2
  background: #ededed; // Not in variable.
3
3
  display: flex;
4
4
  padding: 0.5em;
5
5
  align-items: center;
6
- `,me=v.default.button`
6
+ `,pe=v.default.button`
7
7
  cursor: pointer;
8
8
  padding: 0.75em 1.5em;
9
9
  font-size: 0.938em;
@@ -14,7 +14,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
14
14
  display: inline-block;
15
15
  vertical-align: top;
16
16
  white-space: nowrap;
17
- `,he=(0,v.default)(me)`
17
+ `,me=(0,v.default)(pe)`
18
18
  width: 2em;
19
19
  height: 2em;
20
20
  overflow: hidden;
@@ -28,17 +28,17 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
28
28
  &:disabled {
29
29
  color: #999;
30
30
  }
31
- `,ge=v.default.div`
31
+ `,he=v.default.div`
32
32
  margin: 0 1em;
33
33
  font-size: 0.85em;
34
34
  color: #000;
35
- `,_e=v.default.div`
35
+ `,ge=v.default.div`
36
36
  flex: 1 1 0px;
37
37
  height: 6px;
38
38
  display: flex;
39
39
  position: relative;
40
40
  padding: 15px 0;
41
- `,ve=v.default.div`
41
+ `,_e=v.default.div`
42
42
  background: #d85680;
43
43
  height: 6px;
44
44
  pointer-events: none;
@@ -47,7 +47,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
47
47
  left: 0;
48
48
  border-radius: 3px;
49
49
  transition: width 200ms;
50
- `,ye=v.default.div`
50
+ `,ve=v.default.div`
51
51
  position: absolute;
52
52
  top: 13px;
53
53
  left: 0;
@@ -56,7 +56,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
56
56
  width: 100%;
57
57
  pointer-events: none;
58
58
  background: #fff;
59
- `,be=(0,v.default)(me)`
59
+ `,ye=(0,v.default)(pe)`
60
60
  width: 2em;
61
61
  height: 2em;
62
62
  overflow: hidden;
@@ -65,10 +65,10 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
65
65
  border-radius: 3px;
66
66
  padding: 0;
67
67
  margin: 0;
68
- `,xe=v.default.div`
68
+ `,be=v.default.div`
69
69
  display: flex;
70
70
  align-items: center;
71
- `,Se=v.default.div`
71
+ `,xe=v.default.div`
72
72
  width: 0;
73
73
  overflow: hidden;
74
74
  transition: width 500ms;
@@ -77,10 +77,10 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
77
77
  ${e=>e.$isOpen&&v.css`
78
78
  width: 150px;
79
79
  `}
80
- `,Ce=v.default.input.attrs({type:`range`})`
80
+ `,Se=v.default.input.attrs({type:`range`})`
81
81
  width: 120px;
82
82
  margin: 0 15px;
83
- `;function we(e){return(0,h.jsx)(`svg`,{width:`1em`,height:`1em`,viewBox:`0 0 42 42`,xmlns:`http://www.w3.org/2000/svg`,stroke:`currentColor`,...e,children:(0,h.jsxs)(`g`,{transform:`translate(2 2)`,strokeWidth:5,fill:`none`,fillRule:`evenodd`,children:[(0,h.jsx)(`circle`,{strokeOpacity:.5,cx:18,cy:18,r:18}),(0,h.jsx)(`path`,{d:`M36 18c0-9.94-8.06-18-18-18`,children:(0,h.jsx)(`animateTransform`,{attributeName:`transform`,type:`rotate`,from:`0 18 18`,to:`360 18 18`,dur:`1s`,repeatCount:`indefinite`})})]})})}const Te=v.css`
83
+ `;function Ce(e){return(0,h.jsx)(`svg`,{width:`1em`,height:`1em`,viewBox:`0 0 42 42`,xmlns:`http://www.w3.org/2000/svg`,stroke:`currentColor`,...e,children:(0,h.jsxs)(`g`,{transform:`translate(2 2)`,strokeWidth:5,fill:`none`,fillRule:`evenodd`,children:[(0,h.jsx)(`circle`,{strokeOpacity:.5,cx:18,cy:18,r:18}),(0,h.jsx)(`path`,{d:`M36 18c0-9.94-8.06-18-18-18`,children:(0,h.jsx)(`animateTransform`,{attributeName:`transform`,type:`rotate`,from:`0 18 18`,to:`360 18 18`,dur:`1s`,repeatCount:`indefinite`})})]})})}const we=v.css`
84
84
  clip: rect(1px, 1px, 1px, 1px);
85
85
  clip-path: inset(50%);
86
86
  height: 1px;
@@ -89,10 +89,11 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
89
89
  overflow: hidden;
90
90
  padding: 0;
91
91
  position: absolute;
92
- `,Ee=v.default.label`
93
- ${Te}
94
- `;function E(e){let[t,n]=(0,m.useState)(!1),{progress:r,currentTime:i,element:a}=(0,_.useMediaElements)(),{duration:o,isMuted:s,volume:c,isPlaying:l,playRequested:u}=(0,_.useMediaState)(),{setVolume:d,toggleMute:f,play:p,pause:g,setDurationPercent:v}=(0,_.useMediaActions)(),y=s||c===0?fe:c>50?ue:de;return(0,m.useLayoutEffect)(()=>{if(a.current){let t=a.current;if(t.error&&e.onError){e.onError(t.error?.message||`Unknown error`);return}let n=()=>{e.onError&&e.onError(t.error?.message||`Unknown error`)},r=()=>{t.duration&&e.onDuration&&e.onDuration(t.duration),e.onDimensions&&t instanceof HTMLVideoElement&&e.onDimensions(t.videoWidth,t.videoHeight)};return t.addEventListener(`loadedmetadata`,r),t.addEventListener(`error`,n),()=>{t.removeEventListener(`loadedmetadata`,r),t.removeEventListener(`error`,n)}}},[]),(0,h.jsxs)(pe,{children:[(0,h.jsx)(he,{disabled:u,onClick:()=>{l?g():p()},children:u?(0,h.jsx)(we,{stroke:`#999`}):l?(0,h.jsx)(le,{title:`Pause`}):(0,h.jsx)(ce,{title:`Play`})}),(0,h.jsx)(ge,{ref:i,children:`0:00`}),(0,h.jsxs)(_e,{onClick:e=>{let{left:t,width:n}=e.currentTarget.getBoundingClientRect(),r=(e.pageX-t)/n;v(r)},children:[(0,h.jsx)(ye,{}),o?(0,h.jsx)(ve,{ref:r}):null]}),(0,h.jsx)(ge,{children:(0,_.formatTime)(o)}),(0,h.jsxs)(xe,{onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),children:[(0,h.jsx)(Se,{$isOpen:t,children:(0,h.jsxs)(`span`,{children:[(0,h.jsx)(Ee,{htmlFor:`audio-slider`,children:`Change volume`}),(0,h.jsx)(Ce,{id:`audio-slider`,role:`slider`,disabled:s,min:`0`,max:`100`,value:c,onChange:e=>d(Number(e.currentTarget.value))})]})}),(0,h.jsx)(be,{onClick:()=>f(),children:(0,h.jsx)(y,{title:s?`Mute`:`Unmute`})})]})]})}async function D(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=t.embed({id:e.url,type:`Sound`,format:`audio/mp4`,duration:e.duration||0});if(r===`Annotation`)return t.embed({...n,label:(0,d.getValue)(e.label)&&e.label,motivation:e.motivation||t.options.initialData?.motivation||`painting`,body:i,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),a=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:i,target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:a,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled HTML canvas`]},duration:e.duration||0,items:[s]})}}function O(e){let t=e.options.initialData,[n,r]=(0,m.useState)(t.url||``),[i,a]=(0,m.useState)(0),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)({en:[``]});return(0,m.useEffect)(()=>{if(s(``),a(0),n){let e=n.split(`/`).pop()?.split(`.`).shift();l({en:[e||``]})}},[n]),(0,h.jsxs)(f.PaddedSidebarContainer,{children:[o?(0,h.jsx)(f.ErrorMessage,{children:o}):null,(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`audio-url`,children:`URL`}),(0,h.jsx)(p.Input,{type:`text`,id:`audio-url`,value:n,onChange:e=>r(e.target.value)})]}),n&&!o?(0,h.jsx)(`div`,{children:(0,h.jsx)(p.LanguageFieldEditor,{containerId:`label`,focusId:`label_`,label:`Label`,fields:c,onSave:e=>l(e.toInternationalString())},`${n}__${i}`)}):null,n&&!o?(0,h.jsx)(_.CanvasPanel.AudioHTML,{media:{url:n,duration:i,type:`Sound`},children:(0,h.jsx)(E,{onError:e=>s(e),onDuration:e=>a(~~e)},`${n}__${i}`)},`${n}__${i}`):null,i&&!o?(0,h.jsxs)(p.FormFieldWrapper,{children:[(0,h.jsx)(p.InputLabel,{htmlFor:`duration`,children:`Duration`}),(0,h.jsx)(p.Input,{type:`number`,id:`duration`,value:i,onChange:e=>a(e.target.valueAsNumber)})]}):null,(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`button`,onPress:()=>{e.runCreate({url:n,duration:i,label:c})},isDisabled:!n||!!o,children:`Add audio`})]})}const De=(0,u.defineCreator)({id:`@manifest-editor/audio-annotation`,create:D,label:`Audio`,summary:`Audio annotation`,icon:(0,h.jsx)(f.AudioIcon,{}),render(e){return(0,h.jsx)(O,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],async supportsResource(e,t){return x(e)&&((await w(e,t)).startsWith(`audio/`)||T(e,[`.mp3`,`.m4a`,`.wav`,`.ogg`]))?{initialData:{url:e}}:!1},supports:{initialData:!0,onlyPainting:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},staticFields:{type:`Annotation`}});async function Oe(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=Object.keys(e.body),a=[];for(let r of i){let i=e.body[r].join(`
95
- `);i&&a.push(await t.create(`@manifest-editor/html-body-creator`,{language:r,body:i},{parent:{resource:n,property:`items`}}))}let o=await t.create(`@manifest-editor/image-url-creator`,{url:e.imageUrl},{parent:{resource:n,property:`body`}});if(o&&a.push(o),r===`Annotation`)return t.embed({...n,motivation:e.motivation||t.options.initialData?.motivation||`painting`,body:a,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),i=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:a,target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:i,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled HTML canvas`]},height:e.height||1e3,width:e.width||1e3,items:[s]})}}function ke(e){let[t,n]=(0,y.useAnnotationCreatorState)({key:`bodyValue`,initialValue:{en:[``]},requestId:e.options.initialData?.requestId});return(0,h.jsx)(`form`,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries());e.runCreate({body:{en:[r.caption]},imageUrl:r.url})},children:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`url`,children:`URL to Image`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:``,placeholder:`https://example.org/image.jpg`})]}),(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`caption`,children:`Caption`}),(0,h.jsx)(p.Input,{id:`caption`,name:`caption`,placeholder:`Enter a caption`,onChange:e=>n({en:[e.target.value]}),value:t.en?.[0]||``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,type:`submit`,children:`Create`})]})})}const Ae=(0,u.defineCreator)({id:`@manifest-editor/captioned-image-annotation`,create:Oe,label:`Captioned image`,summary:`Add an image from a URL with caption`,icon:(0,h.jsx)(f.AddImageIcon,{}),render(e){return(0,h.jsx)(ke,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supports:{initialData:!0,disallowPainting:!0,parentTypes:[`AnnotationPage`],parentFields:[`items`]},staticFields:{type:`Annotation`}});async function je(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=Object.keys(e.body),a=[];for(let r of i){let i=e.body[r].join(`
96
- `);i&&a.push(await t.create(`@manifest-editor/html-body-creator`,{language:r,body:i},{parent:{resource:n,property:`items`}}))}if(r===`Annotation`)return t.embed({...n,motivation:e.motivation||t.options.initialData?.motivation||`painting`,body:a,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),i=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:a,target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:i,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled HTML canvas`]},height:e.height||1e3,width:e.width||1e3,items:[s]})}}function Me(e){let[t,n]=(0,y.useAnnotationCreatorState)({key:`bodyValue`,initialValue:{en:[``]},requestId:e.options.initialData?.requestId}),r=(0,d.getValue)(t).trim()===``;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(f.HTMLEditor,{className:`border-none`,value:t.en?.[0]||``,onChange:e=>n({en:[e]})}),(0,h.jsx)(f.ActionButton,{primary:!0,type:`button`,onPress:()=>{e.runCreate({body:t})},isDisabled:r,children:`Create`})]})}const Ne=(0,u.defineCreator)({id:`@manifest-editor/html-annotation`,create:je,label:`HTML`,summary:`HTML annotation`,icon:(0,h.jsx)(f.HTMLIcon,{}),render(e){return(0,h.jsx)(Me,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supports:{initialData:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},staticFields:{type:`Annotation`}}),k={canvasInteraction:!0,spatial:!0,async run(e,{vault:t,options:n}){if(e&&e.type===`Annotation`&&n.targetType===`Annotation`){let n=t.get(e),r=n.target;if(!(r&&r.source?.type===`Canvas`))return;let i=r.source,a=t.get(i);if(!a.items)return;let o=t.get(a.items[0]);if(!o||o.items.length<2&&!a.behavior.includes(`multi-image`))return;let s=t.get(n.body)[0],c=n.body[0]?.selector,l=(s.service||[]).find(e=>(0,b.isImageService)(e));l&&l.width&&l.height&&(l.width!==s.width&&t.modifyEntityField({id:s.id,type:`ContentResource`},`width`,l.width),l.height!==s.height&&t.modifyEntityField({id:s.id,type:`ContentResource`},`height`,l.height));let u=l?.width||s.width,d=l?.height||s.height;if(c&&(c.type===`iiif:ImageApiSelector`||c.type===`ImageApiSelector`)&&c.region){let[e,t,n,r]=c.region.split(`,`);u=Number(n)||u,d=Number(r)||d}let f=new ee.EditorInstance({vault:t,reference:e}),m=(0,p.centerRectangles)(a,{width:u,height:d},.6);f.annotation.target.setPosition(m)}}},A={canvasInteraction:!0,spatial:!0,async run(e,{vault:t,options:n}){if(e&&e.type===`Annotation`&&n.targetType===`Annotation`){let n=t.get(e),r=n.target;if(!(r&&r.source?.type===`Canvas`))return;let i=r.source,a=t.get(i);if(!a.items||a.behavior.includes(`multi-image`))return;let o=t.get(a.items[0]);if(!o||o.items.length>1)return;let s=t.get(n.body);if(s.length!==1)return;let c=s[0],l=n.body[0]?.selector,u=(c.service||[])[0],d=u?.width||c.width,f=u?.height||c.height,p=c.duration||u?.duration;if(l&&(l.type===`iiif:ImageApiSelector`||l.type===`ImageApiSelector`)&&l.region){let[e,t,n,r]=l.region.split(`,`);d=Number(n)||d,f=Number(r)||f}let m=new ee.EditorInstance({vault:t,reference:i});t.batch(()=>{d!==void 0&&m.technical.width.set(d),f!==void 0&&m.technical.height.set(f),p!==void 0&&m.technical.duration.set(p)})}}};var Pe=Object.defineProperty,Fe=(e,t,n)=>t in e?Pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,j=(e,t,n)=>(Fe(e,typeof t==`symbol`?t:t+``,n),n);function M(e){return e.endsWith(`info.json`)?e:e.endsWith(`/`)?`${e}info.json`:`${e}/info.json`}var Ie=`http://library.stanford.edu/iiif/image-api/compliance.html#level0`,Le=`http://library.stanford.edu/iiif/image-api/compliance.html#level1`,Re=`http://library.stanford.edu/iiif/image-api/compliance.html#level2`,ze=`http://library.stanford.edu/iiif/image-api/conformance.html#level0`,Be=`http://library.stanford.edu/iiif/image-api/conformance.html#level1`,Ve=`http://library.stanford.edu/iiif/image-api/conformance.html#level2`,He=`http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0`,Ue=`http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1`,We=`http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2`,Ge=`http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0`,Ke=`http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1`,qe=`http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2`,Je=`http://iiif.io/api/image/1/level0.json`,Ye=`http://iiif.io/api/image/1/profiles/level0.json`,Xe=`http://iiif.io/api/image/1/level1.json`,Ze=`http://iiif.io/api/image/1/profiles/level1.json`,Qe=`http://iiif.io/api/image/1/level2.json`,$e=`http://iiif.io/api/image/1/profiles/level2.json`,et=`http://iiif.io/api/image/2/level0.json`,tt=`http://iiif.io/api/image/2/profiles/level0.json`,nt=`http://iiif.io/api/image/2/level1.json`,rt=`http://iiif.io/api/image/2/profiles/level1.json`,it=`http://iiif.io/api/image/2/level2.json`,at=`http://iiif.io/api/image/2/profiles/level2.json`,ot=`level0`,st=`level1`,ct=`level2`,lt=`http://iiif.io/api/image/2/level0`,ut=`http://iiif.io/api/image/2/level1`,dt=`http://iiif.io/api/image/2/level2`,ft=[dt,Re,Ve,We,qe,Qe,$e,it,at,ct],pt=[...ft,ut,Le,Be,Ue,Ke,Xe,Ze,nt,rt,st],mt=[lt,ut,dt,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge,Ke,qe,Je,Ye,Xe,Ze,Qe,$e,et,tt,nt,rt,it,at,ot,st,ct],ht={extraFormats:[`jpg`],extraQualities:[`default`],extraFeatures:[`sizeByWhListed`]},gt={extraFormats:[`jpg`],extraQualities:[`default`],extraFeatures:[`baseUriRedirect`,`cors`,`jsonldMediaType`,`regionByPx`,`regionSquare`,`sizeByWhListed`,`sizeByH`,`sizeByW`,`sizeByWh`]},_t={extraFormats:[`jpg`,`png`],extraQualities:[`default`],extraFeatures:[`baseUriRedirect`,`cors`,`jsonldMediaType`,`regionByPct`,`regionByPx`,`regionSquare`,`rotationBy90s`,`sizeByWhListed`,`sizeByConfinedWh`,`sizeByH`,`sizeByPct`,`sizeByW`,`sizeByWh`]};function vt(e){return ft.indexOf(e)===-1?pt.indexOf(e)===-1?ht:gt:_t}function yt(e){let t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],n={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let e of t)if(typeof e==`string`&&(e=vt(e)),e){if(e.formats)for(let t of e.formats)n.extraFormats.indexOf(t)===-1&&n.extraFormats.push(t);if(e.qualities)for(let t of e.qualities)n.extraQualities.indexOf(t)===-1&&n.extraQualities.push(t);if(e.supports)for(let t of e.supports)n.extraFeatures.indexOf(t)===-1&&n.extraFeatures.push(t);if(e.maxHeight&&(n.maxHeight=e.maxHeight),e.maxWidth&&(n.maxWidth=e.maxWidth),e.maxArea&&(n.maxArea=e.maxArea),e.extraFormats)for(let t of e.extraFormats)n.extraFormats.indexOf(t)===-1&&n.extraFormats.push(t);if(e.extraQualities)for(let t of e.extraQualities)n.extraQualities.indexOf(t)===-1&&n.extraQualities.push(t);if(e.extraFeatures)for(let t of e.extraFeatures)n.extraFeatures.indexOf(t)===-1&&n.extraFeatures.push(t);e.maxHeight&&(n.maxHeight=e.maxHeight),e.maxWidth&&(n.maxWidth=e.maxWidth),e.maxArea&&(n.maxArea=e.maxArea)}if(e.extraFormats)for(let t of e.extraFormats)n.extraFormats.indexOf(t)===-1&&n.extraFormats.push(t);if(e.extraFeatures)for(let t of e.extraFeatures)n.extraFeatures.indexOf(t)===-1&&n.extraFeatures.push(t);if(e.extraQualities)for(let t of e.extraQualities)n.extraQualities.indexOf(t)===-1&&n.extraQualities.push(t);return n}function bt(e){try{if(e===`full`)return{full:!0};if(e===`square`)return{square:!0};let t=e.startsWith(`pct:`),n=e.substr(t?4:0).split(`,`).map(e=>parseFloat(e));return{x:n[0],y:n[1],w:n[2],h:n[3],percent:t}}catch{throw Error(`Expected 'full', 'square' or 'x,y,w,h'. Found `+e)}}function xt(e){let t={upscaled:!1,max:!1,confined:!1};if(e[0]===`^`&&(t.upscaled=!0,e=e.slice(1)),e===`max`||e===`full`)return t.max=!0,t.serialiseAsFull=e===`full`,t;if(e[0]===`!`&&(t.confined=!0,e=e.slice(1)),e[0]===`p`)return t.percentScale=parseFloat(e.slice(4)),t;let n=e.split(`,`).map(e=>e.trim());return n.length&&typeof n[0]<`u`&&(n[0]!==``&&(t.width=parseInt(n[0],10)),typeof n[1]<`u`&&n[1]!==``?(t.height=parseInt(n[1],10),t.version=2):t.version=3),t}function St(e){let t={angle:0};if(e[0]===`!`&&(t.mirror=!0,e=e.substr(1)),t.angle=parseFloat(e)%360,Number.isNaN(t.angle))throw Error(`Invalid rotation ${e}`);return t}function Ct(e,t=``){let n=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!n)throw Error(`Invalid or unknown input ${e}`);let r=n[2],i=n[3],a=n[4];if(a[0]===`/`&&(a=a.substring(1)),t.length>0){if(t[0]===`/`&&(t=t.substring(1)),t!==a.substring(0,t.length))throw Error(`Path does not start with prefix (path: ${a}, prefix: ${t})`);a=a.substring(t.length)}return{scheme:r,server:i,path:a,prefix:t}}function wt(e,t=``){let{path:n,scheme:r,server:i,prefix:a}=Ct(e,t),o=(n||``).split(`/`).reverse(),[s,c,l,u,...d]=o,f=d.reverse().filter(Boolean).join(`/`);if(o.length===1||s===``)return{type:`base`,scheme:r,server:i,prefix:a,identifier:f};if(s===`info.json`){let[,...e]=o;return{type:`info`,scheme:r,server:i,prefix:a,identifier:e.reverse().filter(Boolean).join(`/`)}}let p=(s||``).split(`.`);if(typeof p[1]>`u`||typeof p[0]>`u`||typeof u>`u`||typeof l>`u`||typeof c>`u`)throw Error(`Invalid image request`);return{type:`image`,scheme:r,server:i,prefix:a,identifier:f,originalPath:n,region:bt(u),size:xt(l),rotation:St(c),quality:p[0],format:p[1]}}function Tt(e){let t=wt(M(e.id));if(t.type!==`info`)throw Error(`Invalid service URL`);let n=yt(e);return{identifier:t.identifier,originalPath:``,server:t.server,prefix:t.prefix,scheme:t.scheme,type:`image`,quality:n.extraQualities.indexOf(`default`)===-1?n.extraQualities[0]:`default`,region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:`jpg`,rotation:{angle:0}}}function Et(e,t,n){let r=n.length,i=[];for(let t=0;t<r;t++){let r=n[t];if(r){let t=r.width;i.push(e/t)}}return i}function Dt(e,t,n){let r=n.length,i=[];for(let a=0;a<r;a++){let r=n[a];r&&i.push({width:Math.floor(e/r),height:Math.floor(t/r)})}return i}function N(e){if(e[`@id`])return e[`@id`];if(e.id)return e.id}function P(e){if(!e||!e.profile||!N(e))return!1;let t=Array.isArray(e.profile)?e.profile:[e.profile];for(let e of t)if(typeof e==`string`&&mt.indexOf(e)!==-1)return!0;return!1}function Ot(e){if(!P(e))return!1;let t=Array.isArray(e.profile)?e.profile:[e.profile];for(let e of t)if(typeof e==`string`){if(pt.indexOf(e)!==-1)return!0}else{let t=[...e.supports||[],...e.extraFeatures||[]];if(t.indexOf(`regionByPx`)!==-1&&(t.indexOf(`sizeByW`)!==-1||t.indexOf(`sizeByWh`)!==-1))return!0}return!1}function F(e,t){if(t&&t.profile){let n=t.profile;if(n){let t=Array.isArray(n)?n:[n];return t.includes(`level${e}`)||t.includes(`http://iiif.io/api/image/2/level${e}.json`)||t.includes(`http://iiif.io/api/image/1/level${e}.json`)||t.includes(`http://iiif.io/api/image/1/profiles/level${e}.json`)}}return!1}function I(e){return P(e)?F(0,e)?0:F(1,e)?1:F(2,e)?2:null:null}function kt(e){return(e[`@context`]?Array.isArray(e[`@context`])?e[`@context`]:[e[`@context`]]:[]).indexOf(`http://iiif.io/api/image/3/context.json`)!==-1}function At(e){if(!Ot(e))return[];let t=[],n=Array.isArray(e.profile)?e.profile:[e.profile],r=n.length;for(let t=0;t<r;t++){let r=n[t];if(r&&typeof r!=`string`&&(r.maxHeight||r.maxWidth))return[{id:N(e),type:`variable`,minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight,level:I(e),version:e[`@context`]===`http://iiif.io/api/image/3/context.json`?3:2}]}if(e.tiles){let n=e.tiles.length;for(let r=0;r<n;r++){let n=e.tiles[r];n&&(n.height||n.width)&&t.push({id:N(e),type:`variable`,minHeight:0,minWidth:0,maxHeight:n.height||n.width,maxWidth:n.width,level:I(e),version:kt(e)?3:2})}}return t}function jt(e){let t=e.match(/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/);if(t&&t[4]&&t[5]){let n=t[1],r=parseInt(t[4],10),i=parseInt(t[5],10),a=t[7];if((n===`max`||n===`full`)&&r&&i&&a)return{type:`fixed`,id:e,height:i,width:r}}return{type:`unknown`,id:e}}function Mt(e){if(e[`@type`])return e[`@type`];if(e.type)return e.type}function Nt(e){if(typeof e==`string`)return jt(e);let t=Mt(e);if(t!==`Image`&&t!==`sc:Image`)return null;let n=e,r=N(n);return r?r&&n.width&&n.height?{id:r,type:`fixed`,width:n.width,height:n.height,unsafe:!0}:jt(r):null}function Pt(e){return P(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:N(e),type:`fixed-service`,height:t.height,width:t.width,level:I(e),version:kt(e)?3:2})):[]}function Ft(e){let t=[],n=e.length;for(let r=0;r<n;r++){let n=e[r];if(!n)continue;let i=Pt(n);i.length&&t.push(...i);let a=At(n);a.length&&t.push(...a)}return t}function It(e){let t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],n=t.length,r=[];for(let e=0;e<n;e++)P(t[e])&&r.push(t[e]);return r}function Lt(e,t=!0,n){let r=[],i=Nt(e);if(i===null)return r;let a=e;if(r.push(i),t&&a&&a.width&&a.height){let e=[],t=It(a);for(let r of t){let t={id:N(r),width:a.width,height:a.height};if(n.canLoadSync(t)){let r=n.loadServiceSync(t);r&&(r.height||(r.height=a.height),r.width||(r.width=a.width),e.push(...Ft([r])))}}if(e.length)return r.push(...e),r}return a.service&&r.push(...Ft(a.service)),r}function Rt({x:e=0,y:t=0,w:n,h:r,full:i,square:a,percent:o}){if(i)return`full`;if(a)return`square`;if(typeof n>`u`||typeof r>`u`)throw Error(`RegionParameter: invalid region`);let s=`${e},${t},${n},${r}`;return o?`pct:${s}`:s}function zt({max:e,percentScale:t,upscaled:n,confined:r,width:i,height:a,serialiseAsFull:o,version:s}){let c=[];return n&&c.push(`^`),e?(c.push(o?`full`:`max`),c.join(``)):(r&&c.push(`!`),t&&c.push(`pct:${t}`),i&&c.push(`${i}`),c.push(`,`),a&&s===3&&c.push(`${a}`),c.join(``))}function Bt(e){return`${e.mirror?`!`:``}${(e.angle||0)%360}`}function Vt(e,t){let n=e.prefix.startsWith(`/`)?e.prefix.substr(1):e.prefix,r=`${e.scheme}://${e.server}/${n?`${n}/`:``}${e.identifier}`;if(e.type===`base`)return r;if(e.type===`info`)return`${r}/info.json`;let{size:i}=e,{region:a,rotation:o,format:s,quality:c}=e;if(t){let e=t[`@context`]?Array.isArray(t[`@context`])?t[`@context`]:[t[`@context`]]:[],n=e.indexOf(`http://iiif.io/api/image/2/context.json`)!==-1,r=e.indexOf(`http://iiif.io/api/image/3/context.json`)!==-1;if((i.width===t.width&&!i.height||i.height===t.height&&!i.width||i.width===t.width&&i.height===t.height)&&(i={...i,max:!0}),n&&(i.max&&!i.serialiseAsFull&&(i={...i,serialiseAsFull:!0}),!i.max&&i.width&&i.height&&(i={...i,height:void 0}),i={...i,version:2}),r){if(i.max&&i.serialiseAsFull&&(i={...i,serialiseAsFull:!1}),i.width&&!i.height&&t.width&&t.height){let e=t.height/t.width;i={...i,height:Math.ceil(i.width*e)}}i={...i,version:3}}}return[r,Rt(a),zt(i),Bt(o),`${c}.${s}`].filter(Boolean).join(`/`)}function L(e,t,n){let r=Tt({"@context":e.version===3?`http://iiif.io/api/image/3/context.json`:`http://iiif.io/api/image/2/context.json`,id:M(N(e)),profile:e.level===null||typeof e.level>`u`?`level0`:`level${e.level}`,type:e.version===3?`ImageService3`:`ImageService2`});if(r.type!==`image`)throw Error(`Invalid service`);return r.size.max=!1,r.size.width=t,r.size.height=n,{id:Vt(r),type:`fixed`,width:t,height:n||e.height/(e.width||1)*t,unsafe:e.width>t}}function R(e){let t=e.replace(/(https?:\/\/)?(www.)?/i,``);return t.indexOf(`/`)===-1?t:t.split(`/`)[0]}function Ht(e,t,n){let r=e.width?e.width:e.maxWidth;return n.height<=e.maxHeight&&n.width<=e.maxWidth&&n.height>=e.minHeight&&n.width>=e.minWidth&&(!t||Math.abs(n.width-r)<Math.abs(t.width-r))}function Ut(e,t){let n=[],r=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),i=(e,t=0)=>r.explain?n.push(Array(t).fill(0).map(e=>` `).join(``)+e().trim()):void 0,a=[],o=[],s=null;i(()=>`Using configuration: ${JSON.stringify(r,null,2)}`);let c=(e,t)=>{if(i(()=>`Swapping choice`,3),Ht(r,t,e)){if(r.preferFixedSize&&e.unsafe){i(()=>`We found an image that was marked as unsafe, but it was the best size. (${e.id})`,4),o.push(e);return}r.returnAllOptions&&t&&o.push(t),i(()=>`We found a new image that was the best size. (${e.id})`,4),s=e}else r.returnAllOptions&&o.push(e)};i(()=>`The input shows we have ${t.length} list(s) of candidates to choose from.`);let l=t.length;for(let e=0;e<l;e++){let n=t[e]();i(()=>`Candidate group ${e}: ${JSON.stringify(n,null,2)}`,1);let o=n.length;i(()=>`Checking candidate list number ${e} and found ${o} potential ways of creating image(s)`,1);for(let e=0;e<o;e++){let t=n[e];i(()=>`-> Checking candidate ${e}`,1),t.type===`unknown`&&r.atAnyCost&&(i(()=>`We've found an unknown image type, adding this to the "last resort" list`,2),a.push(t)),t.type===`fixed`&&(t.unsafe?(i(()=>`We've found an unsafe fixed image type, adding this to the "last resort" list`,2),a.push(t)):(i(()=>`We've found a fixed size image, checking if it matches the request`,2),c(t,s))),t.type===`fixed-service`&&(r.unsafeImageService?(i(()=>`Checking for an image from the tile source, without calculating the right height and width (unsafeImageService)`,2),c(L(t,r.width,r.height),s)):(i(()=>`Checking for an image from the tile source 3`,2),c(L(t,t.width,t.height),s))),t.type===`variable`&&t.maxWidth&&c(L({id:t.id,type:`fixed-service`,width:t.maxWidth,height:t.maxWidth,level:t.level,version:t.version},t.maxWidth),s)}if(s&&!r.returnAllOptions){if(s.unsafe||r.allowUnsafe)continue;i(()=>`We found a match in choice list number ${e}, no searching any more`);break}}return r.atAnyCost&&o.length===0?(i(()=>s?`We found an image! ${s.id} of type ${s.type}`:`We found no images, but "atAnyCost" is set, so returning that`),{best:s||a[0]||null,fallback:a.slice(1),log:n}):r.returnAllOptions?(i(()=>`Returning all options that we have found`),{best:(r.atAnyCost?s||o[0]||a[0]:s||o[0])||null,fallback:[...o,...a],log:n}):(i(()=>`Returning the best image that we found, and a fallback`),{best:s||o[0]||null,fallback:s?o:o.slice(1),log:n})}function Wt(e,t,n){let r=e>t?e:t,i=n.length,a=[];for(let e=0;e<i;e++){let t=n[e];if(!t||t.scaleFactors.length===0)continue;let i=t.scaleFactors[0];if(!i)continue;let o=r/i,s=[i];for(;o>=t.width;)i*=2,s.push(i),o/=2;a.push({...t,scaleFactors:s})}return a}function Gt(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;let n=e.length,r=!0;for(let i=0;i<n;i++){let n=e[i],a=t[i];if(n.width!==a.width||n.height!==a.height){r=!1;break}}if(r)return!0;let i=0;for(let r=0;r<n;r++)for(let a=0;a<n;a++)if(e[r].width===t[a].width&&e[r].height===t[a].height){i++;break}return i===n}function Kt(e){return F(0,e)}new class{constructor(e={}){j(this,`config`,{verificationsRequired:1,approximateServices:!1,enableFetching:!0,disableThrottling:!1}),j(this,`fetchingCount`,0),j(this,`imageServices`,{}),j(this,`knownImageServers`,{}),this.config=Object.assign(this.config,e)}setConfig(e){Object.assign(this.config,e)}sample(e,t,n=!0){let r=R(N(e)),i=M(N(e)),a=this.knownImageServers[r];return this.imageServices[i]=Object.assign(e,{real:!0}),!a&&e.tiles&&!Kt(e)?(this.knownImageServers[r]={verifications:0,malformed:!1,root:r,preLoaded:n,sampledId:N(e),verified:!1,server:null,result:{context:e[`@context`]||[],sampledProfile:e.profile,resourceServiceRatio:t&&e.height?t.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Et(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0):this.verify(e)}preLoad(e,t=!0){this.knownImageServers[e.root]=e,t&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,t=!1,n=!1){let r=e?.source,i=R(N(e)),a=this.knownImageServers[i],o=M(N(e));return this.imageServices[o]?this.imageServices[o]||null:!this.config.approximateServices||!a||!a.result||!(r?.height||e.height)||!(r?.width||e.width)||!n&&(a.malformed||a.verifications<this.config.verificationsRequired)||Kt(e.source)?null:(this.imageServices[o]||(this.imageServices[o]={"@context":a.result.context,"@id":N(e),id:N(e),protocol:`http://iiif.io/api/image`,tiles:r?.tiles||Wt(e.width,e.height,a.result.sampledTiles),sizes:r?.sizes||Dt(Math.round(e.width/a.result.resourceServiceRatio),Math.round(e.height/a.result.resourceServiceRatio),a.result.sizeRatios),profile:r?.profile||a.result.sampledProfile,height:r?.height||e.height,width:r?.width||e.width,real:!1}),this.imageServices[o]||null)}async getThumbnailFromResource(e,t,n=!0,r=[]){let i=e?await this.getImageCandidates(e,n):[];return Ut(t,[()=>r,()=>i])}async getImageCandidates(e,t=!0){let n=e;if(t&&n&&n.height&&n.width){let e=It(n);for(let t of e){let e={id:N(t),width:t.width?t.width:n.width,height:t.height?t.height:n.height,source:t};await this.loadService(e)}}return Lt(e,t,this)}async verify(e){let t=this.predict(e,!1,!0),n=await this.fetchService(N(e));if(!t)return!1;let r=t.height===n.height&&t.width===n.width&&t[`@context`]===n[`@context`]&&Gt(t.sizes||[],n.sizes||[]);if(r){let t=R(N(e)),n=this.knownImageServers[t];n&&(n.verifications+=1,n.verifications>=this.config.verificationsRequired&&(n.verified=!0))}return r}canLoadSync(e){let t=typeof e==`string`?e:N(e),n=M(t);if(this.imageServices[n])return!0;let r=this.knownImageServers[R(t)];return!!(r&&!r.malformed&&r.verifications>=this.config.verificationsRequired)}async markAsMalformed(e){return this.knownImageServers[R(N(e))].malformed=!0,this.loadService(e,!0)}async fetchService(e,t=!1){let n=M(e),r=this.imageServices[n];if(r&&(!t||r.real))return r;if(!this.config.enableFetching)throw Error(`Fetching is not enabled`);let i=await this.fetch(n).then(e=>e.json());return!i.id&&i[`@id`]&&(i.id=i[`@id`]),i.id!==e&&(i.id=e,i[`@id`]&&(i[`@id`]=e)),this.imageServices[n]=Object.assign(i,{real:!0}),this.imageServices[n]}async fetch(e,t){return fetch(e,t)}async loadService(e,t=!1){if(!this.config.disableThrottling){let e=!0;for(;e;)if(this.fetchingCount>=this.config.verificationsRequired)await new Promise(e=>setTimeout(e,500));else{e=!1;break}}let n=this.knownImageServers[R(N(e))];if(n&&!n.malformed&&!t){await n.result;let t=this.loadServiceSync(e);if(t)return t}this.fetchingCount++;let r=await this.fetchService(N(e),t);return this.fetchingCount--,r.real&&this.sample(r,e),r}loadServiceSync(e){let t=M(N(e));return this.imageServices[t]?this.imageServices[t]:this.config.approximateServices?this.predict(e):null}};const z={canvasInteraction:!0,spatial:!0,async run(e,{vault:t,options:n}){if(e&&e.type===`Annotation`&&n.targetType===`Annotation`){let n=t.get(e),r=n.target;if(!(r&&r.source?.type===`Canvas`))return;let i=r.source,a=t.get(i);if(!a.items||a.behavior.includes(`multi-image`)||!t.get(a.items[0]))return;let o=Array.isArray(n.body)?n.body[0]:n.body;if(o.type===`SpecificResource`&&o.selector)return;let s=t.get(n.body)[0],c=(s.service||[]).find(e=>P(e));c&&c.width&&c.height&&(c.width!==s.width&&t.modifyEntityField({id:s.id,type:`ContentResource`},`width`,c.width),c.height!==s.height&&t.modifyEntityField({id:s.id,type:`ContentResource`},`height`,c.height))}}};function B(e){let{"@id":t,"@type":n,...r}=e,i=`${e[`@context`]||``} ${e.profile||``}`.match(/\/(?:image|image-api)\/([123])(?:[./])/);return{...r,id:e.id||t,type:e.type||n||`ImageService${i?.[1]||`2`}`}}function qt(e,t={},n=!1){let r=[];t.compact!==`compact`&&r.push(`width`,`height`),(n||t.includeSizes===!0)&&r.push(`sizes`),(n||t.includeTiles===!0)&&r.push(`tiles`);let i=B(e);return{id:i.id,type:i.type,profile:i.profile,...Object.fromEntries(r.filter(e=>i[e]!==void 0).map(e=>[e,i[e]]))}}async function Jt(e,t){let n=B(e.service),r=(0,b.createImageServiceRequest)(n),i=(0,b.imageServiceRequestToString)({identifier:r.identifier,server:r.server,scheme:r.scheme,type:`image`,size:{max:!e.size?.width&&!e.size?.height,confined:!1,upscaled:!1,...e.size||{}},format:`jpg`,region:{full:!0},rotation:{angle:0},quality:`default`,prefix:r.prefix,originalPath:r.originalPath});return t.embed({id:i,type:`Image`,format:e.format||`image/jpeg`,height:e.height||n.height,width:e.width||n.width,service:e.embedService===!1?void 0:[qt(n,t.config,t.options.parent?.property===`thumbnail`)]})}function V(e){return e.endsWith(`default.jpg`)?(0,b.imageServiceRequestToString)({...(0,b.parseImageServiceRequest)(e),type:`info`}):(0,b.canonicalServiceUrl)(e)}function H(e){let t=e.options.initialData,n=t.url?V(t.url):``,[r,i]=(0,m.useState)(n||``);return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries()),i=r.url;if(i){let t=V(i);if(!t)throw Error(`Invalid image service request`);fetch(t).then(e=>e.json()).then(t=>{e.runCreate({url:r.url,service:t})})}},children:[(0,h.jsx)(`div`,{className:`flex gap-2 items-center`,children:(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`url`,children:`Link to image service`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:t.url||``,onPaste:e=>{let t=e.clipboardData.getData(`text/plain`);i(t?V(t):``)},onBlur:e=>i(e.currentTarget.value?V(e.currentTarget.value):``)})]})}),(0,h.jsx)(`div`,{className:`relative flex z-0 my-5 h-96 min-h-0 min-w-0 overflow-hidden bg-gray-200 rounded items-center justify-center`,children:r.trim()?(0,h.jsx)(te.ErrorBoundary,{fallbackRender:()=>(0,h.jsx)(`div`,{children:`Invalid service`}),children:(0,h.jsx)(Yt,{src:r},r)}):(0,h.jsx)(`div`,{className:`text-grey-600`,children:`Preview`})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,isDisabled:!r,children:`Create`})})]})})}function Yt({src:e}){let t=(0,_.useImage)({id:e},{size:{width:512}});return t?(0,h.jsx)(`div`,{className:`h-full`,children:(0,h.jsx)(`img`,{className:`w-full h-full object-contain`,src:t})}):(0,h.jsx)(we,{})}async function Xt(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=await(0,u.creatorHelper)(t,`Annotation`,`body`,`@manifest-editor/image-service-creator`)(e,{parent:{resource:n,property:`body`}});if(r===`Annotation`)return{...n,body:[i],motivation:e.motivation||`painting`,target:t.getTarget()};if(r===`Canvas`){let r=t.generateId(`canvas`),a=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:[i],target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:a,type:`AnnotationPage`,items:[o]}),c;return e.service?.sizes&&(c=await(0,u.creatorHelper)(t,`Canvas`,`thumbnail`,`@manifest-editor/thumbnail-image`)({service:e.service,width:e.thumbnailSize||400})),t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled canvas`]},height:i.resource.height||1e3,width:i.resource.width||1e3,thumbnail:c?[c]:void 0,items:[s]})}}function Zt(e){return(0,h.jsx)(H,{...e})}const U=(0,u.defineCreator)({id:`@manifest-editor/image-service-creator`,configKey:`iiif-image-services`,create:Jt,label:`Image Service`,summary:`Add an image from Image Service`,icon:(0,h.jsx)(f.IIIFLogo,{style:{padding:10}}),tags:[`image`,`image-service`],async supportsResource(e,t){if(!x(e))return!1;let n=V(e);if(!n)return!1;let r=await S(n,t);return oe(r)?{initialData:{url:e,service:r}}:!1},render(e){return(0,h.jsx)(H,{...e})},resourceType:`ContentResource`,resourceFields:[`id`,`type`,`height`,`width`,`format`,`service`],supports:{initialData:!0,parentFields:[`logo`,`body`,`thumbnail`,`items`],custom(e,t){return e.property!==`items`||e.resource.type===`ContentResource`&&t.get(e.resource,{skipSelfReturn:!1})?.type===`Choice`}}}),Qt=(0,u.defineCreator)({id:`@manifest-editor/image-service-annotation`,create:Xt,label:`IIIF Image`,dependencies:[`@manifest-editor/image-service-creator`],summary:`IIIF Image service`,tags:[`image`,`image-service`],icon:(0,h.jsx)(f.IIIFLogo,{style:{padding:10}}),render(e){return(0,h.jsx)(Zt,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supportsResource:U.supportsResource,supports:{initialData:!0,onlyPainting:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},sideEffects:[z,A,k],staticFields:{type:`Annotation`}});async function $t(e,t){if(!e.height||!e.width){let t=await(0,y.getImageDimensions)(e.url);t&&(e.height=t.height,e.width=t.width)}return t.embed({id:e.url,type:`Image`,format:e.format||await(0,y.getFormat)(e.url),height:e.height,width:e.width,service:e.service?Array.isArray(e.service)?e.service:[e.service]:void 0})}function W(e){let t=e.options.initialData;return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries());r.url&&e.runCreate({url:r.url})},children:[(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`id`,children:`Link to Image`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:t.url||``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create`})]})})}async function en(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=await(0,u.creatorHelper)(t,`Annotation`,`body`,`@manifest-editor/image-url-creator`)(e,{parent:{resource:n,property:`body`}});if(r===`Annotation`)return t.embed({...n,body:[i],motivation:e.motivation||`painting`,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),a=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:[i],target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:a,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled canvas`]},height:i.resource.height||1e3,width:i.resource.width||1e3,items:[s]})}throw Error(`Unsupported target type`)}function tn(e){return(0,h.jsx)(W,{...e})}const G=(0,u.defineCreator)({id:`@manifest-editor/image-url-creator`,create:$t,label:`Image`,summary:`Image from a URL`,icon:(0,h.jsx)(f.AddImageIcon,{}),tags:[`image`],async supportsResource(e,t){if(!x(e))return!1;let n=V(e);if(n)try{if(oe(await t.json(n)))return!1}catch{}let r=await w(e,t);return r.startsWith(`image/`)||T(e,[`.jpg`,`.jpeg`,`.png`,`.gif`,`.webp`])?{initialData:{url:e,format:r||void 0}}:!1},render(e){return(0,h.jsx)(W,{...e})},resourceType:`ContentResource`,resourceFields:[`format`],supports:{initialData:!0,parentFields:[`logo`,`body`,`thumbnail`,`items`],custom(e,t){return e.property!==`items`||e.resource.type===`ContentResource`&&t.get(e.resource,{skipSelfReturn:!1})?.type===`Choice`}},staticFields:{type:`Image`}}),nn=(0,u.defineCreator)({id:`@manifest-editor/image-url-annotation`,create:en,label:`Image`,dependencies:[`@manifest-editor/image-url-creator`],summary:`Image from URL`,tags:[`image`],icon:(0,h.jsx)(f.AddImageIcon,{}),render(e){return(0,h.jsx)(tn,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supportsResource:G.supportsResource,supports:{initialData:!0,onlyPainting:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},sideEffects:[z,A,k],staticFields:{type:`Annotation`}});async function rn(e,t){let n=[],r=(0,u.creatorHelper)(t,`Annotation`,`body`,`@manifest-editor/image-url-creator`);for(let i of e.images)n.push(await r(i,t.options));return n}function K(e){return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(f.Form.Form,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries());r.urls&&e.runCreate({images:r.urls.split(`
97
- `).map(e=>({url:e}))})},children:[(0,h.jsxs)(f.Form.InputContainer,{className:`mb-4`,children:[(0,h.jsx)(f.Form.Label,{children:`Enter a list of URLs (one per line)`}),(0,h.jsx)(f.Form.TextArea,{name:`urls`,rows:`10`})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create`})]})})}async function an(e,t){let n=[],r=(0,u.creatorHelper)(t,`AnnotationPage`,`items`,`@manifest-editor/image-url-annotation`);for(let i of e.images)n.push(await r(i,t.options));return n}const on=(0,u.defineCreator)({id:`@manifest-editor/image-url-list-annotation`,create:an,label:`List of Images`,dependencies:[`@manifest-editor/image-url-annotation`],summary:`List of Images from URLs`,tags:[`image`],icon:(0,h.jsx)(f.ImageListIcon,{}),render(e){return(0,h.jsx)(K,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supports:{onlyPainting:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},sideEffects:[z,A,k],staticFields:{type:`Annotation`}}),sn=(0,u.defineCreator)({id:`@manifest-editor/no-body-annotation`,create:cn,label:`Annotation without body`,summary:`Add an annotation that only has motivation and target`,icon:(0,h.jsx)(f.EmptyCanvasIcon,{}),resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`target`],supports:{initialData:!0,parentTypes:[`AnnotationPage`],parentFields:[`items`],disallowPainting:!0},actionButton:`Create empty annotation`,sideEffects:[],staticFields:{type:`Annotation`}});function cn(e,t){return t.embed({id:t.generateId(`annotation`),type:`Annotation`,label:e?.label,motivation:e.motivation||t.options.initialData?.motivation||`highlighting`,target:t.getTarget()})}function ln({media:e,onError:t,duration:n,onDuration:r,onDimensions:i}){let[{element:a,currentTime:o,progress:s},c,l]=(0,_.useSimpleMediaPlayer)({duration:n});return(0,h.jsxs)(_.MediaPlayerProvider,{element:a,state:c,actions:l,currentTime:o,progress:s,children:[(0,h.jsx)(`div`,{style:{maxHeight:400,aspectRatio:`${e.width}/${e.height}`,position:`relative`},children:(0,h.jsx)(_.CanvasPanel.VideoHTML,{element:a,media:e,playPause:l.playPause})}),(0,h.jsx)(E,{onError:t,onDuration:r,onDimensions:i})]})}async function un(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=t.embed({id:e.url,type:`Video`,format:`video/mp4`,width:e.width,height:e.height,duration:e.duration||0});if(r===`Annotation`)return t.embed({...n,label:(0,d.getValue)(e.label)&&e.label,motivation:e.motivation||t.options.initialData?.motivation||`painting`,body:i,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),a=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:i,target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:a,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled HTML canvas`]},duration:e.duration||0,width:e.width,height:e.height,items:[s]})}}function dn(e){let t=e.options.initialData,[n,r]=(0,m.useState)(t.url||``),[i,a]=(0,m.useState)(0),[o,s]=(0,m.useState)(0),[c,l]=(0,m.useState)(0),[u,d]=(0,m.useState)(``),[g,_]=(0,m.useState)({en:[``]});return(0,m.useEffect)(()=>{if(d(``),a(0),n){let e=n.split(`/`).pop()?.split(`.`).shift();_({en:[e||``]})}},[n]),(0,h.jsxs)(f.PaddedSidebarContainer,{children:[u?(0,h.jsx)(f.ErrorMessage,{children:u}):null,(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`video-url`,children:`URL`}),(0,h.jsx)(p.Input,{type:`text`,id:`video-url`,value:n,onChange:e=>r(e.target.value)})]}),n&&!u?(0,h.jsx)(`div`,{children:(0,h.jsx)(p.LanguageFieldEditor,{containerId:`label`,focusId:`label_`,label:`Label`,fields:g,onSave:e=>_(e.toInternationalString())},`${n}__${i}`)}):null,n&&!u?(0,h.jsx)(`div`,{className:`mb-4 bg-black`,children:(0,h.jsx)(ln,{duration:i,onDuration:e=>a(e),onError:e=>d(e),media:{url:n,duration:i,height:c,width:o,type:`Video`},onDimensions:(e,t)=>{s(e||0),l(t||0)}})}):null,!u&&(i||o||c)?(0,h.jsx)(p.InputContainer,{$wide:!0,children:(0,h.jsx)(p.DimensionsTriplet,{widthId:`width`,width:o||0,changeWidth:e=>s(e),heightId:`height`,height:c||0,changeHeight:e=>l(e),durationId:`duration`,duration:i||0,changeDuration:e=>a(e)})}):null,(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`button`,onPress:()=>{e.runCreate({url:n,duration:i,label:g,width:o,height:c})},isDisabled:!n||!!u,children:`Add video`})]})}const fn=(0,u.defineCreator)({id:`@manifest-editor/video-annotation`,create:un,label:`Video`,summary:`Video annotation`,icon:(0,h.jsx)(f.VideoIcon,{}),render(e){return(0,h.jsx)(dn,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],async supportsResource(e,t){return x(e)&&((await w(e,t)).startsWith(`video/`)||T(e,[`.mp4`,`.m4v`,`.webm`,`.mov`]))?{initialData:{url:e}}:!1},supports:{onlyPainting:!0,initialData:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},staticFields:{type:`Annotation`}}),pn=()=>(0,h.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`24px`,viewBox:`0 0 24 24`,width:`24px`,fill:`#000000`,transform:`scale(-1, 1)`,children:(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`rect`,{fill:`none`,height:`24`,width:`24`}),(0,h.jsx)(`path`,{d:`M16,20H2V4h14V20z M18,8h4V4h-4V8z M18,20h4v-4h-4V20z M18,14h4v-4h-4V14z`})]})}),mn=(0,u.defineCreator)({id:`@manifest-editor/empty-annotation-page`,create:(e,t)=>t.embed({id:t.generateId(`annotations`),label:e.label,type:`AnnotationPage`,items:[]}),label:`Empty annotation page`,summary:`AnnotationPage with nothing`,icon:(0,h.jsx)(pn,{}),resourceType:`AnnotationPage`,resourceFields:[`id`,`type`,`items`],supports:{parentTypes:[`Manifest`,`Canvas`,`Range`],parentFieldMap:{Manifest:[`annotations`],Canvas:[`items`,`annotations`],Range:[`annotations`]}}}),hn=(0,u.defineCreator)({id:`@manifest-editor/empty-canvas`,create:(e,t)=>{let n=t.generateId(`canvas`),r=t.embed({id:t.generateId(`annotation-page`,{id:n,type:`Canvas`}),type:`AnnotationPage`,items:[]});return{id:n,type:`Canvas`,label:e.label||{en:[``]},height:e.height||1e3,width:e.width||1e3,items:[r]}},label:`Empty canvas`,summary:`No content`,icon:(0,h.jsx)(f.EmptyCanvasIcon,{}),resourceType:`Canvas`,resourceFields:[`id`,`type`,`label`,`height`,`width`,`items`],supports:{parentTypes:[`Manifest`],parentFields:[`items`]}});var gn=process.env.NODE_ENV===`production`,q=`Invariant failed`;function J(e,t){if(!e){if(gn)throw Error(q);var n=typeof t==`function`?t():t,r=n?`${q}: ${n}`:q;throw Error(r)}}const _n=(0,u.defineCreator)({id:`@manifest-editor/internal-canvas`,create:yn,label:`Internal canvas link`,summary:`Canvas from the same manifest`,icon:(0,h.jsx)(pn,{}),resourceType:`Canvas`,resourceFields:[`id`,`type`,`label`],supports:{parentTypes:[`Manifest`],parentFields:[`start`]},render:e=>(0,h.jsx)(vn,{...e})});function vn(e){let t=(0,_.useManifest)(),n=(0,_.useVault)(),r=(0,m.useMemo)(()=>({canSelectCanvas:!1,canSelectCollection:!1,canSelectManifest:!0,canCropImage:!1,alwaysShowNavigationArrow:!1,multiSelect:!1}),[]),i=(0,m.useMemo)(()=>[{type:`callback`,cb:t=>e.runCreate({id:t}),label:`Select canvas`,supportedTypes:[`Canvas`],format:{type:`url`}}],[e.runCreate]),a=(0,m.useMemo)(()=>({saveToLocalStorage:!1,restoreFromLocalStorage:!1,initialHistory:[{url:t?.id,resource:t?.id,route:`/loading?id=${t?.id}`,metadata:{type:`Manifest`}}]}),[t?.id]);return J(t,`Manifest is not loaded`),(0,h.jsx)(_.VaultProvider,{vault:n,children:(0,h.jsx)(ne.IIIFBrowser,{vault:n,navigation:r,output:i,history:a})})}async function yn(e,t){return t.embed({id:e.id,type:`Canvas`})}const bn=e=>(0,h.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,height:`1em`,width:`1em`,...e,children:[(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{d:`M5 17v2h14v-2H5zm4.5-4.2h5l.9 2.2h2.1L12.75 4h-1.5L6.5 15h2.1l.9-2.2zM12 5.98 13.87 11h-3.74L12 5.98z`})]});async function xn(e,t){return t.embed({id:t.generateId(`html/${e.language}`),language:e.language,type:`TextualBody`,format:`text/html`,value:e.body||``})}function Sn(e){let{i18n:t}=(0,y.useConfig)(),[n,r]=(0,m.useState)(`<p></p>`),[i,a]=(0,m.useState)(t.defaultLanguage);return(0,h.jsxs)(f.PaddedSidebarContainer,{children:[(0,h.jsx)(f.HTMLEditor,{className:`border-none`,value:n,onChange:e=>r(e)}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`button`,onPress:()=>{e.runCreate({language:i,body:n})},children:`Create`})]})}const Cn=(0,u.defineCreator)({id:`@manifest-editor/html-body-creator`,create:xn,label:`HTML Body`,summary:`Add HTML annotation body`,icon:(0,h.jsx)(bn,{}),render(e){return(0,h.jsx)(Sn,{...e})},resourceType:`ContentResource`,resourceFields:[`id`,`language`,`type`,`format`,`value`],supports:{parentTypes:[`Annotation`,`ContentResource`],parentFields:[`body`,`items`],custom(e,t){if(e.resource.type===`Annotation`)return e.property===`body`;let n=t.get(e.resource,{skipSelfReturn:!1});return e.property===`items`&&n?.type===`Choice`}},staticFields:{type:`TextualBody`,format:`text/html`}});function Y(e,t,n,r=0){return`${e}/${Math.floor(t.x)},${Math.floor(t.y)},${Math.floor(t.width)},${Math.floor(t.height)}/${n}/${r}/default.jpg`}async function wn(e,t){let n=t.options.targetType,r=e.output,i=[];for(let{resource:a,selector:o,parent:s,rotation:c}of r){let r=a.type,u=new d.Vault;if((n===`Canvas`||n===`Annotation`||n===`ContentResource`)&&r===`Canvas`){let r=a.id,d=s?.type===`Manifest`?s.id:void 0;J(d,`Could not find Manifest`);let f=u.get({id:d,type:`Manifest`})||await u.loadManifest(d);J(f,`Manifest not found`);let p=t.config.addManifestMetadataToCanvas!==!1;e.trackManifest?.({requiredStatement:f.requiredStatement,rights:f.rights,...p?{metadata:f.metadata||[]}:{},partOf:[{id:d,type:`Manifest`,label:f.label}]});let m=e=>{if(e.type===`SpecificResource`&&e.source)return{...e,source:m(e.source)};let t=e.type===`Canvas`&&!p?{}:{metadata:f.metadata||[]};return{requiredStatement:f.requiredStatement,rights:f.rights,...t,...e,partOf:[{id:d,type:`Manifest`,label:f.label}]}},h=f.items.find(e=>e.id===r);J(h,`Canvas not found`);let g=u.get(h),_=l.t(o,c);if(n===`Canvas`&&!_){let e=u.toPresentation3(g);e.label||(e.label={en:[`Untitled canvas`]}),t.vault.loadSync(e.id,m(e)),i.push(t.embed(t.vault.get({id:e.id,type:`Canvas`})));continue}let v=u.get(g.items[0]),y=u.get(v.items[0]);if(n===`Annotation`||n===`Canvas`||n===`ContentResource`){let r=u.toPresentation3(y);r.id=t.generateId(`Annotation`);let a=null,s={width:0,height:0};if(r?.body?.service){let t=r?.body.width,n=r?.body.height;a=(0,b.getImageServices)(r?.body)[0],a&&(!a.width||!a.height)&&(a.width=t,a.height=n),s.width=t,s.height=n,e.trackSize&&e.trackSize(s)}if(_){let u={...r.body},d=``;if(a&&o?.type===`BoxSelector`){let e=a.id||a[`@id`]||``;e&&(u.id=Y(e,o.spatial,`max`,c),d=Y(e,o.spatial,`512,`,c))}r.body={id:t.generateId(`SpecificResource`,y),type:`SpecificResource`,source:u,selector:_};let f=l.n(o?.type===`BoxSelector`?{width:~~o.spatial.width,height:~~o.spatial.height}:s,c);if(e.trackSize&&e.trackSize(f),n===`ContentResource`){i.push(m(r.body));continue}if(n===`Canvas`){let e=t.generateId(`Canvas`,y);r.target=e;let n=t.generateId(`Page`,y),a=t.embed({id:n,type:`AnnotationPage`,items:[r]}),{width:o,height:s}=f;i.push(t.embed(m({id:e,type:`Canvas`,label:{en:[`Untitled canvas`]},width:o,height:s,thumbnail:d?[t.embed({id:d,type:`Image`,format:`image/jpeg`,width:512,height:Math.round(s/o*512)})]:void 0,items:[a]})));continue}i.push(t.embed(m({...r,target:t.getTarget()})));continue}i.push(t.embed(m({...r,target:t.getTarget()})))}}}return i}const Tn=(0,m.lazy)(()=>Promise.resolve().then(()=>require("./iiif-browser-form.lazy-Df2fAM6b.cjs"))),En=(0,u.defineCreator)({id:`@manifest-editor/iiif-browser-creator`,create:wn,label:`IIIF Browser`,summary:`Browse IIIF Resources`,icon:(0,h.jsx)(f.IIIFBrowserIcon,{}),configuration:{fields:[{id:`addManifestMetadataToCanvas`,type:`checkbox`,label:`Add manifest metadata to imported canvases`,summary:`Copies metadata from the source Manifest when the IIIF Browser creates a Canvas.`,defaultValue:!0}]},render(e){return(0,h.jsx)(Tn,{...e})},hiddenModal:!0,tags:[`image`,`image-service`],async supportsResource(e,t){let n=C(await S(e,t));return n===`Manifest`||n===`Collection`||await se(e)?{initialData:{url:e}}:!1},resourceType:`ContentResource`,resourceFields:[`id`,`language`,`type`,`format`,`value`],additionalTypes:[`Annotation`,`Canvas`],supports:{initialData:!0,onlyPainting:!0,parentTypes:[`Annotation`,`Manifest`,`AnnotationPage`],parentFields:[`body`,`items`],parentFieldMap:{Annotation:[`body`],Manifest:[`items`],AnnotationPage:[`items`]}},sideEffects:[{canvasInteraction:!0,spatial:!0,async run(e,{vault:t,options:n}){if(!(e&&e.type===`Annotation`&&n.targetType===`Annotation`))return;let r=t.get(e),i=r.target;if(!(i&&i.source?.type===`Canvas`))return;let a=(Array.isArray(r.body)?r.body[0]:r.body)?.selector;if(!(a&&(a.type===`iiif:ImageApiSelector`||a.type===`ImageApiSelector`)&&a.region))return;let[o,s,c,l]=a.region.split(`,`).map(Number);if(![o,s,c,l].every(Number.isFinite)||c<=0||l<=0)return;let[u]=t.get(r.body),d=(u?.service||[]).find(e=>(0,b.isImageService)(e)),f=d?.id||d?.[`@id`];if(!f)return;let p=Y(f,{x:o,y:s,width:c,height:l},`512,`);t.loadSync(p,{id:p,type:`Image`,format:`image/jpeg`,width:512,height:Math.round(l/c*512),service:[d]}),t.modifyEntityField(i.source,`thumbnail`,[{id:p,type:`ContentResource`}])}},z,A,k],staticFields:{}}),Dn=(0,u.defineCreator)({id:`@manifest-editor/image-url-list`,label:`Image URL List`,summary:`Image from a list of URLs`,create:rn,icon:(0,h.jsx)(f.ImageListIcon,{}),render(e){return(0,h.jsx)(K,{...e})},resourceType:`ContentResource`,resourceFields:[`format`],supports:{parentFields:[`logo`,`body`,`thumbnail`]},staticFields:{type:`Image`}});async function On(e,t){return t.embed({id:e.url,type:`Text`,label:e.label,format:`text/plain`})}function kn(e){let[t,n]=(0,m.useState)({en:[`View as text`]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:n=>{n.preventDefault();let r=new FormData(n.target),i=Object.fromEntries(r.entries());i.url&&e.runCreate({url:i.url,label:t})},children:[(0,h.jsx)(p.LanguageFieldEditor,{focusId:`label`,label:`Label`,fields:t,onSave:e=>n(e.toInternationalString())}),(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`id`,children:`Link to plaintext`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create`})]})})}const An=(0,u.defineCreator)({id:`@manifest-editor/plaintext-creator`,create:On,label:`Plaintext`,summary:`Add link to an plaintext`,icon:(0,h.jsx)(bn,{}),render(e){return(0,h.jsx)(kn,{...e})},resourceType:`ContentResource`,resourceFields:[`label`,`format`],supports:{parentFields:[`seeAlso`,`rendering`]},staticFields:{format:`text/plain`}});function jn(e,t){let n=(0,b.createImageServiceRequest)(B(e));return(0,b.imageServiceRequestToString)({identifier:n.identifier,server:n.server,scheme:n.scheme,type:`image`,size:{max:!1,confined:!1,upscaled:!1,width:t.width,height:t.height},format:`jpg`,region:{full:!0},rotation:{angle:0},quality:`default`,prefix:n.prefix,originalPath:n.originalPath})}function X(e){return e.endsWith(`default.jpg`)?(0,b.imageServiceRequestToString)({...(0,b.parseImageServiceRequest)(e),type:`info`}):(0,b.canonicalServiceUrl)(e)}async function Mn(e,t){let n=B(e.service),r=n.sizes,i=qt(n,t.config,!0);if(e.thumbnailUrl)return t.embed({id:e.thumbnailUrl,type:`Image`,format:`image/jpeg`,width:e.width,height:e.height,service:[i]});if(r){let a=e.width||400,o=null;for(let e of r)(!o||Math.abs(e.width-a)<Math.abs(o.width-a))&&(o={width:e.width,height:e.height});if(o){let e=jn(n,o);return t.embed({id:e,type:`Image`,format:`image/jpeg`,width:o.width,height:o.height,service:[i]})}}return null}function Nn(e){let[t,n]=(0,m.useState)(``),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)({width:0,height:0}),s=(0,m.useMemo)(()=>!r||!a.width||!a.height?null:jn(r,a),[a,r]);return r?(0,h.jsxs)(f.PaddedSidebarContainer,{children:[(0,h.jsxs)(`div`,{className:`mb-4`,children:[(0,h.jsx)(`div`,{className:`mb-2`,children:r[`@id`]||r.id}),(0,h.jsx)(`div`,{className:`flex gap-2 mb-4`,children:r.sizes?.map(e=>{let t=e.width===a.width;return(0,h.jsxs)(f.ActionButton,{primary:t,isDisabled:t,large:!0,onPress:()=>o(e),children:[e.width,`x`,e.height]},e.width)})}),s?(0,h.jsx)(`img`,{src:s,alt:`preview of selected resource`}):null]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,isDisabled:!s,onPress:()=>{r&&e.runCreate({service:r,width:a.width,height:a.height})},children:`Add thumbnail`})]}):(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=new FormData(e.target),n=Object.fromEntries(t.entries()).url;if(n){let e=X(n);if(!e)throw Error(`Invalid image service request`);fetch(e).then(e=>e.json()).then(e=>{i(e);let t=e.sizes?.[0];t&&o(t)})}},children:[(0,h.jsx)(`div`,{className:`flex gap-2 items-center`,children:(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`url`,children:`Link to image service`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:``,onPaste:e=>{let t=e.clipboardData.getData(`text/plain`);n(t?X(t):``)},onBlur:e=>n(e.currentTarget.value?X(e.currentTarget.value):``)})]})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,isDisabled:!t,children:`Select size`})})]})})}const Pn=(0,u.defineCreator)({id:`@manifest-editor/thumbnail-image`,configKey:`iiif-image-services`,create:Mn,label:`Thumbnail from service`,summary:`Add thumbnail from an image service`,icon:(0,h.jsx)(f.ScaledImageIcon,{}),render(e){return(0,h.jsx)(Nn,{...e})},resourceType:`ContentResource`,resourceFields:[`id`,`type`,`format`,`width`,`height`,`service`],supports:{parentFields:[`thumbnail`]}});function Fn(){return(0,h.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`24px`,viewBox:`0 0 24 24`,width:`24px`,fill:`#000000`,children:[(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{d:`M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z`})]})}async function In(e,t){return t.embed({id:e.url,type:`Text`,label:e.label,format:`text/html`})}function Ln(e){let[t,n]=(0,m.useState)({en:[``]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:n=>{n.preventDefault();let r=new FormData(n.target),i=Object.fromEntries(r.entries());i.url&&e.runCreate({url:i.url,label:t})},children:[(0,h.jsx)(p.LanguageFieldEditor,{focusId:`label`,label:`Label`,fields:t,onSave:e=>n(e.toInternationalString())}),(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`id`,children:`Link`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create link`})]})})}const Rn=(0,u.defineCreator)({id:`@manifest-editor/web-page-creator`,create:In,label:`Web page`,summary:`Add link to an external web page`,icon:(0,h.jsx)(Fn,{}),render(e){return(0,h.jsx)(Ln,{...e})},resourceType:`ContentResource`,resourceFields:[`label`,`format`],supports:{parentFields:[`seeAlso`,`rendering`,`homepage`]}}),zn=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function Z(e){let t=(e||``).match(zn);return t?t[1]:null}function Bn(e){return!!Z(e.youtubeUrl)}function Vn(e,t){let n=Z(e.youtubeUrl);return t.embed({id:`https://www.youtube.com/watch?v=${n}`,type:`Video`,service:[{type:`Service`,profile:`http://digirati.com/objectifier`,params:{data:`https://www.youtube.com/embed/${n}`}},{id:`https://www.youtube.com/watch?v=${n}`,type:`Service`,profile:`https://www.youtube.com`}]})}async function Hn(e,t){let n=Vn(e,t);if(t.options.targetType===`Canvas`){let r=t.generateId(`canvas`),i=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),a=t.embed({id:t.generateId(`annotation`,{id:i,type:`AnnotationPage`}),type:`Annotation`,motivation:`painting`,body:[n],target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),o=t.embed({id:i,type:`AnnotationPage`,items:[a]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled YouTube canvas`]},height:e.height||1e3,width:e.width||1e3,duration:e.duration||1,items:[o]})}return t.options.targetType===`Annotation`?t.embed({id:t.generateId(`annotation`),type:`Annotation`,motivation:`painting`,body:[n],target:t.getTarget()}):n}function Un(e){let t=e.options.initialData;return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries());r.youtubeUrl&&e.runCreate({youtubeUrl:r.youtubeUrl})},children:[(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`id`,children:`Link to YouTube`}),(0,h.jsx)(p.Input,{id:`youtubeUrl`,name:`youtubeUrl`,defaultValue:t.youtubeUrl||``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create`})]})})}const Wn=(0,u.defineCreator)({id:`@manifest-editor/youtube`,create:Hn,label:`YouTube`,summary:`Embed YouTube`,icon:(0,h.jsx)(f.YouTubeIcon,{}),resourceType:`ContentResource`,additionalTypes:[`Canvas`,`Annotation`],resourceFields:[`id`,`type`,`service`],supportsResource(e){return Z(e)?{initialData:{youtubeUrl:e}}:!1},render:e=>(0,h.jsx)(Un,{...e}),supports:{initialData:!0,onlyPainting:!0,parentTypes:[`Annotation`,`Manifest`,`AnnotationPage`],parentFieldMap:{Annotation:[`body`],Manifest:[`items`],AnnotationPage:[`items`]}},staticFields:{type:`Video`}});async function Gn(e,t){let n=e.output||[],r=[];for(let e of n){let{resource:n,parent:i,selector:a}=e,o=t.getPreviewVault(),s=(0,d.createThumbnailHelper)(o);if(n.type===`Manifest`){let e=n.id;J(e,`Could not find Manifest ID`);let i=await o.loadManifest(e),a=await s.getBestThumbnailAtSize(i,{width:256,height:256},!1);J(i,`Manifest not found`),r.push(t.embed({id:n.id,type:`Manifest`,label:i.label,summary:i.summary,thumbnail:a?.best?[{id:a.best.id,type:`Image`}]:void 0}));continue}if(n.type===`Collection`){let e=n.id;J(e,`Could not find Manifest ID`);let i=await o.loadManifest(e);J(i,`Collection not found`),r.push(t.embed({id:n.id,type:`Collection`,label:i.label}))}}return r}const Kn=(0,m.lazy)(()=>Promise.resolve().then(()=>qn));var qn=o({default:()=>Jn});function Jn(e){let t=(0,y.usePreviewVault)(),n=(0,m.useMemo)(()=>e.options.initialData||{},[e.options.initialData]),r=(0,m.useMemo)(()=>[{type:`callback`,label:`Select`,supportedTypes:[`Manifest`,`Collection`,`ManifestList`,`CollectionList`,`CollectionItemList`],cb:t=>e.runCreate({output:t}),format:{type:`custom`,format:(e,t,n)=>{let r=Array.isArray(e)?e:[{...e,parent:t}],i=[];for(let e of r)i.push({resource:n.get(e),parent:e.parent,selector:e.selector});return i}}}],[e.runCreate]),i=(0,m.useMemo)(()=>({canCropImage:!1,canSelectCanvas:!1,canSelectManifest:!0,canSelectCollection:!0,multiSelect:!0,...n.iiifBrowserOptions?.navigation||{}}),[n.iiifBrowserOptions?.navigation]),a=(0,m.useMemo)(()=>({buttonClassName:`bg-me-primary-500 text-white hover:bg-me-primary-600`,homeLink:n.url||(typeof e.config?.defaultCollection==`string`?e.config.defaultCollection:void 0),...n.iiifBrowserOptions?.ui||{}}),[n,e.config]),o=(0,m.useMemo)(()=>{let e=n.iiifBrowserOptions?.history||{};return n.url?{...e,restoreFromLocalStorage:!1,saveToLocalStorage:!1,initialHistory:[{url:n.url,resource:null,route:`/loading?id=${encodeURIComponent(n.url)}`}]}:e},[n]);return(0,h.jsx)(y.PreviewVaultBoundary,{children:(0,h.jsx)(ne.IIIFBrowser,{ui:a,vault:t,className:`iiif-browser border-none border-t rounded-none h-[70vh] min-h-[60vh] max-h-full max-w-full`,output:r,navigation:i,customPages:n.iiifBrowserOptions?.customPages||{},history:o})})}const Yn=(0,u.defineCreator)({id:`@manifest-editor/manifest-browser-creator`,configKey:`@manifest-editor/iiif-browser-creator`,create:Gn,label:`IIIF Browser`,summary:`Browse IIIF Resources`,icon:(0,h.jsx)(f.IIIFBrowserIcon,{}),render(e){return(0,h.jsx)(Jn,{...e})},async supportsResource(e,t){let n=C(await S(e,t));return n===`Manifest`||n===`Collection`||await se(e)?{initialData:{url:e}}:!1},resourceType:`Manifest`,resourceFields:[`id`,`label`],additionalTypes:[`Collection`],supports:{initialData:!0,parentTypes:[`Collection`,`Manifest`,`Canvas`],parentFieldMap:{Collection:[`items`],Manifest:[`partOf`],Canvas:[`partOf`]}},sideEffects:[],staticFields:{}});async function Xn(e,t,n){let r=t.generateId(`range`,n?{id:n,type:`Range`}:void 0);return t.embed({id:r,type:`Range`,label:e.label||{en:[`Untitled range`]},items:e.items||[]})}function Q(e){let[t,n]=(0,m.useState)({en:[``]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:n=>{n.preventDefault(),t&&e.runCreate({type:`Range`,label:t})},children:[(0,h.jsx)(p.LanguageFieldEditor,{focusId:`label`,label:`Label`,fields:t,onSave:e=>n(e.toInternationalString())}),(0,h.jsx)(f.ActionButton,{primary:!0,type:`submit`,children:`Create range`})]})})}const Zn=(0,u.defineCreator)({id:`@manifest-editor/range-with-items`,create:Xn,label:`Range`,summary:`Add a new range`,icon:(0,h.jsx)(f.RangesIcon,{}),render(e){return(0,h.jsx)(Q,{...e})},resourceType:`Range`,resourceFields:[`id`,`label`,`type`],supports:{parentTypes:[`Range`],parentFields:[`items`]},staticFields:{type:`Range`}});async function Qn(e,t,n){let r=t.generateId(`range`,n?{id:n,type:`Range`}:void 0);return t.embed({id:r,type:`Range`,label:e.label||{en:[`Table of Contents`]},items:(e.items||[]).map(e=>t.ref(e))})}function $n(e){let[t,n]=(0,m.useState)({en:[``]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:n=>{n.preventDefault(),t&&e.runCreate({type:`Range`,label:t})},children:[(0,h.jsx)(p.LanguageFieldEditor,{focusId:`label`,label:`Label`,fields:t,onSave:e=>n(e.toInternationalString())}),(0,h.jsx)(f.ActionButton,{primary:!0,type:`submit`,children:`Create range`})]})})}const $=(0,u.defineCreator)({id:`@manifest-editor/range-top-level`,create:Qn,label:`Top Level Range`,summary:`Add a new top level range`,icon:(0,h.jsx)(f.RangesIcon,{}),render(e){return(0,h.jsx)($n,{...e})},resourceType:`Range`,resourceFields:[`id`,`label`,`type`],supports:{parentTypes:[`Manifest`],parentFields:[`structures`]},staticFields:{type:`Range`}}),er=[U,Qt,G,nn,fn,De,Cn,Ne,Wn,En,hn,An,Rn,mn,sn,_n,Ae,Dn,on,Pn,$,Zn,ae];exports.CreateAudioAnnotationForm=O,exports.CreateCaptionedImageAnnotation=ke,exports.CreateHTMLAnnotation=Me,exports.CreateHTMLBodyForm=Sn,exports.CreateImageServerForm=H,exports.CreateImageServiceAnnotationForm=Zt,exports.CreateImageUrlAnnotationForm=tn,exports.CreateImageUrlForm=W,exports.CreateImageUrlListForm=K,exports.CreatePlaintextForm=kn,exports.CreateProviderForm=ie,exports.CreateThumbnailForm=Nn,exports.CreateVideoAnnotationForm=dn,exports.CreateWebPageForm=Ln,exports.IIIFBrowserCreatorForm=Tn,exports.ManifestBrowserCreatorForm=Kn,exports.RangeWithItemsCreatorForm=Q,exports.TopLevelRangeCreatorForm=$n,exports.YouTubeForm=Un,exports.allCreators=er,exports.audioAnnotation=De,exports.captionedImageAnnotation=Ae,exports.createAudioAnnotation=D,exports.createCaptionedImageAnnotation=Oe,exports.createFromIIIFBrowserOutput=wn,exports.createFromManifestBrowserOutput=Gn,exports.createHtmlAnnotation=je,exports.createHtmlBody=xn,exports.createImageServer=Jt,exports.createImageServiceAnnotation=Xt,exports.createImageUrl=$t,exports.createImageUrlAnnotation=en,exports.createImageUrlList=rn,exports.createImageUrlListAnnotation=an,exports.createNoBodyAnnotation=cn,exports.createPlaintext=On,exports.createProvider=re,exports.createRangeTopLevel=Qn,exports.createRangeWithItems=Xn,exports.createThumbnail=Mn,exports.createVideoAnnotation=un,exports.createWebPage=In,exports.createYoutubeBody=Hn,exports.createYoutubeBodyResource=Vn,exports.croppedRegion=Y,exports.emptyAnnotationPage=mn,exports.emptyCanvas=hn,exports.getCanonicalUrl=V,exports.getYouTubeId=Z,exports.htmlAnnotation=Ne,exports.htmlBodyCreator=Cn,exports.iiifBrowserCreator=En,exports.imageServiceAnnotation=Qt,exports.imageServiceCreator=U,exports.imageUrlAnnotation=nn,exports.imageUrlCreator=G,exports.imageUrlListAnnotation=on,exports.imageUrlListCreator=Dn,exports.internalCanvas=_n,exports.manifestBrowserCreator=Yn,exports.noBodyAnnotation=sn,exports.plaintextCreator=An,exports.providerCreator=ae,exports.rangeTopLevel=$,exports.rangeWithItems=Zn,exports.validateYouTube=Bn,exports.videoAnnotation=fn,exports.webPageCreator=Rn,exports.youTubeBodyCreator=Wn;
92
+ `,Te=v.default.label`
93
+ ${we}
94
+ `;function Ee(e){let[t,n]=(0,m.useState)(!1),{progress:r,currentTime:i,element:a}=(0,_.useMediaElements)(),{duration:o,isMuted:s,volume:c,isPlaying:l,playRequested:u}=(0,_.useMediaState)(),{setVolume:d,toggleMute:f,play:p,pause:g,setDurationPercent:v}=(0,_.useMediaActions)(),y=s||c===0?de:c>50?le:ue;return(0,m.useLayoutEffect)(()=>{if(a.current){let t=a.current;if(t.error&&e.onError){e.onError(t.error?.message||`Unknown error`);return}let n=()=>{e.onError&&e.onError(t.error?.message||`Unknown error`)},r=()=>{t.duration&&e.onDuration&&e.onDuration(t.duration),e.onDimensions&&t instanceof HTMLVideoElement&&e.onDimensions(t.videoWidth,t.videoHeight)};return t.addEventListener(`loadedmetadata`,r),t.addEventListener(`error`,n),()=>{t.removeEventListener(`loadedmetadata`,r),t.removeEventListener(`error`,n)}}},[]),(0,h.jsxs)(fe,{children:[(0,h.jsx)(me,{disabled:u,onClick:()=>{l?g():p()},children:u?(0,h.jsx)(Ce,{stroke:`#999`}):l?(0,h.jsx)(ce,{title:`Pause`}):(0,h.jsx)(se,{title:`Play`})}),(0,h.jsx)(he,{ref:i,children:`0:00`}),(0,h.jsxs)(ge,{onClick:e=>{let{left:t,width:n}=e.currentTarget.getBoundingClientRect(),r=(e.pageX-t)/n;v(r)},children:[(0,h.jsx)(ve,{}),o?(0,h.jsx)(_e,{ref:r}):null]}),(0,h.jsx)(he,{children:(0,_.formatTime)(o)}),(0,h.jsxs)(be,{onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),children:[(0,h.jsx)(xe,{$isOpen:t,children:(0,h.jsxs)(`span`,{children:[(0,h.jsx)(Te,{htmlFor:`audio-slider`,children:`Change volume`}),(0,h.jsx)(Se,{id:`audio-slider`,role:`slider`,disabled:s,min:`0`,max:`100`,value:c,onChange:e=>d(Number(e.currentTarget.value))})]})}),(0,h.jsx)(ye,{onClick:()=>f(),children:(0,h.jsx)(y,{title:s?`Mute`:`Unmute`})})]})]})}async function D(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=t.embed({id:e.url,type:`Sound`,format:`audio/mp4`,duration:e.duration||0});if(r===`Annotation`)return t.embed({...n,label:(0,d.getValue)(e.label)&&e.label,motivation:e.motivation||t.options.initialData?.motivation||`painting`,body:i,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),a=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:i,target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:a,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled HTML canvas`]},duration:e.duration||0,items:[s]})}}function O(e){let[t]=(0,m.useState)(()=>e.options.initialData),[n,r]=(0,m.useState)(t.url||``),[i,a]=(0,m.useState)(t.duration||0),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(t.label||{en:[``]});return(0,m.useEffect)(()=>{if(s(``),a(n===t.url&&t.duration||0),n){let e=n.split(`/`).pop()?.split(`.`).shift();l(n===t.url&&t.label?t.label:{en:[e||``]})}},[n,t]),(0,h.jsxs)(f.PaddedSidebarContainer,{children:[o?(0,h.jsx)(f.ErrorMessage,{children:o}):null,(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`audio-url`,children:`URL`}),(0,h.jsx)(p.Input,{type:`text`,id:`audio-url`,value:n,onChange:e=>r(e.target.value)})]}),n&&!o?(0,h.jsx)(`div`,{children:(0,h.jsx)(p.LanguageFieldEditor,{containerId:`label`,focusId:`label_`,label:`Label`,fields:c,onSave:e=>l(e.toInternationalString())},`${n}__${i}`)}):null,n&&!o?(0,h.jsx)(_.CanvasPanel.AudioHTML,{media:{url:n,duration:i,type:`Sound`},children:(0,h.jsx)(Ee,{onError:e=>s(e),onDuration:e=>a(~~e)},`${n}__${i}`)},`${n}__${i}`):null,i&&!o?(0,h.jsxs)(p.FormFieldWrapper,{children:[(0,h.jsx)(p.InputLabel,{htmlFor:`duration`,children:`Duration`}),(0,h.jsx)(p.Input,{type:`number`,id:`duration`,value:i,onChange:e=>a(e.target.valueAsNumber)})]}):null,(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`button`,onPress:()=>{e.runCreate({url:n,duration:i,label:c})},isDisabled:!n||!!o,children:`Add audio`})]})}const De=(0,u.defineCreator)({id:`@manifest-editor/audio-annotation`,create:D,label:`Audio`,summary:`Audio annotation`,icon:(0,h.jsx)(f.AudioIcon,{}),render(e){return(0,h.jsx)(O,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],async supportsResource(e,t){return S(e)&&((await T(e,t)).startsWith(`audio/`)||E(e,[`.mp3`,`.m4a`,`.wav`,`.ogg`]))?{initialData:{url:e}}:!1},supports:{initialData:!0,onlyPainting:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},staticFields:{type:`Annotation`}});async function Oe(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=Object.keys(e.body),a=[];for(let r of i){let i=e.body[r].join(`
95
+ `);i&&a.push(await t.create(`@manifest-editor/html-body-creator`,{language:r,body:i},{parent:{resource:n,property:`items`}}))}let o=await t.create(`@manifest-editor/image-url-creator`,{url:e.imageUrl},{parent:{resource:n,property:`body`}});if(o&&a.push(o),r===`Annotation`)return t.embed({...n,motivation:e.motivation||t.options.initialData?.motivation||`painting`,body:a,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),i=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:a,target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:i,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled HTML canvas`]},height:e.height||1e3,width:e.width||1e3,items:[s]})}}function ke(e){let[t,n]=(0,y.useAnnotationCreatorState)({key:`bodyValue`,initialValue:e.options.initialData?.body||{en:[``]},requestId:e.options.initialData?.requestId});return(0,h.jsx)(`form`,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries());e.runCreate({body:{en:[r.caption]},imageUrl:r.url})},children:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`url`,children:`URL to Image`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:e.options.initialData?.imageUrl||``,placeholder:`https://example.org/image.jpg`})]}),(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`caption`,children:`Caption`}),(0,h.jsx)(p.Input,{id:`caption`,name:`caption`,placeholder:`Enter a caption`,onChange:e=>n({en:[e.target.value]}),value:t.en?.[0]||``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,type:`submit`,children:`Create`})]})})}const Ae=(0,u.defineCreator)({id:`@manifest-editor/captioned-image-annotation`,create:Oe,label:`Captioned image`,summary:`Add an image from a URL with caption`,icon:(0,h.jsx)(f.AddImageIcon,{}),render(e){return(0,h.jsx)(ke,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supports:{initialData:!0,disallowPainting:!0,parentTypes:[`AnnotationPage`],parentFields:[`items`]},staticFields:{type:`Annotation`}});async function je(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=Object.keys(e.body),a=[];for(let r of i){let i=e.body[r].join(`
96
+ `);i&&a.push(await t.create(`@manifest-editor/html-body-creator`,{language:r,body:i},{parent:{resource:n,property:`items`}}))}if(r===`Annotation`)return t.embed({...n,motivation:e.motivation||t.options.initialData?.motivation||`painting`,body:a,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),i=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:a,target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:i,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled HTML canvas`]},height:e.height||1e3,width:e.width||1e3,items:[s]})}}function Me(e){let[t,n]=(0,y.useAnnotationCreatorState)({key:`bodyValue`,initialValue:e.options.initialData?.body||{en:[``]},requestId:e.options.initialData?.requestId}),r=(0,d.getValue)(t).trim()===``;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(f.HTMLEditor,{className:`border-none`,value:t.en?.[0]||``,onChange:e=>n({en:[e]})}),(0,h.jsx)(f.ActionButton,{primary:!0,type:`button`,onPress:()=>{e.runCreate({body:t})},isDisabled:r,children:`Create`})]})}const Ne=(0,u.defineCreator)({id:`@manifest-editor/html-annotation`,create:je,label:`HTML`,summary:`HTML annotation`,icon:(0,h.jsx)(f.HTMLIcon,{}),render(e){return(0,h.jsx)(Me,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supports:{initialData:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},staticFields:{type:`Annotation`}}),k={canvasInteraction:!0,spatial:!0,async run(e,{vault:t,options:n}){if(e&&e.type===`Annotation`&&n.targetType===`Annotation`){let n=t.get(e),r=n.target;if(!(r&&r.source?.type===`Canvas`))return;let i=r.source,a=t.get(i);if(!a.items)return;let o=t.get(a.items[0]);if(!o||o.items.length<2&&!a.behavior.includes(`multi-image`))return;let s=t.get(n.body)[0],c=n.body[0]?.selector,l=(s.service||[]).find(e=>(0,b.isImageService)(e));l&&l.width&&l.height&&(l.width!==s.width&&t.modifyEntityField({id:s.id,type:`ContentResource`},`width`,l.width),l.height!==s.height&&t.modifyEntityField({id:s.id,type:`ContentResource`},`height`,l.height));let u=l?.width||s.width,d=l?.height||s.height;if(c&&(c.type===`iiif:ImageApiSelector`||c.type===`ImageApiSelector`)&&c.region){let[e,t,n,r]=c.region.split(`,`);u=Number(n)||u,d=Number(r)||d}let f=new x.EditorInstance({vault:t,reference:e}),m=(0,p.centerRectangles)(a,{width:u,height:d},.6);f.annotation.target.setPosition(m)}}},A={canvasInteraction:!0,spatial:!0,async run(e,{vault:t,options:n}){if(e&&e.type===`Annotation`&&n.targetType===`Annotation`){let n=t.get(e),r=n.target;if(!(r&&r.source?.type===`Canvas`))return;let i=r.source,a=t.get(i);if(!a.items||a.behavior.includes(`multi-image`))return;let o=t.get(a.items[0]);if(!o||o.items.length>1)return;let s=t.get(n.body);if(s.length!==1)return;let c=s[0],l=n.body[0]?.selector,u=(c.service||[])[0],d=u?.width||c.width,f=u?.height||c.height,p=c.duration||u?.duration;if(l&&(l.type===`iiif:ImageApiSelector`||l.type===`ImageApiSelector`)&&l.region){let[e,t,n,r]=l.region.split(`,`);d=Number(n)||d,f=Number(r)||f}let m=new x.EditorInstance({vault:t,reference:i});t.batch(()=>{d!==void 0&&m.technical.width.set(d),f!==void 0&&m.technical.height.set(f),p!==void 0&&m.technical.duration.set(p)})}}};var Pe=Object.defineProperty,Fe=(e,t,n)=>t in e?Pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,j=(e,t,n)=>(Fe(e,typeof t==`symbol`?t:t+``,n),n);function M(e){return e.endsWith(`info.json`)?e:e.endsWith(`/`)?`${e}info.json`:`${e}/info.json`}var Ie=`http://library.stanford.edu/iiif/image-api/compliance.html#level0`,Le=`http://library.stanford.edu/iiif/image-api/compliance.html#level1`,Re=`http://library.stanford.edu/iiif/image-api/compliance.html#level2`,ze=`http://library.stanford.edu/iiif/image-api/conformance.html#level0`,Be=`http://library.stanford.edu/iiif/image-api/conformance.html#level1`,Ve=`http://library.stanford.edu/iiif/image-api/conformance.html#level2`,He=`http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0`,Ue=`http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1`,We=`http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2`,Ge=`http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0`,Ke=`http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1`,qe=`http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2`,Je=`http://iiif.io/api/image/1/level0.json`,Ye=`http://iiif.io/api/image/1/profiles/level0.json`,Xe=`http://iiif.io/api/image/1/level1.json`,Ze=`http://iiif.io/api/image/1/profiles/level1.json`,Qe=`http://iiif.io/api/image/1/level2.json`,$e=`http://iiif.io/api/image/1/profiles/level2.json`,et=`http://iiif.io/api/image/2/level0.json`,tt=`http://iiif.io/api/image/2/profiles/level0.json`,nt=`http://iiif.io/api/image/2/level1.json`,rt=`http://iiif.io/api/image/2/profiles/level1.json`,it=`http://iiif.io/api/image/2/level2.json`,at=`http://iiif.io/api/image/2/profiles/level2.json`,ot=`level0`,st=`level1`,ct=`level2`,lt=`http://iiif.io/api/image/2/level0`,ut=`http://iiif.io/api/image/2/level1`,dt=`http://iiif.io/api/image/2/level2`,ft=[dt,Re,Ve,We,qe,Qe,$e,it,at,ct],pt=[...ft,ut,Le,Be,Ue,Ke,Xe,Ze,nt,rt,st],mt=[lt,ut,dt,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge,Ke,qe,Je,Ye,Xe,Ze,Qe,$e,et,tt,nt,rt,it,at,ot,st,ct],ht={extraFormats:[`jpg`],extraQualities:[`default`],extraFeatures:[`sizeByWhListed`]},gt={extraFormats:[`jpg`],extraQualities:[`default`],extraFeatures:[`baseUriRedirect`,`cors`,`jsonldMediaType`,`regionByPx`,`regionSquare`,`sizeByWhListed`,`sizeByH`,`sizeByW`,`sizeByWh`]},_t={extraFormats:[`jpg`,`png`],extraQualities:[`default`],extraFeatures:[`baseUriRedirect`,`cors`,`jsonldMediaType`,`regionByPct`,`regionByPx`,`regionSquare`,`rotationBy90s`,`sizeByWhListed`,`sizeByConfinedWh`,`sizeByH`,`sizeByPct`,`sizeByW`,`sizeByWh`]};function vt(e){return ft.indexOf(e)===-1?pt.indexOf(e)===-1?ht:gt:_t}function yt(e){let t=e?Array.isArray(e.profile)?e.profile:[e.profile]:[],n={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let e of t)if(typeof e==`string`&&(e=vt(e)),e){if(e.formats)for(let t of e.formats)n.extraFormats.indexOf(t)===-1&&n.extraFormats.push(t);if(e.qualities)for(let t of e.qualities)n.extraQualities.indexOf(t)===-1&&n.extraQualities.push(t);if(e.supports)for(let t of e.supports)n.extraFeatures.indexOf(t)===-1&&n.extraFeatures.push(t);if(e.maxHeight&&(n.maxHeight=e.maxHeight),e.maxWidth&&(n.maxWidth=e.maxWidth),e.maxArea&&(n.maxArea=e.maxArea),e.extraFormats)for(let t of e.extraFormats)n.extraFormats.indexOf(t)===-1&&n.extraFormats.push(t);if(e.extraQualities)for(let t of e.extraQualities)n.extraQualities.indexOf(t)===-1&&n.extraQualities.push(t);if(e.extraFeatures)for(let t of e.extraFeatures)n.extraFeatures.indexOf(t)===-1&&n.extraFeatures.push(t);e.maxHeight&&(n.maxHeight=e.maxHeight),e.maxWidth&&(n.maxWidth=e.maxWidth),e.maxArea&&(n.maxArea=e.maxArea)}if(e.extraFormats)for(let t of e.extraFormats)n.extraFormats.indexOf(t)===-1&&n.extraFormats.push(t);if(e.extraFeatures)for(let t of e.extraFeatures)n.extraFeatures.indexOf(t)===-1&&n.extraFeatures.push(t);if(e.extraQualities)for(let t of e.extraQualities)n.extraQualities.indexOf(t)===-1&&n.extraQualities.push(t);return n}function bt(e){try{if(e===`full`)return{full:!0};if(e===`square`)return{square:!0};let t=e.startsWith(`pct:`),n=e.substr(t?4:0).split(`,`).map(e=>parseFloat(e));return{x:n[0],y:n[1],w:n[2],h:n[3],percent:t}}catch{throw Error(`Expected 'full', 'square' or 'x,y,w,h'. Found `+e)}}function xt(e){let t={upscaled:!1,max:!1,confined:!1};if(e[0]===`^`&&(t.upscaled=!0,e=e.slice(1)),e===`max`||e===`full`)return t.max=!0,t.serialiseAsFull=e===`full`,t;if(e[0]===`!`&&(t.confined=!0,e=e.slice(1)),e[0]===`p`)return t.percentScale=parseFloat(e.slice(4)),t;let n=e.split(`,`).map(e=>e.trim());return n.length&&typeof n[0]<`u`&&(n[0]!==``&&(t.width=parseInt(n[0],10)),typeof n[1]<`u`&&n[1]!==``?(t.height=parseInt(n[1],10),t.version=2):t.version=3),t}function St(e){let t={angle:0};if(e[0]===`!`&&(t.mirror=!0,e=e.substr(1)),t.angle=parseFloat(e)%360,Number.isNaN(t.angle))throw Error(`Invalid rotation ${e}`);return t}function Ct(e,t=``){let n=e.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!n)throw Error(`Invalid or unknown input ${e}`);let r=n[2],i=n[3],a=n[4];if(a[0]===`/`&&(a=a.substring(1)),t.length>0){if(t[0]===`/`&&(t=t.substring(1)),t!==a.substring(0,t.length))throw Error(`Path does not start with prefix (path: ${a}, prefix: ${t})`);a=a.substring(t.length)}return{scheme:r,server:i,path:a,prefix:t}}function wt(e,t=``){let{path:n,scheme:r,server:i,prefix:a}=Ct(e,t),o=(n||``).split(`/`).reverse(),[s,c,l,u,...d]=o,f=d.reverse().filter(Boolean).join(`/`);if(o.length===1||s===``)return{type:`base`,scheme:r,server:i,prefix:a,identifier:f};if(s===`info.json`){let[,...e]=o;return{type:`info`,scheme:r,server:i,prefix:a,identifier:e.reverse().filter(Boolean).join(`/`)}}let p=(s||``).split(`.`);if(typeof p[1]>`u`||typeof p[0]>`u`||typeof u>`u`||typeof l>`u`||typeof c>`u`)throw Error(`Invalid image request`);return{type:`image`,scheme:r,server:i,prefix:a,identifier:f,originalPath:n,region:bt(u),size:xt(l),rotation:St(c),quality:p[0],format:p[1]}}function Tt(e){let t=wt(M(e.id));if(t.type!==`info`)throw Error(`Invalid service URL`);let n=yt(e);return{identifier:t.identifier,originalPath:``,server:t.server,prefix:t.prefix,scheme:t.scheme,type:`image`,quality:n.extraQualities.indexOf(`default`)===-1?n.extraQualities[0]:`default`,region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:`jpg`,rotation:{angle:0}}}function Et(e,t,n){let r=n.length,i=[];for(let t=0;t<r;t++){let r=n[t];if(r){let t=r.width;i.push(e/t)}}return i}function Dt(e,t,n){let r=n.length,i=[];for(let a=0;a<r;a++){let r=n[a];r&&i.push({width:Math.floor(e/r),height:Math.floor(t/r)})}return i}function N(e){if(e[`@id`])return e[`@id`];if(e.id)return e.id}function P(e){if(!e||!e.profile||!N(e))return!1;let t=Array.isArray(e.profile)?e.profile:[e.profile];for(let e of t)if(typeof e==`string`&&mt.indexOf(e)!==-1)return!0;return!1}function Ot(e){if(!P(e))return!1;let t=Array.isArray(e.profile)?e.profile:[e.profile];for(let e of t)if(typeof e==`string`){if(pt.indexOf(e)!==-1)return!0}else{let t=[...e.supports||[],...e.extraFeatures||[]];if(t.indexOf(`regionByPx`)!==-1&&(t.indexOf(`sizeByW`)!==-1||t.indexOf(`sizeByWh`)!==-1))return!0}return!1}function F(e,t){if(t&&t.profile){let n=t.profile;if(n){let t=Array.isArray(n)?n:[n];return t.includes(`level${e}`)||t.includes(`http://iiif.io/api/image/2/level${e}.json`)||t.includes(`http://iiif.io/api/image/1/level${e}.json`)||t.includes(`http://iiif.io/api/image/1/profiles/level${e}.json`)}}return!1}function I(e){return P(e)?F(0,e)?0:F(1,e)?1:F(2,e)?2:null:null}function kt(e){return(e[`@context`]?Array.isArray(e[`@context`])?e[`@context`]:[e[`@context`]]:[]).indexOf(`http://iiif.io/api/image/3/context.json`)!==-1}function At(e){if(!Ot(e))return[];let t=[],n=Array.isArray(e.profile)?e.profile:[e.profile],r=n.length;for(let t=0;t<r;t++){let r=n[t];if(r&&typeof r!=`string`&&(r.maxHeight||r.maxWidth))return[{id:N(e),type:`variable`,minWidth:0,minHeight:0,maxHeight:r.maxHeight||r.maxWidth,maxWidth:r.maxWidth||r.maxHeight,level:I(e),version:e[`@context`]===`http://iiif.io/api/image/3/context.json`?3:2}]}if(e.tiles){let n=e.tiles.length;for(let r=0;r<n;r++){let n=e.tiles[r];n&&(n.height||n.width)&&t.push({id:N(e),type:`variable`,minHeight:0,minWidth:0,maxHeight:n.height||n.width,maxWidth:n.width,level:I(e),version:kt(e)?3:2})}}return t}function jt(e){let t=e.match(/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/);if(t&&t[4]&&t[5]){let n=t[1],r=parseInt(t[4],10),i=parseInt(t[5],10),a=t[7];if((n===`max`||n===`full`)&&r&&i&&a)return{type:`fixed`,id:e,height:i,width:r}}return{type:`unknown`,id:e}}function Mt(e){if(e[`@type`])return e[`@type`];if(e.type)return e.type}function Nt(e){if(typeof e==`string`)return jt(e);let t=Mt(e);if(t!==`Image`&&t!==`sc:Image`)return null;let n=e,r=N(n);return r?r&&n.width&&n.height?{id:r,type:`fixed`,width:n.width,height:n.height,unsafe:!0}:jt(r):null}function Pt(e){return P(e)?(e&&e.sizes?e.sizes:[]).map(t=>({id:N(e),type:`fixed-service`,height:t.height,width:t.width,level:I(e),version:kt(e)?3:2})):[]}function Ft(e){let t=[],n=e.length;for(let r=0;r<n;r++){let n=e[r];if(!n)continue;let i=Pt(n);i.length&&t.push(...i);let a=At(n);a.length&&t.push(...a)}return t}function It(e){let t=e.service?Array.isArray(e.service)?e.service:[e.service]:[],n=t.length,r=[];for(let e=0;e<n;e++)P(t[e])&&r.push(t[e]);return r}function Lt(e,t=!0,n){let r=[],i=Nt(e);if(i===null)return r;let a=e;if(r.push(i),t&&a&&a.width&&a.height){let e=[],t=It(a);for(let r of t){let t={id:N(r),width:a.width,height:a.height};if(n.canLoadSync(t)){let r=n.loadServiceSync(t);r&&(r.height||(r.height=a.height),r.width||(r.width=a.width),e.push(...Ft([r])))}}if(e.length)return r.push(...e),r}return a.service&&r.push(...Ft(a.service)),r}function Rt({x:e=0,y:t=0,w:n,h:r,full:i,square:a,percent:o}){if(i)return`full`;if(a)return`square`;if(typeof n>`u`||typeof r>`u`)throw Error(`RegionParameter: invalid region`);let s=`${e},${t},${n},${r}`;return o?`pct:${s}`:s}function zt({max:e,percentScale:t,upscaled:n,confined:r,width:i,height:a,serialiseAsFull:o,version:s}){let c=[];return n&&c.push(`^`),e?(c.push(o?`full`:`max`),c.join(``)):(r&&c.push(`!`),t&&c.push(`pct:${t}`),i&&c.push(`${i}`),c.push(`,`),a&&s===3&&c.push(`${a}`),c.join(``))}function Bt(e){return`${e.mirror?`!`:``}${(e.angle||0)%360}`}function Vt(e,t){let n=e.prefix.startsWith(`/`)?e.prefix.substr(1):e.prefix,r=`${e.scheme}://${e.server}/${n?`${n}/`:``}${e.identifier}`;if(e.type===`base`)return r;if(e.type===`info`)return`${r}/info.json`;let{size:i}=e,{region:a,rotation:o,format:s,quality:c}=e;if(t){let e=t[`@context`]?Array.isArray(t[`@context`])?t[`@context`]:[t[`@context`]]:[],n=e.indexOf(`http://iiif.io/api/image/2/context.json`)!==-1,r=e.indexOf(`http://iiif.io/api/image/3/context.json`)!==-1;if((i.width===t.width&&!i.height||i.height===t.height&&!i.width||i.width===t.width&&i.height===t.height)&&(i={...i,max:!0}),n&&(i.max&&!i.serialiseAsFull&&(i={...i,serialiseAsFull:!0}),!i.max&&i.width&&i.height&&(i={...i,height:void 0}),i={...i,version:2}),r){if(i.max&&i.serialiseAsFull&&(i={...i,serialiseAsFull:!1}),i.width&&!i.height&&t.width&&t.height){let e=t.height/t.width;i={...i,height:Math.ceil(i.width*e)}}i={...i,version:3}}}return[r,Rt(a),zt(i),Bt(o),`${c}.${s}`].filter(Boolean).join(`/`)}function L(e,t,n){let r=Tt({"@context":e.version===3?`http://iiif.io/api/image/3/context.json`:`http://iiif.io/api/image/2/context.json`,id:M(N(e)),profile:e.level===null||typeof e.level>`u`?`level0`:`level${e.level}`,type:e.version===3?`ImageService3`:`ImageService2`});if(r.type!==`image`)throw Error(`Invalid service`);return r.size.max=!1,r.size.width=t,r.size.height=n,{id:Vt(r),type:`fixed`,width:t,height:n||e.height/(e.width||1)*t,unsafe:e.width>t}}function R(e){let t=e.replace(/(https?:\/\/)?(www.)?/i,``);return t.indexOf(`/`)===-1?t:t.split(`/`)[0]}function Ht(e,t,n){let r=e.width?e.width:e.maxWidth;return n.height<=e.maxHeight&&n.width<=e.maxWidth&&n.height>=e.minHeight&&n.width>=e.minWidth&&(!t||Math.abs(n.width-r)<Math.abs(t.width-r))}function Ut(e,t){let n=[],r=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},e),i=(e,t=0)=>r.explain?n.push(Array(t).fill(0).map(e=>` `).join(``)+e().trim()):void 0,a=[],o=[],s=null;i(()=>`Using configuration: ${JSON.stringify(r,null,2)}`);let c=(e,t)=>{if(i(()=>`Swapping choice`,3),Ht(r,t,e)){if(r.preferFixedSize&&e.unsafe){i(()=>`We found an image that was marked as unsafe, but it was the best size. (${e.id})`,4),o.push(e);return}r.returnAllOptions&&t&&o.push(t),i(()=>`We found a new image that was the best size. (${e.id})`,4),s=e}else r.returnAllOptions&&o.push(e)};i(()=>`The input shows we have ${t.length} list(s) of candidates to choose from.`);let l=t.length;for(let e=0;e<l;e++){let n=t[e]();i(()=>`Candidate group ${e}: ${JSON.stringify(n,null,2)}`,1);let o=n.length;i(()=>`Checking candidate list number ${e} and found ${o} potential ways of creating image(s)`,1);for(let e=0;e<o;e++){let t=n[e];i(()=>`-> Checking candidate ${e}`,1),t.type===`unknown`&&r.atAnyCost&&(i(()=>`We've found an unknown image type, adding this to the "last resort" list`,2),a.push(t)),t.type===`fixed`&&(t.unsafe?(i(()=>`We've found an unsafe fixed image type, adding this to the "last resort" list`,2),a.push(t)):(i(()=>`We've found a fixed size image, checking if it matches the request`,2),c(t,s))),t.type===`fixed-service`&&(r.unsafeImageService?(i(()=>`Checking for an image from the tile source, without calculating the right height and width (unsafeImageService)`,2),c(L(t,r.width,r.height),s)):(i(()=>`Checking for an image from the tile source 3`,2),c(L(t,t.width,t.height),s))),t.type===`variable`&&t.maxWidth&&c(L({id:t.id,type:`fixed-service`,width:t.maxWidth,height:t.maxWidth,level:t.level,version:t.version},t.maxWidth),s)}if(s&&!r.returnAllOptions){if(s.unsafe||r.allowUnsafe)continue;i(()=>`We found a match in choice list number ${e}, no searching any more`);break}}return r.atAnyCost&&o.length===0?(i(()=>s?`We found an image! ${s.id} of type ${s.type}`:`We found no images, but "atAnyCost" is set, so returning that`),{best:s||a[0]||null,fallback:a.slice(1),log:n}):r.returnAllOptions?(i(()=>`Returning all options that we have found`),{best:(r.atAnyCost?s||o[0]||a[0]:s||o[0])||null,fallback:[...o,...a],log:n}):(i(()=>`Returning the best image that we found, and a fallback`),{best:s||o[0]||null,fallback:s?o:o.slice(1),log:n})}function Wt(e,t,n){let r=e>t?e:t,i=n.length,a=[];for(let e=0;e<i;e++){let t=n[e];if(!t||t.scaleFactors.length===0)continue;let i=t.scaleFactors[0];if(!i)continue;let o=r/i,s=[i];for(;o>=t.width;)i*=2,s.push(i),o/=2;a.push({...t,scaleFactors:s})}return a}function Gt(e,t){if(e.length!==t.length)return!1;if(e.length===0&&t.length===0)return!0;let n=e.length,r=!0;for(let i=0;i<n;i++){let n=e[i],a=t[i];if(n.width!==a.width||n.height!==a.height){r=!1;break}}if(r)return!0;let i=0;for(let r=0;r<n;r++)for(let a=0;a<n;a++)if(e[r].width===t[a].width&&e[r].height===t[a].height){i++;break}return i===n}function Kt(e){return F(0,e)}new class{constructor(e={}){j(this,`config`,{verificationsRequired:1,approximateServices:!1,enableFetching:!0,disableThrottling:!1}),j(this,`fetchingCount`,0),j(this,`imageServices`,{}),j(this,`knownImageServers`,{}),this.config=Object.assign(this.config,e)}setConfig(e){Object.assign(this.config,e)}sample(e,t,n=!0){let r=R(N(e)),i=M(N(e)),a=this.knownImageServers[r];return this.imageServices[i]=Object.assign(e,{real:!0}),!a&&e.tiles&&!Kt(e)?(this.knownImageServers[r]={verifications:0,malformed:!1,root:r,preLoaded:n,sampledId:N(e),verified:!1,server:null,result:{context:e[`@context`]||[],sampledProfile:e.profile,resourceServiceRatio:t&&e.height?t.height/e.height:1,sampledSizes:e.sizes||[],sizeRatios:Et(e.width,e.height,e.sizes||[]),sampledTiles:e.tiles||[]}},!0):this.verify(e)}preLoad(e,t=!0){this.knownImageServers[e.root]=e,t&&(this.knownImageServers[e.root].malformed=!1,this.knownImageServers[e.root].verifications=this.config.verificationsRequired)}predict(e,t=!1,n=!1){let r=e?.source,i=R(N(e)),a=this.knownImageServers[i],o=M(N(e));return this.imageServices[o]?this.imageServices[o]||null:!this.config.approximateServices||!a||!a.result||!(r?.height||e.height)||!(r?.width||e.width)||!n&&(a.malformed||a.verifications<this.config.verificationsRequired)||Kt(e.source)?null:(this.imageServices[o]||(this.imageServices[o]={"@context":a.result.context,"@id":N(e),id:N(e),protocol:`http://iiif.io/api/image`,tiles:r?.tiles||Wt(e.width,e.height,a.result.sampledTiles),sizes:r?.sizes||Dt(Math.round(e.width/a.result.resourceServiceRatio),Math.round(e.height/a.result.resourceServiceRatio),a.result.sizeRatios),profile:r?.profile||a.result.sampledProfile,height:r?.height||e.height,width:r?.width||e.width,real:!1}),this.imageServices[o]||null)}async getThumbnailFromResource(e,t,n=!0,r=[]){let i=e?await this.getImageCandidates(e,n):[];return Ut(t,[()=>r,()=>i])}async getImageCandidates(e,t=!0){let n=e;if(t&&n&&n.height&&n.width){let e=It(n);for(let t of e){let e={id:N(t),width:t.width?t.width:n.width,height:t.height?t.height:n.height,source:t};await this.loadService(e)}}return Lt(e,t,this)}async verify(e){let t=this.predict(e,!1,!0),n=await this.fetchService(N(e));if(!t)return!1;let r=t.height===n.height&&t.width===n.width&&t[`@context`]===n[`@context`]&&Gt(t.sizes||[],n.sizes||[]);if(r){let t=R(N(e)),n=this.knownImageServers[t];n&&(n.verifications+=1,n.verifications>=this.config.verificationsRequired&&(n.verified=!0))}return r}canLoadSync(e){let t=typeof e==`string`?e:N(e),n=M(t);if(this.imageServices[n])return!0;let r=this.knownImageServers[R(t)];return!!(r&&!r.malformed&&r.verifications>=this.config.verificationsRequired)}async markAsMalformed(e){return this.knownImageServers[R(N(e))].malformed=!0,this.loadService(e,!0)}async fetchService(e,t=!1){let n=M(e),r=this.imageServices[n];if(r&&(!t||r.real))return r;if(!this.config.enableFetching)throw Error(`Fetching is not enabled`);let i=await this.fetch(n).then(e=>e.json());return!i.id&&i[`@id`]&&(i.id=i[`@id`]),i.id!==e&&(i.id=e,i[`@id`]&&(i[`@id`]=e)),this.imageServices[n]=Object.assign(i,{real:!0}),this.imageServices[n]}async fetch(e,t){return fetch(e,t)}async loadService(e,t=!1){if(!this.config.disableThrottling){let e=!0;for(;e;)if(this.fetchingCount>=this.config.verificationsRequired)await new Promise(e=>setTimeout(e,500));else{e=!1;break}}let n=this.knownImageServers[R(N(e))];if(n&&!n.malformed&&!t){await n.result;let t=this.loadServiceSync(e);if(t)return t}this.fetchingCount++;let r=await this.fetchService(N(e),t);return this.fetchingCount--,r.real&&this.sample(r,e),r}loadServiceSync(e){let t=M(N(e));return this.imageServices[t]?this.imageServices[t]:this.config.approximateServices?this.predict(e):null}};const z={canvasInteraction:!0,spatial:!0,async run(e,{vault:t,options:n}){if(e&&e.type===`Annotation`&&n.targetType===`Annotation`){let n=t.get(e),r=n.target;if(!(r&&r.source?.type===`Canvas`))return;let i=r.source,a=t.get(i);if(!a.items||a.behavior.includes(`multi-image`)||!t.get(a.items[0]))return;let o=Array.isArray(n.body)?n.body[0]:n.body;if(o.type===`SpecificResource`&&o.selector)return;let s=t.get(n.body)[0],c=(s.service||[]).find(e=>P(e));c&&c.width&&c.height&&(c.width!==s.width&&t.modifyEntityField({id:s.id,type:`ContentResource`},`width`,c.width),c.height!==s.height&&t.modifyEntityField({id:s.id,type:`ContentResource`},`height`,c.height))}}};function B(e){let{"@id":t,"@type":n,...r}=e,i=`${e[`@context`]||``} ${e.profile||``}`.match(/\/(?:image|image-api)\/([123])(?:[./])/);return{...r,id:e.id||t,type:e.type||n||`ImageService${i?.[1]||`2`}`}}function qt(e,t={},n=!1){let r=[];t.compact!==`compact`&&r.push(`width`,`height`),(n||t.includeSizes===!0)&&r.push(`sizes`),(n||t.includeTiles===!0)&&r.push(`tiles`);let i=B(e);return{id:i.id,type:i.type,profile:i.profile,...Object.fromEntries(r.filter(e=>i[e]!==void 0).map(e=>[e,i[e]]))}}async function Jt(e,t){let n=B(e.service),r=(0,b.createImageServiceRequest)(n),i=(0,b.imageServiceRequestToString)({identifier:r.identifier,server:r.server,scheme:r.scheme,type:`image`,size:{max:!e.size?.width&&!e.size?.height,confined:!1,upscaled:!1,...e.size||{}},format:`jpg`,region:{full:!0},rotation:{angle:0},quality:`default`,prefix:r.prefix,originalPath:r.originalPath});return t.embed({id:i,type:`Image`,format:e.format||`image/jpeg`,height:e.height||n.height,width:e.width||n.width,service:e.embedService===!1?void 0:[qt(n,t.config,t.options.parent?.property===`thumbnail`)]})}function V(e){return e.endsWith(`default.jpg`)?(0,b.imageServiceRequestToString)({...(0,b.parseImageServiceRequest)(e),type:`info`}):(0,b.canonicalServiceUrl)(e)}function H(e){let t=e.options.initialData,n=t.url?V(t.url):``,[r,i]=(0,m.useState)(n||``);return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries()),i=r.url;if(i){let t=V(i);if(!t)throw Error(`Invalid image service request`);fetch(t).then(e=>e.json()).then(t=>{e.runCreate({url:r.url,service:t})})}},children:[(0,h.jsx)(`div`,{className:`flex gap-2 items-center`,children:(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`url`,children:`Link to image service`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:t.url||``,onPaste:e=>{let t=e.clipboardData.getData(`text/plain`);i(t?V(t):``)},onBlur:e=>i(e.currentTarget.value?V(e.currentTarget.value):``)})]})}),(0,h.jsx)(`div`,{className:`relative flex z-0 my-5 h-96 min-h-0 min-w-0 overflow-hidden bg-gray-200 rounded items-center justify-center`,children:r.trim()?(0,h.jsx)(ee.ErrorBoundary,{fallbackRender:()=>(0,h.jsx)(`div`,{children:`Invalid service`}),children:(0,h.jsx)(Yt,{src:r},r)}):(0,h.jsx)(`div`,{className:`text-grey-600`,children:`Preview`})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,isDisabled:!r,children:`Create`})})]})})}function Yt({src:e}){let t=(0,_.useImage)({id:e},{size:{width:512}});return t?(0,h.jsx)(`div`,{className:`h-full`,children:(0,h.jsx)(`img`,{className:`w-full h-full object-contain`,src:t})}):(0,h.jsx)(Ce,{})}async function Xt(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=await(0,u.creatorHelper)(t,`Annotation`,`body`,`@manifest-editor/image-service-creator`)(e,{parent:{resource:n,property:`body`}});if(r===`Annotation`)return{...n,body:[i],motivation:e.motivation||`painting`,target:t.getTarget()};if(r===`Canvas`){let r=t.generateId(`canvas`),a=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:[i],target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:a,type:`AnnotationPage`,items:[o]}),c;return e.service?.sizes&&(c=await(0,u.creatorHelper)(t,`Canvas`,`thumbnail`,`@manifest-editor/thumbnail-image`)({service:e.service,width:e.thumbnailSize||400})),t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled canvas`]},height:i.resource.height||1e3,width:i.resource.width||1e3,thumbnail:c?[c]:void 0,items:[s]})}}function Zt(e){return(0,h.jsx)(H,{...e})}const U=(0,u.defineCreator)({id:`@manifest-editor/image-service-creator`,configKey:`iiif-image-services`,create:Jt,label:`Image Service`,summary:`Add an image from Image Service`,icon:(0,h.jsx)(f.IIIFLogo,{style:{padding:10}}),tags:[`image`,`image-service`],async supportsResource(e,t){if(!S(e))return!1;let n=V(e);if(!n)return!1;let r=await C(n,t);return ae(r)?{initialData:{url:e,service:r}}:!1},render(e){return(0,h.jsx)(H,{...e})},resourceType:`ContentResource`,resourceFields:[`id`,`type`,`height`,`width`,`format`,`service`],supports:{initialData:!0,parentFields:[`logo`,`body`,`thumbnail`,`items`],custom(e,t){return e.property!==`items`||e.resource.type===`ContentResource`&&t.get(e.resource,{skipSelfReturn:!1})?.type===`Choice`}}}),Qt=(0,u.defineCreator)({id:`@manifest-editor/image-service-annotation`,create:Xt,label:`IIIF Image`,dependencies:[`@manifest-editor/image-service-creator`],summary:`IIIF Image service`,tags:[`image`,`image-service`],icon:(0,h.jsx)(f.IIIFLogo,{style:{padding:10}}),render(e){return(0,h.jsx)(Zt,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supportsResource:U.supportsResource,supports:{initialData:!0,onlyPainting:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},sideEffects:[z,A,k],staticFields:{type:`Annotation`}});async function $t(e,t){if(!e.height||!e.width){let t=await(0,y.getImageDimensions)(e.url);t&&(e.height=t.height,e.width=t.width)}return t.embed({id:e.url,type:`Image`,format:e.format||await(0,y.getFormat)(e.url),height:e.height,width:e.width,service:e.service?Array.isArray(e.service)?e.service:[e.service]:void 0})}function W(e){let t=e.options.initialData;return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries());r.url&&e.runCreate({url:r.url})},children:[(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`id`,children:`Link to Image`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:t.url||``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create`})]})})}async function en(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=await(0,u.creatorHelper)(t,`Annotation`,`body`,`@manifest-editor/image-url-creator`)(e,{parent:{resource:n,property:`body`}});if(r===`Annotation`)return t.embed({...n,body:[i],motivation:e.motivation||`painting`,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),a=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:[i],target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:a,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled canvas`]},height:i.resource.height||1e3,width:i.resource.width||1e3,items:[s]})}throw Error(`Unsupported target type`)}function tn(e){return(0,h.jsx)(W,{...e})}const G=(0,u.defineCreator)({id:`@manifest-editor/image-url-creator`,create:$t,label:`Image`,summary:`Image from a URL`,icon:(0,h.jsx)(f.AddImageIcon,{}),tags:[`image`],async supportsResource(e,t){if(!S(e))return!1;let n=V(e);if(n)try{if(ae(await t.json(n)))return!1}catch{}let r=await T(e,t);return r.startsWith(`image/`)||E(e,[`.jpg`,`.jpeg`,`.png`,`.gif`,`.webp`])?{initialData:{url:e,format:r||void 0}}:!1},render(e){return(0,h.jsx)(W,{...e})},resourceType:`ContentResource`,resourceFields:[`format`],supports:{initialData:!0,parentFields:[`logo`,`body`,`thumbnail`,`items`],custom(e,t){return e.property!==`items`||e.resource.type===`ContentResource`&&t.get(e.resource,{skipSelfReturn:!1})?.type===`Choice`}},staticFields:{type:`Image`}}),nn=(0,u.defineCreator)({id:`@manifest-editor/image-url-annotation`,create:en,label:`Image`,dependencies:[`@manifest-editor/image-url-creator`],summary:`Image from URL`,tags:[`image`],icon:(0,h.jsx)(f.AddImageIcon,{}),render(e){return(0,h.jsx)(tn,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supportsResource:G.supportsResource,supports:{initialData:!0,onlyPainting:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},sideEffects:[z,A,k],staticFields:{type:`Annotation`}});async function rn(e,t){let n=[],r=(0,u.creatorHelper)(t,`Annotation`,`body`,`@manifest-editor/image-url-creator`);for(let i of e.images)n.push(await r(i,t.options));return n}function K(e){return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(f.Form.Form,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries());r.urls&&e.runCreate({images:r.urls.split(`
97
+ `).map(e=>({url:e}))})},children:[(0,h.jsxs)(f.Form.InputContainer,{className:`mb-4`,children:[(0,h.jsx)(f.Form.Label,{children:`Enter a list of URLs (one per line)`}),(0,h.jsx)(f.Form.TextArea,{"aria-label":`Image URLs`,name:`urls`,rows:`10`,defaultValue:e.options.initialData?.images?.map(e=>e.url).join(`
98
+ `)||``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create`})]})})}async function an(e,t){let n=[],r=(0,u.creatorHelper)(t,`AnnotationPage`,`items`,`@manifest-editor/image-url-annotation`);for(let i of e.images)n.push(await r(i,t.options));return n}const on=(0,u.defineCreator)({id:`@manifest-editor/image-url-list-annotation`,create:an,label:`List of Images`,dependencies:[`@manifest-editor/image-url-annotation`],summary:`List of Images from URLs`,tags:[`image`],icon:(0,h.jsx)(f.ImageListIcon,{}),render(e){return(0,h.jsx)(K,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],supports:{onlyPainting:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},sideEffects:[z,A,k],staticFields:{type:`Annotation`}}),sn=(0,u.defineCreator)({id:`@manifest-editor/no-body-annotation`,create:cn,label:`Annotation without body`,summary:`Add an annotation that only has motivation and target`,icon:(0,h.jsx)(f.EmptyCanvasIcon,{}),resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`target`],supports:{initialData:!0,parentTypes:[`AnnotationPage`],parentFields:[`items`],disallowPainting:!0},actionButton:`Create empty annotation`,sideEffects:[],staticFields:{type:`Annotation`}});function cn(e,t){return t.embed({id:t.generateId(`annotation`),type:`Annotation`,label:e?.label,motivation:e.motivation||t.options.initialData?.motivation||`highlighting`,target:t.getTarget()})}function ln({media:e,onError:t,duration:n,onDuration:r,onDimensions:i}){let[{element:a,currentTime:o,progress:s},c,l]=(0,_.useSimpleMediaPlayer)({duration:n});return(0,h.jsxs)(_.MediaPlayerProvider,{element:a,state:c,actions:l,currentTime:o,progress:s,children:[(0,h.jsx)(`div`,{style:{maxHeight:400,aspectRatio:`${e.width}/${e.height}`,position:`relative`},children:(0,h.jsx)(_.CanvasPanel.VideoHTML,{element:a,media:e,playPause:l.playPause})}),(0,h.jsx)(Ee,{onError:t,onDuration:r,onDimensions:i})]})}async function un(e,t){let n={id:t.generateId(`annotation`),type:`Annotation`},r=t.options.targetType,i=t.embed({id:e.url,type:`Video`,format:`video/mp4`,width:e.width,height:e.height,duration:e.duration||0});if(r===`Annotation`)return t.embed({...n,label:(0,d.getValue)(e.label)&&e.label,motivation:e.motivation||t.options.initialData?.motivation||`painting`,body:i,target:t.getTarget()});if(r===`Canvas`){let r=t.generateId(`canvas`),a=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),o=t.embed({...n,motivation:`painting`,body:i,target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),s=t.embed({id:a,type:`AnnotationPage`,items:[o]});return t.embed({id:r,type:`Canvas`,label:(0,d.getValue)(e.label)?e.label:void 0,duration:e.duration||0,width:e.width,height:e.height,items:[s]})}}function dn(e){let[t]=(0,m.useState)(()=>e.options.initialData),[n,r]=(0,m.useState)(t.url||``),[i,a]=(0,m.useState)(t.duration||0),[o,s]=(0,m.useState)(t.width||0),[c,l]=(0,m.useState)(t.height||0),[u,d]=(0,m.useState)(``),[g,_]=(0,m.useState)(t.label||{en:[``]});return(0,m.useEffect)(()=>{d(``);let e=n===t.url?t:{};if(a(e.duration||0),s(e.width||0),l(e.height||0),n){let e=n.split(`/`).pop()?.split(`.`).shift();_(n===t.url&&t.label?t.label:{en:[e||``]})}},[n,t]),(0,h.jsxs)(f.PaddedSidebarContainer,{children:[u?(0,h.jsx)(f.ErrorMessage,{children:u}):null,(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`video-url`,children:`URL`}),(0,h.jsx)(p.Input,{type:`text`,id:`video-url`,value:n,onChange:e=>r(e.target.value)})]}),n&&!u?(0,h.jsx)(`div`,{children:(0,h.jsx)(p.LanguageFieldEditor,{containerId:`label`,focusId:`label_`,label:`Label`,fields:g,onSave:e=>_(e.toInternationalString())},`${n}__${i}`)}):null,n&&!u?(0,h.jsx)(`div`,{className:`mb-4 bg-black`,children:(0,h.jsx)(ln,{duration:i,onDuration:e=>a(e),onError:e=>d(e),media:{url:n,duration:i,height:c,width:o,type:`Video`},onDimensions:(e,t)=>{s(e||0),l(t||0)}})}):null,!u&&(i||o||c)?(0,h.jsx)(p.InputContainer,{$wide:!0,children:(0,h.jsx)(p.DimensionsTriplet,{widthId:`width`,width:o||0,changeWidth:e=>s(e),heightId:`height`,height:c||0,changeHeight:e=>l(e),durationId:`duration`,duration:i||0,changeDuration:e=>a(e)})}):null,(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`button`,onPress:()=>{e.runCreate({url:n,duration:i,label:g,width:o,height:c})},isDisabled:!n||!!u,children:`Add video`})]})}const fn=(0,u.defineCreator)({id:`@manifest-editor/video-annotation`,create:un,label:`Video`,summary:`Video annotation`,icon:(0,h.jsx)(f.VideoIcon,{}),render(e){return(0,h.jsx)(dn,{...e})},resourceType:`Annotation`,resourceFields:[`id`,`type`,`motivation`,`body`,`target`],additionalTypes:[`Canvas`],async supportsResource(e,t){return S(e)&&((await T(e,t)).startsWith(`video/`)||E(e,[`.mp4`,`.m4v`,`.webm`,`.mov`]))?{initialData:{url:e}}:!1},supports:{onlyPainting:!0,initialData:!0,parentTypes:[`AnnotationPage`,`Manifest`],parentFields:[`items`]},staticFields:{type:`Annotation`}}),pn=()=>(0,h.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`24px`,viewBox:`0 0 24 24`,width:`24px`,fill:`#000000`,transform:`scale(-1, 1)`,children:(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`rect`,{fill:`none`,height:`24`,width:`24`}),(0,h.jsx)(`path`,{d:`M16,20H2V4h14V20z M18,8h4V4h-4V8z M18,20h4v-4h-4V20z M18,14h4v-4h-4V14z`})]})}),mn=(0,u.defineCreator)({id:`@manifest-editor/empty-annotation-page`,create:(e,t)=>t.embed({id:t.generateId(`annotations`),label:e.label,type:`AnnotationPage`,items:[]}),label:`Empty annotation page`,summary:`AnnotationPage with nothing`,icon:(0,h.jsx)(pn,{}),resourceType:`AnnotationPage`,resourceFields:[`id`,`type`,`items`],supports:{parentTypes:[`Manifest`,`Canvas`,`Range`],parentFieldMap:{Manifest:[`annotations`],Canvas:[`items`,`annotations`],Range:[`annotations`]}}}),q=e=>(0,h.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,height:`1em`,width:`1em`,...e,children:[(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{d:`M5 17v2h14v-2H5zm4.5-4.2h5l.9 2.2h2.1L12.75 4h-1.5L6.5 15h2.1l.9-2.2zM12 5.98 13.87 11h-3.74L12 5.98z`})]});async function hn(e,t){let n=e.url.trim();if(!S(n))throw Error(`Enter an absolute HTTP or HTTPS URL for the WebVTT file.`);let r=t.getParent();if(r?.type!==`Canvas`)throw Error(`WebVTT captions must belong to a Canvas.`);let i=t.embed({id:n,type:`Text`,format:`text/vtt`,...(0,d.getValue)(e.label)?{label:e.label}:{},...e.language?.trim()?{language:e.language.trim()}:{}}),a=t.embed({id:t.generateId(`annotation`),type:`Annotation`,motivation:`supplementing`,body:i,target:r});return t.embed({id:t.generateId(`annotation-page`),type:`AnnotationPage`,items:[a]})}function gn(e){let[t,n]=(0,m.useState)(e.options.initialData?.label||{en:[`Captions in WebVTT format`]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:n=>{n.preventDefault();let r=new FormData(n.currentTarget),i=String(r.get(`url`)||``).trim(),a=String(r.get(`language`)||``).trim();e.runCreate({url:i,label:(0,d.getValue)(t)?t:void 0,language:a||void 0})},children:[(0,h.jsx)(`p`,{id:`vtt-help`,className:`mb-4 text-sm text-gray-600`,children:`Link an existing WebVTT (.vtt) file to this canvas. Host the file at a public URL before adding it.`}),(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`vtt-url`,children:`WebVTT file URL`}),(0,h.jsx)(p.Input,{id:`vtt-url`,name:`url`,type:`url`,required:!0,placeholder:`https://example.org/captions.vtt`,pattern:`https?://.+`,title:`Enter an absolute http:// or https:// URL`,"aria-describedby":`vtt-help`,defaultValue:e.options.initialData?.url||``})]}),(0,h.jsx)(p.LanguageFieldEditor,{focusId:`vtt-label`,label:`Label`,fields:t,onSave:e=>n(e.toInternationalString())}),(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`vtt-language`,children:`Language (BCP 47 code)`}),(0,h.jsx)(p.Input,{id:`vtt-language`,name:`language`,type:`text`,placeholder:`en`,title:`A language code such as en, fr or pt-BR`,defaultValue:e.options.initialData?.language??`en`})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Add captions`})]})})}const _n=(0,u.defineCreator)({id:`@manifest-editor/vtt-annotation-page`,label:`WebVTT captions`,tags:[`captions`],summary:`Link captions to an audio or video canvas`,icon:(0,h.jsx)(q,{}),create:hn,render:e=>(0,h.jsx)(gn,{...e}),resourceType:`AnnotationPage`,resourceFields:[`id`,`type`,`items`],supports:{parentTypes:[`Canvas`],parentFields:[`annotations`],custom:({resource:e},t)=>(0,x.canvasHasAv)(t,e)}}),vn=(0,u.defineCreator)({id:`@manifest-editor/empty-canvas`,create:(e,t)=>{let n=t.generateId(`canvas`),r=t.embed({id:t.generateId(`annotation-page`,{id:n,type:`Canvas`}),type:`AnnotationPage`,items:[]});return{id:n,type:`Canvas`,label:e.label||{en:[``]},height:e.height||1e3,width:e.width||1e3,items:[r]}},label:`Empty canvas`,summary:`No content`,icon:(0,h.jsx)(f.EmptyCanvasIcon,{}),resourceType:`Canvas`,resourceFields:[`id`,`type`,`label`,`height`,`width`,`items`],supports:{parentTypes:[`Manifest`],parentFields:[`items`]}});var yn=process.env.NODE_ENV===`production`,J=`Invariant failed`;function Y(e,t){if(!e){if(yn)throw Error(J);var n=typeof t==`function`?t():t,r=n?`${J}: ${n}`:J;throw Error(r)}}const bn=(0,u.defineCreator)({id:`@manifest-editor/internal-canvas`,create:Sn,label:`Internal canvas link`,summary:`Canvas from the same manifest`,icon:(0,h.jsx)(pn,{}),resourceType:`Canvas`,resourceFields:[`id`,`type`,`label`],supports:{parentTypes:[`Manifest`],parentFields:[`start`]},render:e=>(0,h.jsx)(xn,{...e})});function xn(e){let{runCreate:t}=e,n=(0,_.useManifest)(),r=(0,_.useVault)(),i=(0,m.useMemo)(()=>({canSelectCanvas:!0,canSelectCollection:!1,canSelectManifest:!1,canCropImage:!1,alwaysShowNavigationArrow:!1,multiSelect:!1}),[]),a=(0,m.useMemo)(()=>[{type:`callback`,cb:e=>t({id:e}),label:`Select canvas`,supportedTypes:[`Canvas`],format:{type:`url`}}],[t]),o=(0,m.useMemo)(()=>({saveToLocalStorage:!1,restoreFromLocalStorage:!1,initialHistory:[{url:n?.id,resource:n?.id,route:`/manifest?id=${encodeURIComponent(n?.id||``)}`,metadata:{type:`Manifest`}}]}),[n?.id]);return Y(n,`Manifest is not loaded`),(0,h.jsx)(_.VaultProvider,{vault:r,children:(0,h.jsx)(te.IIIFBrowser,{vault:r,navigation:i,output:a,history:o})})}async function Sn(e,t){let n=t.vault.get({id:e.id,type:`Canvas`},{skipSelfReturn:!0});return Y(n,`Selected Canvas is not loaded`),t.embed(n)}async function Cn(e,t){return t.embed({id:t.generateId(`html/${e.language}`),language:e.language,type:`TextualBody`,format:`text/html`,value:e.body||``})}function wn(e){let{i18n:t}=(0,y.useConfig)(),[n,r]=(0,m.useState)(e.options.initialData?.body??`<p></p>`),[i,a]=(0,m.useState)(e.options.initialData?.language??t.defaultLanguage);return(0,h.jsxs)(f.PaddedSidebarContainer,{children:[(0,h.jsx)(f.HTMLEditor,{className:`border-none`,value:n,onChange:e=>r(e)}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`button`,onPress:()=>{e.runCreate({language:i,body:n})},children:`Create`})]})}const Tn=(0,u.defineCreator)({id:`@manifest-editor/html-body-creator`,create:Cn,label:`HTML Body`,summary:`Add HTML annotation body`,icon:(0,h.jsx)(q,{}),render(e){return(0,h.jsx)(wn,{...e})},resourceType:`ContentResource`,resourceFields:[`id`,`language`,`type`,`format`,`value`],supports:{parentTypes:[`Annotation`,`ContentResource`],parentFields:[`body`,`items`],custom(e,t){if(e.resource.type===`Annotation`)return e.property===`body`;let n=t.get(e.resource,{skipSelfReturn:!1});return e.property===`items`&&n?.type===`Choice`}},staticFields:{type:`TextualBody`,format:`text/html`}});function X(e,t,n,r=0){return`${e}/${Math.floor(t.x)},${Math.floor(t.y)},${Math.floor(t.width)},${Math.floor(t.height)}/${n}/${r}/default.jpg`}async function En(e,t){let n=t.options.targetType,r=e.output,i=[];for(let{resource:a,selector:o,parent:s,rotation:c}of r){let r=a.type,u=new d.Vault;if((n===`Canvas`||n===`Annotation`||n===`ContentResource`)&&r===`Canvas`){let r=a.id,d=s?.type===`Manifest`?s.id:void 0;Y(d,`Could not find Manifest`);let f=u.get({id:d,type:`Manifest`})||await u.loadManifest(d);Y(f,`Manifest not found`);let p=t.config.addManifestMetadataToCanvas!==!1;e.trackManifest?.({requiredStatement:f.requiredStatement,rights:f.rights,...p?{metadata:f.metadata||[]}:{},partOf:[{id:d,type:`Manifest`,label:f.label}]});let m=e=>{if(e.type===`SpecificResource`&&e.source)return{...e,source:m(e.source)};let t=e.type===`Canvas`&&!p?{}:{metadata:f.metadata||[]};return{requiredStatement:f.requiredStatement,rights:f.rights,...t,...e,partOf:[{id:d,type:`Manifest`,label:f.label}]}},h=f.items.find(e=>e.id===r);Y(h,`Canvas not found`);let g=u.get(h),_=l.t(o,c);if(n===`Canvas`&&!_){let e=u.toPresentation3(g);e.label||(e.label={en:[`Untitled canvas`]}),t.vault.loadSync(e.id,m(e)),i.push(t.embed(t.vault.get({id:e.id,type:`Canvas`})));continue}let v=u.get(g.items[0]),y=u.get(v.items[0]);if(n===`Annotation`||n===`Canvas`||n===`ContentResource`){let r=u.toPresentation3(y);r.id=t.generateId(`Annotation`);let a=null,s={width:0,height:0};if(r?.body?.service){let t=r?.body.width,n=r?.body.height;a=(0,b.getImageServices)(r?.body)[0],a&&(!a.width||!a.height)&&(a.width=t,a.height=n),s.width=t,s.height=n,e.trackSize&&e.trackSize(s)}if(_){let u={...r.body},d=``;if(a&&o?.type===`BoxSelector`){let e=a.id||a[`@id`]||``;e&&(u.id=X(e,o.spatial,`max`,c),d=X(e,o.spatial,`512,`,c))}r.body={id:t.generateId(`SpecificResource`,y),type:`SpecificResource`,source:u,selector:_};let f=l.n(o?.type===`BoxSelector`?{width:~~o.spatial.width,height:~~o.spatial.height}:s,c);if(e.trackSize&&e.trackSize(f),n===`ContentResource`){i.push(m(r.body));continue}if(n===`Canvas`){let e=t.generateId(`Canvas`,y);r.target=e;let n=t.generateId(`Page`,y),a=t.embed({id:n,type:`AnnotationPage`,items:[r]}),{width:o,height:s}=f;i.push(t.embed(m({id:e,type:`Canvas`,label:{en:[`Untitled canvas`]},width:o,height:s,thumbnail:d?[t.embed({id:d,type:`Image`,format:`image/jpeg`,width:512,height:Math.round(s/o*512)})]:void 0,items:[a]})));continue}i.push(t.embed(m({...r,target:t.getTarget()})));continue}i.push(t.embed(m({...r,target:t.getTarget()})))}}}return i}const Dn=(0,m.lazy)(()=>Promise.resolve().then(()=>require("./iiif-browser-form.lazy-Df2fAM6b.cjs"))),On=(0,u.defineCreator)({id:`@manifest-editor/iiif-browser-creator`,create:En,label:`IIIF Browser`,summary:`Browse IIIF Resources`,icon:(0,h.jsx)(f.IIIFBrowserIcon,{}),configuration:{fields:[{id:`addManifestMetadataToCanvas`,type:`checkbox`,label:`Add manifest metadata to imported canvases`,summary:`Copies metadata from the source Manifest when the IIIF Browser creates a Canvas.`,defaultValue:!0}]},render(e){return(0,h.jsx)(Dn,{...e})},hiddenModal:!0,tags:[`image`,`image-service`],async supportsResource(e,t){let n=w(await C(e,t));return n===`Manifest`||n===`Collection`||await oe(e)?{initialData:{url:e}}:!1},resourceType:`ContentResource`,resourceFields:[`id`,`language`,`type`,`format`,`value`],additionalTypes:[`Annotation`,`Canvas`],supports:{initialData:!0,onlyPainting:!0,parentTypes:[`Annotation`,`Manifest`,`AnnotationPage`],parentFields:[`body`,`items`],parentFieldMap:{Annotation:[`body`],Manifest:[`items`],AnnotationPage:[`items`]}},sideEffects:[{canvasInteraction:!0,spatial:!0,async run(e,{vault:t,options:n}){if(!(e&&e.type===`Annotation`&&n.targetType===`Annotation`))return;let r=t.get(e),i=r.target;if(!(i&&i.source?.type===`Canvas`))return;let a=(Array.isArray(r.body)?r.body[0]:r.body)?.selector;if(!(a&&(a.type===`iiif:ImageApiSelector`||a.type===`ImageApiSelector`)&&a.region))return;let[o,s,c,l]=a.region.split(`,`).map(Number);if(![o,s,c,l].every(Number.isFinite)||c<=0||l<=0)return;let[u]=t.get(r.body),d=(u?.service||[]).find(e=>(0,b.isImageService)(e)),f=d?.id||d?.[`@id`];if(!f)return;let p=X(f,{x:o,y:s,width:c,height:l},`512,`);t.loadSync(p,{id:p,type:`Image`,format:`image/jpeg`,width:512,height:Math.round(l/c*512),service:[d]}),t.modifyEntityField(i.source,`thumbnail`,[{id:p,type:`ContentResource`}])}},z,A,k],staticFields:{}}),kn=(0,u.defineCreator)({id:`@manifest-editor/image-url-list`,label:`Image URL List`,summary:`Image from a list of URLs`,create:rn,icon:(0,h.jsx)(f.ImageListIcon,{}),render(e){return(0,h.jsx)(K,{...e})},resourceType:`ContentResource`,resourceFields:[`format`],supports:{parentFields:[`logo`,`body`,`thumbnail`]},staticFields:{type:`Image`}});async function An(e,t){return t.embed({id:e.url,type:`Text`,label:e.label,format:`text/plain`})}function jn(e){let[t,n]=(0,m.useState)(e.options.initialData?.label||{en:[`View as text`]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:n=>{n.preventDefault();let r=new FormData(n.target),i=Object.fromEntries(r.entries());i.url&&e.runCreate({url:i.url,label:t})},children:[(0,h.jsx)(p.LanguageFieldEditor,{focusId:`label`,label:`Label`,fields:t,onSave:e=>n(e.toInternationalString())}),(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`id`,children:`Link to plaintext`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:e.options.initialData?.url||``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create`})]})})}const Mn=(0,u.defineCreator)({id:`@manifest-editor/plaintext-creator`,create:An,label:`Plaintext`,summary:`Add link to an plaintext`,icon:(0,h.jsx)(q,{}),render(e){return(0,h.jsx)(jn,{...e})},resourceType:`ContentResource`,resourceFields:[`label`,`format`],supports:{parentFields:[`seeAlso`,`rendering`]},staticFields:{format:`text/plain`}});function Nn(e,t){let n=(0,b.createImageServiceRequest)(B(e));return(0,b.imageServiceRequestToString)({identifier:n.identifier,server:n.server,scheme:n.scheme,type:`image`,size:{max:!1,confined:!1,upscaled:!1,width:t.width,height:t.height},format:`jpg`,region:{full:!0},rotation:{angle:0},quality:`default`,prefix:n.prefix,originalPath:n.originalPath})}function Z(e){return e.endsWith(`default.jpg`)?(0,b.imageServiceRequestToString)({...(0,b.parseImageServiceRequest)(e),type:`info`}):(0,b.canonicalServiceUrl)(e)}async function Pn(e,t){let n=B(e.service),r=n.sizes,i=qt(n,t.config,!0);if(e.thumbnailUrl)return t.embed({id:e.thumbnailUrl,type:`Image`,format:`image/jpeg`,width:e.width,height:e.height,service:[i]});if(r){let a=e.width||400,o=null;for(let e of r)(!o||Math.abs(e.width-a)<Math.abs(o.width-a))&&(o={width:e.width,height:e.height});if(o){let e=Nn(n,o);return t.embed({id:e,type:`Image`,format:`image/jpeg`,width:o.width,height:o.height,service:[i]})}}return null}function Fn(e){let[t,n]=(0,m.useState)(e.options.initialData?.url||``),[r,i]=(0,m.useState)(e.options.initialData?.service||null),[a,o]=(0,m.useState)({width:e.options.initialData?.width||0,height:e.options.initialData?.height||0}),s=(0,m.useMemo)(()=>!r||!a.width||!a.height?null:Nn(r,a),[a,r]);return r?(0,h.jsxs)(f.PaddedSidebarContainer,{children:[(0,h.jsxs)(`div`,{className:`mb-4`,children:[(0,h.jsx)(`div`,{className:`mb-2`,children:r[`@id`]||r.id}),(0,h.jsx)(`div`,{className:`flex gap-2 mb-4`,children:r.sizes?.map(e=>{let t=e.width===a.width;return(0,h.jsxs)(f.ActionButton,{primary:t,isDisabled:t,large:!0,onPress:()=>o(e),children:[e.width,`x`,e.height]},e.width)})}),s?(0,h.jsx)(`img`,{src:s,alt:`preview of selected resource`}):null]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,isDisabled:!s,onPress:()=>{r&&e.runCreate({service:r,width:a.width,height:a.height,thumbnailUrl:s})},children:`Add thumbnail`})]}):(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=new FormData(e.target),n=Object.fromEntries(t.entries()).url;if(n){let e=Z(n);if(!e)throw Error(`Invalid image service request`);fetch(e).then(e=>e.json()).then(e=>{i(e);let t=e.sizes?.[0];t&&o(t)})}},children:[(0,h.jsx)(`div`,{className:`flex gap-2 items-center`,children:(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`url`,children:`Link to image service`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:e.options.initialData?.url||``,onPaste:e=>{let t=e.clipboardData.getData(`text/plain`);n(t?Z(t):``)},onBlur:e=>n(e.currentTarget.value?Z(e.currentTarget.value):``)})]})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,isDisabled:!t,children:`Select size`})})]})})}const In=(0,u.defineCreator)({id:`@manifest-editor/thumbnail-image`,configKey:`iiif-image-services`,create:Pn,label:`Thumbnail from service`,summary:`Add thumbnail from an image service`,icon:(0,h.jsx)(f.ScaledImageIcon,{}),render(e){return(0,h.jsx)(Fn,{...e})},resourceType:`ContentResource`,resourceFields:[`id`,`type`,`format`,`width`,`height`,`service`],supports:{parentFields:[`thumbnail`]}});function Ln(){return(0,h.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`24px`,viewBox:`0 0 24 24`,width:`24px`,fill:`#000000`,children:[(0,h.jsx)(`path`,{d:`M0 0h24v24H0z`,fill:`none`}),(0,h.jsx)(`path`,{d:`M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z`})]})}async function Rn(e,t){return t.embed({id:e.url,type:`Text`,label:e.label,format:`text/html`})}function zn(e){let[t,n]=(0,m.useState)(e.options.initialData?.label||{en:[``]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:n=>{n.preventDefault();let r=new FormData(n.target),i=Object.fromEntries(r.entries());i.url&&e.runCreate({url:i.url,label:t})},children:[(0,h.jsx)(p.LanguageFieldEditor,{focusId:`label`,label:`Label`,fields:t,onSave:e=>n(e.toInternationalString())}),(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`id`,children:`Link`}),(0,h.jsx)(p.Input,{id:`url`,name:`url`,defaultValue:e.options.initialData?.url||``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create link`})]})})}const Bn=(0,u.defineCreator)({id:`@manifest-editor/web-page-creator`,create:Rn,label:`Web page`,summary:`Add link to an external web page`,icon:(0,h.jsx)(Ln,{}),render(e){return(0,h.jsx)(zn,{...e})},resourceType:`ContentResource`,resourceFields:[`label`,`format`],supports:{parentFields:[`seeAlso`,`rendering`,`homepage`]}}),Vn=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function Q(e){let t=(e||``).match(Vn);return t?t[1]:null}function Hn(e){return!!Q(e.youtubeUrl)}function Un(e,t){let n=Q(e.youtubeUrl);return t.embed({id:`https://www.youtube.com/watch?v=${n}`,type:`Video`,service:[{type:`Service`,profile:`http://digirati.com/objectifier`,params:{data:`https://www.youtube.com/embed/${n}`}},{id:`https://www.youtube.com/watch?v=${n}`,type:`Service`,profile:`https://www.youtube.com`}]})}async function Wn(e,t){let n=Un(e,t);if(t.options.targetType===`Canvas`){let r=t.generateId(`canvas`),i=t.generateId(`annotation-page`,{id:r,type:`Canvas`}),a=t.embed({id:t.generateId(`annotation`,{id:i,type:`AnnotationPage`}),type:`Annotation`,motivation:`painting`,body:[n],target:{type:`SpecificResource`,source:{id:r,type:`Canvas`}}}),o=t.embed({id:i,type:`AnnotationPage`,items:[a]});return t.embed({id:r,type:`Canvas`,label:e.label||{en:[`Untitled YouTube canvas`]},height:e.height||1e3,width:e.width||1e3,duration:e.duration||1,items:[o]})}return t.options.targetType===`Annotation`?t.embed({id:t.generateId(`annotation`),type:`Annotation`,motivation:`painting`,body:[n],target:t.getTarget()}):n}function Gn(e){let t=e.options.initialData;return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n=new FormData(t.target),r=Object.fromEntries(n.entries());r.youtubeUrl&&e.runCreate({youtubeUrl:r.youtubeUrl})},children:[(0,h.jsxs)(p.InputContainer,{$wide:!0,children:[(0,h.jsx)(p.InputLabel,{htmlFor:`id`,children:`Link to YouTube`}),(0,h.jsx)(p.Input,{id:`youtubeUrl`,name:`youtubeUrl`,defaultValue:t.youtubeUrl||``})]}),(0,h.jsx)(f.ActionButton,{primary:!0,large:!0,type:`submit`,children:`Create`})]})})}const Kn=(0,u.defineCreator)({id:`@manifest-editor/youtube`,create:Wn,label:`YouTube`,summary:`Embed YouTube`,icon:(0,h.jsx)(f.YouTubeIcon,{}),resourceType:`ContentResource`,additionalTypes:[`Canvas`,`Annotation`],resourceFields:[`id`,`type`,`service`],supportsResource(e){return Q(e)?{initialData:{youtubeUrl:e}}:!1},render:e=>(0,h.jsx)(Gn,{...e}),supports:{initialData:!0,onlyPainting:!0,parentTypes:[`Annotation`,`Manifest`,`AnnotationPage`],parentFieldMap:{Annotation:[`body`],Manifest:[`items`],AnnotationPage:[`items`]}},staticFields:{type:`Video`}});async function qn(e,t){let n=e.output||[],r=[];for(let e of n){let{resource:n,parent:i,selector:a}=e,o=t.getPreviewVault(),s=(0,d.createThumbnailHelper)(o);if(n.type===`Manifest`){let e=n.id;Y(e,`Could not find Manifest ID`);let i=await o.loadManifest(e),a=await s.getBestThumbnailAtSize(i,{width:256,height:256},!1);Y(i,`Manifest not found`),r.push(t.embed({id:n.id,type:`Manifest`,label:i.label,summary:i.summary,thumbnail:a?.best?[{id:a.best.id,type:`Image`}]:void 0}));continue}if(n.type===`Collection`){let e=n.id;Y(e,`Could not find Manifest ID`);let i=await o.loadManifest(e);Y(i,`Collection not found`),r.push(t.embed({id:n.id,type:`Collection`,label:i.label}))}}return r}const Jn=(0,m.lazy)(()=>Promise.resolve().then(()=>Yn));var Yn=o({default:()=>$});function $(e){let t=(0,y.usePreviewVault)(),n=(0,m.useMemo)(()=>e.options.initialData||{},[e.options.initialData]),r=(0,m.useMemo)(()=>[{type:`callback`,label:`Select`,supportedTypes:[`Manifest`,`Collection`,`ManifestList`,`CollectionList`,`CollectionItemList`],cb:t=>e.runCreate({output:t}),format:{type:`custom`,format:(e,t,n)=>{let r=Array.isArray(e)?e:[{...e,parent:t}],i=[];for(let e of r)i.push({resource:n.get(e),parent:e.parent,selector:e.selector});return i}}}],[e.runCreate]),i=(0,m.useMemo)(()=>({canCropImage:!1,canSelectCanvas:!1,canSelectManifest:!0,canSelectCollection:!0,multiSelect:!0,...n.iiifBrowserOptions?.navigation||{}}),[n.iiifBrowserOptions?.navigation]),a=(0,m.useMemo)(()=>({buttonClassName:`bg-me-primary-500 text-white hover:bg-me-primary-600`,homeLink:n.url||(typeof e.config?.defaultCollection==`string`?e.config.defaultCollection:void 0),...n.iiifBrowserOptions?.ui||{}}),[n,e.config]),o=(0,m.useMemo)(()=>{let e=n.iiifBrowserOptions?.history||{};return n.url?{...e,restoreFromLocalStorage:!1,saveToLocalStorage:!1,initialHistory:[{url:n.url,resource:null,route:`/loading?id=${encodeURIComponent(n.url)}`}]}:e},[n]);return(0,h.jsx)(y.PreviewVaultBoundary,{children:(0,h.jsx)(te.IIIFBrowser,{ui:a,vault:t,className:`iiif-browser border-none border-t rounded-none h-[70vh] min-h-[60vh] max-h-full max-w-full`,output:r,navigation:i,customPages:n.iiifBrowserOptions?.customPages||{},history:o})})}const Xn=(0,u.defineCreator)({id:`@manifest-editor/manifest-browser-creator`,configKey:`@manifest-editor/iiif-browser-creator`,create:qn,label:`IIIF Browser`,summary:`Browse IIIF Resources`,icon:(0,h.jsx)(f.IIIFBrowserIcon,{}),render(e){return(0,h.jsx)($,{...e})},async supportsResource(e,t){let n=w(await C(e,t));return n===`Manifest`||n===`Collection`||await oe(e)?{initialData:{url:e}}:!1},resourceType:`Manifest`,resourceFields:[`id`,`label`],additionalTypes:[`Collection`],supports:{initialData:!0,parentTypes:[`Collection`,`Manifest`,`Canvas`],parentFieldMap:{Collection:[`items`],Manifest:[`partOf`],Canvas:[`partOf`]}},sideEffects:[],staticFields:{}});async function Zn(e,t,n){let r=t.generateId(`range`,n?{id:n,type:`Range`}:void 0);return t.embed({id:r,type:`Range`,label:e.label||{en:[`Untitled range`]},items:e.items||[]})}function Qn(e){let[t,n]=(0,m.useState)(e.options.initialData?.label||{en:[``]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:n=>{n.preventDefault(),t&&e.runCreate({type:`Range`,label:t,items:e.options.initialData?.items||[]})},children:[(0,h.jsx)(p.LanguageFieldEditor,{focusId:`label`,label:`Label`,fields:t,onSave:e=>n(e.toInternationalString())}),(0,h.jsx)(f.ActionButton,{primary:!0,type:`submit`,children:`Create range`})]})})}const $n=(0,u.defineCreator)({id:`@manifest-editor/range-with-items`,create:Zn,label:`Range`,summary:`Add a new range`,icon:(0,h.jsx)(f.RangesIcon,{}),render(e){return(0,h.jsx)(Qn,{...e})},resourceType:`Range`,resourceFields:[`id`,`label`,`type`],supports:{parentTypes:[`Range`],parentFields:[`items`]},staticFields:{type:`Range`}});async function er(e,t,n){let r=t.generateId(`range`,n?{id:n,type:`Range`}:void 0);return t.embed({id:r,type:`Range`,label:e.label||{en:[`Table of Contents`]},items:(e.items||[]).map(e=>t.ref(e))})}function tr(e){let[t,n]=(0,m.useState)(e.options.initialData?.label||{en:[``]});return(0,h.jsx)(f.PaddedSidebarContainer,{children:(0,h.jsxs)(`form`,{onSubmit:n=>{n.preventDefault(),t&&e.runCreate({type:`Range`,label:t})},children:[(0,h.jsx)(p.LanguageFieldEditor,{focusId:`label`,label:`Label`,fields:t,onSave:e=>n(e.toInternationalString())}),(0,h.jsx)(f.ActionButton,{primary:!0,type:`submit`,children:`Create range`})]})})}const nr=(0,u.defineCreator)({id:`@manifest-editor/range-top-level`,create:er,label:`Top Level Range`,summary:`Add a new top level range`,icon:(0,h.jsx)(f.RangesIcon,{}),render(e){return(0,h.jsx)(tr,{...e})},resourceType:`Range`,resourceFields:[`id`,`label`,`type`],supports:{parentTypes:[`Manifest`],parentFields:[`structures`]},staticFields:{type:`Range`}}),rr=[U,Qt,G,nn,fn,De,Tn,Ne,Kn,On,vn,Mn,Bn,mn,_n,sn,bn,Ae,kn,on,In,nr,$n,ie];exports.CreateAudioAnnotationForm=O,exports.CreateCaptionedImageAnnotation=ke,exports.CreateHTMLAnnotation=Me,exports.CreateHTMLBodyForm=wn,exports.CreateImageServerForm=H,exports.CreateImageServiceAnnotationForm=Zt,exports.CreateImageUrlAnnotationForm=tn,exports.CreateImageUrlForm=W,exports.CreateImageUrlListForm=K,exports.CreatePlaintextForm=jn,exports.CreateProviderForm=re,exports.CreateThumbnailForm=Fn,exports.CreateVideoAnnotationForm=dn,exports.CreateVttAnnotationPageForm=gn,exports.CreateWebPageForm=zn,exports.IIIFBrowserCreatorForm=Dn,exports.ManifestBrowserCreatorForm=Jn,exports.RangeWithItemsCreatorForm=Qn,exports.TopLevelRangeCreatorForm=tr,exports.YouTubeForm=Gn,exports.allCreators=rr,exports.audioAnnotation=De,exports.captionedImageAnnotation=Ae,exports.createAudioAnnotation=D,exports.createCaptionedImageAnnotation=Oe,exports.createFromIIIFBrowserOutput=En,exports.createFromManifestBrowserOutput=qn,exports.createHtmlAnnotation=je,exports.createHtmlBody=Cn,exports.createImageServer=Jt,exports.createImageServiceAnnotation=Xt,exports.createImageUrl=$t,exports.createImageUrlAnnotation=en,exports.createImageUrlList=rn,exports.createImageUrlListAnnotation=an,exports.createNoBodyAnnotation=cn,exports.createPlaintext=An,exports.createProvider=ne,exports.createRangeTopLevel=er,exports.createRangeWithItems=Zn,exports.createThumbnail=Pn,exports.createVideoAnnotation=un,exports.createVttAnnotationPage=hn,exports.createWebPage=Rn,exports.createYoutubeBody=Wn,exports.createYoutubeBodyResource=Un,exports.croppedRegion=X,exports.emptyAnnotationPage=mn,exports.emptyCanvas=vn,exports.getCanonicalUrl=V,exports.getYouTubeId=Q,exports.htmlAnnotation=Ne,exports.htmlBodyCreator=Tn,exports.iiifBrowserCreator=On,exports.imageServiceAnnotation=Qt,exports.imageServiceCreator=U,exports.imageUrlAnnotation=nn,exports.imageUrlCreator=G,exports.imageUrlListAnnotation=on,exports.imageUrlListCreator=kn,exports.internalCanvas=bn,exports.manifestBrowserCreator=Xn,exports.noBodyAnnotation=sn,exports.plaintextCreator=Mn,exports.providerCreator=ie,exports.rangeTopLevel=nr,exports.rangeWithItems=$n,exports.validateYouTube=Hn,exports.videoAnnotation=fn,exports.vttAnnotationPage=_n,exports.webPageCreator=Bn,exports.youTubeBodyCreator=Kn;
98
99
  //# sourceMappingURL=index.cjs.map