@kubohiroya/turbowarp-plus-editor-code-views 0.22.0 → 0.22.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 CHANGED
@@ -57,7 +57,7 @@ Editor は GUI の React 16 にこれらを描画するので、React 16.14 以
57
57
 
58
58
  ## スクリプト間の矢印
59
59
 
60
- コードの背面に、関数呼び出しを紫系の実線、メッセージ送信を橙系の破線で表示する。「送って待つ」には待機の印を添える。通常配置、Z/N 配置、折り畳み、プレビュー、別窓で同じ表現を使う。関数の再帰はスクリプトの外へ回る線で示す。選択・ホバーによる強調は太さと不透明度で行い、関係種別の色・線種は変えない。
60
+ コードの背面に、関数呼び出しを紫系の実線、メッセージ送信を橙系の破線で表示する。「送って待つ」は線7・間隔5の破線、「送る」はその半分の線3.5・間隔2.5の細かい破線で区別し、砂時計アイコンは表示しない。通常配置、Z/N 配置、折り畳み、プレビュー、別窓で同じ表現を使う。関数の再帰はスクリプトの外へ回る線で示す。選択・ホバーによる強調は太さと不透明度で行い、関係種別の色・線種は変えない。
61
61
 
62
62
  関数呼び出しとメッセージ送受信は、常に呼び出し元・送信元の右から出て、呼び出し先・受信先の左へ入る。左右の配置が逆でも接続する側を入れ替えない。自己呼び出しもスクリプトの外を回って左側へ戻る。
63
63
 
@@ -1,12 +1,12 @@
1
1
  import { isFoldedDefinition } from "./procedure-edits.js";
2
2
  import { readScriptRelations } from "./script-relations.js";
