@gjsify/adwaita-core 0.64.33-next.323 → 0.64.34

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 @@
1
+ import"./_virtual/_rolldown/runtime.js";const e=360,t=1,n=1.5,r=600;function clampAppScale(e){return Number.isFinite(e)?Math.round(Math.min(n,Math.max(1,e))*1e3)/1e3:1}function deriveAppScale(e){let t=Math.min(e.widthDips,e.heightDips);return!Number.isFinite(t)||t<=0||t>=600?1:clampAppScale(t/360)}function resolveAppScale(e,t){return clampAppScale(e===`auto`?t:e)}function scaleDip(e,t){return!Number.isFinite(e)||!Number.isFinite(t)?e:Math.round(e*t*1e3)/1e3}function appScaleChoices(e=.1){let t=Number.isFinite(e)&&e>0?e:.1,r=Math.floor((n-1)/t+1e-9),i=[];for(let e=0;e<=r;e++)i.push(clampAppScale(1+e*t));return i[i.length-1]!==1.5&&i.push(n),i}function parseAppScaleSetting(e){if(typeof e==`number`)return clampAppScale(e);if(typeof e==`string`&&e.trim()!==``&&e!==`auto`){let t=Number(e);if(Number.isFinite(t))return clampAppScale(t)}return`auto`}export{n as APP_SCALE_MAX,t as APP_SCALE_MIN,e as APP_SCALE_REFERENCE_WIDTH,r as APP_SCALE_WIDE_WIDTH,appScaleChoices,clampAppScale,deriveAppScale,parseAppScaleSetting,resolveAppScale,scaleDip};
@@ -1 +1,2 @@
1
- import"./_virtual/_rolldown/runtime.js";const e=String.raw`\/\*[\s\S]*?\*\/|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|url\([^)]*\)`,t=String.raw`(?<![\w.#-])([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)px(?![\w-])`;function cssPxToDip(n){return n.replace(RegExp(`${e}|${t}`,`gi`),(e,t)=>t===void 0?e:t)}export{cssPxToDip};
1
+ import"./_virtual/_rolldown/runtime.js";const e=String.raw`\/\*[\s\S]*?\*\/|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|url\([^)]*\)`,t=String.raw`(?<![\w.#-])([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)px(?![\w-])`;function cssPxToDip(n){return n.replace(RegExp(`${e}|${t}`,`gi`),(e,t)=>t===void 0?e:t)}const n=`font-size.line-height.margin.margin-top.margin-right.margin-bottom.margin-left.padding.padding-top.padding-right.padding-bottom.padding-left.width.height.min-width.min-height.border-radius.border-top-left-radius.border-top-right-radius.border-bottom-right-radius.border-bottom-left-radius.border-width.border-top-width.border-right-width.border-bottom-width.border-left-width`.split(`.`),r=new Set(n),i=String.raw`(?<![\w.#-])([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(px)?(?![\w%.-])`;function roundLength(e){return String(Math.round(e*1e3)/1e3)}function scaleLengthValue(t,n){let r=!1;return{text:t.replace(RegExp(`${e}|${i}`,`gi`),(e,t,i)=>t===void 0?e:(r=!0,`${roundLength(Number(t)*n)}${i??``}`)),scaled:r}}function stripComments(e){return e.replace(/\/\*[\s\S]*?\*\//g,` `)}function closingBrace(e,t){let n=0;for(let r=t;r<e.length;r++){let t=e[r];if(t===`/`&&e[r+1]===`*`){let t=e.indexOf(`*/`,r+2);r=t===-1?e.length:t+1}else if(t===`"`||t===`'`)for(r++;r<e.length&&e[r]!==t;r++)e[r]===`\\`&&r++;else if(t===`{`)n++;else if(t===`}`&&--n===0)return r+1}return e.length}function splitDeclarations(e){let t=[],n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i];if(a===`/`&&e[i+1]===`*`){let t=e.indexOf(`*/`,i+2);i=t===-1?e.length:t+1}else if(a===`"`||a===`'`)for(i++;i<e.length&&e[i]!==a;i++)e[i]===`\\`&&i++;else a===`(`?n++:a===`)`?n--:a===`;`&&n===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}function scaleDeclarations(e,t){let n=[];for(let i of splitDeclarations(e)){let e=stripComments(i),a=e.indexOf(`:`);if(a===-1)continue;let o=e.slice(0,a).trim().toLowerCase();if(!r.has(o))continue;let{text:s,scaled:c}=scaleLengthValue(e.slice(a+1),t);c&&n.push(`${o}:${s.replace(/\s+$/,``)}`)}return n.join(`; `)}function scaleAdwaitaCss(e,t){if(!Number.isFinite(t)||t<=0)return``;let n=[],r=0;for(let i=0;i<e.length;i++){let a=e[i];if(a===`/`&&e[i+1]===`*`){let t=e.indexOf(`*/`,i+2);i=t===-1?e.length:t+1}else if(a===`"`||a===`'`)for(i++;i<e.length&&e[i]!==a;i++)e[i]===`\\`&&i++;else if(a===`;`)r=i+1;else if(a===`{`){let a=closingBrace(e,i),o=stripComments(e.slice(r,i)).trim(),s=e.slice(i+1,a-1);if(o.startsWith(`@`)){let e=/^@[\w-]*/.exec(o)?.[0].toLowerCase();if(e===`@media`||e===`@supports`){let e=scaleAdwaitaCss(s,t);e!==``&&n.push(`${o} { ${e} }`)}}else if(o!==``){let e=scaleDeclarations(s,t);e!==``&&n.push(`${o} { ${e} }`)}i=a-1,r=a}}return n.join(`
2
+ `)}export{n as SCALED_CSS_PROPERTIES,cssPxToDip,scaleAdwaitaCss};
@@ -0,0 +1,47 @@
1
+ /** What the interface scale is set to: a factor, or `'auto'` for the one derived from the screen. */
2
+ export type AppScaleSetting = 'auto' | number;
3
+ /** The logical width a libadwaita stylesheet is authored for. */
4
+ export declare const APP_SCALE_REFERENCE_WIDTH = 360;
5
+ /** The authored size. Below it the app would be smaller than the stylesheet means it to be. */
6
+ export declare const APP_SCALE_MIN = 1;
7
+ /** Past this a phone layout no longer fits the breakpoints it declares. */
8
+ export declare const APP_SCALE_MAX = 1.5;
9
+ /** Android's `sw600dp`: at or above this shortest edge the window is wide enough as authored. */
10
+ export declare const APP_SCALE_WIDE_WIDTH = 600;
11
+ /** The screen the scale is derived from, in device-independent pixels. */
12
+ export interface AppScaleScreen {
13
+ readonly widthDips: number;
14
+ readonly heightDips: number;
15
+ }
16
+ /** `scale` held to `[APP_SCALE_MIN, APP_SCALE_MAX]` and three decimals; a non-number becomes 1. */
17
+ export declare function clampAppScale(scale: number): number;
18
+ /**
19
+ * The scale a screen asks for: its shortest edge over the authored width, clamped.
20
+ *
21
+ * The SHORTEST edge, so that turning the device does not resize the interface — a phone is a
22
+ * phone in landscape too. A screen at or past {@link APP_SCALE_WIDE_WIDTH} is left at 1.
23
+ */
24
+ export declare function deriveAppScale(screen: AppScaleScreen): number;
25
+ /** The factor to apply: the user's number when they set one, otherwise the derived default. */
26
+ export declare function resolveAppScale(setting: AppScaleSetting, derived: number): number;
27
+ /**
28
+ * A length the code sets itself, scaled — the counterpart to `scaleAdwaitaCss` for the sizes no
29
+ * stylesheet reaches: an icon's rendered square, a drag grip's height, an avatar's side.
30
+ *
31
+ * Rounded the way the CSS lengths are, so a constant and the rule drawn next to it agree. The
32
+ * scale is used as given, not clamped: it comes from `resolveAppScale`, which already clamped it.
33
+ *
34
+ * NOT for breakpoints. A width a layout DECIDES by (`sw600dp`, a dialog's max width, a carousel's
35
+ * fallback page) describes the screen, not the drawing on it, and scaling it would move the line
36
+ * the layout switches at.
37
+ */
38
+ export declare function scaleDip(length: number, scale: number): number;
39
+ /**
40
+ * The factors a chooser can offer, from {@link APP_SCALE_MIN} to {@link APP_SCALE_MAX}.
41
+ *
42
+ * Here rather than in the app, so a setting cannot offer a factor the clamp refuses: a list that
43
+ * went past the ceiling would show an entry that silently selects a different one.
44
+ */
45
+ export declare function appScaleChoices(step?: number): number[];
46
+ /** `'auto'`, or the clamped number — what a stored setting means after it is read back. */
47
+ export declare function parseAppScaleSetting(value: unknown): AppScaleSetting;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -1,2 +1,24 @@
1
1
  /** `12px` -> `12`, `0 -4.5px` -> `0 -4.5`; everything else, and anything quoted or commented, as is. */
2
2
  export declare function cssPxToDip(css: string): string;
3
+ /**
4
+ * The declarations an app scale multiplies: lengths, and nothing that only looks like one.
5
+ *
6
+ * `letter-spacing` is absent on purpose — NativeScript reads it as a multiple of the font size,
7
+ * so it already follows a scaled `font-size` and scaling it again would widen the tracking.
8
+ */
9
+ export declare const SCALED_CSS_PROPERTIES: readonly string[];
10
+ /**
11
+ * The override sheet that puts `scale` over every length of `css`.
12
+ *
13
+ * Style rules keep their selector; `@media` and `@supports` keep their condition, so a rule that
14
+ * only applies on a wide window still only applies there. `@keyframes`, `@font-face` and the
15
+ * other at-rules carry no layout length and are dropped. A rule left with no length declaration
16
+ * is dropped too, so the sheet is always a fraction of the one it came from.
17
+ *
18
+ * Pure, and length-only by construction: it can never clobber the append-only accent and named
19
+ * colour overrides (`widgets/named-colors-theme.ts`), because it emits no colour.
20
+ *
21
+ * @param css a stylesheet whose `px` have already been dropped (see {@link cssPxToDip}).
22
+ * @param scale the factor; `1` emits the original lengths, which is how a scale is taken back.
23
+ */
24
+ export declare function scaleAdwaitaCss(css: string, scale: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/adwaita-core",
3
- "version": "0.64.33-next.323",
3
+ "version": "0.64.34",
4
4
  "description": "Headless Adwaita widget behavior (breakpoint condition grammar + apply/unapply state machine, color-scheme observable, avatar derivation) shared by the web and NativeScript Adwaita renderers — pure TS, no platform imports",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -33,6 +33,10 @@
33
33
  "./css-length": {
34
34
  "types": "./lib/types/css-length.d.ts",
35
35
  "default": "./lib/esm/css-length.js"
36
+ },
37
+ "./app-scale": {
38
+ "types": "./lib/types/app-scale.d.ts",
39
+ "default": "./lib/esm/app-scale.js"
36
40
  }
37
41
  },
38
42
  "files": [
@@ -71,9 +75,9 @@
71
75
  "headless"
72
76
  ],
73
77
  "devDependencies": {
74
- "@gjsify/cli": "0.64.33-next.323",
78
+ "@gjsify/cli": "^0.64.34",
75
79
  "@gjsify/node-gi": "file:../../../packages/node-gi/node-gi",
76
- "@gjsify/unit": "0.64.33-next.323",
80
+ "@gjsify/unit": "^0.64.34",
77
81
  "@types/node": "^25.9.2",
78
82
  "typescript": "^6.0.3"
79
83
  },
@@ -96,6 +100,5 @@
96
100
  "bugs": {
97
101
  "url": "https://github.com/gjsify/gjsify/issues"
98
102
  },
99
- "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/web/adwaita-core#readme",
100
- "gitHead": "603d30dc7b5600376fca2b715ecc154cc12b4b31"
103
+ "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/web/adwaita-core#readme"
101
104
  }