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.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
-
var DiffMatchPatch = require('diff-match-patch');
|
|
8
7
|
var uuid = require('uuid');
|
|
8
|
+
var DiffMatchPatch = require('diff-match-patch');
|
|
9
9
|
|
|
10
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
|
|
@@ -452,14 +452,212 @@ var TIMEOUTS = {
|
|
|
452
452
|
/** Cleanup delay (ms) */
|
|
453
453
|
CLEANUP_DELAY: 100
|
|
454
454
|
};
|
|
455
|
+
var CSS_NAMED_COLORS = {
|
|
456
|
+
// Basic colors
|
|
457
|
+
black: "#000000",
|
|
458
|
+
white: "#ffffff",
|
|
459
|
+
red: "#ff0000",
|
|
460
|
+
green: "#008000",
|
|
461
|
+
blue: "#0000ff",
|
|
462
|
+
yellow: "#ffff00",
|
|
463
|
+
cyan: "#00ffff",
|
|
464
|
+
magenta: "#ff00ff",
|
|
465
|
+
// Extended colors
|
|
466
|
+
orange: "#ffa500",
|
|
467
|
+
pink: "#ffc0cb",
|
|
468
|
+
purple: "#800080",
|
|
469
|
+
violet: "#ee82ee",
|
|
470
|
+
brown: "#a52a2a",
|
|
471
|
+
gray: "#808080",
|
|
472
|
+
grey: "#808080",
|
|
473
|
+
// Light variants
|
|
474
|
+
lightblue: "#add8e6",
|
|
475
|
+
lightgreen: "#90ee90",
|
|
476
|
+
lightgray: "#d3d3d3",
|
|
477
|
+
lightgrey: "#d3d3d3",
|
|
478
|
+
lightpink: "#ffb6c1",
|
|
479
|
+
lightyellow: "#ffffe0",
|
|
480
|
+
// Dark variants
|
|
481
|
+
darkblue: "#00008b",
|
|
482
|
+
darkgreen: "#006400",
|
|
483
|
+
darkgray: "#a9a9a9",
|
|
484
|
+
darkgrey: "#a9a9a9",
|
|
485
|
+
darkred: "#8b0000",
|
|
486
|
+
// Other common colors
|
|
487
|
+
navy: "#000080",
|
|
488
|
+
teal: "#008080",
|
|
489
|
+
maroon: "#800000",
|
|
490
|
+
olive: "#808000",
|
|
491
|
+
silver: "#c0c0c0",
|
|
492
|
+
aqua: "#00ffff",
|
|
493
|
+
fuchsia: "#ff00ff",
|
|
494
|
+
lime: "#00ff00",
|
|
495
|
+
coral: "#ff7f50",
|
|
496
|
+
salmon: "#fa8072",
|
|
497
|
+
gold: "#ffd700",
|
|
498
|
+
indigo: "#4b0082",
|
|
499
|
+
crimson: "#dc143c",
|
|
500
|
+
tomato: "#ff6347",
|
|
501
|
+
chocolate: "#d2691e",
|
|
502
|
+
tan: "#d2b48c",
|
|
503
|
+
beige: "#f5f5dc",
|
|
504
|
+
ivory: "#fffff0",
|
|
505
|
+
khaki: "#f0e68c",
|
|
506
|
+
lavender: "#e6e6fa",
|
|
507
|
+
plum: "#dda0dd",
|
|
508
|
+
orchid: "#da70d6",
|
|
509
|
+
turquoise: "#40e0d0",
|
|
510
|
+
skyblue: "#87ceeb",
|
|
511
|
+
steelblue: "#4682b4",
|
|
512
|
+
slategray: "#708090",
|
|
513
|
+
slategrey: "#708090"
|
|
514
|
+
};
|
|
515
|
+
function ensureValidCssColor(color) {
|
|
516
|
+
if (typeof color !== "string" || !color) {
|
|
517
|
+
return void 0;
|
|
518
|
+
}
|
|
519
|
+
const trimmed = color.trim();
|
|
520
|
+
const lowerColor = trimmed.toLowerCase();
|
|
521
|
+
if (CSS_NAMED_COLORS[lowerColor]) {
|
|
522
|
+
return CSS_NAMED_COLORS[lowerColor];
|
|
523
|
+
}
|
|
524
|
+
if (/^[0-9a-fA-F]{6}$/.test(trimmed)) {
|
|
525
|
+
return `#${trimmed}`;
|
|
526
|
+
}
|
|
527
|
+
if (/^[0-9a-fA-F]{3}$/.test(trimmed)) {
|
|
528
|
+
return `#${trimmed}`;
|
|
529
|
+
}
|
|
530
|
+
return trimmed;
|
|
531
|
+
}
|
|
532
|
+
function normalizeMark(mark) {
|
|
533
|
+
const attrs = { ...mark.attrs || {} };
|
|
534
|
+
if (attrs.color !== void 0) {
|
|
535
|
+
attrs.color = ensureValidCssColor(attrs.color);
|
|
536
|
+
}
|
|
537
|
+
return {
|
|
538
|
+
type: mark.type,
|
|
539
|
+
attrs
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
function normalizeMarks(marks) {
|
|
543
|
+
return marks.map(normalizeMark);
|
|
544
|
+
}
|
|
545
|
+
function normalizeMarksForRendering(marks) {
|
|
546
|
+
return normalizeMarks(marks);
|
|
547
|
+
}
|
|
548
|
+
function createTrackInsertMark(author = DEFAULT_AUTHOR, id) {
|
|
549
|
+
return {
|
|
550
|
+
type: "trackInsert",
|
|
551
|
+
attrs: {
|
|
552
|
+
id: id ?? uuid.v4(),
|
|
553
|
+
author: author.name,
|
|
554
|
+
authorEmail: author.email,
|
|
555
|
+
authorImage: "",
|
|
556
|
+
date: (/* @__PURE__ */ new Date()).toISOString()
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
function createTrackDeleteMark(author = DEFAULT_AUTHOR, id) {
|
|
561
|
+
return {
|
|
562
|
+
type: "trackDelete",
|
|
563
|
+
attrs: {
|
|
564
|
+
id: id ?? uuid.v4(),
|
|
565
|
+
author: author.name,
|
|
566
|
+
authorEmail: author.email,
|
|
567
|
+
authorImage: "",
|
|
568
|
+
date: (/* @__PURE__ */ new Date()).toISOString()
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function createTrackFormatMark(before, after, author = DEFAULT_AUTHOR) {
|
|
573
|
+
const normalizedBefore = normalizeMarks(before);
|
|
574
|
+
const normalizedAfter = normalizeMarks(after);
|
|
575
|
+
return {
|
|
576
|
+
type: "trackFormat",
|
|
577
|
+
attrs: {
|
|
578
|
+
id: uuid.v4(),
|
|
579
|
+
author: author.name,
|
|
580
|
+
authorEmail: author.email,
|
|
581
|
+
authorImage: "",
|
|
582
|
+
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
583
|
+
before: normalizedBefore,
|
|
584
|
+
after: normalizedAfter
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
}
|
|
455
588
|
|
|
456
589
|
// src/services/runPropertiesSync.ts
|
|
457
590
|
var PT_TO_TWIPS = 20;
|
|
591
|
+
var CSS_NAMED_COLORS_HEX = {
|
|
592
|
+
// Basic colors
|
|
593
|
+
black: "000000",
|
|
594
|
+
white: "ffffff",
|
|
595
|
+
red: "ff0000",
|
|
596
|
+
green: "008000",
|
|
597
|
+
blue: "0000ff",
|
|
598
|
+
yellow: "ffff00",
|
|
599
|
+
cyan: "00ffff",
|
|
600
|
+
magenta: "ff00ff",
|
|
601
|
+
// Extended colors
|
|
602
|
+
orange: "ffa500",
|
|
603
|
+
pink: "ffc0cb",
|
|
604
|
+
purple: "800080",
|
|
605
|
+
violet: "ee82ee",
|
|
606
|
+
brown: "a52a2a",
|
|
607
|
+
gray: "808080",
|
|
608
|
+
grey: "808080",
|
|
609
|
+
// Light variants
|
|
610
|
+
lightblue: "add8e6",
|
|
611
|
+
lightgreen: "90ee90",
|
|
612
|
+
lightgray: "d3d3d3",
|
|
613
|
+
lightgrey: "d3d3d3",
|
|
614
|
+
lightpink: "ffb6c1",
|
|
615
|
+
lightyellow: "ffffe0",
|
|
616
|
+
// Dark variants
|
|
617
|
+
darkblue: "00008b",
|
|
618
|
+
darkgreen: "006400",
|
|
619
|
+
darkgray: "a9a9a9",
|
|
620
|
+
darkgrey: "a9a9a9",
|
|
621
|
+
darkred: "8b0000",
|
|
622
|
+
// Other common colors
|
|
623
|
+
navy: "000080",
|
|
624
|
+
teal: "008080",
|
|
625
|
+
maroon: "800000",
|
|
626
|
+
olive: "808000",
|
|
627
|
+
silver: "c0c0c0",
|
|
628
|
+
aqua: "00ffff",
|
|
629
|
+
fuchsia: "ff00ff",
|
|
630
|
+
lime: "00ff00",
|
|
631
|
+
coral: "ff7f50",
|
|
632
|
+
salmon: "fa8072",
|
|
633
|
+
gold: "ffd700",
|
|
634
|
+
indigo: "4b0082",
|
|
635
|
+
crimson: "dc143c",
|
|
636
|
+
tomato: "ff6347",
|
|
637
|
+
chocolate: "d2691e",
|
|
638
|
+
tan: "d2b48c",
|
|
639
|
+
beige: "f5f5dc",
|
|
640
|
+
ivory: "fffff0",
|
|
641
|
+
khaki: "f0e68c",
|
|
642
|
+
lavender: "e6e6fa",
|
|
643
|
+
plum: "dda0dd",
|
|
644
|
+
orchid: "da70d6",
|
|
645
|
+
turquoise: "40e0d0",
|
|
646
|
+
skyblue: "87ceeb",
|
|
647
|
+
steelblue: "4682b4",
|
|
648
|
+
slategray: "708090",
|
|
649
|
+
slategrey: "708090"
|
|
650
|
+
};
|
|
458
651
|
function ptToTwips(ptValue) {
|
|
459
652
|
return Math.round(ptValue * PT_TO_TWIPS);
|
|
460
653
|
}
|
|
461
|
-
function
|
|
462
|
-
|
|
654
|
+
function colorToHexWithoutHash(color) {
|
|
655
|
+
const trimmed = color.trim();
|
|
656
|
+
const lowerColor = trimmed.toLowerCase();
|
|
657
|
+
if (CSS_NAMED_COLORS_HEX[lowerColor]) {
|
|
658
|
+
return CSS_NAMED_COLORS_HEX[lowerColor];
|
|
659
|
+
}
|
|
660
|
+
return trimmed.replace(/^#/, "");
|
|
463
661
|
}
|
|
464
662
|
function parseFontSizeToPoints(fontSize) {
|
|
465
663
|
if (typeof fontSize === "number") {
|
|
@@ -503,7 +701,7 @@ function marksToRunProperties(marks) {
|
|
|
503
701
|
underlineAttrs["w:val"] = "single";
|
|
504
702
|
}
|
|
505
703
|
if (attrs.underlineColor) {
|
|
506
|
-
underlineAttrs["w:color"] =
|
|
704
|
+
underlineAttrs["w:color"] = colorToHexWithoutHash(String(attrs.underlineColor));
|
|
507
705
|
}
|
|
508
706
|
if (Object.keys(underlineAttrs).length > 0) {
|
|
509
707
|
runProperties.underline = underlineAttrs;
|
|
@@ -526,7 +724,7 @@ function marksToRunProperties(marks) {
|
|
|
526
724
|
case "textStyle": {
|
|
527
725
|
if (attrs.color != null) {
|
|
528
726
|
runProperties.color = {
|
|
529
|
-
val:
|
|
727
|
+
val: colorToHexWithoutHash(String(attrs.color))
|
|
530
728
|
};
|
|
531
729
|
}
|
|
532
730
|
if (attrs.fontSize != null) {
|
|
@@ -584,8 +782,17 @@ function collectMarksFromRunChildren(runNode) {
|
|
|
584
782
|
return Array.from(marksByType.values());
|
|
585
783
|
}
|
|
586
784
|
function normalizeNode(node) {
|
|
785
|
+
if (node.type === "text" && node.marks && Array.isArray(node.marks)) {
|
|
786
|
+
const normalizedMarks = normalizeMarksForRendering(node.marks);
|
|
787
|
+
return {
|
|
788
|
+
...node,
|
|
789
|
+
marks: normalizedMarks
|
|
790
|
+
};
|
|
791
|
+
}
|
|
587
792
|
if (node.type === "run") {
|
|
588
|
-
const
|
|
793
|
+
const normalizedContent = node.content?.map(normalizeNode);
|
|
794
|
+
const normalizedNode = { ...node, content: normalizedContent };
|
|
795
|
+
const marks = collectMarksFromRunChildren(normalizedNode);
|
|
589
796
|
if (marks.length > 0) {
|
|
590
797
|
const runPropsFromMarks = marksToRunProperties(marks);
|
|
591
798
|
const existingRunProps = node.attrs?.runProperties || {};
|
|
@@ -594,15 +801,14 @@ function normalizeNode(node) {
|
|
|
594
801
|
...runPropsFromMarks
|
|
595
802
|
};
|
|
596
803
|
return {
|
|
597
|
-
...
|
|
804
|
+
...normalizedNode,
|
|
598
805
|
attrs: {
|
|
599
|
-
...
|
|
806
|
+
...normalizedNode.attrs,
|
|
600
807
|
runProperties: mergedRunProps
|
|
601
|
-
}
|
|
602
|
-
// Also recursively process children (though runs usually just have text)
|
|
603
|
-
content: node.content?.map(normalizeNode)
|
|
808
|
+
}
|
|
604
809
|
};
|
|
605
810
|
}
|
|
811
|
+
return normalizedNode;
|
|
606
812
|
}
|
|
607
813
|
if (node.content && Array.isArray(node.content)) {
|
|
608
814
|
return {
|
|
@@ -1303,74 +1509,6 @@ function groupReplacements(changes) {
|
|
|
1303
1509
|
}
|
|
1304
1510
|
return result;
|
|
1305
1511
|
}
|
|
1306
|
-
function ensureValidCssColor(color) {
|
|
1307
|
-
if (typeof color !== "string" || !color) {
|
|
1308
|
-
return void 0;
|
|
1309
|
-
}
|
|
1310
|
-
if (/^[0-9a-fA-F]{6}$/.test(color)) {
|
|
1311
|
-
return `#${color}`;
|
|
1312
|
-
}
|
|
1313
|
-
if (/^[0-9a-fA-F]{3}$/.test(color)) {
|
|
1314
|
-
return `#${color}`;
|
|
1315
|
-
}
|
|
1316
|
-
return color;
|
|
1317
|
-
}
|
|
1318
|
-
function normalizeMark(mark) {
|
|
1319
|
-
const attrs = { ...mark.attrs || {} };
|
|
1320
|
-
if (attrs.color !== void 0) {
|
|
1321
|
-
attrs.color = ensureValidCssColor(attrs.color);
|
|
1322
|
-
}
|
|
1323
|
-
return {
|
|
1324
|
-
type: mark.type,
|
|
1325
|
-
attrs
|
|
1326
|
-
};
|
|
1327
|
-
}
|
|
1328
|
-
function normalizeMarks(marks) {
|
|
1329
|
-
return marks.map(normalizeMark);
|
|
1330
|
-
}
|
|
1331
|
-
function normalizeMarksForRendering(marks) {
|
|
1332
|
-
return normalizeMarks(marks);
|
|
1333
|
-
}
|
|
1334
|
-
function createTrackInsertMark(author = DEFAULT_AUTHOR, id) {
|
|
1335
|
-
return {
|
|
1336
|
-
type: "trackInsert",
|
|
1337
|
-
attrs: {
|
|
1338
|
-
id: id ?? uuid.v4(),
|
|
1339
|
-
author: author.name,
|
|
1340
|
-
authorEmail: author.email,
|
|
1341
|
-
authorImage: "",
|
|
1342
|
-
date: (/* @__PURE__ */ new Date()).toISOString()
|
|
1343
|
-
}
|
|
1344
|
-
};
|
|
1345
|
-
}
|
|
1346
|
-
function createTrackDeleteMark(author = DEFAULT_AUTHOR, id) {
|
|
1347
|
-
return {
|
|
1348
|
-
type: "trackDelete",
|
|
1349
|
-
attrs: {
|
|
1350
|
-
id: id ?? uuid.v4(),
|
|
1351
|
-
author: author.name,
|
|
1352
|
-
authorEmail: author.email,
|
|
1353
|
-
authorImage: "",
|
|
1354
|
-
date: (/* @__PURE__ */ new Date()).toISOString()
|
|
1355
|
-
}
|
|
1356
|
-
};
|
|
1357
|
-
}
|
|
1358
|
-
function createTrackFormatMark(before, after, author = DEFAULT_AUTHOR) {
|
|
1359
|
-
const normalizedBefore = normalizeMarks(before);
|
|
1360
|
-
const normalizedAfter = normalizeMarks(after);
|
|
1361
|
-
return {
|
|
1362
|
-
type: "trackFormat",
|
|
1363
|
-
attrs: {
|
|
1364
|
-
id: uuid.v4(),
|
|
1365
|
-
author: author.name,
|
|
1366
|
-
authorEmail: author.email,
|
|
1367
|
-
authorImage: "",
|
|
1368
|
-
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1369
|
-
before: normalizedBefore,
|
|
1370
|
-
after: normalizedAfter
|
|
1371
|
-
}
|
|
1372
|
-
};
|
|
1373
|
-
}
|
|
1374
1512
|
|
|
1375
1513
|
// src/services/nodeAligner.ts
|
|
1376
1514
|
init_nodeFingerprint();
|