@stefan.inc/feedback-engine 1.0.2 → 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.0.2",
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
+ }
@@ -0,0 +1,3 @@
1
+ /** ProcrastiMate's app icon without its tile, 66 pixels square for 22 CSS pixels. Rendered by `scripts/procrastimate-icon.ts` from ProcrastiMate's `app-icon.svg`. */
2
+ export const procrastimateIcon =
3
+ 'data:image/png;base64,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';
@@ -23,6 +23,7 @@
23
23
  type ExportFormat,
24
24
  } from '../dom/share.ts';
25
25
  import type { Webhook } from '../dom/webhook.ts';
26
+ import { destinations, shortcutCount, type Destination } from './destinations.ts';
26
27
  import type { Engine } from './engine.ts';
27
28
  import ItemsSheet from './ItemsSheet.svelte';
28
29
  import ProcrastimateSheet from './ProcrastimateSheet.svelte';
@@ -91,6 +92,8 @@
91
92
  let showsShare = $state(false);
92
93
  let showsProcrastimate = $state(false);
93
94
  let posting = $state<Webhook>();
95
+ // svelte-ignore state_referenced_locally
96
+ const targets = destinations(engine.options);
94
97
  let confirmsClose = $state(false);
95
98
  let pending = $state<{ format: ExportFormat; ready: Export }>();
96
99
  let busy = $state(false);
@@ -209,6 +212,12 @@
209
212
  }
210
213
  }
211
214
 