3
- function roundedRoute(points, radius) {
3
+ function roundedRoute(points, radii) {
4
4
  let path = `M ${points[0].x} ${points[0].y}`;
5
5
  for (let index = 1; index < points.length - 1; index++) {
6
6
  const before = points[index - 1], corner = points[index], after = points[index + 1];
7
7
  const entering = Math.hypot(corner.x - before.x, corner.y - before.y);
8
8
  const leaving = Math.hypot(after.x - corner.x, after.y - corner.y);
9
- const size = Math.min(radius, entering / 2, leaving / 2);
9
+ const size = Math.min(radii[index - 1], entering / 2, leaving / 2);
10
10
  if (!size) {
11
11
  path += ` L ${corner.x} ${corner.y}`;
12
12
  continue;
@@ -21,22 +21,6 @@ function roundedRoute(points, radius) {
21
21
  return `${path} L ${end.x} ${end.y}`;
22
22
  }
23
23
  const ns = 'http://www.w3.org/2000/svg';
24
- // Keep the same sixteen-unit hourglass as the call graph's relation badge.
25
- const relationWaitGlyph = 'M1 1h14M1 15h14M2 1v3l12 8v3M14 1v3l-12 8v3M2 4h12M2 12h12';
26
- /** Keep the badge beside the receiving end of the path, leaving its stroke visible. */
27
- function waitBadgePoint(path, offset) {
28
- const values = path.match(/-?(?:\d*\.?\d+)(?:e[+-]?\d+)?/gi).map(Number);
29
- const [sx, sy] = values;
30
- const [bx, by, tx, ty] = values.slice(-4);
31
- const endX = tx - bx;
32
- const endY = ty - by;
33
- const dx = endX || endY ? endX : tx - sx;
34
- const dy = endX || endY ? endY : ty - sy;
35
- const length = Math.hypot(dx, dy) || 1;
36
- const side = -dy < 0 || dy === 0 && dx > 0 ? -1 : 1;
37
- return { x: tx - dx / length * offset * .75 - dy / length * offset * side,
38
- y: ty - dy / length * offset * .75 + dx / length * offset * side };
39
- }
40
24
  const outlines = new Map();
41
25
  /** Intersect the actual outline, including a hat's overhang, rather than Blockly's layout padding. */
42
26
  function outlinePoint(shape, bounds, side, fraction) {
@@ -286,25 +270,19 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
286
270
  badgePoint = { x: middle, y: top - 6 };
287
271
  }
288
272
  if (serialRoute && source && destination) {
289
- const { right, top, clearance } = serialRoute;
273
+ const { right, top, clearance, radius } = serialRoute;
290
274
  // Leave room beside every script before turning vertically, then return through the gap above the hat.
291
275
  const approach = end.x - clearance;
292
276
  path = roundedRoute([start, { x: right, y: start.y }, { x: right, y: top },
293
- { x: approach, y: top }, { x: approach, y: end.y }, end], clearance);
277
+ { x: approach, y: top }, { x: approach, y: end.y }, end], [radius, radius, clearance, clearance]);
294
278
  badgePoint = { x: right, y: (start.y + top) / 2 };
295
279
  }
296
280
  const head = `M ${end.x - 9} ${end.y - 5} L ${end.x} ${end.y} L ${end.x - 9} ${end.y + 5}`;
297
- let waitTransform;
298
- if (relation.kind === 'message' && relation.wait) {
299
- const point = waitBadgePoint(path, 24);
300
- badgePoint = { x: point.x + 16, y: point.y + 4 };
301
- waitTransform = `translate(${point.x} ${point.y})`;
302
- }
303
- return { path, head, recursive, badgePoint, waitTransform };
281
+ return { path, head, recursive, badgePoint };
304
282
  }
305
283
  function drawArrow(drawing, matrix, inverse, area, highlighted) {
306
284
  const { relation, source, destination, count } = drawing;
307
- const { path, head, recursive, badgePoint, waitTransform } = arrowGeometry(drawing, matrix, inverse, area, highlighted);
285
+ const { path, head, recursive, badgePoint } = arrowGeometry(drawing, matrix, inverse, area, highlighted);
308
286
  const strings = text();
309
287
  const group = element('g', {
310
288
  'data-script-relation': relation.kind,
@@ -327,17 +305,9 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
327
305
  class: 'tw-script-relation-head',
328
306
  d: head
329
307
  }));
330
- if (waiting) {
331
- const badge = element('g', { class: 'tw-script-relation-wait', 'aria-label': strings.wait,
332
- transform: waitTransform });
333
- const title = element('title');
334
- title.textContent = strings.wait;
335
- badge.append(title, element('rect', { x: '-10', y: '-10', width: '20', height: '20', rx: '4' }), element('path', { class: 'tw-script-relation-wait-glyph', d: relationWaitGlyph, transform: 'translate(-8 -8)' }));
336
- group.append(badge);
337
- }
338
308
  if (count > 1) {
339
309
  const badge = element('text', { x: String(badgePoint.x), y: String(badgePoint.y),
340
- class: 'tw-script-relation-badge', 'text-anchor': waiting ? 'start' : 'middle' });
310
+ class: 'tw-script-relation-badge', 'text-anchor': 'middle' });
341
311
  badge.textContent = `×${count}`;
342
312
  group.append(badge);
343
313
  }
@@ -403,8 +373,6 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
403
373
  };
404
374
  set(group.querySelector('.tw-script-relation-line'), 'd', shape.path);
405
375
  set(group.querySelector('.tw-script-relation-head'), 'd', shape.head);
406
- if (shape.waitTransform)
407
- set(group.querySelector('.tw-script-relation-wait'), 'transform', shape.waitTransform);
408
376
  const count = group.querySelector('.tw-script-relation-badge');
409
377
  set(count, 'x', shape.badgePoint.x);
410
378
  set(count, 'y', shape.badgePoint.y);
@@ -484,7 +452,7 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
484
452
  if (!destination)
485
453
  continue;
486
454
  drawing.serialRoute = { right: rightEdge + (96 + lane * 16) * unit,
487
- top: destination.y - (14 + lane % 4 * 6) * unit, clearance: 8 * unit };
455
+ top: destination.y - (14 + lane % 4 * 6) * unit, clearance: 8 * unit, radius: 48 * unit };
488
456
  lane++;
489
457
  }
490
458
  // Reserve actual scrollable SVG width for the right-hand routes while preserving the block scale.
@@ -541,7 +509,7 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
541
509
  vm?.runtime?.targets?.find(item => item.id === endpoint.targetId)?.getName?.());
