@pretextbook/import 0.4.0 → 0.6.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/import-mode-Bu7Pi9k4.cjs +135 -0
- package/dist/import-mode-C0KIll3S.js +7023 -0
- package/dist/import.css +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +9 -3
- package/dist/index.js +160 -138
- 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/pretext-divisions.d.ts +1 -1
- package/dist/lib/types.d.ts +14 -0
- package/dist/lib/upload.d.ts +27 -1
- package/dist/react.cjs +2 -2
- package/dist/react.js +484 -417
- package/package.json +5 -4
- package/dist/import-mode-DlOXwZkx.cjs +0 -115
- package/dist/import-mode-G2KcSH17.js +0 -4774
- 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,36 @@
|
|
|
1
|
+
export type DiffOp = "keep" | "add" | "remove";
|
|
2
|
+
export interface DiffLine {
|
|
3
|
+
op: DiffOp;
|
|
4
|
+
text: string;
|
|
5
|
+
/** 1-based line number in the "before" text; absent for added lines. */
|
|
6
|
+
beforeLine?: number;
|
|
7
|
+
/** 1-based line number in the "after" text; absent for removed lines. */
|
|
8
|
+
afterLine?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface DiffHunk {
|
|
11
|
+
/** Lines in this hunk, including the surrounding context. */
|
|
12
|
+
lines: DiffLine[];
|
|
13
|
+
}
|
|
14
|
+
export interface DiffStats {
|
|
15
|
+
added: number;
|
|
16
|
+
removed: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Longest common subsequence of two line arrays, as a diff.
|
|
20
|
+
*
|
|
21
|
+
* The classic O(n·m) dynamic program. A division is at most a few thousand
|
|
22
|
+
* lines, so the table is small enough not to matter; anything larger is guarded
|
|
23
|
+
* by `MAX_DIFF_LINES` below, which falls back to a whole-file replacement
|
|
24
|
+
* rather than allocating a table nobody will read.
|
|
25
|
+
*/
|
|
26
|
+
export declare function diffLines(before: string, after: string): DiffLine[];
|
|
27
|
+
/** Above this combined line count, the LCS table is not worth building. */
|
|
28
|
+
export declare const MAX_DIFF_LINES = 20000;
|
|
29
|
+
export declare function diffStats(lines: DiffLine[]): DiffStats;
|
|
30
|
+
/**
|
|
31
|
+
* Group a diff into hunks of changed lines with `context` unchanged lines
|
|
32
|
+
* around each, dropping the long runs of untouched text between them. A
|
|
33
|
+
* cleaning pass usually touches a handful of scattered lines, so showing the
|
|
34
|
+
* whole file would bury them.
|
|
35
|
+
*/
|
|
36
|
+
export declare function diffHunks(lines: DiffLine[], context?: number): DiffHunk[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DiffHunk, DiffStats } from './diff';
|
|
2
|
+
import { ImportedProjectSuccess } from './types';
|
|
3
|
+
export interface FileChangeRecord {
|
|
4
|
+
path: string;
|
|
5
|
+
/** Division title this file holds, or `""` for the main file. */
|
|
6
|
+
title: string;
|
|
7
|
+
before: string;
|
|
8
|
+
after: string;
|
|
9
|
+
stats: DiffStats;
|
|
10
|
+
hunks: DiffHunk[];
|
|
11
|
+
/** Number of cleaning fixes applied within this file's source. */
|
|
12
|
+
fixCount: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A before/after record for each generated source file at `splitLevel`.
|
|
16
|
+
*
|
|
17
|
+
* Files with no matching chunk are omitted rather than shown with an empty
|
|
18
|
+
* diff: a title that did not survive conversion means the join is unreliable
|
|
19
|
+
* for that file, and an empty diff would read as "nothing changed here" when
|
|
20
|
+
* the truth is "we do not know".
|
|
21
|
+
*/
|
|
22
|
+
export declare function fileChangesForImport(result: ImportedProjectSuccess, splitLevel?: number): FileChangeRecord[];
|
|
@@ -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[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Root elements of a PreTeXt document. */
|
|
2
2
|
export declare const PRETEXT_ROOT_TAGS: readonly ["book", "article"];
|
|
3
3
|
/** Divisions that may be split into their own file, in rough outline order. */
|
|
4
|
-
export declare const PRETEXT_DIVISION_TAGS: readonly ["frontmatter", "preface", "acknowledgement", "dedication", "biography", "contributors", "part", "chapter", "section", "subsection", "subsubsection", "exercises", "worksheet", "reading-questions", "references", "solutions", "glossary", "backmatter", "appendix", "index", "colophon"];
|
|
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];
|
|
6
6
|
export type PretextDivisionTag = (typeof PRETEXT_DIVISION_TAGS)[number];
|
|
7
7
|
export declare function isDivisionTag(name: string): name is PretextDivisionTag;
|
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;
|
package/dist/react.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),P=require("./import-mode-Bu7Pi9k4.cjs");var ie={exports:{}},se={};var ue;function he(){if(ue)return se;ue=1;var l=Symbol.for("react.transitional.element"),x=Symbol.for("react.fragment");function h(j,b,c){var v=null;if(c!==void 0&&(v=""+c),b.key!==void 0&&(v=""+b.key),"key"in b){c={};for(var N in b)N!=="key"&&(c[N]=b[N])}else c=b;return b=c.ref,{$$typeof:l,type:j,key:v,ref:b!==void 0?b:null,props:c}}return se.Fragment=x,se.jsx=h,se.jsxs=h,se}var re={};var me;function be(){return me||(me=1,process.env.NODE_ENV!=="production"&&(function(){function l(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===X?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case D:return"Fragment";case q:return"Profiler";case R:return"StrictMode";case ae:return"Suspense";case de:return"SuspenseList";case ne:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case C:return"Portal";case T:return t.displayName||"Context";case u:return(t._context.displayName||"Context")+".Consumer";case F:var r=t.render;return t=t.displayName,t||(t=r.displayName||r.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case H:return r=t.displayName||null,r!==null?r:l(t.type)||"Memo";case V:r=t._payload,t=t._init;try{return l(t(r))}catch{}}return null}function x(t){return""+t}function h(t){try{x(t);var r=!1}catch{r=!0}if(r){r=console;var m=r.error,g=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return m.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",g),x(t)}}function j(t){if(t===D)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===V)return"<...>";try{var r=l(t);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function b(){var t=G.A;return t===null?null:t.getOwner()}function c(){return Error("react-stack-top-frame")}function v(t){if(Z.call(t,"key")){var r=Object.getOwnPropertyDescriptor(t,"key").get;if(r&&r.isReactWarning)return!1}return t.key!==void 0}function N(t,r){function m(){M||(M=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}m.isReactWarning=!0,Object.defineProperty(t,"key",{get:m,configurable:!0})}function p(){var t=l(this.type);return A[t]||(A[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function L(t,r,m,g,B,W){var f=m.ref;return t={$$typeof:k,type:t,key:r,props:m,_owner:g},(f!==void 0?f:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:p}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:B}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:W}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function S(t,r,m,g,B,W){var f=r.children;if(f!==void 0)if(g)if(Q(f)){for(g=0;g<f.length;g++)_(f[g]);Object.freeze&&Object.freeze(f)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else _(f);if(Z.call(r,"key")){f=l(t);var O=Object.keys(r).filter(function(s){return s!=="key"});g=0<O.length?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}",Y[f+g]||(O=0<O.length?"{"+O.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
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} />`,g,f,O,f),Y[f+g]=!0)}if(f=null,m!==void 0&&(h(m),f=""+m),v(r)&&(h(r.key),f=""+r.key),"key"in r){m={};for(var te in r)te!=="key"&&(m[te]=r[te])}else m=r;return f&&N(m,typeof t=="function"?t.displayName||t.name||"Unknown":t),L(t,f,m,b(),B,W)}function _(t){I(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===V&&(t._payload.status==="fulfilled"?I(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function I(t){return typeof t=="object"&&t!==null&&t.$$typeof===k}var E=d,k=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),D=Symbol.for("react.fragment"),R=Symbol.for("react.strict_mode"),q=Symbol.for("react.profiler"),u=Symbol.for("react.consumer"),T=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),ae=Symbol.for("react.suspense"),de=Symbol.for("react.suspense_list"),H=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),ne=Symbol.for("react.activity"),X=Symbol.for("react.client.reference"),G=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Z=Object.prototype.hasOwnProperty,Q=Array.isArray,z=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(t){return t()}};var M,A={},ee=E.react_stack_bottom_frame.bind(E,c)(),U=z(j(c)),Y={};re.Fragment=D,re.jsx=function(t,r,m){var g=1e4>G.recentlyCreatedOwnerStacks++;return S(t,r,m,!1,g?Error("react-stack-top-frame"):ee,g?z(j(t)):U)},re.jsxs=function(t,r,m){var g=1e4>G.recentlyCreatedOwnerStacks++;return S(t,r,m,!0,g?Error("react-stack-top-frame"):ee,g?z(j(t)):U)}})()),re}var xe;function ge(){return xe||(xe=1,process.env.NODE_ENV==="production"?ie.exports=he():ie.exports=be()),ie.exports}var e=ge();const fe=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],je={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:fe,convertFile:P.handleImportUploadFile,prepare:async l=>{const{files:x,assets:h}=await P.extractUpload(l);return{fileName:l.name,files:x,assets:h,analysis:P.analyzeImportSources(x)}},convertPrepared:(l,x)=>P.importProjectFromFiles(l.files,{...x,assets:l.assets})},pe={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function ve(l){const x=l.reason==="manifest-target"?`project.ptx target “${l.targetName}”`:l.reason==="latex-root"?"LaTeX document":l.reason==="pretext-root"?"PreTeXt document":l.reason==="markdown-root"?"Markdown document":"possible document";return l.title?`${l.title} — ${x}`:x}function Ne(l){return l.candidates.filter(h=>h.reason==="manifest-target").length>1?!0:l.manifest&&l.primary?.reason==="manifest-target"?!1:l.formats.length>1||l.candidates.length>1||l.extraRoots.length>0}function ye({onConfirm:l,onCancel:x,importOptions:h,defaultDocumentKind:j="auto",engines:b}){const c=b&&b.length>0?b:[je],v=d.useRef(null),[N,p]=d.useState({name:"upload"}),[L,S]=d.useState(!1),[_,I]=d.useState(j),[E,k]=d.useState(null),[C,D]=d.useState(new Set),[R,q]=d.useState(c[0].id),[u,T]=d.useState("converted"),[F,ae]=d.useState(!1),[de,H]=d.useState(new Set),[V,ne]=d.useState(null),[X,G]=d.useState("auto"),[Z,Q]=d.useState(null),[z,M]=d.useState({}),A=c.find(s=>s.id===R)??c[0],ee=A.acceptExtensions??fe,U=N.name==="review"?N.result:null,Y=d.useMemo(()=>U&&E!==null?P.relayoutImport(U,E):U,[U,E]),t=d.useMemo(()=>new Map(Y?P.fileChangesForImport(Y).map(s=>[s.path,s]):[]),[Y]),r=()=>h??{documentKind:_==="auto"?void 0:_},m=s=>P.analyzeImportSources(s.files,{sourceFormat:X==="auto"?void 0:X,mainFile:Z??void 0}),g=s=>{p({name:"processing"});try{const n=m(s).extraRoots.map(i=>({path:i.path,include:z[i.path]?.include??!0,level:z[i.path]?.level})),y=A.convertPrepared(s,{...r(),sourceFormat:X==="auto"?void 0:X,mainFile:Z??void 0,attachRoots:n});"pretextError"in y?p({name:"error",message:y.pretextError}):p({name:"review",result:y})}catch(o){p({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},B=async s=>{p({name:"processing"});try{if(A.prepare&&A.convertPrepared){const n=await A.prepare(s);if(ne(n),G("auto"),Q(null),M({}),Ne(n.analysis)){p({name:"sources",prepared:n});return}const y=A.convertPrepared(n,r());p("pretextError"in y?{name:"error",message:y.pretextError}:{name:"review",result:y});return}const o=await A.convertFile(s,r());"pretextError"in o?p({name:"error",message:o.pretextError}):p({name:"review",result:o})}catch(o){p({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},W=()=>{p({name:"upload"}),T("converted"),ae(!1),H(new Set),D(new Set),k(null),ne(null)};function f(s,o){return[...s].sort((n,y)=>n===o?-1:y===o?1:n.localeCompare(y))}function O(s,o){const n=P.filesForImportMode(s,o),y=o==="converted"?s.projectLayout.mainSourcePath:s.sourcePath,i=f(Object.keys(n),y)[0];H(i?new Set([i]):new Set)}function te(s){H(o=>{const n=new Set(o);return n.has(s)?n.delete(s):n.add(s),n})}if(N.name==="processing")return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16 text-slate-600",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-700 border-t-transparent"}),e.jsx("p",{className:"text-sm",children:"Processing your file…"})]});if(N.name==="error")return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800",children:[e.jsx("p",{className:"font-semibold",children:"Import failed"}),e.jsx("p",{className:"mt-1",children:N.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:W,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(N.name==="sources"){const s=N.prepared,o=m(s),n=o.manifest,y=o.primary?.path??"";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:"Choose what to import"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[s.fileName," contains more than one possible starting point."]})]}),n?e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm text-blue-900",children:[e.jsxs("p",{className:"font-medium",children:["Found ",n.manifestPath," — an existing PreTeXt project."]}),e.jsxs("p",{className:"mt-1 text-blue-800",children:["Its publication file, assets, and directory layout will be kept as they are. Targets:"," ",n.targets.map(i=>i.name).join(", "),"."]})]}):null,e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Source format"}),e.jsxs("select",{value:X,onChange:i=>{G(i.currentTarget.value),Q(null),M({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",o.primary?` (${pe[o.primary.format]})`:""]}),o.formats.map(i=>e.jsx("option",{value:i,children:pe[i]},i))]})]})}),o.candidates.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Main document"}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:o.candidates.map(i=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:i.path,checked:y===i.path,onChange:()=>{Q(i.path),M({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:i.path}),e.jsx("span",{className:"block text-slate-500",children:ve(i)})]})]},i.path))})]}):null,o.extraRoots.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Other documents"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"These files also stand on their own. Attach them to the main document, or leave them out."}),e.jsx("div",{className:"mt-3 flex flex-col gap-2",children:o.extraRoots.map(i=>{const J=z[i.path],le=J?.include??!0;return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm",children:[e.jsxs("label",{className:"flex flex-1 cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:le,onChange:$=>M(K=>({...K,[i.path]:{...K[i.path],include:$.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:i.path}),i.title?e.jsxs("span",{className:"text-slate-500",children:["— ",i.title]}):null]}),e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Attach as"}),e.jsxs("select",{value:J?.level??"auto",disabled:!le,onChange:$=>M(K=>({...K,[i.path]:{include:K[i.path]?.include??!0,level:$.currentTarget.value==="auto"?void 0:$.currentTarget.value}})),className:"rounded border border-slate-300 px-2 py-1 text-sm disabled:opacity-50",children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"chapter",children:"Chapter"}),e.jsx("option",{value:"section",children:"Section"})]})]})]},i.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:W,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>g(s),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(N.name==="review"){let s=function(a){T(a),F&&O(n,a)},o=function(a){D(w=>{const ce=new Set(w);return ce.has(a)?ce.delete(a):ce.add(a),ce})};const n=Y??N.result,y=n.splitLevel,i=n.detectedSourceFormat==="latex",J=n.warnings.length,le=Object.keys(n.outputFiles).length,$=P.filesForImportMode(n,u),K=u==="converted"?n.projectLayout.mainSourcePath:n.sourcePath,oe=f(Object.keys($),K);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-slate-700",children:"Import Summary"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsx("dt",{className:"text-slate-500",children:"Source"}),e.jsx("dd",{className:"font-medium text-slate-900",children:n.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:n.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:n.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:le}),n.projectLayout.preserved?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Existing project"}),e.jsx("dd",{className:"font-medium text-slate-900",children:"Kept publication file, assets, and layout"})]}):null,n.attachedRoots.length>0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Attached"}),e.jsx("dd",{className:"font-medium text-slate-900",children:n.attachedRoots.map(a=>`${a.title} (${a.level})`).join(", ")})]}):null]})]}),J>0?e.jsxs("details",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-amber-800",children:[J," conversion"," ",J===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:n.warnings.map((a,w)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:a.macro})," — ",a.action==="replace"||a.action==="rewrite"?`replaced with \`${a.replacement}\``:a.message??a.action,a.occurrences>1?` (×${a.occurrences})`:null]},w))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),i?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Import mode"}),e.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"converted",checked:u==="converted",onChange:()=>s("converted"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Convert to PreTeXt"}),e.jsx("span",{className:"block text-slate-500",children:"Use the converted PreTeXt output. Recommended for new PreTeXt projects."})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"native",checked:u==="native",onChange:()=>s("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Keep as LaTeX"}),e.jsx("span",{className:"block text-slate-500",children:"Preserve the original LaTeX source. The conversion will not be applied."})]})]})]})]}):null,!h&&n.cleanChunks.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Split into files"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Array.from({length:P.MAX_SUGGESTED_SPLIT_LEVEL+1},(a,w)=>e.jsx("button",{type:"button",onClick:()=>k(w),"aria-pressed":y===w,className:y===w?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:w===0?"One file":`${w} level${w===1?"":"s"}`},w)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[oe.length," file",oe.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:oe.map(a=>e.jsxs("li",{className:"truncate py-0.5",children:[a,t.get(a)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[t.get(a).fixCount," change",t.get(a).fixCount===1?"":"s"]}):null]},a))})]}):null,F?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:oe.map(a=>{const w=de.has(a);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>te(a),className:"flex w-full items-center gap-2 bg-slate-100 px-4 py-2 text-left font-mono text-xs text-slate-700 hover:bg-slate-200",children:[e.jsx("span",{className:"shrink-0 text-slate-400",children:w?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:a}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[($[a].length/1024).toFixed(1)," KB"]})]}),w?e.jsxs("div",{className:"bg-white",children:[t.get(a)?.hunks.length?e.jsxs("div",{className:"flex gap-2 border-b border-slate-200 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>o(a),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:C.has(a)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",t.get(a).stats.added," −",t.get(a).stats.removed," in the LaTeX source"]})]}):null,C.has(a)&&t.has(a)?e.jsx(Se,{hunks:t.get(a).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:$[a]})]}):null]},a)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:x??W,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:x?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[V?e.jsx("button",{type:"button",onClick:()=>p({name:"sources",prepared:V}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{F||O(n,u),ae(a=>!a)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:F?"Hide Preview":"Preview"}),e.jsx("button",{type:"button",onClick:()=>l(n,u),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Confirm Import"})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[c.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Converter"}),e.jsx("div",{className:"mt-2 flex flex-col gap-3",children:c.map(s=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-engine",value:s.id,checked:R===s.id,onChange:()=>q(s.id),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:s.label}),s.description?e.jsx("span",{className:"block text-slate-500",children:s.description}):null]})]},s.id))})]}):null,h?null:e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Document kind"}),e.jsxs("select",{value:_,onChange:s=>I(s.currentTarget.value),className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&v.current?.click(),onClick:()=>v.current?.click(),onDragOver:s=>{s.preventDefault(),S(!0)},onDragLeave:()=>S(!1),onDrop:s=>{s.preventDefault(),S(!1);const o=s.dataTransfer.files?.[0];o&&B(o)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${L?"border-blue-500 bg-blue-50":"border-slate-300 bg-slate-50 hover:border-slate-400"}`,children:[e.jsx("p",{className:"text-slate-600",children:"Drop a file here, or click to select."}),e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),v.current?.click()},className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Select File"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Supports ",ee.join(", ")]}),e.jsx("input",{ref:v,type:"file",hidden:!0,accept:ee.join(","),onChange:s=>{const o=s.currentTarget.files?.[0];o&&B(o),s.currentTarget.value=""}})]})]})}function Se({hunks:l}){return l.length===0?e.jsx("p",{className:"m-0 px-4 py-3 text-xs text-slate-500",children:"Nothing was changed in this file."}):e.jsx("div",{className:"max-h-72 overflow-auto bg-white font-mono text-xs leading-relaxed",children:l.map((x,h)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[h>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,x.lines.map((j,b)=>e.jsxs("div",{className:j.op==="add"?"bg-green-50 px-4 text-green-900":j.op==="remove"?"bg-red-50 px-4 text-red-900":"px-4 text-slate-600",children:[e.jsx("span",{className:"mr-2 select-none text-slate-400",children:j.op==="add"?"+":j.op==="remove"?"−":" "}),j.text||" "]},b))]},h))})}const Ee={title:"Import Source Content",description:"Paste LaTeX, Markdown, or PreTeXt source to convert into PreTeXt.",sourceLabel:"Source",sourcePlaceholder:"Paste source content here...",formatLabel:"Source format",convertButton:"Convert to PreTeXt",detectedFormatPrefix:"Detected",successPrefix:"Ready",errorPrefix:"Error"};function Te({initialSource:l="",initialSourceFormat:x,labels:h,disabled:j=!1,onImport:b}){const c=d.useMemo(()=>({...Ee,...h??{}}),[h]),[v,N]=d.useState(l),[p,L]=d.useState(x??"auto"),[S,_]=d.useState(null),I=d.useMemo(()=>P.detectSourceFormat(v),[v]),E=j||!v.trim();return e.jsx("form",{onSubmit:k=>{k.preventDefault();const C=P.convertSourceToPretext(v,p==="auto"?void 0:p);_(C),b(C)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:j,children:[e.jsx("legend",{children:c.title}),e.jsx("p",{children:c.description}),e.jsxs("label",{children:[c.sourceLabel,e.jsx("textarea",{value:v,onChange:k=>N(k.currentTarget.value),placeholder:c.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[c.formatLabel,e.jsxs("select",{value:p,onChange:k=>L(k.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"latex",children:"LaTeX"}),e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"pretext",children:"PreTeXt"})]})]}),e.jsxs("p",{children:[c.detectedFormatPrefix,": ",e.jsx("strong",{children:I})]}),e.jsx("button",{type:"submit",disabled:E,children:c.convertButton}),S?"pretextError"in S?e.jsxs("p",{role:"alert",children:[c.errorPrefix,": ",S.pretextError]}):e.jsxs("p",{children:[c.successPrefix,": ",S.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const we={title:"Upload Source File",hint:"Supports .tex, .md, .ptx, .xml, .zip, and .tar.gz files.",selectButton:"Select File",dropHint:"Drop a file here, or click Select File.",documentKindLabel:"Document kind",splitSectionsLabel:"Split each chapter into sections"};function ke({labels:l,disabled:x=!1,defaultDocumentKind:h="auto",importOptions:j,onImport:b}){const c=d.useMemo(()=>({...we,...l??{}}),[l]),v=d.useRef(null),[N,p]=d.useState(!1),[L,S]=d.useState(!1),[_,I]=d.useState([]),[E,k]=d.useState(h),[C,D]=d.useState(!1),R=x||L,q=async u=>{S(!0);try{const T=j??{documentKind:E==="auto"?void 0:E,splitSections:C},F=await P.handleImportUploadFile(u,T);I(F.statusMessages),b(F)}finally{S(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:c.title}),e.jsx("p",{children:c.hint}),j?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[c.documentKindLabel,e.jsxs("select",{value:E,disabled:R,onChange:u=>k(u.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]}),e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:C,disabled:R,onChange:u=>D(u.currentTarget.checked)}),c.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:u=>{u.preventDefault(),R||p(!0)},onDragLeave:()=>p(!1),onDrop:u=>{if(u.preventDefault(),p(!1),R)return;const T=u.dataTransfer.files?.[0];T&&q(T)},children:[e.jsx("p",{children:c.dropHint}),e.jsx("button",{type:"button",disabled:R,onClick:()=>v.current?.click(),children:L?"Processing...":c.selectButton}),e.jsx("input",{ref:v,type:"file",hidden:!0,disabled:R,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:u=>{const T=u.currentTarget.files?.[0];T&&q(T),u.currentTarget.value=""}})]}),_.length>0?e.jsx("ul",{"aria-live":"polite",children:_.map((u,T)=>e.jsx("li",{children:u.message},`${u.type}-${T}`))}):null,N&&!R?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=Te;exports.ImportUploadPanel=ke;exports.ImportWizard=ye;
|