@mizchi/vlmkit-core 0.23.2 → 0.28.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.
Files changed (112) hide show
  1. package/dist/a11y-semantic.d.mts +6 -10
  2. package/dist/a11y-semantic.mjs +3 -4
  3. package/dist/animated-image.d.mts +27 -0
  4. package/dist/animated-image.mjs +112 -0
  5. package/dist/apng.d.mts +5 -9
  6. package/dist/apng.mjs +6 -7
  7. package/dist/arg-reader.d.mts +9 -12
  8. package/dist/arg-reader.mjs +1 -2
  9. package/dist/auth-state.d.mts +6 -9
  10. package/dist/auth-state.mjs +1 -2
  11. package/dist/authored-style-capture.d.mts +7 -10
  12. package/dist/authored-style-capture.mjs +1 -2
  13. package/dist/authored-style-diff.d.mts +8 -12
  14. package/dist/authored-style-diff.mjs +1 -2
  15. package/dist/bitmap-font.d.mts +7 -10
  16. package/dist/bitmap-font.mjs +1 -2
  17. package/dist/browser-launch.d.mts +7 -11
  18. package/dist/browser-launch.mjs +1 -2
  19. package/dist/cli-args.d.mts +8 -11
  20. package/dist/cli-args.mjs +1 -2
  21. package/dist/cli-error.d.mts +10 -13
  22. package/dist/cli-error.mjs +2 -3
  23. package/dist/computed-style-capture.d.mts +20 -23
  24. package/dist/computed-style-capture.mjs +4 -5
  25. package/dist/computed-style-diff.d.mts +8 -11
  26. package/dist/computed-style-diff.mjs +2 -3
  27. package/dist/diff-regions.d.mts +3 -7
  28. package/dist/diff-regions.mjs +1 -2
  29. package/dist/dom-equivalence.d.mts +5 -8
  30. package/dist/dom-equivalence.mjs +1 -2
  31. package/dist/dom-position-styles.d.mts +14 -15
  32. package/dist/dom-position-styles.mjs +4 -5
  33. package/dist/element-compare.d.mts +8 -9
  34. package/dist/element-compare.mjs +5 -5
  35. package/dist/filmstrip.d.mts +60 -9
  36. package/dist/filmstrip.mjs +83 -12
  37. package/dist/gate-config.d.mts +18 -22
  38. package/dist/gate-config.mjs +8 -4
  39. package/dist/gate-exit.d.mts +5 -8
  40. package/dist/gate-exit.mjs +1 -2
  41. package/dist/gif.d.mts +41 -0
  42. package/dist/gif.mjs +73 -0
  43. package/dist/heatmap-regions.d.mts +4 -7
  44. package/dist/heatmap-regions.mjs +1 -2
  45. package/dist/heatmap.d.mts +21 -17
  46. package/dist/heatmap.mjs +23 -11
  47. package/dist/image-resize.d.mts +9 -12
  48. package/dist/image-resize.mjs +1 -2
  49. package/dist/image-timing.d.mts +57 -0
  50. package/dist/image-timing.mjs +166 -0
  51. package/dist/index.d.mts +14 -14
  52. package/dist/index.mjs +11 -11
  53. package/dist/mask.d.mts +5 -9
  54. package/dist/mask.mjs +1 -2
  55. package/dist/motion-spec.d.mts +97 -0
  56. package/dist/motion-spec.mjs +145 -0
  57. package/dist/navigation-redirect.d.mts +1 -4
  58. package/dist/navigation-redirect.mjs +1 -2
  59. package/dist/page-load.d.mts +40 -16
  60. package/dist/page-load.mjs +34 -5
  61. package/dist/page-open.d.mts +15 -15
  62. package/dist/page-open.mjs +4 -3
  63. package/dist/plugin/args.d.mts +16 -12
  64. package/dist/plugin/args.mjs +15 -4
  65. package/dist/plugin/browser.d.mts +3 -3
  66. package/dist/plugin/browser.mjs +2 -2
  67. package/dist/plugin/cli-entry.d.mts +1 -4
  68. package/dist/plugin/cli-entry.mjs +1 -2
  69. package/dist/plugin/contract.d.mts +17 -21
  70. package/dist/plugin/contract.mjs +1 -2
  71. package/dist/plugin/index.d.mts +6 -9
  72. package/dist/plugin/index.mjs +7 -8
  73. package/dist/plugin/load.d.mts +7 -11
  74. package/dist/plugin/load.mjs +1 -2
  75. package/dist/plugin/registry.d.mts +8 -12
  76. package/dist/plugin/registry.mjs +1 -2
  77. package/dist/plugin/rule-prose.d.mts +4 -8
  78. package/dist/plugin/rule-prose.mjs +1 -2
  79. package/dist/plugin/rule-tier.d.mts +7 -11
  80. package/dist/plugin/rule-tier.mjs +1 -2
  81. package/dist/plugin/rules.d.mts +18 -22
  82. package/dist/plugin/rules.mjs +1 -2
  83. package/dist/plugin/runner.d.mts +18 -21
  84. package/dist/plugin/runner.mjs +55 -6
  85. package/dist/png-decode.d.mts +17 -0
  86. package/dist/png-decode.mjs +160 -0
  87. package/dist/png-utils.d.mts +7 -10
  88. package/dist/png-utils.mjs +3 -3
  89. package/dist/project-config.d.mts +7 -10
  90. package/dist/project-config.mjs +1 -2
  91. package/dist/rect-overlap.d.mts +3 -6
  92. package/dist/rect-overlap.mjs +1 -2
  93. package/dist/region-shift.d.mts +3 -6
  94. package/dist/region-shift.mjs +1 -2
  95. package/dist/run-ledger.d.mts +10 -13
  96. package/dist/run-ledger.mjs +4 -4
  97. package/dist/stable-selector.d.mts +1 -4
  98. package/dist/stable-selector.mjs +1 -2
  99. package/dist/terminal-colors.d.mts +8 -11
  100. package/dist/terminal-colors.mjs +1 -2
  101. package/dist/text-rows.d.mts +10 -13
  102. package/dist/text-rows.mjs +1 -2
  103. package/dist/types.d.mts +87 -64
  104. package/dist/version.d.mts +1 -4
  105. package/dist/version.mjs +2 -3
  106. package/dist/video-decode.d.mts +144 -0
  107. package/dist/video-decode.mjs +939 -0
  108. package/dist/video-frames.d.mts +310 -0
  109. package/dist/video-frames.mjs +576 -0
  110. package/dist/webp.d.mts +7 -11
  111. package/dist/webp.mjs +3 -3
  112. package/package.json +7 -7
