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