@stefan.inc/feedback-engine 1.2.1 → 1.2.3

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.md CHANGED
@@ -8,7 +8,7 @@ Alt+Meta+click anything in the browser, click any component on the frozen screen
8
8
 
9
9
  | The editor in the browser | The `feedback.png` it exports |
10
10
  | :---: | :---: |
11
- | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-editor.png" alt="The Feedback editor in Google Chrome over the React example: the page's screenshot on the left with four notes numbered 1 to 4 and an @5 tag on the New List button, and the panel on the right with the Groceries row, a ListRow, selected and its note, Show a progress bar here." width="320"> | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-export.png" alt="The feedback.png exported from the browser: the page with four numbered boxes and the New List button tagged @5. One column on the left holds the app's details as Name: value lines, a line naming @5 with its file:line, and a card per note, each joined to its box by a curve that crosses no other box. Each card has its note, the component or element, and its file:line. The note on Settings reads Move this next to @5_Button." width="520"> |
11
+ | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-editor.png" alt="The Feedback editor in Google Chrome over the React example: the page's screenshot on the left with four notes numbered 1 to 4 and an @5 tag on the New List button, and the panel on the right with the Groceries row, a ListRow, selected and its note, Show a progress bar here." width="320"> | <img src="https://raw.githubusercontent.com/smirea/feedback-engine/master/docs/web-export.png" alt="The feedback.png exported from the browser: the page with four numbered boxes and the New List button tagged @5. One column on the left holds the app's details as Name: value lines, a References line naming @5 with its file:line, and a card per note, each joined to its box by a curve with a dot at each end that crosses no other box. Each card has its note, the component or element, and its file:line. The note on Settings reads Move this next to @5_Button. A faint GitHub mark and the repository's URL sit in the top left corner, above the details." width="520"> |
12
12
 
13
13
  Four notes on the React example in Google Chrome. The last one points at a second element. Type `@`, click the element, and the note reads `Move this next to @5_Button`. The export draws that element's box and highlights the token in the same color, so an agent knows which button you meant. Each card names its component or element and the `file:line` it comes from, such as `src/components/ListRow.tsx:4`.
14
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stefan.inc/feedback-engine",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "In-app feedback for Svelte and React: point at a component, write what should change, and export its name, file:line, and data for an agent.",
5
5
  "keywords": [
6
6
  "accessibility",
@@ -9,10 +9,12 @@ export const cards = {
9
9
  padding: 10,
10
10
  rightColumnPenalty: 80,
11
11
  crossingPenalty: 500,
12
+ watermark: 13,
12
13
  };
13
14
 
14
15
  export type Card = { isLeft: boolean; origin: Point };
15
- export type Layout = { shot: Frame; cards: Card[]; environment: Point; size: Size };
16
+ /** `watermark` is the top-left of a column-wide strip `cards.watermark` tall, aligned to its left or right edge. */
17
+ export type Layout = { shot: Frame; cards: Card[]; environment: Point; watermark: Card; size: Size };
16
18
  export type Curve = { start: Point; control1: Point; control2: Point; end: Point };
17
19
 
18
20
  /**
@@ -103,10 +105,11 @@ function arrange(
103
105
  viewport: number,
104
106
  references: Frame[],
105
107
  ): Arrangement {
106
- const { margin, column, gutter, spacing, rightColumnPenalty, crossingPenalty } = cards;
108
+ const { margin, column, gutter, spacing, rightColumnPenalty, crossingPenalty, watermark } = cards;
109
+ const top = margin + watermark + spacing;
107
110
  const shot = {
108
111
  x: columns === 'right' ? margin : margin + column + gutter,
109
- y: margin,
112
+ y: top,
110
113
  width: screen.width,
111
114
  height: screen.height,
112
115
  };
@@ -117,15 +120,16 @@ function arrange(
117
120
  const midY = (index: number) => moved[index]!.y + moved[index]!.height / 2;
118
121
  const placed: Card[] = moved.map(() => ({ isLeft: true, origin: { x: 0, y: 0 } }));
119
122
  const paths: Point[][] = [];
120
- const underEnvironment = margin + environmentHeight + spacing * 2;
121
- let nextLeft = columns === 'left' ? underEnvironment : margin;
123
+ const environment = { x: columns === 'left' ? margin : rightX, y: top };
124
+ const underEnvironment = top + environmentHeight + spacing * 2;
125
+ let nextLeft = columns === 'left' ? underEnvironment : top;
122
126
  let nextRight = underEnvironment;
123
127
  let cost = 0;
124
128
  let crossed = 0;
125
129
  const order = moved.map((_, index) => index).toSorted((a, b) => midY(a) - midY(b) || a - b);
126
130
  for (const index of order) {
127
131
  const target = moved[index]!;
128
- const desired = Math.max(midY(index) - heights[index]! / 2, margin);
132
+ const desired = Math.max(midY(index) - heights[index]! / 2, top);
129
133
  const options: Card[] = [];
130
134
  if (columns !== 'right') options.push({ isLeft: true, origin: { x: margin, y: Math.max(desired, nextLeft) } });
131
135
  if (columns !== 'left') options.push({ isLeft: false, origin: { x: rightX, y: Math.max(desired, nextRight) } });
@@ -156,7 +160,8 @@ function arrange(
156
160
  return {
157
161
  shot,
158
162
  cards: placed,
159
- environment: { x: columns === 'left' ? margin : rightX, y: margin },
163
+ environment,
164
+ watermark: { isLeft: columns === 'left', origin: { x: environment.x, y: margin } },
160
165
  size: { width: columns === 'left' ? shot.x + shot.width + margin : rightX + column + margin, height },
161
166
  cost,
162
167
  crossings: crossed,
@@ -166,9 +171,11 @@ function arrange(
166
171
  /**
167
172
  * Where the image export puts each item's card. Cards go in the column whose path to the target costs least: its
168
173
  * length, `rightColumnPenalty` points for the right column, and `crossingPenalty` for each other box or earlier path
169
- * it crosses, as level with the target as the cards above allow. The environment sits at the top of the right column,
170
- * and right-column cards start below it. When one column holds the environment and every card with no crossing and no
171
- * taller image, the image drops the other column and keeps only a margin on that side. A tall capture is cut half the
174
+ * it crosses, as level with the target as the cards above allow. The watermark has a strip across the top of the image,
175
+ * in the outer corner of the environment's column. The environment sits at the top of the right column, and
176
+ * right-column cards start below it. When one column holds the
177
+ * environment and every card with no crossing and no taller image, the image drops the other column and keeps only a
178
+ * margin on that side, and of the two sides it takes the one whose paths are shorter in total. A tall capture is cut half the
172
179
  * height that was on screen below the lowest box or card, and never shorter than that height, and `shot` is the part
173
180
  * that is drawn. `targets` and `references` are frames in the capture. The layout's frames are in the image.
174
181
  */
@@ -189,6 +196,6 @@ export function place(
189
196
  (chosen, option) => (chosen && chosen.cost <= option.cost ? chosen : option),
190
197
  undefined,
191
198
  );
192
- const { shot, cards: placed, environment, size } = single ?? both;
193
- return { shot, cards: placed, environment, size };
199
+ const { shot, cards: placed, environment, watermark, size } = single ?? both;
200
+ return { shot, cards: placed, environment, watermark, size };
194
201
  }
package/src/dom/image.ts CHANGED
@@ -7,10 +7,12 @@ import {
7
7
  tag,
8
8
  title,
9
9
  type Annotations,
10
+ type Card,
10
11
  type Frame,
11
12
  type Point,
12
13
  } from '../core/index.ts';
13
14
  import type { Screen } from './capture.ts';
15
+ import { githubPath } from './webhook.ts';
14
16
 
15
17
  /** Keeps a tall full-length capture shareable. */
16
18
  const pixelBudget = 40_000_000;
@@ -18,6 +20,7 @@ const secondary = '#6b6b6b';
18
20
  const primary = '#141414';
19
21
  const sans = 'system-ui, -apple-system, "Segoe UI", sans-serif';