@@ -1,7 +1,5 @@
1
1
  import { PngData } from "./png-utils.mjs";
2
-
3
- //#region src/filmstrip.d.ts
4
- interface FilmstripOptions {
2
+ export interface FilmstripOptions {
5
3
  /**
6
4
  * Cells per row. Omit for a single row (a filmstrip); set it to wrap into a
7
5
  * grid (a contact sheet).
@@ -43,12 +41,18 @@ interface FilmstripOptions {
43
41
  * enough for one would dominate a sheet of 200px cells.
44
42
  */
45
43
  rowLabels?: readonly string[];
44
+ /**
45
+ * One label per cell, in input order, drawn in a band above that cell (below its row's label).
46
+ * For a sheet whose cells are not one instant per column — a storyboard row of one event's
47
+ * keyframes — each cell says its own time. Empty strings leave a cell unlabelled.
48
+ */
49
+ cellLabels?: readonly string[];
46
50
  /** Integer pixel size of one font unit. Default 2, i.e. 10x14 glyphs. */
47
51
  labelScale?: number;
48
52
  /** Label ink, RGB. Default near-white, for the default grey sheet. */
49
53
  labelColor?: readonly [number, number, number];
50
54
  }
51
- interface FilmstripLayout {
55
+ export interface FilmstripLayout {
52
56
  /**
53
57
  * Cell box, i.e. the largest frame after scaling.
54
58
  *
@@ -72,18 +76,26 @@ interface FilmstripLayout {
72
76
  columnLabelBand: number;
73
77
  /** Height reserved above each row for its label; 0 when there are none. */
74
78
  rowLabelBand: number;
79
+ /** Height reserved above each cell for its own label; 0 when there are none. */
80
+ cellLabelBand: number;
75
81
  }
82
+ /**
83
+ * The source pixel a scaled pixel `i` shows, along one axis of `srcLen` scaled to `dstLen`. In
84
+ * floating point, as it always was: `105 * (1440 / 175)` is 863.9999999999999, so row 105 shows
85
+ * source row 863, not the 864 exact arithmetic gives. `boxOnSheet` inverts this, not the ideal.
86
+ */
87
+ export declare function sourceIndex(i: number, srcLen: number, dstLen: number): number;
76
88
  /** Nearest-neighbour, matching `image-resize.ts`: hard edges stay legible small. */
77
89
  /**
78
90
  * Exported for the animated-strip path, which downscales the same frames the sheet would and must
79
91
  * shrink them the same way — two nearest-neighbour implementations would drift on which pixel wins.
80
92
  */
81
- declare function scalePngData(src: PngData, factor: number): PngData;
93
+ export declare function scalePngData(src: PngData, factor: number): PngData;
82
94
  /**
83
95
  * Where each frame lands. Exported so a caller can label the sheet (in Markdown,
84
96
  * a report, a PR comment) without re-deriving the arithmetic.
85
97
  */
86
- declare function filmstripLayout(frames: readonly PngData[], options?: FilmstripOptions): FilmstripLayout;
98
+ export declare function filmstripLayout(frames: readonly PngData[], options?: FilmstripOptions): FilmstripLayout;
87
99
  /**
88
100
  * One image containing every frame, in order.
89
101
  *
@@ -114,8 +126,47 @@ declare function filmstripLayout(frames: readonly PngData[], options?: Filmstrip
114
126
  * reader is looking for — turning visible motion into a still. Cells are sized
115
127
  * from the largest frame so nothing is cropped.
116
128
  */
117
- declare function composeFilmstrip(frames: readonly PngData[], options?: FilmstripOptions): PngData & {
129
+ export declare function composeFilmstrip(frames: readonly PngData[], options?: FilmstripOptions): PngData & {
118
130
  layout: FilmstripLayout;
119
131
  };
120
- //#endregion
121
- export { FilmstripLayout, FilmstripOptions, composeFilmstrip, filmstripLayout, scalePngData };
132
+ /**
133
+ * Where a box in frame `index`'s own pixels lands on the sheet: the first and last sheet pixel,
134
+ * on each axis, that `scalePngData` fills from a source pixel inside the box. Nearest-neighbour
135
+ * skips source pixels when it shrinks, so a box can fall between two sheet pixels; it then keeps
136
+ * the one showing the source pixel just before it.
137
+ */
138
+ export declare function boxOnSheet(layout: FilmstripLayout, index: number, frame: {
139
+ width: number;
140
+ height: number;
141
+ }, box: {
142
+ x: number;
143
+ y: number;
144
+ width: number;
145
+ height: number;
146
+ }): {
147
+ x: number;
148
+ y: number;
149
+ width: number;
150
+ height: number;
151
+ };
152
+ /**
153
+ * A rectangle's outline drawn just OUTSIDE `box`, `thickness` px wide, never over it, so the
154
+ * pixels the box marks stay visible however thin it is. Nothing is drawn outside `clip`: a caller
155
+ * outlining a box inside a sheet cell passes the cell grown by `thickness` into the gap around it,
156
+ * so a box at the frame's edge keeps its outer side in the gap instead of losing it.
157
+ */
158
+ export declare function strokeOutside(target: {
159
+ width: number;
160
+ height: number;
161
+ data: Uint8Array;
162
+ }, box: {
163
+ x: number;
164
+ y: number;
165
+ width: number;
166
+ height: number;
167
+ }, rgb: readonly [number, number, number], thickness: number, clip: {
168
+ x: number;
169
+ y: number;
170
+ width: number;
171
+ height: number;
172
+ }): void;
@@ -1,5 +1,5 @@
1
1
  import { drawText, fitText, textHeight } from "./bitmap-font.mjs";
2
- //#region src/filmstrip.ts
2
+ // src/filmstrip.ts
3
3
  const DEFAULT_BACKGROUND = [
4
4
  96,
5
5
  96,
@@ -12,6 +12,14 @@ const DEFAULT_LABEL_COLOR = [
12
12
  ];
13
13
  /** Breathing room under a label band, so ink does not touch the frame below it. */
14
14
  const LABEL_PAD = 3;
15
+ /**
16
+ * The source pixel a scaled pixel `i` shows, along one axis of `srcLen` scaled to `dstLen`. In
17
+ * floating point, as it always was: `105 * (1440 / 175)` is 863.9999999999999, so row 105 shows
18
+ * source row 863, not the 864 exact arithmetic gives. `boxOnSheet` inverts this, not the ideal.
19
+ */
20
+ function sourceIndex(i, srcLen, dstLen) {
21
+ return Math.min(Math.floor(i * (srcLen / dstLen)), srcLen - 1);
22
+ }
15
23
  /** Nearest-neighbour, matching `image-resize.ts`: hard edges stay legible small. */
16
24
  /**
17
25
  * Exported for the animated-strip path, which downscales the same frames the sheet would and must
@@ -22,12 +30,10 @@ function scalePngData(src, factor) {
22
30
  const width = Math.max(1, Math.round(src.width / factor));
23
31
  const height = Math.max(1, Math.round(src.height / factor));
24
32
  const data = new Uint8Array(width * height * 4);
25
- const xRatio = src.width / width;
26
- const yRatio = src.height / height;
27
33
  for (let y = 0; y < height; y++) {
28
- const srcY = Math.min(Math.floor(y * yRatio), src.height - 1);
34
+ const srcY = sourceIndex(y, src.height, height);
29
35
  for (let x = 0; x < width; x++) {
30
- const srcX = Math.min(Math.floor(x * xRatio), src.width - 1);
36
+ const srcX = sourceIndex(x, src.width, width);
31
37
  const si = (srcY * src.width + srcX) * 4;
32
38
  const di = (y * width + x) * 4;
33
39
  data[di] = src.data[si];
@@ -67,9 +73,12 @@ function filmstripLayout(frames, options = {}) {
67
73
  width: Math.max(...scaled.map((s) => s.width)),
68
74
  height: Math.max(...scaled.map((s) => s.height))
69
75
  };
70
- const band = textHeight(Math.max(1, Math.round(options.labelScale ?? 2))) + LABEL_PAD;
76
+ const labelScale = Math.max(1, Math.round(options.labelScale ?? 2));
77
+ const band = textHeight(labelScale) + LABEL_PAD;
71
78
  const columnLabelBand = options.columnLabels && options.columnLabels.length > 0 ? band : 0;
72
79
  const rowLabelBand = options.rowLabels && options.rowLabels.length > 0 ? band : 0;
80
+ const cellLabelBand = options.cellLabels && options.cellLabels.some((l) => l.length > 0) ? band : 0;
81
+ const above = rowLabelBand + cellLabelBand;
73
82
  return {
74
83
  cell,
75
84
  columns,
@@ -78,12 +87,13 @@ function filmstripLayout(frames, options = {}) {
78
87
  const row = Math.floor(i / columns);
79
88
  return {
80
89
  x: padding + i % columns * (cell.width + gap),
81
- y: padding + columnLabelBand + row * (cell.height + gap + rowLabelBand) + rowLabelBand
90
+ y: padding + columnLabelBand + row * (cell.height + gap + above) + above
82
91
  };
83
92
  }),
84
93
  scale,
85
94
  columnLabelBand,
86
- rowLabelBand
95
+ rowLabelBand,
96
+ cellLabelBand
87
97
  };
88
98
  }
89
99
  /**
@@ -122,7 +132,7 @@ function composeFilmstrip(frames, options = {}) {
122
132
  const padding = options.padding ?? gap;
123
133
  const [bgR, bgG, bgB] = options.background ?? DEFAULT_BACKGROUND;
124
134
  const width = padding * 2 + layout.columns * layout.cell.width + gap * (layout.columns - 1);
125
- const height = padding * 2 + layout.columnLabelBand + layout.rows * (layout.cell.height + layout.rowLabelBand) + gap * (layout.rows - 1);
135
+ const height = padding * 2 + layout.columnLabelBand + layout.rows * (layout.cell.height + layout.rowLabelBand + layout.cellLabelBand) + gap * (layout.rows - 1);
126
136
  const data = new Uint8Array(width * height * 4);
127
137
  for (let i = 0; i < data.length; i += 4) {
128
138
  data[i] = bgR;
@@ -166,10 +176,14 @@ function composeFilmstrip(frames, options = {}) {
166
176
  if (layout.rowLabelBand > 0) {
167
177
  const rowWidth = width - padding * 2;
168
178
  options.rowLabels.slice(0, layout.rows).forEach((label, row) => {
169
- const y = padding + layout.columnLabelBand + row * (layout.cell.height + gap + layout.rowLabelBand);
179
+ const y = padding + layout.columnLabelBand + row * (layout.cell.height + gap + layout.rowLabelBand + layout.cellLabelBand);
170
180
  drawText(sheet, fitText(label, rowWidth, labelScale), padding, y, ink, labelScale);
171
181
  });
172
182
  }
183
+ if (layout.cellLabelBand > 0) options.cellLabels.slice(0, frames.length).forEach((label, index) => {
184
+ const { x, y } = layout.positions[index];
185
+ drawText(sheet, fitText(label, layout.cell.width, labelScale), x, y - layout.cellLabelBand, ink, labelScale);
186
+ });
173
187
  return {
174
188
  width,
175
189
  height,
@@ -177,5 +191,62 @@ function composeFilmstrip(frames, options = {}) {
177
191
  layout
178
192
  };
179
193
  }
180
- //#endregion
181
- export { composeFilmstrip, filmstripLayout, scalePngData };
194
+ /**
195
+ * Where a box in frame `index`'s own pixels lands on the sheet: the first and last sheet pixel,
196
+ * on each axis, that `scalePngData` fills from a source pixel inside the box. Nearest-neighbour
197
+ * skips source pixels when it shrinks, so a box can fall between two sheet pixels; it then keeps
198
+ * the one showing the source pixel just before it.
199
+ */
200
+ function boxOnSheet(layout, index, frame, box) {
201
+ const { x: ox, y: oy } = layout.positions[index];
202
+ const span = (start, length, srcLen) => {
203
+ const dstLen = Math.max(1, Math.round(srcLen / layout.scale));
204
+ let first = -1;
205
+ let last = -1;
206
+ let below = 0;
207
+ for (let i = 0; i < dstLen; i++) {
208
+ const src = sourceIndex(i, srcLen, dstLen);
209
+ if (src < start) below = i;
210
+ else if (src < start + length) {
211
+ if (first === -1) first = i;
212
+ last = i;
213
+ }
214
+ }
215
+ return first === -1 ? {
216
+ at: below,
217
+ length: 1
218
+ } : {
219
+ at: first,
220
+ length: last - first + 1
221
+ };
222
+ };
223
+ const x = span(box.x, box.width, frame.width);
224
+ const y = span(box.y, box.height, frame.height);
225
+ return {
226
+ x: ox + x.at,
227
+ y: oy + y.at,
228
+ width: x.length,
229
+ height: y.length
230
+ };
231
+ }
232
+ /**
233
+ * A rectangle's outline drawn just OUTSIDE `box`, `thickness` px wide, never over it, so the
234
+ * pixels the box marks stay visible however thin it is. Nothing is drawn outside `clip`: a caller
235
+ * outlining a box inside a sheet cell passes the cell grown by `thickness` into the gap around it,
236
+ * so a box at the frame's edge keeps its outer side in the gap instead of losing it.
237
+ */
238
+ function strokeOutside(target, box, rgb, thickness, clip) {
239
+ const x0 = Math.max(0, clip.x, box.x - thickness);
240
+ const y0 = Math.max(0, clip.y, box.y - thickness);
241
+ const x1 = Math.min(target.width - 1, clip.x + clip.width - 1, box.x + box.width - 1 + thickness);
242
+ const y1 = Math.min(target.height - 1, clip.y + clip.height - 1, box.y + box.height - 1 + thickness);
243
+ for (let y = y0; y <= y1; y++) for (let x = x0; x <= x1; x++) {
244
+ if (x >= box.x && x < box.x + box.width && y >= box.y && y < box.y + box.height) continue;
245
+ const i = (y * target.width + x) * 4;
246
+ target.data[i] = rgb[0];
247
+ target.data[i + 1] = rgb[1];
248
+ target.data[i + 2] = rgb[2];
249
+ target.data[i + 3] = 255;
250
+ }
251
+ }
252
+ export { boxOnSheet, composeFilmstrip, filmstripLayout, scalePngData, sourceIndex, strokeOutside };
@@ -1,7 +1,5 @@
1
1
  import { RuleSettingEntry, RuleSettings } from "./plugin/rules.mjs";
2
-
3
- //#region src/gate-config.d.ts
4
- interface GateSuppression {
2
+ export interface GateSuppression {
5
3
  /**
6
4
  * Gate this applies to, as a prefix of the gate command: `check copy`
7
5
  * matches `check copy --manifest x.txt`.
@@ -16,7 +14,7 @@ interface GateSuppression {
16
14
  /** `YYYY-MM-DD`. Omitted means permanent, which the inventory counts separately. */
17
15
  expires?: string;
18
16
  }
19
- interface GatePage {
17
+ export interface GatePage {
20
18
  /** Short stable name for `--only` and reports. Defaults to the source. */
21
19
  id?: string;
22
20
  /** File path, glob, or URL handed to each gate. */
@@ -55,7 +53,7 @@ interface GatePage {
55
53
  * Named and shaped after Playwright's on purpose. A team that has written one
56
54
  * should not have to learn a second vocabulary to write this one.
57
55
  */
58
- interface GateWebServer {
56
+ export interface GateWebServer {
59
57
  /** Shell command that starts the server. */
60
58
  command: string;
61
59
  /**
@@ -79,7 +77,7 @@ interface GateWebServer {
79
77
  /** Extra environment for the server process, on top of the current one. */
80
78
  env?: Readonly<Record<string, string>>;
81
79
  }
82
- interface GateConfig {
80
+ export interface GateConfig {
83
81
  webServer?: GateWebServer;
84
82
  defaults?: {
85
83
  gates?: string[];
@@ -89,7 +87,7 @@ interface GateConfig {
89
87
  };
90
88
  pages: GatePage[];
91
89
  }
92
- interface ResolvedSuppression extends GateSuppression {
90
+ export interface ResolvedSuppression extends GateSuppression {
93
91
  /** Page id this came from, or `defaults`. */
94
92
  scope: string;
95
93
  status: "active" | "expired" | "permanent";
@@ -109,7 +107,7 @@ interface ResolvedSuppression extends GateSuppression {
109
107
  /** Rule reference, for `kind: "rule"` only. */
110
108
  ref?: string;
111
109
  }
112
- interface GateJob {
110
+ export interface GateJob {
113
111
  pageId: string;
114
112
  source: string;
115
113
  /** Gate command with active suppression flags and rule settings appended. */
@@ -120,7 +118,7 @@ interface GateJob {
120
118
  /** Rule settings in effect, defaults merged with the page's. */
121
119
  rules: RuleSettings;
122
120
  }
123
- interface GatePlan {
121
+ export interface GatePlan {
124
122
  jobs: GateJob[];
125
123
  /** Every suppression the config declares, resolved against `now`. */
126
124
  suppressions: ResolvedSuppression[];
@@ -130,17 +128,17 @@ interface GatePlan {
130
128
  */
131
129
  expired: ResolvedSuppression[];
132
130
  }
133
- declare const GATE_CONFIG_FILENAMES: string[];
131
+ export declare const GATE_CONFIG_FILENAMES: string[];
134
132
  /** Parse and validate. Every error names the JSON path so the fix is obvious. */
135
- declare function parseGateConfig(raw: string): GateConfig;
133
+ export declare function parseGateConfig(raw: string): GateConfig;
136
134
  /**
137
135
  * Whether to reuse a server already listening. Playwright's default, and for
138
136
  * Playwright's reason: locally the listening port is your own `npm run dev`; in
139
137
  * CI it is usually a leaked process from an earlier job, and reusing it gates a
140
138
  * build nobody asked about.
141
139
  */
142
- declare function shouldReuseExistingServer(server: GateWebServer, env?: NodeJS.ProcessEnv): boolean;
143
- declare function resolveSuppression(s: GateSuppression, scope: string, now: Date): ResolvedSuppression;
140
+ export declare function shouldReuseExistingServer(server: GateWebServer, env?: NodeJS.ProcessEnv): boolean;
141
+ export declare function resolveSuppression(s: GateSuppression, scope: string, now: Date): ResolvedSuppression;
144
142
  /**
145
143
  * Resolve one long-form `rules` entry onto the same shape as a suppression, so
146
144
  * the inventory, the expiry notice and `--require-expiry` cover both.
@@ -149,8 +147,8 @@ declare function resolveSuppression(s: GateSuppression, scope: string, now: Date
149
147
  * -> `check.integrity`), which is what a reader scanning the inventory wants to
150
148
  * see; a bare rule id has no gate to name and reports as `*`.
151
149
  */
152
- declare function resolveRuleSetting(ref: string, entry: RuleSettingEntry, scope: string, now: Date): ResolvedSuppression;
153
- interface ResolveOptions {
150
+ export declare function resolveRuleSetting(ref: string, entry: RuleSettingEntry, scope: string, now: Date): ResolvedSuppression;
151
+ export interface ResolveOptions {
154
152
  now?: Date;
155
153
  /**
156
154
  * Which of the resolved rule settings belong on THIS gate's command line.
@@ -178,15 +176,15 @@ interface ResolveOptions {
178
176
  * command line: the gate returns to failing, which is what an expiry date is
179
177
  * supposed to mean.
180
178
  */
181
- declare function resolveGatePlan(config: GateConfig, options?: ResolveOptions): GatePlan;
179
+ export declare function resolveGatePlan(config: GateConfig, options?: ResolveOptions): GatePlan;
182
180
  /** `{ "check.integrity/text-collision": "off" }` → `["--rule", "check.integrity/text-collision=off"]`. */
183
- declare function ruleFlags(rules: RuleSettings): string[];
181
+ export declare function ruleFlags(rules: RuleSettings): string[];
184
182
  /**
185
183
  * Token-wise prefix match: `check copy` matches `check copy --manifest x.txt`
186
184
  * but not `check copyright`, and `check` matches every check gate.
187
185
  */
188
- declare function gateMatches(gate: string, pattern: string): boolean;
189
- interface SuppressionSummary {
186
+ export declare function gateMatches(gate: string, pattern: string): boolean;
187
+ export interface SuppressionSummary {
190
188
  rows: ResolvedSuppression[];
191
189
  active: number;
192
190
  expired: number;
@@ -196,6 +194,4 @@ interface SuppressionSummary {
196
194
  /** Active entries expiring within `soonDays`. */
197
195
  expiringSoon: number;
198
196
  }
199
- declare function summarizeSuppressions(suppressions: ResolvedSuppression[], soonDays?: number): SuppressionSummary;
200
- //#endregion
201
- export { GATE_CONFIG_FILENAMES, GateConfig, GateJob, GatePage, GatePlan, GateSuppression, GateWebServer, ResolveOptions, ResolvedSuppression, SuppressionSummary, gateMatches, parseGateConfig, resolveGatePlan, resolveRuleSetting, resolveSuppression, ruleFlags, shouldReuseExistingServer, summarizeSuppressions };
197
+ export declare function summarizeSuppressions(suppressions: ResolvedSuppression[], soonDays?: number): SuppressionSummary;
@@ -1,6 +1,7 @@
1
1
  import { UsageError } from "./cli-error.mjs";
2
+ import { motionSpecCommand } from "./motion-spec.mjs";
2
3
  import { parseAnnotatedRuleSettings } from "./plugin/rules.mjs";
3
- //#region src/gate-config.ts
4
+ // src/gate-config.ts
4
5
  /**
5
6
  * `vlmkit.gates.json` — one reviewed file that says which gates run on which
6
7
  * pages, and holds every suppression with a reason attached.
@@ -48,10 +49,14 @@ function parseSuppression(raw, path) {
48
49
  };
49
50
  }
50
51
  function parseGateList(raw, path) {
51
- if (!Array.isArray(raw)) fail(path, "must be an array of gate command strings");
52
+ if (!Array.isArray(raw)) fail(path, "must be an array of gate command strings (or { \"motion\": {...} } entries)");
52
53
  if (raw.length === 0) fail(path, "is empty — remove the key or list at least one gate");
53
54
  return raw.map((g, i) => {
54
- if (typeof g !== "string" || !g.trim()) fail(`${path}[${i}]`, "must be a non-empty string");
55
+ if (typeof g === "object" && g !== null && !Array.isArray(g) && "motion" in g) {
56
+ if (Object.keys(g).length !== 1) fail(`${path}[${i}]`, "a { \"motion\": {...} } entry has no other keys");
57
+ return motionSpecCommand(g.motion, `${path}[${i}].motion`, fail);
58
+ }
59
+ if (typeof g !== "string" || !g.trim()) fail(`${path}[${i}]`, "must be a non-empty string (a gate command), or { \"motion\": {...} }");
55
60
  return g.trim();
56
61
  });
57
62
  }
@@ -294,5 +299,4 @@ function summarizeSuppressions(suppressions, soonDays = 30) {
294
299
  expiringSoon: rows.filter((s) => s.status === "active" && (s.daysLeft ?? Infinity) <= soonDays).length
295
300
  };
296
301
  }
297
- //#endregion
298
302
  export { GATE_CONFIG_FILENAMES, gateMatches, parseGateConfig, resolveGatePlan, resolveRuleSetting, resolveSuppression, ruleFlags, shouldReuseExistingServer, summarizeSuppressions };
@@ -1,4 +1,3 @@
1
- //#region src/gate-exit.d.ts
2
1
  /**
3
2
  * One exit-code contract for every gate.
4
3
  *
@@ -23,23 +22,21 @@
23
22
  *
24
23
  * Warns never affect the exit code, under any flag.
25
24
  */
26
- interface GateExitFlags {
25
+ export interface GateExitFlags {
27
26
  /** Print findings and exit 0 even when suspects exist. */
28
27
  advisory: boolean;
29
28
  }
30
29
  /** Parse the shared exit-code flags out of an argv array. */
31
- declare function parseGateExitFlags(argv: readonly string[]): GateExitFlags;
30
+ export declare function parseGateExitFlags(argv: readonly string[]): GateExitFlags;
32
31
  /**
33
32
  * Decide the process exit code. `hasSuspect` should count only
34
33
  * defect-severity findings; warn-level findings must not reach it.
35
34
  */
36
- declare function gateExitCode(hasSuspect: boolean, flags: GateExitFlags): 0 | 1;
35
+ export declare function gateExitCode(hasSuspect: boolean, flags: GateExitFlags): 0 | 1;
37
36
  /** Shared help text so every gate documents the contract identically. */
38
- declare const GATE_EXIT_HELP = " --advisory Print findings but exit 0 (default: a suspect exits 1)";
37
+ export declare const GATE_EXIT_HELP = " --advisory Print findings but exit 0 (default: a suspect exits 1)";
39
38
  /**
40
39
  * Apply the contract. Sets `process.exitCode` rather than calling
41
40
  * `process.exit` so buffered stdout is not truncated.
42
41
  */
43
- declare function applyGateExit(hasSuspect: boolean, flags: GateExitFlags): void;
44
- //#endregion
45
- export { GATE_EXIT_HELP, GateExitFlags, applyGateExit, gateExitCode, parseGateExitFlags };
42
+ export declare function applyGateExit(hasSuspect: boolean, flags: GateExitFlags): void;
@@ -1,4 +1,4 @@
1
- //#region src/gate-exit.ts
1
+ // src/gate-exit.ts
2
2
  /** Parse the shared exit-code flags out of an argv array. */
3
3
  function parseGateExitFlags(argv) {
4
4
  return { advisory: argv.includes("--advisory") };
@@ -21,5 +21,4 @@ function applyGateExit(hasSuspect, flags) {
21
21
  const code = gateExitCode(hasSuspect, flags);
22
22
  if (code !== 0) process.exitCode = code;
23
23
  }
24
- //#endregion
25
24
  export { GATE_EXIT_HELP, applyGateExit, gateExitCode, parseGateExitFlags };
package/dist/gif.d.mts ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * A minimal GIF writer: a global palette, an optional loop block, and frames each with its own
3
+ * place on the logical screen and its graphic control extension (delay, disposal, transparent
4
+ * index) or none. Written so the cases ffmpeg composites otherwise than a browser can be built
5
+ * byte for byte (`gifCompositingProblem`); the LZW stream sends a clear code before the table
6
+ * would grow, so every code has the minimum width and no dictionary is kept.
7
+ *
8
+ * Pure: frames in, bytes out.
9
+ */
10
+ export interface GifFrame {
11
+ x?: number;
12
+ y?: number;
13
+ width?: number;
14
+ height?: number;
15
+ /** Palette index per pixel, row by row, or one index for every pixel. */
16
+ pixels: number | ((x: number, y: number) => number);
17
+ /** Centiseconds; default 10. */
18
+ delayCs?: number;
19
+ /** 0-1 leave it, 2 restore to background, 3 restore to previous. */
20
+ disposal?: number;
21
+ /** A transparent palette index. */
22
+ transparent?: number;
23
+ /** false: no graphic control extension at all. */
24
+ gce?: boolean;
25
+ }
26
+ export interface GifOptions {
27
+ width: number;
28
+ height: number;
29
+ /** RGB triples; at most 256. */
30
+ palette: readonly (readonly [number, number, number])[];
31
+ /** The logical screen's background colour index. */
32
+ background?: number;
33
+ /** NETSCAPE2.0 loop count (0 forever); none when absent (plays once). */
34
+ loop?: number;
35
+ /** The logical screen's pixel aspect byte (0: none). */
36
+ aspectByte?: number;
37
+ /** Give each image the palette as a local colour table and write no global one. */
38
+ localTables?: boolean;
39
+ frames: readonly GifFrame[];
40
+ }
41
+ export declare function encodeGif(options: GifOptions): Uint8Array;
package/dist/gif.mjs ADDED
@@ -0,0 +1,73 @@
1
+ // src/gif.ts
2
+ function lzw(indices, minCodeSize) {
3
+ const clear = 1 << minCodeSize;
4
+ const end = clear + 1;
5
+ const width = minCodeSize + 1;
6
+ const every = (1 << minCodeSize) - 2;
7
+ const codes = [clear];
8
+ indices.forEach((v, i) => {
9
+ if (i > 0 && i % every === 0) codes.push(clear);
10
+ codes.push(v);
11
+ });
12
+ codes.push(end);
13
+ const bytes = [];
14
+ let acc = 0;
15
+ let bits = 0;
16
+ for (const c of codes) {
17
+ acc |= c << bits;
18
+ bits += width;
19
+ while (bits >= 8) {
20
+ bytes.push(acc & 255);
21
+ acc >>>= 8;
22
+ bits -= 8;
23
+ }
24
+ }
25
+ if (bits > 0) bytes.push(acc & 255);
26
+ const out = [minCodeSize];
27
+ for (let i = 0; i < bytes.length; i += 255) {
28
+ const block = bytes.slice(i, i + 255);
29
+ out.push(block.length, ...block);
30
+ }
31
+ out.push(0);
32
+ return out;
33
+ }
34
+ const u16 = (v) => [v & 255, v >> 8 & 255];
35
+ function encodeGif(options) {
36
+ const { width, height, palette } = options;
37
+ let bits = 1;
38
+ while (1 << bits < palette.length) bits++;
39
+ const table = [];
40
+ for (let i = 0; i < 1 << bits; i++) table.push(...palette[i] ?? [
41
+ 0,
42
+ 0,
43
+ 0
44
+ ]);
45
+ const local = options.localTables === true;
46
+ const out = [
47
+ ...Array.from("GIF89a", (c) => c.charCodeAt(0)),
48
+ ...u16(width),
49
+ ...u16(height),
50
+ local ? 0 : 128 | bits - 1 << 4 | bits - 1,
51
+ options.background ?? 0,
52
+ options.aspectByte ?? 0,
53
+ ...local ? [] : table
54
+ ];
55
+ if (options.loop !== void 0) out.push(33, 255, 11, ...Array.from("NETSCAPE2.0", (c) => c.charCodeAt(0)), 3, 1, ...u16(options.loop), 0);
56
+ for (const f of options.frames) {
57
+ if (f.gce !== false) {
58
+ const packed = (f.disposal ?? 0) << 2 | (f.transparent !== void 0 ? 1 : 0);
59
+ out.push(33, 249, 4, packed, ...u16(f.delayCs ?? 10), f.transparent ?? 0, 0);
60
+ }
61
+ const x = f.x ?? 0;
62
+ const y = f.y ?? 0;
63
+ const w = f.width ?? width;
64
+ const h = f.height ?? height;
65
+ out.push(44, ...u16(x), ...u16(y), ...u16(w), ...u16(h), local ? 128 | bits - 1 : 0, ...local ? table : []);
66
+ const paint = f.pixels;
67
+ const px = Array.from({ length: w * h }, (_, i) => typeof paint === "number" ? paint : paint(i % w, Math.floor(i / w)));
68
+ out.push(...lzw(px, Math.max(2, bits)));
69
+ }
70
+ out.push(59);
71
+ return Uint8Array.from(out);
72
+ }
73
+ export { encodeGif };
@@ -1,5 +1,4 @@
1
- //#region src/heatmap-regions.d.ts
2
- interface HeatmapRegion {
1
+ export interface HeatmapRegion {
3
2
  top: number;
4
3
  left: number;
5
4
  width: number;
@@ -33,7 +32,7 @@ interface HeatmapRegion {
33
32
  /** Classifier confidence ∈ [0, 1]. */
34
33
  kindConfidence?: number;
35
34
  }
36
- interface FindHeatmapRegionsOptions {
35
+ export interface FindHeatmapRegionsOptions {
37
36
  /** Minimum hot-pixel count for a region to be kept. Default 80. */
38
37
  minArea?: number;
39
38
  /** Cap on returned regions, sorted by area desc. Default 8. */
@@ -51,7 +50,5 @@ interface FindHeatmapRegionsOptions {
51
50
  */
52
51
  maxRegionFraction?: number;
53
52
  }
54
- declare function findHeatmapRegionsFromRgba(data: Uint8Array, width: number, height: number, options?: FindHeatmapRegionsOptions): HeatmapRegion[];
55
- declare function findHeatmapRegionsFromFile(path: string, options?: FindHeatmapRegionsOptions, sourceImagePath?: string): Promise<HeatmapRegion[]>;
56
- //#endregion
57
- export { FindHeatmapRegionsOptions, HeatmapRegion, findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba };
53
+ export declare function findHeatmapRegionsFromRgba(data: Uint8Array, width: number, height: number, options?: FindHeatmapRegionsOptions): HeatmapRegion[];
54
+ export declare function findHeatmapRegionsFromFile(path: string, options?: FindHeatmapRegionsOptions, sourceImagePath?: string): Promise<HeatmapRegion[]>;
@@ -1,6 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { PNG } from "pngjs";
3
- //#region src/heatmap-regions.ts
3
+ // src/heatmap-regions.ts
4
4
  /**
5
5
  * Heatmap region clustering.
6
6
  *
@@ -154,5 +154,4 @@ async function findHeatmapRegionsFromFile(path, options = {}, sourceImagePath) {
154
154
  } catch {}
155
155
  return regions;
156
156
  }
157
- //#endregion
158
157
  export { findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba };