@pretextbook/import 0.7.0 → 0.9.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.
@@ -68,10 +68,25 @@ export interface ImportWizardProps {
68
68
  /** Pass fixed options to skip the document-kind / split-sections controls. */
69
69
  importOptions?: ImportProjectOptions;
70
70
  defaultDocumentKind?: DocumentKind | "auto";
71
+ /**
72
+ * Which import style the review step starts on: `"converted"` (the PreTeXt
73
+ * output) or `"native"` (the cleaned LaTeX/Markdown source, unconverted).
74
+ * The user can still switch, unless `lockImportMode` is set. Ignored for
75
+ * results with no native alternative — a PreTeXt upload always reviews as
76
+ * converted.
77
+ */
78
+ defaultImportMode?: ImportMode;
79
+ /**
80
+ * Hide the import-mode chooser and import in `defaultImportMode` only. For
81
+ * hosts that support just one style, or that already asked elsewhere.
82
+ */
83
+ lockImportMode?: boolean;
84
+ /** Called when the user picks a different import mode on the review step. */
85
+ onImportModeChange?: (mode: ImportMode) => void;
71
86
  /**
72
87
  * Converters offered to the user. When more than one is supplied, an engine
73
88
  * selector is shown on the upload step. Defaults to a single built-in engine.
74
89
  */
75
90
  engines?: ImportEngine[];
76
91
  }
