@graview/guest 0.2.3 → 0.2.5

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 (107) hide show
  1. package/README.md +66 -0
  2. package/client.js +1 -1
  3. package/dist/audit/page.generated.js +1 -1
  4. package/dist/client.generated.js +2 -2
  5. package/dist/headless/draw.d.ts +2 -0
  6. package/dist/headless/draw.d.ts.map +1 -1
  7. package/dist/headless/draw.js +1 -1
  8. package/dist/headless/draw.js.map +1 -1
  9. package/dist/headless/index.d.ts +2 -0
  10. package/dist/headless/index.d.ts.map +1 -1
  11. package/dist/headless/index.js +1 -1
  12. package/dist/headless/index.js.map +1 -1
  13. package/dist/headless/judge.d.ts +2 -0
  14. package/dist/headless/judge.d.ts.map +1 -1
  15. package/dist/headless/judge.js +1 -1
  16. package/dist/headless/judge.js.map +1 -1
  17. package/dist/headless/runtime.generated.d.ts.map +1 -1
  18. package/dist/headless/runtime.generated.js +1 -1
  19. package/dist/headless/runtime.generated.js.map +1 -1
  20. package/dist/headless/seats.d.ts +2 -1
  21. package/dist/headless/seats.d.ts.map +1 -1
  22. package/dist/headless/seats.js +7 -2
  23. package/dist/headless/seats.js.map +1 -1
  24. package/dist/host/drop.d.ts +2 -1
  25. package/dist/host/drop.d.ts.map +1 -1
  26. package/dist/host/drop.js +1 -1
  27. package/dist/host/drop.js.map +1 -1
  28. package/dist/host/fonts.d.ts +5 -4
  29. package/dist/host/fonts.d.ts.map +1 -1
  30. package/dist/host/fonts.js +13 -11
  31. package/dist/host/fonts.js.map +1 -1
  32. package/dist/host/frame.d.ts +10 -3
  33. package/dist/host/frame.d.ts.map +1 -1
  34. package/dist/host/frame.js +16 -6
  35. package/dist/host/frame.js.map +1 -1
  36. package/dist/host/index.d.ts +1 -0
  37. package/dist/host/index.d.ts.map +1 -1
  38. package/dist/host/links.d.ts +2 -1
  39. package/dist/host/links.d.ts.map +1 -1
  40. package/dist/host/links.js +1 -1
  41. package/dist/host/links.js.map +1 -1
  42. package/dist/host/manifest.d.ts.map +1 -1
  43. package/dist/host/manifest.js +10 -7
  44. package/dist/host/manifest.js.map +1 -1
  45. package/dist/host/media.d.ts +2 -1
  46. package/dist/host/media.d.ts.map +1 -1
  47. package/dist/host/media.js +1 -1
  48. package/dist/host/media.js.map +1 -1
  49. package/dist/host/open-draw.d.ts +2 -0
  50. package/dist/host/open-draw.d.ts.map +1 -1
  51. package/dist/host/open-draw.js +1 -1
  52. package/dist/host/open-draw.js.map +1 -1
  53. package/dist/host/parts.d.ts +2 -1
  54. package/dist/host/parts.d.ts.map +1 -1
  55. package/dist/host/parts.js +1 -1
  56. package/dist/host/parts.js.map +1 -1
  57. package/dist/host/picture-thumb.d.ts +40 -2
  58. package/dist/host/picture-thumb.d.ts.map +1 -1
  59. package/dist/host/picture-thumb.js +37 -2
  60. package/dist/host/picture-thumb.js.map +1 -1
  61. package/dist/host/pictures.d.ts +48 -6
  62. package/dist/host/pictures.d.ts.map +1 -1
  63. package/dist/host/pictures.js +121 -29
  64. package/dist/host/pictures.js.map +1 -1
  65. package/dist/host/problems.d.ts +13 -0
  66. package/dist/host/problems.d.ts.map +1 -0
  67. package/dist/host/problems.js +61 -0
  68. package/dist/host/problems.js.map +1 -0
  69. package/dist/host/react.d.ts +4 -1
  70. package/dist/host/react.d.ts.map +1 -1
  71. package/dist/host/react.js +3 -4
  72. package/dist/host/react.js.map +1 -1
  73. package/dist/host/sections.d.ts +2 -1
  74. package/dist/host/sections.d.ts.map +1 -1
  75. package/dist/host/sections.js +3 -3
  76. package/dist/host/sections.js.map +1 -1
  77. package/dist/host/session.d.ts +23 -3
  78. package/dist/host/session.d.ts.map +1 -1
  79. package/dist/host/session.js +40 -2
  80. package/dist/host/session.js.map +1 -1
  81. package/dist/host/view-runtime.generated.d.ts.map +1 -1
  82. package/dist/host/view-runtime.generated.js +1 -1
  83. package/dist/host/view-runtime.generated.js.map +1 -1
  84. package/dist/host/view.d.ts +16 -2
  85. package/dist/host/view.d.ts.map +1 -1
  86. package/dist/host/view.js +29 -28
  87. package/dist/host/view.js.map +1 -1
  88. package/dist/host/views.d.ts +3 -0
  89. package/dist/host/views.d.ts.map +1 -1
  90. package/dist/host/views.js +2 -0
  91. package/dist/host/views.js.map +1 -1
  92. package/dist/host/worker-react.d.ts +11 -2
  93. package/dist/host/worker-react.d.ts.map +1 -1
  94. package/dist/host/worker-react.js +1 -0
  95. package/dist/host/worker-react.js.map +1 -1
  96. package/dist/host/worker.d.ts +2 -0
  97. package/dist/host/worker.d.ts.map +1 -1
  98. package/dist/host/worker.js +2 -0
  99. package/dist/host/worker.js.map +1 -1
  100. package/dist/protocol.d.ts +33 -2
  101. package/dist/protocol.d.ts.map +1 -1
  102. package/dist/protocol.js.map +1 -1
  103. package/dist/worker/view-global.d.ts +23 -1
  104. package/dist/worker/view-global.d.ts.map +1 -1
  105. package/dist/worker/view-global.js +13 -0
  106. package/dist/worker/view-global.js.map +1 -1
  107. package/package.json +3 -3
