@fieldnotes/core 0.45.0 → 0.46.1
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.cjs +40 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +40 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -698,8 +698,20 @@ var InputFilter = class _InputFilter {
|
|
|
698
698
|
|
|
699
699
|
// src/elements/create-id.ts
|
|
700
700
|
var counter = 0;
|
|
701
|
+
function randomClientComponent() {
|
|
702
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
703
|
+
const bytes = new Uint8Array(8);
|
|
704
|
+
crypto.getRandomValues(bytes);
|
|
705
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
706
|
+
}
|
|
707
|
+
return Math.random().toString(36).slice(2, 14);
|
|
708
|
+
}
|
|
709
|
+
var CLIENT = randomClientComponent();
|
|
710
|
+
function formatId(prefix, time, counter2, client) {
|
|
711
|
+
return `${prefix}_${time}_${counter2}_${client}`;
|
|
712
|
+
}
|
|
701
713
|
function createId(prefix) {
|
|
702
|
-
return
|
|
714
|
+
return formatId(prefix, Date.now().toString(36), (counter++).toString(36), CLIENT);
|
|
703
715
|
}
|
|
704
716
|
|
|
705
717
|
// src/core/geometry.ts
|
|
@@ -2232,6 +2244,7 @@ var Background = class {
|
|
|
2232
2244
|
};
|
|
2233
2245
|
|
|
2234
2246
|
// src/core/event-bus.ts
|
|
2247
|
+
var EMPTY_META = Object.freeze({});
|
|
2235
2248
|
var EventBus = class {
|
|
2236
2249
|
listeners = /* @__PURE__ */ new Map();
|
|
2237
2250
|
on(event, listener) {
|
|
@@ -2247,10 +2260,10 @@ var EventBus = class {
|
|
|
2247
2260
|
off(event, listener) {
|
|
2248
2261
|
this.listeners.get(event)?.delete(listener);
|
|
2249
2262
|
}
|
|
2250
|
-
emit(event, data) {
|
|
2263
|
+
emit(event, data, meta = EMPTY_META) {
|
|
2251
2264
|
this.listeners.get(event)?.forEach((listener) => {
|
|
2252
2265
|
try {
|
|
2253
|
-
listener(data);
|
|
2266
|
+
listener(data, meta);
|
|
2254
2267
|
} catch (err) {
|
|
2255
2268
|
console.error(`[fieldnotes] listener error for "${String(event)}"`, err);
|
|
2256
2269
|
}
|
|
@@ -2570,15 +2583,15 @@ var ElementStore = class {
|
|
|
2570
2583
|
const angle = element.rotation ?? 0;
|
|
2571
2584
|
return angle === 0 ? bounds : rotatedAABB(bounds, angle);
|
|
2572
2585
|
}
|
|
2573
|
-
add(element) {
|
|
2586
|
+
add(element, meta) {
|
|
2574
2587
|
this.sortedCache = null;
|
|
2575
2588
|
this._versions.set(element.id, 0);
|
|
2576
2589
|
this.elements.set(element.id, element);
|
|
2577
2590
|
const bounds = this.indexBounds(element);
|
|
2578
2591
|
if (bounds) this.spatialIndex.insert(element.id, bounds);
|
|
2579
|
-
this.bus.emit("add", element);
|
|
2592
|
+
this.bus.emit("add", element, meta);
|
|
2580
2593
|
}
|
|
2581
|
-
update(id, partial) {
|
|
2594
|
+
update(id, partial, meta) {
|
|
2582
2595
|
const existing = this.elements.get(id);
|
|
2583
2596
|
if (!existing) return;
|
|
2584
2597
|
this.sortedCache = null;
|
|
@@ -2605,28 +2618,28 @@ var ElementStore = class {
|
|
|
2605
2618
|
if (newBounds) {
|
|
2606
2619
|
this.spatialIndex.update(id, newBounds);
|
|
2607
2620
|
}
|
|
2608
|
-
this.bus.emit("update", { previous: existing, current: updated });
|
|
2621
|
+
this.bus.emit("update", { previous: existing, current: updated }, meta);
|
|
2609
2622
|
}
|
|
2610
|
-
remove(id) {
|
|
2623
|
+
remove(id, meta) {
|
|
2611
2624
|
const element = this.elements.get(id);
|
|
2612
2625
|
if (!element) return;
|
|
2613
2626
|
this.sortedCache = null;
|
|
2614
2627
|
this._versions.delete(id);
|
|
2615
2628
|
this.elements.delete(id);
|
|
2616
2629
|
this.spatialIndex.remove(id);
|
|
2617
|
-
this.bus.emit("remove", element);
|
|
2630
|
+
this.bus.emit("remove", element, meta);
|
|
2618
2631
|
}
|
|
2619
|
-
clear() {
|
|
2632
|
+
clear(meta) {
|
|
2620
2633
|
this.sortedCache = null;
|
|
2621
2634
|
this._versions.clear();
|
|
2622
2635
|
this.elements.clear();
|
|
2623
2636
|
this.spatialIndex.clear();
|
|
2624
|
-
this.bus.emit("clear", null);
|
|
2637
|
+
this.bus.emit("clear", null, meta);
|
|
2625
2638
|
}
|
|
2626
2639
|
snapshot() {
|
|
2627
2640
|
return this.getAll().map((el) => ({ ...el }));
|
|
2628
2641
|
}
|
|
2629
|
-
loadSnapshot(elements) {
|
|
2642
|
+
loadSnapshot(elements, meta) {
|
|
2630
2643
|
this.sortedCache = null;
|
|
2631
2644
|
this._versions.clear();
|
|
2632
2645
|
this.elements.clear();
|
|
@@ -2643,9 +2656,9 @@ var ElementStore = class {
|
|
|
2643
2656
|
el.cachedControlPoint = getArrowControlPoint(el.from, el.to, el.bend);
|
|
2644
2657
|
}
|
|
2645
2658
|
}
|
|
2646
|
-
this.bus.emit("clear", null);
|
|
2659
|
+
this.bus.emit("clear", null, meta);
|
|
2647
2660
|
for (const el of elements) {
|
|
2648
|
-
this.bus.emit("add", el);
|
|
2661
|
+
this.bus.emit("add", el, meta);
|
|
2649
2662
|
}
|
|
2650
2663
|
}
|
|
2651
2664
|
bringToFront(id) {
|
|
@@ -4920,15 +4933,18 @@ var UpdateLayerCommand = class {
|
|
|
4920
4933
|
};
|
|
4921
4934
|
|
|
4922
4935
|
// src/history/history-recorder.ts
|
|
4936
|
+
function isExternalChange(meta) {
|
|
4937
|
+
return meta.origin !== void 0 && meta.origin !== "local";
|
|
4938
|
+
}
|
|
4923
4939
|
var HistoryRecorder = class {
|
|
4924
4940
|
constructor(store, stack, layerManager) {
|
|
4925
4941
|
this.store = store;
|
|
4926
4942
|
this.stack = stack;
|
|
4927
4943
|
this.layerManager = layerManager;
|
|
4928
4944
|
this.unsubscribers = [
|
|
4929
|
-
store.on("add", (el) => this.onAdd(el)),
|
|
4930
|
-
store.on("remove", (el) => this.onRemove(el)),
|
|
4931
|
-
store.on("update", ({ previous, current }) => this.onUpdate(previous, current))
|
|
4945
|
+
store.on("add", (el, meta) => this.onAdd(el, meta)),
|
|
4946
|
+
store.on("remove", (el, meta) => this.onRemove(el, meta)),
|
|
4947
|
+
store.on("update", ({ previous, current }, meta) => this.onUpdate(previous, current, meta))
|
|
4932
4948
|
];
|
|
4933
4949
|
if (layerManager) {
|
|
4934
4950
|
this.unsubscribers.push(
|
|
@@ -4984,18 +5000,21 @@ var HistoryRecorder = class {
|
|
|
4984
5000
|
this.stack.push(command);
|
|
4985
5001
|
}
|
|
4986
5002
|
}
|
|
4987
|
-
onAdd(element) {
|
|
5003
|
+
onAdd(element, meta) {
|
|
5004
|
+
if (isExternalChange(meta)) return;
|
|
4988
5005
|
if (!this.recording) return;
|
|
4989
5006
|
this.record(new AddElementCommand(element));
|
|
4990
5007
|
}
|
|
4991
|
-
onRemove(element) {
|
|
5008
|
+
onRemove(element, meta) {
|
|
5009
|
+
if (isExternalChange(meta)) return;
|
|
4992
5010
|
if (!this.recording) return;
|
|
4993
5011
|
if (this.transaction && this.updateSnapshots.has(element.id)) {
|
|
4994
5012
|
this.updateSnapshots.delete(element.id);
|
|
4995
5013
|
}
|
|
4996
5014
|
this.record(new RemoveElementCommand(element));
|
|
4997
5015
|
}
|
|
4998
|
-
onUpdate(previous, current) {
|
|
5016
|
+
onUpdate(previous, current, meta) {
|
|
5017
|
+
if (isExternalChange(meta)) return;
|
|
4999
5018
|
if (!this.recording) return;
|
|
5000
5019
|
if (this.transaction) {
|
|
5001
5020
|
if (!this.updateSnapshots.has(current.id)) {
|
|
@@ -10167,7 +10186,7 @@ var LaserTool = class {
|
|
|
10167
10186
|
};
|
|
10168
10187
|
|
|
10169
10188
|
// src/index.ts
|
|
10170
|
-
var VERSION = "0.
|
|
10189
|
+
var VERSION = "0.46.1";
|
|
10171
10190
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10172
10191
|
0 && (module.exports = {
|
|
10173
10192
|
ArrowTool,
|