@pretextbook/import 0.8.0 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/import",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Shared import helpers for converting LaTeX/Markdown/PreTeXt into PreTeXt for VS Code and web apps",
5
5
  "author": "Oscar Levin",
6
6
  "license": "MIT",
@@ -1,112 +0,0 @@
1
- import { X as p, a4 as h } from "./upload-BmErkg8I.js";
2
- function u(e, i) {
3
- const n = e.length === 0 ? [] : e.split(`
4
- `), o = i.length === 0 ? [] : i.split(`
5
- `);
6
- if (n.length + o.length > d)
7
- return [
8
- ...n.map(
9
- (s, l) => ({ op: "remove", text: s, beforeLine: l + 1 })
10
- ),
11
- ...o.map((s, l) => ({ op: "add", text: s, afterLine: l + 1 }))
12
- ];
13
- const a = Array.from(
14
- { length: n.length + 1 },
15
- () => new Array(o.length + 1).fill(0)
16
- );
17
- for (let s = n.length - 1; s >= 0; s--)
18
- for (let l = o.length - 1; l >= 0; l--)
19
- a[s][l] = n[s] === o[l] ? a[s + 1][l + 1] + 1 : Math.max(a[s + 1][l], a[s][l + 1]);
20
- const c = [];
21
- let t = 0, r = 0;
22
- for (; t < n.length && r < o.length; )
23
- n[t] === o[r] ? (c.push({
24
- op: "keep",
25
- text: n[t],
26
- beforeLine: t + 1,
27
- afterLine: r + 1
28
- }), t++, r++) : a[t + 1][r] >= a[t][r + 1] ? (c.push({ op: "remove", text: n[t], beforeLine: t + 1 }), t++) : (c.push({ op: "add", text: o[r], afterLine: r + 1 }), r++);
29
- for (; t < n.length; )
30
- c.push({ op: "remove", text: n[t], beforeLine: ++t });
31
- for (; r < o.length; ) c.push({ op: "add", text: o[r], afterLine: ++r });
32
- return c;
33
- }
34
- const d = 2e4;
35
- function m(e) {
36
- let i = 0, n = 0;
37
- for (const o of e)
38
- o.op === "add" ? i++ : o.op === "remove" && n++;
39
- return { added: i, removed: n };
40
- }
41
- function g(e, i = 2) {
42
- const n = e.map((t, r) => t.op === "keep" ? -1 : r).filter((t) => t >= 0);
43
- if (n.length === 0) return [];
44
- const o = [];
45
- let a = Math.max(0, n[0] - i), c = Math.min(e.length - 1, n[0] + i);
46
- for (const t of n.slice(1)) {
47
- if (t - i <= c + 1) {
48
- c = Math.min(e.length - 1, t + i);
49
- continue;
50
- }
51
- o.push({ lines: e.slice(a, c + 1) }), a = Math.max(0, t - i), c = Math.min(e.length - 1, t + i);
52
- }
53
- return o.push({ lines: e.slice(a, c + 1) }), o;
54
- }
55
- function j(e, i = e.splitLevel) {
56
- if (e.cleanChunks.length === 0) return [];
57
- const n = p(e.cleanChunks, i), o = v(n), { pathByRef: a } = h(e.project, {
58
- mainSourcePath: e.projectLayout.mainSourcePath,
59
- publicationPath: e.projectLayout.publicationPath,
60
- projectFilePath: e.projectLayout.projectFilePath,
61
- includeScaffold: !e.projectLayout.preserved
62
- }), c = [];
63
- for (const t of e.project.divisions) {
64
- const r = a[t.xmlId];
65
- if (!r) continue;
66
- const s = t.isRoot ? n.find((f) => f.kind === "preamble" || f.kind === "lead") : o.get(t.title);
67
- if (!s) continue;
68
- const l = u(s.before, s.after);
69
- c.push({
70
- path: r,
71
- title: t.title,
72
- before: s.before,
73
- after: s.after,
74
- stats: m(l),
75
- hunks: g(l),
76
- fixCount: s.fixes.length
77
- });
78
- }
79
- return c.sort((t, r) => t.path.localeCompare(r.path));
80
- }
81
- function v(e) {
82
- const i = /* @__PURE__ */ new Map();
83
- for (const o of e)
84
- o.kind !== "division" || !o.title || i.set(o.title, i.has(o.title) ? null : o);
85
- const n = /* @__PURE__ */ new Map();
86
- for (const [o, a] of i)
87
- a && n.set(o, a);
88
- return n;
89
- }
90
- function k(e, i) {
91
- return i === "native" ? e.nativeProject ?? e.project : e.project;
92
- }
93
- function b(e, i) {
94
- return i === "converted" ? e.outputFiles : e.nativeOutputFiles ?? e.files;
95
- }
96
- function M(e, i) {
97
- return i === "converted" ? e.outputAssets : e.assets;
98
- }
99
- function F(e) {
100
- const i = e.action === "replace" || e.action === "rewrite" ? `replaced with \`${e.replacement}\`` : e.message ?? e.action, n = e.occurrences > 1 ? ` (x${e.occurrences})` : "";
101
- return `[${e.severity}] ${e.macro}: ${i}${n}`;
102
- }
103
- export {
104
- M as a,
105
- u as b,
106
- m as c,
107
- g as d,
108
- b as e,
109
- j as f,
110
- F as g,
111
- k as p
112
- };
@@ -1,3 +0,0 @@
1
- "use strict";const p=require("./upload-BtS22hIH.cjs");function h(e,i){const o=e.length===0?[]:e.split(`
2
- `),n=i.length===0?[]:i.split(`
3
- `);if(o.length+n.length>m)return[...o.map((s,f)=>({op:"remove",text:s,beforeLine:f+1})),...n.map((s,f)=>({op:"add",text:s,afterLine:f+1}))];const c=Array.from({length:o.length+1},()=>new Array(n.length+1).fill(0));for(let s=o.length-1;s>=0;s--)for(let f=n.length-1;f>=0;f--)c[s][f]=o[s]===n[f]?c[s+1][f+1]+1:Math.max(c[s+1][f],c[s][f+1]);const a=[];let t=0,r=0;for(;t<o.length&&r<n.length;)o[t]===n[r]?(a.push({op:"keep",text:o[t],beforeLine:t+1,afterLine:r+1}),t++,r++):c[t+1][r]>=c[t][r+1]?(a.push({op:"remove",text:o[t],beforeLine:t+1}),t++):(a.push({op:"add",text:n[r],afterLine:r+1}),r++);for(;t<o.length;)a.push({op:"remove",text:o[t],beforeLine:++t});for(;r<n.length;)a.push({op:"add",text:n[r],afterLine:++r});return a}const m=2e4;function u(e){let i=0,o=0;for(const n of e)n.op==="add"?i++:n.op==="remove"&&o++;return{added:i,removed:o}}function d(e,i=2){const o=e.map((t,r)=>t.op==="keep"?-1:r).filter(t=>t>=0);if(o.length===0)return[];const n=[];let c=Math.max(0,o[0]-i),a=Math.min(e.length-1,o[0]+i);for(const t of o.slice(1)){if(t-i<=a+1){a=Math.min(e.length-1,t+i);continue}n.push({lines:e.slice(c,a+1)}),c=Math.max(0,t-i),a=Math.min(e.length-1,t+i)}return n.push({lines:e.slice(c,a+1)}),n}function g(e,i=e.splitLevel){if(e.cleanChunks.length===0)return[];const o=p.mergeChunksAtLevel(e.cleanChunks,i),n=L(o),{pathByRef:c}=p.serializeProjectToFiles(e.project,{mainSourcePath:e.projectLayout.mainSourcePath,publicationPath:e.projectLayout.publicationPath,projectFilePath:e.projectLayout.projectFilePath,includeScaffold:!e.projectLayout.preserved}),a=[];for(const t of e.project.divisions){const r=c[t.xmlId];if(!r)continue;const s=t.isRoot?o.find(l=>l.kind==="preamble"||l.kind==="lead"):n.get(t.title);if(!s)continue;const f=h(s.before,s.after);a.push({path:r,title:t.title,before:s.before,after:s.after,stats:u(f),hunks:d(f),fixCount:s.fixes.length})}return a.sort((t,r)=>t.path.localeCompare(r.path))}function L(e){const i=new Map;for(const n of e)n.kind!=="division"||!n.title||i.set(n.title,i.has(n.title)?null:n);const o=new Map;for(const[n,c]of i)c&&o.set(n,c);return o}function v(e,i){return i==="native"?e.nativeProject??e.project:e.project}function j(e,i){return i==="converted"?e.outputFiles:e.nativeOutputFiles??e.files}function k(e,i){return i==="converted"?e.outputAssets:e.assets}function F(e){const i=e.action==="replace"||e.action==="rewrite"?`replaced with \`${e.replacement}\``:e.message??e.action,o=e.occurrences>1?` (x${e.occurrences})`:"";return`[${e.severity}] ${e.macro}: ${i}${o}`}exports.assetsForImportMode=k;exports.diffHunks=d;exports.diffLines=h;exports.diffStats=u;exports.fileChangesForImport=g;exports.filesForImportMode=j;exports.formatWarningLine=F;exports.projectForImportMode=v;