@pretextbook/import 0.8.0 → 0.10.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.
Files changed (48) hide show
  1. package/README.md +37 -0
  2. package/dist/convert-worker.cjs +1 -1
  3. package/dist/convert-worker.js +1 -1
  4. package/dist/import-mode-CV7gCDzF.cjs +3 -0
  5. package/dist/import-mode-DQ8g5P8P.js +122 -0
  6. package/dist/import.css +1 -1
  7. package/dist/index.cjs +3 -3
  8. package/dist/index.d.ts +10 -6
  9. package/dist/index.js +524 -214
  10. package/dist/lib/assets/images.d.ts +49 -0
  11. package/dist/lib/detect-snippet-format.d.ts +32 -0
  12. package/dist/lib/import-mode.d.ts +22 -0
  13. package/dist/lib/insert/dedupe-ids.d.ts +36 -0
  14. package/dist/lib/insert/destination.d.ts +21 -0
  15. package/dist/lib/insert/index.d.ts +4 -0
  16. package/dist/lib/insert/prepare.d.ts +44 -0
  17. package/dist/lib/insert/retarget.d.ts +35 -0
  18. package/dist/lib/layout/xml-scan.d.ts +28 -0
  19. package/dist/lib/pandoc/formats.d.ts +40 -0
  20. package/dist/lib/pandoc/index.d.ts +3 -0
  21. package/dist/lib/pandoc/pandoc-engine.d.ts +24 -0
  22. package/dist/lib/pandoc/remote-pandoc.d.ts +74 -0
  23. package/dist/lib/pool/division-pool.d.ts +5 -0
  24. package/dist/lib/pool/index.d.ts +5 -1
  25. package/dist/lib/pool/place-divisions.d.ts +25 -0
  26. package/dist/lib/pool/placeholders.d.ts +4 -0
  27. package/dist/lib/pool/refs.d.ts +8 -0
  28. package/dist/lib/pool/serialize-destination.d.ts +24 -0
  29. package/dist/lib/pool/serialize-files.d.ts +1 -2
  30. package/dist/lib/pool/serialize-insert-records.d.ts +22 -0
  31. package/dist/lib/pool/serialize-insert.d.ts +44 -0
  32. package/dist/lib/pool/serialize-plus.d.ts +4 -4
  33. package/dist/lib/pool/serialize-records.d.ts +11 -0
  34. package/dist/lib/pretext-divisions.d.ts +25 -0
  35. package/dist/lib/select/divisions.d.ts +44 -0
  36. package/dist/lib/types.d.ts +82 -2
  37. package/dist/lib/upload.d.ts +56 -4
  38. package/dist/react/import-wizard.d.ts +45 -1
  39. package/dist/react/index.d.ts +1 -1
  40. package/dist/react.cjs +2 -2
  41. package/dist/react.js +655 -498
  42. package/dist/upload-BnRj1gU1.cjs +135 -0
  43. package/dist/upload-H_OCZBBn.js +7648 -0
  44. package/package.json +1 -1
  45. package/dist/import-mode-BCGuSwkM.js +0 -112
  46. package/dist/import-mode-D1gOJw3N.cjs +0 -3
  47. package/dist/upload-BmErkg8I.js +0 -7140
  48. package/dist/upload-BtS22hIH.cjs +0 -135
@@ -7,3 +7,28 @@ export type PretextDivisionTag = (typeof PRETEXT_DIVISION_TAGS)[number];
7
7
  export declare function isDivisionTag(name: string): name is PretextDivisionTag;
8
8
  export declare function filePrefixForDivision(type: string): string;
9
9
  export declare function isSingletonDivision(type: string): boolean;
10
+ /**
11
+ * The depth-indexed divisions, outermost first (SPEC §9.3). Retargeting an
12
+ * imported fragment onto a chosen level shifts tags along this ladder. Every
13
+ * other division tag names a *role* rather than a depth — an `<exercises>` is
14
+ * an exercises wherever it sits — so retargeting leaves them alone.
15
+ *
16
+ * Matches `LATEX_DIVISION_COMMANDS` (latex-split.ts) rung for rung, since the
17
+ * LaTeX sectioning commands are where most imported hierarchies come from.
18
+ */
19
+ export declare const DIVISION_LADDER: readonly ["part", "chapter", "section", "subsection", "subsubsection"];
20
+ export type LadderTag = (typeof DIVISION_LADDER)[number];
21
+ /**
22
+ * Where content pushed past the bottom of the ladder lands. `<paragraphs>` is
23
+ * deliberately absent from `PRETEXT_DIVISION_TAGS`, so overflow stays inline
24
+ * and can never be split into a file of its own — the overflow rule and the
25
+ * splitter agree without either referring to the other (SPEC §9.3).
26
+ */
27
+ export declare const LADDER_OVERFLOW_TAG = "paragraphs";
28
+ /** Rung index of a tag on the ladder, or `-1` when it is off the ladder. */
29
+ export declare function ladderDepth(name: string): number;
30
+ /**
31
+ * Shift a tag `delta` rungs down the ladder. Off-ladder tags pass through
32
+ * untouched; anything pushed past the last rung becomes `<paragraphs>`.
33
+ */
34
+ export declare function shiftLadderTag(name: string, delta: number): string;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * A division's address within a document: its index among its siblings, joined
3
+ * by dots (`"2"`, `"2.0"`).
4
+ *
5
+ * Positional rather than by `xml:id` because most converted documents have no
6
+ * ids yet — the pool mints them downstream — and an address that only works for
7
+ * documents that were already well-labelled would be no use on exactly the
8
+ * imports that need it. Stable for a given source, which is all a selection has
9
+ * to outlive.
10
+ */
11
+ export type DivisionPath = string;
12
+ export interface DivisionOutlineItem {
13
+ path: DivisionPath;
14
+ /** Element name (`section`, `exercises`, …). */
15
+ tag: string;
16
+ /** The division's own `<title>`, or `""`. */
17
+ title: string;
18
+ /** Its `xml:id`, when the source already carried one. */
19
+ xmlId?: string;
20
+ children: DivisionOutlineItem[];
21
+ }
22
+ /**
23
+ * The document's divisions as a tree, addressed by `DivisionPath` — what a host
24
+ * renders its picker from.
25
+ */
26
+ export declare function outlineDivisions(pretextSource: string): DivisionOutlineItem[];
27
+ export interface PruneDivisionsResult {
28
+ source: string;
29
+ /** Paths of the divisions removed, in document order. */
30
+ removed: DivisionPath[];
31
+ }
32
+ /**
33
+ * Remove every division the selection does not reach.
34
+ *
35
+ * A selected division comes whole — its own subdivisions travel with it — and
36
+ * the divisions containing it are kept as the structure it hangs from. Content
37
+ * that belongs to a kept division but to none of its subdivisions (a chapter's
38
+ * introductory prose, say) stays: it is the parent's own, and dropping it would
39
+ * lose material the author never deselected.
40
+ *
41
+ * An empty or absent selection expresses no narrowing, so nothing is pruned —
42
+ * a host that wants "import nothing" should not run an import.
43
+ */
44
+ export declare function pruneDivisions(pretextSource: string, selection: readonly DivisionPath[] | undefined): PruneDivisionsResult;
@@ -1,4 +1,7 @@
1
1
  import { CleanedChunk } from './clean/clean-chunks';
2
+ import { ImportDestination } from './insert/destination';
3
+ import { XmlIdRename } from './insert/dedupe-ids';
4
+ import { DivisionPath } from './select/divisions';
2
5
  import { CleaningWarning } from './clean/warnings';
3
6
  import { DocumentKind } from './layout/document-kind';
4
7
  import { PretextDivisionTag, PretextRootTag } from './pretext-divisions';
@@ -64,8 +67,9 @@ export interface ImportedAsset {
64
67
  }
65
68
  /**
66
69
  * The host-independent intermediate model of an imported project
67
- * (SPEC §4.1). Serialize with `serializeProjectToFiles` (VS Code file tree)
68
- * or `serializeProjectToPlusPayload` (pretext-plus).
70
+ * (SPEC §4.1). Serialize with `serializeProjectToFiles` (a file tree) or
71
+ * `serializeProjectToRecords` (a flat, ref-addressed projection for a host that
72
+ * stores divisions rather than files).
69
73
  */
