@m4k/common 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to `@m4k/common` are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.9]
9
+
10
+ ### Added
11
+
12
+ - Added the versioned image-classification contract, candidate validation and input-bound results.
13
+ - Added Unicode-safe option encoding and embedded-preview image options.
14
+
8
15
  ## [0.2.8]
9
16
 
10
17
  ### Changed
@@ -0,0 +1,31 @@
1
+ /** Closed, immutable classifier profile. Changing weights, runtime, prompt or preprocessing needs a new version. */
2
+ export declare const imageClassifier: {
3
+ readonly id: "clip-image-labels";
4
+ readonly version: "1";
5
+ readonly model: "Xenova/clip-vit-base-patch32";
6
+ readonly revision: "6b7c523703ae26e39be4b03774966f8571c7f523";
7
+ readonly template: "This is a photo of {}";
8
+ readonly maxBytes: number;
9
+ readonly maxPixels: number;
10
+ readonly maxLabels: 32;
11
+ };
12
+ export type ClassificationOptions = {
13
+ classifierId: string;
14
+ classifierVersion: string;
15
+ labels: readonly string[];
16
+ };
17
+ export type ClassificationResult = {
18
+ classifierId: string;
19
+ classifierVersion: string;
20
+ /** SHA-256 of the exact uploaded representation, not of the decoded image. */
21
+ sha256: string;
22
+ /** Softmax across the complete candidate set, not calibrated independent probabilities. */
23
+ labels: {
24
+ label: string;
25
+ score: number;
26
+ }[];
27
+ };
28
+ /** ASCII-safe JSON for HTTP byte-string headers, preserving arbitrary Unicode label text. */
29
+ export declare function encodeOptions(value: unknown): string;
30
+ export declare function validateClassificationOptions(value: unknown): value is ClassificationOptions;
31
+ //# sourceMappingURL=classification.d.ts.map
@@ -0,0 +1,32 @@
1
+ /** Closed, immutable classifier profile. Changing weights, runtime, prompt or preprocessing needs a new version. */
2
+ export const imageClassifier = {
3
+ id: "clip-image-labels",
4
+ version: "1",
5
+ model: "Xenova/clip-vit-base-patch32",
6
+ revision: "6b7c523703ae26e39be4b03774966f8571c7f523",
7
+ template: "This is a photo of {}",
8
+ maxBytes: 8 * 1024 * 1024,
9
+ maxPixels: 1024 * 1024,
10
+ maxLabels: 32,
11
+ };
12
+ /** ASCII-safe JSON for HTTP byte-string headers, preserving arbitrary Unicode label text. */
13
+ export function encodeOptions(value) {
14
+ return JSON.stringify(value).replace(/[^\u0020-\u007e]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`);
15
+ }
16
+ export function validateClassificationOptions(value) {
17
+ if (!value || typeof value !== "object")
18
+ return false;
19
+ const o = value;
20
+ return (o.classifierId === imageClassifier.id &&
21
+ o.classifierVersion === imageClassifier.version &&
22
+ Array.isArray(o.labels) &&
23
+ o.labels.length >= 2 &&
24
+ o.labels.length <= imageClassifier.maxLabels &&
25
+ new Set(o.labels).size === o.labels.length &&
26
+ o.labels.every((label) => typeof label === "string" &&
27
+ label.length > 0 &&
28
+ label.length <= 80 &&
29
+ label === label.trim() &&
30
+ !/[\u0000-\u001f\u007f{}]/.test(label)));
31
+ }
32
+ //# sourceMappingURL=classification.js.map
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { imageClassifier, encodeOptions, validateClassificationOptions, type ClassificationOptions, type ClassificationResult, } from "./classification.js";
1
2
  export type Progress = {
2
3
  progress: number;
3
4
  };
@@ -9,6 +10,8 @@ export type ProcessingError = {
9
10
  };
10
11
  type ImageFormat = "avif" | "jpeg" | "png" | "webp" | "tiff" | "dz" | "ppm" | "fits" | "gif" | "svg" | "heif" | "pdf" | "jp2";
11
12
  export type ImageOptions = {
13
+ /** Extract a bounded embedded JPEG preview from a TIFF-based camera file; never demosaic RAW. */
14
+ embeddedPreview?: boolean;
12
15
  /** The rotation of the image. If not provided, the image will be auto-rotated, according to the EXIF data. To disable auto-rotation, set to `0`. */
13
16
  rotate?: number;
14
17
  /** Resizing options. */
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { imageClassifier, encodeOptions, validateClassificationOptions, } from "./classification.js";
1
2
  export class ProcessedFile {
2
3
  name;
3
4
  type;
@@ -13,7 +14,8 @@ export function isImageNoOp(opt, inputExt) {
13
14
  const outFmt = opt.format ?? opt.ext ?? "avif";
14
15
  if (outFmt !== inputExt)
15
16
  return false;
16
- return (!opt.resize &&
17
+ return (!opt.embeddedPreview &&
18
+ !opt.resize &&
17
19
  !opt.crop &&
18
20
  opt.rotate == null &&
19
21
  opt.quality == null &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4k/common",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Common types and utilities for m4k",
5
5
  "license": "MIT",
6
6
  "author": "sv2dev",