@automovie/viewer 0.3.1 → 0.3.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.
@@ -4,14 +4,14 @@ import type { IAutoMovieInspectorAction } from "./IAutoMovieInspectorAction.js";
4
4
  /**
5
5
  * The playhead's slider and clock, the one component that reads the playhead's second and so the only one a playing frame re-renders; the time panel reads only whether it plays.
6
6
  *
7
- * Dragging the slider, which steps by one frame of the subject's grid, seeks the playhead and dispatches the second as a `time` edit, and so does playback stopping, by a pause or at the end, so the request names the picture left on screen. The slider gives its second and frame as its value text, which a screen reader announces in place of the raw number.
7
+ * Moving the slider seeks to a regular frame or the exact end and dispatches the second as a `time` edit. Without a frame rate, the slider seeks directly in seconds. A pause or playback reaching the end also dispatches its second, so the request names the picture left on screen. The slider announces its second and, when available, its frame number.
8
8
  *
9
9
  * @evidence contracts/development/common.md#meaningful-documentation States what it shows, why it alone reads the playhead's second, when it edits the request and what it announces.
10
- * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` is React's contract for reading an external store without tearing; the playhead's cached snapshot keeps it from rendering when nothing moved.
11
- * @evidence contracts/development/implementation.md#clear-and-simple-structure One read of the store, one input and one output.
10
+ * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` reads the cached playhead snapshot without tearing. Native range inputs enforce their step grid, so integer positions give every frame and the exact end a valid slider value.
11
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One store read, one slider that converts its position to seconds on seek, and one clock output.
12
12
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Playback frames dispatch nothing; only a seek and the change from playing to stopped edit the request, and the first render, which stops nothing, edits nothing.
13
13
  * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per render, one render per moved snapshot.
14
- * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A view of one snapshot.
14
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the shared presentation grid and computes its last frame number once per render.
15
15
  * @evidence contracts/development/implementation.md#bound-retention-and-release-resources React holds one playhead subscription while the readout is mounted and removes it on unmount.
16
16
  */
17
17
  export declare function AutoMovieInspectorTimeReadout(props: {
@@ -2,18 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AutoMovieInspectorTimeReadout = AutoMovieInspectorTimeReadout;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const render_1 = require("@automovie/render");
5
6
  const react_1 = require("react");
6
7
  /**
7
8
  * The playhead's slider and clock, the one component that reads the playhead's second and so the only one a playing frame re-renders; the time panel reads only whether it plays.
8
9
  *
9
- * Dragging the slider, which steps by one frame of the subject's grid, seeks the playhead and dispatches the second as a `time` edit, and so does playback stopping, by a pause or at the end, so the request names the picture left on screen. The slider gives its second and frame as its value text, which a screen reader announces in place of the raw number.
10
+ * Moving the slider seeks to a regular frame or the exact end and dispatches the second as a `time` edit. Without a frame rate, the slider seeks directly in seconds. A pause or playback reaching the end also dispatches its second, so the request names the picture left on screen. The slider announces its second and, when available, its frame number.
10
11
  *
11
12
  * @evidence contracts/development/common.md#meaningful-documentation States what it shows, why it alone reads the playhead's second, when it edits the request and what it announces.
12
- * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` is React's contract for reading an external store without tearing; the playhead's cached snapshot keeps it from rendering when nothing moved.
13
- * @evidence contracts/development/implementation.md#clear-and-simple-structure One read of the store, one input and one output.
13
+ * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` reads the cached playhead snapshot without tearing. Native range inputs enforce their step grid, so integer positions give every frame and the exact end a valid slider value.
14
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One store read, one slider that converts its position to seconds on seek, and one clock output.
14
15
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Playback frames dispatch nothing; only a seek and the change from playing to stopped edit the request, and the first render, which stops nothing, edits nothing.
15
16
  * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per render, one render per moved snapshot.
16
- * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A view of one snapshot.
17
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the shared presentation grid and computes its last frame number once per render.
17
18
  * @evidence contracts/development/implementation.md#bound-retention-and-release-resources React holds one playhead subscription while the readout is mounted and removes it on unmount.
18
19
  */
19
20
  function AutoMovieInspectorTimeReadout(props) {
@@ -26,14 +27,26 @@ function AutoMovieInspectorTimeReadout(props) {
26
27
  dispatch({ type: "time", seconds: snapshot.seconds });
27
28
  was.current = snapshot.playing;
28
29
  }, [snapshot, dispatch]);
29
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { type: "range", "aria-label": "Second", "aria-valuetext": props.fps === null
30
- ? `${snapshot.seconds.toFixed(2)} seconds`
31
- : `${snapshot.seconds.toFixed(2)} seconds, frame ${Math.round(snapshot.seconds * props.fps)} of ${Math.round(snapshot.durationSeconds * props.fps)}`, min: 0, max: snapshot.durationSeconds, step: props.fps === null ? "any" : 1 / props.fps, value: snapshot.seconds, style: { flex: "1 1 auto" }, onChange: (event) => {
32
- props.playhead.seek(Number(event.target.value));
30
+ // Integer slider positions keep the end reachable even between regular frames.
31
+ const { fps } = props;
32
+ const { durationSeconds, seconds } = snapshot;
33
+ const last = fps === null
34
+ ? durationSeconds
35
+ : render_1.AutoMovieFrameGrid.last(durationSeconds, fps);
36
+ const position = fps === null
37
+ ? seconds
38
+ : render_1.AutoMovieFrameGrid.nearest(seconds, durationSeconds, fps, last);
39
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { type: "range", "aria-label": "Second", "aria-valuetext": fps === null
40
+ ? `${seconds.toFixed(2)} seconds`
41
+ : `${seconds.toFixed(2)} seconds, frame ${position} of ${last}`, min: 0, max: last, step: fps === null ? "any" : 1, value: position, style: { flex: "1 1 auto" }, onChange: (event) => {
42
+ const value = event.currentTarget.valueAsNumber;
43
+ props.playhead.seek(fps === null
44
+ ? value
45
+ : render_1.AutoMovieFrameGrid.time(value, durationSeconds, fps));
33
46
  props.dispatch({
34
47
  type: "time",
35
48
  seconds: props.playhead.getSnapshot().seconds,
36
49
  });
37
- } }), (0, jsx_runtime_1.jsxs)("output", { style: { fontVariantNumeric: "tabular-nums" }, children: [snapshot.seconds.toFixed(2), " / ", snapshot.durationSeconds.toFixed(2), " s"] })] }));
50
+ } }), (0, jsx_runtime_1.jsxs)("output", { style: { fontVariantNumeric: "tabular-nums" }, children: [seconds.toFixed(2), " / ", durationSeconds.toFixed(2), " s"] })] }));
38
51
  }
39
52
  //# sourceMappingURL=AutoMovieInspectorTimeReadout.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AutoMovieInspectorTimeReadout.js","sourceRoot":"","sources":["../../src/inspector/AutoMovieInspectorTimeReadout.tsx"],"names":[],"mappings":";;;;AAAA,iCAOe;AAKf;;;;;;;;;;;;GAYG;AACH,uCAA8C,KAS7C;IACC,MAAM,QAAQ,GAAyC,IAAA,4BAAoB,EACzE,KAAK,CAAC,QAAQ,CAAC,SAAS,EACxB,KAAK,CAAC,QAAQ,CAAC,WAAW,CAC3B,CAAC;IAEF,2FAA2F;IAC3F,MAAM,GAAG,GAAuB,IAAA,cAAM,EAAU,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,IAAA,iBAAS,EAAC,GAAS,EAAE;QACnB,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO;YAClC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACxD,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IACjC,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IACzB,OAAO,CACL,6DACE,kCACE,IAAI,EAAC,OAAO,gB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AG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU;oBACjC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,QAAQ,OAAO,IAAI,EAAE,EAEnE,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,IAAI,EACT,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAC9B,KAAK,EAAE,QAAQ,EACf,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAC3B,QAAQ,EAAE,CAAC,KAAoC,EAAQ,EAAE;oBACvD,MAAM,KAAK,GAAW,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC;oBACxD,KAAK,CAAC,QAAQ,CAAC,IAAI,CACjB,GAAG,KAAK,IAAI;wBACV,CAAC,CAAC,KAAK;wBACP,CAAC,CAAC,2BAAkB,CAAC,IAAI,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,CAAC,CACzD,CAAC;oBACF,KAAK,CAAC,QAAQ,CAAC;wBACb,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO;qBAC9C,CAAC,CAAC;gBACL,CAAC,GACD,EACF,oCAAQ,KAAK,EAAE,EAAE,kBAAkB,EAAE,cAAc,EAAE,aAClD,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,SAAK,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,UAC3C,IACR,CACJ,CAAC;AACJ,CAAC"}