@@ -1,5 +1,43 @@
1
+ /**
2
+ * A THUMB OF A SHAPE (Graview HQ f-picture-thumb-around-focus): its width,
3
+ * and the width over the height it is cropped to, around the picture's
4
+ * `focus` (its middle where the record says none). A cutout is never
5
+ * cropped: its thumb is the whole picture at that width.
6
+ */
7
+ export interface ThumbShape {
8
+ readonly width: number;
9
+ readonly aspect?: number;
10
+ }
11
+ /** The narrowest and widest shape a thumb is cropped to, width over height. */
12
+ export declare const THUMB_ASPECT: {
13
+ readonly least: 0.1;
14
+ readonly most: 10;
15
+ };
1
16
  /** What is said of a `thumb` that is not a whole number of pixels from 16 to 4096 narrower than the width. */
2
17
  export declare const THUMB_REFUSED = "The view's pictures thumb is a whole number of pixels from 16 to 4096, narrower than its width (1,200 by default): the size it draws a picture small at (view-pictures-thumb).";
3
- /** Whether `thumb` is a width a view may draw a picture small at, beside `width` (1 200 where it says none). */
4
- export declare function thumbIsSound(thumb: unknown, width: unknown): thumb is number;
18
+ /** What is said of a `thumb` written as a shape that is not one. */
19
+ export declare const THUMB_SHAPE_REFUSED: string;
20
+ /** Whether `thumb` is written as a shape (`{ width, aspect }`) rather than a width or a kind's fields. */
21
+ export declare const isThumbShape: (thumb: unknown) => thumb is Record<string, unknown>;
22
+ /** Whether `thumb` is a width a view may draw a picture small at, or a shape of one, beside `width` (1 200 where it says none). */
23
+ export declare function thumbIsSound(thumb: unknown, width: unknown): thumb is number | ThumbShape;
24
+ /** What is said of a `thumb` that is no sound one, in its own form; nothing where it is sound. */
25
+ export declare function thumbRefusal(thumb: unknown, width: unknown): string | undefined;
26
+ /** A sound thumb as a shape: its width, and its aspect where it has one. */
27
+ export declare const thumbShapeOf: (thumb: number | ThumbShape) => ThumbShape;
28
+ /**
29
+ * THE PART OF A PICTURE A THUMB OF `aspect` SHOWS, in its pixels: as much of
30
+ * it as that shape holds, its middle as near `focus` as the picture's edges
31
+ * allow — a portrait cropped square around a face high in it keeps the
32
+ * face, not the chest.
33
+ */
34
+ export declare function cropAround(width: number, height: number, aspect: number, focus?: {
35
+ readonly x: number;
36
+ readonly y: number;
37
+ }): {
38
+ readonly x: number;
39
+ readonly y: number;
40
+ readonly width: number;
41
+ readonly height: number;
42
+ };
5
43
  //# sourceMappingURL=picture-thumb.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"picture-thumb.d.ts","sourceRoot":"","sources":["../../src/host/picture-thumb.ts"],"names":[],"mappings":"AASA,8GAA8G;AAC9G,eAAO,MAAM,aAAa,mLAAmL,CAAC;AAE9M,gHAAgH;AAChH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAG5E"}
