@kubohiroya/turbowarp-plus-editor-code-views 0.21.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/script-fit.d.ts +1 -1
- package/dist/script-fit.js +7 -9
- package/package.json +1 -1
- package/src/script-fit.ts +8 -10
package/README.ja.md
CHANGED
|
@@ -6,7 +6,7 @@ TurboWarp Plus Editor のコードの画面。1つの作品と1つの取り消
|
|
|
6
6
|
|
|
7
7
|
## 選択したスクリプトの表示
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
関数・ハットなどを選んで開くと、そのスクリプトの描画範囲に合わせて倍率を調整し、先頭ブロックの左上をコードパネルの左上から右・下へ24px空けた位置に合わせる。自動ズームは50〜125%に制限し、ワークスペース固有の制限が厳しければそちらに従う。短いスクリプトや下限倍率でも同じ位置から表示し、後続の幅広いブロックの形には左右されない。通常の編集・手動ズームでは再フィットしない。
|
|
10
10
|
|
|
11
11
|
ホストが独立したワークスペースを表示する場合は、ルートまたは `./sprite-code-windows` の `fitScriptInWorkspace(workspace, scriptId, ScratchBlocks)` を使える。表示領域やブロックがまだない場合は `false` を返すので、レイアウト後に再試行する。
|
|
12
12
|
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ The code views of TurboWarp Plus Editor: code in tabs and windows that share one
|
|
|
6
6
|
|
|
7
7
|
## Opening a selected script
|
|
8
8
|
|
|
9
|
-
Opening a function or hat
|
|
9
|
+
Opening a function or hat adjusts the zoom to its rendered script and places the first block's top left 24px right and down from the code pane's top left. Automatic zoom stays between 50% and 125%, respecting stricter workspace limits. Short scripts and scripts at the zoom floor start at the same position, regardless of wider blocks farther down the script. Ordinary edits and manual zoom do not refit it.
|
|
10
10
|
|
|
11
11
|
Hosts with a separate workspace can call `fitScriptInWorkspace(workspace, scriptId, ScratchBlocks)` from the root or `./sprite-code-windows` export. It returns `false` if the viewport or block is not ready, so the host can retry after layout.
|
|
12
12
|
|
package/dist/script-fit.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ type ScriptFitWorkspace = {
|
|
|
27
27
|
set(x: number, y: number): void;
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
-
/** Fit a
|
|
30
|
+
/** Fit a script once, placing its first block at the viewport's top left with padding. */
|
|
31
31
|
export declare function fitScriptInWorkspace(workspace: ScriptFitWorkspace, scriptId: string, blocks: {
|
|
32
32
|
svgResize(workspace: ScriptFitWorkspace): void;
|
|
33
33
|
}): boolean;
|
package/dist/script-fit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const padding = 24;
|
|
2
2
|
const positive = (value, fallback) => Number.isFinite(value) && value > 0 ? value : fallback;
|
|
3
|
-
/** Fit a
|
|
3
|
+
/** Fit a script once, placing its first block at the viewport's top left with padding. */
|
|
4
4
|
export function fitScriptInWorkspace(workspace, scriptId, blocks) {
|
|
5
5
|
const injection = workspace.getInjectionDiv();
|
|
6
6
|
const block = workspace.getBlockById(scriptId);
|
|
@@ -18,8 +18,11 @@ export function fitScriptInWorkspace(workspace, scriptId, blocks) {
|
|
|
18
18
|
return false;
|
|
19
19
|
// SVG bounds include nested reporters and the hat's overhang, but exclude folded, hidden bodies.
|
|
20
20
|
const origin = block.getRelativeToSurfaceXY();
|
|
21
|
-
|
|
22
|
-
const
|
|
21
|
+
// A wider block farther down the script must not shift the first block's anchor.
|
|
22
|
+
const path = root.querySelector(':scope > .blocklyPath');
|
|
23
|
+
const first = path?.getBBox() ?? bounds;
|
|
24
|
+
const left = origin.x + (path && workspace.RTL ? -first.x - first.width : first.x);
|
|
25
|
+
const top = origin.y + first.y;
|
|
23
26
|
const zoom = workspace.options?.zoomOptions;
|
|
24
27
|
const workspaceMin = positive(zoom?.minScale, 0.01);
|
|
25
28
|
const workspaceMax = Math.max(workspaceMin, positive(zoom?.maxScale, Infinity));
|
|
@@ -31,11 +34,6 @@ export function fitScriptInWorkspace(workspace, scriptId, blocks) {
|
|
|
31
34
|
const scaled = workspace.getMetrics();
|
|
32
35
|
if (!scaled)
|
|
33
36
|
return false;
|
|
34
|
-
|
|
35
|
-
const height = bounds.height * workspace.scale;
|
|
36
|
-
const x = width > scaled.viewWidth - padding * 2 && workspace.RTL ?
|
|
37
|
-
scaled.viewWidth - padding - width : Math.max(padding, (scaled.viewWidth - width) / 2);
|
|
38
|
-
const y = workspace.scale <= minScale ? padding : Math.max(padding, (scaled.viewHeight - height) / 2);
|
|
39
|
-
workspace.scrollbar.set(left * workspace.scale - scaled.contentLeft - x, top * workspace.scale - scaled.contentTop - y);
|
|
37
|
+
workspace.scrollbar.set(left * workspace.scale - scaled.contentLeft - padding, top * workspace.scale - scaled.contentTop - padding);
|
|
40
38
|
return true;
|
|
41
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-code-views",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.1",
|
|
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",
|
package/src/script-fit.ts
CHANGED
|
@@ -17,7 +17,7 @@ const padding = 24;
|
|
|
17
17
|
const positive = (value: number | undefined, fallback: number) =>
|
|
18
18
|
Number.isFinite(value) && value > 0 ? value : fallback;
|
|
19
19
|
|
|
20
|
-
/** Fit a
|
|
20
|
+
/** Fit a script once, placing its first block at the viewport's top left with padding. */
|
|
21
21
|
export function fitScriptInWorkspace(workspace: ScriptFitWorkspace, scriptId: string,
|
|
22
22
|
blocks: {svgResize(workspace: ScriptFitWorkspace): void}): boolean {
|
|
23
23
|
const injection = workspace.getInjectionDiv();
|
|
@@ -33,8 +33,11 @@ export function fitScriptInWorkspace(workspace: ScriptFitWorkspace, scriptId: st
|
|
|
33
33
|
if (!metrics?.viewWidth || !metrics.viewHeight || !(bounds.width > 0) || !(bounds.height > 0)) return false;
|
|
34
34
|
// SVG bounds include nested reporters and the hat's overhang, but exclude folded, hidden bodies.
|
|
35
35
|
const origin = block.getRelativeToSurfaceXY();
|
|
36
|
-
|
|
37
|
-
const
|
|
36
|
+
// A wider block farther down the script must not shift the first block's anchor.
|
|
37
|
+
const path = root.querySelector<SVGGraphicsElement>(':scope > .blocklyPath');
|
|
38
|
+
const first = path?.getBBox() ?? bounds;
|
|
39
|
+
const left = origin.x + (path && workspace.RTL ? -first.x - first.width : first.x);
|
|
40
|
+
const top = origin.y + first.y;
|
|
38
41
|
const zoom = workspace.options?.zoomOptions;
|
|
39
42
|
const workspaceMin = positive(zoom?.minScale, 0.01);
|
|
40
43
|
const workspaceMax = Math.max(workspaceMin, positive(zoom?.maxScale, Infinity));
|
|
@@ -46,12 +49,7 @@ export function fitScriptInWorkspace(workspace: ScriptFitWorkspace, scriptId: st
|
|
|
46
49
|
workspace.setScale(scale);
|
|
47
50
|
const scaled = workspace.getMetrics();
|
|
48
51
|
if (!scaled) return false;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const x = width > scaled.viewWidth - padding * 2 && workspace.RTL ?
|
|
52
|
-
scaled.viewWidth - padding - width : Math.max(padding, (scaled.viewWidth - width) / 2);
|
|
53
|
-
const y = workspace.scale <= minScale ? padding : Math.max(padding, (scaled.viewHeight - height) / 2);
|
|
54
|
-
workspace.scrollbar.set(left * workspace.scale - scaled.contentLeft - x,
|
|
55
|
-
top * workspace.scale - scaled.contentTop - y);
|
|
52
|
+
workspace.scrollbar.set(left * workspace.scale - scaled.contentLeft - padding,
|
|
53
|
+
top * workspace.scale - scaled.contentTop - padding);
|
|
56
54
|
return true;
|
|
57
55
|
}
|