@tldraw/editor 4.3.0 → 4.4.0-canary.15cff7ea86f8
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/README.md +1 -1
- package/dist-cjs/index.d.ts +9 -0
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/config/TLUserPreferences.js +9 -3
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +58 -6
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +13 -21
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/RBushIndex.js +144 -0
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/RBushIndex.js.map +7 -0
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +180 -0
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +8 -3
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +9 -0
- package/dist-esm/index.mjs +3 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/config/TLUserPreferences.mjs +9 -3
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +58 -6
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +13 -21
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SpatialIndexManager/RBushIndex.mjs +114 -0
- package/dist-esm/lib/editor/managers/SpatialIndexManager/RBushIndex.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +160 -0
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +8 -3
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +10 -8
- package/src/index.ts +1 -0
- package/src/lib/components/default-components/DefaultCanvas.tsx +1 -5
- package/src/lib/config/TLUserPreferences.test.ts +1 -0
- package/src/lib/config/TLUserPreferences.ts +8 -0
- package/src/lib/editor/Editor.ts +84 -6
- package/src/lib/editor/derivations/notVisibleShapes.ts +15 -41
- package/src/lib/editor/managers/SpatialIndexManager/RBushIndex.ts +144 -0
- package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +214 -0
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +24 -0
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +8 -0
- package/src/version.ts +3 -3
|
@@ -23,33 +23,25 @@ __export(notVisibleShapes_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(notVisibleShapes_exports);
|
|
24
24
|
var import_state = require("@tldraw/state");
|
|
25
25
|
function notVisibleShapes(editor) {
|
|
26
|
-
return (0, import_state.computed)("notVisibleShapes", function
|
|
27
|
-
const
|
|
28
|
-
const nextValue = /* @__PURE__ */ new Set();
|
|
26
|
+
return (0, import_state.computed)("notVisibleShapes", function(prevValue) {
|
|
27
|
+
const allShapeIds = editor.getCurrentPageShapeIds();
|
|
29
28
|
const viewportPageBounds = editor.getViewportPageBounds();
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
continue;
|
|
29
|
+
const visibleIds = editor.getShapeIdsInsideBounds(viewportPageBounds);
|
|
30
|
+
const nextValue = /* @__PURE__ */ new Set();
|
|
31
|
+
for (const id of allShapeIds) {
|
|
32
|
+
if (!visibleIds.has(id)) {
|
|
33
|
+
const shape = editor.getShape(id);
|
|
34
|
+
if (!shape) continue;
|
|
35
|
+
const canCull = editor.getShapeUtil(shape.type).canCull(shape);
|
|
36
|
+
if (!canCull) continue;
|
|
37
|
+
nextValue.add(id);
|
|
38
38
|
}
|
|
39
|
-
const shape = editor.getShape(id);
|
|
40
|
-
if (!shape) continue;
|
|
41
|
-
const canCull = editor.getShapeUtil(shape.type).canCull(shape);
|
|
42
|
-
if (!canCull) continue;
|
|
43
|
-
nextValue.add(id);
|
|
44
39
|
}
|
|
45
|
-
if ((0, import_state.isUninitialized)(prevValue)) {
|
|
40
|
+
if ((0, import_state.isUninitialized)(prevValue) || prevValue.size !== nextValue.size) {
|
|
46
41
|
return nextValue;
|
|
47
42
|
}
|
|
48
|
-
if (prevValue.size !== nextValue.size) return nextValue;
|
|
49
43
|
for (const prev of prevValue) {
|
|
50
|
-
if (!nextValue.has(prev))
|
|
51
|
-
return nextValue;
|
|
52
|
-
}
|
|
44
|
+
if (!nextValue.has(prev)) return nextValue;
|
|
53
45
|
}
|
|
54
46
|
return prevValue;
|
|
55
47
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/editor/derivations/notVisibleShapes.ts"],
|
|
4
|
-
"sourcesContent": ["import { computed, isUninitialized } from '@tldraw/state'\nimport { TLShapeId } from '@tldraw/tlschema'\nimport { Editor } from '../Editor'\n\n/**\n * Non visible shapes are shapes outside of the viewport page bounds.\n *\n * @param editor - Instance of the tldraw Editor.\n * @returns Incremental derivation of non visible shapes.\n */\nexport function notVisibleShapes(editor: Editor) {\n\treturn computed<Set<TLShapeId>>('notVisibleShapes', function
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0C;AAUnC,SAAS,iBAAiB,QAAgB;AAChD,aAAO,uBAAyB,oBAAoB,
|
|
4
|
+
"sourcesContent": ["import { computed, isUninitialized } from '@tldraw/state'\nimport { TLShapeId } from '@tldraw/tlschema'\nimport { Editor } from '../Editor'\n\n/**\n * Non visible shapes are shapes outside of the viewport page bounds.\n *\n * @param editor - Instance of the tldraw Editor.\n * @returns Incremental derivation of non visible shapes.\n */\nexport function notVisibleShapes(editor: Editor) {\n\treturn computed<Set<TLShapeId>>('notVisibleShapes', function (prevValue) {\n\t\tconst allShapeIds = editor.getCurrentPageShapeIds()\n\t\tconst viewportPageBounds = editor.getViewportPageBounds()\n\t\tconst visibleIds = editor.getShapeIdsInsideBounds(viewportPageBounds)\n\n\t\tconst nextValue = new Set<TLShapeId>()\n\n\t\t// Non-visible shapes are all shapes minus visible shapes\n\t\tfor (const id of allShapeIds) {\n\t\t\tif (!visibleIds.has(id)) {\n\t\t\t\tconst shape = editor.getShape(id)\n\t\t\t\tif (!shape) continue\n\n\t\t\t\tconst canCull = editor.getShapeUtil(shape.type).canCull(shape)\n\t\t\t\tif (!canCull) continue\n\n\t\t\t\tnextValue.add(id)\n\t\t\t}\n\t\t}\n\n\t\tif (isUninitialized(prevValue) || prevValue.size !== nextValue.size) {\n\t\t\treturn nextValue\n\t\t}\n\n\t\tfor (const prev of prevValue) {\n\t\t\tif (!nextValue.has(prev)) return nextValue\n\t\t}\n\n\t\treturn prevValue\n\t})\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0C;AAUnC,SAAS,iBAAiB,QAAgB;AAChD,aAAO,uBAAyB,oBAAoB,SAAU,WAAW;AACxE,UAAM,cAAc,OAAO,uBAAuB;AAClD,UAAM,qBAAqB,OAAO,sBAAsB;AACxD,UAAM,aAAa,OAAO,wBAAwB,kBAAkB;AAEpE,UAAM,YAAY,oBAAI,IAAe;AAGrC,eAAW,MAAM,aAAa;AAC7B,UAAI,CAAC,WAAW,IAAI,EAAE,GAAG;AACxB,cAAM,QAAQ,OAAO,SAAS,EAAE;AAChC,YAAI,CAAC,MAAO;AAEZ,cAAM,UAAU,OAAO,aAAa,MAAM,IAAI,EAAE,QAAQ,KAAK;AAC7D,YAAI,CAAC,QAAS;AAEd,kBAAU,IAAI,EAAE;AAAA,MACjB;AAAA,IACD;AAEA,YAAI,8BAAgB,SAAS,KAAK,UAAU,SAAS,UAAU,MAAM;AACpE,aAAO;AAAA,IACR;AAEA,eAAW,QAAQ,WAAW;AAC7B,UAAI,CAAC,UAAU,IAAI,IAAI,EAAG,QAAO;AAAA,IAClC;AAEA,WAAO;AAAA,EACR,CAAC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var RBushIndex_exports = {};
|
|
30
|
+
__export(RBushIndex_exports, {
|
|
31
|
+
RBushIndex: () => RBushIndex
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(RBushIndex_exports);
|
|
34
|
+
var import_rbush = __toESM(require("rbush"), 1);
|
|
35
|
+
var import_Box = require("../../../primitives/Box");
|
|
36
|
+
class TldrawRBush extends import_rbush.default {
|
|
37
|
+
}
|
|
38
|
+
class RBushIndex {
|
|
39
|
+
rBush;
|
|
40
|
+
elementsInTree;
|
|
41
|
+
constructor() {
|
|
42
|
+
this.rBush = new TldrawRBush();
|
|
43
|
+
this.elementsInTree = /* @__PURE__ */ new Map();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Search for shapes within the given bounds.
|
|
47
|
+
* Returns set of shape IDs that intersect with the bounds.
|
|
48
|
+
*/
|
|
49
|
+
search(bounds) {
|
|
50
|
+
const results = this.rBush.search({
|
|
51
|
+
minX: bounds.minX,
|
|
52
|
+
minY: bounds.minY,
|
|
53
|
+
maxX: bounds.maxX,
|
|
54
|
+
maxY: bounds.maxY
|
|
55
|
+
});
|
|
56
|
+
return new Set(results.map((e) => e.id));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Insert or update a shape in the spatial index.
|
|
60
|
+
* If the shape already exists, it will be removed first to prevent duplicates.
|
|
61
|
+
*/
|
|
62
|
+
upsert(id, bounds) {
|
|
63
|
+
const existing = this.elementsInTree.get(id);
|
|
64
|
+
if (existing) {
|
|
65
|
+
this.rBush.remove(existing);
|
|
66
|
+
}
|
|
67
|
+
const element = {
|
|
68
|
+
minX: bounds.minX,
|
|
69
|
+
minY: bounds.minY,
|
|
70
|
+
maxX: bounds.maxX,
|
|
71
|
+
maxY: bounds.maxY,
|
|
72
|
+
id
|
|
73
|
+
};
|
|
74
|
+
this.rBush.insert(element);
|
|
75
|
+
this.elementsInTree.set(id, element);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Remove a shape from the spatial index.
|
|
79
|
+
*/
|
|
80
|
+
remove(id) {
|
|
81
|
+
const element = this.elementsInTree.get(id);
|
|
82
|
+
if (element) {
|
|
83
|
+
this.rBush.remove(element);
|
|
84
|
+
this.elementsInTree.delete(id);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Bulk load elements into the spatial index.
|
|
89
|
+
* More efficient than individual inserts for initial loading.
|
|
90
|
+
*/
|
|
91
|
+
bulkLoad(elements) {
|
|
92
|
+
this.rBush.load(elements);
|
|
93
|
+
for (const element of elements) {
|
|
94
|
+
this.elementsInTree.set(element.id, element);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Clear all elements from the spatial index.
|
|
99
|
+
*/
|
|
100
|
+
clear() {
|
|
101
|
+
this.rBush.clear();
|
|
102
|
+
this.elementsInTree.clear();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if a shape is in the spatial index.
|
|
106
|
+
*/
|
|
107
|
+
has(id) {
|
|
108
|
+
return this.elementsInTree.has(id);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the number of elements in the spatial index.
|
|
112
|
+
*/
|
|
113
|
+
getSize() {
|
|
114
|
+
return this.elementsInTree.size;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get all shape IDs currently in the spatial index.
|
|
118
|
+
*/
|
|
119
|
+
getAllShapeIds() {
|
|
120
|
+
return Array.from(this.elementsInTree.keys());
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get the bounds currently stored in the spatial index for a shape.
|
|
124
|
+
* Returns undefined if the shape is not in the index.
|
|
125
|
+
*/
|
|
126
|
+
getBounds(id) {
|
|
127
|
+
const element = this.elementsInTree.get(id);
|
|
128
|
+
if (!element) return void 0;
|
|
129
|
+
return new import_Box.Box(
|
|
130
|
+
element.minX,
|
|
131
|
+
element.minY,
|
|
132
|
+
element.maxX - element.minX,
|
|
133
|
+
element.maxY - element.minY
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Dispose of the spatial index.
|
|
138
|
+
* Clears all data structures to prevent memory leaks.
|
|
139
|
+
*/
|
|
140
|
+
dispose() {
|
|
141
|
+
this.clear();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=RBushIndex.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/lib/editor/managers/SpatialIndexManager/RBushIndex.ts"],
|
|
4
|
+
"sourcesContent": ["import type { TLShapeId } from '@tldraw/tlschema'\nimport RBush from 'rbush'\nimport { Box } from '../../../primitives/Box'\n\n/**\n * Element stored in the R-tree spatial index.\n * Contains bounds (minX, minY, maxX, maxY) and shape ID.\n */\nexport interface SpatialElement {\n\tminX: number\n\tminY: number\n\tmaxX: number\n\tmaxY: number\n\tid: TLShapeId\n}\n\n/**\n * Custom RBush class for tldraw shapes.\n */\nclass TldrawRBush extends RBush<SpatialElement> {}\n\n/**\n * Wrapper around RBush R-tree for efficient spatial queries.\n * Maintains a map of elements currently in the tree for efficient updates.\n */\nexport class RBushIndex {\n\tprivate rBush: TldrawRBush\n\tprivate elementsInTree: Map<TLShapeId, SpatialElement>\n\n\tconstructor() {\n\t\tthis.rBush = new TldrawRBush()\n\t\tthis.elementsInTree = new Map()\n\t}\n\n\t/**\n\t * Search for shapes within the given bounds.\n\t * Returns set of shape IDs that intersect with the bounds.\n\t */\n\tsearch(bounds: Box): Set<TLShapeId> {\n\t\tconst results = this.rBush.search({\n\t\t\tminX: bounds.minX,\n\t\t\tminY: bounds.minY,\n\t\t\tmaxX: bounds.maxX,\n\t\t\tmaxY: bounds.maxY,\n\t\t})\n\t\treturn new Set(results.map((e: SpatialElement) => e.id))\n\t}\n\n\t/**\n\t * Insert or update a shape in the spatial index.\n\t * If the shape already exists, it will be removed first to prevent duplicates.\n\t */\n\tupsert(id: TLShapeId, bounds: Box): void {\n\t\t// Remove existing entry to prevent map-tree desync\n\t\tconst existing = this.elementsInTree.get(id)\n\t\tif (existing) {\n\t\t\tthis.rBush.remove(existing)\n\t\t}\n\n\t\tconst element: SpatialElement = {\n\t\t\tminX: bounds.minX,\n\t\t\tminY: bounds.minY,\n\t\t\tmaxX: bounds.maxX,\n\t\t\tmaxY: bounds.maxY,\n\t\t\tid,\n\t\t}\n\t\tthis.rBush.insert(element)\n\t\tthis.elementsInTree.set(id, element)\n\t}\n\n\t/**\n\t * Remove a shape from the spatial index.\n\t */\n\tremove(id: TLShapeId): void {\n\t\tconst element = this.elementsInTree.get(id)\n\t\tif (element) {\n\t\t\tthis.rBush.remove(element)\n\t\t\tthis.elementsInTree.delete(id)\n\t\t}\n\t}\n\n\t/**\n\t * Bulk load elements into the spatial index.\n\t * More efficient than individual inserts for initial loading.\n\t */\n\tbulkLoad(elements: SpatialElement[]): void {\n\t\tthis.rBush.load(elements)\n\t\tfor (const element of elements) {\n\t\t\tthis.elementsInTree.set(element.id, element)\n\t\t}\n\t}\n\n\t/**\n\t * Clear all elements from the spatial index.\n\t */\n\tclear(): void {\n\t\tthis.rBush.clear()\n\t\tthis.elementsInTree.clear()\n\t}\n\n\t/**\n\t * Check if a shape is in the spatial index.\n\t */\n\thas(id: TLShapeId): boolean {\n\t\treturn this.elementsInTree.has(id)\n\t}\n\n\t/**\n\t * Get the number of elements in the spatial index.\n\t */\n\tgetSize(): number {\n\t\treturn this.elementsInTree.size\n\t}\n\n\t/**\n\t * Get all shape IDs currently in the spatial index.\n\t */\n\tgetAllShapeIds(): TLShapeId[] {\n\t\treturn Array.from(this.elementsInTree.keys())\n\t}\n\n\t/**\n\t * Get the bounds currently stored in the spatial index for a shape.\n\t * Returns undefined if the shape is not in the index.\n\t */\n\tgetBounds(id: TLShapeId): Box | undefined {\n\t\tconst element = this.elementsInTree.get(id)\n\t\tif (!element) return undefined\n\t\treturn new Box(\n\t\t\telement.minX,\n\t\t\telement.minY,\n\t\t\telement.maxX - element.minX,\n\t\t\telement.maxY - element.minY\n\t\t)\n\t}\n\n\t/**\n\t * Dispose of the spatial index.\n\t * Clears all data structures to prevent memory leaks.\n\t */\n\tdispose(): void {\n\t\tthis.clear()\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,iBAAoB;AAiBpB,MAAM,oBAAoB,aAAAA,QAAsB;AAAC;AAM1C,MAAM,WAAW;AAAA,EACf;AAAA,EACA;AAAA,EAER,cAAc;AACb,SAAK,QAAQ,IAAI,YAAY;AAC7B,SAAK,iBAAiB,oBAAI,IAAI;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,QAA6B;AACnC,UAAM,UAAU,KAAK,MAAM,OAAO;AAAA,MACjC,MAAM,OAAO;AAAA,MACb,MAAM,OAAO;AAAA,MACb,MAAM,OAAO;AAAA,MACb,MAAM,OAAO;AAAA,IACd,CAAC;AACD,WAAO,IAAI,IAAI,QAAQ,IAAI,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AE;AAC1C,QAAI,CAAC,QAAS,QAAO;AACrB,WAAO,IAAI;AAAA,MACV,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,QAAQ,OAAO,QAAQ;AAAA,MACvB,QAAQ,OAAO,QAAQ;AAAA,IACxB;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAgB;AACf,SAAK,MAAM;AAAA,EACZ;AACD;",
|
|
6
|
+
"names": ["RBush"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var SpatialIndexManager_exports = {};
|
|
20
|
+
__export(SpatialIndexManager_exports, {
|
|
21
|
+
SpatialIndexManager: () => SpatialIndexManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(SpatialIndexManager_exports);
|
|
24
|
+
var import_state = require("@tldraw/state");
|
|
25
|
+
var import_tlschema = require("@tldraw/tlschema");
|
|
26
|
+
var import_utils = require("@tldraw/utils");
|
|
27
|
+
var import_Box = require("../../../primitives/Box");
|
|
28
|
+
var import_RBushIndex = require("./RBushIndex");
|
|
29
|
+
class SpatialIndexManager {
|
|
30
|
+
constructor(editor) {
|
|
31
|
+
this.editor = editor;
|
|
32
|
+
this.rbush = new import_RBushIndex.RBushIndex();
|
|
33
|
+
this.spatialIndexComputed = this.createSpatialIndexComputed();
|
|
34
|
+
}
|
|
35
|
+
rbush;
|
|
36
|
+
spatialIndexComputed;
|
|
37
|
+
lastPageId = null;
|
|
38
|
+
createSpatialIndexComputed() {
|
|
39
|
+
const shapeHistory = this.editor.store.query.filterHistory("shape");
|
|
40
|
+
return (0, import_state.computed)("spatialIndex", (_prevValue, lastComputedEpoch) => {
|
|
41
|
+
if ((0, import_state.isUninitialized)(_prevValue)) {
|
|
42
|
+
return this.buildFromScratch(lastComputedEpoch);
|
|
43
|
+
}
|
|
44
|
+
const shapeDiff = shapeHistory.getDiffSince(lastComputedEpoch);
|
|
45
|
+
if (shapeDiff === import_state.RESET_VALUE) {
|
|
46
|
+
return this.buildFromScratch(lastComputedEpoch);
|
|
47
|
+
}
|
|
48
|
+
const currentPageId = this.editor.getCurrentPageId();
|
|
49
|
+
if (this.lastPageId !== currentPageId) {
|
|
50
|
+
return this.buildFromScratch(lastComputedEpoch);
|
|
51
|
+
}
|
|
52
|
+
if (shapeDiff.length === 0) {
|
|
53
|
+
return lastComputedEpoch;
|
|
54
|
+
}
|
|
55
|
+
this.processIncrementalUpdate(shapeDiff);
|
|
56
|
+
return lastComputedEpoch;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
buildFromScratch(epoch) {
|
|
60
|
+
this.rbush.clear();
|
|
61
|
+
this.lastPageId = this.editor.getCurrentPageId();
|
|
62
|
+
const shapes = this.editor.getCurrentPageShapes();
|
|
63
|
+
const elements = [];
|
|
64
|
+
for (const shape of shapes) {
|
|
65
|
+
const bounds = this.editor.getShapePageBounds(shape.id);
|
|
66
|
+
if (bounds) {
|
|
67
|
+
elements.push({
|
|
68
|
+
minX: bounds.minX,
|
|
69
|
+
minY: bounds.minY,
|
|
70
|
+
maxX: bounds.maxX,
|
|
71
|
+
maxY: bounds.maxY,
|
|
72
|
+
id: shape.id
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
this.rbush.bulkLoad(elements);
|
|
77
|
+
return epoch;
|
|
78
|
+
}
|
|
79
|
+
processIncrementalUpdate(shapeDiff) {
|
|
80
|
+
const processedShapeIds = /* @__PURE__ */ new Set();
|
|
81
|
+
for (const changes of shapeDiff) {
|
|
82
|
+
for (const shape of (0, import_utils.objectMapValues)(changes.added)) {
|
|
83
|
+
if ((0, import_tlschema.isShape)(shape) && this.editor.getAncestorPageId(shape) === this.lastPageId) {
|
|
84
|
+
const bounds = this.editor.getShapePageBounds(shape.id);
|
|
85
|
+
if (bounds) {
|
|
86
|
+
this.rbush.upsert(shape.id, bounds);
|
|
87
|
+
}
|
|
88
|
+
processedShapeIds.add(shape.id);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const shape of (0, import_utils.objectMapValues)(changes.removed)) {
|
|
92
|
+
if ((0, import_tlschema.isShape)(shape)) {
|
|
93
|
+
this.rbush.remove(shape.id);
|
|
94
|
+
processedShapeIds.add(shape.id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const [, to] of (0, import_utils.objectMapValues)(changes.updated)) {
|
|
98
|
+
if (!(0, import_tlschema.isShape)(to)) continue;
|
|
99
|
+
processedShapeIds.add(to.id);
|
|
100
|
+
const isOnPage = this.editor.getAncestorPageId(to) === this.lastPageId;
|
|
101
|
+
if (isOnPage) {
|
|
102
|
+
const bounds = this.editor.getShapePageBounds(to.id);
|
|
103
|
+
if (bounds) {
|
|
104
|
+
this.rbush.upsert(to.id, bounds);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
this.rbush.remove(to.id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const allShapeIds = this.rbush.getAllShapeIds();
|
|
112
|
+
for (const shapeId of allShapeIds) {
|
|
113
|
+
if (processedShapeIds.has(shapeId)) continue;
|
|
114
|
+
const currentBounds = this.editor.getShapePageBounds(shapeId);
|
|
115
|
+
const indexedBounds = this.rbush.getBounds(shapeId);
|
|
116
|
+
if (!this.areBoundsEqual(currentBounds, indexedBounds)) {
|
|
117
|
+
if (currentBounds) {
|
|
118
|
+
this.rbush.upsert(shapeId, currentBounds);
|
|
119
|
+
} else {
|
|
120
|
+
this.rbush.remove(shapeId);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
areBoundsEqual(a, b) {
|
|
126
|
+
if (!a && !b) return true;
|
|
127
|
+
if (!a || !b) return false;
|
|
128
|
+
return a.minX === b.minX && a.minY === b.minY && a.maxX === b.maxX && a.maxY === b.maxY;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get shape IDs within the given bounds.
|
|
132
|
+
* Optimized for viewport culling queries.
|
|
133
|
+
*
|
|
134
|
+
* Note: Results are unordered. If you need z-order, combine with sorted shapes:
|
|
135
|
+
* ```ts
|
|
136
|
+
* const candidates = editor.spatialIndex.getShapeIdsInsideBounds(bounds)
|
|
137
|
+
* const sorted = editor.getCurrentPageShapesSorted().filter(s => candidates.has(s.id))
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @param bounds - The bounds to search within
|
|
141
|
+
* @returns Unordered set of shape IDs within the bounds
|
|
142
|
+
*
|
|
143
|
+
* @public
|
|
144
|
+
*/
|
|
145
|
+
getShapeIdsInsideBounds(bounds) {
|
|
146
|
+
this.spatialIndexComputed.get();
|
|
147
|
+
return this.rbush.search(bounds);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get shape IDs at a point (with optional margin).
|
|
151
|
+
* Creates a small bounding box around the point and searches the spatial index.
|
|
152
|
+
*
|
|
153
|
+
* Note: Results are unordered. If you need z-order, combine with sorted shapes:
|
|
154
|
+
* ```ts
|
|
155
|
+
* const candidates = editor.spatialIndex.getShapeIdsAtPoint(point, margin)
|
|
156
|
+
* const sorted = editor.getCurrentPageShapesSorted().filter(s => candidates.has(s.id))
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* @param point - The point to search at
|
|
160
|
+
* @param margin - The margin around the point to search (default: 0)
|
|
161
|
+
* @returns Unordered set of shape IDs that could potentially contain the point
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
getShapeIdsAtPoint(point, margin = 0) {
|
|
166
|
+
this.spatialIndexComputed.get();
|
|
167
|
+
return this.rbush.search(new import_Box.Box(point.x - margin, point.y - margin, margin * 2, margin * 2));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Dispose of the spatial index manager.
|
|
171
|
+
* Clears the R-tree to prevent memory leaks.
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
dispose() {
|
|
176
|
+
this.rbush.dispose();
|
|
177
|
+
this.lastPageId = null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=SpatialIndexManager.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts"],
|
|
4
|
+
"sourcesContent": ["import { Computed, RESET_VALUE, computed, isUninitialized } from '@tldraw/state'\nimport type { RecordsDiff } from '@tldraw/store'\nimport type { TLRecord } from '@tldraw/tlschema'\nimport { TLPageId, TLShape, TLShapeId, isShape } from '@tldraw/tlschema'\nimport { objectMapValues } from '@tldraw/utils'\nimport { Box } from '../../../primitives/Box'\nimport type { Editor } from '../../Editor'\nimport { RBushIndex, type SpatialElement } from './RBushIndex'\n\n/**\n * Manages spatial indexing for efficient shape location queries.\n *\n * Uses an R-tree (via RBush) to enable O(log n) spatial queries instead of O(n) iteration.\n * Handles shapes with computed bounds (arrows, groups, custom shapes) by checking all shapes'\n * bounds on each update using the reactive bounds cache.\n *\n * Key features:\n * - Incremental updates using filterHistory pattern\n * - Leverages existing bounds cache reactivity for dependency tracking\n * - Works with any custom shape type with computed bounds\n * - Per-page index (rebuilds on page change)\n * - Optimized for viewport culling queries\n *\n * @internal\n */\nexport class SpatialIndexManager {\n\tprivate rbush: RBushIndex\n\tprivate spatialIndexComputed: Computed<number>\n\tprivate lastPageId: TLPageId | null = null\n\n\tconstructor(public readonly editor: Editor) {\n\t\tthis.rbush = new RBushIndex()\n\t\tthis.spatialIndexComputed = this.createSpatialIndexComputed()\n\t}\n\n\tprivate createSpatialIndexComputed() {\n\t\tconst shapeHistory = this.editor.store.query.filterHistory('shape')\n\n\t\treturn computed<number>('spatialIndex', (_prevValue, lastComputedEpoch) => {\n\t\t\tif (isUninitialized(_prevValue)) {\n\t\t\t\treturn this.buildFromScratch(lastComputedEpoch)\n\t\t\t}\n\n\t\t\tconst shapeDiff = shapeHistory.getDiffSince(lastComputedEpoch)\n\n\t\t\tif (shapeDiff === RESET_VALUE) {\n\t\t\t\treturn this.buildFromScratch(lastComputedEpoch)\n\t\t\t}\n\n\t\t\tconst currentPageId = this.editor.getCurrentPageId()\n\t\t\tif (this.lastPageId !== currentPageId) {\n\t\t\t\treturn this.buildFromScratch(lastComputedEpoch)\n\t\t\t}\n\n\t\t\t// No shape changes - index is already up to date\n\t\t\tif (shapeDiff.length === 0) {\n\t\t\t\treturn lastComputedEpoch\n\t\t\t}\n\n\t\t\t// Process incremental updates\n\t\t\tthis.processIncrementalUpdate(shapeDiff)\n\n\t\t\treturn lastComputedEpoch\n\t\t})\n\t}\n\n\tprivate buildFromScratch(epoch: number): number {\n\t\tthis.rbush.clear()\n\t\tthis.lastPageId = this.editor.getCurrentPageId()\n\n\t\tconst shapes = this.editor.getCurrentPageShapes()\n\t\tconst elements: SpatialElement[] = []\n\n\t\t// Collect all shape elements for bulk loading\n\t\tfor (const shape of shapes) {\n\t\t\tconst bounds = this.editor.getShapePageBounds(shape.id)\n\t\t\tif (bounds) {\n\t\t\t\telements.push({\n\t\t\t\t\tminX: bounds.minX,\n\t\t\t\t\tminY: bounds.minY,\n\t\t\t\t\tmaxX: bounds.maxX,\n\t\t\t\t\tmaxY: bounds.maxY,\n\t\t\t\t\tid: shape.id,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\t// Bulk load for efficiency\n\t\tthis.rbush.bulkLoad(elements)\n\n\t\treturn epoch\n\t}\n\n\tprivate processIncrementalUpdate(shapeDiff: RecordsDiff<TLRecord>[]): void {\n\t\t// Track shapes we've already processed from the diff\n\t\tconst processedShapeIds = new Set<TLShapeId>()\n\n\t\t// 1. Process shape additions, removals, and updates from diff\n\t\tfor (const changes of shapeDiff) {\n\t\t\t// Handle additions (only for shapes on current page)\n\t\t\tfor (const shape of objectMapValues(changes.added) as TLShape[]) {\n\t\t\t\tif (isShape(shape) && this.editor.getAncestorPageId(shape) === this.lastPageId) {\n\t\t\t\t\tconst bounds = this.editor.getShapePageBounds(shape.id)\n\t\t\t\t\tif (bounds) {\n\t\t\t\t\t\tthis.rbush.upsert(shape.id, bounds)\n\t\t\t\t\t}\n\t\t\t\t\tprocessedShapeIds.add(shape.id)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle removals\n\t\t\tfor (const shape of objectMapValues(changes.removed) as TLShape[]) {\n\t\t\t\tif (isShape(shape)) {\n\t\t\t\t\tthis.rbush.remove(shape.id)\n\t\t\t\t\tprocessedShapeIds.add(shape.id)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle updated shapes: page changes and bounds updates\n\t\t\tfor (const [, to] of objectMapValues(changes.updated) as [TLShape, TLShape][]) {\n\t\t\t\tif (!isShape(to)) continue\n\t\t\t\tprocessedShapeIds.add(to.id)\n\n\t\t\t\tconst isOnPage = this.editor.getAncestorPageId(to) === this.lastPageId\n\n\t\t\t\tif (isOnPage) {\n\t\t\t\t\tconst bounds = this.editor.getShapePageBounds(to.id)\n\t\t\t\t\tif (bounds) {\n\t\t\t\t\t\tthis.rbush.upsert(to.id, bounds)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthis.rbush.remove(to.id)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// 2. Check remaining shapes in index for bounds changes\n\t\t// This handles shapes with computed bounds (arrows bound to moved shapes, groups with moved children, etc.)\n\t\tconst allShapeIds = this.rbush.getAllShapeIds()\n\n\t\tfor (const shapeId of allShapeIds) {\n\t\t\tif (processedShapeIds.has(shapeId)) continue\n\n\t\t\tconst currentBounds = this.editor.getShapePageBounds(shapeId)\n\t\t\tconst indexedBounds = this.rbush.getBounds(shapeId)\n\n\t\t\tif (!this.areBoundsEqual(currentBounds, indexedBounds)) {\n\t\t\t\tif (currentBounds) {\n\t\t\t\t\tthis.rbush.upsert(shapeId, currentBounds)\n\t\t\t\t} else {\n\t\t\t\t\tthis.rbush.remove(shapeId)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate areBoundsEqual(a: Box | undefined, b: Box | undefined): boolean {\n\t\tif (!a && !b) return true\n\t\tif (!a || !b) return false\n\t\treturn a.minX === b.minX && a.minY === b.minY && a.maxX === b.maxX && a.maxY === b.maxY\n\t}\n\n\t/**\n\t * Get shape IDs within the given bounds.\n\t * Optimized for viewport culling queries.\n\t *\n\t * Note: Results are unordered. If you need z-order, combine with sorted shapes:\n\t * ```ts\n\t * const candidates = editor.spatialIndex.getShapeIdsInsideBounds(bounds)\n\t * const sorted = editor.getCurrentPageShapesSorted().filter(s => candidates.has(s.id))\n\t * ```\n\t *\n\t * @param bounds - The bounds to search within\n\t * @returns Unordered set of shape IDs within the bounds\n\t *\n\t * @public\n\t */\n\tgetShapeIdsInsideBounds(bounds: Box): Set<TLShapeId> {\n\t\tthis.spatialIndexComputed.get()\n\t\treturn this.rbush.search(bounds)\n\t}\n\n\t/**\n\t * Get shape IDs at a point (with optional margin).\n\t * Creates a small bounding box around the point and searches the spatial index.\n\t *\n\t * Note: Results are unordered. If you need z-order, combine with sorted shapes:\n\t * ```ts\n\t * const candidates = editor.spatialIndex.getShapeIdsAtPoint(point, margin)\n\t * const sorted = editor.getCurrentPageShapesSorted().filter(s => candidates.has(s.id))\n\t * ```\n\t *\n\t * @param point - The point to search at\n\t * @param margin - The margin around the point to search (default: 0)\n\t * @returns Unordered set of shape IDs that could potentially contain the point\n\t *\n\t * @public\n\t */\n\tgetShapeIdsAtPoint(point: { x: number; y: number }, margin = 0): Set<TLShapeId> {\n\t\tthis.spatialIndexComputed.get()\n\t\treturn this.rbush.search(new Box(point.x - margin, point.y - margin, margin * 2, margin * 2))\n\t}\n\n\t/**\n\t * Dispose of the spatial index manager.\n\t * Clears the R-tree to prevent memory leaks.\n\t *\n\t * @public\n\t */\n\tdispose(): void {\n\t\tthis.rbush.dispose()\n\t\tthis.lastPageId = null\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiE;AAGjE,sBAAsD;AACtD,mBAAgC;AAChC,iBAAoB;AAEpB,wBAAgD;AAkBzC,MAAM,oBAAoB;AAAA,EAKhC,YAA4B,QAAgB;AAAhB;AAC3B,SAAK,QAAQ,IAAI,6BAAW;AAC5B,SAAK,uBAAuB,KAAK,2BAA2B;AAAA,EAC7D;AAAA,EAPQ;AAAA,EACA;AAAA,EACA,aAA8B;AAAA,EAO9B,6BAA6B;AACpC,UAAM,eAAe,KAAK,OAAO,MAAM,MAAM,cAAc,OAAO;AAElE,eAAO,uBAAiB,gBAAgB,CAAC,YAAY,sBAAsB;AAC1E,cAAI,8BAAgB,UAAU,GAAG;AAChC,eAAO,KAAK,iBAAiB,iBAAiB;AAAA,MAC/C;AAEA,YAAM,YAAY,aAAa,aAAa,iBAAiB;AAE7D,UAAI,cAAc,0BAAa;AAC9B,eAAO,KAAK,iBAAiB,iBAAiB;AAAA,MAC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6B;AACpD,SAAK,qBAAqB,IAAI;AAC9B,WAAO,KAAK,MAAM,OAAO,MAAM;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,mBAAmB,OAAiC,SAAS,GAAmB;AAC/E,SAAK,qBAAqB,IAAI;AAC9B,WAAO,KAAK,MAAM,OAAO,IAAI,eAAI,MAAM,IAAI,QAAQ,MAAM,IAAI,QAAQ,SAAS,GAAG,SAAS,CAAC,CAAC;AAAA,EAC7F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAgB;AACf,SAAK,MAAM,QAAQ;AACnB,SAAK,aAAa;AAAA,EACnB;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -69,8 +69,8 @@ __export(UserPreferencesManager_exports, {
|
|
|
69
69
|
module.exports = __toCommonJS(UserPreferencesManager_exports);
|
|
70
70
|
var import_state = require("@tldraw/state");
|
|
71
71
|
var import_TLUserPreferences = require("../../../config/TLUserPreferences");
|
|
72
|
-
var _getInputMode_dec, _getEnhancedA11yMode_dec, _getIsPasteAtCursorMode_dec, _getIsDynamicResizeMode_dec, _getIsWrapMode_dec, _getIsSnapMode_dec, _getColor_dec, _getLocale_dec, _getName_dec, _getId_dec, _getAreKeyboardShortcutsEnabled_dec, _getAnimationSpeed_dec, _getEdgeScrollSpeed_dec, _getIsDarkMode_dec, _getUserPreferences_dec, _init;
|
|
73
|
-
_getUserPreferences_dec = [import_state.computed], _getIsDarkMode_dec = [import_state.computed], _getEdgeScrollSpeed_dec = [import_state.computed], _getAnimationSpeed_dec = [import_state.computed], _getAreKeyboardShortcutsEnabled_dec = [import_state.computed], _getId_dec = [import_state.computed], _getName_dec = [import_state.computed], _getLocale_dec = [import_state.computed], _getColor_dec = [import_state.computed], _getIsSnapMode_dec = [import_state.computed], _getIsWrapMode_dec = [import_state.computed], _getIsDynamicResizeMode_dec = [import_state.computed], _getIsPasteAtCursorMode_dec = [import_state.computed], _getEnhancedA11yMode_dec = [import_state.computed], _getInputMode_dec = [import_state.computed];
|
|
72
|
+
var _getIsZoomDirectionInverted_dec, _getInputMode_dec, _getEnhancedA11yMode_dec, _getIsPasteAtCursorMode_dec, _getIsDynamicResizeMode_dec, _getIsWrapMode_dec, _getIsSnapMode_dec, _getColor_dec, _getLocale_dec, _getName_dec, _getId_dec, _getAreKeyboardShortcutsEnabled_dec, _getAnimationSpeed_dec, _getEdgeScrollSpeed_dec, _getIsDarkMode_dec, _getUserPreferences_dec, _init;
|
|
73
|
+
_getUserPreferences_dec = [import_state.computed], _getIsDarkMode_dec = [import_state.computed], _getEdgeScrollSpeed_dec = [import_state.computed], _getAnimationSpeed_dec = [import_state.computed], _getAreKeyboardShortcutsEnabled_dec = [import_state.computed], _getId_dec = [import_state.computed], _getName_dec = [import_state.computed], _getLocale_dec = [import_state.computed], _getColor_dec = [import_state.computed], _getIsSnapMode_dec = [import_state.computed], _getIsWrapMode_dec = [import_state.computed], _getIsDynamicResizeMode_dec = [import_state.computed], _getIsPasteAtCursorMode_dec = [import_state.computed], _getEnhancedA11yMode_dec = [import_state.computed], _getInputMode_dec = [import_state.computed], _getIsZoomDirectionInverted_dec = [import_state.computed];
|
|
74
74
|
class UserPreferencesManager {
|
|
75
75
|
constructor(user, inferDarkMode) {
|
|
76
76
|
this.user = user;
|
|
@@ -116,7 +116,8 @@ class UserPreferencesManager {
|
|
|
116
116
|
isWrapMode: this.getIsWrapMode(),
|
|
117
117
|
isDynamicResizeMode: this.getIsDynamicResizeMode(),
|
|
118
118
|
enhancedA11yMode: this.getEnhancedA11yMode(),
|
|
119
|
-
inputMode: this.getInputMode()
|
|
119
|
+
inputMode: this.getInputMode(),
|
|
120
|
+
isZoomDirectionInverted: this.getIsZoomDirectionInverted()
|
|
120
121
|
};
|
|
121
122
|
}
|
|
122
123
|
getIsDarkMode() {
|
|
@@ -170,6 +171,9 @@ class UserPreferencesManager {
|
|
|
170
171
|
getInputMode() {
|
|
171
172
|
return this.user.userPreferences.get().inputMode ?? import_TLUserPreferences.defaultUserPreferences.inputMode;
|
|
172
173
|
}
|
|
174
|
+
getIsZoomDirectionInverted() {
|
|
175
|
+
return this.user.userPreferences.get().isZoomDirectionInverted ?? import_TLUserPreferences.defaultUserPreferences.isZoomDirectionInverted;
|
|
176
|
+
}
|
|
173
177
|
}
|
|
174
178
|
_init = __decoratorStart(null);
|
|
175
179
|
__decorateElement(_init, 1, "getUserPreferences", _getUserPreferences_dec, UserPreferencesManager);
|
|
@@ -187,5 +191,6 @@ __decorateElement(_init, 1, "getIsDynamicResizeMode", _getIsDynamicResizeMode_de
|
|
|
187
191
|
__decorateElement(_init, 1, "getIsPasteAtCursorMode", _getIsPasteAtCursorMode_dec, UserPreferencesManager);
|
|
188
192
|
__decorateElement(_init, 1, "getEnhancedA11yMode", _getEnhancedA11yMode_dec, UserPreferencesManager);
|
|
189
193
|
__decorateElement(_init, 1, "getInputMode", _getInputMode_dec, UserPreferencesManager);
|
|
194
|
+
__decorateElement(_init, 1, "getIsZoomDirectionInverted", _getIsZoomDirectionInverted_dec, UserPreferencesManager);
|
|
190
195
|
__decoratorMetadata(_init, UserPreferencesManager);
|
|
191
196
|
//# sourceMappingURL=UserPreferencesManager.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts"],
|
|
4
|
-
"sourcesContent": ["import { atom, computed } from '@tldraw/state'\nimport { TLUserPreferences, defaultUserPreferences } from '../../../config/TLUserPreferences'\nimport { TLUser } from '../../../config/createTLUser'\n\n/** @public */\nexport class UserPreferencesManager {\n\tsystemColorScheme = atom<'dark' | 'light'>('systemColorScheme', 'light')\n\tdisposables = new Set<() => void>()\n\tdispose() {\n\t\tthis.disposables.forEach((d) => d())\n\t}\n\tconstructor(\n\t\tprivate readonly user: TLUser,\n\t\tprivate readonly inferDarkMode: boolean\n\t) {\n\t\tif (typeof window === 'undefined' || !window.matchMedia) return\n\n\t\tconst darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')\n\t\tif (darkModeMediaQuery?.matches) {\n\t\t\tthis.systemColorScheme.set('dark')\n\t\t}\n\t\tconst handleChange = (e: MediaQueryListEvent) => {\n\t\t\tif (e.matches) {\n\t\t\t\tthis.systemColorScheme.set('dark')\n\t\t\t} else {\n\t\t\t\tthis.systemColorScheme.set('light')\n\t\t\t}\n\t\t}\n\t\tdarkModeMediaQuery?.addEventListener('change', handleChange)\n\t\tthis.disposables.add(() => darkModeMediaQuery?.removeEventListener('change', handleChange))\n\t}\n\n\tupdateUserPreferences(userPreferences: Partial<TLUserPreferences>) {\n\t\tthis.user.setUserPreferences({\n\t\t\t...this.user.userPreferences.get(),\n\t\t\t...userPreferences,\n\t\t})\n\t}\n\t@computed getUserPreferences() {\n\t\treturn {\n\t\t\tid: this.getId(),\n\t\t\tname: this.getName(),\n\t\t\tlocale: this.getLocale(),\n\t\t\tcolor: this.getColor(),\n\t\t\tanimationSpeed: this.getAnimationSpeed(),\n\t\t\tareKeyboardShortcutsEnabled: this.getAreKeyboardShortcutsEnabled(),\n\t\t\tisSnapMode: this.getIsSnapMode(),\n\t\t\tcolorScheme: this.user.userPreferences.get().colorScheme,\n\t\t\tisDarkMode: this.getIsDarkMode(),\n\t\t\tisWrapMode: this.getIsWrapMode(),\n\t\t\tisDynamicResizeMode: this.getIsDynamicResizeMode(),\n\t\t\tenhancedA11yMode: this.getEnhancedA11yMode(),\n\t\t\tinputMode: this.getInputMode(),\n\t\t}\n\t}\n\n\t@computed getIsDarkMode() {\n\t\tswitch (this.user.userPreferences.get().colorScheme) {\n\t\t\tcase 'dark':\n\t\t\t\treturn true\n\t\t\tcase 'light':\n\t\t\t\treturn false\n\t\t\tcase 'system':\n\t\t\t\treturn this.systemColorScheme.get() === 'dark'\n\t\t\tdefault:\n\t\t\t\treturn this.inferDarkMode ? this.systemColorScheme.get() === 'dark' : false\n\t\t}\n\t}\n\n\t/**\n\t * The speed at which the user can scroll by dragging toward the edge of the screen.\n\t */\n\t@computed getEdgeScrollSpeed() {\n\t\treturn this.user.userPreferences.get().edgeScrollSpeed ?? defaultUserPreferences.edgeScrollSpeed\n\t}\n\n\t@computed getAnimationSpeed() {\n\t\treturn this.user.userPreferences.get().animationSpeed ?? defaultUserPreferences.animationSpeed\n\t}\n\n\t@computed getAreKeyboardShortcutsEnabled() {\n\t\treturn (\n\t\t\tthis.user.userPreferences.get().areKeyboardShortcutsEnabled ??\n\t\t\tdefaultUserPreferences.areKeyboardShortcutsEnabled\n\t\t)\n\t}\n\n\t@computed getId() {\n\t\treturn this.user.userPreferences.get().id\n\t}\n\n\t@computed getName() {\n\t\treturn this.user.userPreferences.get().name?.trim() ?? defaultUserPreferences.name\n\t}\n\n\t@computed getLocale() {\n\t\treturn this.user.userPreferences.get().locale ?? defaultUserPreferences.locale\n\t}\n\n\t@computed getColor() {\n\t\treturn this.user.userPreferences.get().color ?? defaultUserPreferences.color\n\t}\n\n\t@computed getIsSnapMode() {\n\t\treturn this.user.userPreferences.get().isSnapMode ?? defaultUserPreferences.isSnapMode\n\t}\n\n\t@computed getIsWrapMode() {\n\t\treturn this.user.userPreferences.get().isWrapMode ?? defaultUserPreferences.isWrapMode\n\t}\n\n\t@computed getIsDynamicResizeMode() {\n\t\treturn (\n\t\t\tthis.user.userPreferences.get().isDynamicSizeMode ?? defaultUserPreferences.isDynamicSizeMode\n\t\t)\n\t}\n\n\t@computed getIsPasteAtCursorMode() {\n\t\treturn (\n\t\t\tthis.user.userPreferences.get().isPasteAtCursorMode ??\n\t\t\tdefaultUserPreferences.isPasteAtCursorMode\n\t\t)\n\t}\n\n\t@computed getEnhancedA11yMode() {\n\t\treturn (\n\t\t\tthis.user.userPreferences.get().enhancedA11yMode ?? defaultUserPreferences.enhancedA11yMode\n\t\t)\n\t}\n\n\t@computed getInputMode() {\n\t\treturn this.user.userPreferences.get().inputMode ?? defaultUserPreferences.inputMode\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,+BAA0D;AAD1D;AAsCC,2BAAC,
|
|
4
|
+
"sourcesContent": ["import { atom, computed } from '@tldraw/state'\nimport { TLUserPreferences, defaultUserPreferences } from '../../../config/TLUserPreferences'\nimport { TLUser } from '../../../config/createTLUser'\n\n/** @public */\nexport class UserPreferencesManager {\n\tsystemColorScheme = atom<'dark' | 'light'>('systemColorScheme', 'light')\n\tdisposables = new Set<() => void>()\n\tdispose() {\n\t\tthis.disposables.forEach((d) => d())\n\t}\n\tconstructor(\n\t\tprivate readonly user: TLUser,\n\t\tprivate readonly inferDarkMode: boolean\n\t) {\n\t\tif (typeof window === 'undefined' || !window.matchMedia) return\n\n\t\tconst darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')\n\t\tif (darkModeMediaQuery?.matches) {\n\t\t\tthis.systemColorScheme.set('dark')\n\t\t}\n\t\tconst handleChange = (e: MediaQueryListEvent) => {\n\t\t\tif (e.matches) {\n\t\t\t\tthis.systemColorScheme.set('dark')\n\t\t\t} else {\n\t\t\t\tthis.systemColorScheme.set('light')\n\t\t\t}\n\t\t}\n\t\tdarkModeMediaQuery?.addEventListener('change', handleChange)\n\t\tthis.disposables.add(() => darkModeMediaQuery?.removeEventListener('change', handleChange))\n\t}\n\n\tupdateUserPreferences(userPreferences: Partial<TLUserPreferences>) {\n\t\tthis.user.setUserPreferences({\n\t\t\t...this.user.userPreferences.get(),\n\t\t\t...userPreferences,\n\t\t})\n\t}\n\t@computed getUserPreferences() {\n\t\treturn {\n\t\t\tid: this.getId(),\n\t\t\tname: this.getName(),\n\t\t\tlocale: this.getLocale(),\n\t\t\tcolor: this.getColor(),\n\t\t\tanimationSpeed: this.getAnimationSpeed(),\n\t\t\tareKeyboardShortcutsEnabled: this.getAreKeyboardShortcutsEnabled(),\n\t\t\tisSnapMode: this.getIsSnapMode(),\n\t\t\tcolorScheme: this.user.userPreferences.get().colorScheme,\n\t\t\tisDarkMode: this.getIsDarkMode(),\n\t\t\tisWrapMode: this.getIsWrapMode(),\n\t\t\tisDynamicResizeMode: this.getIsDynamicResizeMode(),\n\t\t\tenhancedA11yMode: this.getEnhancedA11yMode(),\n\t\t\tinputMode: this.getInputMode(),\n\t\t\tisZoomDirectionInverted: this.getIsZoomDirectionInverted(),\n\t\t}\n\t}\n\n\t@computed getIsDarkMode() {\n\t\tswitch (this.user.userPreferences.get().colorScheme) {\n\t\t\tcase 'dark':\n\t\t\t\treturn true\n\t\t\tcase 'light':\n\t\t\t\treturn false\n\t\t\tcase 'system':\n\t\t\t\treturn this.systemColorScheme.get() === 'dark'\n\t\t\tdefault:\n\t\t\t\treturn this.inferDarkMode ? this.systemColorScheme.get() === 'dark' : false\n\t\t}\n\t}\n\n\t/**\n\t * The speed at which the user can scroll by dragging toward the edge of the screen.\n\t */\n\t@computed getEdgeScrollSpeed() {\n\t\treturn this.user.userPreferences.get().edgeScrollSpeed ?? defaultUserPreferences.edgeScrollSpeed\n\t}\n\n\t@computed getAnimationSpeed() {\n\t\treturn this.user.userPreferences.get().animationSpeed ?? defaultUserPreferences.animationSpeed\n\t}\n\n\t@computed getAreKeyboardShortcutsEnabled() {\n\t\treturn (\n\t\t\tthis.user.userPreferences.get().areKeyboardShortcutsEnabled ??\n\t\t\tdefaultUserPreferences.areKeyboardShortcutsEnabled\n\t\t)\n\t}\n\n\t@computed getId() {\n\t\treturn this.user.userPreferences.get().id\n\t}\n\n\t@computed getName() {\n\t\treturn this.user.userPreferences.get().name?.trim() ?? defaultUserPreferences.name\n\t}\n\n\t@computed getLocale() {\n\t\treturn this.user.userPreferences.get().locale ?? defaultUserPreferences.locale\n\t}\n\n\t@computed getColor() {\n\t\treturn this.user.userPreferences.get().color ?? defaultUserPreferences.color\n\t}\n\n\t@computed getIsSnapMode() {\n\t\treturn this.user.userPreferences.get().isSnapMode ?? defaultUserPreferences.isSnapMode\n\t}\n\n\t@computed getIsWrapMode() {\n\t\treturn this.user.userPreferences.get().isWrapMode ?? defaultUserPreferences.isWrapMode\n\t}\n\n\t@computed getIsDynamicResizeMode() {\n\t\treturn (\n\t\t\tthis.user.userPreferences.get().isDynamicSizeMode ?? defaultUserPreferences.isDynamicSizeMode\n\t\t)\n\t}\n\n\t@computed getIsPasteAtCursorMode() {\n\t\treturn (\n\t\t\tthis.user.userPreferences.get().isPasteAtCursorMode ??\n\t\t\tdefaultUserPreferences.isPasteAtCursorMode\n\t\t)\n\t}\n\n\t@computed getEnhancedA11yMode() {\n\t\treturn (\n\t\t\tthis.user.userPreferences.get().enhancedA11yMode ?? defaultUserPreferences.enhancedA11yMode\n\t\t)\n\t}\n\n\t@computed getInputMode() {\n\t\treturn this.user.userPreferences.get().inputMode ?? defaultUserPreferences.inputMode\n\t}\n\n\t@computed getIsZoomDirectionInverted() {\n\t\treturn (\n\t\t\tthis.user.userPreferences.get().isZoomDirectionInverted ??\n\t\t\tdefaultUserPreferences.isZoomDirectionInverted\n\t\t)\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,+BAA0D;AAD1D;AAsCC,2BAAC,wBAmBD,sBAAC,wBAgBD,2BAAC,wBAID,0BAAC,wBAID,uCAAC,wBAOD,cAAC,wBAID,gBAAC,wBAID,kBAAC,wBAID,iBAAC,wBAID,sBAAC,wBAID,sBAAC,wBAID,+BAAC,wBAMD,+BAAC,wBAOD,4BAAC,wBAMD,qBAAC,wBAID,mCAAC;AAlIK,MAAM,uBAAuB;AAAA,EAMnC,YACkB,MACA,eAChB;AAFgB;A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AAAA,EAEU,yBAAyB;AAClC,WACC,KAAK,KAAK,gBAAgB,IAAI,EAAE,uBAChC,gDAAuB;AAAA,EAEzB;AAAA,EAEU,sBAAsB;AAC/B,WACC,KAAK,KAAK,gBAAgB,IAAI,EAAE,oBAAoB,gDAAuB;AAAA,EAE7E;AAAA,EAEU,eAAe;AACxB,WAAO,KAAK,KAAK,gBAAgB,IAAI,EAAE,aAAa,gDAAuB;AAAA,EAC5E;AAAA,EAEU,6BAA6B;AACtC,WACC,KAAK,KAAK,gBAAgB,IAAI,EAAE,2BAChC,gDAAuB;AAAA,EAEzB;AACD;AAxIO;AAiCI,kDAAV,yBAjCY;AAoDF,6CAAV,oBApDY;AAoEF,kDAAV,yBApEY;AAwEF,iDAAV,wBAxEY;AA4EF,8DAAV,qCA5EY;AAmFF,qCAAV,YAnFY;AAuFF,uCAAV,cAvFY;AA2FF,yCAAV,gBA3FY;AA+FF,wCAAV,eA/FY;AAmGF,6CAAV,oBAnGY;AAuGF,6CAAV,oBAvGY;AA2GF,sDAAV,6BA3GY;AAiHF,sDAAV,6BAjHY;AAwHF,mDAAV,0BAxHY;AA8HF,4CAAV,mBA9HY;AAkIF,0DAAV,iCAlIY;AAAN,2BAAM;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-cjs/version.js
CHANGED
|
@@ -22,10 +22,10 @@ __export(version_exports, {
|
|
|
22
22
|
version: () => version
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(version_exports);
|
|
25
|
-
const version = "4.
|
|
25
|
+
const version = "4.4.0-canary.15cff7ea86f8";
|
|
26
26
|
const publishDates = {
|
|
27
27
|
major: "2025-09-18T14:39:22.803Z",
|
|
28
|
-
minor: "2026-01-
|
|
29
|
-
patch: "2026-01-
|
|
28
|
+
minor: "2026-01-26T14:52:43.591Z",
|
|
29
|
+
patch: "2026-01-26T14:52:43.591Z"
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=version.js.map
|
package/dist-cjs/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.
|
|
4
|
+
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.4.0-canary.15cff7ea86f8'\nexport const publishDates = {\n\tmajor: '2025-09-18T14:39:22.803Z',\n\tminor: '2026-01-26T14:52:43.591Z',\n\tpatch: '2026-01-26T14:52:43.591Z',\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-esm/index.d.mts
CHANGED
|
@@ -931,6 +931,7 @@ export declare const defaultUserPreferences: Readonly<{
|
|
|
931
931
|
isPasteAtCursorMode: false;
|
|
932
932
|
isSnapMode: false;
|
|
933
933
|
isWrapMode: false;
|
|
934
|
+
isZoomDirectionInverted: false;
|
|
934
935
|
locale: "ar" | "bn" | "ca" | "cs" | "da" | "de" | "el" | "en" | "es" | "fa" | "fi" | "fr" | "gl" | "gu-in" | "he" | "hi-in" | "hr" | "hu" | "id" | "it" | "ja" | "km-kh" | "kn" | "ko-kr" | "ml" | "mr" | "ms" | "ne" | "nl" | "no" | "pa" | "pl" | "pt-br" | "pt-pt" | "ro" | "ru" | "sl" | "so" | "sv" | "ta" | "te" | "th" | "tl" | "tr" | "uk" | "ur" | "vi" | "zh-cn" | "zh-tw";
|
|
935
936
|
name: "";
|
|
936
937
|
}>;
|
|
@@ -1072,6 +1073,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
1072
1073
|
* @public
|
|
1073
1074
|
*/
|
|
1074
1075
|
readonly snaps: SnapManager;
|
|
1076
|
+
private readonly _spatialIndex;
|
|
1075
1077
|
/**
|
|
1076
1078
|
* A manager for the any asynchronous events and making sure they're
|
|
1077
1079
|
* cleaned up upon disposal.
|
|
@@ -2708,6 +2710,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
2708
2710
|
*/
|
|
2709
2711
|
getNotVisibleShapes(): Set<TLShapeId>;
|
|
2710
2712
|
private _notVisibleShapes;
|
|
2713
|
+
private _culledShapesCache;
|
|
2711
2714
|
/**
|
|
2712
2715
|
* Get culled shapes (those that should not render), taking into account which shapes are selected or editing.
|
|
2713
2716
|
*
|
|
@@ -2757,6 +2760,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
2757
2760
|
hitInside?: boolean;
|
|
2758
2761
|
margin?: number;
|
|
2759
2762
|
}): TLShape[];
|
|
2763
|
+
/* Excluded from this release type: getShapeIdsInsideBounds */
|
|
2760
2764
|
/**
|
|
2761
2765
|
* Test whether a point (in the current page space) will will a shape. This method takes into account masks,
|
|
2762
2766
|
* such as when a shape is the child of a frame and is partially clipped by the frame.
|
|
@@ -6077,6 +6081,8 @@ export declare class SnapManager {
|
|
|
6077
6081
|
getCurrentCommonAncestor(): TLShapeId | undefined;
|
|
6078
6082
|
}
|
|
6079
6083
|
|
|
6084
|
+
/* Excluded from this release type: SpatialIndexManager */
|
|
6085
|
+
|
|
6080
6086
|
/** @public */
|
|
6081
6087
|
export declare class Stadium2d extends Geometry2d {
|
|
6082
6088
|
config: Omit<Geometry2dOptions, 'isClosed'> & {
|
|
@@ -8106,6 +8112,7 @@ export declare interface TLUserPreferences {
|
|
|
8106
8112
|
isPasteAtCursorMode?: boolean | null;
|
|
8107
8113
|
enhancedA11yMode?: boolean | null;
|
|
8108
8114
|
inputMode?: 'mouse' | 'trackpad' | null;
|
|
8115
|
+
isZoomDirectionInverted?: boolean | null;
|
|
8109
8116
|
}
|
|
8110
8117
|
|
|
8111
8118
|
/** @public */
|
|
@@ -8280,6 +8287,7 @@ export declare class UserPreferencesManager {
|
|
|
8280
8287
|
isDynamicResizeMode: boolean;
|
|
8281
8288
|
isSnapMode: boolean;
|
|
8282
8289
|
isWrapMode: boolean;
|
|
8290
|
+
isZoomDirectionInverted: boolean;
|
|
8283
8291
|
locale: string;
|
|
8284
8292
|
name: string;
|
|
8285
8293
|
};
|
|
@@ -8300,6 +8308,7 @@ export declare class UserPreferencesManager {
|
|
|
8300
8308
|
getIsPasteAtCursorMode(): boolean;
|
|
8301
8309
|
getEnhancedA11yMode(): boolean;
|
|
8302
8310
|
getInputMode(): "mouse" | "trackpad" | null;
|
|
8311
|
+
getIsZoomDirectionInverted(): boolean;
|
|
8303
8312
|
}
|
|
8304
8313
|
|
|
8305
8314
|
/** @public */
|
package/dist-esm/index.mjs
CHANGED
|
@@ -110,6 +110,7 @@ import { HandleSnaps } from "./lib/editor/managers/SnapManager/HandleSnaps.mjs";
|
|
|
110
110
|
import {
|
|
111
111
|
SnapManager
|
|
112
112
|
} from "./lib/editor/managers/SnapManager/SnapManager.mjs";
|
|
113
|
+
import { SpatialIndexManager } from "./lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs";
|
|
113
114
|
import {
|
|
114
115
|
TextManager
|
|
115
116
|
} from "./lib/editor/managers/TextManager/TextManager.mjs";
|
|
@@ -304,7 +305,7 @@ import { uniq } from "./lib/utils/uniq.mjs";
|
|
|
304
305
|
import { openWindow } from "./lib/utils/window-open.mjs";
|
|
305
306
|
registerTldrawLibraryVersion(
|
|
306
307
|
"@tldraw/editor",
|
|
307
|
-
"4.
|
|
308
|
+
"4.4.0-canary.15cff7ea86f8",
|
|
308
309
|
"esm"
|
|
309
310
|
);
|
|
310
311
|
export {
|
|
@@ -382,6 +383,7 @@ export {
|
|
|
382
383
|
ShapeUtil,
|
|
383
384
|
SharedStyleMap,
|
|
384
385
|
SnapManager,
|
|
386
|
+
SpatialIndexManager,
|
|
385
387
|
Stadium2d,
|
|
386
388
|
StateNode,
|
|
387
389
|
TAB_ID,
|