@stefan.inc/feedback-engine 1.1.0 → 1.2.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.
package/README.md CHANGED
@@ -42,8 +42,9 @@ Requires Svelte 5.29 or later.
42
42
  - `setupFeedbackEngine()` turns on the trigger. Alt+Meta+click on anything, which is Option+Command+click on a Mac, captures the page and opens the editor with what you clicked selected. The app never gets that click, so a link does not navigate, and a disabled button can be clicked too. Pass `shortcut: 'Ctrl+Shift+Click'` for another chord, or `shortcut: false` for none. On a server the call returns an engine that does nothing, so a layout needs no guard.
43
43
  - A chord that ends in a key, such as `shortcut: 'Alt+Shift+F'`, drops an **Add Feedback** pill in at the top center instead, and clicking the pill captures the page. Left alone, the pill leaves after 5 seconds, and it leaves at once when the tab goes to the background.
44
44
  - `feedback.context(name, () => value)` attaches app state to every JSON export. The function runs when a capture is taken.
45
- - `button: true` shows a round Feedback button in the bottom right corner of every screen. It is the trigger for a phone, which has no modifier keys, and for an app opened from the home screen. Tapping it captures the page. Drag it to move it up or down, or to the other side. It stays where you leave it.
46
- - `feedback.countdown()` is the other trigger for a phone, where a shake does not work yet. Call it from an entry in one of your app's menus, such as Settings. The pill shows **Feedback in 5** and counts down, so you have 5 seconds to leave the menu and open the screen you mean. Then it captures. Tapping the pill captures at once, and `countdown(10)` gives more time.
45
+ - `button: true` shows a round Feedback button in the bottom right corner of every screen, for a phone, which has no modifier keys, and for an app opened from the home screen. Tapping it captures the page. Drag it to move it up or down, or to the other side. It stays where you leave it.
46
+ - On a phone, hold three fingers still on the screen. A capsule grows at the top center while you hold, and after 0.7 seconds the page is captured and the editor opens. Lifting or sliding a finger cancels it, so pans and pinches stay the app's. Pass `threeFingerHold: false` to turn it off.
47
+ - `feedback.countdown()` is another trigger for a phone, where a shake does not work yet. Call it from an entry in one of your app's menus, such as Settings. The pill shows **Feedback in 5** and counts down, so you have 5 seconds to leave the menu and open the screen you mean. Then it captures. Tapping the pill captures at once, and `countdown(10)` gives more time.
47
48
  - `feedback.present()` captures at once, with no countdown. It suits a control that is on the screen you want to capture.
48
49
  - To keep Feedback out of production, call it behind `import.meta.env.DEV` with a dynamic import. The production bundle then has the tags and none of the editor.
49
50
 
@@ -257,7 +258,7 @@ The token is the switch. With `PROCRASTIMATE_TOKEN` set, **ProcrastiMate** shows
257
258
  - A minified production build shows a class's minified name in component data, such as `a(count: 2)`.
258
259
  - Element locations for untagged content exist only in development builds, unless a React app turns on `elementSources`. Components keep theirs in every build.
259
260
  - React: a capture reads fields that are internal to React, the ones React's own developer tools read. If React renames them, components found without a tag are missing, and tagged regions and elements still appear. Bundlers other than Vite and Next.js are not supported.
260
- - A shake does not trigger Feedback on phones, where `button: true` or `countdown()` from a menu stands in for it, and the task name is not summarized by an on-device model. [spec/features.md](https://github.com/smirea/feedback-engine/blob/master/spec/features.md) lists both as planned.
261
+ - A shake does not trigger Feedback on phones, where a three-finger hold, `button: true`, or `countdown()` from a menu stands in for it, and the task name is not summarized by an on-device model. [spec/features.md](https://github.com/smirea/feedback-engine/blob/master/spec/features.md) lists both as planned.
261
262
 
262
263
  ## Drive it from a script
263
264
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stefan.inc/feedback-engine",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
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",
@@ -0,0 +1,84 @@
1
+ export const holdFingers = 3;
2
+ /** A quick three-finger touch, such as the start of a pinch or an accidental brush, shows nothing. */
3
+ export const holdDelay = 100;
4
+ /** From the third finger down to the capture. */
5
+ export const holdDuration = 700;
6
+ /** Fingers resting on glass drift a little. More than this is a pan or a pinch, and gives the touch back to the app. */
7
+ const slop = 20;
8
+
9
+ export type HoldEvents = {
10
+ /** The hold has lasted `holdDelay`. The indicator grows for the rest of `holdDuration`. */
11
+ onshow: () => void;
12
+ /** A finger lifted, moved, or joined before the hold was done. */
13
+ oncancel: () => void;
14
+ ondone: () => void;
15
+ /** Touches that start inside Feedback's own UI, such as a pinch on the editor's screenshot, are not a hold. */
16
+ ignores: (event: TouchEvent) => boolean;
17
+ };
18
+
19
+ /**
20
+ * Watches for three fingers held still on the page. Touch events, not pointer events: iOS Safari can claim a
21
+ * multi-finger pointer for its own pinch and cancel it, while it keeps sending the touches. The listeners are passive,
22
+ * so the app's scrolling and its own touch handling are untouched.
23
+ */
24
+ export function watchHold(events: HoldEvents) {
25
+ let starts = new Map<number, { x: number; y: number }>();
26
+ let shown: ReturnType<typeof setTimeout> | undefined;
27
+ let done: ReturnType<typeof setTimeout> | undefined;
28
+ let visible = false;
29
+ // After a hold fires, the fingers still on the glass must lift before another can start.
30
+ let spent = false;
31
+
32
+ const stop = () => {
33
+ if (!done) return;
34
+ clearTimeout(shown);
35
+ clearTimeout(done);
36
+ shown = done = undefined;
37
+ if (visible) events.oncancel();
38
+ visible = false;
39
+ };
40
+
41
+ const start = (event: TouchEvent) => {
42
+ if (spent || event.touches.length !== holdFingers || events.ignores(event)) return stop();
43
+ starts = new Map(
44
+ Array.from(event.touches).map(touch => [touch.identifier, { x: touch.clientX, y: touch.clientY }]),
45
+ );
46
+ shown = setTimeout(() => {
47
+ visible = true;
48
+ events.onshow();
49
+ }, holdDelay);
50
+ done = setTimeout(() => {
51
+ shown = done = undefined;
52
+ visible = false;
53
+ spent = true;
54
+ events.ondone();
55
+ }, holdDuration);
56
+ };
57
+
58
+ const move = (event: TouchEvent) => {
59
+ if (!done) return;
60
+ const moved = Array.from(event.changedTouches).some(touch => {
61
+ const from = starts.get(touch.identifier);
62
+ return from && Math.hypot(touch.clientX - from.x, touch.clientY - from.y) > slop;
63
+ });
64
+ if (moved) stop();
65
+ };
66
+
67
+ const end = (event: TouchEvent) => {
68
+ stop();
69
+ if (event.touches.length === 0) spent = false;
70
+ };
71
+
72
+ const options = { capture: true, passive: true };
73
+ addEventListener('touchstart', start, options);
74
+ addEventListener('touchmove', move, options);
75
+ addEventListener('touchend', end, options);
76
+ addEventListener('touchcancel', end, options);
77
+ return () => {
78
+ stop();
79
+ removeEventListener('touchstart', start, options);
80
+ removeEventListener('touchmove', move, options);
81
+ removeEventListener('touchend', end, options);
82
+ removeEventListener('touchcancel', end, options);
83
+ };
84
+ }
@@ -601,6 +601,7 @@
601
601
  'Segoe UI',
602
602
  sans-serif;
603
603
  overflow: hidden;
604
+ overflow-wrap: anywhere;
604
605
  }
605
606
 
606
607
  .editor::backdrop {
@@ -696,7 +697,9 @@
696
697
  right: 0;
697
698
  z-index: 3;
698
699
  display: grid;
700
+ width: max-content;
699
701
  min-width: 220px;
702
+ max-width: calc(100vw - 32px);
700
703
  border-radius: 12px;
701
704
  background: #2c2c2e;
702
705
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.5);
@@ -715,6 +718,10 @@
715
718
  background: rgb(255 255 255 / 0.08);
716
719
  }
717
720
 
