@popcorn245/cornfield 0.41.0 → 0.43.0

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.
Files changed (45) hide show
  1. package/core/contrast.js +68 -2
  2. package/core/delta-e.js +66 -0
  3. package/core/schema.js +29 -7
  4. package/core/strings.js +11 -0
  5. package/explorer/capped.js +6 -5
  6. package/explorer/cloud-model.js +10 -7
  7. package/explorer/decision-model.js +231 -0
  8. package/explorer/diff-marks.js +3 -1
  9. package/explorer/edge-key.js +59 -0
  10. package/explorer/explorer.css +55 -9
  11. package/explorer/flows.js +0 -2
  12. package/explorer/forge-panel.js +30 -8
  13. package/explorer/glyphs.js +130 -0
  14. package/explorer/house-model.js +2 -2
  15. package/explorer/index.html +7 -18
  16. package/explorer/keyboard-model.js +4 -1
  17. package/explorer/keyboard.js +14 -2
  18. package/explorer/kind-letters.js +9 -5
  19. package/explorer/labels.js +33 -34
  20. package/explorer/layers.js +16 -5
  21. package/explorer/main.js +3 -2
  22. package/explorer/map-style.js +3 -0
  23. package/explorer/panels.js +92 -7
  24. package/explorer/proposal-model.js +24 -0
  25. package/explorer/proposal.js +13 -6
  26. package/explorer/render.js +2 -2
  27. package/explorer/renderer-canvas2d.js +169 -26
  28. package/explorer/renderer-webgl.js +51 -17
  29. package/explorer/review-column.js +22 -4
  30. package/explorer/review.js +413 -44
  31. package/explorer/runs-model.js +1 -1
  32. package/explorer/scene.js +58 -47
  33. package/explorer/selection-model.js +150 -0
  34. package/explorer/selection-view.js +36 -0
  35. package/explorer/shaders.js +76 -13
  36. package/explorer/spatial.js +7 -4
  37. package/explorer/state.js +8 -0
  38. package/explorer/tokens.css +1 -0
  39. package/explorer/whatif.js +84 -7
  40. package/package.json +1 -1
  41. package/server/decision.js +117 -0
  42. package/server/proposal-pulls.js +1 -1
  43. package/server/proposals.js +58 -9
  44. package/server/server.js +19 -2
  45. package/server/submit-review.js +52 -7
@@ -8,15 +8,48 @@
8
8
  * labels are the label layer's (labels.js), one transparent canvas over the map for either renderer.
9
9
  */
10
10
 
11
- import { CORE_RATIO, ARROW, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, packetPoint } from './scene.js';
12
- import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
11
+ import { CORE_RATIO, ARROW, END_SHAPES, SHAPE_SIZES, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, packetPoint } from './scene.js';
12
+ import { GLYPH_TOKEN, ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
13
13
  import { LETTER_RATIO, letterImage, showsLetters } from './kind-letters.js';
14
+ import { GLYPH_RATIO, glyphImage, glyphInk, showsGlyph } from './glyphs.js';
14
15
 
15
16
  const TAU = Math.PI * 2;
16
17
  /** A glow thinner than this on screen (px) is not drawn: zoomed out it is a fraction of a pixel, and costs a stroke or fill per edge and node */
17
18
  const GLOW_MIN_PX = 1.5;
19
+ /** A scene with this many edges or fewer is drawn directly each frame; more, and its lines go into the layer while packets move */
20
+ export const LAYER_MIN_EDGES = 600;
18
21
  const circle = (ctx, x, y, r) => { ctx.beginPath(); ctx.arc(x, y, r, 0, TAU); };
19
22
 
23
+ /**
24
+ * The path of a node's silhouette (spec 0008 D8), inside the circle of radius `r` it is hit-tested by, or a little past it for a diamond: the circle for code,
25
+ * a rounded square for data, a hexagon for what is outside, a square for where things run, a diamond for people. The WebGL node shader draws the same shapes
26
+ * with the same sizes (scene.js `SHAPE_SIZES`, shaders.js `sdShape`).
27
+ */
28
+ export function silhouette(ctx, shape, x, y, r) {
29
+ if (shape === 'rounded-square' || shape === 'square') {
30
+ const h = r * (shape === 'square' ? SHAPE_SIZES.squareHalf : SHAPE_SIZES.roundedHalf);
31
+ const c = r * (shape === 'square' ? SHAPE_SIZES.squareCorner : SHAPE_SIZES.roundedCorner);
32
+ ctx.beginPath();
33
+ if (ctx.roundRect) ctx.roundRect(x - h, y - h, h * 2, h * 2, c); else ctx.rect(x - h, y - h, h * 2, h * 2);
34
+ return;
35
+ }
36
+ if (shape === 'hexagon') {
37
+ const R = (r * SHAPE_SIZES.hexInradius) / Math.cos(Math.PI / 6); // flat top and bottom: the inradius is what the SDF takes
38
+ ctx.beginPath();
39
+ for (let i = 0; i < 6; i++) { const a = Math.PI / 6 + (i * Math.PI) / 3; const px = x + R * Math.cos(a), py = y + R * Math.sin(a); if (i) ctx.lineTo(px, py); else ctx.moveTo(px, py); }
40
+ ctx.closePath();
41
+ return;
42
+ }
43
+ if (shape === 'diamond') {
44
+ const h = r * SHAPE_SIZES.diamondHalf;
45
+ ctx.beginPath();
46
+ ctx.moveTo(x, y - h); ctx.lineTo(x + h, y); ctx.lineTo(x, y + h); ctx.lineTo(x - h, y);
47
+ ctx.closePath();
48
+ return;
49
+ }
50
+ circle(ctx, x, y, r);
51
+ }
52
+
20
53
  // ---------------------------------------------------------------------------
21
54
  // The background
22
55
  // ---------------------------------------------------------------------------
@@ -101,17 +134,13 @@ function drawEdge(ctx, edge, timeMs, zoom, withPacket = true) {
101
134
  ctx.stroke();
102
135
  }
103
136
 
104
- // Arrowhead along the curve's end tangent
137
+ // The tick marks of a call that bites later than now: across the middle, one or two (spec 0008 D7)
138
+ if (edge.ticks) drawTicks(ctx, edge, zoom);
139
+
140
+ // The mark at the target, along the curve's end tangent: one per family of edge (spec 0008 D7)
105
141
  if (edge.arrow) {
106
142
  const { cx, cy } = edge.curve || { cx: edge.x1, cy: edge.y1 };
107
- const ang = Math.atan2(edge.y2 - cy, edge.x2 - cx);
108
- ctx.beginPath();
109
- ctx.moveTo(edge.x2, edge.y2);
110
- ctx.lineTo(edge.x2 - Math.cos(ang - ARROW.spread) * ARROW.length, edge.y2 - Math.sin(ang - ARROW.spread) * ARROW.length);
111
- ctx.lineTo(edge.x2 - Math.cos(ang + ARROW.spread) * ARROW.length, edge.y2 - Math.sin(ang + ARROW.spread) * ARROW.length);
112
- ctx.closePath();
113
- ctx.fillStyle = edge.color;
114
- ctx.fill();
143
+ drawEnd(ctx, edge, Math.atan2(edge.y2 - cy, edge.x2 - cx), zoom);
115
144
  }
116
145
 
117
146
  // The edge's label (selection only) is the label layer's, not drawn here
@@ -120,6 +149,66 @@ function drawEdge(ctx, edge, timeMs, zoom, withPacket = true) {
120
149
  ctx.restore();
121
150
  }
122
151
 
152
+ /**
153
+ * The mark at an edge's target, pointing along `ang` (spec 0008 D7): a filled triangle (services), an open chevron (data), a bar across the
154
+ * line (places) or an open diamond (tokens). The same shapes the WebGL tips pass draws (shaders.js TIP_FRAG).
155
+ */
156
+ function drawEnd(ctx, edge, ang, zoom) {
157
+ const kind = edge.end || 'triangle';
158
+ const { x2: x, y2: y, color } = edge;
159
+ const cs = Math.cos(ang), sn = Math.sin(ang);
160
+ const at = (back, across) => [x - cs * back - sn * across, y - sn * back + cs * across]; // the tip's own frame: `back` behind it, `across` to its left
161
+ const thin = Math.max(END_SHAPES.strokeWidth, 1.2 / zoom);
162
+ ctx.beginPath();
163
+ if (kind === 'triangle') {
164
+ ctx.moveTo(x, y);
165
+ ctx.lineTo(x - Math.cos(ang - ARROW.spread) * ARROW.length, y - Math.sin(ang - ARROW.spread) * ARROW.length);
166
+ ctx.lineTo(x - Math.cos(ang + ARROW.spread) * ARROW.length, y - Math.sin(ang + ARROW.spread) * ARROW.length);
167
+ ctx.closePath();
168
+ ctx.fillStyle = color;
169
+ ctx.fill();
170
+ return;
171
+ }
172
+ ctx.strokeStyle = color;
173
+ ctx.lineWidth = thin;
174
+ ctx.lineJoin = 'miter';
175
+ if (kind === 'chevron') {
176
+ const back = ARROW.length * Math.cos(ARROW.spread), side = ARROW.length * Math.sin(ARROW.spread);
177
+ ctx.moveTo(...at(back, side));
178
+ ctx.lineTo(x, y);
179
+ ctx.lineTo(...at(back, -side));
180
+ } else if (kind === 'bar') {
181
+ ctx.moveTo(...at(thin / 2, END_SHAPES.barHalf));
182
+ ctx.lineTo(...at(thin / 2, -END_SHAPES.barHalf));
183
+ } else { // diamond: its front vertex at the tip
184
+ const h = END_SHAPES.diamondHalf;
185
+ ctx.moveTo(x, y);
186
+ ctx.lineTo(...at(h, END_SHAPES.diamondAcross));
187
+ ctx.lineTo(...at(2 * h, 0));
188
+ ctx.lineTo(...at(h, -END_SHAPES.diamondAcross));
189
+ ctx.closePath();
190
+ }
191
+ ctx.stroke();
192
+ }
193
+
194
+ /** The ticks of a `when` across the middle of an edge: short lines square to it, a few units apart along it */
195
+ function drawTicks(ctx, edge, zoom) {
196
+ const len = Math.hypot(edge.x2 - edge.x1, edge.y2 - edge.y1);
197
+ const [dx, dy] = len > 0 ? [(edge.x2 - edge.x1) / len, (edge.y2 - edge.y1) / len] : [1, 0];
198
+ const mid = edgePoint(edge, 0.5);
199
+ ctx.beginPath();
200
+ for (let i = 0; i < edge.ticks; i++) {
201
+ const along = (i - (edge.ticks - 1) / 2) * END_SHAPES.tickGap;
202
+ const px = mid.x + dx * along, py = mid.y + dy * along;
203
+ ctx.moveTo(px - dy * END_SHAPES.tickHalf, py + dx * END_SHAPES.tickHalf);
204
+ ctx.lineTo(px + dy * END_SHAPES.tickHalf, py - dx * END_SHAPES.tickHalf);
205
+ }
206
+ ctx.strokeStyle = edge.color;
207
+ ctx.lineWidth = Math.max(END_SHAPES.tickWidth, 1.5 / zoom);
208
+ ctx.setLineDash([]);
209
+ ctx.stroke();
210
+ }
211
+
123
212
  /** The packet's dot: a soft disc under it for the glow (no `shadowBlur`: see drawEdge), then the dot */
124
213
  function drawPacketIn(ctx, edge, timeMs, zoom) {
125
214
  const p = packetPoint(edge, timeMs);
@@ -146,6 +235,44 @@ function drawPacket(ctx, edge, timeMs, zoom) {
146
235
  ctx.restore();
147
236
  }
148
237
 
238
+ /**
239
+ * Each edge's box in world units, worked out once per scene: the hull of its curve, grown by what is drawn past the line (its glow,
240
+ * its end mark, its ticks, its packet). An edge whose box misses the view draws nothing there, so it is not drawn: the picture is the
241
+ * same, and a pan at zoom 1 strokes the few hundred lines in view, not every line of a big map (a selection's faint traces included).
242
+ */
243
+ const EDGE_REACH = 16; // world units past the line: the largest end mark (a diamond, 12), a tick, a strike, a packet's glow
244
+ const boxLists = new WeakMap();
245
+ function edgeBoxes(scene) {
246
+ let boxes = boxLists.get(scene);
247
+ if (!boxes) {
248
+ boxes = new Float64Array(scene.edges.length * 4);
249
+ scene.edges.forEach((e, i) => {
250
+ const cx = e.curve ? e.curve.cx : e.x1, cy = e.curve ? e.curve.cy : e.y1;
251
+ const glow = (e.glow || 0) * 0.6 + (e.packet ? e.packet.radius + (e.packet.glow || 0) * 0.5 : 0);
252
+ const pad = (e.width || 0) / 2 + glow + EDGE_REACH;
253
+ boxes[i * 4] = Math.min(e.x1, e.x2, cx) - pad;
254
+ boxes[i * 4 + 1] = Math.min(e.y1, e.y2, cy) - pad;
255
+ boxes[i * 4 + 2] = Math.max(e.x1, e.x2, cx) + pad;
256
+ boxes[i * 4 + 3] = Math.max(e.y1, e.y2, cy) + pad;
257
+ });
258
+ boxLists.set(scene, boxes);
259
+ }
260
+ return boxes;
261
+ }
262
+ /** The edges whose box reaches the part of the world the camera shows (with a few screen px for the widths a zoomed-out edge is held to) */
263
+ function edgesInView(scene, camera, width, height) {
264
+ const boxes = edgeBoxes(scene);
265
+ const z = camera.zoom || 1;
266
+ const m = 4 / z;
267
+ const x0 = -camera.x / z - m, y0 = -camera.y / z - m, x1 = (width - camera.x) / z + m, y1 = (height - camera.y) / z + m;
268
+ const out = [];
269
+ for (let i = 0; i < scene.edges.length; i++) {
270
+ if (boxes[i * 4 + 2] < x0 || boxes[i * 4] > x1 || boxes[i * 4 + 3] < y0 || boxes[i * 4 + 1] > y1) continue;
271
+ out.push(scene.edges[i]);
272
+ }
273
+ return out;
274
+ }
275
+
149
276
  // ---------------------------------------------------------------------------
150
277
  // Nodes
151
278
  // ---------------------------------------------------------------------------
@@ -186,8 +313,8 @@ function drawNode(ctx, node, zoom, looks, style) {
186
313
  }
187
314
  }
188
315
 
189
- // The node circle, glowing, with a white core dot
190
- circle(ctx, node.x, node.y, node.r);
316
+ // The node's silhouette, glowing
317
+ silhouette(ctx, node.shape, node.x, node.y, node.r);
191
318
  if (node.glow && node.glow * zoom >= GLOW_MIN_PX) {
192
319
  // A soft disc behind the node, not `shadowBlur` (see drawEdge): one cheap fill instead of a blur pass
193
320
  ctx.save();
@@ -196,36 +323,47 @@ function drawNode(ctx, node, zoom, looks, style) {
196
323
  ctx.fillStyle = node.color;
197
324
  ctx.fill();
198
325
  ctx.restore();
199
- circle(ctx, node.x, node.y, node.r);
326
+ silhouette(ctx, node.shape, node.x, node.y, node.r);
200
327
  }
201
328
  ctx.fillStyle = node.color;
202
329
  ctx.fill();
203
- circle(ctx, node.x, node.y, node.r * CORE_RATIO);
204
- ctx.fillStyle = looks.core;
205
- ctx.fill();
330
+ // What sits in the middle: a theme's icon, else a finer kind's letters, else the type's glyph (spec 0008 D8), else the white core dot.
331
+ // The glyph takes the core dot's place: drawn over it, the dot would fill the glyph's own shapes and blur it at the sizes nodes have
332
+ const image = node.icon && style.icons ? style.icons.get(node.icon) : null;
333
+ const letters = !image && showsLetters(node, zoom);
334
+ const glyph = !image && !letters && showsGlyph(node, zoom) ? glyphImage(node.glyph, glyphInk(node, style)) : null;
335
+ if (!glyph) {
336
+ circle(ctx, node.x, node.y, node.r * CORE_RATIO);
337
+ ctx.fillStyle = looks.core;
338
+ ctx.fill();
339
+ }
206
340
 
207
341
  // The theme's outline (--corn-map-stroke), just inside the edge of the circle
208
342
  if (node.stroke) {
209
- circle(ctx, node.x, node.y, Math.max(0, node.r - node.stroke.width / 2));
343
+ silhouette(ctx, node.shape, node.x, node.y, Math.max(0, node.r - node.stroke.width / 2));
210
344
  ctx.strokeStyle = node.stroke.color;
211
345
  ctx.lineWidth = node.stroke.width;
212
346
  ctx.stroke();
213
347
  }
214
348
 
215
349
  // The theme's icon for this kind (theme.icons), inside the circle; crisp when the theme is pixelated
216
- const image = node.icon && style.icons ? style.icons.get(node.icon) : null;
217
350
  if (image) {
218
351
  const side = node.r * ICON_RATIO;
219
352
  ctx.imageSmoothingEnabled = !style.pixelated;
220
353
  ctx.drawImage(image, node.x - side / 2, node.y - side / 2, side, side);
221
- } else if (showsLetters(node, zoom)) {
354
+ } else if (letters) {
222
355
  // A finer kind's letters (spec 0009 D5), where a theme's icon would be: the shortest start of its name, once the node is wide enough
223
- const letters = letterImage(node.letters);
356
+ const letters = letterImage(node.letters, style.values && style.values[GLYPH_TOKEN]);
224
357
  if (letters) {
225
358
  const side = node.r * LETTER_RATIO;
226
359
  ctx.imageSmoothingEnabled = true;
227
360
  ctx.drawImage(letters, node.x - side / 2, node.y - side / 2, side, side);
228
361
  }
362
+ } else if (glyph) {
363
+ // The type's own glyph (spec 0008 D8), in place of the white core dot: after a theme's icon and a finer kind's letters
364
+ const side = node.r * GLYPH_RATIO;
365
+ ctx.imageSmoothingEnabled = true;
366
+ ctx.drawImage(glyph, node.x - side / 2, node.y - side / 2, side, side);
229
367
  }
230
368
  ctx.restore();
231
369
  }
@@ -236,7 +374,7 @@ function drawNode(ctx, node, zoom, looks, style) {
236
374
 
237
375
  /**
238
376
  * @param {HTMLCanvasElement} canvas the canvas to draw on
239
- * @param {{mapStyle?: () => import('./map-style.js').MapStyle}} [opts] `mapStyle`: where the theme's map tokens come from (default: the page's, map-style.js `getMapStyle`)
377
+ * @param {{mapStyle?: () => import('./map-style.js').MapStyle, layerMinEdges?: number}} [opts] `mapStyle`: where the theme's map tokens come from (default: the page's, map-style.js `getMapStyle`); `layerMinEdges`: how many drawn lines make the layer worth it (default LAYER_MIN_EDGES)
240
378
  * @returns {import('./scene.js').Renderer}
241
379
  */
242
380
  export function createCanvas2dRenderer(canvas, opts = {}) {
@@ -262,6 +400,10 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
262
400
  if (!layerCtx) layer = null;
263
401
  return layer;
264
402
  };
403
+ // The layer pays for itself only when there are many lines to redraw every frame: a blit of the whole canvas is not free (a phone's
404
+ // software raster takes ~0.4 s for the first one), so a scene with a few hundred lines and a few packets (one hop of a selection)
405
+ // draws directly
406
+ const layerMin = opts.layerMinEdges ?? LAYER_MIN_EDGES;
265
407
  const hasPacket = new WeakMap();
266
408
  const packetsIn = (scene) => {
267
409
  if (!hasPacket.has(scene)) hasPacket.set(scene, scene.edges.some((e) => e.packet));
@@ -276,7 +418,7 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
276
418
  if (decor.grid) drawGrid(c, decor.grid, camera, width, height);
277
419
  if (decor.lanes.length) drawLanes(c, decor.lanes);
278
420
  if (decor.rings.length) drawRings(c, decor.rings);
279
- scene.edges.forEach((edge) => drawEdge(c, edge, 0, camera.zoom, false));
421
+ edgesInView(scene, camera, width, height).forEach((edge) => drawEdge(c, edge, 0, camera.zoom, false));
280
422
  c.restore();
281
423
  }
282
424
 
@@ -300,7 +442,8 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
300
442
  ctx.clearRect(0, 0, width, height);
301
443
 
302
444
  const looks = looksWith(looksFor(scene.theme), style); // the halos, mark rings and core for the scene's ground, in the theme's colours
303
- if (packetsIn(scene) && makeLayer()) {
445
+ const inView = edgesInView(scene, camera, width, height);
446
+ if (packetsIn(scene) && inView.length > layerMin && makeLayer()) {
304
447
  const same = layerFor && layerFor.scene === scene && layerFor.x === camera.x && layerFor.y === camera.y && layerFor.zoom === camera.zoom && layerFor.w === canvas.width && layerFor.h === canvas.height;
305
448
  if (!same) {
306
449
  if (layer.width !== canvas.width || layer.height !== canvas.height) { layer.width = canvas.width; layer.height = canvas.height; }
@@ -316,7 +459,7 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
316
459
  ctx.save();
317
460
  ctx.translate(camera.x, camera.y);
318
461
  ctx.scale(camera.zoom, camera.zoom);
319
- scene.edges.forEach((edge) => { if (edge.packet) drawPacket(ctx, edge, timeMs, camera.zoom); });
462
+ inView.forEach((edge) => { if (edge.packet) drawPacket(ctx, edge, timeMs, camera.zoom); });
320
463
  scene.nodes.forEach((node) => drawNode(ctx, node, camera.zoom, looks, style));
321
464
  ctx.restore();
322
465
  return;
@@ -331,7 +474,7 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
331
474
  if (decor.lanes.length) drawLanes(ctx, decor.lanes);
332
475
  if (decor.rings.length) drawRings(ctx, decor.rings);
333
476
 
334
- scene.edges.forEach((edge) => drawEdge(ctx, edge, timeMs, camera.zoom));
477
+ inView.forEach((edge) => drawEdge(ctx, edge, timeMs, camera.zoom));
335
478
  scene.nodes.forEach((node) => drawNode(ctx, node, camera.zoom, looks, style));
336
479
  // No text here: every label (and the strike through a removed one) is drawn by the label layer (labels.js) over this canvas
337
480
 
@@ -24,9 +24,11 @@
24
24
  * The pure packing (`packNodes`, `packEdges`, `packDecor`, `styleTables`) is what the tests read: there is no GPU in CI.
25
25
  */
26
26
 
27
- import { ARROW, CORE_RATIO, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, parseColor } from './scene.js';
28
- import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
27
+ import { ARROW, CORE_RATIO, EDGE_STRIKE, END_SHAPES, SHAPE_SIZES, MARK_MIN_PX, edgePoint, looksFor, parseColor } from './scene.js';
28
+ import { GLYPH_TOKEN, ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
29
29
  import { LETTER_MIN_PX, LETTER_RATIO, isLetterKey, letterImage, letterKey, lettersOfKey } from './kind-letters.js';
30
+ import { GLYPH_MIN_PX, GLYPH_RATIO, glyphImage, glyphInk, glyphKey, glyphOfKey, isGlyphKey } from './glyphs.js';
31
+ import { SHAPES } from '../core/schema.js';
30
32
  import {
31
33
  CURVE_SEGMENTS, EDGE_FRAG, GRID_FRAG, GRID_VERT, ICON_FRAG, ICON_VERT, LANE_FRAG, LANE_VERT, NODE_FRAG, NODE_VERT, PACKET_FRAG, PACKET_VERT,
32
34
  RING_FRAG, RING_VERT, TIP_FRAG, TIP_VERT, edgeVert,
@@ -36,8 +38,8 @@ import {
36
38
  // Packing: scene -> typed arrays (pure)
37
39
  // ---------------------------------------------------------------------------
38
40
 
39
- /** Floats per node: x, y, r, alpha | red, green, blue, glow | halo code, mark code, colour alpha */
40
- export const NODE_STRIDE = 11;
41
+ /** Floats per node: x, y, r, alpha | red, green, blue, glow | halo code, mark code, colour alpha, shape code (SHAPE_CODE, plus GLYPH_FLAG when the type's glyph takes the core dot's place) */
42
+ export const NODE_STRIDE = 12;
41
43
  /** Floats per ring: x, y, r, width | rgba | dash on, off */
42
44
  export const RING_STRIDE = 10;
43
45
  /** Floats per lane: x, y, w, h | fill rgba | stroke rgba | radius, stroke width */
@@ -55,7 +57,12 @@ export const TIP_STRIDE = 9;
55
57
  export const PACKET_STRIDE = 18;
56
58
 
57
59
  export const HALO_CODE = { none: 0, selected: 1, match: 2, child: 3 };
58
- export const TIP_CODE = { arrow: 1, strike: 2 };
60
+ /** What a tip is: a filled arrowhead, the strike across a removed edge, and (spec 0008 D7) the open chevron, the bar and the open diamond that end the other families, and the tick of a `when` */
61
+ export const TIP_CODE = { arrow: 1, strike: 2, chevron: 3, bar: 4, diamond: 5, tick: 6 };
62
+ /** The silhouettes, as the node shader numbers them (core/schema.js SHAPES) */
63
+ export const SHAPE_CODE = Object.freeze(Object.fromEntries(SHAPES.map((name, i) => [name, i])));
64
+ /** Added to a node's shape code when its glyph is drawn in place of the white core dot (no theme icon, no letters): the shader leaves the dot out once the glyph shows */
65
+ export const GLYPH_FLAG = 8;
59
66
  export const MARK_CODE = { none: 0, added: 1, changed: 2, removed: 3, edit: 4 };
60
67
 
61
68
  /** A CSS colour as [r, g, b, a], all 0..1 */
@@ -76,7 +83,7 @@ export function packNodes(scene) {
76
83
  nodes.forEach((n, i) => {
77
84
  const [r, g, b, a] = rgba(n.color);
78
85
  // scene.js has already faded a removed node (MARK.removed.alpha is in n.alpha); the ring is the shader's (u_markGeom, u_markColor)
79
- data.set([n.x, n.y, n.r, n.alpha, r, g, b, n.glow || 0, codeOf(HALO_CODE, n.halo), codeOf(MARK_CODE, n.mark), a], i * NODE_STRIDE);
86
+ data.set([n.x, n.y, n.r, n.alpha, r, g, b, n.glow || 0, codeOf(HALO_CODE, n.halo), codeOf(MARK_CODE, n.mark), a, codeOf(SHAPE_CODE, n.shape) + (n.glyph && !n.icon && !n.letters ? GLYPH_FLAG : 0)], i * NODE_STRIDE);
80
87
  });
81
88
  return { data, count: nodes.length, stride: NODE_STRIDE };
82
89
  }
@@ -141,7 +148,18 @@ export function packEdges(scene) {
141
148
  if (edge.arrow) {
142
149
  // along the end tangent: from the control point (a straight edge: from its start)
143
150
  const ang = Math.atan2(edge.y2 - (edge.curve ? edge.curve.cy : edge.y1), edge.x2 - (edge.curve ? edge.curve.cx : edge.x1));
144
- rows.tips.push([edge.x2, edge.y2, Math.cos(ang), Math.sin(ang), r, g, b, lineAlpha, TIP_CODE.arrow]);
151
+ const code = edge.end && edge.end !== 'triangle' ? codeOf(TIP_CODE, edge.end) || TIP_CODE.arrow : TIP_CODE.arrow;
152
+ rows.tips.push([edge.x2, edge.y2, Math.cos(ang), Math.sin(ang), r, g, b, lineAlpha, code]);
153
+ }
154
+ if (edge.ticks) {
155
+ // across the middle, one or two, a few units apart along the chord (renderer-canvas2d.js drawTicks)
156
+ const mid = edgePoint(edge, 0.5);
157
+ const len = Math.hypot(edge.x2 - edge.x1, edge.y2 - edge.y1);
158
+ const [dx, dy] = len > 0 ? [(edge.x2 - edge.x1) / len, (edge.y2 - edge.y1) / len] : [1, 0];
159
+ for (let i = 0; i < edge.ticks; i++) {
160
+ const along = (i - (edge.ticks - 1) / 2) * END_SHAPES.tickGap;
161
+ rows.tips.push([mid.x + dx * along, mid.y + dy * along, dx, dy, r, g, b, lineAlpha, TIP_CODE.tick]);
162
+ }
145
163
  }
146
164
  if (edge.mark === 'removed') {
147
165
  // across the edge at its midpoint (the quadratic's tangent there is its chord)
@@ -202,22 +220,24 @@ export function packStrokes(scene) {
202
220
  * @param {(kind: string) => boolean} has whether the kind's image has loaded (a letters key: whether its image could be made)
203
221
  * @returns {{data: Float32Array, count: number, stride: number, groups: {kind: string, first: number, count: number, minR: number}[]}}
204
222
  */
205
- export function packIcons(scene, has) {
223
+ export function packIcons(scene, has, style = null) {
206
224
  const byKind = new Map();
207
225
  scene.nodes.forEach((n) => {
208
226
  let kind = n.icon && has(n.icon) ? n.icon : null;
209
227
  let side = n.r * ICON_RATIO;
210
228
  if (!kind && !n.icon && n.letters && has(letterKey(n.letters))) { kind = letterKey(n.letters); side = n.r * LETTER_RATIO; }
229
+ if (!kind && !n.icon && !n.letters && n.glyph) { const key = glyphKey(n.glyph, glyphInk(n, style)); if (has(key)) { kind = key; side = n.r * GLYPH_RATIO; } } // the type's own glyph, last (glyphs.js)
211
230
  if (!kind) return;
212
- if (!byKind.has(kind)) byKind.set(kind, { rows: [], minR: Infinity });
231
+ if (!byKind.has(kind)) byKind.set(kind, { rows: [], minR: Infinity, maxR: 0 });
213
232
  const group = byKind.get(kind);
233
+ group.maxR = Math.max(group.maxR, n.r);
214
234
  group.rows.push([n.x, n.y, side, n.alpha]);
215
235
  group.minR = Math.min(group.minR, n.r);
216
236
  });
217
237
  const groups = [];
218
238
  const rows = [];
219
- for (const [kind, { rows: list, minR }] of byKind) {
220
- groups.push({ kind, first: rows.length, count: list.length, minR });
239
+ for (const [kind, { rows: list, minR, maxR }] of byKind) {
240
+ groups.push({ kind, first: rows.length, count: list.length, minR, maxR });
221
241
  rows.push(...list);
222
242
  }
223
243
  const data = new Float32Array(rows.length * ICON_STRIDE);
@@ -284,7 +304,7 @@ export const PASSES = [
284
304
  { name: 'curved', vert: edgeVert(CURVE_SEGMENTS), frag: EDGE_FRAG, stride: EDGE_STRIDE, verts: CURVED_VERTS, attribs: [[1, 4, 0], [2, 4, 4], [3, 4, 8], [4, 4, 12], [5, 2, 16], [6, 1, 18]], constants: 'edges' },
285
305
  { name: 'tips', vert: TIP_VERT, frag: TIP_FRAG, stride: TIP_STRIDE, attribs: [[1, 4, 0], [2, 4, 4], [3, 1, 8]], constants: 'tips' },
286
306
  { name: 'packets', vert: PACKET_VERT, frag: PACKET_FRAG, stride: PACKET_STRIDE, attribs: [[1, 4, 0], [2, 4, 4], [3, 4, 8], [4, 4, 12], [5, 2, 16]], time: true },
287
- { name: 'nodes', vert: NODE_VERT, frag: NODE_FRAG, stride: NODE_STRIDE, attribs: [[1, 4, 0], [2, 4, 4], [3, 3, 8]], constants: 'nodes' },
307
+ { name: 'nodes', vert: NODE_VERT, frag: NODE_FRAG, stride: NODE_STRIDE, attribs: [[1, 4, 0], [2, 4, 4], [3, 4, 8]], constants: 'nodes' },
288
308
  ];
289
309
 
290
310
  /** The uniforms that never change, set once per program (the looks live in scene.js, nowhere else) */
@@ -298,12 +318,17 @@ const CONSTANTS = {
298
318
  gl.uniform3fv(at('u_markMin'), tables.markMin);
299
319
  gl.uniform4fv(at('u_core'), tables.core);
300
320
  gl.uniform1f(at('u_coreRatio'), tables.coreRatio);
321
+ gl.uniform4f(at('u_shape'), SHAPE_SIZES.roundedHalf, SHAPE_SIZES.roundedCorner, SHAPE_SIZES.hexInradius, SHAPE_SIZES.squareHalf);
322
+ gl.uniform2f(at('u_shape2'), SHAPE_SIZES.squareCorner, SHAPE_SIZES.diamondHalf);
323
+ gl.uniform1f(at('u_glyphMin'), GLYPH_MIN_PX);
301
324
  },
302
325
  edges(gl, at, tables) {
303
326
  gl.uniform3fv(at('u_markMin'), tables.markMin);
304
327
  },
305
328
  tips(gl, at) {
306
329
  gl.uniform4f(at('u_tip'), ARROW.length, ARROW.spread, EDGE_STRIKE.halfLength, EDGE_STRIKE.width);
330
+ gl.uniform4f(at('u_end'), END_SHAPES.strokeWidth, END_SHAPES.barHalf, END_SHAPES.diamondHalf, END_SHAPES.diamondAcross);
331
+ gl.uniform2f(at('u_tick'), END_SHAPES.tickHalf, END_SHAPES.tickWidth);
307
332
  },
308
333
  };
309
334
 
@@ -494,13 +519,16 @@ export function createWebglRenderer(canvas, opts = {}) {
494
519
  if (lost || !gpu || !width || !height) return;
495
520
  const style = styleOf();
496
521
  const scene = styledScene(drawn, style); // the map in the theme's colours, outlines and icons (map-style.js); the scene itself when nothing is set
497
- if (gpu.iconStore !== style.icons) { // a new set of icons (or none): the old ones' textures go now, not when the renderer does
522
+ const ink = style.values ? style.values[GLYPH_TOKEN] : undefined; // the theme's glyph ink: the letters' and glyphs' textures are made in it
523
+ if (gpu.iconStore !== style.icons || gpu.glyphInk !== ink) { // a new set of icons (or none), or another ink: the old ones' textures go now, not when the renderer does
498
524
  gpu.textures.forEach(({ texture }) => gl.deleteTexture(texture));
499
525
  gpu.textures.clear();
500
526
  gpu.iconStore = style.icons;
527
+ gpu.glyphInk = ink;
528
+ packedScene = null; // the icon rows are made again for the new ink
501
529
  }
502
530
  if (scene !== packedScene || scene.version !== packedVersion) {
503
- packed = { ...packScene(scene), strokes: packStrokes(scene), icons: packIcons(scene, (kind) => (isLetterKey(kind) ? !!letterImage(lettersOfKey(kind)) : !!(style.icons && style.icons.get(kind)))) };
531
+ packed = { ...packScene(scene), strokes: packStrokes(scene), icons: packIcons(scene, (kind) => (isLetterKey(kind) ? !!letterImage(lettersOfKey(kind), ink) : isGlyphKey(kind) ? !!glyphImage(glyphOfKey(kind).type, glyphOfKey(kind).ink) : !!(style.icons && style.icons.get(kind))), style) };
504
532
  packedScene = scene;
505
533
  packedVersion = scene.version;
506
534
  upload();
@@ -548,10 +576,16 @@ export function createWebglRenderer(canvas, opts = {}) {
548
576
  gl.bindBuffer(gl.ARRAY_BUFFER, icons.buffer);
549
577
  for (const group of packed.icons.groups) {
550
578
  const letters = isLetterKey(group.kind);
551
- if (letters && group.minR * 2 * camera.zoom < LETTER_MIN_PX) continue; // too small on screen: the letters would be a smudge (kind-letters.js)
552
- const image = letters ? letterImage(lettersOfKey(group.kind)) : style.icons && style.icons.get(group.kind);
579
+ const glyph = isGlyphKey(group.kind);
580
+ // Letters and a glyph are drawn only on a node wide enough on screen (kind-letters.js, glyphs.js): the vertex shader drops each
581
+ // smaller one, as Canvas 2D does node by node, and a group whose largest node is under it is not drawn at all
582
+ const minPx = letters ? LETTER_MIN_PX : glyph ? GLYPH_MIN_PX : 0;
583
+ if (minPx && group.maxR * 2 * camera.zoom < minPx) continue;
584
+ gl.uniform1f(icons.at('u_minR'), minPx / 2);
585
+ gl.uniform1f(icons.at('u_sideRatio'), letters ? LETTER_RATIO : glyph ? GLYPH_RATIO : 1);
586
+ const image = letters ? letterImage(lettersOfKey(group.kind), style.values && style.values[GLYPH_TOKEN]) : glyph ? glyphImage(glyphOfKey(group.kind).type, glyphOfKey(group.kind).ink) : style.icons && style.icons.get(group.kind);
553
587
  if (!image) continue;
554
- gl.bindTexture(gl.TEXTURE_2D, textureOf(group.kind, image, !!style.pixelated && !letters));
588
+ gl.bindTexture(gl.TEXTURE_2D, textureOf(group.kind, image, !!style.pixelated && !letters && !glyph));
555
589
  gl.vertexAttribPointer(1, 4, gl.FLOAT, false, ICON_STRIDE * 4, group.first * ICON_STRIDE * 4); // this kind's rows
556
590
  gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 4, group.count);
557
591
  stats.draws++;
@@ -111,16 +111,19 @@ function model() {
111
111
  return buildScenarioList({ scenarios: scenariosNow(), nodes: state.nodes, edges: state.edges, proposal, verdicts, seen: ui.seen, words, hidden });
112
112
  }
113
113
 
114
+ /** The proposal's own changes: the reviewer's what-if edits are a group of their own (spec 0007 D5), never counted into them */
115
+ const theirRows = (proposal) => changeRows(state.nodes, state.edges, proposal).filter((r) => r.mark !== 'edit');
116
+
114
117
  /** What opening a proposal says: "Opened Checkout: 6 changes, 3 scenarios for 2 personas." */
115
118
  export function reviewOpenedLine(title) {
116
119
  const proposal = state.effectiveProposal || state.proposal;
117
- return reviewOpenedWords(title, changeRows(state.nodes, state.edges, proposal).length, model());
120
+ return reviewOpenedWords(title, theirRows(proposal).length, model());
118
121
  }
119
122
 
120
123
  /** The phone's peek line: "6 changes · 3 scenarios for 2 personas" */
121
124
  export function reviewPeekLine() {
122
125
  const proposal = state.effectiveProposal || state.proposal;
123
- return reviewCounts(changeRows(state.nodes, state.edges, proposal).length, model());
126
+ return reviewCounts(theirRows(proposal).length, model());
124
127
  }
125
128
 
126
129
  // ---------------------------------------------------------------------------
@@ -167,7 +170,9 @@ function groupHtml(g) {
167
170
  /** Everything the two lists say, as markup (the foot is static in index.html) */
168
171
  function listsHtml() {
169
172
  const proposal = state.effectiveProposal || state.proposal;
170
- const rows = changeRows(state.nodes, state.edges, proposal);
173
+ const everyRow = changeRows(state.nodes, state.edges, proposal);
174
+ const rows = everyRow.filter((r) => r.mark !== 'edit');
175
+ const mine = everyRow.filter((r) => r.mark === 'edit'); // "Your edits · 1": the first group, not the last row
171
176
  const list = model();
172
177
  const phone = isPhone();
173
178
  // the phone's tab: the reviewer's last choice, or Scenarios when there are any; a proposal with none opens on its changes
@@ -181,6 +186,7 @@ function listsHtml() {
181
186
 
182
187
  const changes = `<section id="rc-changes" class="hx-rc-section" data-corn="proposal-changes"${phone ? ` role="tabpanel" aria-labelledby="rc-tab-changes"${tab === 'changes' ? '' : ' hidden'}` : ' aria-labelledby="rc-changes-h"'}>`
183
188
  + `<h3 id="rc-changes-h" class="hx-rc-h" tabindex="-1">${countHeading(t('changes'), rows.length)}</h3>`
189
+ + (mine.length ? `<h4 class="hx-rc-sub">${countHeading(t('yourEdits'), mine.length)}</h4><ul class="hx-change-list">${mine.map(changeRowHtml).join('')}</ul>` : '')
184
190
  + (rows.length ? `<ul class="hx-change-list">${rows.map(changeRowHtml).join('')}</ul>` : '<p class="hx-faint hx-rc-empty">This proposal changes nothing on the map.</p>')
185
191
  + '</section>';
186
192
 
@@ -190,7 +196,6 @@ function listsHtml() {
190
196
  body = list.groups.map(groupHtml).join('');
191
197
  if (!personas) body += `<p class="hx-faint hx-rc-note">This map has no personas (topology.personas.json), so every scenario is listed under ${escHtml(t('anyone'))}.</p>`;
192
198
  if (list.coverage) body += `<p class="hx-rc-coverage" data-corn="notice">${escHtml(t('notInAnyScenario'))}: ${list.notInAny.map(escHtml).join(', ')}</p>`;
193
- if (list.playedLine) body += `<p class="hx-faint hx-rc-note" data-corn="notice">${escHtml(list.playedLine)}</p>`;
194
199
  }
195
200
  const scenarios = `<section id="rc-scenarios" class="hx-rc-section" data-corn="scenario-list"${phone ? ` role="tabpanel" aria-labelledby="rc-tab-scenarios"${tab === 'scenarios' ? '' : ' hidden'}` : ' aria-labelledby="rc-scenarios-h"'}>`
196
201
  + `<h3 id="rc-scenarios-h" class="hx-rc-h" tabindex="-1">${countHeading(t('personasAndScenarios'), list.total)}</h3><div class="hx-rc-sbody">${body}</div></section>`;
@@ -254,6 +259,18 @@ export function shareRoom() {
254
259
  col.style.setProperty('--hx-changes-max', `${Math.floor(Math.max(0.4 * h, h - need - gap))}px`);
255
260
  }
256
261
 
262
+ /** "2 of 3 scenarios played", or '': the decision line says it (spec 0007 D1; it used to sit under the scenario list) */
263
+ export function playedLine() {
264
+ return state.proposal ? model().playedLine : '';
265
+ }
266
+
267
+ const paintWatchers = new Set();
268
+ /** `fn()` after the lists are drawn again: the decision line follows what was played */
269
+ export function onReviewColumnPaint(fn) {
270
+ paintWatchers.add(fn);
271
+ return () => paintWatchers.delete(fn);
272
+ }
273
+
257
274
  function repaint() {
258
275
  const lists = $('review-lists');
259
276
  const col = $('review-column');
@@ -277,6 +294,7 @@ function repaint() {
277
294
  if (again) again.focus();
278
295
  }
279
296
  shareRoom();
297
+ for (const fn of paintWatchers) fn();
280
298
  }
281
299
 
282
300
  // ---------------------------------------------------------------------------