542
510
  const reason = relation.unresolved && strings[relation.unresolved];
543
511
  external.textContent = `${name ? `${name} · ` : ''}` +
544
- `${relation.label}${reason ? ` · ${reason}` : ''}${relation.kind === 'message' && relation.wait ? ' ⏳' : ''}${count > 1 ? ` ×${count}` : ''}`;
512
+ `${relation.label}${reason ? ` · ${reason}` : ''}${count > 1 ? ` ×${count}` : ''}`;
545
513
  external.disabled = !endpoint;
546
514
  external.setAttribute('aria-label', `${strings[relation.kind]}: ${external.textContent}`);
547
515
  external.toggleAttribute('data-highlighted', Boolean(highlighted));
@@ -146,7 +146,8 @@ export function attachScriptView({ workspace, ScratchBlocks, getLocale, mount, i
146
146
  width: box.width, height: box.height };
147
147
  });
148
148
  const placements = arrangeScripts(scripts, view, 'vertical', Math.max(64, 48 / scale))
149
- .map(placement => ({ ...placement, x: Math.max(placement.x, 32 / scale) }));
149
+ // Leave room for incoming arrowheads and return paths beside the fixed fold gutter.
150
+ .map(placement => ({ ...placement, x: placement.x + 40 / scale }));
150
151
  paintScripts(contents, placements, scale);
151
152
  paintFoldButtons(placements, scale);
152
153
  const projection = contents.querySelector('svg');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-code-views",
3
- "version": "0.22.0",
3
+ "version": "0.22.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",
@@ -24,15 +24,15 @@ type Point = {x: number; y: number};
24
24
  type Box = Point & {width: number; height: number};
25
25
  type Anchor = {id: string; box: Box; point(side: 'left' | 'right', fraction: number): Point};
26
26
  type Drawing = {relation: ScriptRelation; source?: Anchor; destination?: Anchor; count: number;
27
- serialRoute?: {right: number; top: number; clearance: number}};
27
+ serialRoute?: {right: number; top: number; clearance: number; radius: number}};
28
28
 
