@pie-players/pie-players-shared 0.3.58 → 0.3.59
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.
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure browser-zoom compensation math (framework-agnostic, no Svelte runes).
|
|
3
|
+
*
|
|
4
|
+
* Browser zoom is approximated as outerWidth / innerWidth: outerWidth is the
|
|
5
|
+
* OS window size (zoom-independent) while innerWidth is in CSS pixels (shrinks
|
|
6
|
+
* as zoom increases). Callers apply the returned factor via CSS `zoom` so an
|
|
7
|
+
* element that would otherwise keep enlarging past `maxZoom` compounds back
|
|
8
|
+
* down to the cap.
|
|
9
|
+
*
|
|
10
|
+
* This module is tsc-buildable and shipped in `dist`, so it can be consumed by
|
|
11
|
+
* packages that resolve `@pie-players/pie-players-shared` from its published
|
|
12
|
+
* build (e.g. the assessment-toolkit CE bundle) as well as by the reactive
|
|
13
|
+
* Svelte wrapper in `./use-zoom-compensation.svelte.ts`, which packages built
|
|
14
|
+
* with Vite alias to source.
|
|
15
|
+
*/
|
|
16
|
+
export type ZoomCompensationOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* Zoom level (as a ratio, e.g. `2` for 200%) below which the factor is 1.
|
|
19
|
+
* Above this level the factor shrinks as `maxZoom / zoom`.
|
|
20
|
+
*/
|
|
21
|
+
maxZoom: number;
|
|
22
|
+
/** Lower bound on the returned factor. */
|
|
23
|
+
minCompensation: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Shared zoom-cap settings for the toolbar icon buttons (the TTS play button and
|
|
27
|
+
* the calculator button) so both compensate identically and can't drift apart.
|
|
28
|
+
* Grow normally up to 200%, then freeze; the 0.25 floor keeps the cap holding
|
|
29
|
+
* past 500% browser zoom (see the minCompensation note in
|
|
30
|
+
* section-player's SectionPlayerTabbedContent).
|
|
31
|
+
*/
|
|
32
|
+
export declare const ICON_BUTTON_ZOOM_OPTIONS: ZoomCompensationOptions;
|
|
33
|
+
/**
|
|
34
|
+
* Approximate the browser zoom level from an outer/inner width pair. Falls
|
|
35
|
+
* back to 1 (100%) if the ratio isn't finite or is non-positive (which happens
|
|
36
|
+
* during SSR, in headless envs, and briefly during resize on some browsers).
|
|
37
|
+
*/
|
|
38
|
+
export declare function approximateZoomFromWidths(outerWidth: number, innerWidth: number): number;
|
|
39
|
+
/**
|
|
40
|
+
* Pure zoom-compensation math: exactly 1 at zoom <= maxZoom, then shrinks as
|
|
41
|
+
* `maxZoom / zoom`, floored at `minCompensation` to guard against inflated
|
|
42
|
+
* ratios from window chrome / side panels making the element unusably small.
|
|
43
|
+
*/
|
|
44
|
+
export declare function computeZoomCompensation(zoom: number, maxZoom: number, minCompensation: number): number;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure browser-zoom compensation math (framework-agnostic, no Svelte runes).
|
|
3
|
+
*
|
|
4
|
+
* Browser zoom is approximated as outerWidth / innerWidth: outerWidth is the
|
|
5
|
+
* OS window size (zoom-independent) while innerWidth is in CSS pixels (shrinks
|
|
6
|
+
* as zoom increases). Callers apply the returned factor via CSS `zoom` so an
|
|
7
|
+
* element that would otherwise keep enlarging past `maxZoom` compounds back
|
|
8
|
+
* down to the cap.
|
|
9
|
+
*
|
|
10
|
+
* This module is tsc-buildable and shipped in `dist`, so it can be consumed by
|
|
11
|
+
* packages that resolve `@pie-players/pie-players-shared` from its published
|
|
12
|
+
* build (e.g. the assessment-toolkit CE bundle) as well as by the reactive
|
|
13
|
+
* Svelte wrapper in `./use-zoom-compensation.svelte.ts`, which packages built
|
|
14
|
+
* with Vite alias to source.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Shared zoom-cap settings for the toolbar icon buttons (the TTS play button and
|
|
18
|
+
* the calculator button) so both compensate identically and can't drift apart.
|
|
19
|
+
* Grow normally up to 200%, then freeze; the 0.25 floor keeps the cap holding
|
|
20
|
+
* past 500% browser zoom (see the minCompensation note in
|
|
21
|
+
* section-player's SectionPlayerTabbedContent).
|
|
22
|
+
*/
|
|
23
|
+
export const ICON_BUTTON_ZOOM_OPTIONS = {
|
|
24
|
+
maxZoom: 2,
|
|
25
|
+
minCompensation: 0.25,
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Approximate the browser zoom level from an outer/inner width pair. Falls
|
|
29
|
+
* back to 1 (100%) if the ratio isn't finite or is non-positive (which happens
|
|
30
|
+
* during SSR, in headless envs, and briefly during resize on some browsers).
|
|
31
|
+
*/
|
|
32
|
+
export function approximateZoomFromWidths(outerWidth, innerWidth) {
|
|
33
|
+
const ratio = outerWidth / innerWidth;
|
|
34
|
+
return Number.isFinite(ratio) && ratio > 0 ? ratio : 1;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Pure zoom-compensation math: exactly 1 at zoom <= maxZoom, then shrinks as
|
|
38
|
+
* `maxZoom / zoom`, floored at `minCompensation` to guard against inflated
|
|
39
|
+
* ratios from window chrome / side panels making the element unusably small.
|
|
40
|
+
*/
|
|
41
|
+
export function computeZoomCompensation(zoom, maxZoom, minCompensation) {
|
|
42
|
+
return Math.max(minCompensation, Math.min(1, maxZoom / zoom));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=zoom-compensation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zoom-compensation.js","sourceRoot":"","sources":["../../src/ui/zoom-compensation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA4B;IAChE,OAAO,EAAE,CAAC;IACV,eAAe,EAAE,IAAI;CACrB,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACxC,UAAkB,EAClB,UAAkB;IAElB,MAAM,KAAK,GAAG,UAAU,GAAG,UAAU,CAAC;IACtC,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACtC,IAAY,EACZ,OAAe,EACf,eAAuB;IAEvB,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["/**\n * Pure browser-zoom compensation math (framework-agnostic, no Svelte runes).\n *\n * Browser zoom is approximated as outerWidth / innerWidth: outerWidth is the\n * OS window size (zoom-independent) while innerWidth is in CSS pixels (shrinks\n * as zoom increases). Callers apply the returned factor via CSS `zoom` so an\n * element that would otherwise keep enlarging past `maxZoom` compounds back\n * down to the cap.\n *\n * This module is tsc-buildable and shipped in `dist`, so it can be consumed by\n * packages that resolve `@pie-players/pie-players-shared` from its published\n * build (e.g. the assessment-toolkit CE bundle) as well as by the reactive\n * Svelte wrapper in `./use-zoom-compensation.svelte.ts`, which packages built\n * with Vite alias to source.\n */\n\nexport type ZoomCompensationOptions = {\n\t/**\n\t * Zoom level (as a ratio, e.g. `2` for 200%) below which the factor is 1.\n\t * Above this level the factor shrinks as `maxZoom / zoom`.\n\t */\n\tmaxZoom: number;\n\t/** Lower bound on the returned factor. */\n\tminCompensation: number;\n};\n\n/**\n * Shared zoom-cap settings for the toolbar icon buttons (the TTS play button and\n * the calculator button) so both compensate identically and can't drift apart.\n * Grow normally up to 200%, then freeze; the 0.25 floor keeps the cap holding\n * past 500% browser zoom (see the minCompensation note in\n * section-player's SectionPlayerTabbedContent).\n */\nexport const ICON_BUTTON_ZOOM_OPTIONS: ZoomCompensationOptions = {\n\tmaxZoom: 2,\n\tminCompensation: 0.25,\n};\n\n/**\n * Approximate the browser zoom level from an outer/inner width pair. Falls\n * back to 1 (100%) if the ratio isn't finite or is non-positive (which happens\n * during SSR, in headless envs, and briefly during resize on some browsers).\n */\nexport function approximateZoomFromWidths(\n\touterWidth: number,\n\tinnerWidth: number,\n): number {\n\tconst ratio = outerWidth / innerWidth;\n\treturn Number.isFinite(ratio) && ratio > 0 ? ratio : 1;\n}\n\n/**\n * Pure zoom-compensation math: exactly 1 at zoom <= maxZoom, then shrinks as\n * `maxZoom / zoom`, floored at `minCompensation` to guard against inflated\n * ratios from window chrome / side panels making the element unusably small.\n */\nexport function computeZoomCompensation(\n\tzoom: number,\n\tmaxZoom: number,\n\tminCompensation: number,\n): number {\n\treturn Math.max(minCompensation, Math.min(1, maxZoom / zoom));\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-players/pie-players-shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.59",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared runtime + UI utilities for PIE players",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,6 +60,10 @@
|
|
|
60
60
|
"./nds-icon-button": {
|
|
61
61
|
"types": "./dist/components/vendor/nds/nds-icon-button.d.ts",
|
|
62
62
|
"import": "./dist/components/vendor/nds/nds-icon-button.js"
|
|
63
|
+
},
|
|
64
|
+
"./ui/zoom-compensation": {
|
|
65
|
+
"types": "./dist/ui/zoom-compensation.d.ts",
|
|
66
|
+
"import": "./dist/ui/zoom-compensation.js"
|
|
63
67
|
}
|
|
64
68
|
},
|
|
65
69
|
"files": [
|