@pretextbook/web-editor 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeEditor.d.ts +2 -0
- package/dist/components/toc/types.d.ts +6 -0
- package/dist/index.es.js +403 -352
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/sectionUtils.d.ts +8 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -434,7 +434,7 @@ $0`,documentation:`To add a watermark to the document`}},Qa=`alert.angles.articl
|
|
|
434
434
|
`+e),e}let i=fs(n,t);return r&&(i=r+`
|
|
435
435
|
|
|
436
436
|
`+i),i}function ms(e,t,n,r){switch(e.type){case`instruction`:t.push(`<?${e.name}${e.value?` `+e.value:``}?>`);break;case`doctype`:t.push(`<!DOCTYPE ${e.name}>`);break;case`comment`:t.push(`${r.ind.repeat(n)}<!--${e.value}-->`);break;case`cdata`:t.push(`${r.ind.repeat(n)}<![CDATA[${e.value}]]>`);break;case`text`:{let i=e.value.trim();i&&t.push(`${r.ind.repeat(n)}${Is(i)}`);break}case`element`:hs(e,t,n,r);break}}function hs(e,t,n,r){let i=e.name;as.includes(i)?gs(e,t,n,r):us.includes(i)?vs(e,t,n,r):ts.includes(i)?_s(e,t,n,r):ls.includes(i)&&!Fs(e)?ys(e,t,n,r):ls.includes(i)?bs(e,t,n,r):xs(e,t,n,r)}function gs(e,t,n,r){if(e.children.some(e=>e.type===`element`)){xs(e,t,n,r);return}let i=r.ind.repeat(n);if(Ms(e)){t.push(`${i}${Os(e)}`);return}let a=e.children.map(e=>e.type===`text`?Is(e.value):e.type===`cdata`?`<![CDATA[${e.value}]]>`:``).join(``);if(/\n[ \t]*$/.test(a)){let n=a.replace(/\n[ \t]*$/,`
|
|
437
|
-
`);t.push(`${i}${Ds(e)}${n}${i}</${e.name}>`)}else t.push(`${i}${Ds(e)}${a}</${e.name}>`)}function _s(e,t,n,r){let i=r.ind.repeat(n);if(Ms(e)){t.push(`${i}${Os(e)}`);return}let a=Cs(e.children);t.push(`${i}${Ds(e)}${a}</${e.name}>`)}function vs(e,t,n,r){let i=r.ind.repeat(n);if(Ms(e)){t.push(`${i}${Os(e)}`);return}if(Fs(e)){bs(e,t,n,r);return}let a=Ts(e.children),o=r.ind.repeat(n+1),s=`${i}${Ds(e)}${a.join(` `)}</${e.name}>`;if(r.printWidth===0||s.length<=r.printWidth){t.push(s);return}t.push(`${i}${Ds(e)}`);for(let e of Es(a,r.printWidth,o.length,r.breakSentences))t.push(`${o}${e}`);t.push(`${i}</${e.name}>`)}function ys(e,t,n,r){let i=r.ind.repeat(n),a=r.ind.repeat(n+1);if(Ms(e)){t.push(`${i}${Os(e)}`);return}t.push(`${i}${Ds(e)}`);let o=Ts(e.children);for(let e of Es(o,r.printWidth,a.length,r.breakSentences))t.push(`${a}${e}`);t.push(`${i}</${e.name}>`)}function bs(e,t,n,r){let i=r.ind.repeat(n),a=r.ind.repeat(n+1);if(Ms(e)){t.push(`${i}${Os(e)}`);return}t.push(`${i}${Ds(e)}`);let o=Ns(e),s=0;for(;s<o.length;)if(Ps(o[s])){let e=o[s];s++;let i=``;if(s<o.length&&o[s].type===`text`){let e=o[s].value,t=/^(\s*)([.,;:!?])/.exec(e);if(t){i=t[2];let n=e.slice(t[0].length);o[s].value=n,n.trim()||s++}}let a=[];hs(e,a,n+1,r),i&&a.length>0&&(a[a.length-1]+=i),t.push(...a)}else{let e=[];for(;s<o.length&&!Ps(o[s]);)e.push(o[s]),s++;let n=Ts(e);if(n.length>0)for(let e of Es(n,r.printWidth,a.length,r.breakSentences))t.push(`${a}${e}`)}t.push(`${i}</${e.name}>`)}function xs(e,t,n,r){let i=r.ind.repeat(n);if(Ms(e)){t.push(...js(e,n,r,!0));return}let a=Ns(e);if(a.length===1&&a[0].type===`element`&&a[0].name===`xi:include`){let o=a[0],s=js(e,n,r);if(s.length===1){let n=Ms(o)?Os(o):`${Ds(o)}${Cs(o.children)}</${o.name}>`;t.push(`${s[0]}${n}</${e.name}>`);return}t.push(...s),ms(o,t,n+1,r),t.push(`${i}</${e.name}>`);return}t.push(...js(e,n,r));for(let i of Ns(e))ms(i,t,n+1,r);t.push(`${i}</${e.name}>`)}function Ss(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r].trim(),a=r<e.length-1?e[r+1].trim():null;if(n.push(e[r]),r===0&&/^<\?xml(?:\s|\?>)/.test(i)){n.push(``);continue}if(t.blankLines!==`few`)if(t.blankLines===`some`)if(i.startsWith(`</`)&&a!==null&&a.startsWith(`<`)){let e=/^<([^\s>/]+)/.exec(a)?.[1];e&&ss.includes(e)&&n.push(``)}else /^<title[\s>]/.test(i)&&i.includes(`</title>`)&&n.push(``);else t.blankLines===`many`&&(i.startsWith(`</`)||i.startsWith(`<`)&&a!==null&&a.startsWith(`<`))&&n.push(``)}return n}function Cs(e){return e.map(e=>e.type===`text`?Is(e.value):e.type===`element`?ws(e):e.type===`comment`?`<!--${e.value}-->`:e.type===`cdata`?`<![CDATA[${e.value}]]>`:``).join(``)}function ws(e){return Ms(e)?Os(e):`${Ds(e)}${Cs(e.children)}</${e.name}>`}function Ts(e){let t=[];for(let n of e)if(n.type===`text`){let e=n.value.split(/\s+/).filter(e=>e.length>0);for(let n=0;n<e.length;n++){let r=Is(e[n]);n===0&&t.length>0&&/^[.,;:!?\-]/.test(r)?t[t.length-1]+=r:t.push(r)}}else n.type===`element`?t.push(ws(n)):n.type===`comment`&&t.push(`<!--${n.value}-->`);return t}function Es(e,t,n,r){if(e.length===0)return[];let i=t===0?1/0:Math.max(20,t-n),a=[],o=``;for(let t=0;t<e.length;t++){let n=e[t];o===``?o=n:o.length+1+n.length<=i?o+=` `+n:(a.push(o),o=n),r&&/[.!?]$/.test(n)&&t<e.length-1&&(a.push(o),o=``)}return o&&a.push(o),a}function Ds(e){let t=ks(e);return t?`<${e.name} ${t}>`:`<${e.name}>`}function Os(e){let t=ks(e);return t?`<${e.name} ${t}/>`:`<${e.name}/>`}function ks(e){return As(e).join(` `)}function As(e){return Object.entries(e.attributes||{}).map(([e,t])=>t==null?e:`${e}="${Ls(t)}"`)}function js(e,t,n,r=!1){let i=n.ind.repeat(t),a=As(e),o=r?`/>`:`>`;if(a.length===0)return[`${i}<${e.name}${o}`];let s=`${i}<${e.name} ${a.join(` `)}${o}`;if(!n.breakLongAttributes||n.printWidth===0||s.length<=n.printWidth)return[s];let c=`${i}${` `.repeat(e.name.length+2)}`,l=[`${i}<${e.name} ${a[0]}`];for(let e of a.slice(1))l.push(`${c}${e}`);return l[l.length-1]+=o,l}function Ms(e){return e.children.every(e=>e.type===`text`&&e.value.trim()===``)}function Ns(e){return e.children.filter(e=>!(e.type===`text`&&e.value.trim()===``))}function Ps(e){if(e.type!==`element`)return!1;let t=e.name;return t===`c`?!1:(cs.includes(t)||as.includes(t))&&!ts.includes(t)}function Fs(e){return e.children.some(e=>Ps(e))}function Is(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}function Ls(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`)}var Rs=6,zs=({actions:e})=>{let r=(0,n.useRef)(null),i=(0,n.useRef)(null),a=(0,n.useRef)(null),o=(0,n.useRef)([]),s=(0,n.useRef)(0),[c,l]=(0,n.useState)(e.length),[u,d]=(0,n.useState)(!1),f=(0,n.useCallback)(()=>{let e=r.current,t=o.current;if(!e||t.length===0)return;let n=e.clientWidth,i=t.length>0?Rs*(t.length-1):0;if(t.reduce((e,t)=>e+t,0)+i<=n){l(t.length);return}let a=s.current,c=0;for(let e=0;e<t.length;e++){let r=a+t[e]+Rs;if(r<=n)a=r,c++;else break}l(c)},[]);(0,n.useLayoutEffect)(()=>{let e=i.current;if(!e)return;o.current=Array.from(e.querySelectorAll(`[data-measure-btn]`)).map(e=>e.offsetWidth);let t=e.querySelector(`[data-measure-more]`);s.current=t?t.offsetWidth+Rs:0,f()},[e.map(e=>`${e.key}:${e.label}:${+!!e.disabled}`).join(`|`),f]),(0,n.useEffect)(()=>{let e=r.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>f());return t.observe(e),()=>t.disconnect()},[f]),(0,n.useEffect)(()=>{if(!u)return;let e=e=>{a.current?.contains(e.target)||d(!1)},t=e=>{e.key===`Escape`&&d(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[u]);let p=e.slice(0,c),m=e.slice(c);return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-actions`,ref:r,children:[p.map(e=>(0,t.jsx)(`button`,{className:`pretext-plus-editor__menu-button ${e.className??``}`,onClick:e.onClick,disabled:e.disabled,title:e.title,children:e.label},e.key)),m.length>0&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-dropdown`,ref:a,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__menu-button`,onClick:()=>d(e=>!e),"aria-haspopup":`menu`,"aria-expanded":u,title:`More actions`,children:`More ▾`}),u&&(0,t.jsx)(`div`,{className:`pretext-plus-editor__menu-dropdown-list`,role:`menu`,children:m.map(e=>(0,t.jsx)(`button`,{type:`button`,role:`menuitem`,className:`pretext-plus-editor__menu-dropdown-item`,onClick:()=>{d(!1),e.onClick()},disabled:e.disabled,title:e.title,children:e.label},e.key))})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-measure`,ref:i,"aria-hidden":!0,children:[e.map(e=>(0,t.jsx)(`button`,{"data-measure-btn":!0,className:`pretext-plus-editor__menu-button ${e.className??``}`,tabIndex:-1,children:e.label},e.key)),(0,t.jsx)(`button`,{"data-measure-more":!0,className:`pretext-plus-editor__menu-button`,tabIndex:-1,children:`More ▾`})]})]})},Bs=({content:e,sourceFormat:n,onContentChange:r,onOpenLatexImport:i,onOpenDocinfoEditor:a,onConvertToPretext:o,canConvertToPretext:s,onOpenAssets:c,onShowFullSource:l})=>{let u=()=>{try{r(ps(e))}catch(e){console.error(`Error formatting:`,e),alert(`Error formatting XML`)}},d={key:`full-source`,label:`Display Full Source`,onClick:l,title:`Show the full assembled PreTeXt source for the project`},f;return f=n===`latex`?[...o?[{key:`convert`,label:`Convert to PreTeXt`,onClick:o,title:`Create a new project copy using the converted PreTeXt source`,className:`pretext-plus-editor__menu-button--convert`,disabled:s===!1}]:[],{key:`preamble`,label:`Edit Preamble`,onClick:a,title:`Edit Preamble`},d]:n===`markdown`?[...o?[{key:`convert`,label:`Convert to PreTeXt`,onClick:o,title:`Create a new project copy using the converted PreTeXt source`,className:`pretext-plus-editor__menu-button--convert`,disabled:s===!1}]:[],{key:`macros`,label:`Edit Macros`,onClick:a,title:`Edit Macros`},d]:[{key:`format`,label:`Format PreTeXt`,onClick:u,title:`Format the PreTeXt source`},{key:`import-latex`,label:`Import LaTeX`,onClick:i,title:`Import LaTeX`},{key:`macros`,label:`Edit Macros`,onClick:a,title:`Edit Macros`},...c?[{key:`assets`,label:`Assets`,onClick:c,title:`Manage assets`}]:[],d],(0,t.jsxs)(`div`,{className:`pretext-plus-editor__code-editor-menu`,children:[(0,t.jsx)(zs,{actions:f}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__code-editor-source-badge pretext-plus-editor__code-editor-source-badge--right`,children:n===`latex`?`LaTeX`:n===`markdown`?`Markdown`:`PreTeXt`})]})};function Vs(e){let t=e.getLineCount();if(t<2||!/^\s*<title\b/.test(e.getLineContent(2)))return 1;let n=2;for(;n<=t&&!/<\/title\s*>/.test(e.getLineContent(n));)n++;return n<=t?n:1}function Hs(e,t){let n=e.getLineCount();if(t===`pretext`){if(n<3)return null;let t=Vs(e);if(t>=n-1)return null;let r=[];for(let e=1;e<=t;e++)r.push(e);return r.push(n),{editableRange:[t+1,1,n-1,e.getLineMaxColumn(n-1)],lockedLines:r,leadingLockedLines:t}}if(t===`markdown`){if(e.getLineContent(1).trim()!==`---`)return null;let t=-1;for(let r=2;r<=n;r++)if(e.getLineContent(r).trim()===`---`){t=r;break}if(t===-1)return null;let r=t,i=t+1;for(;i<=n&&e.getLineContent(i).trim()===``;)i++;if(i<=n&&/^#{1,6}[ \t]+\S/.test(e.getLineContent(i))&&(r=i),r>=n)return null;let a=[];for(let e=1;e<=r;e++)a.push(e);return{editableRange:[r+1,1,n,e.getLineMaxColumn(n)],lockedLines:a,leadingLockedLines:r}}return t===`latex`?n<2||!/^\s*\\(?!begin\b|end\b)[A-Za-z][A-Za-z-]*\*?\{/.test(e.getLineContent(1))?null:{editableRange:[2,1,n,e.getLineMaxColumn(n)],lockedLines:[1],leadingLockedLines:1}:null}var Us={automaticLayout:!0,minimap:{enabled:!1},acceptSuggestionOnCommitCharacter:!1,quickSuggestions:!1,wordWrap:`on`,insertSpaces:!0,tabSize:2,padding:{top:10,bottom:10}},Ws=(0,n.forwardRef)(({content:e,sourceFormat:r,onChange:i,onRebuild:a,onSave:o,onOpenLatexImport:s,onOpenDocinfoEditor:c,onOpenConvertToPretext:l,canConvertToPretext:u,onOpenAssets:d,onShowFullSource:f,onRequestWrapperEdit:p},m)=>{let h=(0,n.useRef)(null),g=(0,n.useRef)(null),_=(0,n.useRef)(null),v=(0,n.useRef)(null),y=(0,n.useRef)(!1),b=(0,n.useRef)(0),x=(0,n.useRef)(null),S=(0,n.useRef)(null),C=(0,n.useRef)(p),w=(0,n.useRef)(null),T=(0,n.useRef)(null),E=(0,n.useRef)(!1),[D,O]=(0,n.useState)(!1),[k,A]=(0,n.useState)(!1),j=(0,n.useRef)(a),ee=(0,n.useRef)(o);(0,n.useImperativeHandle)(m,()=>({insertAtCursor:e=>{let t=h.current;if(!t)return;let n=t.getSelection();n&&(t.executeEdits(`insert-asset`,[{range:n,text:e,forceMoveMarkers:!0}]),t.focus())}}),[]),(0,n.useEffect)(()=>{j.current=a},[a]),(0,n.useEffect)(()=>{ee.current=o},[o]),(0,n.useEffect)(()=>{C.current=p},[p]),(0,n.useEffect)(()=>{w.current?.dispose?.();let e=ko[r];w.current=g.current?e.registerMonacoExtensions?.(g.current)??null:null,ne()},[r]),(0,n.useEffect)(()=>()=>{x.current?.dispose?.(),w.current?.dispose?.(),S.current?.dispose?.(),_.current?.disposeConstrainer?.(),T.current&&clearTimeout(T.current)},[]);let M=(e,t,n)=>{if(r!==`pretext`)return;let i=t.getLineCount();if(i<2)return;let a=t.getLineContent(1).trim();if(!a.startsWith(`<`)||a.startsWith(`</`)||a.endsWith(`/>`))return;let o=Vs(t);if(i!==o+1)return;let s=t.getLineContent(i).trim();if(!/^<\/[A-Za-z][\w.:-]*\s*>$/.test(s))return;E.current=!0;let c=t.getLineMaxColumn(o);e.executeEdits(`ensure-body-line`,[{range:new n.Range(o,c,o,c),text:`
|
|
437
|
+
`);t.push(`${i}${Ds(e)}${n}${i}</${e.name}>`)}else t.push(`${i}${Ds(e)}${a}</${e.name}>`)}function _s(e,t,n,r){let i=r.ind.repeat(n);if(Ms(e)){t.push(`${i}${Os(e)}`);return}let a=Cs(e.children);t.push(`${i}${Ds(e)}${a}</${e.name}>`)}function vs(e,t,n,r){let i=r.ind.repeat(n);if(Ms(e)){t.push(`${i}${Os(e)}`);return}if(Fs(e)){bs(e,t,n,r);return}let a=Ts(e.children),o=r.ind.repeat(n+1),s=`${i}${Ds(e)}${a.join(` `)}</${e.name}>`;if(r.printWidth===0||s.length<=r.printWidth){t.push(s);return}t.push(`${i}${Ds(e)}`);for(let e of Es(a,r.printWidth,o.length,r.breakSentences))t.push(`${o}${e}`);t.push(`${i}</${e.name}>`)}function ys(e,t,n,r){let i=r.ind.repeat(n),a=r.ind.repeat(n+1);if(Ms(e)){t.push(`${i}${Os(e)}`);return}t.push(`${i}${Ds(e)}`);let o=Ts(e.children);for(let e of Es(o,r.printWidth,a.length,r.breakSentences))t.push(`${a}${e}`);t.push(`${i}</${e.name}>`)}function bs(e,t,n,r){let i=r.ind.repeat(n),a=r.ind.repeat(n+1);if(Ms(e)){t.push(`${i}${Os(e)}`);return}t.push(`${i}${Ds(e)}`);let o=Ns(e),s=0;for(;s<o.length;)if(Ps(o[s])){let e=o[s];s++;let i=``;if(s<o.length&&o[s].type===`text`){let e=o[s].value,t=/^(\s*)([.,;:!?])/.exec(e);if(t){i=t[2];let n=e.slice(t[0].length);o[s].value=n,n.trim()||s++}}let a=[];hs(e,a,n+1,r),i&&a.length>0&&(a[a.length-1]+=i),t.push(...a)}else{let e=[];for(;s<o.length&&!Ps(o[s]);)e.push(o[s]),s++;let n=Ts(e);if(n.length>0)for(let e of Es(n,r.printWidth,a.length,r.breakSentences))t.push(`${a}${e}`)}t.push(`${i}</${e.name}>`)}function xs(e,t,n,r){let i=r.ind.repeat(n);if(Ms(e)){t.push(...js(e,n,r,!0));return}let a=Ns(e);if(a.length===1&&a[0].type===`element`&&a[0].name===`xi:include`){let o=a[0],s=js(e,n,r);if(s.length===1){let n=Ms(o)?Os(o):`${Ds(o)}${Cs(o.children)}</${o.name}>`;t.push(`${s[0]}${n}</${e.name}>`);return}t.push(...s),ms(o,t,n+1,r),t.push(`${i}</${e.name}>`);return}t.push(...js(e,n,r));for(let i of Ns(e))ms(i,t,n+1,r);t.push(`${i}</${e.name}>`)}function Ss(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r].trim(),a=r<e.length-1?e[r+1].trim():null;if(n.push(e[r]),r===0&&/^<\?xml(?:\s|\?>)/.test(i)){n.push(``);continue}if(t.blankLines!==`few`)if(t.blankLines===`some`)if(i.startsWith(`</`)&&a!==null&&a.startsWith(`<`)){let e=/^<([^\s>/]+)/.exec(a)?.[1];e&&ss.includes(e)&&n.push(``)}else /^<title[\s>]/.test(i)&&i.includes(`</title>`)&&n.push(``);else t.blankLines===`many`&&(i.startsWith(`</`)||i.startsWith(`<`)&&a!==null&&a.startsWith(`<`))&&n.push(``)}return n}function Cs(e){return e.map(e=>e.type===`text`?Is(e.value):e.type===`element`?ws(e):e.type===`comment`?`<!--${e.value}-->`:e.type===`cdata`?`<![CDATA[${e.value}]]>`:``).join(``)}function ws(e){return Ms(e)?Os(e):`${Ds(e)}${Cs(e.children)}</${e.name}>`}function Ts(e){let t=[];for(let n of e)if(n.type===`text`){let e=n.value.split(/\s+/).filter(e=>e.length>0);for(let n=0;n<e.length;n++){let r=Is(e[n]);n===0&&t.length>0&&/^[.,;:!?\-]/.test(r)?t[t.length-1]+=r:t.push(r)}}else n.type===`element`?t.push(ws(n)):n.type===`comment`&&t.push(`<!--${n.value}-->`);return t}function Es(e,t,n,r){if(e.length===0)return[];let i=t===0?1/0:Math.max(20,t-n),a=[],o=``;for(let t=0;t<e.length;t++){let n=e[t];o===``?o=n:o.length+1+n.length<=i?o+=` `+n:(a.push(o),o=n),r&&/[.!?]$/.test(n)&&t<e.length-1&&(a.push(o),o=``)}return o&&a.push(o),a}function Ds(e){let t=ks(e);return t?`<${e.name} ${t}>`:`<${e.name}>`}function Os(e){let t=ks(e);return t?`<${e.name} ${t}/>`:`<${e.name}/>`}function ks(e){return As(e).join(` `)}function As(e){return Object.entries(e.attributes||{}).map(([e,t])=>t==null?e:`${e}="${Ls(t)}"`)}function js(e,t,n,r=!1){let i=n.ind.repeat(t),a=As(e),o=r?`/>`:`>`;if(a.length===0)return[`${i}<${e.name}${o}`];let s=`${i}<${e.name} ${a.join(` `)}${o}`;if(!n.breakLongAttributes||n.printWidth===0||s.length<=n.printWidth)return[s];let c=`${i}${` `.repeat(e.name.length+2)}`,l=[`${i}<${e.name} ${a[0]}`];for(let e of a.slice(1))l.push(`${c}${e}`);return l[l.length-1]+=o,l}function Ms(e){return e.children.every(e=>e.type===`text`&&e.value.trim()===``)}function Ns(e){return e.children.filter(e=>!(e.type===`text`&&e.value.trim()===``))}function Ps(e){if(e.type!==`element`)return!1;let t=e.name;return t===`c`?!1:(cs.includes(t)||as.includes(t))&&!ts.includes(t)}function Fs(e){return e.children.some(e=>Ps(e))}function Is(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}function Ls(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`)}var Rs=6,zs=({actions:e})=>{let r=(0,n.useRef)(null),i=(0,n.useRef)(null),a=(0,n.useRef)(null),o=(0,n.useRef)([]),s=(0,n.useRef)(0),[c,l]=(0,n.useState)(e.length),[u,d]=(0,n.useState)(!1),f=(0,n.useCallback)(()=>{let e=r.current,t=o.current;if(!e||t.length===0)return;let n=e.clientWidth,i=t.length>0?Rs*(t.length-1):0;if(t.reduce((e,t)=>e+t,0)+i<=n){l(t.length);return}let a=s.current,c=0;for(let e=0;e<t.length;e++){let r=a+t[e]+Rs;if(r<=n)a=r,c++;else break}l(c)},[]);(0,n.useLayoutEffect)(()=>{let e=i.current;if(!e)return;o.current=Array.from(e.querySelectorAll(`[data-measure-btn]`)).map(e=>e.offsetWidth);let t=e.querySelector(`[data-measure-more]`);s.current=t?t.offsetWidth+Rs:0,f()},[e.map(e=>`${e.key}:${e.label}:${+!!e.disabled}`).join(`|`),f]),(0,n.useEffect)(()=>{let e=r.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>f());return t.observe(e),()=>t.disconnect()},[f]),(0,n.useEffect)(()=>{if(!u)return;let e=e=>{a.current?.contains(e.target)||d(!1)},t=e=>{e.key===`Escape`&&d(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[u]);let p=e.slice(0,c),m=e.slice(c);return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-actions`,ref:r,children:[p.map(e=>(0,t.jsx)(`button`,{className:`pretext-plus-editor__menu-button ${e.className??``}`,onClick:e.onClick,disabled:e.disabled,title:e.title,children:e.label},e.key)),m.length>0&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-dropdown`,ref:a,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__menu-button`,onClick:()=>d(e=>!e),"aria-haspopup":`menu`,"aria-expanded":u,title:`More actions`,children:`More ▾`}),u&&(0,t.jsx)(`div`,{className:`pretext-plus-editor__menu-dropdown-list`,role:`menu`,children:m.map(e=>(0,t.jsx)(`button`,{type:`button`,role:`menuitem`,className:`pretext-plus-editor__menu-dropdown-item`,onClick:()=>{d(!1),e.onClick()},disabled:e.disabled,title:e.title,children:e.label},e.key))})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-measure`,ref:i,"aria-hidden":!0,children:[e.map(e=>(0,t.jsx)(`button`,{"data-measure-btn":!0,className:`pretext-plus-editor__menu-button ${e.className??``}`,tabIndex:-1,children:e.label},e.key)),(0,t.jsx)(`button`,{"data-measure-more":!0,className:`pretext-plus-editor__menu-button`,tabIndex:-1,children:`More ▾`})]})]})},Bs=({content:e,sourceFormat:n,onContentChange:r,onOpenLatexImport:i,onOpenDocinfoEditor:a,onConvertToPretext:o,canConvertToPretext:s,onOpenAssets:c,onShowFullSource:l})=>{let u=()=>{try{r(ps(e))}catch(e){console.error(`Error formatting:`,e),alert(`Error formatting XML`)}},d={key:`full-source`,label:`Display Full Source`,onClick:l,title:`Show the full assembled PreTeXt source for the project`},f;return f=n===`latex`?[...o?[{key:`convert`,label:`Convert to PreTeXt`,onClick:o,title:`Create a new project copy using the converted PreTeXt source`,className:`pretext-plus-editor__menu-button--convert`,disabled:s===!1}]:[],{key:`preamble`,label:`Edit Preamble`,onClick:a,title:`Edit Preamble`},d]:n===`markdown`?[...o?[{key:`convert`,label:`Convert to PreTeXt`,onClick:o,title:`Create a new project copy using the converted PreTeXt source`,className:`pretext-plus-editor__menu-button--convert`,disabled:s===!1}]:[],{key:`macros`,label:`Edit Macros`,onClick:a,title:`Edit Macros`},d]:[{key:`format`,label:`Format PreTeXt`,onClick:u,title:`Format the PreTeXt source`},{key:`import-latex`,label:`Import LaTeX`,onClick:i,title:`Import LaTeX`},{key:`macros`,label:`Edit Macros`,onClick:a,title:`Edit Macros`},...c?[{key:`assets`,label:`Assets`,onClick:c,title:`Manage assets`}]:[],d],(0,t.jsxs)(`div`,{className:`pretext-plus-editor__code-editor-menu`,children:[(0,t.jsx)(zs,{actions:f}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__code-editor-source-badge pretext-plus-editor__code-editor-source-badge--right`,children:n===`latex`?`LaTeX`:n===`markdown`?`Markdown`:`PreTeXt`})]})};function Vs(e){let t=e.getLineCount();if(t<2||!/^\s*<title\b/.test(e.getLineContent(2)))return 1;let n=2;for(;n<=t&&!/<\/title\s*>/.test(e.getLineContent(n));)n++;return n<=t?n:1}function Hs(e,t){let n=e.getLineCount();if(t===`pretext`){if(n<3)return null;let t=Vs(e);if(t>=n-1)return null;let r=[];for(let e=1;e<=t;e++)r.push(e);return r.push(n),{editableRange:[t+1,1,n-1,e.getLineMaxColumn(n-1)],lockedLines:r,leadingLockedLines:t}}if(t===`markdown`){if(e.getLineContent(1).trim()!==`---`)return null;let t=-1;for(let r=2;r<=n;r++)if(e.getLineContent(r).trim()===`---`){t=r;break}if(t===-1)return null;let r=t,i=t+1;for(;i<=n&&e.getLineContent(i).trim()===``;)i++;if(i<=n&&/^#{1,6}[ \t]+\S/.test(e.getLineContent(i))&&(r=i),r>=n)return null;let a=[];for(let e=1;e<=r;e++)a.push(e);return{editableRange:[r+1,1,n,e.getLineMaxColumn(n)],lockedLines:a,leadingLockedLines:r}}return t===`latex`?n<2||!/^\s*\\(?!begin\b|end\b)[A-Za-z][A-Za-z-]*\*?\{/.test(e.getLineContent(1))?null:{editableRange:[2,1,n,e.getLineMaxColumn(n)],lockedLines:[1],leadingLockedLines:1}:null}var Us={automaticLayout:!0,minimap:{enabled:!1},acceptSuggestionOnCommitCharacter:!1,quickSuggestions:!1,wordWrap:`on`,insertSpaces:!0,tabSize:2,padding:{top:10,bottom:10}},Ws=(0,n.forwardRef)(({content:e,sourceFormat:r,onChange:i,onRebuild:a,onSave:o,onOpenLatexImport:s,onOpenDocinfoEditor:c,onOpenConvertToPretext:l,canConvertToPretext:u,onOpenAssets:d,onShowFullSource:f,onRequestWrapperEdit:p},m)=>{let h=(0,n.useRef)(null),g=(0,n.useRef)(null),_=(0,n.useRef)(null),v=(0,n.useRef)(null),y=(0,n.useRef)(!1),b=(0,n.useRef)(0),x=(0,n.useRef)(null),S=(0,n.useRef)(null),C=(0,n.useRef)(p),w=(0,n.useRef)(null),T=(0,n.useRef)(null),E=(0,n.useRef)(!1),[D,O]=(0,n.useState)(!1),[k,A]=(0,n.useState)(!1),j=(0,n.useRef)(a),ee=(0,n.useRef)(o);(0,n.useImperativeHandle)(m,()=>({insertAtCursor:e=>{let t=h.current;if(!t)return;let n=t.getSelection();n&&(t.executeEdits(`insert-asset`,[{range:n,text:e,forceMoveMarkers:!0}]),t.focus())},focus:()=>{h.current?.focus()}}),[]),(0,n.useEffect)(()=>{j.current=a},[a]),(0,n.useEffect)(()=>{ee.current=o},[o]),(0,n.useEffect)(()=>{C.current=p},[p]),(0,n.useEffect)(()=>{w.current?.dispose?.();let e=ko[r];w.current=g.current?e.registerMonacoExtensions?.(g.current)??null:null,ne()},[r]),(0,n.useEffect)(()=>()=>{x.current?.dispose?.(),w.current?.dispose?.(),S.current?.dispose?.(),_.current?.disposeConstrainer?.(),T.current&&clearTimeout(T.current)},[]);let M=(e,t,n)=>{if(r!==`pretext`)return;let i=t.getLineCount();if(i<2)return;let a=t.getLineContent(1).trim();if(!a.startsWith(`<`)||a.startsWith(`</`)||a.endsWith(`/>`))return;let o=Vs(t);if(i!==o+1)return;let s=t.getLineContent(i).trim();if(!/^<\/[A-Za-z][\w.:-]*\s*>$/.test(s))return;E.current=!0;let c=t.getLineMaxColumn(o);e.executeEdits(`ensure-body-line`,[{range:new n.Range(o,c,o,c),text:`
|
|
438
438
|
`,forceMoveMarkers:!0}]),queueMicrotask(()=>{E.current=!1})},te=(e,t,n)=>{if(r!==`pretext`)return;let i=t.getLineCount();if(i<2||t.getLineContent(i).trim()!==``)return;let a=i-1;for(;a>1&&t.getLineContent(a).trim()===``;)a--;let o=t.getLineContent(a).trim();/^<\/[A-Za-z][\w.:-]*\s*>$/.test(o)&&(E.current=!0,e.executeEdits(`trim-trailing-blank-lines`,[{range:new n.Range(a,t.getLineMaxColumn(a),i,t.getLineMaxColumn(i)),text:``,forceMoveMarkers:!0}]),queueMicrotask(()=>{E.current=!1}))},ne=()=>{let e=h.current,t=g.current,n=_.current;if(!e||!t||!n)return;let i=e.getModel();if(!i)return;typeof i.disposeRestrictions==`function`&&i.disposeRestrictions(),te(e,i,t),M(e,i,t);let a=Hs(i,r);if(y.current=a!==null,b.current=a?.leadingLockedLines??0,a&&n.addRestrictionsTo(i,[{range:a.editableRange,allowMultiline:!0}]),typeof e.createDecorationsCollection==`function`)if(v.current||=e.createDecorationsCollection(),!a)v.current.clear();else{let e={isWholeLine:!0,className:`pretext-plus-editor__locked-line`,inlineClassName:`pretext-plus-editor__locked-line-text`,stickiness:t.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,hoverMessage:{value:`These properties are structural — edit them from the Table of Contents.`}};v.current.set(a.lockedLines.map(n=>({range:new t.Range(n,1,n,i.getLineMaxColumn(n)),options:e})))}},N=(e,t)=>{e.getValue()!==t&&(E.current=!0,typeof e.disposeRestrictions==`function`&&e.disposeRestrictions(),e.setValue(t),ne(),queueMicrotask(()=>{E.current=!1}))};(0,n.useEffect)(()=>{let t=h.current;if(!t)return;let n=t.getModel();if(n&&n.getValue()!==e){let r=t.getPosition(),i=t.getSelections();N(n,e),r&&t.setPosition(r),i&&t.setSelections(i)}},[e]);let re=(t,n)=>{h.current=t,g.current=n,_.current=tr(n),_.current.initializeIn(t);let i=t.getModel();i&&i.getValue()!==e&&N(i,e),x.current?.dispose?.(),x.current=t.onDidChangeModelContent(()=>{ie()}),ie(),S.current?.dispose?.(),S.current=t.onMouseDown(e=>{let t=e?.target?.position?.lineNumber;y.current&&typeof t==`number`&&t<=b.current&&C.current?.()}),t.addCommand(n.KeyMod.CtrlCmd|n.KeyCode.Enter,()=>{j.current?.()}),t.addCommand(n.KeyMod.CtrlCmd|n.KeyCode.KeyS,()=>{ee.current?.()}),w.current?.dispose?.(),w.current=ko[r].registerMonacoExtensions?.(n)??null,ne()},ie=()=>{let e=h.current?.getModel?.();if(e&&typeof e.canUndo==`function`&&typeof e.canRedo==`function`)try{O(e.canUndo()),A(e.canRedo());return}catch{}let t=!!h.current;O(t),A(t)},ae=e=>{i(e)};return(0,t.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`},children:[(0,t.jsx)(Bs,{content:e,sourceFormat:r,onContentChange:ae,onOpenLatexImport:s,onOpenDocinfoEditor:c,onUndo:()=>{h.current?.trigger(``,`undo`),ie()},onRedo:()=>{h.current?.trigger(``,`redo`),ie()},canUndo:D,canRedo:k,onConvertToPretext:l,canConvertToPretext:u,onOpenAssets:d,onShowFullSource:f}),(0,t.jsx)(`div`,{style:{flex:1},children:(0,t.jsx)(Yn,{options:Us,height:`100%`,language:ko[r].language,defaultValue:e,onMount:re,onChange:(e,t)=>{t?.isFlush||E.current||(T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{ae(e||``)},500))}})})]})});Ws.displayName=`CodeEditor`;function Gs(e){this.content=e}Gs.prototype={constructor:Gs,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return-1},get:function(e){var t=this.find(e);return t==-1?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,i=r.find(e),a=r.content.slice();return i==-1?a.push(n||e,t):(a[i+1]=t,n&&(a[i]=n)),new Gs(a)},remove:function(e){var t=this.find(e);if(t==-1)return this;var n=this.content.slice();return n.splice(t,2),new Gs(n)},addToStart:function(e,t){return new Gs([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new Gs(n)},addBefore:function(e,t,n){var r=this.remove(t),i=r.content.slice(),a=r.find(e);return i.splice(a==-1?i.length:a,0,t,n),new Gs(i)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return e=Gs.from(e),e.size?new Gs(e.content.concat(this.subtract(e).content)):this},append:function(e){return e=Gs.from(e),e.size?new Gs(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=Gs.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},Gs.from=function(e){if(e instanceof Gs)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new Gs(t)};function Ks(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){let e=i.text,t=a.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r<e.length&&r<t.length&&Ys(e.charCodeAt(r-1))&&Js(e.charCodeAt(r))&&n--,n}if(i.content.size||a.content.size){let e=Ks(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function qs(e,t,n,r){for(let i=e.childCount,a=t.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let o=e.child(--i),s=t.child(--a),c=o.nodeSize;if(o==s){n-=c,r-=c;continue}if(!o.sameMarkup(s))return{a:n,b:r};if(o.isText&&o.text!=s.text){let e=o.text,t=s.text,i=e.length,a=t.length;for(;i>0&&a>0&&e[i-1]==t[a-1];)i--,a--,n--,r--;return i&&a&&i<e.length&&Ys(e.charCodeAt(i-1))&&Js(e.charCodeAt(i))&&(n++,r++),{a:n,b:r}}if(o.content.size||s.content.size){let e=qs(o.content,s.content,n-1,r-1);if(e)return e}n-=c,r-=c}}function Js(e){return e>=56320&&e<57344}function Ys(e){return e>=55296&&e<56320}var Xs=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let a=0,o=0;o<t;a++){let s=this.content[a],c=o+s.nodeSize;if(c>e&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);a<t.content.length;a++)i.push(t.content[a]);return new e(i,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],i=0;if(n>t)for(let e=0,a=0;a<n;e++){let o=this.content[e],s=a+o.nodeSize;s>t&&((a<t||s>n)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw RangeError(`Index `+e+` out of range for `+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return Ks(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return qs(this,e,t,n)}findIndex(e){if(e==0)return Qs(0,e);if(e==this.size)return Qs(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?Qs(t+1,i):Qs(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;e<t.length;e++){let i=t[e];r+=i.nodeSize,e&&i.isText&&t[e-1].sameMarkup(i)?(n||=t.slice(0,e),n[n.length-1]=i.withText(n[n.length-1].text+i.text)):n&&n.push(i)}return new e(n||t,r)}static from(t){if(!t)return e.empty;if(t instanceof e)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new e([t],t.nodeSize);throw RangeError(`Can not convert `+t+` to a Fragment`+(t.nodesBetween?` (looks like multiple versions of prosemirror-model were loaded)`:``))}};Xs.empty=new Xs([],0);var Zs={index:0,offset:0};function Qs(e,t){return Zs.index=e,Zs.offset=t,Zs}function $s(e,t){if(e===t)return!0;if(!(e&&typeof e==`object`)||!(t&&typeof t==`object`))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!$s(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!$s(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var ec=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||=e.slice(0,r);else if(i.type.excludes(this.type))return e;else !n&&i.type.rank>this.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&$s(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Mark.fromJSON`);let n=e.marks[t.type];if(!n)throw RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};ec.none=[];var tc=class extends Error{},nc=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=ic(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(rc(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(Xs.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};nc.empty=new nc(Xs.empty,0,0);function rc(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(rc(a.content,t-i-1,n-i-1)))}function ic(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=ic(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function ac(e,t,n){if(n.openStart>e.depth)throw new tc(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new tc(`Inconsistent open depths`);return oc(e,t,n,0)}function oc(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r<e.depth-n.openStart){let o=oc(e,t,n,r+1);return a.copy(a.content.replaceChild(i,o))}else if(!n.content.size)return dc(a,pc(e,t,r));else if(!n.openStart&&!n.openEnd&&e.depth==r&&t.depth==r){let r=e.parent,i=r.content;return dc(r,i.cut(0,e.parentOffset).append(n.content).append(i.cut(t.parentOffset)))}else{let{start:i,end:o}=mc(n,e);return dc(a,fc(e,i,o,t,r))}}function sc(e,t){if(!t.type.compatibleContent(e.type))throw new tc(`Cannot join `+t.type.name+` onto `+e.type.name)}function cc(e,t,n){let r=e.node(n);return sc(r,t.node(n)),r}function lc(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function uc(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(lc(e.nodeAfter,r),a++));for(let e=a;e<o;e++)lc(i.child(e),r);t&&t.depth==n&&t.textOffset&&lc(t.nodeBefore,r)}function dc(e,t){if(!e.type.validContent(t))throw new tc(`Invalid content for node `+e.type.name);return e.copy(t)}function fc(e,t,n,r,i){let a=e.depth>i&&cc(e,t,i+1),o=r.depth>i&&cc(n,r,i+1),s=[];return uc(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(sc(a,o),lc(dc(a,fc(e,t,n,r,i+1)),s)):(a&&lc(dc(a,pc(e,t,i+1)),s),uc(t,n,i,s),o&&lc(dc(o,pc(n,r,i+1)),s)),uc(r,null,i,s),new Xs(s)}function pc(e,t,n){let r=[];return uc(null,e,n,r),e.depth>n&&lc(dc(cc(e,t,n+1),pc(e,t,n+1)),r),uc(t,null,n,r),new Xs(r)}function mc(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(Xs.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var hc=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return ec.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var a=0;a<i.length;a++)i[a].type.spec.inclusive===!1&&(!r||!i[a].isInSet(r.marks))&&(i=i[a--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)n[i].type.spec.inclusive===!1&&(!r||!n[i].isInSet(r.marks))&&(n=n[i--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new yc(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e=``;for(let t=1;t<=this.depth;t++)e+=(e?`/`:``)+this.node(t).type.name+`_`+this.index(t-1);return e+`:`+this.parentOffset}static resolve(t,n){if(!(n>=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=vc.get(t);if(r)for(let e=0;e<r.elts.length;e++){let t=r.elts[e];if(t.pos==n)return t}else vc.set(t,r=new gc);let i=r.elts[r.i]=e.resolve(t,n);return r.i=(r.i+1)%_c,i}},gc=class{constructor(){this.elts=[],this.i=0}},_c=12,vc=new WeakMap,yc=class{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},bc=Object.create(null),xc=class e{constructor(e,t,n,r=ec.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||Xs.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,``)}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&$s(this.attrs,t||e.defaultAttrs||bc)&&ec.sameSet(this.marks,n||ec.none)}copy(t=null){return t==this.content?this:new e(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.content,t)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return nc.empty;let r=this.resolve(e),i=this.resolve(t),a=n?0:r.sharedDepth(t),o=r.start(a);return new nc(r.node(a).content.cut(r.pos-o,i.pos-o),r.depth-a,i.depth-a)}replace(e,t,n){return ac(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return hc.resolveCached(this,e)}resolveNoCache(e){return hc.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),Cc(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=Xs.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),a=i&&i.matchFragment(this.content,t);return a?a.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=ec.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!ec.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=Xs.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};xc.prototype.text=void 0;var Sc=class e extends xc{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Cc(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Cc(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var wc=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Tc(t,n);if(r.next==null)return e.empty;let i=Ec(r);r.next&&r.err(`Unexpected trailing text`);let a=Ic(Nc(i));return Lc(a,r),a}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];function i(a,o){let s=a.matchFragment(e,n);if(s&&(!t||s.validEnd))return Xs.from(o.map(e=>e.createAndFill()));for(let e=0;e<a.next.length;e++){let{type:t,next:n}=a.next[e];if(!(t.isText||t.hasRequiredAttrs())&&r.indexOf(n)==-1){r.push(n);let e=i(n,o.concat(t));if(e)return e}}return null}return i(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),i=r.match;if(i.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<i.next.length;e++){let{type:a,next:o}=i.next[e];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in t)&&(!r.type||o.validEnd)&&(n.push({match:a.contentMatch,type:a,via:r}),t[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r<n.next.length;r++)e.indexOf(n.next[r].next)==-1&&t(n.next[r].next)}return t(this),e.map((t,n)=>{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n<t.next.length;n++)r+=(n?`, `:``)+t.next[n].type.name+`->`+e.indexOf(t.next[n].next);return r}).join(`
|
|
439
439
|
`)}};wc.empty=new wc(!0);var Tc=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+` (in content expression '`+this.string+`')`)}};function Ec(e){let t=[];do t.push(Dc(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function Dc(e){let t=[];do t.push(Oc(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function Oc(e){let t=Mc(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=Ac(e,t);else break;return t}function kc(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function Ac(e,t){let n=kc(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:kc(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function jc(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function Mc(e){if(e.eat(`(`)){let t=Ec(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=jc(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function Nc(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t<e.min;t++){let t=n();i(a(e.expr,o),t),o=t}if(e.max==-1)i(a(e.expr,o),o);else for(let t=e.min;t<e.max;t++){let t=n();r(o,t),i(a(e.expr,o),t),o=t}return[r(o)]}else if(e.type==`name`)return[r(t,void 0,e.value)];else throw Error(`Unknown expr type`)}}function Pc(e,t){return t-e}function Fc(e,t){let n=[];return r(t),n.sort(Pc);function r(t){let i=e[t];if(i.length==1&&!i[0].term)return r(i[0].to);n.push(t);for(let e=0;e<i.length;e++){let{term:t,to:a}=i[e];!t&&n.indexOf(a)==-1&&r(a)}}}function Ic(e){let t=Object.create(null);return n(Fc(e,0));function n(r){let i=[];r.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<i.length;e++)i[e][0]==t&&(r=i[e][1]);Fc(e,n).forEach(e=>{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new wc(r.indexOf(e.length-1)>-1);for(let e=0;e<i.length;e++){let r=i[e][1].sort(Pc);a.next.push({type:i[e][0],next:t[r.join(`,`)]||n(r)})}return a}}function Lc(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,a=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];a.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),r.indexOf(o)==-1&&r.push(o)}i&&t.err(`Only non-generatable nodes (`+a.join(`, `)+`) in a required position (see https://prosemirror.net/docs/guide/#generatable)`)}}function Rc(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function zc(e,t){let n=Object.create(null);for(let r in e){let i=t&&t[r];if(i===void 0){let t=e[r];if(t.hasDefault)i=t.default;else throw RangeError(`No value supplied for attribute `+r)}n[r]=i}return n}function Bc(e,t,n,r){for(let i in t)if(!(i in e))throw RangeError(`Unsupported attribute ${i} for ${n} of type ${r}`);for(let n in e)e[n].validate&&e[n].validate(t[n])}function Vc(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new Wc(e,r,t[r]);return n}var Hc=class e{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(` `):[],this.attrs=Vc(e,n.attrs),this.defaultAttrs=Rc(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e==`text`),this.isText=e==`text`}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==wc.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?`pre`:`normal`)}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:zc(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new xc(this,this.computeAttrs(e),Xs.from(t),ec.setFrom(n))}createChecked(e=null,t,n){return t=Xs.from(t),this.checkContent(t),new xc(this,this.computeAttrs(e),t,ec.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=Xs.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(Xs.empty,!0);return i?new xc(this,e,t.append(i),ec.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){Bc(this.attrs,e,`node`,this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||=e.slice(0,n);return t?t.length?t:ec.none:e}static compile(t,n){let r=Object.create(null);t.forEach((t,i)=>r[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function Uc(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var Wc=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?Uc(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},Gc=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=Vc(e,r.attrs),this.excluded=null;let i=Rc(this.attrs);this.instance=i?new ec(this,i):null}create(e=null){return!e&&this.instance?this.instance:new ec(this,zc(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){Bc(this.attrs,e,`mark`,this.name)}excludes(e){return this.excluded.indexOf(e)>-1}},Kc=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=Gs.from(e.nodes),t.marks=Gs.from(e.marks||{}),this.nodes=Hc.compile(this.spec.nodes,this),this.marks=Gc.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=wc.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?qc(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:qc(this,n.split(` `))}this.nodeFromJSON=e=>xc.fromJSON(this,e),this.markFromJSON=e=>ec.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof Hc))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new Sc(n,n.defaultAttrs,e,ec.setFrom(t))}mark(e,t){return typeof e==`string`&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type: `+e);return t}};function qc(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],a=e.marks[i],o=a;if(a)n.push(a);else for(let t in e.marks){let r=e.marks[t];(i==`_`||r.spec.group&&r.spec.group.split(` `).indexOf(i)>-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function Jc(e){return e.tag!=null}function Yc(e){return e.style!=null}var Xc=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(Jc(e))this.tags.push(e);else if(Yc(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new al(this,t,!1);return n.addAll(e,ec.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new al(this,t,!0);return n.addAll(e,ec.none,t.from,t.to),nc.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(sl(e,n.tag)&&(n.namespace===void 0||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(t===!1)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],a=r.style;if(!(a.indexOf(e)!=0||r.context&&!n.matchesContext(r.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((e.priority==null?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=cl(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=cl(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},Zc={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Qc={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},$c={ol:!0,ul:!0},el=1,tl=2,nl=4;function rl(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?el:0)|(t===`full`?tl:0)}var il=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=ec.none,this.match=i||(a&nl?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Xs.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&el)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=Xs.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Xs.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Zc.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},al=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=rl(null,t.preserveWhitespace,0)|(n?nl:0);i=r?new il(r.type,r.attrs,ec.none,!0,t.topMatch||r.type.contentMatch,a):n?new il(null,null,ec.none,!0,null,a):new il(e.schema.topNodeType,null,ec.none,!0,null,a),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=r.options&tl?`full`:this.localPreserveWS||(r.options&el)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,`
|
|
440
440
|
`);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(a.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(a.text(e[n]),t,!/\S/.test(e[n]));n=``}else n=n.replace(/\r?\n|\r/g,` `);n&&this.insertNode(a.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;(e.tagName==`PRE`||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let a=e.nodeName.toLowerCase(),o;$c.hasOwnProperty(a)&&this.parser.normalizeLists&&ol(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,n));out:if(s?s.ignore:Qc.hasOwnProperty(a))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let n,r=this.needsBlock;if(Zc.hasOwnProperty(a))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break out}let o=s&&s.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,s,n,s.consuming===!1?o:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName==`BR`&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
@@ -1074,7 +1074,7 @@ Expected it to be ${r}.`}var cW=class extends Error{name=`InvalidDocError`;const
|
|
|
1074
1074
|
`),this.column=r,this.excerpt=i,this.line=a,this.name=`XmlError`,this.pos=t}},M=class extends w{constructor(e,t=``){super(),this.name=e,this.content=t}get type(){return w.TYPE_PROCESSING_INSTRUCTION}toJSON(){return Object.assign(w.prototype.toJSON.call(this),{name:this.name,content:this.content})}},te=``,ne=class{constructor(e,t={}){let n=this.document=new A;this.j=n,this.g=t,this.c=new f(e),this.g.includeOffsets&&(n.start=0,n.end=e.length),this.parse()}i(e,t){return e.parent=this.j,this.g.includeOffsets&&(e.start=this.c.f(t),e.end=this.c.f()),this.j.children.push(e),!0}y(e,t){let{children:n}=this.j,{length:r}=n;if(e=N(e),r>0){let t=n[r-1];if(t?.type===w.TYPE_TEXT){let n=t;return n.text+=e,this.g.includeOffsets&&(n.end=this.c.f()),!0}}return this.i(new T(e),t)}H(){let e=Object.create(null);for(;this.e();){let t=this.q();if(!t)break;let n=this.t()&&this.I();if(n===!1)throw this.a(`Attribute value expected`);if(t in e)throw this.a(`Duplicate attribute: ${t}`);if(t===`xml:space`&&n!=="default"&&n!==`preserve`)throw this.a('Value of the `xml:space` attribute must be "default" or "preserve"');e[t]=n}if(this.g.sortAttributes){let t=Object.keys(e).sort(),n=Object.create(null);for(let r=0;r<t.length;++r){let i=t[r];n[i]=e[i]}e=n}return e}I(){let{c:e}=this,t=e.m();if(t!==`"`&&t!==`'`)return!1;e.p();let n,r=!1,i=te,a=t===`"`?p:m;matchLoop:for(;!e.B;)switch(n=e.x(a),n&&(this.o(n),i+=n.replace(h,` `)),e.m()){case t:r=!0;break matchLoop;case`&`:i+=this.C();continue;case`<`:throw this.a("Unescaped `<` is not allowed in an attribute value");default:break matchLoop}if(!r)throw this.a(`Unclosed attribute`);return e.p(),i}J(){let{c:e}=this,t=e.d;if(!e.b(`<![CDATA[`))return!1;let n=e.s(`]]>`);if(this.o(n),!e.b(`]]>`))throw this.a(`Unclosed CDATA section`);return this.g.preserveCdata?this.i(new E(N(n)),t):this.y(n,t)}K(){let{c:e}=this,t=e.d,n=e.x(g);if(!n)return!1;if(this.o(n),e.m(3)===`]]>`)throw this.a("Element content may not contain the CDATA section close delimiter `]]>`");return this.y(n,t)}D(){let{c:e}=this,t=e.d;if(!e.b(`<!--`))return!1;let n=e.s(`--`);if(this.o(n),!e.b(`-->`))throw e.m(2)===`--`?this.a("The string `--` isn't allowed inside a comment"):this.a(`Unclosed comment`);return this.g.preserveComments?this.i(new D(N(n)),t):!0}L(){let e=this.c.d,t=this.C();return t?this.y(t,e):!1}M(){let{c:e}=this,t=e.d;if(!e.b(`<!DOCTYPE`))return!1;let n=this.e()&&this.q();if(!n)throw this.a(`Expected a name`);let r,i;if(this.e()){if(e.b(`PUBLIC`)){if(r=this.e()&&this.N(),r===!1)throw this.a(`Expected a public identifier`);this.e()}if(r!==void 0||e.b(`SYSTEM`)){if(this.e(),i=this.r(),i===!1)throw this.a(`Expected a system identifier`);this.e()}}let a;if(e.b(`[`)){if(a=e.x(/\][\x20\t\r\n]*>/),!e.b(`]`))throw this.a(`Unclosed internal subset`);this.e()}if(!e.b(`>`))throw this.a(`Unclosed doctype declaration`);return this.g.preserveDocumentType?this.i(new j(n,r,i,a),t):!0}E(){let{c:e}=this,t=e.d;if(!e.b(`<`))return!1;let n=this.q();if(!n)return e.n(t),!1;let r=this.H(),i=!!e.b(`/>`),a=new k(n,r);if(a.parent=this.j,!i){if(!e.b(`>`))throw this.a(`Unclosed start tag for element \`${n}\``);this.j=a;do this.K();while(this.E()||this.L()||this.J()||this.F()||this.D());let t=e.d,r;if(!e.b(`</`)||!(r=this.q())||r!==n)throw e.n(t),this.a(`Missing end tag for element ${n}`);if(this.e(),!e.b(`>`))throw this.a(`Unclosed end tag for element ${n}`);this.j=a.parent}return this.i(a,t)}t(){return this.e(),this.c.b(`=`)?(this.e(),!0):!1}z(){return this.D()||this.F()||this.e()}q(){return y(this.c.m())?this.c.w(v):te}F(){let{c:e}=this,t=e.d;if(!e.b(`<?`))return!1;let n=this.q();if(n){if(n.toLowerCase()===`xml`)throw e.n(t),this.a(`XML declaration isn't allowed here`)}else throw this.a(`Invalid processing instruction`);if(!this.e()){if(e.b(`?>`))return this.i(new M(n),t);throw this.a(`Whitespace is required after a processing instruction name`)}let r=e.s(`?>`);if(this.o(r),!e.b(`?>`))throw this.a(`Unterminated processing instruction`);return this.i(new M(n,N(r)),t)}O(){let{c:e}=this,t=e.d;for(this.P();this.z(););if(this.M())for(;this.z(););return t<e.d}N(){let e=this.c.d,t=this.r();if(t!==!1&&!/^[-\x20\r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(t))throw this.c.n(e),this.a(`Invalid character in public identifier`);return t}C(){let{c:e}=this;if(!e.b(`&`))return!1;let t=e.w(b);if(e.G()!==`;`)throw this.a("Unterminated reference (a reference must end with `;`)");let n;if(t[0]===`#`){let e=t[1]===`x`?parseInt(t.slice(2),16):parseInt(t.slice(1),10);if(isNaN(e))throw this.a(`Invalid character reference`);if(!S(e))throw this.a(`Character reference resolves to an invalid character`);n=String.fromCodePoint(e)}else if(n=_[t],n===void 0){let{ignoreUndefinedEntities:n,resolveUndefinedEntity:r}=this.g,i=`&${t};`;if(r){let e=r(i);if(e!=null){let t=typeof e;if(t!==`string`)throw TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${t}`);return e}}if(n)return i;throw e.n(-i.length),this.a(`Named entity isn't defined: ${i}`)}return n}r(){let{c:e}=this,t=e.b(`"`)||e.b(`'`);if(!t)return!1;let n=e.s(t);if(this.o(n),!e.b(t))throw this.a(`Missing end quote`);return n}e(){return!!this.c.w(x)}P(){let{c:e}=this,t=e.d;if(!e.b(`<?xml`))return!1;if(!this.e())throw this.a(`Invalid XML declaration`);let n=!!e.b(`version`)&&this.t()&&this.r();if(n===!1)throw this.a(`XML version is missing or invalid`);if(!/^1\.[0-9]+$/.test(n))throw this.a(`Invalid character in version number`);let r,i;if(this.e()){if(r=!!e.b(`encoding`)&&this.t()&&this.r(),r){if(!/^[A-Za-z][\w.-]*$/.test(r))throw this.a(`Invalid character in encoding name`);this.e()}if(i=!!e.b(`standalone`)&&this.t()&&this.r(),i){if(i!==`yes`&&i!==`no`)throw this.a('Only "yes" and "no" are permitted as values of `standalone`');this.e()}}if(!e.b(`?>`))throw this.a(`Invalid or unclosed XML declaration`);return this.g.preserveXmlDeclaration?this.i(new O(n,r||void 0,i||void 0),t):!0}a(e){let{c:t}=this;return new ee(e,t.d,t.h)}parse(){if(this.c.b(``),this.O(),!this.E())throw this.a(`Root element is missing or invalid`);for(;this.z(););if(!this.c.B)throw this.a(`Extra content at the end of the document`)}o(e){let{length:t}=e;for(let n=0;n<t;++n){let t=e.codePointAt(n);if(!S(t))throw this.c.n(-([...e].length-n)),this.a(`Invalid character`);t>65535&&(n+=1)}}};function N(e){let t=0;for(;(t=e.indexOf(`\r`,t))!==-1;)e=e[t+1]===`
|
|
1075
1075
|
`?e.slice(0,t)+e.slice(t+1):e.slice(0,t)+`
|
|
1076
1076
|
`+e.slice(t+1);return e}function re(e,t){return new ne(e,t).document}}));function q3(e){let t=String(e),n=[];return{toOffset:i,toPoint:r};function r(e){if(typeof e==`number`&&e>-1&&e<=t.length){let r=0;for(;;){let i=n[r];if(i===void 0){let e=J3(t,n[r-1]);i=e===-1?t.length+1:e+1,n[r]=i}if(i>e)return{line:r+1,column:e-(r>0?n[r-1]:0)+1,offset:e};r++}}}function i(e){if(e&&typeof e.line==`number`&&typeof e.column==`number`&&!Number.isNaN(e.line)&&!Number.isNaN(e.column)){for(;n.length<e.line;){let e=n[n.length-1],r=J3(t,e),i=r===-1?t.length+1:r+1;if(e===i)break;n.push(i)}let r=(e.line>1?n[e.line-2]:0)+e.column-1;if(r<n[e.line-1])return r}}}function J3(e,t){let n=e.indexOf(`\r`,t),r=e.indexOf(`
|
|
1077
|
-
`,t);return r===-1?n:n===-1||n+1===r?r:n<r?n:r}var Y3=K3();function X3(e){let t=q3(e),n;try{n=(0,Y3.parseXml)(String(e),{includeOffsets:!0,preserveCdata:!0,preserveComments:!0,preserveDocumentType:!0,preserveXmlDeclaration:!0})}catch(e){let n=e,r=new SJ("Could not parse XML with `@rgrove/parse-xml`",{cause:n,place:t.toPoint(n.pos),ruleId:`error`,source:`xast-util-from-xml`});throw r.fatal=!0,r.url=`https://github.com/syntax-tree/xast-util-from-xml#throws`,r}let r={location:t},i=$3(n,r);return o6(n,i,r),i}function Z3(e){return{type:`cdata`,value:e.text}}function Q3(e){return{type:`comment`,value:e.content}}function $3(e,t){return{type:`root`,children:a6(e.children,t)}}function e6(e){return{type:`doctype`,name:e.name,public:e.publicId||void 0,system:e.systemId||void 0}}function t6(e,t){let n=a6(e.children,t);return{type:`element`,name:e.name,attributes:{...e.attributes},children:n}}function n6(e){return{type:`instruction`,name:e.name,value:e.content}}function r6(e){return{type:`text`,value:e.text}}function i6(e){let t=[];return e.version&&t.push(`version="`+e.version+`"`),e.encoding&&t.push(`encoding="`+e.encoding+`"`),e.standalone&&t.push(`standalone="`+e.standalone+`"`),{type:`instruction`,name:`xml`,value:t.join(` `)}}function a6(e,t){let n=[],r=-1;for(;++r<e.length;){let i=e[r],a;i.type===`cdata`?a=Z3(i):i.type===`comment`?a=Q3(i):i.type===`doctype`?a=e6(i):i.type===`element`?a=t6(i,t):i.type===`pi`?a=n6(i):i.type===`text`?a=r6(i):i.type===`xmldecl`&&(a=i6(i)),a&&(o6(i,a,t),n.push(a))}return n}function o6(e,t,n){let r=e.start===-1?void 0:n.location.toPoint(e.start),i=e.end===-1?void 0:n.location.toPoint(e.end);r&&i&&(t.position={start:r,end:i})}function s6(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/"/g,`"`)}function c6(e,t,n){if(e.isFile&&!e.fileRef&&!e.url)return`<!-- image asset "${t}" is marked as file-based but has no fileRef or url -->`;let r=e.isFile?` source="${s6(e.fileRef??e.url)}"`:``,i=n?` width="${s6(n)}"`:``,a=e.source?.trim();return a?`<image${r}${i}>\n${a}\n</image>`:`<image${r}${i}/>`}function l6(e,t){let n=e.source?.trim();return n?`<interactive xml:id="${s6(t)}">\n${n}\n</interactive>`:`<interactive xml:id="${s6(t)}"></interactive>`}var u6={image:c6,doenet:l6},d6=new Set(Object.keys(u6));function f6(e,t,n,r){let i=n.find(n=>n.kind===e&&n.ref===t);return i?u6[e](i,t,r):`<!-- missing asset: ${e} ${t} -->`}function p6(){return`sec-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function m6(e){let t=e.children.find(e=>e.type===`element`&&e.name===`title`);return t?t.children.filter(e=>e.type===`text`).map(e=>e.value).join(``).trim():``}var h6=new Set([`book`,`article`,`slideshow`,`part`,`chapter`,...new Set([`introduction`,`section`,`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`,`conclusion`])]);function g6(e){let t=0,n=e.length;for(;t<n;){let n=e[t];if(n.type!==`text`||/\S/.test(n.value))break;t+=1}for(;n>t;){let t=e[n-1];if(t.type!==`text`||/\S/.test(t.value))break;--n}return e.slice(t,n)}function _6(e){return e.replace(/^(?:[ \t]*\r?\n)+/,``).replace(/(?:\r?\n[ \t]*)+$/,``)}function v6(e){try{return X3(e)}catch{return null}}function y6(e){let t=v6(`<__title__>${e}</__title__>`)?.children.find(e=>e.type===`element`);return t?t.children:[{type:`text`,value:e}]}function b6(e){let t=e.match(/^\s*<([A-Za-z_][\w.:-]*)\b[^>]*?>/);if(!t||t.index===void 0)return e;let n=e.slice(t.index+t[0].length),r=RegExp(`\\s*</${
|
|
1077
|
+
`,t);return r===-1?n:n===-1||n+1===r?r:n<r?n:r}var Y3=K3();function X3(e){let t=q3(e),n;try{n=(0,Y3.parseXml)(String(e),{includeOffsets:!0,preserveCdata:!0,preserveComments:!0,preserveDocumentType:!0,preserveXmlDeclaration:!0})}catch(e){let n=e,r=new SJ("Could not parse XML with `@rgrove/parse-xml`",{cause:n,place:t.toPoint(n.pos),ruleId:`error`,source:`xast-util-from-xml`});throw r.fatal=!0,r.url=`https://github.com/syntax-tree/xast-util-from-xml#throws`,r}let r={location:t},i=$3(n,r);return o6(n,i,r),i}function Z3(e){return{type:`cdata`,value:e.text}}function Q3(e){return{type:`comment`,value:e.content}}function $3(e,t){return{type:`root`,children:a6(e.children,t)}}function e6(e){return{type:`doctype`,name:e.name,public:e.publicId||void 0,system:e.systemId||void 0}}function t6(e,t){let n=a6(e.children,t);return{type:`element`,name:e.name,attributes:{...e.attributes},children:n}}function n6(e){return{type:`instruction`,name:e.name,value:e.content}}function r6(e){return{type:`text`,value:e.text}}function i6(e){let t=[];return e.version&&t.push(`version="`+e.version+`"`),e.encoding&&t.push(`encoding="`+e.encoding+`"`),e.standalone&&t.push(`standalone="`+e.standalone+`"`),{type:`instruction`,name:`xml`,value:t.join(` `)}}function a6(e,t){let n=[],r=-1;for(;++r<e.length;){let i=e[r],a;i.type===`cdata`?a=Z3(i):i.type===`comment`?a=Q3(i):i.type===`doctype`?a=e6(i):i.type===`element`?a=t6(i,t):i.type===`pi`?a=n6(i):i.type===`text`?a=r6(i):i.type===`xmldecl`&&(a=i6(i)),a&&(o6(i,a,t),n.push(a))}return n}function o6(e,t,n){let r=e.start===-1?void 0:n.location.toPoint(e.start),i=e.end===-1?void 0:n.location.toPoint(e.end);r&&i&&(t.position={start:r,end:i})}function s6(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/"/g,`"`)}function c6(e,t,n){if(e.isFile&&!e.fileRef&&!e.url)return`<!-- image asset "${t}" is marked as file-based but has no fileRef or url -->`;let r=e.isFile?` source="${s6(e.fileRef??e.url)}"`:``,i=n?` width="${s6(n)}"`:``,a=e.source?.trim();return a?`<image${r}${i}>\n${a}\n</image>`:`<image${r}${i}/>`}function l6(e,t){let n=e.source?.trim();return n?`<interactive xml:id="${s6(t)}">\n${n}\n</interactive>`:`<interactive xml:id="${s6(t)}"></interactive>`}var u6={image:c6,doenet:l6},d6=new Set(Object.keys(u6));function f6(e,t,n,r){let i=n.find(n=>n.kind===e&&n.ref===t);return i?u6[e](i,t,r):`<!-- missing asset: ${e} ${t} -->`}function p6(){return`sec-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function m6(e){let t=e.children.find(e=>e.type===`element`&&e.name===`title`);return t?t.children.filter(e=>e.type===`text`).map(e=>e.value).join(``).trim():``}var h6=new Set([`book`,`article`,`slideshow`,`part`,`chapter`,...new Set([`introduction`,`section`,`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`,`conclusion`])]);function g6(e){let t=0,n=e.length;for(;t<n;){let n=e[t];if(n.type!==`text`||/\S/.test(n.value))break;t+=1}for(;n>t;){let t=e[n-1];if(t.type!==`text`||/\S/.test(t.value))break;--n}return e.slice(t,n)}function _6(e){return e.replace(/^(?:[ \t]*\r?\n)+/,``).replace(/(?:\r?\n[ \t]*)+$/,``)}function v6(e){try{return X3(e)}catch{return null}}function y6(e){let t=v6(`<__title__>${e}</__title__>`)?.children.find(e=>e.type===`element`);return t?t.children:[{type:`text`,value:e}]}function b6(e){let t=e.match(/^\s*<([A-Za-z_][\w.:-]*)\b[^>]*?>/);if(!t||t.index===void 0)return e;let n=e.slice(t.index+t[0].length),r=RegExp(`\\s*</${$6(t[1])}\\s*>\\s*$`);return _6(n.replace(r,``))}function x6(e,t){let n=v6(e);if(!n)return e;let r=n.children.find(e=>e.type===`element`);if(!r)return e;let i=r.children.findIndex(e=>e.type===`element`&&e.name===`title`),a={type:`element`,name:`title`,attributes:{},children:y6(t)};return i===-1?r.children.unshift(a):r.children.splice(i,1,a),FY(n)}function S6(e=`New Section`){let t=p6();return{id:t,xmlId:t,title:e,content:`<section xml:id="${t}">\n\t<title>${e}</title>\n\n\t<p>\n\n\t</p>\n\n</section>`,type:`section`,sourceFormat:`pretext`}}function C6(){let e=p6();return{id:e,xmlId:e,title:`Introduction`,content:`<introduction xml:id="${e}">\n\n\t<p>\n\n\t</p>\n\n</introduction>`,type:`introduction`,sourceFormat:`pretext`}}function w6(){let e=p6();return{id:e,xmlId:e,title:`Conclusion`,content:`<conclusion xml:id="${e}">\n\n\t<p>\n\n\t</p>\n\n</conclusion>`,type:`conclusion`,sourceFormat:`pretext`}}function T6(e){let t=v6(e);if(!t)return b6(e);let n=t.children.find(e=>e.type===`element`);return n?g8(FY({type:`root`,children:g6(n.children)})):e}function E6(e,t){return`<${t}>\n${_6(e)}\n</${t}>`}function D6(e,t){return e.trimStart().startsWith(`<${t}`)?e:E6(e,t)}function O6(e,t){if(t===`introduction`||t===`conclusion`)return e;let n=e.trimStart();return n.startsWith(`\\begin{section}`)?n.replace(/^\\begin\{section\}\s*\n?/,``).replace(/\n?\\end\{section\}\s*$/,``):e.replace(/^\\section\*?\{[^}]*\}\s*\n?/,``)}function k6(e,t,n,r){return t===`introduction`||t===`conclusion`?e:r?.trimStart().startsWith(`\\begin{section}`)?`\\begin{section}\n\n${e}\n\n\\end{section}`:`\\section{${n}}\n\n${e}`}function A6(e,t,n,r){if(t===`introduction`||t===`conclusion`)return e;let i=e.trimStart();return i.startsWith(`\\section`)||i.startsWith(`\\begin{section}`)?e:k6(e,t,n,r)}var j6=/^(\s*)\\(?!begin\b|end\b)[A-Za-z][A-Za-z-]*(\*?\{)/;function M6(e,t){let n=/^(\s*\\(?!begin\b|end\b)[A-Za-z][A-Za-z-]*\*?\{)[^}]*/;return n.test(e)?e.replace(n,(e,n)=>`${n}${t}`):e.includes(`\\begin{section}`)?/\\title\{/.test(e)?e.replace(/\\title\{[^}]*\}/,`\\title{${t}}`):e.replace(`\\begin{section}`,`\\begin{section}\n\n\\title{${t}}\n\n`):e}function N6(e){let t=/^\s*\\(?!begin\b|end\b)[A-Za-z][A-Za-z-]*\*?\{([^}]*)\}/.exec(e);if(t)return t[1].trim();if(e.includes(`\\begin{section}`)){let t=/\\title\{([^}]*)\}/.exec(e);if(t)return t[1].trim()}return null}function P6(e){return/^\s*\\(?!begin\b|end\b)[A-Za-z][A-Za-z-]*\*?\{[^}]*\}\s*\\label\{([^}]*)\}/.exec(e)?.[1]?.trim()??``}function F6(e,t){let n=e.content;return t.type!==void 0&&(n=n.replace(j6,`$1\\${t.type}$2`)),t.title!==void 0&&(n=M6(n,t.title)),t.xmlId!==void 0&&(n=n.replace(/^(\s*\\(?!begin\b|end\b)[A-Za-z][A-Za-z-]*\*?\{[^}]*\})(\s*\\label\{[^}]*\})?/,(e,n)=>t.xmlId==null||t.xmlId===``?n:`${n}\\label{${t.xmlId}}`)),{...e,content:n,title:t.title??e.title,type:t.type??e.type,xmlId:t.xmlId||e.xmlId}}function I6(e){let{pretextSource:t,pretextError:n}=_3(e.content,`latex`);return n||t===void 0?null:x8.has(e.type)?`<${e.type} xml:id="${e.xmlId}">\n<title>${e.title}</title>\n\n${t}\n</${e.type}>`:t}function L6(e=`New Section`){let t=p6();return{id:t,xmlId:t,title:e,content:`\\section{${e}}\n\n`,type:`section`,sourceFormat:`latex`}}function R6(){let e=p6();return{id:e,xmlId:e,title:`Introduction`,content:`% Introduction
|
|
1078
1078
|
|
|
1079
1079
|
`,type:`introduction`,sourceFormat:`latex`}}function z6(){let e=p6();return{id:e,xmlId:e,title:`Conclusion`,content:`% Conclusion
|
|
1080
1080
|
|
|
@@ -1082,12 +1082,12 @@ Expected it to be ${r}.`}var cW=class extends Error{name=`InvalidDocError`;const
|
|
|
1082
1082
|
|
|
1083
1083
|
`+n.trimStart()}}let r=v6(e.content),i=v6(t.content),a=r?.children.find(e=>e.type===`element`),o=i?.children.find(e=>e.type===`element`);if(!a||!o)return{...e,content:e.content+`
|
|
1084
1084
|
|
|
1085
|
-
`+t.content};let s=o.children.filter(e=>!(e.type===`element`&&e.name===`title`)),c={...a,children:[...a.children,...s]};return{...e,content:FY({type:`root`,children:[c]})}}function V6(e){try{let t=X3(e).children.find(e=>e.type===`element`);return t?{xmlId:t.attributes?.[`xml:id`]??``,label:t.attributes?.label??``}:{xmlId:``,label:``}}catch{return{xmlId:``,label:``}}}function H6(e){return e.trim().replace(/[^A-Za-z0-9_-]/g,`-`).replace(/^[^A-Za-z_]+/,``)}function U6(e){let t=v6(e);if(!t)return null;let n=t.children.find(e=>e.type===`element`);return!n||!h6.has(n.name)?null:{title:m6(n),type:n.name,xmlId:n.attributes?.[`xml:id`]??``,label:n.attributes?.label??``}}function
|
|
1086
|
-
`)}\n---`}function
|
|
1085
|
+
`+t.content};let s=o.children.filter(e=>!(e.type===`element`&&e.name===`title`)),c={...a,children:[...a.children,...s]};return{...e,content:FY({type:`root`,children:[c]})}}function V6(e){try{let t=X3(e).children.find(e=>e.type===`element`);return t?{xmlId:t.attributes?.[`xml:id`]??``,label:t.attributes?.label??``}:{xmlId:``,label:``}}catch{return{xmlId:``,label:``}}}function H6(e){return e.trim().replace(/[^A-Za-z0-9_-]/g,`-`).replace(/^[^A-Za-z_]+/,``)}function U6(e){return H6(e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``))}function W6(e){let t=v6(e);if(!t)return null;let n=t.children.find(e=>e.type===`element`);return!n||!h6.has(n.name)?null:{title:m6(n),type:n.name,xmlId:n.attributes?.[`xml:id`]??``,label:n.attributes?.label??``}}function G6(e,t){let n=t.type??e.type,r=t.title??e.title;try{let i=X3(e.content).children.find(e=>e.type===`element`);if(!i)return{...e,title:r,type:n};let a={...i,name:n,attributes:{...i.attributes}};t.xmlId!==void 0&&(t.xmlId===null||t.xmlId===``?delete a.attributes[`xml:id`]:a.attributes[`xml:id`]=t.xmlId),t.label!==void 0&&(t.label===null||t.label===``?delete a.attributes.label:a.attributes.label=t.label);let o=a.children.findIndex(e=>e.type===`element`&&e.name===`title`),s={type:`element`,name:`title`,attributes:{},children:y6(r)};o===-1?a.children=[s,...a.children]:a.children=[...a.children.slice(0,o),s,...a.children.slice(o+1)];let c=FY({type:`root`,children:[a]}),l=t.xmlId!==void 0&&t.xmlId!==null&&t.xmlId!==``?t.xmlId:e.xmlId;return{...e,title:r,type:n,xmlId:l,content:c}}catch{return{...e,title:r,type:n}}}var K6=/^\uFEFF?[ \t]*---[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*---[ \t]*(?:\r?\n|$)/;function q6(e){let t=K6.exec(e);if(!t)return null;let n=e.slice(t[0].length),r=`section`,i=``,a=``;for(let e of t[1].split(/\r?\n/)){let t=/^[ \t]*(xmlid|xml:id|division|label)[ \t]*:[ \t]*(.*)$/.exec(e);if(!t)continue;let n=t[2].trim().replace(/^["']|["']$/g,``);t[1]===`division`?r=n:t[1]===`xmlid`||t[1]===`xml:id`?i=n:a=n}return{type:r||`section`,xmlId:i,label:a,body:n}}function J6(e){let t=[`division: ${e.type}`,`xmlid: ${e.xmlId}`];return e.label&&t.push(`label: ${e.label}`),`---\n${t.join(`
|
|
1086
|
+
`)}\n---`}function Y6(e){let t=/^[ \t]*#[ \t]+(.*)$/m.exec(e);return t?t[1].trim():null}function X6(e,t){let n=/^[ \t]*#[ \t]+.*$/m.exec(e);return n?e.slice(0,n.index)+`# ${t}`+e.slice(n.index+n[0].length):`# ${t}\n\n${e.replace(/^\s+/,``)}`}function Z6(e){let t=q6(e);return t?{title:Y6(t.body)??``,type:t.type,xmlId:t.xmlId,label:t.label}:null}function Q6(e,t){let n=q6(e.content),r=n?n.body:e.content,i=n?.type??e.type,a=n?.xmlId??e.xmlId,o=n?.label??``,s=t.type??i,c=(t.xmlId===void 0?a:t.xmlId??``)||e.xmlId,l=t.label===void 0?o:t.label??``,u=t.title===void 0?r:X6(r,t.title),d=`${J6({type:s,xmlId:c,label:l})}\n${u}`;return{...e,title:t.title??e.title,type:s,xmlId:c,content:d}}function $6(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}var e8=new Set([`division`,...h6]),t8=Array.from(e8).join(`|`);function n8(e){let t=e===null?`ref="([^"]+)"`:`ref="${$6(e)}"`,n=`(?:${t8})`;return`<plus:${n}\\s[^>]*${t}[^>]*?(?:/>|>\\s*</plus:${n}>)`}function r8(e){let t=[],n=new RegExp(n8(null),`g`),r;for(;(r=n.exec(e))!==null;)t.push(r[1]);return t}function i8(e){let t=[],n=`(?:${t8})`,r=RegExp(`<plus:(${t8})\\s[^>]*ref="([^"]+)"[^>]*?(?:/>|>\\s*</plus:${n}>)`,`g`),i;for(;(i=r.exec(e))!==null;){let e=i[1],n=e===`division`?`section`:e;t.push({type:n,xmlId:i[2]})}return t}function a8(e){let t=[],n=/<plus:(image|doenet)\b[^>]*\bref="([^"]+)"/g,r;for(;(r=n.exec(e))!==null;)t.push({kind:r[1],ref:r[2]});return t}function o8(e,t,n,r){let i=RegExp(`(<plus:${$6(t)}\\b[^>]*?\\bref=")${$6(n)}(")`,`g`);return e.replace(i,`$1${r}$2`)}function s8(e,t,n){let r=RegExp(`<plus:${$6(t)}\\b[^>]*?\\bref="${$6(n)}"[^>]*/?>`,`g`);return e.replace(r,``)}function c8(e,t,n=`pretext`){let r=`New ${t.charAt(0).toUpperCase()+t.slice(1)}`;return{id:e,xmlId:e,title:r,type:t,sourceFormat:n,content:l8(t,n,r,e)}}function l8(e,t,n,r){return t===`latex`?e===`introduction`||e===`conclusion`?`% ${n}\n\n`:`\\${e}{${n}}\\label{${r}}\n\n`:t===`markdown`?`${J6({type:e,xmlId:r,label:``})}\n# ${n}\n\n`:e===`introduction`||e===`conclusion`?`<${e} xml:id="${r}">\n\n\t<p>\n\n\t</p>\n\n</${e}>`:`<${e} xml:id="${r}">\n\t<title>${n}</title>\n\n\t<p>\n\n\t</p>\n\n</${e}>`}function u8(e,t,n,r){let i=`<plus:${n} ref="${t}"/>`;if(r!==null){let t=new RegExp(n8(r)).exec(e);if(t){let n=t.index+t[0].length;return e.slice(0,n)+`
|
|
1087
1087
|
`+i+e.slice(n)}}let a=e.lastIndexOf(`</`);return a===-1?e+`
|
|
1088
1088
|
`+i:e.slice(0,a)+i+`
|
|
1089
|
-
`+e.slice(a)}function
|
|
1089
|
+
`+e.slice(a)}function d8(e,t){let n=RegExp(`[ \t]*${n8(t)}[ \t]*\n?`,`g`);return e.replace(n,``)}function f8(e,t,n){let r=new RegExp(n8(t)).exec(e),i=r?g8(r[0]):`<plus:division ref="${t}"/>`,a=d8(e,t);if(n!==null){let e=new RegExp(n8(n)).exec(a);if(e){let t=e.index+e[0].length;return a.slice(0,t)+`
|
|
1090
1090
|
`+i+a.slice(t)}}let o=a.lastIndexOf(`</`);return o===-1?a+`
|
|
1091
1091
|
`+i:a.slice(0,o)+i+`
|
|
1092
|
-
`+a.slice(o)}function f8(e,t,n,r){let i=new RegExp(t8(t));return i.test(e)?e.replace(i,`<plus:${r} ref="${n}"/>`):e}function p8(e,t){let n=new RegExp(t8(t));return e.find(e=>n.test(e.content))??null}function m8(e,t){let n=e,r=null;for(let e of t)n=d8(n,e,r),r=e;return n}function h8(e){return e.replace(/<plus:([a-z-]+)((?:\s[^>]*?)?)>\s*<\/plus:\1>/g,(e,t,n)=>`<plus:${t}${n}/>`)}function g8(e,t){let n=new Set,r=[t];for(;r.length>0;){let t=r.pop();if(n.has(t))continue;n.add(t);let i=e.find(e=>e.xmlId===t);if(i)for(let e of n8(i.content))r.push(e)}return n}function _8(e,t){let n=g8(e,t);return e.filter(e=>!n.has(e.xmlId))}function v8(e,t){let n=[],r=new Set([t]),i=(t,a)=>{let o=e.find(e=>e.xmlId===t);if(o)for(let s of n8(o.content)){if(r.has(s))continue;let o=e.find(e=>e.xmlId===s);o&&(r.add(s),n.push({division:o,depth:a,parentXmlId:t}),i(s,a+1))}};return i(t,0),n}function y8(e,t){let n=_8(e,t),r=new Set(n.map(e=>e.xmlId)),i=new Set;for(let e of n)for(let t of n8(e.content))r.has(t)&&i.add(t);return n.filter(e=>!i.has(e.xmlId))}var b8=new Set([`book`,`article`,`slideshow`]);function x8(e){try{let t=X3(e),n=t.children.find(e=>e.type===`element`),r=n?.name===`pretext`?n.children.find(e=>e.type===`element`&&b8.has(e.name)):n&&b8.has(n.name)?n:void 0;if(!r)return e;if(!r.attributes.label){let e=C8(t,`pretext-plus-preview`);return r.attributes.label=e,FY(t)}return e}catch(t){return console.error(`Error ensuring label:`,t),e}}function S8(e,t){return e.type===`element`&&e.attributes?.label===t?!0:`children`in e&&e.children?e.children.some(e=>e.type===`element`?S8(e,t):!1):!1}function C8(e,t){let n=t,r=1;for(;S8(e,n);)n=`${t}-${r}`,r++;return n}function w8(e,t,n,r){let i=t.find(t=>t.xmlId===e);if(!i)return`<!-- missing division: ${e} -->`;if(n.has(e))return`<!-- circular reference: ${e} -->`;let a;if(i.sourceFormat===`pretext`)a=i.content;else if(i.sourceFormat===`markdown`){let{pretextSource:e,pretextError:t}=_3(i.content,`markdown`);a=e??`<!-- conversion error: ${t} -->`}else a=I6(i)??`<!-- conversion error: ${i.xmlId} -->`;if(i.sourceFormat!==`pretext`)return a;let o=new Set(n).add(e);return a.replace(/<plus:([a-z-]+)\s([^>]*ref="[^"]+"[^>]*?)(?:\/>|>\s*<\/plus:\1>)/g,(e,n,i)=>{let a=/ref="([^"]+)"/.exec(i)?.[1]??``;if(!d6.has(n))return w8(a,t,o,r);let s=/width="([^"]+)"/.exec(i)?.[1];return f6(n,a,r,s)})}function T8(e,t,n=[]){return x8(w8(t,e,new Set,n))}function E8(e,t){return x8(`<pretext>\n${t.trim()?`${t.trim()}\n`:``}${e}\n</pretext>`)}function D8(e,t,n,r=[]){return E8(w8(t,e,new Set,r),n)}var O8=new Set([`part`,`chapter`]);function k8(e,t,n,r){return E8(b8.has(e)?t:O8.has(e)?`<book>\n<title>${r}</title>\n${t}\n</book>`:`<article>\n<title>${r}</title>\n${t}\n</article>`,n)}function A8(e){let t=e.trim(),n=t.match(/^<title\b[^>]*>([\s\S]*?)<\/title>\s*/);return n?{title:n[1].trim(),body:t.slice(n[0].length)}:{title:``,body:t}}function j8(e,t,n,r){let i=n===`book`?`book`:`article`;return e.map(e=>{if(e.sourceFormat===`markdown`){if(!e.title){let t=X6(e.content)?.title;if(t)return{...e,title:t}}return e}if(e.sourceFormat!==`pretext`)return e;let n=U6(e.content);if(e.xmlId===t&&!(n&&b8.has(n.type))){let{title:t,body:n}=A8(e.content),a=e.title||t||r||`Untitled`;return{...e,type:i,title:a,content:`<${i} xml:id="${e.xmlId}">\n<title>${a}</title>\n\n${n}\n</${i}>`}}return!e.title&&n?.title?{...e,title:n.title}:e})}function M8(e,t){let n=t??[],r=(e,t)=>n.find(n=>n.kind===e&&n.ref===t),i=[],a=new Set;for(let t of e??[])for(let{kind:e,ref:n}of i8(t.content)){let t=`${e}:${n}`;if(a.has(t))continue;a.add(t);let o=r(e,n);i.push({kind:e,ref:n,asset:o,inDocument:!0,status:o?`linked`:`unlinked`})}for(let e of n){if(!e.ref)continue;let t=`${e.kind}:${e.ref}`;a.has(t)||(a.add(t),i.push({kind:e.kind,ref:e.ref,asset:e,inDocument:!1,status:`unused`}))}return i}function N8(e,t){let n=`${e}-copy`;if(!t.has(n))return n;for(let e=2;;e++){let r=`${n}-${e}`;if(!t.has(r))return r}}var P8={image:`Images`,doenet:`Doenet`},F8=[`image`,`doenet`].filter(e=>e!==`doenet`||!1),I8=(e,t)=>`<plus:${e} ref="${t}"/>`,L8=({open:e,onClose:r,resolveTarget:i,replaceTarget:a,onLoadAssets:o,onLoadLibraryAssets:s,onAddFromLibrary:c,onUpload:l,onFetchUrl:u,onCreateDoenet:d,onRemoveAsset:f,onDuplicateAsset:p,onAssetAdded:m,onResolveRef:h,onReplaceAsset:g})=>{let _=T3(e=>e.divisions),v=T3(e=>e.projectAssets)??[],y=T3(e=>e.setProjectAssets),b=T3(e=>e.libraryAssets),x=T3(e=>e.openAssetEditor),S=T3(e=>e.openAssetResolver),C=T3(e=>e.removeAssetRefFromDocument),w=!!(o||s),[T,E]=(0,n.useState)(null),[D,O]=(0,n.useState)(!1),[k,A]=(0,n.useState)(null),j=v,ee=T??b??j,M=new Set(j.map(e=>e.id)),[te,ne]=(0,n.useState)(`in-document`),[N,re]=(0,n.useState)(null),[ie,ae]=(0,n.useState)(`library`),[oe,se]=(0,n.useState)(`library`),[P,ce]=(0,n.useState)(null),[le,ue]=(0,n.useState)(!1),[de,F]=(0,n.useState)(!1),[fe,pe]=(0,n.useState)(null),me=(0,n.useRef)(null),[he,ge]=(0,n.useState)(``),[I,_e]=(0,n.useState)(``),[ve,ye]=(0,n.useState)(!1),[be,xe]=(0,n.useState)(null),[Se,Ce]=(0,n.useState)(``),[L,we]=(0,n.useState)(``),[Te,Ee]=(0,n.useState)(!1),[R,De]=(0,n.useState)(null),[Oe,ke]=(0,n.useState)(null),[z,Ae]=(0,n.useState)(null),[je,Me]=(0,n.useState)(null),Ne=(0,n.useCallback)(()=>{!o&&!s||(O(!0),A(null),Promise.all([o?.()??Promise.resolve(null),s?.()??Promise.resolve(null)]).then(([e,t])=>{e!==null&&y(e),t!==null&&E(t)}).catch(e=>{A(e instanceof Error?e.message:`Failed to load assets.`)}).finally(()=>O(!1)))},[o,s,y]),Pe=(0,n.useRef)(Ne);if((0,n.useEffect)(()=>{Pe.current=Ne}),(0,n.useEffect)(()=>{e&&Pe.current()},[e]),(0,n.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,r]),!e)return null;let Fe=M8(_,j),Ie=(e,t)=>{if(a){g(a,e,!!t?.fromLibrary),r();return}if(m(e),i){e.ref&&h(i.kind,i.ref,e.ref),r();return}e.ref&&navigator.clipboard.writeText(I8(e.kind,e.ref)).catch(()=>{}),Me(e)},Le=(e,t)=>{let n=`${e}:${t}`;navigator.clipboard.writeText(I8(e,t)).catch(()=>{}),ke(n),setTimeout(()=>ke(e=>e===n?null:e),2e3)},Re=async e=>{if(!M.has(e.id)&&c){ce(e.id);try{await c(e)}finally{ce(null)}}Ie(e,{fromLibrary:!0})},ze=async e=>{if(l){pe(null),F(!0);try{Ie(await l(e))}catch(e){pe(e instanceof Error?e.message:`Upload failed.`)}finally{F(!1)}}},Be=async()=>{let e=he.trim();if(!e)return;let t=I.trim();if(u&&l){xe(null),ye(!0);try{let n=await u(e);Ie(await l(t?new File([n],t,{type:n.type}):n))}catch(e){xe(e instanceof Error?e.message:`Failed to add URL.`)}finally{ye(!1)}}else Ie({id:`url-${Date.now()}`,name:t||e,ref:e.split(`/`).pop()??`image`,kind:`image`,url:e})},Ve=async()=>{let e=Se.trim(),t=L.trim();if(!(!e||!t))if(d){De(null),Ee(!0);try{Ie(await d(e,t))}catch(e){De(e instanceof Error?e.message:`Failed to create activity.`)}finally{Ee(!1)}}else Ie({id:`doenet-${Date.now()}`,name:e,ref:t,kind:`doenet`})},He=e=>{let n=ee.filter(t=>t.kind===e);return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-library`,children:[w&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-toolbar`,children:[k&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__asset-load-error`,children:k}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__asset-library-refresh`,onClick:Ne,disabled:D,children:D?`Loading…`:`Refresh`})]}),D&&n.length===0?(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-empty-text`,children:`Loading…`}):n.length===0?(0,t.jsxs)(`p`,{className:`pretext-plus-editor__am-empty-text`,children:[`No `,P8[e].toLowerCase(),` assets in your library.`]}):(0,t.jsx)(`ul`,{className:`pretext-plus-editor__am-list`,children:n.map(e=>{let n=M.has(e.id),r=P===e.id;return(0,t.jsx)(`li`,{children:(0,t.jsxs)(`button`,{type:`button`,className:[`pretext-plus-editor__am-lib-row`,n?`pretext-plus-editor__am-lib-row--in-project`:``].filter(Boolean).join(` `),onClick:()=>Re(e),disabled:r||!e.ref,title:e.ref?n?`Use "${e.ref}"`:`Add to project & use "${e.ref}"`:`Asset has no reference — cannot use`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-info`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-name`,children:e.name}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-ref`,children:r?`Adding…`:e.ref})]}),n&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-badge`,children:`✓`})]})},e.id)})})]})},Ue=()=>{if(Fe.length===0)return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-placeholder`,children:[(0,t.jsx)(`p`,{children:`No assets in this project yet.`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:()=>{ne(`add`),re(null)},children:`Add an asset`})]});let e=F8.map(e=>({kind:e,rows:Fe.filter(t=>t.kind===e)})).filter(e=>e.rows.length>0),n=e=>{let n=`${e.kind}:${e.ref}`,i=z===n,a=()=>{e.status===`unlinked`?S(e.kind,e.ref):(x(e.kind,e.ref),r())};return(0,t.jsxs)(`li`,{className:`pretext-plus-editor__am-doc-row`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__am-row-info pretext-plus-editor__am-row-info--btn`,onClick:a,title:e.status===`unlinked`?`No asset for this reference — click to link or create one`:`Edit asset`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-name`,children:e.asset?.name??e.ref}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-ref`,children:e.ref})]}),e.status===`unlinked`&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-status pretext-plus-editor__am-status--warn`,title:`No asset for this reference`,children:`needs asset`}),e.status===`unused`&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-status`,title:`Not referenced in the document yet`,children:`not placed`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn`,onClick:a,children:e.status===`unlinked`?`Link / create`:`Edit`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn${Oe===n?` pretext-plus-editor__am-action-btn--done`:``}`,onClick:()=>Le(e.kind,e.ref),title:`Copy ${I8(e.kind,e.ref)}`,children:Oe===n?`Copied!`:`Copy embed code`}),p&&e.asset?.url&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn`,disabled:i,onClick:async()=>{Ae(n);try{await p(e.asset),r()}catch{Ae(null)}},title:`Create a copy of this asset under a new reference`,children:i?`Duplicating…`:`Duplicate`}),f&&e.asset&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn pretext-plus-editor__am-action-btn--danger`,onClick:()=>{e.inDocument&&!window.confirm(`Remove "${e.asset.name}" from the project? This also deletes its reference(s) from the document.`)||(f(e.asset),C(e.kind,e.ref),r())},title:`Remove from project`,children:`Remove`})]})]},n)};return(0,t.jsx)(`div`,{className:`pretext-plus-editor__am-in-doc`,children:e.map(({kind:e,rows:r})=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-group`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-header`,children:[(0,t.jsx)(`span`,{"aria-hidden":`true`,children:`📁`}),(0,t.jsx)(`span`,{children:P8[e]}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-count`,children:r.length})]}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__am-list`,children:r.map(n)})]},e))})},B=e=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-success`,children:[(0,t.jsxs)(`p`,{className:`pretext-plus-editor__am-success-title`,children:[`✓ Added “`,e.name,`” — embed code copied to clipboard`]}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`It now appears in the Assets list. Paste this where you want it to appear:`}),e.ref&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-embed-row`,children:[(0,t.jsx)(`code`,{className:`pretext-plus-editor__am-embed-code`,children:I8(e.kind,e.ref)}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn${Oe===`${e.kind}:${e.ref}`?` pretext-plus-editor__am-action-btn--done`:``}`,onClick:()=>Le(e.kind,e.ref),children:Oe===`${e.kind}:${e.ref}`?`Copied!`:`Copy again`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-success-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:()=>{Me(null),re(null),ne(`add`)},children:`Add another`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:()=>{Me(null),ne(`in-document`)},children:`Done`})]})]}),We=()=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-picker`,children:[(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-kind-picker-label`,children:`What kind of asset?`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-cards`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__am-kind-card`,onClick:()=>{re(`image`),ae(`library`)},children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-icon`,"aria-hidden":`true`,children:`🖼️`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-label`,children:`Image`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-hint`,children:`PNG, JPEG, SVG, etc.`})]}),!1,(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-card pretext-plus-editor__am-kind-card--soon`,"aria-disabled":`true`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-icon`,"aria-hidden":`true`,children:`✨`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-label`,children:`More coming soon`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-hint`,children:`Interactive activities and more`})]})]})]}),Ge=e=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure`,children:[e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-back-btn`,onClick:()=>re(null),children:`← Back`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar pretext-plus-editor__am-sub-tabs`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${ie===`library`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ae(`library`),children:`Library`}),l&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${ie===`upload`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ae(`upload`),children:`Upload`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${ie===`url`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ae(`url`),children:`External URL`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure-body`,children:[ie===`library`&&He(`image`),ie===`upload`&&l&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-upload`,children:[(0,t.jsxs)(`div`,{className:[`pretext-plus-editor__am-drop-zone`,le?`pretext-plus-editor__am-drop-zone--active`:``,de?`pretext-plus-editor__am-drop-zone--uploading`:``].filter(Boolean).join(` `),onDragOver:e=>{e.preventDefault(),ue(!0)},onDragLeave:()=>ue(!1),onDrop:e=>{e.preventDefault(),ue(!1);let t=e.dataTransfer.files[0];t&&ze(t)},onClick:()=>!de&&me.current?.click(),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),me.current?.click())},"aria-label":`Upload image — click or drag and drop`,children:[(0,t.jsx)(`input`,{ref:me,type:`file`,accept:`image/*`,className:`pretext-plus-editor__dialog-file-input`,onChange:e=>{let t=e.target.files?.[0];t&&ze(t)}}),de?(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-drop-text`,children:`Uploading…`}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-drop-icon`,"aria-hidden":`true`,children:`↑`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-drop-text`,children:`Drag & drop an image, or click to browse`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`PNG, JPEG, GIF, SVG, WebP`})]})]}),fe&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:fe})]}),ie===`url`&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-url-form`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-url-value`,children:`Image URL`}),(0,t.jsx)(`input`,{id:`am-url-value`,type:`url`,className:`pretext-plus-editor__am-input`,placeholder:`https://example.com/image.png`,value:he,onChange:e=>ge(e.target.value),disabled:ve,autoFocus:!0}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-url-name`,children:[`Name `,(0,t.jsx)(`span`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`(optional)`})]}),(0,t.jsx)(`input`,{id:`am-url-name`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`My image`,value:I,onChange:e=>_e(e.target.value),disabled:ve}),be&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:be}),he.trim()&&(0,t.jsx)(`img`,{src:he.trim(),alt:`Preview`,className:`pretext-plus-editor__am-url-preview`,onError:e=>{e.currentTarget.style.display=`none`}}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:Be,disabled:!he.trim()||ve,children:ve?`Adding…`:u&&l?`Add to Project`:`Add`})]})]})]}),Ke=e=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure`,children:[e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-back-btn`,onClick:()=>re(null),children:`← Back`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar pretext-plus-editor__am-sub-tabs`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${oe===`library`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>se(`library`),children:`Library`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${oe===`create`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>se(`create`),children:`Create New`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure-body`,children:[oe===`library`&&He(`doenet`),oe===`create`&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-create-form`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-doenet-name`,children:`Name`}),(0,t.jsx)(`input`,{id:`am-doenet-name`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`My Activity`,value:Se,onChange:e=>Ce(e.target.value),disabled:Te,autoFocus:!0}),(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-doenet-ref`,children:`Reference ID`}),(0,t.jsx)(`input`,{id:`am-doenet-ref`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`my-activity`,value:L,onChange:e=>we(e.target.value),disabled:Te}),(0,t.jsxs)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:[`The reference ID is used in the embed code: `,(0,t.jsx)(`code`,{children:I8(`doenet`,L||`my-activity`)})]}),R&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:R}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:Ve,disabled:!Se.trim()||!L.trim()||Te,children:Te?`Creating…`:d?`Create`:`Add`})]})]})]}),V=(e,n,i)=>(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsx)(`h2`,{className:`pretext-plus-editor__dialog-title`,children:n}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single`,children:[(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy pretext-plus-editor__am-resolve-hint`,children:i}),e===`doenet`?Ke(!1):Ge(!1)]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:r,children:`Cancel`})})]});return(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-overlay`,onClick:e=>e.target===e.currentTarget&&r(),children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog pretext-plus-editor__dialog--asset-manager`,role:`dialog`,"aria-modal":`true`,"aria-label":`Asset manager`,children:i?(e=>V(e.kind,`Link asset`,(0,t.jsxs)(t.Fragment,{children:[`The reference `,(0,t.jsx)(`code`,{children:e.ref}),` has no asset yet. Choose or create one — the reference in your document will be updated to match.`]})))(i):a?(e=>V(e.kind,`Replace asset`,(0,t.jsxs)(t.Fragment,{children:[`Choose or upload a new asset to replace `,(0,t.jsx)(`code`,{children:e.name}),`. Every place it’s used in your document will show the new asset.`]})))(a):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsx)(`h2`,{className:`pretext-plus-editor__dialog-title`,children:`Assets`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),je?(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single`,children:B(je)}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${te===`in-document`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ne(`in-document`),children:[`Assets`,Fe.length>0&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__asset-tab-count`,children:Fe.length})]}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${te===`add`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>{ne(`add`),re(null)},children:`Add Asset`})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single`,children:te===`in-document`?Ue():N===null?We():N===`image`?Ge(!0):Ke(!0)})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:r,children:`Close`})})]})})})},R8={automaticLayout:!0,minimap:{enabled:!1},wordWrap:`on`,insertSpaces:!0,tabSize:2,padding:{top:10,bottom:10},scrollBeyondLastLine:!1},z8=160,B8={image:`image`,doenet:`interactive`},V8=({asset:e,projectAssets:r,onClose:i,onSave:a,onReplace:o,onDuplicate:s})=>{let c=e.ref??``,[l,u]=(0,n.useState)(e.name),[d,f]=(0,n.useState)(c),[p,m]=(0,n.useState)(e.source??``),[h,g]=(0,n.useState)(!1),[_,v]=(0,n.useState)(!1),[y,b]=(0,n.useState)(null),[x,S]=(0,n.useState)(!1),[C,w]=(0,n.useState)(z8),T=(0,n.useRef)(null);(0,n.useEffect)(()=>{T.current?.scrollTo({top:0})},[]);let E=e=>{let t=()=>w(Math.max(z8,e.getContentHeight()));e.onDidContentSizeChange(t),t()},D=`<plus:${e.kind} ref="${d.trim()||c}"/>`,O=()=>{navigator.clipboard.writeText(D).catch(()=>{}),S(!0),setTimeout(()=>S(!1),2e3)},k=async()=>{let t=d.trim();if(!t){b(`Reference can't be empty — it identifies the asset and is used by every embed of it.`);return}if(t!==c&&r.some(n=>n.kind===e.kind&&n.ref===t)){b(`Reference "${t}" is already used by another asset. Choose a unique reference.`);return}b(null),g(!0);try{await a({...e,name:l.trim()||t,ref:t,source:p},c),i()}catch(e){b(e instanceof Error?e.message:`Failed to save asset.`),g(!1)}},A=async()=>{if(s){b(null),v(!0);try{await s(e)}catch(e){b(e instanceof Error?e.message:`Failed to duplicate asset.`),v(!1)}}},j=h||_,ee=e.kind===`image`&&!!e.url,M=e.kind===`image`&&!!o;return(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-overlay`,onClick:e=>e.target===e.currentTarget&&i(),children:(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`Edit asset ${e.name}`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsx)(`h2`,{className:`pretext-plus-editor__dialog-title`,children:`Edit asset`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,t.jsx)(`div`,{ref:T,className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single pretext-plus-editor__am-edit-content`,children:(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-section`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-edit-grid`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-edit-col`,children:[ee&&(0,t.jsx)(`img`,{src:e.url,alt:l,className:`pretext-plus-editor__am-url-preview`,onError:e=>{e.currentTarget.style.display=`none`}}),M&&(0,t.jsx)(`div`,{className:`pretext-plus-editor__am-replace-row`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn`,onClick:()=>o?.(e),disabled:j,title:`Choose or upload a different asset to use here`,children:`Replace image…`})})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-edit-col`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-edit-name`,children:`Name`}),(0,t.jsx)(`input`,{id:`am-edit-name`,type:`text`,className:`pretext-plus-editor__am-input`,value:l,onChange:e=>u(e.target.value),disabled:j}),(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-edit-ref`,children:`Reference`}),(0,t.jsx)(`input`,{id:`am-edit-ref`,type:`text`,className:`pretext-plus-editor__am-input`,value:d,onChange:e=>f(e.target.value),disabled:j}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`Used in the embed code. Changing it updates every reference to this asset already in your document.`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-embed-row`,children:[(0,t.jsx)(`code`,{className:`pretext-plus-editor__am-embed-code`,children:D}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn${x?` pretext-plus-editor__am-action-btn--done`:``}`,onClick:O,title:`Copy embed code to clipboard`,children:x?`Copied!`:`Copy embed code`})]})]})]}),(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,children:`Asset content`}),(0,t.jsxs)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:[`Inserted verbatim inside the generated `,(0,t.jsx)(`code`,{children:`<${B8[e.kind]}>`}),` element — e.g. `,(0,t.jsx)(`code`,{children:`<shortdescription>...</shortdescription>`}),`.`]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-editor pretext-plus-editor__am-edit-editor`,style:{height:C},children:(0,t.jsx)(Yn,{options:{...R8,readOnly:j},height:`100%`,language:`xml`,value:p,onMount:E,onChange:e=>m(e??``)})}),y&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:y})]})}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:[s&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary pretext-plus-editor__am-duplicate-btn`,onClick:A,disabled:j,title:`Create a copy of this asset under a new reference`,children:_?`Duplicating…`:`Duplicate`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:i,disabled:j,children:`Cancel`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:k,disabled:j,children:h?`Saving…`:`Save`})]})]})})},H8=e=>{let n=T3(e=>e.showFullPreview),r=T3(e=>e.setShowFullPreview),i=T3(e=>e.title),a=T3(e=>e.updateTitle),o;return o=e.showPreviewModeToggle===!1?null:(0,t.jsxs)(`label`,{className:`pretext-plus-editor__preview-toggle`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:!n,onChange:()=>r(!n),className:`pretext-plus-editor__preview-toggle-input`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__preview-toggle-container`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-label`,children:`Simple`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-slider ${n?`pretext-plus-editor__preview-toggle-slider--active`:``}`,children:(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-dot ${n?`pretext-plus-editor__preview-toggle-dot--active`:``}`})}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-label`,children:`Full`})]}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-caption`,children:`Preview Mode`}),(0,t.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>r(!n),className:`pretext-plus-editor__preview-toggle-input`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-bar`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__menu-left`,children:(0,t.jsxs)(`label`,{className:`pretext-plus-editor__title-label`,children:[`Title`,` `,(0,t.jsx)(`input`,{className:`pretext-plus-editor__title-input`,type:`text`,value:i,onChange:e=>a(e.target.value)})]})}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-right`,children:[e.onSaveButton&&(0,t.jsx)(`button`,{className:`pretext-plus-editor__button pretext-plus-editor__button--save`,onClick:e.onSaveButton,children:e.saveButtonLabel||`Save`}),e.onCancelButton&&(0,t.jsx)(`button`,{className:`pretext-plus-editor__button pretext-plus-editor__button--cancel`,onClick:e.onCancelButton,children:e.cancelButtonLabel||`Cancel`}),(0,t.jsx)(E3,{label:`Give feedback`,context:`main-editor`}),o]})]})},U8={pretext:`PreTeXt`,latex:`LaTeX`,markdown:`Markdown`},W8={book:`Book`,article:`Article`,slideshow:`Slideshow`,part:`Part`,chapter:`Chapter`,section:`Section`,worksheet:`Worksheet`,handout:`Handout`,exercises:`Exercises`,references:`References`,glossary:`Glossary`,solutions:`Solutions`,"reading-questions":`Reading Questions`,introduction:`Introduction`,conclusion:`Conclusion`,subsection:`Subsection`,subsubsection:`Subsubsection`,paragraphs:`Paragraphs`},G8=[`part`,`chapter`,`section`,`subsection`,`subsubsection`,`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`,`paragraphs`],K8=[`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`,`paragraphs`],q8={book:[`part`,`chapter`],article:[`section`,...K8],slideshow:[`section`],part:[`chapter`],chapter:[`section`,...K8],section:[`subsection`,...K8],subsection:[`subsubsection`,...K8],subsubsection:[...K8],worksheet:[`paragraphs`],handout:[`paragraphs`]};function J8(e){return e?q8[e]??G8:G8}var Y8=({draft:e,isNew:r=!1,isRoot:i=!1,parentType:a=null,onDraftChange:o,onCommit:s,onCancel:c})=>{let l=J8(a);return(0,n.useEffect)(()=>{i||l.length>0&&!l.includes(e.type)&&o({...e,type:l[0]})},[e,i,o,l]),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-edit-form`,children:[(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Title`}),(0,t.jsx)(`input`,{type:`text`,value:e.title,onChange:t=>o({...e,title:t.target.value}),onKeyDown:e=>{e.key===`Enter`&&s(),e.key===`Escape`&&c()},autoFocus:!0})]}),r?(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Format`}),(0,t.jsx)(`select`,{value:e.sourceFormat,onChange:t=>o({...e,sourceFormat:t.target.value}),children:Object.keys(U8).map(e=>(0,t.jsx)(`option`,{value:e,children:U8[e]},e))})]}):void 0,!i&&(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Type`}),(0,t.jsx)(`select`,{value:e.type,onChange:t=>o({...e,type:t.target.value}),children:l.map(e=>(0,t.jsx)(`option`,{value:e,children:W8[e]},e))})]}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Id`}),(0,t.jsx)(`input`,{type:`text`,value:e.xmlId,placeholder:`unique identifier`,onChange:t=>o({...e,xmlId:t.target.value})})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-edit-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-edit-save`,onClick:s,children:`Save`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-edit-cancel`,onClick:c,children:`Cancel`})]})]})},X8=({items:e})=>{let[i,a]=(0,n.useState)(!1),[o,s]=(0,n.useState)(null),c=(0,n.useRef)(null),l=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!i)return;let e=e=>{let t=e.target;c.current&&!c.current.contains(t)&&l.current&&!l.current.contains(t)&&a(!1)},t=e=>{e.key===`Escape`&&a(!1)},n=()=>a(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),window.addEventListener(`scroll`,n,!0),window.addEventListener(`resize`,n),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t),window.removeEventListener(`scroll`,n,!0),window.removeEventListener(`resize`,n)}},[i]),(0,n.useLayoutEffect)(()=>{if(!i)return;let e=c.current,t=l.current;if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),a=window.innerHeight-n.bottom,o=r.height+4>a&&n.top>a;s({right:Math.max(4,window.innerWidth-n.right),...o?{bottom:window.innerHeight-n.top+3}:{top:n.bottom+3}})},[i]);let u=e=>{a(!1),e()};return(0,t.jsxs)(`div`,{ref:c,className:`pretext-plus-editor__toc-div-menu`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-div-menu-trigger`,onClick:e=>{e.stopPropagation(),a(e=>(e||s(null),!e))},"aria-haspopup":`true`,"aria-expanded":i,title:`More options`,children:`⋮`}),i&&(0,r.createPortal)((0,t.jsx)(`div`,{ref:l,className:`pretext-plus-editor__toc-div-menu-popup pretext-plus-editor__toc-div-menu-popup--portal`,style:{visibility:o?`visible`:`hidden`,right:o?.right,top:o?.top,bottom:o?.bottom},children:e.map(e=>(0,t.jsx)(`button`,{type:`button`,className:[`pretext-plus-editor__toc-div-menu-item`,e.danger?`pretext-plus-editor__toc-div-menu-item--danger`:``].filter(Boolean).join(` `),onClick:()=>u(e.onClick),children:e.label},e.label))}),document.body)]})},Z8=({division:e,depth:n,isActive:r,hasChildren:i,isExpanded:a,onToggleExpand:o,editDraft:s,onSelect:c,onDraftChange:l,onEditCommit:u,onEditCancel:d,menuItems:f,isNew:p=!1,isRoot:m=!1,parentType:h=null})=>{let g=s!==null,_=e.type===`introduction`||e.type===`conclusion`?W8[e.type]:null;return(0,t.jsxs)(`li`,{className:[`pretext-plus-editor__toc-item`,`pretext-plus-editor__toc-item--${e.type}`,r?`pretext-plus-editor__toc-item--active`:``,g?`pretext-plus-editor__toc-item--editing`:``].filter(Boolean).join(` `),children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-item-row`,style:n>0?{paddingLeft:`${n*14}px`}:void 0,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-expand-btn`,onClick:o,"aria-label":a?`Collapse`:`Expand`,tabIndex:i?0:-1,style:{visibility:i?`visible`:`hidden`},children:a?`▾`:`▸`}),(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__toc-select`,onClick:c,"aria-current":r?`true`:void 0,title:W8[e.type]??e.type,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-title`,children:e.title||_||(0,t.jsx)(`em`,{children:`Untitled`})}),e.xmlId&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-xmlid`,children:e.xmlId})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-actions`,children:(0,t.jsx)(X8,{items:f})})]}),g&&s&&(0,t.jsx)(Y8,{draft:s,isNew:p,isRoot:m,parentType:h,onDraftChange:l,onCommit:u,onCancel:d})]})},Q8=({onOpenAssetPicker:e})=>{let r=T3(e=>e.divisions),i=T3(e=>e.rootDivisionId),a=T3(e=>e.activeDivisionId),o=T3(e=>e.projectAssets)??[],s=T3(e=>e.selectSection),c=T3(e=>e.addSection),l=T3(e=>e.removeSection),u=T3(e=>e.divisionContentChange),d=T3(e=>e.insertAtCursor),f=T3(e=>e.openAssetEditor),p=T3(e=>e.openAssetResolver),m=T3(e=>e.removeAsset),h=T3(e=>e.removeAssetRefFromDocument),g=T3(e=>e.duplicateAsset),_=T3(e=>e.hasAssetDuplicate),v=T3(e=>e.startSectionEdit),y=T3(e=>e.setEditDraft),b=T3(e=>e.commitSectionEdit),x=T3(e=>e.cancelSectionEdit),S=T3(e=>e.editingId),C=T3(e=>e.editDraft),w=T3(e=>e.editingIsNew),T=r?r.find(e=>e.xmlId===i)??r.find(e=>e.type===`book`||e.type===`article`||e.type===`slideshow`)??r[0]??null:null,E=T&&r?v8(r,T.xmlId):[],D=T&&r?y8(r,T.xmlId):[],O=M8(r,o),k=F8.map(e=>({kind:e,rows:O.filter(t=>t.kind===e)})).filter(e=>e.rows.length>0),[A,j]=(0,n.useState)(!1),[ee,M]=(0,n.useState)(null),te=async e=>{if(!(!e.asset||ee)){M(e.ref);try{await g(e.asset)}finally{M(null)}}},[ne,N]=(0,n.useState)(new Set),re=e=>!ne.has(e),ie=e=>{N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[ae,oe]=(0,n.useState)(a);if(a!==ae&&(oe(a),a&&T)){let e=new Map(E.map(e=>[e.division.xmlId,e])),t=new Set;t.add(T.xmlId);let n=a;for(;n;){let r=e.get(n);if(!r?.parentXmlId)break;t.add(r.parentXmlId),n=r.parentXmlId}N(e=>{if([...t].every(t=>!e.has(t)))return e;let n=new Set(e);return t.forEach(e=>n.delete(e)),n})}let se=new Set(E.map(e=>e.parentXmlId).filter(Boolean)),P=[];if(T){let e=new Set;re(T.xmlId)&&e.add(T.xmlId);for(let t of E)t.parentXmlId&&e.has(t.parentXmlId)&&(P.push(t),re(t.division.xmlId)&&e.add(t.division.xmlId))}let ce=(e,t)=>{if(!r)return;let n=r.find(e=>e.xmlId===t);n&&u(n.xmlId,h8(u8(n.content,e)))},le=(e,t)=>{if(window.confirm(`Delete "${e.title||`Untitled`}"? This permanently removes the division.`)){if(t&&r){let n=r.find(e=>e.xmlId===t);n&&u(n.xmlId,h8(u8(n.content,e.xmlId)))}l(e.xmlId)}},ue=e=>{d(`<plus:${e.type} ref="${e.xmlId}"/>`)},de=e=>{T&&u(T.xmlId,h8(l8(T.content,e.xmlId,e.type,null)))},F=e=>e&&r?.find(t=>t.xmlId===e)?.type||null,fe=e=>e.status===`unlinked`?p(e.kind,e.ref):f(e.kind,e.ref),pe=(e,t)=>{navigator.clipboard.writeText(`<plus:${e} ref="${t}"/>`).catch(()=>{})},me=e=>{let t=[{label:e.status===`unlinked`?`Link / create asset`:`Edit asset`,onClick:()=>fe(e)},{label:`Copy embed code`,onClick:()=>pe(e.kind,e.ref)}];return _&&e.asset&&t.push({label:`Duplicate asset`,onClick:()=>te(e)}),e.status===`unlinked`?t.push({label:`Remove from document`,onClick:()=>h(e.kind,e.ref),danger:!0}):e.asset&&t.push({label:`Remove from project`,onClick:()=>{e.inDocument&&!window.confirm(`Remove "${e.asset.name}" from the project? This also deletes its ${e.inDocument?`reference(s)`:`reference`} from the document.`)||(m(e.asset),h(e.kind,e.ref))},danger:!0}),t};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`ul`,{className:`pretext-plus-editor__toc-list`,role:`list`,children:[T&&(0,t.jsx)(Z8,{division:T,depth:0,isActive:a===T.xmlId,hasChildren:se.has(T.xmlId),isExpanded:re(T.xmlId),onToggleExpand:()=>ie(T.xmlId),editDraft:S===T.xmlId?C:null,onSelect:()=>s(T.xmlId),onDraftChange:y,onEditCommit:b,onEditCancel:x,menuItems:[{label:`Edit properties`,onClick:()=>v(T)},...T.sourceFormat===`pretext`?[{label:`Add new division`,onClick:()=>c(T.xmlId)}]:[]],isNew:S===T.xmlId&&w,isRoot:!0}),P.length===0&&T&&re(T.xmlId)&&(0,t.jsx)(`li`,{className:`pretext-plus-editor__toc-no-sections`,children:(0,t.jsx)(`span`,{children:`No placed divisions`})}),P.map(e=>(0,t.jsx)(Z8,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:se.has(e.division.xmlId),isExpanded:re(e.division.xmlId),onToggleExpand:()=>ie(e.division.xmlId),editDraft:S===e.division.xmlId?C:null,onSelect:()=>s(e.division.xmlId),onDraftChange:y,onEditCommit:b,onEditCancel:x,menuItems:[{label:`Edit properties`,onClick:()=>v(e.division)},...e.division.sourceFormat===`pretext`?[{label:`Add new division`,onClick:()=>c(e.division.xmlId)}]:[],{label:`Remove from document`,onClick:()=>ce(e.division.xmlId,e.parentXmlId)},{label:`Delete from project`,onClick:()=>le(e.division,e.parentXmlId),danger:!0}],isNew:S===e.division.xmlId&&w,parentType:F(e.parentXmlId)},e.division.xmlId))]}),D.length>0&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-orphans`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-orphans-heading`,children:`Unplaced divisions`}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__toc-list`,children:D.map(e=>{let i=r?v8(r,e.xmlId):[],o=new Set(i.map(e=>e.parentXmlId).filter(Boolean));return(0,t.jsxs)(n.Fragment,{children:[(0,t.jsx)(Z8,{division:e,depth:0,isActive:a===e.xmlId,hasChildren:o.has(e.xmlId),isExpanded:re(e.xmlId),onToggleExpand:()=>ie(e.xmlId),editDraft:S===e.xmlId?C:null,onSelect:()=>s(e.xmlId),onDraftChange:y,onEditCommit:b,onEditCancel:x,menuItems:[{label:`Edit properties`,onClick:()=>v(e)},{label:`Place in document`,onClick:()=>de(e)},{label:`Insert at cursor`,onClick:()=>ue(e)},{label:`Delete from project`,onClick:()=>le(e,null),danger:!0}],parentType:null}),re(e.xmlId)&&i.map(e=>(0,t.jsx)(Z8,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:o.has(e.division.xmlId),isExpanded:re(e.division.xmlId),onToggleExpand:()=>ie(e.division.xmlId),editDraft:S===e.division.xmlId?C:null,onSelect:()=>s(e.division.xmlId),onDraftChange:y,onEditCommit:b,onEditCancel:x,menuItems:[{label:`Edit properties`,onClick:()=>v(e.division)},{label:`Insert at cursor`,onClick:()=>ue(e.division)},{label:`Delete from project`,onClick:()=>le(e.division,e.parentXmlId),danger:!0}],parentType:F(e.parentXmlId)},e.division.xmlId))]},e.xmlId)})})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-assets`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-header`,children:(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-toggle`,onClick:()=>j(e=>!e),"aria-expanded":A,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-assets-chevron`,children:A?`▾`:`▸`}),(0,t.jsx)(`span`,{children:`Assets`}),O.length>0&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-assets-count`,children:O.length})]})}),A&&(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-body`,children:O.length===0?(0,t.jsxs)(`p`,{className:`pretext-plus-editor__toc-assets-empty`,children:[`No assets in this project yet.`,` `,e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-add-link`,onClick:e,children:`Add one`})]}):(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-groups`,children:k.map(({kind:e,rows:n})=>(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-group-header`,children:P8[e]}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__toc-assets-list`,children:n.map(e=>(0,t.jsxs)(`li`,{className:[`pretext-plus-editor__toc-asset-item`,e.status===`unlinked`?`pretext-plus-editor__toc-asset-item--unlinked`:``,e.status===`unused`?`pretext-plus-editor__toc-asset-item--unused`:``,ee===e.ref?`pretext-plus-editor__toc-asset-item--busy`:``].filter(Boolean).join(` `),children:[e.asset?.url?(0,t.jsx)(`img`,{src:e.asset.url,className:`pretext-plus-editor__toc-asset-img`,onClick:()=>fe(e)}):(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-img pretext-plus-editor__toc-asset-img--placeholder`,onClick:()=>fe(e),title:e.status===`unlinked`?`No asset — click to link`:void 0,"aria-hidden":`true`,children:e.status===`unlinked`?`⚠`:`🖼`}),(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__toc-asset-name`,onClick:()=>fe(e),title:e.status===`unlinked`?`No asset for this reference — click to link or create one`:`Edit asset`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-label`,children:e.asset?.name??e.ref}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-filename`,children:e.status===`unlinked`?`${e.ref} — needs asset`:e.status===`unused`?`${e.ref} — not placed`:e.ref})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-actions`,children:ee===e.ref?(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-spinner`,role:`status`,"aria-label":`Duplicating asset`,title:`Duplicating…`}):(0,t.jsx)(X8,{items:me(e)})})]},e.ref))})]},e))})})]}),e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-btn`,onClick:e,children:`Manage Assets`})]})},$8=({isCollapsed:e,onToggleCollapse:n,onOpenAssetPicker:r})=>e?(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc pretext-plus-editor__toc--collapsed`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-toggle`,onClick:n,"aria-label":`Expand table of contents`,title:`Expand table of contents`,children:`☰`})}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-header`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-heading`,children:`Contents`}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-header-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-toggle`,onClick:n,"aria-label":`Collapse table of contents`,title:`Collapse table of contents`,children:`✕`})})]}),(0,t.jsx)(Q8,{onOpenAssetPicker:r})]}),e5=class extends n.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.props.onError?.(e,t),console.error(`ErrorBoundary caught an error:`,e,t)}componentDidUpdate(e){if(this.state.error===null)return;let{resetKeys:t}=this.props,n=e.resetKeys;t&&n&&(t.length!==n.length||t.some((e,t)=>!Object.is(e,n[t])))&&this.reset()}reset=()=>{this.setState({error:null})};render(){let{error:e}=this.state;return e===null?this.props.children:this.props.fallback?this.props.fallback(e,this.reset):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__error-boundary`,role:`alert`,children:[(0,t.jsx)(`strong`,{children:`Something went wrong rendering this view.`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__error-boundary-detail`,children:e.message}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__error-boundary-retry`,onClick:this.reset,children:`Try again`})]})}},t5=(e,t)=>e.kind===t.kind&&e.ref===t.ref;function n5(e){let t=()=>{},n={cbs:{selectDivision:t,addDivision:t,removeDivision:t,updateDivision:t,divisionContentChange:t,handleDivisionContentChange:t,assetInsert:t,updateTitle:t}};return{store:x3()((t,r)=>({source:e.source,sourceFormat:e.sourceFormat,projectAssets:e.projectAssets,libraryAssets:void 0,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,projectType:e.projectType,projectUrl:void 0,divisions:e.divisions,rootDivisionId:void 0,activeDivisionId:e.activeDivisionId,canConvertToPretext:!0,activeEditorSource:e.source,hasFeedback:!1,hasAssetDuplicate:!1,isTocCollapsed:!1,showFullPreview:!0,isNarrowScreen:typeof window<`u`?window.innerWidth<800:!1,activeTab:`editor`,isLatexDialogOpen:!1,isConvertDialogOpen:!1,isDocinfoEditorOpen:!1,isAssetPickerOpen:!1,isFullSourceOpen:!1,editingId:null,editDraft:null,editingIsNew:!1,editingAssetRef:null,assetResolveTarget:null,syncState:e=>t(e),applyExternalUpdate:e=>t(e),setDivisionContent:(e,n)=>t(t=>{if(!t.divisions)return{};let r=!1,i=t.divisions.map(t=>t.xmlId===e&&t.content!==n?(r=!0,{...t,content:n}):t);return r?{divisions:i}:{}}),patchDivision:(e,n)=>t(t=>t.divisions?{divisions:t.divisions.map(t=>t.xmlId===e?{...t,...n.id!==void 0&&{id:n.id},...n.title!==void 0&&{title:n.title},...n.type!==void 0&&{type:n.type},...n.xmlId!=null&&{xmlId:n.xmlId},...n.sourceFormat!==void 0&&{sourceFormat:n.sourceFormat}}:t)}:{}),addDivisionToPool:e=>t(t=>{let n=t.divisions??[];return n.some(t=>t.xmlId===e.xmlId)?{}:{divisions:[...n,e]}}),removeDivisionFromPool:e=>t(t=>({divisions:(t.divisions??[]).filter(t=>t.xmlId!==e)})),setActiveDivisionId:e=>t({activeDivisionId:e}),setTitle:e=>t({title:e}),setDocinfo:({docinfo:e,commonDocinfo:n,useCommonDocinfo:r})=>t({docinfo:e,commonDocinfo:n,useCommonDocinfo:r}),setShowFullPreview:e=>t({showFullPreview:e}),setActiveTab:e=>t({activeTab:e}),setIsNarrowScreen:e=>t({isNarrowScreen:e}),setIsTocCollapsed:e=>t(t=>({isTocCollapsed:typeof e==`function`?e(t.isTocCollapsed):e})),openModal:e=>t({[e]:!0}),closeModal:e=>t({[e]:!1}),selectSection:e=>n.cbs.selectDivision(e),addSection:e=>n.cbs.addDivision(e),removeSection:e=>n.cbs.removeDivision(e),updateSection:(e,t)=>n.cbs.updateDivision(e,t),divisionContentChange:(e,t)=>n.cbs.divisionContentChange?.(e,t),startSectionEdit:(e,n)=>{let{xmlId:r,label:i}=e.sourceFormat===`markdown`?X6(e.content)??{xmlId:e.xmlId,label:``}:e.sourceFormat===`latex`?{xmlId:P6(e.content)||e.xmlId,label:``}:V6(e.content);t({editingId:e.xmlId,editDraft:{title:e.title,type:e.type,xmlId:r,label:i,sourceFormat:e.sourceFormat},editingIsNew:n?.isNew??!1})},setEditDraft:e=>t({editDraft:e}),commitSectionEdit:()=>{let{editingId:e,editDraft:i,divisions:a}=r();if(e&&i){let t=(a??[]).find(t=>t.xmlId===e),r=null;if(t){let t=H6(i.xmlId);if(!t){window.alert(`xml:id can't be empty — it identifies the division and is used by references to it.`);return}if((a??[]).some(n=>n.xmlId!==e&&n.xmlId===t)){window.alert(`xml:id "${t}" is already used by another division. Choose a unique id.`);return}r=t}n.cbs.updateDivision(e,{title:i.title.trim()||void 0,type:i.type,xmlId:r,label:i.label.trim()||null,sourceFormat:i.sourceFormat})}t({editingId:null,editDraft:null,editingIsNew:!1})},cancelSectionEdit:()=>t({editingId:null,editDraft:null,editingIsNew:!1}),insertAsset:e=>n.cbs.assetInsert(e),insertAtCursor:e=>n.cbs.insertContentAtCursor?.(e),openAssetEditor:(e,n)=>t({editingAssetRef:{kind:e,ref:n}}),closeAssetEditor:()=>t({editingAssetRef:null}),openAssetResolver:(e,n)=>t({assetResolveTarget:{kind:e,ref:n}}),closeAssetResolver:()=>t({assetResolveTarget:null}),removeAsset:e=>n.cbs.assetRemove?.(e),removeAssetRefFromDocument:(e,t)=>n.cbs.assetRefRemove?.(e,t),duplicateAsset:async e=>{await n.cbs.assetDuplicate?.(e)},setProjectAssets:e=>t({projectAssets:e}),addAssetToPool:e=>t(t=>{let n=t.projectAssets??[];return n.some(t=>t5(t,e))?{}:{projectAssets:[...n,e]}}),updateAssetInPool:e=>t(t=>{let n=t.projectAssets??[];return n.some(t=>t5(t,e))?{projectAssets:n.map(t=>t5(t,e)?e:t)}:{projectAssets:[...n,e]}}),renameAssetInPool:(e,n,r)=>t(t=>({projectAssets:[...(t.projectAssets??[]).filter(t=>!(t.kind===e&&t.ref===n)&&!t5(t,r)),r]})),removeAssetFromPool:e=>t(t=>({projectAssets:(t.projectAssets??[]).filter(t=>!t5(t,e))})),updateTitle:e=>n.cbs.updateTitle(e),feedbackSubmit:e=>n.cbs.feedbackSubmit?.(e)})),bindCallbacks:e=>{n.cbs=e}}}function r5({store:e,children:n}){return(0,t.jsx)(w3.Provider,{value:e,children:n})}var i5=(e,t)=>e.find(e=>t?e.xmlId===t:e.type===`book`||e.type===`article`||e.type===`slideshow`)??e[0]??null,a5=e=>{let[r]=(0,n.useState)(()=>{let t=i5(e.divisions,e.rootDivisionId),n=j8(e.divisions,t?.xmlId,e.projectType,e.title),r=n.find(e=>e.xmlId===t?.xmlId)??t,i=e.activeDivisionId??r?.xmlId??null,a=n.find(e=>e.xmlId===i)??r;return n5({source:a?.content??``,sourceFormat:a?.sourceFormat??`pretext`,title:e.title||r?.title||`Document Title`,docinfo:e.docinfo??``,commonDocinfo:e.commonDocinfo??``,useCommonDocinfo:e.useCommonDocinfo??!1,projectType:e.projectType,divisions:n,activeDivisionId:i,projectAssets:e.projectAssets})});return(0,t.jsx)(r5,{store:r.store,children:(0,t.jsx)(o5,{...e,bindCallbacks:r.bindCallbacks})})},o5=e=>{let{bindCallbacks:r}=e,i=T3(e=>e.showFullPreview),a=T3(e=>e.isNarrowScreen),o=T3(e=>e.setIsNarrowScreen),s=T3(e=>e.activeTab),c=T3(e=>e.setActiveTab),l=T3(e=>e.isTocCollapsed),u=T3(e=>e.setIsTocCollapsed),d=T3(e=>e.isLatexDialogOpen),f=T3(e=>e.isConvertDialogOpen),p=T3(e=>e.isDocinfoEditorOpen),m=T3(e=>e.isAssetPickerOpen),h=T3(e=>e.isFullSourceOpen),g=T3(e=>e.editingAssetRef),_=T3(e=>e.openAssetEditor),v=T3(e=>e.closeAssetEditor),y=T3(e=>e.assetResolveTarget),b=T3(e=>e.closeAssetResolver),[x,S]=(0,n.useState)(null),C=T3(e=>e.openModal),w=T3(e=>e.closeModal),T=T3(e=>e.syncState),E=T3(e=>e.projectAssets),D=T3(e=>e.addAssetToPool),O=T3(e=>e.updateAssetInPool),k=T3(e=>e.renameAssetInPool),A=T3(e=>e.removeAssetFromPool),j=g?E?.find(e=>e.kind===g.kind&&e.ref===g.ref):void 0,ee=T3(e=>e.divisions),M=(0,n.useMemo)(()=>ee??[],[ee]),te=T3(e=>e.activeDivisionId),ne=T3(e=>e.title),N=T3(e=>e.docinfo),re=T3(e=>e.commonDocinfo),ie=T3(e=>e.useCommonDocinfo),ae=T3(e=>e.applyExternalUpdate),oe=T3(e=>e.setDivisionContent),se=T3(e=>e.patchDivision),P=T3(e=>e.addDivisionToPool),ce=T3(e=>e.removeDivisionFromPool),le=T3(e=>e.setActiveDivisionId),ue=T3(e=>e.startSectionEdit),de=T3(e=>e.setTitle),F=T3(e=>e.setDocinfo),fe=(0,n.useRef)(null),pe=(0,n.useRef)(null),me=i5(M,e.rootDivisionId),he=M.find(e=>e.xmlId===te)??M[0]??null,ge=he?.sourceFormat??`pretext`,I=he?.content??``,_e=(t,n,r,i)=>{oe(t,n),e.onContentChange({xmlId:t,sourceContent:n,sourceFormat:r,pretextSource:r===`pretext`?n:void 0,...i})},ve=(t,n)=>{se(t,n),e.onDivisionUpdate?.(t,n)},ye=(e,t)=>{let n=M.find(t=>t.xmlId===e);if(!n){ve(e,t);return}let r;if(t.sourceFormat!==void 0&&t.sourceFormat!==n.sourceFormat){let e=t.type??n.type,i=t.title??n.title,a=t.xmlId||n.xmlId;r={...n,sourceFormat:t.sourceFormat,type:e,title:i,xmlId:a,content:c8(e,t.sourceFormat,i,a)}}else r=n.sourceFormat===`markdown`?Z6(n,t):n.sourceFormat===`latex`?F6(n,t):W6(n,t);let i=r.xmlId;if(r.content!==n.content&&_e(n.xmlId,r.sourceFormat===`pretext`?h8(r.content):r.content,r.sourceFormat),ve(e,{...t,xmlId:i}),i!==n.xmlId||r.type!==n.type){let e=p8(M,n.xmlId);if(e){let t=f8(e.content,n.xmlId,i,r.type);t!==e.content&&_e(e.xmlId,t,e.sourceFormat)}}i!==n.xmlId&&Se(i)},be=t=>{P(t),(e.onDivisionAdd?.(t))?.then(e=>se(t.xmlId,{id:e})).catch(()=>{})},xe=t=>{ce(t),e.onDivisionRemove?.(t)},Se=t=>{le(t),e.onDivisionSelect?.(t)},Ce=(0,n.useMemo)(()=>{if(!he||ge===`pretext`)return;if(ge===`latex`)return I6(he)??void 0;let e=_3(I,ge);return e.pretextError?void 0:e.pretextSource},[he,ge,I]),L=e=>{if(!he)return;let t=ge===`pretext`?h8(e||``):e||``;if(ge===`pretext`){let e=U6(t);e&&e.xmlId!==he.xmlId&&(t=h8(W6({...he,content:t,title:e.title,type:e.type},{xmlId:he.xmlId,label:e.label||null}).content))}else if(ge===`markdown`){let e=X6(t);e&&e.xmlId!==he.xmlId&&(t=Z6({...he,content:t},{xmlId:he.xmlId}).content)}if(t===he.content)return;if(_e(he.xmlId,t,ge),ge===`pretext`){let e=U6(t);if(e&&(ve(he.xmlId,{title:e.title,type:e.type,label:e.label||null}),e.type!==he.type)){let t=p8(M,he.xmlId);if(t){let n=f8(t.content,he.xmlId,he.xmlId,e.type);n!==t.content&&_e(t.xmlId,n,t.sourceFormat)}}}else if(ge===`markdown`){let e=X6(t);if(e&&(ve(he.xmlId,{title:e.title,type:e.type,label:e.label||null}),e.type!==he.type)){let t=p8(M,he.xmlId);if(t){let n=f8(t.content,he.xmlId,he.xmlId,e.type);n!==t.content&&_e(t.xmlId,n,t.sourceFormat)}}}else if(ge===`latex`){let e=N6(t);e!==null&&ve(he.xmlId,{title:e})}let n=new Set(M.map(e=>e.xmlId));for(let{xmlId:e,type:r}of r8(t))n.has(e)||(be(s8(e,r,ge)),n.add(e))},we=e=>{Se(e)},Te=()=>{he&&(u(!1),ue(he))},Ee=e=>{let t=S6();if(be(t),e){let n=M.find(t=>t.xmlId===e);n&&_e(n.xmlId,h8(l8(n.content,t.xmlId,t.type,null)),n.sourceFormat)}le(t.xmlId),ue(t,{isNew:!0})},R=e=>{D(e)},De=t=>{A(t),e.onAssetRemove?.(t)},Oe=!!(e.onAssetUpload&&e.onAssetFetchUrl&&e.onAssetUpdate),ke=!!(e.onAssetRemove&&(e.onAssetUpload||e.onAssetAddFromLibrary)),z=async t=>{if(!e.onAssetUpload||!e.onAssetFetchUrl||!t.ref||!t.url)return;let n=new Set(M8(M,E).map(e=>e.ref)),r=N8(t.ref,n),i=await e.onAssetFetchUrl(t.url),a={...await e.onAssetUpload(i),ref:r,name:`${t.name} (copy)`,source:t.source};await e.onAssetUpdate?.(a),D(a),_(a.kind,r)},Ae=async(t,n,r)=>{if(r)n.ref&&t.ref&&je(t.kind,t.ref,n.ref),D(n);else{let r={...n,ref:t.ref,name:t.name,source:t.source};await e.onAssetUpdate?.(r),O(r)}e.onAssetRemove?.(t),A(t)},je=(e,t,n)=>{if(t!==n)for(let r of M){let i=a8(r.content,e,t,n);i!==r.content&&_e(r.xmlId,i,r.sourceFormat)}},Me=(e,t)=>{for(let n of M){let r=o8(n.content,e,t);r!==n.content&&_e(n.xmlId,r,n.sourceFormat)}};(0,n.useEffect)(()=>{let e=()=>o(window.innerWidth<800);return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[o]);let Ne=ge!==`pretext`;(0,n.useLayoutEffect)(()=>{r({selectDivision:we,addDivision:e=>Ee(e),removeDivision:e=>xe(e),updateDivision:(e,t)=>ye(e,t),divisionContentChange:(e,t)=>{_e(e,t,M.find(t=>t.xmlId===e)?.sourceFormat??`pretext`)},handleDivisionContentChange:L,assetInsert:R,assetRemove:De,assetRefRemove:Me,assetDuplicate:Oe?z:void 0,insertContentAtCursor:e=>pe.current?.insertAtCursor(e),updateTitle:t=>{de(t),e.onTitleChange?.(t)},feedbackSubmit:e.onFeedbackSubmit})}),(0,n.useEffect)(()=>{T({source:I,sourceFormat:ge,libraryAssets:e.libraryAssets,projectType:e.projectType,projectUrl:e.projectUrl,rootDivisionId:me?.xmlId,canConvertToPretext:Ce!==void 0,activeEditorSource:I,hasFeedback:e.onFeedbackSubmit!==void 0,hasAssetDuplicate:Oe})});let Pe=(0,n.useRef)({divisions:e.divisions,projectAssets:e.projectAssets,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,activeDivisionId:e.activeDivisionId});(0,n.useEffect)(()=>{let t=Pe.current,n={},r=!1;if(e.projectAssets!==void 0&&e.projectAssets!==t.projectAssets&&(n.projectAssets=e.projectAssets,r=!0),e.divisions!==t.divisions){let t=i5(e.divisions,e.rootDivisionId),i=j8(e.divisions,t?.xmlId,e.projectType,e.title);n.divisions=i;let a=i.find(e=>e.xmlId===t?.xmlId)??t;(te==null||!e.divisions.some(e=>e.xmlId===te))&&(n.activeDivisionId=a?.xmlId??null),!e.title&&a?.title&&(n.title=a.title),r=!0}e.title!==void 0&&e.title!==t.title&&(n.title=e.title,r=!0),e.docinfo!==void 0&&e.docinfo!==t.docinfo&&(n.docinfo=e.docinfo,r=!0),e.commonDocinfo!==void 0&&e.commonDocinfo!==t.commonDocinfo&&(n.commonDocinfo=e.commonDocinfo,r=!0),e.useCommonDocinfo!==void 0&&e.useCommonDocinfo!==t.useCommonDocinfo&&(n.useCommonDocinfo=e.useCommonDocinfo,r=!0),e.activeDivisionId!==void 0&&e.activeDivisionId!==t.activeDivisionId&&(n.activeDivisionId=e.activeDivisionId,r=!0),r&&ae(n),Pe.current={divisions:e.divisions,projectAssets:e.projectAssets,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,activeDivisionId:e.activeDivisionId}});let Fe=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(Fe.current===e.divisions)return;Fe.current=e.divisions;let t=i5(e.divisions,e.rootDivisionId),n=j8(e.divisions,t?.xmlId,e.projectType,e.title);for(let t of n){if(t.sourceFormat!==`pretext`)continue;let n=e.divisions.find(e=>e.xmlId===t.xmlId);!n||t.content===n.content||e.onContentChange({xmlId:t.xmlId,sourceContent:t.content,sourceFormat:`pretext`,pretextSource:t.content})}});let Ie=ie?re:N,Le=(0,n.useMemo)(()=>{if(!h||!me)return``;try{return D8(M,me.xmlId,Ie,E??[])}catch(e){return`<!-- Unable to assemble document source: ${e instanceof Error?e.message:String(e)} -->`}},[h,me,M,Ie,E]),Re=he?ge===`pretext`?T8(M,he.xmlId,E):Ce:void 0,ze=he&&Re!==void 0?k8(he.type,Re,Ie,he.title):void 0,Be=()=>fe.current?.rebuild(),Ve=()=>{e.onSave?.(),fe.current?.rebuild()},He=t=>{let n=t.ctrlKey||t.metaKey;n&&t.key===`Enter`&&e.onPreviewRebuild?(t.preventDefault(),Be()):n&&t.key===`s`&&(t.preventDefault(),Ve())},Ue=()=>{if(!he||!Ce)return;let e=S6(),t={id:e.xmlId,xmlId:he.xmlId,title:he.title,type:he.type,sourceFormat:ge,content:he.content};be(ge===`markdown`?Z6(t,{xmlId:e.xmlId}):F6(t,{xmlId:e.xmlId})),_e(he.xmlId,h8(Ce),`pretext`),ve(he.xmlId,{sourceFormat:`pretext`})},B=(0,t.jsx)(Ws,{ref:pe,content:I,sourceFormat:ge,onChange:L,onRebuild:e.onPreviewRebuild?Be:void 0,onSave:Ve,onOpenLatexImport:()=>C(`isLatexDialogOpen`),onOpenDocinfoEditor:()=>C(`isDocinfoEditorOpen`),onOpenConvertToPretext:Ne&&Ce!==void 0?()=>C(`isConvertDialogOpen`):void 0,canConvertToPretext:Ce!==void 0,onOpenAssets:e.projectAssets!==void 0&&ge===`pretext`?()=>C(`isAssetPickerOpen`):void 0,onShowFullSource:()=>C(`isFullSourceOpen`),onRequestWrapperEdit:Te}),We;We=i&&e.onPreviewRebuild?(0,t.jsx)(lR,{ref:fe,content:ze||``,title:ne,onRebuild:e.onPreviewRebuild}):(0,t.jsx)(oR,{content:I,canEdit:ge===`pretext`,editDisabledReason:ge===`markdown`?`Visual editing is not available for Markdown documents.`:ge===`latex`?`Visual editing is not available for LaTeX documents.`:``,onChange:e=>L(e)});let Ge=(0,t.jsx)($8,{isCollapsed:l,onToggleCollapse:()=>u(e=>!e),onOpenAssetPicker:e.projectAssets===void 0?void 0:()=>C(`isAssetPickerOpen`)}),Ke=`pretext-plus-tab-editor`,V=`pretext-plus-tab-preview`,qe=`pretext-plus-tabpanel`,Je;return Je=a?(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tabs`,children:[Ge,(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tabs-main`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tab-list`,role:`tablist`,children:[(0,t.jsx)(`button`,{type:`button`,id:Ke,role:`tab`,"aria-controls":qe,"aria-selected":s===`editor`,tabIndex:s===`editor`?0:-1,className:`pretext-plus-editor__tab-button ${s===`editor`?`is-active`:``}`,onClick:()=>c(`editor`),children:`Editor`}),(0,t.jsx)(`button`,{type:`button`,id:V,role:`tab`,"aria-controls":qe,"aria-selected":s===`preview`,tabIndex:s===`preview`?0:-1,className:`pretext-plus-editor__tab-button ${s===`preview`?`is-active`:``}`,onClick:()=>c(`preview`),children:`Preview`})]}),(0,t.jsx)(`div`,{id:qe,className:`pretext-plus-editor__tab-panel`,role:`tabpanel`,"aria-labelledby":s===`editor`?Ke:V,children:(0,t.jsx)(`div`,{style:{height:`100%`},children:s===`editor`?B:We})})]})]}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__sectioned-layout`,children:[Ge,(0,t.jsxs)(gt,{orientation:`horizontal`,className:`pretext-plus-editor__splitter`,children:[(0,t.jsx)(yt,{className:`pretext-plus-editor__editor-panel`,children:B}),(0,t.jsx)(St,{className:`pretext-plus-editor__resize-handle`,children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__resize-dots`})}),(0,t.jsx)(yt,{className:`pretext-plus-editor__preview-panel`,children:We})]})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor`,onKeyDown:He,children:[(0,t.jsx)(H8,{onSaveButton:e.onSaveButton,saveButtonLabel:e.saveButtonLabel,onCancelButton:e.onCancelButton,cancelButtonLabel:e.cancelButtonLabel,showPreviewModeToggle:e.onPreviewRebuild!==void 0}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__editor-displays`,children:[(0,t.jsx)(e5,{resetKeys:[I,te],children:Je}),d?(0,t.jsx)(D3,{onClose:()=>w(`isLatexDialogOpen`)}):null,f&&he&&Ce?(0,t.jsx)(j3,{sourceContent:I,sourceFormat:ge,pretextSource:Ce,onConfirm:Ue,onClose:()=>w(`isConvertDialogOpen`)}):null,p?(0,t.jsx)(U3,{docinfo:N,showCommonDocinfoControls:!0,commonDocinfo:re,initialUseCommonDocinfo:ie,onClose:t=>{if(w(`isDocinfoEditorOpen`),t!==void 0){F({docinfo:t.docinfo,commonDocinfo:t.commonDocinfo,useCommonDocinfo:t.useCommonDocinfo}),e.onCommonDocinfoChange?.(t.commonDocinfo),e.onUseCommonDocinfoChange?.(t.useCommonDocinfo);let n=me??he;_e(n?.xmlId??``,n?.content??``,n?.sourceFormat??`pretext`,{docinfo:t.docinfo,commonDocinfo:t.commonDocinfo,useCommonDocinfo:t.useCommonDocinfo})}}}):null,(m||y||x)&&e.projectAssets!==void 0?(0,t.jsx)(L8,{open:m||!!y||!!x,resolveTarget:y,replaceTarget:x,onClose:()=>{w(`isAssetPickerOpen`),b(),S(null)},onLoadAssets:e.onLoadAssets,onLoadLibraryAssets:e.onLoadLibraryAssets,onAddFromLibrary:e.onAssetAddFromLibrary,onUpload:e.onAssetUpload,onFetchUrl:e.onAssetFetchUrl,onCreateDoenet:e.onCreateDoenet,onRemoveAsset:e.onAssetRemove?De:void 0,onDuplicateAsset:Oe?z:void 0,onAssetAdded:R,onResolveRef:je,onReplaceAsset:Ae}):null,h?(0,t.jsx)(G3,{source:Le,onClose:()=>w(`isFullSourceOpen`)}):null,j?(0,t.jsx)(V8,{asset:j,projectAssets:E??[],onClose:v,onReplace:ke?e=>{v(),S(e)}:void 0,onDuplicate:Oe?e=>z(e):void 0,onSave:async(t,n)=>{t.ref&&t.ref!==n?(je(t.kind,n,t.ref),k(t.kind,n,t)):O(t),await e.onAssetUpdate?.(t)}},`${j.kind}:${j.ref}`):null]})]})};e.CodeEditor=Ws,e.DocinfoEditor=U3,e.Editors=a5,e.FeedbackLink=y3,e.FullPreview=lR,e.VisualEditor=oR,e.assembleFullProjectSource=D8,e.assembleProjectSource=T8,e.buildDivisionTree=v8,e.convertLatexToPretext=m3,e.createConclusion=w6,e.createIntroduction=C6,e.createLatexConclusion=z6,e.createLatexIntroduction=R6,e.createNewLatexSection=L6,e.createNewSection=S6,e.derivePretextContent=_3,e.detectSourceFormat=p3,e.ensureLatexSectionWrapper=A6,e.ensureSectionWrapper=D6,e.extractDivisionMetadata=U6,e.extractLatexDivisionTitle=N6,e.findDivisionParent=p8,e.getOrphanRoots=y8,e.getOrphanedDivisions=_8,e.getSectionAttributes=V6,e.insertDivisionRef=l8,e.mergeTwoSections=B6,e.moveDivisionRef=d8,e.normalizeSelfClosingRefs=h8,e.parseDivisionRefs=n8,e.postToIframe=cR,e.removeDivisionRef=u8,e.renameDivisionRef=f8,e.reorderDivisionRefs=m8,e.rewrapLatexSection=k6,e.rewrapSection=E6,e.stripLatexSectionWrapper=O6,e.stripSectionWrapper=T6,e.updateDivisionTitle=x6,e.updateLatexSectionTitle=M6,e.updateSectionMetadata=W6,e.wrapDivisionForPreview=k8});
|
|
1092
|
+
`+a.slice(o)}function p8(e,t,n,r){let i=new RegExp(n8(t));return i.test(e)?e.replace(i,`<plus:${r} ref="${n}"/>`):e}function m8(e,t){let n=new RegExp(n8(t));return e.find(e=>n.test(e.content))??null}function h8(e,t){let n=e,r=null;for(let e of t)n=f8(n,e,r),r=e;return n}function g8(e){return e.replace(/<plus:([a-z-]+)((?:\s[^>]*?)?)>\s*<\/plus:\1>/g,(e,t,n)=>`<plus:${t}${n}/>`)}function _8(e,t){let n=new Set,r=[t];for(;r.length>0;){let t=r.pop();if(n.has(t))continue;n.add(t);let i=e.find(e=>e.xmlId===t);if(i)for(let e of r8(i.content))r.push(e)}return n}function v8(e,t){let n=_8(e,t);return e.filter(e=>!n.has(e.xmlId))}function y8(e,t){let n=[],r=new Set([t]),i=(t,a)=>{let o=e.find(e=>e.xmlId===t);if(o)for(let s of r8(o.content)){if(r.has(s))continue;let o=e.find(e=>e.xmlId===s);o&&(r.add(s),n.push({division:o,depth:a,parentXmlId:t}),i(s,a+1))}};return i(t,0),n}function b8(e,t){let n=v8(e,t),r=new Set(n.map(e=>e.xmlId)),i=new Set;for(let e of n)for(let t of r8(e.content))r.has(t)&&i.add(t);return n.filter(e=>!i.has(e.xmlId))}var x8=new Set([`book`,`article`,`slideshow`]);function S8(e){try{let t=X3(e),n=t.children.find(e=>e.type===`element`),r=n?.name===`pretext`?n.children.find(e=>e.type===`element`&&x8.has(e.name)):n&&x8.has(n.name)?n:void 0;if(!r)return e;if(!r.attributes.label){let e=w8(t,`pretext-plus-preview`);return r.attributes.label=e,FY(t)}return e}catch(t){return console.error(`Error ensuring label:`,t),e}}function C8(e,t){return e.type===`element`&&e.attributes?.label===t?!0:`children`in e&&e.children?e.children.some(e=>e.type===`element`?C8(e,t):!1):!1}function w8(e,t){let n=t,r=1;for(;C8(e,n);)n=`${t}-${r}`,r++;return n}function T8(e,t,n,r){let i=t.find(t=>t.xmlId===e);if(!i)return`<!-- missing division: ${e} -->`;if(n.has(e))return`<!-- circular reference: ${e} -->`;let a;if(i.sourceFormat===`pretext`)a=i.content;else if(i.sourceFormat===`markdown`){let{pretextSource:e,pretextError:t}=_3(i.content,`markdown`);a=e??`<!-- conversion error: ${t} -->`}else a=I6(i)??`<!-- conversion error: ${i.xmlId} -->`;if(i.sourceFormat!==`pretext`)return a;let o=new Set(n).add(e);return a.replace(/<plus:([a-z-]+)\s([^>]*ref="[^"]+"[^>]*?)(?:\/>|>\s*<\/plus:\1>)/g,(e,n,i)=>{let a=/ref="([^"]+)"/.exec(i)?.[1]??``;if(!d6.has(n))return T8(a,t,o,r);let s=/width="([^"]+)"/.exec(i)?.[1];return f6(n,a,r,s)})}function E8(e,t,n=[]){return S8(T8(t,e,new Set,n))}function D8(e,t){return S8(`<pretext>\n${t.trim()?`${t.trim()}\n`:``}${e}\n</pretext>`)}function O8(e,t,n,r=[]){return D8(T8(t,e,new Set,r),n)}var k8=new Set([`part`,`chapter`]);function A8(e,t,n,r){return D8(x8.has(e)?t:k8.has(e)?`<book>\n<title>${r}</title>\n${t}\n</book>`:`<article>\n<title>${r}</title>\n${t}\n</article>`,n)}function j8(e){let t=e.trim(),n=t.match(/^<title\b[^>]*>([\s\S]*?)<\/title>\s*/);return n?{title:n[1].trim(),body:t.slice(n[0].length)}:{title:``,body:t}}function M8(e,t,n,r){let i=n===`book`?`book`:`article`;return e.map(e=>{if(e.sourceFormat===`markdown`){if(!e.title){let t=Z6(e.content)?.title;if(t)return{...e,title:t}}return e}if(e.sourceFormat!==`pretext`)return e;let n=W6(e.content);if(e.xmlId===t&&!(n&&x8.has(n.type))){let{title:t,body:n}=j8(e.content),a=e.title||t||r||`Untitled`;return{...e,type:i,title:a,content:`<${i} xml:id="${e.xmlId}">\n<title>${a}</title>\n\n${n}\n</${i}>`}}return!e.title&&n?.title?{...e,title:n.title}:e})}function N8(e,t){let n=t??[],r=(e,t)=>n.find(n=>n.kind===e&&n.ref===t),i=[],a=new Set;for(let t of e??[])for(let{kind:e,ref:n}of a8(t.content)){let t=`${e}:${n}`;if(a.has(t))continue;a.add(t);let o=r(e,n);i.push({kind:e,ref:n,asset:o,inDocument:!0,status:o?`linked`:`unlinked`})}for(let e of n){if(!e.ref)continue;let t=`${e.kind}:${e.ref}`;a.has(t)||(a.add(t),i.push({kind:e.kind,ref:e.ref,asset:e,inDocument:!1,status:`unused`}))}return i}function P8(e,t){let n=`${e}-copy`;if(!t.has(n))return n;for(let e=2;;e++){let r=`${n}-${e}`;if(!t.has(r))return r}}var F8={image:`Images`,doenet:`Doenet`},I8=[`image`,`doenet`].filter(e=>e!==`doenet`||!1),L8=(e,t)=>`<plus:${e} ref="${t}"/>`,R8=({open:e,onClose:r,resolveTarget:i,replaceTarget:a,onLoadAssets:o,onLoadLibraryAssets:s,onAddFromLibrary:c,onUpload:l,onFetchUrl:u,onCreateDoenet:d,onRemoveAsset:f,onDuplicateAsset:p,onAssetAdded:m,onResolveRef:h,onReplaceAsset:g})=>{let _=T3(e=>e.divisions),v=T3(e=>e.projectAssets)??[],y=T3(e=>e.setProjectAssets),b=T3(e=>e.libraryAssets),x=T3(e=>e.openAssetEditor),S=T3(e=>e.openAssetResolver),C=T3(e=>e.removeAssetRefFromDocument),w=!!(o||s),[T,E]=(0,n.useState)(null),[D,O]=(0,n.useState)(!1),[k,A]=(0,n.useState)(null),j=v,ee=T??b??j,M=new Set(j.map(e=>e.id)),[te,ne]=(0,n.useState)(`in-document`),[N,re]=(0,n.useState)(null),[ie,ae]=(0,n.useState)(`library`),[oe,se]=(0,n.useState)(`library`),[P,ce]=(0,n.useState)(null),[le,ue]=(0,n.useState)(!1),[de,F]=(0,n.useState)(!1),[fe,pe]=(0,n.useState)(null),me=(0,n.useRef)(null),[he,ge]=(0,n.useState)(``),[I,_e]=(0,n.useState)(``),[ve,ye]=(0,n.useState)(!1),[be,xe]=(0,n.useState)(null),[Se,Ce]=(0,n.useState)(``),[L,we]=(0,n.useState)(``),[Te,Ee]=(0,n.useState)(!1),[R,De]=(0,n.useState)(null),[Oe,ke]=(0,n.useState)(null),[z,Ae]=(0,n.useState)(null),[je,Me]=(0,n.useState)(null),Ne=(0,n.useCallback)(()=>{!o&&!s||(O(!0),A(null),Promise.all([o?.()??Promise.resolve(null),s?.()??Promise.resolve(null)]).then(([e,t])=>{e!==null&&y(e),t!==null&&E(t)}).catch(e=>{A(e instanceof Error?e.message:`Failed to load assets.`)}).finally(()=>O(!1)))},[o,s,y]),Pe=(0,n.useRef)(Ne);if((0,n.useEffect)(()=>{Pe.current=Ne}),(0,n.useEffect)(()=>{e&&Pe.current()},[e]),(0,n.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,r]),!e)return null;let Fe=N8(_,j),Ie=(e,t)=>{if(a){g(a,e,!!t?.fromLibrary),r();return}if(m(e),i){e.ref&&h(i.kind,i.ref,e.ref),r();return}e.ref&&navigator.clipboard.writeText(L8(e.kind,e.ref)).catch(()=>{}),Me(e)},Le=(e,t)=>{let n=`${e}:${t}`;navigator.clipboard.writeText(L8(e,t)).catch(()=>{}),ke(n),setTimeout(()=>ke(e=>e===n?null:e),2e3)},Re=async e=>{if(!M.has(e.id)&&c){ce(e.id);try{await c(e)}finally{ce(null)}}Ie(e,{fromLibrary:!0})},ze=async e=>{if(l){pe(null),F(!0);try{Ie(await l(e))}catch(e){pe(e instanceof Error?e.message:`Upload failed.`)}finally{F(!1)}}},Be=async()=>{let e=he.trim();if(!e)return;let t=I.trim();if(u&&l){xe(null),ye(!0);try{let n=await u(e);Ie(await l(t?new File([n],t,{type:n.type}):n))}catch(e){xe(e instanceof Error?e.message:`Failed to add URL.`)}finally{ye(!1)}}else Ie({id:`url-${Date.now()}`,name:t||e,ref:e.split(`/`).pop()??`image`,kind:`image`,url:e})},Ve=async()=>{let e=Se.trim(),t=L.trim();if(!(!e||!t))if(d){De(null),Ee(!0);try{Ie(await d(e,t))}catch(e){De(e instanceof Error?e.message:`Failed to create activity.`)}finally{Ee(!1)}}else Ie({id:`doenet-${Date.now()}`,name:e,ref:t,kind:`doenet`})},He=e=>{let n=ee.filter(t=>t.kind===e);return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-library`,children:[w&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-toolbar`,children:[k&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__asset-load-error`,children:k}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__asset-library-refresh`,onClick:Ne,disabled:D,children:D?`Loading…`:`Refresh`})]}),D&&n.length===0?(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-empty-text`,children:`Loading…`}):n.length===0?(0,t.jsxs)(`p`,{className:`pretext-plus-editor__am-empty-text`,children:[`No `,F8[e].toLowerCase(),` assets in your library.`]}):(0,t.jsx)(`ul`,{className:`pretext-plus-editor__am-list`,children:n.map(e=>{let n=M.has(e.id),r=P===e.id;return(0,t.jsx)(`li`,{children:(0,t.jsxs)(`button`,{type:`button`,className:[`pretext-plus-editor__am-lib-row`,n?`pretext-plus-editor__am-lib-row--in-project`:``].filter(Boolean).join(` `),onClick:()=>Re(e),disabled:r||!e.ref,title:e.ref?n?`Use "${e.ref}"`:`Add to project & use "${e.ref}"`:`Asset has no reference — cannot use`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-info`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-name`,children:e.name}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-ref`,children:r?`Adding…`:e.ref})]}),n&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-badge`,children:`✓`})]})},e.id)})})]})},Ue=()=>{if(Fe.length===0)return(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-placeholder`,children:[(0,t.jsx)(`p`,{children:`No assets in this project yet.`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:()=>{ne(`add`),re(null)},children:`Add an asset`})]});let e=I8.map(e=>({kind:e,rows:Fe.filter(t=>t.kind===e)})).filter(e=>e.rows.length>0),n=e=>{let n=`${e.kind}:${e.ref}`,i=z===n,a=()=>{e.status===`unlinked`?S(e.kind,e.ref):(x(e.kind,e.ref),r())};return(0,t.jsxs)(`li`,{className:`pretext-plus-editor__am-doc-row`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__am-row-info pretext-plus-editor__am-row-info--btn`,onClick:a,title:e.status===`unlinked`?`No asset for this reference — click to link or create one`:`Edit asset`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-name`,children:e.asset?.name??e.ref}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-row-ref`,children:e.ref})]}),e.status===`unlinked`&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-status pretext-plus-editor__am-status--warn`,title:`No asset for this reference`,children:`needs asset`}),e.status===`unused`&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-status`,title:`Not referenced in the document yet`,children:`not placed`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-row-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn`,onClick:a,children:e.status===`unlinked`?`Link / create`:`Edit`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn${Oe===n?` pretext-plus-editor__am-action-btn--done`:``}`,onClick:()=>Le(e.kind,e.ref),title:`Copy ${L8(e.kind,e.ref)}`,children:Oe===n?`Copied!`:`Copy embed code`}),p&&e.asset?.url&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn`,disabled:i,onClick:async()=>{Ae(n);try{await p(e.asset),r()}catch{Ae(null)}},title:`Create a copy of this asset under a new reference`,children:i?`Duplicating…`:`Duplicate`}),f&&e.asset&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn pretext-plus-editor__am-action-btn--danger`,onClick:()=>{e.inDocument&&!window.confirm(`Remove "${e.asset.name}" from the project? This also deletes its reference(s) from the document.`)||(f(e.asset),C(e.kind,e.ref),r())},title:`Remove from project`,children:`Remove`})]})]},n)};return(0,t.jsx)(`div`,{className:`pretext-plus-editor__am-in-doc`,children:e.map(({kind:e,rows:r})=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-group`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-header`,children:[(0,t.jsx)(`span`,{"aria-hidden":`true`,children:`📁`}),(0,t.jsx)(`span`,{children:F8[e]}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-count`,children:r.length})]}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__am-list`,children:r.map(n)})]},e))})},B=e=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-success`,children:[(0,t.jsxs)(`p`,{className:`pretext-plus-editor__am-success-title`,children:[`✓ Added “`,e.name,`” — embed code copied to clipboard`]}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`It now appears in the Assets list. Paste this where you want it to appear:`}),e.ref&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-embed-row`,children:[(0,t.jsx)(`code`,{className:`pretext-plus-editor__am-embed-code`,children:L8(e.kind,e.ref)}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn${Oe===`${e.kind}:${e.ref}`?` pretext-plus-editor__am-action-btn--done`:``}`,onClick:()=>Le(e.kind,e.ref),children:Oe===`${e.kind}:${e.ref}`?`Copied!`:`Copy again`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-success-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:()=>{Me(null),re(null),ne(`add`)},children:`Add another`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:()=>{Me(null),ne(`in-document`)},children:`Done`})]})]}),We=()=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-picker`,children:[(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-kind-picker-label`,children:`What kind of asset?`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-cards`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__am-kind-card`,onClick:()=>{re(`image`),ae(`library`)},children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-icon`,"aria-hidden":`true`,children:`🖼️`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-label`,children:`Image`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-hint`,children:`PNG, JPEG, SVG, etc.`})]}),!1,(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-kind-card pretext-plus-editor__am-kind-card--soon`,"aria-disabled":`true`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-icon`,"aria-hidden":`true`,children:`✨`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-label`,children:`More coming soon`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-kind-card-hint`,children:`Interactive activities and more`})]})]})]}),Ge=e=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure`,children:[e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-back-btn`,onClick:()=>re(null),children:`← Back`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar pretext-plus-editor__am-sub-tabs`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${ie===`library`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ae(`library`),children:`Library`}),l&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${ie===`upload`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ae(`upload`),children:`Upload`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${ie===`url`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ae(`url`),children:`External URL`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure-body`,children:[ie===`library`&&He(`image`),ie===`upload`&&l&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-upload`,children:[(0,t.jsxs)(`div`,{className:[`pretext-plus-editor__am-drop-zone`,le?`pretext-plus-editor__am-drop-zone--active`:``,de?`pretext-plus-editor__am-drop-zone--uploading`:``].filter(Boolean).join(` `),onDragOver:e=>{e.preventDefault(),ue(!0)},onDragLeave:()=>ue(!1),onDrop:e=>{e.preventDefault(),ue(!1);let t=e.dataTransfer.files[0];t&&ze(t)},onClick:()=>!de&&me.current?.click(),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),me.current?.click())},"aria-label":`Upload image — click or drag and drop`,children:[(0,t.jsx)(`input`,{ref:me,type:`file`,accept:`image/*`,className:`pretext-plus-editor__dialog-file-input`,onChange:e=>{let t=e.target.files?.[0];t&&ze(t)}}),de?(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-drop-text`,children:`Uploading…`}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__am-drop-icon`,"aria-hidden":`true`,children:`↑`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-drop-text`,children:`Drag & drop an image, or click to browse`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`PNG, JPEG, GIF, SVG, WebP`})]})]}),fe&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:fe})]}),ie===`url`&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-url-form`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-url-value`,children:`Image URL`}),(0,t.jsx)(`input`,{id:`am-url-value`,type:`url`,className:`pretext-plus-editor__am-input`,placeholder:`https://example.com/image.png`,value:he,onChange:e=>ge(e.target.value),disabled:ve,autoFocus:!0}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-url-name`,children:[`Name `,(0,t.jsx)(`span`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`(optional)`})]}),(0,t.jsx)(`input`,{id:`am-url-name`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`My image`,value:I,onChange:e=>_e(e.target.value),disabled:ve}),be&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:be}),he.trim()&&(0,t.jsx)(`img`,{src:he.trim(),alt:`Preview`,className:`pretext-plus-editor__am-url-preview`,onError:e=>{e.currentTarget.style.display=`none`}}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:Be,disabled:!he.trim()||ve,children:ve?`Adding…`:u&&l?`Add to Project`:`Add`})]})]})]}),Ke=e=>(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure`,children:[e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-back-btn`,onClick:()=>re(null),children:`← Back`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar pretext-plus-editor__am-sub-tabs`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${oe===`library`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>se(`library`),children:`Library`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${oe===`create`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>se(`create`),children:`Create New`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-configure-body`,children:[oe===`library`&&He(`doenet`),oe===`create`&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-create-form`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-doenet-name`,children:`Name`}),(0,t.jsx)(`input`,{id:`am-doenet-name`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`My Activity`,value:Se,onChange:e=>Ce(e.target.value),disabled:Te,autoFocus:!0}),(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-doenet-ref`,children:`Reference ID`}),(0,t.jsx)(`input`,{id:`am-doenet-ref`,type:`text`,className:`pretext-plus-editor__am-input`,placeholder:`my-activity`,value:L,onChange:e=>we(e.target.value),disabled:Te}),(0,t.jsxs)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:[`The reference ID is used in the embed code: `,(0,t.jsx)(`code`,{children:L8(`doenet`,L||`my-activity`)})]}),R&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:R}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:Ve,disabled:!Se.trim()||!L.trim()||Te,children:Te?`Creating…`:d?`Create`:`Add`})]})]})]}),V=(e,n,i)=>(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsx)(`h2`,{className:`pretext-plus-editor__dialog-title`,children:n}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single`,children:[(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy pretext-plus-editor__am-resolve-hint`,children:i}),e===`doenet`?Ke(!1):Ge(!1)]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:r,children:`Cancel`})})]});return(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-overlay`,onClick:e=>e.target===e.currentTarget&&r(),children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog pretext-plus-editor__dialog--asset-manager`,role:`dialog`,"aria-modal":`true`,"aria-label":`Asset manager`,children:i?(e=>V(e.kind,`Link asset`,(0,t.jsxs)(t.Fragment,{children:[`The reference `,(0,t.jsx)(`code`,{children:e.ref}),` has no asset yet. Choose or create one — the reference in your document will be updated to match.`]})))(i):a?(e=>V(e.kind,`Replace asset`,(0,t.jsxs)(t.Fragment,{children:[`Choose or upload a new asset to replace `,(0,t.jsx)(`code`,{children:e.name}),`. Every place it’s used in your document will show the new asset.`]})))(a):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsx)(`h2`,{className:`pretext-plus-editor__dialog-title`,children:`Assets`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),je?(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single`,children:B(je)}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-tab-bar`,children:[(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${te===`in-document`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>ne(`in-document`),children:[`Assets`,Fe.length>0&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__asset-tab-count`,children:Fe.length})]}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-tab${te===`add`?` pretext-plus-editor__dialog-tab--active`:``}`,onClick:()=>{ne(`add`),re(null)},children:`Add Asset`})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single`,children:te===`in-document`?Ue():N===null?We():N===`image`?Ge(!0):Ke(!0)})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:r,children:`Close`})})]})})})},z8={automaticLayout:!0,minimap:{enabled:!1},wordWrap:`on`,insertSpaces:!0,tabSize:2,padding:{top:10,bottom:10},scrollBeyondLastLine:!1},B8=160,V8={image:`image`,doenet:`interactive`},H8=({asset:e,projectAssets:r,onClose:i,onSave:a,onReplace:o,onDuplicate:s})=>{let c=e.ref??``,[l,u]=(0,n.useState)(e.name),[d,f]=(0,n.useState)(c),[p,m]=(0,n.useState)(e.source??``),[h,g]=(0,n.useState)(!1),[_,v]=(0,n.useState)(!1),[y,b]=(0,n.useState)(null),[x,S]=(0,n.useState)(!1),[C,w]=(0,n.useState)(B8),T=(0,n.useRef)(null);(0,n.useEffect)(()=>{T.current?.scrollTo({top:0})},[]);let E=e=>{let t=()=>w(Math.max(B8,e.getContentHeight()));e.onDidContentSizeChange(t),t()},D=`<plus:${e.kind} ref="${d.trim()||c}"/>`,O=()=>{navigator.clipboard.writeText(D).catch(()=>{}),S(!0),setTimeout(()=>S(!1),2e3)},k=async()=>{let t=d.trim();if(!t){b(`Reference can't be empty — it identifies the asset and is used by every embed of it.`);return}if(t!==c&&r.some(n=>n.kind===e.kind&&n.ref===t)){b(`Reference "${t}" is already used by another asset. Choose a unique reference.`);return}b(null),g(!0);try{await a({...e,name:l.trim()||t,ref:t,source:p},c),i()}catch(e){b(e instanceof Error?e.message:`Failed to save asset.`),g(!1)}},A=async()=>{if(s){b(null),v(!0);try{await s(e)}catch(e){b(e instanceof Error?e.message:`Failed to duplicate asset.`),v(!1)}}},j=h||_,ee=e.kind===`image`&&!!e.url,M=e.kind===`image`&&!!o;return(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-overlay`,onClick:e=>e.target===e.currentTarget&&i(),children:(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`Edit asset ${e.name}`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-header`,children:[(0,t.jsx)(`h2`,{className:`pretext-plus-editor__dialog-title`,children:`Edit asset`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,t.jsx)(`div`,{ref:T,className:`pretext-plus-editor__dialog-content pretext-plus-editor__dialog-content--single pretext-plus-editor__am-edit-content`,children:(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-section`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-edit-grid`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-edit-col`,children:[ee&&(0,t.jsx)(`img`,{src:e.url,alt:l,className:`pretext-plus-editor__am-url-preview`,onError:e=>{e.currentTarget.style.display=`none`}}),M&&(0,t.jsx)(`div`,{className:`pretext-plus-editor__am-replace-row`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn`,onClick:()=>o?.(e),disabled:j,title:`Choose or upload a different asset to use here`,children:`Replace image…`})})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-edit-col`,children:[(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-edit-name`,children:`Name`}),(0,t.jsx)(`input`,{id:`am-edit-name`,type:`text`,className:`pretext-plus-editor__am-input`,value:l,onChange:e=>u(e.target.value),disabled:j}),(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,htmlFor:`am-edit-ref`,children:`Reference`}),(0,t.jsx)(`input`,{id:`am-edit-ref`,type:`text`,className:`pretext-plus-editor__am-input`,value:d,onChange:e=>f(e.target.value),disabled:j}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:`Used in the embed code. Changing it updates every reference to this asset already in your document.`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__am-embed-row`,children:[(0,t.jsx)(`code`,{className:`pretext-plus-editor__am-embed-code`,children:D}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__am-action-btn${x?` pretext-plus-editor__am-action-btn--done`:``}`,onClick:O,title:`Copy embed code to clipboard`,children:x?`Copied!`:`Copy embed code`})]})]})]}),(0,t.jsx)(`label`,{className:`pretext-plus-editor__dialog-label`,children:`Asset content`}),(0,t.jsxs)(`p`,{className:`pretext-plus-editor__dialog-helper-copy`,children:[`Inserted verbatim inside the generated `,(0,t.jsx)(`code`,{children:`<${V8[e.kind]}>`}),` element — e.g. `,(0,t.jsx)(`code`,{children:`<shortdescription>...</shortdescription>`}),`.`]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__dialog-editor pretext-plus-editor__am-edit-editor`,style:{height:C},children:(0,t.jsx)(Yn,{options:{...z8,readOnly:j},height:`100%`,language:`xml`,value:p,onMount:E,onChange:e=>m(e??``)})}),y&&(0,t.jsx)(`p`,{className:`pretext-plus-editor__am-error`,children:y})]})}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__dialog-actions`,children:[s&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary pretext-plus-editor__am-duplicate-btn`,onClick:A,disabled:j,title:`Create a copy of this asset under a new reference`,children:_?`Duplicating…`:`Duplicate`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button pretext-plus-editor__dialog-button--secondary`,onClick:i,disabled:j,children:`Cancel`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__dialog-button`,onClick:k,disabled:j,children:h?`Saving…`:`Save`})]})]})})},U8=e=>{let n=T3(e=>e.showFullPreview),r=T3(e=>e.setShowFullPreview),i=T3(e=>e.title),a=T3(e=>e.updateTitle),o;return o=e.showPreviewModeToggle===!1?null:(0,t.jsxs)(`label`,{className:`pretext-plus-editor__preview-toggle`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:!n,onChange:()=>r(!n),className:`pretext-plus-editor__preview-toggle-input`}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__preview-toggle-container`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-label`,children:`Simple`}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-slider ${n?`pretext-plus-editor__preview-toggle-slider--active`:``}`,children:(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-dot ${n?`pretext-plus-editor__preview-toggle-dot--active`:``}`})}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-label`,children:`Full`})]}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__preview-toggle-caption`,children:`Preview Mode`}),(0,t.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>r(!n),className:`pretext-plus-editor__preview-toggle-input`})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-bar`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__menu-left`,children:(0,t.jsxs)(`label`,{className:`pretext-plus-editor__title-label`,children:[`Title`,` `,(0,t.jsx)(`input`,{className:`pretext-plus-editor__title-input`,type:`text`,value:i,onChange:e=>a(e.target.value)})]})}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__menu-right`,children:[e.onSaveButton&&(0,t.jsx)(`button`,{className:`pretext-plus-editor__button pretext-plus-editor__button--save`,onClick:e.onSaveButton,children:e.saveButtonLabel||`Save`}),e.onCancelButton&&(0,t.jsx)(`button`,{className:`pretext-plus-editor__button pretext-plus-editor__button--cancel`,onClick:e.onCancelButton,children:e.cancelButtonLabel||`Cancel`}),(0,t.jsx)(E3,{label:`Give feedback`,context:`main-editor`}),o]})]})},W8={pretext:`PreTeXt`,latex:`LaTeX`,markdown:`Markdown`},G8={book:`bk`,article:`art`,slideshow:`slides`,part:`pt`,chapter:`ch`,section:`sec`,subsection:`subsec`,subsubsection:`subsubsec`,introduction:`intro`,conclusion:`conc`,worksheet:`ws`,handout:`ho`,exercises:`ex`,references:`ref`,glossary:`gloss`,solutions:`sol`,"reading-questions":`rq`,paragraphs:`para`},K8={book:`Book`,article:`Article`,slideshow:`Slideshow`,part:`Part`,chapter:`Chapter`,section:`Section`,worksheet:`Worksheet`,handout:`Handout`,exercises:`Exercises`,references:`References`,glossary:`Glossary`,solutions:`Solutions`,"reading-questions":`Reading Questions`,introduction:`Introduction`,conclusion:`Conclusion`,subsection:`Subsection`,subsubsection:`Subsubsection`,paragraphs:`Paragraphs`},q8=[`part`,`chapter`,`section`,`subsection`,`subsubsection`,`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`,`paragraphs`],J8=[`worksheet`,`handout`,`exercises`,`references`,`glossary`,`solutions`,`reading-questions`,`paragraphs`],Y8={book:[`part`,`chapter`],article:[`section`,...J8],slideshow:[`section`],part:[`chapter`],chapter:[`section`,...J8],section:[`subsection`,...J8],subsection:[`subsubsection`,...J8],subsubsection:[...J8],worksheet:[`paragraphs`],handout:[`paragraphs`]};function X8(e){return e?Y8[e]??q8:q8}function Z8(e,t){let n=G8[e]??`sec`,r=U6(t);return r?`${n}-${r}`:n}var Q8=({draft:e,isNew:r=!1,isRoot:i=!1,parentType:a=null,onDraftChange:o,onCommit:s,onCancel:c})=>{let l=X8(a),u=(0,n.useRef)(r);return(0,n.useEffect)(()=>{i||l.length>0&&!l.includes(e.type)&&o({...e,type:l[0]})},[e,i,o,l]),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-edit-form`,children:[(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Title`}),(0,t.jsx)(`input`,{type:`text`,value:e.title,onChange:t=>{let n=t.target.value;o(u.current?{...e,title:n,xmlId:Z8(e.type,n)}:{...e,title:n})},onKeyDown:e=>{e.key===`Enter`&&s(),e.key===`Escape`&&c()},autoFocus:!0})]}),r?(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Format`}),(0,t.jsx)(`select`,{value:e.sourceFormat,onChange:t=>o({...e,sourceFormat:t.target.value}),children:Object.keys(W8).map(e=>(0,t.jsx)(`option`,{value:e,children:W8[e]},e))})]}):void 0,!i&&(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Type`}),(0,t.jsx)(`select`,{value:e.type,onChange:t=>{let n=t.target.value;o(u.current?{...e,type:n,xmlId:Z8(n,e.title)}:{...e,type:n})},children:l.map(e=>(0,t.jsx)(`option`,{value:e,children:K8[e]},e))})]}),(0,t.jsxs)(`label`,{className:`pretext-plus-editor__toc-edit-field`,children:[(0,t.jsx)(`span`,{children:`Id`}),(0,t.jsx)(`input`,{type:`text`,value:e.xmlId,placeholder:`unique identifier`,onChange:t=>{u.current=!1,o({...e,xmlId:t.target.value})}})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-edit-actions`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-edit-save`,onClick:s,children:`Save`}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-edit-cancel`,onClick:c,children:`Cancel`})]})]})},$8=({items:e})=>{let[i,a]=(0,n.useState)(!1),[o,s]=(0,n.useState)(null),c=(0,n.useRef)(null),l=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!i)return;let e=e=>{let t=e.target;c.current&&!c.current.contains(t)&&l.current&&!l.current.contains(t)&&a(!1)},t=e=>{e.key===`Escape`&&a(!1)},n=()=>a(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),window.addEventListener(`scroll`,n,!0),window.addEventListener(`resize`,n),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t),window.removeEventListener(`scroll`,n,!0),window.removeEventListener(`resize`,n)}},[i]),(0,n.useLayoutEffect)(()=>{if(!i)return;let e=c.current,t=l.current;if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),a=window.innerHeight-n.bottom,o=r.height+4>a&&n.top>a;s({right:Math.max(4,window.innerWidth-n.right),...o?{bottom:window.innerHeight-n.top+3}:{top:n.bottom+3}})},[i]);let u=e=>{a(!1),e()};return(0,t.jsxs)(`div`,{ref:c,className:`pretext-plus-editor__toc-div-menu`,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-div-menu-trigger`,onClick:e=>{e.stopPropagation(),a(e=>(e||s(null),!e))},"aria-haspopup":`true`,"aria-expanded":i,title:`More options`,children:`⋮`}),i&&(0,r.createPortal)((0,t.jsx)(`div`,{ref:l,className:`pretext-plus-editor__toc-div-menu-popup pretext-plus-editor__toc-div-menu-popup--portal`,style:{visibility:o?`visible`:`hidden`,right:o?.right,top:o?.top,bottom:o?.bottom},children:e.map(e=>(0,t.jsx)(`button`,{type:`button`,className:[`pretext-plus-editor__toc-div-menu-item`,e.danger?`pretext-plus-editor__toc-div-menu-item--danger`:``].filter(Boolean).join(` `),onClick:()=>u(e.onClick),children:e.label},e.label))}),document.body)]})},e5=({division:e,depth:n,isActive:r,hasChildren:i,isExpanded:a,onToggleExpand:o,editDraft:s,onSelect:c,onDraftChange:l,onEditCommit:u,onEditCancel:d,menuItems:f,isNew:p=!1,isRoot:m=!1,parentType:h=null})=>{let g=s!==null,_=e.type===`introduction`||e.type===`conclusion`?K8[e.type]:null;return(0,t.jsxs)(`li`,{className:[`pretext-plus-editor__toc-item`,`pretext-plus-editor__toc-item--${e.type}`,r?`pretext-plus-editor__toc-item--active`:``,g?`pretext-plus-editor__toc-item--editing`:``].filter(Boolean).join(` `),children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-item-row`,style:n>0?{paddingLeft:`${n*14}px`}:void 0,children:[(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-expand-btn`,onClick:o,"aria-label":a?`Collapse`:`Expand`,tabIndex:i?0:-1,style:{visibility:i?`visible`:`hidden`},children:a?`▾`:`▸`}),(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__toc-select`,onClick:c,"aria-current":r?`true`:void 0,title:K8[e.type]??e.type,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-title`,children:e.title||_||(0,t.jsx)(`em`,{children:`Untitled`})}),e.xmlId&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-xmlid`,children:e.xmlId})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-actions`,children:(0,t.jsx)($8,{items:f})})]}),g&&s&&(0,t.jsx)(Q8,{draft:s,isNew:p,isRoot:m,parentType:h,onDraftChange:l,onCommit:u,onCancel:d})]})},t5=({onOpenAssetPicker:e})=>{let r=T3(e=>e.divisions),i=T3(e=>e.rootDivisionId),a=T3(e=>e.activeDivisionId),o=T3(e=>e.projectAssets)??[],s=T3(e=>e.selectSection),c=T3(e=>e.addSection),l=T3(e=>e.removeSection),u=T3(e=>e.divisionContentChange),d=T3(e=>e.insertAtCursor),f=T3(e=>e.openAssetEditor),p=T3(e=>e.openAssetResolver),m=T3(e=>e.removeAsset),h=T3(e=>e.removeAssetRefFromDocument),g=T3(e=>e.duplicateAsset),_=T3(e=>e.hasAssetDuplicate),v=T3(e=>e.startSectionEdit),y=T3(e=>e.setEditDraft),b=T3(e=>e.commitSectionEdit),x=T3(e=>e.cancelSectionEdit),S=T3(e=>e.editingId),C=T3(e=>e.editDraft),w=T3(e=>e.editingIsNew),T=r?r.find(e=>e.xmlId===i)??r.find(e=>e.type===`book`||e.type===`article`||e.type===`slideshow`)??r[0]??null:null,E=T&&r?y8(r,T.xmlId):[],D=T&&r?b8(r,T.xmlId):[],O=N8(r,o),k=I8.map(e=>({kind:e,rows:O.filter(t=>t.kind===e)})).filter(e=>e.rows.length>0),[A,j]=(0,n.useState)(!1),[ee,M]=(0,n.useState)(null),te=async e=>{if(!(!e.asset||ee)){M(e.ref);try{await g(e.asset)}finally{M(null)}}},[ne,N]=(0,n.useState)(new Set),re=e=>!ne.has(e),ie=e=>{N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[ae,oe]=(0,n.useState)(a);if(a!==ae&&(oe(a),a&&T)){let e=new Map(E.map(e=>[e.division.xmlId,e])),t=new Set;t.add(T.xmlId);let n=a;for(;n;){let r=e.get(n);if(!r?.parentXmlId)break;t.add(r.parentXmlId),n=r.parentXmlId}N(e=>{if([...t].every(t=>!e.has(t)))return e;let n=new Set(e);return t.forEach(e=>n.delete(e)),n})}let se=new Set(E.map(e=>e.parentXmlId).filter(Boolean)),P=[];if(T){let e=new Set;re(T.xmlId)&&e.add(T.xmlId);for(let t of E)t.parentXmlId&&e.has(t.parentXmlId)&&(P.push(t),re(t.division.xmlId)&&e.add(t.division.xmlId))}let ce=(e,t)=>{if(!r)return;let n=r.find(e=>e.xmlId===t);n&&u(n.xmlId,g8(d8(n.content,e)))},le=(e,t)=>{if(window.confirm(`Delete "${e.title||`Untitled`}"? This permanently removes the division.`)){if(t&&r){let n=r.find(e=>e.xmlId===t);n&&u(n.xmlId,g8(d8(n.content,e.xmlId)))}l(e.xmlId)}},ue=e=>{d(`<plus:${e.type} ref="${e.xmlId}"/>`)},de=e=>{T&&u(T.xmlId,g8(u8(T.content,e.xmlId,e.type,null)))},F=e=>e&&r?.find(t=>t.xmlId===e)?.type||null,fe=e=>e.status===`unlinked`?p(e.kind,e.ref):f(e.kind,e.ref),pe=(e,t)=>{navigator.clipboard.writeText(`<plus:${e} ref="${t}"/>`).catch(()=>{})},me=e=>{let t=[{label:e.status===`unlinked`?`Link / create asset`:`Edit asset`,onClick:()=>fe(e)},{label:`Copy embed code`,onClick:()=>pe(e.kind,e.ref)}];return _&&e.asset&&t.push({label:`Duplicate asset`,onClick:()=>te(e)}),e.status===`unlinked`?t.push({label:`Remove from document`,onClick:()=>h(e.kind,e.ref),danger:!0}):e.asset&&t.push({label:`Remove from project`,onClick:()=>{e.inDocument&&!window.confirm(`Remove "${e.asset.name}" from the project? This also deletes its ${e.inDocument?`reference(s)`:`reference`} from the document.`)||(m(e.asset),h(e.kind,e.ref))},danger:!0}),t};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(`ul`,{className:`pretext-plus-editor__toc-list`,role:`list`,children:[T&&(0,t.jsx)(e5,{division:T,depth:0,isActive:a===T.xmlId,hasChildren:se.has(T.xmlId),isExpanded:re(T.xmlId),onToggleExpand:()=>ie(T.xmlId),editDraft:S===T.xmlId?C:null,onSelect:()=>s(T.xmlId),onDraftChange:y,onEditCommit:b,onEditCancel:x,menuItems:[{label:`Edit properties`,onClick:()=>v(T)},...T.sourceFormat===`pretext`?[{label:`Add new division`,onClick:()=>c(T.xmlId)}]:[]],isNew:S===T.xmlId&&w,isRoot:!0}),P.length===0&&T&&re(T.xmlId)&&(0,t.jsx)(`li`,{className:`pretext-plus-editor__toc-no-sections`,children:(0,t.jsx)(`span`,{children:`No placed divisions`})}),P.map(e=>(0,t.jsx)(e5,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:se.has(e.division.xmlId),isExpanded:re(e.division.xmlId),onToggleExpand:()=>ie(e.division.xmlId),editDraft:S===e.division.xmlId?C:null,onSelect:()=>s(e.division.xmlId),onDraftChange:y,onEditCommit:b,onEditCancel:x,menuItems:[{label:`Edit properties`,onClick:()=>v(e.division)},...e.division.sourceFormat===`pretext`?[{label:`Add new division`,onClick:()=>c(e.division.xmlId)}]:[],{label:`Remove from document`,onClick:()=>ce(e.division.xmlId,e.parentXmlId)},{label:`Delete from project`,onClick:()=>le(e.division,e.parentXmlId),danger:!0}],isNew:S===e.division.xmlId&&w,parentType:F(e.parentXmlId)},e.division.xmlId))]}),D.length>0&&(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-orphans`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-orphans-heading`,children:`Unplaced divisions`}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__toc-list`,children:D.map(e=>{let i=r?y8(r,e.xmlId):[],o=new Set(i.map(e=>e.parentXmlId).filter(Boolean));return(0,t.jsxs)(n.Fragment,{children:[(0,t.jsx)(e5,{division:e,depth:0,isActive:a===e.xmlId,hasChildren:o.has(e.xmlId),isExpanded:re(e.xmlId),onToggleExpand:()=>ie(e.xmlId),editDraft:S===e.xmlId?C:null,onSelect:()=>s(e.xmlId),onDraftChange:y,onEditCommit:b,onEditCancel:x,menuItems:[{label:`Edit properties`,onClick:()=>v(e)},{label:`Place in document`,onClick:()=>de(e)},{label:`Insert at cursor`,onClick:()=>ue(e)},{label:`Delete from project`,onClick:()=>le(e,null),danger:!0}],parentType:null}),re(e.xmlId)&&i.map(e=>(0,t.jsx)(e5,{division:e.division,depth:e.depth+1,isActive:a===e.division.xmlId,hasChildren:o.has(e.division.xmlId),isExpanded:re(e.division.xmlId),onToggleExpand:()=>ie(e.division.xmlId),editDraft:S===e.division.xmlId?C:null,onSelect:()=>s(e.division.xmlId),onDraftChange:y,onEditCommit:b,onEditCancel:x,menuItems:[{label:`Edit properties`,onClick:()=>v(e.division)},{label:`Insert at cursor`,onClick:()=>ue(e.division)},{label:`Delete from project`,onClick:()=>le(e.division,e.parentXmlId),danger:!0}],parentType:F(e.parentXmlId)},e.division.xmlId))]},e.xmlId)})})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-assets`,children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-header`,children:(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-toggle`,onClick:()=>j(e=>!e),"aria-expanded":A,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-assets-chevron`,children:A?`▾`:`▸`}),(0,t.jsx)(`span`,{children:`Assets`}),O.length>0&&(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-assets-count`,children:O.length})]})}),A&&(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-body`,children:O.length===0?(0,t.jsxs)(`p`,{className:`pretext-plus-editor__toc-assets-empty`,children:[`No assets in this project yet.`,` `,e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-add-link`,onClick:e,children:`Add one`})]}):(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-groups`,children:k.map(({kind:e,rows:n})=>(0,t.jsxs)(`div`,{children:[(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-assets-group-header`,children:F8[e]}),(0,t.jsx)(`ul`,{className:`pretext-plus-editor__toc-assets-list`,children:n.map(e=>(0,t.jsxs)(`li`,{className:[`pretext-plus-editor__toc-asset-item`,e.status===`unlinked`?`pretext-plus-editor__toc-asset-item--unlinked`:``,e.status===`unused`?`pretext-plus-editor__toc-asset-item--unused`:``,ee===e.ref?`pretext-plus-editor__toc-asset-item--busy`:``].filter(Boolean).join(` `),children:[e.asset?.url?(0,t.jsx)(`img`,{src:e.asset.url,className:`pretext-plus-editor__toc-asset-img`,onClick:()=>fe(e)}):(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-img pretext-plus-editor__toc-asset-img--placeholder`,onClick:()=>fe(e),title:e.status===`unlinked`?`No asset — click to link`:void 0,"aria-hidden":`true`,children:e.status===`unlinked`?`⚠`:`🖼`}),(0,t.jsxs)(`button`,{type:`button`,className:`pretext-plus-editor__toc-asset-name`,onClick:()=>fe(e),title:e.status===`unlinked`?`No asset for this reference — click to link or create one`:`Edit asset`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-label`,children:e.asset?.name??e.ref}),(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-filename`,children:e.status===`unlinked`?`${e.ref} — needs asset`:e.status===`unused`?`${e.ref} — not placed`:e.ref})]}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-actions`,children:ee===e.ref?(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-asset-spinner`,role:`status`,"aria-label":`Duplicating asset`,title:`Duplicating…`}):(0,t.jsx)($8,{items:me(e)})})]},e.ref))})]},e))})})]}),e&&(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-assets-btn`,onClick:e,children:`Manage Assets`})]})},n5=({isCollapsed:e,onToggleCollapse:n,onOpenAssetPicker:r})=>e?(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc pretext-plus-editor__toc--collapsed`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-toggle`,onClick:n,"aria-label":`Expand table of contents`,title:`Expand table of contents`,children:`☰`})}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__toc-header`,children:[(0,t.jsx)(`span`,{className:`pretext-plus-editor__toc-heading`,children:`Contents`}),(0,t.jsx)(`div`,{className:`pretext-plus-editor__toc-header-actions`,children:(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__toc-toggle`,onClick:n,"aria-label":`Collapse table of contents`,title:`Collapse table of contents`,children:`✕`})})]}),(0,t.jsx)(t5,{onOpenAssetPicker:r})]}),r5=class extends n.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.props.onError?.(e,t),console.error(`ErrorBoundary caught an error:`,e,t)}componentDidUpdate(e){if(this.state.error===null)return;let{resetKeys:t}=this.props,n=e.resetKeys;t&&n&&(t.length!==n.length||t.some((e,t)=>!Object.is(e,n[t])))&&this.reset()}reset=()=>{this.setState({error:null})};render(){let{error:e}=this.state;return e===null?this.props.children:this.props.fallback?this.props.fallback(e,this.reset):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__error-boundary`,role:`alert`,children:[(0,t.jsx)(`strong`,{children:`Something went wrong rendering this view.`}),(0,t.jsx)(`p`,{className:`pretext-plus-editor__error-boundary-detail`,children:e.message}),(0,t.jsx)(`button`,{type:`button`,className:`pretext-plus-editor__error-boundary-retry`,onClick:this.reset,children:`Try again`})]})}},i5=(e,t)=>e.kind===t.kind&&e.ref===t.ref;function a5(e){let t=()=>{},n={cbs:{selectDivision:t,addDivision:t,removeDivision:t,updateDivision:t,divisionContentChange:t,handleDivisionContentChange:t,assetInsert:t,updateTitle:t}};return{store:x3()((t,r)=>({source:e.source,sourceFormat:e.sourceFormat,projectAssets:e.projectAssets,libraryAssets:void 0,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,projectType:e.projectType,projectUrl:void 0,divisions:e.divisions,rootDivisionId:void 0,activeDivisionId:e.activeDivisionId,canConvertToPretext:!0,activeEditorSource:e.source,hasFeedback:!1,hasAssetDuplicate:!1,isTocCollapsed:!1,showFullPreview:!0,isNarrowScreen:typeof window<`u`?window.innerWidth<800:!1,activeTab:`editor`,isLatexDialogOpen:!1,isConvertDialogOpen:!1,isDocinfoEditorOpen:!1,isAssetPickerOpen:!1,isFullSourceOpen:!1,editingId:null,editDraft:null,editingIsNew:!1,editingAssetRef:null,assetResolveTarget:null,syncState:e=>t(e),applyExternalUpdate:e=>t(e),setDivisionContent:(e,n)=>t(t=>{if(!t.divisions)return{};let r=!1,i=t.divisions.map(t=>t.xmlId===e&&t.content!==n?(r=!0,{...t,content:n}):t);return r?{divisions:i}:{}}),patchDivision:(e,n)=>t(t=>t.divisions?{divisions:t.divisions.map(t=>t.xmlId===e?{...t,...n.id!==void 0&&{id:n.id},...n.title!==void 0&&{title:n.title},...n.type!==void 0&&{type:n.type},...n.xmlId!=null&&{xmlId:n.xmlId},...n.sourceFormat!==void 0&&{sourceFormat:n.sourceFormat}}:t)}:{}),addDivisionToPool:e=>t(t=>{let n=t.divisions??[];return n.some(t=>t.xmlId===e.xmlId)?{}:{divisions:[...n,e]}}),removeDivisionFromPool:e=>t(t=>({divisions:(t.divisions??[]).filter(t=>t.xmlId!==e)})),setActiveDivisionId:e=>t({activeDivisionId:e}),setTitle:e=>t({title:e}),setDocinfo:({docinfo:e,commonDocinfo:n,useCommonDocinfo:r})=>t({docinfo:e,commonDocinfo:n,useCommonDocinfo:r}),setShowFullPreview:e=>t({showFullPreview:e}),setActiveTab:e=>t({activeTab:e}),setIsNarrowScreen:e=>t({isNarrowScreen:e}),setIsTocCollapsed:e=>t(t=>({isTocCollapsed:typeof e==`function`?e(t.isTocCollapsed):e})),openModal:e=>t({[e]:!0}),closeModal:e=>t({[e]:!1}),selectSection:e=>n.cbs.selectDivision(e),addSection:e=>n.cbs.addDivision(e),removeSection:e=>n.cbs.removeDivision(e),updateSection:(e,t)=>n.cbs.updateDivision(e,t),divisionContentChange:(e,t)=>n.cbs.divisionContentChange?.(e,t),startSectionEdit:(e,n)=>{let{xmlId:r,label:i}=e.sourceFormat===`markdown`?Z6(e.content)??{xmlId:e.xmlId,label:``}:e.sourceFormat===`latex`?{xmlId:P6(e.content)||e.xmlId,label:``}:V6(e.content);t({editingId:e.xmlId,editDraft:{title:e.title,type:e.type,xmlId:r,label:i,sourceFormat:e.sourceFormat},editingIsNew:n?.isNew??!1})},setEditDraft:e=>t({editDraft:e}),commitSectionEdit:()=>{let{editingId:e,editDraft:i,divisions:a}=r();if(e&&i){let t=(a??[]).find(t=>t.xmlId===e),r=null;if(t){let t=H6(i.xmlId);if(!t){window.alert(`xml:id can't be empty — it identifies the division and is used by references to it.`);return}if((a??[]).some(n=>n.xmlId!==e&&n.xmlId===t)){window.alert(`xml:id "${t}" is already used by another division. Choose a unique id.`);return}r=t}n.cbs.updateDivision(e,{title:i.title.trim()||void 0,type:i.type,xmlId:r,label:i.label.trim()||null,sourceFormat:i.sourceFormat})}t({editingId:null,editDraft:null,editingIsNew:!1})},cancelSectionEdit:()=>t({editingId:null,editDraft:null,editingIsNew:!1}),insertAsset:e=>n.cbs.assetInsert(e),insertAtCursor:e=>n.cbs.insertContentAtCursor?.(e),openAssetEditor:(e,n)=>t({editingAssetRef:{kind:e,ref:n}}),closeAssetEditor:()=>t({editingAssetRef:null}),openAssetResolver:(e,n)=>t({assetResolveTarget:{kind:e,ref:n}}),closeAssetResolver:()=>t({assetResolveTarget:null}),removeAsset:e=>n.cbs.assetRemove?.(e),removeAssetRefFromDocument:(e,t)=>n.cbs.assetRefRemove?.(e,t),duplicateAsset:async e=>{await n.cbs.assetDuplicate?.(e)},setProjectAssets:e=>t({projectAssets:e}),addAssetToPool:e=>t(t=>{let n=t.projectAssets??[];return n.some(t=>i5(t,e))?{}:{projectAssets:[...n,e]}}),updateAssetInPool:e=>t(t=>{let n=t.projectAssets??[];return n.some(t=>i5(t,e))?{projectAssets:n.map(t=>i5(t,e)?e:t)}:{projectAssets:[...n,e]}}),renameAssetInPool:(e,n,r)=>t(t=>({projectAssets:[...(t.projectAssets??[]).filter(t=>!(t.kind===e&&t.ref===n)&&!i5(t,r)),r]})),removeAssetFromPool:e=>t(t=>({projectAssets:(t.projectAssets??[]).filter(t=>!i5(t,e))})),updateTitle:e=>n.cbs.updateTitle(e),feedbackSubmit:e=>n.cbs.feedbackSubmit?.(e)})),bindCallbacks:e=>{n.cbs=e}}}function o5({store:e,children:n}){return(0,t.jsx)(w3.Provider,{value:e,children:n})}var s5=(e,t)=>e.find(e=>t?e.xmlId===t:e.type===`book`||e.type===`article`||e.type===`slideshow`)??e[0]??null,c5=e=>{let[r]=(0,n.useState)(()=>{let t=s5(e.divisions,e.rootDivisionId),n=M8(e.divisions,t?.xmlId,e.projectType,e.title),r=n.find(e=>e.xmlId===t?.xmlId)??t,i=e.activeDivisionId??r?.xmlId??null,a=n.find(e=>e.xmlId===i)??r;return a5({source:a?.content??``,sourceFormat:a?.sourceFormat??`pretext`,title:e.title||r?.title||`Document Title`,docinfo:e.docinfo??``,commonDocinfo:e.commonDocinfo??``,useCommonDocinfo:e.useCommonDocinfo??!1,projectType:e.projectType,divisions:n,activeDivisionId:i,projectAssets:e.projectAssets})});return(0,t.jsx)(o5,{store:r.store,children:(0,t.jsx)(l5,{...e,bindCallbacks:r.bindCallbacks})})},l5=e=>{let{bindCallbacks:r}=e,i=T3(e=>e.showFullPreview),a=T3(e=>e.isNarrowScreen),o=T3(e=>e.setIsNarrowScreen),s=T3(e=>e.activeTab),c=T3(e=>e.setActiveTab),l=T3(e=>e.isTocCollapsed),u=T3(e=>e.setIsTocCollapsed),d=T3(e=>e.isLatexDialogOpen),f=T3(e=>e.isConvertDialogOpen),p=T3(e=>e.isDocinfoEditorOpen),m=T3(e=>e.isAssetPickerOpen),h=T3(e=>e.isFullSourceOpen),g=T3(e=>e.editingAssetRef),_=T3(e=>e.openAssetEditor),v=T3(e=>e.closeAssetEditor),y=T3(e=>e.assetResolveTarget),b=T3(e=>e.closeAssetResolver),[x,S]=(0,n.useState)(null),C=T3(e=>e.openModal),w=T3(e=>e.closeModal),T=T3(e=>e.syncState),E=T3(e=>e.projectAssets),D=T3(e=>e.addAssetToPool),O=T3(e=>e.updateAssetInPool),k=T3(e=>e.renameAssetInPool),A=T3(e=>e.removeAssetFromPool),j=g?E?.find(e=>e.kind===g.kind&&e.ref===g.ref):void 0,ee=T3(e=>e.divisions),M=(0,n.useMemo)(()=>ee??[],[ee]),te=T3(e=>e.activeDivisionId),ne=T3(e=>e.title),N=T3(e=>e.docinfo),re=T3(e=>e.commonDocinfo),ie=T3(e=>e.useCommonDocinfo),ae=T3(e=>e.applyExternalUpdate),oe=T3(e=>e.setDivisionContent),se=T3(e=>e.patchDivision),P=T3(e=>e.addDivisionToPool),ce=T3(e=>e.removeDivisionFromPool),le=T3(e=>e.setActiveDivisionId),ue=T3(e=>e.startSectionEdit),de=T3(e=>e.setTitle),F=T3(e=>e.setDocinfo),fe=T3(e=>e.editingId),pe=T3(e=>e.editingIsNew),me=(0,n.useRef)(null),he=(0,n.useRef)(null),ge=(0,n.useRef)(!1);(0,n.useEffect)(()=>{fe&&pe?ge.current=!0:ge.current&&(ge.current=!1,he.current?.focus())},[fe,pe]);let I=s5(M,e.rootDivisionId),_e=M.find(e=>e.xmlId===te)??M[0]??null,ve=_e?.sourceFormat??`pretext`,ye=_e?.content??``,be=(t,n,r,i)=>{oe(t,n),e.onContentChange({xmlId:t,sourceContent:n,sourceFormat:r,pretextSource:r===`pretext`?n:void 0,...i})},xe=(t,n)=>{se(t,n),e.onDivisionUpdate?.(t,n)},Se=(e,t)=>{let n=M.find(t=>t.xmlId===e);if(!n){xe(e,t);return}let r;if(t.sourceFormat!==void 0&&t.sourceFormat!==n.sourceFormat){let e=t.type??n.type,i=t.title??n.title,a=t.xmlId||n.xmlId;r={...n,sourceFormat:t.sourceFormat,type:e,title:i,xmlId:a,content:l8(e,t.sourceFormat,i,a)}}else r=n.sourceFormat===`markdown`?Q6(n,t):n.sourceFormat===`latex`?F6(n,t):G6(n,t);let i=r.xmlId;if(r.content!==n.content&&be(n.xmlId,r.sourceFormat===`pretext`?g8(r.content):r.content,r.sourceFormat),xe(e,{...t,xmlId:i}),i!==n.xmlId||r.type!==n.type){let e=m8(M,n.xmlId);if(e){let t=p8(e.content,n.xmlId,i,r.type);t!==e.content&&be(e.xmlId,t,e.sourceFormat)}}i!==n.xmlId&&we(i)},Ce=t=>{P(t),(e.onDivisionAdd?.(t))?.then(e=>se(t.xmlId,{id:e})).catch(()=>{})},L=t=>{ce(t),e.onDivisionRemove?.(t)},we=t=>{le(t),e.onDivisionSelect?.(t)},Te=(0,n.useMemo)(()=>{if(!_e||ve===`pretext`)return;if(ve===`latex`)return I6(_e)??void 0;let e=_3(ye,ve);return e.pretextError?void 0:e.pretextSource},[_e,ve,ye]),Ee=e=>{if(!_e)return;let t=ve===`pretext`?g8(e||``):e||``;if(ve===`pretext`){let e=W6(t);e&&e.xmlId!==_e.xmlId&&(t=g8(G6({..._e,content:t,title:e.title,type:e.type},{xmlId:_e.xmlId,label:e.label||null}).content))}else if(ve===`markdown`){let e=Z6(t);e&&e.xmlId!==_e.xmlId&&(t=Q6({..._e,content:t},{xmlId:_e.xmlId}).content)}if(t===_e.content)return;if(be(_e.xmlId,t,ve),ve===`pretext`){let e=W6(t);if(e&&(xe(_e.xmlId,{title:e.title,type:e.type,label:e.label||null}),e.type!==_e.type)){let t=m8(M,_e.xmlId);if(t){let n=p8(t.content,_e.xmlId,_e.xmlId,e.type);n!==t.content&&be(t.xmlId,n,t.sourceFormat)}}}else if(ve===`markdown`){let e=Z6(t);if(e&&(xe(_e.xmlId,{title:e.title,type:e.type,label:e.label||null}),e.type!==_e.type)){let t=m8(M,_e.xmlId);if(t){let n=p8(t.content,_e.xmlId,_e.xmlId,e.type);n!==t.content&&be(t.xmlId,n,t.sourceFormat)}}}else if(ve===`latex`){let e=N6(t);e!==null&&xe(_e.xmlId,{title:e})}let n=new Set(M.map(e=>e.xmlId));for(let{xmlId:e,type:r}of i8(t))n.has(e)||(Ce(c8(e,r,ve)),n.add(e))},R=e=>{we(e)},De=()=>{_e&&(u(!1),ue(_e))},Oe=e=>{let t=S6();if(Ce(t),e){let n=M.find(t=>t.xmlId===e);n&&be(n.xmlId,g8(u8(n.content,t.xmlId,t.type,null)),n.sourceFormat)}le(t.xmlId),ue(t,{isNew:!0})},ke=e=>{D(e)},z=t=>{A(t),e.onAssetRemove?.(t)},Ae=!!(e.onAssetUpload&&e.onAssetFetchUrl&&e.onAssetUpdate),je=!!(e.onAssetRemove&&(e.onAssetUpload||e.onAssetAddFromLibrary)),Me=async t=>{if(!e.onAssetUpload||!e.onAssetFetchUrl||!t.ref||!t.url)return;let n=new Set(N8(M,E).map(e=>e.ref)),r=P8(t.ref,n),i=await e.onAssetFetchUrl(t.url),a=/\.[^./\\]+$/.exec(i.name)?.[0]??``,o=new File([i],`${r}${a}`,{type:i.type}),s={...await e.onAssetUpload(o),ref:r,name:`${t.name} (copy)`,source:t.source};await e.onAssetUpdate?.(s),D(s),_(s.kind,r)},Ne=async(t,n,r)=>{if(r)n.ref&&t.ref&&Pe(t.kind,t.ref,n.ref),D(n);else{let r={...n,ref:t.ref,name:t.name,source:t.source};await e.onAssetUpdate?.(r),O(r)}e.onAssetRemove?.(t),A(t)},Pe=(e,t,n)=>{if(t!==n)for(let r of M){let i=o8(r.content,e,t,n);i!==r.content&&be(r.xmlId,i,r.sourceFormat)}},Fe=(e,t)=>{for(let n of M){let r=s8(n.content,e,t);r!==n.content&&be(n.xmlId,r,n.sourceFormat)}};(0,n.useEffect)(()=>{let e=()=>o(window.innerWidth<800);return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[o]);let Ie=ve!==`pretext`;(0,n.useLayoutEffect)(()=>{r({selectDivision:R,addDivision:e=>Oe(e),removeDivision:e=>L(e),updateDivision:(e,t)=>Se(e,t),divisionContentChange:(e,t)=>{be(e,t,M.find(t=>t.xmlId===e)?.sourceFormat??`pretext`)},handleDivisionContentChange:Ee,assetInsert:ke,assetRemove:z,assetRefRemove:Fe,assetDuplicate:Ae?Me:void 0,insertContentAtCursor:e=>he.current?.insertAtCursor(e),updateTitle:t=>{de(t),e.onTitleChange?.(t)},feedbackSubmit:e.onFeedbackSubmit})}),(0,n.useEffect)(()=>{T({source:ye,sourceFormat:ve,libraryAssets:e.libraryAssets,projectType:e.projectType,projectUrl:e.projectUrl,rootDivisionId:I?.xmlId,canConvertToPretext:Te!==void 0,activeEditorSource:ye,hasFeedback:e.onFeedbackSubmit!==void 0,hasAssetDuplicate:Ae})});let Le=(0,n.useRef)({divisions:e.divisions,projectAssets:e.projectAssets,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,activeDivisionId:e.activeDivisionId});(0,n.useEffect)(()=>{let t=Le.current,n={},r=!1;if(e.projectAssets!==void 0&&e.projectAssets!==t.projectAssets&&(n.projectAssets=e.projectAssets,r=!0),e.divisions!==t.divisions){let t=s5(e.divisions,e.rootDivisionId),i=M8(e.divisions,t?.xmlId,e.projectType,e.title);n.divisions=i;let a=i.find(e=>e.xmlId===t?.xmlId)??t;(te==null||!e.divisions.some(e=>e.xmlId===te))&&(n.activeDivisionId=a?.xmlId??null),!e.title&&a?.title&&(n.title=a.title),r=!0}e.title!==void 0&&e.title!==t.title&&(n.title=e.title,r=!0),e.docinfo!==void 0&&e.docinfo!==t.docinfo&&(n.docinfo=e.docinfo,r=!0),e.commonDocinfo!==void 0&&e.commonDocinfo!==t.commonDocinfo&&(n.commonDocinfo=e.commonDocinfo,r=!0),e.useCommonDocinfo!==void 0&&e.useCommonDocinfo!==t.useCommonDocinfo&&(n.useCommonDocinfo=e.useCommonDocinfo,r=!0),e.activeDivisionId!==void 0&&e.activeDivisionId!==t.activeDivisionId&&(n.activeDivisionId=e.activeDivisionId,r=!0),r&&ae(n),Le.current={divisions:e.divisions,projectAssets:e.projectAssets,title:e.title,docinfo:e.docinfo,commonDocinfo:e.commonDocinfo,useCommonDocinfo:e.useCommonDocinfo,activeDivisionId:e.activeDivisionId}});let Re=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(Re.current===e.divisions)return;Re.current=e.divisions;let t=s5(e.divisions,e.rootDivisionId),n=M8(e.divisions,t?.xmlId,e.projectType,e.title);for(let t of n){if(t.sourceFormat!==`pretext`)continue;let n=e.divisions.find(e=>e.xmlId===t.xmlId);!n||t.content===n.content||e.onContentChange({xmlId:t.xmlId,sourceContent:t.content,sourceFormat:`pretext`,pretextSource:t.content})}});let ze=ie?re:N,Be=(0,n.useMemo)(()=>{if(!h||!I)return``;try{return O8(M,I.xmlId,ze,E??[])}catch(e){return`<!-- Unable to assemble document source: ${e instanceof Error?e.message:String(e)} -->`}},[h,I,M,ze,E]),Ve=_e?ve===`pretext`?E8(M,_e.xmlId,E):Te:void 0,He=_e&&Ve!==void 0?A8(_e.type,Ve,ze,_e.title):void 0,Ue=()=>me.current?.rebuild(),B=()=>{e.onSave?.(),me.current?.rebuild()},We=t=>{let n=t.ctrlKey||t.metaKey;n&&t.key===`Enter`&&e.onPreviewRebuild?(t.preventDefault(),Ue()):n&&t.key===`s`&&(t.preventDefault(),B())},Ge=()=>{if(!_e||!Te)return;let e=S6(),t={id:e.xmlId,xmlId:_e.xmlId,title:_e.title,type:_e.type,sourceFormat:ve,content:_e.content};Ce(ve===`markdown`?Q6(t,{xmlId:e.xmlId}):F6(t,{xmlId:e.xmlId})),be(_e.xmlId,g8(Te),`pretext`),xe(_e.xmlId,{sourceFormat:`pretext`})},Ke=(0,t.jsx)(Ws,{ref:he,content:ye,sourceFormat:ve,onChange:Ee,onRebuild:e.onPreviewRebuild?Ue:void 0,onSave:B,onOpenLatexImport:()=>C(`isLatexDialogOpen`),onOpenDocinfoEditor:()=>C(`isDocinfoEditorOpen`),onOpenConvertToPretext:Ie&&Te!==void 0?()=>C(`isConvertDialogOpen`):void 0,canConvertToPretext:Te!==void 0,onOpenAssets:e.projectAssets!==void 0&&ve===`pretext`?()=>C(`isAssetPickerOpen`):void 0,onShowFullSource:()=>C(`isFullSourceOpen`),onRequestWrapperEdit:De}),V;V=i&&e.onPreviewRebuild?(0,t.jsx)(lR,{ref:me,content:He||``,title:ne,onRebuild:e.onPreviewRebuild}):(0,t.jsx)(oR,{content:ye,canEdit:ve===`pretext`,editDisabledReason:ve===`markdown`?`Visual editing is not available for Markdown documents.`:ve===`latex`?`Visual editing is not available for LaTeX documents.`:``,onChange:e=>Ee(e)});let qe=(0,t.jsx)(n5,{isCollapsed:l,onToggleCollapse:()=>u(e=>!e),onOpenAssetPicker:e.projectAssets===void 0?void 0:()=>C(`isAssetPickerOpen`)}),Je=`pretext-plus-tab-editor`,Ye=`pretext-plus-tab-preview`,Xe=`pretext-plus-tabpanel`,Ze;return Ze=a?(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tabs`,children:[qe,(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tabs-main`,children:[(0,t.jsxs)(`div`,{className:`pretext-plus-editor__tab-list`,role:`tablist`,children:[(0,t.jsx)(`button`,{type:`button`,id:Je,role:`tab`,"aria-controls":Xe,"aria-selected":s===`editor`,tabIndex:s===`editor`?0:-1,className:`pretext-plus-editor__tab-button ${s===`editor`?`is-active`:``}`,onClick:()=>c(`editor`),children:`Editor`}),(0,t.jsx)(`button`,{type:`button`,id:Ye,role:`tab`,"aria-controls":Xe,"aria-selected":s===`preview`,tabIndex:s===`preview`?0:-1,className:`pretext-plus-editor__tab-button ${s===`preview`?`is-active`:``}`,onClick:()=>c(`preview`),children:`Preview`})]}),(0,t.jsx)(`div`,{id:Xe,className:`pretext-plus-editor__tab-panel`,role:`tabpanel`,"aria-labelledby":s===`editor`?Je:Ye,children:(0,t.jsx)(`div`,{style:{height:`100%`},children:s===`editor`?Ke:V})})]})]}):(0,t.jsxs)(`div`,{className:`pretext-plus-editor__sectioned-layout`,children:[qe,(0,t.jsxs)(gt,{orientation:`horizontal`,className:`pretext-plus-editor__splitter`,children:[(0,t.jsx)(yt,{className:`pretext-plus-editor__editor-panel`,children:Ke}),(0,t.jsx)(St,{className:`pretext-plus-editor__resize-handle`,children:(0,t.jsx)(`div`,{className:`pretext-plus-editor__resize-dots`})}),(0,t.jsx)(yt,{className:`pretext-plus-editor__preview-panel`,children:V})]})]}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor`,onKeyDown:We,children:[(0,t.jsx)(U8,{onSaveButton:e.onSaveButton,saveButtonLabel:e.saveButtonLabel,onCancelButton:e.onCancelButton,cancelButtonLabel:e.cancelButtonLabel,showPreviewModeToggle:e.onPreviewRebuild!==void 0}),(0,t.jsxs)(`div`,{className:`pretext-plus-editor__editor-displays`,children:[(0,t.jsx)(r5,{resetKeys:[ye,te],children:Ze}),d?(0,t.jsx)(D3,{onClose:()=>w(`isLatexDialogOpen`)}):null,f&&_e&&Te?(0,t.jsx)(j3,{sourceContent:ye,sourceFormat:ve,pretextSource:Te,onConfirm:Ge,onClose:()=>w(`isConvertDialogOpen`)}):null,p?(0,t.jsx)(U3,{docinfo:N,showCommonDocinfoControls:!0,commonDocinfo:re,initialUseCommonDocinfo:ie,onClose:t=>{if(w(`isDocinfoEditorOpen`),t!==void 0){F({docinfo:t.docinfo,commonDocinfo:t.commonDocinfo,useCommonDocinfo:t.useCommonDocinfo}),e.onCommonDocinfoChange?.(t.commonDocinfo),e.onUseCommonDocinfoChange?.(t.useCommonDocinfo);let n=I??_e;be(n?.xmlId??``,n?.content??``,n?.sourceFormat??`pretext`,{docinfo:t.docinfo,commonDocinfo:t.commonDocinfo,useCommonDocinfo:t.useCommonDocinfo})}}}):null,(m||y||x)&&e.projectAssets!==void 0?(0,t.jsx)(R8,{open:m||!!y||!!x,resolveTarget:y,replaceTarget:x,onClose:()=>{w(`isAssetPickerOpen`),b(),S(null)},onLoadAssets:e.onLoadAssets,onLoadLibraryAssets:e.onLoadLibraryAssets,onAddFromLibrary:e.onAssetAddFromLibrary,onUpload:e.onAssetUpload,onFetchUrl:e.onAssetFetchUrl,onCreateDoenet:e.onCreateDoenet,onRemoveAsset:e.onAssetRemove?z:void 0,onDuplicateAsset:Ae?Me:void 0,onAssetAdded:ke,onResolveRef:Pe,onReplaceAsset:Ne}):null,h?(0,t.jsx)(G3,{source:Be,onClose:()=>w(`isFullSourceOpen`)}):null,j?(0,t.jsx)(H8,{asset:j,projectAssets:E??[],onClose:v,onReplace:je?e=>{v(),S(e)}:void 0,onDuplicate:Ae?e=>Me(e):void 0,onSave:async(t,n)=>{t.ref&&t.ref!==n?(Pe(t.kind,n,t.ref),k(t.kind,n,t)):O(t),await e.onAssetUpdate?.(t)}},`${j.kind}:${j.ref}`):null]})]})};e.CodeEditor=Ws,e.DocinfoEditor=U3,e.Editors=c5,e.FeedbackLink=y3,e.FullPreview=lR,e.VisualEditor=oR,e.assembleFullProjectSource=O8,e.assembleProjectSource=E8,e.buildDivisionTree=y8,e.convertLatexToPretext=m3,e.createConclusion=w6,e.createIntroduction=C6,e.createLatexConclusion=z6,e.createLatexIntroduction=R6,e.createNewLatexSection=L6,e.createNewSection=S6,e.derivePretextContent=_3,e.detectSourceFormat=p3,e.ensureLatexSectionWrapper=A6,e.ensureSectionWrapper=D6,e.extractDivisionMetadata=W6,e.extractLatexDivisionTitle=N6,e.findDivisionParent=m8,e.getOrphanRoots=b8,e.getOrphanedDivisions=v8,e.getSectionAttributes=V6,e.insertDivisionRef=u8,e.mergeTwoSections=B6,e.moveDivisionRef=f8,e.normalizeSelfClosingRefs=g8,e.parseDivisionRefs=r8,e.postToIframe=cR,e.removeDivisionRef=d8,e.renameDivisionRef=p8,e.reorderDivisionRefs=h8,e.rewrapLatexSection=k6,e.rewrapSection=E6,e.stripLatexSectionWrapper=O6,e.stripSectionWrapper=T6,e.updateDivisionTitle=x6,e.updateLatexSectionTitle=M6,e.updateSectionMetadata=G6,e.wrapDivisionForPreview=A8});
|
|
1093
1093
|
//# sourceMappingURL=index.js.map
|