29
- function roundedRoute(points: Point[], radius: number) {
29
+ function roundedRoute(points: Point[], radii: readonly number[]) {
30
30
  let path = `M ${points[0].x} ${points[0].y}`;
31
31
  for (let index = 1; index < points.length - 1; index++) {
32
32
  const before = points[index - 1], corner = points[index], after = points[index + 1];
33
33
  const entering = Math.hypot(corner.x - before.x, corner.y - before.y);
34
34
  const leaving = Math.hypot(after.x - corner.x, after.y - corner.y);
35
- const size = Math.min(radius, entering / 2, leaving / 2);
35
+ const size = Math.min(radii[index - 1], entering / 2, leaving / 2);
36
36
  if (!size) {path += ` L ${corner.x} ${corner.y}`; continue;}
37
37
  const first = {x: corner.x + (before.x - corner.x) * size / entering,
38
38
  y: corner.y + (before.y - corner.y) * size / entering};
@@ -44,23 +44,6 @@ function roundedRoute(points: Point[], radius: number) {
44
44
  return `${path} L ${end.x} ${end.y}`;
45
45
  }
46
46
  const ns = 'http://www.w3.org/2000/svg';
47
- // Keep the same sixteen-unit hourglass as the call graph's relation badge.
48
- const relationWaitGlyph = 'M1 1h14M1 15h14M2 1v3l12 8v3M14 1v3l-12 8v3M2 4h12M2 12h12';
49
-
50
- /** Keep the badge beside the receiving end of the path, leaving its stroke visible. */
51
- function waitBadgePoint(path: string, offset: number): Point {
52
- const values = path.match(/-?(?:\d*\.?\d+)(?:e[+-]?\d+)?/gi).map(Number);
53
- const [sx, sy] = values;
54
- const [bx, by, tx, ty] = values.slice(-4);
55
- const endX = tx - bx;
56
- const endY = ty - by;
57
- const dx = endX || endY ? endX : tx - sx;
58
- const dy = endX || endY ? endY : ty - sy;
59
- const length = Math.hypot(dx, dy) || 1;
60
- const side = -dy < 0 || dy === 0 && dx > 0 ? -1 : 1;
61
- return {x: tx - dx / length * offset * .75 - dy / length * offset * side,
62
- y: ty - dy / length * offset * .75 + dx / length * offset * side};
63
- }
64
47
  type Outline = {points: (Point & {distance: number})[]; cuts: Map<string, Point>};
65
48
  const outlines = new Map<string, Outline>();
66
49
 
@@ -306,26 +289,20 @@ export function attachScriptArrows({workspace, vm, getTarget, getRelations, getL
306
289
  badgePoint = {x: middle, y: top - 6};
307
290
  }
308
291
  if (serialRoute && source && destination) {
309
- const {right, top, clearance} = serialRoute;
292
+ const {right, top, clearance, radius} = serialRoute;
310
293
  // Leave room beside every script before turning vertically, then return through the gap above the hat.
311
294
  const approach = end.x - clearance;
312
295
  path = roundedRoute([start, {x: right, y: start.y}, {x: right, y: top},
313
- {x: approach, y: top}, {x: approach, y: end.y}, end], clearance);
296
+ {x: approach, y: top}, {x: approach, y: end.y}, end], [radius, radius, clearance, clearance]);
314
297
  badgePoint = {x: right, y: (start.y + top) / 2};
315
298
  }
316
299
  const head = `M ${end.x - 9} ${end.y - 5} L ${end.x} ${end.y} L ${end.x - 9} ${end.y + 5}`;
317
- let waitTransform: string | undefined;
318
- if (relation.kind === 'message' && relation.wait) {
319
- const point = waitBadgePoint(path, 24);
320
- badgePoint = {x: point.x + 16, y: point.y + 4};
321
- waitTransform = `translate(${point.x} ${point.y})`;
322
- }
323
- return {path, head, recursive, badgePoint, waitTransform};
300
+ return {path, head, recursive, badgePoint};
324
301
  }
325
302
 
326
303
  function drawArrow(drawing: Drawing, matrix: DOMMatrix, inverse: DOMMatrix, area: DOMRect, highlighted: boolean) {
327
304
  const {relation, source, destination, count} = drawing;
328
- const {path, head, recursive, badgePoint, waitTransform} = arrowGeometry(drawing, matrix, inverse, area, highlighted);
305
+ const {path, head, recursive, badgePoint} = arrowGeometry(drawing, matrix, inverse, area, highlighted);
329
306
  const strings = text();
330
307
  const group = element('g', {
331
308
  'data-script-relation': relation.kind,
@@ -348,18 +325,9 @@ export function attachScriptArrows({workspace, vm, getTarget, getRelations, getL
348
325
  class: 'tw-script-relation-head',
349
326
  d: head
350
327
  }));
351
- if (waiting) {
352
- const badge = element('g', {class: 'tw-script-relation-wait', 'aria-label': strings.wait,
353
- transform: waitTransform});
354
- const title = element('title');
355
- title.textContent = strings.wait;
356
- badge.append(title, element('rect', {x: '-10', y: '-10', width: '20', height: '20', rx: '4'}),
357
- element('path', {class: 'tw-script-relation-wait-glyph', d: relationWaitGlyph, transform: 'translate(-8 -8)'}));
358
- group.append(badge);
359
- }
360
328
  if (count > 1) {
361
329
  const badge = element('text', {x: String(badgePoint.x), y: String(badgePoint.y),
362
- class: 'tw-script-relation-badge', 'text-anchor': waiting ? 'start' : 'middle'});
330
+ class: 'tw-script-relation-badge', 'text-anchor': 'middle'});
363
331
  badge.textContent = `×${count}`;
364
332
  group.append(badge);
365
333
  }
@@ -414,7 +382,6 @@ export function attachScriptArrows({workspace, vm, getTarget, getRelations, getL
414
382
  };
415
383
  set(group.querySelector('.tw-script-relation-line'), 'd', shape.path);
416
384
  set(group.querySelector('.tw-script-relation-head'), 'd', shape.head);
417
- if (shape.waitTransform) set(group.querySelector('.tw-script-relation-wait'), 'transform', shape.waitTransform);
418
385
  const count = group.querySelector('.tw-script-relation-badge');
419
386
  set(count, 'x', shape.badgePoint.x); set(count, 'y', shape.badgePoint.y);
420
387
  }
@@ -482,7 +449,7 @@ export function attachScriptArrows({workspace, vm, getTarget, getRelations, getL
482
449
  const destination = scripts.get(drawing.relation.destination.scriptId);
483
450
  if (!destination) continue;
484
451
  drawing.serialRoute = {right: rightEdge + (96 + lane * 16) * unit,
485
- top: destination.y - (14 + lane % 4 * 6) * unit, clearance: 8 * unit};
452
+ top: destination.y - (14 + lane % 4 * 6) * unit, clearance: 8 * unit, radius: 48 * unit};
486
453
  lane++;
487
454
  }
488
455
  // Reserve actual scrollable SVG width for the right-hand routes while preserving the block scale.
@@ -535,7 +502,7 @@ export function attachScriptArrows({workspace, vm, getTarget, getRelations, getL
535
502
  vm?.runtime?.targets?.find(item => item.id === endpoint.targetId)?.getName?.());
536
503
  const reason = relation.unresolved && strings[relation.unresolved];
537
504
  external.textContent = `${name ? `${name} · ` : ''}` +
538
- `${relation.label}${reason ? ` · ${reason}` : ''}${relation.kind === 'message' && relation.wait ? ' ⏳' : ''}${count > 1 ? ` ×${count}` : ''}`;
505
+ `${relation.label}${reason ? ` · ${reason}` : ''}${count > 1 ? ` ×${count}` : ''}`;
539
506
  external.disabled = !endpoint;
540
507
  external.setAttribute('aria-label', `${strings[relation.kind]}: ${external.textContent}`);
541
508
  external.toggleAttribute('data-highlighted', Boolean(highlighted));
@@ -165,7 +165,8 @@ export function attachScriptView({
165
165
  width: box.width, height: box.height};
166
166
  });
167
167
  const placements = arrangeScripts(scripts, view, 'vertical', Math.max(64, 48 / scale))
168
- .map(placement => ({...placement, x: Math.max(placement.x, 32 / scale)}));
168
+ // Leave room for incoming arrowheads and return paths beside the fixed fold gutter.
169
+ .map(placement => ({...placement, x: placement.x + 40 / scale}));
169
170
  paintScripts(contents, placements, scale);
170
171
  paintFoldButtons(placements, scale);
171
172
  const projection = contents.querySelector('svg');
package/src/styles.css CHANGED
@@ -567,6 +567,10 @@
567
567
  --tw-script-relation-dash: 7 5;
568
568
  }
