@pretextbook/import 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/convert-worker.cjs +1 -0
- package/dist/convert-worker.js +29 -0
- package/dist/import-mode-GqdypBfV.js +112 -0
- package/dist/import-mode-YW6Lr4SU.cjs +3 -0
- package/dist/import.css +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +11 -3
- package/dist/index.js +256 -150
- package/dist/lib/clean/clean-chunks.d.ts +47 -0
- package/dist/lib/clean/clean-latex.d.ts +35 -1
- package/dist/lib/convert.d.ts +7 -0
- package/dist/lib/diff.d.ts +36 -0
- package/dist/lib/file-changes.d.ts +22 -0
- package/dist/lib/latex-split.d.ts +86 -0
- package/dist/lib/pool/native-pool.d.ts +6 -0
- package/dist/lib/pool/serialize-files.d.ts +6 -0
- package/dist/lib/types.d.ts +14 -0
- package/dist/lib/upload.d.ts +27 -1
- package/dist/react/import-wizard.d.ts +22 -4
- package/dist/react/index.d.ts +2 -0
- package/dist/react/processing-panel.d.ts +6 -0
- package/dist/react.cjs +2 -2
- package/dist/react.js +592 -436
- package/dist/upload-BBHV4rXJ.js +7102 -0
- package/dist/upload-CGxfSSDN.cjs +135 -0
- package/dist/worker/convert-worker.d.ts +1 -0
- package/dist/worker/protocol.d.ts +30 -0
- package/dist/worker/worker-engine.d.ts +52 -0
- package/package.json +11 -5
- package/dist/import-mode-C8xFGO8j.cjs +0 -115
- package/dist/import-mode-Dc8qmZP6.js +0 -4787
- package/dist/lib/clean/latex-clean.d.ts +0 -10
- package/dist/lib/clean/latex-data.d.ts +0 -38
- package/dist/lib/clean/latex-scan.d.ts +0 -11
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { DocumentKind } from './layout/document-kind';
|
|
2
|
+
/**
|
|
3
|
+
* LaTeX's sectioning commands, outermost first. A document's own hierarchy is
|
|
4
|
+
* whichever of these it actually uses (`latexDivisionHierarchy`), so an article
|
|
5
|
+
* that starts at `\section` gets sections at depth 1 rather than an empty level
|
|
6
|
+
* standing in for the chapters it does not have.
|
|
7
|
+
*/
|
|
8
|
+
export declare const LATEX_DIVISION_COMMANDS: readonly ["part", "chapter", "section", "subsection", "subsubsection"];
|
|
9
|
+
export type LatexDivisionCommand = (typeof LATEX_DIVISION_COMMANDS)[number];
|
|
10
|
+
/** PreTeXt division tag for each LaTeX sectioning command. */
|
|
11
|
+
export declare const PRETEXT_TAG_FOR_COMMAND: Record<LatexDivisionCommand, string>;
|
|
12
|
+
export interface LatexDivision {
|
|
13
|
+
command: LatexDivisionCommand;
|
|
14
|
+
/** 1-based depth within the document's own hierarchy. */
|
|
15
|
+
level: number;
|
|
16
|
+
/** Raw LaTeX title as it appeared in the header's braces. */
|
|
17
|
+
rawTitle: string;
|
|
18
|
+
/** Title reduced to plain text. */
|
|
19
|
+
title: string;
|
|
20
|
+
/** Ref from a `\label` immediately after the header, if any. */
|
|
21
|
+
labelId?: string;
|
|
22
|
+
/** Offset of the header macro's backslash, in the original source. */
|
|
23
|
+
start: number;
|
|
24
|
+
/** Offset just past the header (and any consumed `\label`). */
|
|
25
|
+
contentStart: number;
|
|
26
|
+
/** Offset just past this division's content — the next sibling's `start`. */
|
|
27
|
+
end: number;
|
|
28
|
+
children: LatexDivision[];
|
|
29
|
+
}
|
|
30
|
+
/** Reduce a LaTeX title fragment to plain text. */
|
|
31
|
+
export declare function latexTitleToPlainText(tex: string): string;
|
|
32
|
+
interface RawHeader {
|
|
33
|
+
command: LatexDivisionCommand;
|
|
34
|
+
start: number;
|
|
35
|
+
rawTitle: string;
|
|
36
|
+
contentStart: number;
|
|
37
|
+
labelId?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Every sectioning header in `source` at brace depth 0, in source order.
|
|
41
|
+
*
|
|
42
|
+
* One linear pass. The previous implementation re-counted brace depth from the
|
|
43
|
+
* start of the document for every candidate match, which is quadratic in
|
|
44
|
+
* document size — exactly the wrong shape for the large multi-section documents
|
|
45
|
+
* this splitter exists to handle.
|
|
46
|
+
*/
|
|
47
|
+
export declare function findLatexHeaders(source: string): RawHeader[];
|
|
48
|
+
/**
|
|
49
|
+
* The sectioning commands this document actually uses, outermost first.
|
|
50
|
+
*
|
|
51
|
+
* Depth is relative to the document, not to LaTeX's absolute hierarchy: an
|
|
52
|
+
* article whose outermost divisions are `\section`s has sections at depth 1, so
|
|
53
|
+
* `splitLevel: 1` means the same thing ("split the top-level divisions") for
|
|
54
|
+
* every document.
|
|
55
|
+
*/
|
|
56
|
+
export declare function latexDivisionHierarchy(source: string): LatexDivisionCommand[];
|
|
57
|
+
/**
|
|
58
|
+
* Parse `source` into a division tree. Offsets are absolute within `source`.
|
|
59
|
+
*
|
|
60
|
+
* Headers are already in source order, so the tree is built with a stack: a
|
|
61
|
+
* header deeper than the stack top becomes its child, and anything at or above
|
|
62
|
+
* the top pops until it finds its parent.
|
|
63
|
+
*/
|
|
64
|
+
export declare function parseLatexDivisions(source: string): LatexDivision[];
|
|
65
|
+
/** A document past this size is worth splitting one level deeper than default. */
|
|
66
|
+
export declare const LARGE_DOCUMENT_CHARS = 80000;
|
|
67
|
+
/** A single division past this size is worth splitting, whatever the total. */
|
|
68
|
+
export declare const LARGE_DIVISION_CHARS = 40000;
|
|
69
|
+
/** Below this many children, splitting a level just makes tiny files. */
|
|
70
|
+
export declare const MIN_DIVISIONS_TO_SPLIT = 3;
|
|
71
|
+
/** Deepest level `suggestSplitLevel` will recommend on its own. */
|
|
72
|
+
export declare const MAX_SUGGESTED_SPLIT_LEVEL = 3;
|
|
73
|
+
/** Every division at exactly `level` in the tree. */
|
|
74
|
+
export declare function divisionsAtLevel(roots: LatexDivision[], level: number): LatexDivision[];
|
|
75
|
+
/**
|
|
76
|
+
* A sensible default split depth for `source`.
|
|
77
|
+
*
|
|
78
|
+
* The old default — chapters for a book, nothing for an article — left a
|
|
79
|
+
* thirty-section article in one enormous file. This goes deeper while the
|
|
80
|
+
* document (or one of its divisions) is still large and the next level down has
|
|
81
|
+
* enough divisions to be worth its own files. Settles SPEC §8.7.
|
|
82
|
+
*/
|
|
83
|
+
export declare function suggestSplitLevel(source: string, documentKind: DocumentKind): number;
|
|
84
|
+
/** A ref-safe slug of a division's title, or `""`. */
|
|
85
|
+
export declare function titleSlug(title: string): string;
|
|
86
|
+
export {};
|
|
@@ -2,6 +2,12 @@ import { DocumentKind } from '../layout/document-kind';
|
|
|
2
2
|
import { BuildDivisionPoolResult } from './division-pool';
|
|
3
3
|
export interface BuildNativeDivisionPoolOptions {
|
|
4
4
|
documentKind?: DocumentKind;
|
|
5
|
+
/**
|
|
6
|
+
* How many levels of the document's own division hierarchy to split out —
|
|
7
|
+
* the same number `buildDivisionPool` takes. Takes precedence over
|
|
8
|
+
* `splitChapters`/`splitSections`.
|
|
9
|
+
*/
|
|
10
|
+
splitLevel?: number;
|
|
5
11
|
splitChapters?: boolean;
|
|
6
12
|
splitSections?: boolean;
|
|
7
13
|
/** Project title, hoisted from the converted PreTeXt pool. */
|
|
@@ -8,6 +8,12 @@ export interface SerializeProjectFilesOptions {
|
|
|
8
8
|
}
|
|
9
9
|
export interface SerializedProjectFiles {
|
|
10
10
|
files: Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* Which file each division landed in, keyed by its `xml:id`. Hosts need this
|
|
13
|
+
* to attach anything division-shaped — a cleaning diff, a warning count — to
|
|
14
|
+
* the file the author is actually looking at.
|
|
15
|
+
*/
|
|
16
|
+
pathByRef: Record<string, string>;
|
|
11
17
|
}
|
|
12
18
|
/** The refs of a division's direct children, in document order. */
|
|
13
19
|
export declare function divisionChildRefs(content: string): string[];
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CleanedChunk } from './clean/clean-chunks';
|
|
1
2
|
import { CleaningWarning } from './clean/warnings';
|
|
2
3
|
import { DocumentKind } from './layout/document-kind';
|
|
3
4
|
import { PretextDivisionTag, PretextRootTag } from './pretext-divisions';
|
|
@@ -12,6 +13,8 @@ export interface ConvertedPretextSuccess extends ConversionContext {
|
|
|
12
13
|
pretextSource: string;
|
|
13
14
|
warnings: CleaningWarning[];
|
|
14
15
|
cleanedNativeSource?: string;
|
|
16
|
+
/** Per-division before/after cleaning record; empty for non-LaTeX input. */
|
|
17
|
+
cleanChunks?: CleanedChunk[];
|
|
15
18
|
}
|
|
16
19
|
export interface ConvertedPretextError extends ConversionContext {
|
|
17
20
|
pretextError: string;
|
|
@@ -133,6 +136,8 @@ export interface ProjectLayout {
|
|
|
133
136
|
}
|
|
134
137
|
export interface ImportedProjectSuccess extends ConversionContext {
|
|
135
138
|
pretextSource: string;
|
|
139
|
+
/** Cleaned but unconverted source, when the input was LaTeX or Markdown. */
|
|
140
|
+
cleanedNativeSource?: string;
|
|
136
141
|
sourcePath: string;
|
|
137
142
|
sourceName: string;
|
|
138
143
|
sourceType: UploadSourceType;
|
|
@@ -163,6 +168,15 @@ export interface ImportedProjectSuccess extends ConversionContext {
|
|
|
163
168
|
outputFiles: Record<string, string>;
|
|
164
169
|
outputAssets: Record<string, Uint8Array>;
|
|
165
170
|
nativeOutputFiles?: Record<string, string>;
|
|
171
|
+
/**
|
|
172
|
+
* The cleaned source cut at every division header, each piece carrying its own
|
|
173
|
+
* before/after text and fix list (SPEC §3.5). Cut at the deepest level the
|
|
174
|
+
* document has, so a host can show any split depth by folding adjacent chunks
|
|
175
|
+
* (`mergeChunksAtLevel`) without re-running the import.
|
|
176
|
+
*/
|
|
177
|
+
cleanChunks: CleanedChunk[];
|
|
178
|
+
/** The split depth this result was laid out at. */
|
|
179
|
+
splitLevel: number;
|
|
166
180
|
statusMessages: UploadStatusMessage[];
|
|
167
181
|
warnings: CleaningWarning[];
|
|
168
182
|
}
|
package/dist/lib/upload.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BuildProjectFilesOptions } from './layout';
|
|
2
2
|
import { RootAttachment } from './project/attach-roots';
|
|
3
|
-
import {
|
|
3
|
+
import { DocumentKind } from './layout/document-kind';
|
|
4
|
+
import { ImportedProjectResult, ImportedProjectSuccess, SourceFormat } from './types';
|
|
4
5
|
export interface ImportProjectOptions extends BuildProjectFilesOptions {
|
|
5
6
|
/** When true (default), the layout splitter runs and outputFiles is populated. */
|
|
6
7
|
buildLayout?: boolean;
|
|
@@ -47,3 +48,28 @@ export interface ExtractedUpload {
|
|
|
47
48
|
export declare function extractUpload(file: File): Promise<ExtractedUpload>;
|
|
48
49
|
export declare function importProjectFromFiles(files: Record<string, string>, options?: ImportProjectOptions): ImportedProjectResult;
|
|
49
50
|
export declare function handleImportUploadFile(file: File, options?: ImportProjectOptions): Promise<ImportedProjectResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Decide the split depth for an import.
|
|
53
|
+
*
|
|
54
|
+
* An explicit `splitLevel` wins; the legacy `splitChapters`/`splitSections`
|
|
55
|
+
* booleans are honoured next (they predate the depth number and still appear in
|
|
56
|
+
* host options); otherwise the depth is suggested from the source's size and
|
|
57
|
+
* structure.
|
|
58
|
+
*/
|
|
59
|
+
export interface SplitLevelContext {
|
|
60
|
+
format: SourceFormat;
|
|
61
|
+
/** Cleaned LaTeX source, when there is one. */
|
|
62
|
+
latexSource?: string;
|
|
63
|
+
documentKind?: DocumentKind;
|
|
64
|
+
}
|
|
65
|
+
export declare function resolveImportSplitLevel(options: ImportProjectOptions, context: SplitLevelContext): number;
|
|
66
|
+
/**
|
|
67
|
+
* Re-derive an import's file layout at a different split depth.
|
|
68
|
+
*
|
|
69
|
+
* Everything expensive — extraction, include expansion, cleaning, and the
|
|
70
|
+
* unified-latex conversion — already happened and is carried on `result`. This
|
|
71
|
+
* only rebuilds the division pool and re-serializes it, so a host can offer a
|
|
72
|
+
* live split-depth control without re-importing. Pure: same input, same output,
|
|
73
|
+
* no closures, safe to call across a webview boundary.
|
|
74
|
+
*/
|
|
75
|
+
export declare function relayoutImport(result: ImportedProjectSuccess, splitLevel: number): ImportedProjectSuccess;
|
|
@@ -39,12 +39,30 @@ export interface ImportEngine {
|
|
|
39
39
|
convertFile: (file: File, options: ImportProjectOptions) => Promise<ImportedProjectResult>;
|
|
40
40
|
/** Unpack and survey an upload without converting it. */
|
|
41
41
|
prepare?: (file: File) => Promise<PreparedUpload>;
|
|
42
|
-
/**
|
|
43
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Convert an already-prepared upload with the user's source choices.
|
|
44
|
+
*
|
|
45
|
+
* May return synchronously (the built-in engine does) or a promise (the
|
|
46
|
+
* worker engine does). The wizard always awaits, which is what lets the
|
|
47
|
+
* processing screen paint and its timer tick before the work starts.
|
|
48
|
+
*/
|
|
49
|
+
convertPrepared?: (prepared: PreparedUpload, options: ImportProjectOptions) => ImportedProjectResult | Promise<ImportedProjectResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Stop an in-flight conversion. Engines that run the pipeline in-process
|
|
52
|
+
* cannot honour this — the pipeline has no yield points — so only the worker
|
|
53
|
+
* engine supplies it, and the processing screen shows Cancel only when it is
|
|
54
|
+
* present.
|
|
55
|
+
*/
|
|
56
|
+
cancel?: () => void;
|
|
44
57
|
}
|
|
45
58
|
export interface ImportWizardProps {
|
|
46
|
-
/**
|
|
47
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Called when the user confirms the import. May return a promise — writing
|
|
61
|
+
* the file map out is the host's slow step (VS Code writes to disk,
|
|
62
|
+
* pretext-plus uploads), so the wizard awaits it and holds the button in a
|
|
63
|
+
* pending state until it settles rather than appearing to do nothing.
|
|
64
|
+
*/
|
|
65
|
+
onConfirm: (result: ImportedProjectSuccess, mode: ImportMode) => void | Promise<void>;
|
|
48
66
|
/** Called when the user cancels at the review step. */
|
|
49
67
|
onCancel?: () => void;
|
|
50
68
|
/** Pass fixed options to skip the document-kind / split-sections controls. */
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { ImportWizard } from './import-wizard';
|
|
2
2
|
export type { ImportWizardProps, ImportMode, ImportEngine, PreparedUpload, } from './import-wizard';
|
|
3
|
+
export { ProcessingPanel } from './processing-panel';
|
|
4
|
+
export type { ProcessingPanelProps } from './processing-panel';
|
|
3
5
|
export { ImportSourceForm } from './import-source-form';
|
|
4
6
|
export { ImportUploadPanel } from './import-upload-panel';
|
|
5
7
|
export type { ImportSourceFormProps, ImportSourceFormLabels, } from './import-source-form';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface ProcessingPanelProps {
|
|
2
|
+
message?: string;
|
|
3
|
+
/** Omitted when the work cannot be interrupted (e.g. a host write). */
|
|
4
|
+
onCancel?: () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function ProcessingPanel({ message, onCancel, }: ProcessingPanelProps): import("react").JSX.Element;
|
package/dist/react.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),F=require("./upload-CGxfSSDN.cjs"),me=require("./import-mode-YW6Lr4SU.cjs");var de={exports:{}},re={};var he;function Se(){if(he)return re;he=1;var r=Symbol.for("react.transitional.element"),u=Symbol.for("react.fragment");function p(b,g,i){var v=null;if(i!==void 0&&(v=""+i),g.key!==void 0&&(v=""+g.key),"key"in g){i={};for(var N in g)N!=="key"&&(i[N]=g[N])}else i=g;return g=i.ref,{$$typeof:r,type:b,key:v,ref:g!==void 0?g:null,props:i}}return re.Fragment=u,re.jsx=p,re.jsxs=p,re}var ae={};var be;function we(){return be||(be=1,process.env.NODE_ENV!=="production"&&(function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===Y?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case I:return"Fragment";case W:return"Profiler";case P:return"StrictMode";case ne:return"Suspense";case ue:return"SuspenseList";case le:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case A:return"Portal";case E:return t.displayName||"Context";case f:return(t._context.displayName||"Context")+".Consumer";case O:var a=t.render;return t=t.displayName,t||(t=a.displayName||a.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Z:return a=t.displayName||null,a!==null?a:r(t.type)||"Memo";case U:a=t._payload,t=t._init;try{return r(t(a))}catch{}}return null}function u(t){return""+t}function p(t){try{u(t);var a=!1}catch{a=!0}if(a){a=console;var x=a.error,m=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return x.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",m),u(t)}}function b(t){if(t===I)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===U)return"<...>";try{var a=r(t);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function g(){var t=K.A;return t===null?null:t.getOwner()}function i(){return Error("react-stack-top-frame")}function v(t){if(Q.call(t,"key")){var a=Object.getOwnPropertyDescriptor(t,"key").get;if(a&&a.isReactWarning)return!1}return t.key!==void 0}function N(t,a){function x(){D||(D=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",a))}x.isReactWarning=!0,Object.defineProperty(t,"key",{get:x,configurable:!0})}function h(){var t=r(this.type);return V[t]||(V[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function _(t,a,x,m,$,G){var j=x.ref;return t={$$typeof:k,type:t,key:a,props:x,_owner:m},(j!==void 0?j:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:h}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:$}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function S(t,a,x,m,$,G){var j=a.children;if(j!==void 0)if(m)if(ee(j)){for(m=0;m<j.length;m++)C(j[m]);Object.freeze&&Object.freeze(j)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else C(j);if(Q.call(a,"key")){j=r(t);var X=Object.keys(a).filter(function(se){return se!=="key"});m=0<X.length?"{key: someKey, "+X.join(": ..., ")+": ...}":"{key: someKey}",R[j+m]||(X=0<X.length?"{"+X.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,f,a,m,a),K[a+f]=!0)}if(a=null,u!==void 0&&(v(u),a=""+u),j(n)&&(v(n.key),a=""+n.key),"key"in n){u={};for(var l in n)l!=="key"&&(u[l]=n[l])}else u=n;return a&&g(u,typeof t=="function"?t.displayName||t.name||"Unknown":t),A(t,a,u,b(),r,s)}function w(t){F(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===C&&(t._payload.status==="fulfilled"?F(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function F(t){return typeof t=="object"&&t!==null&&t.$$typeof===k}var E=d,k=Symbol.for("react.transitional.element"),R=Symbol.for("react.portal"),I=Symbol.for("react.fragment"),N=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),x=Symbol.for("react.consumer"),y=Symbol.for("react.context"),$=Symbol.for("react.forward_ref"),Y=Symbol.for("react.suspense"),V=Symbol.for("react.suspense_list"),G=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),H=Symbol.for("react.activity"),Z=Symbol.for("react.client.reference"),D=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,X=Object.prototype.hasOwnProperty,M=Array.isArray,P=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(t){return t()}};var B,z={},W=E.react_stack_bottom_frame.bind(E,c)(),Q=P(T(c)),K={};J.Fragment=I,J.jsx=function(t,n,u){var f=1e4>D.recentlyCreatedOwnerStacks++;return S(t,n,u,!1,f?Error("react-stack-top-frame"):W,f?P(T(t)):Q)},J.jsxs=function(t,n,u){var f=1e4>D.recentlyCreatedOwnerStacks++;return S(t,n,u,!0,f?Error("react-stack-top-frame"):W,f?P(T(t)):Q)}})()),J}var ne;function de(){return ne||(ne=1,process.env.NODE_ENV==="production"?re.exports=ce():re.exports=ie()),re.exports}var e=de();const oe=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],ue={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:oe,convertFile:_.handleImportUploadFile,prepare:async o=>{const{files:h,assets:v}=await _.extractUpload(o);return{fileName:o.name,files:h,assets:v,analysis:_.analyzeImportSources(h)}},convertPrepared:(o,h)=>_.importProjectFromFiles(o.files,{...h,assets:o.assets})},le={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function me(o){const h=o.reason==="manifest-target"?`project.ptx target “${o.targetName}”`:o.reason==="latex-root"?"LaTeX document":o.reason==="pretext-root"?"PreTeXt document":o.reason==="markdown-root"?"Markdown document":"possible document";return o.title?`${o.title} — ${h}`:h}function xe(o){return o.candidates.filter(v=>v.reason==="manifest-target").length>1?!0:o.manifest&&o.primary?.reason==="manifest-target"?!1:o.formats.length>1||o.candidates.length>1||o.extraRoots.length>0}function pe({onConfirm:o,onCancel:h,importOptions:v,defaultDocumentKind:T="auto",engines:b}){const c=b&&b.length>0?b:[ue],j=d.useRef(null),[g,p]=d.useState({name:"upload"}),[A,S]=d.useState(!1),[w,F]=d.useState(T),[E,k]=d.useState(!1),[R,I]=d.useState(c[0].id),[N,L]=d.useState("converted"),[x,y]=d.useState(!1),[$,Y]=d.useState(new Set),[V,G]=d.useState(null),[C,H]=d.useState("auto"),[Z,D]=d.useState(null),[X,M]=d.useState({}),P=c.find(r=>r.id===R)??c[0],B=P.acceptExtensions??oe,z=()=>v??{documentKind:w==="auto"?void 0:w,splitSections:E},W=r=>_.analyzeImportSources(r.files,{sourceFormat:C==="auto"?void 0:C,mainFile:Z??void 0}),Q=r=>{p({name:"processing"});try{const a=W(r).extraRoots.map(l=>({path:l.path,include:X[l.path]?.include??!0,level:X[l.path]?.level})),m=P.convertPrepared(r,{...z(),sourceFormat:C==="auto"?void 0:C,mainFile:Z??void 0,attachRoots:a});"pretextError"in m?p({name:"error",message:m.pretextError}):p({name:"review",result:m})}catch(s){p({name:"error",message:s instanceof Error?s.message:"An unexpected error occurred."})}},K=async r=>{p({name:"processing"});try{if(P.prepare&&P.convertPrepared){const a=await P.prepare(r);if(G(a),H("auto"),D(null),M({}),xe(a.analysis)){p({name:"sources",prepared:a});return}const m=P.convertPrepared(a,z());p("pretextError"in m?{name:"error",message:m.pretextError}:{name:"review",result:m});return}const s=await P.convertFile(r,z());"pretextError"in s?p({name:"error",message:s.pretextError}):p({name:"review",result:s})}catch(s){p({name:"error",message:s instanceof Error?s.message:"An unexpected error occurred."})}},t=()=>{p({name:"upload"}),L("converted"),y(!1),Y(new Set),G(null)};function n(r,s){return[...r].sort((a,m)=>a===s?-1:m===s?1:a.localeCompare(m))}function u(r,s){const a=_.filesForImportMode(r,s),m=s==="converted"?r.projectLayout.mainSourcePath:r.sourcePath,l=n(Object.keys(a),m)[0];Y(l?new Set([l]):new Set)}function f(r){Y(s=>{const a=new Set(s);return a.has(r)?a.delete(r):a.add(r),a})}if(g.name==="processing")return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16 text-slate-600",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-700 border-t-transparent"}),e.jsx("p",{className:"text-sm",children:"Processing your file…"})]});if(g.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:g.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:t,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(g.name==="sources"){const r=g.prepared,s=W(r),a=s.manifest,m=s.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:[r.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(l=>l.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:C,onChange:l=>{H(l.currentTarget.value),D(null),M({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",s.primary?` (${le[s.primary.format]})`:""]}),s.formats.map(l=>e.jsx("option",{value:l,children:le[l]},l))]})]})}),s.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:s.candidates.map(l=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:l.path,checked:m===l.path,onChange:()=>{D(l.path),M({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:l.path}),e.jsx("span",{className:"block text-slate-500",children:me(l)})]})]},l.path))})]}):null,s.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:s.extraRoots.map(l=>{const O=X[l.path],ee=O?.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:ee,onChange:U=>M(i=>({...i,[l.path]:{...i[l.path],include:U.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:l.path}),l.title?e.jsxs("span",{className:"text-slate-500",children:["— ",l.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:O?.level??"auto",disabled:!ee,onChange:U=>M(i=>({...i,[l.path]:{include:i[l.path]?.include??!0,level:U.currentTarget.value==="auto"?void 0:U.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"})]})]})]},l.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Q(r),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(g.name==="review"){let r=function(i){L(i),x&&u(s,i)};const{result:s}=g,a=s.detectedSourceFormat==="latex",m=s.warnings.length,l=Object.keys(s.outputFiles).length,O=_.filesForImportMode(s,N),ee=N==="converted"?s.projectLayout.mainSourcePath:s.sourcePath,U=n(Object.keys(O),ee);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:s.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:s.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:s.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:l}),s.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,s.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:s.attachedRoots.map(i=>`${i.title} (${i.level})`).join(", ")})]}):null]})]}),m>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:[m," conversion"," ",m===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:s.warnings.map((i,te)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:i.macro})," — ",i.action==="replace"||i.action==="rewrite"?`replaced with \`${i.replacement}\``:i.message??i.action,i.occurrences>1?` (×${i.occurrences})`:null]},te))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),a?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:N==="converted",onChange:()=>r("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:N==="native",onChange:()=>r("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,x?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:U.map(i=>{const te=$.has(i);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>f(i),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:te?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:i}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(O[i].length/1024).toFixed(1)," KB"]})]}),te?e.jsx("pre",{className:"m-0 max-h-72 overflow-auto bg-white p-4 font-mono text-xs leading-relaxed text-slate-800",children:O[i]}):null]},i)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:h??t,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:h?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[V?e.jsx("button",{type:"button",onClick:()=>p({name:"sources",prepared:V}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{x||u(s,N),y(i=>!i)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:x?"Hide Preview":"Preview"}),e.jsx("button",{type:"button",onClick:()=>o(s,N),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Confirm Import"})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[c.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Converter"}),e.jsx("div",{className:"mt-2 flex flex-col gap-3",children:c.map(r=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-engine",value:r.id,checked:R===r.id,onChange:()=>I(r.id),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:r.label}),r.description?e.jsx("span",{className:"block text-slate-500",children:r.description}):null]})]},r.id))})]}):null,v?null:e.jsxs("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:w,onChange:r=>F(r.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("label",{className:"flex items-center gap-2 text-sm text-slate-700",children:[e.jsx("input",{type:"checkbox",checked:E,onChange:r=>k(r.currentTarget.checked)}),"Split sections into separate files"]})]}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:r=>r.key==="Enter"&&j.current?.click(),onClick:()=>j.current?.click(),onDragOver:r=>{r.preventDefault(),S(!0)},onDragLeave:()=>S(!1),onDrop:r=>{r.preventDefault(),S(!1);const s=r.dataTransfer.files?.[0];s&&K(s)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${A?"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:r=>{r.stopPropagation(),j.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 ",B.join(", ")]}),e.jsx("input",{ref:j,type:"file",hidden:!0,accept:B.join(","),onChange:r=>{const s=r.currentTarget.files?.[0];s&&K(s),r.currentTarget.value=""}})]})]})}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 he({initialSource:o="",initialSourceFormat:h,labels:v,disabled:T=!1,onImport:b}){const c=d.useMemo(()=>({...fe,...v??{}}),[v]),[j,g]=d.useState(o),[p,A]=d.useState(h??"auto"),[S,w]=d.useState(null),F=d.useMemo(()=>_.detectSourceFormat(j),[j]),E=T||!j.trim();return e.jsx("form",{onSubmit:k=>{k.preventDefault();const R=_.convertSourceToPretext(j,p==="auto"?void 0:p);w(R),b(R)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:T,children:[e.jsx("legend",{children:c.title}),e.jsx("p",{children:c.description}),e.jsxs("label",{children:[c.sourceLabel,e.jsx("textarea",{value:j,onChange:k=>g(k.currentTarget.value),placeholder:c.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[c.formatLabel,e.jsxs("select",{value:p,onChange:k=>A(k.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"latex",children:"LaTeX"}),e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"pretext",children:"PreTeXt"})]})]}),e.jsxs("p",{children:[c.detectedFormatPrefix,": ",e.jsx("strong",{children:F})]}),e.jsx("button",{type:"submit",disabled:E,children:c.convertButton}),S?"pretextError"in S?e.jsxs("p",{role:"alert",children:[c.errorPrefix,": ",S.pretextError]}):e.jsxs("p",{children:[c.successPrefix,": ",S.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const be={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 je({labels:o,disabled:h=!1,defaultDocumentKind:v="auto",importOptions:T,onImport:b}){const c=d.useMemo(()=>({...be,...o??{}}),[o]),j=d.useRef(null),[g,p]=d.useState(!1),[A,S]=d.useState(!1),[w,F]=d.useState([]),[E,k]=d.useState(v),[R,I]=d.useState(!1),N=h||A,L=async x=>{S(!0);try{const y=T??{documentKind:E==="auto"?void 0:E,splitSections:R},$=await _.handleImportUploadFile(x,y);F($.statusMessages),b($)}finally{S(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:c.title}),e.jsx("p",{children:c.hint}),T?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[c.documentKindLabel,e.jsxs("select",{value:E,disabled:N,onChange:x=>k(x.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:R,disabled:N,onChange:x=>I(x.currentTarget.checked)}),c.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:x=>{x.preventDefault(),N||p(!0)},onDragLeave:()=>p(!1),onDrop:x=>{if(x.preventDefault(),p(!1),N)return;const y=x.dataTransfer.files?.[0];y&&L(y)},children:[e.jsx("p",{children:c.dropHint}),e.jsx("button",{type:"button",disabled:N,onClick:()=>j.current?.click(),children:A?"Processing...":c.selectButton}),e.jsx("input",{ref:j,type:"file",hidden:!0,disabled:N,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:x=>{const y=x.currentTarget.files?.[0];y&&L(y),x.currentTarget.value=""}})]}),w.length>0?e.jsx("ul",{"aria-live":"polite",children:w.map((x,y)=>e.jsx("li",{children:x.message},`${x.type}-${y}`))}):null,g&&!N?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=he;exports.ImportUploadPanel=je;exports.ImportWizard=pe;
|
|
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;
|