@welcome-back/brand 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,7 @@ Use it for loading moments that mean "on the way to the next step".
19
19
  - [API](#api)
20
20
  - [Examples](#examples)
21
21
  - [POS design tokens](#pos-design-tokens)
22
+ - [Product image frames](#product-image-frames)
22
23
  - [Accessibility](#accessibility)
23
24
  - [Where to use it, and where not](#where-to-use-it-and-where-not)
24
25
  - [Troubleshooting](#troubleshooting)
@@ -319,6 +320,28 @@ POS_TOKENS['--wb-accent']; // '#171717'
319
320
 
320
321
  `posTokensCss(selector)` returns the same rule for another selector.
321
322
 
323
+ ## Product image frames
324
+
325
+ The frames a product photo is shown in: `1:1`, `4:3`, `3:2`, `16:9`. The
326
+ dashboard cropper saves one square photo. The digital menu, the kiosk and the
327
+ POS show it centered with `object-cover` in one of these frames, and the cropper
328
+ draws a guide for each one. So what the owner crops is what each surface shows.
329
+
330
+ A surface that shows a product photo in a frame outside this list breaks that
331
+ promise. Add the frame here, or use one that is already here.
332
+
333
+ ```tsx
334
+ import {
335
+ productImageAspectRatio,
336
+ productImageKeptArea,
337
+ } from '@welcome-back/brand';
338
+
339
+ <div style={{ aspectRatio: productImageAspectRatio('4:3') }}>…</div>;
340
+ productImageKeptArea('16:9'); // { width: 1, height: 0.5625 } of the square, centered
341
+ ```
342
+
343
+ `PRODUCT_IMAGE_FRAMES` holds the raw `{ width, height }` of each frame.
344
+
322
345
  ## Accessibility
323
346
 
324
347
  - **Give exactly one accessible name per loading state.** Either put `label` on
package/dist/cjs/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.posTokensCss = exports.POS_TOKENS = exports.RunnerLoader = void 0;
3
+ exports.productImageKeptArea = exports.productImageAspectRatio = exports.PRODUCT_IMAGE_FRAMES = exports.posTokensCss = exports.POS_TOKENS = exports.RunnerLoader = void 0;
4
4
  var RunnerLoader_js_1 = require("./RunnerLoader.js");
5
5
  Object.defineProperty(exports, "RunnerLoader", { enumerable: true, get: function () { return RunnerLoader_js_1.RunnerLoader; } });
6
6
  var posTokens_js_1 = require("./posTokens.js");
7
7
  Object.defineProperty(exports, "POS_TOKENS", { enumerable: true, get: function () { return posTokens_js_1.POS_TOKENS; } });
8
8
  Object.defineProperty(exports, "posTokensCss", { enumerable: true, get: function () { return posTokens_js_1.posTokensCss; } });
9
+ var productImageFrames_js_1 = require("./productImageFrames.js");
10
+ Object.defineProperty(exports, "PRODUCT_IMAGE_FRAMES", { enumerable: true, get: function () { return productImageFrames_js_1.PRODUCT_IMAGE_FRAMES; } });
11
+ Object.defineProperty(exports, "productImageAspectRatio", { enumerable: true, get: function () { return productImageFrames_js_1.productImageAspectRatio; } });
12
+ Object.defineProperty(exports, "productImageKeptArea", { enumerable: true, get: function () { return productImageFrames_js_1.productImageKeptArea; } });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRODUCT_IMAGE_FRAMES = void 0;
4
+ exports.productImageAspectRatio = productImageAspectRatio;
5
+ exports.productImageKeptArea = productImageKeptArea;
6
+ /**
7
+ * The frames a product photo is shown in. The dashboard cropper saves one
8
+ * square photo; the digital menu (catalog-ui), the kiosk and the POS show it
9
+ * centered with `object-cover` in one of these frames. The cropper draws a
10
+ * guide for each frame, so what the owner crops is what each surface shows.
11
+ *
12
+ * A surface that shows a product photo in a frame outside this list breaks
13
+ * that promise: add the frame here, or use one that is already here.
14
+ */
15
+ exports.PRODUCT_IMAGE_FRAMES = {
16
+ "1:1": { width: 1, height: 1 },
17
+ "4:3": { width: 4, height: 3 },
18
+ "3:2": { width: 3, height: 2 },
19
+ "16:9": { width: 16, height: 9 },
20
+ };
21
+ /** CSS `aspect-ratio` value for a frame, e.g. `"4 / 3"`. */
22
+ function productImageAspectRatio(frame) {
23
+ const { width, height } = exports.PRODUCT_IMAGE_FRAMES[frame];
24
+ return `${width} / ${height}`;
25
+ }
26
+ /**
27
+ * The part of the square photo a frame keeps, centered, as fractions of the
28
+ * square's side. Every frame is as wide as or wider than it is tall, so it
29
+ * keeps the full width and cuts the top and bottom equally.
30
+ */
31
+ function productImageKeptArea(frame) {
32
+ const { width, height } = exports.PRODUCT_IMAGE_FRAMES[frame];
33
+ return { width: 1, height: height / width };
34
+ }
@@ -2,3 +2,5 @@ export { RunnerLoader } from "./RunnerLoader.js";
2
2
  export type { RunnerLoaderProps } from "./RunnerLoader.js";
3
3
  export { POS_TOKENS, posTokensCss } from "./posTokens.js";
4
4
  export type { PosToken } from "./posTokens.js";
5
+ export { PRODUCT_IMAGE_FRAMES, productImageAspectRatio, productImageKeptArea, } from "./productImageFrames.js";
6
+ export type { ProductImageFrame } from "./productImageFrames.js";
package/dist/esm/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { RunnerLoader } from "./RunnerLoader.js";
2
2
  export { POS_TOKENS, posTokensCss } from "./posTokens.js";
3
+ export { PRODUCT_IMAGE_FRAMES, productImageAspectRatio, productImageKeptArea, } from "./productImageFrames.js";
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The frames a product photo is shown in. The dashboard cropper saves one
3
+ * square photo; the digital menu (catalog-ui), the kiosk and the POS show it
4
+ * centered with `object-cover` in one of these frames. The cropper draws a
5
+ * guide for each frame, so what the owner crops is what each surface shows.
6
+ *
7
+ * A surface that shows a product photo in a frame outside this list breaks
8
+ * that promise: add the frame here, or use one that is already here.
9
+ */
10
+ export declare const PRODUCT_IMAGE_FRAMES: {
11
+ readonly "1:1": {
12
+ readonly width: 1;
13
+ readonly height: 1;
14
+ };
15
+ readonly "4:3": {
16
+ readonly width: 4;
17
+ readonly height: 3;
18
+ };
19
+ readonly "3:2": {
20
+ readonly width: 3;
21
+ readonly height: 2;
22
+ };
23
+ readonly "16:9": {
24
+ readonly width: 16;
25
+ readonly height: 9;
26
+ };
27
+ };
28
+ export type ProductImageFrame = keyof typeof PRODUCT_IMAGE_FRAMES;
29
+ /** CSS `aspect-ratio` value for a frame, e.g. `"4 / 3"`. */
30
+ export declare function productImageAspectRatio(frame: ProductImageFrame): string;
31
+ /**
32
+ * The part of the square photo a frame keeps, centered, as fractions of the
33
+ * square's side. Every frame is as wide as or wider than it is tall, so it
34
+ * keeps the full width and cuts the top and bottom equally.
35
+ */
36
+ export declare function productImageKeptArea(frame: ProductImageFrame): {
37
+ width: number;
38
+ height: number;
39
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The frames a product photo is shown in. The dashboard cropper saves one
3
+ * square photo; the digital menu (catalog-ui), the kiosk and the POS show it
4
+ * centered with `object-cover` in one of these frames. The cropper draws a
5
+ * guide for each frame, so what the owner crops is what each surface shows.
6
+ *
7
+ * A surface that shows a product photo in a frame outside this list breaks
8
+ * that promise: add the frame here, or use one that is already here.
9
+ */
10
+ export const PRODUCT_IMAGE_FRAMES = {
11
+ "1:1": { width: 1, height: 1 },
12
+ "4:3": { width: 4, height: 3 },
13
+ "3:2": { width: 3, height: 2 },
14
+ "16:9": { width: 16, height: 9 },
15
+ };
16
+ /** CSS `aspect-ratio` value for a frame, e.g. `"4 / 3"`. */
17
+ export function productImageAspectRatio(frame) {
18
+ const { width, height } = PRODUCT_IMAGE_FRAMES[frame];
19
+ return `${width} / ${height}`;
20
+ }
21
+ /**
22
+ * The part of the square photo a frame keeps, centered, as fractions of the
23
+ * square's side. Every frame is as wide as or wider than it is tall, so it
24
+ * keeps the full width and cuts the top and bottom equally.
25
+ */
26
+ export function productImageKeptArea(frame) {
27
+ const { width, height } = PRODUCT_IMAGE_FRAMES[frame];
28
+ return { width: 1, height: height / width };
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@welcome-back/brand",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "WelcomeBack brand assets for React apps: the running-W loader and the POS design tokens.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {