@pretextbook/import 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),P=require("./import-mode-Bu7Pi9k4.cjs");var ie={exports:{}},se={};var ue;function he(){if(ue)return se;ue=1;var l=Symbol.for("react.transitional.element"),x=Symbol.for("react.fragment");function h(j,b,c){var v=null;if(c!==void 0&&(v=""+c),b.key!==void 0&&(v=""+b.key),"key"in b){c={};for(var N in b)N!=="key"&&(c[N]=b[N])}else c=b;return b=c.ref,{$$typeof:l,type:j,key:v,ref:b!==void 0?b:null,props:c}}return se.Fragment=x,se.jsx=h,se.jsxs=h,se}var re={};var me;function be(){return me||(me=1,process.env.NODE_ENV!=="production"&&(function(){function l(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===X?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case D:return"Fragment";case q:return"Profiler";case R:return"StrictMode";case ae:return"Suspense";case de:return"SuspenseList";case ne:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case C:return"Portal";case T:return t.displayName||"Context";case u:return(t._context.displayName||"Context")+".Consumer";case F:var r=t.render;return t=t.displayName,t||(t=r.displayName||r.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case H:return r=t.displayName||null,r!==null?r:l(t.type)||"Memo";case V:r=t._payload,t=t._init;try{return l(t(r))}catch{}}return null}function x(t){return""+t}function h(t){try{x(t);var r=!1}catch{r=!0}if(r){r=console;var m=r.error,g=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return m.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",g),x(t)}}function j(t){if(t===D)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===V)return"<...>";try{var r=l(t);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function b(){var t=G.A;return t===null?null:t.getOwner()}function c(){return Error("react-stack-top-frame")}function v(t){if(Z.call(t,"key")){var r=Object.getOwnPropertyDescriptor(t,"key").get;if(r&&r.isReactWarning)return!1}return t.key!==void 0}function N(t,r){function m(){M||(M=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}m.isReactWarning=!0,Object.defineProperty(t,"key",{get:m,configurable:!0})}function p(){var t=l(this.type);return A[t]||(A[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function L(t,r,m,g,B,W){var f=m.ref;return t={$$typeof:k,type:t,key:r,props:m,_owner:g},(f!==void 0?f:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:p}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:B}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:W}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function S(t,r,m,g,B,W){var f=r.children;if(f!==void 0)if(g)if(Q(f)){for(g=0;g<f.length;g++)_(f[g]);Object.freeze&&Object.freeze(f)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else _(f);if(Z.call(r,"key")){f=l(t);var O=Object.keys(r).filter(function(s){return s!=="key"});g=0<O.length?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}",Y[f+g]||(O=0<O.length?"{"+O.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),F=require("./upload-CGxfSSDN.cjs"),me=require("./import-mode-YW6Lr4SU.cjs");var de={exports:{}},re={};var he;function Se(){if(he)return re;he=1;var r=Symbol.for("react.transitional.element"),u=Symbol.for("react.fragment");function p(b,g,i){var v=null;if(i!==void 0&&(v=""+i),g.key!==void 0&&(v=""+g.key),"key"in g){i={};for(var N in g)N!=="key"&&(i[N]=g[N])}else i=g;return g=i.ref,{$$typeof:r,type:b,key:v,ref:g!==void 0?g:null,props:i}}return re.Fragment=u,re.jsx=p,re.jsxs=p,re}var ae={};var be;function we(){return be||(be=1,process.env.NODE_ENV!=="production"&&(function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===Y?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case I:return"Fragment";case W:return"Profiler";case P:return"StrictMode";case ne:return"Suspense";case ue:return"SuspenseList";case le:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case A:return"Portal";case E:return t.displayName||"Context";case f:return(t._context.displayName||"Context")+".Consumer";case O:var a=t.render;return t=t.displayName,t||(t=a.displayName||a.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Z:return a=t.displayName||null,a!==null?a:r(t.type)||"Memo";case U:a=t._payload,t=t._init;try{return r(t(a))}catch{}}return null}function u(t){return""+t}function p(t){try{u(t);var a=!1}catch{a=!0}if(a){a=console;var x=a.error,m=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return x.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",m),u(t)}}function b(t){if(t===I)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===U)return"<...>";try{var a=r(t);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function g(){var t=K.A;return t===null?null:t.getOwner()}function i(){return Error("react-stack-top-frame")}function v(t){if(Q.call(t,"key")){var a=Object.getOwnPropertyDescriptor(t,"key").get;if(a&&a.isReactWarning)return!1}return t.key!==void 0}function N(t,a){function x(){D||(D=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",a))}x.isReactWarning=!0,Object.defineProperty(t,"key",{get:x,configurable:!0})}function h(){var t=r(this.type);return V[t]||(V[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function _(t,a,x,m,$,G){var j=x.ref;return t={$$typeof:k,type:t,key:a,props:x,_owner:m},(j!==void 0?j:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:h}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:$}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function S(t,a,x,m,$,G){var j=a.children;if(j!==void 0)if(m)if(ee(j)){for(m=0;m<j.length;m++)C(j[m]);Object.freeze&&Object.freeze(j)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else C(j);if(Q.call(a,"key")){j=r(t);var X=Object.keys(a).filter(function(se){return se!=="key"});m=0<X.length?"{key: someKey, "+X.join(": ..., ")+": ...}":"{key: someKey}",R[j+m]||(X=0<X.length?"{"+X.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
2
  let props = %s;
3
3
  <%s {...props} />
4
4
  React keys must be passed directly to JSX without using spread:
5
5
  let props = %s;
6
- <%s key={someKey} {...props} />`,g,f,O,f),Y[f+g]=!0)}if(f=null,m!==void 0&&(h(m),f=""+m),v(r)&&(h(r.key),f=""+r.key),"key"in r){m={};for(var te in r)te!=="key"&&(m[te]=r[te])}else m=r;return f&&N(m,typeof t=="function"?t.displayName||t.name||"Unknown":t),L(t,f,m,b(),B,W)}function _(t){I(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===V&&(t._payload.status==="fulfilled"?I(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function I(t){return typeof t=="object"&&t!==null&&t.$$typeof===k}var E=d,k=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),D=Symbol.for("react.fragment"),R=Symbol.for("react.strict_mode"),q=Symbol.for("react.profiler"),u=Symbol.for("react.consumer"),T=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),ae=Symbol.for("react.suspense"),de=Symbol.for("react.suspense_list"),H=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),ne=Symbol.for("react.activity"),X=Symbol.for("react.client.reference"),G=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Z=Object.prototype.hasOwnProperty,Q=Array.isArray,z=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(t){return t()}};var M,A={},ee=E.react_stack_bottom_frame.bind(E,c)(),U=z(j(c)),Y={};re.Fragment=D,re.jsx=function(t,r,m){var g=1e4>G.recentlyCreatedOwnerStacks++;return S(t,r,m,!1,g?Error("react-stack-top-frame"):ee,g?z(j(t)):U)},re.jsxs=function(t,r,m){var g=1e4>G.recentlyCreatedOwnerStacks++;return S(t,r,m,!0,g?Error("react-stack-top-frame"):ee,g?z(j(t)):U)}})()),re}var xe;function ge(){return xe||(xe=1,process.env.NODE_ENV==="production"?ie.exports=he():ie.exports=be()),ie.exports}var e=ge();const fe=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],je={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:fe,convertFile:P.handleImportUploadFile,prepare:async l=>{const{files:x,assets:h}=await P.extractUpload(l);return{fileName:l.name,files:x,assets:h,analysis:P.analyzeImportSources(x)}},convertPrepared:(l,x)=>P.importProjectFromFiles(l.files,{...x,assets:l.assets})},pe={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function ve(l){const x=l.reason==="manifest-target"?`project.ptx target “${l.targetName}”`:l.reason==="latex-root"?"LaTeX document":l.reason==="pretext-root"?"PreTeXt document":l.reason==="markdown-root"?"Markdown document":"possible document";return l.title?`${l.title} — ${x}`:x}function Ne(l){return l.candidates.filter(h=>h.reason==="manifest-target").length>1?!0:l.manifest&&l.primary?.reason==="manifest-target"?!1:l.formats.length>1||l.candidates.length>1||l.extraRoots.length>0}function ye({onConfirm:l,onCancel:x,importOptions:h,defaultDocumentKind:j="auto",engines:b}){const c=b&&b.length>0?b:[je],v=d.useRef(null),[N,p]=d.useState({name:"upload"}),[L,S]=d.useState(!1),[_,I]=d.useState(j),[E,k]=d.useState(null),[C,D]=d.useState(new Set),[R,q]=d.useState(c[0].id),[u,T]=d.useState("converted"),[F,ae]=d.useState(!1),[de,H]=d.useState(new Set),[V,ne]=d.useState(null),[X,G]=d.useState("auto"),[Z,Q]=d.useState(null),[z,M]=d.useState({}),A=c.find(s=>s.id===R)??c[0],ee=A.acceptExtensions??fe,U=N.name==="review"?N.result:null,Y=d.useMemo(()=>U&&E!==null?P.relayoutImport(U,E):U,[U,E]),t=d.useMemo(()=>new Map(Y?P.fileChangesForImport(Y).map(s=>[s.path,s]):[]),[Y]),r=()=>h??{documentKind:_==="auto"?void 0:_},m=s=>P.analyzeImportSources(s.files,{sourceFormat:X==="auto"?void 0:X,mainFile:Z??void 0}),g=s=>{p({name:"processing"});try{const n=m(s).extraRoots.map(i=>({path:i.path,include:z[i.path]?.include??!0,level:z[i.path]?.level})),y=A.convertPrepared(s,{...r(),sourceFormat:X==="auto"?void 0:X,mainFile:Z??void 0,attachRoots:n});"pretextError"in y?p({name:"error",message:y.pretextError}):p({name:"review",result:y})}catch(o){p({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},B=async s=>{p({name:"processing"});try{if(A.prepare&&A.convertPrepared){const n=await A.prepare(s);if(ne(n),G("auto"),Q(null),M({}),Ne(n.analysis)){p({name:"sources",prepared:n});return}const y=A.convertPrepared(n,r());p("pretextError"in y?{name:"error",message:y.pretextError}:{name:"review",result:y});return}const o=await A.convertFile(s,r());"pretextError"in o?p({name:"error",message:o.pretextError}):p({name:"review",result:o})}catch(o){p({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},W=()=>{p({name:"upload"}),T("converted"),ae(!1),H(new Set),D(new Set),k(null),ne(null)};function f(s,o){return[...s].sort((n,y)=>n===o?-1:y===o?1:n.localeCompare(y))}function O(s,o){const n=P.filesForImportMode(s,o),y=o==="converted"?s.projectLayout.mainSourcePath:s.sourcePath,i=f(Object.keys(n),y)[0];H(i?new Set([i]):new Set)}function te(s){H(o=>{const n=new Set(o);return n.has(s)?n.delete(s):n.add(s),n})}if(N.name==="processing")return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16 text-slate-600",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-700 border-t-transparent"}),e.jsx("p",{className:"text-sm",children:"Processing your file…"})]});if(N.name==="error")return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800",children:[e.jsx("p",{className:"font-semibold",children:"Import failed"}),e.jsx("p",{className:"mt-1",children:N.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:W,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(N.name==="sources"){const s=N.prepared,o=m(s),n=o.manifest,y=o.primary?.path??"";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:"Choose what to import"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[s.fileName," contains more than one possible starting point."]})]}),n?e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm text-blue-900",children:[e.jsxs("p",{className:"font-medium",children:["Found ",n.manifestPath," — an existing PreTeXt project."]}),e.jsxs("p",{className:"mt-1 text-blue-800",children:["Its publication file, assets, and directory layout will be kept as they are. Targets:"," ",n.targets.map(i=>i.name).join(", "),"."]})]}):null,e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Source format"}),e.jsxs("select",{value:X,onChange:i=>{G(i.currentTarget.value),Q(null),M({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",o.primary?` (${pe[o.primary.format]})`:""]}),o.formats.map(i=>e.jsx("option",{value:i,children:pe[i]},i))]})]})}),o.candidates.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Main document"}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:o.candidates.map(i=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:i.path,checked:y===i.path,onChange:()=>{Q(i.path),M({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:i.path}),e.jsx("span",{className:"block text-slate-500",children:ve(i)})]})]},i.path))})]}):null,o.extraRoots.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Other documents"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"These files also stand on their own. Attach them to the main document, or leave them out."}),e.jsx("div",{className:"mt-3 flex flex-col gap-2",children:o.extraRoots.map(i=>{const J=z[i.path],le=J?.include??!0;return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm",children:[e.jsxs("label",{className:"flex flex-1 cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:le,onChange:$=>M(K=>({...K,[i.path]:{...K[i.path],include:$.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:i.path}),i.title?e.jsxs("span",{className:"text-slate-500",children:["— ",i.title]}):null]}),e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Attach as"}),e.jsxs("select",{value:J?.level??"auto",disabled:!le,onChange:$=>M(K=>({...K,[i.path]:{include:K[i.path]?.include??!0,level:$.currentTarget.value==="auto"?void 0:$.currentTarget.value}})),className:"rounded border border-slate-300 px-2 py-1 text-sm disabled:opacity-50",children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"chapter",children:"Chapter"}),e.jsx("option",{value:"section",children:"Section"})]})]})]},i.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:W,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>g(s),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(N.name==="review"){let s=function(a){T(a),F&&O(n,a)},o=function(a){D(w=>{const ce=new Set(w);return ce.has(a)?ce.delete(a):ce.add(a),ce})};const n=Y??N.result,y=n.splitLevel,i=n.detectedSourceFormat==="latex",J=n.warnings.length,le=Object.keys(n.outputFiles).length,$=P.filesForImportMode(n,u),K=u==="converted"?n.projectLayout.mainSourcePath:n.sourcePath,oe=f(Object.keys($),K);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-slate-700",children:"Import Summary"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsx("dt",{className:"text-slate-500",children:"Source"}),e.jsx("dd",{className:"font-medium text-slate-900",children:n.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:n.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:n.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:le}),n.projectLayout.preserved?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Existing project"}),e.jsx("dd",{className:"font-medium text-slate-900",children:"Kept publication file, assets, and layout"})]}):null,n.attachedRoots.length>0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Attached"}),e.jsx("dd",{className:"font-medium text-slate-900",children:n.attachedRoots.map(a=>`${a.title} (${a.level})`).join(", ")})]}):null]})]}),J>0?e.jsxs("details",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-amber-800",children:[J," conversion"," ",J===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:n.warnings.map((a,w)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:a.macro})," — ",a.action==="replace"||a.action==="rewrite"?`replaced with \`${a.replacement}\``:a.message??a.action,a.occurrences>1?` (×${a.occurrences})`:null]},w))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),i?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Import mode"}),e.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"converted",checked:u==="converted",onChange:()=>s("converted"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Convert to PreTeXt"}),e.jsx("span",{className:"block text-slate-500",children:"Use the converted PreTeXt output. Recommended for new PreTeXt projects."})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"native",checked:u==="native",onChange:()=>s("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Keep as LaTeX"}),e.jsx("span",{className:"block text-slate-500",children:"Preserve the original LaTeX source. The conversion will not be applied."})]})]})]})]}):null,!h&&n.cleanChunks.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Split into files"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Array.from({length:P.MAX_SUGGESTED_SPLIT_LEVEL+1},(a,w)=>e.jsx("button",{type:"button",onClick:()=>k(w),"aria-pressed":y===w,className:y===w?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:w===0?"One file":`${w} level${w===1?"":"s"}`},w)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[oe.length," file",oe.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:oe.map(a=>e.jsxs("li",{className:"truncate py-0.5",children:[a,t.get(a)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[t.get(a).fixCount," change",t.get(a).fixCount===1?"":"s"]}):null]},a))})]}):null,F?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:oe.map(a=>{const w=de.has(a);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>te(a),className:"flex w-full items-center gap-2 bg-slate-100 px-4 py-2 text-left font-mono text-xs text-slate-700 hover:bg-slate-200",children:[e.jsx("span",{className:"shrink-0 text-slate-400",children:w?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:a}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[($[a].length/1024).toFixed(1)," KB"]})]}),w?e.jsxs("div",{className:"bg-white",children:[t.get(a)?.hunks.length?e.jsxs("div",{className:"flex gap-2 border-b border-slate-200 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>o(a),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:C.has(a)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",t.get(a).stats.added," −",t.get(a).stats.removed," in the LaTeX source"]})]}):null,C.has(a)&&t.has(a)?e.jsx(Se,{hunks:t.get(a).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:$[a]})]}):null]},a)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:x??W,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:x?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[V?e.jsx("button",{type:"button",onClick:()=>p({name:"sources",prepared:V}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{F||O(n,u),ae(a=>!a)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:F?"Hide Preview":"Preview"}),e.jsx("button",{type:"button",onClick:()=>l(n,u),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Confirm Import"})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[c.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Converter"}),e.jsx("div",{className:"mt-2 flex flex-col gap-3",children:c.map(s=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-engine",value:s.id,checked:R===s.id,onChange:()=>q(s.id),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:s.label}),s.description?e.jsx("span",{className:"block text-slate-500",children:s.description}):null]})]},s.id))})]}):null,h?null:e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Document kind"}),e.jsxs("select",{value:_,onChange:s=>I(s.currentTarget.value),className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&v.current?.click(),onClick:()=>v.current?.click(),onDragOver:s=>{s.preventDefault(),S(!0)},onDragLeave:()=>S(!1),onDrop:s=>{s.preventDefault(),S(!1);const o=s.dataTransfer.files?.[0];o&&B(o)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${L?"border-blue-500 bg-blue-50":"border-slate-300 bg-slate-50 hover:border-slate-400"}`,children:[e.jsx("p",{className:"text-slate-600",children:"Drop a file here, or click to select."}),e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),v.current?.click()},className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Select File"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Supports ",ee.join(", ")]}),e.jsx("input",{ref:v,type:"file",hidden:!0,accept:ee.join(","),onChange:s=>{const o=s.currentTarget.files?.[0];o&&B(o),s.currentTarget.value=""}})]})]})}function Se({hunks:l}){return l.length===0?e.jsx("p",{className:"m-0 px-4 py-3 text-xs text-slate-500",children:"Nothing was changed in this file."}):e.jsx("div",{className:"max-h-72 overflow-auto bg-white font-mono text-xs leading-relaxed",children:l.map((x,h)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[h>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,x.lines.map((j,b)=>e.jsxs("div",{className:j.op==="add"?"bg-green-50 px-4 text-green-900":j.op==="remove"?"bg-red-50 px-4 text-red-900":"px-4 text-slate-600",children:[e.jsx("span",{className:"mr-2 select-none text-slate-400",children:j.op==="add"?"+":j.op==="remove"?"−":" "}),j.text||" "]},b))]},h))})}const Ee={title:"Import Source Content",description:"Paste LaTeX, Markdown, or PreTeXt source to convert into PreTeXt.",sourceLabel:"Source",sourcePlaceholder:"Paste source content here...",formatLabel:"Source format",convertButton:"Convert to PreTeXt",detectedFormatPrefix:"Detected",successPrefix:"Ready",errorPrefix:"Error"};function Te({initialSource:l="",initialSourceFormat:x,labels:h,disabled:j=!1,onImport:b}){const c=d.useMemo(()=>({...Ee,...h??{}}),[h]),[v,N]=d.useState(l),[p,L]=d.useState(x??"auto"),[S,_]=d.useState(null),I=d.useMemo(()=>P.detectSourceFormat(v),[v]),E=j||!v.trim();return e.jsx("form",{onSubmit:k=>{k.preventDefault();const C=P.convertSourceToPretext(v,p==="auto"?void 0:p);_(C),b(C)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:j,children:[e.jsx("legend",{children:c.title}),e.jsx("p",{children:c.description}),e.jsxs("label",{children:[c.sourceLabel,e.jsx("textarea",{value:v,onChange:k=>N(k.currentTarget.value),placeholder:c.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[c.formatLabel,e.jsxs("select",{value:p,onChange:k=>L(k.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"latex",children:"LaTeX"}),e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"pretext",children:"PreTeXt"})]})]}),e.jsxs("p",{children:[c.detectedFormatPrefix,": ",e.jsx("strong",{children:I})]}),e.jsx("button",{type:"submit",disabled:E,children:c.convertButton}),S?"pretextError"in S?e.jsxs("p",{role:"alert",children:[c.errorPrefix,": ",S.pretextError]}):e.jsxs("p",{children:[c.successPrefix,": ",S.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const we={title:"Upload Source File",hint:"Supports .tex, .md, .ptx, .xml, .zip, and .tar.gz files.",selectButton:"Select File",dropHint:"Drop a file here, or click Select File.",documentKindLabel:"Document kind",splitSectionsLabel:"Split each chapter into sections"};function ke({labels:l,disabled:x=!1,defaultDocumentKind:h="auto",importOptions:j,onImport:b}){const c=d.useMemo(()=>({...we,...l??{}}),[l]),v=d.useRef(null),[N,p]=d.useState(!1),[L,S]=d.useState(!1),[_,I]=d.useState([]),[E,k]=d.useState(h),[C,D]=d.useState(!1),R=x||L,q=async u=>{S(!0);try{const T=j??{documentKind:E==="auto"?void 0:E,splitSections:C},F=await P.handleImportUploadFile(u,T);I(F.statusMessages),b(F)}finally{S(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:c.title}),e.jsx("p",{children:c.hint}),j?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[c.documentKindLabel,e.jsxs("select",{value:E,disabled:R,onChange:u=>k(u.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]}),e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:C,disabled:R,onChange:u=>D(u.currentTarget.checked)}),c.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:u=>{u.preventDefault(),R||p(!0)},onDragLeave:()=>p(!1),onDrop:u=>{if(u.preventDefault(),p(!1),R)return;const T=u.dataTransfer.files?.[0];T&&q(T)},children:[e.jsx("p",{children:c.dropHint}),e.jsx("button",{type:"button",disabled:R,onClick:()=>v.current?.click(),children:L?"Processing...":c.selectButton}),e.jsx("input",{ref:v,type:"file",hidden:!0,disabled:R,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:u=>{const T=u.currentTarget.files?.[0];T&&q(T),u.currentTarget.value=""}})]}),_.length>0?e.jsx("ul",{"aria-live":"polite",children:_.map((u,T)=>e.jsx("li",{children:u.message},`${u.type}-${T}`))}):null,N&&!R?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=Te;exports.ImportUploadPanel=ke;exports.ImportWizard=ye;
6
+ <%s key={someKey} {...props} />`,m,j,X,j),R[j+m]=!0)}if(j=null,x!==void 0&&(p(x),j=""+x),v(a)&&(p(a.key),j=""+a.key),"key"in a){x={};for(var J in a)J!=="key"&&(x[J]=a[J])}else x=a;return j&&N(x,typeof t=="function"?t.displayName||t.name||"Unknown":t),_(t,j,x,g(),$,G)}function C(t){L(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===U&&(t._payload.status==="fulfilled"?L(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function L(t){return typeof t=="object"&&t!==null&&t.$$typeof===k}var w=c,k=Symbol.for("react.transitional.element"),A=Symbol.for("react.portal"),I=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),W=Symbol.for("react.profiler"),f=Symbol.for("react.consumer"),E=Symbol.for("react.context"),O=Symbol.for("react.forward_ref"),ne=Symbol.for("react.suspense"),ue=Symbol.for("react.suspense_list"),Z=Symbol.for("react.memo"),U=Symbol.for("react.lazy"),le=Symbol.for("react.activity"),Y=Symbol.for("react.client.reference"),K=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Q=Object.prototype.hasOwnProperty,ee=Array.isArray,B=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(t){return t()}};var D,V={},te=w.react_stack_bottom_frame.bind(w,i)(),M=B(b(i)),R={};ae.Fragment=I,ae.jsx=function(t,a,x){var m=1e4>K.recentlyCreatedOwnerStacks++;return S(t,a,x,!1,m?Error("react-stack-top-frame"):te,m?B(b(t)):M)},ae.jsxs=function(t,a,x){var m=1e4>K.recentlyCreatedOwnerStacks++;return S(t,a,x,!0,m?Error("react-stack-top-frame"):te,m?B(b(t)):M)}})()),ae}var ge;function Ee(){return ge||(ge=1,process.env.NODE_ENV==="production"?de.exports=Se():de.exports=we()),de.exports}var e=Ee();function Te(){const[r,u]=c.useState(0),p=c.useRef(Date.now());return c.useEffect(()=>{const b=setInterval(()=>{u(Math.floor((Date.now()-p.current)/1e3))},1e3);return()=>clearInterval(b)},[]),r}function ke(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function ve({message:r="Processing your file…",onCancel:u}){const p=Te();return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16 text-slate-600",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-700 border-t-transparent"}),e.jsx("p",{className:"text-sm",children:r}),e.jsx("p",{className:"text-xs tabular-nums text-slate-500",children:ke(p)}),p>=10?e.jsx("p",{className:"max-w-xs text-center text-xs text-slate-500",children:"Large documents can take a while. You can keep working in other tabs."}):null,u?e.jsx("button",{type:"button",onClick:u,className:"mt-2 rounded border border-slate-300 px-3 py-1.5 text-xs font-medium text-slate-700 hover:bg-slate-50",children:"Cancel"}):null]})}const Ne=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],Pe={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:Ne,convertFile:F.handleImportUploadFile,prepare:async r=>{const{files:u,assets:p}=await F.extractUpload(r);return{fileName:r.name,files:u,assets:p,analysis:F.analyzeImportSources(u)}},convertPrepared:(r,u)=>F.importProjectFromFiles(r.files,{...u,assets:r.assets})};function xe(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const je={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function Re(r){const u=r.reason==="manifest-target"?`project.ptx target “${r.targetName}”`:r.reason==="latex-root"?"LaTeX document":r.reason==="pretext-root"?"PreTeXt document":r.reason==="markdown-root"?"Markdown document":"possible document";return r.title?`${r.title} — ${u}`:u}function Ce(r){return r.candidates.filter(p=>p.reason==="manifest-target").length>1?!0:r.manifest&&r.primary?.reason==="manifest-target"?!1:r.formats.length>1||r.candidates.length>1||r.extraRoots.length>0}function _e({onConfirm:r,onCancel:u,importOptions:p,defaultDocumentKind:b="auto",engines:g}){const i=g&&g.length>0?g:[Pe],v=c.useRef(null),[N,h]=c.useState({name:"upload"}),[_,S]=c.useState(!1),[C,L]=c.useState(b),[w,k]=c.useState(null),[A,I]=c.useState(new Set),[P,W]=c.useState(i[0].id),[f,E]=c.useState("converted"),[O,ne]=c.useState(!1),[ue,Z]=c.useState(new Set),[U,le]=c.useState(null),[Y,K]=c.useState("auto"),[Q,ee]=c.useState(null),[B,D]=c.useState({}),[V,te]=c.useState(!1),M=c.useRef(!1),R=i.find(s=>s.id===P)??i[0],t=R.acceptExtensions??Ne,a=N.name==="review"?N.result:null,x=c.useMemo(()=>a&&w!==null?F.relayoutImport(a,w):a,[a,w]),m=c.useMemo(()=>new Map(x?me.fileChangesForImport(x).map(s=>[s.path,s]):[]),[x]),$=()=>p??{documentKind:C==="auto"?void 0:C},G=s=>F.analyzeImportSources(s.files,{sourceFormat:Y==="auto"?void 0:Y,mainFile:Q??void 0}),j=s=>{M.current=!0,R.cancel?.(),h(s?{name:"sources",prepared:s}:{name:"upload"})},X=async s=>{M.current=!1,h({name:"processing"}),await xe();try{const l=G(s).extraRoots.map(d=>({path:d.path,include:B[d.path]?.include??!0,level:B[d.path]?.level})),y=await R.convertPrepared(s,{...$(),sourceFormat:Y==="auto"?void 0:Y,mainFile:Q??void 0,attachRoots:l});"pretextError"in y?h({name:"error",message:y.pretextError}):h({name:"review",result:y})}catch(o){if(M.current)return;h({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},J=async s=>{M.current=!1,h({name:"processing"}),await xe();try{if(R.prepare&&R.convertPrepared){const l=await R.prepare(s);if(le(l),K("auto"),ee(null),D({}),Ce(l.analysis)){h({name:"sources",prepared:l});return}await xe();const y=await R.convertPrepared(l,$());h("pretextError"in y?{name:"error",message:y.pretextError}:{name:"review",result:y});return}const o=await R.convertFile(s,$());"pretextError"in o?h({name:"error",message:o.pretextError}):h({name:"review",result:o})}catch(o){if(M.current)return;h({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},se=()=>{h({name:"upload"}),E("converted"),ne(!1),Z(new Set),I(new Set),k(null),le(null)};function pe(s,o){return[...s].sort((l,y)=>l===o?-1:y===o?1:l.localeCompare(y))}function fe(s,o){const l=me.filesForImportMode(s,o),y=o==="converted"?s.projectLayout.mainSourcePath:s.sourcePath,d=pe(Object.keys(l),y)[0];Z(d?new Set([d]):new Set)}function ye(s){Z(o=>{const l=new Set(o);return l.has(s)?l.delete(s):l.add(s),l})}if(N.name==="processing")return e.jsx(ve,{onCancel:R.cancel?()=>j(U):void 0});if(N.name==="error")return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800",children:[e.jsx("p",{className:"font-semibold",children:"Import failed"}),e.jsx("p",{className:"mt-1",children:N.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:se,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(N.name==="sources"){const s=N.prepared,o=G(s),l=o.manifest,y=o.primary?.path??"";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:"Choose what to import"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[s.fileName," contains more than one possible starting point."]})]}),l?e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm text-blue-900",children:[e.jsxs("p",{className:"font-medium",children:["Found ",l.manifestPath," — an existing PreTeXt project."]}),e.jsxs("p",{className:"mt-1 text-blue-800",children:["Its publication file, assets, and directory layout will be kept as they are. Targets:"," ",l.targets.map(d=>d.name).join(", "),"."]})]}):null,e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Source format"}),e.jsxs("select",{value:Y,onChange:d=>{K(d.currentTarget.value),ee(null),D({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",o.primary?` (${je[o.primary.format]})`:""]}),o.formats.map(d=>e.jsx("option",{value:d,children:je[d]},d))]})]})}),o.candidates.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Main document"}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:o.candidates.map(d=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:d.path,checked:y===d.path,onChange:()=>{ee(d.path),D({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:d.path}),e.jsx("span",{className:"block text-slate-500",children:Re(d)})]})]},d.path))})]}):null,o.extraRoots.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Other documents"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"These files also stand on their own. Attach them to the main document, or leave them out."}),e.jsx("div",{className:"mt-3 flex flex-col gap-2",children:o.extraRoots.map(d=>{const H=B[d.path],oe=H?.include??!0;return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm",children:[e.jsxs("label",{className:"flex flex-1 cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:oe,onChange:z=>D(q=>({...q,[d.path]:{...q[d.path],include:z.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:d.path}),d.title?e.jsxs("span",{className:"text-slate-500",children:["— ",d.title]}):null]}),e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Attach as"}),e.jsxs("select",{value:H?.level??"auto",disabled:!oe,onChange:z=>D(q=>({...q,[d.path]:{include:q[d.path]?.include??!0,level:z.currentTarget.value==="auto"?void 0:z.currentTarget.value}})),className:"rounded border border-slate-300 px-2 py-1 text-sm disabled:opacity-50",children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"chapter",children:"Chapter"}),e.jsx("option",{value:"section",children:"Section"})]})]})]},d.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:se,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>X(s),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(N.name==="review"){let s=function(n){E(n),O&&fe(l,n)},o=function(n){I(T=>{const ie=new Set(T);return ie.has(n)?ie.delete(n):ie.add(n),ie})};const l=x??N.result,y=l.splitLevel,d=l.detectedSourceFormat==="latex",H=l.warnings.length,oe=Object.keys(l.outputFiles).length,z=me.filesForImportMode(l,f),q=f==="converted"?l.projectLayout.mainSourcePath:l.sourcePath,ce=pe(Object.keys(z),q);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-slate-700",children:"Import Summary"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsx("dt",{className:"text-slate-500",children:"Source"}),e.jsx("dd",{className:"font-medium text-slate-900",children:l.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:l.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:l.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:oe}),l.projectLayout.preserved?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Existing project"}),e.jsx("dd",{className:"font-medium text-slate-900",children:"Kept publication file, assets, and layout"})]}):null,l.attachedRoots.length>0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Attached"}),e.jsx("dd",{className:"font-medium text-slate-900",children:l.attachedRoots.map(n=>`${n.title} (${n.level})`).join(", ")})]}):null]})]}),H>0?e.jsxs("details",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-amber-800",children:[H," conversion"," ",H===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:l.warnings.map((n,T)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:n.macro})," — ",n.action==="replace"||n.action==="rewrite"?`replaced with \`${n.replacement}\``:n.message??n.action,n.occurrences>1?` (×${n.occurrences})`:null]},T))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),d?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Import mode"}),e.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"converted",checked:f==="converted",onChange:()=>s("converted"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Convert to PreTeXt"}),e.jsx("span",{className:"block text-slate-500",children:"Use the converted PreTeXt output. Recommended for new PreTeXt projects."})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"native",checked:f==="native",onChange:()=>s("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Keep as LaTeX"}),e.jsx("span",{className:"block text-slate-500",children:"Preserve the original LaTeX source. The conversion will not be applied."})]})]})]})]}):null,!p&&l.cleanChunks.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Split into files"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Array.from({length:F.MAX_SUGGESTED_SPLIT_LEVEL+1},(n,T)=>e.jsx("button",{type:"button",onClick:()=>k(T),"aria-pressed":y===T,className:y===T?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:T===0?"One file":`${T} level${T===1?"":"s"}`},T)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[ce.length," file",ce.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:ce.map(n=>e.jsxs("li",{className:"truncate py-0.5",children:[n,m.get(n)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[m.get(n).fixCount," change",m.get(n).fixCount===1?"":"s"]}):null]},n))})]}):null,O?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:ce.map(n=>{const T=ue.has(n);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>ye(n),className:"flex w-full items-center gap-2 bg-slate-100 px-4 py-2 text-left font-mono text-xs text-slate-700 hover:bg-slate-200",children:[e.jsx("span",{className:"shrink-0 text-slate-400",children:T?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:n}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(z[n].length/1024).toFixed(1)," KB"]})]}),T?e.jsxs("div",{className:"bg-white",children:[m.get(n)?.hunks.length?e.jsxs("div",{className:"flex gap-2 border-b border-slate-200 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>o(n),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:A.has(n)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",m.get(n).stats.added," −",m.get(n).stats.removed," in the LaTeX source"]})]}):null,A.has(n)&&m.has(n)?e.jsx(Ae,{hunks:m.get(n).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:z[n]})]}):null]},n)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:u??se,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:u?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[U?e.jsx("button",{type:"button",onClick:()=>h({name:"sources",prepared:U}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{O||fe(l,f),ne(n=>!n)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:O?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:V,onClick:async()=>{te(!0);try{await r(l,f)}finally{te(!1)}},className:"flex items-center gap-2 rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600 disabled:opacity-60",children:[V?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"}):null,V?"Importing…":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[i.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Converter"}),e.jsx("div",{className:"mt-2 flex flex-col gap-3",children:i.map(s=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-engine",value:s.id,checked:P===s.id,onChange:()=>W(s.id),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:s.label}),s.description?e.jsx("span",{className:"block text-slate-500",children:s.description}):null]})]},s.id))})]}):null,p?null:e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Document kind"}),e.jsxs("select",{value:C,onChange:s=>L(s.currentTarget.value),className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&v.current?.click(),onClick:()=>v.current?.click(),onDragOver:s=>{s.preventDefault(),S(!0)},onDragLeave:()=>S(!1),onDrop:s=>{s.preventDefault(),S(!1);const o=s.dataTransfer.files?.[0];o&&J(o)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${_?"border-blue-500 bg-blue-50":"border-slate-300 bg-slate-50 hover:border-slate-400"}`,children:[e.jsx("p",{className:"text-slate-600",children:"Drop a file here, or click to select."}),e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),v.current?.click()},className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Select File"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Supports ",t.join(", ")]}),e.jsx("input",{ref:v,type:"file",hidden:!0,accept:t.join(","),onChange:s=>{const o=s.currentTarget.files?.[0];o&&J(o),s.currentTarget.value=""}})]})]})}function Ae({hunks:r}){return r.length===0?e.jsx("p",{className:"m-0 px-4 py-3 text-xs text-slate-500",children:"Nothing was changed in this file."}):e.jsx("div",{className:"max-h-72 overflow-auto bg-white font-mono text-xs leading-relaxed",children:r.map((u,p)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[p>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,u.lines.map((b,g)=>e.jsxs("div",{className:b.op==="add"?"bg-green-50 px-4 text-green-900":b.op==="remove"?"bg-red-50 px-4 text-red-900":"px-4 text-slate-600",children:[e.jsx("span",{className:"mr-2 select-none text-slate-400",children:b.op==="add"?"+":b.op==="remove"?"−":" "}),b.text||" "]},g))]},p))})}const Fe={title:"Import Source Content",description:"Paste LaTeX, Markdown, or PreTeXt source to convert into PreTeXt.",sourceLabel:"Source",sourcePlaceholder:"Paste source content here...",formatLabel:"Source format",convertButton:"Convert to PreTeXt",detectedFormatPrefix:"Detected",successPrefix:"Ready",errorPrefix:"Error"};function Oe({initialSource:r="",initialSourceFormat:u,labels:p,disabled:b=!1,onImport:g}){const i=c.useMemo(()=>({...Fe,...p??{}}),[p]),[v,N]=c.useState(r),[h,_]=c.useState(u??"auto"),[S,C]=c.useState(null),L=c.useMemo(()=>F.detectSourceFormat(v),[v]),w=b||!v.trim();return e.jsx("form",{onSubmit:k=>{k.preventDefault();const A=F.convertSourceToPretext(v,h==="auto"?void 0:h);C(A),g(A)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:b,children:[e.jsx("legend",{children:i.title}),e.jsx("p",{children:i.description}),e.jsxs("label",{children:[i.sourceLabel,e.jsx("textarea",{value:v,onChange:k=>N(k.currentTarget.value),placeholder:i.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[i.formatLabel,e.jsxs("select",{value:h,onChange:k=>_(k.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"latex",children:"LaTeX"}),e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"pretext",children:"PreTeXt"})]})]}),e.jsxs("p",{children:[i.detectedFormatPrefix,": ",e.jsx("strong",{children:L})]}),e.jsx("button",{type:"submit",disabled:w,children:i.convertButton}),S?"pretextError"in S?e.jsxs("p",{role:"alert",children:[i.errorPrefix,": ",S.pretextError]}):e.jsxs("p",{children:[i.successPrefix,": ",S.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const Le={title:"Upload Source File",hint:"Supports .tex, .md, .ptx, .xml, .zip, and .tar.gz files.",selectButton:"Select File",dropHint:"Drop a file here, or click Select File.",documentKindLabel:"Document kind",splitSectionsLabel:"Split each chapter into sections"};function Ie({labels:r,disabled:u=!1,defaultDocumentKind:p="auto",importOptions:b,onImport:g}){const i=c.useMemo(()=>({...Le,...r??{}}),[r]),v=c.useRef(null),[N,h]=c.useState(!1),[_,S]=c.useState(!1),[C,L]=c.useState([]),[w,k]=c.useState(p),[A,I]=c.useState(!1),P=u||_,W=async f=>{S(!0);try{const E=b??{documentKind:w==="auto"?void 0:w,splitSections:A},O=await F.handleImportUploadFile(f,E);L(O.statusMessages),g(O)}finally{S(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:i.title}),e.jsx("p",{children:i.hint}),b?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[i.documentKindLabel,e.jsxs("select",{value:w,disabled:P,onChange:f=>k(f.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]}),e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:A,disabled:P,onChange:f=>I(f.currentTarget.checked)}),i.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:f=>{f.preventDefault(),P||h(!0)},onDragLeave:()=>h(!1),onDrop:f=>{if(f.preventDefault(),h(!1),P)return;const E=f.dataTransfer.files?.[0];E&&W(E)},children:[e.jsx("p",{children:i.dropHint}),e.jsxs("button",{type:"button",disabled:P,onClick:()=>v.current?.click(),className:"inline-flex items-center gap-2",children:[_?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent","aria-hidden":"true"}):null,_?"Processing…":i.selectButton]}),e.jsx("input",{ref:v,type:"file",hidden:!0,disabled:P,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:f=>{const E=f.currentTarget.files?.[0];E&&W(E),f.currentTarget.value=""}})]}),_?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,C.length>0?e.jsx("ul",{"aria-live":"polite",children:C.map((f,E)=>e.jsx("li",{children:f.message},`${f.type}-${E}`))}):null,N&&!P?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=Oe;exports.ImportUploadPanel=Ie;exports.ImportWizard=_e;exports.ProcessingPanel=ve;