721
+ .popup img {
722
+ flex: none;
723
+ }
724
+
718
725
  .popup .destination {
719
726
  display: flex;
720
727
  align-items: center;
@@ -825,22 +832,24 @@
825
832
 
826
833
  .panel {
827
834
  display: grid;
835
+ grid-template-columns: minmax(0, 1fr);
828
836
  gap: 10px;
829
837
  padding: 16px;
830
838
  padding-bottom: max(16px, env(safe-area-inset-bottom));
831
839
  background: #1f1f1f;
832
840
  }
833
841
 
842
+ /* A long title takes the space it needs, but never all of it: each neighbor keeps its longest word, up to 35%. */
834
843
  .chain {
835
844
  display: flex;
836
845
  align-items: center;
837
846
  gap: 8px;
847
+ container-type: inline-size;
838
848
  }
839
849
 
840
850
  .side {
841
851
  display: flex;
842
- flex: 1;
843
- min-width: 0;
852
+ flex: 1 1 0;
844
853
  }
845
854
 
846
855
  .side.end {
@@ -848,16 +857,14 @@
848
857
  }
849
858
 
850
859
  .neighbor {
851
- max-width: 100%;
860
+ max-width: 35cqi;
852
861
  border: 0;
853
- border-radius: 999px;
862
+ border-radius: 16px;
854
863
  padding: 6px 10px;
855
864
  background: #333336;
856
865
  color: #aeaeb2;
857
866
  font-size: 14px;
858
- overflow: hidden;
859
- text-overflow: ellipsis;
860
- white-space: nowrap;
867
+ overflow-wrap: break-word;
861
868
  }
862
869
 
863
870
  .title {
@@ -874,9 +881,6 @@
874
881
  color: #ffd60a;
875
882
  font-size: 16px;
876
883
  font-weight: 700;
877
- overflow: hidden;
878
- text-overflow: ellipsis;
879
- white-space: nowrap;
880
884
  }
881
885
 
882
886
  /* Above the title, so on a phone it covers the screenshot and not the field being typed in. */
@@ -919,10 +923,6 @@
919
923
  monospace;
920
924
  }
921
925
 