20
22
  const mono = 'ui-monospace, "SF Mono", Menlo, Consolas, monospace';
23
+ const repository = 'github.com/smirea/feedback-engine';
21
24
 
22
25
  type Run = { text: string; font: string; color: string; background?: string; spacing?: number };
23
26
  type Piece = Run & { x: number; width: number };
@@ -25,10 +28,18 @@ type Line = { pieces: Piece[]; height: number; gap: number };
25
28
 
26
29
  const fontSize = (font: string) => Number(/(\d+(?:\.\d+)?)px/.exec(font)![1]);
27
30
 
28
- /** Breaks runs of styled text into lines no wider than `width`. A paragraph ends at each newline, with `gap` points after it. */
29
- function layout(context: CanvasRenderingContext2D, paragraphs: { runs: Run[]; gap?: number }[], width: number): Line[] {
31
+ /**
32
+ * Breaks runs of styled text into lines no wider than `width`. A paragraph ends at each newline, with `gap` points after
33
+ * it, and `before` points more before it.
34
+ */
35
+ function layout(
36
+ context: CanvasRenderingContext2D,
37
+ paragraphs: { runs: Run[]; gap?: number; before?: number }[],
38
+ width: number,
39
+ ): Line[] {
30
40
  const lines: Line[] = [];
31
41
  for (const paragraph of paragraphs) {
42
+ if (paragraph.before && lines.length) lines.at(-1)!.gap += paragraph.before;
32
43
  let current: Line = { pieces: [], height: 0, gap: 0 };
33
44
  let x = 0;
34
45
  const wrap = () => {
@@ -117,9 +128,18 @@ const footerPadding = 6;
117
128
 
118
129
  const clamp = (value: number, low: number, high: number) => Math.min(Math.max(value, low), high);
119
130
 
131
+ const stroke = 1.5;
132
+
133
+ function dot(context: CanvasRenderingContext2D, center: Point, color: string) {
134
+ context.beginPath();
135
+ context.arc(center.x, center.y, 2.5, 0, Math.PI * 2);
136
+ context.fillStyle = color;
137
+ context.fill();
138
+ }
139
+
120
140
  function dashedBox(context: CanvasRenderingContext2D, target: Frame, color: string) {
121
141
  roundedRect(context, { x: target.x - 1, y: target.y - 1, width: target.width + 2, height: target.height + 2 }, 4);
122
- context.lineWidth = 1.5;
142
+ context.lineWidth = stroke;
123
143
  context.setLineDash([6, 4]);
124
144
  context.strokeStyle = withAlpha(color, 0.9);
125
145
  context.stroke();
@@ -163,6 +183,23 @@ function referenceTag(context: CanvasRenderingContext2D, text: string, color: st
163
183
  label(context, text, center);
164
184
  }
165
185
 
186
+ /** GitHub's mark and the repository, faint, against the strip's left or right edge. */
187
+ function watermark(context: CanvasRenderingContext2D, { isLeft, origin }: Card) {
188
+ const side = metrics.watermark;
189
+ context.font = `11px ${sans}`;
190
+ const width = side + 6 + context.measureText(repository).width;
191
+ const x = isLeft ? origin.x : origin.x + metrics.column - width;
192
+ context.fillStyle = withAlpha(secondary, 0.5);
193
+ context.save();
194
+ context.translate(x, origin.y);
195
+ context.scale(side / 16, side / 16);
196
+ const mark = new Path2D(githubPath);
197
+ context.fill(mark);
198
+ context.restore();
199
+ context.textBaseline = 'middle';
200
+ context.fillText(repository, x + side + 6, origin.y + side / 2);
201
+ }
202
+
166
203
  /**
167
204
  * The image export: the screenshot with numbered boxes, each item's text and code location in a card beside it, a
168
205
  * tagged box for each referenced node, and the capture's environment, so the one file is enough on its own.
@@ -175,6 +212,7 @@ export function annotatedImage({ capture, image, scale }: Screen, annotations: A
175
212
 
176
213
  const app = capture.environment.find(entry => entry.name === 'App')?.value ?? 'App';
177
214
  const flagged = new Set(annotations.items.map(item => item.target));
215
+ const unflagged = annotations.used.filter(reference => !flagged.has(reference.target));
178
216
  const environment = layout(
179
217
  context,
180
218
  [
@@ -188,24 +226,31 @@ export function annotatedImage({ capture, image, scale }: Screen, annotations: A
188
226
  ],
189
227
  gap: 4,
190
228
  })),
191
- ...annotations.used
192
- .filter(reference => !flagged.has(reference.target))
193
- .map(reference => {
194
- const source = nearestSource(capture, reference.target);
195
- return {
196
- runs: [
197
- {
198
- text: ` ${tag(reference)} `,
199
- font: `700 11px ${sans}`,
200
- color: 'white',
201
- background: paletteColor(annotations.colorIndex(reference.target)),
202
- },
203
- ...(source ? [{ text: ` ${source}`, font: `11px ${mono}`, color: primary }] : []),
204
- { text: ` ${title(capture.nodes[reference.target]!)}`, font: `12.5px ${sans}`, color: primary },
205
- ],
206
- gap: 4,
207
- };
208
- }),
229
+ ...(unflagged.length
230
+ ? [
231
+ {
232
+ runs: [{ text: 'REFERENCES', font: `700 11px ${sans}`, color: secondary, spacing: 0.6 }],
233
+ before: 6,
234
+ gap: 4,
235
+ },
236
+ ]
237
+ : []),
238
+ ...unflagged.map(reference => {
239
+ const source = nearestSource(capture, reference.target);
240
+ return {
241
+ runs: [
242
+ {
243
+ text: ` ${tag(reference)} `,
244
+ font: `700 11px ${sans}`,
245
+ color: 'white',
246
+ background: paletteColor(annotations.colorIndex(reference.target)),
247
+ },
248
+ ...(source ? [{ text: ` ${source}`, font: `11px ${mono}`, color: primary }] : []),
249
+ { text: ` ${title(capture.nodes[reference.target]!)}`, font: `12.5px ${sans}`, color: primary },
250
+ ],
251
+ gap: 4,
252
+ };
253
+ }),
209
254
  ],
210
255
  column,
211
256
  );
@@ -287,13 +332,10 @@ export function annotatedImage({ capture, image, scale }: Screen, annotations: A
287
332
  context.beginPath();
288
333
  context.moveTo(start.x, start.y);
289
334
  context.bezierCurveTo(control1.x, control1.y, control2.x, control2.y, end.x, end.y);
290
- context.lineWidth = 1.25;
335
+ context.lineWidth = stroke;
291
336
  context.strokeStyle = withAlpha(item.color, 0.6);
292
337
  context.stroke();
293
- context.beginPath();
294
- context.arc(end.x, end.y, 2.5, 0, Math.PI * 2);
295
- context.fillStyle = item.color;
296
- context.fill();
338
+ dot(context, end, item.color);
297
339
  badge(context, item.number, item.color, {
298
340
  x: clamp(target.x, shot.x + badgeSize / 2 + 2, shot.x + shot.width - badgeSize / 2 - 2),
299
341
  y: clamp(target.y, shot.y + badgeSize / 2 + 2, shot.y + shot.height - badgeSize / 2 - 2),
@@ -328,8 +370,10 @@ export function annotatedImage({ capture, image, scale }: Screen, annotations: A
328
370
  });
329
371
  drawText(context, item.text, { x: origin.x + padding * 2 + badgeSize, y: origin.y + padding });
330
372
  drawText(context, item.footer, { x: origin.x + padding, y: origin.y + item.body + footerPadding });
373
+ dot(context, connector(placed.cards[index]!, inShot(item.frame)).start, item.color);
331
374
  }
332
375
 
333
376
  drawText(context, environment, placed.environment);
377
+ watermark(context, placed.watermark);
334
378
  return canvas;
335
379
  }
@@ -31,11 +31,15 @@ export type WebhookPost = {
31
31
  };
32
32
 
33
33
  /**
34
- * GitHub's mark in white, for a webhook that files issues. The iOS package draws the same path
35
- * (`GitHubIcon.swift`), which has only absolute `M`, `L`, `C`, and `Z` commands so that a few lines can read it.
34
+ * GitHub's mark, 16 points square. The iOS package draws the same path (`GitHubIcon.swift`), which has only absolute
35
+ * `M`, `L`, `C`, and `Z` commands so that a few lines can read it.
36
36
  */
37
+ export const githubPath =
38
+ 'M6.766 11.328C4.703 11.078 3.25 9.594 3.25 7.672C3.25 6.891 3.531 6.047 4 5.484C3.797 4.969 3.828 3.875 4.063 3.422C4.688 3.344 5.531 3.672 6.031 4.125C6.625 3.938 7.25 3.844 8.016 3.844C8.781 3.844 9.406 3.938 9.969 4.109C10.453 3.672 11.313 3.344 11.938 3.422C12.156 3.844 12.188 4.937 11.984 5.469C12.484 6.062 12.75 6.859 12.75 7.672C12.75 9.594 11.297 11.047 9.203 11.312C9.734 11.656 10.093 12.406 10.093 13.266L10.093 14.891C10.093 15.359 10.484 15.625 10.953 15.438C13.781 14.359 16 11.53 16 8.03C16 3.61 12.406 0 7.984 0C3.563 0 0 3.61 0 8.031C-0.009 11.347 2.058 14.314 5.172 15.453C5.594 15.609 6 15.328 6 14.906L6 13.656C5.781 13.75 5.5 13.812 5.25 13.812C4.219 13.812 3.61 13.25 3.172 12.203C3 11.781 2.812 11.531 2.453 11.484C2.266 11.469 2.203 11.391 2.203 11.297C2.203 11.109 2.516 10.969 2.828 10.969C3.281 10.969 3.672 11.25 4.078 11.829C4.391 12.281 4.718 12.484 5.109 12.484C5.5 12.484 5.75 12.344 6.109 11.984C6.375 11.719 6.579 11.484 6.766 11.328Z';
39
+
40
+ /** GitHub's mark in white, for a webhook that files issues. */
37
41
  export const githubIcon = `data:image/svg+xml,${encodeURIComponent(
38
- '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="white"><path d="M6.766 11.328C4.703 11.078 3.25 9.594 3.25 7.672C3.25 6.891 3.531 6.047 4 5.484C3.797 4.969 3.828 3.875 4.063 3.422C4.688 3.344 5.531 3.672 6.031 4.125C6.625 3.938 7.25 3.844 8.016 3.844C8.781 3.844 9.406 3.938 9.969 4.109C10.453 3.672 11.313 3.344 11.938 3.422C12.156 3.844 12.188 4.937 11.984 5.469C12.484 6.062 12.75 6.859 12.75 7.672C12.75 9.594 11.297 11.047 9.203 11.312C9.734 11.656 10.093 12.406 10.093 13.266L10.093 14.891C10.093 15.359 10.484 15.625 10.953 15.438C13.781 14.359 16 11.53 16 8.03C16 3.61 12.406 0 7.984 0C3.563 0 0 3.61 0 8.031C-0.009 11.347 2.058 14.314 5.172 15.453C5.594 15.609 6 15.328 6 14.906L6 13.656C5.781 13.75 5.5 13.812 5.25 13.812C4.219 13.812 3.61 13.25 3.172 12.203C3 11.781 2.812 11.531 2.453 11.484C2.266 11.469 2.203 11.391 2.203 11.297C2.203 11.109 2.516 10.969 2.828 10.969C3.281 10.969 3.672 11.25 4.078 11.829C4.391 12.281 4.718 12.484 5.109 12.484C5.5 12.484 5.75 12.344 6.109 11.984C6.375 11.719 6.579 11.484 6.766 11.328Z"/></svg>',
42
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="white"><path d="${githubPath}"/></svg>`,
39
43
  )}`;
40
44
 
41
45
  /** `crypto.randomUUID` exists only in a secure context, and a phone often opens a dev server over plain HTTP. */