@kubohiroya/turbowarp-plus-editor-code-views 0.26.6 → 0.26.7
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/NOTICE +24 -0
- package/README.ja.md +2 -0
- package/dist/script-arrows.js +1 -53
- package/dist/script-outline.d.ts +11 -0
- package/dist/script-outline.js +77 -0
- package/dist/workspace-overview.js +15 -10
- package/package.json +5 -3
- package/src/script-arrows.ts +1 -50
- package/src/script-outline.ts +72 -0
- package/src/workspace-overview.ts +15 -10
package/NOTICE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Third-party notice: svg-path-properties 1.3.0
|
|
2
|
+
Source: https://github.com/rveciana/svg-path-properties
|
|
3
|
+
|
|
4
|
+
MIT License
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2016 Roger Veciana i Rovira
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/README.ja.md
CHANGED
|
@@ -108,6 +108,8 @@ Editor は GUI の React 16 にこれらを描画するので、React 16.14 以
|
|
|
108
108
|
|
|
109
109
|
ミニマップの描画と入力は `attachWorkspaceOverview` が所有し、ホストは workspace・配置・サムネイル取得の口を渡す。画面外のブロックを隠すネイティブの表示変更では形状を再走査せず、スクロール中は表示範囲の枠だけを更新する。ブロック編集時も既存のパスを保ち、必要な形・位置・色だけを書き換える。矢印の輪郭は同じパス形状で共有し、粗い走査と交点の精密化を組み合わせ、スクロール中は測定済みの接続点を使う。
|
|
110
110
|
|
|
111
|
+
Z配置の初回表示では、輪郭の粗い探索を `svg-path-properties` で行い、候補区間と最終的な矢印の接続点は従来と同じブラウザーの輪郭計算で確定する。解釈できないパスや長さが一致しないパスはブラウザー計算へ戻す。輪郭と高さごとの接続点は画面の平行移動・ズームをまたいで共有する。変換時の微小な丸め誤差は、従来の精密化の許容誤差より小さい単位でキャッシュの照合時に吸収する。ミニマップは全形状を読み取ってから描画を更新し、読み取りと書き込みの交互実行を避ける。Editor #868の関連検証は `node --test test/script-outline.browser.ts test/serial-layout.browser.ts test/workspace-overview.browser.ts test/script-arrows.browser.ts` で実行する。切り戻しはこの最適化をrevertし、ホストの依存固定を直前の検証済み版へ戻して再ビルドする。作品データを変更する移行処理はない。
|
|
112
|
+
|
|
111
113
|
自由配置とコードのプレビューは2%まで縮小できる。通常の拡大・縮小ボタンやホイールを使い、リセットでは従来の初期倍率へ戻る。最小倍率はコード画面の接続中だけ変更し、Blockly の他の用途の既定値は変えない。
|
|
112
114
|
|
|
113
115
|
選択・ホバー・ドラッグ中の関係に必要な接続先だけを短く表示する。呼び出し関係の図へ渡す `readScriptRelationGraph(targets, ScratchBlocks)` は、同じ関係データと、接続先スクリプトのハットの文言・対象名・位置を返す。図の向きは呼び出し関係パネルの左端カラム下端で操作する。
|
package/dist/script-arrows.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { outlinePoint } from "./script-outline.js";
|
|
1
2
|
import { isFoldedDefinition } from "./procedure-edits.js";
|
|
2
3
|
import { readScriptRelations } from "./script-relations.js";
|
|
3
4
|
function roundedRoute(points, radii) {
|
|
@@ -21,59 +22,6 @@ function roundedRoute(points, radii) {
|
|
|
21
22
|
return `${path} L ${end.x} ${end.y}`;
|
|
22
23
|
}
|
|
23
24
|
const ns = 'http://www.w3.org/2000/svg';
|
|
24
|
-
const outlines = new Map();
|
|
25
|
-
/** Intersect the actual outline, including a hat's overhang, rather than Blockly's layout padding. */
|
|
26
|
-
function outlinePoint(shape, bounds, side, fraction) {
|
|
27
|
-
const data = shape.getAttribute('d') ?? '';
|
|
28
|
-
let outline = outlines.get(data);
|
|
29
|
-
if (!outline) {
|
|
30
|
-
const length = shape.getTotalLength();
|
|
31
|
-
const count = Math.max(24, Math.min(96, Math.ceil(length / 8)));
|
|
32
|
-
const points = Array.from({ length: count + 1 }, (_, index) => {
|
|
33
|
-
const distance = length * index / count;
|
|
34
|
-
const point = shape.getPointAtLength(distance);
|
|
35
|
-
return { x: point.x, y: point.y, distance };
|
|
36
|
-
});
|
|
37
|
-
outline = { points, cuts: new Map() };
|
|
38
|
-
if (outlines.size >= 512)
|
|
39
|
-
outlines.delete(outlines.keys().next().value);
|
|
40
|
-
outlines.set(data, outline);
|
|
41
|
-
}
|
|
42
|
-
const y = bounds.y + bounds.height * fraction;
|
|
43
|
-
const key = `${side}:${y}`;
|
|
44
|
-
const cached = outline.cuts.get(key);
|
|
45
|
-
if (cached)
|
|
46
|
-
return cached;
|
|
47
|
-
let edge;
|
|
48
|
-
for (let index = 1; index < outline.points.length; index++) {
|
|
49
|
-
const before = outline.points[index - 1];
|
|
50
|
-
const after = outline.points[index];
|
|
51
|
-
if ((before.y <= y && after.y >= y) || (before.y >= y && after.y <= y)) {
|
|
52
|
-
let x;
|
|
53
|
-
if (before.y === after.y)
|
|
54
|
-
x = side === 'left' ? Math.min(before.x, after.x) : Math.max(before.x, after.x);
|
|
55
|
-
else {
|
|
56
|
-
// Refine only a crossing instead of sampling every two units along the entire outline.
|
|
57
|
-
let low = before.distance, high = after.distance;
|
|
58
|
-
for (let step = 0; step < 12; step++) {
|
|
59
|
-
const middle = (low + high) / 2;
|
|
60
|
-
const point = shape.getPointAtLength(middle);
|
|
61
|
-
x = point.x;
|
|
62
|
-
if (Math.abs(point.y - y) < .001)
|
|
63
|
-
break;
|
|
64
|
-
if ((point.y < y) === (before.y < y))
|
|
65
|
-
low = middle;
|
|
66
|
-
else
|
|
67
|
-
high = middle;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
edge = edge === undefined ? x : side === 'left' ? Math.min(edge, x) : Math.max(edge, x);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const point = { x: edge ?? bounds.x + (side === 'right' ? bounds.width : 0), y };
|
|
74
|
-
outline.cuts.set(key, point);
|
|
75
|
-
return point;
|
|
76
|
-
}
|
|
77
25
|
// The shared workspace owns navigation even when an arrow is in a read-only preview.
|
|
78
26
|
const navigators = new WeakMap();
|
|
79
27
|
export function registerScriptRelationNavigation(vm, navigate) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type Point = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
type Box = Point & {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
/** Bracket crossings without DOM queries, then refine against the browser's actual outline. */
|
|
10
|
+
export declare function outlinePoint(shape: SVGGeometryElement, bounds: Box, side: 'left' | 'right', fraction: number): Point;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { svgPathProperties } from 'svg-path-properties';
|
|
2
|
+
const outlines = new Map();
|
|
3
|
+
/** Bracket crossings without DOM queries, then refine against the browser's actual outline. */
|
|
4
|
+
export function outlinePoint(shape, bounds, side, fraction) {
|
|
5
|
+
const data = shape.getAttribute('d') ?? '';
|
|
6
|
+
let outline = outlines.get(data);
|
|
7
|
+
if (!outline) {
|
|
8
|
+
const length = shape.getTotalLength();
|
|
9
|
+
const count = Math.max(24, Math.min(96, Math.ceil(length / 8)));
|
|
10
|
+
let properties;
|
|
11
|
+
try {
|
|
12
|
+
if (data) {
|
|
13
|
+
const candidate = new svgPathProperties(data);
|
|
14
|
+
// Reject unsupported parsing before using its samples to bracket native geometry.
|
|
15
|
+
if (Math.abs(candidate.getTotalLength() - length) <= .05)
|
|
16
|
+
properties = candidate;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch { /* Keep native support for other shapes. */ }
|
|
20
|
+
const points = Array.from({ length: count + 1 }, (_, index) => {
|
|
21
|
+
const distance = length * index / count;
|
|
22
|
+
// Move-only segments and the exact endpoint can differ between SVG implementations.
|
|
23
|
+
if (properties && index > 0 && index < count) {
|
|
24
|
+
try {
|
|
25
|
+
const point = properties.getPointAtLength(distance);
|
|
26
|
+
if (Number.isFinite(point.x) && Number.isFinite(point.y))
|
|
27
|
+
return { ...point, distance };
|
|
28
|
+
}
|
|
29
|
+
catch { /* A valid browser path can use syntax the parser does not support. */ }
|
|
30
|
+
}
|
|
31
|
+
const point = shape.getPointAtLength(distance);
|
|
32
|
+
return { x: point.x, y: point.y, distance, native: point };
|
|
33
|
+
});
|
|
34
|
+
outline = { points, cuts: new Map() };
|
|
35
|
+
if (outlines.size >= 512)
|
|
36
|
+
outlines.delete(outlines.keys().next().value);
|
|
37
|
+
outlines.set(data, outline);
|
|
38
|
+
}
|
|
39
|
+
const y = bounds.y + bounds.height * fraction;
|
|
40
|
+
// Ignore transform round-off far below the native .001 refinement tolerance.
|
|
41
|
+
const key = `${side}:${y.toFixed(6)}`;
|
|
42
|
+
const cached = outline.cuts.get(key);
|
|
43
|
+
if (cached)
|
|
44
|
+
return cached.y === y ? cached : { x: cached.x, y };
|
|
45
|
+
const native = (sample) => sample.native ??= shape.getPointAtLength(sample.distance);
|
|
46
|
+
let edge;
|
|
47
|
+
for (let index = 1; index < outline.points.length; index++) {
|
|
48
|
+
const first = outline.points[index - 1], last = outline.points[index];
|
|
49
|
+
// The coarse calculation only selects candidates; it never supplies the final attachment.
|
|
50
|
+
if (y < Math.min(first.y, last.y) - .1 || y > Math.max(first.y, last.y) + .1)
|
|
51
|
+
continue;
|
|
52
|
+
const before = native(first), after = native(last);
|
|
53
|
+
if ((before.y <= y && after.y >= y) || (before.y >= y && after.y <= y)) {
|
|
54
|
+
let x;
|
|
55
|
+
if (before.y === after.y)
|
|
56
|
+
x = side === 'left' ? Math.min(before.x, after.x) : Math.max(before.x, after.x);
|
|
57
|
+
else {
|
|
58
|
+
let low = first.distance, high = last.distance;
|
|
59
|
+
for (let step = 0; step < 12; step++) {
|
|
60
|
+
const middle = (low + high) / 2;
|
|
61
|
+
const point = shape.getPointAtLength(middle);
|
|
62
|
+
x = point.x;
|
|
63
|
+
if (Math.abs(point.y - y) < .001)
|
|
64
|
+
break;
|
|
65
|
+
if ((point.y < y) === (before.y < y))
|
|
66
|
+
low = middle;
|
|
67
|
+
else
|
|
68
|
+
high = middle;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
edge = edge === undefined ? x : side === 'left' ? Math.min(edge, x) : Math.max(edge, x);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const point = { x: edge ?? bounds.x + (side === 'right' ? bounds.width : 0), y };
|
|
75
|
+
outline.cuts.set(key, point);
|
|
76
|
+
return point;
|
|
77
|
+
}
|
|
@@ -35,17 +35,9 @@ export function attachWorkspaceOverview({ workspace, ScratchBlocks, zoomHeight =
|
|
|
35
35
|
function refreshShapes() {
|
|
36
36
|
const retained = new Set();
|
|
37
37
|
const additions = document.createDocumentFragment();
|
|
38
|
+
const painting = [];
|
|
38
39
|
const paint = (id, data, fill, transform) => {
|
|
39
|
-
|
|
40
|
-
let path = paths.get(id);
|
|
41
|
-
if (!path) {
|
|
42
|
-
path = element('path');
|
|
43
|
-
paths.set(id, path);
|
|
44
|
-
additions.append(path);
|
|
45
|
-
}
|
|
46
|
-
attribute(path, 'd', data);
|
|
47
|
-
attribute(path, 'fill', fill);
|
|
48
|
-
attribute(path, 'transform', transform);
|
|
40
|
+
painting.push([id, data, fill, transform]);
|
|
49
41
|
};
|
|
50
42
|
const projection = getScriptProjection(workspace);
|
|
51
43
|
if (projection) {
|
|
@@ -76,6 +68,19 @@ export function attachWorkspaceOverview({ workspace, ScratchBlocks, zoomHeight =
|
|
|
76
68
|
paint(block.id, data, source.getAttribute('fill') || block.getColour(), `translate(${position.x} ${position.y})${block.RTL ? ' scale(-1 1)' : ''}`);
|
|
77
69
|
}
|
|
78
70
|
}
|
|
71
|
+
// Measure every projected path before updating the live overview's cached shapes.
|
|
72
|
+
for (const [id, data, fill, transform] of painting) {
|
|
73
|
+
retained.add(id);
|
|
74
|
+
let path = paths.get(id);
|
|
75
|
+
if (!path) {
|
|
76
|
+
path = element('path');
|
|
77
|
+
paths.set(id, path);
|
|
78
|
+
additions.append(path);
|
|
79
|
+
}
|
|
80
|
+
attribute(path, 'd', data);
|
|
81
|
+
attribute(path, 'fill', fill);
|
|
82
|
+
attribute(path, 'transform', transform);
|
|
83
|
+
}
|
|
79
84
|
for (const [id, path] of paths)
|
|
80
85
|
if (!retained.has(id)) {
|
|
81
86
|
path.remove();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-code-views",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.7",
|
|
4
4
|
"description": "Code views for TurboWarp Plus Editor: code in tabs and windows, the detached block palette, script layout and block field editing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -139,7 +139,8 @@
|
|
|
139
139
|
"README.md",
|
|
140
140
|
"README.ja.md",
|
|
141
141
|
"LICENSE",
|
|
142
|
-
"EDITOR-MIGRATION.md"
|
|
142
|
+
"EDITOR-MIGRATION.md",
|
|
143
|
+
"NOTICE"
|
|
143
144
|
],
|
|
144
145
|
"scripts": {
|
|
145
146
|
"build": "tsc -p tsconfig.json",
|
|
@@ -149,7 +150,8 @@
|
|
|
149
150
|
},
|
|
150
151
|
"dependencies": {
|
|
151
152
|
"@kubohiroya/turbowarp-script-transfer": "0.1.5",
|
|
152
|
-
"matter-js": "0.20.0"
|
|
153
|
+
"matter-js": "0.20.0",
|
|
154
|
+
"svg-path-properties": "1.3.0"
|
|
153
155
|
},
|
|
154
156
|
"peerDependencies": {
|
|
155
157
|
"@kubohiroya/turbowarp-extension-security-dialog": ">=0.9.0 <0.10.0 || 0.10.0 || 0.13.0 || 0.13.1 || 0.14.2",
|
package/src/script-arrows.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {outlinePoint} from './script-outline.ts';
|
|
1
2
|
import {isFoldedDefinition} from './procedure-edits.ts';
|
|
2
3
|
import {readScriptRelations, type RelationTarget, type ScriptEndpoint, type ScriptRelation} from './script-relations.ts';
|
|
3
4
|
|
|
@@ -44,56 +45,6 @@ function roundedRoute(points: Point[], radii: readonly number[]) {
|
|
|
44
45
|
return `${path} L ${end.x} ${end.y}`;
|
|
45
46
|
}
|
|
46
47
|
const ns = 'http://www.w3.org/2000/svg';
|
|
47
|
-
type Outline = {points: (Point & {distance: number})[]; cuts: Map<string, Point>};
|
|
48
|
-
const outlines = new Map<string, Outline>();
|
|
49
|
-
|
|
50
|
-
/** Intersect the actual outline, including a hat's overhang, rather than Blockly's layout padding. */
|
|
51
|
-
function outlinePoint(shape: SVGGeometryElement, bounds: Box, side: 'left' | 'right', fraction: number): Point {
|
|
52
|
-
const data = shape.getAttribute('d') ?? '';
|
|
53
|
-
let outline = outlines.get(data);
|
|
54
|
-
if (!outline) {
|
|
55
|
-
const length = shape.getTotalLength();
|
|
56
|
-
const count = Math.max(24, Math.min(96, Math.ceil(length / 8)));
|
|
57
|
-
const points = Array.from({length: count + 1}, (_, index) => {
|
|
58
|
-
const distance = length * index / count;
|
|
59
|
-
const point = shape.getPointAtLength(distance);
|
|
60
|
-
return {x: point.x, y: point.y, distance};
|
|
61
|
-
});
|
|
62
|
-
outline = {points, cuts: new Map()};
|
|
63
|
-
if (outlines.size >= 512) outlines.delete(outlines.keys().next().value);
|
|
64
|
-
outlines.set(data, outline);
|
|
65
|
-
}
|
|
66
|
-
const y = bounds.y + bounds.height * fraction;
|
|
67
|
-
const key = `${side}:${y}`;
|
|
68
|
-
const cached = outline.cuts.get(key);
|
|
69
|
-
if (cached) return cached;
|
|
70
|
-
let edge: number | undefined;
|
|
71
|
-
for (let index = 1; index < outline.points.length; index++) {
|
|
72
|
-
const before = outline.points[index - 1];
|
|
73
|
-
const after = outline.points[index];
|
|
74
|
-
if ((before.y <= y && after.y >= y) || (before.y >= y && after.y <= y)) {
|
|
75
|
-
let x: number;
|
|
76
|
-
if (before.y === after.y) x = side === 'left' ? Math.min(before.x, after.x) : Math.max(before.x, after.x);
|
|
77
|
-
else {
|
|
78
|
-
// Refine only a crossing instead of sampling every two units along the entire outline.
|
|
79
|
-
let low = before.distance, high = after.distance;
|
|
80
|
-
for (let step = 0; step < 12; step++) {
|
|
81
|
-
const middle = (low + high) / 2;
|
|
82
|
-
const point = shape.getPointAtLength(middle);
|
|
83
|
-
x = point.x;
|
|
84
|
-
if (Math.abs(point.y - y) < .001) break;
|
|
85
|
-
if ((point.y < y) === (before.y < y)) low = middle;
|
|
86
|
-
else high = middle;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
edge = edge === undefined ? x : side === 'left' ? Math.min(edge, x) : Math.max(edge, x);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const point = {x: edge ?? bounds.x + (side === 'right' ? bounds.width : 0), y};
|
|
93
|
-
outline.cuts.set(key, point);
|
|
94
|
-
return point;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
48
|
// The shared workspace owns navigation even when an arrow is in a read-only preview.
|
|
98
49
|
const navigators = new WeakMap<object, (endpoint: ScriptEndpoint) => void>();
|
|
99
50
|
export function registerScriptRelationNavigation(vm: object, navigate: (endpoint: ScriptEndpoint) => void) {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {svgPathProperties} from 'svg-path-properties';
|
|
2
|
+
|
|
3
|
+
type Point = {x: number; y: number};
|
|
4
|
+
type Box = Point & {width: number; height: number};
|
|
5
|
+
type Sample = Point & {distance: number; native?: Point};
|
|
6
|
+
type Outline = {points: Sample[]; cuts: Map<string, Point>};
|
|
7
|
+
const outlines = new Map<string, Outline>();
|
|
8
|
+
|
|
9
|
+
/** Bracket crossings without DOM queries, then refine against the browser's actual outline. */
|
|
10
|
+
export function outlinePoint(shape: SVGGeometryElement, bounds: Box, side: 'left' | 'right', fraction: number): Point {
|
|
11
|
+
const data = shape.getAttribute('d') ?? '';
|
|
12
|
+
let outline = outlines.get(data);
|
|
13
|
+
if (!outline) {
|
|
14
|
+
const length = shape.getTotalLength();
|
|
15
|
+
const count = Math.max(24, Math.min(96, Math.ceil(length / 8)));
|
|
16
|
+
let properties: {getPointAtLength(distance: number): Point} | undefined;
|
|
17
|
+
try {
|
|
18
|
+
if (data) {
|
|
19
|
+
const candidate = new svgPathProperties(data);
|
|
20
|
+
// Reject unsupported parsing before using its samples to bracket native geometry.
|
|
21
|
+
if (Math.abs(candidate.getTotalLength() - length) <= .05) properties = candidate;
|
|
22
|
+
}
|
|
23
|
+
} catch { /* Keep native support for other shapes. */ }
|
|
24
|
+
const points = Array.from({length: count + 1}, (_, index): Sample => {
|
|
25
|
+
const distance = length * index / count;
|
|
26
|
+
// Move-only segments and the exact endpoint can differ between SVG implementations.
|
|
27
|
+
if (properties && index > 0 && index < count) {
|
|
28
|
+
try {
|
|
29
|
+
const point = properties.getPointAtLength(distance);
|
|
30
|
+
if (Number.isFinite(point.x) && Number.isFinite(point.y)) return {...point, distance};
|
|
31
|
+
} catch { /* A valid browser path can use syntax the parser does not support. */ }
|
|
32
|
+
}
|
|
33
|
+
const point = shape.getPointAtLength(distance);
|
|
34
|
+
return {x: point.x, y: point.y, distance, native: point};
|
|
35
|
+
});
|
|
36
|
+
outline = {points, cuts: new Map()};
|
|
37
|
+
if (outlines.size >= 512) outlines.delete(outlines.keys().next().value);
|
|
38
|
+
outlines.set(data, outline);
|
|
39
|
+
}
|
|
40
|
+
const y = bounds.y + bounds.height * fraction;
|
|
41
|
+
// Ignore transform round-off far below the native .001 refinement tolerance.
|
|
42
|
+
const key = `${side}:${y.toFixed(6)}`;
|
|
43
|
+
const cached = outline.cuts.get(key);
|
|
44
|
+
if (cached) return cached.y === y ? cached : {x: cached.x, y};
|
|
45
|
+
const native = (sample: Sample) => sample.native ??= shape.getPointAtLength(sample.distance);
|
|
46
|
+
let edge: number | undefined;
|
|
47
|
+
for (let index = 1; index < outline.points.length; index++) {
|
|
48
|
+
const first = outline.points[index - 1], last = outline.points[index];
|
|
49
|
+
// The coarse calculation only selects candidates; it never supplies the final attachment.
|
|
50
|
+
if (y < Math.min(first.y, last.y) - .1 || y > Math.max(first.y, last.y) + .1) continue;
|
|
51
|
+
const before = native(first), after = native(last);
|
|
52
|
+
if ((before.y <= y && after.y >= y) || (before.y >= y && after.y <= y)) {
|
|
53
|
+
let x: number;
|
|
54
|
+
if (before.y === after.y) x = side === 'left' ? Math.min(before.x, after.x) : Math.max(before.x, after.x);
|
|
55
|
+
else {
|
|
56
|
+
let low = first.distance, high = last.distance;
|
|
57
|
+
for (let step = 0; step < 12; step++) {
|
|
58
|
+
const middle = (low + high) / 2;
|
|
59
|
+
const point = shape.getPointAtLength(middle);
|
|
60
|
+
x = point.x;
|
|
61
|
+
if (Math.abs(point.y - y) < .001) break;
|
|
62
|
+
if ((point.y < y) === (before.y < y)) low = middle;
|
|
63
|
+
else high = middle;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
edge = edge === undefined ? x : side === 'left' ? Math.min(edge, x) : Math.max(edge, x);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const point = {x: edge ?? bounds.x + (side === 'right' ? bounds.width : 0), y};
|
|
70
|
+
outline.cuts.set(key, point);
|
|
71
|
+
return point;
|
|
72
|
+
}
|
|
@@ -46,17 +46,9 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
|
|
|
46
46
|
function refreshShapes() {
|
|
47
47
|
const retained = new Set<string>();
|
|
48
48
|
const additions = document.createDocumentFragment();
|
|
49
|
+
const painting: [string, string, string, string][] = [];
|
|
49
50
|
const paint = (id: string, data: string, fill: string, transform: string) => {
|
|
50
|
-
|
|
51
|
-
let path = paths.get(id);
|
|
52
|
-
if (!path) {
|
|
53
|
-
path = element('path');
|
|
54
|
-
paths.set(id, path);
|
|
55
|
-
additions.append(path);
|
|
56
|
-
}
|
|
57
|
-
attribute(path, 'd', data);
|
|
58
|
-
attribute(path, 'fill', fill);
|
|
59
|
-
attribute(path, 'transform', transform);
|
|
51
|
+
painting.push([id, data, fill, transform]);
|
|
60
52
|
};
|
|
61
53
|
const projection = getScriptProjection(workspace);
|
|
62
54
|
if (projection) {
|
|
@@ -83,6 +75,19 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
|
|
|
83
75
|
`translate(${position.x} ${position.y})${block.RTL ? ' scale(-1 1)' : ''}`);
|
|
84
76
|
}
|
|
85
77
|
}
|
|
78
|
+
// Measure every projected path before updating the live overview's cached shapes.
|
|
79
|
+
for (const [id, data, fill, transform] of painting) {
|
|
80
|
+
retained.add(id);
|
|
81
|
+
let path = paths.get(id);
|
|
82
|
+
if (!path) {
|
|
83
|
+
path = element('path');
|
|
84
|
+
paths.set(id, path);
|
|
85
|
+
additions.append(path);
|
|
86
|
+
}
|
|
87
|
+
attribute(path, 'd', data);
|
|
88
|
+
attribute(path, 'fill', fill);
|
|
89
|
+
attribute(path, 'transform', transform);
|
|
90
|
+
}
|
|
86
91
|
for (const [id, path] of paths) if (!retained.has(id)) {path.remove(); paths.delete(id);}
|
|
87
92
|
if (additions.childNodes.length) shapes.append(additions);
|
|
88
93
|
needsShapes = false;
|