922
- .source {
923
- overflow-wrap: anywhere;
924
- }
925
-
926
926
  .similar-count {
927
927
  flex: none;
928
928
  color: rgb(255 214 10 / 0.7);
@@ -950,10 +950,8 @@
950
950
 
951
951
  .picked {
952
952
  flex: 1;
953
+ min-width: 0;
953
954
  color: #32ade6;
954
- overflow: hidden;
955
- text-overflow: ellipsis;
956
- white-space: nowrap;
957
955
  }
958
956
 
959
957
  .insert {
@@ -1004,6 +1002,8 @@
1004
1002
  top: 60px;
1005
1003
  left: 50%;
1006
1004
  z-index: 4;
1005
+ width: max-content;
1006
+ max-width: calc(100% - 32px);
1007
1007
  translate: -50% 0;
1008
1008
  }
1009
1009
 
@@ -0,0 +1,112 @@
1
+ <svelte:options css="injected" />
2
+
3
+ <script lang="ts">
4
+ import { holdDelay, holdDuration } from '../dom/hold.ts';
5
+ </script>
6
+
7
+ <!-- It grows for exactly the rest of the hold, so it is full when the capture starts. -->
8
+ <div class="hold" role="status" aria-label="Hold for Feedback" style="--grow:{holdDuration - holdDelay}ms">
9
+ <span class="fill"></span>
10
+ <span class="label">
11
+ <svg viewBox="0 0 256 256" aria-hidden="true">
12
+ <path d="M40 56h120l24 24v64H96l-32 28v-28H40z" />
13
+ <path d="M112 172v20h64l32 28v-28h20v-88l-16-16" />
14
+ </svg>
15
+ Add Feedback
16
+ </span>
17
+ </div>
18
+
19
+ <style>
20
+ .hold {
21
+ position: fixed;
22
+ top: max(10px, env(safe-area-inset-top));
23
+ left: 50%;
24
+ z-index: 2147483647;
25
+ display: grid;
26
+ place-items: center;
27
+ width: 176px;
28
+ height: 42px;
29
+ border: 1px solid rgb(255 255 255 / 0.35);
30
+ border-radius: 999px;
31
+ box-sizing: border-box;
32
+ background: rgb(40 40 44 / 0.72);
33
+ backdrop-filter: blur(18px) saturate(1.6);
34
+ -webkit-backdrop-filter: blur(18px) saturate(1.6);
35
+ box-shadow: 0 8px 28px rgb(0 0 0 / 0.28);
36
+ color: white;
37
+ overflow: hidden;
38
+ pointer-events: none;
39
+ translate: -50% 0;
40
+ animation:
41
+ grow var(--grow) cubic-bezier(0.3, 0.7, 0.4, 1) both,
42
+ ready 0.5s var(--grow) ease-in-out infinite alternate;
43
+ }
44
+
45
+ .fill {
46
+ position: absolute;
47
+ inset: 0;
48
+ background: linear-gradient(90deg, rgb(10 132 255 / 0.55), rgb(100 210 255 / 0.55));
49
+ transform-origin: left;
50
+ animation: fill var(--grow) linear both;
51
+ }
52
+
53
+ .label {
54
+ position: relative;
55
+ display: flex;
56
+ align-items: center;
57
+ gap: 8px;
58
+ font:
59
+ 600 15px/1 system-ui,
60
+ sans-serif;
61
+ white-space: nowrap;
62
+ animation: appear var(--grow) ease-out both;
63
+ }
64
+
65
+ svg {
66
+ width: 22px;
67
+ height: 22px;
68
+ fill: none;
69
+ stroke: currentColor;
70
+ stroke-width: 16;
71
+ stroke-linejoin: round;
72
+ }
73
+
74
+ /* From a capsule the size of a phone's camera cutout to the size of the Add Feedback pill. */
75
+ @keyframes grow {
76
+ from {
77
+ width: 44px;
78
+ height: 14px;
79
+ opacity: 0.4;
80
+ }
81
+ }
82
+
83
+ @keyframes fill {
84
+ from {
85
+ scale: 0 1;
86
+ }
87
+ }
88
+
89
+ @keyframes appear {
90
+ 0%,
91
+ 45% {
92
+ opacity: 0;
93
+ scale: 0.8;
94
+ }
95
+ }
96
+
97
+ @keyframes ready {
98
+ to {
99
+ box-shadow: 0 0 0 4px rgb(10 132 255 / 0.35);
100
+ }
101
+ }
102
+
103
+ @media (prefers-reduced-motion: reduce) {
104
+ .hold {
105
+ animation: none;
106
+ }
107
+
108
+ .label {
109
+ animation: none;
110
+ }
111
+ }
112
+ </style>
@@ -4,6 +4,7 @@
4
4
  import Button from './Button.svelte';
5
5
  import Editor from './Editor.svelte';
6
6
  import type { Engine } from './engine.ts';
7
+ import Hold from './Hold.svelte';
7
8
  import Pill from './Pill.svelte';
8
9
 
9
10
  let { engine }: { engine: Engine } = $props();
@@ -14,7 +15,7 @@
14
15
  engine.onchange = () => (version += 1);
15
16
  const shown = $derived.by(() => {
16
17
  void version;
17
- return { pill: engine.pill, remaining: engine.remaining, screen: engine.screen };
18
+ return { pill: engine.pill, holding: engine.holding, remaining: engine.remaining, screen: engine.screen };
18
19
  });
19
20
  </script>
20
21
 
@@ -24,6 +25,9 @@
24
25
  {#if shown.pill}
25
26
  <Pill remaining={shown.remaining} onpress={() => void engine.present()} />
26
27
  {/if}
28
+ {#if shown.holding}
29
+ <Hold />
30
+ {/if}
27
31
  {#if shown.screen}
28
32
  {#key shown.screen}
29
33
  <Editor {engine} screen={shown.screen} />
@@ -20,6 +20,11 @@ export type FeedbackOptions = {
20
20
  * keyboard. Pressing it captures the page. Drag it to move it to another height or the other side.
21
21
  */
22
22
  button?: boolean;
23
+ /**
24
+ * Holding three fingers still on the screen for a moment captures the page, for a phone, which has no keyboard. A
25
+ * capsule grows at the top center while the fingers are down. On unless `false`.
26
+ */
27
+ threeFingerHold?: boolean;
23
28
  /**
24
29
  * Adds ProcrastiMate to the Share menu. Leave it out behind `feedbackProcrastimate()` from the Vite entry point,
25
30
  * which adds the entry by itself when it has a token. Set it for a proxy of your own.
@@ -44,12 +49,14 @@ export class Engine {
44
49
  readonly options: FeedbackOptions;
45
50
  readonly providers: { name: string; value: () => unknown }[] = [];
46
51
  pill = false;
52
+ /** Whether the three-finger hold's capsule shows, from a moment into the hold until the editor opens. */
53
+ holding = false;
47
54
  /** The seconds left before the pill captures by itself, while a countdown runs. */
48
55
  remaining: number | undefined;
49
56
  screen: Screen | undefined;
50
57
  /** Where the user pointed to open the editor, in the capture's coordinates. The editor starts with that node selected. */
51
58
  pointed: Point | undefined;
52
- /** Called after `pill`, `remaining`, or `screen` changes, so the host draws again. */
59
+ /** Called after `pill`, `holding`, `remaining`, or `screen` changes, so the host draws again. */
53
60
  onchange = () => {};
54
61
  /** The files of the last export, for automation that cannot use the clipboard or a download. */
55
62
  lastExport: { name: string; blob: Blob }[] = [];
@@ -93,6 +100,12 @@ export class Engine {
93
100
  this.timer = setTimeout(count, 1000);
94
101
  }
95
102
 
103
+ showHold(shown: boolean) {
104
+ if (this.screen || this.holding === shown) return;
105
+ this.holding = shown;
106
+ this.onchange();
107
+ }
108
+
96
109
  hidePill() {
97
110
  clearTimeout(this.timer);
98
111
  this.pill = false;
@@ -113,9 +126,10 @@ export class Engine {
113
126
  version: this.options.version,
114
127
  context: this.providers,
115
128
  });
116
- this.onchange();
117
129
  } finally {
118
130
  this.capturing = false;
131
+ this.holding = false;
132
+ this.onchange();
119
133
  }
120
134
  }
121
135
 
@@ -1,4 +1,5 @@
1
1
  import { mount, unmount } from 'svelte';
2
+ import { watchHold } from '../dom/hold.ts';
2
3
  import { hostAttribute } from '../dom/tags.ts';
3
4
  import { defaultShortcut, Engine, matchesShortcut, type FeedbackOptions } from './engine.ts';
4
5
  import Host from './Host.svelte';
@@ -30,8 +31,9 @@ declare global {
30
31
  let current: { engine: FeedbackEngine; destroy: () => void } | undefined;
31
32
 
32
33
  /**
33
- * Turns Feedback on: Alt+Meta+click on anything captures the page and opens the editor on what was clicked. Call it
34
- * once, in the browser. On a server it returns an engine that does nothing, so a layout can call it without a guard.
34
+ * Turns Feedback on: Alt+Meta+click on anything captures the page and opens the editor on what was clicked, and so
35
+ * does a three-finger hold on a phone. Call it once, in the browser. On a server it returns an engine that does
36
+ * nothing, so a layout can call it without a guard.
35
37
  */
36
38
  export function setupFeedbackEngine(options: FeedbackOptions = {}): FeedbackEngine {
37
39
  if (typeof document === 'undefined') {
@@ -77,6 +79,15 @@ export function setupFeedbackEngine(options: FeedbackOptions = {}): FeedbackEngi
77
79
  // In the capture phase, so the chord reaches Feedback before the element under the pointer.
78
80
  for (const type of pointerEvents) addEventListener(type, pointer, true);
79
81
  document.addEventListener('visibilitychange', hidden);
82
+ const unwatchHold =
83
+ options.threeFingerHold === false
84
+ ? () => {}
85
+ : watchHold({
86
+ onshow: () => engine.showHold(true),
87
+ oncancel: () => engine.showHold(false),
88
+ ondone: () => void engine.present(),
89
+ ignores: event => engine.screen !== undefined || event.composedPath().includes(host),
90
+ });
80
91
 
81
92
  const api: FeedbackEngine = {
82
93
  context(name, value) {
@@ -94,6 +105,7 @@ export function setupFeedbackEngine(options: FeedbackOptions = {}): FeedbackEngi
94
105
  removeEventListener('keydown', keydown);
95
106
  for (const type of pointerEvents) removeEventListener(type, pointer, true);
96
107
  document.removeEventListener('visibilitychange', hidden);
108
+ unwatchHold();
97
109
  void unmount(component);
98
110
  host.remove();
99
111
  if (current?.engine === api) current = undefined;
@@ -18,6 +18,11 @@ export type FeedbackOptions = {
18
18
  * keyboard. Pressing it captures the page. Drag it to move it to another height or the other side.
19
19
  */
20
20
  button?: boolean;
21
+ /**
22
+ * Holding three fingers still on the screen for a moment captures the page, for a phone, which has no keyboard. A
23
+ * capsule grows at the top center while the fingers are down. On unless `false`.
24
+ */
25
+ threeFingerHold?: boolean;
21
26
  /**
22
27
  * Adds ProcrastiMate to the Share menu. Leave it out behind `feedbackProcrastimate()` from the Vite entry point,
23
28
  * which adds the entry by itself when it has a token. Set it for a proxy of your own.
@@ -84,8 +89,9 @@ export type FeedbackEngine = {
84
89
  export type FeedbackRepresentable = { toFeedback(): unknown };
85
90
 
86
91
  /**
87
- * Turns Feedback on: Alt+Meta+click on anything captures the page and opens the editor on what was clicked. Call it
88
- * once, in the browser, before or after React renders. On a server it returns an engine that does nothing.
92
+ * Turns Feedback on: Alt+Meta+click on anything captures the page and opens the editor on what was clicked, and so
93
+ * does a three-finger hold on a phone. Call it once, in the browser, before or after React renders. On a server it
94
+ * returns an engine that does nothing.
89
95
  */
90
96
  export function setupFeedbackEngine(options?: FeedbackOptions): FeedbackEngine;
91
97