@pretextbook/import 0.0.1 → 0.2.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/README.md CHANGED
@@ -1,121 +1,118 @@
1
- # @pretextbook/import
2
-
3
- Shared helpers for importing existing source content into PreTeXt.
4
-
5
- Two use cases:
6
-
7
- - VS Code extension logic: format detection, cleaning, and conversion utilities.
8
- - Web apps: React components for paste-or-upload import UX, plus a non-React
9
- library entry point suitable for server-side or extension-host use.
10
-
11
- The LaTeX cleaning pipeline is a TypeScript port of
12
- [`davidfarmer/PreprocessLaTeX`](https://github.com/davidfarmer/PreprocessLaTeX)
13
- (`src/main.js`'s `describeFiles` flow): drop comments, normalize whitespace,
14
- expand `\input`/`\include`, rewrite plain-TeX font directives, scrub
15
- presentation macros, and convert via `@pretextbook/latex-pretext`.
16
-
17
- ## Install
18
-
19
- ```sh
20
- npm install @pretextbook/import
21
- ```
22
-
23
- ## Utilities
24
-
25
- ```ts
26
- import {
27
- detectSourceFormat,
28
- convertSourceToPretext,
29
- importProjectFromFiles,
30
- } from "@pretextbook/import";
31
-
32
- const format = detectSourceFormat(rawInput);
33
- const result = convertSourceToPretext(rawInput, format);
34
-
35
- if ("pretextError" in result) {
36
- console.error(result.pretextError);
37
- } else {
38
- console.log(result.pretextSource);
39
- console.log(result.warnings); // cleaning diagnostics
40
- }
41
-
42
- // Multi-file project import (file paths -> source text):
43
- const project = importProjectFromFiles({
44
- "main.tex": "\\documentclass{article}\\begin{document}Hi.\\end{document}",
45
- });
46
- if ("outputFiles" in project) {
47
- // Standard PreTeXt project layout, keyed by path:
48
- console.log(project.outputFiles["source/main.ptx"]);
49
- console.log(project.outputFiles["project.ptx"]);
50
- console.log(project.outputFiles["publication/publication.ptx"]);
51
- }
52
- ```
53
-
54
- ### Book splitting
55
-
56
- If the converted source is a `<book>`, the layout splitter writes each
57
- `<chapter>` to its own file under `source/`, and `source/main.ptx` is rebuilt
58
- with `xi:include` references. Chapter filenames use `ch-<xml:id>.ptx` when an
59
- `xml:id` is present, falling back to a zero-padded index. Pass
60
- `splitSections: true` to additionally split each chapter by section.
61
-
62
- ```ts
63
- importProjectFromFiles(files, {
64
- documentKind: "book", // override auto-detect
65
- splitSections: true,
66
- });
67
- ```
68
-
69
- ## Upload pipeline
70
-
71
- ```ts
72
- import { handleImportUploadFile } from "@pretextbook/import";
73
-
74
- const result = await handleImportUploadFile(file);
75
- if ("pretextError" in result) {
76
- console.error(result.pretextError);
77
- } else {
78
- // Text files (the converted PreTeXt project + routed .bib auxiliaries)
79
- for (const [path, content] of Object.entries(result.outputFiles)) {
80
- saveOrUpload(path, content);
81
- }
82
- // Binary assets (images, PDFs, EPS) routed to source/assets/
83
- for (const [path, bytes] of Object.entries(result.outputAssets)) {
84
- saveBinary(path, bytes);
85
- }
86
- // Optional cleaned native source (LaTeX/Markdown), if the input was that format
87
- if (result.nativeOutputFiles) {
88
- for (const [path, content] of Object.entries(result.nativeOutputFiles)) {
89
- saveOrUpload(path, content);
90
- }
91
- }
92
- }
93
- ```
94
-
95
- Supports `.tex`, `.md`, `.ptx`, `.xml`, `.zip`, and `.tar.gz` uploads. For zip
96
- and tar.gz archives, the extractor identifies the main source file, expands
97
- LaTeX `\input`/`\include` or PreTeXt `xi:include` references, and routes
98
- binaries (`.png`, `.jpg`, `.pdf`, `.eps`, ...) into `source/assets/` and `.bib`
99
- files into `source/`.
100
-
101
- ## React Components
102
-
103
- ```tsx
104
- import {
105
- ImportSourceForm,
106
- ImportUploadPanel,
107
- } from "@pretextbook/import/react";
108
-
109
- function ImportPanel() {
110
- return (
111
- <>
112
- <ImportSourceForm onImport={(r) => console.log(r)} />
113
- <ImportUploadPanel onImport={(r) => console.log(r)} />
114
- </>
115
- );
116
- }
117
- ```
118
-
119
- `ImportUploadPanel` exposes UI controls for the `documentKind` override and
120
- `splitSections` toggle. Pass `importOptions={...}` to suppress those controls
121
- and use a fixed configuration.
1
+ # @pretextbook/import
2
+
3
+ Shared helpers for importing existing source content into PreTeXt.
4
+
5
+ Two use cases:
6
+
7
+ - VS Code extension logic: format detection, cleaning, and conversion utilities.
8
+ - Web apps: React components for paste-or-upload import UX, plus a non-React
9
+ library entry point suitable for server-side or extension-host use.
10
+
11
+ The LaTeX cleaning pipeline is a TypeScript port of
12
+ [`davidfarmer/PreprocessLaTeX`](https://github.com/davidfarmer/PreprocessLaTeX)
13
+ (`src/main.js`'s `describeFiles` flow): drop comments, normalize whitespace,
14
+ expand `\input`/`\include`, rewrite plain-TeX font directives, scrub
15
+ presentation macros, and convert via `@pretextbook/latex-pretext`.
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ npm install @pretextbook/import
21
+ ```
22
+
23
+ ## Utilities
24
+
25
+ ```ts
26
+ import {
27
+ detectSourceFormat,
28
+ convertSourceToPretext,
29
+ importProjectFromFiles,
30
+ } from "@pretextbook/import";
31
+
32
+ const format = detectSourceFormat(rawInput);
33
+ const result = convertSourceToPretext(rawInput, format);
34
+
35
+ if ("pretextError" in result) {
36
+ console.error(result.pretextError);
37
+ } else {
38
+ console.log(result.pretextSource);
39
+ console.log(result.warnings); // cleaning diagnostics
40
+ }
41
+
42
+ // Multi-file project import (file paths -> source text):
43
+ const project = importProjectFromFiles({
44
+ "main.tex": "\\documentclass{article}\\begin{document}Hi.\\end{document}",
45
+ });
46
+ if ("outputFiles" in project) {
47
+ // Standard PreTeXt project layout, keyed by path:
48
+ console.log(project.outputFiles["source/main.ptx"]);
49
+ console.log(project.outputFiles["project.ptx"]);
50
+ console.log(project.outputFiles["publication/publication.ptx"]);
51
+ }
52
+ ```
53
+
54
+ ### Book splitting
55
+
56
+ If the converted source is a `<book>`, the layout splitter writes each
57
+ `<chapter>` to its own file under `source/`, and `source/main.ptx` is rebuilt
58
+ with `xi:include` references. Chapter filenames use `ch-<xml:id>.ptx` when an
59
+ `xml:id` is present, falling back to a zero-padded index. Pass
60
+ `splitSections: true` to additionally split each chapter by section.
61
+
62
+ ```ts
63
+ importProjectFromFiles(files, {
64
+ documentKind: "book", // override auto-detect
65
+ splitSections: true,
66
+ });
67
+ ```
68
+
69
+ ## Upload pipeline
70
+
71
+ ```ts
72
+ import { handleImportUploadFile } from "@pretextbook/import";
73
+
74
+ const result = await handleImportUploadFile(file);
75
+ if ("pretextError" in result) {
76
+ console.error(result.pretextError);
77
+ } else {
78
+ // Text files (the converted PreTeXt project + routed .bib auxiliaries)
79
+ for (const [path, content] of Object.entries(result.outputFiles)) {
80
+ saveOrUpload(path, content);
81
+ }
82
+ // Binary assets (images, PDFs, EPS) routed to source/assets/
83
+ for (const [path, bytes] of Object.entries(result.outputAssets)) {
84
+ saveBinary(path, bytes);
85
+ }
86
+ // Optional cleaned native source (LaTeX/Markdown), if the input was that format
87
+ if (result.nativeOutputFiles) {
88
+ for (const [path, content] of Object.entries(result.nativeOutputFiles)) {
89
+ saveOrUpload(path, content);
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ Supports `.tex`, `.md`, `.ptx`, `.xml`, `.zip`, and `.tar.gz` uploads. For zip
96
+ and tar.gz archives, the extractor identifies the main source file, expands
97
+ LaTeX `\input`/`\include` or PreTeXt `xi:include` references, and routes
98
+ binaries (`.png`, `.jpg`, `.pdf`, `.eps`, ...) into `source/assets/` and `.bib`
99
+ files into `source/`.
100
+
101
+ ## React Components
102
+
103
+ ```tsx
104
+ import { ImportSourceForm, ImportUploadPanel } from "@pretextbook/import/react";
105
+
106
+ function ImportPanel() {
107
+ return (
108
+ <>
109
+ <ImportSourceForm onImport={(r) => console.log(r)} />
110
+ <ImportUploadPanel onImport={(r) => console.log(r)} />
111
+ </>
112
+ );
113
+ }
114
+ ```
115
+
116
+ `ImportUploadPanel` exposes UI controls for the `documentKind` override and
117
+ `splitSections` toggle. Pass `importOptions={...}` to suppress those controls
118
+ and use a fixed configuration.
@@ -343,7 +343,12 @@ function Re(d) {
343
343
  p,
344
344
  { type: "line", action: "delete" },
345
345
  c
346
- ), a = ut(a, p, { type: "line", action: "delete" }, c);
346
+ ), a = ut(
347
+ a,
348
+ p,
349
+ { type: "line", action: "delete" },
350
+ c
351
+ );
347
352
  for (const p of Se)
348
353
  f = ut(
349
354
  f,
@@ -560,7 +565,9 @@ function Xe(d) {
560
565
  if (!r.trim())
561
566
  return { pretext: "", cleanedLatex: r, warnings: i };
562
567
  const l = f ? r + `
563
- \\end{document}` : r, p = Me(ge(l)).trim();
568
+ \\end{document}` : r, p = Me(
569
+ ge(l)
570
+ ).trim();
564
571
  if (!p)
565
572
  return { pretext: "", cleanedLatex: r, warnings: i };
566
573
  const w = He(p, a);
@@ -3075,9 +3082,7 @@ function Nt(d, c) {
3075
3082
  end: r.end,
3076
3083
  inner: d.slice(n.end, r.pos),
3077
3084
  outer: d.slice(n.pos, r.end),
3078
- attributes: At(
3079
- n.attrs
3080
- )
3085
+ attributes: At(n.attrs)
3081
3086
  }), n = null);
3082
3087
  }
3083
3088
  return f;
@@ -3310,7 +3315,10 @@ ${S}
3310
3315
  replacement: `<plus:section ref="${k.ref}"/>`
3311
3316
  };
3312
3317
  });
3313
- B = qt(z.inner, P);
3318
+ B = qt(
3319
+ z.inner,
3320
+ P
3321
+ );
3314
3322
  }
3315
3323
  return x.push({
3316
3324
  xmlId: R.ref,
@@ -3384,10 +3392,13 @@ function _r(d, c) {
3384
3392
  return d.startsWith(e) ? d.slice(e.length) : d;
3385
3393
  }
3386
3394
  function ne(d, c) {
3387
- return d.replace($t, (e, f, a) => {
3388
- const n = c.get(a);
3389
- return n ? `<xi:include href="${n}"/>` : e;
3390
- });
3395
+ return d.replace(
3396
+ $t,
3397
+ (e, f, a) => {
3398
+ const n = c.get(a);
3399
+ return n ? `<xi:include href="${n}"/>` : e;
3400
+ }
3401
+ );
3391
3402
  }
3392
3403
  function br(d, c = {}) {
3393
3404
  const e = c.mainSourcePath ?? Ft.mainSourcePath, f = c.publicationPath ?? Ft.publicationPath, a = c.projectFilePath ?? Ft.projectFilePath, n = c.includeScaffold ?? !0, r = {}, i = new Map(
package/dist/import.css CHANGED
@@ -1 +1 @@
1
- @layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-red-50:oklch(97.1% .013 17.38);--color-red-200:oklch(88.5% .062 18.334);--color-red-800:oklch(44.4% .177 26.899);--color-amber-50:oklch(98.7% .022 95.277);--color-amber-100:oklch(96.2% .059 95.617);--color-amber-200:oklch(92.4% .12 95.746);--color-amber-700:oklch(55.5% .163 48.998);--color-amber-800:oklch(47.3% .137 46.201);--color-green-700:oklch(52.7% .154 150.069);--color-blue-50:oklch(97% .014 254.604);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-blue-700:oklch(48.8% .243 264.376);--color-slate-50:oklch(98.4% .003 247.858);--color-slate-100:oklch(96.8% .007 247.896);--color-slate-200:oklch(92.9% .013 255.508);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-400:oklch(70.4% .04 256.788);--color-slate-500:oklch(55.4% .046 257.417);--color-slate-600:oklch(44.6% .043 257.281);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-800:oklch(27.9% .041 260.031);--color-slate-900:oklch(20.8% .042 265.755);--color-white:#fff;--spacing:.25rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--font-weight-medium:500;--font-weight-semibold:600;--leading-relaxed:1.625;--radius-lg:.5rem;--animate-spin:spin 1s linear infinite;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.collapse{visibility:collapse}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.container{width:100%}@media(min-width:40rem){.container{max-width:40rem}}@media(min-width:48rem){.container{max-width:48rem}}@media(min-width:64rem){.container{max-width:64rem}}@media(min-width:80rem){.container{max-width:80rem}}@media(min-width:96rem){.container{max-width:96rem}}.m-0{margin:calc(var(--spacing) * 0)}.mt-0\.5{margin-top:calc(var(--spacing) * .5)}.mt-1{margin-top:calc(var(--spacing) * 1)}.mt-2{margin-top:calc(var(--spacing) * 2)}.mt-3{margin-top:calc(var(--spacing) * 3)}.mb-3{margin-bottom:calc(var(--spacing) * 3)}.block{display:block}.contents{display:contents}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.h-8{height:calc(var(--spacing) * 8)}.max-h-72{max-height:calc(var(--spacing) * 72)}.w-8{width:calc(var(--spacing) * 8)}.w-full{width:100%}.flex-1{flex:1}.shrink-0{flex-shrink:0}.animate-spin{animation:var(--animate-spin)}.cursor-pointer{cursor:pointer}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-2{gap:calc(var(--spacing) * 2)}.gap-3{gap:calc(var(--spacing) * 3)}.gap-4{gap:calc(var(--spacing) * 4)}:where(.space-y-1\.5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 1.5) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 1.5) * calc(1 - var(--tw-space-y-reverse)))}.gap-x-6{column-gap:calc(var(--spacing) * 6)}.gap-y-2{row-gap:calc(var(--spacing) * 2)}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.rounded{border-radius:.25rem}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.border{border-style:var(--tw-border-style);border-width:1px}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-amber-200{border-color:var(--color-amber-200)}.border-blue-500{border-color:var(--color-blue-500)}.border-blue-700{border-color:var(--color-blue-700)}.border-red-200{border-color:var(--color-red-200)}.border-slate-200{border-color:var(--color-slate-200)}.border-slate-300{border-color:var(--color-slate-300)}.border-t-transparent{border-top-color:#0000}.bg-amber-50{background-color:var(--color-amber-50)}.bg-amber-100{background-color:var(--color-amber-100)}.bg-blue-50{background-color:var(--color-blue-50)}.bg-blue-700{background-color:var(--color-blue-700)}.bg-red-50{background-color:var(--color-red-50)}.bg-slate-50{background-color:var(--color-slate-50)}.bg-slate-100{background-color:var(--color-slate-100)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-10{padding:calc(var(--spacing) * 10)}.px-1{padding-inline:calc(var(--spacing) * 1)}.px-2{padding-inline:calc(var(--spacing) * 2)}.px-4{padding-inline:calc(var(--spacing) * 4)}.py-0\.5{padding-block:calc(var(--spacing) * .5)}.py-1{padding-block:calc(var(--spacing) * 1)}.py-2{padding-block:calc(var(--spacing) * 2)}.py-16{padding-block:calc(var(--spacing) * 16)}.pt-1{padding-top:calc(var(--spacing) * 1)}.text-center{text-align:center}.text-left{text-align:left}.font-mono{font-family:var(--font-mono)}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.text-amber-700{color:var(--color-amber-700)}.text-amber-800{color:var(--color-amber-800)}.text-green-700{color:var(--color-green-700)}.text-red-800{color:var(--color-red-800)}.text-slate-400{color:var(--color-slate-400)}.text-slate-500{color:var(--color-slate-500)}.text-slate-600{color:var(--color-slate-600)}.text-slate-700{color:var(--color-slate-700)}.text-slate-800{color:var(--color-slate-800)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.capitalize{text-transform:capitalize}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.last\:border-b-0:last-child{border-bottom-style:var(--tw-border-style);border-bottom-width:0}@media(hover:hover){.hover\:border-slate-400:hover{border-color:var(--color-slate-400)}.hover\:bg-blue-600:hover{background-color:var(--color-blue-600)}.hover\:bg-slate-50:hover{background-color:var(--color-slate-50)}.hover\:bg-slate-200:hover{background-color:var(--color-slate-200)}.hover\:text-slate-900:hover{color:var(--color-slate-900)}}}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@keyframes spin{to{transform:rotate(360deg)}}
1
+ @layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial}}}@layer theme{:root,:host{--font-sans:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-red-50:oklch(97.1% .013 17.38);--color-red-200:oklch(88.5% .062 18.334);--color-red-800:oklch(44.4% .177 26.899);--color-amber-50:oklch(98.7% .022 95.277);--color-amber-100:oklch(96.2% .059 95.617);--color-amber-200:oklch(92.4% .12 95.746);--color-amber-700:oklch(55.5% .163 48.998);--color-amber-800:oklch(47.3% .137 46.201);--color-green-700:oklch(52.7% .154 150.069);--color-blue-50:oklch(97% .014 254.604);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-blue-700:oklch(48.8% .243 264.376);--color-slate-50:oklch(98.4% .003 247.858);--color-slate-100:oklch(96.8% .007 247.896);--color-slate-200:oklch(92.9% .013 255.508);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-400:oklch(70.4% .04 256.788);--color-slate-500:oklch(55.4% .046 257.417);--color-slate-600:oklch(44.6% .043 257.281);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-800:oklch(27.9% .041 260.031);--color-slate-900:oklch(20.8% .042 265.755);--color-white:#fff;--spacing:.25rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--font-weight-medium:500;--font-weight-semibold:600;--leading-relaxed:1.625;--radius-lg:.5rem;--animate-spin:spin 1s linear infinite;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring:where(:not(iframe)){outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.collapse{visibility:collapse}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.container{width:100%}@media(min-width:40rem){.container{max-width:40rem}}@media(min-width:48rem){.container{max-width:48rem}}@media(min-width:64rem){.container{max-width:64rem}}@media(min-width:80rem){.container{max-width:80rem}}@media(min-width:96rem){.container{max-width:96rem}}.m-0{margin:0}.mt-0\.5{margin-top:calc(var(--spacing) * .5)}.mt-1{margin-top:var(--spacing)}.mt-2{margin-top:calc(var(--spacing) * 2)}.mt-3{margin-top:calc(var(--spacing) * 3)}.mb-3{margin-bottom:calc(var(--spacing) * 3)}.block{display:block}.contents{display:contents}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.h-8{height:calc(var(--spacing) * 8)}.max-h-72{max-height:calc(var(--spacing) * 72)}.w-8{width:calc(var(--spacing) * 8)}.w-full{width:100%}.flex-1{flex:1}.shrink-0{flex-shrink:0}.animate-spin{animation:var(--animate-spin)}.cursor-pointer{cursor:pointer}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-2{gap:calc(var(--spacing) * 2)}.gap-3{gap:calc(var(--spacing) * 3)}.gap-4{gap:calc(var(--spacing) * 4)}:where(.space-y-1\.5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 1.5) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 1.5) * calc(1 - var(--tw-space-y-reverse)))}.gap-x-6{column-gap:calc(var(--spacing) * 6)}.gap-y-2{row-gap:calc(var(--spacing) * 2)}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.rounded{border-radius:.25rem}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.border{border-style:var(--tw-border-style);border-width:1px}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-amber-200{border-color:var(--color-amber-200)}.border-blue-500{border-color:var(--color-blue-500)}.border-blue-700{border-color:var(--color-blue-700)}.border-red-200{border-color:var(--color-red-200)}.border-slate-200{border-color:var(--color-slate-200)}.border-slate-300{border-color:var(--color-slate-300)}.border-t-transparent{border-top-color:#0000}.bg-amber-50{background-color:var(--color-amber-50)}.bg-amber-100{background-color:var(--color-amber-100)}.bg-blue-50{background-color:var(--color-blue-50)}.bg-blue-700{background-color:var(--color-blue-700)}.bg-red-50{background-color:var(--color-red-50)}.bg-slate-50{background-color:var(--color-slate-50)}.bg-slate-100{background-color:var(--color-slate-100)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-10{padding:calc(var(--spacing) * 10)}.px-1{padding-inline:var(--spacing)}.px-2{padding-inline:calc(var(--spacing) * 2)}.px-4{padding-inline:calc(var(--spacing) * 4)}.py-0\.5{padding-block:calc(var(--spacing) * .5)}.py-1{padding-block:var(--spacing)}.py-2{padding-block:calc(var(--spacing) * 2)}.py-16{padding-block:calc(var(--spacing) * 16)}.pt-1{padding-top:var(--spacing)}.text-center{text-align:center}.text-left{text-align:left}.font-mono{font-family:var(--font-mono)}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.text-amber-700{color:var(--color-amber-700)}.text-amber-800{color:var(--color-amber-800)}.text-green-700{color:var(--color-green-700)}.text-red-800{color:var(--color-red-800)}.text-slate-400{color:var(--color-slate-400)}.text-slate-500{color:var(--color-slate-500)}.text-slate-600{color:var(--color-slate-600)}.text-slate-700{color:var(--color-slate-700)}.text-slate-800{color:var(--color-slate-800)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.capitalize{text-transform:capitalize}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.last\:border-b-0:last-child{border-bottom-style:var(--tw-border-style);border-bottom-width:0}@media(hover:hover){.hover\:border-slate-400:hover{border-color:var(--color-slate-400)}.hover\:bg-blue-600:hover{background-color:var(--color-blue-600)}.hover\:bg-slate-50:hover{background-color:var(--color-slate-50)}.hover\:bg-slate-200:hover{background-color:var(--color-slate-200)}.hover\:text-slate-900:hover{color:var(--color-slate-900)}}}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@keyframes spin{to{transform:rotate(360deg)}}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { d as T, r as E, a as R, f as P, b as h, w as f, s as g, e as v, c as M, p as j } from "./import-mode-iBDd9oQY.js";
2
- import { L, M as U, g as z, h as O, i as N, j as W, k as B, l as X, m as q, n as G, o as H, q as J, t as Q, u as V, v as Y, x as Z, y as tt, z as et, A as nt } from "./import-mode-iBDd9oQY.js";
1
+ import { d as T, r as E, a as R, f as P, b as h, w as f, s as g, e as v, c as M, p as j } from "./import-mode-BDY8WcYJ.js";
2
+ import { L, M as U, g as z, h as O, i as N, j as W, k as B, l as X, m as q, n as G, o as H, q as J, t as Q, u as V, v as Y, x as Z, y as tt, z as et, A as nt } from "./import-mode-BDY8WcYJ.js";
3
3
  function x() {
4
4
  const t = globalThis.crypto;
5
5
  return t?.randomUUID ? t.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
@@ -99,7 +99,12 @@ function w(t, e, s) {
99
99
  const d = F(i, "ch", s).map((o) => {
100
100
  let m = o.span.outer;
101
101
  if (e.splitSections) {
102
- const y = o.span.inner, S = I(y, o.slug, a, s);
102
+ const y = o.span.inner, S = I(
103
+ y,
104
+ o.slug,
105
+ a,
106
+ s
107
+ );
103
108
  m = o.span.outer.slice(0, o.span.startTagEnd - o.span.start) + S + o.span.outer.slice(o.span.contentEnd - o.span.start);
104
109
  }
105
110
  const k = `source/${o.filename}`;
@@ -17,4 +17,4 @@ export interface ImportSourceFormProps {
17
17
  disabled?: boolean;
18
18
  onImport: (result: ConvertedPretextResult) => void;
19
19
  }
20
- export declare function ImportSourceForm({ initialSource, initialSourceFormat, labels, disabled, onImport, }: ImportSourceFormProps): import("react/jsx-runtime").JSX.Element;
20
+ export declare function ImportSourceForm({ initialSource, initialSourceFormat, labels, disabled, onImport, }: ImportSourceFormProps): import("react").JSX.Element;
@@ -18,4 +18,4 @@ export interface ImportUploadPanelProps {
18
18
  importOptions?: ImportProjectOptions;
19
19
  onImport: (result: ImportedProjectResult) => void;
20
20
  }
21
- export declare function ImportUploadPanel({ labels, disabled, defaultDocumentKind, importOptions, onImport, }: ImportUploadPanelProps): import("react/jsx-runtime").JSX.Element;
21
+ export declare function ImportUploadPanel({ labels, disabled, defaultDocumentKind, importOptions, onImport, }: ImportUploadPanelProps): import("react").JSX.Element;
@@ -1,8 +1,26 @@
1
1
  import { ImportProjectOptions } from '../lib/upload';
2
2
  import { ImportMode } from '../lib/import-mode';
3
3
  import { DocumentKind } from '../lib/layout/document-kind';
4
- import { ImportedProjectSuccess } from '../lib/types';
4
+ import { ImportedProjectResult, ImportedProjectSuccess } from '../lib/types';
5
5
  export type { ImportMode };
6
+ /**
7
+ * A pluggable conversion engine. The wizard owns the whole UI (upload, review,
8
+ * preview, confirm) and only delegates the source → result step to the selected
9
+ * engine, so hosts can inject their own converters (e.g. a VS Code-only pandoc
10
+ * engine that round-trips to the extension host) without touching this package.
11
+ */
12
+ export interface ImportEngine {
13
+ /** Stable identifier, used as the radio value. */
14
+ id: string;
15
+ /** Short name shown in the engine selector. */
16
+ label: string;
17
+ /** Optional one-line explanation shown under the label. */
18
+ description?: string;
19
+ /** Extensions this engine accepts (with leading dot). Defaults to the built-in set. */
20
+ acceptExtensions?: string[];
21
+ /** Convert an uploaded file into an import result. */
22
+ convertFile: (file: File, options: ImportProjectOptions) => Promise<ImportedProjectResult>;
23
+ }
6
24
  export interface ImportWizardProps {
7
25
  /** Called when the user confirms the import. */
8
26
  onConfirm: (result: ImportedProjectSuccess, mode: ImportMode) => void;
@@ -11,5 +29,10 @@ export interface ImportWizardProps {
11
29
  /** Pass fixed options to skip the document-kind / split-sections controls. */
12
30
  importOptions?: ImportProjectOptions;
13
31
  defaultDocumentKind?: DocumentKind | "auto";
32
+ /**
33
+ * Converters offered to the user. When more than one is supplied, an engine
34
+ * selector is shown on the upload step. Defaults to a single built-in engine.
35
+ */
36
+ engines?: ImportEngine[];
14
37
  }
15
- export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, }: ImportWizardProps): import("react/jsx-runtime").JSX.Element;
38
+ export declare function ImportWizard({ onConfirm, onCancel, importOptions, defaultDocumentKind, engines, }: ImportWizardProps): import("react").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  export { ImportWizard } from './import-wizard';
2
- export type { ImportWizardProps, ImportMode } from './import-wizard';
2
+ export type { ImportWizardProps, ImportMode, ImportEngine, } from './import-wizard';
3
3
  export { ImportSourceForm } from './import-source-form';
4
4
  export { ImportUploadPanel } from './import-upload-panel';
5
5
  export type { ImportSourceFormProps, ImportSourceFormLabels, } from './import-source-form';
package/dist/react.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),M=require("./import-mode-CSZlmUxw.cjs");var W={exports:{}},$={};var Z;function re(){if(Z)return $;Z=1;var h=Symbol.for("react.transitional.element"),E=Symbol.for("react.fragment");function v(g,u,n){var d=null;if(n!==void 0&&(d=""+n),u.key!==void 0&&(d=""+u.key),"key"in u){n={};for(var T in u)T!=="key"&&(n[T]=u[T])}else n=u;return u=n.ref,{$$typeof:h,type:g,key:d,ref:u!==void 0?u:null,props:n}}return $.Fragment=E,$.jsx=v,$.jsxs=v,$}var Y={};var Q;function se(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&(function(){function h(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===P?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case A:return"Fragment";case C:return"Profiler";case y:return"StrictMode";case U:return"Suspense";case B:return"SuspenseList";case p: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 k:return"Portal";case b:return t.displayName||"Context";case c: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 a:return r=t.displayName||null,r!==null?r:h(t.type)||"Memo";case s:r=t._payload,t=t._init;try{return h(t(r))}catch{}}return null}function E(t){return""+t}function v(t){try{E(t);var r=!1}catch{r=!0}if(r){r=console;var l=r.error,m=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return l.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",m),E(t)}}function g(t){if(t===A)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===s)return"<...>";try{var r=h(t);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function u(){var t=O.A;return t===null?null:t.getOwner()}function n(){return Error("react-stack-top-frame")}function d(t){if(I.call(t,"key")){var r=Object.getOwnPropertyDescriptor(t,"key").get;if(r&&r.isReactWarning)return!1}return t.key!==void 0}function T(t,r){function l(){o||(o=!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))}l.isReactWarning=!0,Object.defineProperty(t,"key",{get:l,configurable:!0})}function j(){var t=h(this.type);return D[t]||(D[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,r,l,m,X,K){var x=l.ref;return t={$$typeof:S,type:t,key:r,props:l,_owner:m},(x!==void 0?x:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:j}):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:X}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:K}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function N(t,r,l,m,X,K){var x=r.children;if(x!==void 0)if(m)if(q(x)){for(m=0;m<x.length;m++)R(x[m]);Object.freeze&&Object.freeze(x)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else R(x);if(I.call(r,"key")){x=h(t);var L=Object.keys(r).filter(function(te){return te!=="key"});m=0<L.length?"{key: someKey, "+L.join(": ..., ")+": ...}":"{key: someKey}",H[x+m]||(L=0<L.length?"{"+L.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),M=require("./import-mode-CSZlmUxw.cjs");var V={exports:{}},z={};var Z;function se(){if(Z)return z;Z=1;var b=Symbol.for("react.transitional.element"),T=Symbol.for("react.fragment");function g(N,i,a){var d=null;if(a!==void 0&&(d=""+a),i.key!==void 0&&(d=""+i.key),"key"in i){a={};for(var f in i)f!=="key"&&(a[f]=i[f])}else a=i;return i=a.ref,{$$typeof:b,type:N,key:d,ref:i!==void 0?i:null,props:a}}return z.Fragment=T,z.jsx=g,z.jsxs=g,z}var U={};var Q;function ne(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&(function(){function b(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===W?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case w:return"Fragment";case C:return"Profiler";case p:return"StrictMode";case $:return"Suspense";case X:return"SuspenseList";case B: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 _:return"Portal";case j:return t.displayName||"Context";case l:return(t._context.displayName||"Context")+".Consumer";case O:var r=t.render;return t=t.displayName,t||(t=r.displayName||r.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Y:return r=t.displayName||null,r!==null?r:b(t.type)||"Memo";case F:r=t._payload,t=t._init;try{return b(t(r))}catch{}}return null}function T(t){return""+t}function g(t){try{T(t);var r=!1}catch{r=!0}if(r){r=console;var o=r.error,u=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return o.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",u),T(t)}}function N(t){if(t===w)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===F)return"<...>";try{var r=b(t);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function i(){var t=D.A;return t===null?null:t.getOwner()}function a(){return Error("react-stack-top-frame")}function d(t){if(q.call(t,"key")){var r=Object.getOwnPropertyDescriptor(t,"key").get;if(r&&r.isReactWarning)return!1}return t.key!==void 0}function f(t,r){function o(){x||(x=!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))}o.isReactWarning=!0,Object.defineProperty(t,"key",{get:o,configurable:!0})}function h(){var t=b(this.type);return y[t]||(y[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 P(t,r,o,u,J,G){var m=o.ref;return t={$$typeof:E,type:t,key:r,props:o,_owner:u},(m!==void 0?m: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:J}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function v(t,r,o,u,J,G){var m=r.children;if(m!==void 0)if(u)if(s(m)){for(u=0;u<m.length;u++)k(m[u]);Object.freeze&&Object.freeze(m)}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 k(m);if(q.call(r,"key")){m=b(t);var L=Object.keys(r).filter(function(re){return re!=="key"});u=0<L.length?"{key: someKey, "+L.join(": ..., ")+": ...}":"{key: someKey}",K[m+u]||(L=0<L.length?"{"+L.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
2
  let props = %s;
3
3
  <%s {...props} />
4
4
  React keys must be passed directly to JSX without using spread:
5
5
  let props = %s;
6
- <%s key={someKey} {...props} />`,m,x,L,x),H[x+m]=!0)}if(x=null,l!==void 0&&(v(l),x=""+l),d(r)&&(v(r.key),x=""+r.key),"key"in r){l={};for(var J in r)J!=="key"&&(l[J]=r[J])}else l=r;return x&&T(l,typeof t=="function"?t.displayName||t.name||"Unknown":t),_(t,x,l,u(),X,K)}function R(t){w(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===s&&(t._payload.status==="fulfilled"?w(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function w(t){return typeof t=="object"&&t!==null&&t.$$typeof===S}var f=i,S=Symbol.for("react.transitional.element"),k=Symbol.for("react.portal"),A=Symbol.for("react.fragment"),y=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),b=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),U=Symbol.for("react.suspense"),B=Symbol.for("react.suspense_list"),a=Symbol.for("react.memo"),s=Symbol.for("react.lazy"),p=Symbol.for("react.activity"),P=Symbol.for("react.client.reference"),O=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=Object.prototype.hasOwnProperty,q=Array.isArray,z=console.createTask?console.createTask:function(){return null};f={react_stack_bottom_frame:function(t){return t()}};var o,D={},V=f.react_stack_bottom_frame.bind(f,n)(),G=z(g(n)),H={};Y.Fragment=A,Y.jsx=function(t,r,l){var m=1e4>O.recentlyCreatedOwnerStacks++;return N(t,r,l,!1,m?Error("react-stack-top-frame"):V,m?z(g(t)):G)},Y.jsxs=function(t,r,l){var m=1e4>O.recentlyCreatedOwnerStacks++;return N(t,r,l,!0,m?Error("react-stack-top-frame"):V,m?z(g(t)):G)}})()),Y}var ee;function ne(){return ee||(ee=1,process.env.NODE_ENV==="production"?W.exports=re():W.exports=se()),W.exports}var e=ne();function ae({onConfirm:h,onCancel:E,importOptions:v,defaultDocumentKind:g="auto"}){const u=i.useRef(null),[n,d]=i.useState({name:"upload"}),[T,j]=i.useState(!1),[_,N]=i.useState(g),[R,w]=i.useState(!1),[f,S]=i.useState("converted"),[k,A]=i.useState(!1),[y,C]=i.useState(new Set),c=async a=>{d({name:"processing"});try{const s=v??{documentKind:_==="auto"?void 0:_,splitSections:R},p=await M.handleImportUploadFile(a,s);"pretextError"in p?d({name:"error",message:p.pretextError}):d({name:"review",result:p})}catch(s){d({name:"error",message:s instanceof Error?s.message:"An unexpected error occurred."})}},b=()=>{d({name:"upload"}),S("converted"),A(!1),C(new Set)};function F(a,s){return[...a].sort((p,P)=>p===s?-1:P===s?1:p.localeCompare(P))}function U(a,s){const p=M.filesForImportMode(a,s),P=s==="converted"?"source/main.ptx":a.sourcePath,O=F(Object.keys(p),P)[0];C(O?new Set([O]):new Set)}function B(a){C(s=>{const p=new Set(s);return p.has(a)?p.delete(a):p.add(a),p})}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:b,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==="review"){let a=function(o){S(o),k&&U(s,o)};const{result:s}=n,p=s.detectedSourceFormat==="latex",P=s.warnings.length,O=Object.keys(s.outputFiles).length,I=M.filesForImportMode(s,f),q=f==="converted"?"source/main.ptx":s.sourcePath,z=F(Object.keys(I),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: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:O})]})]}),P>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:[P," conversion ",P===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:s.warnings.map((o,D)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:o.macro})," — ",o.action==="replace"||o.action==="rewrite"?`replaced with \`${o.replacement}\``:o.message??o.action,o.occurrences>1?` (×${o.occurrences})`:null]},D))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),p?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:()=>a("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:()=>a("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,k?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:z.map(o=>{const D=y.has(o);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>B(o),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:D?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:o}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(I[o].length/1024).toFixed(1)," KB"]})]}),D?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:I[o]}):null]},o)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:E??b,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:E?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{k||U(s,f),A(o=>!o)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:k?"Hide Preview":"Preview"}),e.jsx("button",{type:"button",onClick:()=>h(s,f),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:[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:_,onChange:a=>N(a.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:R,onChange:a=>w(a.currentTarget.checked)}),"Split sections into separate files"]})]}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:a=>a.key==="Enter"&&u.current?.click(),onClick:()=>u.current?.click(),onDragOver:a=>{a.preventDefault(),j(!0)},onDragLeave:()=>j(!1),onDrop:a=>{a.preventDefault(),j(!1);const s=a.dataTransfer.files?.[0];s&&c(s)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${T?"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:a=>{a.stopPropagation(),u.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.jsx("p",{className:"text-xs text-slate-400",children:"Supports .tex, .md, .ptx, .xml, .zip, .tar.gz"}),e.jsx("input",{ref:u,type:"file",hidden:!0,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:a=>{const s=a.currentTarget.files?.[0];s&&c(s),a.currentTarget.value=""}})]})]})}const oe={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 le({initialSource:h="",initialSourceFormat:E,labels:v,disabled:g=!1,onImport:u}){const n=i.useMemo(()=>({...oe,...v??{}}),[v]),[d,T]=i.useState(h),[j,_]=i.useState(E??"auto"),[N,R]=i.useState(null),w=i.useMemo(()=>M.detectSourceFormat(d),[d]),f=g||!d.trim();return e.jsx("form",{onSubmit:S=>{S.preventDefault();const k=M.convertSourceToPretext(d,j==="auto"?void 0:j);R(k),u(k)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:g,children:[e.jsx("legend",{children:n.title}),e.jsx("p",{children:n.description}),e.jsxs("label",{children:[n.sourceLabel,e.jsx("textarea",{value:d,onChange:S=>T(S.currentTarget.value),placeholder:n.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[n.formatLabel,e.jsxs("select",{value:j,onChange:S=>_(S.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:[n.detectedFormatPrefix,": ",e.jsx("strong",{children:w})]}),e.jsx("button",{type:"submit",disabled:f,children:n.convertButton}),N?"pretextError"in N?e.jsxs("p",{role:"alert",children:[n.errorPrefix,": ",N.pretextError]}):e.jsxs("p",{children:[n.successPrefix,": ",N.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const ce={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:h,disabled:E=!1,defaultDocumentKind:v="auto",importOptions:g,onImport:u}){const n=i.useMemo(()=>({...ce,...h??{}}),[h]),d=i.useRef(null),[T,j]=i.useState(!1),[_,N]=i.useState(!1),[R,w]=i.useState([]),[f,S]=i.useState(v),[k,A]=i.useState(!1),y=E||_,C=async c=>{N(!0);try{const b=g??{documentKind:f==="auto"?void 0:f,splitSections:k},F=await M.handleImportUploadFile(c,b);w(F.statusMessages),u(F)}finally{N(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:n.title}),e.jsx("p",{children:n.hint}),g?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[n.documentKindLabel,e.jsxs("select",{value:f,disabled:y,onChange:c=>S(c.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:k,disabled:y,onChange:c=>A(c.currentTarget.checked)}),n.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:c=>{c.preventDefault(),y||j(!0)},onDragLeave:()=>j(!1),onDrop:c=>{if(c.preventDefault(),j(!1),y)return;const b=c.dataTransfer.files?.[0];b&&C(b)},children:[e.jsx("p",{children:n.dropHint}),e.jsx("button",{type:"button",disabled:y,onClick:()=>d.current?.click(),children:_?"Processing...":n.selectButton}),e.jsx("input",{ref:d,type:"file",hidden:!0,disabled:y,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:c=>{const b=c.currentTarget.files?.[0];b&&C(b),c.currentTarget.value=""}})]}),R.length>0?e.jsx("ul",{"aria-live":"polite",children:R.map((c,b)=>e.jsx("li",{children:c.message},`${c.type}-${b}`))}):null,T&&!y?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=le;exports.ImportUploadPanel=ie;exports.ImportWizard=ae;
6
+ <%s key={someKey} {...props} />`,u,m,L,m),K[m+u]=!0)}if(m=null,o!==void 0&&(g(o),m=""+o),d(r)&&(g(r.key),m=""+r.key),"key"in r){o={};for(var H in r)H!=="key"&&(o[H]=r[H])}else o=r;return m&&f(o,typeof t=="function"?t.displayName||t.name||"Unknown":t),P(t,m,o,i(),J,G)}function k(t){R(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===F&&(t._payload.status==="fulfilled"?R(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function R(t){return typeof t=="object"&&t!==null&&t.$$typeof===E}var S=c,E=Symbol.for("react.transitional.element"),_=Symbol.for("react.portal"),w=Symbol.for("react.fragment"),p=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),l=Symbol.for("react.consumer"),j=Symbol.for("react.context"),O=Symbol.for("react.forward_ref"),$=Symbol.for("react.suspense"),X=Symbol.for("react.suspense_list"),Y=Symbol.for("react.memo"),F=Symbol.for("react.lazy"),B=Symbol.for("react.activity"),W=Symbol.for("react.client.reference"),D=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,q=Object.prototype.hasOwnProperty,s=Array.isArray,n=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(t){return t()}};var x,y={},A=S.react_stack_bottom_frame.bind(S,a)(),I=n(N(a)),K={};U.Fragment=w,U.jsx=function(t,r,o){var u=1e4>D.recentlyCreatedOwnerStacks++;return v(t,r,o,!1,u?Error("react-stack-top-frame"):A,u?n(N(t)):I)},U.jsxs=function(t,r,o){var u=1e4>D.recentlyCreatedOwnerStacks++;return v(t,r,o,!0,u?Error("react-stack-top-frame"):A,u?n(N(t)):I)}})()),U}var ee;function ae(){return ee||(ee=1,process.env.NODE_ENV==="production"?V.exports=se():V.exports=ne()),V.exports}var e=ae();const te=[".tex",".md",".markdown",".ptx",".xml",".zip",".gz",".tar.gz",".tgz"],oe={id:"builtin",label:"Built-in converter",description:"Create a new project starting with LaTeX, Markdown, or PreTeXt files.",acceptExtensions:te,convertFile:M.handleImportUploadFile};function le({onConfirm:b,onCancel:T,importOptions:g,defaultDocumentKind:N="auto",engines:i}){const a=i&&i.length>0?i:[oe],d=c.useRef(null),[f,h]=c.useState({name:"upload"}),[P,v]=c.useState(!1),[k,R]=c.useState(N),[S,E]=c.useState(!1),[_,w]=c.useState(a[0].id),[p,C]=c.useState("converted"),[l,j]=c.useState(!1),[O,$]=c.useState(new Set),X=a.find(s=>s.id===_)??a[0],Y=X.acceptExtensions??te,F=async s=>{h({name:"processing"});try{const n=g??{documentKind:k==="auto"?void 0:k,splitSections:S},x=await X.convertFile(s,n);"pretextError"in x?h({name:"error",message:x.pretextError}):h({name:"review",result:x})}catch(n){h({name:"error",message:n instanceof Error?n.message:"An unexpected error occurred."})}},B=()=>{h({name:"upload"}),C("converted"),j(!1),$(new Set)};function W(s,n){return[...s].sort((x,y)=>x===n?-1:y===n?1:x.localeCompare(y))}function D(s,n){const x=M.filesForImportMode(s,n),y=n==="converted"?"source/main.ptx":s.sourcePath,A=W(Object.keys(x),y)[0];$(A?new Set([A]):new Set)}function q(s){$(n=>{const x=new Set(n);return x.has(s)?x.delete(s):x.add(s),x})}if(f.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(f.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:f.message})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:B,className:"rounded bg-blue-700 px-4 py-2 text-sm font-medium text-white hover:bg-blue-600",children:"Try Another File"})})]});if(f.name==="review"){let s=function(r){C(r),l&&D(n,r)};const{result:n}=f,x=n.detectedSourceFormat==="latex",y=n.warnings.length,A=Object.keys(n.outputFiles).length,I=M.filesForImportMode(n,p),K=p==="converted"?"source/main.ptx":n.sourcePath,t=W(Object.keys(I),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:A})]})]}),y>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:[y," conversion"," ",y===1?"warning":"warnings"]}),e.jsx("ul",{className:"mt-3 space-y-1.5 text-amber-700",children:n.warnings.map((r,o)=>e.jsxs("li",{children:[e.jsx("code",{className:"rounded bg-amber-100 px-1 py-0.5 text-xs",children:r.macro})," — ",r.action==="replace"||r.action==="rewrite"?`replaced with \`${r.replacement}\``:r.message??r.action,r.occurrences>1?` (×${r.occurrences})`:null]},o))})]}):e.jsx("p",{className:"text-sm text-green-700",children:"No conversion warnings."}),x?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:p==="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:p==="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,l?e.jsx("div",{className:"overflow-hidden rounded-lg border border-slate-200 text-sm",children:t.map(r=>{const o=O.has(r);return e.jsxs("div",{className:"border-b border-slate-200 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>q(r),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:o?"▾":"▸"}),e.jsx("span",{className:"flex-1 truncate",children:r}),e.jsxs("span",{className:"shrink-0 text-slate-400",children:[(I[r].length/1024).toFixed(1)," KB"]})]}),o?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:I[r]}):null]},r)})}):null,e.jsxs("div",{className:"flex items-center justify-between gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:T??B,className:"px-4 py-2 text-sm text-slate-600 hover:text-slate-900",children:T?"Cancel":"Start Over"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{l||D(n,p),j(r=>!r)},className:"rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50",children:l?"Hide Preview":"Preview"}),e.jsx("button",{type:"button",onClick:()=>b(n,p),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:[a.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:a.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:_===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,g?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:k,onChange:s=>R(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("label",{className:"flex items-center gap-2 text-sm text-slate-700",children:[e.jsx("input",{type:"checkbox",checked:S,onChange:s=>E(s.currentTarget.checked)}),"Split sections into separate files"]})]}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&d.current?.click(),onClick:()=>d.current?.click(),onDragOver:s=>{s.preventDefault(),v(!0)},onDragLeave:()=>v(!1),onDrop:s=>{s.preventDefault(),v(!1);const n=s.dataTransfer.files?.[0];n&&F(n)},className:`flex cursor-pointer flex-col items-center gap-3 rounded-lg border-2 border-dashed p-10 text-center transition-colors ${P?"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(),d.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 ",Y.join(", ")]}),e.jsx("input",{ref:d,type:"file",hidden:!0,accept:Y.join(","),onChange:s=>{const n=s.currentTarget.files?.[0];n&&F(n),s.currentTarget.value=""}})]})]})}const ce={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 ie({initialSource:b="",initialSourceFormat:T,labels:g,disabled:N=!1,onImport:i}){const a=c.useMemo(()=>({...ce,...g??{}}),[g]),[d,f]=c.useState(b),[h,P]=c.useState(T??"auto"),[v,k]=c.useState(null),R=c.useMemo(()=>M.detectSourceFormat(d),[d]),S=N||!d.trim();return e.jsx("form",{onSubmit:E=>{E.preventDefault();const _=M.convertSourceToPretext(d,h==="auto"?void 0:h);k(_),i(_)},"aria-label":"Import source form",children:e.jsxs("fieldset",{disabled:N,children:[e.jsx("legend",{children:a.title}),e.jsx("p",{children:a.description}),e.jsxs("label",{children:[a.sourceLabel,e.jsx("textarea",{value:d,onChange:E=>f(E.currentTarget.value),placeholder:a.sourcePlaceholder,rows:12})]}),e.jsxs("label",{children:[a.formatLabel,e.jsxs("select",{value:h,onChange:E=>P(E.currentTarget.value),children:[e.jsx("option",{value:"auto",children:"Auto detect"}),e.jsx("option",{value:"latex",children:"LaTeX"}),e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"pretext",children:"PreTeXt"})]})]}),e.jsxs("p",{children:[a.detectedFormatPrefix,": ",e.jsx("strong",{children:R})]}),e.jsx("button",{type:"submit",disabled:S,children:a.convertButton}),v?"pretextError"in v?e.jsxs("p",{role:"alert",children:[a.errorPrefix,": ",v.pretextError]}):e.jsxs("p",{children:[a.successPrefix,": ",v.pretextSource.length," characters of PreTeXt generated."]}):null]})})}const de={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 ue({labels:b,disabled:T=!1,defaultDocumentKind:g="auto",importOptions:N,onImport:i}){const a=c.useMemo(()=>({...de,...b??{}}),[b]),d=c.useRef(null),[f,h]=c.useState(!1),[P,v]=c.useState(!1),[k,R]=c.useState([]),[S,E]=c.useState(g),[_,w]=c.useState(!1),p=T||P,C=async l=>{v(!0);try{const j=N??{documentKind:S==="auto"?void 0:S,splitSections:_},O=await M.handleImportUploadFile(l,j);R(O.statusMessages),i(O)}finally{v(!1)}};return e.jsxs("section",{"aria-label":"Import upload panel",children:[e.jsx("h3",{children:a.title}),e.jsx("p",{children:a.hint}),N?null:e.jsxs("div",{className:"import-options",children:[e.jsxs("label",{children:[a.documentKindLabel,e.jsxs("select",{value:S,disabled:p,onChange:l=>E(l.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:_,disabled:p,onChange:l=>w(l.currentTarget.checked)}),a.splitSectionsLabel]})]}),e.jsxs("div",{onDragOver:l=>{l.preventDefault(),p||h(!0)},onDragLeave:()=>h(!1),onDrop:l=>{if(l.preventDefault(),h(!1),p)return;const j=l.dataTransfer.files?.[0];j&&C(j)},children:[e.jsx("p",{children:a.dropHint}),e.jsx("button",{type:"button",disabled:p,onClick:()=>d.current?.click(),children:P?"Processing...":a.selectButton}),e.jsx("input",{ref:d,type:"file",hidden:!0,disabled:p,accept:".tex,.md,.markdown,.ptx,.xml,.zip,.gz,.tar.gz,.tgz",onChange:l=>{const j=l.currentTarget.files?.[0];j&&C(j),l.currentTarget.value=""}})]}),k.length>0?e.jsx("ul",{"aria-live":"polite",children:k.map((l,j)=>e.jsx("li",{children:l.message},`${l.type}-${j}`))}):null,f&&!p?e.jsx("p",{children:"Release to upload the file."}):null]})}exports.ImportSourceForm=ie;exports.ImportUploadPanel=ue;exports.ImportWizard=le;