docx-diff-editor 1.0.48 → 1.0.51

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 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
 
@@ -453,14 +453,156 @@ var TIMEOUTS = {
453
453
  CLEANUP_DELAY: 100
454
454
  };
455
455
 
456
+ // src/services/colorUtils.ts
457
+ var CSS_NAMED_COLORS = {
458
+ // Basic colors
459
+ black: "000000",
460
+ white: "ffffff",
461
+ red: "ff0000",
462
+ green: "008000",
463
+ blue: "0000ff",
464
+ yellow: "ffff00",
465
+ cyan: "00ffff",
466
+ magenta: "ff00ff",
467
+ // Extended colors
468
+ orange: "ffa500",
469
+ pink: "ffc0cb",
470
+ purple: "800080",
471
+ violet: "ee82ee",
472
+ brown: "a52a2a",
473
+ gray: "808080",
474
+ grey: "808080",
475
+ // Light variants
476
+ lightblue: "add8e6",
477
+ lightgreen: "90ee90",
478
+ lightgray: "d3d3d3",
479
+ lightgrey: "d3d3d3",
480
+ lightpink: "ffb6c1",
481
+ lightyellow: "ffffe0",
482
+ // Dark variants
483
+ darkblue: "00008b",
484
+ darkgreen: "006400",
485
+ darkgray: "a9a9a9",
486
+ darkgrey: "a9a9a9",
487
+ darkred: "8b0000",
488
+ // Other common colors
489
+ navy: "000080",
490
+ teal: "008080",
491
+ maroon: "800000",
492
+ olive: "808000",
493
+ silver: "c0c0c0",
494
+ aqua: "00ffff",
495
+ fuchsia: "ff00ff",
496
+ lime: "00ff00",
497
+ coral: "ff7f50",
498
+ salmon: "fa8072",
499
+ gold: "ffd700",
500
+ indigo: "4b0082",
501
+ crimson: "dc143c",
502
+ tomato: "ff6347",
503
+ chocolate: "d2691e",
504
+ tan: "d2b48c",
505
+ beige: "f5f5dc",
506
+ ivory: "fffff0",
507
+ khaki: "f0e68c",
508
+ lavender: "e6e6fa",
509
+ plum: "dda0dd",
510
+ orchid: "da70d6",
511
+ turquoise: "40e0d0",
512
+ skyblue: "87ceeb",
513
+ steelblue: "4682b4",
514
+ slategray: "708090",
515
+ slategrey: "708090"
516
+ };
517
+ function colorToHexWithoutHash(color) {
518
+ const trimmed = color.trim();
519
+ const lowerColor = trimmed.toLowerCase();
520
+ if (CSS_NAMED_COLORS[lowerColor]) {
521
+ return CSS_NAMED_COLORS[lowerColor];
522
+ }
523
+ return trimmed.replace(/^#/, "");
524
+ }
525
+ function ensureValidCssColor(color) {
526
+ if (typeof color !== "string" || !color) {
527
+ return void 0;
528
+ }
529
+ const trimmed = color.trim();
530
+ const lowerColor = trimmed.toLowerCase();
531
+ if (CSS_NAMED_COLORS[lowerColor]) {
532
+ return `#${CSS_NAMED_COLORS[lowerColor]}`;
533
+ }
534
+ if (/^[0-9a-fA-F]{6}$/.test(trimmed)) {
535
+ return `#${trimmed}`;
536
+ }
537
+ if (/^[0-9a-fA-F]{3}$/.test(trimmed)) {
538
+ return `#${trimmed}`;
539
+ }
540
+ return trimmed;
541
+ }
542
+
543
+ // src/services/trackChangeInjector.ts
544
+ function normalizeMark(mark) {
545
+ const attrs = { ...mark.attrs || {} };
546
+ if (attrs.color !== void 0) {
547
+ attrs.color = ensureValidCssColor(attrs.color);
548
+ }
549
+ return {
550
+ type: mark.type,
551
+ attrs
552
+ };
553
+ }
554
+ function normalizeMarks(marks) {
555
+ return marks.map(normalizeMark);
556
+ }
557
+ function normalizeMarksForRendering(marks) {
558
+ return normalizeMarks(marks);
559
+ }
560
+ function createTrackInsertMark(author = DEFAULT_AUTHOR, id) {
561
+ return {
562
+ type: "trackInsert",
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 createTrackDeleteMark(author = DEFAULT_AUTHOR, id) {
573
+ return {
574
+ type: "trackDelete",
575
+ attrs: {
576
+ id: id ?? uuid.v4(),
577
+ author: author.name,
578
+ authorEmail: author.email,
579
+ authorImage: "",
580
+ date: (/* @__PURE__ */ new Date()).toISOString()
581
+ }
582
+ };
583
+ }
584
+ function createTrackFormatMark(before, after, author = DEFAULT_AUTHOR) {
585
+ const normalizedBefore = normalizeMarks(before);
586
+ const normalizedAfter = normalizeMarks(after);
587
+ return {
588
+ type: "trackFormat",
589
+ attrs: {
590
+ id: uuid.v4(),
591
+ author: author.name,
592
+ authorEmail: author.email,
593
+ authorImage: "",
594
+ date: (/* @__PURE__ */ new Date()).toISOString(),
595
+ before: normalizedBefore,
596
+ after: normalizedAfter
597
+ }
598
+ };
599
+ }
600
+
456
601
  // src/services/runPropertiesSync.ts
457
602
  var PT_TO_TWIPS = 20;
458
603
  function ptToTwips(ptValue) {
459
604
  return Math.round(ptValue * PT_TO_TWIPS);
460
605
  }
461
- function stripHashFromColor(color) {
462
- return color.replace(/^#/, "");
463
- }
464
606
  function parseFontSizeToPoints(fontSize) {
465
607
  if (typeof fontSize === "number") {
466
608
  return fontSize;
@@ -503,7 +645,7 @@ function marksToRunProperties(marks) {
503
645
  underlineAttrs["w:val"] = "single";
504
646
  }
505
647
  if (attrs.underlineColor) {
506
- underlineAttrs["w:color"] = stripHashFromColor(String(attrs.underlineColor));
648
+ underlineAttrs["w:color"] = colorToHexWithoutHash(String(attrs.underlineColor));
507
649
  }
508
650
  if (Object.keys(underlineAttrs).length > 0) {
509
651
  runProperties.underline = underlineAttrs;
@@ -526,7 +668,7 @@ function marksToRunProperties(marks) {
526
668
  case "textStyle": {
527
669
  if (attrs.color != null) {
528
670
  runProperties.color = {
529
- val: stripHashFromColor(String(attrs.color))
671
+ val: colorToHexWithoutHash(String(attrs.color))
530
672
  };
531
673
  }
532
674
  if (attrs.fontSize != null) {
@@ -584,8 +726,17 @@ function collectMarksFromRunChildren(runNode) {
584
726
  return Array.from(marksByType.values());
585
727
  }
586
728
  function normalizeNode(node) {
729
+ if (node.type === "text" && node.marks && Array.isArray(node.marks)) {
730
+ const normalizedMarks = normalizeMarksForRendering(node.marks);
731
+ return {
732
+ ...node,
733
+ marks: normalizedMarks
734
+ };
735
+ }
587
736
  if (node.type === "run") {
588
- const marks = collectMarksFromRunChildren(node);
737
+ const normalizedContent = node.content?.map(normalizeNode);
738
+ const normalizedNode = { ...node, content: normalizedContent };
739
+ const marks = collectMarksFromRunChildren(normalizedNode);
589
740
  if (marks.length > 0) {
590
741
  const runPropsFromMarks = marksToRunProperties(marks);
591
742
  const existingRunProps = node.attrs?.runProperties || {};
@@ -594,15 +745,14 @@ function normalizeNode(node) {
594
745
  ...runPropsFromMarks
595
746
  };
596
747
  return {
597
- ...node,
748
+ ...normalizedNode,
598
749
  attrs: {
599
- ...node.attrs,
750
+ ...normalizedNode.attrs,
600
751
  runProperties: mergedRunProps
601
- },
602
- // Also recursively process children (though runs usually just have text)
603
- content: node.content?.map(normalizeNode)
752
+ }
604
753
  };
605
754
  }
755
+ return normalizedNode;
606
756
  }
607
757
  if (node.content && Array.isArray(node.content)) {
608
758
  return {
@@ -1303,74 +1453,6 @@ function groupReplacements(changes) {
1303
1453
  }
1304
1454
  return result;
1305
1455
  }
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
1456
 
1375
1457
  // src/services/nodeAligner.ts
1376
1458
  init_nodeFingerprint();