70
74
  export interface ImportedProject {
71
75
  title: string;
@@ -76,6 +80,40 @@ export interface ImportedProject {
76
80
  divisions: ImportedDivision[];
77
81
  assets: ImportedAsset[];
78
82
  }
83
+ /**
84
+ * One division of the flat, ref-addressed projection (SPEC §4.3) — the shape a
85
+ * host that stores divisions in a database wants, as against the file tree
86
+ * `serializeProjectToFiles` produces. Hierarchy lives in the `<plus:TYPE
87
+ * ref="…"/>` placeholders inside `source`, not in the record.
88
+ */
89
+ export interface DivisionRecord {
90
+ /** The division's `xml:id`. */
91
+ ref: string;
92
+ source: string;
93
+ sourceFormat: SourceFormat;
94
+ isRoot: boolean;
95
+ }
96
+ /** One asset of the record projection, its bytes base64-encoded. */
97
+ export interface AssetRecord {
98
+ ref: string;
99
+ fileName: string;
100
+ contentType: string;
101
+ /** Base64-encoded bytes, so the projection travels as JSON. */
102
+ data: string;
103
+ }
104
+ /**
105
+ * The record projection of an imported project (SPEC §4.3). Consumer-neutral:
106
+ * `recordsToPlusPayload` renames these fields for pretext-plus's endpoint, and
107
+ * another hosted consumer would write its own adapter rather than inherit
108
+ * someone else's field names.
109
+ */
110
+ export interface ProjectRecords {
111
+ title: string;
112
+ docinfo: string;
113
+ documentKind: DocumentKind;
114
+ divisions: DivisionRecord[];
115
+ assets: AssetRecord[];
116
+ }
79
117
  /**
80
118
  * One division row of the pretext-plus import payload (`divisions_attributes`
81
119
  * on `POST /projects/import`). New rows only — `ProjectsController#import_params`
@@ -134,6 +172,27 @@ export interface ProjectLayout {
134
172
  /** True when an existing project's layout and publication file were kept. */
135
173
  preserved: boolean;
136
174
  }
175
+ /**
176
+ * What an `insert` destination did to the document on its way into the host
177
+ * project (SPEC §9.2). Absent for a new-project import.
178
+ */
179
+ export interface InsertRecord {
180
+ /** True when the document wrapper was dropped in favour of its children. */
181
+ unwrapRoot: boolean;
182
+ /** `<xi:include>` elements for the host to splice in at the cursor. */
183
+ includes: string[];
184
+ /** `xml:id`s renamed because the host project already used them. */
185
+ renamed: XmlIdRename[];
186
+ /** Rungs the document's divisions were shifted down the ladder. */
187
+ retargetDelta: number;
188
+ /**
189
+ * `pretextSource` after retargeting and de-colliding — what was actually
190
+ * split and written. `pretextSource` itself stays the raw conversion, so the
191
+ * attach level can be changed later without re-converting (and without
192
+ * shifting an already-shifted document a second time).
193
+ */
194
+ preparedSource: string;
195
+ }
137
196
  export interface ImportedProjectSuccess extends ConversionContext {
138
197
  pretextSource: string;
139
198
  /** Cleaned but unconverted source, when the input was LaTeX or Markdown. */
@@ -177,6 +236,27 @@ export interface ImportedProjectSuccess extends ConversionContext {
177
236
  cleanChunks: CleanedChunk[];
178
237
  /** The split depth this result was laid out at. */
179
238
  splitLevel: number;
239
+ /**
240
+ * Which divisions this import kept, by `DivisionPath` (SPEC §9, step 6).
241
+ * Absent when the whole document was imported.
242
+ */
243
+ selection?: DivisionPath[];
244
+ /**
245
+ * Warnings from the stages a rebuild redoes — the selection prune and the
246
+ * insert preparation. Also present in `warnings`; held separately so
247
+ * `rebuildImport` can replace exactly these rather than accumulate a set per
248
+ * attempt, since an author trying three attach levels should be left with one
249
+ * overflow notice, not three.
250
+ */
251
+ rebuiltWarnings: CleaningWarning[];
252
+ /**
253
+ * Where this import went. Carried on the result so `relayoutImport` cannot
254
+ * silently regenerate a project scaffold the moment an author changes the
255
+ * split level during an insertion (SPEC §9.2).
256
+ */
257
+ destination: ImportDestination;
258
+ /** Present only for an `insert` destination. */
259
+ insert?: InsertRecord;
180
260
  statusMessages: UploadStatusMessage[];
181
261
  warnings: CleaningWarning[];
182
262
  }
@@ -1,5 +1,8 @@
1
1
  import { BuildProjectFilesOptions } from './layout';
2
+ import { ImportDestination } from './insert/destination';
2
3
  import { RootAttachment } from './project/attach-roots';
4
+ import { PretextDivisionTag } from './pretext-divisions';
5
+ import { DivisionPath } from './select/divisions';
3
6
  import { DocumentKind } from './layout/document-kind';
4
7
  import { ImportedProjectResult, ImportedProjectSuccess, SourceFormat } from './types';
5
8
  export interface ImportProjectOptions extends BuildProjectFilesOptions {
@@ -32,6 +35,26 @@ export interface ImportProjectOptions extends BuildProjectFilesOptions {
32
35
  * loose source into this package's standard layout instead.
33
36
  */
34
37
  preserveProjectLayout?: boolean;
38
+ /**
39
+ * Where the import is going (SPEC §9.2). Defaults to a project of its own;
40
+ * an `insert` destination retargets the document onto a chosen division
41
+ * level in a project that already exists and emits `<xi:include>` elements
42
+ * instead of a scaffold.
43
+ */
44
+ destination?: ImportDestination;
45
+ /**
46
+ * Import only these divisions of the document, by `DivisionPath` (SPEC §9,
47
+ * step 6). Absent — or empty — imports the whole document.
48
+ */
49
+ selection?: DivisionPath[];
50
+ /**
51
+ * The publication file's `<directories external="…"/>` — where author-supplied
52
+ * images go, relative to the main source file (SPEC §3.9). Defaults to
53
+ * `external`, which is what this package's generated publication file
54
+ * declares; a host inserting into a project it already has should pass that
55
+ * project's own.
56
+ */
57
+ externalDir?: string;
35
58
  }
36
59
  export interface ExtractedUpload {
37
60
  files: Record<string, string>;
@@ -63,13 +86,42 @@ export interface SplitLevelContext {
63
86
  documentKind?: DocumentKind;
64
87
  }
65
88
  export declare function resolveImportSplitLevel(options: ImportProjectOptions, context: SplitLevelContext): number;
89
+ export interface RebuildImportOptions {
90
+ /** New split depth; defaults to the one the result was laid out at. */
91
+ splitLevel?: number;
92
+ /**
93
+ * New attach level for an `insert` destination. Ignored for a new-project
94
+ * import, which has no attach level.
95
+ */
96
+ targetTag?: PretextDivisionTag;
97
+ /**
98
+ * New division selection (SPEC §9, step 6). Pass `[]` to go back to importing
99
+ * the whole document.
100
+ */
101
+ selection?: DivisionPath[];
102
+ }
66
103
  /**
67
- * Re-derive an import's file layout at a different split depth.
104
+ * Re-derive an import's file layout without re-importing.
68
105
  *
69
106
  * Everything expensive — extraction, include expansion, cleaning, and the
70
107
  * 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.
108
+ * redoes only what the two live controls affect: the split depth, and (for an
109
+ * insert) the attach level. Both restart from `result.pretextSource`, the raw
110
+ * conversion, so changing the attach level re-prepares from scratch rather than
111
+ * shifting an already-shifted document a second time. Pure: same input, same
112
+ * output, no closures, safe to call across a webview boundary.
74
113
  */
114
+ export declare function rebuildImport(result: ImportedProjectSuccess, options?: RebuildImportOptions): ImportedProjectSuccess;
115
+ /**
116
+ * Re-derive an import keeping only the named divisions — the wizard's
117
+ * cherry-picking control (SPEC §9, step 6). An empty selection restores the
118
+ * whole document.
119
+ */
120
+ export declare function reselectImport(result: ImportedProjectSuccess, selection: DivisionPath[]): ImportedProjectSuccess;
121
+ /** Re-derive an import's file layout at a different split depth. */
75
122
  export declare function relayoutImport(result: ImportedProjectSuccess, splitLevel: number): ImportedProjectSuccess;
123
+ /**
124
+ * Re-derive an insert at a different attach level — the wizard's attach-point
125
+ * control (SPEC §9.4). A no-op for a new-project import.
126
+ */
127
+ export declare function retargetImport(result: ImportedProjectSuccess, targetTag: PretextDivisionTag): ImportedProjectSuccess;
@@ -1,4 +1,5 @@
1
1
  import { ImportProjectOptions } from '../lib/upload';
2
+ import { PretextDivisionTag } from '../lib/pretext-divisions';
2
3
  import { ImportMode } from '../lib/import-mode';
3
4
  import { DocumentKind } from '../lib/layout/document-kind';
4
5
  import { UploadAnalysis } from '../lib/project/analyze';
@@ -68,10 +69,53 @@ export interface ImportWizardProps {
68
69
  /** Pass fixed options to skip the document-kind / split-sections controls. */
69
70
  importOptions?: ImportProjectOptions;
70
71
  defaultDocumentKind?: DocumentKind | "auto";
72
+ /**
73
+ * Which import style the review step starts on: `"converted"` (the PreTeXt
74
+ * output) or `"native"` (the cleaned LaTeX/Markdown source, unconverted).
75
+ * The user can still switch, unless `lockImportMode` is set. Ignored for
76
+ * results with no native alternative — a PreTeXt upload always reviews as
77
+ * converted.
78
+ */
79
+ defaultImportMode?: ImportMode;
80
+ /**
81
+ * Hide the import-mode chooser and import in `defaultImportMode` only. For
82
+ * hosts that support just one style, or that already asked elsewhere.
83
+ */
84
+ lockImportMode?: boolean;
85
+ /** Called when the user picks a different import mode on the review step. */
86
+ onImportModeChange?: (mode: ImportMode) => void;
71
87
  /**
72
88
  * Converters offered to the user. When more than one is supplied, an engine
73
89
  * selector is shown on the upload step. Defaults to a single built-in engine.
74
90
  */
75
91
  engines?: ImportEngine[];
92
+ /**
93
+ * Import into a document that already exists rather than creating a project
94
+ * (SPEC §9). Only the host knows where the cursor is and what the project
95
+ * already contains, so it supplies both; the wizard adds the control that
96
+ * lets the author move the attach level and see the result before confirming.
97
+ */
98
+ insertTarget?: InsertTargetOffer;
99
+ }
100
+ /** What the host knows about the document an import is being inserted into. */
101
+ export interface InsertTargetOffer {
102
+ /** How to name that document to the author, e.g. `ch-intro.ptx`. */
103
+ documentLabel: string;
104
+ /** The level derived from the cursor; the control starts here. */
105
+ defaultTargetTag: PretextDivisionTag;
106
+ /** Levels on offer, outermost first. Defaults to the whole division ladder. */
107
+ targetTags?: PretextDivisionTag[];
108
+ /**
109
+ * Every `xml:id` live in the host project. An array rather than a `Set`
110
+ * because this crosses a webview `postMessage` boundary.
111
+ */
112
+ takenIds: string[];
113
+ /** Directory of the file receiving the include, with a trailing slash. */
114
+ hrefBase: string;
115
+ /**
116
+ * The host project's `<directories external="…"/>`, so imported images land
117
+ * where that project keeps its own rather than in this package's default.
118
+ */
119
+ externalDir?: string;
76
120
  }
77
- export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, engines, }: ImportWizardProps): import("react").JSX.Element;
121
+ export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, defaultImportMode, lockImportMode, onImportModeChange, engines, insertTarget, }: ImportWizardProps): import("react").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  export { ImportWizard } from './import-wizard';
2
- export type { ImportWizardProps, ImportMode, ImportEngine, PreparedUpload, } from './import-wizard';
2
+ export type { ImportWizardProps, ImportMode, ImportEngine, InsertTargetOffer, PreparedUpload, } from './import-wizard';
3
3
  export { ProcessingPanel } from './processing-panel';