215
+ function send(destination: Destination) {
216
+ showsShare = false;
217
+ if (destination.kind === 'procrastimate') showsProcrastimate = true;
218
+ else posting = destination.webhook;
219
+ }
220
+
212
221
  async function choose(format: ExportFormat) {
213
222
  showsShare = false;
214
223
  busy = true;
@@ -271,6 +280,22 @@
271
280
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6h11M9 12h11M9 18h11M4 6h.01M4 12h.01M4 18h.01" /></svg>
272
281
  {#if view.items.length}<span class="count" aria-hidden="true">{view.items.length}</span>{/if}
273
282
  </button>
283
+ {#each targets.slice(0, shortcutCount) as destination, index (index)}
284
+ <button
285
+ type="button"
286
+ class="round"
287
+ aria-label={destination.name}
288
+ title={destination.name}
289
+ disabled={!view.items.length || busy}
290
+ onclick={() => send(destination)}
291
+ >
292
+ {#if destination.image}
293
+ <img src={destination.image} alt="" />
294
+ {:else}
295
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z" /></svg>
296
+ {/if}
297
+ </button>
298
+ {/each}
274
299
  <div class="menu">
275
300
  <button
276
301
  type="button"
@@ -288,28 +313,10 @@
288
313
  {#each Object.entries(exportTitles) as [format, name] (format)}
289
314
  <button type="button" role="menuitem" onclick={() => void choose(format as ExportFormat)}>{name}</button>
290
315
  {/each}
291
- {#if engine.options.procrastimate}
292
- <button
293
- type="button"
294
- role="menuitem"
295
- onclick={() => {
296
- showsShare = false;
297
- showsProcrastimate = true;
298
- }}>ProcrastiMate</button
299
- >
300
- {/if}
301
- {#each engine.options.webhooks ?? [] as webhook, index (index)}
302
- <button
303
- type="button"
304
- role="menuitem"
305
- class="webhook"
306
- onclick={() => {
307
- showsShare = false;
308
- posting = webhook;
309
- }}
310
- >
311
- {#if webhook.image}<img src={webhook.image} alt="" />{/if}
312
- {webhook.name}
316
+ {#each targets as destination, index (index)}
317
+ <button type="button" role="menuitem" class="destination" onclick={() => send(destination)}>
318
+ {#if destination.image}<img src={destination.image} alt="" />{/if}
319
+ {destination.name}
313
320
  </button>
314
321
  {/each}
315
322
  </div>
@@ -594,6 +601,7 @@
594
601
  'Segoe UI',
595
602
  sans-serif;
596
603
  overflow: hidden;
604
+ overflow-wrap: anywhere;
597
605
  }
598
606
 
599
607
  .editor::backdrop {
@@ -624,7 +632,11 @@
624
632
 
625
633
  h1 {
626
634
  flex: 1;
635
+ min-width: 0;
627
636
  margin: 0;
637
+ overflow: hidden;
638
+ text-overflow: ellipsis;
639
+ white-space: nowrap;
628
640
  font-size: 17px;
629
641
  font-weight: 600;
630
642
  text-align: center;
@@ -641,6 +653,12 @@
641
653
  background: #2c2c2e;
642
654
  }
643
655
 
656
+ .round img {
657
+ width: 22px;
658
+ height: 22px;
659
+ object-fit: contain;
660
+ }
661
+
644
662
  .round.small {
645
663
  width: 30px;
646
664
  height: 30px;
@@ -679,7 +697,9 @@
679
697
  right: 0;
680
698
  z-index: 3;
681
699
  display: grid;
700
+ width: max-content;
682
701
  min-width: 220px;
702
+ max-width: calc(100vw - 32px);
683
703
  border-radius: 12px;
684
704
  background: #2c2c2e;
685
705
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.5);
@@ -698,7 +718,11 @@
698
718
  background: rgb(255 255 255 / 0.08);
699
719
  }
700
720
 
701
- .popup .webhook {
721
+ .popup img {
722
+ flex: none;
723
+ }
724
+
725
+ .popup .destination {
702
726
  display: flex;
703
727
  align-items: center;
704
728
  gap: 10px;
@@ -808,22 +832,24 @@
808
832
 
809
833
  .panel {
810
834
  display: grid;
835
+ grid-template-columns: minmax(0, 1fr);
811
836
  gap: 10px;
812
837
  padding: 16px;
813
838
  padding-bottom: max(16px, env(safe-area-inset-bottom));
814
839
  background: #1f1f1f;
815
840
  }
816
841
 
842
+ /* A long title takes the space it needs, but never all of it: each neighbor keeps its longest word, up to 35%. */
817
843
  .chain {
818
844
  display: flex;
819
845
  align-items: center;
820
846
  gap: 8px;
847
+ container-type: inline-size;
821
848
  }
822
849
 
823
850
  .side {
824
851
  display: flex;
825
- flex: 1;
826
- min-width: 0;
852
+ flex: 1 1 0;
827
853
  }
828
854
 
829
855
  .side.end {
@@ -831,16 +857,14 @@
831
857
  }
832
858
 
833
859
  .neighbor {
834
- max-width: 100%;
860
+ max-width: 35cqi;
835
861
  border: 0;
836
- border-radius: 999px;
862
+ border-radius: 16px;
837
863
  padding: 6px 10px;
838
864
  background: #333336;
839
865
  color: #aeaeb2;
840
866
  font-size: 14px;
841
- overflow: hidden;
842
- text-overflow: ellipsis;
843
- white-space: nowrap;
867
+ overflow-wrap: break-word;
844
868
  }
845
869
 
846
870
  .title {
@@ -857,9 +881,6 @@
857
881
  color: #ffd60a;
858
882
  font-size: 16px;
859
883
  font-weight: 700;
860
- overflow: hidden;
861
- text-overflow: ellipsis;
862
- white-space: nowrap;
863
884
  }
864
885
 
865
886
  /* Above the title, so on a phone it covers the screenshot and not the field being typed in. */
@@ -902,10 +923,6 @@
902
923
  monospace;
903
924
  }
904
925
 
905
- .source {
906
- overflow-wrap: anywhere;
907
- }
908
-
909
926
  .similar-count {
910
927
  flex: none;
911
928
  color: rgb(255 214 10 / 0.7);
@@ -933,10 +950,8 @@
933
950
 
934
951
  .picked {
935
952
  flex: 1;
953
+ min-width: 0;
936
954
  color: #32ade6;
937
- overflow: hidden;
938
- text-overflow: ellipsis;
939
- white-space: nowrap;
940
955
  }
941
956
 
942
957
  .insert {
@@ -987,6 +1002,8 @@
987
1002
  top: 60px;
988
1003
  left: 50%;
989
1004
  z-index: 4;
1005
+ width: max-content;
1006
+ max-width: calc(100% - 32px);
990
1007
  translate: -50% 0;
991
1008
  }
992
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} />
@@ -0,0 +1,25 @@
1
+ import type { ProcrastimateConfig } from '../dom/procrastimate.ts';
2
+ import { procrastimateIcon } from '../dom/procrastimate-icon.ts';
3
+ import { githubIcon, type Webhook } from '../dom/webhook.ts';
4
+
5
+ /** A server the feedback can be posted to, as the Share menu lists it after the exports. */
6
+ export type Destination = { name: string; image?: string } & (
7
+ | { kind: 'procrastimate' }
8
+ | { kind: 'webhook'; webhook: Webhook }
9
+ );
10
+
11
+ /** How many destinations also get a button beside Share. */
12
+ export const shortcutCount = 2;
13
+
14
+ /** ProcrastiMate first, then the webhooks with GitHub's icon, then the other webhooks in the app's order. */
15
+ export function destinations(options: { procrastimate?: ProcrastimateConfig; webhooks?: Webhook[] }): Destination[] {
16
+ const webhooks = [...(options.webhooks ?? [])].sort(
17
+ (a, b) => Number(b.image === githubIcon) - Number(a.image === githubIcon),
18
+ );
19
+ return [
20
+ ...(options.procrastimate
21
+ ? [{ kind: 'procrastimate' as const, name: 'ProcrastiMate', image: procrastimateIcon }]
22
+ : []),
23
+ ...webhooks.map(webhook => ({ kind: 'webhook' as const, name: webhook.name, image: webhook.image, webhook })),
24
+ ];
25
+ }
@@ -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.
@@ -27,7 +32,8 @@ export type FeedbackOptions = {
27
32
  procrastimate?: ProcrastimateConfig;
28
33
  /**
29
34
  * Adds one entry to the Share menu per webhook. Choosing it posts the image export and the JSON export to the
30
- * webhook's `url`, with nothing more to fill in.
35
+ * webhook's `url`, with nothing more to fill in. The menu lists ProcrastiMate, then the webhooks with `githubIcon`,
36
+ * then the others, and the first two of them also get a button beside Share.
31
37
  */
32
38
  webhooks?: Webhook[];
33
39
  };
@@ -43,12 +49,14 @@ export class Engine {
43
49
  readonly options: FeedbackOptions;
44
50
  readonly providers: { name: string; value: () => unknown }[] = [];
45
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;
46
54
  /** The seconds left before the pill captures by itself, while a countdown runs. */
47
55
  remaining: number | undefined;
48
56
  screen: Screen | undefined;
49
57
  /** Where the user pointed to open the editor, in the capture's coordinates. The editor starts with that node selected. */
50
58
  pointed: Point | undefined;
51
- /** 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. */
52
60
  onchange = () => {};
53
61
  /** The files of the last export, for automation that cannot use the clipboard or a download. */
54
62
  lastExport: { name: string; blob: Blob }[] = [];
@@ -92,6 +100,12 @@ export class Engine {
92
100
  this.timer = setTimeout(count, 1000);
93
101
  }
94
102
 
103
+ showHold(shown: boolean) {
104
+ if (this.screen || this.holding === shown) return;
105
+ this.holding = shown;
106
+ this.onchange();
107
+ }
108
+
95
109
  hidePill() {
96
110
  clearTimeout(this.timer);
97
111
  this.pill = false;
@@ -112,9 +126,10 @@ export class Engine {
112
126
  version: this.options.version,
113
127
  context: this.providers,
114
128
  });
115
- this.onchange();
116
129
  } finally {
117
130
  this.capturing = false;
131
+ this.holding = false;
132
+ this.onchange();
118
133
  }
119
134
  }
120
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.
@@ -32,7 +37,8 @@ export type FeedbackOptions = {
32
37
  };
33
38
  /**
34
39
  * Adds one entry to the Share menu per webhook. Choosing it posts the image export and the JSON export to the
35
- * webhook's `url`, with nothing more to fill in.
40
+ * webhook's `url`, with nothing more to fill in. The menu lists ProcrastiMate, then the webhooks with `githubIcon`,
41
+ * then the others, and the first two of them also get a button beside Share.
36
42
  */
37
43
  webhooks?: Webhook[];
38
44
  };
@@ -83,8 +89,9 @@ export type FeedbackEngine = {
83
89
  export type FeedbackRepresentable = { toFeedback(): unknown };
84
90
 
85
91
  /**
86
- * Turns Feedback on: Alt+Meta+click on anything captures the page and opens the editor on what was clicked. Call it
87
- * 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.
88
95
  */
89
96
  export function setupFeedbackEngine(options?: FeedbackOptions): FeedbackEngine;
90
97