@pretextbook/import 0.12.0 → 0.14.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/convert-worker.cjs +1 -1
- package/dist/convert-worker.js +1 -1
- package/dist/{engine-routing-08ynicii.cjs → engine-routing-B03PZ4P-.cjs} +1 -1
- package/dist/{engine-routing-Bu0zM4aw.js → engine-routing-vjkGBbmx.js} +7 -7
- package/dist/index.cjs +12 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +413 -343
- package/dist/lib/clean/latex-preamble.d.ts +7 -0
- package/dist/lib/convert.d.ts +21 -2
- package/dist/lib/layout/document-kind.d.ts +1 -1
- package/dist/lib/paste/place-markup.d.ts +26 -4
- package/dist/lib/pretext-divisions.d.ts +1 -1
- package/dist/react.cjs +2 -2
- package/dist/react.js +19 -18
- package/dist/{upload-BnRj1gU1.cjs → upload-CPMLFrdG.cjs} +24 -24
- package/dist/{upload-H_OCZBBn.js → upload-w0BmYtpp.js} +413 -388
- package/package.json +2 -2
|
@@ -37,6 +37,13 @@ export interface ExtractMacrosResult {
|
|
|
37
37
|
* (e.g. WeBWorK/PG macro extraction) only recognises `\newcommand`.
|
|
38
38
|
*/
|
|
39
39
|
export declare function extractMacros(preamble: string): ExtractMacrosResult;
|
|
40
|
+
/**
|
|
41
|
+
* Does this `\documentclass` argument name a slide class?
|
|
42
|
+
*
|
|
43
|
+
* `beamerarticle` is deliberately excluded: it is the package that typesets a
|
|
44
|
+
* beamer source *as an article*, so a document using it wants article output.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isBeamerClass(documentClass: string): boolean;
|
|
40
47
|
export interface ExtractPreambleInfoResult {
|
|
41
48
|
info: PreambleInfo;
|
|
42
49
|
warnings: CleaningWarning[];
|
package/dist/lib/convert.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { CleanedChunk } from './clean/clean-chunks';
|
|
2
2
|
import { CleaningWarning } from './clean/warnings';
|
|
3
|
+
import { DocumentKind } from './layout/document-kind';
|
|
4
|
+
import { PretextRootTag } from './pretext-divisions';
|
|
3
5
|
import { ConvertedPretextResult, SourceFormat } from './types';
|
|
4
6
|
export declare function normalizePretextSource(pretextSource: string): string;
|
|
5
7
|
export interface LatexConversionResult {
|
|
@@ -18,6 +20,23 @@ export interface MarkdownConversionResult {
|
|
|
18
20
|
pretext: string;
|
|
19
21
|
cleanedMarkdown: string;
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Convert Markdown to PreTeXt.
|
|
25
|
+
*
|
|
26
|
+
* `documentRoot` names the root to wrap the document in, which for Markdown is
|
|
27
|
+
* not cosmetic: it selects the heading hierarchy. Under `slideshow`, `#` is a
|
|
28
|
+
* `<section>` and `##` a `<slide>` (`SLIDESHOW_HIERARCHY` in `@pretextbook/ptxast`),
|
|
29
|
+
* not the `section`/`subsection` chain. Left undefined, the markdown's own
|
|
30
|
+
* `division:` frontmatter decides — so an author who wrote `division: slideshow`
|
|
31
|
+
* gets a deck without touching the wizard.
|
|
32
|
+
*/
|
|
33
|
+
export declare function convertMarkdownToPretext(markdownSource: string, documentRoot?: PretextRootTag): MarkdownConversionResult;
|
|
22
34
|
export declare function getConversionErrorMessage(error: unknown): string;
|
|
23
|
-
|
|
35
|
+
/**
|
|
36
|
+
* `documentKind` is the user's explicit choice from the wizard, or `undefined`
|
|
37
|
+
* for "auto detect". It reaches conversion — rather than only the layout stage,
|
|
38
|
+
* where the rest of the pipeline resolves it — because Markdown's heading
|
|
39
|
+
* hierarchy depends on the root: by the time layout runs, `##` has already
|
|
40
|
+
* become a `<subsection>` and there is no slide left to recover.
|
|
41
|
+
*/
|
|
42
|
+
export declare function convertSourceToPretext(source: string, sourceFormat?: SourceFormat, documentKind?: DocumentKind): ConvertedPretextResult;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type DocumentKind = "article" | "book";
|
|
1
|
+
export type DocumentKind = "article" | "book" | "slideshow";
|
|
2
2
|
export declare function detectDocumentKind(pretextSource: string): DocumentKind;
|
|
@@ -15,6 +15,26 @@ export declare function firstDivisionTag(markup: string): string | undefined;
|
|
|
15
15
|
* left as-is because the editor places it after the existing content there.
|
|
16
16
|
*/
|
|
17
17
|
export declare function reindentForContext(text: string, baseIndent: string, skipFirst: boolean): string;
|
|
18
|
+
/** Tags dropped from the generated `<p>` content model, and why — see above. */
|
|
19
|
+
export declare const PARAGRAPH_CONTENT_EXCLUSIONS: readonly string[];
|
|
20
|
+
/**
|
|
21
|
+
* Wrap every run of loose paragraph content in `markup` in a `<p>`.
|
|
22
|
+
*
|
|
23
|
+
* Converters do not always do this themselves. `unified-latex`'s PreTeXt
|
|
24
|
+
* conversion wraps paragraphs only when the source has more than one of them,
|
|
25
|
+
* so pasting a single paragraph — the commonest paste there is — yields bare
|
|
26
|
+
* text, and pasting `Intro \begin{theorem}…\end{theorem} outro` yields text on
|
|
27
|
+
* either side of a block with no paragraph around either. Both are invalid
|
|
28
|
+
* where the insertion point is not already inside a `<p>`.
|
|
29
|
+
*
|
|
30
|
+
* The rule is the schema's: content that may sit inside a `<p>` accumulates
|
|
31
|
+
* into one, and content that may not ends the run and passes through untouched.
|
|
32
|
+
* A run is only given a `<p>` if it holds real text or an element — a run of
|
|
33
|
+
* whitespace and comments between two blocks is left as it was. Markup that is
|
|
34
|
+
* already correctly wrapped therefore comes through unchanged, which is what
|
|
35
|
+
* lets this run unconditionally on the block-context path.
|
|
36
|
+
*/
|
|
37
|
+
export declare function wrapLooseParagraphs(markup: string): string;
|
|
18
38
|
export interface PlacementContext {
|
|
19
39
|
/** The insertion point sits inside a `<p>`, so only inline content fits. */
|
|
20
40
|
inline: boolean;
|
|
@@ -33,9 +53,11 @@ export interface PlacedMarkup {
|
|
|
33
53
|
*
|
|
34
54
|
* Two adjustments, both about context rather than conversion. Inside a
|
|
35
55
|
* paragraph the converter's own wrapping `<p>` is one paragraph too many, so it
|
|
36
|
-
* is unwrapped
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
56
|
+
* is unwrapped; outside one, loose text that never got a `<p>` is given one.
|
|
57
|
+
* What cannot be repaired here at all is block content landing inside a
|
|
58
|
+
* paragraph — a division, or several paragraphs pasted into the middle of one.
|
|
59
|
+
* The honest thing is to insert it and say so, leaving the author to move it,
|
|
60
|
+
* rather than silently emitting invalid markup or refusing a paste they asked
|
|
61
|
+
* for.
|
|
40
62
|
*/
|
|
41
63
|
export declare function placeConvertedMarkup(converted: string, context: PlacementContext): PlacedMarkup;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Root elements of a PreTeXt document. */
|
|
2
|
-
export declare const PRETEXT_ROOT_TAGS: readonly ["book", "article"];
|
|
2
|
+
export declare const PRETEXT_ROOT_TAGS: readonly ["book", "article", "slideshow"];
|
|
3
3
|
/** Divisions that may be split into their own file, in rough outline order. */
|
|
4
4
|
export declare const PRETEXT_DIVISION_TAGS: readonly ["frontmatter", "preface", "acknowledgement", "dedication", "biography", "contributors", "part", "introduction", "chapter", "section", "subsection", "subsubsection", "conclusion", "exercises", "worksheet", "handout", "reading-questions", "references", "solutions", "glossary", "backmatter", "appendix", "index", "colophon"];
|
|
5
5
|
export type PretextRootTag = (typeof PRETEXT_ROOT_TAGS)[number];
|
package/dist/react.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),I=require("./upload-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),I=require("./upload-CPMLFrdG.cjs"),A=require("./engine-routing-B03PZ4P-.cjs");var ge={exports:{}},oe={};var Ie;function Ke(){if(Ie)return oe;Ie=1;var r=Symbol.for("react.transitional.element"),i=Symbol.for("react.fragment");function u(m,p,d){var y=null;if(d!==void 0&&(y=""+d),p.key!==void 0&&(y=""+p.key),"key"in p){d={};for(var R in p)R!=="key"&&(d[R]=p[R])}else d=p;return p=d.ref,{$$typeof:r,type:m,key:y,ref:p!==void 0?p:null,props:d}}return oe.Fragment=i,oe.jsx=u,oe.jsxs=u,oe}var ce={};var De;function Ve(){return De||(De=1,process.env.NODE_ENV!=="production"&&(function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===G?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case K:return"Fragment";case V:return"Profiler";case C:return"StrictMode";case ne:return"Suspense";case ie:return"SuspenseList";case ve: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 D:return"Portal";case P:return t.displayName||"Context";case b:return(t._context.displayName||"Context")+".Consumer";case _:var l=t.render;return t=t.displayName,t||(t=l.displayName||l.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case de:return l=t.displayName||null,l!==null?l:r(t.type)||"Memo";case ae:l=t._payload,t=t._init;try{return r(t(l))}catch{}}return null}function i(t){return""+t}function u(t){try{i(t);var l=!1}catch{l=!0}if(l){l=console;var f=l.error,g=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return f.call(l,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",g),i(t)}}function m(t){if(t===K)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===ae)return"<...>";try{var l=r(t);return l?"<"+l+">":"<...>"}catch{return"<...>"}}function p(){var t=J.A;return t===null?null:t.getOwner()}function d(){return Error("react-stack-top-frame")}function y(t){if(ue.call(t,"key")){var l=Object.getOwnPropertyDescriptor(t,"key").get;if(l&&l.isReactWarning)return!1}return t.key!==void 0}function R(t,l){function f(){le||(le=!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)",l))}f.isReactWarning=!0,Object.defineProperty(t,"key",{get:f,configurable:!0})}function h(){var t=r(this.type);return xe[t]||(xe[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 k(t,l,f,g,B,O){var v=f.ref;return t={$$typeof:T,type:t,key:l,props:f,_owner:g},(v!==void 0?v: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:B}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:O}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function E(t,l,f,g,B,O){var v=l.children;if(v!==void 0)if(g)if(me(v)){for(g=0;g<v.length;g++)w(v[g]);Object.freeze&&Object.freeze(v)}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 w(v);if(ue.call(l,"key")){v=r(t);var L=Object.keys(l).filter(function(se){return se!=="key"});g=0<L.length?"{key: someKey, "+L.join(": ..., ")+": ...}":"{key: someKey}",te[v+g]||(L=0<L.length?"{"+L.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,v,L,v),te[v+g]=!0)}if(v=null,f!==void 0&&(u(f),v=""+f),y(l)&&(u(l.key),v=""+l.key),"key"in l){f={};for(var $ in l)$!=="key"&&(f[$]=l[$])}else f=l;return v&&R(f,typeof t=="function"?t.displayName||t.name||"Unknown":t),k(t,v,f,p(),B,O)}function w(t){j(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===ae&&(t._payload.status==="fulfilled"?j(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function j(t){return typeof t=="object"&&t!==null&&t.$$typeof===T}var F=o,T=Symbol.for("react.transitional.element"),D=Symbol.for("react.portal"),K=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),b=Symbol.for("react.consumer"),P=Symbol.for("react.context"),_=Symbol.for("react.forward_ref"),ne=Symbol.for("react.suspense"),ie=Symbol.for("react.suspense_list"),de=Symbol.for("react.memo"),ae=Symbol.for("react.lazy"),ve=Symbol.for("react.activity"),G=Symbol.for("react.client.reference"),J=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ue=Object.prototype.hasOwnProperty,me=Array.isArray,z=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(t){return t()}};var le,xe={},Q=F.react_stack_bottom_frame.bind(F,d)(),ee=z(m(d)),te={};ce.Fragment=K,ce.jsx=function(t,l,f){var g=1e4>J.recentlyCreatedOwnerStacks++;return E(t,l,f,!1,g?Error("react-stack-top-frame"):Q,g?z(m(t)):ee)},ce.jsxs=function(t,l,f){var g=1e4>J.recentlyCreatedOwnerStacks++;return E(t,l,f,!0,g?Error("react-stack-top-frame"):Q,g?z(m(t)):ee)}})()),ce}var Oe;function Ge(){return Oe||(Oe=1,process.env.NODE_ENV==="production"?ge.exports=Ke():ge.exports=Ve()),ge.exports}var e=Ge();function Je(){const[r,i]=o.useState(0),u=o.useRef(Date.now());return o.useEffect(()=>{const m=setInterval(()=>{i(Math.floor((Date.now()-u.current)/1e3))},1e3);return()=>clearInterval(m)},[]),r}function He(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function $e({message:r="Processing your file…",onCancel:i}){const u=Je();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:He(u)}),u>=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,i?e.jsx("button",{type:"button",onClick:i,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 Ze={id:"builtin",label:"Built-in converter",description:"Converts LaTeX, Markdown, and PreTeXt without any other tools.",acceptExtensions:A.DEFAULT_ACCEPT_EXTENSIONS,convertFile:I.handleImportUploadFile,prepare:async r=>{const{files:i,assets:u}=await I.extractUpload(r);return{fileName:r.name,files:i,assets:u,analysis:I.analyzeImportSources(i)}},convertPrepared:(r,i)=>I.importProjectFromFiles(r.files,{...i,assets:r.assets})};function ke(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const Le={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function Qe(r){const i=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} — ${i}`:i}function et(r){return r.candidates.filter(u=>u.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 tt({onConfirm:r,onCancel:i,importOptions:u,defaultDocumentKind:m="auto",defaultImportMode:p=A.DEFAULT_IMPORT_MODE,lockImportMode:d=!1,onImportModeChange:y,engines:R,insertTarget:h}){const k=R&&R.length>0?R:[Ze],E=o.useRef(null),[w,j]=o.useState({name:"upload"}),[F,T]=o.useState(!1),[D,K]=o.useState(m),[C,V]=o.useState(null),[b,P]=o.useState(null),[_,ne]=o.useState([]),[ie,de]=o.useState(new Set),[ae,ve]=o.useState(k[0].id),[G,J]=o.useState(null),[ue,me]=o.useState(p),[z,le]=o.useState(!1),[xe,Q]=o.useState(new Set),[ee,te]=o.useState(null),[t,l]=o.useState("auto"),[f,g]=o.useState(null),[B,O]=o.useState({}),[v,L]=o.useState(!1),$=o.useRef(!1),se=k.find(n=>n.id===ae)??k[0],Ee=A.allAcceptExtensions(k),W=G?A.alternateFor(k,G.name):void 0,Te=W?se.id===W.id:!1,pe=W?Te?A.routeEngine(k,G.name)??null:W:null,H=w.name==="review"?w.result:null,he=o.useMemo(()=>H&&(C!==null||b!==null||_.length>0)?I.rebuildImport(H,{splitLevel:C??void 0,targetTag:b??void 0,selection:_}):H,[H,C,b,_]),je=o.useMemo(()=>H?I.outlineDivisions(H.pretextSource):[],[H]),q=o.useMemo(()=>new Map(he?A.fileChangesForImport(he).map(n=>[n.path,n]):[]),[he]),Pe=o.useMemo(()=>h?{kind:"insert",targetTag:b??h.defaultTargetTag,takenIds:new Set(h.takenIds),hrefBase:h.hrefBase}:void 0,[h,b]),Ne=()=>({...u??{documentKind:D==="auto"?void 0:D},...Pe?{destination:Pe}:{},...h?.externalDir?{externalDir:h.externalDir}:{}}),Re=n=>I.analyzeImportSources(n.files,{sourceFormat:t==="auto"?void 0:t,mainFile:f??void 0}),Ue=n=>{$.current=!0,se.cancel?.(),j(n?{name:"sources",prepared:n}:{name:"upload"})},Ye=async n=>{$.current=!1,j({name:"processing"}),await ke();try{const a=Re(n).extraRoots.map(c=>({path:c.path,include:B[c.path]?.include??!0,level:B[c.path]?.level})),N=await se.convertPrepared(n,{...Ne(),sourceFormat:t==="auto"?void 0:t,mainFile:f??void 0,attachRoots:a});"pretextError"in N?j({name:"error",message:N.pretextError}):j({name:"review",result:N})}catch(x){if($.current)return;j({name:"error",message:x instanceof Error?x.message:"An unexpected error occurred."})}},ye=async(n,x)=>{const a=x??A.routeEngine(k,n.name);if(!a){J(n),j({name:"error",message:A.unsupportedFileMessage(n.name,k)});return}J(n),ve(a.id),Ce(),$.current=!1,j({name:"processing"}),await ke();try{if(a.prepare&&a.convertPrepared){const c=await a.prepare(n);if(te(c),l("auto"),g(null),O({}),et(c.analysis)){j({name:"sources",prepared:c});return}await ke();const M=await a.convertPrepared(c,Ne());j("pretextError"in M?{name:"error",message:M.pretextError}:{name:"review",result:M});return}te(null);const N=await a.convertFile(n,Ne());"pretextError"in N?j({name:"error",message:N.pretextError}):j({name:"review",result:N})}catch(N){if($.current)return;j({name:"error",message:N instanceof Error?N.message:"An unexpected error occurred."})}},Ce=()=>{me(p),le(!1),Q(new Set),de(new Set),V(null),P(null),ne([])},we=()=>{j({name:"upload"}),Ce(),te(null),J(null)},_e=()=>{G&&pe&&ye(G,pe)};function Ae(n,x){return[...n].sort((a,N)=>a===x?-1:N===x?1:a.localeCompare(N))}function Fe(n,x){const a=A.filesForImportMode(n,x),N=x==="converted"?n.projectLayout.mainSourcePath:n.sourcePath,c=Ae(Object.keys(a),N)[0];Q(c?new Set([c]):new Set)}function ze(n){Q(x=>{const a=new Set(x);return a.has(n)?a.delete(n):a.add(n),a})}if(w.name==="processing")return e.jsx($e,{onCancel:se.cancel?()=>Ue(ee):void 0});if(w.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:w.message})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[pe?e.jsxs("button",{type:"button",onClick:_e,className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:["Try ",pe.label," Instead"]}):null,e.jsx("button",{type:"button",onClick:we,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})]})]});if(w.name==="sources"){const n=w.prepared,x=Re(n),a=x.manifest,N=x.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:[n.fileName," contains more than one possible starting point."]})]}),a?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 ",a.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:"," ",a.targets.map(c=>c.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:t,onChange:c=>{l(c.currentTarget.value),g(null),O({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",x.primary?` (${Le[x.primary.format]})`:""]}),x.formats.map(c=>e.jsx("option",{value:c,children:Le[c]},c))]})]})}),x.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:x.candidates.map(c=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:c.path,checked:N===c.path,onChange:()=>{g(c.path),O({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:c.path}),e.jsx("span",{className:"block text-slate-500",children:Qe(c)})]})]},c.path))})]}):null,x.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:x.extraRoots.map(c=>{const M=B[c.path],X=M?.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:X,onChange:Z=>O(U=>({...U,[c.path]:{...U[c.path],include:Z.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:c.path}),c.title?e.jsxs("span",{className:"text-slate-500",children:["— ",c.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:M?.level??"auto",disabled:!X,onChange:Z=>O(U=>({...U,[c.path]:{include:U[c.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"})]})]})]},c.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:we,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Ye(n),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(w.name==="review"){let n=function(s){me(s),y?.(s),z&&Fe(a,s)},x=function(s){de(S=>{const re=new Set(S);return re.has(s)?re.delete(s):re.add(s),re})};const a=he??w.result,N=a.splitLevel,c=_.length>0,M=A.hasNativeImportMode(a)&&!c,X=M?A.resolveImportMode(a,ue):"converted",Z=a.detectedSourceFormat==="markdown"?"Markdown":"LaTeX",U=a.warnings.length,Be=Object.keys(a.outputFiles).length,Y=a.insert,fe=a.destination.kind==="insert"?a.destination.targetTag:void 0,We=h?.targetTags??[...I.DIVISION_LADDER],Se=A.filesForImportMode(a,X),qe=X==="converted"?a.projectLayout.mainSourcePath:a.sourcePath,be=Ae(Object.keys(Se),qe);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:a.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:Be}),h?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Destination"}),e.jsxs("dd",{className:"font-medium text-slate-900",children:["Inserted into ",h.documentLabel]})]}):null,a.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,a.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:a.attachedRoots.map(s=>`${s.title} (${s.level})`).join(", ")})]}):null]})]}),W?e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-lg border border-slate-200 p-4 text-sm",children:[e.jsx("input",{type:"checkbox",checked:Te,onChange:_e,className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Convert with ",W.label," instead"]}),e.jsx("span",{className:"block text-slate-500",children:W.description??`Runs ${a.sourceName} through ${W.label} and rebuilds this preview.`})]})]}):null,U>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:[U," conversion"," ",U===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:a.warnings.map((s,S)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:s.macro})," — ",s.action==="replace"||s.action==="rewrite"?`replaced with \`${s.replacement}\``:s.message??s.action,s.occurrences>1?` (×${s.occurrences})`:null]},S))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),M&&!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:X==="converted",onChange:()=>n("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:X==="native",onChange:()=>n("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Keep as ",Z]}),e.jsxs("span",{className:"block text-slate-500",children:["Preserve the original ",Z," source. The conversion will not be applied."]})]})]})]})]}):null,je.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:"Divisions to import"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("button",{type:"button",onClick:()=>ne([]),className:"rounded border border-slate-300 px-3 py-1 text-slate-700 hover:bg-slate-50",children:"Everything"}),e.jsx("span",{className:"text-slate-500",children:_.length===0?"The whole document":`${_.length} of ${Me(je)} divisions`})]}),e.jsx("div",{className:"mt-3 max-h-56 overflow-auto",children:e.jsx(Xe,{items:je,selection:_,onToggle:s=>ne(S=>S.includes(s)?S.filter(re=>re!==s):[...S,s].sort(st))})}),_.length>0?e.jsxs("p",{className:"mt-2 text-sm text-slate-500",children:["A selected division is imported whole, with everything inside it. Divisions above one you selected are kept as structure.",A.hasNativeImportMode(w.result)?" Selecting divisions imports the converted PreTeXt; keeping the original source imports the document whole.":""]}):null]}):null,Y&&h?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsxs("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:["Attach to ",h.documentLabel]}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:We.map(s=>e.jsxs("button",{type:"button",onClick:()=>P(s),"aria-pressed":fe===s,className:fe===s?"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:["<",s,">"]},s))}),e.jsxs("p",{className:"mt-3 text-sm text-slate-600",children:[Y.includes.length===1?`One <${fe}> is added to ${h.documentLabel}, `:`${Y.includes.length} <${fe}> divisions are added to ${h.documentLabel}, `,Y.includes.length===1?"included from a new file beside it.":"each included from a new file beside it."]}),Y.renamed.length>0?e.jsxs("p",{className:"mt-2 text-sm text-amber-700",children:[Y.renamed.length," id",Y.renamed.length===1?"":"s"," already used in this project"," ",Y.renamed.length===1?"was":"were"," renamed:"," ",e.jsx("span",{className:"font-mono text-xs",children:Y.renamed.map(s=>`${s.from} → ${s.to}`).join(", ")})]}):null]}):null,!u&&a.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:I.MAX_SUGGESTED_SPLIT_LEVEL+1},(s,S)=>e.jsx("button",{type:"button",onClick:()=>V(S),"aria-pressed":N===S,className:N===S?"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:S===0?"One file":`${S} level${S===1?"":"s"}`},S)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[be.length," file",be.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:be.map(s=>e.jsxs("li",{className:"truncate py-0.5",children:[s,q.get(s)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[q.get(s).fixCount," change",q.get(s).fixCount===1?"":"s"]}):null]},s))})]}):null,z?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:be.map(s=>{const S=xe.has(s);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>ze(s),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:S?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:s}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(Se[s].length/1024).toFixed(1)," KB"]})]}),S?e.jsxs("div",{className:"bg-white",children:[q.get(s)?.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:()=>x(s),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:ie.has(s)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",q.get(s).stats.added," −",q.get(s).stats.removed," in the LaTeX source"]})]}):null,ie.has(s)&&q.has(s)?e.jsx(rt,{hunks:q.get(s).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:Se[s]})]}):null]},s)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:i??we,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:i?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[ee?e.jsx("button",{type:"button",onClick:()=>j({name:"sources",prepared:ee}),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:()=>{z||Fe(a,X),le(s=>!s)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:z?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:v,onClick:async()=>{L(!0);try{await r(a,X)}finally{L(!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?h?"Inserting…":"Importing…":h?"Confirm Insert":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[u?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:D,onChange:n=>K(n.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:n=>n.key==="Enter"&&E.current?.click(),onClick:()=>E.current?.click(),onDragOver:n=>{n.preventDefault(),T(!0)},onDragLeave:()=>T(!1),onDrop:n=>{n.preventDefault(),T(!1);const x=n.dataTransfer.files?.[0];x&&ye(x)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${F?"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:n=>{n.stopPropagation(),E.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:E,type:"file",hidden:!0,accept:Ee.join(","),onChange:n=>{const x=n.currentTarget.files?.[0];x&&ye(x),n.currentTarget.value=""}})]})]})}function Me(r){return r.reduce((i,u)=>i+1+Me(u.children),0)}function st(r,i){const u=r.split(".").map(Number),m=i.split(".").map(Number);for(let p=0;p<Math.max(u.length,m.length);p++){const d=(u[p]??-1)-(m[p]??-1);if(d!==0)return d}return 0}function Xe({items:r,selection:i,onToggle:u}){return e.jsx("ul",{className:"space-y-0.5 text-sm",children:r.map(m=>{const p=i.includes(m.path),d=i.some(y=>m.path.startsWith(`${y}.`));return e.jsxs("li",{children:[e.jsxs("label",{className:"flex items-baseline gap-2",children:[e.jsx("input",{type:"checkbox",checked:p||d,disabled:d,onChange:()=>u(m.path)}),e.jsxs("span",{className:d?"text-slate-400":"text-slate-700",children:[m.title||e.jsx("em",{children:"Untitled"}),e.jsxs("span",{className:"ml-2 font-mono text-xs text-slate-400",children:["<",m.tag,">"]})]})]}),m.children.length>0?e.jsx("div",{className:"ml-5 border-l border-slate-200 pl-3",children:e.jsx(Xe,{items:m.children,selection:i,onToggle:u})}):null]},m.path)})})}function rt({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((i,u)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[u>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,i.lines.map((m,p)=>e.jsxs("div",{className:m.op==="add"?"bg-green-50 px-4 text-green-900":m.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:m.op==="add"?"+":m.op==="remove"?"−":" "}),m.text||" "]},p))]},u))})}const nt={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 at({initialSource:r="",initialSourceFormat:i,labels:u,disabled:m=!1,onImport:p}){const d=o.useMemo(()=>({...nt,...u??{}}),[u]),[y,R]=o.useState(r),[h,k]=o.useState(i??"auto"),[E,w]=o.useState(null),j=o.useMemo(()=>I.detectSourceFormat(y),[y]),F=m||!y.trim();return e.jsx("form",{onSubmit:T=>{T.preventDefault();const D=I.convertSourceToPretext(y,h==="auto"?void 0:h);w(D),p(D)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:m,children:[e.jsx("legend",{children:d.title}),e.jsx("p",{children:d.description}),e.jsxs("label",{children:[d.sourceLabel,e.jsx("textarea",{value:y,onChange:T=>R(T.currentTarget.value),placeholder:d.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[d.formatLabel,e.jsxs("select",{value:h,onChange:T=>k(T.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:[d.detectedFormatPrefix,": ",e.jsx("strong",{children:j})]}),e.jsx("button",{type:"submit",disabled:F,children:d.convertButton}),E?"pretextError"in E?e.jsxs("p",{role:"alert",children:[d.errorPrefix,": ",E.pretextError]}):e.jsxs("p",{children:[d.successPrefix,": ",E.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const lt={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 ot({labels:r,disabled:i=!1,defaultDocumentKind:u="auto",importOptions:m,onImport:p}){const d=o.useMemo(()=>({...lt,...r??{}}),[r]),y=o.useRef(null),[R,h]=o.useState(!1),[k,E]=o.useState(!1),[w,j]=o.useState([]),[F,T]=o.useState(u),[D,K]=o.useState(!1),C=i||k,V=async b=>{E(!0);try{const P=m??{documentKind:F==="auto"?void 0:F,splitSections:D},_=await I.handleImportUploadFile(b,P);j(_.statusMessages),p(_)}finally{E(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:d.title}),e.jsx("p",{children:d.hint}),m?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[d.documentKindLabel,e.jsxs("select",{value:F,disabled:C,onChange:b=>T(b.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:D,disabled:C,onChange:b=>K(b.currentTarget.checked)}),d.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:b=>{b.preventDefault(),C||h(!0)},onDragLeave:()=>h(!1),onDrop:b=>{if(b.preventDefault(),h(!1),C)return;const P=b.dataTransfer.files?.[0];P&&V(P)},children:[e.jsx("p",{children:d.dropHint}),e.jsxs("button",{type:"button",disabled:C,onClick:()=>y.current?.click(),className:"inline-flex items-center gap-2",children:[k?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,k?"Processing…":d.selectButton]}),e.jsx("input",{ref:y,type:"file",hidden:!0,disabled:C,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:b=>{const P=b.currentTarget.files?.[0];P&&V(P),b.currentTarget.value=""}})]}),k?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,w.length>0?e.jsx("ul",{"aria-live":"polite",children:w.map((b,P)=>e.jsx("li",{children:b.message},`${b.type}-${P}`))}):null,R&&!C?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=at;exports.ImportUploadPanel=ot;exports.ImportWizard=tt;exports.ProcessingPanel=$e;
|
|
6
|
+
<%s key={someKey} {...props} />`,g,v,L,v),te[v+g]=!0)}if(v=null,f!==void 0&&(u(f),v=""+f),y(l)&&(u(l.key),v=""+l.key),"key"in l){f={};for(var $ in l)$!=="key"&&(f[$]=l[$])}else f=l;return v&&R(f,typeof t=="function"?t.displayName||t.name||"Unknown":t),k(t,v,f,p(),B,O)}function w(t){j(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===ae&&(t._payload.status==="fulfilled"?j(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function j(t){return typeof t=="object"&&t!==null&&t.$$typeof===T}var F=o,T=Symbol.for("react.transitional.element"),D=Symbol.for("react.portal"),K=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),b=Symbol.for("react.consumer"),P=Symbol.for("react.context"),_=Symbol.for("react.forward_ref"),ne=Symbol.for("react.suspense"),ie=Symbol.for("react.suspense_list"),de=Symbol.for("react.memo"),ae=Symbol.for("react.lazy"),ve=Symbol.for("react.activity"),G=Symbol.for("react.client.reference"),J=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ue=Object.prototype.hasOwnProperty,me=Array.isArray,z=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(t){return t()}};var le,xe={},Q=F.react_stack_bottom_frame.bind(F,d)(),ee=z(m(d)),te={};ce.Fragment=K,ce.jsx=function(t,l,f){var g=1e4>J.recentlyCreatedOwnerStacks++;return E(t,l,f,!1,g?Error("react-stack-top-frame"):Q,g?z(m(t)):ee)},ce.jsxs=function(t,l,f){var g=1e4>J.recentlyCreatedOwnerStacks++;return E(t,l,f,!0,g?Error("react-stack-top-frame"):Q,g?z(m(t)):ee)}})()),ce}var Oe;function Ge(){return Oe||(Oe=1,process.env.NODE_ENV==="production"?ge.exports=Ke():ge.exports=Ve()),ge.exports}var e=Ge();function Je(){const[r,i]=o.useState(0),u=o.useRef(Date.now());return o.useEffect(()=>{const m=setInterval(()=>{i(Math.floor((Date.now()-u.current)/1e3))},1e3);return()=>clearInterval(m)},[]),r}function He(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function $e({message:r="Processing your file…",onCancel:i}){const u=Je();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:He(u)}),u>=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,i?e.jsx("button",{type:"button",onClick:i,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 Ze={id:"builtin",label:"Built-in converter",description:"Converts LaTeX, Markdown, and PreTeXt without any other tools.",acceptExtensions:A.DEFAULT_ACCEPT_EXTENSIONS,convertFile:I.handleImportUploadFile,prepare:async r=>{const{files:i,assets:u}=await I.extractUpload(r);return{fileName:r.name,files:i,assets:u,analysis:I.analyzeImportSources(i)}},convertPrepared:(r,i)=>I.importProjectFromFiles(r.files,{...i,assets:r.assets})};function ke(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const Le={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function Qe(r){const i=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} — ${i}`:i}function et(r){return r.candidates.filter(u=>u.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 tt({onConfirm:r,onCancel:i,importOptions:u,defaultDocumentKind:m="auto",defaultImportMode:p=A.DEFAULT_IMPORT_MODE,lockImportMode:d=!1,onImportModeChange:y,engines:R,insertTarget:h}){const k=R&&R.length>0?R:[Ze],E=o.useRef(null),[w,j]=o.useState({name:"upload"}),[F,T]=o.useState(!1),[D,K]=o.useState(m),[C,V]=o.useState(null),[b,P]=o.useState(null),[_,ne]=o.useState([]),[ie,de]=o.useState(new Set),[ae,ve]=o.useState(k[0].id),[G,J]=o.useState(null),[ue,me]=o.useState(p),[z,le]=o.useState(!1),[xe,Q]=o.useState(new Set),[ee,te]=o.useState(null),[t,l]=o.useState("auto"),[f,g]=o.useState(null),[B,O]=o.useState({}),[v,L]=o.useState(!1),$=o.useRef(!1),se=k.find(n=>n.id===ae)??k[0],Ee=A.allAcceptExtensions(k),W=G?A.alternateFor(k,G.name):void 0,Te=W?se.id===W.id:!1,pe=W?Te?A.routeEngine(k,G.name)??null:W:null,H=w.name==="review"?w.result:null,he=o.useMemo(()=>H&&(C!==null||b!==null||_.length>0)?I.rebuildImport(H,{splitLevel:C??void 0,targetTag:b??void 0,selection:_}):H,[H,C,b,_]),je=o.useMemo(()=>H?I.outlineDivisions(H.pretextSource):[],[H]),q=o.useMemo(()=>new Map(he?A.fileChangesForImport(he).map(n=>[n.path,n]):[]),[he]),Pe=o.useMemo(()=>h?{kind:"insert",targetTag:b??h.defaultTargetTag,takenIds:new Set(h.takenIds),hrefBase:h.hrefBase}:void 0,[h,b]),Ne=()=>({...u??{documentKind:D==="auto"?void 0:D},...Pe?{destination:Pe}:{},...h?.externalDir?{externalDir:h.externalDir}:{}}),Re=n=>I.analyzeImportSources(n.files,{sourceFormat:t==="auto"?void 0:t,mainFile:f??void 0}),Ue=n=>{$.current=!0,se.cancel?.(),j(n?{name:"sources",prepared:n}:{name:"upload"})},Ye=async n=>{$.current=!1,j({name:"processing"}),await ke();try{const a=Re(n).extraRoots.map(c=>({path:c.path,include:B[c.path]?.include??!0,level:B[c.path]?.level})),N=await se.convertPrepared(n,{...Ne(),sourceFormat:t==="auto"?void 0:t,mainFile:f??void 0,attachRoots:a});"pretextError"in N?j({name:"error",message:N.pretextError}):j({name:"review",result:N})}catch(x){if($.current)return;j({name:"error",message:x instanceof Error?x.message:"An unexpected error occurred."})}},ye=async(n,x)=>{const a=x??A.routeEngine(k,n.name);if(!a){J(n),j({name:"error",message:A.unsupportedFileMessage(n.name,k)});return}J(n),ve(a.id),Ce(),$.current=!1,j({name:"processing"}),await ke();try{if(a.prepare&&a.convertPrepared){const c=await a.prepare(n);if(te(c),l("auto"),g(null),O({}),et(c.analysis)){j({name:"sources",prepared:c});return}await ke();const M=await a.convertPrepared(c,Ne());j("pretextError"in M?{name:"error",message:M.pretextError}:{name:"review",result:M});return}te(null);const N=await a.convertFile(n,Ne());"pretextError"in N?j({name:"error",message:N.pretextError}):j({name:"review",result:N})}catch(N){if($.current)return;j({name:"error",message:N instanceof Error?N.message:"An unexpected error occurred."})}},Ce=()=>{me(p),le(!1),Q(new Set),de(new Set),V(null),P(null),ne([])},we=()=>{j({name:"upload"}),Ce(),te(null),J(null)},_e=()=>{G&&pe&&ye(G,pe)};function Ae(n,x){return[...n].sort((a,N)=>a===x?-1:N===x?1:a.localeCompare(N))}function Fe(n,x){const a=A.filesForImportMode(n,x),N=x==="converted"?n.projectLayout.mainSourcePath:n.sourcePath,c=Ae(Object.keys(a),N)[0];Q(c?new Set([c]):new Set)}function ze(n){Q(x=>{const a=new Set(x);return a.has(n)?a.delete(n):a.add(n),a})}if(w.name==="processing")return e.jsx($e,{onCancel:se.cancel?()=>Ue(ee):void 0});if(w.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:w.message})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[pe?e.jsxs("button",{type:"button",onClick:_e,className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:["Try ",pe.label," Instead"]}):null,e.jsx("button",{type:"button",onClick:we,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})]})]});if(w.name==="sources"){const n=w.prepared,x=Re(n),a=x.manifest,N=x.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:[n.fileName," contains more than one possible starting point."]})]}),a?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 ",a.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:"," ",a.targets.map(c=>c.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:t,onChange:c=>{l(c.currentTarget.value),g(null),O({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",x.primary?` (${Le[x.primary.format]})`:""]}),x.formats.map(c=>e.jsx("option",{value:c,children:Le[c]},c))]})]})}),x.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:x.candidates.map(c=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:c.path,checked:N===c.path,onChange:()=>{g(c.path),O({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:c.path}),e.jsx("span",{className:"block text-slate-500",children:Qe(c)})]})]},c.path))})]}):null,x.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:x.extraRoots.map(c=>{const M=B[c.path],X=M?.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:X,onChange:Z=>O(U=>({...U,[c.path]:{...U[c.path],include:Z.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:c.path}),c.title?e.jsxs("span",{className:"text-slate-500",children:["— ",c.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:M?.level??"auto",disabled:!X,onChange:Z=>O(U=>({...U,[c.path]:{include:U[c.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"})]})]})]},c.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:we,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Ye(n),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(w.name==="review"){let n=function(s){me(s),y?.(s),z&&Fe(a,s)},x=function(s){de(S=>{const re=new Set(S);return re.has(s)?re.delete(s):re.add(s),re})};const a=he??w.result,N=a.splitLevel,c=_.length>0,M=A.hasNativeImportMode(a)&&!c,X=M?A.resolveImportMode(a,ue):"converted",Z=a.detectedSourceFormat==="markdown"?"Markdown":"LaTeX",U=a.warnings.length,Be=Object.keys(a.outputFiles).length,Y=a.insert,fe=a.destination.kind==="insert"?a.destination.targetTag:void 0,We=h?.targetTags??[...I.DIVISION_LADDER],Se=A.filesForImportMode(a,X),qe=X==="converted"?a.projectLayout.mainSourcePath:a.sourcePath,be=Ae(Object.keys(Se),qe);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:a.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:Be}),h?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Destination"}),e.jsxs("dd",{className:"font-medium text-slate-900",children:["Inserted into ",h.documentLabel]})]}):null,a.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,a.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:a.attachedRoots.map(s=>`${s.title} (${s.level})`).join(", ")})]}):null]})]}),W?e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-lg border border-slate-200 p-4 text-sm",children:[e.jsx("input",{type:"checkbox",checked:Te,onChange:_e,className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Convert with ",W.label," instead"]}),e.jsx("span",{className:"block text-slate-500",children:W.description??`Runs ${a.sourceName} through ${W.label} and rebuilds this preview.`})]})]}):null,U>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:[U," conversion"," ",U===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:a.warnings.map((s,S)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:s.macro})," — ",s.action==="replace"||s.action==="rewrite"?`replaced with \`${s.replacement}\``:s.message??s.action,s.occurrences>1?` (×${s.occurrences})`:null]},S))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),M&&!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:X==="converted",onChange:()=>n("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:X==="native",onChange:()=>n("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Keep as ",Z]}),e.jsxs("span",{className:"block text-slate-500",children:["Preserve the original ",Z," source. The conversion will not be applied."]})]})]})]})]}):null,je.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:"Divisions to import"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("button",{type:"button",onClick:()=>ne([]),className:"rounded border border-slate-300 px-3 py-1 text-slate-700 hover:bg-slate-50",children:"Everything"}),e.jsx("span",{className:"text-slate-500",children:_.length===0?"The whole document":`${_.length} of ${Me(je)} divisions`})]}),e.jsx("div",{className:"mt-3 max-h-56 overflow-auto",children:e.jsx(Xe,{items:je,selection:_,onToggle:s=>ne(S=>S.includes(s)?S.filter(re=>re!==s):[...S,s].sort(st))})}),_.length>0?e.jsxs("p",{className:"mt-2 text-sm text-slate-500",children:["A selected division is imported whole, with everything inside it. Divisions above one you selected are kept as structure.",A.hasNativeImportMode(w.result)?" Selecting divisions imports the converted PreTeXt; keeping the original source imports the document whole.":""]}):null]}):null,Y&&h?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsxs("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:["Attach to ",h.documentLabel]}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:We.map(s=>e.jsxs("button",{type:"button",onClick:()=>P(s),"aria-pressed":fe===s,className:fe===s?"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:["<",s,">"]},s))}),e.jsxs("p",{className:"mt-3 text-sm text-slate-600",children:[Y.includes.length===1?`One <${fe}> is added to ${h.documentLabel}, `:`${Y.includes.length} <${fe}> divisions are added to ${h.documentLabel}, `,Y.includes.length===1?"included from a new file beside it.":"each included from a new file beside it."]}),Y.renamed.length>0?e.jsxs("p",{className:"mt-2 text-sm text-amber-700",children:[Y.renamed.length," id",Y.renamed.length===1?"":"s"," already used in this project"," ",Y.renamed.length===1?"was":"were"," renamed:"," ",e.jsx("span",{className:"font-mono text-xs",children:Y.renamed.map(s=>`${s.from} → ${s.to}`).join(", ")})]}):null]}):null,!u&&a.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:I.MAX_SUGGESTED_SPLIT_LEVEL+1},(s,S)=>e.jsx("button",{type:"button",onClick:()=>V(S),"aria-pressed":N===S,className:N===S?"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:S===0?"One file":`${S} level${S===1?"":"s"}`},S)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[be.length," file",be.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:be.map(s=>e.jsxs("li",{className:"truncate py-0.5",children:[s,q.get(s)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[q.get(s).fixCount," change",q.get(s).fixCount===1?"":"s"]}):null]},s))})]}):null,z?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:be.map(s=>{const S=xe.has(s);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>ze(s),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:S?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:s}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(Se[s].length/1024).toFixed(1)," KB"]})]}),S?e.jsxs("div",{className:"bg-white",children:[q.get(s)?.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:()=>x(s),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:ie.has(s)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",q.get(s).stats.added," −",q.get(s).stats.removed," in the LaTeX source"]})]}):null,ie.has(s)&&q.has(s)?e.jsx(rt,{hunks:q.get(s).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:Se[s]})]}):null]},s)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:i??we,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:i?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[ee?e.jsx("button",{type:"button",onClick:()=>j({name:"sources",prepared:ee}),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:()=>{z||Fe(a,X),le(s=>!s)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:z?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:v,onClick:async()=>{L(!0);try{await r(a,X)}finally{L(!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?h?"Inserting…":"Importing…":h?"Confirm Insert":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[u?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:D,onChange:n=>K(n.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.jsx("option",{value:"slideshow",children:"Slides"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:n=>n.key==="Enter"&&E.current?.click(),onClick:()=>E.current?.click(),onDragOver:n=>{n.preventDefault(),T(!0)},onDragLeave:()=>T(!1),onDrop:n=>{n.preventDefault(),T(!1);const x=n.dataTransfer.files?.[0];x&&ye(x)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${F?"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:n=>{n.stopPropagation(),E.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:E,type:"file",hidden:!0,accept:Ee.join(","),onChange:n=>{const x=n.currentTarget.files?.[0];x&&ye(x),n.currentTarget.value=""}})]})]})}function Me(r){return r.reduce((i,u)=>i+1+Me(u.children),0)}function st(r,i){const u=r.split(".").map(Number),m=i.split(".").map(Number);for(let p=0;p<Math.max(u.length,m.length);p++){const d=(u[p]??-1)-(m[p]??-1);if(d!==0)return d}return 0}function Xe({items:r,selection:i,onToggle:u}){return e.jsx("ul",{className:"space-y-0.5 text-sm",children:r.map(m=>{const p=i.includes(m.path),d=i.some(y=>m.path.startsWith(`${y}.`));return e.jsxs("li",{children:[e.jsxs("label",{className:"flex items-baseline gap-2",children:[e.jsx("input",{type:"checkbox",checked:p||d,disabled:d,onChange:()=>u(m.path)}),e.jsxs("span",{className:d?"text-slate-400":"text-slate-700",children:[m.title||e.jsx("em",{children:"Untitled"}),e.jsxs("span",{className:"ml-2 font-mono text-xs text-slate-400",children:["<",m.tag,">"]})]})]}),m.children.length>0?e.jsx("div",{className:"ml-5 border-l border-slate-200 pl-3",children:e.jsx(Xe,{items:m.children,selection:i,onToggle:u})}):null]},m.path)})})}function rt({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((i,u)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[u>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,i.lines.map((m,p)=>e.jsxs("div",{className:m.op==="add"?"bg-green-50 px-4 text-green-900":m.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:m.op==="add"?"+":m.op==="remove"?"−":" "}),m.text||" "]},p))]},u))})}const nt={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 at({initialSource:r="",initialSourceFormat:i,labels:u,disabled:m=!1,onImport:p}){const d=o.useMemo(()=>({...nt,...u??{}}),[u]),[y,R]=o.useState(r),[h,k]=o.useState(i??"auto"),[E,w]=o.useState(null),j=o.useMemo(()=>I.detectSourceFormat(y),[y]),F=m||!y.trim();return e.jsx("form",{onSubmit:T=>{T.preventDefault();const D=I.convertSourceToPretext(y,h==="auto"?void 0:h);w(D),p(D)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:m,children:[e.jsx("legend",{children:d.title}),e.jsx("p",{children:d.description}),e.jsxs("label",{children:[d.sourceLabel,e.jsx("textarea",{value:y,onChange:T=>R(T.currentTarget.value),placeholder:d.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[d.formatLabel,e.jsxs("select",{value:h,onChange:T=>k(T.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:[d.detectedFormatPrefix,": ",e.jsx("strong",{children:j})]}),e.jsx("button",{type:"submit",disabled:F,children:d.convertButton}),E?"pretextError"in E?e.jsxs("p",{role:"alert",children:[d.errorPrefix,": ",E.pretextError]}):e.jsxs("p",{children:[d.successPrefix,": ",E.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const lt={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 ot({labels:r,disabled:i=!1,defaultDocumentKind:u="auto",importOptions:m,onImport:p}){const d=o.useMemo(()=>({...lt,...r??{}}),[r]),y=o.useRef(null),[R,h]=o.useState(!1),[k,E]=o.useState(!1),[w,j]=o.useState([]),[F,T]=o.useState(u),[D,K]=o.useState(!1),C=i||k,V=async b=>{E(!0);try{const P=m??{documentKind:F==="auto"?void 0:F,splitSections:D},_=await I.handleImportUploadFile(b,P);j(_.statusMessages),p(_)}finally{E(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:d.title}),e.jsx("p",{children:d.hint}),m?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[d.documentKindLabel,e.jsxs("select",{value:F,disabled:C,onChange:b=>T(b.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:D,disabled:C,onChange:b=>K(b.currentTarget.checked)}),d.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:b=>{b.preventDefault(),C||h(!0)},onDragLeave:()=>h(!1),onDrop:b=>{if(b.preventDefault(),h(!1),C)return;const P=b.dataTransfer.files?.[0];P&&V(P)},children:[e.jsx("p",{children:d.dropHint}),e.jsxs("button",{type:"button",disabled:C,onClick:()=>y.current?.click(),className:"inline-flex items-center gap-2",children:[k?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,k?"Processing…":d.selectButton]}),e.jsx("input",{ref:y,type:"file",hidden:!0,disabled:C,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:b=>{const P=b.currentTarget.files?.[0];P&&V(P),b.currentTarget.value=""}})]}),k?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,w.length>0?e.jsx("ul",{"aria-live":"polite",children:w.map((b,P)=>e.jsx("li",{children:b.message},`${b.type}-${P}`))}):null,R&&!C?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=at;exports.ImportUploadPanel=ot;exports.ImportWizard=tt;exports.ProcessingPanel=$e;
|
package/dist/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import He, { useState as h, useRef as ge, useEffect as Ze, useMemo as H } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { D as ot, a as ct, b as it, d as dt, q as De, k as ut, n as Oe, r as mt, l as Le, u as xt } from "./engine-routing-
|
|
2
|
+
import { Z as Ue, a9 as Qe, a4 as et, D as tt, n as st, k as rt, h as nt, j as Ye, N as at, H as lt } from "./upload-w0BmYtpp.js";
|
|
3
|
+
import { D as ot, a as ct, b as it, d as dt, q as De, k as ut, n as Oe, r as mt, l as Le, u as xt } from "./engine-routing-vjkGBbmx.js";
|
|
4
4
|
var be = { exports: {} }, le = {};
|
|
5
5
|
var Ie;
|
|
6
6
|
function pt() {
|
|
@@ -31,12 +31,12 @@ function ht() {
|
|
|
31
31
|
function r(t) {
|
|
32
32
|
if (t == null) return null;
|
|
33
33
|
if (typeof t == "function")
|
|
34
|
-
return t.$$typeof ===
|
|
34
|
+
return t.$$typeof === K ? null : t.displayName || t.name || null;
|
|
35
35
|
if (typeof t == "string") return t;
|
|
36
36
|
switch (t) {
|
|
37
37
|
case W:
|
|
38
38
|
return "Fragment";
|
|
39
|
-
case
|
|
39
|
+
case q:
|
|
40
40
|
return "Profiler";
|
|
41
41
|
case C:
|
|
42
42
|
return "StrictMode";
|
|
@@ -221,7 +221,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
221
221
|
function j(t) {
|
|
222
222
|
return typeof t == "object" && t !== null && t.$$typeof === S;
|
|
223
223
|
}
|
|
224
|
-
var A = He, S = /* @__PURE__ */ Symbol.for("react.transitional.element"), F = /* @__PURE__ */ Symbol.for("react.portal"), W = /* @__PURE__ */ Symbol.for("react.fragment"), C = /* @__PURE__ */ Symbol.for("react.strict_mode"),
|
|
224
|
+
var A = He, S = /* @__PURE__ */ Symbol.for("react.transitional.element"), F = /* @__PURE__ */ Symbol.for("react.portal"), W = /* @__PURE__ */ Symbol.for("react.fragment"), C = /* @__PURE__ */ Symbol.for("react.strict_mode"), q = /* @__PURE__ */ Symbol.for("react.profiler"), b = /* @__PURE__ */ Symbol.for("react.consumer"), R = /* @__PURE__ */ Symbol.for("react.context"), _ = /* @__PURE__ */ Symbol.for("react.forward_ref"), re = /* @__PURE__ */ Symbol.for("react.suspense"), ce = /* @__PURE__ */ Symbol.for("react.suspense_list"), ie = /* @__PURE__ */ Symbol.for("react.memo"), ne = /* @__PURE__ */ Symbol.for("react.lazy"), ve = /* @__PURE__ */ Symbol.for("react.activity"), K = /* @__PURE__ */ Symbol.for("react.client.reference"), V = A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, de = Object.prototype.hasOwnProperty, ue = Array.isArray, U = console.createTask ? console.createTask : function() {
|
|
225
225
|
return null;
|
|
226
226
|
};
|
|
227
227
|
A = {
|
|
@@ -356,9 +356,9 @@ function Rt({
|
|
|
356
356
|
engines: P,
|
|
357
357
|
insertTarget: p
|
|
358
358
|
}) {
|
|
359
|
-
const E = P && P.length > 0 ? P : [jt], T = ge(null), [w, j] = h({ name: "upload" }), [A, S] = h(!1), [F, W] = h(u), [C,
|
|
359
|
+
const E = P && P.length > 0 ? P : [jt], T = ge(null), [w, j] = h({ name: "upload" }), [A, S] = h(!1), [F, W] = h(u), [C, q] = h(null), [b, R] = h(null), [_, re] = h([]), [ce, ie] = h(/* @__PURE__ */ new Set()), [ne, ve] = h(E[0].id), [K, V] = h(null), [de, ue] = h(x), [U, ae] = h(!1), [me, Z] = h(/* @__PURE__ */ new Set()), [Q, ee] = h(null), [t, l] = h(
|
|
360
360
|
"auto"
|
|
361
|
-
), [f, g] = h(null), [Y, D] = h({}), [v, O] = h(!1), L = ge(!1), te = E.find((n) => n.id === ne) ?? E[0], Te = it(E), B =
|
|
361
|
+
), [f, g] = h(null), [Y, D] = h({}), [v, O] = h(!1), L = ge(!1), te = E.find((n) => n.id === ne) ?? E[0], Te = it(E), B = K ? dt(E, K.name) : void 0, Se = B ? te.id === B.id : !1, xe = B ? Se ? De(E, K.name) ?? null : B : null, G = w.name === "review" ? w.result : null, pe = H(
|
|
362
362
|
() => G && (C !== null || b !== null || _.length > 0) ? Qe(G, {
|
|
363
363
|
splitLevel: C ?? void 0,
|
|
364
364
|
targetTag: b ?? void 0,
|
|
@@ -394,7 +394,7 @@ function Rt({
|
|
|
394
394
|
L.current = !0, te.cancel?.(), j(
|
|
395
395
|
n ? { name: "sources", prepared: n } : { name: "upload" }
|
|
396
396
|
);
|
|
397
|
-
},
|
|
397
|
+
}, qe = async (n) => {
|
|
398
398
|
L.current = !1, j({ name: "processing" }), await Ee();
|
|
399
399
|
try {
|
|
400
400
|
const a = Ce(n).extraRoots.map((o) => ({
|
|
@@ -452,11 +452,11 @@ function Rt({
|
|
|
452
452
|
});
|
|
453
453
|
}
|
|
454
454
|
}, Re = () => {
|
|
455
|
-
ue(x), ae(!1), Z(/* @__PURE__ */ new Set()), ie(/* @__PURE__ */ new Set()),
|
|
455
|
+
ue(x), ae(!1), Z(/* @__PURE__ */ new Set()), ie(/* @__PURE__ */ new Set()), q(null), R(null), re([]);
|
|
456
456
|
}, we = () => {
|
|
457
457
|
j({ name: "upload" }), Re(), ee(null), V(null);
|
|
458
458
|
}, _e = () => {
|
|
459
|
-
|
|
459
|
+
K && xe && ye(K, xe);
|
|
460
460
|
};
|
|
461
461
|
function Ae(n, m) {
|
|
462
462
|
return [...n].sort((a, N) => a === m ? -1 : N === m ? 1 : a.localeCompare(N));
|
|
@@ -465,7 +465,7 @@ function Rt({
|
|
|
465
465
|
const a = Le(n, m), N = m === "converted" ? n.projectLayout.mainSourcePath : n.sourcePath, o = Ae(Object.keys(a), N)[0];
|
|
466
466
|
Z(o ? /* @__PURE__ */ new Set([o]) : /* @__PURE__ */ new Set());
|
|
467
467
|
}
|
|
468
|
-
function
|
|
468
|
+
function Ke(n) {
|
|
469
469
|
Z((m) => {
|
|
470
470
|
const a = new Set(m);
|
|
471
471
|
return a.has(n) ? a.delete(n) : a.add(n), a;
|
|
@@ -655,7 +655,7 @@ function Rt({
|
|
|
655
655
|
"button",
|
|
656
656
|
{
|
|
657
657
|
type: "button",
|
|
658
|
-
onClick: () =>
|
|
658
|
+
onClick: () => qe(n),
|
|
659
659
|
className: "rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",
|
|
660
660
|
children: "Continue"
|
|
661
661
|
}
|
|
@@ -858,7 +858,7 @@ function Rt({
|
|
|
858
858
|
"button",
|
|
859
859
|
{
|
|
860
860
|
type: "button",
|
|
861
|
-
onClick: () =>
|
|
861
|
+
onClick: () => q(k),
|
|
862
862
|
"aria-pressed": N === k,
|
|
863
863
|
className: N === k ? "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",
|
|
864
864
|
children: k === 0 ? "One file" : `${k} level${k === 1 ? "" : "s"}`
|
|
@@ -892,7 +892,7 @@ function Rt({
|
|
|
892
892
|
"button",
|
|
893
893
|
{
|
|
894
894
|
type: "button",
|
|
895
|
-
onClick: () =>
|
|
895
|
+
onClick: () => Ke(s),
|
|
896
896
|
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",
|
|
897
897
|
children: [
|
|
898
898
|
/* @__PURE__ */ e.jsx("span", { className: "shrink-0 text-slate-400", children: k ? "▾" : "▸" }),
|
|
@@ -999,7 +999,8 @@ function Rt({
|
|
|
999
999
|
children: [
|
|
1000
1000
|
/* @__PURE__ */ e.jsx("option", { value: "auto", children: "Auto detect" }),
|
|
1001
1001
|
/* @__PURE__ */ e.jsx("option", { value: "article", children: "Article" }),
|
|
1002
|
-
/* @__PURE__ */ e.jsx("option", { value: "book", children: "Book" })
|
|
1002
|
+
/* @__PURE__ */ e.jsx("option", { value: "book", children: "Book" }),
|
|
1003
|
+
/* @__PURE__ */ e.jsx("option", { value: "slideshow", children: "Slides" })
|
|
1003
1004
|
]
|
|
1004
1005
|
}
|
|
1005
1006
|
)
|
|
@@ -1241,7 +1242,7 @@ function At({
|
|
|
1241
1242
|
[r]
|
|
1242
1243
|
), y = ge(null), [P, p] = h(!1), [E, T] = h(!1), [w, j] = h(
|
|
1243
1244
|
[]
|
|
1244
|
-
), [A, S] = h(d), [F, W] = h(!1), C = c || E,
|
|
1245
|
+
), [A, S] = h(d), [F, W] = h(!1), C = c || E, q = async (b) => {
|
|
1245
1246
|
T(!0);
|
|
1246
1247
|
try {
|
|
1247
1248
|
const _ = await Ue(b, u ?? {
|
|
@@ -1299,7 +1300,7 @@ function At({
|
|
|
1299
1300
|
if (b.preventDefault(), p(!1), C)
|
|
1300
1301
|
return;
|
|
1301
1302
|
const R = b.dataTransfer.files?.[0];
|
|
1302
|
-
R &&
|
|
1303
|
+
R && q(R);
|
|
1303
1304
|
},
|
|
1304
1305
|
children: [
|
|
1305
1306
|
/* @__PURE__ */ e.jsx("p", { children: i.dropHint }),
|
|
@@ -1332,7 +1333,7 @@ function At({
|
|
|
1332
1333
|
accept: ".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",
|
|
1333
1334
|
onChange: (b) => {
|
|
1334
1335
|
const R = b.currentTarget.files?.[0];
|
|
1335
|
-
R &&
|
|
1336
|
+
R && q(R), b.currentTarget.value = "";
|
|
1336
1337
|
}
|
|
1337
1338
|
}
|
|
1338
1339
|
)
|