569
569
 
570
+ [data-script-relation="message"][data-wait="false"] {
571
+ --tw-script-relation-dash: 3.5 2.5;
572
+ }
573
+
570
574
  [data-script-relation-layer] {
571
575
  pointer-events: none;
572
576
  }
@@ -593,7 +597,7 @@
593
597
  stroke-opacity: 0.2;
594
598
  }
595
599
 
596
- /* Fade external connections without reducing the wait icon's opacity. */
600
+ /* Keep external connections faint, including during highlighting. */
597
601
  [data-script-relation-layer] > [data-script-relation][data-script-external] >
598
602
  :is(.tw-script-relation-line, .tw-script-relation-head, .tw-script-relation-badge) {
599
603
  opacity: 0.05;
@@ -634,24 +638,6 @@
634
638
  pointer-events: none;
635
639
  }
636
640
 
637
- .tw-script-relation-wait {
638
- pointer-events: visiblePainted;
639
- }
640
-
641
- .tw-script-relation-wait rect {
642
- fill: var(--ui-primary, Canvas);
643
- stroke: var(--tw-script-relation-stroke);
644
- stroke-width: 1;
645
- }
646
-
647
- .tw-script-relation-wait .tw-script-relation-wait-glyph {
648
- fill: none;
649
- stroke: var(--tw-script-relation-stroke);
650
- stroke-width: 1.4;
651
- stroke-linecap: round;
652
- stroke-linejoin: round;
653
- }
654
-
655
641
  .tw-script-relation-guide {
656
642
  position: absolute;
657
643
  z-index: 5;