@hubpav/hwio-web-runtime 0.3.0 → 0.4.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/dist/inline.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export const consentDefaults = { "code": "(function(){window.dataLayer=window.dataLayer||[];window.gtag=window.gtag||function(){window.dataLayer.push(arguments)};window.gtag('consent','default',{ad_storage:'denied',ad_user_data:'denied',ad_personalization:'denied',analytics_storage:'denied',functionality_storage:'denied',personalization_storage:'denied',security_storage:'granted'})})();", "hash": "sha256-8ypBBYlrPDUYAWyidrG8ZMBi91IYR2VYNNXABFu2aI8=" };
2
2
  export const fontGate = { "code": "(function(){var h=document.documentElement,d=h.dataset,fam=d.hwioFontFamily;if(!fam||!('fonts' in document)){h.classList.remove('fonts-loading');h.classList.add('fonts-ready');return}var T=5000;function load(s){return new Promise(function(res,rej){var id=setTimeout(function(){rej(new Error('font timeout'))},T);document.fonts.load('400 1em \"'+fam+'\"',s).then(function(f){clearTimeout(id);res(f)},function(e){clearTimeout(id);rej(e)})})}if(!window.__hwioFontGate){window.__hwioFontGate={state:'loading',ready:Promise.all([load(d.hwioFontSample||'HARDWARIO'),load(d.hwioFontSampleExt||'Řešení Vývojáři Odwiedź')])};document.addEventListener('astro:before-swap',function(ev){var n=ev.newDocument.documentElement;n.classList.add('js');n.classList.remove('fonts-loading');n.classList.toggle('fonts-failed',window.__hwioFontGate.state==='failed');n.classList.add('fonts-ready');var cur=h.getAttribute('data-theme');if(cur)n.setAttribute('data-theme',cur);else n.removeAttribute('data-theme')})}window.__hwioFontGate.ready.then(function(){window.__hwioFontGate.state='ready';h.classList.remove('fonts-loading');h.classList.add('fonts-ready')},function(){window.__hwioFontGate.state='failed';h.classList.remove('fonts-loading');h.classList.add('fonts-failed','fonts-ready')})})();", "hash": "sha256-yZ5zwDTjvBj25m7DRmqzRrznrnc2PqP3T7FWx0ftKO8=" };
3
- export const themeBootstrap = { "code": "(function(){var h=document.documentElement,d=h.dataset;h.classList.add('js');try{var v=d.hwioConsentVersion;var sv=localStorage.getItem('hwio_theme_consent_version')||localStorage.getItem('hw_theme_consent_version');if(!v||sv!==v)return;var t=localStorage.getItem('hwio_theme')||localStorage.getItem('theme');if(t==='dark'&&d.hwioThemeDark)h.setAttribute('data-theme',d.hwioThemeDark);else if(t==='light'&&d.hwioThemeLight)h.setAttribute('data-theme',d.hwioThemeLight)}catch(e){}})();", "hash": "sha256-JW1fCR5ZsiIO72q9E9VB79Buasr9rvLssoILZij91Yk=" }; // legacy-ok: reads the pre-design-system storage keys once
3
+ export const themeBootstrap = { "code": "(function(){var h=document.documentElement,d=h.dataset;h.classList.add('js');try{var v=d.hwioConsentVersion;var sv=localStorage.getItem('hwio_theme_consent_version')||localStorage.getItem('hw_theme_consent_version');if(v&&sv===v){var t=localStorage.getItem('hwio_theme')||localStorage.getItem('theme');if(t==='dark'&&d.hwioThemeDark)h.setAttribute('data-theme',d.hwioThemeDark);else if(t==='light'&&d.hwioThemeLight)h.setAttribute('data-theme',d.hwioThemeLight)}}catch(e){}if(!h.getAttribute('data-theme')&&d.hwioThemeLight){var dk=false;try{dk=matchMedia('(prefers-color-scheme: dark)').matches}catch(e){}h.setAttribute('data-theme',dk&&d.hwioThemeDark?d.hwioThemeDark:d.hwioThemeLight)}})();", "hash": "sha256-2j6kEk35lbk4ErIco/G03YuZwTwDNma2HXX466e1BlI=" }; // legacy-ok: reads the pre-design-system storage keys once
4
4
  export const hwioInlineHashes = [consentDefaults.hash, fontGate.hash, themeBootstrap.hash];
package/dist/theme.js CHANGED
@@ -17,10 +17,10 @@ function themeNames() {
17
17
  export function hwioApplyTheme(choice) {
18
18
  const html = document.documentElement;
19
19
  const names = themeNames();
20
- if (choice === 'system')
21
- html.removeAttribute('data-theme');
22
- else
23
- html.setAttribute('data-theme', choice === 'dark' ? names.dark : names.light);
20
+ // 'system' stamps the resolved theme (never an empty attribute): non-default themes only apply when stamped.
21
+ const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
22
+ const dark = choice === 'system' ? systemDark : choice === 'dark';
23
+ html.setAttribute('data-theme', dark ? names.dark : names.light);
24
24
  html.classList.add('hwio-theme-transition');
25
25
  window.setTimeout(() => html.classList.remove('hwio-theme-transition'), 300);
26
26
  try {
@@ -48,14 +48,22 @@ export function hwioApplyTheme(choice) {
48
48
  */
49
49
  export function hwioThemeRuntime() {
50
50
  let controller = null;
51
+ // No stored choice: follow the OS scheme while the page is open.
52
+ try {
53
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
54
+ if (!localStorage.getItem(THEME_KEY))
55
+ hwioApplyTheme('system');
56
+ });
57
+ }
58
+ catch {
59
+ // matchMedia unavailable
60
+ }
51
61
  let themeBeforeSwap = null;
52
62
  document.addEventListener('astro:before-swap', () => { themeBeforeSwap = document.documentElement.getAttribute('data-theme'); });
53
63
  document.addEventListener('astro:after-swap', () => {
54
64
  document.documentElement.classList.add('js');
55
65
  if (themeBeforeSwap)
56
66
  document.documentElement.setAttribute('data-theme', themeBeforeSwap);
57
- else
58
- document.documentElement.removeAttribute('data-theme');
59
67
  });
60
68
  function syncPressed() {
61
69
  const dark = hwioResolvedScheme() === 'dark';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubpav/hwio-web-runtime",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Framework-free browser runtime for the HARDWARIO websites: consent (Consent Mode v2 + GTM), HubSpot forms with Turnstile, attribution, theme, CTA tracking and small behaviours. View-transition safe.",
5
5
  "license": "MIT",
6
6
  "type": "module",