@@ -1,17 +1,18 @@
1
+ import { AutoMovieFrameGrid } from "@automovie/render";
1
2
  import { useEffect, useRef, useSyncExternalStore } from "react";
2
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
4
  // src/inspector/AutoMovieInspectorTimeReadout.tsx
4
5
  /**
5
6
  * The playhead's slider and clock, the one component that reads the playhead's second and so the only one a playing frame re-renders; the time panel reads only whether it plays.
6
7
  *
7
- * Dragging the slider, which steps by one frame of the subject's grid, seeks the playhead and dispatches the second as a `time` edit, and so does playback stopping, by a pause or at the end, so the request names the picture left on screen. The slider gives its second and frame as its value text, which a screen reader announces in place of the raw number.
8
+ * Moving the slider seeks to a regular frame or the exact end and dispatches the second as a `time` edit. Without a frame rate, the slider seeks directly in seconds. A pause or playback reaching the end also dispatches its second, so the request names the picture left on screen. The slider announces its second and, when available, its frame number.
8
9
  *
9
10
  * @evidence contracts/development/common.md#meaningful-documentation States what it shows, why it alone reads the playhead's second, when it edits the request and what it announces.
10
- * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` is React's contract for reading an external store without tearing; the playhead's cached snapshot keeps it from rendering when nothing moved.
11
- * @evidence contracts/development/implementation.md#clear-and-simple-structure One read of the store, one input and one output.
11
+ * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` reads the cached playhead snapshot without tearing. Native range inputs enforce their step grid, so integer positions give every frame and the exact end a valid slider value.
12
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One store read, one slider that converts its position to seconds on seek, and one clock output.
12
13
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Playback frames dispatch nothing; only a seek and the change from playing to stopped edit the request, and the first render, which stops nothing, edits nothing.
13
14
  * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per render, one render per moved snapshot.
14
- * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A view of one snapshot.
15
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the shared presentation grid and computes its last frame number once per render.
15
16
  * @evidence contracts/development/implementation.md#bound-retention-and-release-resources React holds one playhead subscription while the readout is mounted and removes it on unmount.
16
17
  */
17
18
  function AutoMovieInspectorTimeReadout(props) {
@@ -25,17 +26,22 @@ function AutoMovieInspectorTimeReadout(props) {
25
26
  });
26
27
  was.current = snapshot.playing;
27
28
  }, [snapshot, dispatch]);
29
+ const { fps } = props;
30
+ const { durationSeconds, seconds } = snapshot;
31
+ const last = fps === null ? durationSeconds : AutoMovieFrameGrid.last(durationSeconds, fps);
32
+ const position = fps === null ? seconds : AutoMovieFrameGrid.nearest(seconds, durationSeconds, fps, last);
28
33
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
29
34
  type: "range",
30
35
  "aria-label": "Second",
31
- "aria-valuetext": props.fps === null ? `${snapshot.seconds.toFixed(2)} seconds` : `${snapshot.seconds.toFixed(2)} seconds, frame ${Math.round(snapshot.seconds * props.fps)} of ${Math.round(snapshot.durationSeconds * props.fps)}`,
36
+ "aria-valuetext": fps === null ? `${seconds.toFixed(2)} seconds` : `${seconds.toFixed(2)} seconds, frame ${position} of ${last}`,
32
37
  min: 0,
33
- max: snapshot.durationSeconds,
34
- step: props.fps === null ? "any" : 1 / props.fps,
35
- value: snapshot.seconds,
38
+ max: last,
39
+ step: fps === null ? "any" : 1,
40
+ value: position,
36
41
  style: { flex: "1 1 auto" },
37
42
  onChange: (event) => {
38
- props.playhead.seek(Number(event.target.value));
43
+ const value = event.currentTarget.valueAsNumber;
44
+ props.playhead.seek(fps === null ? value : AutoMovieFrameGrid.time(value, durationSeconds, fps));
39
45
  props.dispatch({
40
46
  type: "time",
41
47
  seconds: props.playhead.getSnapshot().seconds
@@ -44,9 +50,9 @@ function AutoMovieInspectorTimeReadout(props) {
44
50
  }), /* @__PURE__ */ jsxs("output", {
45
51
  style: { fontVariantNumeric: "tabular-nums" },
46
52
  children: [
47
- snapshot.seconds.toFixed(2),
53
+ seconds.toFixed(2),
48
54
  " / ",
49
- snapshot.durationSeconds.toFixed(2),
55
+ durationSeconds.toFixed(2),
50
56
  " s"
51
57
  ]
52
58
  })] });
