@stefan.inc/feedback-engine 1.2.2 → 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 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"> |
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.2",
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,7 +9,7 @@ export const cards = {
9
9
  padding: 10,
10
10
  rightColumnPenalty: 80,
11
11
  crossingPenalty: 500,
12
- watermark: 16,
12
+ watermark: 13,
13
13
  };
14
14
 
15
15
  export type Card = { isLeft: boolean; origin: Point };
@@ -94,8 +94,7 @@ function crossings(path: Point[], target: Frame, boxes: Frame[], earlier: Point[
94
94
  }
95
95
 
96
96
  type Columns = 'both' | 'left' | 'right';
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 };
97
+ type Arrangement = Layout & { cost: number; crossings: number };
99
98
 
100
99
  function arrange(
101
100
  columns: Columns,
@@ -107,9 +106,10 @@ function arrange(
107
106
  references: Frame[],
108
107
  ): Arrangement {
109
108
  const { margin, column, gutter, spacing, rightColumnPenalty, crossingPenalty, watermark } = cards;
109
+ const top = margin + watermark + spacing;
110
110
  const shot = {
111
111
  x: columns === 'right' ? margin : margin + column + gutter,
112
- y: margin,
112
+ y: top,
113
113
  width: screen.width,
114
114
  height: screen.height,
115
115
  };
@@ -120,15 +120,16 @@ function arrange(
120
120
  const midY = (index: number) => moved[index]!.y + moved[index]!.height / 2;
121
121
  const placed: Card[] = moved.map(() => ({ isLeft: true, origin: { x: 0, y: 0 } }));
122
122
  const paths: Point[][] = [];
123
- const underEnvironment = margin + environmentHeight + spacing * 2;
124
- 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;
125
126
  let nextRight = underEnvironment;
126
127
  let cost = 0;
127
128
  let crossed = 0;
128
129
  const order = moved.map((_, index) => index).toSorted((a, b) => midY(a) - midY(b) || a - b);
129
130
  for (const index of order) {
130
131
  const target = moved[index]!;
131
- const desired = Math.max(midY(index) - heights[index]! / 2, margin);
132
+ const desired = Math.max(midY(index) - heights[index]! / 2, top);
132
133
  const options: Card[] = [];
133
134
  if (columns !== 'right') options.push({ isLeft: true, origin: { x: margin, y: Math.max(desired, nextLeft) } });
134
135
  if (columns !== 'left') options.push({ isLeft: false, origin: { x: rightX, y: Math.max(desired, nextRight) } });
@@ -155,32 +156,26 @@ function arrange(
155
156
  ...placed.map((card, index) => card.origin.y + heights[index]! - shot.y),
156
157
  );
157
158
  shot.height = Math.min(screen.height, Math.max(viewport, lowest + viewport / 2));
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);
159
+ const height = Math.max(shot.y + shot.height, nextLeft - spacing, nextRight - spacing) + margin;
161
160
  return {
162
161
  shot,
163
162
  cards: placed,
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
- },
163
+ environment,
164
+ watermark: { isLeft: columns === 'left', origin: { x: environment.x, y: margin } },
169
165
  size: { width: columns === 'left' ? shot.x + shot.width + margin : rightX + column + margin, height },
170
166
  cost,
171
167
  crossings: crossed,
172
- fit,
173
168
  };
174
169
  }
175
170
 
176
171
  /**
177
172
  * Where the image export puts each item's card. Cards go in the column whose path to the target costs least: its
178
173
  * length, `rightColumnPenalty` points for the right column, and `crossingPenalty` for each other box or earlier path
179
- * it crosses, as level with the target as the cards above allow. The environment sits at the top of the right column,
180
- * and right-column cards start below it. When one column holds the environment and every card with no crossing and no
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
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
184
179
  * height that was on screen below the lowest box or card, and never shorter than that height, and `shot` is the part
185
180
  * that is drawn. `targets` and `references` are frames in the capture. The layout's frames are in the image.
186
181
  */
@@ -196,7 +191,7 @@ export function place(
196
191
  arrange(columns, targets, heights, screen, environmentHeight, viewport, references);
197
192
  const both = build('both');
198
193
  const single = [build('left'), build('right')]
199
- .filter(option => option.crossings === 0 && option.fit <= both.fit)
194
+ .filter(option => option.crossings === 0 && option.size.height <= both.size.height)
200
195
  .reduce<Arrangement | undefined>(
201
196
  (chosen, option) => (chosen && chosen.cost <= option.cost ? chosen : option),
202
197
  undefined,
package/src/dom/image.ts CHANGED
@@ -128,9 +128,18 @@ const footerPadding = 6;
128
128
 
129
129
  const clamp = (value: number, low: number, high: number) => Math.min(Math.max(value, low), high);
130
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
+
131
140
  function dashedBox(context: CanvasRenderingContext2D, target: Frame, color: string) {
132
141
  roundedRect(context, { x: target.x - 1, y: target.y - 1, width: target.width + 2, height: target.height + 2 }, 4);
133
- context.lineWidth = 1.5;
142
+ context.lineWidth = stroke;
134
143
  context.setLineDash([6, 4]);
135
144
  context.strokeStyle = withAlpha(color, 0.9);
136
145
  context.stroke();
@@ -183,6 +192,7 @@ function watermark(context: CanvasRenderingContext2D, { isLeft, origin }: Card)
183
192
  context.fillStyle = withAlpha(secondary, 0.5);
184
193
  context.save();
185
194
  context.translate(x, origin.y);
195
+ context.scale(side / 16, side / 16);
186
196
  const mark = new Path2D(githubPath);
187
197
  context.fill(mark);
188
198
  context.restore();
@@ -322,13 +332,10 @@ export function annotatedImage({ capture, image, scale }: Screen, annotations: A
322
332
  context.beginPath();
323
333
  context.moveTo(start.x, start.y);
324
334
  context.bezierCurveTo(control1.x, control1.y, control2.x, control2.y, end.x, end.y);
325
- context.lineWidth = 1.25;
335
+ context.lineWidth = stroke;
326
336
  context.strokeStyle = withAlpha(item.color, 0.6);
327
337
  context.stroke();
328
- context.beginPath();
329
- context.arc(end.x, end.y, 2.5, 0, Math.PI * 2);
330
- context.fillStyle = item.color;
331
- context.fill();
338
+ dot(context, end, item.color);
332
339
  badge(context, item.number, item.color, {
333
340
  x: clamp(target.x, shot.x + badgeSize / 2 + 2, shot.x + shot.width - badgeSize / 2 - 2),
334
341
  y: clamp(target.y, shot.y + badgeSize / 2 + 2, shot.y + shot.height - badgeSize / 2 - 2),
@@ -363,6 +370,7 @@ export function annotatedImage({ capture, image, scale }: Screen, annotations: A
363
370
  });
364
371
  drawText(context, item.text, { x: origin.x + padding * 2 + badgeSize, y: origin.y + padding });
365
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);
366
374
  }
367
375
 
368
376
  drawText(context, environment, placed.environment);