y-mxgraph 0.5.6 → 0.5.8

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const xmlJs = require("xml-js");
3
+ const transformer = require("./index-CcOHH2TY.cjs");
4
4
  const Y = require("yjs");
5
5
  const colord = require("colord");
6
6
  function _interopNamespaceDefault(e) {
@@ -20,191 +20,25 @@ function _interopNamespaceDefault(e) {
20
20
  return Object.freeze(n);
21
21
  }
22
22
  const Y__namespace = /* @__PURE__ */ _interopNamespaceDefault(Y);
23
- function deepProcess(node) {
24
- if (node == null) return;
25
- if (Array.isArray(node)) {
26
- for (const item of node) {
27
- deepProcess(item);
23
+ var __defProp$1 = Object.defineProperty;
24
+ var __defProps = Object.defineProperties;
25
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
26
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
27
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
28
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
29
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
30
+ var __spreadValues$1 = (a, b) => {
31
+ for (var prop in b || (b = {}))
32
+ if (__hasOwnProp$1.call(b, prop))
33
+ __defNormalProp$1(a, prop, b[prop]);
34
+ if (__getOwnPropSymbols$1)
35
+ for (var prop of __getOwnPropSymbols$1(b)) {
36
+ if (__propIsEnum$1.call(b, prop))
37
+ __defNormalProp$1(a, prop, b[prop]);
28
38
  }
29
- return;
30
- }
31
- if (typeof node !== "object") return;
32
- const obj = node;
33
- const keys = Object.keys(obj);
34
- for (const key2 of keys) {
35
- if (key2 === "_attributes") continue;
36
- let value = obj[key2];
37
- const keyLower = key2.toLowerCase();
38
- if ((keyLower === "diagram" || keyLower === "mxcell") && value !== void 0 && !Array.isArray(value)) {
39
- obj[key2] = [value];
40
- value = obj[key2];
41
- }
42
- if (Array.isArray(value)) {
43
- for (const v of value) deepProcess(v);
44
- } else if (value && typeof value === "object") {
45
- deepProcess(value);
46
- }
47
- }
48
- }
49
- function parse$4(xml) {
50
- const result = xmlJs.xml2js(xml, { compact: true });
51
- deepProcess(result);
52
- return result;
53
- }
54
- function serializer$1(obj, spaces = 2) {
55
- return xmlJs.js2xml(obj, {
56
- compact: true,
57
- spaces
58
- });
59
- }
60
- const key$3 = "mxCell";
61
- const mxGeometryKey = "mxGeometry";
62
- const mxGeometryAttributeKey = "geometry";
63
- function parse$3(object) {
64
- var _a;
65
- const xmlElement = new Y__namespace.XmlElement("mxCell");
66
- for (const attribute of Object.keys(object._attributes || {})) {
67
- xmlElement.setAttribute(
68
- attribute,
69
- `${((_a = object._attributes) == null ? void 0 : _a[attribute]) || ""}`
70
- );
71
- }
72
- if (object[mxGeometryKey]) {
73
- const geometry = object[mxGeometryKey];
74
- const geometryString = xmlJs.js2xml(geometry, {
75
- compact: true
76
- });
77
- xmlElement.setAttribute(mxGeometryAttributeKey, geometryString);
78
- delete object[mxGeometryKey];
79
- }
80
- return xmlElement;
81
- }
82
- function serialize$2(xmlElement) {
83
- const rawAttributes = {
84
- ...xmlElement.getAttributes()
85
- };
86
- let mxGeometry = null;
87
- let mxGeometryString;
88
- if (mxGeometryAttributeKey in rawAttributes) {
89
- mxGeometryString = rawAttributes[mxGeometryAttributeKey];
90
- delete rawAttributes[mxGeometryAttributeKey];
91
- }
92
- const attributes = {};
93
- for (const [key2, value] of Object.entries(rawAttributes)) {
94
- if (typeof value === "string") {
95
- attributes[key2] = value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
96
- } else if (value != null) {
97
- attributes[key2] = String(value);
98
- }
99
- }
100
- if (mxGeometryString) {
101
- try {
102
- const parsed = xmlJs.xml2js(mxGeometryString, { compact: true });
103
- mxGeometry = parsed[mxGeometryKey] ?? null;
104
- if (mxGeometry && mxGeometry._attributes) {
105
- mxGeometry._attributes["as"] = "geometry";
106
- }
107
- } catch (e) {
108
- console.warn("[y-mxgraph] Failed to parse mxGeometry:", e);
109
- }
110
- }
111
- const obj = {
112
- _attributes: attributes
113
- };
114
- if (mxGeometry) {
115
- obj[mxGeometryKey] = mxGeometry;
116
- }
117
- return obj;
118
- }
119
- const key$2 = "mxGraphModel";
120
- const mxCellOrderKey = key$3 + "Order";
121
- function parse$2(object, doc) {
122
- const mxCells = (object.root[key$3] || []).map((cell) => {
123
- var _a;
124
- return {
125
- value: parse$3(cell),
126
- id: ((_a = cell._attributes) == null ? void 0 : _a.id) || ""
127
- };
128
- });
129
- const mxGraphElement = (doc == null ? void 0 : doc.getMap(key$2)) || new Y__namespace.Map();
130
- const cells = new Y__namespace.Map();
131
- const cellsOrder = new Y__namespace.Array();
132
- mxCells.forEach((cell) => {
133
- cells.set(cell.id, cell.value);
134
- });
135
- cellsOrder.push(mxCells.map((cell) => cell.id));
136
- mxGraphElement.set(key$3, cells);
137
- mxGraphElement.set(mxCellOrderKey, cellsOrder);
138
- return mxGraphElement;
139
- }
140
- function serialize$1(map) {
141
- const cells = map.get(key$3);
142
- const cellsOrder = map.get(mxCellOrderKey);
143
- return {
144
- _attributes: {},
145
- root: {
146
- [key$3]: cellsOrder.toArray().map((id) => serialize$2(cells.get(id)))
147
- }
148
- };
149
- }
150
- const key$1 = "diagram";
151
- function parse$1(object) {
152
- var _a, _b;
153
- const yDiagramElement = new Y__namespace.Map();
154
- yDiagramElement.set("name", `${((_a = object._attributes) == null ? void 0 : _a.name) || ""}`);
155
- yDiagramElement.set("id", `${((_b = object._attributes) == null ? void 0 : _b.id) || ""}`);
156
- const mxGraphModel = parse$2(object[key$2]);
157
- yDiagramElement.set(key$2, mxGraphModel);
158
- return yDiagramElement;
159
- }
160
- function serialize(yDiagram) {
161
- const mxGraphModel = yDiagram.get(key$2);
162
- return {
163
- _attributes: {
164
- name: yDiagram.get("name"),
165
- id: yDiagram.get("id")
166
- },
167
- [key$2]: mxGraphModel ? serialize$1(mxGraphModel) : void 0
168
- };
169
- }
170
- const key = "mxfile";
171
- const diagramOrderKey = key$1 + "Order";
172
- function parse(object, doc) {
173
- var _a;
174
- const mxfile = doc.getMap(key);
175
- mxfile.set("pages", (((_a = object._attributes) == null ? void 0 : _a.pages) || "1") + "");
176
- const diagramList = object.diagram.map((diagram) => {
177
- var _a2;
178
- return {
179
- value: parse$1(diagram),
180
- id: ((_a2 = diagram._attributes) == null ? void 0 : _a2.id) || ""
181
- };
182
- });
183
- const diagramMap = new Y__namespace.Map();
184
- const diagramOrder = new Y__namespace.Array();
185
- diagramList.forEach((diagram) => {
186
- diagramMap.set(diagram.id, diagram.value);
187
- });
188
- diagramOrder.push(diagramList.map((diagram) => diagram.id));
189
- mxfile.set(key$1, diagramMap);
190
- mxfile.set(diagramOrderKey, diagramOrder);
191
- return mxfile;
192
- }
193
- function serializer(yMxFile) {
194
- const diagrams = yMxFile.get(key$1);
195
- const diagramOrder = yMxFile.get(
196
- diagramOrderKey
197
- );
198
- const orderIds = diagramOrder ? diagramOrder.toArray() : [];
199
- const ids = orderIds.length > 0 ? orderIds : diagrams ? Array.from(diagrams.keys()) : [];
200
- const obj = {
201
- _attributes: {
202
- pages: yMxFile.get("pages") || "1"
203
- },
204
- [key$1]: ids.map((id) => diagrams.get(id)).filter((d) => !!d).map((diagramElement) => serialize(diagramElement))
205
- };
206
- return obj;
207
- }
39
+ return a;
40
+ };
41
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
208
42
  const DIFF_INSERT = "i";
209
43
  const DIFF_REMOVE = "r";
210
44
  const DIFF_UPDATE = "u";
@@ -240,11 +74,11 @@ function ensureUniqueOrder(orderArr) {
240
74
  }
241
75
  function applyFilePatch(doc, patch, options) {
242
76
  doc.transact(() => {
243
- const mxfile = doc.getMap(key);
77
+ const mxfile = doc.getMap(transformer.key);
244
78
  if (patch[DIFF_REMOVE]) {
245
- const diagramsMap = mxfile.get(key$1);
79
+ const diagramsMap = mxfile.get(transformer.key$1);
246
80
  const orderArr = mxfile.get(
247
- diagramOrderKey
81
+ transformer.diagramOrderKey
248
82
  );
249
83
  ensureUniqueOrder(orderArr);
250
84
  const orderList = orderArr.toArray();
@@ -256,9 +90,9 @@ function applyFilePatch(doc, patch, options) {
256
90
  }
257
91
  }
258
92
  if (patch[DIFF_INSERT]) {
259
- const diagramsMap = mxfile.get(key$1);
93
+ const diagramsMap = mxfile.get(transformer.key$1);
260
94
  const orderArr = mxfile.get(
261
- diagramOrderKey
95
+ transformer.diagramOrderKey
262
96
  );
263
97
  ensureUniqueOrder(orderArr);
264
98
  const currentOrder = orderArr.toArray();
@@ -271,9 +105,9 @@ function applyFilePatch(doc, patch, options) {
271
105
  const existingIndex = /* @__PURE__ */ new Map();
272
106
  existingIds.forEach((id, idx) => existingIndex.set(id, idx));
273
107
  const inserts = patch[DIFF_INSERT].map((item, order) => {
274
- const object = parse$4(item.data);
108
+ const object = transformer.parse(item.data);
275
109
  const diagramObj = Array.isArray(object == null ? void 0 : object.diagram) ? object.diagram[0] : object == null ? void 0 : object.diagram;
276
- const diagramElement = parse$1(
110
+ const diagramElement = transformer.parse$1(
277
111
  diagramObj
278
112
  );
279
113
  return {
@@ -311,7 +145,7 @@ function applyFilePatch(doc, patch, options) {
311
145
  }
312
146
  return { anchorId, depth };
313
147
  };
314
- const enriched = inserts.map((i) => ({ ...i, ...computeAnchor(i) }));
148
+ const enriched = inserts.map((i) => __spreadValues$1(__spreadValues$1({}, i), computeAnchor(i)));
315
149
  enriched.sort((a, b) => {
316
150
  const aIdx = a.anchorId ? existingIndex.get(a.anchorId) : -1;
317
151
  const bIdx = b.anchorId ? existingIndex.get(b.anchorId) : -1;
@@ -327,7 +161,7 @@ function applyFilePatch(doc, patch, options) {
327
161
  if (patch[DIFF_UPDATE]) {
328
162
  Object.keys(patch[DIFF_UPDATE]).forEach((id) => {
329
163
  const diagramsMap = mxfile.get(
330
- key$1
164
+ transformer.key$1
331
165
  );
332
166
  const diagram = diagramsMap.get(id);
333
167
  if (diagram) {
@@ -339,10 +173,10 @@ function applyFilePatch(doc, patch, options) {
339
173
  );
340
174
  }
341
175
  if (update.cells) {
342
- const yMxGraphModel = diagram.get(key$2);
176
+ const yMxGraphModel = diagram.get(transformer.key$2);
343
177
  if (!yMxGraphModel) return;
344
- const cellsMap = yMxGraphModel.get(key$3);
345
- const orderArr = yMxGraphModel.get(mxCellOrderKey);
178
+ const cellsMap = yMxGraphModel.get(transformer.key$3);
179
+ const orderArr = yMxGraphModel.get(transformer.mxCellOrderKey);
346
180
  if (!cellsMap || !orderArr) return;
347
181
  ensureUniqueOrder(orderArr);
348
182
  if (update.cells[DIFF_REMOVE] && update.cells[DIFF_REMOVE].length) {
@@ -358,9 +192,9 @@ function applyFilePatch(doc, patch, options) {
358
192
  const id2 = item["id"];
359
193
  if (!id2) continue;
360
194
  const xmlElement = new Y__namespace.XmlElement("mxCell");
361
- Object.keys(item).forEach((key2) => {
362
- if (key2 === "previous") return;
363
- xmlElement.setAttribute(key2, item[key2]);
195
+ Object.keys(item).forEach((key) => {
196
+ if (key === "previous") return;
197
+ xmlElement.setAttribute(key, item[key]);
364
198
  });
365
199
  cellsMap.set(id2, xmlElement);
366
200
  const previous = item["previous"];
@@ -462,7 +296,7 @@ function applyFilePatch(doc, patch, options) {
462
296
  if ("previous" in update) {
463
297
  const previous = update.previous || null;
464
298
  const orderArr = mxfile.get(
465
- diagramOrderKey
299
+ transformer.diagramOrderKey
466
300
  );
467
301
  ensureUniqueOrder(orderArr);
468
302
  insertAfterUnique(orderArr, id, previous, false);
@@ -474,9 +308,9 @@ function applyFilePatch(doc, patch, options) {
474
308
  }
475
309
  function initDocSnapshot(doc, resetSnapshot = false) {
476
310
  try {
477
- const mxfile = doc.getMap(key);
478
- const diagramsMap = mxfile.get(key$1);
479
- const orderArr = mxfile.get(diagramOrderKey);
311
+ const mxfile = doc.getMap(transformer.key);
312
+ const diagramsMap = mxfile.get(transformer.key$1);
313
+ const orderArr = mxfile.get(transformer.diagramOrderKey);
480
314
  const orderIds = orderArr ? orderArr.toArray() : [];
481
315
  const allDiagramIds = orderIds.length > 0 ? orderIds : diagramsMap ? Array.from(diagramsMap.keys()) : [];
482
316
  const diagramOrder = resetSnapshot ? [] : allDiagramIds.slice();
@@ -489,12 +323,12 @@ function initDocSnapshot(doc, resetSnapshot = false) {
489
323
  for (const d of diagrams) {
490
324
  const did = d.get("id") || "";
491
325
  if (!did) continue;
492
- const gm = d.get(key$2);
326
+ const gm = d.get(transformer.key$2);
493
327
  if (gm) {
494
- const order = gm.get(mxCellOrderKey);
328
+ const order = gm.get(transformer.mxCellOrderKey);
495
329
  const ids = order ? order.toArray().slice() : [];
496
330
  snap.cellsOrder.set(did, ids);
497
- const cellsMap = gm.get(key$3);
331
+ const cellsMap = gm.get(transformer.key$3);
498
332
  const attrMap = /* @__PURE__ */ new Map();
499
333
  if (cellsMap) {
500
334
  for (const cid of ids) {
@@ -519,14 +353,14 @@ function initDocSnapshot(doc, resetSnapshot = false) {
519
353
  }
520
354
  }
521
355
  function generatePatch(events, explicitDoc) {
522
- var _a, _b;
356
+ var _a, _b, _c, _d, _e;
523
357
  const patch = {};
524
358
  const doc = (_b = (_a = events[0]) == null ? void 0 : _a.transaction) == null ? void 0 : _b.doc;
525
359
  if (!doc) return patch;
526
360
  if (!events || events.length === 0) return patch;
527
- const mxfile = doc.getMap(key);
528
- const diagramsMap = mxfile.get(key$1);
529
- const orderArr = mxfile.get(diagramOrderKey);
361
+ const mxfile = doc.getMap(transformer.key);
362
+ const diagramsMap = mxfile.get(transformer.key$1);
363
+ const orderArr = mxfile.get(transformer.diagramOrderKey);
530
364
  let snap = docSnapshots.get(doc);
531
365
  if (!snap) {
532
366
  snap = {
@@ -549,7 +383,7 @@ function generatePatch(events, explicitDoc) {
549
383
  u.cells = u.cells || {};
550
384
  return u.cells;
551
385
  };
552
- const orderIds = (orderArr == null ? void 0 : orderArr.toArray()) ?? [];
386
+ const orderIds = (_c = orderArr == null ? void 0 : orderArr.toArray()) != null ? _c : [];
553
387
  const currDiagramOrder = orderIds.length > 0 ? orderIds : diagramsMap ? Array.from(diagramsMap.keys()) : [];
554
388
  const diagramsList = currDiagramOrder.map((id) => diagramsMap.get(id)).filter((d) => !!d);
555
389
  const currCellsOrder = /* @__PURE__ */ new Map();
@@ -557,10 +391,10 @@ function generatePatch(events, explicitDoc) {
557
391
  for (const d of diagramsList) {
558
392
  const did = d.get("id") || "";
559
393
  const attrs = /* @__PURE__ */ new Map();
560
- const gm = d.get(key$2);
394
+ const gm = d.get(transformer.key$2);
561
395
  if (gm) {
562
- const cellsMap = gm.get(key$3);
563
- const orderArr2 = gm.get(mxCellOrderKey);
396
+ const cellsMap = gm.get(transformer.key$3);
397
+ const orderArr2 = gm.get(transformer.mxCellOrderKey);
564
398
  if (cellsMap && orderArr2) {
565
399
  const ids = orderArr2.toArray();
566
400
  currCellsOrder.set(did, ids);
@@ -597,7 +431,7 @@ function generatePatch(events, explicitDoc) {
597
431
  const previous = index <= 0 ? "" : currDiagramOrder[index - 1];
598
432
  const yDiagram = diagramsMap.get(id);
599
433
  if (!yDiagram) continue;
600
- const data = serializer$1({ diagram: serialize(yDiagram) });
434
+ const data = transformer.serializer({ diagram: transformer.serialize(yDiagram) });
601
435
  patch[DIFF_INSERT].push({ id, previous, data });
602
436
  insertedDiagramIdGlobal.add(id);
603
437
  }
@@ -645,10 +479,9 @@ function generatePatch(events, explicitDoc) {
645
479
  const attrs = attrsMap.get(cid) || {};
646
480
  const index = currCells.indexOf(cid);
647
481
  const previous = index <= 0 ? "" : currCells[index - 1];
648
- cells[DIFF_INSERT].push({
649
- ...attrs,
482
+ cells[DIFF_INSERT].push(__spreadProps(__spreadValues$1({}, attrs), {
650
483
  previous
651
- });
484
+ }));
652
485
  insertedCellIdGlobal.add(cid);
653
486
  }
654
487
  }
@@ -714,8 +547,8 @@ function generatePatch(events, explicitDoc) {
714
547
  const cellsPatch = ensureCellSection(diagramId);
715
548
  cellsPatch[DIFF_UPDATE] = cellsPatch[DIFF_UPDATE] || {};
716
549
  const cellUpdate = cellsPatch[DIFF_UPDATE][cellId] = cellsPatch[DIFF_UPDATE][cellId] || {};
717
- for (const key2 of Array.from(changed)) {
718
- cellUpdate[key2] = el.getAttribute(key2) || "";
550
+ for (const key of Array.from(changed)) {
551
+ cellUpdate[key] = el.getAttribute(key) || "";
719
552
  }
720
553
  }
721
554
  if (prevDiagramOrder) {
@@ -736,8 +569,8 @@ function generatePatch(events, explicitDoc) {
736
569
  const cellUpdate = updateBucket[cid] = updateBucket[cid] || {};
737
570
  let changed = false;
738
571
  for (const k of keys) {
739
- const pv = prevAttrs[k] ?? "";
740
- const cv = currAttrs[k] ?? "";
572
+ const pv = (_d = prevAttrs[k]) != null ? _d : "";
573
+ const cv = (_e = currAttrs[k]) != null ? _e : "";
741
574
  if (pv !== cv) {
742
575
  cellUpdate[k] = cv;
743
576
  changed = true;
@@ -760,7 +593,7 @@ function generatePatch(events, explicitDoc) {
760
593
  for (const [did, attrsMap] of cellAttrMap.entries()) {
761
594
  const copy = /* @__PURE__ */ new Map();
762
595
  for (const [cid, attrs] of attrsMap.entries()) {
763
- copy.set(cid, { ...attrs });
596
+ copy.set(cid, __spreadValues$1({}, attrs));
764
597
  }
765
598
  newCellsAttrs.set(did, copy);
766
599
  }
@@ -769,45 +602,6 @@ function generatePatch(events, explicitDoc) {
769
602
  docSnapshots.set(doc, snap);
770
603
  return patch;
771
604
  }
772
- function xml2ydoc(xml, doc) {
773
- const object = parse$4(xml);
774
- const mxfile = object.mxfile;
775
- const mxGraphModel = object.mxGraphModel;
776
- if (mxfile) {
777
- doc.transact(() => {
778
- parse(mxfile, doc);
779
- });
780
- } else if (mxGraphModel) {
781
- doc.transact(() => {
782
- parse$2(mxGraphModel, doc);
783
- });
784
- } else {
785
- throw new Error("不支持的文件格式");
786
- }
787
- return doc;
788
- }
789
- function ydoc2xml(doc, spaces = 0) {
790
- if (doc.share.has(key)) {
791
- return serializer$1(
792
- {
793
- [key]: serializer(
794
- doc.share.get(key)
795
- )
796
- },
797
- spaces
798
- );
799
- } else if (doc.share.has(key$2)) {
800
- return serializer$1(
801
- {
802
- [key$2]: serialize$1(
803
- doc.share.get(key$2)
804
- )
805
- },
806
- spaces
807
- );
808
- }
809
- return "";
810
- }
811
605
  const LOCAL_ORIGIN = {};
812
606
  function createMxEventObject(name, props) {
813
607
  const _props = props || {};
@@ -832,9 +626,9 @@ function bindUndoManager(doc, file, yUndo) {
832
626
  const pairs = [];
833
627
  const raw = Array.isArray(originUndoManager == null ? void 0 : originUndoManager.eventListeners) ? originUndoManager.eventListeners : [];
834
628
  for (let i = 0; i + 1 < raw.length; i += 2) {
835
- const key2 = String(raw[i]);
629
+ const key = String(raw[i]);
836
630
  const fn = raw[i + 1];
837
- pairs.push([key2, fn]);
631
+ pairs.push([key, fn]);
838
632
  }
839
633
  const mxLike = {
840
634
  eventListeners: [],
@@ -845,12 +639,12 @@ function bindUndoManager(doc, file, yUndo) {
845
639
  this.eventListeners.push(name, fn);
846
640
  },
847
641
  fireEvent(evt) {
848
- var _a;
849
- const eventName = (evt == null ? void 0 : evt.name) || (((_a = evt == null ? void 0 : evt.getName) == null ? void 0 : _a.call(evt)) ?? "");
642
+ var _a, _b;
643
+ const eventName = (evt == null ? void 0 : evt.name) || ((_b = (_a = evt == null ? void 0 : evt.getName) == null ? void 0 : _a.call(evt)) != null ? _b : "");
850
644
  for (let i = 0; i + 1 < this.eventListeners.length; i += 2) {
851
- const key2 = this.eventListeners[i];
645
+ const key = this.eventListeners[i];
852
646
  const listener = this.eventListeners[i + 1];
853
- if (key2 === eventName) {
647
+ if (key === eventName) {
854
648
  try {
855
649
  listener(this, evt);
856
650
  } catch (e) {
@@ -936,8 +730,8 @@ function bindUndoManager(doc, file, yUndo) {
936
730
  mxLike.fireEvent(evt);
937
731
  };
938
732
  yUndo.on("stack-item-updated", updatedHandler);
939
- pairs.forEach(([key2, fn]) => {
940
- const k = key2.toLowerCase();
733
+ pairs.forEach(([key, fn]) => {
734
+ const k = key.toLowerCase();
941
735
  if (k === "add" || k === "clear" || k === "undo" || k === "redo") {
942
736
  mxLike.addListener(k, fn);
943
737
  }
@@ -958,56 +752,72 @@ function bindUndoManager(doc, file, yUndo) {
958
752
  };
959
753
  return destroy;
960
754
  }
961
- function getAwarenessStateValue(awareness, key2, clientId) {
755
+ var __defProp = Object.defineProperty;
756
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
757
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
758
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
759
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
760
+ var __spreadValues = (a, b) => {
761
+ for (var prop in b || (b = {}))
762
+ if (__hasOwnProp.call(b, prop))
763
+ __defNormalProp(a, prop, b[prop]);
764
+ if (__getOwnPropSymbols)
765
+ for (var prop of __getOwnPropSymbols(b)) {
766
+ if (__propIsEnum.call(b, prop))
767
+ __defNormalProp(a, prop, b[prop]);
768
+ }
769
+ return a;
770
+ };
771
+ function getAwarenessStateValue(awareness, key, clientId) {
962
772
  const states = awareness.getStates();
963
773
  const id = clientId != null ? Number(clientId) : awareness.clientID;
964
774
  const clientState = states.get(id);
965
775
  if (!clientState) return null;
966
- if (!key2) return clientState;
967
- return getByPath(clientState, key2);
776
+ if (!key) return clientState;
777
+ return getByPath(clientState, key);
968
778
  }
969
779
  function getByPath(obj, path) {
970
780
  const parts = path.split(".");
971
781
  let cur = obj;
972
782
  for (const part of parts) {
973
783
  if (cur == null) return null;
974
- const key2 = Array.isArray(cur) && /^\d+$/.test(part) ? Number(part) : part;
975
- cur = cur == null ? void 0 : cur[key2];
784
+ const key = Array.isArray(cur) && /^\d+$/.test(part) ? Number(part) : part;
785
+ cur = cur == null ? void 0 : cur[key];
976
786
  }
977
787
  return cur;
978
788
  }
979
- function setAwarenessStateValue(awareness, key2, value, clientId) {
789
+ function setAwarenessStateValue(awareness, key, value, clientId) {
980
790
  const id = awareness.clientID;
981
791
  if (id !== awareness.clientID) return false;
982
- if (!key2) {
792
+ if (!key) {
983
793
  awareness.setLocalState(value);
984
794
  return true;
985
795
  }
986
796
  const current = awareness.getLocalState() || {};
987
- const next = setByPath(current, key2, value);
797
+ const next = setByPath(current, key, value);
988
798
  awareness.setLocalState(next);
989
799
  return true;
990
800
  }
991
801
  function setByPath(obj, path, value) {
992
802
  const parts = path.split(".");
993
- const root = Array.isArray(obj) ? obj.slice() : { ...obj };
803
+ const root = Array.isArray(obj) ? obj.slice() : __spreadValues({}, obj);
994
804
  let cur = root;
995
805
  for (let i = 0; i < parts.length; i++) {
996
806
  const part = parts[i];
997
807
  const isIndex = /^\d+$/.test(part);
998
- const key2 = isIndex ? Number(part) : part;
808
+ const key = isIndex ? Number(part) : part;
999
809
  const isLast = i === parts.length - 1;
1000
810
  if (isLast) {
1001
- cur[key2] = value;
811
+ cur[key] = value;
1002
812
  } else {
1003
- let next = cur[key2];
813
+ let next = cur[key];
1004
814
  const nextIsIndex = /^\d+$/.test(parts[i + 1]);
1005
815
  if (next == null) {
1006
816
  next = nextIsIndex ? [] : {};
1007
817
  } else {
1008
- next = Array.isArray(next) ? next.slice() : { ...next };
818
+ next = Array.isArray(next) ? next.slice() : __spreadValues({}, next);
1009
819
  }
1010
- cur[key2] = next;
820
+ cur[key] = next;
1011
821
  cur = next;
1012
822
  }
1013
823
  }
@@ -1131,9 +941,10 @@ function createCursorEl(color, username) {
1131
941
  return cursor;
1132
942
  }
1133
943
  function bindCursor(file, options) {
944
+ var _a;
1134
945
  const graph = options.graph || file.getUi().editor.graph;
1135
946
  const awareness = options.awareness;
1136
- const mouseMoveThrottle = options.mouseMoveThrottle ?? 100;
947
+ const mouseMoveThrottle = (_a = options.mouseMoveThrottle) != null ? _a : 100;
1137
948
  const listener = {
1138
949
  startX: 0,
1139
950
  startY: 0,
@@ -1144,7 +955,7 @@ function bindCursor(file, options) {
1144
955
  mouseUp: function() {
1145
956
  },
1146
957
  mouseMove: throttle(function(_sender, event) {
1147
- var _a;
958
+ var _a2;
1148
959
  const containerRect = graph.container.getBoundingClientRect();
1149
960
  const { translate, scale } = graph.view;
1150
961
  const x = Math.round(
@@ -1156,17 +967,17 @@ function bindCursor(file, options) {
1156
967
  awareness.setLocalStateField("cursor", {
1157
968
  x,
1158
969
  y,
1159
- pageId: (_a = file.getUi().currentPage) == null ? void 0 : _a.getId()
970
+ pageId: (_a2 = file.getUi().currentPage) == null ? void 0 : _a2.getId()
1160
971
  });
1161
972
  }, mouseMoveThrottle)
1162
973
  };
1163
974
  graph.addMouseListener(listener);
1164
975
  const handleMouseLeave = () => {
1165
- var _a;
976
+ var _a2;
1166
977
  awareness.setLocalStateField("cursor", {
1167
978
  x: 0,
1168
979
  y: 0,
1169
- pageId: (_a = file.getUi().currentPage) == null ? void 0 : _a.getId(),
980
+ pageId: (_a2 = file.getUi().currentPage) == null ? void 0 : _a2.getId(),
1170
981
  hide: true
1171
982
  });
1172
983
  };
@@ -1269,7 +1080,7 @@ function bindSelection(file, options) {
1269
1080
  const cells = graph.getSelectionModel().cells;
1270
1081
  const ids = Object.keys(cells || {}).map(
1271
1082
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1272
- (key2) => getId(cells[key2])
1083
+ (key) => getId(cells[key])
1273
1084
  ).filter(Boolean);
1274
1085
  awareness.setLocalStateField("selection", { ids, pageId });
1275
1086
  };
@@ -1320,16 +1131,17 @@ function renderRemoteSelections(ui, remotes) {
1320
1131
  if (!currentPageRemotes.length) return;
1321
1132
  const graph = ui.editor.graph;
1322
1133
  currentPageRemotes.forEach(({ clientId, selectionState, userColor }) => {
1134
+ var _a2;
1323
1135
  let highlightCellMap = cache.get(clientId);
1324
1136
  if (!highlightCellMap) {
1325
1137
  highlightCellMap = /* @__PURE__ */ new Map();
1326
1138
  cache.set(clientId, highlightCellMap);
1327
1139
  }
1328
- const currentIds = new Set((selectionState == null ? void 0 : selectionState.ids) ?? []);
1140
+ const currentIds = new Set((_a2 = selectionState == null ? void 0 : selectionState.ids) != null ? _a2 : []);
1329
1141
  Array.from(highlightCellMap.keys()).forEach((id) => {
1330
- var _a2;
1142
+ var _a3;
1331
1143
  if (!currentIds.has(id)) {
1332
- (_a2 = highlightCellMap.get(id)) == null ? void 0 : _a2.destroy();
1144
+ (_a3 = highlightCellMap.get(id)) == null ? void 0 : _a3.destroy();
1333
1145
  highlightCellMap.delete(id);
1334
1146
  }
1335
1147
  });
@@ -1352,9 +1164,10 @@ function renderRemoteSelections(ui, remotes) {
1352
1164
  const DEFAULT_USER_NAME_KEY = "user.name";
1353
1165
  const DEFAULT_USER_COLOR_KEY = "user.color";
1354
1166
  function bindCollaborator(file, options) {
1167
+ var _a, _b;
1355
1168
  const graph = options.graph || file.getUi().editor.graph;
1356
1169
  const awareness = options.awareness;
1357
- const mouseMoveThrottle = options.mouseMoveThrottle ?? 100;
1170
+ const mouseMoveThrottle = (_a = options.mouseMoveThrottle) != null ? _a : 100;
1358
1171
  const cursorOption = options.cursor;
1359
1172
  const userNameKey = typeof cursorOption === "object" && (cursorOption == null ? void 0 : cursorOption.userNameKey) ? cursorOption.userNameKey : DEFAULT_USER_NAME_KEY;
1360
1173
  const userColorKey = typeof cursorOption === "object" && (cursorOption == null ? void 0 : cursorOption.userColorKey) ? cursorOption.userColorKey : DEFAULT_USER_COLOR_KEY;
@@ -1377,7 +1190,7 @@ function bindCollaborator(file, options) {
1377
1190
  awareness,
1378
1191
  graph
1379
1192
  });
1380
- const showCursor = options.cursor ?? true;
1193
+ const showCursor = (_b = options.cursor) != null ? _b : true;
1381
1194
  let cleanupAwareness;
1382
1195
  if (typeof showCursor === "boolean" && showCursor) {
1383
1196
  const awarenessHandler = (update) => {
@@ -1423,7 +1236,7 @@ const defaultApplyFileData = (file, xml) => {
1423
1236
  function mergeFileIntoDoc(doc, fileXml, strategy) {
1424
1237
  let parsed;
1425
1238
  try {
1426
- parsed = parse$4(fileXml);
1239
+ parsed = transformer.parse(fileXml);
1427
1240
  } catch (err) {
1428
1241
  console.warn(
1429
1242
  "[y-mxgraph] 合并失败,file XML 解析异常,回退到 replace:",
@@ -1438,9 +1251,9 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
1438
1251
  );
1439
1252
  return false;
1440
1253
  }
1441
- const mxfileMap = doc.getMap(key);
1442
- const diagramMap = mxfileMap.get(key$1);
1443
- const diagramOrder = mxfileMap.get(diagramOrderKey);
1254
+ const mxfileMap = doc.getMap(transformer.key);
1255
+ const diagramMap = mxfileMap.get(transformer.key$1);
1256
+ const diagramOrder = mxfileMap.get(transformer.diagramOrderKey);
1444
1257
  if (!diagramMap || !diagramOrder) {
1445
1258
  console.warn("[y-mxgraph] 合并失败,doc 结构不完整,回退到 replace");
1446
1259
  return false;
@@ -1454,7 +1267,7 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
1454
1267
  if (docHas && strategy === "merge-remote") {
1455
1268
  continue;
1456
1269
  }
1457
- const yDiagram = parse$1(
1270
+ const yDiagram = transformer.parse$1(
1458
1271
  diagram
1459
1272
  );
1460
1273
  diagramMap.set(id, yDiagram);
@@ -1466,13 +1279,13 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
1466
1279
  return true;
1467
1280
  }
1468
1281
  function reconcileInitialContent(doc, file, strategy, applyFileData) {
1469
- const mxfileMap = doc.getMap(key);
1282
+ const mxfileMap = doc.getMap(transformer.key);
1470
1283
  const docHasData = mxfileMap.size > 0;
1471
1284
  const fileHasAnyData = !!file.data;
1472
1285
  const fileHasDiagrams = fileHasAnyData && file.data.includes("<diagram");
1473
1286
  if (strategy === "replace") {
1474
1287
  if (docHasData) {
1475
- const xml2 = ydoc2xml(doc);
1288
+ const xml2 = transformer.ydoc2xml(doc);
1476
1289
  if (xml2 && xml2.includes("<diagram")) {
1477
1290
  applyFileData(file, xml2);
1478
1291
  } else if (!fileHasAnyData) {
@@ -1492,7 +1305,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
1492
1305
  if (!docHasData && fileHasDiagrams) {
1493
1306
  try {
1494
1307
  doc.transact(() => {
1495
- xml2ydoc(file.data, doc);
1308
+ transformer.xml2ydoc(file.data, doc);
1496
1309
  });
1497
1310
  return true;
1498
1311
  } catch (err) {
@@ -1505,7 +1318,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
1505
1318
  }
1506
1319
  }
1507
1320
  if (docHasData && !fileHasDiagrams) {
1508
- const xml2 = ydoc2xml(doc);
1321
+ const xml2 = transformer.ydoc2xml(doc);
1509
1322
  if (xml2 && xml2.includes("<diagram")) {
1510
1323
  applyFileData(file, xml2);
1511
1324
  } else if (!fileHasAnyData) {
@@ -1515,11 +1328,11 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
1515
1328
  }
1516
1329
  const ok = mergeFileIntoDoc(doc, file.data, strategy);
1517
1330
  if (!ok) {
1518
- const xml2 = ydoc2xml(doc);
1331
+ const xml2 = transformer.ydoc2xml(doc);
1519
1332
  if (xml2 && xml2.includes("<diagram")) applyFileData(file, xml2);
1520
1333
  return mxfileMap.size > 0;
1521
1334
  }
1522
- const xml = ydoc2xml(doc);
1335
+ const xml = transformer.ydoc2xml(doc);
1523
1336
  if (xml && xml.includes("<diagram")) applyFileData(file, xml);
1524
1337
  return true;
1525
1338
  }
@@ -1573,7 +1386,7 @@ class Binding {
1573
1386
  if (patchKeys.length === 0) return;
1574
1387
  if (!this.docInitialized) {
1575
1388
  doc.transact(() => {
1576
- xml2ydoc(file.data, doc);
1389
+ transformer.xml2ydoc(file.data, doc);
1577
1390
  initDocSnapshot(doc, false);
1578
1391
  });
1579
1392
  this.docInitialized = true;
@@ -1589,10 +1402,10 @@ class Binding {
1589
1402
  return;
1590
1403
  }
1591
1404
  if (this.shouldReplaceWhenDocHasData && !transaction.local) {
1592
- const mxfileMap = doc.getMap(key);
1593
- const diagramMap = mxfileMap.get(key$1);
1405
+ const mxfileMap = doc.getMap(transformer.key);
1406
+ const diagramMap = mxfileMap.get(transformer.key$1);
1594
1407
  if (diagramMap && diagramMap.size > 0) {
1595
- const xml = ydoc2xml(doc);
1408
+ const xml = transformer.ydoc2xml(doc);
1596
1409
  if (xml && xml.includes("<diagram")) {
1597
1410
  this.suppressLocalApply = true;
1598
1411
  try {
@@ -1622,12 +1435,12 @@ class Binding {
1622
1435
  this.suppressLocalApply = false;
1623
1436
  }
1624
1437
  };
1625
- doc.getMap(key).observeDeep(this.docObserver);
1438
+ doc.getMap(transformer.key).observeDeep(this.docObserver);
1626
1439
  if (awareness) {
1627
1440
  this.cleanupCollaborator = bindCollaborator(file, {
1628
1441
  awareness,
1629
1442
  graph,
1630
- cursor: cursor ?? true,
1443
+ cursor: cursor != null ? cursor : true,
1631
1444
  mouseMoveThrottle
1632
1445
  });
1633
1446
  }
@@ -1657,7 +1470,7 @@ class Binding {
1657
1470
  destroy(deep = false) {
1658
1471
  var _a, _b;
1659
1472
  this.mxGraphModel.removeListener("change", this.mxListener);
1660
- this.doc.getMap(key).unobserveDeep(this.docObserver);
1473
+ this.doc.getMap(transformer.key).unobserveDeep(this.docObserver);
1661
1474
  if (deep) {
1662
1475
  (_a = this.cleanupCollaborator) == null ? void 0 : _a.call(this);
1663
1476
  (_b = this.cleanupUndoManager) == null ? void 0 : _b.call(this);
@@ -1698,10 +1511,10 @@ class Binding {
1698
1511
  return new Binding(file, options);
1699
1512
  }
1700
1513
  }
1514
+ exports.xml2ydoc = transformer.xml2ydoc;
1515
+ exports.ydoc2xml = transformer.ydoc2xml;
1701
1516
  exports.Binding = Binding;
1702
1517
  exports.DEFAULT_USER_COLOR_KEY = DEFAULT_USER_COLOR_KEY;
1703
1518
  exports.DEFAULT_USER_NAME_KEY = DEFAULT_USER_NAME_KEY;
1704
1519
  exports.LOCAL_ORIGIN = LOCAL_ORIGIN;
1705
- exports.xml2ydoc = xml2ydoc;
1706
- exports.ydoc2xml = ydoc2xml;
1707
- //# sourceMappingURL=y-mxgraph.cjs.js.map
1520
+ //# sourceMappingURL=y-mxgraph.cjs.map