@kubohiroya/turbowarp-plus-editor-code-views 0.21.0 → 0.21.2

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 CHANGED
@@ -6,7 +6,7 @@ TurboWarp Plus Editor のコードの画面。1つの作品と1つの取り消
6
6
 
7
7
  ## 選択したスクリプトの表示
8
8
 
9
- 関数・ハットなどを選んで開くと、そのスクリプトの描画範囲を24pxの余白付きでパネルへ収める。自動ズームは50〜125%に制限し、ワークスペース固有の制限が厳しければそちらに従う。下限倍率ではスクリプトの上端を余白の下に置き、長いスクリプトも先頭から読めるようにする。通常の編集・手動ズームでは再フィットしない。
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 fits its rendered script into the pane with 24px of padding. Automatic zoom stays between 50% and 125%, respecting stricter workspace limits. At the lower limit, the script starts below the top padding so a long script remains readable from its beginning. Ordinary edits and manual zoom do not refit it.
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
 
@@ -252,10 +252,9 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
252
252
  const head = `M ${end.x - 9} ${end.y - 5} L ${end.x} ${end.y} L ${end.x - 9} ${end.y + 5}`;
253
253
  let waitTransform;
254
254
  if (relation.kind === 'message' && relation.wait) {
255
- const scale = Math.hypot(matrix.a, matrix.b) || 1;
256
- const point = waitBadgePoint(path, 24 / scale);
257
- badgePoint = { x: point.x + 16 / scale, y: point.y + 4 / scale };
258
- waitTransform = `translate(${point.x} ${point.y}) scale(${1 / scale})`;
255
+ const point = waitBadgePoint(path, 24);
256
+ badgePoint = { x: point.x + 16, y: point.y + 4 };
257
+ waitTransform = `translate(${point.x} ${point.y})`;
259
258
  }
260
259
  return { path, head, recursive, badgePoint, waitTransform };
261
260
  }
@@ -27,7 +27,7 @@ type ScriptFitWorkspace = {
27
27
  set(x: number, y: number): void;
28
28
  };
29
29
  };
30
- /** Fit a visible script once. Hidden or not-yet-rendered workspaces can retry after their layout settles. */
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;
@@ -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 visible script once. Hidden or not-yet-rendered workspaces can retry after their layout settles. */
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
- const left = origin.x + bounds.x;
22
- const top = origin.y + bounds.y;
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
- const width = bounds.width * workspace.scale;
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.0",
3
+ "version": "0.21.2",
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",
@@ -277,10 +277,9 @@ export function attachScriptArrows({workspace, vm, getTarget, getRelations, getL
277
277
  const head = `M ${end.x - 9} ${end.y - 5} L ${end.x} ${end.y} L ${end.x - 9} ${end.y + 5}`;
278
278
  let waitTransform: string | undefined;
279
279
  if (relation.kind === 'message' && relation.wait) {
280
- const scale = Math.hypot(matrix.a, matrix.b) || 1;
281
- const point = waitBadgePoint(path, 24 / scale);
282
- badgePoint = {x: point.x + 16 / scale, y: point.y + 4 / scale};
283
- waitTransform = `translate(${point.x} ${point.y}) scale(${1 / scale})`;
280
+ const point = waitBadgePoint(path, 24);
281
+ badgePoint = {x: point.x + 16, y: point.y + 4};
282
+ waitTransform = `translate(${point.x} ${point.y})`;
284
283
  }
285
284
  return {path, head, recursive, badgePoint, waitTransform};
286
285
  }
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 visible script once. Hidden or not-yet-rendered workspaces can retry after their layout settles. */
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
- const left = origin.x + bounds.x;
37
- const top = origin.y + bounds.y;
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
- const width = bounds.width * workspace.scale;
50
- const height = bounds.height * workspace.scale;
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
  }
package/src/styles.css CHANGED
@@ -593,7 +593,9 @@
593
593
  stroke-opacity: 0.2;
594
594
  }
595
595
 
596
- [data-script-relation-layer] > [data-script-relation][data-script-external] {
596
+ /* Fade external connections without reducing the wait icon's opacity. */
597
+ [data-script-relation-layer] > [data-script-relation][data-script-external] >
598
+ :is(.tw-script-relation-line, .tw-script-relation-head, .tw-script-relation-badge) {
597
599
  opacity: 0.05;
598
600
  }
599
601