77
- export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, engines, }: ImportWizardProps): import("react").JSX.Element;
92
+ export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, defaultImportMode, lockImportMode, onImportModeChange, engines, }: ImportWizardProps): import("react").JSX.Element;
package/dist/react.cjs CHANGED
@@ -1,6 +1,6 @@
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:
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),A=require("./upload-BtS22hIH.cjs"),Q=require("./import-mode-DuPFMu97.cjs");var ie={exports:{}},ae={};var je;function Pe(){if(je)return ae;je=1;var r=Symbol.for("react.transitional.element"),m=Symbol.for("react.fragment");function p(h,j,u){var y=null;if(u!==void 0&&(y=""+u),j.key!==void 0&&(y=""+j.key),"key"in j){u={};for(var P in j)P!=="key"&&(u[P]=j[P])}else u=j;return j=u.ref,{$$typeof:r,type:h,key:y,ref:j!==void 0?j:null,props:u}}return ae.Fragment=m,ae.jsx=p,ae.jsxs=p,ae}var ne={};var ve;function Re(){return ve||(ve=1,process.env.NODE_ENV!=="production"&&(function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===ee?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case O:return"Fragment";case z:return"Profiler";case _:return"StrictMode";case de:return"Suspense";case le:return"SuspenseList";case ue: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 F:return"Portal";case k:return t.displayName||"Context";case g:return(t._context.displayName||"Context")+".Consumer";case q:var a=t.render;return t=t.displayName,t||(t=a.displayName||a.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case W:return a=t.displayName||null,a!==null?a:r(t.type)||"Memo";case K:a=t._payload,t=t._init;try{return r(t(a))}catch{}}return null}function m(t){return""+t}function p(t){try{m(t);var a=!1}catch{a=!0}if(a){a=console;var d=a.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return d.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),m(t)}}function h(t){if(t===O)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===K)return"<...>";try{var a=r(t);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function j(){var t=U.A;return t===null?null:t.getOwner()}function u(){return Error("react-stack-top-frame")}function y(t){if(te.call(t,"key")){var a=Object.getOwnPropertyDescriptor(t,"key").get;if(a&&a.isReactWarning)return!1}return t.key!==void 0}function P(t,a){function d(){se||(se=!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))}d.isReactWarning=!0,Object.defineProperty(t,"key",{get:d,configurable:!0})}function S(){var t=r(this.type);return G[t]||(G[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 R(t,a,d,f,I,$){var x=d.ref;return t={$$typeof:E,type:t,key:a,props:d,_owner:f},(x!==void 0?x:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:S}):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:I}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:$}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function v(t,a,d,f,I,$){var x=a.children;if(x!==void 0)if(f)if(Y(x)){for(f=0;f<x.length;f++)b(x[f]);Object.freeze&&Object.freeze(x)}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 b(x);if(te.call(a,"key")){x=r(t);var C=Object.keys(a).filter(function(me){return me!=="key"});f=0<C.length?"{key: someKey, "+C.join(": ..., ")+": ...}":"{key: someKey}",H[x+f]||(C=0<C.length?"{"+C.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} />`,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;
6
+ <%s key={someKey} {...props} />`,f,x,C,x),H[x+f]=!0)}if(x=null,d!==void 0&&(p(d),x=""+d),y(a)&&(p(a.key),x=""+a.key),"key"in a){d={};for(var Z in a)Z!=="key"&&(d[Z]=a[Z])}else d=a;return x&&P(d,typeof t=="function"?t.displayName||t.name||"Unknown":t),R(t,x,d,j(),I,$)}function b(t){D(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===K&&(t._payload.status==="fulfilled"?D(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function D(t){return typeof t=="object"&&t!==null&&t.$$typeof===E}var w=c,E=Symbol.for("react.transitional.element"),F=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),z=Symbol.for("react.profiler"),g=Symbol.for("react.consumer"),k=Symbol.for("react.context"),q=Symbol.for("react.forward_ref"),de=Symbol.for("react.suspense"),le=Symbol.for("react.suspense_list"),W=Symbol.for("react.memo"),K=Symbol.for("react.lazy"),ue=Symbol.for("react.activity"),ee=Symbol.for("react.client.reference"),U=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,te=Object.prototype.hasOwnProperty,Y=Array.isArray,V=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(t){return t()}};var se,G={},J=w.react_stack_bottom_frame.bind(w,u)(),M=V(h(u)),H={};ne.Fragment=O,ne.jsx=function(t,a,d){var f=1e4>U.recentlyCreatedOwnerStacks++;return v(t,a,d,!1,f?Error("react-stack-top-frame"):J,f?V(h(t)):M)},ne.jsxs=function(t,a,d){var f=1e4>U.recentlyCreatedOwnerStacks++;return v(t,a,d,!0,f?Error("react-stack-top-frame"):J,f?V(h(t)):M)}})()),ne}var Ne;function _e(){return Ne||(Ne=1,process.env.NODE_ENV==="production"?ie.exports=Pe():ie.exports=Re()),ie.exports}var e=_e();function Ce(){const[r,m]=c.useState(0),p=c.useRef(Date.now());return c.useEffect(()=>{const h=setInterval(()=>{m(Math.floor((Date.now()-p.current)/1e3))},1e3);return()=>clearInterval(h)},[]),r}function Ae(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function Se({message:r="Processing your file…",onCancel:m}){const p=Ce();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:Ae(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,m?e.jsx("button",{type:"button",onClick:m,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 we=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],Fe={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:we,convertFile:A.handleImportUploadFile,prepare:async r=>{const{files:m,assets:p}=await A.extractUpload(r);return{fileName:r.name,files:m,assets:p,analysis:A.analyzeImportSources(m)}},convertPrepared:(r,m)=>A.importProjectFromFiles(r.files,{...m,assets:r.assets})};function fe(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const ye={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function Oe(r){const m=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} — ${m}`:m}function Ie(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 Le({onConfirm:r,onCancel:m,importOptions:p,defaultDocumentKind:h="auto",defaultImportMode:j=Q.DEFAULT_IMPORT_MODE,lockImportMode:u=!1,onImportModeChange:y,engines:P}){const S=P&&P.length>0?P:[Fe],R=c.useRef(null),[v,b]=c.useState({name:"upload"}),[D,w]=c.useState(!1),[E,F]=c.useState(h),[O,_]=c.useState(null),[z,g]=c.useState(new Set),[k,q]=c.useState(S[0].id),[de,le]=c.useState(j),[W,K]=c.useState(!1),[ue,ee]=c.useState(new Set),[U,te]=c.useState(null),[Y,V]=c.useState("auto"),[se,G]=c.useState(null),[J,M]=c.useState({}),[H,t]=c.useState(!1),a=c.useRef(!1),d=S.find(s=>s.id===k)??S[0],f=d.acceptExtensions??we,I=v.name==="review"?v.result:null,$=c.useMemo(()=>I&&O!==null?A.relayoutImport(I,O):I,[I,O]),x=c.useMemo(()=>new Map($?Q.fileChangesForImport($).map(s=>[s.path,s]):[]),[$]),C=()=>p??{documentKind:E==="auto"?void 0:E},Z=s=>A.analyzeImportSources(s.files,{sourceFormat:Y==="auto"?void 0:Y,mainFile:se??void 0}),me=s=>{a.current=!0,d.cancel?.(),b(s?{name:"sources",prepared:s}:{name:"upload"})},Ee=async s=>{a.current=!1,b({name:"processing"}),await fe();try{const l=Z(s).extraRoots.map(i=>({path:i.path,include:J[i.path]?.include??!0,level:J[i.path]?.level})),N=await d.convertPrepared(s,{...C(),sourceFormat:Y==="auto"?void 0:Y,mainFile:se??void 0,attachRoots:l});"pretextError"in N?b({name:"error",message:N.pretextError}):b({name:"review",result:N})}catch(o){if(a.current)return;b({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},he=async s=>{a.current=!1,b({name:"processing"}),await fe();try{if(d.prepare&&d.convertPrepared){const l=await d.prepare(s);if(te(l),V("auto"),G(null),M({}),Ie(l.analysis)){b({name:"sources",prepared:l});return}await fe();const N=await d.convertPrepared(l,C());b("pretextError"in N?{name:"error",message:N.pretextError}:{name:"review",result:N});return}const o=await d.convertFile(s,C());"pretextError"in o?b({name:"error",message:o.pretextError}):b({name:"review",result:o})}catch(o){if(a.current)return;b({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},xe=()=>{b({name:"upload"}),le(j),K(!1),ee(new Set),g(new Set),_(null),te(null)};function be(s,o){return[...s].sort((l,N)=>l===o?-1:N===o?1:l.localeCompare(N))}function ge(s,o){const l=Q.filesForImportMode(s,o),N=o==="converted"?s.projectLayout.mainSourcePath:s.sourcePath,i=be(Object.keys(l),N)[0];ee(i?new Set([i]):new Set)}function ke(s){ee(o=>{const l=new Set(o);return l.has(s)?l.delete(s):l.add(s),l})}if(v.name==="processing")return e.jsx(Se,{onCancel:d.cancel?()=>me(U):void 0});if(v.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:v.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:xe,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(v.name==="sources"){const s=v.prepared,o=Z(s),l=o.manifest,N=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(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:Y,onChange:i=>{V(i.currentTarget.value),G(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?` (${ye[o.primary.format]})`:""]}),o.formats.map(i=>e.jsx("option",{value:i,children:ye[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:N===i.path,onChange:()=>{G(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:Oe(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 L=J[i.path],re=L?.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:re,onChange:X=>M(B=>({...B,[i.path]:{...B[i.path],include:X.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:L?.level??"auto",disabled:!re,onChange:X=>M(B=>({...B,[i.path]:{include:B[i.path]?.include??!0,level:X.currentTarget.value==="auto"?void 0:X.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:xe,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Ee(s),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(v.name==="review"){let s=function(n){le(n),y?.(n),W&&ge(l,n)},o=function(n){g(T=>{const ce=new Set(T);return ce.has(n)?ce.delete(n):ce.add(n),ce})};const l=$??v.result,N=l.splitLevel,i=Q.hasNativeImportMode(l),L=Q.resolveImportMode(l,de),re=l.detectedSourceFormat==="markdown"?"Markdown":"LaTeX",X=l.warnings.length,B=Object.keys(l.outputFiles).length,pe=Q.filesForImportMode(l,L),Te=L==="converted"?l.projectLayout.mainSourcePath:l.sourcePath,oe=be(Object.keys(pe),Te);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:B}),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]})]}),X>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:[X," conversion"," ",X===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."}),i&&!u?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:L==="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:L==="native",onChange:()=>s("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Keep as ",re]}),e.jsxs("span",{className:"block text-slate-500",children:["Preserve the original ",re," 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:A.MAX_SUGGESTED_SPLIT_LEVEL+1},(n,T)=>e.jsx("button",{type:"button",onClick:()=>_(T),"aria-pressed":N===T,className:N===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:[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(n=>e.jsxs("li",{className:"truncate py-0.5",children:[n,x.get(n)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[x.get(n).fixCount," change",x.get(n).fixCount===1?"":"s"]}):null]},n))})]}):null,W?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:oe.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:()=>ke(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:[(pe[n].length/1024).toFixed(1)," KB"]})]}),T?e.jsxs("div",{className:"bg-white",children:[x.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:z.has(n)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",x.get(n).stats.added," −",x.get(n).stats.removed," in the LaTeX source"]})]}):null,z.has(n)&&x.has(n)?e.jsx(De,{hunks:x.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:pe[n]})]}):null]},n)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:m??xe,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:m?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[U?e.jsx("button",{type:"button",onClick:()=>b({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:()=>{W||ge(l,L),K(n=>!n)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:W?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:H,onClick:async()=>{t(!0);try{await r(l,L)}finally{t(!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:[H?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"}):null,H?"Importing…":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[S.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:S.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:k===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,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:E,onChange:s=>F(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"&&R.current?.click(),onClick:()=>R.current?.click(),onDragOver:s=>{s.preventDefault(),w(!0)},onDragLeave:()=>w(!1),onDrop:s=>{s.preventDefault(),w(!1);const o=s.dataTransfer.files?.[0];o&&he(o)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${D?"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(),R.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 ",f.join(", ")]}),e.jsx("input",{ref:R,type:"file",hidden:!0,accept:f.join(","),onChange:s=>{const o=s.currentTarget.files?.[0];o&&he(o),s.currentTarget.value=""}})]})]})}function De({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((m,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,m.lines.map((h,j)=>e.jsxs("div",{className:h.op==="add"?"bg-green-50 px-4 text-green-900":h.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:h.op==="add"?"+":h.op==="remove"?"−":" "}),h.text||" "]},j))]},p))})}const Me={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 $e({initialSource:r="",initialSourceFormat:m,labels:p,disabled:h=!1,onImport:j}){const u=c.useMemo(()=>({...Me,...p??{}}),[p]),[y,P]=c.useState(r),[S,R]=c.useState(m??"auto"),[v,b]=c.useState(null),D=c.useMemo(()=>A.detectSourceFormat(y),[y]),w=h||!y.trim();return e.jsx("form",{onSubmit:E=>{E.preventDefault();const F=A.convertSourceToPretext(y,S==="auto"?void 0:S);b(F),j(F)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:h,children:[e.jsx("legend",{children:u.title}),e.jsx("p",{children:u.description}),e.jsxs("label",{children:[u.sourceLabel,e.jsx("textarea",{value:y,onChange:E=>P(E.currentTarget.value),placeholder:u.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[u.formatLabel,e.jsxs("select",{value:S,onChange:E=>R(E.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:[u.detectedFormatPrefix,": ",e.jsx("strong",{children:D})]}),e.jsx("button",{type:"submit",disabled:w,children:u.convertButton}),v?"pretextError"in v?e.jsxs("p",{role:"alert",children:[u.errorPrefix,": ",v.pretextError]}):e.jsxs("p",{children:[u.successPrefix,": ",v.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const Xe={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 ze({labels:r,disabled:m=!1,defaultDocumentKind:p="auto",importOptions:h,onImport:j}){const u=c.useMemo(()=>({...Xe,...r??{}}),[r]),y=c.useRef(null),[P,S]=c.useState(!1),[R,v]=c.useState(!1),[b,D]=c.useState([]),[w,E]=c.useState(p),[F,O]=c.useState(!1),_=m||R,z=async g=>{v(!0);try{const k=h??{documentKind:w==="auto"?void 0:w,splitSections:F},q=await A.handleImportUploadFile(g,k);D(q.statusMessages),j(q)}finally{v(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:u.title}),e.jsx("p",{children:u.hint}),h?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[u.documentKindLabel,e.jsxs("select",{value:w,disabled:_,onChange:g=>E(g.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:F,disabled:_,onChange:g=>O(g.currentTarget.checked)}),u.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:g=>{g.preventDefault(),_||S(!0)},onDragLeave:()=>S(!1),onDrop:g=>{if(g.preventDefault(),S(!1),_)return;const k=g.dataTransfer.files?.[0];k&&z(k)},children:[e.jsx("p",{children:u.dropHint}),e.jsxs("button",{type:"button",disabled:_,onClick:()=>y.current?.click(),className:"inline-flex items-center gap-2",children:[R?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,R?"Processing…":u.selectButton]}),e.jsx("input",{ref:y,type:"file",hidden:!0,disabled:_,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:g=>{const k=g.currentTarget.files?.[0];k&&z(k),g.currentTarget.value=""}})]}),R?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,b.length>0?e.jsx("ul",{"aria-live":"polite",children:b.map((g,k)=>e.jsx("li",{children:g.message},`${g.type}-${k}`))}):null,P&&!_?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=$e;exports.ImportUploadPanel=ze;exports.ImportWizard=Le;exports.ProcessingPanel=Se;