y-mxgraph 0.5.3 → 0.5.7

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,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const xmlJs = require("xml-js");
3
+ const transformer = require("./index-Dpa3-atS.cjs");
4
4
  const Y = require("yjs");
5
- const lodashEs = require("lodash-es");
6
5
  const colord = require("colord");
7
6
  function _interopNamespaceDefault(e) {
8
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -21,191 +20,6 @@ function _interopNamespaceDefault(e) {
21
20
  return Object.freeze(n);
22
21
  }
23
22
  const Y__namespace = /* @__PURE__ */ _interopNamespaceDefault(Y);
24
- function deepProcess(node) {
25
- if (node == null) return;
26
- if (Array.isArray(node)) {
27
- for (const item of node) {
28
- deepProcess(item);
29
- }
30
- return;
31
- }
32
- if (typeof node !== "object") return;
33
- const obj = node;
34
- const keys = Object.keys(obj);
35
- for (const key2 of keys) {
36
- if (key2 === "_attributes") continue;
37
- let value = obj[key2];
38
- const keyLower = key2.toLowerCase();
39
- if ((keyLower === "diagram" || keyLower === "mxcell") && value !== void 0 && !Array.isArray(value)) {
40
- obj[key2] = [value];
41
- value = obj[key2];
42
- }
43
- if (Array.isArray(value)) {
44
- for (const v of value) deepProcess(v);
45
- } else if (value && typeof value === "object") {
46
- deepProcess(value);
47
- }
48
- }
49
- }
50
- function parse$4(xml) {
51
- const result = xmlJs.xml2js(xml, { compact: true });
52
- deepProcess(result);
53
- return result;
54
- }
55
- function serializer$1(obj, spaces = 2) {
56
- return xmlJs.js2xml(obj, {
57
- compact: true,
58
- spaces
59
- });
60
- }
61
- const key$3 = "mxCell";
62
- const mxGeometryKey = "mxGeometry";
63
- const mxGeometryAttributeKey = "geometry";
64
- function parse$3(object) {
65
- var _a;
66
- const xmlElement = new Y__namespace.XmlElement("mxCell");
67
- for (const attribute of Object.keys(object._attributes || {})) {
68
- xmlElement.setAttribute(
69
- attribute,
70
- `${((_a = object._attributes) == null ? void 0 : _a[attribute]) || ""}`
71
- );
72
- }
73
- if (object[mxGeometryKey]) {
74
- const geometry = object[mxGeometryKey];
75
- const geometryString = xmlJs.js2xml(geometry, {
76
- compact: true
77
- });
78
- xmlElement.setAttribute(mxGeometryAttributeKey, geometryString);
79
- delete object[mxGeometryKey];
80
- }
81
- return xmlElement;
82
- }
83
- function serialize$2(xmlElement) {
84
- const rawAttributes = {
85
- ...xmlElement.getAttributes()
86
- };
87
- let mxGeometry = null;
88
- let mxGeometryString;
89
- if (mxGeometryAttributeKey in rawAttributes) {
90
- mxGeometryString = rawAttributes[mxGeometryAttributeKey];
91
- delete rawAttributes[mxGeometryAttributeKey];
92
- }
93
- const attributes = {};
94
- for (const [key2, value] of Object.entries(rawAttributes)) {
95
- if (typeof value === "string") {
96
- attributes[key2] = value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
97
- } else if (value != null) {
98
- attributes[key2] = String(value);
99
- }
100
- }
101
- if (mxGeometryString) {
102
- try {
103
- const parsed = xmlJs.xml2js(mxGeometryString, { compact: true });
104
- mxGeometry = parsed[mxGeometryKey] ?? null;
105
- if (mxGeometry && mxGeometry._attributes) {
106
- mxGeometry._attributes["as"] = "geometry";
107
- }
108
- } catch (e) {
109
- console.warn("[y-mxgraph] Failed to parse mxGeometry:", e);
110
- }
111
- }
112
- const obj = {
113
- _attributes: attributes
114
- };
115
- if (mxGeometry) {
116
- obj[mxGeometryKey] = mxGeometry;
117
- }
118
- return obj;
119
- }
120
- const key$2 = "mxGraphModel";
121
- const mxCellOrderKey = key$3 + "Order";
122
- function parse$2(object, doc) {
123
- const mxCells = (object.root[key$3] || []).map((cell) => {
124
- var _a;
125
- return {
126
- value: parse$3(cell),
127
- id: ((_a = cell._attributes) == null ? void 0 : _a.id) || ""
128
- };
129
- });
130
- const mxGraphElement = (doc == null ? void 0 : doc.getMap(key$2)) || new Y__namespace.Map();
131
- const cells = new Y__namespace.Map();
132
- const cellsOrder = new Y__namespace.Array();
133
- mxCells.forEach((cell) => {
134
- cells.set(cell.id, cell.value);
135
- });
136
- cellsOrder.push(mxCells.map((cell) => cell.id));
137
- mxGraphElement.set(key$3, cells);
138
- mxGraphElement.set(mxCellOrderKey, cellsOrder);
139
- return mxGraphElement;
140
- }
141
- function serialize$1(map) {
142
- const cells = map.get(key$3);
143
- const cellsOrder = map.get(mxCellOrderKey);
144
- return {
145
- _attributes: {},
146
- root: {
147
- [key$3]: cellsOrder.toArray().map((id) => serialize$2(cells.get(id)))
148
- }
149
- };
150
- }
151
- const key$1 = "diagram";
152
- function parse$1(object) {
153
- var _a, _b;
154
- const yDiagramElement = new Y__namespace.Map();
155
- yDiagramElement.set("name", `${((_a = object._attributes) == null ? void 0 : _a.name) || ""}`);
156
- yDiagramElement.set("id", `${((_b = object._attributes) == null ? void 0 : _b.id) || ""}`);
157
- const mxGraphModel = parse$2(object[key$2]);
158
- yDiagramElement.set(key$2, mxGraphModel);
159
- return yDiagramElement;
160
- }
161
- function serialize(yDiagram) {
162
- const mxGraphModel = yDiagram.get(key$2);
163
- return {
164
- _attributes: {
165
- name: yDiagram.get("name"),
166
- id: yDiagram.get("id")
167
- },
168
- [key$2]: mxGraphModel ? serialize$1(mxGraphModel) : void 0
169
- };
170
- }
171
- const key = "mxfile";
172
- const diagramOrderKey = key$1 + "Order";
173
- function parse(object, doc) {
174
- var _a;
175
- const mxfile = doc.getMap(key);
176
- mxfile.set("pages", (((_a = object._attributes) == null ? void 0 : _a.pages) || "1") + "");
177
- const diagramList = object.diagram.map((diagram) => {
178
- var _a2;
179
- return {
180
- value: parse$1(diagram),
181
- id: ((_a2 = diagram._attributes) == null ? void 0 : _a2.id) || ""
182
- };
183
- });
184
- const diagramMap = new Y__namespace.Map();
185
- const diagramOrder = new Y__namespace.Array();
186
- diagramList.forEach((diagram) => {
187
- diagramMap.set(diagram.id, diagram.value);
188
- });
189
- diagramOrder.push(diagramList.map((diagram) => diagram.id));
190
- mxfile.set(key$1, diagramMap);
191
- mxfile.set(diagramOrderKey, diagramOrder);
192
- return mxfile;
193
- }
194
- function serializer(yMxFile) {
195
- const diagrams = yMxFile.get(key$1);
196
- const diagramOrder = yMxFile.get(
197
- diagramOrderKey
198
- );
199
- const orderIds = diagramOrder ? diagramOrder.toArray() : [];
200
- const ids = orderIds.length > 0 ? orderIds : diagrams ? Array.from(diagrams.keys()) : [];
201
- const obj = {
202
- _attributes: {
203
- pages: yMxFile.get("pages") || "1"
204
- },
205
- [key$1]: ids.map((id) => diagrams.get(id)).filter((d) => !!d).map((diagramElement) => serialize(diagramElement))
206
- };
207
- return obj;
208
- }
209
23
  const DIFF_INSERT = "i";
210
24
  const DIFF_REMOVE = "r";
211
25
  const DIFF_UPDATE = "u";
@@ -241,11 +55,11 @@ function ensureUniqueOrder(orderArr) {
241
55
  }
242
56
  function applyFilePatch(doc, patch, options) {
243
57
  doc.transact(() => {
244
- const mxfile = doc.getMap(key);
58
+ const mxfile = doc.getMap(transformer.key);
245
59
  if (patch[DIFF_REMOVE]) {
246
- const diagramsMap = mxfile.get(key$1);
60
+ const diagramsMap = mxfile.get(transformer.key$1);
247
61
  const orderArr = mxfile.get(
248
- diagramOrderKey
62
+ transformer.diagramOrderKey
249
63
  );
250
64
  ensureUniqueOrder(orderArr);
251
65
  const orderList = orderArr.toArray();
@@ -257,9 +71,9 @@ function applyFilePatch(doc, patch, options) {
257
71
  }
258
72
  }
259
73
  if (patch[DIFF_INSERT]) {
260
- const diagramsMap = mxfile.get(key$1);
74
+ const diagramsMap = mxfile.get(transformer.key$1);
261
75
  const orderArr = mxfile.get(
262
- diagramOrderKey
76
+ transformer.diagramOrderKey
263
77
  );
264
78
  ensureUniqueOrder(orderArr);
265
79
  const currentOrder = orderArr.toArray();
@@ -272,9 +86,9 @@ function applyFilePatch(doc, patch, options) {
272
86
  const existingIndex = /* @__PURE__ */ new Map();
273
87
  existingIds.forEach((id, idx) => existingIndex.set(id, idx));
274
88
  const inserts = patch[DIFF_INSERT].map((item, order) => {
275
- const object = parse$4(item.data);
89
+ const object = transformer.parse(item.data);
276
90
  const diagramObj = Array.isArray(object == null ? void 0 : object.diagram) ? object.diagram[0] : object == null ? void 0 : object.diagram;
277
- const diagramElement = parse$1(
91
+ const diagramElement = transformer.parse$1(
278
92
  diagramObj
279
93
  );
280
94
  return {
@@ -328,7 +142,7 @@ function applyFilePatch(doc, patch, options) {
328
142
  if (patch[DIFF_UPDATE]) {
329
143
  Object.keys(patch[DIFF_UPDATE]).forEach((id) => {
330
144
  const diagramsMap = mxfile.get(
331
- key$1
145
+ transformer.key$1
332
146
  );
333
147
  const diagram = diagramsMap.get(id);
334
148
  if (diagram) {
@@ -340,10 +154,10 @@ function applyFilePatch(doc, patch, options) {
340
154
  );
341
155
  }
342
156
  if (update.cells) {
343
- const yMxGraphModel = diagram.get(key$2);
157
+ const yMxGraphModel = diagram.get(transformer.key$2);
344
158
  if (!yMxGraphModel) return;
345
- const cellsMap = yMxGraphModel.get(key$3);
346
- const orderArr = yMxGraphModel.get(mxCellOrderKey);
159
+ const cellsMap = yMxGraphModel.get(transformer.key$3);
160
+ const orderArr = yMxGraphModel.get(transformer.mxCellOrderKey);
347
161
  if (!cellsMap || !orderArr) return;
348
162
  ensureUniqueOrder(orderArr);
349
163
  if (update.cells[DIFF_REMOVE] && update.cells[DIFF_REMOVE].length) {
@@ -359,9 +173,9 @@ function applyFilePatch(doc, patch, options) {
359
173
  const id2 = item["id"];
360
174
  if (!id2) continue;
361
175
  const xmlElement = new Y__namespace.XmlElement("mxCell");
362
- Object.keys(item).forEach((key2) => {
363
- if (key2 === "previous") return;
364
- xmlElement.setAttribute(key2, item[key2]);
176
+ Object.keys(item).forEach((key) => {
177
+ if (key === "previous") return;
178
+ xmlElement.setAttribute(key, item[key]);
365
179
  });
366
180
  cellsMap.set(id2, xmlElement);
367
181
  const previous = item["previous"];
@@ -463,7 +277,7 @@ function applyFilePatch(doc, patch, options) {
463
277
  if ("previous" in update) {
464
278
  const previous = update.previous || null;
465
279
  const orderArr = mxfile.get(
466
- diagramOrderKey
280
+ transformer.diagramOrderKey
467
281
  );
468
282
  ensureUniqueOrder(orderArr);
469
283
  insertAfterUnique(orderArr, id, previous, false);
@@ -475,9 +289,9 @@ function applyFilePatch(doc, patch, options) {
475
289
  }
476
290
  function initDocSnapshot(doc, resetSnapshot = false) {
477
291
  try {
478
- const mxfile = doc.getMap(key);
479
- const diagramsMap = mxfile.get(key$1);
480
- const orderArr = mxfile.get(diagramOrderKey);
292
+ const mxfile = doc.getMap(transformer.key);
293
+ const diagramsMap = mxfile.get(transformer.key$1);
294
+ const orderArr = mxfile.get(transformer.diagramOrderKey);
481
295
  const orderIds = orderArr ? orderArr.toArray() : [];
482
296
  const allDiagramIds = orderIds.length > 0 ? orderIds : diagramsMap ? Array.from(diagramsMap.keys()) : [];
483
297
  const diagramOrder = resetSnapshot ? [] : allDiagramIds.slice();
@@ -490,12 +304,12 @@ function initDocSnapshot(doc, resetSnapshot = false) {
490
304
  for (const d of diagrams) {
491
305
  const did = d.get("id") || "";
492
306
  if (!did) continue;
493
- const gm = d.get(key$2);
307
+ const gm = d.get(transformer.key$2);
494
308
  if (gm) {
495
- const order = gm.get(mxCellOrderKey);
309
+ const order = gm.get(transformer.mxCellOrderKey);
496
310
  const ids = order ? order.toArray().slice() : [];
497
311
  snap.cellsOrder.set(did, ids);
498
- const cellsMap = gm.get(key$3);
312
+ const cellsMap = gm.get(transformer.key$3);
499
313
  const attrMap = /* @__PURE__ */ new Map();
500
314
  if (cellsMap) {
501
315
  for (const cid of ids) {
@@ -525,9 +339,9 @@ function generatePatch(events, explicitDoc) {
525
339
  const doc = (_b = (_a = events[0]) == null ? void 0 : _a.transaction) == null ? void 0 : _b.doc;
526
340
  if (!doc) return patch;
527
341
  if (!events || events.length === 0) return patch;
528
- const mxfile = doc.getMap(key);
529
- const diagramsMap = mxfile.get(key$1);
530
- const orderArr = mxfile.get(diagramOrderKey);
342
+ const mxfile = doc.getMap(transformer.key);
343
+ const diagramsMap = mxfile.get(transformer.key$1);
344
+ const orderArr = mxfile.get(transformer.diagramOrderKey);
531
345
  let snap = docSnapshots.get(doc);
532
346
  if (!snap) {
533
347
  snap = {
@@ -558,10 +372,10 @@ function generatePatch(events, explicitDoc) {
558
372
  for (const d of diagramsList) {
559
373
  const did = d.get("id") || "";
560
374
  const attrs = /* @__PURE__ */ new Map();
561
- const gm = d.get(key$2);
375
+ const gm = d.get(transformer.key$2);
562
376
  if (gm) {
563
- const cellsMap = gm.get(key$3);
564
- const orderArr2 = gm.get(mxCellOrderKey);
377
+ const cellsMap = gm.get(transformer.key$3);
378
+ const orderArr2 = gm.get(transformer.mxCellOrderKey);
565
379
  if (cellsMap && orderArr2) {
566
380
  const ids = orderArr2.toArray();
567
381
  currCellsOrder.set(did, ids);
@@ -598,7 +412,7 @@ function generatePatch(events, explicitDoc) {
598
412
  const previous = index <= 0 ? "" : currDiagramOrder[index - 1];
599
413
  const yDiagram = diagramsMap.get(id);
600
414
  if (!yDiagram) continue;
601
- const data = serializer$1({ diagram: serialize(yDiagram) });
415
+ const data = transformer.serializer({ diagram: transformer.serialize(yDiagram) });
602
416
  patch[DIFF_INSERT].push({ id, previous, data });
603
417
  insertedDiagramIdGlobal.add(id);
604
418
  }
@@ -715,8 +529,8 @@ function generatePatch(events, explicitDoc) {
715
529
  const cellsPatch = ensureCellSection(diagramId);
716
530
  cellsPatch[DIFF_UPDATE] = cellsPatch[DIFF_UPDATE] || {};
717
531
  const cellUpdate = cellsPatch[DIFF_UPDATE][cellId] = cellsPatch[DIFF_UPDATE][cellId] || {};
718
- for (const key2 of Array.from(changed)) {
719
- cellUpdate[key2] = el.getAttribute(key2) || "";
532
+ for (const key of Array.from(changed)) {
533
+ cellUpdate[key] = el.getAttribute(key) || "";
720
534
  }
721
535
  }
722
536
  if (prevDiagramOrder) {
@@ -770,45 +584,6 @@ function generatePatch(events, explicitDoc) {
770
584
  docSnapshots.set(doc, snap);
771
585
  return patch;
772
586
  }
773
- function xml2ydoc(xml, doc) {
774
- const object = parse$4(xml);
775
- const mxfile = object.mxfile;
776
- const mxGraphModel = object.mxGraphModel;
777
- if (mxfile) {
778
- doc.transact(() => {
779
- parse(mxfile, doc);
780
- });
781
- } else if (mxGraphModel) {
782
- doc.transact(() => {
783
- parse$2(mxGraphModel, doc);
784
- });
785
- } else {
786
- throw new Error("不支持的文件格式");
787
- }
788
- return doc;
789
- }
790
- function ydoc2xml(doc, spaces = 0) {
791
- if (doc.share.has(key)) {
792
- return serializer$1(
793
- {
794
- [key]: serializer(
795
- doc.share.get(key)
796
- )
797
- },
798
- spaces
799
- );
800
- } else if (doc.share.has(key$2)) {
801
- return serializer$1(
802
- {
803
- [key$2]: serialize$1(
804
- doc.share.get(key$2)
805
- )
806
- },
807
- spaces
808
- );
809
- }
810
- return "";
811
- }
812
587
  const LOCAL_ORIGIN = {};
813
588
  function createMxEventObject(name, props) {
814
589
  const _props = props || {};
@@ -833,9 +608,9 @@ function bindUndoManager(doc, file, yUndo) {
833
608
  const pairs = [];
834
609
  const raw = Array.isArray(originUndoManager == null ? void 0 : originUndoManager.eventListeners) ? originUndoManager.eventListeners : [];
835
610
  for (let i = 0; i + 1 < raw.length; i += 2) {
836
- const key2 = String(raw[i]);
611
+ const key = String(raw[i]);
837
612
  const fn = raw[i + 1];
838
- pairs.push([key2, fn]);
613
+ pairs.push([key, fn]);
839
614
  }
840
615
  const mxLike = {
841
616
  eventListeners: [],
@@ -849,9 +624,9 @@ function bindUndoManager(doc, file, yUndo) {
849
624
  var _a;
850
625
  const eventName = (evt == null ? void 0 : evt.name) || (((_a = evt == null ? void 0 : evt.getName) == null ? void 0 : _a.call(evt)) ?? "");
851
626
  for (let i = 0; i + 1 < this.eventListeners.length; i += 2) {
852
- const key2 = this.eventListeners[i];
627
+ const key = this.eventListeners[i];
853
628
  const listener = this.eventListeners[i + 1];
854
- if (key2 === eventName) {
629
+ if (key === eventName) {
855
630
  try {
856
631
  listener(this, evt);
857
632
  } catch (e) {
@@ -937,8 +712,8 @@ function bindUndoManager(doc, file, yUndo) {
937
712
  mxLike.fireEvent(evt);
938
713
  };
939
714
  yUndo.on("stack-item-updated", updatedHandler);
940
- pairs.forEach(([key2, fn]) => {
941
- const k = key2.toLowerCase();
715
+ pairs.forEach(([key, fn]) => {
716
+ const k = key.toLowerCase();
942
717
  if (k === "add" || k === "clear" || k === "undo" || k === "redo") {
943
718
  mxLike.addListener(k, fn);
944
719
  }
@@ -959,33 +734,33 @@ function bindUndoManager(doc, file, yUndo) {
959
734
  };
960
735
  return destroy;
961
736
  }
962
- function getAwarenessStateValue(awareness, key2, clientId) {
737
+ function getAwarenessStateValue(awareness, key, clientId) {
963
738
  const states = awareness.getStates();
964
739
  const id = clientId != null ? Number(clientId) : awareness.clientID;
965
740
  const clientState = states.get(id);
966
741
  if (!clientState) return null;
967
- if (!key2) return clientState;
968
- return getByPath(clientState, key2);
742
+ if (!key) return clientState;
743
+ return getByPath(clientState, key);
969
744
  }
970
745
  function getByPath(obj, path) {
971
746
  const parts = path.split(".");
972
747
  let cur = obj;
973
748
  for (const part of parts) {
974
749
  if (cur == null) return null;
975
- const key2 = Array.isArray(cur) && /^\d+$/.test(part) ? Number(part) : part;
976
- cur = cur == null ? void 0 : cur[key2];
750
+ const key = Array.isArray(cur) && /^\d+$/.test(part) ? Number(part) : part;
751
+ cur = cur == null ? void 0 : cur[key];
977
752
  }
978
753
  return cur;
979
754
  }
980
- function setAwarenessStateValue(awareness, key2, value, clientId) {
755
+ function setAwarenessStateValue(awareness, key, value, clientId) {
981
756
  const id = awareness.clientID;
982
757
  if (id !== awareness.clientID) return false;
983
- if (!key2) {
758
+ if (!key) {
984
759
  awareness.setLocalState(value);
985
760
  return true;
986
761
  }
987
762
  const current = awareness.getLocalState() || {};
988
- const next = setByPath(current, key2, value);
763
+ const next = setByPath(current, key, value);
989
764
  awareness.setLocalState(next);
990
765
  return true;
991
766
  }
@@ -996,19 +771,19 @@ function setByPath(obj, path, value) {
996
771
  for (let i = 0; i < parts.length; i++) {
997
772
  const part = parts[i];
998
773
  const isIndex = /^\d+$/.test(part);
999
- const key2 = isIndex ? Number(part) : part;
774
+ const key = isIndex ? Number(part) : part;
1000
775
  const isLast = i === parts.length - 1;
1001
776
  if (isLast) {
1002
- cur[key2] = value;
777
+ cur[key] = value;
1003
778
  } else {
1004
- let next = cur[key2];
779
+ let next = cur[key];
1005
780
  const nextIsIndex = /^\d+$/.test(parts[i + 1]);
1006
781
  if (next == null) {
1007
782
  next = nextIsIndex ? [] : {};
1008
783
  } else {
1009
784
  next = Array.isArray(next) ? next.slice() : { ...next };
1010
785
  }
1011
- cur[key2] = next;
786
+ cur[key] = next;
1012
787
  cur = next;
1013
788
  }
1014
789
  }
@@ -1064,6 +839,34 @@ function hslToHex(h, s, l) {
1064
839
  const b = Math.round((b1 + m) * 255);
1065
840
  return "#" + [r, g, b].map((v) => v.toString(16).padStart(2, "0")).join("");
1066
841
  }
842
+ function throttle(fn, wait) {
843
+ let lastTime = 0;
844
+ let timeoutId = null;
845
+ let lastArgs = null;
846
+ return (...args) => {
847
+ const now = Date.now();
848
+ const remaining = wait - (now - lastTime);
849
+ lastArgs = args;
850
+ if (remaining <= 0) {
851
+ if (timeoutId) {
852
+ clearTimeout(timeoutId);
853
+ timeoutId = null;
854
+ }
855
+ lastTime = now;
856
+ return fn(...args);
857
+ }
858
+ if (!timeoutId) {
859
+ timeoutId = setTimeout(() => {
860
+ lastTime = Date.now();
861
+ timeoutId = null;
862
+ if (lastArgs) {
863
+ fn(...lastArgs);
864
+ }
865
+ }, remaining);
866
+ }
867
+ return void 0;
868
+ };
869
+ }
1067
870
  function createCursorImage(color) {
1068
871
  const w = 8;
1069
872
  const h = 12;
@@ -1116,7 +919,7 @@ function bindCursor(file, options) {
1116
919
  },
1117
920
  mouseUp: function() {
1118
921
  },
1119
- mouseMove: lodashEs.throttle(function(_sender, event) {
922
+ mouseMove: throttle(function(_sender, event) {
1120
923
  var _a;
1121
924
  const containerRect = graph.container.getBoundingClientRect();
1122
925
  const { translate, scale } = graph.view;
@@ -1242,7 +1045,7 @@ function bindSelection(file, options) {
1242
1045
  const cells = graph.getSelectionModel().cells;
1243
1046
  const ids = Object.keys(cells || {}).map(
1244
1047
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1245
- (key2) => getId(cells[key2])
1048
+ (key) => getId(cells[key])
1246
1049
  ).filter(Boolean);
1247
1050
  awareness.setLocalStateField("selection", { ids, pageId });
1248
1051
  };
@@ -1396,7 +1199,7 @@ const defaultApplyFileData = (file, xml) => {
1396
1199
  function mergeFileIntoDoc(doc, fileXml, strategy) {
1397
1200
  let parsed;
1398
1201
  try {
1399
- parsed = parse$4(fileXml);
1202
+ parsed = transformer.parse(fileXml);
1400
1203
  } catch (err) {
1401
1204
  console.warn(
1402
1205
  "[y-mxgraph] 合并失败,file XML 解析异常,回退到 replace:",
@@ -1411,9 +1214,9 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
1411
1214
  );
1412
1215
  return false;
1413
1216
  }
1414
- const mxfileMap = doc.getMap(key);
1415
- const diagramMap = mxfileMap.get(key$1);
1416
- const diagramOrder = mxfileMap.get(diagramOrderKey);
1217
+ const mxfileMap = doc.getMap(transformer.key);
1218
+ const diagramMap = mxfileMap.get(transformer.key$1);
1219
+ const diagramOrder = mxfileMap.get(transformer.diagramOrderKey);
1417
1220
  if (!diagramMap || !diagramOrder) {
1418
1221
  console.warn("[y-mxgraph] 合并失败,doc 结构不完整,回退到 replace");
1419
1222
  return false;
@@ -1427,7 +1230,7 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
1427
1230
  if (docHas && strategy === "merge-remote") {
1428
1231
  continue;
1429
1232
  }
1430
- const yDiagram = parse$1(
1233
+ const yDiagram = transformer.parse$1(
1431
1234
  diagram
1432
1235
  );
1433
1236
  diagramMap.set(id, yDiagram);
@@ -1439,13 +1242,13 @@ function mergeFileIntoDoc(doc, fileXml, strategy) {
1439
1242
  return true;
1440
1243
  }
1441
1244
  function reconcileInitialContent(doc, file, strategy, applyFileData) {
1442
- const mxfileMap = doc.getMap(key);
1245
+ const mxfileMap = doc.getMap(transformer.key);
1443
1246
  const docHasData = mxfileMap.size > 0;
1444
1247
  const fileHasAnyData = !!file.data;
1445
1248
  const fileHasDiagrams = fileHasAnyData && file.data.includes("<diagram");
1446
1249
  if (strategy === "replace") {
1447
1250
  if (docHasData) {
1448
- const xml2 = ydoc2xml(doc);
1251
+ const xml2 = transformer.ydoc2xml(doc);
1449
1252
  if (xml2 && xml2.includes("<diagram")) {
1450
1253
  applyFileData(file, xml2);
1451
1254
  } else if (!fileHasAnyData) {
@@ -1465,7 +1268,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
1465
1268
  if (!docHasData && fileHasDiagrams) {
1466
1269
  try {
1467
1270
  doc.transact(() => {
1468
- xml2ydoc(file.data, doc);
1271
+ transformer.xml2ydoc(file.data, doc);
1469
1272
  });
1470
1273
  return true;
1471
1274
  } catch (err) {
@@ -1478,7 +1281,7 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
1478
1281
  }
1479
1282
  }
1480
1283
  if (docHasData && !fileHasDiagrams) {
1481
- const xml2 = ydoc2xml(doc);
1284
+ const xml2 = transformer.ydoc2xml(doc);
1482
1285
  if (xml2 && xml2.includes("<diagram")) {
1483
1286
  applyFileData(file, xml2);
1484
1287
  } else if (!fileHasAnyData) {
@@ -1488,11 +1291,11 @@ function reconcileInitialContent(doc, file, strategy, applyFileData) {
1488
1291
  }
1489
1292
  const ok = mergeFileIntoDoc(doc, file.data, strategy);
1490
1293
  if (!ok) {
1491
- const xml2 = ydoc2xml(doc);
1294
+ const xml2 = transformer.ydoc2xml(doc);
1492
1295
  if (xml2 && xml2.includes("<diagram")) applyFileData(file, xml2);
1493
1296
  return mxfileMap.size > 0;
1494
1297
  }
1495
- const xml = ydoc2xml(doc);
1298
+ const xml = transformer.ydoc2xml(doc);
1496
1299
  if (xml && xml.includes("<diagram")) applyFileData(file, xml);
1497
1300
  return true;
1498
1301
  }
@@ -1546,7 +1349,7 @@ class Binding {
1546
1349
  if (patchKeys.length === 0) return;
1547
1350
  if (!this.docInitialized) {
1548
1351
  doc.transact(() => {
1549
- xml2ydoc(file.data, doc);
1352
+ transformer.xml2ydoc(file.data, doc);
1550
1353
  initDocSnapshot(doc, false);
1551
1354
  });
1552
1355
  this.docInitialized = true;
@@ -1562,10 +1365,10 @@ class Binding {
1562
1365
  return;
1563
1366
  }
1564
1367
  if (this.shouldReplaceWhenDocHasData && !transaction.local) {
1565
- const mxfileMap = doc.getMap(key);
1566
- const diagramMap = mxfileMap.get(key$1);
1368
+ const mxfileMap = doc.getMap(transformer.key);
1369
+ const diagramMap = mxfileMap.get(transformer.key$1);
1567
1370
  if (diagramMap && diagramMap.size > 0) {
1568
- const xml = ydoc2xml(doc);
1371
+ const xml = transformer.ydoc2xml(doc);
1569
1372
  if (xml && xml.includes("<diagram")) {
1570
1373
  this.suppressLocalApply = true;
1571
1374
  try {
@@ -1595,7 +1398,7 @@ class Binding {
1595
1398
  this.suppressLocalApply = false;
1596
1399
  }
1597
1400
  };
1598
- doc.getMap(key).observeDeep(this.docObserver);
1401
+ doc.getMap(transformer.key).observeDeep(this.docObserver);
1599
1402
  if (awareness) {
1600
1403
  this.cleanupCollaborator = bindCollaborator(file, {
1601
1404
  awareness,
@@ -1630,7 +1433,7 @@ class Binding {
1630
1433
  destroy(deep = false) {
1631
1434
  var _a, _b;
1632
1435
  this.mxGraphModel.removeListener("change", this.mxListener);
1633
- this.doc.getMap(key).unobserveDeep(this.docObserver);
1436
+ this.doc.getMap(transformer.key).unobserveDeep(this.docObserver);
1634
1437
  if (deep) {
1635
1438
  (_a = this.cleanupCollaborator) == null ? void 0 : _a.call(this);
1636
1439
  (_b = this.cleanupUndoManager) == null ? void 0 : _b.call(this);
@@ -1671,10 +1474,10 @@ class Binding {
1671
1474
  return new Binding(file, options);
1672
1475
  }
1673
1476
  }
1477
+ exports.xml2ydoc = transformer.xml2ydoc;
1478
+ exports.ydoc2xml = transformer.ydoc2xml;
1674
1479
  exports.Binding = Binding;
1675
1480
  exports.DEFAULT_USER_COLOR_KEY = DEFAULT_USER_COLOR_KEY;
1676
1481
  exports.DEFAULT_USER_NAME_KEY = DEFAULT_USER_NAME_KEY;
1677
1482
  exports.LOCAL_ORIGIN = LOCAL_ORIGIN;
1678
- exports.xml2ydoc = xml2ydoc;
1679
- exports.ydoc2xml = ydoc2xml;
1680
- //# sourceMappingURL=y-mxgraph.cjs.js.map
1483
+ //# sourceMappingURL=y-mxgraph.cjs.map