@fieldnotes/core 0.49.0 → 0.50.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 +20 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -367,7 +367,7 @@ function migrateElement(obj) {
|
|
|
367
367
|
if (obj["type"] === "note" && typeof obj["textColor"] !== "string") {
|
|
368
368
|
obj["textColor"] = "#000000";
|
|
369
369
|
}
|
|
370
|
-
if (obj["type"] === "note" && typeof obj["text"] === "string") {
|
|
370
|
+
if ((obj["type"] === "note" || obj["type"] === "text") && typeof obj["text"] === "string") {
|
|
371
371
|
obj["text"] = sanitizeNoteHtml(obj["text"]);
|
|
372
372
|
}
|
|
373
373
|
}
|
|
@@ -2580,6 +2580,11 @@ function transferStrokeRenderData(prev, next) {
|
|
|
2580
2580
|
}
|
|
2581
2581
|
|
|
2582
2582
|
// src/elements/element-store.ts
|
|
2583
|
+
function sanitizeRichText(element) {
|
|
2584
|
+
if (element.type !== "note" && element.type !== "text") return element;
|
|
2585
|
+
const text = sanitizeNoteHtml(element.text);
|
|
2586
|
+
return text === element.text ? element : { ...element, text };
|
|
2587
|
+
}
|
|
2583
2588
|
var ElementStore = class {
|
|
2584
2589
|
elements = /* @__PURE__ */ new Map();
|
|
2585
2590
|
bus = new EventBus();
|
|
@@ -2624,6 +2629,7 @@ var ElementStore = class {
|
|
|
2624
2629
|
return angle === 0 ? bounds : rotatedAABB(bounds, angle);
|
|
2625
2630
|
}
|
|
2626
2631
|
add(element, meta) {
|
|
2632
|
+
element = sanitizeRichText(element);
|
|
2627
2633
|
this.sortedCache = null;
|
|
2628
2634
|
this._versions.set(element.id, 0);
|
|
2629
2635
|
this.elements.set(element.id, element);
|
|
@@ -2650,7 +2656,7 @@ var ElementStore = class {
|
|
|
2650
2656
|
const arrow = updated;
|
|
2651
2657
|
arrow.cachedControlPoint = getArrowControlPoint(arrow.from, arrow.to, arrow.bend);
|
|
2652
2658
|
}
|
|
2653
|
-
if (updated.type === "note" && "text" in partial) {
|
|
2659
|
+
if ((updated.type === "note" || updated.type === "text") && "text" in partial) {
|
|
2654
2660
|
updated.text = sanitizeNoteHtml(updated.text);
|
|
2655
2661
|
}
|
|
2656
2662
|
this.elements.set(id, updated);
|
|
@@ -2680,11 +2686,12 @@ var ElementStore = class {
|
|
|
2680
2686
|
return this.getAll().map((el) => ({ ...el }));
|
|
2681
2687
|
}
|
|
2682
2688
|
loadSnapshot(elements, meta) {
|
|
2689
|
+
const sanitizedElements = elements.map(sanitizeRichText);
|
|
2683
2690
|
this.sortedCache = null;
|
|
2684
2691
|
this._versions.clear();
|
|
2685
2692
|
this.elements.clear();
|
|
2686
2693
|
this.spatialIndex.clear();
|
|
2687
|
-
for (const el of
|
|
2694
|
+
for (const el of sanitizedElements) {
|
|
2688
2695
|
this.elements.set(el.id, el);
|
|
2689
2696
|
this._versions.set(el.id, 0);
|
|
2690
2697
|
const bounds = this.indexBounds(el);
|
|
@@ -2697,7 +2704,7 @@ var ElementStore = class {
|
|
|
2697
2704
|
}
|
|
2698
2705
|
}
|
|
2699
2706
|
this.bus.emit("clear", null, meta);
|
|
2700
|
-
for (const el of
|
|
2707
|
+
for (const el of sanitizedElements) {
|
|
2701
2708
|
this.bus.emit("add", el, meta);
|
|
2702
2709
|
}
|
|
2703
2710
|
}
|
|
@@ -4112,7 +4119,7 @@ function createText(input) {
|
|
|
4112
4119
|
locked: input.locked ?? false,
|
|
4113
4120
|
layerId: input.layerId ?? "",
|
|
4114
4121
|
size: input.size ?? { w: 200, h: 28 },
|
|
4115
|
-
text: input.text ?? "",
|
|
4122
|
+
text: sanitizeNoteHtml(input.text ?? ""),
|
|
4116
4123
|
fontSize: input.fontSize ?? 16,
|
|
4117
4124
|
color: input.color ?? "#1a1a1a",
|
|
4118
4125
|
textAlign: input.textAlign ?? "left"
|
|
@@ -8965,7 +8972,7 @@ function anchorOffset(handle, w, h) {
|
|
|
8965
8972
|
return { x: 0, y: 0 };
|
|
8966
8973
|
}
|
|
8967
8974
|
}
|
|
8968
|
-
function computeResize(el, handle, world, lastWorld, aspectRatio,
|
|
8975
|
+
function computeResize(el, handle, world, lastWorld, aspectRatio, lockAspect) {
|
|
8969
8976
|
const dx = world.x - lastWorld.x;
|
|
8970
8977
|
const dy = world.y - lastWorld.y;
|
|
8971
8978
|
let { x, y, w, h } = { x: el.position.x, y: el.position.y, w: el.size.w, h: el.size.h };
|
|
@@ -8991,7 +8998,7 @@ function computeResize(el, handle, world, lastWorld, aspectRatio, shiftKey) {
|
|
|
8991
8998
|
h -= dy;
|
|
8992
8999
|
break;
|
|
8993
9000
|
}
|
|
8994
|
-
if (
|
|
9001
|
+
if (lockAspect && aspectRatio > 0) {
|
|
8995
9002
|
const absDw = Math.abs(w - el.size.w);
|
|
8996
9003
|
const absDh = Math.abs(h - el.size.h);
|
|
8997
9004
|
if (absDw >= absDh) {
|
|
@@ -9016,7 +9023,7 @@ function computeResize(el, handle, world, lastWorld, aspectRatio, shiftKey) {
|
|
|
9016
9023
|
}
|
|
9017
9024
|
return { position: { x, y }, size: { w, h } };
|
|
9018
9025
|
}
|
|
9019
|
-
function computeRotatedResize(el, handle, angle, world, lastWorld, aspectRatio,
|
|
9026
|
+
function computeRotatedResize(el, handle, angle, world, lastWorld, aspectRatio, lockAspect) {
|
|
9020
9027
|
const wdx = world.x - lastWorld.x;
|
|
9021
9028
|
const wdy = world.y - lastWorld.y;
|
|
9022
9029
|
const cosN = Math.cos(-angle);
|
|
@@ -9043,7 +9050,7 @@ function computeRotatedResize(el, handle, angle, world, lastWorld, aspectRatio,
|
|
|
9043
9050
|
h -= ldy;
|
|
9044
9051
|
break;
|
|
9045
9052
|
}
|
|
9046
|
-
if (
|
|
9053
|
+
if (lockAspect && aspectRatio > 0) {
|
|
9047
9054
|
const absDw = Math.abs(w - el.size.w);
|
|
9048
9055
|
const absDh = Math.abs(h - el.size.h);
|
|
9049
9056
|
if (absDw >= absDh) h = w / aspectRatio;
|
|
@@ -9573,6 +9580,7 @@ var SelectTool = class {
|
|
|
9573
9580
|
if (this.mode.type !== "resizing") return;
|
|
9574
9581
|
const el = ctx.store.getById(this.mode.elementId);
|
|
9575
9582
|
if (!el || !("size" in el) || el.locked) return;
|
|
9583
|
+
const lockAspect = shiftKey !== (el.type === "image");
|
|
9576
9584
|
const angle = el.rotation ?? 0;
|
|
9577
9585
|
const patch = angle !== 0 ? computeRotatedResize(
|
|
9578
9586
|
el,
|
|
@@ -9581,14 +9589,14 @@ var SelectTool = class {
|
|
|
9581
9589
|
world,
|
|
9582
9590
|
this.lastWorld,
|
|
9583
9591
|
this.resizeAspectRatio,
|
|
9584
|
-
|
|
9592
|
+
lockAspect
|
|
9585
9593
|
) : computeResize(
|
|
9586
9594
|
el,
|
|
9587
9595
|
this.mode.handle,
|
|
9588
9596
|
world,
|
|
9589
9597
|
this.lastWorld,
|
|
9590
9598
|
this.resizeAspectRatio,
|
|
9591
|
-
|
|
9599
|
+
lockAspect
|
|
9592
9600
|
);
|
|
9593
9601
|
this.lastWorld = world;
|
|
9594
9602
|
ctx.store.update(this.mode.elementId, patch);
|
|
@@ -10613,7 +10621,7 @@ var LaserTool = class {
|
|
|
10613
10621
|
};
|
|
10614
10622
|
|
|
10615
10623
|
// src/index.ts
|
|
10616
|
-
var VERSION = "0.
|
|
10624
|
+
var VERSION = "0.50.1";
|
|
10617
10625
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10618
10626
|
0 && (module.exports = {
|
|
10619
10627
|
ArrowTool,
|