@fieldnotes/core 0.11.2 → 0.11.3
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 +19 -3
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +19 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1412,19 +1412,23 @@ var ElementStore = class {
|
|
|
1412
1412
|
bus = new EventBus();
|
|
1413
1413
|
layerOrderMap = /* @__PURE__ */ new Map();
|
|
1414
1414
|
spatialIndex = new Quadtree({ x: -1e5, y: -1e5, w: 2e5, h: 2e5 });
|
|
1415
|
+
sortedCache = null;
|
|
1415
1416
|
get count() {
|
|
1416
1417
|
return this.elements.size;
|
|
1417
1418
|
}
|
|
1418
1419
|
setLayerOrder(order) {
|
|
1419
1420
|
this.layerOrderMap = new Map(order);
|
|
1421
|
+
this.sortedCache = null;
|
|
1420
1422
|
}
|
|
1421
1423
|
getAll() {
|
|
1422
|
-
|
|
1424
|
+
if (this.sortedCache) return this.sortedCache;
|
|
1425
|
+
this.sortedCache = [...this.elements.values()].sort((a, b) => {
|
|
1423
1426
|
const layerA = this.layerOrderMap.get(a.layerId) ?? 0;
|
|
1424
1427
|
const layerB = this.layerOrderMap.get(b.layerId) ?? 0;
|
|
1425
1428
|
if (layerA !== layerB) return layerA - layerB;
|
|
1426
1429
|
return a.zIndex - b.zIndex;
|
|
1427
1430
|
});
|
|
1431
|
+
return this.sortedCache;
|
|
1428
1432
|
}
|
|
1429
1433
|
getById(id) {
|
|
1430
1434
|
return this.elements.get(id);
|
|
@@ -1435,6 +1439,7 @@ var ElementStore = class {
|
|
|
1435
1439
|
);
|
|
1436
1440
|
}
|
|
1437
1441
|
add(element) {
|
|
1442
|
+
this.sortedCache = null;
|
|
1438
1443
|
this.elements.set(element.id, element);
|
|
1439
1444
|
const bounds = getElementBounds(element);
|
|
1440
1445
|
if (bounds) this.spatialIndex.insert(element.id, bounds);
|
|
@@ -1443,11 +1448,15 @@ var ElementStore = class {
|
|
|
1443
1448
|
update(id, partial) {
|
|
1444
1449
|
const existing = this.elements.get(id);
|
|
1445
1450
|
if (!existing) return;
|
|
1451
|
+
this.sortedCache = null;
|
|
1446
1452
|
const updated = { ...existing, ...partial, id: existing.id, type: existing.type };
|
|
1447
1453
|
if (updated.type === "arrow") {
|
|
1448
1454
|
const arrow = updated;
|
|
1449
1455
|
arrow.cachedControlPoint = getArrowControlPoint(arrow.from, arrow.to, arrow.bend);
|
|
1450
1456
|
}
|
|
1457
|
+
if (updated.type === "note" && "text" in partial) {
|
|
1458
|
+
updated.text = sanitizeNoteHtml(updated.text);
|
|
1459
|
+
}
|
|
1451
1460
|
this.elements.set(id, updated);
|
|
1452
1461
|
const newBounds = getElementBounds(updated);
|
|
1453
1462
|
if (newBounds) {
|
|
@@ -1458,11 +1467,13 @@ var ElementStore = class {
|
|
|
1458
1467
|
remove(id) {
|
|
1459
1468
|
const element = this.elements.get(id);
|
|
1460
1469
|
if (!element) return;
|
|
1470
|
+
this.sortedCache = null;
|
|
1461
1471
|
this.elements.delete(id);
|
|
1462
1472
|
this.spatialIndex.remove(id);
|
|
1463
1473
|
this.bus.emit("remove", element);
|
|
1464
1474
|
}
|
|
1465
1475
|
clear() {
|
|
1476
|
+
this.sortedCache = null;
|
|
1466
1477
|
this.elements.clear();
|
|
1467
1478
|
this.spatialIndex.clear();
|
|
1468
1479
|
this.bus.emit("clear", null);
|
|
@@ -1471,6 +1482,7 @@ var ElementStore = class {
|
|
|
1471
1482
|
return this.getAll().map((el) => ({ ...el }));
|
|
1472
1483
|
}
|
|
1473
1484
|
loadSnapshot(elements) {
|
|
1485
|
+
this.sortedCache = null;
|
|
1474
1486
|
this.elements.clear();
|
|
1475
1487
|
this.spatialIndex.clear();
|
|
1476
1488
|
for (const el of elements) {
|
|
@@ -1478,6 +1490,10 @@ var ElementStore = class {
|
|
|
1478
1490
|
const bounds = getElementBounds(el);
|
|
1479
1491
|
if (bounds) this.spatialIndex.insert(el.id, bounds);
|
|
1480
1492
|
}
|
|
1493
|
+
this.bus.emit("clear", null);
|
|
1494
|
+
for (const el of elements) {
|
|
1495
|
+
this.bus.emit("add", el);
|
|
1496
|
+
}
|
|
1481
1497
|
}
|
|
1482
1498
|
queryRect(rect) {
|
|
1483
1499
|
const ids = this.spatialIndex.query(rect);
|
|
@@ -2558,7 +2574,7 @@ function createNote(input) {
|
|
|
2558
2574
|
locked: input.locked ?? false,
|
|
2559
2575
|
layerId: input.layerId ?? "",
|
|
2560
2576
|
size: input.size ?? { w: 200, h: 100 },
|
|
2561
|
-
text: input.text ?? "",
|
|
2577
|
+
text: sanitizeNoteHtml(input.text ?? ""),
|
|
2562
2578
|
backgroundColor: input.backgroundColor ?? "#ffeb3b",
|
|
2563
2579
|
textColor: input.textColor ?? "#000000",
|
|
2564
2580
|
fontSize: input.fontSize ?? DEFAULT_NOTE_FONT_SIZE
|
|
@@ -6414,7 +6430,7 @@ var UpdateLayerCommand = class {
|
|
|
6414
6430
|
};
|
|
6415
6431
|
|
|
6416
6432
|
// src/index.ts
|
|
6417
|
-
var VERSION = "0.11.
|
|
6433
|
+
var VERSION = "0.11.3";
|
|
6418
6434
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6419
6435
|
0 && (module.exports = {
|
|
6420
6436
|
AddElementCommand,
|
package/dist/index.d.cts
CHANGED
|
@@ -200,6 +200,7 @@ declare class ElementStore {
|
|
|
200
200
|
private bus;
|
|
201
201
|
private layerOrderMap;
|
|
202
202
|
private spatialIndex;
|
|
203
|
+
private sortedCache;
|
|
203
204
|
get count(): number;
|
|
204
205
|
setLayerOrder(order: Map<string, number>): void;
|
|
205
206
|
getAll(): CanvasElement[];
|
|
@@ -1144,6 +1145,6 @@ declare class UpdateLayerCommand implements Command {
|
|
|
1144
1145
|
undo(_store: ElementStore): void;
|
|
1145
1146
|
}
|
|
1146
1147
|
|
|
1147
|
-
declare const VERSION = "0.11.
|
|
1148
|
+
declare const VERSION = "0.11.3";
|
|
1148
1149
|
|
|
1149
1150
|
export { type ActiveFormats, AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, DEFAULT_FONT_SIZE_PRESETS, DEFAULT_NOTE_FONT_SIZE, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type FilterAction, type FilteredEvent, type FilteredUpEvent, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputFilter, InputHandler, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteEditorOptions, type NoteElement, NoteTool, type NoteToolOptions, NoteToolbar, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type StyledRun, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };
|
package/dist/index.d.ts
CHANGED
|
@@ -200,6 +200,7 @@ declare class ElementStore {
|
|
|
200
200
|
private bus;
|
|
201
201
|
private layerOrderMap;
|
|
202
202
|
private spatialIndex;
|
|
203
|
+
private sortedCache;
|
|
203
204
|
get count(): number;
|
|
204
205
|
setLayerOrder(order: Map<string, number>): void;
|
|
205
206
|
getAll(): CanvasElement[];
|
|
@@ -1144,6 +1145,6 @@ declare class UpdateLayerCommand implements Command {
|
|
|
1144
1145
|
undo(_store: ElementStore): void;
|
|
1145
1146
|
}
|
|
1146
1147
|
|
|
1147
|
-
declare const VERSION = "0.11.
|
|
1148
|
+
declare const VERSION = "0.11.3";
|
|
1148
1149
|
|
|
1149
1150
|
export { type ActiveFormats, AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, DEFAULT_FONT_SIZE_PRESETS, DEFAULT_NOTE_FONT_SIZE, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type ExportImageOptions, type FilterAction, type FilteredEvent, type FilteredUpEvent, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputFilter, InputHandler, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, NoteEditor, type NoteEditorOptions, type NoteElement, NoteTool, type NoteToolOptions, NoteToolbar, PencilTool, type PencilToolOptions, type Point, type PointerState, Quadtree, RemoveElementCommand, RemoveLayerCommand, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type StyledRun, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, boundsIntersect, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, exportState, findBindTarget, findBoundArrows, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isBindable, isNearBezier, parseState, sanitizeNoteHtml, setFontSize, smartSnap, snapPoint, snapToHexCenter, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline, unbindArrow, updateBoundArrow };
|
package/dist/index.js
CHANGED
|
@@ -1305,19 +1305,23 @@ var ElementStore = class {
|
|
|
1305
1305
|
bus = new EventBus();
|
|
1306
1306
|
layerOrderMap = /* @__PURE__ */ new Map();
|
|
1307
1307
|
spatialIndex = new Quadtree({ x: -1e5, y: -1e5, w: 2e5, h: 2e5 });
|
|
1308
|
+
sortedCache = null;
|
|
1308
1309
|
get count() {
|
|
1309
1310
|
return this.elements.size;
|
|
1310
1311
|
}
|
|
1311
1312
|
setLayerOrder(order) {
|
|
1312
1313
|
this.layerOrderMap = new Map(order);
|
|
1314
|
+
this.sortedCache = null;
|
|
1313
1315
|
}
|
|
1314
1316
|
getAll() {
|
|
1315
|
-
|
|
1317
|
+
if (this.sortedCache) return this.sortedCache;
|
|
1318
|
+
this.sortedCache = [...this.elements.values()].sort((a, b) => {
|
|
1316
1319
|
const layerA = this.layerOrderMap.get(a.layerId) ?? 0;
|
|
1317
1320
|
const layerB = this.layerOrderMap.get(b.layerId) ?? 0;
|
|
1318
1321
|
if (layerA !== layerB) return layerA - layerB;
|
|
1319
1322
|
return a.zIndex - b.zIndex;
|
|
1320
1323
|
});
|
|
1324
|
+
return this.sortedCache;
|
|
1321
1325
|
}
|
|
1322
1326
|
getById(id) {
|
|
1323
1327
|
return this.elements.get(id);
|
|
@@ -1328,6 +1332,7 @@ var ElementStore = class {
|
|
|
1328
1332
|
);
|
|
1329
1333
|
}
|
|
1330
1334
|
add(element) {
|
|
1335
|
+
this.sortedCache = null;
|
|
1331
1336
|
this.elements.set(element.id, element);
|
|
1332
1337
|
const bounds = getElementBounds(element);
|
|
1333
1338
|
if (bounds) this.spatialIndex.insert(element.id, bounds);
|
|
@@ -1336,11 +1341,15 @@ var ElementStore = class {
|
|
|
1336
1341
|
update(id, partial) {
|
|
1337
1342
|
const existing = this.elements.get(id);
|
|
1338
1343
|
if (!existing) return;
|
|
1344
|
+
this.sortedCache = null;
|
|
1339
1345
|
const updated = { ...existing, ...partial, id: existing.id, type: existing.type };
|
|
1340
1346
|
if (updated.type === "arrow") {
|
|
1341
1347
|
const arrow = updated;
|
|
1342
1348
|
arrow.cachedControlPoint = getArrowControlPoint(arrow.from, arrow.to, arrow.bend);
|
|
1343
1349
|
}
|
|
1350
|
+
if (updated.type === "note" && "text" in partial) {
|
|
1351
|
+
updated.text = sanitizeNoteHtml(updated.text);
|
|
1352
|
+
}
|
|
1344
1353
|
this.elements.set(id, updated);
|
|
1345
1354
|
const newBounds = getElementBounds(updated);
|
|
1346
1355
|
if (newBounds) {
|
|
@@ -1351,11 +1360,13 @@ var ElementStore = class {
|
|
|
1351
1360
|
remove(id) {
|
|
1352
1361
|
const element = this.elements.get(id);
|
|
1353
1362
|
if (!element) return;
|
|
1363
|
+
this.sortedCache = null;
|
|
1354
1364
|
this.elements.delete(id);
|
|
1355
1365
|
this.spatialIndex.remove(id);
|
|
1356
1366
|
this.bus.emit("remove", element);
|
|
1357
1367
|
}
|
|
1358
1368
|
clear() {
|
|
1369
|
+
this.sortedCache = null;
|
|
1359
1370
|
this.elements.clear();
|
|
1360
1371
|
this.spatialIndex.clear();
|
|
1361
1372
|
this.bus.emit("clear", null);
|
|
@@ -1364,6 +1375,7 @@ var ElementStore = class {
|
|
|
1364
1375
|
return this.getAll().map((el) => ({ ...el }));
|
|
1365
1376
|
}
|
|
1366
1377
|
loadSnapshot(elements) {
|
|
1378
|
+
this.sortedCache = null;
|
|
1367
1379
|
this.elements.clear();
|
|
1368
1380
|
this.spatialIndex.clear();
|
|
1369
1381
|
for (const el of elements) {
|
|
@@ -1371,6 +1383,10 @@ var ElementStore = class {
|
|
|
1371
1383
|
const bounds = getElementBounds(el);
|
|
1372
1384
|
if (bounds) this.spatialIndex.insert(el.id, bounds);
|
|
1373
1385
|
}
|
|
1386
|
+
this.bus.emit("clear", null);
|
|
1387
|
+
for (const el of elements) {
|
|
1388
|
+
this.bus.emit("add", el);
|
|
1389
|
+
}
|
|
1374
1390
|
}
|
|
1375
1391
|
queryRect(rect) {
|
|
1376
1392
|
const ids = this.spatialIndex.query(rect);
|
|
@@ -2451,7 +2467,7 @@ function createNote(input) {
|
|
|
2451
2467
|
locked: input.locked ?? false,
|
|
2452
2468
|
layerId: input.layerId ?? "",
|
|
2453
2469
|
size: input.size ?? { w: 200, h: 100 },
|
|
2454
|
-
text: input.text ?? "",
|
|
2470
|
+
text: sanitizeNoteHtml(input.text ?? ""),
|
|
2455
2471
|
backgroundColor: input.backgroundColor ?? "#ffeb3b",
|
|
2456
2472
|
textColor: input.textColor ?? "#000000",
|
|
2457
2473
|
fontSize: input.fontSize ?? DEFAULT_NOTE_FONT_SIZE
|
|
@@ -6307,7 +6323,7 @@ var UpdateLayerCommand = class {
|
|
|
6307
6323
|
};
|
|
6308
6324
|
|
|
6309
6325
|
// src/index.ts
|
|
6310
|
-
var VERSION = "0.11.
|
|
6326
|
+
var VERSION = "0.11.3";
|
|
6311
6327
|
export {
|
|
6312
6328
|
AddElementCommand,
|
|
6313
6329
|
ArrowTool,
|