@@ -1 +1 @@
1
- {"version":3,"file":"AutoMovieInspectorTimeReadout.mjs","names":[],"sources":["../../src/inspector/AutoMovieInspectorTimeReadout.tsx"],"sourcesContent":["import {\n type ChangeEvent,\n type JSX,\n type RefObject,\n useEffect,\n useRef,\n useSyncExternalStore,\n} from \"react\";\n\nimport type { AutoMovieInspectorPlayhead } from \"./AutoMovieInspectorPlayhead.js\";\nimport type { IAutoMovieInspectorAction } from \"./IAutoMovieInspectorAction.js\";\n\n/**\n * The playhead's slider and clock, the one component that reads the playhead's second and so the only one a playing frame re-renders; the time panel reads only whether it plays.\n *\n * Dragging the slider, which steps by one frame of the subject's grid, seeks the playhead and dispatches the second as a `time` edit, and so does playback stopping, by a pause or at the end, so the request names the picture left on screen. The slider gives its second and frame as its value text, which a screen reader announces in place of the raw number.\n *\n * @evidence contracts/development/common.md#meaningful-documentation States what it shows, why it alone reads the playhead's second, when it edits the request and what it announces.\n * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` is React's contract for reading an external store without tearing; the playhead's cached snapshot keeps it from rendering when nothing moved.\n * @evidence contracts/development/implementation.md#clear-and-simple-structure One read of the store, one input and one output.\n * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Playback frames dispatch nothing; only a seek and the change from playing to stopped edit the request, and the first render, which stops nothing, edits nothing.\n * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per render, one render per moved snapshot.\n * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A view of one snapshot.\n * @evidence contracts/development/implementation.md#bound-retention-and-release-resources React holds one playhead subscription while the readout is mounted and removes it on unmount.\n */\nexport function AutoMovieInspectorTimeReadout(props: {\n /** The playhead shown and sought. */\n playhead: AutoMovieInspectorPlayhead;\n\n /** The subject's frames per second, so the slider steps from frame to frame of its grid, as a capture's seconds do; null before a subject is ready, when the slider steps freely. */\n fps: number | null;\n\n /** Where the sought second goes. */\n dispatch: (action: IAutoMovieInspectorAction) => void;\n}): JSX.Element {\n const snapshot: AutoMovieInspectorPlayhead.ISnapshot = useSyncExternalStore(\n props.playhead.subscribe,\n props.playhead.getSnapshot,\n );\n\n // When playback stops, by a pause or at the end, the stopped second becomes the request's.\n const was: RefObject<boolean> = useRef<boolean>(snapshot.playing);\n const { dispatch } = props;\n useEffect((): void => {\n if (was.current && !snapshot.playing)\n dispatch({ type: \"time\", seconds: snapshot.seconds });\n was.current = snapshot.playing;\n }, [snapshot, dispatch]);\n return (\n <>\n <input\n type=\"range\"\n aria-label=\"Second\"\n aria-valuetext={\n props.fps === null\n ? `${snapshot.seconds.toFixed(2)} seconds`\n : `${snapshot.seconds.toFixed(2)} seconds, frame ${Math.round(snapshot.seconds * props.fps)} of ${Math.round(snapshot.durationSeconds * props.fps)}`\n }\n min={0}\n max={snapshot.durationSeconds}\n step={props.fps === null ? \"any\" : 1 / props.fps}\n value={snapshot.seconds}\n style={{ flex: \"1 1 auto\" }}\n onChange={(event: ChangeEvent<HTMLInputElement>): void => {\n props.playhead.seek(Number(event.target.value));\n props.dispatch({\n type: \"time\",\n seconds: props.playhead.getSnapshot().seconds,\n });\n }}\n />\n <output style={{ fontVariantNumeric: \"tabular-nums\" }}>\n {snapshot.seconds.toFixed(2)} / {snapshot.durationSeconds.toFixed(2)} s\n </output>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAgB,8BAA8B,OAS9B;CACd,MAAM,WAAiD,qBACrD,MAAM,SAAS,WACf,MAAM,SAAS,WACjB;CAGA,MAAM,MAA0B,OAAgB,SAAS,OAAO;CAChE,MAAM,EAAE,aAAa;CACrB,gBAAsB;EACpB,IAAI,IAAI,WAAW,CAAC,SAAS,SAC3B,SAAS;GAAE,MAAM;GAAQ,SAAS,SAAS;EAAQ,CAAC;EACtD,IAAI,UAAU,SAAS;CACzB,GAAG,CAAC,UAAU,QAAQ,CAAC;CACvB,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,SAAD;EACE,MAAK;EACL,cAAW;EACX,kBACE,MAAM,QAAQ,OACV,GAAG,SAAS,QAAQ,QAAQ,CAAC,EAAE,YAC/B,GAAG,SAAS,QAAQ,QAAQ,CAAC,EAAE,kBAAkB,KAAK,MAAM,SAAS,UAAU,MAAM,GAAG,EAAE,MAAM,KAAK,MAAM,SAAS,kBAAkB,MAAM,GAAG;EAErJ,KAAK;EACL,KAAK,SAAS;EACd,MAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI,MAAM;EAC7C,OAAO,SAAS;EAChB,OAAO,EAAE,MAAM,WAAW;EAC1B,WAAW,UAA+C;GACxD,MAAM,SAAS,KAAK,OAAO,MAAM,OAAO,KAAK,CAAC;GAC9C,MAAM,SAAS;IACb,MAAM;IACN,SAAS,MAAM,SAAS,YAAY,CAAC,CAAC;GACxC,CAAC;EACH;CACD,CAAA,GACD,qBAAC,UAAD;EAAQ,OAAO,EAAE,oBAAoB,eAAe;EAApD,UAAA;GACG,SAAS,QAAQ,QAAQ,CAAC;GAAE;GAAI,SAAS,gBAAgB,QAAQ,CAAC;GAAE;EAC/D;CACR,CAAA,CAAA,EAAA,CAAA;AAEN"}
1
+ {"version":3,"file":"AutoMovieInspectorTimeReadout.mjs","names":[],"sources":["../../src/inspector/AutoMovieInspectorTimeReadout.tsx"],"sourcesContent":["import { AutoMovieFrameGrid } from \"@automovie/render\";\nimport {\n type ChangeEvent,\n type JSX,\n type RefObject,\n useEffect,\n useRef,\n useSyncExternalStore,\n} from \"react\";\n\nimport type { AutoMovieInspectorPlayhead } from \"./AutoMovieInspectorPlayhead.js\";\nimport type { IAutoMovieInspectorAction } from \"./IAutoMovieInspectorAction.js\";\n\n/**\n * The playhead's slider and clock, the one component that reads the playhead's second and so the only one a playing frame re-renders; the time panel reads only whether it plays.\n *\n * Moving the slider seeks to a regular frame or the exact end and dispatches the second as a `time` edit. Without a frame rate, the slider seeks directly in seconds. A pause or playback reaching the end also dispatches its second, so the request names the picture left on screen. The slider announces its second and, when available, its frame number.\n *\n * @evidence contracts/development/common.md#meaningful-documentation States what it shows, why it alone reads the playhead's second, when it edits the request and what it announces.\n * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` reads the cached playhead snapshot without tearing. Native range inputs enforce their step grid, so integer positions give every frame and the exact end a valid slider value.\n * @evidence contracts/development/implementation.md#clear-and-simple-structure One store read, one slider that converts its position to seconds on seek, and one clock output.\n * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Playback frames dispatch nothing; only a seek and the change from playing to stopped edit the request, and the first render, which stops nothing, edits nothing.\n * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per render, one render per moved snapshot.\n * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the shared presentation grid and computes its last frame number once per render.\n * @evidence contracts/development/implementation.md#bound-retention-and-release-resources React holds one playhead subscription while the readout is mounted and removes it on unmount.\n */\nexport function AutoMovieInspectorTimeReadout(props: {\n /** The playhead shown and sought. */\n playhead: AutoMovieInspectorPlayhead;\n\n /** The subject's frames per second, so the slider steps from frame to frame of its grid, as a capture's seconds do; null before a subject is ready, when the slider steps freely. */\n fps: number | null;\n\n /** Where the sought second goes. */\n dispatch: (action: IAutoMovieInspectorAction) => void;\n}): JSX.Element {\n const snapshot: AutoMovieInspectorPlayhead.ISnapshot = useSyncExternalStore(\n props.playhead.subscribe,\n props.playhead.getSnapshot,\n );\n\n // When playback stops, by a pause or at the end, the stopped second becomes the request's.\n const was: RefObject<boolean> = useRef<boolean>(snapshot.playing);\n const { dispatch } = props;\n useEffect((): void => {\n if (was.current && !snapshot.playing)\n dispatch({ type: \"time\", seconds: snapshot.seconds });\n was.current = snapshot.playing;\n }, [snapshot, dispatch]);\n\n // Integer slider positions keep the end reachable even between regular frames.\n const { fps }: typeof props = props;\n const { durationSeconds, seconds }: AutoMovieInspectorPlayhead.ISnapshot =\n snapshot;\n const last: number =\n fps === null\n ? durationSeconds\n : AutoMovieFrameGrid.last(durationSeconds, fps);\n const position: number =\n fps === null\n ? seconds\n : AutoMovieFrameGrid.nearest(seconds, durationSeconds, fps, last);\n\n return (\n <>\n <input\n type=\"range\"\n aria-label=\"Second\"\n aria-valuetext={\n fps === null\n ? `${seconds.toFixed(2)} seconds`\n : `${seconds.toFixed(2)} seconds, frame ${position} of ${last}`\n }\n min={0}\n max={last}\n step={fps === null ? \"any\" : 1}\n value={position}\n style={{ flex: \"1 1 auto\" }}\n onChange={(event: ChangeEvent<HTMLInputElement>): void => {\n const value: number = event.currentTarget.valueAsNumber;\n props.playhead.seek(\n fps === null\n ? value\n : AutoMovieFrameGrid.time(value, durationSeconds, fps),\n );\n props.dispatch({\n type: \"time\",\n seconds: props.playhead.getSnapshot().seconds,\n });\n }}\n />\n <output style={{ fontVariantNumeric: \"tabular-nums\" }}>\n {seconds.toFixed(2)} / {durationSeconds.toFixed(2)} s\n </output>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,SAAgB,8BAA8B,OAS9B;CACd,MAAM,WAAiD,qBACrD,MAAM,SAAS,WACf,MAAM,SAAS,WACjB;CAGA,MAAM,MAA0B,OAAgB,SAAS,OAAO;CAChE,MAAM,EAAE,aAAa;CACrB,gBAAsB;EACpB,IAAI,IAAI,WAAW,CAAC,SAAS,SAC3B,SAAS;GAAE,MAAM;GAAQ,SAAS,SAAS;EAAQ,CAAC;EACtD,IAAI,UAAU,SAAS;CACzB,GAAG,CAAC,UAAU,QAAQ,CAAC;CAGvB,MAAM,EAAE,QAAsB;CAC9B,MAAM,EAAE,iBAAiB,YACvB;CACF,MAAM,OACJ,QAAQ,OACJ,kBACA,mBAAmB,KAAK,iBAAiB,GAAG;CAClD,MAAM,WACJ,QAAQ,OACJ,UACA,mBAAmB,QAAQ,SAAS,iBAAiB,KAAK,IAAI;CAEpE,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,SAAD;EACE,MAAK;EACL,cAAW;EACX,kBACE,QAAQ,OACJ,GAAG,QAAQ,QAAQ,CAAC,EAAE,YACtB,GAAG,QAAQ,QAAQ,CAAC,EAAE,kBAAkB,SAAS,MAAM;EAE7D,KAAK;EACL,KAAK;EACL,MAAM,QAAQ,OAAO,QAAQ;EAC7B,OAAO;EACP,OAAO,EAAE,MAAM,WAAW;EAC1B,WAAW,UAA+C;GACxD,MAAM,QAAgB,MAAM,cAAc;GAC1C,MAAM,SAAS,KACb,QAAQ,OACJ,QACA,mBAAmB,KAAK,OAAO,iBAAiB,GAAG,CACzD;GACA,MAAM,SAAS;IACb,MAAM;IACN,SAAS,MAAM,SAAS,YAAY,CAAC,CAAC;GACxC,CAAC;EACH;CACD,CAAA,GACD,qBAAC,UAAD;EAAQ,OAAO,EAAE,oBAAoB,eAAe;EAApD,UAAA;GACG,QAAQ,QAAQ,CAAC;GAAE;GAAI,gBAAgB,QAAQ,CAAC;GAAE;EAC7C;CACR,CAAA,CAAA,EAAA,CAAA;AAEN"}
@@ -2,6 +2,8 @@ import type { AutoMovieInspectorPlayhead } from "./AutoMovieInspectorPlayhead.js
2
2
  /**
3
3
  * The inspector's playback keys, as a video player's: Space and K play or pause, J and L seek one second back and forward, comma and full stop step one frame back and forward with playback paused, Home and End go to the first and last second. K, J and L work in either case.
4
4
  *
5
+ * Frame steps start at the slider's displayed frame and include the exact end of the subject, even when it falls between regular frames.
6
+ *
5
7
  * A key is left to the page, unhandled and moving nothing, when Ctrl, Meta or Alt is held, so the browser's and the system's shortcuts keep working, and when the key's target is or sits inside an element that takes the key itself (a field, a button, a summary, a link, editable text, or a widget by its role), so Space still presses a button and opens a section. Shift is allowed, since it only changes a letter's case.
6
8
  *
7
9
  * A seek or a step returns the second the playhead now shows, which the caller makes the request's `time`, as the slider does; play and pause return null, because a stop already becomes the request's second through the time readout. A key the inspector does not use is not handled either.
@@ -12,11 +14,11 @@ import type { AutoMovieInspectorPlayhead } from "./AutoMovieInspectorPlayhead.js
12
14
  * @returns Whether the key was used, so the caller prevents its default, and the second a seek left the playhead on.
13
15
  *
14
16
  * @evidence contracts/development/common.md#meaningful-documentation States every key, when a key is left to the page and why, what each returns and why play and pause return no second.
15
- * @evidence contracts/development/implementation.md#principled-implementation The keys follow the web's established video-player bindings, every move goes through the playhead's own `play`, `pause` and `seek`, and the interactive target is found with the platform's `Element.closest` over one selector list.
17
+ * @evidence contracts/development/implementation.md#principled-implementation Every move goes through the playhead's own `play`, `pause` and `seek`; a frame step advances the slider's displayed index; the interactive target is found with the platform's `Element.closest` over one selector list.
16
18
  * @evidence contracts/development/implementation.md#clear-and-simple-structure Two early returns, then one table from key to move and one lookup.
17
19
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The playhead clamps every seek to the film, so nothing here restates its bounds; a key is never taken from a control that answers it, so no control loses its own keyboard behaviour.
18
20
  * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per key, besides one `closest` walk up the target's ancestors.
19
- * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A pure dispatch with nothing to reuse.
21
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the same presentation grid as the slider.
20
22
  * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Holds nothing between calls.
21
23
  */
22
24
  export declare function handleAutoMovieInspectorKey(event: {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleAutoMovieInspectorKey = handleAutoMovieInspectorKey;
4
+ const render_1 = require("@automovie/render");
4
5
  /**
5
6
  * The elements that take a key themselves: fields, buttons, disclosure summaries, links, editable text and the widgets that answer Space or arrows by their role.
6
7
  */
@@ -21,6 +22,8 @@ const INTERACTIVE = [
21
22
  /**
22
23
  * The inspector's playback keys, as a video player's: Space and K play or pause, J and L seek one second back and forward, comma and full stop step one frame back and forward with playback paused, Home and End go to the first and last second. K, J and L work in either case.
23
24
  *
25
+ * Frame steps start at the slider's displayed frame and include the exact end of the subject, even when it falls between regular frames.
26
+ *
24
27
  * A key is left to the page, unhandled and moving nothing, when Ctrl, Meta or Alt is held, so the browser's and the system's shortcuts keep working, and when the key's target is or sits inside an element that takes the key itself (a field, a button, a summary, a link, editable text, or a widget by its role), so Space still presses a button and opens a section. Shift is allowed, since it only changes a letter's case.
25
28
  *
26
29
  * A seek or a step returns the second the playhead now shows, which the caller makes the request's `time`, as the slider does; play and pause return null, because a stop already becomes the request's second through the time readout. A key the inspector does not use is not handled either.
@@ -31,11 +34,11 @@ const INTERACTIVE = [
31
34
  * @returns Whether the key was used, so the caller prevents its default, and the second a seek left the playhead on.
32
35
  *
33
36
  * @evidence contracts/development/common.md#meaningful-documentation States every key, when a key is left to the page and why, what each returns and why play and pause return no second.
34
- * @evidence contracts/development/implementation.md#principled-implementation The keys follow the web's established video-player bindings, every move goes through the playhead's own `play`, `pause` and `seek`, and the interactive target is found with the platform's `Element.closest` over one selector list.
37
+ * @evidence contracts/development/implementation.md#principled-implementation Every move goes through the playhead's own `play`, `pause` and `seek`; a frame step advances the slider's displayed index; the interactive target is found with the platform's `Element.closest` over one selector list.
35
38
  * @evidence contracts/development/implementation.md#clear-and-simple-structure Two early returns, then one table from key to move and one lookup.
36
39
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The playhead clamps every seek to the film, so nothing here restates its bounds; a key is never taken from a control that answers it, so no control loses its own keyboard behaviour.
37
40
  * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per key, besides one `closest` walk up the target's ancestors.
38
- * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A pure dispatch with nothing to reuse.
41
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the same presentation grid as the slider.
39
42
  * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Holds nothing between calls.
40
43
  */
41
44
  function handleAutoMovieInspectorKey(event, playhead, fps) {
@@ -44,11 +47,19 @@ function handleAutoMovieInspectorKey(event, playhead, fps) {
44
47
  return { handled: false, seconds: null };
45
48
  if (event.target !== null && event.target.closest(INTERACTIVE) !== null)
46
49
  return { handled: false, seconds: null };
47
- const step = 1 / (fps ?? 24);
48
50
  const seek = (seconds) => {
49
51
  playhead.seek(seconds);
50
52
  return playhead.getSnapshot().seconds;
51
53
  };
54
+ const step = (direction) => {
55
+ playhead.pause();
56
+ const { seconds, durationSeconds } = playhead.getSnapshot();
57
+ if (fps === null)
58
+ return seek(seconds + direction / 24);
59
+ const last = render_1.AutoMovieFrameGrid.last(durationSeconds, fps);
60
+ const frame = render_1.AutoMovieFrameGrid.nearest(seconds, durationSeconds, fps, last);
61
+ return seek(render_1.AutoMovieFrameGrid.time(frame + direction, durationSeconds, fps));
62
+ };
52
63
  const toggle = () => {
53
64
  if (playhead.getSnapshot().playing)
54
65
  playhead.pause();
@@ -64,14 +75,8 @@ function handleAutoMovieInspectorKey(event, playhead, fps) {
64
75
  J: () => seek(playhead.getSnapshot().seconds - 1),
65
76
  l: () => seek(playhead.getSnapshot().seconds + 1),
66
77
  L: () => seek(playhead.getSnapshot().seconds + 1),
67
- ",": () => {
68
- playhead.pause();
69
- return seek(playhead.getSnapshot().seconds - step);
70
- },
71
- ".": () => {
72
- playhead.pause();
73
- return seek(playhead.getSnapshot().seconds + step);
74
- },
78
+ ",": () => step(-1),
79
+ ".": () => step(1),
75
80
  Home: () => seek(0),
76
81
  End: () => seek(playhead.getSnapshot().durationSeconds),
77
82
  };
@@ -1 +1 @@
1
- {"version":3,"file":"handleAutoMovieInspectorKey.js","sourceRoot":"","sources":["../../src/inspector/handleAutoMovieInspectorKey.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAM,WAAW,GAAW;IAC1B,OAAO;IACP,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,SAAS;IACT,SAAS;IACT,kDAAkD;IAClD,eAAe;IACf,YAAY;IACZ,iBAAiB;IACjB,eAAe;IACf,eAAe;CAChB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qCACE,KAMC,EACD,QAAoC,EACpC,GAAkB;IAElB,sEAAsE;IACtE,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM;QAChD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI;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,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QACrD,CAAC;QACD,IAAI,EAAE,GAAW,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3B,GAAG,EAAE,GAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,eAAe,CAAC;KAChE,CAAC;IACF,MAAM,IAAI,GAAsC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,IAAI,KAAK,SAAS;QACvB,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE;QACnC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;AACzC,CAAC"}
1
+ {"version":3,"file":"handleAutoMovieInspectorKey.js","sourceRoot":"","sources":["../../src/inspector/handleAutoMovieInspectorKey.ts"],"names":[],"mappings":";;;AAAA,8CAAuD;AAIvD;;GAEG;AACH,MAAM,WAAW,GAAW;IAC1B,OAAO;IACP,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,SAAS;IACT,SAAS;IACT,kDAAkD;IAClD,eAAe;IACf,YAAY;IACZ,iBAAiB;IACjB,eAAe;IACf,eAAe;CAChB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qCACE,KAMC,EACD,QAAoC,EACpC,GAAkB;IAElB,sEAAsE;IACtE,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM;QAChD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC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,CAAC,EAAE,GAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,GAAG,CAAC,CAAC;QACzD,CAAC,EAAE,GAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,GAAG,CAAC,CAAC;QACzD,CAAC,EAAE,GAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,GAAG,CAAC,CAAC;QACzD,GAAG,EAAE,GAAW,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,GAAG,EAAE,GAAW,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1B,IAAI,EAAE,GAAW,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3B,GAAG,EAAE,GAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,eAAe,CAAC;KAChE,CAAC;IACF,MAAM,IAAI,GAAsC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,IAAI,KAAK,SAAS;QACvB,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE;QACnC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;AACzC,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { AutoMovieFrameGrid } from "@automovie/render";
1
2
  // src/inspector/handleAutoMovieInspectorKey.ts
2
3
  /**
3
4
  * The elements that take a key themselves: fields, buttons, disclosure summaries, links, editable text and the widgets that answer Space or arrows by their role.
@@ -19,6 +20,8 @@ const INTERACTIVE = [
19
20
  /**
20
21
  * The inspector's playback keys, as a video player's: Space and K play or pause, J and L seek one second back and forward, comma and full stop step one frame back and forward with playback paused, Home and End go to the first and last second. K, J and L work in either case.
21
22
  *
23
+ * Frame steps start at the slider's displayed frame and include the exact end of the subject, even when it falls between regular frames.
24
+ *
22
25
  * A key is left to the page, unhandled and moving nothing, when Ctrl, Meta or Alt is held, so the browser's and the system's shortcuts keep working, and when the key's target is or sits inside an element that takes the key itself (a field, a button, a summary, a link, editable text, or a widget by its role), so Space still presses a button and opens a section. Shift is allowed, since it only changes a letter's case.
23
26
  *
24
27
  * A seek or a step returns the second the playhead now shows, which the caller makes the request's `time`, as the slider does; play and pause return null, because a stop already becomes the request's second through the time readout. A key the inspector does not use is not handled either.
@@ -29,11 +32,11 @@ const INTERACTIVE = [
29
32
  * @returns Whether the key was used, so the caller prevents its default, and the second a seek left the playhead on.
30
33
  *
31
34
  * @evidence contracts/development/common.md#meaningful-documentation States every key, when a key is left to the page and why, what each returns and why play and pause return no second.
32
- * @evidence contracts/development/implementation.md#principled-implementation The keys follow the web's established video-player bindings, every move goes through the playhead's own `play`, `pause` and `seek`, and the interactive target is found with the platform's `Element.closest` over one selector list.
35
+ * @evidence contracts/development/implementation.md#principled-implementation Every move goes through the playhead's own `play`, `pause` and `seek`; a frame step advances the slider's displayed index; the interactive target is found with the platform's `Element.closest` over one selector list.
33
36
  * @evidence contracts/development/implementation.md#clear-and-simple-structure Two early returns, then one table from key to move and one lookup.
34
37
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The playhead clamps every seek to the film, so nothing here restates its bounds; a key is never taken from a control that answers it, so no control loses its own keyboard behaviour.
35
38
  * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per key, besides one `closest` walk up the target's ancestors.
36
- * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A pure dispatch with nothing to reuse.
39
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the same presentation grid as the slider.
37
40
  * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Holds nothing between calls.
38
41
  */
39
42
  function handleAutoMovieInspectorKey(event, playhead, fps) {
@@ -45,11 +48,18 @@ function handleAutoMovieInspectorKey(event, playhead, fps) {
45
48
  handled: false,
46
49
  seconds: null
47
50
  };
48
- const step = 1 / (fps ?? 24);
49
51
  const seek = (seconds) => {
50
52
  playhead.seek(seconds);
51
53
  return playhead.getSnapshot().seconds;
52
54
  };
55
+ const step = (direction) => {
56
+ playhead.pause();
57
+ const { seconds, durationSeconds } = playhead.getSnapshot();
58
+ if (fps === null) return seek(seconds + direction / 24);
59
+ const last = AutoMovieFrameGrid.last(durationSeconds, fps);
60
+ const frame = AutoMovieFrameGrid.nearest(seconds, durationSeconds, fps, last);
61
+ return seek(AutoMovieFrameGrid.time(frame + direction, durationSeconds, fps));
62
+ };
53
63
  const toggle = () => {
54
64
  if (playhead.getSnapshot().playing) playhead.pause();
55
65
  else playhead.play();
@@ -63,14 +73,8 @@ function handleAutoMovieInspectorKey(event, playhead, fps) {
63
73
  J: () => seek(playhead.getSnapshot().seconds - 1),
64
74
  l: () => seek(playhead.getSnapshot().seconds + 1),
65
75
  L: () => seek(playhead.getSnapshot().seconds + 1),
66
- ",": () => {
67
- playhead.pause();
68
- return seek(playhead.getSnapshot().seconds - step);
69
- },
70
- ".": () => {
71
- playhead.pause();
72
- return seek(playhead.getSnapshot().seconds + step);
73
- },
76
+ ",": () => step(-1),
77
+ ".": () => step(1),
74
78
  Home: () => seek(0),
75
79
  End: () => seek(playhead.getSnapshot().durationSeconds)
76
80
  }[event.key];
@@ -1 +1 @@
1
- {"version":3,"file":"handleAutoMovieInspectorKey.mjs","names":[],"sources":["../../src/inspector/handleAutoMovieInspectorKey.ts"],"sourcesContent":["import type { AutoMovieInspectorPlayhead } from \"./AutoMovieInspectorPlayhead.js\";\n\n/**\n * The elements that take a key themselves: fields, buttons, disclosure summaries, links, editable text and the widgets that answer Space or arrows by their role.\n */\nconst INTERACTIVE: string = [\n \"input\",\n \"select\",\n \"textarea\",\n \"button\",\n \"summary\",\n \"a[href]\",\n '[contenteditable]:not([contenteditable=\"false\"])',\n \"[role=button]\",\n \"[role=tab]\",\n \"[role=checkbox]\",\n \"[role=slider]\",\n \"[role=switch]\",\n].join(\", \");\n\n/**\n * The inspector's playback keys, as a video player's: Space and K play or pause, J and L seek one second back and forward, comma and full stop step one frame back and forward with playback paused, Home and End go to the first and last second. K, J and L work in either case.\n *\n * A key is left to the page, unhandled and moving nothing, when Ctrl, Meta or Alt is held, so the browser's and the system's shortcuts keep working, and when the key's target is or sits inside an element that takes the key itself (a field, a button, a summary, a link, editable text, or a widget by its role), so Space still presses a button and opens a section. Shift is allowed, since it only changes a letter's case.\n *\n * A seek or a step returns the second the playhead now shows, which the caller makes the request's `time`, as the slider does; play and pause return null, because a stop already becomes the request's second through the time readout. A key the inspector does not use is not handled either.\n *\n * @param event The pressed key's `KeyboardEvent` members the decision reads; `target` is the element the key went to, or null when it is not an element.\n * @param playhead The playhead the keys drive.\n * @param fps The subject's frames per second, the step of comma and full stop; null before a subject is ready, when they step a twenty-fourth of a second.\n * @returns Whether the key was used, so the caller prevents its default, and the second a seek left the playhead on.\n *\n * @evidence contracts/development/common.md#meaningful-documentation States every key, when a key is left to the page and why, what each returns and why play and pause return no second.\n * @evidence contracts/development/implementation.md#principled-implementation The keys follow the web's established video-player bindings, every move goes through the playhead's own `play`, `pause` and `seek`, and the interactive target is found with the platform's `Element.closest` over one selector list.\n * @evidence contracts/development/implementation.md#clear-and-simple-structure Two early returns, then one table from key to move and one lookup.\n * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The playhead clamps every seek to the film, so nothing here restates its bounds; a key is never taken from a control that answers it, so no control loses its own keyboard behaviour.\n * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per key, besides one `closest` walk up the target's ancestors.\n * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A pure dispatch with nothing to reuse.\n * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Holds nothing between calls.\n */\nexport function handleAutoMovieInspectorKey(\n event: {\n key: string;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n target: { closest(selectors: string): unknown } | null;\n },\n playhead: AutoMovieInspectorPlayhead,\n fps: number | null,\n): { handled: boolean; seconds: number | null } {\n // A shortcut, or a key a control answers itself, stays with the page.\n if (event.ctrlKey || event.metaKey || event.altKey)\n return { handled: false, seconds: null };\n if (event.target !== null && event.target.closest(INTERACTIVE) !== null)\n return { handled: false, seconds: null };\n\n const step: number = 1 / (fps ?? 24);\n const seek: (seconds: number) => number = (seconds: number): number => {\n playhead.seek(seconds);\n return playhead.getSnapshot().seconds;\n };\n const toggle: () => null = (): null => {\n if (playhead.getSnapshot().playing) playhead.pause();\n else playhead.play();\n return null;\n };\n const moves: Readonly<Record<string, () => number | null>> = {\n \" \": toggle,\n k: toggle,\n K: toggle,\n j: (): number => seek(playhead.getSnapshot().seconds - 1),\n J: (): number => seek(playhead.getSnapshot().seconds - 1),\n l: (): number => seek(playhead.getSnapshot().seconds + 1),\n L: (): number => seek(playhead.getSnapshot().seconds + 1),\n \",\": (): number => {\n playhead.pause();\n return seek(playhead.getSnapshot().seconds - step);\n },\n \".\": (): number => {\n playhead.pause();\n return seek(playhead.getSnapshot().seconds + step);\n },\n Home: (): number => seek(0),\n End: (): number => seek(playhead.getSnapshot().durationSeconds),\n };\n const move: (() => number | null) | undefined = moves[event.key];\n return move === undefined\n ? { handled: false, seconds: null }\n : { handled: true, seconds: move() };\n}\n"],"mappings":";;;;AAKA,MAAM,cAAsB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;AAsBX,SAAgB,4BACd,OAOA,UACA,KAC8C;CAE9C,IAAI,MAAM,WAAW,MAAM,WAAW,MAAM,QAC1C,OAAO;EAAE,SAAS;EAAO,SAAS;CAAK;CACzC,IAAI,MAAM,WAAW,QAAQ,MAAM,OAAO,QAAQ,WAAW,MAAM,MACjE,OAAO;EAAE,SAAS;EAAO,SAAS;CAAK;CAEzC,MAAM,OAAe,KAAK,OAAO;CACjC,MAAM,QAAqC,YAA4B;EACrE,SAAS,KAAK,OAAO;EACrB,OAAO,SAAS,YAAY,CAAC,CAAC;CAChC;CACA,MAAM,eAAiC;EACrC,IAAI,SAAS,YAAY,CAAC,CAAC,SAAS,SAAS,MAAM;OAC9C,SAAS,KAAK;EACnB,OAAO;CACT;CAoBA,MAAM,OAA0C;EAlB9C,KAAK;EACL,GAAG;EACH,GAAG;EACH,SAAiB,KAAK,SAAS,YAAY,CAAC,CAAC,UAAU,CAAC;EACxD,SAAiB,KAAK,SAAS,YAAY,CAAC,CAAC,UAAU,CAAC;EACxD,SAAiB,KAAK,SAAS,YAAY,CAAC,CAAC,UAAU,CAAC;EACxD,SAAiB,KAAK,SAAS,YAAY,CAAC,CAAC,UAAU,CAAC;EACxD,WAAmB;GACjB,SAAS,MAAM;GACf,OAAO,KAAK,SAAS,YAAY,CAAC,CAAC,UAAU,IAAI;EACnD;EACA,WAAmB;GACjB,SAAS,MAAM;GACf,OAAO,KAAK,SAAS,YAAY,CAAC,CAAC,UAAU,IAAI;EACnD;EACA,YAAoB,KAAK,CAAC;EAC1B,WAAmB,KAAK,SAAS,YAAY,CAAC,CAAC,eAAe;CAEZ,EAAE,MAAM;CAC5D,OAAO,SAAS,KAAA,IACZ;EAAE,SAAS;EAAO,SAAS;CAAK,IAChC;EAAE,SAAS;EAAM,SAAS,KAAK;CAAE;AACvC"}
1
+ {"version":3,"file":"handleAutoMovieInspectorKey.mjs","names":[],"sources":["../../src/inspector/handleAutoMovieInspectorKey.ts"],"sourcesContent":["import { AutoMovieFrameGrid } from \"@automovie/render\";\n\nimport type { AutoMovieInspectorPlayhead } from \"./AutoMovieInspectorPlayhead.js\";\n\n/**\n * The elements that take a key themselves: fields, buttons, disclosure summaries, links, editable text and the widgets that answer Space or arrows by their role.\n */\nconst INTERACTIVE: string = [\n \"input\",\n \"select\",\n \"textarea\",\n \"button\",\n \"summary\",\n \"a[href]\",\n '[contenteditable]:not([contenteditable=\"false\"])',\n \"[role=button]\",\n \"[role=tab]\",\n \"[role=checkbox]\",\n \"[role=slider]\",\n \"[role=switch]\",\n].join(\", \");\n\n/**\n * The inspector's playback keys, as a video player's: Space and K play or pause, J and L seek one second back and forward, comma and full stop step one frame back and forward with playback paused, Home and End go to the first and last second. K, J and L work in either case.\n *\n * Frame steps start at the slider's displayed frame and include the exact end of the subject, even when it falls between regular frames.\n *\n * A key is left to the page, unhandled and moving nothing, when Ctrl, Meta or Alt is held, so the browser's and the system's shortcuts keep working, and when the key's target is or sits inside an element that takes the key itself (a field, a button, a summary, a link, editable text, or a widget by its role), so Space still presses a button and opens a section. Shift is allowed, since it only changes a letter's case.\n *\n * A seek or a step returns the second the playhead now shows, which the caller makes the request's `time`, as the slider does; play and pause return null, because a stop already becomes the request's second through the time readout. A key the inspector does not use is not handled either.\n *\n * @param event The pressed key's `KeyboardEvent` members the decision reads; `target` is the element the key went to, or null when it is not an element.\n * @param playhead The playhead the keys drive.\n * @param fps The subject's frames per second, the step of comma and full stop; null before a subject is ready, when they step a twenty-fourth of a second.\n * @returns Whether the key was used, so the caller prevents its default, and the second a seek left the playhead on.\n *\n * @evidence contracts/development/common.md#meaningful-documentation States every key, when a key is left to the page and why, what each returns and why play and pause return no second.\n * @evidence contracts/development/implementation.md#principled-implementation Every move goes through the playhead's own `play`, `pause` and `seek`; a frame step advances the slider's displayed index; the interactive target is found with the platform's `Element.closest` over one selector list.\n * @evidence contracts/development/implementation.md#clear-and-simple-structure Two early returns, then one table from key to move and one lookup.\n * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The playhead clamps every seek to the film, so nothing here restates its bounds; a key is never taken from a control that answers it, so no control loses its own keyboard behaviour.\n * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per key, besides one `closest` walk up the target's ancestors.\n * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the same presentation grid as the slider.\n * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Holds nothing between calls.\n */\nexport function handleAutoMovieInspectorKey(\n event: {\n key: string;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n target: { closest(selectors: string): unknown } | null;\n },\n playhead: AutoMovieInspectorPlayhead,\n fps: number | null,\n): { handled: boolean; seconds: number | null } {\n // A shortcut, or a key a control answers itself, stays with the page.\n if (event.ctrlKey || event.metaKey || event.altKey)\n return { handled: false, seconds: null };\n if (event.target !== null && event.target.closest(INTERACTIVE) !== null)\n return { handled: false, seconds: null };\n\n const seek: (seconds: number) => number = (seconds: number): number => {\n playhead.seek(seconds);\n return playhead.getSnapshot().seconds;\n };\n const step: (direction: -1 | 1) => number = (direction: -1 | 1): number => {\n playhead.pause();\n const { seconds, durationSeconds }: AutoMovieInspectorPlayhead.ISnapshot =\n playhead.getSnapshot();\n if (fps === null) return seek(seconds + direction / 24);\n\n const last: number = AutoMovieFrameGrid.last(durationSeconds, fps);\n const frame: number = AutoMovieFrameGrid.nearest(\n seconds,\n durationSeconds,\n fps,\n last,\n );\n return seek(\n AutoMovieFrameGrid.time(frame + direction, durationSeconds, fps),\n );\n };\n const toggle: () => null = (): null => {\n if (playhead.getSnapshot().playing) playhead.pause();\n else playhead.play();\n return null;\n };\n const moves: Readonly<Record<string, () => number | null>> = {\n \" \": toggle,\n k: toggle,\n K: toggle,\n j: (): number => seek(playhead.getSnapshot().seconds - 1),\n J: (): number => seek(playhead.getSnapshot().seconds - 1),\n l: (): number => seek(playhead.getSnapshot().seconds + 1),\n L: (): number => seek(playhead.getSnapshot().seconds + 1),\n \",\": (): number => step(-1),\n \".\": (): number => step(1),\n Home: (): number => seek(0),\n End: (): number => seek(playhead.getSnapshot().durationSeconds),\n };\n const move: (() => number | null) | undefined = moves[event.key];\n return move === undefined\n ? { handled: false, seconds: null }\n : { handled: true, seconds: move() };\n}\n"],"mappings":";;;;;AAOA,MAAM,cAAsB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;AAwBX,SAAgB,4BACd,OAOA,UACA,KAC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;AACvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automovie/viewer",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "automovie viewer: the interactive display, a React inspector and an imperative mount over the render package's three.js scene (not an editor)",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -29,7 +29,7 @@
29
29
  "url": "https://github.com/samchon/automovie"
30
30
  },
31
31
  "dependencies": {
32
- "@automovie/render": "^0.3.1",
32
+ "@automovie/render": "^0.3.2",
33
33
  "three": "^0.186.0"
34
34
  },
35
35
  "peerDependencies": {
@@ -1,3 +1,4 @@
1
+ import { AutoMovieFrameGrid } from "@automovie/render";
1
2
  import {
2
3
  type ChangeEvent,
3
4
  type JSX,
@@ -13,14 +14,14 @@ import type { IAutoMovieInspectorAction } from "./IAutoMovieInspectorAction.js";
13
14
  /**
14
15
  * The playhead's slider and clock, the one component that reads the playhead's second and so the only one a playing frame re-renders; the time panel reads only whether it plays.
15
16
  *
16
- * Dragging the slider, which steps by one frame of the subject's grid, seeks the playhead and dispatches the second as a `time` edit, and so does playback stopping, by a pause or at the end, so the request names the picture left on screen. The slider gives its second and frame as its value text, which a screen reader announces in place of the raw number.
17
+ * Moving the slider seeks to a regular frame or the exact end and dispatches the second as a `time` edit. Without a frame rate, the slider seeks directly in seconds. A pause or playback reaching the end also dispatches its second, so the request names the picture left on screen. The slider announces its second and, when available, its frame number.
17
18
  *
18
19
  * @evidence contracts/development/common.md#meaningful-documentation States what it shows, why it alone reads the playhead's second, when it edits the request and what it announces.
19
- * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` is React's contract for reading an external store without tearing; the playhead's cached snapshot keeps it from rendering when nothing moved.
20
- * @evidence contracts/development/implementation.md#clear-and-simple-structure One read of the store, one input and one output.
20
+ * @evidence contracts/development/implementation.md#principled-implementation `useSyncExternalStore` reads the cached playhead snapshot without tearing. Native range inputs enforce their step grid, so integer positions give every frame and the exact end a valid slider value.
21
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One store read, one slider that converts its position to seconds on seek, and one clock output.
21
22
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Playback frames dispatch nothing; only a seek and the change from playing to stopped edit the request, and the first render, which stops nothing, edits nothing.
22
23
  * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per render, one render per moved snapshot.
23
- * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A view of one snapshot.
24
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the shared presentation grid and computes its last frame number once per render.
24
25
  * @evidence contracts/development/implementation.md#bound-retention-and-release-resources React holds one playhead subscription while the readout is mounted and removes it on unmount.
25
26
  */
26
27
  export function AutoMovieInspectorTimeReadout(props: {
@@ -46,23 +47,42 @@ export function AutoMovieInspectorTimeReadout(props: {
46
47
  dispatch({ type: "time", seconds: snapshot.seconds });
47
48
  was.current = snapshot.playing;
48
49
  }, [snapshot, dispatch]);
50
+
51
+ // Integer slider positions keep the end reachable even between regular frames.
52
+ const { fps }: typeof props = props;
53
+ const { durationSeconds, seconds }: AutoMovieInspectorPlayhead.ISnapshot =
54
+ snapshot;
55
+ const last: number =
56
+ fps === null
57
+ ? durationSeconds
58
+ : AutoMovieFrameGrid.last(durationSeconds, fps);
59
+ const position: number =
60
+ fps === null
61
+ ? seconds
62
+ : AutoMovieFrameGrid.nearest(seconds, durationSeconds, fps, last);
63
+
49
64
  return (
50
65
  <>
51
66
  <input
52
67
  type="range"
53
68
  aria-label="Second"
54
69
  aria-valuetext={
55
- props.fps === null
56
- ? `${snapshot.seconds.toFixed(2)} seconds`
57
- : `${snapshot.seconds.toFixed(2)} seconds, frame ${Math.round(snapshot.seconds * props.fps)} of ${Math.round(snapshot.durationSeconds * props.fps)}`
70
+ fps === null
71
+ ? `${seconds.toFixed(2)} seconds`
72
+ : `${seconds.toFixed(2)} seconds, frame ${position} of ${last}`
58
73
  }
59
74
  min={0}
60
- max={snapshot.durationSeconds}
61
- step={props.fps === null ? "any" : 1 / props.fps}
62
- value={snapshot.seconds}
75
+ max={last}
76
+ step={fps === null ? "any" : 1}
77
+ value={position}
63
78
  style={{ flex: "1 1 auto" }}
64
79
  onChange={(event: ChangeEvent<HTMLInputElement>): void => {
65
- props.playhead.seek(Number(event.target.value));
80
+ const value: number = event.currentTarget.valueAsNumber;
81
+ props.playhead.seek(
82
+ fps === null
83
+ ? value
84
+ : AutoMovieFrameGrid.time(value, durationSeconds, fps),
85
+ );
66
86
  props.dispatch({
67
87
  type: "time",
68
88
  seconds: props.playhead.getSnapshot().seconds,
@@ -70,7 +90,7 @@ export function AutoMovieInspectorTimeReadout(props: {
70
90
  }}
71
91
  />
72
92
  <output style={{ fontVariantNumeric: "tabular-nums" }}>
73
- {snapshot.seconds.toFixed(2)} / {snapshot.durationSeconds.toFixed(2)} s
93
+ {seconds.toFixed(2)} / {durationSeconds.toFixed(2)} s
74
94
  </output>
75
95
  </>
76
96
  );
@@ -1,3 +1,5 @@
1
+ import { AutoMovieFrameGrid } from "@automovie/render";
2
+
1
3
  import type { AutoMovieInspectorPlayhead } from "./AutoMovieInspectorPlayhead.js";
2
4
 
3
5
  /**
@@ -21,6 +23,8 @@ const INTERACTIVE: string = [
21
23
  /**
22
24
  * The inspector's playback keys, as a video player's: Space and K play or pause, J and L seek one second back and forward, comma and full stop step one frame back and forward with playback paused, Home and End go to the first and last second. K, J and L work in either case.
23
25
  *
26
+ * Frame steps start at the slider's displayed frame and include the exact end of the subject, even when it falls between regular frames.
27
+ *
24
28
  * A key is left to the page, unhandled and moving nothing, when Ctrl, Meta or Alt is held, so the browser's and the system's shortcuts keep working, and when the key's target is or sits inside an element that takes the key itself (a field, a button, a summary, a link, editable text, or a widget by its role), so Space still presses a button and opens a section. Shift is allowed, since it only changes a letter's case.
25
29
  *
26
30
  * A seek or a step returns the second the playhead now shows, which the caller makes the request's `time`, as the slider does; play and pause return null, because a stop already becomes the request's second through the time readout. A key the inspector does not use is not handled either.
@@ -31,11 +35,11 @@ const INTERACTIVE: string = [
31
35
  * @returns Whether the key was used, so the caller prevents its default, and the second a seek left the playhead on.
32
36
  *
33
37
  * @evidence contracts/development/common.md#meaningful-documentation States every key, when a key is left to the page and why, what each returns and why play and pause return no second.
34
- * @evidence contracts/development/implementation.md#principled-implementation The keys follow the web's established video-player bindings, every move goes through the playhead's own `play`, `pause` and `seek`, and the interactive target is found with the platform's `Element.closest` over one selector list.
38
+ * @evidence contracts/development/implementation.md#principled-implementation Every move goes through the playhead's own `play`, `pause` and `seek`; a frame step advances the slider's displayed index; the interactive target is found with the platform's `Element.closest` over one selector list.
35
39
  * @evidence contracts/development/implementation.md#clear-and-simple-structure Two early returns, then one table from key to move and one lookup.
36
40
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The playhead clamps every seek to the film, so nothing here restates its bounds; a key is never taken from a control that answers it, so no control loses its own keyboard behaviour.
37
41
  * @evidence contracts/development/implementation.md#efficient-algorithms Constant work per key, besides one `closest` walk up the target's ancestors.
38
- * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A pure dispatch with nothing to reuse.
42
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the same presentation grid as the slider.
39
43
  * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Holds nothing between calls.
40
44
  */
41
45
  export function handleAutoMovieInspectorKey(
@@ -55,11 +59,27 @@ export function handleAutoMovieInspectorKey(
55
59
  if (event.target !== null && event.target.closest(INTERACTIVE) !== null)
56
60
  return { handled: false, seconds: null };
57
61
 
58
- const step: number = 1 / (fps ?? 24);
59
62
  const seek: (seconds: number) => number = (seconds: number): number => {
60
63
  playhead.seek(seconds);
61
64
  return playhead.getSnapshot().seconds;
62
65
  };
66
+ const step: (direction: -1 | 1) => number = (direction: -1 | 1): number => {
67
+ playhead.pause();
68
+ const { seconds, durationSeconds }: AutoMovieInspectorPlayhead.ISnapshot =
69
+ playhead.getSnapshot();
70
+ if (fps === null) return seek(seconds + direction / 24);
71
+
72
+ const last: number = AutoMovieFrameGrid.last(durationSeconds, fps);
73
+ const frame: number = AutoMovieFrameGrid.nearest(
74
+ seconds,
75
+ durationSeconds,
76
+ fps,
77
+ last,
78
+ );
79
+ return seek(
80
+ AutoMovieFrameGrid.time(frame + direction, durationSeconds, fps),
81
+ );
82
+ };
63
83
  const toggle: () => null = (): null => {
64
84
  if (playhead.getSnapshot().playing) playhead.pause();
65
85
  else playhead.play();
@@ -73,14 +93,8 @@ export function handleAutoMovieInspectorKey(
73
93
  J: (): number => seek(playhead.getSnapshot().seconds - 1),
74
94
  l: (): number => seek(playhead.getSnapshot().seconds + 1),
75
95
  L: (): number => seek(playhead.getSnapshot().seconds + 1),
76
- ",": (): number => {
77
- playhead.pause();
78
- return seek(playhead.getSnapshot().seconds - step);
79
- },
80
- ".": (): number => {
81
- playhead.pause();
82
- return seek(playhead.getSnapshot().seconds + step);
83
- },
96
+ ",": (): number => step(-1),
97
+ ".": (): number => step(1),
84
98
  Home: (): number => seek(0),
85
99
  End: (): number => seek(playhead.getSnapshot().durationSeconds),
86
100
  };