@vio-live/web-sdk 0.3.0 → 0.4.1

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/README.md CHANGED
@@ -24,10 +24,37 @@ import '@vio-live/web-sdk/ui' // registers <vio-product-carousel>, <vio-cart>,
24
24
 
25
25
  Vio.init({
26
26
  apiKey: import.meta.env.VITE_VIO_API_KEY,
27
- // apiBase, graphqlBase, stripePublishableKey — optional overrides
27
+ environment: 'production', // 'development' | 'testing' | 'production'
28
28
  })
29
29
  ```
30
30
 
31
+ `environment` is the recommended way to configure — it resolves the right
32
+ `apiBase`/`graphQLBase` for you (each environment has known-good defaults
33
+ baked in). Note the middle value is **`'testing'`, not `'staging'`**
34
+ (naming kept in parity with the iOS SDK).
35
+
36
+ Only pass `apiBase`/`graphQLBase`/`stripePublishableKey` directly if you need
37
+ to override those specific values — e.g. a self-hosted proxy, or a Stripe key
38
+ that differs from the environment default:
39
+
40
+ ```ts
41
+ Vio.init({
42
+ apiKey: '…',
43
+ environment: 'production',
44
+ apiBase: 'https://my-proxy.example.com', // optional, overrides the environment default
45
+ graphQLBase: 'https://my-graphql.example.com', // optional — note the casing: graphQLBase
46
+ stripePublishableKey: 'pk_live_…', // optional — needed for the Apple Pay button
47
+ })
48
+ ```
49
+
50
+ **Apple Pay note**: the button only renders when `canMakePayment()` says the
51
+ device+browser can pay AND your domain is verified for Apple Pay in Stripe's
52
+ dashboard (Settings → Payment method domains) — Stripe serves a verification
53
+ file at `/.well-known/apple-developer-merchantid-domain-association` on that
54
+ domain. Not all hosts let you serve that file (some page builders can't) —
55
+ if the button never appears, check domain verification before assuming it's
56
+ a code bug.
57
+
31
58
  ```html
32
59
  <vio-product-carousel
33
60
  label="Ukens funn"
@@ -51,7 +78,7 @@ Typed wrappers (built on `@lit/react`). Importing this entry **registers the ele
51
78
  import { Vio } from '@vio-live/web-sdk'
52
79
  import { VioProductCarousel, VioCart } from '@vio-live/web-sdk/react'
53
80
 
54
- Vio.init({ apiKey: '…' })
81
+ Vio.init({ apiKey: '…', environment: 'production' })
55
82
 
