@kubohiroya/turbowarp-plus-editor-code-views 0.21.3 → 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/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;
@@ -603,17 +607,19 @@
603
607
  stroke-opacity: 1;
604
608
  }
605
609
 
610
+ .tw-script-editor-menu-divider {
611
+ border-top: 1px solid var(--ui-black-transparent, rgb(0 0 0 / 15%));
612
+ margin-block-start: 4px;
613
+ }
614
+
606
615
  .tw-script-relation-script-highlight {
607
616
  fill: light-dark(#3373cc, #93c5fd);
608
617
  fill-opacity: 0.1;
609
- stroke: light-dark(#2563a8, #93c5fd);
610
- stroke-width: 2;
611
- vector-effect: non-scaling-stroke;
618
+ stroke: none;
612
619
  pointer-events: none;
613
620
  }
614
621
 
615
622
  .tw-script-relation-script-highlight[data-emphasis="source"] {
616
- stroke-width: 3;
617
623
  fill-opacity: 0.15;
618
624
  }
619
625
 
@@ -632,24 +638,6 @@
632
638
  pointer-events: none;
633
639
  }
634
640
 
635
- .tw-script-relation-wait {
636
- pointer-events: visiblePainted;
637
- }
638
-
639
- .tw-script-relation-wait rect {
640
- fill: var(--ui-primary, Canvas);
641
- stroke: var(--tw-script-relation-stroke);
642
- stroke-width: 1;
643
- }
644
-
645
- .tw-script-relation-wait .tw-script-relation-wait-glyph {
646
- fill: none;
647
- stroke: var(--tw-script-relation-stroke);
648
- stroke-width: 1.4;
649
- stroke-linecap: round;
650
- stroke-linejoin: round;
651
- }
652
-
653
641
  .tw-script-relation-guide {
654
642
  position: absolute;
655
643
  z-index: 5;
@@ -747,13 +735,48 @@
747
735
  display: none;
748
736
  }
749
737
 
738
+ .tw-script-fold-gutter {
739
+ position: absolute;
740
+ z-index: 4;
741
+ width: 28px;
742
+ overflow: hidden;
743
+ pointer-events: none;
744
+ }
745
+
746
+ .tw-script-fold-gutter[hidden] {
747
+ display: none;
748
+ }
749
+
750
+ .tw-script-fold-gutter > button {
751
+ position: absolute;
752
+ left: 2px;
753
+ width: 24px;
754
+ height: 24px;
755
+ padding: 0;
756
+ border: 0;
757
+ border-radius: 4px;
758
+ background: var(--ui-primary, Canvas);
759
+ color: var(--text-primary, CanvasText);
760
+ font: 14px/24px system-ui, sans-serif;
761
+ cursor: pointer;
762
+ pointer-events: auto;
763
+ }
764
+
765
+ .tw-script-fold-gutter > button:is(:hover, :focus-visible) {
766
+ background: var(--ui-tertiary, #e5e7eb);
767
+ outline: 2px solid var(--motion-primary, #4c97ff);
768
+ outline-offset: -2px;
769
+ }
770
+
750
771
  .blocklySvg[data-script-serial] {
751
772
  z-index: 2;
752
773
  background: transparent;
753
774
  pointer-events: none;
754
775
  }
755
776
 
756
- .blocklySvg[data-script-serial] :is(.blocklyMainBackground, .blocklyBlockCanvas, .blocklyBubbleCanvas) {
777
+ .blocklySvg[data-script-serial] :is(.blocklyMainBackground, .blocklyBlockCanvas, .blocklyBubbleCanvas, .blocklyFlyout,
778
+ .blocklyScrollbarVertical, .blocklyScrollbarHorizontal),
779
+ .injectionDiv:has(> [data-script-serial]) > .blocklyFlyout {
757
780
  visibility: hidden;
758
781
  }
759
782
 
@@ -778,6 +801,44 @@
778
801
  cursor: pointer;
779
802
  }
780
803
 
804
+ .tw-serial-script-editor {
805
+ position: fixed;
806
+ inset: 0;
807
+ box-sizing: border-box;
808
+ width: 100vw;
809
+ height: 100vh;
810
+ max-width: none;
811
+ max-height: none;
812
+ margin: 0;
813
+ padding: 1rem;
814
+ border: 0;
815
+ background: var(--ui-primary, Canvas);
816
+ color: var(--text-primary, CanvasText);
817
+ font: 0.9rem/1.4 system-ui, sans-serif;
818
+ }
819
+
820
+ .tw-serial-script-editor[open] {
821
+ display: flex;
822
+ flex-direction: column;
823
+ gap: 0.75rem;
824
+ }
825
+
826
+ .tw-serial-script-editor > h2 {
827
+ margin: 0;
828
+ font-size: 1.1rem;
829
+ }
830
+
831
+ .tw-serial-script-editor > [data-serial-script-editor] {
832
+ position: relative;
833
+ flex: 1;
834
+ min-height: 0;
835
+ }
836
+
837
+ .tw-serial-script-editor > button {
838
+ align-self: flex-end;
839
+ padding: 0.5rem 1.5rem;
840
+ }
841
+
781
842
  .tw-script-layout-dialog {
782
843
  box-sizing: border-box;
783
844
  width: min(44rem, calc(100% - 2rem));
@@ -1,3 +1,5 @@
1
+ import {getScriptProjection} from './script-projection.ts';
2
+
1
3
  type OverviewOptions = {
2
4
  workspace: any;
3
5
  ScratchBlocks: any;
@@ -44,23 +46,42 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
44
46
  function refreshShapes() {
45
47
  const retained = new Set<string>();
46
48
  const additions = document.createDocumentFragment();
47
- for (const block of workspace.getAllBlocks(false)) {
48
- const root = block.getSvgRoot() as SVGElement | null;
49
- if (!root || !canvas.contains(root) || root.closest('[data-tw-plus-hidden]')) continue;
50
- const source = root.querySelector(':scope > .blocklyPath');
51
- const data = source?.getAttribute('d');
52
- if (!data) continue;
53
- retained.add(block.id);
54
- let path = paths.get(block.id);
49
+ const paint = (id: string, data: string, fill: string, transform: string) => {
50
+ retained.add(id);
51
+ let path = paths.get(id);
55
52
  if (!path) {
56
53
  path = element('path');
57
- paths.set(block.id, path);
54
+ paths.set(id, path);
58
55
  additions.append(path);
59
56
  }
60
- const position = block.getRelativeToSurfaceXY();
61
57
  attribute(path, 'd', data);
62
- attribute(path, 'fill', source.getAttribute('fill') || block.getColour());
63
- attribute(path, 'transform', `translate(${position.x} ${position.y})${block.RTL ? ' scale(-1 1)' : ''}`);
58
+ attribute(path, 'fill', fill);
59
+ attribute(path, 'transform', transform);
60
+ };
61
+ const projection = getScriptProjection(workspace);
62
+ if (projection) {
63
+ const inverse = projection.svg.getScreenCTM()?.inverse();
64
+ if (inverse) for (const source of projection.svg.querySelectorAll<SVGPathElement>('.blocklyPath')) {
65
+ if (source.closest('[data-tw-plus-hidden]')) continue;
66
+ const id = source.closest('[data-id]')?.getAttribute('data-id');
67
+ const data = source.getAttribute('d');
68
+ const matrix = source.getScreenCTM();
69
+ if (!id || !data || !matrix) continue;
70
+ const transform = inverse.multiply(matrix);
71
+ paint(id, data, source.getAttribute('fill') || view.getComputedStyle(source).fill,
72
+ `matrix(${transform.a} ${transform.b} ${transform.c} ${transform.d} ${transform.e} ${transform.f})`);
73
+ }
74
+ } else {
75
+ for (const block of workspace.getAllBlocks(false)) {
76
+ const root = block.getSvgRoot() as SVGElement | null;
77
+ if (!root || !canvas.contains(root) || root.closest('[data-tw-plus-hidden]')) continue;
78
+ const source = root.querySelector(':scope > .blocklyPath');
79
+ const data = source?.getAttribute('d');
80
+ if (!data) continue;
81
+ const position = block.getRelativeToSurfaceXY();
82
+ paint(block.id, data, source.getAttribute('fill') || block.getColour(),
83
+ `translate(${position.x} ${position.y})${block.RTL ? ' scale(-1 1)' : ''}`);
84
+ }
64
85
  }
65
86
  for (const [id, path] of paths) if (!retained.has(id)) {path.remove(); paths.delete(id);}
66
87
  if (additions.childNodes.length) shapes.append(additions);
@@ -73,12 +94,17 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
73
94
  const metrics = workspace.isVisible() && workspace.getMetrics();
74
95
  if (!metrics || metrics.viewWidth <= 32 || metrics.viewHeight <= 32) {map.toggleAttribute('hidden', true); return;}
75
96
  const scale = workspace.scale;
76
- const x = metrics.viewLeft / scale, y = metrics.viewTop / scale;
77
- const width = metrics.viewWidth / scale, height = metrics.viewHeight / scale;
97
+ const projection = getScriptProjection(workspace);
98
+ const x = projection ? projection.surface.scrollLeft / scale : metrics.viewLeft / scale;
99
+ const y = projection ? projection.surface.scrollTop / scale : metrics.viewTop / scale;
100
+ const width = (projection ? projection.surface.clientWidth : metrics.viewWidth) / scale;
101
+ const height = (projection ? projection.surface.clientHeight : metrics.viewHeight) / scale;
78
102
  const content = metrics.contentWidth > 0 && metrics.contentHeight > 0;
79
- const area = content ? {x: metrics.contentLeft / scale, y: metrics.contentTop / scale,
103
+ const box = projection?.svg.viewBox.baseVal;
104
+ const area = box ? {x: box.x, y: box.y, width: Math.max(box.width, width), height: Math.max(box.height, height)} :
105
+ content ? {x: metrics.contentLeft / scale, y: metrics.contentTop / scale,
80
106
  width: metrics.contentWidth / scale, height: metrics.contentHeight / scale} : {x, y, width, height};
81
- if (!workspace.scrollbar && content) {
107
+ if (!projection && !workspace.scrollbar && content) {
82
108
  const right = Math.max(x + width, area.x + area.width), bottom = Math.max(y + height, area.y + area.height);
83
109
  area.x = Math.min(x, area.x); area.y = Math.min(y, area.y);
84
110
  area.width = right - area.x; area.height = bottom - area.y;
@@ -98,8 +124,8 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
98
124
  // All layout reads above precede writes. Identical values do not invalidate the editor's styles.
99
125
  if (needsShapes) refreshShapes();
100
126
  map.toggleAttribute('hidden', false);
101
- const box = `${area.x} ${area.y} ${area.width} ${area.height}`;
102
- attribute(map, 'viewBox', box); attribute(clip, 'viewBox', box);
127
+ const viewBox = `${area.x} ${area.y} ${area.width} ${area.height}`;
128
+ attribute(map, 'viewBox', viewBox); attribute(clip, 'viewBox', viewBox);
103
129
  for (const [name, value] of Object.entries(area)) attribute(clip, name, value);
104
130
  for (const [name, value] of Object.entries({x, y, width, height})) attribute(viewport, name, value);
105
131
  style(map, 'width', `${mapWidth}px`); style(map, 'height', `${mapHeight}px`);
@@ -130,10 +156,22 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
130
156
  const resize = new view.ResizeObserver(schedule);
131
157
  resize.observe(container);
132
158
  const events = new view.AbortController();
159
+ let projectedSVG: SVGSVGElement | undefined;
160
+ container.addEventListener('scriptprojectionchange', () => {
161
+ const next = getScriptProjection(workspace)?.svg;
162
+ needsShapes ||= next !== projectedSVG;
163
+ projectedSVG = next;
164
+ schedule();
165
+ }, {signal: events.signal});
133
166
  view.addEventListener('resize', schedule, {signal: events.signal});
134
167
  view.addEventListener('scroll', schedule, {signal: events.signal, passive: true});
135
168
 
136
169
  const moveView = (left: number, top: number) => {
170
+ const projection = getScriptProjection(workspace);
171
+ if (projection) {
172
+ projection.surface.scrollTo(left * workspace.scale, top * workspace.scale);
173
+ return;
174
+ }
137
175
  const metrics = workspace.getMetrics();
138
176
  if (!metrics || !workspace.scrollbar) return;
139
177
  const clamp = (value: number, maximum: number) => Math.max(0, Math.min(value, Math.max(0, maximum)));
@@ -146,12 +184,14 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
146
184
  const point = (event: PointerEvent, inverse: DOMMatrix) =>
147
185
  new view.DOMPoint(event.clientX, event.clientY).matrixTransform(inverse);
148
186
  map.addEventListener('pointerdown', event => {
149
- if (!event.isPrimary || event.button !== 0 || pointer || !workspace.scrollbar) return;
187
+ const projection = getScriptProjection(workspace);
188
+ if (!event.isPrimary || event.button !== 0 || pointer || (!projection && !workspace.scrollbar)) return;
150
189
  const matrix = map.getScreenCTM(), metrics = workspace.getMetrics();
151
190
  if (!matrix || !metrics) return;
152
191
  const inverse = matrix.inverse();
153
192
  pointer = {id: event.pointerId, x: event.clientX, y: event.clientY, start: point(event, inverse), inverse,
154
- left: metrics.viewLeft / workspace.scale, top: metrics.viewTop / workspace.scale,
193
+ left: projection ? projection.surface.scrollLeft / workspace.scale : metrics.viewLeft / workspace.scale,
194
+ top: projection ? projection.surface.scrollTop / workspace.scale : metrics.viewTop / workspace.scale,
155
195
  viewport: event.target === viewport, moved: false};
156
196
  map.setPointerCapture(event.pointerId);
157
197
  }, {signal: events.signal});
@@ -173,8 +213,9 @@ export function attachWorkspaceOverview({workspace, ScratchBlocks, zoomHeight =
173
213
  move(event);
174
214
  if (!pointer.moved) {
175
215
  const current = point(event, pointer.inverse), metrics = workspace.getMetrics();
176
- if (metrics) moveView(current.x - metrics.viewWidth / (2 * workspace.scale),
177
- current.y - metrics.viewHeight / (2 * workspace.scale));
216
+ const projection = getScriptProjection(workspace);
217
+ if (metrics) moveView(current.x - (projection ? projection.surface.clientWidth : metrics.viewWidth) / (2 * workspace.scale),
218
+ current.y - (projection ? projection.surface.clientHeight : metrics.viewHeight) / (2 * workspace.scale));
178
219
  ScratchBlocks.hideChaff(true);
179
220
  }
180
221
  }
package/src/workspace.ts CHANGED
@@ -222,7 +222,7 @@ function attachScriptVisibility({vm, blocks, workspace, homeDocument, onError})
222
222
  const labels = () => japanese() ? {fold: '折りたたみ', unfold: '折りたたみを解除', folded: '折りたたみ中'} :
223
223
  {fold: 'Fold', unfold: 'Unfold', folded: 'Folded'};
224
224
  const vmBlock = (id: string) => vm.editingTarget?.blocks._blocks[id];
225
- const isFolded = (block: StackBlock) => isHatBlock(block) && isFoldedDefinition(vmBlock(block.id));
225
+ const isFolded = (block: StackBlock) => isFoldedDefinition(vmBlock(block.id));
226
226
 
227
227
  let focus: {id: string; extras: Set<string>; onLost?: () => void} | undefined;
228
228
  // The GUI can attach the code area again; what an earlier attachment left on the workspace is not its own.
@@ -404,7 +404,7 @@ function attachScriptVisibility({vm, blocks, workspace, homeDocument, onError})
404
404
  /** Paint the folded scripts of a read-only workspace, such as the preview of a code view. */
405
405
  function paintPreviewFolds(blocks, preview, target, label: string) {
406
406
  for (const top of preview.getTopBlocks(false) as StackBlock[]) {
407
- paintFold(top, isHatBlock(top) && isFoldedDefinition(target.blocks._blocks[top.id]), label);
407
+ paintFold(top, isFoldedDefinition(target.blocks._blocks[top.id]), label);
408
408
  }
409
409
  }
410
410
 
@@ -1008,6 +1008,7 @@ function attachProcedureEditor({vm, blocks, workspace, options, onError, homeDoc
1008
1008
 
1009
1009
  return {
1010
1010
  workspace: editor,
1011
+ flush() {blocks.Events.fireNow_();},
1011
1012
  showBlock(id: string) {
1012
1013
  pendingBlock = id;
1013
1014
  reveal();