@hubpav/hwio-web-runtime 0.3.0 → 0.5.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/consent.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { hwioMount } from './mount.js';
2
2
  import { HWIO_CONSENT_COOKIE, LEGACY_CONSENT_COOKIE, hwioBaseCategories, hwioConsentToGoogle, hwioCookieString, hwioDisallowedCookieNames, hwioExpireCookieString, hwioHasTrackingConsent, hwioMakeReceipt, hwioParseReceipt, hwioReadCookie, } from './consent-core.js';
3
3
  const ATTRIBUTION_KEYS = ['hwio_attribution', 'hw_attribution']; // legacy-ok
4
- const THEME_KEYS = ['hwio_theme', 'hwio_theme_consent_version', 'theme', 'hw_theme_consent_version']; // legacy-ok
5
4
  /**
6
5
  * Consent runtime. Markup contract (rendered by HWioCookieConsent):
7
6
  * [data-hwio-consent data-version data-gtm? data-locale] banner root (hidden attr toggles it)
@@ -77,14 +76,6 @@ export function hwioConsentRuntime() {
77
76
  try {
78
77
  if (!categories.marketing)
79
78
  ATTRIBUTION_KEYS.forEach((k) => sessionStorage.removeItem(k));
80
- if (!categories.preferences)
81
- THEME_KEYS.forEach((k) => localStorage.removeItem(k));
82
- else {
83
- if (localStorage.getItem('hwio_theme'))
84
- localStorage.setItem('hwio_theme_consent_version', version);
85
- if (localStorage.getItem('theme'))
86
- localStorage.setItem('hw_theme_consent_version', version); // legacy-ok
87
- }
88
79
  }
89
80
  catch {
90
81
  // storage unavailable
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');var t=null;try{if(d.hwioThemeCookieDomain){var m=document.cookie.match(/(?:^|; )hwio_theme=(dark|light)/);if(m)t=m[1]}if(!t)t=localStorage.getItem('hwio_theme')||localStorage.getItem('theme')}catch(e){}if(!h.getAttribute('data-theme')&&d.hwioThemeLight){h.setAttribute('data-theme',t==='dark'&&d.hwioThemeDark?d.hwioThemeDark:d.hwioThemeLight)}})();", "hash": "sha256-N+PCgo10dW74h2jKsCZVedLAmTLJeWIaNkhmjfY8r1Q=" };
4
4
  export const hwioInlineHashes = [consentDefaults.hash, fontGate.hash, themeBootstrap.hash];
package/dist/theme.d.ts CHANGED
@@ -1,7 +1,13 @@
1
1
  export type HWioScheme = 'light' | 'dark';
2
- export type HWioThemeChoice = HWioScheme | 'system';
3
- /** The scheme actually in effect: explicit data-theme ending in "-dark", else the OS preference. */
2
+ export type HWioThemeChoice = HWioScheme;
3
+ /** The scheme actually in effect: the stamped data-theme ending in "-dark" means dark. */
4
4
  export declare function hwioResolvedScheme(): HWioScheme;
5
+ /**
6
+ * Applies and remembers the visitor's choice. Light is the default (owner decision 2026-09-06); the
7
+ * choice is a user-requested display preference, stored without a consent gate: localStorage on every
8
+ * site and, when <html data-hwio-theme-cookie-domain> is set, a first-party cookie shared by that
9
+ * domain's sites (www, docs, stem on .hardwario.com).
10
+ */
5
11
  export declare function hwioApplyTheme(choice: HWioThemeChoice): void;
6
12
  /**
7
13
  * Binds [data-hwio-theme-toggle] buttons (two-state light/dark) and keeps the runtime-only
package/dist/theme.js CHANGED
@@ -1,41 +1,35 @@
1
1
  import { hwioMount } from './mount.js';
2
2
  const THEME_KEY = 'hwio_theme';
3
- const THEME_VERSION_KEY = 'hwio_theme_consent_version';
4
- /** The scheme actually in effect: explicit data-theme ending in "-dark", else the OS preference. */
3
+ /** The scheme actually in effect: the stamped data-theme ending in "-dark" means dark. */
5
4
  export function hwioResolvedScheme() {
6
5
  const theme = document.documentElement.getAttribute('data-theme');
7
6
  if (theme)
8
7
  return theme.endsWith('-dark') ? 'dark' : 'light';
9
8
  if (document.documentElement.classList.contains('dark'))
10
9
  return 'dark'; // legacy-ok: www's class toggle until P2
11
- return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
10
+ return 'light';
12
11
  }
13
12
  function themeNames() {
14
13
  const d = document.documentElement.dataset;
15
14
  return { light: d.hwioThemeLight ?? 'hwio', dark: d.hwioThemeDark ?? 'hwio-dark' };
16
15
  }
16
+ /**
17
+ * Applies and remembers the visitor's choice. Light is the default (owner decision 2026-09-06); the
18
+ * choice is a user-requested display preference, stored without a consent gate: localStorage on every
19
+ * site and, when <html data-hwio-theme-cookie-domain> is set, a first-party cookie shared by that
20
+ * domain's sites (www, docs, stem on .hardwario.com).
21
+ */
17
22
  export function hwioApplyTheme(choice) {
18
23
  const html = document.documentElement;
19
24
  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);
25
+ html.setAttribute('data-theme', choice === 'dark' ? names.dark : names.light);
24
26
  html.classList.add('hwio-theme-transition');
25
27
  window.setTimeout(() => html.classList.remove('hwio-theme-transition'), 300);
26
28
  try {
27
- if (window.hwioConsent?.allows('preferences')) {
28
- if (choice === 'system') {
29
- localStorage.removeItem(THEME_KEY);
30
- localStorage.removeItem(THEME_VERSION_KEY);
31
- }
32
- else {
33
- localStorage.setItem(THEME_KEY, choice);
34
- const version = html.dataset.hwioConsentVersion;
35
- if (version)
36
- localStorage.setItem(THEME_VERSION_KEY, version);
37
- }
38
- }
29
+ localStorage.setItem(THEME_KEY, choice);
30
+ const domain = html.dataset.hwioThemeCookieDomain;
31
+ if (domain)
32
+ document.cookie = `${THEME_KEY}=${choice}; Domain=${domain}; Path=/; Max-Age=31536000; SameSite=Lax; Secure`;
39
33
  }
40
34
  catch {
41
35
  // storage unavailable
@@ -54,8 +48,6 @@ export function hwioThemeRuntime() {
54
48
  document.documentElement.classList.add('js');
55
49
  if (themeBeforeSwap)
56
50
  document.documentElement.setAttribute('data-theme', themeBeforeSwap);
57
- else
58
- document.documentElement.removeAttribute('data-theme');
59
51
  });
60
52
  function syncPressed() {
61
53
  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.5.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",