56
83
  function Shop() {
57
84
  return (
@@ -70,6 +97,43 @@ function Shop() {
70
97
 
71
98
  Wrappers: `VioProduct`, `VioProductCarousel`, `VioProductDetail`, `VioCart`, `VioCheckout`.
72
99
 
100
+ ## Theming
101
+
102
+ Every component reads its colors and fonts from `--vio-*` CSS custom properties
103
+ (shadow DOM inherits these from the light DOM, so this reaches every component,
104
+ including the Apple Pay/Klarna/Vipps panels). `applyVioTheme` is the one
105
+ supported way to override them — don't set `--vio-*` properties by hand, and
106
+ don't rely on the internal variable names staying stable across versions:
107
+
108
+ ```ts
109
+ import { applyVioTheme } from '@vio-live/web-sdk/ui' // or '/react'
110
+
111
+ applyVioTheme({
112
+ colorAccent: '#0044ff',
113
+ colorText: '#111111',
114
+ fontSerif: '"Playfair Display", Georgia, serif',
115
+ fontSans: '"Inter", sans-serif',
116
+ })
117
+ ```
118
+
119
+ A curated set on purpose — colors + fonts, not the full internal token list
120
+ (spacing/radius/sizes stay implementation detail). Call it again any time
121
+ (e.g. after a user picks a different brand color in a settings UI) — pass
122
+ `null`/`undefined` for a key to revert it to the SDK default instead of
123
+ leaving a stale override behind:
124
+
125
+ ```ts
126
+ applyVioTheme({ colorAccent: null }) // back to the default #c14a3b
127
+ ```
128
+
129
+ By default it sets the override on `document.documentElement` (`:root`, the
130
+ whole page). Pass a second argument to scope it to one element instead —
131
+ useful if you show multiple differently-branded sponsors on the same page:
132
+
133
+ ```ts
134
+ applyVioTheme({ colorAccent: '#ff6600' }, document.getElementById('sponsor-2'))
135
+ ```
136
+
73
137
  ## Headless / SSR
74
138
 
75
139
  The root and `/core` entries export the framework-agnostic core with **no DOM side-effects** — SSR-safe and **tree-shakeable** (importing one helper pulls only that helper, ~0.5 kB):
@@ -2,6 +2,158 @@ import { Vio, __decorateClass, primaryImageUrl, displayPrice, getGlobalCurrency,
2
2
  import { LitElement, css, html } from 'lit';
3
3
  import { property, state, query } from 'lit/decorators.js';
4
4
 
5
+ // src/ui/tokens.ts
6
+ var VioTokens = {
7
+ color: {
8
+ text: {
9
+ primary: "#0a0a0a",
10
+ secondary: "#666666",
11
+ tertiary: "#999999",
12
+ onPrimary: "#ffffff"
13
+ },
14
+ accent: {
15
+ editorial: "#c14a3b"
16
+ // "REDAKSJONENS FAVORITTER" red
17
+ },
18
+ surface: {
19
+ base: "#ffffff",
20
+ muted: "#f2f2f2",
21
+ // product image background
22
+ hover: "#fafafa"
23
+ },
24
+ border: {
25
+ subtle: "#e5e5e5",
26
+ default: "#cccccc"
27
+ }
28
+ },
29
+ font: {
30
+ serif: '"Tinos", "Playfair Display", Georgia, serif',
31
+ sans: '"Inter", -apple-system, "Helvetica Neue", Arial, sans-serif'
32
+ },
33
+ size: {
34
+ xs: "12px",
35
+ sm: "14px",
36
+ md: "16px",
37
+ lg: "20px",
38
+ xl: "24px",
39
+ "2xl": "32px",
40
+ "3xl": "40px"
41
+ },
42
+ weight: {
43
+ regular: 400,
44
+ medium: 500,
45
+ semibold: 600,
46
+ bold: 700
47
+ },
48
+ tracking: {
49
+ label: "0.1em",
50
+ // uppercase labels (BRAND, RETAILER, REDAKSJONENS FAVORITTER)
51
+ title: "0"
52
+ },
53
+ lineHeight: {
54
+ tight: 1.1,
55
+ snug: 1.3,
56
+ normal: 1.5
57
+ },
58
+ space: {
59
+ xs: "4px",
60
+ sm: "8px",
61
+ md: "16px",
62
+ lg: "24px",
63
+ xl: "32px",
64
+ "2xl": "48px",
65
+ "3xl": "64px"
66
+ },
67
+ radius: {
68
+ none: "0",
69
+ sm: "2px",
70
+ md: "4px",
71
+ lg: "8px",
72
+ full: "9999px"
73
+ }
74
+ };
75
+ var VIO_TOKENS_CSS = `
76
+ :root {
77
+ /* color \u2014 text */
78
+ --vio-color-text: ${VioTokens.color.text.primary};
79
+ --vio-color-text-secondary: ${VioTokens.color.text.secondary};
80
+ --vio-color-text-tertiary: ${VioTokens.color.text.tertiary};
81
+ --vio-color-text-on-primary:${VioTokens.color.text.onPrimary};
82
+
83
+ /* color \u2014 accent */
84
+ --vio-color-accent: ${VioTokens.color.accent.editorial};
85
+
86
+ /* color \u2014 surface */
87
+ --vio-color-surface: ${VioTokens.color.surface.base};
88
+ --vio-color-surface-muted: ${VioTokens.color.surface.muted};
89
+ --vio-color-surface-hover: ${VioTokens.color.surface.hover};
90
+
91
+ /* color \u2014 border */
92
+ --vio-color-border: ${VioTokens.color.border.subtle};
93
+ --vio-color-border-default: ${VioTokens.color.border.default};
94
+
95
+ /* font */
96
+ --vio-font-serif: ${VioTokens.font.serif};
97
+ --vio-font-sans: ${VioTokens.font.sans};
98
+
99
+ /* size */
100
+ --vio-size-xs: ${VioTokens.size.xs};
101
+ --vio-size-sm: ${VioTokens.size.sm};
102
+ --vio-size-md: ${VioTokens.size.md};
103
+ --vio-size-lg: ${VioTokens.size.lg};
104
+ --vio-size-xl: ${VioTokens.size.xl};
105
+
106
+ /* tracking (uppercase letterspacing) */
107
+ --vio-tracking-label: ${VioTokens.tracking.label};
108
+
109
+ /* space */
110
+ --vio-space-xs: ${VioTokens.space.xs};
111
+ --vio-space-sm: ${VioTokens.space.sm};
112
+ --vio-space-md: ${VioTokens.space.md};
113
+ --vio-space-lg: ${VioTokens.space.lg};
114
+ --vio-space-xl: ${VioTokens.space.xl};
115
+
116
+ /* radius */
117
+ --vio-radius-sm: ${VioTokens.radius.sm};
118
+ --vio-radius-md: ${VioTokens.radius.md};
119
+ --vio-radius-lg: ${VioTokens.radius.lg};
120
+ }
121
+ `;
122
+ function injectTokens() {
123
+ if (typeof document === "undefined") return;
124
+ if (document.querySelector('style[data-vio="tokens"]') !== null) return;
125
+ const style = document.createElement("style");
126
+ style.setAttribute("data-vio", "tokens");
127
+ style.textContent = VIO_TOKENS_CSS;
128
+ document.head.appendChild(style);
129
+ }
130
+ injectTokens();
131
+ var THEME_KEY_TO_CSS_VAR = {
132
+ colorText: "--vio-color-text",
133
+ colorTextSecondary: "--vio-color-text-secondary",
134
+ colorTextTertiary: "--vio-color-text-tertiary",
135
+ colorTextOnPrimary: "--vio-color-text-on-primary",
136
+ colorAccent: "--vio-color-accent",
137
+ colorSurface: "--vio-color-surface",
138
+ colorSurfaceMuted: "--vio-color-surface-muted",
139
+ colorSurfaceHover: "--vio-color-surface-hover",
140
+ colorBorder: "--vio-color-border",
141
+ colorBorderDefault: "--vio-color-border-default",
142
+ fontSerif: "--vio-font-serif",
143
+ fontSans: "--vio-font-sans"
144
+ };
145
+ function applyVioTheme(overrides, target = typeof document !== "undefined" ? document.documentElement : null) {
146
+ if (!target) return;
147
+ for (const key of Object.keys(THEME_KEY_TO_CSS_VAR)) {
148
+ const cssVar = THEME_KEY_TO_CSS_VAR[key];
149
+ const value = overrides[key];
150
+ if (value) {
151
+ target.style.setProperty(cssVar, value);
152
+ } else if (key in overrides) {
153
+ target.style.removeProperty(cssVar);
154
+ }
155
+ }
156
+ }
5
157
  var VioProduct = class extends LitElement {
6
158
  constructor() {
7
159
  super(...arguments);
@@ -4217,6 +4369,6 @@ function registerVioElements() {
4217
4369
  }
4218
4370
  }
4219
4371
 
4220
- export { VioCart, VioCheckout, VioProduct, VioProductCarousel, VioProductDetail, registerVioElements };
4221
- //# sourceMappingURL=chunk-NWORYWIL.js.map
4222
- //# sourceMappingURL=chunk-NWORYWIL.js.map
4372
+ export { VioCart, VioCheckout, VioProduct, VioProductCarousel, VioProductDetail, VioTokens, applyVioTheme, registerVioElements };
4373
+ //# sourceMappingURL=chunk-V5ZQG2H5.js.map
4374
+ //# sourceMappingURL=chunk-V5ZQG2H5.js.map