docx-diff-editor 1.0.48 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +217 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +217 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { forwardRef, useRef, useState, useEffect, useCallback, useImperativeHandle } from 'react';
|
|
2
2
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
-
import DiffMatchPatch from 'diff-match-patch';
|
|
4
3
|
import { v4 } from 'uuid';
|
|
4
|
+
import DiffMatchPatch from 'diff-match-patch';
|
|
5
5
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -444,14 +444,212 @@ var TIMEOUTS = {
|
|
|
444
444
|
/** Cleanup delay (ms) */
|
|
445
445
|
CLEANUP_DELAY: 100
|
|
446
446
|
};
|
|
447
|
+
var CSS_NAMED_COLORS = {
|
|
448
|
+
// Basic colors
|
|
449
|
+
black: "#000000",
|
|
450
|
+
white: "#ffffff",
|
|
451
|
+
red: "#ff0000",
|
|
452
|
+
green: "#008000",
|
|
453
|
+
blue: "#0000ff",
|
|
454
|
+
yellow: "#ffff00",
|
|
455
|
+
cyan: "#00ffff",
|
|
456
|
+
magenta: "#ff00ff",
|
|
457
|
+
// Extended colors
|
|
458
|
+
orange: "#ffa500",
|
|
459
|
+
pink: "#ffc0cb",
|
|
460
|
+
purple: "#800080",
|
|
461
|
+
violet: "#ee82ee",
|
|
462
|
+
brown: "#a52a2a",
|
|
463
|
+
gray: "#808080",
|
|
464
|
+
grey: "#808080",
|
|
465
|
+
// Light variants
|
|
466
|
+
lightblue: "#add8e6",
|
|
467
|
+
lightgreen: "#90ee90",
|
|
468
|
+
lightgray: "#d3d3d3",
|
|
469
|
+
lightgrey: "#d3d3d3",
|
|
470
|
+
lightpink: "#ffb6c1",
|
|
471
|
+
lightyellow: "#ffffe0",
|
|
472
|
+
// Dark variants
|
|
473
|
+
darkblue: "#00008b",
|
|
474
|
+
darkgreen: "#006400",
|
|
475
|
+
darkgray: "#a9a9a9",
|
|
476
|
+
darkgrey: "#a9a9a9",
|
|
477
|
+
darkred: "#8b0000",
|
|
478
|
+
// Other common colors
|
|
479
|
+
navy: "#000080",
|
|
480
|
+
teal: "#008080",
|
|
481
|
+
maroon: "#800000",
|
|
482
|
+
olive: "#808000",
|
|
483
|
+
silver: "#c0c0c0",
|
|
484
|
+
aqua: "#00ffff",
|
|
485
|
+
fuchsia: "#ff00ff",
|
|
486
|
+
lime: "#00ff00",
|
|
487
|
+
coral: "#ff7f50",
|
|
488
|
+
salmon: "#fa8072",
|
|
489
|
+
gold: "#ffd700",
|
|
490
|
+
indigo: "#4b0082",
|
|
491
|
+
crimson: "#dc143c",
|
|
492
|
+
tomato: "#ff6347",
|
|
493
|
+
chocolate: "#d2691e",
|
|
494
|
+
tan: "#d2b48c",
|
|
495
|
+
beige: "#f5f5dc",
|
|
496
|
+
ivory: "#fffff0",
|
|
497
|
+
khaki: "#f0e68c",
|
|
498
|
+
lavender: "#e6e6fa",
|
|
499
|
+
plum: "#dda0dd",
|
|
500
|
+
orchid: "#da70d6",
|
|
501
|
+
turquoise: "#40e0d0",
|
|
502
|
+
skyblue: "#87ceeb",
|
|
503
|
+
steelblue: "#4682b4",
|
|
504
|
+
slategray: "#708090",
|
|
505
|
+
slategrey: "#708090"
|
|
506
|
+
};
|
|
507
|
+
function ensureValidCssColor(color) {
|
|
508
|
+
if (typeof color !== "string" || !color) {
|
|
509
|
+
return void 0;
|
|
510
|
+
}
|
|
511
|
+
const trimmed = color.trim();
|
|
512
|
+
const lowerColor = trimmed.toLowerCase();
|
|
513
|
+
if (CSS_NAMED_COLORS[lowerColor]) {
|
|
514
|
+
return CSS_NAMED_COLORS[lowerColor];
|
|
515
|
+
}
|
|
516
|
+
if (/^[0-9a-fA-F]{6}$/.test(trimmed)) {
|
|
517
|
+
return `#${trimmed}`;
|
|
518
|
+
}
|
|
519
|
+
if (/^[0-9a-fA-F]{3}$/.test(trimmed)) {
|
|
520
|
+
return `#${trimmed}`;
|
|
521
|
+
}
|
|
522
|
+
return trimmed;
|
|
523
|
+
}
|
|
524
|
+
function normalizeMark(mark) {
|
|
525
|
+
const attrs = { ...mark.attrs || {} };
|
|
526
|
+
if (attrs.color !== void 0) {
|
|
527
|
+
attrs.color = ensureValidCssColor(attrs.color);
|
|
528
|
+
}
|
|
529
|
+
return {
|
|
530
|
+
type: mark.type,
|
|
531
|
+
attrs
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
function normalizeMarks(marks) {
|
|
535
|
+
return marks.map(normalizeMark);
|
|
536
|
+
}
|
|
537
|
+
function normalizeMarksForRendering(marks) {
|
|
538
|
+
return normalizeMarks(marks);
|
|
539
|
+
}
|
|
540
|
+
function createTrackInsertMark(author = DEFAULT_AUTHOR, id) {
|
|
541
|
+
return {
|
|
542
|
+
type: "trackInsert",
|
|
543
|
+
attrs: {
|
|
544
|
+
id: id ?? v4(),
|
|
545
|
+
author: author.name,
|
|
546
|
+
authorEmail: author.email,
|
|
547
|
+
authorImage: "",
|
|
548
|
+
date: (/* @__PURE__ */ new Date()).toISOString()
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function createTrackDeleteMark(author = DEFAULT_AUTHOR, id) {
|
|
553
|
+
return {
|
|
554
|
+
type: "trackDelete",
|
|
555
|
+
attrs: {
|
|
556
|
+
id: id ?? v4(),
|
|
557
|
+
author: author.name,
|
|
558
|
+
authorEmail: author.email,
|
|
559
|
+
authorImage: "",
|
|
560
|
+
date: (/* @__PURE__ */ new Date()).toISOString()
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
function createTrackFormatMark(before, after, author = DEFAULT_AUTHOR) {
|
|
565
|
+
const normalizedBefore = normalizeMarks(before);
|
|
566
|
+
const normalizedAfter = normalizeMarks(after);
|
|
567
|
+
return {
|
|
568
|
+
type: "trackFormat",
|
|
569
|
+
attrs: {
|
|
570
|
+
id: v4(),
|
|
571
|
+
author: author.name,
|
|
572
|
+
authorEmail: author.email,
|
|
573
|
+
authorImage: "",
|
|
574
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
575
|
+
before: normalizedBefore,
|
|
576
|
+
after: normalizedAfter
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
}
|
|
447
580
|
|
|
448
581
|
// src/services/runPropertiesSync.ts
|
|
449
582
|
var PT_TO_TWIPS = 20;
|
|
583
|
+
var CSS_NAMED_COLORS_HEX = {
|
|
584
|
+
// Basic colors
|
|
585
|
+
black: "000000",
|
|
586
|
+
white: "ffffff",
|
|
587
|
+
red: "ff0000",
|
|
588
|
+
green: "008000",
|
|
589
|
+
blue: "0000ff",
|
|
590
|
+
yellow: "ffff00",
|
|
591
|
+
cyan: "00ffff",
|
|
592
|
+
magenta: "ff00ff",
|
|
593
|
+
// Extended colors
|
|
594
|
+
orange: "ffa500",
|
|
595
|
+
pink: "ffc0cb",
|
|
596
|
+
purple: "800080",
|
|
597
|
+
violet: "ee82ee",
|
|
598
|
+
brown: "a52a2a",
|
|
599
|
+
gray: "808080",
|
|
600
|
+
grey: "808080",
|
|
601
|
+
// Light variants
|
|
602
|
+
lightblue: "add8e6",
|
|
603
|
+
lightgreen: "90ee90",
|
|
604
|
+
lightgray: "d3d3d3",
|
|
605
|
+
lightgrey: "d3d3d3",
|
|
606
|
+
lightpink: "ffb6c1",
|
|
607
|
+
lightyellow: "ffffe0",
|
|
608
|
+
// Dark variants
|
|
609
|
+
darkblue: "00008b",
|
|
610
|
+
darkgreen: "006400",
|
|
611
|
+
darkgray: "a9a9a9",
|
|
612
|
+
darkgrey: "a9a9a9",
|
|
613
|
+
darkred: "8b0000",
|
|
614
|
+
// Other common colors
|
|
615
|
+
navy: "000080",
|
|
616
|
+
teal: "008080",
|
|
617
|
+
maroon: "800000",
|
|
618
|
+
olive: "808000",
|
|
619
|
+
silver: "c0c0c0",
|
|
620
|
+
aqua: "00ffff",
|
|
621
|
+
fuchsia: "ff00ff",
|
|
622
|
+
lime: "00ff00",
|
|
623
|
+
coral: "ff7f50",
|
|
624
|
+
salmon: "fa8072",
|
|
625
|
+
gold: "ffd700",
|
|
626
|
+
indigo: "4b0082",
|
|
627
|
+
crimson: "dc143c",
|
|
628
|
+
tomato: "ff6347",
|
|
629
|
+
chocolate: "d2691e",
|
|
630
|
+
tan: "d2b48c",
|
|
631
|
+
beige: "f5f5dc",
|
|
632
|
+
ivory: "fffff0",
|
|
633
|
+
khaki: "f0e68c",
|
|
634
|
+
lavender: "e6e6fa",
|
|
635
|
+
plum: "dda0dd",
|
|
636
|
+
orchid: "da70d6",
|
|
637
|
+
turquoise: "40e0d0",
|
|
638
|
+
skyblue: "87ceeb",
|
|
639
|
+
steelblue: "4682b4",
|
|
640
|
+
slategray: "708090",
|
|
641
|
+
slategrey: "708090"
|
|
642
|
+
};
|
|
450
643
|
function ptToTwips(ptValue) {
|
|
451
644
|
return Math.round(ptValue * PT_TO_TWIPS);
|
|
452
645
|
}
|
|
453
|
-
function
|
|
454
|
-
|
|
646
|
+
function colorToHexWithoutHash(color) {
|
|
647
|
+
const trimmed = color.trim();
|
|
648
|
+
const lowerColor = trimmed.toLowerCase();
|
|
649
|
+
if (CSS_NAMED_COLORS_HEX[lowerColor]) {
|
|
650
|
+
return CSS_NAMED_COLORS_HEX[lowerColor];
|
|
651
|
+
}
|
|
652
|
+
return trimmed.replace(/^#/, "");
|
|
455
653
|
}
|
|
456
654
|
function parseFontSizeToPoints(fontSize) {
|
|
457
655
|
if (typeof fontSize === "number") {
|
|
@@ -495,7 +693,7 @@ function marksToRunProperties(marks) {
|
|
|
495
693
|
underlineAttrs["w:val"] = "single";
|
|
496
694
|
}
|
|
497
695
|
if (attrs.underlineColor) {
|
|
498
|
-
underlineAttrs["w:color"] =
|
|
696
|
+
underlineAttrs["w:color"] = colorToHexWithoutHash(String(attrs.underlineColor));
|
|
499
697
|
}
|
|
500
698
|
if (Object.keys(underlineAttrs).length > 0) {
|
|
501
699
|
runProperties.underline = underlineAttrs;
|
|
@@ -518,7 +716,7 @@ function marksToRunProperties(marks) {
|
|
|
518
716
|
case "textStyle": {
|
|
519
717
|
if (attrs.color != null) {
|
|
520
718
|
runProperties.color = {
|
|
521
|
-
val:
|
|
719
|
+
val: colorToHexWithoutHash(String(attrs.color))
|
|
522
720
|
};
|
|
523
721
|
}
|
|
524
722
|
if (attrs.fontSize != null) {
|
|
@@ -576,8 +774,17 @@ function collectMarksFromRunChildren(runNode) {
|
|
|
576
774
|
return Array.from(marksByType.values());
|
|
577
775
|
}
|
|
578
776
|
function normalizeNode(node) {
|
|
777
|
+
if (node.type === "text" && node.marks && Array.isArray(node.marks)) {
|
|
778
|
+
const normalizedMarks = normalizeMarksForRendering(node.marks);
|
|
779
|
+
return {
|
|
780
|
+
...node,
|
|
781
|
+
marks: normalizedMarks
|
|
782
|
+
};
|
|
783
|
+
}
|
|
579
784
|
if (node.type === "run") {
|
|
580
|
-
const
|
|
785
|
+
const normalizedContent = node.content?.map(normalizeNode);
|
|
786
|
+
const normalizedNode = { ...node, content: normalizedContent };
|
|
787
|
+
const marks = collectMarksFromRunChildren(normalizedNode);
|
|
581
788
|
if (marks.length > 0) {
|
|
582
789
|
const runPropsFromMarks = marksToRunProperties(marks);
|
|
583
790
|
const existingRunProps = node.attrs?.runProperties || {};
|
|
@@ -586,15 +793,14 @@ function normalizeNode(node) {
|
|
|
586
793
|
...runPropsFromMarks
|
|
587
794
|
};
|
|
588
795
|
return {
|
|
589
|
-
...
|
|
796
|
+
...normalizedNode,
|
|
590
797
|
attrs: {
|
|
591
|
-
...
|
|
798
|
+
...normalizedNode.attrs,
|
|
592
799
|
runProperties: mergedRunProps
|
|
593
|
-
}
|
|
594
|
-
// Also recursively process children (though runs usually just have text)
|
|
595
|
-
content: node.content?.map(normalizeNode)
|
|
800
|
+
}
|
|
596
801
|
};
|
|
597
802
|
}
|
|
803
|
+
return normalizedNode;
|
|
598
804
|
}
|
|
599
805
|
if (node.content && Array.isArray(node.content)) {
|
|
600
806
|
return {
|
|
@@ -1295,74 +1501,6 @@ function groupReplacements(changes) {
|
|
|
1295
1501
|
}
|
|
1296
1502
|
return result;
|
|
1297
1503
|
}
|
|
1298
|
-
function ensureValidCssColor(color) {
|
|
1299
|
-
if (typeof color !== "string" || !color) {
|
|
1300
|
-
return void 0;
|
|
1301
|
-
}
|
|
1302
|
-
if (/^[0-9a-fA-F]{6}$/.test(color)) {
|
|
1303
|
-
return `#${color}`;
|
|
1304
|
-
}
|
|
1305
|
-
if (/^[0-9a-fA-F]{3}$/.test(color)) {
|
|
1306
|
-
return `#${color}`;
|
|
1307
|
-
}
|
|
1308
|
-
return color;
|
|
1309
|
-
}
|
|
1310
|
-
function normalizeMark(mark) {
|
|
1311
|
-
const attrs = { ...mark.attrs || {} };
|
|
1312
|
-
if (attrs.color !== void 0) {
|
|
1313
|
-
attrs.color = ensureValidCssColor(attrs.color);
|
|
1314
|
-
}
|
|
1315
|
-
return {
|
|
1316
|
-
type: mark.type,
|
|
1317
|
-
attrs
|
|
1318
|
-
};
|
|
1319
|
-
}
|
|
1320
|
-
function normalizeMarks(marks) {
|
|
1321
|
-
return marks.map(normalizeMark);
|
|
1322
|
-
}
|
|
1323
|
-
function normalizeMarksForRendering(marks) {
|
|
1324
|
-
return normalizeMarks(marks);
|
|
1325
|
-
}
|
|
1326
|
-
function createTrackInsertMark(author = DEFAULT_AUTHOR, id) {
|
|
1327
|
-
return {
|
|
1328
|
-
type: "trackInsert",
|
|
1329
|
-
attrs: {
|
|
1330
|
-
id: id ?? v4(),
|
|
1331
|
-
author: author.name,
|
|
1332
|
-
authorEmail: author.email,
|
|
1333
|
-
authorImage: "",
|
|
1334
|
-
date: (/* @__PURE__ */ new Date()).toISOString()
|
|
1335
|
-
}
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
function createTrackDeleteMark(author = DEFAULT_AUTHOR, id) {
|
|
1339
|
-
return {
|
|
1340
|
-
type: "trackDelete",
|
|
1341
|
-
attrs: {
|
|
1342
|
-
id: id ?? v4(),
|
|
1343
|
-
author: author.name,
|
|
1344
|
-
authorEmail: author.email,
|
|
1345
|
-
authorImage: "",
|
|
1346
|
-
date: (/* @__PURE__ */ new Date()).toISOString()
|
|
1347
|
-
}
|
|
1348
|
-
};
|
|
1349
|
-
}
|
|
1350
|
-
function createTrackFormatMark(before, after, author = DEFAULT_AUTHOR) {
|
|
1351
|
-
const normalizedBefore = normalizeMarks(before);
|
|
1352
|
-
const normalizedAfter = normalizeMarks(after);
|
|
1353
|
-
return {
|
|
1354
|
-
type: "trackFormat",
|
|
1355
|
-
attrs: {
|
|
1356
|
-
id: v4(),
|
|
1357
|
-
author: author.name,
|
|
1358
|
-
authorEmail: author.email,
|
|
1359
|
-
authorImage: "",
|
|
1360
|
-
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1361
|
-
before: normalizedBefore,
|
|
1362
|
-
after: normalizedAfter
|
|
1363
|
-
}
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
1504
|
|
|
1367
1505
|
// src/services/nodeAligner.ts
|
|
1368
1506
|
init_nodeFingerprint();
|