@stefan.inc/feedback-engine 1.2.1 → 1.2.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.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 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 at the bottom left." 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.2",
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: 16,
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
  /**
@@ -92,7 +94,8 @@ function crossings(path: Point[], target: Frame, boxes: Frame[], earlier: Point[
92
94
  }
93
95
 
94
96
  type Columns = 'both' | 'left' | 'right';
95
- type Arrangement = Layout & { cost: number; crossings: number };
97
+ /** `fit` is the height without the watermark, so the watermark never costs the image its single column. */
98
+ type Arrangement = Layout & { cost: number; crossings: number; fit: number };
96
99
 
97
100
  function arrange(
98
101
  columns: Columns,
@@ -103,7 +106,7 @@ function arrange(
103
106
  viewport: number,
104
107
  references: Frame[],
105
108
  ): Arrangement {
106
- const { margin, column, gutter, spacing, rightColumnPenalty, crossingPenalty } = cards;
109
+ const { margin, column, gutter, spacing, rightColumnPenalty, crossingPenalty, watermark } = cards;
107
110
  const shot = {
108
111
  x: columns === 'right' ? margin : margin + column + gutter,
109
112
  y: margin,
@@ -152,14 +155,21 @@ function arrange(
152
155
  ...placed.map((card, index) => card.origin.y + heights[index]! - shot.y),
153
156
  );
154
157
  shot.height = Math.min(screen.height, Math.max(viewport, lowest + viewport / 2));
155
- const height = Math.max(shot.y + shot.height, nextLeft - spacing, nextRight - spacing) + margin;
158
+ const last = columns === 'right' ? nextRight : nextLeft;
159
+ const fit = Math.max(shot.y + shot.height, nextLeft - spacing, nextRight - spacing) + margin;
160
+ const height = Math.max(fit, last + watermark + margin);
156
161
  return {
157
162
  shot,
158
163
  cards: placed,
159
164
  environment: { x: columns === 'left' ? margin : rightX, y: margin },
165
+ watermark: {
166
+ isLeft: columns !== 'right',
167
+ origin: { x: columns === 'right' ? rightX : margin, y: height - margin - watermark },
168
+ },
160
169
  size: { width: columns === 'left' ? shot.x + shot.width + margin : rightX + column + margin, height },
161
170
  cost,
162
171
  crossings: crossed,
172
+ fit,
163
173
  };
164
174
  }
165
175
 
@@ -168,7 +178,9 @@ function arrange(
168
178
  * length, `rightColumnPenalty` points for the right column, and `crossingPenalty` for each other box or earlier path
169
179
  * it crosses, as level with the target as the cards above allow. The environment sits at the top of the right column,
170
180
  * 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
181
+ * taller image, not counting the watermark, the image drops the other column and keeps only a margin on that side, and of the two sides it takes
182
+ * the one whose paths are shorter in total. The watermark sits at the bottom of the left column, or of the right one
183
+ * when that is the only column, below the column's last card. A tall capture is cut half the
172
184
  * height that was on screen below the lowest box or card, and never shorter than that height, and `shot` is the part
173
185
  * that is drawn. `targets` and `references` are frames in the capture. The layout's frames are in the image.
174
186
  */
@@ -184,11 +196,11 @@ export function place(
184
196
  arrange(columns, targets, heights, screen, environmentHeight, viewport, references);
185
197
  const both = build('both');
186
198
  const single = [build('left'), build('right')]
187
- .filter(option => option.crossings === 0 && option.size.height <= both.size.height)
199
+ .filter(option => option.crossings === 0 && option.fit <= both.fit)
188
200
  .reduce<Arrangement | undefined>(
189
201
  (chosen, option) => (chosen && chosen.cost <= option.cost ? chosen : option),
190
202
  undefined,
191
203
  );
192
- const { shot, cards: placed, environment, size } = single ?? both;
193
- return { shot, cards: placed, environment, size };
204
+ const { shot, cards: placed, environment, watermark, size } = single ?? both;
205
+ return { shot, cards: placed, environment, watermark, size };
194
206
  }
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 = () => {
@@ -163,6 +174,22 @@ function referenceTag(context: CanvasRenderingContext2D, text: string, color: st
163
174
  label(context, text, center);
164
175
  }
165
176
 
177
+ /** GitHub's mark and the repository, faint, against the strip's left or right edge. */
178
+ function watermark(context: CanvasRenderingContext2D, { isLeft, origin }: Card) {
179
+ const side = metrics.watermark;
180
+ context.font = `11px ${sans}`;
181
+ const width = side + 6 + context.measureText(repository).width;
182
+ const x = isLeft ? origin.x : origin.x + metrics.column - width;
183
+ context.fillStyle = withAlpha(secondary, 0.5);
184
+ context.save();
185
+ context.translate(x, origin.y);
186
+ const mark = new Path2D(githubPath);
187
+ context.fill(mark);
188
+ context.restore();
189
+ context.textBaseline = 'middle';
190
+ context.fillText(repository, x + side + 6, origin.y + side / 2);
191
+ }
192
+
166
193
  /**
167
194
  * The image export: the screenshot with numbered boxes, each item's text and code location in a card beside it, a
168
195
  * tagged box for each referenced node, and the capture's environment, so the one file is enough on its own.
@@ -175,6 +202,7 @@ export function annotatedImage({ capture, image, scale }: Screen, annotations: A
175
202
 
176
203
  const app = capture.environment.find(entry => entry.name === 'App')?.value ?? 'App';
177
204
  const flagged = new Set(annotations.items.map(item => item.target));
205
+ const unflagged = annotations.used.filter(reference => !flagged.has(reference.target));
178
206
  const environment = layout(
179
207
  context,
180
208
  [
@@ -188,24 +216,31 @@ export function annotatedImage({ capture, image, scale }: Screen, annotations: A
188
216
  ],
189
217
  gap: 4,
190
218
  })),
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
- }),
219
+ ...(unflagged.length
220
+ ? [
221
+ {
222
+ runs: [{ text: 'REFERENCES', font: `700 11px ${sans}`, color: secondary, spacing: 0.6 }],
223
+ before: 6,
224
+ gap: 4,
225
+ },
226
+ ]
227
+ : []),
228
+ ...unflagged.map(reference => {
229
+ const source = nearestSource(capture, reference.target);
230
+ return {
231
+ runs: [
232
+ {
233
+ text: ` ${tag(reference)} `,
234
+ font: `700 11px ${sans}`,
235
+ color: 'white',
236
+ background: paletteColor(annotations.colorIndex(reference.target)),
237
+ },
238
+ ...(source ? [{ text: ` ${source}`, font: `11px ${mono}`, color: primary }] : []),
239
+ { text: ` ${title(capture.nodes[reference.target]!)}`, font: `12.5px ${sans}`, color: primary },
240
+ ],
241
+ gap: 4,
242
+ };
243
+ }),
209
244
  ],
210
245
  column,
211
246
  );
@@ -331,5 +366,6 @@ export function annotatedImage({ capture, image, scale }: Screen, annotations: A
331
366
  }
332
367
 
333
368
  drawText(context, environment, placed.environment);
369
+ watermark(context, placed.watermark);
334
370
  return canvas;
335
371
  }
@@ -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. */