4
4
  export type { ProcessingPanelProps } from './processing-panel';
5
5
  export { ImportSourceForm } from './import-source-form';
package/dist/react.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),F=require("./upload-BtS22hIH.cjs"),me=require("./import-mode-D1gOJw3N.cjs");var de={exports:{}},re={};var he;function Se(){if(he)return re;he=1;var r=Symbol.for("react.transitional.element"),u=Symbol.for("react.fragment");function p(b,g,i){var v=null;if(i!==void 0&&(v=""+i),g.key!==void 0&&(v=""+g.key),"key"in g){i={};for(var N in g)N!=="key"&&(i[N]=g[N])}else i=g;return g=i.ref,{$$typeof:r,type:b,key:v,ref:g!==void 0?g:null,props:i}}return re.Fragment=u,re.jsx=p,re.jsxs=p,re}var ae={};var be;function we(){return be||(be=1,process.env.NODE_ENV!=="production"&&(function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===Y?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case I:return"Fragment";case W:return"Profiler";case P:return"StrictMode";case ne:return"Suspense";case ue:return"SuspenseList";case le:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case A:return"Portal";case E:return t.displayName||"Context";case f:return(t._context.displayName||"Context")+".Consumer";case O:var a=t.render;return t=t.displayName,t||(t=a.displayName||a.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Z:return a=t.displayName||null,a!==null?a:r(t.type)||"Memo";case U:a=t._payload,t=t._init;try{return r(t(a))}catch{}}return null}function u(t){return""+t}function p(t){try{u(t);var a=!1}catch{a=!0}if(a){a=console;var x=a.error,m=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return x.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",m),u(t)}}function b(t){if(t===I)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===U)return"<...>";try{var a=r(t);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function g(){var t=K.A;return t===null?null:t.getOwner()}function i(){return Error("react-stack-top-frame")}function v(t){if(Q.call(t,"key")){var a=Object.getOwnPropertyDescriptor(t,"key").get;if(a&&a.isReactWarning)return!1}return t.key!==void 0}function N(t,a){function x(){D||(D=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",a))}x.isReactWarning=!0,Object.defineProperty(t,"key",{get:x,configurable:!0})}function h(){var t=r(this.type);return V[t]||(V[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function _(t,a,x,m,$,G){var j=x.ref;return t={$$typeof:k,type:t,key:a,props:x,_owner:m},(j!==void 0?j:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:h}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:$}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function S(t,a,x,m,$,G){var j=a.children;if(j!==void 0)if(m)if(ee(j)){for(m=0;m<j.length;m++)C(j[m]);Object.freeze&&Object.freeze(j)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else C(j);if(Q.call(a,"key")){j=r(t);var X=Object.keys(a).filter(function(se){return se!=="key"});m=0<X.length?"{key: someKey, "+X.join(": ..., ")+": ...}":"{key: someKey}",R[j+m]||(X=0<X.length?"{"+X.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),D=require("./upload-BnRj1gU1.cjs"),K=require("./import-mode-CV7gCDzF.cjs");var pe={exports:{}},le={};var Te;function Ue(){if(Te)return le;Te=1;var r=Symbol.for("react.transitional.element"),c=Symbol.for("react.fragment");function u(m,p,i){var N=null;if(i!==void 0&&(N=""+i),p.key!==void 0&&(N=""+p.key),"key"in p){i={};for(var C in p)C!=="key"&&(i[C]=p[C])}else i=p;return p=i.ref,{$$typeof:r,type:m,key:N,ref:p!==void 0?p:null,props:i}}return le.Fragment=c,le.jsx=u,le.jsxs=u,le}var oe={};var Pe;function ze(){return Pe||(Pe=1,process.env.NODE_ENV!=="production"&&(function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===fe?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case Y:return"Fragment";case B:return"Profiler";case _:return"StrictMode";case te:return"Suspense";case ce:return"SuspenseList";case he: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 I:return"Portal";case R:return t.displayName||"Context";case j:return(t._context.displayName||"Context")+".Consumer";case A:var l=t.render;return t=t.displayName,t||(t=l.displayName||l.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case ie:return l=t.displayName||null,l!==null?l:r(t.type)||"Memo";case V:l=t._payload,t=t._init;try{return r(t(l))}catch{}}return null}function c(t){return""+t}function u(t){try{c(t);var l=!1}catch{l=!0}if(l){l=console;var f=l.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return f.call(l,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),c(t)}}function m(t){if(t===Y)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===V)return"<...>";try{var l=r(t);return l?"<"+l+">":"<...>"}catch{return"<...>"}}function p(){var t=G.A;return t===null?null:t.getOwner()}function i(){return Error("react-stack-top-frame")}function N(t){if(W.call(t,"key")){var l=Object.getOwnPropertyDescriptor(t,"key").get;if(l&&l.isReactWarning)return!1}return t.key!==void 0}function C(t,l){function f(){J||(J=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",l))}f.isReactWarning=!0,Object.defineProperty(t,"key",{get:f,configurable:!0})}function h(){var t=r(this.type);return H[t]||(H[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(t,l,f,b,U,Z){var g=f.ref;return t={$$typeof:P,type:t,key:l,props:f,_owner:b},(g!==void 0?g: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:U}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Z}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function E(t,l,f,b,U,Z){var g=l.children;if(g!==void 0)if(b)if(de(g)){for(b=0;b<g.length;b++)y(g[b]);Object.freeze&&Object.freeze(g)}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 y(g);if(W.call(l,"key")){g=r(t);var k=Object.keys(l).filter(function(O){return O!=="key"});b=0<k.length?"{key: someKey, "+k.join(": ..., ")+": ...}":"{key: someKey}",ne[g+b]||(k=0<k.length?"{"+k.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
2
  let props = %s;
3
3
  <%s {...props} />
4
4
  React keys must be passed directly to JSX without using spread:
5
5
  let props = %s;
6
- <%s key={someKey} {...props} />`,m,j,X,j),R[j+m]=!0)}if(j=null,x!==void 0&&(p(x),j=""+x),v(a)&&(p(a.key),j=""+a.key),"key"in a){x={};for(var J in a)J!=="key"&&(x[J]=a[J])}else x=a;return j&&N(x,typeof t=="function"?t.displayName||t.name||"Unknown":t),_(t,j,x,g(),$,G)}function C(t){L(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===U&&(t._payload.status==="fulfilled"?L(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function L(t){return typeof t=="object"&&t!==null&&t.$$typeof===k}var w=c,k=Symbol.for("react.transitional.element"),A=Symbol.for("react.portal"),I=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),W=Symbol.for("react.profiler"),f=Symbol.for("react.consumer"),E=Symbol.for("react.context"),O=Symbol.for("react.forward_ref"),ne=Symbol.for("react.suspense"),ue=Symbol.for("react.suspense_list"),Z=Symbol.for("react.memo"),U=Symbol.for("react.lazy"),le=Symbol.for("react.activity"),Y=Symbol.for("react.client.reference"),K=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Q=Object.prototype.hasOwnProperty,ee=Array.isArray,B=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(t){return t()}};var D,V={},te=w.react_stack_bottom_frame.bind(w,i)(),M=B(b(i)),R={};ae.Fragment=I,ae.jsx=function(t,a,x){var m=1e4>K.recentlyCreatedOwnerStacks++;return S(t,a,x,!1,m?Error("react-stack-top-frame"):te,m?B(b(t)):M)},ae.jsxs=function(t,a,x){var m=1e4>K.recentlyCreatedOwnerStacks++;return S(t,a,x,!0,m?Error("react-stack-top-frame"):te,m?B(b(t)):M)}})()),ae}var ge;function Ee(){return ge||(ge=1,process.env.NODE_ENV==="production"?de.exports=Se():de.exports=we()),de.exports}var e=Ee();function Te(){const[r,u]=c.useState(0),p=c.useRef(Date.now());return c.useEffect(()=>{const b=setInterval(()=>{u(Math.floor((Date.now()-p.current)/1e3))},1e3);return()=>clearInterval(b)},[]),r}function ke(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function ve({message:r="Processing your file…",onCancel:u}){const p=Te();return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16 text-slate-600",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-700 border-t-transparent"}),e.jsx("p",{className:"text-sm",children:r}),e.jsx("p",{className:"text-xs tabular-nums text-slate-500",children:ke(p)}),p>=10?e.jsx("p",{className:"max-w-xs text-center text-xs text-slate-500",children:"Large documents can take a while. You can keep working in other tabs."}):null,u?e.jsx("button",{type:"button",onClick:u,className:"mt-2 rounded border border-slate-300 px-3 py-1.5 text-xs font-medium text-slate-700 hover:bg-slate-50",children:"Cancel"}):null]})}const Ne=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],Pe={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:Ne,convertFile:F.handleImportUploadFile,prepare:async r=>{const{files:u,assets:p}=await F.extractUpload(r);return{fileName:r.name,files:u,assets:p,analysis:F.analyzeImportSources(u)}},convertPrepared:(r,u)=>F.importProjectFromFiles(r.files,{...u,assets:r.assets})};function xe(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const je={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function Re(r){const u=r.reason==="manifest-target"?`project.ptx target “${r.targetName}”`:r.reason==="latex-root"?"LaTeX document":r.reason==="pretext-root"?"PreTeXt document":r.reason==="markdown-root"?"Markdown document":"possible document";return r.title?`${r.title} — ${u}`:u}function Ce(r){return r.candidates.filter(p=>p.reason==="manifest-target").length>1?!0:r.manifest&&r.primary?.reason==="manifest-target"?!1:r.formats.length>1||r.candidates.length>1||r.extraRoots.length>0}function _e({onConfirm:r,onCancel:u,importOptions:p,defaultDocumentKind:b="auto",engines:g}){const i=g&&g.length>0?g:[Pe],v=c.useRef(null),[N,h]=c.useState({name:"upload"}),[_,S]=c.useState(!1),[C,L]=c.useState(b),[w,k]=c.useState(null),[A,I]=c.useState(new Set),[P,W]=c.useState(i[0].id),[f,E]=c.useState("converted"),[O,ne]=c.useState(!1),[ue,Z]=c.useState(new Set),[U,le]=c.useState(null),[Y,K]=c.useState("auto"),[Q,ee]=c.useState(null),[B,D]=c.useState({}),[V,te]=c.useState(!1),M=c.useRef(!1),R=i.find(s=>s.id===P)??i[0],t=R.acceptExtensions??Ne,a=N.name==="review"?N.result:null,x=c.useMemo(()=>a&&w!==null?F.relayoutImport(a,w):a,[a,w]),m=c.useMemo(()=>new Map(x?me.fileChangesForImport(x).map(s=>[s.path,s]):[]),[x]),$=()=>p??{documentKind:C==="auto"?void 0:C},G=s=>F.analyzeImportSources(s.files,{sourceFormat:Y==="auto"?void 0:Y,mainFile:Q??void 0}),j=s=>{M.current=!0,R.cancel?.(),h(s?{name:"sources",prepared:s}:{name:"upload"})},X=async s=>{M.current=!1,h({name:"processing"}),await xe();try{const l=G(s).extraRoots.map(d=>({path:d.path,include:B[d.path]?.include??!0,level:B[d.path]?.level})),y=await R.convertPrepared(s,{...$(),sourceFormat:Y==="auto"?void 0:Y,mainFile:Q??void 0,attachRoots:l});"pretextError"in y?h({name:"error",message:y.pretextError}):h({name:"review",result:y})}catch(o){if(M.current)return;h({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},J=async s=>{M.current=!1,h({name:"processing"}),await xe();try{if(R.prepare&&R.convertPrepared){const l=await R.prepare(s);if(le(l),K("auto"),ee(null),D({}),Ce(l.analysis)){h({name:"sources",prepared:l});return}await xe();const y=await R.convertPrepared(l,$());h("pretextError"in y?{name:"error",message:y.pretextError}:{name:"review",result:y});return}const o=await R.convertFile(s,$());"pretextError"in o?h({name:"error",message:o.pretextError}):h({name:"review",result:o})}catch(o){if(M.current)return;h({name:"error",message:o instanceof Error?o.message:"An unexpected error occurred."})}},se=()=>{h({name:"upload"}),E("converted"),ne(!1),Z(new Set),I(new Set),k(null),le(null)};function pe(s,o){return[...s].sort((l,y)=>l===o?-1:y===o?1:l.localeCompare(y))}function fe(s,o){const l=me.filesForImportMode(s,o),y=o==="converted"?s.projectLayout.mainSourcePath:s.sourcePath,d=pe(Object.keys(l),y)[0];Z(d?new Set([d]):new Set)}function ye(s){Z(o=>{const l=new Set(o);return l.has(s)?l.delete(s):l.add(s),l})}if(N.name==="processing")return e.jsx(ve,{onCancel:R.cancel?()=>j(U):void 0});if(N.name==="error")return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-800",children:[e.jsx("p",{className:"font-semibold",children:"Import failed"}),e.jsx("p",{className:"mt-1",children:N.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:se,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(N.name==="sources"){const s=N.prepared,o=G(s),l=o.manifest,y=o.primary?.path??"";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:"Choose what to import"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[s.fileName," contains more than one possible starting point."]})]}),l?e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm text-blue-900",children:[e.jsxs("p",{className:"font-medium",children:["Found ",l.manifestPath," — an existing PreTeXt project."]}),e.jsxs("p",{className:"mt-1 text-blue-800",children:["Its publication file, assets, and directory layout will be kept as they are. Targets:"," ",l.targets.map(d=>d.name).join(", "),"."]})]}):null,e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Source format"}),e.jsxs("select",{value:Y,onChange:d=>{K(d.currentTarget.value),ee(null),D({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",o.primary?` (${je[o.primary.format]})`:""]}),o.formats.map(d=>e.jsx("option",{value:d,children:je[d]},d))]})]})}),o.candidates.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Main document"}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:o.candidates.map(d=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:d.path,checked:y===d.path,onChange:()=>{ee(d.path),D({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:d.path}),e.jsx("span",{className:"block text-slate-500",children:Re(d)})]})]},d.path))})]}):null,o.extraRoots.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Other documents"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"These files also stand on their own. Attach them to the main document, or leave them out."}),e.jsx("div",{className:"mt-3 flex flex-col gap-2",children:o.extraRoots.map(d=>{const H=B[d.path],oe=H?.include??!0;return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm",children:[e.jsxs("label",{className:"flex flex-1 cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:oe,onChange:z=>D(q=>({...q,[d.path]:{...q[d.path],include:z.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:d.path}),d.title?e.jsxs("span",{className:"text-slate-500",children:["— ",d.title]}):null]}),e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Attach as"}),e.jsxs("select",{value:H?.level??"auto",disabled:!oe,onChange:z=>D(q=>({...q,[d.path]:{include:q[d.path]?.include??!0,level:z.currentTarget.value==="auto"?void 0:z.currentTarget.value}})),className:"rounded border border-slate-300 px-2 py-1 text-sm disabled:opacity-50",children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"chapter",children:"Chapter"}),e.jsx("option",{value:"section",children:"Section"})]})]})]},d.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:se,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>X(s),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(N.name==="review"){let s=function(n){E(n),O&&fe(l,n)},o=function(n){I(T=>{const ie=new Set(T);return ie.has(n)?ie.delete(n):ie.add(n),ie})};const l=x??N.result,y=l.splitLevel,d=l.detectedSourceFormat==="latex",H=l.warnings.length,oe=Object.keys(l.outputFiles).length,z=me.filesForImportMode(l,f),q=f==="converted"?l.projectLayout.mainSourcePath:l.sourcePath,ce=pe(Object.keys(z),q);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-slate-700",children:"Import Summary"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsx("dt",{className:"text-slate-500",children:"Source"}),e.jsx("dd",{className:"font-medium text-slate-900",children:l.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:l.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:l.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:oe}),l.projectLayout.preserved?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Existing project"}),e.jsx("dd",{className:"font-medium text-slate-900",children:"Kept publication file, assets, and layout"})]}):null,l.attachedRoots.length>0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Attached"}),e.jsx("dd",{className:"font-medium text-slate-900",children:l.attachedRoots.map(n=>`${n.title} (${n.level})`).join(", ")})]}):null]})]}),H>0?e.jsxs("details",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-amber-800",children:[H," conversion"," ",H===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:l.warnings.map((n,T)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:n.macro})," — ",n.action==="replace"||n.action==="rewrite"?`replaced with \`${n.replacement}\``:n.message??n.action,n.occurrences>1?` (×${n.occurrences})`:null]},T))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),d?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Import mode"}),e.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"converted",checked:f==="converted",onChange:()=>s("converted"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Convert to PreTeXt"}),e.jsx("span",{className:"block text-slate-500",children:"Use the converted PreTeXt output. Recommended for new PreTeXt projects."})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"native",checked:f==="native",onChange:()=>s("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Keep as LaTeX"}),e.jsx("span",{className:"block text-slate-500",children:"Preserve the original LaTeX source. The conversion will not be applied."})]})]})]})]}):null,!p&&l.cleanChunks.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Split into files"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Array.from({length:F.MAX_SUGGESTED_SPLIT_LEVEL+1},(n,T)=>e.jsx("button",{type:"button",onClick:()=>k(T),"aria-pressed":y===T,className:y===T?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:T===0?"One file":`${T} level${T===1?"":"s"}`},T)),e.jsxs("span",{className:"ml-2 text-sm text-slate-500",children:[ce.length," file",ce.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:ce.map(n=>e.jsxs("li",{className:"truncate py-0.5",children:[n,m.get(n)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[m.get(n).fixCount," change",m.get(n).fixCount===1?"":"s"]}):null]},n))})]}):null,O?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:ce.map(n=>{const T=ue.has(n);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>ye(n),className:"flex w-full items-center gap-2 bg-slate-100 px-4 py-2 text-left font-mono text-xs text-slate-700 hover:bg-slate-200",children:[e.jsx("span",{className:"shrink-0 text-slate-400",children:T?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:n}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(z[n].length/1024).toFixed(1)," KB"]})]}),T?e.jsxs("div",{className:"bg-white",children:[m.get(n)?.hunks.length?e.jsxs("div",{className:"flex gap-2 border-b border-slate-200 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>o(n),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:A.has(n)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",m.get(n).stats.added," −",m.get(n).stats.removed," in the LaTeX source"]})]}):null,A.has(n)&&m.has(n)?e.jsx(Ae,{hunks:m.get(n).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:z[n]})]}):null]},n)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:u??se,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:u?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[U?e.jsx("button",{type:"button",onClick:()=>h({name:"sources",prepared:U}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{O||fe(l,f),ne(n=>!n)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:O?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:V,onClick:async()=>{te(!0);try{await r(l,f)}finally{te(!1)}},className:"flex items-center gap-2 rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600 disabled:opacity-60",children:[V?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"}):null,V?"Importing…":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[i.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Converter"}),e.jsx("div",{className:"mt-2 flex flex-col gap-3",children:i.map(s=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-engine",value:s.id,checked:P===s.id,onChange:()=>W(s.id),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:s.label}),s.description?e.jsx("span",{className:"block text-slate-500",children:s.description}):null]})]},s.id))})]}):null,p?null:e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Document kind"}),e.jsxs("select",{value:C,onChange:s=>L(s.currentTarget.value),className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&v.current?.click(),onClick:()=>v.current?.click(),onDragOver:s=>{s.preventDefault(),S(!0)},onDragLeave:()=>S(!1),onDrop:s=>{s.preventDefault(),S(!1);const o=s.dataTransfer.files?.[0];o&&J(o)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${_?"border-blue-500 bg-blue-50":"border-slate-300 bg-slate-50 hover:border-slate-400"}`,children:[e.jsx("p",{className:"text-slate-600",children:"Drop a file here, or click to select."}),e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),v.current?.click()},className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Select File"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Supports ",t.join(", ")]}),e.jsx("input",{ref:v,type:"file",hidden:!0,accept:t.join(","),onChange:s=>{const o=s.currentTarget.files?.[0];o&&J(o),s.currentTarget.value=""}})]})]})}function Ae({hunks:r}){return r.length===0?e.jsx("p",{className:"m-0 px-4 py-3 text-xs text-slate-500",children:"Nothing was changed in this file."}):e.jsx("div",{className:"max-h-72 overflow-auto bg-white font-mono text-xs leading-relaxed",children:r.map((u,p)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[p>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,u.lines.map((b,g)=>e.jsxs("div",{className:b.op==="add"?"bg-green-50 px-4 text-green-900":b.op==="remove"?"bg-red-50 px-4 text-red-900":"px-4 text-slate-600",children:[e.jsx("span",{className:"mr-2 select-none text-slate-400",children:b.op==="add"?"+":b.op==="remove"?"−":" "}),b.text||" "]},g))]},p))})}const Fe={title:"Import Source Content",description:"Paste LaTeX, Markdown, or PreTeXt source to convert into PreTeXt.",sourceLabel:"Source",sourcePlaceholder:"Paste source content here...",formatLabel:"Source format",convertButton:"Convert to PreTeXt",detectedFormatPrefix:"Detected",successPrefix:"Ready",errorPrefix:"Error"};function Oe({initialSource:r="",initialSourceFormat:u,labels:p,disabled:b=!1,onImport:g}){const i=c.useMemo(()=>({...Fe,...p??{}}),[p]),[v,N]=c.useState(r),[h,_]=c.useState(u??"auto"),[S,C]=c.useState(null),L=c.useMemo(()=>F.detectSourceFormat(v),[v]),w=b||!v.trim();return e.jsx("form",{onSubmit:k=>{k.preventDefault();const A=F.convertSourceToPretext(v,h==="auto"?void 0:h);C(A),g(A)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:b,children:[e.jsx("legend",{children:i.title}),e.jsx("p",{children:i.description}),e.jsxs("label",{children:[i.sourceLabel,e.jsx("textarea",{value:v,onChange:k=>N(k.currentTarget.value),placeholder:i.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[i.formatLabel,e.jsxs("select",{value:h,onChange:k=>_(k.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"latex",children:"LaTeX"}),e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"pretext",children:"PreTeXt"})]})]}),e.jsxs("p",{children:[i.detectedFormatPrefix,": ",e.jsx("strong",{children:L})]}),e.jsx("button",{type:"submit",disabled:w,children:i.convertButton}),S?"pretextError"in S?e.jsxs("p",{role:"alert",children:[i.errorPrefix,": ",S.pretextError]}):e.jsxs("p",{children:[i.successPrefix,": ",S.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const Le={title:"Upload Source File",hint:"Supports .tex, .md, .ptx, .xml, .zip, and .tar.gz files.",selectButton:"Select File",dropHint:"Drop a file here, or click Select File.",documentKindLabel:"Document kind",splitSectionsLabel:"Split each chapter into sections"};function Ie({labels:r,disabled:u=!1,defaultDocumentKind:p="auto",importOptions:b,onImport:g}){const i=c.useMemo(()=>({...Le,...r??{}}),[r]),v=c.useRef(null),[N,h]=c.useState(!1),[_,S]=c.useState(!1),[C,L]=c.useState([]),[w,k]=c.useState(p),[A,I]=c.useState(!1),P=u||_,W=async f=>{S(!0);try{const E=b??{documentKind:w==="auto"?void 0:w,splitSections:A},O=await F.handleImportUploadFile(f,E);L(O.statusMessages),g(O)}finally{S(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:i.title}),e.jsx("p",{children:i.hint}),b?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[i.documentKindLabel,e.jsxs("select",{value:w,disabled:P,onChange:f=>k(f.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]}),e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:A,disabled:P,onChange:f=>I(f.currentTarget.checked)}),i.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:f=>{f.preventDefault(),P||h(!0)},onDragLeave:()=>h(!1),onDrop:f=>{if(f.preventDefault(),h(!1),P)return;const E=f.dataTransfer.files?.[0];E&&W(E)},children:[e.jsx("p",{children:i.dropHint}),e.jsxs("button",{type:"button",disabled:P,onClick:()=>v.current?.click(),className:"inline-flex items-center gap-2",children:[_?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent","aria-hidden":"true"}):null,_?"Processing…":i.selectButton]}),e.jsx("input",{ref:v,type:"file",hidden:!0,disabled:P,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:f=>{const E=f.currentTarget.files?.[0];E&&W(E),f.currentTarget.value=""}})]}),_?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,C.length>0?e.jsx("ul",{"aria-live":"polite",children:C.map((f,E)=>e.jsx("li",{children:f.message},`${f.type}-${E}`))}):null,N&&!P?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=Oe;exports.ImportUploadPanel=Ie;exports.ImportWizard=_e;exports.ProcessingPanel=ve;
6
+ <%s key={someKey} {...props} />`,b,g,k,g),ne[g+b]=!0)}if(g=null,f!==void 0&&(u(f),g=""+f),N(l)&&(u(l.key),g=""+l.key),"key"in l){f={};for(var Q in l)Q!=="key"&&(f[Q]=l[Q])}else f=l;return g&&C(f,typeof t=="function"?t.displayName||t.name||"Unknown":t),T(t,g,f,p(),U,Z)}function y(t){v(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===V&&(t._payload.status==="fulfilled"?v(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function v(t){return typeof t=="object"&&t!==null&&t.$$typeof===P}var F=o,P=Symbol.for("react.transitional.element"),I=Symbol.for("react.portal"),Y=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),B=Symbol.for("react.profiler"),j=Symbol.for("react.consumer"),R=Symbol.for("react.context"),A=Symbol.for("react.forward_ref"),te=Symbol.for("react.suspense"),ce=Symbol.for("react.suspense_list"),ie=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),he=Symbol.for("react.activity"),fe=Symbol.for("react.client.reference"),G=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W=Object.prototype.hasOwnProperty,de=Array.isArray,se=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(t){return t()}};var J,H={},re=F.react_stack_bottom_frame.bind(F,i)(),X=se(m(i)),ne={};oe.Fragment=Y,oe.jsx=function(t,l,f){var b=1e4>G.recentlyCreatedOwnerStacks++;return E(t,l,f,!1,b?Error("react-stack-top-frame"):re,b?se(m(t)):X)},oe.jsxs=function(t,l,f){var b=1e4>G.recentlyCreatedOwnerStacks++;return E(t,l,f,!0,b?Error("react-stack-top-frame"):re,b?se(m(t)):X)}})()),oe}var Re;function Ye(){return Re||(Re=1,process.env.NODE_ENV==="production"?pe.exports=Ue():pe.exports=ze()),pe.exports}var e=Ye();function Be(){const[r,c]=o.useState(0),u=o.useRef(Date.now());return o.useEffect(()=>{const m=setInterval(()=>{c(Math.floor((Date.now()-u.current)/1e3))},1e3);return()=>clearInterval(m)},[]),r}function We(r){return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")}`}function _e({message:r="Processing your file…",onCancel:c}){const u=Be();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:We(u)}),u>=10?e.jsx("p",{className:"max-w-xs text-center text-xs text-slate-500",children:"Large documents can take a while. You can keep working in other tabs."}):null,c?e.jsx("button",{type:"button",onClick:c,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 Ae=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],qe={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:Ae,convertFile:D.handleImportUploadFile,prepare:async r=>{const{files:c,assets:u}=await D.extractUpload(r);return{fileName:r.name,files:c,assets:u,analysis:D.analyzeImportSources(c)}},convertPrepared:(r,c)=>D.importProjectFromFiles(r.files,{...c,assets:r.assets})};function Ne(){return new Promise(r=>{if(typeof requestAnimationFrame!="function"){setTimeout(r,0);return}requestAnimationFrame(()=>setTimeout(r,0))})}const Ce={pretext:"PreTeXt",latex:"LaTeX",markdown:"Markdown"};function Ke(r){const c=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} — ${c}`:c}function Ve(r){return r.candidates.filter(u=>u.reason==="manifest-target").length>1?!0:r.manifest&&r.primary?.reason==="manifest-target"?!1:r.formats.length>1||r.candidates.length>1||r.extraRoots.length>0}function Ge({onConfirm:r,onCancel:c,importOptions:u,defaultDocumentKind:m="auto",defaultImportMode:p=K.DEFAULT_IMPORT_MODE,lockImportMode:i=!1,onImportModeChange:N,engines:C,insertTarget:h}){const T=C&&C.length>0?C:[qe],E=o.useRef(null),[y,v]=o.useState({name:"upload"}),[F,P]=o.useState(!1),[I,Y]=o.useState(m),[_,B]=o.useState(null),[j,R]=o.useState(null),[A,te]=o.useState([]),[ce,ie]=o.useState(new Set),[V,he]=o.useState(T[0].id),[fe,G]=o.useState(p),[W,de]=o.useState(!1),[se,J]=o.useState(new Set),[H,re]=o.useState(null),[X,ne]=o.useState("auto"),[t,l]=o.useState(null),[f,b]=o.useState({}),[U,Z]=o.useState(!1),g=o.useRef(!1),k=T.find(n=>n.id===V)??T[0],Q=k.acceptExtensions??Ae,O=y.name==="review"?y.result:null,ue=o.useMemo(()=>O&&(_!==null||j!==null||A.length>0)?D.rebuildImport(O,{splitLevel:_??void 0,targetTag:j??void 0,selection:A}):O,[O,_,j,A]),be=o.useMemo(()=>O?D.outlineDivisions(O.pretextSource):[],[O]),z=o.useMemo(()=>new Map(ue?K.fileChangesForImport(ue).map(n=>[n.path,n]):[]),[ue]),ye=o.useMemo(()=>h?{kind:"insert",targetTag:j??h.defaultTargetTag,takenIds:new Set(h.takenIds),hrefBase:h.hrefBase}:void 0,[h,j]),ge=()=>({...u??{documentKind:I==="auto"?void 0:I},...ye?{destination:ye}:{},...h?.externalDir?{externalDir:h.externalDir}:{}}),we=n=>D.analyzeImportSources(n.files,{sourceFormat:X==="auto"?void 0:X,mainFile:t??void 0}),Ie=n=>{g.current=!0,k.cancel?.(),v(n?{name:"sources",prepared:n}:{name:"upload"})},Oe=async n=>{g.current=!1,v({name:"processing"}),await Ne();try{const a=we(n).extraRoots.map(x=>({path:x.path,include:f[x.path]?.include??!0,level:f[x.path]?.level})),S=await k.convertPrepared(n,{...ge(),sourceFormat:X==="auto"?void 0:X,mainFile:t??void 0,attachRoots:a});"pretextError"in S?v({name:"error",message:S.pretextError}):v({name:"review",result:S})}catch(d){if(g.current)return;v({name:"error",message:d instanceof Error?d.message:"An unexpected error occurred."})}},Se=async n=>{g.current=!1,v({name:"processing"}),await Ne();try{if(k.prepare&&k.convertPrepared){const a=await k.prepare(n);if(re(a),ne("auto"),l(null),b({}),Ve(a.analysis)){v({name:"sources",prepared:a});return}await Ne();const S=await k.convertPrepared(a,ge());v("pretextError"in S?{name:"error",message:S.pretextError}:{name:"review",result:S});return}const d=await k.convertFile(n,ge());"pretextError"in d?v({name:"error",message:d.pretextError}):v({name:"review",result:d})}catch(d){if(g.current)return;v({name:"error",message:d instanceof Error?d.message:"An unexpected error occurred."})}},je=()=>{v({name:"upload"}),G(p),de(!1),J(new Set),ie(new Set),B(null),R(null),te([]),re(null)};function ke(n,d){return[...n].sort((a,S)=>a===d?-1:S===d?1:a.localeCompare(S))}function Ee(n,d){const a=K.filesForImportMode(n,d),S=d==="converted"?n.projectLayout.mainSourcePath:n.sourcePath,x=ke(Object.keys(a),S)[0];J(x?new Set([x]):new Set)}function Le(n){J(d=>{const a=new Set(d);return a.has(n)?a.delete(n):a.add(n),a})}if(y.name==="processing")return e.jsx(_e,{onCancel:k.cancel?()=>Ie(H):void 0});if(y.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:y.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:je,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(y.name==="sources"){const n=y.prepared,d=we(n),a=d.manifest,S=d.primary?.path??"";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:"Choose what to import"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[n.fileName," contains more than one possible starting point."]})]}),a?e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm text-blue-900",children:[e.jsxs("p",{className:"font-medium",children:["Found ",a.manifestPath," — an existing PreTeXt project."]}),e.jsxs("p",{className:"mt-1 text-blue-800",children:["Its publication file, assets, and directory layout will be kept as they are. Targets:"," ",a.targets.map(x=>x.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:x=>{ne(x.currentTarget.value),l(null),b({})},className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsxs("option",{value:"auto",children:["Auto detect",d.primary?` (${Ce[d.primary.format]})`:""]}),d.formats.map(x=>e.jsx("option",{value:x,children:Ce[x]},x))]})]})}),d.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:d.candidates.map(x=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"main-file",value:x.path,checked:S===x.path,onChange:()=>{l(x.path),b({})},className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-xs text-slate-900",children:x.path}),e.jsx("span",{className:"block text-slate-500",children:Ke(x)})]})]},x.path))})]}):null,d.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:d.extraRoots.map(x=>{const ae=f[x.path],L=ae?.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:L,onChange:q=>b(M=>({...M,[x.path]:{...M[x.path],include:q.currentTarget.checked}}))}),e.jsx("span",{className:"font-mono text-xs text-slate-900",children:x.path}),x.title?e.jsxs("span",{className:"text-slate-500",children:["— ",x.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:ae?.level??"auto",disabled:!L,onChange:q=>b(M=>({...M,[x.path]:{include:M[x.path]?.include??!0,level:q.currentTarget.value==="auto"?void 0:q.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"})]})]})]},x.path)})})]}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:je,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:"Start Over"}),e.jsx("button",{type:"button",onClick:()=>Oe(n),className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Continue"})]})]})}if(y.name==="review"){let n=function(s){G(s),N?.(s),W&&Ee(a,s)},d=function(s){ie(w=>{const ee=new Set(w);return ee.has(s)?ee.delete(s):ee.add(s),ee})};const a=ue??y.result,S=a.splitLevel,x=A.length>0,ae=K.hasNativeImportMode(a)&&!x,L=ae?K.resolveImportMode(a,fe):"converted",q=a.detectedSourceFormat==="markdown"?"Markdown":"LaTeX",M=a.warnings.length,Me=Object.keys(a.outputFiles).length,$=a.insert,me=a.destination.kind==="insert"?a.destination.targetTag:void 0,$e=h?.targetTags??[...D.DIVISION_LADDER],ve=K.filesForImportMode(a,L),Xe=L==="converted"?a.projectLayout.mainSourcePath:a.sourcePath,xe=ke(Object.keys(ve),Xe);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-slate-700",children:"Import Summary"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsx("dt",{className:"text-slate-500",children:"Source"}),e.jsx("dd",{className:"font-medium text-slate-900",children:a.sourceName}),e.jsx("dt",{className:"text-slate-500",children:"Detected format"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.detectedSourceFormat}),e.jsx("dt",{className:"text-slate-500",children:"Document kind"}),e.jsx("dd",{className:"font-medium text-slate-900 capitalize",children:a.documentKind}),e.jsx("dt",{className:"text-slate-500",children:"Output files"}),e.jsx("dd",{className:"font-medium text-slate-900",children:Me}),h?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Destination"}),e.jsxs("dd",{className:"font-medium text-slate-900",children:["Inserted into ",h.documentLabel]})]}):null,a.projectLayout.preserved?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Existing project"}),e.jsx("dd",{className:"font-medium text-slate-900",children:"Kept publication file, assets, and layout"})]}):null,a.attachedRoots.length>0?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-slate-500",children:"Attached"}),e.jsx("dd",{className:"font-medium text-slate-900",children:a.attachedRoots.map(s=>`${s.title} (${s.level})`).join(", ")})]}):null]})]}),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:a.warnings.map((s,w)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:s.macro})," — ",s.action==="replace"||s.action==="rewrite"?`replaced with \`${s.replacement}\``:s.message??s.action,s.occurrences>1?` (×${s.occurrences})`:null]},w))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),ae&&!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:L==="converted",onChange:()=>n("converted"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:"Convert to PreTeXt"}),e.jsx("span",{className:"block text-slate-500",children:"Use the converted PreTeXt output. Recommended for new PreTeXt projects."})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-mode",value:"native",checked:L==="native",onChange:()=>n("native"),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["Keep as ",q]}),e.jsxs("span",{className:"block text-slate-500",children:["Preserve the original ",q," source. The conversion will not be applied."]})]})]})]})]}):null,be.length>1?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Divisions to import"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("button",{type:"button",onClick:()=>te([]),className:"rounded border border-slate-300 px-3 py-1 text-slate-700 hover:bg-slate-50",children:"Everything"}),e.jsx("span",{className:"text-slate-500",children:A.length===0?"The whole document":`${A.length} of ${Fe(be)} divisions`})]}),e.jsx("div",{className:"mt-3 max-h-56 overflow-auto",children:e.jsx(De,{items:be,selection:A,onToggle:s=>te(w=>w.includes(s)?w.filter(ee=>ee!==s):[...w,s].sort(Je))})}),A.length>0?e.jsxs("p",{className:"mt-2 text-sm text-slate-500",children:["A selected division is imported whole, with everything inside it. Divisions above one you selected are kept as structure.",K.hasNativeImportMode(y.result)?" Selecting divisions imports the converted PreTeXt; keeping the original source imports the document whole.":""]}):null]}):null,$&&h?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsxs("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:["Attach to ",h.documentLabel]}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:$e.map(s=>e.jsxs("button",{type:"button",onClick:()=>R(s),"aria-pressed":me===s,className:me===s?"rounded bg-blue-700 px-3 py-1 text-sm font-medium text-white":"rounded border border-slate-300 px-3 py-1 text-sm text-slate-700 hover:bg-slate-50",children:["<",s,">"]},s))}),e.jsxs("p",{className:"mt-3 text-sm text-slate-600",children:[$.includes.length===1?`One <${me}> is added to ${h.documentLabel}, `:`${$.includes.length} <${me}> divisions are added to ${h.documentLabel}, `,$.includes.length===1?"included from a new file beside it.":"each included from a new file beside it."]}),$.renamed.length>0?e.jsxs("p",{className:"mt-2 text-sm text-amber-700",children:[$.renamed.length," id",$.renamed.length===1?"":"s"," already used in this project"," ",$.renamed.length===1?"was":"were"," renamed:"," ",e.jsx("span",{className:"font-mono text-xs",children:$.renamed.map(s=>`${s.from} → ${s.to}`).join(", ")})]}):null]}):null,!u&&a.cleanChunks.length>0?e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold text-slate-700",children:"Split into files"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Array.from({length:D.MAX_SUGGESTED_SPLIT_LEVEL+1},(s,w)=>e.jsx("button",{type:"button",onClick:()=>B(w),"aria-pressed":S===w,className:S===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:[xe.length," file",xe.length===1?"":"s"]})]}),e.jsx("ul",{className:"mt-3 max-h-48 overflow-auto font-mono text-xs text-slate-600",children:xe.map(s=>e.jsxs("li",{className:"truncate py-0.5",children:[s,z.get(s)?.fixCount?e.jsxs("span",{className:"ml-2 text-amber-700",children:[z.get(s).fixCount," change",z.get(s).fixCount===1?"":"s"]}):null]},s))})]}):null,W?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:xe.map(s=>{const w=se.has(s);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Le(s),className:"flex w-full items-center gap-2 bg-slate-100 px-4 py-2 text-left font-mono text-xs text-slate-700 hover:bg-slate-200",children:[e.jsx("span",{className:"shrink-0 text-slate-400",children:w?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:s}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(ve[s].length/1024).toFixed(1)," KB"]})]}),w?e.jsxs("div",{className:"bg-white",children:[z.get(s)?.hunks.length?e.jsxs("div",{className:"flex gap-2 border-b border-slate-200 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>d(s),className:"rounded border border-slate-300 px-2 py-0.5 text-xs text-slate-700 hover:bg-slate-50",children:ce.has(s)?"Show converted file":"Show what changed"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["+",z.get(s).stats.added," −",z.get(s).stats.removed," in the LaTeX source"]})]}):null,ce.has(s)&&z.has(s)?e.jsx(He,{hunks:z.get(s).hunks}):e.jsx("pre",{className:"m-0 max-h-72 overflow-auto p-4 font-mono text-xs leading-relaxed text-slate-800",children:ve[s]})]}):null]},s)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:c??je,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:c?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[H?e.jsx("button",{type:"button",onClick:()=>v({name:"sources",prepared:H}),className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:"Change Sources"}):null,e.jsx("button",{type:"button",onClick:()=>{W||Ee(a,L),de(s=>!s)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:W?"Hide Preview":"Preview"}),e.jsxs("button",{type:"button",disabled:U,onClick:async()=>{Z(!0);try{await r(a,L)}finally{Z(!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:[U?e.jsx("span",{className:"h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent"}):null,U?h?"Inserting…":"Importing…":h?"Confirm Insert":"Confirm Import"]})]})]})]})}return e.jsxs("div",{className:"flex flex-col gap-4",children:[T.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:T.map(n=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm",children:[e.jsx("input",{type:"radio",name:"import-engine",value:n.id,checked:V===n.id,onChange:()=>he(n.id),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:n.label}),n.description?e.jsx("span",{className:"block text-slate-500",children:n.description}):null]})]},n.id))})]}):null,u?null:e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:e.jsxs("label",{className:"flex items-center gap-2 text-slate-700",children:[e.jsx("span",{className:"text-slate-500",children:"Document kind"}),e.jsxs("select",{value:I,onChange:n=>Y(n.currentTarget.value),className:"rounded border border-slate-300 px-2 py-1 text-sm",children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"article",children:"Article"}),e.jsx("option",{value:"book",children:"Book"})]})]})}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:n=>n.key==="Enter"&&E.current?.click(),onClick:()=>E.current?.click(),onDragOver:n=>{n.preventDefault(),P(!0)},onDragLeave:()=>P(!1),onDrop:n=>{n.preventDefault(),P(!1);const d=n.dataTransfer.files?.[0];d&&Se(d)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${F?"border-blue-500 bg-blue-50":"border-slate-300 bg-slate-50 hover:border-slate-400"}`,children:[e.jsx("p",{className:"text-slate-600",children:"Drop a file here, or click to select."}),e.jsx("button",{type:"button",onClick:n=>{n.stopPropagation(),E.current?.click()},className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Select File"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Supports ",Q.join(", ")]}),e.jsx("input",{ref:E,type:"file",hidden:!0,accept:Q.join(","),onChange:n=>{const d=n.currentTarget.files?.[0];d&&Se(d),n.currentTarget.value=""}})]})]})}function Fe(r){return r.reduce((c,u)=>c+1+Fe(u.children),0)}function Je(r,c){const u=r.split(".").map(Number),m=c.split(".").map(Number);for(let p=0;p<Math.max(u.length,m.length);p++){const i=(u[p]??-1)-(m[p]??-1);if(i!==0)return i}return 0}function De({items:r,selection:c,onToggle:u}){return e.jsx("ul",{className:"space-y-0.5 text-sm",children:r.map(m=>{const p=c.includes(m.path),i=c.some(N=>m.path.startsWith(`${N}.`));return e.jsxs("li",{children:[e.jsxs("label",{className:"flex items-baseline gap-2",children:[e.jsx("input",{type:"checkbox",checked:p||i,disabled:i,onChange:()=>u(m.path)}),e.jsxs("span",{className:i?"text-slate-400":"text-slate-700",children:[m.title||e.jsx("em",{children:"Untitled"}),e.jsxs("span",{className:"ml-2 font-mono text-xs text-slate-400",children:["<",m.tag,">"]})]})]}),m.children.length>0?e.jsx("div",{className:"ml-5 border-l border-slate-200 pl-3",children:e.jsx(De,{items:m.children,selection:c,onToggle:u})}):null]},m.path)})})}function He({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((c,u)=>e.jsxs("div",{className:"border-b border-slate-100 last:border-b-0",children:[u>0?e.jsx("div",{className:"bg-slate-50 px-4 py-1 text-slate-400",children:"⋯"}):null,c.lines.map((m,p)=>e.jsxs("div",{className:m.op==="add"?"bg-green-50 px-4 text-green-900":m.op==="remove"?"bg-red-50 px-4 text-red-900":"px-4 text-slate-600",children:[e.jsx("span",{className:"mr-2 select-none text-slate-400",children:m.op==="add"?"+":m.op==="remove"?"−":" "}),m.text||" "]},p))]},u))})}const Ze={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 Qe({initialSource:r="",initialSourceFormat:c,labels:u,disabled:m=!1,onImport:p}){const i=o.useMemo(()=>({...Ze,...u??{}}),[u]),[N,C]=o.useState(r),[h,T]=o.useState(c??"auto"),[E,y]=o.useState(null),v=o.useMemo(()=>D.detectSourceFormat(N),[N]),F=m||!N.trim();return e.jsx("form",{onSubmit:P=>{P.preventDefault();const I=D.convertSourceToPretext(N,h==="auto"?void 0:h);y(I),p(I)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:m,children:[e.jsx("legend",{children:i.title}),e.jsx("p",{children:i.description}),e.jsxs("label",{children:[i.sourceLabel,e.jsx("textarea",{value:N,onChange:P=>C(P.currentTarget.value),placeholder:i.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[i.formatLabel,e.jsxs("select",{value:h,onChange:P=>T(P.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:v})]}),e.jsx("button",{type:"submit",disabled:F,children:i.convertButton}),E?"pretextError"in E?e.jsxs("p",{role:"alert",children:[i.errorPrefix,": ",E.pretextError]}):e.jsxs("p",{children:[i.successPrefix,": ",E.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const et={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 tt({labels:r,disabled:c=!1,defaultDocumentKind:u="auto",importOptions:m,onImport:p}){const i=o.useMemo(()=>({...et,...r??{}}),[r]),N=o.useRef(null),[C,h]=o.useState(!1),[T,E]=o.useState(!1),[y,v]=o.useState([]),[F,P]=o.useState(u),[I,Y]=o.useState(!1),_=c||T,B=async j=>{E(!0);try{const R=m??{documentKind:F==="auto"?void 0:F,splitSections:I},A=await D.handleImportUploadFile(j,R);v(A.statusMessages),p(A)}finally{E(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:i.title}),e.jsx("p",{children:i.hint}),m?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[i.documentKindLabel,e.jsxs("select",{value:F,disabled:_,onChange:j=>P(j.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:I,disabled:_,onChange:j=>Y(j.currentTarget.checked)}),i.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:j=>{j.preventDefault(),_||h(!0)},onDragLeave:()=>h(!1),onDrop:j=>{if(j.preventDefault(),h(!1),_)return;const R=j.dataTransfer.files?.[0];R&&B(R)},children:[e.jsx("p",{children:i.dropHint}),e.jsxs("button",{type:"button",disabled:_,onClick:()=>N.current?.click(),className:"inline-flex items-center gap-2",children:[T?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,T?"Processing…":i.selectButton]}),e.jsx("input",{ref:N,type:"file",hidden:!0,disabled:_,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:j=>{const R=j.currentTarget.files?.[0];R&&B(R),j.currentTarget.value=""}})]}),T?e.jsx("p",{role:"status","aria-live":"polite",children:"Converting your file — this can take a while for a long document."}):null,y.length>0?e.jsx("ul",{"aria-live":"polite",children:y.map((j,R)=>e.jsx("li",{children:j.message},`${j.type}-${R}`))}):null,C&&!_?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=Qe;exports.ImportUploadPanel=tt;exports.ImportWizard=Ge;exports.ProcessingPanel=_e;