@edv4h/usketch-core 2.3.2 → 2.4.0
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer-manager.d.ts","sourceRoot":"","sources":["../src/layer-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"layer-manager.d.ts","sourceRoot":"","sources":["../src/layer-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAUjE,wBAAgB,kBAAkB,IAAI,YAAY,CA0DjD"}
|
package/dist/layer-manager.js
CHANGED
|
@@ -1,16 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default per-collision bump for `avoidCollision` layers. `2 ** -10` (=1/1024)
|
|
3
|
+
* is exactly representable in binary floating point, so integer-base + k*step
|
|
4
|
+
* sums stay exact. It also keeps the layer below the next integer order for up
|
|
5
|
+
* to 1023 collisions at the same base — far more than any realistic layer set.
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_COLLISION_STEP = 2 ** -10;
|
|
1
8
|
export function createLayerManager() {
|
|
2
9
|
const layers = new Map();
|
|
10
|
+
// id → resolved effective order used for sorting. For plain layers this is
|
|
11
|
+
// just `layer.order`; for `avoidCollision` layers it may be bumped up.
|
|
12
|
+
const effectiveOrders = new Map();
|
|
3
13
|
let sorted = [];
|
|
14
|
+
/**
|
|
15
|
+
* Resolve the effective order for `layer`. Plain layers keep their `order`.
|
|
16
|
+
* `avoidCollision` layers start at `order` and step up until they land on a
|
|
17
|
+
* slot not occupied by any *other* layer's effective order.
|
|
18
|
+
*/
|
|
19
|
+
function resolveOrder(layer) {
|
|
20
|
+
if (!layer.avoidCollision)
|
|
21
|
+
return layer.order;
|
|
22
|
+
const used = new Set();
|
|
23
|
+
for (const [id, eff] of effectiveOrders) {
|
|
24
|
+
if (id !== layer.id)
|
|
25
|
+
used.add(eff);
|
|
26
|
+
}
|
|
27
|
+
// Guard the caller's step: 0 / negative / non-finite would make the bump
|
|
28
|
+
// loop below never terminate. Fall back to the default in those cases.
|
|
29
|
+
const requested = layer.collisionStep ?? DEFAULT_COLLISION_STEP;
|
|
30
|
+
const step = Number.isFinite(requested) && requested > 0 ? requested : DEFAULT_COLLISION_STEP;
|
|
31
|
+
let eff = layer.order;
|
|
32
|
+
while (used.has(eff))
|
|
33
|
+
eff += step;
|
|
34
|
+
return eff;
|
|
35
|
+
}
|
|
4
36
|
function rebuildSorted() {
|
|
5
|
-
sorted = [...layers.values()].sort((a, b) => a.order - b.order);
|
|
37
|
+
sorted = [...layers.values()].sort((a, b) => (effectiveOrders.get(a.id) ?? a.order) - (effectiveOrders.get(b.id) ?? b.order));
|
|
6
38
|
}
|
|
7
39
|
return {
|
|
8
40
|
register(layer) {
|
|
41
|
+
// Drop any prior effective order first so a re-register doesn't collide
|
|
42
|
+
// with its own previous slot.
|
|
43
|
+
effectiveOrders.delete(layer.id);
|
|
9
44
|
layers.set(layer.id, layer);
|
|
45
|
+
effectiveOrders.set(layer.id, resolveOrder(layer));
|
|
10
46
|
rebuildSorted();
|
|
11
47
|
},
|
|
12
48
|
unregister(layerId) {
|
|
49
|
+
// Only removes this layer; other layers keep their resolved orders so
|
|
50
|
+
// nothing visually reshuffles. The freed slot is reusable by later
|
|
51
|
+
// registrations.
|
|
13
52
|
layers.delete(layerId);
|
|
53
|
+
effectiveOrders.delete(layerId);
|
|
14
54
|
rebuildSorted();
|
|
15
55
|
},
|
|
16
56
|
getLayers() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer-manager.js","sourceRoot":"","sources":["../src/layer-manager.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB;IACjC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IACxC,IAAI,MAAM,GAAqB,EAA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M,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CACjC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CACzF,CAAC;IACH,CAAC;IAED,OAAO;QACN,QAAQ,CAAC,KAAY;YACpB,wEAAwE;YACxE,8BAA8B;YAC9B,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACjC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YAC5B,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YACnD,aAAa,EAAE,CAAC;QACjB,CAAC;QAED,UAAU,CAAC,OAAe;YACzB,sEAAsE;YACtE,mEAAmE;YACnE,iBAAiB;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACvB,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAChC,aAAa,EAAE,CAAC;QACjB,CAAC;QAED,SAAS;YACR,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edv4h/usketch-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@edv4h/usketch-shared": "4.
|
|
15
|
+
"@edv4h/usketch-shared": "4.10.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"typescript": "7.0.2",
|