1
+ {"version":3,"file":"picture-thumb.d.ts","sourceRoot":"","sources":["../../src/host/picture-thumb.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,+EAA+E;AAC/E,eAAO,MAAM,YAAY;;;CAAoC,CAAC;AAE9D,8GAA8G;AAC9G,eAAO,MAAM,aAAa,mLAAmL,CAAC;AAE9M,oEAAoE;AACpE,eAAO,MAAM,mBAAmB,QAA8T,CAAC;AAO/V,0GAA0G;AAC1G,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAyE,CAAC;AAEvJ,mIAAmI;AACnI,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,GAAG,UAAU,CAKzF;AAED,kGAAkG;AAClG,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG/E;AAED,4EAA4E;AAC5E,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,GAAG,UAAU,KAAG,UAAoE,CAAC;AAE/H;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAuB,GAAG;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAM7O"}
@@ -5,11 +5,46 @@
5
5
  */
6
6
  /** The widest a picture is drawn, by default, in CSS pixels (`PICTURE_WIDTH`). */
7
7
  const WIDTH = 1_200;
8
+ /** The narrowest and widest shape a thumb is cropped to, width over height. */
9
+ export const THUMB_ASPECT = { least: 0.1, most: 10 };
8
10
  /** What is said of a `thumb` that is not a whole number of pixels from 16 to 4096 narrower than the width. */
9
11
  export const THUMB_REFUSED = "The view's pictures thumb is a whole number of pixels from 16 to 4096, narrower than its width (1,200 by default): the size it draws a picture small at (view-pictures-thumb).";
10
- /** Whether `thumb` is a width a view may draw a picture small at, beside `width` (1 200 where it says none). */
11
- export function thumbIsSound(thumb, width) {
12
+ /** What is said of a `thumb` written as a shape that is not one. */
13
+ export const THUMB_SHAPE_REFUSED = `The view's pictures thumb, as a shape, is { "width": <a whole number of pixels from 16 to 4096, narrower than its width>, "aspect": <its width over its height, from ${THUMB_ASPECT.least} to ${THUMB_ASPECT.most}> }, cropped to that shape around each picture's focus; "aspect" may be left out (view-pictures-thumb).`;
14
+ const widthIsSound = (thumb, width) => {
12
15
  const across = typeof width === "number" ? width : WIDTH;
13
16
  return Number.isInteger(thumb) && thumb >= 16 && thumb <= 4_096 && thumb < across;
17
+ };
18
+ /** Whether `thumb` is written as a shape (`{ width, aspect }`) rather than a width or a kind's fields. */
19
+ export const isThumbShape = (thumb) => typeof thumb === "object" && thumb !== null && !Array.isArray(thumb);
20
+ /** Whether `thumb` is a width a view may draw a picture small at, or a shape of one, beside `width` (1 200 where it says none). */
21
+ export function thumbIsSound(thumb, width) {
22
+ if (!isThumbShape(thumb))
23
+ return widthIsSound(thumb, width);
24
+ const { width: across, aspect, ...rest } = thumb;
25
+ if (Object.keys(rest).length > 0 || !widthIsSound(across, width))
26
+ return false;
27
+ return aspect === undefined || (typeof aspect === "number" && Number.isFinite(aspect) && aspect >= THUMB_ASPECT.least && aspect <= THUMB_ASPECT.most);
28
+ }
29
+ /** What is said of a `thumb` that is no sound one, in its own form; nothing where it is sound. */
30
+ export function thumbRefusal(thumb, width) {
31
+ if (thumbIsSound(thumb, width))
32
+ return undefined;
33
+ return isThumbShape(thumb) ? THUMB_SHAPE_REFUSED : THUMB_REFUSED;
34
+ }
35
+ /** A sound thumb as a shape: its width, and its aspect where it has one. */
36
+ export const thumbShapeOf = (thumb) => (typeof thumb === "number" ? { width: thumb } : thumb);
37
+ /**
38
+ * THE PART OF A PICTURE A THUMB OF `aspect` SHOWS, in its pixels: as much of
39
+ * it as that shape holds, its middle as near `focus` as the picture's edges
40
+ * allow — a portrait cropped square around a face high in it keeps the
41
+ * face, not the chest.
42
+ */
43
+ export function cropAround(width, height, aspect, focus = { x: 0.5, y: 0.5 }) {
44
+ const wide = width / height > aspect;
45
+ const w = wide ? Math.max(1, Math.round(height * aspect)) : width;
46
+ const h = wide ? height : Math.max(1, Math.round(width / aspect));
47
+ const clamp = (at, span, whole) => Math.min(whole - span, Math.max(0, Math.round(at - span / 2)));
48
+ return { x: clamp(focus.x * width, w, width), y: clamp(focus.y * height, h, height), width: w, height: h };
14
49
  }
15
50
  //# sourceMappingURL=picture-thumb.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"picture-thumb.js","sourceRoot":"","sources":["../../src/host/picture-thumb.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kFAAkF;AAClF,MAAM,KAAK,GAAG,KAAK,CAAC;AAEpB,8GAA8G;AAC9G,MAAM,CAAC,MAAM,aAAa,GAAG,gLAAgL,CAAC;AAE9M,gHAAgH;AAChH,MAAM,UAAU,YAAY,CAAC,KAAc,EAAE,KAAc;IACzD,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IACzD,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAK,KAAgB,IAAI,EAAE,IAAK,KAAgB,IAAI,KAAK,IAAK,KAAgB,GAAG,MAAM,CAAC;AACxH,CAAC"}
1
+ {"version":3,"file":"picture-thumb.js","sourceRoot":"","sources":["../../src/host/picture-thumb.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kFAAkF;AAClF,MAAM,KAAK,GAAG,KAAK,CAAC;AAapB,+EAA+E;AAC/E,MAAM,CAAC,MAAM,YAAY,GAAG,E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AAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1H,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;AAC7G,CAAC"}
@@ -1,5 +1,7 @@
1
- import type { FileValue } from "@graview/core";
1
+ import type { ViewProblemSaid } from "./problems.js";
2
+ import { type FileValue } from "@graview/core";
2
3
  import type { GuestFile, GuestNode, GuestProps } from "../protocol.js";
4
+ import { type ThumbShape } from "./picture-thumb.js";
3
5
  /**
4
6
  * What a guest asks for: `true`, every picture on the records it is handed;
5
7
  * the kinds whose pictures it draws (`["circuit"]`, FR-220); or an object
@@ -31,13 +33,22 @@ import type { GuestFile, GuestNode, GuestProps } from "../protocol.js";
31
33
  * string or a list under `thumb` names a kind called `thumb` and its
32
34
  * fields, as it always did; a number that is not a sound thumb
33
35
  * (`thumbIsSound`) asks for none, and is said.
36
+ *
37
+ * A THUMB OF A SHAPE (Graview HQ f-picture-thumb-around-focus): `thumb:
38
+ * { width, aspect }` hands each picture a thumb cropped to that width over
39
+ * height around its `focus` (its middle where the record says none), so a
40
+ * grid of square tiles is handed square pictures with the subject in them,
41
+ * not a downscale a tile crops at its middle. A cutout — said by the record,
42
+ * or read off the picture — is never cropped: its thumb is the whole of it
43
+ * at that width, and the view draws it whole. `{ width }` alone is
44
+ * `thumb: <width>`.
34
45
  */
35
46
  export type GuestPictures = true | readonly string[] | {
36
47
  readonly width?: number;
37
48
  readonly records?: PictureRecords | string | readonly string[];
38
49
  readonly most?: number | string | readonly string[];
39
- readonly thumb?: number | string | readonly string[];
40
- readonly [kind: string]: number | string | readonly string[] | PictureRecords | undefined;
50
+ readonly thumb?: number | ThumbShape | string | readonly string[];
51
+ readonly [kind: string]: number | string | readonly string[] | PictureRecords | ThumbShape | undefined;
41
52
  };
42
53
  /** The records whose pictures a view draws: its subject and what is linked to it, and/or these ids. */
43
54
  export interface PictureRecords {
@@ -54,6 +65,8 @@ export declare const isPictureRecords: (value: unknown) => value is PictureRecor
54
65
  * that one, either way round — none where it is drawn over no one record.
55
66
  */
56
67
  export declare function pictureRecordsOf(pictures: GuestPictures, props: Pick<GuestProps, "node" | "edges">): (id: string) => boolean;
68
+ /** The second size a guest draws a picture at, where it asked for a sound one (`thumb`): its width in CSS pixels, and the shape it is cropped to. */
69
+ export declare function pictureThumbShapeOf(pictures: GuestPictures): ThumbShape | undefined;
57
70
  /** The width a guest draws a picture small at, in CSS pixels, where it asked for a second size (`thumb`). */
58
71
  export declare function pictureThumbOf(pictures: GuestPictures): number | undefined;
59
72
  /** Where a guest's host asked for a thumb that is no sound one (a frame's, which no manifest check reads): what is said, once. */
@@ -88,10 +101,17 @@ export declare const isGuestPicture: (file: {
88
101
  readonly type: string;
89
102
  }) => boolean;
90
103
  /** A file as a guest is handed it, before the host has its bytes: no path, and for a picture its facts. */
104
+ /** What the host read of a picture's pixels: its size, and whether it is a cutout (`cutoutOf`). */
105
+ export interface PictureLook {
106
+ readonly width: number;
107
+ readonly height: number;
108
+ readonly cutout?: boolean;
109
+ }
91
110
  export declare function guestFileOf(file: FileValue, more?: {
92
111
  readonly src?: string;
93
112
  readonly thumb?: string;
94
113
  readonly left?: string;
114
+ readonly look?: PictureLook;
95
115
  }): GuestFile;
96
116
  /**
97
117
  * EVERY FILE ON THE RECORDS IN `props`, as `hand` makes it — a field that
@@ -109,15 +129,17 @@ export interface GuestPicturesOptions {
109
129
  /** A picture is ready, or was left out: push again. */
110
130
  readonly moved: () => void;
111
131
  /** A picture was left out, and why, said once. */
112
- readonly onLeft?: (said: string) => void;
132
+ readonly onLeft?: ViewProblemSaid;
113
133
  /**
114
134
  * Where the page fetches a record's file (`FileValue.href`): a host that
115
135
  * serves the app under a base answers `base + href`; undefined leaves the
116
136
  * file out. The href, resolved against the page, by default.
117
137
  */
118
138
  readonly file?: (href: string) => string | undefined;
119
- /** How the bytes are made smaller: to at most `width` pixels across, and `bytes` bytes. The canvas, by default. */
120
- readonly shrink?: (blob: Blob, width: number, bytes: number) => Promise<Blob | undefined>;
139
+ /** How the bytes are made smaller: to at most `width` pixels across, and `bytes` bytes, cropped first to `crop` where a thumb of a shape asks it. The canvas, by default. */
140
+ readonly shrink?: (blob: Blob, width: number, bytes: number, crop?: ThumbCrop) => Promise<Blob | undefined>;
141
+ /** How a picture's pixels are read for its shape (HQ f-view-picture-shape): its size and whether it is a cutout. The canvas, by default (`lookOnCanvas`). */
142
+ readonly look?: (blob: Blob) => Promise<PictureLook | undefined>;
121
143
  }
122
144
  export interface GuestPictureHand {
123
145
  /** `props` with each file as the guest is handed it, starting what has not been fetched. */
@@ -135,6 +157,14 @@ export interface GuestPictureHand {
135
157
  /** Let go of every address made. */
136
158
  dispose(): void;
137
159
  }
160
+ /** What a thumb of a shape is cropped to: its width over its height, around where the subject is. */
161
+ export interface ThumbCrop {
162
+ readonly aspect: number;
163
+ readonly focus: {
164
+ readonly x: number;
165
+ readonly y: number;
166
+ };
167
+ }
138
168
  /**
139
169
  * HOW MANY BYTES A VIEW'S PICTURES COME TO, BEFORE ANY IS FETCHED: the
140
170
  * widest it draws one, in device pixels, the budgets, and what a picture
@@ -150,6 +180,7 @@ export declare function pictureBudget(pictures: GuestPictures, limits: GuestPict
150
180
  perView: number;
151
181
  need: number;
152
182
  thumbNeed: number | undefined;
183
+ aspect: number | undefined;
153
184
  thumbIsSrc: (file: FileValue) => boolean;
154
185
  reckon: (file: FileValue) => number;
155
186
  chosen: (kind: string, field: string) => boolean;
@@ -178,4 +209,15 @@ export declare function standInPictures(props: GuestProps, options: {
178
209
  * no more, and let go when no record handed holds them.
179
210
  */
180
211
  export declare function createGuestPictures(window: Window & typeof globalThis, options: GuestPicturesOptions): GuestPictureHand;
212
+ /**
213
+ * WHETHER A PICTURE IS A CUTOUT (HQ f-view-picture-shape), from its pixels
214
+ * read at `side` by `side` (RGBA, a row at a time): a quarter or more of its
215
+ * edge transparent, or nineteen in twenty of its edge transparent or one
216
+ * plain color — a drawing or a product on white, which a view draws whole
217
+ * rather than crops. A photograph's edge is neither; one whose edge is one
218
+ * dark or plain color reads as one, and is drawn whole.
219
+ */
220
+ export declare function cutoutOf(pixels: ArrayLike<number>, side: number): boolean;
221
+ /** A picture's size and whether it is a cutout, read on a canvas: nothing where the browser cannot decode it. */
222
+ export declare function lookOnCanvas(window: Window & typeof globalThis, blob: Blob): Promise<PictureLook | undefined>;
181
223
  //# sourceMappingURL=pictures.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pictures.d.ts","sourceRoot":"","sources":["../../src/host/pictures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAuBvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,MAAM,aAAa,GACrB,IAAI,GACJ,SAAS,MAAM,EAAE,GACjB;IACE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IAC/D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACpD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACrD,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,G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MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAUzE;AAED,iHAAiH;AACjH,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,UAAU,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAenH"}
@@ -1,4 +1,5 @@
1
- import { THUMB_REFUSED, thumbIsSound } from "./picture-thumb.js";
1
+ import { isFocus } from "@graview/core";
2
+ import { cropAround, isThumbShape, thumbIsSound, thumbRefusal, thumbShapeOf } from "./picture-thumb.js";
2
3
  const isKindList = (pictures) => Array.isArray(pictures);
3
4
  /** `records` as the option it is, not a kind called `records`: an object, which no field list ever was. */
4
5
  export const isPictureRecords = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -30,15 +31,21 @@ export function pictureRecordsOf(pictures, props) {
30
31
  const mostOf = (pictures) => (pictures === true || isKindList(pictures) || typeof pictures.most !== "number" ? Infinity : pictures.most);
31
32
  /** A picture past the most a view said it is handed: handed by its facts and this sentence, said once for them all. */
32
33
  const pastTheMost = (view, most) => `The view ${view} is handed at most ${said(most)} ${most === 1 ? "picture" : "pictures"} ("most"), so those after, in the order its records are handed, come without an address.`;
34
+ /** The thumb a guest asked for, as a width or a shape: a number or `{ width, aspect }` under `thumb`, never a kind called `thumb`'s fields. */
35
+ const askedThumb = (pictures) => (pictures === true || isKindList(pictures) || !(typeof pictures.thumb === "number" || isThumbShape(pictures.thumb)) ? undefined : pictures.thumb);
36
+ /** The second size a guest draws a picture at, where it asked for a sound one (`thumb`): its width in CSS pixels, and the shape it is cropped to. */
37
+ export function pictureThumbShapeOf(pictures) {
38
+ const thumb = askedThumb(pictures);
39
+ return thumb !== undefined && thumbIsSound(thumb, pictures.width) ? thumbShapeOf(thumb) : undefined;
40
+ }
33
41
  /** The width a guest draws a picture small at, in CSS pixels, where it asked for a second size (`thumb`). */
34
42
  export function pictureThumbOf(pictures) {
35
- if (pictures === true || isKindList(pictures) || typeof pictures.thumb !== "number")
36
- return undefined;
37
- return thumbIsSound(pictures.thumb, pictures.width) ? pictures.thumb : undefined;
43
+ return pictureThumbShapeOf(pictures)?.width;
38
44
  }
39
45
  /** Where a guest's host asked for a thumb that is no sound one (a frame's, which no manifest check reads): what is said, once. */
40
46
  export function thumbProblemOf(pictures) {
41
- return pictures !== true && !isKindList(pictures) && typeof pictures.thumb === "number" && pictureThumbOf(pictures) === undefined ? THUMB_REFUSED : undefined;
47
+ const thumb = askedThumb(pictures);
48
+ return thumb === undefined ? undefined : thumbRefusal(thumb, pictures.width);
42
49
  }
43
50
  /** The widest a guest draws a picture, in CSS pixels. */
44
51
  export function pictureWidthOf(pictures) {
@@ -77,7 +84,21 @@ export const PICTURES_SETTLE_MS = 100;
77
84
  export const PICTURE_FETCH_BYTES = 40_000_000;
78
85
  /** Whether a file is a picture a guest is handed an address for: an image, not an SVG, which could act. */
79
86
  export const isGuestPicture = (file) => /^image\//i.test(file.type) && !/^image\/svg/i.test(file.type);
80
- /** A file as a guest is handed it, before the host has its bytes: no path, and for a picture its facts. */
87
+ /** A picture's shape as a view is handed it (HQ f-view-picture-shape): its size, as the record says it or the host measured it, its aspect, whether it is a cutout and where its subject is. */
88
+ function shapeOf(file, look) {
89
+ /* Both from one source: the record's where it says both, else the host's measure of what it hands. */
90
+ const said = file.width !== undefined && file.height !== undefined;
91
+ const width = said ? file.width : look?.width;
92
+ const height = said ? file.height : look?.height;
93
+ const cutout = file.cutout ?? look?.cutout;
94
+ return {
95
+ ...(width !== undefined ? { width } : {}),
96
+ ...(height !== undefined ? { height } : {}),
97
+ ...(width !== undefined && height !== undefined && width > 0 && height > 0 ? { aspect: Math.round((width / height) * 10_000) / 10_000 } : {}),
98
+ ...(cutout !== undefined ? { cutout } : {}),
99
+ ...(isFocus(file.focus) ? { focus: { x: file.focus.x, y: file.focus.y } } : {}),
100
+ };
101
+ }
81
102
  export function guestFileOf(file, more = {}) {
82
103
  const base = { name: file.name, type: file.type, bytes: file.bytes };
83
104
  /* A video (0.1.37) is handed its facts, never an address: the host plays it where the view places `<graview-video>` (media.ts). Whether it has a poster is a fact (f-video-hero); the poster's path is not. */
@@ -86,6 +107,7 @@ export function guestFileOf(file, more = {}) {
86
107
  ...base,
87
108
  ...(file.width !== undefined ? { width: file.width } : {}),
88
109
  ...(file.height !== undefined ? { height: file.height } : {}),
110
+ ...(file.width && file.height ? { aspect: Math.round((file.width / file.height) * 10_000) / 10_000 } : {}),
89
111
  ...(file.caption !== undefined ? { caption: file.caption } : {}),
90
112
  ...(file.duration !== undefined ? { duration: file.duration } : {}),
91
113
  ...(file.poster ? { poster: true } : {}),
@@ -95,8 +117,7 @@ export function guestFileOf(file, more = {}) {
95
117
  return base;
96
118
  return {
97
119
  ...base,
98
- ...(file.width !== undefined ? { width: file.width } : {}),
99
- ...(file.height !== undefined ? { height: file.height } : {}),
120
+ ...shapeOf(file, more.look),
100
121
  ...(file.caption !== undefined ? { caption: file.caption } : {}),
101
122
  ...(more.src !== undefined ? { src: more.src } : {}),
102
123
  ...(more.thumb !== undefined ? { thumb: more.thumb } : {}),
@@ -147,10 +168,16 @@ export function pictureBudget(pictures, limits, devicePixelRatio) {
147
168
  /* As many device pixels as the screen draws a CSS pixel with, up to two. */
148
169
  const need = Math.round(width * Math.min(2, Math.max(1, devicePixelRatio || 1)));
149
170
  const at = (file, across) => Math.min(perFile, Math.ceil(file.bytes * (file.width && file.width > across ? (across / file.width) ** 2 : 1)));
150
- const thumb = pictureThumbOf(pictures);
151
- const thumbNeed = thumb === undefined ? undefined : Math.round(thumb * Math.min(2, Math.max(1, devicePixelRatio || 1)));
152
- /* Whether a picture's thumb is its `src` itself: no wider than the thumb is drawn, so the one address serves both and is reckoned once. */
153
- const thumbIsSrc = (file) => thumbNeed !== undefined && file.width !== undefined && file.width <= thumbNeed;
171
+ const shape = pictureThumbShapeOf(pictures);
172
+ const thumbNeed = shape === undefined ? undefined : Math.round(shape.width * Math.min(2, Math.max(1, devicePixelRatio || 1)));
173
+ const aspect = shape?.aspect;
174
+ /*
175
+ * Whether a picture's thumb is its `src` itself: no wider than the thumb is
176
+ * drawn, so the one address serves both and is reckoned once. A thumb of a
177
+ * shape is its own picture, cropped, but for a cutout the record says is
178
+ * one, which is never cropped.
179
+ */
180
+ const thumbIsSrc = (file) => thumbNeed !== undefined && file.width !== undefined && file.width <= thumbNeed && (aspect === undefined || file.cutout === true);
154
181
  /*
155
182
  * A picture and its thumb, together: both are handed, so both are counted,
156
183
  * before either is made. Erring high: a thumb the page then finds no
@@ -158,7 +185,7 @@ export function pictureBudget(pictures, limits, devicePixelRatio) {
158
185
  * record that says no width is counted at its bytes twice.
159
186
  */
160
187
  const reckon = (file) => at(file, need) + (thumbNeed === undefined || thumbIsSrc(file) ? 0 : at(file, thumbNeed));
161
- return { width, perFile, perView, need, thumbNeed, thumbIsSrc, reckon, chosen: picturesChosen(pictures), most: mostOf(pictures) };
188
+ return { width, perFile, perView, need, thumbNeed, aspect, thumbIsSrc, reckon, chosen: picturesChosen(pictures), most: mostOf(pictures) };
162
189
  }
163
190
  /** A picture heavier, as the record says it, than the host fetches for a view: left out unfetched. */
164
191
  const tooHeavyToFetch = (file, on) => `${namedPicture(file, on)} is left out: at ${said(file.bytes)} bytes it is more than the host fetches for a view.`;
@@ -212,8 +239,9 @@ export function standInPictures(props, options) {
212
239
  * no more, and let go when no record handed holds them.
213
240
  */
214
241
  export function createGuestPictures(window, options) {
215
- const { width, perFile, perView, need, thumbNeed, thumbIsSrc, reckon, chosen, most } = pictureBudget(options.pictures, options.limits, window.devicePixelRatio);
216
- const shrink = options.shrink ?? ((blob, across, bytes) => shrinkOnCanvas(window, blob, across, bytes));
242
+ const { width, perFile, perView, need, thumbNeed, aspect, thumbIsSrc, reckon, chosen, most } = pictureBudget(options.pictures, options.limits, window.devicePixelRatio);
243
+ const shrink = options.shrink ?? ((blob, across, bytes, crop) => shrinkOnCanvas(window, blob, across, bytes, crop));
244
+ const look = options.look ?? ((blob) => lookOnCanvas(window, blob));
217
245
  const entries = new Map();
218
246
  /* Each `src` handed, to what the page draws for it. */
219
247
  const drawnFor = new Map();
@@ -222,7 +250,7 @@ export function createGuestPictures(window, options) {
222
250
  /* A thumb its host asked for that is no sound one: none is made, and it is said once. */
223
251
  const thumbProblem = thumbProblemOf(options.pictures);
224
252
  if (thumbProblem)
225
- queueMicrotask(() => (options.onLeft ? options.onLeft(thumbProblem) : window.console.warn(thumbProblem)));
253
+ queueMicrotask(() => (options.onLeft ? options.onLeft(thumbProblem, { code: "picture-thumb-unsound" }) : window.console.warn(thumbProblem)));
226
254
  /*
227
255
  * PUSHED AGAIN AT MOST ONCE IN `PICTURES_SETTLE_MS` (FR-207): each push is
228
256
  * the view's whole props, drawn and answered, so sixty pictures settling
@@ -254,7 +282,7 @@ export function createGuestPictures(window, options) {
254
282
  if (told.has(text))
255
283
  return;
256
284
  told.add(text);
257
- options.onLeft?.(text);
285
+ options.onLeft?.(text, { code: "picture-left-out" });
258
286
  };
259
287
  const release = (entry) => {
260
288
  if (entry?.state !== "ready")
@@ -339,16 +367,34 @@ export function createGuestPictures(window, options) {
339
367
  }
340
368
  if (blob.size > perFile)
341
369
  return { state: "left", said: `${named(file, on)} is left out: made as small as the ${said(width)} pixels across the view ${options.view} draws a picture at, it is still more than the ${said(perFile)} bytes one picture is handed.` };
370
+ /*
371
+ * Its shape (HQ f-view-picture-shape), read from what is handed — already
372
+ * no wider than the view draws one, so it is small to decode — where the
373
+ * record does not say all of it: the size of `src`, and whether it is a
374
+ * cutout. A PNG made a JPEG lost its transparency for a plain ground,
375
+ * which still reads as one.
376
+ */
377
+ const seen = file.width !== undefined && file.height !== undefined && file.cutout !== undefined ? undefined : await look(blob).catch(() => undefined);
342
378
  const full = await addressOf(blob);
379
+ const shape = seen ? { look: seen } : {};
343
380
  if (thumbNeed === undefined)
344
- return { state: "ready", ...full };
381
+ return { state: "ready", ...full, ...shape };
345
382
  /*
346
383
  * Its second size (`thumb`): made from `src`'s bytes, already no wider than
347
384
  * the view draws one, so the picture as fetched — as large as 40 MB — is
348
385
  * decoded once and let go. Where it is no smaller than `src`, none.
349
386
  */
350
- const small = thumbIsSrc(file) ? undefined : await shrink(blob, thumbNeed, perFile).catch(() => undefined);
351
- return { state: "ready", ...full, ...(small && small.size < blob.size ? { thumb: await addressOf(small) } : {}) };
387
+ /*
388
+ * Of a shape, where it asked one: cropped around the subject — its focus,
389
+ * else its middle — and whole for a cutout, as the record says it or the
390
+ * pixels read. A crop is its own picture, handed whatever it weighs
391
+ * beside `src`; a thumb that is only smaller, only where it is.
392
+ */
393
+ const cutout = file.cutout ?? seen?.cutout;
394
+ const crop = aspect !== undefined && cutout !== true ? { aspect, focus: isFocus(file.focus) ? file.focus : { x: 0.5, y: 0.5 } } : undefined;
395
+ const small = thumbIsSrc(file) && !crop ? undefined : await shrink(blob, thumbNeed, perFile, crop).catch(() => undefined);
396
+ const keep = small !== undefined && (crop ? small.size <= perFile : small.size < blob.size);
397
+ return { state: "ready", ...full, ...shape, ...(keep ? { thumb: await addressOf(small) } : {}) };
352
398
  };
353
399
  const start = (file, on) => {
354
400
  entries.set(file.href, { state: "pending" });
@@ -412,7 +458,7 @@ export function createGuestPictures(window, options) {
412
458
  return guestFileOf(file, { left: entry.said });
413
459
  if (!entry)
414
460
  start(file, on);
415
- return guestFileOf(file, entry?.state === "ready" ? { src: entry.url, ...(entry.thumb ? { thumb: entry.thumb.url } : {}) } : {});
461
+ return guestFileOf(file, entry?.state === "ready" ? { src: entry.url, ...(entry.thumb ? { thumb: entry.thumb.url } : {}), ...(entry.look ? { look: entry.look } : {}) } : {});
416
462
  });
417
463
  /* What no record handed holds any more is let go: its address, and a fetch still on its way. */
418
464
  for (const [href, entry] of entries) {
@@ -437,29 +483,75 @@ export function createGuestPictures(window, options) {
437
483
  },
438
484
  };
439
485
  }
486
+ /** The side of the square a picture is read at for whether it is a cutout: enough to see its edges, little to decode. */
487
+ const LOOK_SIDE = 32;
488
+ /**
489
+ * WHETHER A PICTURE IS A CUTOUT (HQ f-view-picture-shape), from its pixels
490
+ * read at `side` by `side` (RGBA, a row at a time): a quarter or more of its
491
+ * edge transparent, or nineteen in twenty of its edge transparent or one
492
+ * plain color — a drawing or a product on white, which a view draws whole
493
+ * rather than crops. A photograph's edge is neither; one whose edge is one
494
+ * dark or plain color reads as one, and is drawn whole.
495
+ */
496
+ export function cutoutOf(pixels, side) {
497
+ const edge = [];
498
+ for (let at = 0; at < side; at += 1)
499
+ edge.push(at, (side - 1) * side + at);
500
+ for (let at = 1; at < side - 1; at += 1)
501
+ edge.push(at * side, at * side + side - 1);
502
+ const clear = edge.filter((at) => pixels[at * 4 + 3] < 250).length;
503
+ if (clear >= edge.length / 4)
504
+ return true;
505
+ const opaque = edge.filter((at) => pixels[at * 4 + 3] >= 250);
506
+ const mean = [0, 1, 2].map((channel) => opaque.reduce((sum, at) => sum + pixels[at * 4 + channel], 0) / opaque.length);
507
+ const plain = opaque.filter((at) => [0, 1, 2].reduce((sum, channel) => sum + Math.abs(pixels[at * 4 + channel] - mean[channel]), 0) <= 30).length;
508
+ return clear + plain >= edge.length * 0.95;
509
+ }
510
+ /** A picture's size and whether it is a cutout, read on a canvas: nothing where the browser cannot decode it. */
511
+ export async function lookOnCanvas(window, blob) {
512
+ if (typeof window.createImageBitmap !== "function")
513
+ return undefined;
514
+ const bitmap = await window.createImageBitmap(blob);
515
+ try {
516
+ const { width, height } = bitmap;
517
+ const canvas = window.document.createElement("canvas");
518
+ canvas.width = LOOK_SIDE;
519
+ canvas.height = LOOK_SIDE;
520
+ const context = canvas.getContext("2d", { willReadFrequently: true });
521
+ if (!context)
522
+ return { width, height };
523
+ context.drawImage(bitmap, 0, 0, LOOK_SIDE, LOOK_SIDE);
524
+ return { width, height, cutout: cutoutOf(context.getImageData(0, 0, LOOK_SIDE, LOOK_SIDE).data, LOOK_SIDE) };
525
+ }
526
+ finally {
527
+ bitmap.close();
528
+ }
529
+ }
440
530
  /**
441
531
  * A PICTURE MADE SMALLER ON A CANVAS: at most `across` pixels wide, kept in
442
532
  * its own type where the canvas writes it (a JPEG stays a JPEG), and a JPEG
443
- * where that is still heavier than `bytes`. Nothing where the browser
444
- * cannot decode it.
533
+ * where that is still heavier than `bytes`; cropped first, where `crop`
534
+ * says, to that shape around its focus (`cropAround`). Nothing where the
535
+ * browser cannot decode it.
445
536
  */
446
- async function shrinkOnCanvas(window, blob, across, bytes) {
537
+ async function shrinkOnCanvas(window, blob, across, bytes, crop) {
447
538
  if (typeof window.createImageBitmap !== "function")
448
539
  return undefined;
449
540
  const bitmap = await window.createImageBitmap(blob);
450
541
  try {
451
- if (bitmap.width <= across && blob.size <= bytes)
542
+ if (!crop && bitmap.width <= across && blob.size <= bytes)
452
543
  return blob;
453
- const scale = Math.min(1, across / bitmap.width);
454
- const w = Math.max(1, Math.round(bitmap.width * scale));
455
- const h = Math.max(1, Math.round(bitmap.height * scale));
544
+ const part = crop ? cropAround(bitmap.width, bitmap.height, crop.aspect, crop.focus) : { x: 0, y: 0, width: bitmap.width, height: bitmap.height };
545
+ const scale = Math.min(1, across / part.width);
546
+ const w = Math.max(1, Math.round(part.width * scale));
547
+ const h = Math.max(1, Math.round(part.height * scale));
456
548
  const canvas = window.document.createElement("canvas");
457
549
  canvas.width = w;
458
550
  canvas.height = h;
459
551
  const context = canvas.getContext("2d");
460
552
  if (!context)
461
553
  return undefined;
462
- context.drawImage(bitmap, 0, 0, w, h);
554
+ context.drawImage(bitmap, part.x, part.y, part.width, part.height, 0, 0, w, h);
463
555
  const write = (type) => new Promise((done) => canvas.toBlob(done, type, 0.85));
464
556
  const own = /^image\/(jpeg|webp|png)$/i.test(blob.type) ? blob.type : "image/png";
465
557
  const first = await write(own);