@seed-design/css 1.2.16 → 1.2.17

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/theming/index.cjs CHANGED
@@ -1,5 +1,32 @@
1
1
  const { DefaultColorModeValue, isValidColorMode } = require("./mode.cjs");
2
2
 
3
+ // Never write a comment inside the template literal below. It is emitted
4
+ // verbatim into an inline <script>, so a comment there is string content rather
5
+ // than source: the bundler minifying this module cannot reach it, and whether
6
+ // the host's HTML pipeline minifies an injected inline script is out of this
7
+ // package's hands. Every such comment ships on every page load. The rationale
8
+ // for what the snippet does lives here instead.
9
+ //
10
+ // `--seed-static-font-scale`, written outside the `fontScaling` gate: Android
11
+ // WebView multiplies every computed font-size and line-height by
12
+ // Configuration.fontScale whether or not the app opted in, so the `*-static`
13
+ // tokens have to divide it back out either way. The option picks whether SEED
14
+ // *follows* the user's scale, not whether the WebView applies one. iOS needs
15
+ // nothing here, because its scaling arrives through `-apple-system-body`
16
+ // inheritance, which the gate does control, and a literal px is never inflated.
17
+ // The measured scale stays uncapped because it is a divisor: the tokens cancel
18
+ // textZoom only by dividing by exactly what the WebView multiplied back in,
19
+ // whatever cap the native app chose.
20
+ //
21
+ // `data-seed-font-multiplier`, written on both platforms inside the gate: it
22
+ // reports how much SEED grew the text, not how large a step the user picked.
23
+ // On iOS the measurement is normalized to the web 16px baseline and then
24
+ // clamped to the cap iOS actually applies, the 1.35 that globalCss sets as
25
+ // `--seed-font-size-limit-max`; the Dynamic Type accessibility steps reach 3.1
26
+ // and would otherwise overstate it. On Android the token clamp bounds the same
27
+ // value to [`--seed-font-size-limit-min`, `--seed-font-size-limit-max`], so
28
+ // past the cap it stays deliberately below the raw scale measured above.
29
+
3
30
  function generateThemingScript({ mode = DefaultColorModeValue, fontScaling = false }) {
4
31
  if (!isValidColorMode(mode)) {
5
32
  throw new Error(`Invalid color mode: ${mode}`);
@@ -42,6 +69,15 @@ function generateThemingScript({ mode = DefaultColorModeValue, fontScaling = fal
42
69
  }
43
70
  } catch (e) {}
44
71
 
72
+ var seedAndroidFontScale = 1;
73
+ try {
74
+ if (document.documentElement.dataset.seedPlatform === 'android') {
75
+ var rootSize = parseFloat(window.getComputedStyle(document.documentElement).fontSize);
76
+ seedAndroidFontScale = rootSize > 0 ? rootSize / 16 : 1;
77
+ document.documentElement.style.setProperty('--seed-static-font-scale', seedAndroidFontScale.toString());
78
+ }
79
+ } catch (e) {}
80
+
45
81
  try {
46
82
  if (${fontScaling}) {
47
83
  var platform = document.documentElement.dataset.seedPlatform;
@@ -56,8 +92,9 @@ function generateThemingScript({ mode = DefaultColorModeValue, fontScaling = fal
56
92
  document.body.appendChild(tempEl);
57
93
  var size = parseFloat(window.getComputedStyle(tempEl).fontSize);
58
94
  document.body.removeChild(tempEl);
59
- var mult = Math.max(0.8, Math.min(1.35, (size / 16) * 0.9412));
60
- document.documentElement.dataset.seedFontMultiplier = parseFloat(mult.toFixed(2)).toString();
95
+ var raw = size > 0 ? (size / 16) * 0.9412 : 1;
96
+ var scale = Math.max(0.8, Math.min(1.35, raw));
97
+ document.documentElement.dataset.seedFontMultiplier = parseFloat(scale.toFixed(2)).toString();
61
98
  } catch (e) {}
62
99
  }
63
100
 
@@ -67,9 +104,8 @@ function generateThemingScript({ mode = DefaultColorModeValue, fontScaling = fal
67
104
  applyIOSFontScaling();
68
105
  }
69
106
  } else if (platform === 'android') {
70
- var fontSize = parseFloat(window.getComputedStyle(document.documentElement).fontSize);
71
- var scale = Math.max(0.8, Math.min(1.5, fontSize / 16));
72
- document.documentElement.dataset.seedFontMultiplier = parseFloat(scale.toFixed(2)).toString();
107
+ var applied = Math.max(0.8, Math.min(1.5, seedAndroidFontScale));
108
+ document.documentElement.dataset.seedFontMultiplier = parseFloat(applied.toFixed(2)).toString();
73
109
  document.documentElement.dataset.seedFontScaling = 'enabled';
74
110
  }
75
111
  }
package/theming/index.mjs CHANGED
@@ -1,5 +1,32 @@
1
1
  import { DefaultColorModeValue, isValidColorMode } from "./mode.mjs";
2
2
 
3
+ // Never write a comment inside the template literal below. It is emitted
4
+ // verbatim into an inline <script>, so a comment there is string content rather
5
+ // than source: the bundler minifying this module cannot reach it, and whether
6
+ // the host's HTML pipeline minifies an injected inline script is out of this
7
+ // package's hands. Every such comment ships on every page load. The rationale
8
+ // for what the snippet does lives here instead.
9
+ //
10
+ // `--seed-static-font-scale`, written outside the `fontScaling` gate: Android
11
+ // WebView multiplies every computed font-size and line-height by
12
+ // Configuration.fontScale whether or not the app opted in, so the `*-static`
13
+ // tokens have to divide it back out either way. The option picks whether SEED
14
+ // *follows* the user's scale, not whether the WebView applies one. iOS needs
15
+ // nothing here, because its scaling arrives through `-apple-system-body`
16
+ // inheritance, which the gate does control, and a literal px is never inflated.
17
+ // The measured scale stays uncapped because it is a divisor: the tokens cancel
18
+ // textZoom only by dividing by exactly what the WebView multiplied back in,
19
+ // whatever cap the native app chose.
20
+ //
21
+ // `data-seed-font-multiplier`, written on both platforms inside the gate: it
22
+ // reports how much SEED grew the text, not how large a step the user picked.
23
+ // On iOS the measurement is normalized to the web 16px baseline and then
24
+ // clamped to the cap iOS actually applies, the 1.35 that globalCss sets as
25
+ // `--seed-font-size-limit-max`; the Dynamic Type accessibility steps reach 3.1
26
+ // and would otherwise overstate it. On Android the token clamp bounds the same
27
+ // value to [`--seed-font-size-limit-min`, `--seed-font-size-limit-max`], so
28
+ // past the cap it stays deliberately below the raw scale measured above.
29
+
3
30
  export const generateThemingScript = ({ mode = DefaultColorModeValue, fontScaling = false }) => {
4
31
  if (!isValidColorMode(mode)) {
5
32
  throw new Error(`Invalid color mode: ${mode}`);
@@ -42,6 +69,15 @@ export const generateThemingScript = ({ mode = DefaultColorModeValue, fontScalin
42
69
  }
43
70
  } catch (e) {}
44
71
 
72
+ var seedAndroidFontScale = 1;
73
+ try {
74
+ if (document.documentElement.dataset.seedPlatform === 'android') {
75
+ var rootSize = parseFloat(window.getComputedStyle(document.documentElement).fontSize);
76
+ seedAndroidFontScale = rootSize > 0 ? rootSize / 16 : 1;
77
+ document.documentElement.style.setProperty('--seed-static-font-scale', seedAndroidFontScale.toString());
78
+ }
79
+ } catch (e) {}
80
+
45
81
  try {
46
82
  if (${fontScaling}) {
47
83
  var platform = document.documentElement.dataset.seedPlatform;
@@ -56,8 +92,9 @@ export const generateThemingScript = ({ mode = DefaultColorModeValue, fontScalin
56
92
  document.body.appendChild(tempEl);
57
93
  var size = parseFloat(window.getComputedStyle(tempEl).fontSize);
58
94
  document.body.removeChild(tempEl);
59
- var mult = Math.max(0.8, Math.min(1.35, (size / 16) * 0.9412));
60
- document.documentElement.dataset.seedFontMultiplier = parseFloat(mult.toFixed(2)).toString();
95
+ var raw = size > 0 ? (size / 16) * 0.9412 : 1;
96
+ var scale = Math.max(0.8, Math.min(1.35, raw));
97
+ document.documentElement.dataset.seedFontMultiplier = parseFloat(scale.toFixed(2)).toString();
61
98
  } catch (e) {}
62
99
  }
63
100
 
@@ -67,9 +104,8 @@ export const generateThemingScript = ({ mode = DefaultColorModeValue, fontScalin
67
104
  applyIOSFontScaling();
68
105
  }
69
106
  } else if (platform === 'android') {
70
- var fontSize = parseFloat(window.getComputedStyle(document.documentElement).fontSize);
71
- var scale = Math.max(0.8, Math.min(1.5, fontSize / 16));
72
- document.documentElement.dataset.seedFontMultiplier = parseFloat(scale.toFixed(2)).toString();
107
+ var applied = Math.max(0.8, Math.min(1.5, seedAndroidFontScale));
108
+ document.documentElement.dataset.seedFontMultiplier = parseFloat(applied.toFixed(2)).toString();
73
109
  document.documentElement.dataset.seedFontScaling = 'enabled';
74
110
  }
75
111
  }