@pixerate/editor 0.21.0 → 0.23.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 +100 -13
- package/THIRD_PARTY_NOTICES.md +88 -0
- package/dist/agent/index.cjs +86 -111
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +69 -211
- package/dist/agent/index.d.ts +69 -211
- package/dist/agent/index.js +77 -102
- package/dist/agent/index.js.map +1 -1
- package/dist/arrangeShortcuts-B8O3f8-P.d.cts +184 -0
- package/dist/arrangeShortcuts-sLlD2rSX.d.ts +184 -0
- package/dist/canvas/index.cjs +2112 -60
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +712 -181
- package/dist/canvas/index.d.ts +712 -181
- package/dist/canvas/index.js +2105 -53
- package/dist/canvas/index.js.map +1 -1
- package/dist/chunk-26BVFKHU.cjs +453 -0
- package/dist/chunk-26BVFKHU.cjs.map +1 -0
- package/dist/chunk-2H7ZHPEJ.js +762 -0
- package/dist/chunk-2H7ZHPEJ.js.map +1 -0
- package/dist/chunk-7DWMJCAT.js +453 -0
- package/dist/chunk-7DWMJCAT.js.map +1 -0
- package/dist/{chunk-TVRC4KVT.cjs → chunk-AA4ZEVCC.cjs} +845 -90
- package/dist/chunk-AA4ZEVCC.cjs.map +1 -0
- package/dist/chunk-ARRTP33I.js +101 -0
- package/dist/chunk-ARRTP33I.js.map +1 -0
- package/dist/{chunk-LA7PEGU3.cjs → chunk-CL37JGFW.cjs} +4 -4
- package/dist/{chunk-LA7PEGU3.cjs.map → chunk-CL37JGFW.cjs.map} +1 -1
- package/dist/chunk-CPOKFNBG.cjs +101 -0
- package/dist/chunk-CPOKFNBG.cjs.map +1 -0
- package/dist/chunk-G2I4QJOT.cjs +762 -0
- package/dist/chunk-G2I4QJOT.cjs.map +1 -0
- package/dist/{chunk-4QPLEUL2.cjs → chunk-GVSMRPHB.cjs} +1046 -54
- package/dist/chunk-GVSMRPHB.cjs.map +1 -0
- package/dist/{chunk-KYRZDWM4.js → chunk-JJDLPEWL.js} +2 -2
- package/dist/{chunk-GVW4P7BG.js → chunk-K3R5NG2D.js} +448 -54
- package/dist/chunk-K3R5NG2D.js.map +1 -0
- package/dist/{chunk-3TYMNULT.js → chunk-MJZBNWG7.js} +807 -52
- package/dist/chunk-MJZBNWG7.js.map +1 -0
- package/dist/{chunk-A7DKIA72.js → chunk-QBJ22YZR.js} +1059 -93
- package/dist/chunk-QBJ22YZR.js.map +1 -0
- package/dist/{chunk-CYFJCKC4.js → chunk-QGHGJ56O.js} +997 -5
- package/dist/chunk-QGHGJ56O.js.map +1 -0
- package/dist/{chunk-JYRIOFEN.cjs → chunk-RIKBJLS2.cjs} +1064 -98
- package/dist/chunk-RIKBJLS2.cjs.map +1 -0
- package/dist/{chunk-U6NDQFOK.cjs → chunk-XDMXXC4Z.cjs} +569 -175
- package/dist/chunk-XDMXXC4Z.cjs.map +1 -0
- package/dist/commands/index.cjs +860 -0
- package/dist/commands/index.cjs.map +1 -0
- package/dist/commands/index.d.cts +592 -0
- package/dist/commands/index.d.ts +592 -0
- package/dist/commands/index.js +860 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/{controller-OUdxPY-X.d.ts → controller-pePCJLT1.d.cts} +216 -11
- package/dist/{controller-OUdxPY-X.d.cts → controller-pePCJLT1.d.ts} +216 -11
- package/dist/extensions/index.cjs +14 -4
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +3 -3
- package/dist/extensions/index.d.ts +3 -3
- package/dist/extensions/index.js +13 -3
- package/dist/history/index.cjs +12 -2
- package/dist/history/index.cjs.map +1 -1
- package/dist/history/index.d.cts +211 -7
- package/dist/history/index.d.ts +211 -7
- package/dist/history/index.js +13 -3
- package/dist/image-editor/index.cjs +418 -13
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +154 -3
- package/dist/image-editor/index.d.ts +154 -3
- package/dist/image-editor/index.js +417 -12
- package/dist/image-editor/index.js.map +1 -1
- package/dist/{index-k3mFbPx_.d.cts → index-CCr_z9kF.d.cts} +3 -3
- package/dist/{index-Ng1pG7JE.d.ts → index-Ck6ajwXh.d.ts} +3 -3
- package/dist/index.cjs +275 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +296 -47
- package/dist/index.d.ts +296 -47
- package/dist/index.js +266 -74
- package/dist/index.js.map +1 -1
- package/dist/registry-D5-R90p0.d.cts +209 -0
- package/dist/registry-D5-R90p0.d.ts +209 -0
- package/dist/{registry-iAHbqkYt.d.cts → registry-GJI4gToU.d.cts} +15 -4
- package/dist/{registry-iAHbqkYt.d.ts → registry-GJI4gToU.d.ts} +15 -4
- package/dist/serializers/index.cjs +3 -3
- package/dist/serializers/index.d.cts +1 -1
- package/dist/serializers/index.d.ts +1 -1
- package/dist/serializers/index.js +2 -2
- package/dist/spreadsheet/index.cjs +23 -3
- package/dist/spreadsheet/index.cjs.map +1 -1
- package/dist/spreadsheet/index.d.cts +97 -10
- package/dist/spreadsheet/index.d.ts +97 -10
- package/dist/spreadsheet/index.js +22 -2
- package/dist/{track-changes-G8JcWB8b.d.cts → track-changes-BSF58RK0.d.cts} +92 -9
- package/dist/{track-changes-G8JcWB8b.d.ts → track-changes-BSF58RK0.d.ts} +92 -9
- package/dist/{types-DMe0vFB1.d.cts → types-DX4Mh4SL.d.cts} +1 -1
- package/dist/{types-DMe0vFB1.d.ts → types-DX4Mh4SL.d.ts} +1 -1
- package/dist/types-GT5a5YAX.d.cts +86 -0
- package/dist/types-GT5a5YAX.d.ts +86 -0
- package/package.json +8 -2
- package/dist/chunk-2TWGLC5K.cjs +0 -262
- package/dist/chunk-2TWGLC5K.cjs.map +0 -1
- package/dist/chunk-3TYMNULT.js.map +0 -1
- package/dist/chunk-4QPLEUL2.cjs.map +0 -1
- package/dist/chunk-A7DKIA72.js.map +0 -1
- package/dist/chunk-CYFJCKC4.js.map +0 -1
- package/dist/chunk-GVW4P7BG.js.map +0 -1
- package/dist/chunk-JYRIOFEN.cjs.map +0 -1
- package/dist/chunk-KAADNAPF.js +0 -262
- package/dist/chunk-KAADNAPF.js.map +0 -1
- package/dist/chunk-TVRC4KVT.cjs.map +0 -1
- package/dist/chunk-U6NDQFOK.cjs.map +0 -1
- package/dist/types-BZgcDsC5.d.cts +0 -42
- package/dist/types-BZgcDsC5.d.ts +0 -42
- /package/dist/{chunk-KYRZDWM4.js.map → chunk-JJDLPEWL.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -29,6 +29,10 @@ import {
|
|
|
29
29
|
Comments,
|
|
30
30
|
CrossReference,
|
|
31
31
|
DEFAULT_AUTOCORRECT_EXCEPTIONS,
|
|
32
|
+
DEFAULT_DOCX_MAX_IMAGE_SIZE,
|
|
33
|
+
DEFAULT_ZIP_MAX_ENTRIES,
|
|
34
|
+
DEFAULT_ZIP_MAX_TOTAL_SIZE,
|
|
35
|
+
DOCX_MIME_TYPES,
|
|
32
36
|
FileImport,
|
|
33
37
|
FontSize,
|
|
34
38
|
Footnote,
|
|
@@ -48,11 +52,14 @@ import {
|
|
|
48
52
|
SmilieReplacer,
|
|
49
53
|
TableOfContents,
|
|
50
54
|
TemplateSuggestions,
|
|
55
|
+
ZipArchive,
|
|
56
|
+
ZipError,
|
|
51
57
|
autocorrectPluginKey,
|
|
52
58
|
buildOutlineTree,
|
|
53
59
|
capitalizeSentenceRules,
|
|
54
60
|
commentsPluginKey,
|
|
55
61
|
computeOutline,
|
|
62
|
+
createDocxImportAdapter,
|
|
56
63
|
createImportAdapterRegistry,
|
|
57
64
|
createImportContext,
|
|
58
65
|
createMentionExtension,
|
|
@@ -62,6 +69,8 @@ import {
|
|
|
62
69
|
defaultAutocorrectRules,
|
|
63
70
|
defaultImportRegistry,
|
|
64
71
|
documentStructureCommandItems,
|
|
72
|
+
docxImportAdapter,
|
|
73
|
+
docxToDocumentImport,
|
|
65
74
|
fileImportPluginKey,
|
|
66
75
|
findAutocorrection,
|
|
67
76
|
findCommentRanges,
|
|
@@ -91,10 +100,12 @@ import {
|
|
|
91
100
|
insertImageNode,
|
|
92
101
|
insertImportedDocument,
|
|
93
102
|
isInsidePromptToken,
|
|
103
|
+
isUnsafeZipPath,
|
|
94
104
|
markdownImportAdapter,
|
|
95
105
|
navigateToHeading,
|
|
96
106
|
outlinePluginKey,
|
|
97
107
|
plainTextImportAdapter,
|
|
108
|
+
readZip,
|
|
98
109
|
registerImportAdapter,
|
|
99
110
|
removeImageNode,
|
|
100
111
|
richClipboardPluginKey,
|
|
@@ -108,8 +119,9 @@ import {
|
|
|
108
119
|
twoInitialCapitalsRules,
|
|
109
120
|
unregisterImportAdapter,
|
|
110
121
|
updateImageSrc,
|
|
111
|
-
writeRichClipboard
|
|
112
|
-
|
|
122
|
+
writeRichClipboard,
|
|
123
|
+
zipCrc32
|
|
124
|
+
} from "./chunk-QGHGJ56O.js";
|
|
113
125
|
import {
|
|
114
126
|
INSTRUCTION_REGEX,
|
|
115
127
|
TEMPLATE_REGEX,
|
|
@@ -136,7 +148,7 @@ import {
|
|
|
136
148
|
rtfToPlainText,
|
|
137
149
|
sanitizeImportedHtml,
|
|
138
150
|
serializeRichClipboardPayload
|
|
139
|
-
} from "./chunk-
|
|
151
|
+
} from "./chunk-JJDLPEWL.js";
|
|
140
152
|
import {
|
|
141
153
|
DEFAULT_COLUMN_WIDTH,
|
|
142
154
|
DEFAULT_ROW_HEIGHT,
|
|
@@ -150,6 +162,7 @@ import {
|
|
|
150
162
|
applyFormulaSuggestion,
|
|
151
163
|
bindSpreadsheetTableActions,
|
|
152
164
|
buildSpreadsheetView,
|
|
165
|
+
clampMenuPosition,
|
|
153
166
|
columnDependencyKey,
|
|
154
167
|
compareCellValues,
|
|
155
168
|
computeFillTarget,
|
|
@@ -190,14 +203,21 @@ import {
|
|
|
190
203
|
shiftFormulaReferences,
|
|
191
204
|
toNumber,
|
|
192
205
|
tsvImportAdapter
|
|
193
|
-
} from "./chunk-
|
|
206
|
+
} from "./chunk-K3R5NG2D.js";
|
|
194
207
|
import {
|
|
208
|
+
DirtyTracker,
|
|
195
209
|
HistoryManager,
|
|
196
|
-
|
|
197
|
-
|
|
210
|
+
bindDirtyToHistory,
|
|
211
|
+
createDirtyTracker,
|
|
212
|
+
createHistoryManager,
|
|
213
|
+
defaultIsEqual,
|
|
214
|
+
withoutDirty
|
|
215
|
+
} from "./chunk-2H7ZHPEJ.js";
|
|
198
216
|
import {
|
|
217
|
+
BLOCK_CHANGE_ATTRIBUTE,
|
|
199
218
|
CommentStore,
|
|
200
219
|
DELETION_MARK_NAME,
|
|
220
|
+
FORMAT_CHANGE_MARK_NAME,
|
|
201
221
|
INSERTION_MARK_NAME,
|
|
202
222
|
MARKDOWN_MENTION_SPLIT_REGEX,
|
|
203
223
|
MENTION_REGEX,
|
|
@@ -205,9 +225,12 @@ import {
|
|
|
205
225
|
TrackChanges,
|
|
206
226
|
TrackChangesStore,
|
|
207
227
|
TrackedDeletion,
|
|
228
|
+
TrackedFormatChange,
|
|
208
229
|
TrackedInsertion,
|
|
209
230
|
createCommentStore,
|
|
210
231
|
createReviewId,
|
|
232
|
+
describeBlockChange,
|
|
233
|
+
describeFormatChange,
|
|
211
234
|
escapeHtml,
|
|
212
235
|
extractMentions,
|
|
213
236
|
extractMentionsFromDoc,
|
|
@@ -229,15 +252,19 @@ import {
|
|
|
229
252
|
sanitizeHtml,
|
|
230
253
|
stripMarkdownCode,
|
|
231
254
|
trackChangesPluginKey
|
|
232
|
-
} from "./chunk-
|
|
255
|
+
} from "./chunk-MJZBNWG7.js";
|
|
233
256
|
import {
|
|
234
257
|
FORMULA_ERRORS,
|
|
235
258
|
FormulaEvaluator,
|
|
236
259
|
FormulaParser,
|
|
260
|
+
MAX_FORMULA_ARRAY_SIZE,
|
|
237
261
|
WHOLE_COLUMN_END_ROW,
|
|
238
262
|
checkFormulaArgumentCount,
|
|
239
263
|
colNameToIndex,
|
|
264
|
+
compareNumbers,
|
|
265
|
+
compareValues,
|
|
240
266
|
describeFormulaError,
|
|
267
|
+
formatCellDisplay,
|
|
241
268
|
formatValueWithCode,
|
|
242
269
|
getFormulaArgumentSpecIndex,
|
|
243
270
|
getFormulaFunction,
|
|
@@ -246,16 +273,21 @@ import {
|
|
|
246
273
|
indexToColName,
|
|
247
274
|
isFormulaError,
|
|
248
275
|
listFormulaFunctions,
|
|
276
|
+
numberToText,
|
|
277
|
+
parseCellInput,
|
|
249
278
|
parseCellReference,
|
|
250
279
|
parseCriteria,
|
|
251
280
|
parseFormula,
|
|
281
|
+
parseNumberText,
|
|
252
282
|
parseRange,
|
|
253
283
|
registerFormulaFunction,
|
|
254
284
|
searchFormulaFunctions,
|
|
285
|
+
serialFromYmd,
|
|
286
|
+
sortCompareValues,
|
|
255
287
|
tokenizeFormula,
|
|
256
288
|
unregisterFormulaFunction,
|
|
257
289
|
wildcardToRegExp
|
|
258
|
-
} from "./chunk-
|
|
290
|
+
} from "./chunk-QBJ22YZR.js";
|
|
259
291
|
|
|
260
292
|
// src/controller.ts
|
|
261
293
|
import { Editor } from "@tiptap/core";
|
|
@@ -413,71 +445,6 @@ function createEditor(options = {}) {
|
|
|
413
445
|
return new EditorController(options);
|
|
414
446
|
}
|
|
415
447
|
|
|
416
|
-
// src/dirty.ts
|
|
417
|
-
function defaultIsEqual(a, b) {
|
|
418
|
-
if (Object.is(a, b)) return true;
|
|
419
|
-
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
422
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
423
|
-
if (a.length !== b.length) return false;
|
|
424
|
-
for (let i = 0; i < a.length; i++) {
|
|
425
|
-
if (!defaultIsEqual(a[i], b[i])) return false;
|
|
426
|
-
}
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
429
|
-
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
const keysA = Object.keys(a);
|
|
433
|
-
const keysB = Object.keys(b);
|
|
434
|
-
if (keysA.length !== keysB.length) return false;
|
|
435
|
-
for (const key of keysA) {
|
|
436
|
-
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
437
|
-
if (!defaultIsEqual(a[key], b[key])) return false;
|
|
438
|
-
}
|
|
439
|
-
return true;
|
|
440
|
-
}
|
|
441
|
-
var DirtyTracker = class {
|
|
442
|
-
baseline;
|
|
443
|
-
isEqual;
|
|
444
|
-
constructor(initialBaseline, options) {
|
|
445
|
-
this.baseline = initialBaseline;
|
|
446
|
-
if (typeof options === "function") {
|
|
447
|
-
this.isEqual = options;
|
|
448
|
-
} else {
|
|
449
|
-
this.isEqual = options?.isEqual ?? defaultIsEqual;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Returns current baseline value.
|
|
454
|
-
*/
|
|
455
|
-
getBaseline() {
|
|
456
|
-
return this.baseline;
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Sets a new baseline value without triggering any dirty state.
|
|
460
|
-
*/
|
|
461
|
-
setBaseline(value) {
|
|
462
|
-
this.baseline = value;
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Checks whether the given value differs from the baseline.
|
|
466
|
-
*/
|
|
467
|
-
isDirty(current) {
|
|
468
|
-
return !this.isEqual(this.baseline, current);
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Resets the baseline to the provided current value (or clears dirty status).
|
|
472
|
-
*/
|
|
473
|
-
reset(current) {
|
|
474
|
-
this.baseline = current;
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
function createDirtyTracker(initialBaseline, options) {
|
|
478
|
-
return new DirtyTracker(initialBaseline, options);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
448
|
// src/import/controller.ts
|
|
482
449
|
function pickImportFiles(options = {}) {
|
|
483
450
|
if (typeof document === "undefined") return Promise.resolve([]);
|
|
@@ -560,8 +527,199 @@ var FileImportController = class {
|
|
|
560
527
|
function createFileImportController(getTarget, options) {
|
|
561
528
|
return new FileImportController(getTarget, options);
|
|
562
529
|
}
|
|
530
|
+
|
|
531
|
+
// src/import/pdf.ts
|
|
532
|
+
var isTextItem = (item) => typeof item.str === "string";
|
|
533
|
+
function median(values) {
|
|
534
|
+
if (!values.length) return 0;
|
|
535
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
536
|
+
const mid = sorted.length >> 1;
|
|
537
|
+
return sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
|
|
538
|
+
}
|
|
539
|
+
function groupLines(items) {
|
|
540
|
+
const lines = [];
|
|
541
|
+
let current = null;
|
|
542
|
+
let breakNext = false;
|
|
543
|
+
for (const item of items) {
|
|
544
|
+
if (!isTextItem(item)) continue;
|
|
545
|
+
const x = item.transform?.[4] ?? 0;
|
|
546
|
+
const y = item.transform?.[5] ?? (current?.y ?? 0);
|
|
547
|
+
const height = item.height || Math.abs(item.transform?.[3] ?? 0) || current?.height || 10;
|
|
548
|
+
const tolerance = Math.max(1, height * 0.5);
|
|
549
|
+
if (!item.str) {
|
|
550
|
+
if (item.hasEOL) {
|
|
551
|
+
if (breakNext && current) current.blankAfter = true;
|
|
552
|
+
breakNext = true;
|
|
553
|
+
}
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (!current || breakNext || Math.abs(y - current.y) > tolerance) {
|
|
557
|
+
current = { text: "", y, height, blankAfter: false };
|
|
558
|
+
lines.push(current);
|
|
559
|
+
} else if (current.endX !== void 0 && x - current.endX > height * 0.15) {
|
|
560
|
+
if (!/\s$/.test(current.text) && !/^\s/.test(item.str)) current.text += " ";
|
|
561
|
+
}
|
|
562
|
+
current.text += item.str;
|
|
563
|
+
current.height = Math.max(current.height, height);
|
|
564
|
+
current.endX = item.width !== void 0 ? x + item.width : void 0;
|
|
565
|
+
breakNext = !!item.hasEOL;
|
|
566
|
+
}
|
|
567
|
+
return lines;
|
|
568
|
+
}
|
|
569
|
+
function pdfTextItemsToParagraphs(items, options = {}) {
|
|
570
|
+
const lines = groupLines(items).filter((line) => line.text.trim() || line.blankAfter);
|
|
571
|
+
const gaps = [];
|
|
572
|
+
for (let i = 1; i < lines.length; i++) {
|
|
573
|
+
const gap = lines[i - 1].y - lines[i].y;
|
|
574
|
+
if (gap > 0) gaps.push(gap);
|
|
575
|
+
}
|
|
576
|
+
const typical = median(gaps);
|
|
577
|
+
const factor = options.paragraphGap ?? 1.4;
|
|
578
|
+
const paragraphs = [];
|
|
579
|
+
let current = [];
|
|
580
|
+
const flush = () => {
|
|
581
|
+
const text = current.join(" ").replace(/\s+/g, " ").trim();
|
|
582
|
+
if (text) paragraphs.push(text);
|
|
583
|
+
current = [];
|
|
584
|
+
};
|
|
585
|
+
lines.forEach((line, i) => {
|
|
586
|
+
if (i > 0) {
|
|
587
|
+
const prev = lines[i - 1];
|
|
588
|
+
const gap = prev.y - line.y;
|
|
589
|
+
const bigGap = typical > 0 ? gap > typical * factor : gap > prev.height * 1.8;
|
|
590
|
+
if (prev.blankAfter || bigGap || gap < -prev.height * 0.5) flush();
|
|
591
|
+
}
|
|
592
|
+
const text = line.text.trim();
|
|
593
|
+
if (!text) return;
|
|
594
|
+
if (current.length && /\w-$/.test(current[current.length - 1]) && /^[a-z]/.test(text)) {
|
|
595
|
+
current[current.length - 1] = current[current.length - 1].slice(0, -1) + text;
|
|
596
|
+
} else {
|
|
597
|
+
current.push(text);
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
flush();
|
|
601
|
+
return paragraphs;
|
|
602
|
+
}
|
|
603
|
+
function createPdfImportAdapter(pdfjs, options = {}) {
|
|
604
|
+
return {
|
|
605
|
+
id: options.id ?? "pdf",
|
|
606
|
+
label: "PDF",
|
|
607
|
+
mimeTypes: ["application/pdf"],
|
|
608
|
+
extensions: [".pdf"],
|
|
609
|
+
target: "document",
|
|
610
|
+
async import(_input, context) {
|
|
611
|
+
const data = new Uint8Array((await context.readArrayBuffer()).slice(0));
|
|
612
|
+
const doc = await pdfjs.getDocument({ ...options.documentParams, data }).promise;
|
|
613
|
+
const paragraphs = [];
|
|
614
|
+
try {
|
|
615
|
+
const pages = Math.min(doc.numPages, options.maxPages ?? Infinity);
|
|
616
|
+
for (let n = 1; n <= pages; n++) {
|
|
617
|
+
const page = await doc.getPage(n);
|
|
618
|
+
const content = await page.getTextContent();
|
|
619
|
+
paragraphs.push(...pdfTextItemsToParagraphs(content.items, options));
|
|
620
|
+
page.cleanup?.();
|
|
621
|
+
}
|
|
622
|
+
} finally {
|
|
623
|
+
await doc.destroy?.();
|
|
624
|
+
}
|
|
625
|
+
const text = paragraphs.join("\n");
|
|
626
|
+
return { html: plainTextToParagraphHtml(text), text };
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// src/import/zip-export.ts
|
|
632
|
+
var INDEX_NAMES = /^(index|readme|home|_index|start)$/i;
|
|
633
|
+
var baseName = (path) => path.slice(path.lastIndexOf("/") + 1);
|
|
634
|
+
var stem = (name) => name.replace(/\.[^./]+$/, "");
|
|
635
|
+
function zipEntryTitle(path) {
|
|
636
|
+
const title = stem(baseName(path)).replace(/\s+[0-9a-f]{32}$/i, "").replace(/[_]+/g, " ").trim();
|
|
637
|
+
return title || baseName(path);
|
|
638
|
+
}
|
|
639
|
+
function sortZipEntryNames(names) {
|
|
640
|
+
const isIndex = (name) => INDEX_NAMES.test(stem(baseName(name)));
|
|
641
|
+
const depth = (name) => name.split("/").length;
|
|
642
|
+
return [...names].sort((a, b) => {
|
|
643
|
+
const ai = isIndex(a);
|
|
644
|
+
const bi = isIndex(b);
|
|
645
|
+
if (ai !== bi) return ai ? -1 : 1;
|
|
646
|
+
if (ai && bi && depth(a) !== depth(b)) return depth(a) - depth(b);
|
|
647
|
+
return a.localeCompare(b, void 0, { numeric: true, sensitivity: "base" });
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
var isJunk = (name) => name.startsWith("__MACOSX/") || name.split("/").some((segment) => segment.startsWith("."));
|
|
651
|
+
function createZipImportAdapter(options = {}) {
|
|
652
|
+
const id = options.id ?? "zip";
|
|
653
|
+
return {
|
|
654
|
+
id,
|
|
655
|
+
label: "Zipped documents",
|
|
656
|
+
mimeTypes: ["application/zip", "application/x-zip-compressed"],
|
|
657
|
+
extensions: [".zip"],
|
|
658
|
+
target: "document",
|
|
659
|
+
async import(_input, context) {
|
|
660
|
+
const registry = options.registry ?? context.registry ?? defaultImportRegistry;
|
|
661
|
+
const zip = await readZip(await context.readArrayBuffer(), {
|
|
662
|
+
maxTotalSize: 100 * 1024 * 1024,
|
|
663
|
+
maxEntries: 5e3,
|
|
664
|
+
...options.zip
|
|
665
|
+
});
|
|
666
|
+
const maxFiles = options.maxFiles ?? 500;
|
|
667
|
+
const level = options.headingLevel ?? 2;
|
|
668
|
+
const files = [];
|
|
669
|
+
const skipped = [];
|
|
670
|
+
let html = "";
|
|
671
|
+
let text = "";
|
|
672
|
+
const names = zip.entries.filter((entry) => !entry.isDirectory).map((entry) => entry.name);
|
|
673
|
+
for (const name of sortZipEntryNames(names)) {
|
|
674
|
+
if (isJunk(name)) continue;
|
|
675
|
+
const adapter = registry.find({ fileName: name, target: "document" });
|
|
676
|
+
if (!adapter) {
|
|
677
|
+
skipped.push({ name, reason: "unsupported type" });
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
if (adapter.id === id || adapter.extensions.some((ext) => ext.toLowerCase() === ".zip")) {
|
|
681
|
+
skipped.push({ name, reason: "nested archive" });
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
if (files.length >= maxFiles) {
|
|
685
|
+
skipped.push({ name, reason: "file limit reached" });
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
try {
|
|
689
|
+
const outcome = await registry.importFile(await zip.read(name), {
|
|
690
|
+
fileName: name,
|
|
691
|
+
adapterId: adapter.id
|
|
692
|
+
});
|
|
693
|
+
const title = zipEntryTitle(name);
|
|
694
|
+
if (options.headings !== false) {
|
|
695
|
+
html += `<h${level}>${escapeHtml(title)}</h${level}>`;
|
|
696
|
+
text += `${text ? "\n" : ""}${title}
|
|
697
|
+
`;
|
|
698
|
+
} else if (text) {
|
|
699
|
+
text += "\n";
|
|
700
|
+
}
|
|
701
|
+
html += outcome.result.html.trim();
|
|
702
|
+
text += outcome.result.text;
|
|
703
|
+
files.push({ name, adapterId: adapter.id });
|
|
704
|
+
} catch (error) {
|
|
705
|
+
const code = error?.code;
|
|
706
|
+
if (code === "too_large") throw error;
|
|
707
|
+
skipped.push({ name, reason: error instanceof Error ? error.message : String(error) });
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
if (!files.length) {
|
|
711
|
+
throw new ImportError("invalid_file", "The archive contains no importable documents.", {
|
|
712
|
+
fileName: context.fileName
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
return { html, text, files, skipped };
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
var zipImportAdapter = createZipImportAdapter();
|
|
563
720
|
export {
|
|
564
721
|
Autocorrect,
|
|
722
|
+
BLOCK_CHANGE_ATTRIBUTE,
|
|
565
723
|
BUILT_IN_IMPORT_ADAPTERS,
|
|
566
724
|
Bookmark,
|
|
567
725
|
COMMENT_MARK_NAME,
|
|
@@ -571,12 +729,17 @@ export {
|
|
|
571
729
|
CrossReference,
|
|
572
730
|
DEFAULT_AUTOCORRECT_EXCEPTIONS,
|
|
573
731
|
DEFAULT_COLUMN_WIDTH,
|
|
732
|
+
DEFAULT_DOCX_MAX_IMAGE_SIZE,
|
|
574
733
|
DEFAULT_ROW_HEIGHT,
|
|
734
|
+
DEFAULT_ZIP_MAX_ENTRIES,
|
|
735
|
+
DEFAULT_ZIP_MAX_TOTAL_SIZE,
|
|
575
736
|
DELETION_MARK_NAME,
|
|
737
|
+
DOCX_MIME_TYPES,
|
|
576
738
|
DataSourceBinder,
|
|
577
739
|
DependencyGraph,
|
|
578
740
|
DirtyTracker,
|
|
579
741
|
EditorController,
|
|
742
|
+
FORMAT_CHANGE_MARK_NAME,
|
|
580
743
|
FORMULA_ERRORS,
|
|
581
744
|
FileImport,
|
|
582
745
|
FileImportController,
|
|
@@ -595,6 +758,7 @@ export {
|
|
|
595
758
|
ImportError,
|
|
596
759
|
LoadingNode,
|
|
597
760
|
MARKDOWN_MENTION_SPLIT_REGEX,
|
|
761
|
+
MAX_FORMULA_ARRAY_SIZE,
|
|
598
762
|
MENTION_REGEX,
|
|
599
763
|
Markdown,
|
|
600
764
|
Mention,
|
|
@@ -617,27 +781,35 @@ export {
|
|
|
617
781
|
TrackChanges,
|
|
618
782
|
TrackChangesStore,
|
|
619
783
|
TrackedDeletion,
|
|
784
|
+
TrackedFormatChange,
|
|
620
785
|
TrackedInsertion,
|
|
621
786
|
VARIABLE_REGEX,
|
|
622
787
|
WHOLE_COLUMN_END_ROW,
|
|
788
|
+
ZipArchive,
|
|
789
|
+
ZipError,
|
|
623
790
|
aggregateValues,
|
|
624
791
|
applyFormulaSuggestion,
|
|
625
792
|
autocorrectPluginKey,
|
|
793
|
+
bindDirtyToHistory,
|
|
626
794
|
bindSpreadsheetTableActions,
|
|
627
795
|
buildOutlineTree,
|
|
628
796
|
buildSpreadsheetView,
|
|
629
797
|
capitalizeSentenceRules,
|
|
630
798
|
checkFormulaArgumentCount,
|
|
799
|
+
clampMenuPosition,
|
|
631
800
|
colNameToIndex,
|
|
632
801
|
columnDependencyKey,
|
|
633
802
|
commentsPluginKey,
|
|
634
803
|
compactVariableValues,
|
|
635
804
|
compareCellValues,
|
|
805
|
+
compareNumbers,
|
|
806
|
+
compareValues,
|
|
636
807
|
computeFillTarget,
|
|
637
808
|
computeOutline,
|
|
638
809
|
computeRowGroups,
|
|
639
810
|
createCommentStore,
|
|
640
811
|
createDirtyTracker,
|
|
812
|
+
createDocxImportAdapter,
|
|
641
813
|
createEditor,
|
|
642
814
|
createFileImportController,
|
|
643
815
|
createHistoryManager,
|
|
@@ -645,16 +817,22 @@ export {
|
|
|
645
817
|
createImportContext,
|
|
646
818
|
createMentionExtension,
|
|
647
819
|
createOutlineStore,
|
|
820
|
+
createPdfImportAdapter,
|
|
648
821
|
createReviewId,
|
|
649
822
|
createRichTextPreset,
|
|
650
823
|
createSpreadsheetClipboardData,
|
|
824
|
+
createZipImportAdapter,
|
|
651
825
|
crossReferencePluginKey,
|
|
652
826
|
csvImportAdapter,
|
|
653
827
|
defaultAutocorrectRules,
|
|
654
828
|
defaultImportRegistry,
|
|
655
829
|
defaultIsEqual,
|
|
830
|
+
describeBlockChange,
|
|
831
|
+
describeFormatChange,
|
|
656
832
|
describeFormulaError,
|
|
657
833
|
documentStructureCommandItems,
|
|
834
|
+
docxImportAdapter,
|
|
835
|
+
docxToDocumentImport,
|
|
658
836
|
escapeCsvField,
|
|
659
837
|
escapeHtml,
|
|
660
838
|
escapeVariableText,
|
|
@@ -675,6 +853,7 @@ export {
|
|
|
675
853
|
findImportAdapter,
|
|
676
854
|
footnotesMarkdownIt,
|
|
677
855
|
footnotesPluginKey,
|
|
856
|
+
formatCellDisplay,
|
|
678
857
|
formatReviewTime,
|
|
679
858
|
formatValueWithCode,
|
|
680
859
|
fractionRules,
|
|
@@ -730,6 +909,7 @@ export {
|
|
|
730
909
|
isPromptValueSet,
|
|
731
910
|
isSingleCellRange,
|
|
732
911
|
isTrackChangesEnabled,
|
|
912
|
+
isUnsafeZipPath,
|
|
733
913
|
listFormulaFunctions,
|
|
734
914
|
mapFormulaReferences,
|
|
735
915
|
mapRawOffsetToResolved,
|
|
@@ -740,18 +920,22 @@ export {
|
|
|
740
920
|
matchesFilterRule,
|
|
741
921
|
navigateToHeading,
|
|
742
922
|
normalizeRange,
|
|
923
|
+
numberToText,
|
|
743
924
|
offsetFormulaReferences,
|
|
744
925
|
outlinePluginKey,
|
|
926
|
+
parseCellInput,
|
|
745
927
|
parseCellReference,
|
|
746
928
|
parseCriteria,
|
|
747
929
|
parseCsv,
|
|
748
930
|
parseFormula,
|
|
749
931
|
parseHtmlTable,
|
|
750
932
|
parseMentionSegments,
|
|
933
|
+
parseNumberText,
|
|
751
934
|
parseRange,
|
|
752
935
|
parseRichClipboardPayload,
|
|
753
936
|
parseTsv,
|
|
754
937
|
parseVariableBody,
|
|
938
|
+
pdfTextItemsToParagraphs,
|
|
755
939
|
pickImportFiles,
|
|
756
940
|
plainTextImportAdapter,
|
|
757
941
|
plainTextToParagraphHtml,
|
|
@@ -764,6 +948,7 @@ export {
|
|
|
764
948
|
rangesIntersect,
|
|
765
949
|
readRichClipboard,
|
|
766
950
|
readSpreadsheetClipboard,
|
|
951
|
+
readZip,
|
|
767
952
|
rebaseClipboardRows,
|
|
768
953
|
registerFormulaFunction,
|
|
769
954
|
registerImportAdapter,
|
|
@@ -783,6 +968,7 @@ export {
|
|
|
783
968
|
sanitizeHtml,
|
|
784
969
|
sanitizeImportedHtml,
|
|
785
970
|
searchFormulaFunctions,
|
|
971
|
+
serialFromYmd,
|
|
786
972
|
serializeCsv,
|
|
787
973
|
serializeHtmlTable,
|
|
788
974
|
serializeRichClipboardPayload,
|
|
@@ -790,6 +976,8 @@ export {
|
|
|
790
976
|
shiftFormulaReferences,
|
|
791
977
|
smartQuoteRules,
|
|
792
978
|
smilieAutocorrectRules,
|
|
979
|
+
sortCompareValues,
|
|
980
|
+
sortZipEntryNames,
|
|
793
981
|
stripMarkdownCode,
|
|
794
982
|
symbolRules,
|
|
795
983
|
syncFootnotes,
|
|
@@ -809,6 +997,10 @@ export {
|
|
|
809
997
|
updateImageSrc,
|
|
810
998
|
variableRegex,
|
|
811
999
|
wildcardToRegExp,
|
|
812
|
-
|
|
1000
|
+
withoutDirty,
|
|
1001
|
+
writeRichClipboard,
|
|
1002
|
+
zipCrc32,
|
|
1003
|
+
zipEntryTitle,
|
|
1004
|
+
zipImportAdapter
|
|
813
1005
|
};
|
|
814
1006
|
//# sourceMappingURL=index.js.map
|