@vio-live/web-sdk 0.1.0 → 0.3.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../node_modules/@lit/react/src/create-component.ts","../../src/react/index.ts"],"names":["reservedReactProperties","Set","createComponent","react","React","tagName","elementClass","events","displayName","eventProps","Object","keys","ReactComponent","forwardRef","props","ref","useRef","Map","elementRef","reactProps","elementProps","k","v","entries","has","prototype","createElement","name","globalThis","litSsrReactEnabled","length","useCallback","node","current","VioProduct","VioProductCarousel","VioProductDetail","VioCart","VioCheckout"],"mappings":";;;;;AAgHA,IAAMA,CAAAA,uBAA8BC,GAAAA,CAAI,CACtC,YACA,WAAA,EACA,KAAA,EACA,OAAA,EACA,WAAA,CAAA,CAAA;AALF,IAwGaC,CAAAA,GAAkB,CAAA,EAI7BC,KAAAA,EAAOC,EAAAA,EACPC,OAAAA,EAAAA,CAAAA,EACAC,YAAAA,EAAAA,CAAAA,EACAC,MAAAA,EAAAA,CAAAA,EACAC,WAAAA,EAAAA,GAAAA,KAAAA;AAEA,EAAA,MAAMC,CAAAA,GAAa,IAAIR,GAAAA,CAAIS,MAAAA,CAAOC,KAAKJ,CAAAA,IAAU,EAAE,CAAA,GAoB7CK,CAAAA,GAAiBR,EAAAA,CAAMS,UAAAA,EAAqB,CAACC,IAAOC,EAAAA,KAAAA;AAC/BX,IAAAA,EAAAA,CAAMY,MAAAA,iBAAO,IAAIC,GAAAA,EAAAA,CAAAA;AAC1C,IAAA,MAAMC,EAAAA,GAAad,GAAMY,MAAAA,CAAiB,IAAA,GAGpCG,CAAAA,GAAsC,EAAA,EAEtCC,CAAAA,GAAwC,EAAA;AAE9C,IAAA,KAAA,MAAK,CAAOC,EAAAA,EAAGC,EAAAA,CAAAA,IAAMZ,OAAOa,OAAAA,CAAQT,EAAAA,CAAAA,EAC9Bd,CAAAA,CAAwBwB,GAAAA,CAAIH,EAAAA,CAA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AAA,IAChB,YAAA,EAAc;AAAA;AAElB,CAAC;AAEM,IAAMC,sBAAqB,CAAA,CAAgB;AAAA,EAChD,KAAA,EAAO,KAAA;AAAA,EACP,OAAA,EAAS,sBAAA;AAAA,EACT,YAAA,EAAc,kBAAA;AAAA,EACd,QAAQ;AACV,CAAC;AAEM,IAAMC,oBAAmB,CAAA,CAAgB;AAAA,EAC9C,KAAA,EAAO,KAAA;AAAA,EACP,OAAA,EAAS,oBAAA;AAAA,EACT,YAAA,EAAc,gBAAA;AAAA,EACd,MAAA,EAAQ;AAAA,IACN,aAAA,EAAe,mBAAA;AAAA,IACf,cAAA,EAAgB;AAAA;AAEpB,CAAC;AAEM,IAAMC,WAAU,CAAA,CAAgB;AAAA,EACrC,KAAA,EAAO,KAAA;AAAA,EACP,OAAA,EAAS,UAAA;AAAA,EACT,YAAA,EAAc,OAAA;AAAA,EACd,MAAA,EAAQ;AAAA,IACN,gBAAA,EAAkB,qBAAA;AAAA,IAClB,cAAA,EAAgB;AAAA;AAEpB,CAAC;AAEM,IAAMC,eAAc,CAAA,CAAgB;AAAA,EACzC,KAAA,EAAO,KAAA;AAAA,EACP,OAAA,EAAS,cAAA;AAAA,EACT,YAAA,EAAc,WAAA;AAAA,EACd,MAAA,EAAQ;AAAA,IACN,gBAAA,EAAkB;AAAA;AAEtB,CAAC","file":"index.js","sourcesContent":["/**\n * @license\n * Copyright 2018 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport type React from 'react';\n\nconst NODE_MODE = false;\nconst DEV_MODE = true;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype DistributiveOmit<T, K extends string | number | symbol> = T extends any\n ? K extends keyof T\n ? Omit<T, K>\n : T\n : T;\ntype PropsWithoutRef<T> = DistributiveOmit<T, 'ref'>;\n\n/**\n * Creates a type to be used for the props of a web component used directly in\n * React JSX.\n *\n * Example:\n *\n * ```ts\n * declare module \"react\" {\n * namespace JSX {\n * interface IntrinsicElements {\n * 'x-foo': WebComponentProps<XFoo>;\n * }\n * }\n * }\n * ```\n */\nexport type WebComponentProps<I extends HTMLElement> = React.DetailedHTMLProps<\n React.HTMLAttributes<I>,\n I\n> &\n ElementProps<I>;\n\n/**\n * Type of the React component wrapping the web component. This is the return\n * type of `createComponent`.\n */\nexport type ReactWebComponent<\n I extends HTMLElement,\n E extends EventNames = {},\n> = React.ForwardRefExoticComponent<\n // TODO(augustjk): Remove and use `React.PropsWithoutRef` when\n // https://github.com/preactjs/preact/issues/4124 is fixed.\n PropsWithoutRef<ComponentProps<I, E>> & React.RefAttributes<I>\n>;\n\n// Props derived from custom element class. Currently has limitations of making\n// all properties optional and also surfaces life cycle methods in autocomplete.\n// TODO(augustjk) Consider omitting keyof LitElement to remove \"internal\"\n// lifecycle methods or allow user to explicitly provide props.\ntype ElementProps<I> = Partial<Omit<I, keyof HTMLElement>>;\n\n// Acceptable props to the React component.\ntype ComponentProps<I, E extends EventNames = {}> = Omit<\n React.HTMLAttributes<I>,\n // Prefer type of provided event handler props or those on element over\n // built-in HTMLAttributes\n keyof E | keyof ElementProps<I>\n> &\n EventListeners<E> &\n ElementProps<I>;\n\n/**\n * Type used to cast an event name with an event type when providing the\n * `events` option to `createComponent` for better typing of the event handler\n * prop.\n *\n * Example:\n *\n * ```ts\n * const FooComponent = createComponent({\n * ...\n * events: {\n * onfoo: 'foo' as EventName<FooEvent>,\n * }\n * });\n * ```\n *\n * `onfoo` prop will have the type `(e: FooEvent) => void`.\n */\nexport type EventName<T extends Event = Event> = string & {\n __eventType: T;\n};\n\n// A key value map matching React prop names to event names.\ntype EventNames = Record<string, EventName | string>;\n\n// A map of expected event listener types based on EventNames.\ntype EventListeners<R extends EventNames> = {\n [K in keyof R]?: R[K] extends EventName\n ? (e: R[K]['__eventType']) => void\n : (e: Event) => void;\n};\n\nexport interface Options<I extends HTMLElement, E extends EventNames = {}> {\n react: typeof React;\n tagName: string;\n elementClass: Constructor<I>;\n events?: E;\n displayName?: string;\n}\n\ntype Constructor<T> = {new (): T};\n\nconst reservedReactProperties = new Set([\n 'children',\n 'localName',\n 'ref',\n 'style',\n 'className',\n]);\n\nconst listenedEvents = new WeakMap<Element, Map<string, EventListenerObject>>();\n\n/**\n * Adds an event listener for the specified event to the given node. In the\n * React setup, there should only ever be one event listener. Thus, for\n * efficiency only one listener is added and the handler for that listener is\n * updated to point to the given listener function.\n */\nconst addOrUpdateEventListener = (\n node: Element,\n event: string,\n listener: (event?: Event) => void\n) => {\n let events = listenedEvents.get(node);\n if (events === undefined) {\n listenedEvents.set(node, (events = new Map()));\n }\n let handler = events.get(event);\n if (listener !== undefined) {\n // If necessary, add listener and track handler\n if (handler === undefined) {\n events.set(event, (handler = {handleEvent: listener}));\n node.addEventListener(event, handler);\n // Otherwise just update the listener with new value\n } else {\n handler.handleEvent = listener;\n }\n // Remove listener if one exists and value is undefined\n } else if (handler !== undefined) {\n events.delete(event);\n node.removeEventListener(event, handler);\n }\n};\n\n/**\n * Sets properties and events on custom elements. These properties and events\n * have been pre-filtered so we know they should apply to the custom element.\n */\nconst setProperty = <E extends Element>(\n node: E,\n name: string,\n value: unknown,\n old: unknown,\n events?: EventNames\n) => {\n const event = events?.[name];\n // Dirty check event value.\n if (event !== undefined) {\n if (value !== old) {\n addOrUpdateEventListener(node, event, value as (e?: Event) => void);\n }\n return;\n }\n // But don't dirty check properties; elements are assumed to do this.\n node[name as keyof E] = value as E[keyof E];\n\n // This block is to replicate React's behavior for attributes of native\n // elements where `undefined` or `null` values result in attributes being\n // removed.\n // https://github.com/facebook/react/blob/899cb95f52cc83ab5ca1eb1e268c909d3f0961e7/packages/react-dom-bindings/src/client/DOMPropertyOperations.js#L107-L141\n //\n // It's only needed here for native HTMLElement properties that reflect\n // attributes of the same name but don't have that behavior like \"id\" or\n // \"draggable\".\n if (\n (value === undefined || value === null) &&\n name in HTMLElement.prototype\n ) {\n node.removeAttribute(name);\n }\n};\n\n/**\n * Creates a React component for a custom element. Properties are distinguished\n * from attributes automatically, and events can be configured so they are added\n * to the custom element as event listeners.\n *\n * @param options An options bag containing the parameters needed to generate a\n * wrapped web component.\n *\n * @param options.react The React module, typically imported from the `react`\n * npm package.\n * @param options.tagName The custom element tag name registered via\n * `customElements.define`.\n * @param options.elementClass The custom element class registered via\n * `customElements.define`.\n * @param options.events An object listing events to which the component can\n * listen. The object keys are the event property names passed in via React\n * props and the object values are the names of the corresponding events\n * generated by the custom element. For example, given `{onactivate:\n * 'activate'}` an event function may be passed via the component's `onactivate`\n * prop and will be called when the custom element fires its `activate` event.\n * @param options.displayName A React component display name, used in debugging\n * messages. Default value is inferred from the name of custom element class\n * registered via `customElements.define`.\n */\nexport const createComponent = <\n I extends HTMLElement,\n E extends EventNames = {},\n>({\n react: React,\n tagName,\n elementClass,\n events,\n displayName,\n}: Options<I, E>): ReactWebComponent<I, E> => {\n const eventProps = new Set(Object.keys(events ?? {}));\n\n if (DEV_MODE && !NODE_MODE) {\n for (const p of reservedReactProperties) {\n if (p in elementClass.prototype && !(p in HTMLElement.prototype)) {\n // Note, this effectively warns only for `ref` since the other\n // reserved props are on HTMLElement.prototype. To address this\n // would require crawling down the prototype, which doesn't feel worth\n // it since implementing these properties on an element is extremely\n // rare.\n console.warn(\n `${tagName} contains property ${p} which is a React reserved ` +\n `property. It will be used by React and not set on the element.`\n );\n }\n }\n }\n\n type Props = ComponentProps<I, E>;\n\n const ReactComponent = React.forwardRef<I, Props>((props, ref) => {\n const prevElemPropsRef = React.useRef(new Map());\n const elementRef = React.useRef<I | null>(null);\n\n // Props to be passed to React.createElement\n const reactProps: Record<string, unknown> = {};\n // Props to be set on element with setProperty\n const elementProps: Record<string, unknown> = {};\n\n for (const [k, v] of Object.entries(props)) {\n if (reservedReactProperties.has(k)) {\n // React does *not* handle `className` for custom elements so\n // coerce it to `class` so it's handled correctly.\n reactProps[k === 'className' ? 'class' : k] = v;\n continue;\n }\n\n if (eventProps.has(k) || k in elementClass.prototype) {\n elementProps[k] = v;\n continue;\n }\n\n reactProps[k] = v;\n }\n\n // useLayoutEffect produces warnings during server rendering.\n if (!NODE_MODE) {\n // This one has no dependency array so it'll run on every re-render.\n React.useLayoutEffect(() => {\n if (elementRef.current === null) {\n return;\n }\n const newElemProps = new Map();\n for (const key in elementProps) {\n setProperty(\n elementRef.current,\n key,\n props[key],\n prevElemPropsRef.current.get(key),\n events\n );\n prevElemPropsRef.current.delete(key);\n newElemProps.set(key, props[key]);\n }\n // \"Unset\" any props from previous render that no longer exist.\n // Setting to `undefined` seems like the correct thing to \"unset\"\n // but currently React will set it as `null`.\n // See https://github.com/facebook/react/issues/28203\n for (const [key, value] of prevElemPropsRef.current) {\n setProperty(elementRef.current, key, undefined, value, events);\n }\n prevElemPropsRef.current = newElemProps;\n });\n\n // Empty dependency array so this will only run once after first render.\n React.useLayoutEffect(() => {\n elementRef.current?.removeAttribute('defer-hydration');\n }, []);\n }\n\n if (NODE_MODE) {\n // If component is to be server rendered with `@lit/ssr-react`, pass\n // element properties in a special bag to be set by the server-side\n // element renderer.\n if (\n (React.createElement.name === 'litPatchedCreateElement' ||\n globalThis.litSsrReactEnabled) &&\n Object.keys(elementProps).length\n ) {\n // This property needs to remain unminified.\n reactProps['_$litProps$'] = elementProps;\n }\n } else {\n // Suppress hydration warning for server-rendered attributes.\n // This property needs to remain unminified.\n reactProps['suppressHydrationWarning'] = true;\n }\n\n return React.createElement(tagName, {\n ...reactProps,\n ref: React.useCallback(\n (node: I) => {\n elementRef.current = node;\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref !== null) {\n ref.current = node;\n }\n },\n [ref]\n ),\n });\n });\n\n ReactComponent.displayName = displayName ?? elementClass.name;\n\n return ReactComponent;\n};\n","/**\n * Vio React adapter — typed React wrappers for the `<vio-*>` web components.\n *\n * Built on `@lit/react`'s `createComponent`, which gives each wrapper:\n * - typed props derived from the element's reactive properties, and\n * - typed event props (the `vio:*` CustomEvents below) as `onX` callbacks.\n *\n * Importing this entry also REGISTERS the custom elements (via the\n * `registerVioElements()` call below), so you do NOT need a separate\n * `import '@vio-live/web-sdk/ui'` when you use these.\n *\n * React 18+ is an (optional) peer dependency — only required if you import this\n * entry. `@lit/react` is bundled in, so consumers install nothing extra.\n *\n * import { Vio } from '@vio-live/web-sdk'\n * import { VioProductCarousel } from '@vio-live/web-sdk/react'\n * Vio.init({ apiKey, apiBase, graphqlBase, stripePublishableKey })\n * <VioProductCarousel onProductAdd={(e) => console.log(e.detail)} />\n */\n\nimport * as React from 'react'\nimport { createComponent } from '@lit/react'\nimport {\n registerVioElements,\n VioProduct as VioProductEl,\n VioProductCarousel as VioProductCarouselEl,\n VioProductDetail as VioProductDetailEl,\n VioCart as VioCartEl,\n VioCheckout as VioCheckoutEl,\n} from '../ui/elements.js'\n\n// Register the underlying custom elements when this entry is imported.\nregisterVioElements()\n\nexport const VioProduct = createComponent({\n react: React,\n tagName: 'vio-product',\n elementClass: VioProductEl,\n events: {\n onProductClick: 'vio:product-click',\n onProductAdd: 'vio:product-add',\n },\n})\n\nexport const VioProductCarousel = createComponent({\n react: React,\n tagName: 'vio-product-carousel',\n elementClass: VioProductCarouselEl,\n events: {},\n})\n\nexport const VioProductDetail = createComponent({\n react: React,\n tagName: 'vio-product-detail',\n elementClass: VioProductDetailEl,\n events: {\n onAddedToCart: 'vio:added-to-cart',\n onCheckoutOpen: 'vio:checkout-open',\n },\n})\n\nexport const VioCart = createComponent({\n react: React,\n tagName: 'vio-cart',\n elementClass: VioCartEl,\n events: {\n onPaymentSuccess: 'vio:payment-success',\n onCheckoutOpen: 'vio:checkout-open',\n },\n})\n\nexport const VioCheckout = createComponent({\n react: React,\n tagName: 'vio-checkout',\n elementClass: VioCheckoutEl,\n events: {\n onPaymentSuccess: 'vio:payment-success',\n },\n})\n"]}
@@ -1,7 +1,29 @@
1
- export { V as VioCart, a as VioCheckout, b as VioProduct, c as VioProductCarousel, d as VioProductDetail } from '../vio-checkout-D8B4Upk8.js';
1
+ export { V as VioCart, a as VioCheckout, b as VioProduct, c as VioProductCarousel, d as VioProductDetail } from '../vio-checkout-T9R5hpDx.js';
2
2
  import 'lit-html';
3
3
  import 'lit';
4
4
 
5
+ /**
6
+ * Vio elements — owns the `<vio-*>` custom-element classes and their registration.
7
+ *
8
+ * WHY REGISTRATION IS A FUNCTION (not `@customElement` module side-effects):
9
+ * Both `./ui` and `./react` need the component classes, so the bundler hoists
10
+ * them into a *hashed* shared chunk that package.json `sideEffects` can't name.
11
+ * If registration were a module-eval side-effect (`@customElement`), a
12
+ * consumer's tree-shaker would drop that chunk on a bare `import '.../ui'` and
13
+ * the elements would never `define`. Instead, `registerVioElements()` is a
14
+ * *called value*: any sideEffects-listed entry that calls it (see ui/index +
15
+ * react/index) keeps the function and the classes it references — regardless of
16
+ * chunking — while `./core` stays free of these side-effects and remains
17
+ * tree-shakeable. See lessons/web-sdk-tsup-singleton-and-build.
18
+ */
19
+
20
+ /**
21
+ * Register every `<vio-*>` custom element. Idempotent (skips already-defined
22
+ * tags, so calling it from both `./ui` and `./react` is safe) and SSR-safe
23
+ * (no-op when `customElements` is undefined).
24
+ */
25
+ declare function registerVioElements(): void;
26
+
5
27
  /**
6
28
  * Vio Design Tokens — editorial commerce aesthetic.
7
29
  *
@@ -88,11 +110,14 @@ declare const VioTokens: {
88
110
  * Importing this file (directly or via the main `vio` entry) has two
89
111
  * side-effects:
90
112
  * 1. Injects design tokens as CSS custom properties on `:root`
91
- * 2. Registers all `<vio-*>` custom elements
113
+ * 2. Registers all `<vio-*>` custom elements (via `registerVioElements()`)
114
+ *
115
+ * Registration goes through an explicit function call (see ./elements) so it
116
+ * survives tree-shaking while keeping `./core` tree-shakeable.
92
117
  *
93
118
  * SSR-safe: every side-effect guards on `typeof document !== 'undefined'`.
94
119
  */
95
120
 
96
- declare const VIO_UI_VERSION = "0.1.0";
121
+ declare const VIO_UI_VERSION = "0.2.0";
97
122
 
98
- export { VIO_UI_VERSION, VioTokens };
123
+ export { VIO_UI_VERSION, VioTokens, registerVioElements };
package/dist/ui/index.js CHANGED
@@ -1,4 +1,138 @@
1
- export { VIO_UI_VERSION, VioCart, VioCheckout, VioProduct, VioProductCarousel, VioProductDetail, VioTokens } from '../chunk-4CCGE7DE.js';
2
- import '../chunk-5SPY7TH6.js';
1
+ import { registerVioElements } from '../chunk-NWORYWIL.js';
2
+ export { VioCart, VioCheckout, VioProduct, VioProductCarousel, VioProductDetail, registerVioElements } from '../chunk-NWORYWIL.js';
3
+ import '../chunk-NP2KCM7X.js';
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
+
132
+ // src/ui/index.ts
133
+ registerVioElements();
134
+ var VIO_UI_VERSION = "0.2.0";
135
+
136
+ export { VIO_UI_VERSION, VioTokens };
3
137
  //# sourceMappingURL=index.js.map
4
138
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../../src/ui/tokens.ts","../../src/ui/index.ts"],"names":[],"mappings":";;;;;AAcO,IAAM,SAAA,GAAY;AAAA,EACvB,KAAA,EAAO;AAAA,IACL,IAAA,EAAM;AAAA,MACJ,OAAA,EAAS,SAAA;AAAA,MACT,SAAA,EAAW,SAAA;AAAA,MACX,QAAA,EAAU,SAAA;AAAA,MACV,SAAA,EAAW;AAAA,KACb;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,SAAA,EAAW;AAAA;AAAA,KACb;AAAA,IACA,OAAA,EAAS;AAAA,MACP,IAAA,EAAM,SAAA;AAAA,MACN,KAAA,EAAO,SAAA;AAAA;AAAA,MACP,KAAA,EAAO;AAAA,KACT;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,MAAA,EAAQ,SAAA;AAAA,MACR,OAAA,EAAS;AAAA;AACX,GACF;AAAA,EACA,IAAA,EAAM;AAAA,IACJ,KAAA,EAAO,6CAAA;AAAA,IACP,IAAA,EAAM;AAAA,GACR;AAAA,EACA,IAAA,EAAM;AAAA,IACJ,EAAA,EAAI,MAAA;AAAA,IACJ,EAAA,EAAI,MAAA;AAAA,IACJ,EAAA,EAAI,MAAA;AAAA,IACJ,EAAA,EAAI,MAAA;AAAA,IACJ,EAAA,EAAI,MAAA;AAAA,IACJ,KAAA,EAAO,MAAA;AAAA,IACP,KA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,IAAI,QAAA,CAAS,aAAA,CAAc,0BAA0B,CAAA,KAAM,IAAA,EAAM;AACjE,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,aAAA,CAAc,OAAO,CAAA;AAC5C,EAAA,KAAA,CAAM,YAAA,CAAa,YAAY,QAAQ,CAAA;AACvC,EAAA,KAAA,CAAM,WAAA,GAAc,cAAA;AACpB,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,KAAK,CAAA;AACjC;AAEA,YAAA,EAAa;;;AC5Hb,mBAAA,EAAoB;AAYb,IAAM,cAAA,GAAiB","file":"index.js","sourcesContent":["/**\n * Vio Design Tokens — editorial commerce aesthetic.\n *\n * Extracted from the Allermedia \"Mote & Livsstil\" reference (the target\n * pilot site). Mood: Vogue-like fashion magazine — serif headlines,\n * sans-serif body, near-monochrome palette, terracotta accent for\n * editorial labels (\"REDAKSJONENS FAVORITTER\").\n *\n * Tokens are exposed both as a typed TS object (`VioTokens`) and as\n * CSS custom properties on `:root` (auto-injected when this module is\n * imported in a browser). Consumers can override individual variables\n * to re-skin without touching SDK source.\n */\n\nexport const VioTokens = {\n color: {\n text: {\n primary: '#0a0a0a',\n secondary: '#666666',\n tertiary: '#999999',\n onPrimary: '#ffffff',\n },\n accent: {\n editorial: '#c14a3b', // \"REDAKSJONENS FAVORITTER\" red\n },\n surface: {\n base: '#ffffff',\n muted: '#f2f2f2', // product image background\n hover: '#fafafa',\n },\n border: {\n subtle: '#e5e5e5',\n default: '#cccccc',\n },\n },\n font: {\n serif: '\"Tinos\", \"Playfair Display\", Georgia, serif',\n sans: '\"Inter\", -apple-system, \"Helvetica Neue\", Arial, sans-serif',\n },\n size: {\n xs: '12px',\n sm: '14px',\n md: '16px',\n lg: '20px',\n xl: '24px',\n '2xl': '32px',\n '3xl': '40px',\n },\n weight: {\n regular: 400,\n medium: 500,\n semibold: 600,\n bold: 700,\n },\n tracking: {\n label: '0.1em', // uppercase labels (BRAND, RETAILER, REDAKSJONENS FAVORITTER)\n title: '0',\n },\n lineHeight: {\n tight: 1.1,\n snug: 1.3,\n normal: 1.5,\n },\n space: {\n xs: '4px',\n sm: '8px',\n md: '16px',\n lg: '24px',\n xl: '32px',\n '2xl': '48px',\n '3xl': '64px',\n },\n radius: {\n none: '0',\n sm: '2px',\n md: '4px',\n lg: '8px',\n full: '9999px',\n },\n} as const\n\n/**\n * CSS Custom Properties — generated from VioTokens. Injected once into\n * the document head on first import. Consumers can override any\n * `--vio-*` var on their root or component selector to customise.\n */\nconst VIO_TOKENS_CSS = `\n :root {\n /* color — text */\n --vio-color-text: ${VioTokens.color.text.primary};\n --vio-color-text-secondary: ${VioTokens.color.text.secondary};\n --vio-color-text-tertiary: ${VioTokens.color.text.tertiary};\n --vio-color-text-on-primary:${VioTokens.color.text.onPrimary};\n\n /* color — accent */\n --vio-color-accent: ${VioTokens.color.accent.editorial};\n\n /* color — surface */\n --vio-color-surface: ${VioTokens.color.surface.base};\n --vio-color-surface-muted: ${VioTokens.color.surface.muted};\n --vio-color-surface-hover: ${VioTokens.color.surface.hover};\n\n /* color — border */\n --vio-color-border: ${VioTokens.color.border.subtle};\n --vio-color-border-default: ${VioTokens.color.border.default};\n\n /* font */\n --vio-font-serif: ${VioTokens.font.serif};\n --vio-font-sans: ${VioTokens.font.sans};\n\n /* size */\n --vio-size-xs: ${VioTokens.size.xs};\n --vio-size-sm: ${VioTokens.size.sm};\n --vio-size-md: ${VioTokens.size.md};\n --vio-size-lg: ${VioTokens.size.lg};\n --vio-size-xl: ${VioTokens.size.xl};\n\n /* tracking (uppercase letterspacing) */\n --vio-tracking-label: ${VioTokens.tracking.label};\n\n /* space */\n --vio-space-xs: ${VioTokens.space.xs};\n --vio-space-sm: ${VioTokens.space.sm};\n --vio-space-md: ${VioTokens.space.md};\n --vio-space-lg: ${VioTokens.space.lg};\n --vio-space-xl: ${VioTokens.space.xl};\n\n /* radius */\n --vio-radius-sm: ${VioTokens.radius.sm};\n --vio-radius-md: ${VioTokens.radius.md};\n --vio-radius-lg: ${VioTokens.radius.lg};\n }\n`\n\nfunction injectTokens(): void {\n if (typeof document === 'undefined') return\n if (document.querySelector('style[data-vio=\"tokens\"]') !== null) return\n const style = document.createElement('style')\n style.setAttribute('data-vio', 'tokens')\n style.textContent = VIO_TOKENS_CSS\n document.head.appendChild(style)\n}\n\ninjectTokens()\n","/**\n * Vio UI — Web Components + design tokens.\n *\n * Importing this file (directly or via the main `vio` entry) has two\n * side-effects:\n * 1. Injects design tokens as CSS custom properties on `:root`\n * 2. Registers all `<vio-*>` custom elements (via `registerVioElements()`)\n *\n * Registration goes through an explicit function call (see ./elements) so it\n * survives tree-shaking while keeping `./core` tree-shakeable.\n *\n * SSR-safe: every side-effect guards on `typeof document !== 'undefined'`.\n */\n\nimport './tokens.js'\nimport { registerVioElements } from './elements.js'\n\n// Auto-register on import, so the conventional `import '@vio-live/web-sdk/ui'`\n// keeps working. This call is what pins the registration into this entry.\nregisterVioElements()\n\nexport { VioTokens } from './tokens.js'\nexport {\n registerVioElements,\n VioProduct,\n VioProductCarousel,\n VioProductDetail,\n VioCart,\n VioCheckout,\n} from './elements.js'\n\nexport const VIO_UI_VERSION = '0.2.0'\n"]}
@@ -20,6 +20,14 @@ declare class VioProduct extends LitElement {
20
20
  /** Whether the product has selectable variants — the quick-add button then
21
21
  * opens the detail to pick one instead of adding directly. */
22
22
  hasVariants: boolean;
23
+ /** Optional raw variants/options from the host — extra signal that a
24
+ * variant must be picked before adding (selection is mandatory). */
25
+ variants: unknown[] | undefined;
26
+ options: unknown[] | undefined;
27
+ /** Image-only mode: hide the meta block (brand / name / price / retailer)
28
+ * and show just the image + the quick-add button. Click still opens the
29
+ * detail. */
30
+ hideMeta: boolean;
23
31
  /** True when this product currently sits in the cart (persistent mark). */
24
32
  private inCart;
25
33
  /** Total units of this product in the cart (shown as a count when > 1). */
@@ -111,6 +119,14 @@ declare class VioProductDetail extends LitElement {
111
119
  private adding;
112
120
  /** Apple Pay actually usable (real Stripe + registered domain) — set on load. */
113
121
  private applePayOk;
122
+ /** Payment method names enabled for the sponsor (backend-configured).
123
+ * null = not loaded yet → all buy buttons render; [] = none enabled. */
124
+ private availableMethods;
125
+ /** Race guard: only the latest fetch may write state (two quick taps on
126
+ * different cards would otherwise let the slow response win). */
127
+ private fetchSeq;
128
+ /** Memoised option maps per variant object (recomputed per product). */
129
+ private optMapCache;
114
130
  /** Pre-prepared Apple Pay handle — show() fires synchronously on tap. */
115
131
  private applePayHandle;
116
132
  private boundProductClick;
@@ -120,12 +136,44 @@ declare class VioProductDetail extends LitElement {
120
136
  show(): void;
121
137
  close(): void;
122
138
  private fetchProduct;
123
- /** Resolve the active variant from the selected option values. */
139
+ /** Which buy buttons to render — backend-configured per sponsor. */
140
+ private loadAvailablePaymentMethods;
141
+ /** Backend names arrive as e.g. "Apple Pay" — compare letters only. */
142
+ private methodEnabled;
143
+ /**
144
+ * Build an option-name → value map for a variant, from every shape the feeds
145
+ * ship: option1/2/3 columns, options/selected_options/variant arrays, plain
146
+ * object maps, and finally the title (value scan first, position fallback).
147
+ */
148
+ private getVariantOptionMap;
149
+ /** Option values a variant represents (map values ∪ title parts). */
150
+ private variantOptionValues;
151
+ /** Does a variant part represent this option value? Exact match, plus a
152
+ * whole-token match ONLY for numeric values ("30" matches "30 ml") — word
153
+ * subsets of text values are not matches ("Large" must NOT match
154
+ * "Extra Large"). */
155
+ private partMatchesValue;
156
+ /** Does a variant satisfy every currently-selected option value? */
157
+ private variantMatchesSelection;
158
+ /** Sellable quantity for a variant, across the stock field zoo. Boolean
159
+ * availability flags win; a numeric field wins next; `null` = the feed does
160
+ * not report stock for this variant (callers fall back to product stock —
161
+ * never assume "in stock" from absent data). */
162
+ private getVariantQty;
163
+ /** Variant stock with the product-level fallback applied (0 = not sellable). */
164
+ private variantSellableQty;
165
+ /** Resolve the active variant: full in-stock match → full match → best score
166
+ * (2 per mapped option match, 1 per title match, +0.5 if in stock). */
124
167
  private selectedVariant;
168
+ /** True if some in-stock variant carries this option value. */
169
+ private isValueAvailable;
125
170
  private get unitPrice();
126
171
  private get compareAt();
127
172
  private get availableQuantity();
128
173
  private stockLabel;
174
+ /** Pick an option value. If the exact combination doesn't exist, jump to an
175
+ * in-stock variant that carries the value and adopt its full option map
176
+ * (keeps the selection always resolvable to a real variant). */
129
177
  private selectOption;
130
178
  private allImages;
131
179
  private get activeImage();
@@ -139,6 +187,10 @@ declare class VioProductDetail extends LitElement {
139
187
  * loads immediately. Reuses the working Klarna Payments flow (no express SDK).
140
188
  */
141
189
  private buyWithKlarna;
190
+ /** Buy with Vipps — opens the checkout with Vipps preselected. */
191
+ private buyWithVipps;
192
+ /** Buy with Stripe — opens the checkout with Stripe preselected. */
193
+ private buyWithStripe;
142
194
  /**
143
195
  * Express buy with Apple Pay. Runs synchronously inside the click so the
144
196
  * Apple Pay sheet keeps the user gesture: add to cart → open checkout (sets
@@ -162,13 +214,15 @@ declare class VioCart extends LitElement {
162
214
  /** Drawer visibility. Reflects to attribute for `:host([open])`. */
163
215
  open: boolean;
164
216
  heading: string;
165
- checkoutLabel: string;
166
217
  emptyLabel: string;
167
218
  subtotalLabel: string;
168
219
  private carts;
169
220
  private itemCount;
170
221
  /** True when Apple Pay is usable (Safari + device + Stripe configured). */
171
222
  private applePayAvailable;
223
+ /** Payment method names enabled for the sponsor (backend-configured).
224
+ * null = not loaded yet → all buttons render; [] = none enabled. */
225
+ private availableMethods;
172
226
  /** Set after an Apple Pay express purchase — switches the drawer to the
173
227
  * confirmation screen (so the rest of the cart/checkout is not shown). */
174
228
  private confirmedOrder;
@@ -176,12 +230,19 @@ declare class VioCart extends LitElement {
176
230
  private applePayHandle;
177
231
  /** Cart total Apple Pay was last prepared for (avoids redundant prep). */
178
232
  private preparedTotal;
233
+ /** In-flight guard for loadAvailablePaymentMethods. */
234
+ private loadingPaymentMethods;
179
235
  private boundOnCartChange;
180
236
  static styles: lit.CSSResult;
181
237
  connectedCallback(): void;
182
238
  disconnectedCallback(): void;
183
239
  close(): void;
184
240
  show(): void;
241
+ /** Which payment buttons to render — backend-configured per sponsor.
242
+ * Falls back to showing everything if the query fails or none is set. */
243
+ private loadAvailablePaymentMethods;
244
+ /** Backend names arrive as e.g. "Apple Pay" — compare letters only. */
245
+ private methodEnabled;
185
246
  updated(changed: Map<string, unknown>): void;
186
247
  /** Pre-resolve the Apple Pay sheet for the current cart total. */
187
248
  private refreshApplePay;
@@ -194,6 +255,10 @@ declare class VioCart extends LitElement {
194
255
  * (betalingsmetode). The host's checkout-open handler closes this cart and
195
256
  * opens <vio-checkout> in express mode with Klarna preselected. */
196
257
  private onKlarnaExpress;
258
+ /** Vipps — opens the checkout with Vipps preselected. */
259
+ private onVipps;
260
+ /** Stripe — opens the checkout with Stripe preselected. */
261
+ private onStripe;
197
262
  private get totalAcrossSponsors();
198
263
  private get primaryCurrency();
199
264
  private onIncrement;
@@ -222,6 +287,8 @@ declare class VioCheckout extends LitElement {
222
287
  private orderConfirmed;
223
288
  private confirmedMethod;
224
289
  private paymentError;
290
+ /** Neutral (non-error) status line: "verifying payment…" / "still processing". */
291
+ private paymentNotice;
225
292
  /** Snapshot of the placed order, for the confirmation screen. */
226
293
  private confirmedOrder;
227
294
  /** Active Klarna Payments widget handle + the subtotal it was mounted for. */
@@ -235,24 +302,84 @@ declare class VioCheckout extends LitElement {
235
302
  private klarnaAuthorizing;
236
303
  /** Chosen shipping option id (express flow) — drives the Klarna order total. */
237
304
  private selectedShipping;
305
+ /** Real per-supplier shippings from the backend (empty → static fallback). */
306
+ private availableShippingsList;
307
+ /** Payment method names enabled for the sponsor (backend-configured).
308
+ * null = not loaded yet → all buttons render; [] = none enabled. */
309
+ private availableMethods;
310
+ /** Redirecting to the Stripe / Vipps hosted page. */
311
+ private stripeLoading;
312
+ private vippsLoading;
238
313
  private form;
314
+ /** In-flight guard for loadAvailablePaymentMethods. */
315
+ private loadingPaymentMethods;
316
+ /** In-flight + attempted guards for loadAvailableShippings (change events
317
+ * fire per keystroke — without these, typing an address hammers the API). */
318
+ private loadingShippings;
319
+ private shippingsAttempted;
239
320
  private boundOnCheckoutChange;
240
321
  private boundOnPaymentComplete;
241
322
  private boundOnPaymentError;
242
323
  static styles: lit.CSSResult;
243
324
  connectedCallback(): void;
325
+ /**
326
+ * Detect the redirect return from a hosted payment page (Stripe / Vipps /
327
+ * Klarna): the return URL carries vio_payment/vio_method/vio_sponsor. On
328
+ * success: clear that sponsor's cart, show the confirmation drawer, emit
329
+ * vio:payment-success (analytics/host hooks) and scrub the URL params.
330
+ */
331
+ /** Backend checkout statuses that mean the payment went through. */
332
+ private static readonly PAID_STATUSES;
333
+ /** Statuses that mean the payment definitively did NOT go through. */
334
+ private static readonly FAILED_STATUSES;
335
+ /** Waits between GetCheckout attempts — PSP webhooks (Vipps especially) can
336
+ * land seconds after the shopper is redirected back, so a single immediate
337
+ * check misreads a successful charge as unpaid. ~20s total. */
338
+ private static readonly RETURN_VERIFY_DELAYS_MS;
339
+ /** Vipps polling cadence — up to 2 minutes. Its webhook can lag well behind
340
+ * the redirect; this window was verified against a live checkout. */
341
+ private static readonly VIPPS_STATUS_MAX_ATTEMPTS;
342
+ private static readonly VIPPS_STATUS_DELAY_MS;
343
+ /**
344
+ * Vipps redirects to our return URL the same way on cancel as on success —
345
+ * the URL alone can't tell them apart, and the generic checkout status can
346
+ * lag behind Vipps' own webhook. Poll Vipps' own state directly instead:
347
+ * AUTHORIZED confirms, CREATED means still processing (keep polling),
348
+ * anything else (including an unrecognized state) is treated as failed —
349
+ * fail-closed by default rather than guessing.
350
+ */
351
+ private pollVippsStatus;
352
+ /** Shared outcome handler for both the generic (GetCheckout) and the
353
+ * Vipps-specific (GetVippsStatus) return-verification paths. */
354
+ private applyReturnOutcome;
355
+ private checkReturnPaymentStatus;
356
+ /** Remove our payment-return params from the URL without a reload. */
357
+ private cleanReturnQueryParams;
244
358
  disconnectedCallback(): void;
245
- updated(): void;
359
+ updated(changed: Map<string, unknown>): void;
246
360
  close(): void;
247
361
  show(): void;
362
+ /** Fetch the real per-supplier shippings and preselect + persist the first. */
363
+ private loadAvailableShippings;
364
+ /** Whether all mandatory Leveringsadresse fields are filled. */
365
+ private get isAddressValid();
366
+ /** Whether a valid shipping option is selected (when shippings exist). */
367
+ private get hasSelectedShipping();
368
+ /** Which payment buttons to render — backend-configured per sponsor. */
369
+ private loadAvailablePaymentMethods;
370
+ /** Backend names arrive as e.g. "Apple Pay" — compare letters only. */
371
+ private methodEnabled;
248
372
  private refreshApplePay;
249
373
  private refreshKlarna;
250
374
  /** Mount (or re-mount on amount change) the Klarna Payments widget. */
251
375
  private mountKlarnaIfNeeded;
252
376
  private unmountKlarna;
377
+ /** Shippings in effect: backend per-supplier when loaded, static otherwise. */
378
+ private get shippingList();
253
379
  /** Selected shipping option (express flow). */
254
380
  private get shippingOption();
255
- /** Pick a shipping option → re-mounts the Klarna widget with the new total. */
381
+ /** Pick a shipping option → re-mounts the Klarna widget with the new total.
382
+ * Also persists the choice on the backend cart (per supplier). */
256
383
  private onSelectShipping;
257
384
  /** Switch the Klarna widget to a different payment_method_category. */
258
385
  private onKlarnaCategory;
@@ -262,11 +389,9 @@ declare class VioCheckout extends LitElement {
262
389
  private onApplePay;
263
390
  private onPay;
264
391
  /**
265
- * Complete the order for the selected method (Vipps / Card / plain Klarna).
266
- * Apple Pay and Klarna Express finish inside their own sheet/popup, so they
267
- * never reach here. No real PSP is wired for Vipps/Card in this iteration —
268
- * the capture happens backend-side in the full flow — so this confirms the
269
- * order state-only and shows the confirmation screen.
392
+ * Complete the order for the selected method. Apple Pay and Klarna Express
393
+ * finish inside their own sheet/popup; Stripe and Vipps redirect to their
394
+ * hosted pages (via onPay). Anything else confirms state-only.
270
395
  */
271
396
  private onCompleteOrder;
272
397
  /**
@@ -280,7 +405,9 @@ declare class VioCheckout extends LitElement {
280
405
  /** True for methods that complete via a separate sheet/widget, not the CTA. */
281
406
  private isExpressMethod;
282
407
  private orderTotal;
283
- /** Shipping cost (major units) applied in express mode, else 0. */
408
+ /** Shipping cost (major units) whenever a shipping option is in effect —
409
+ * express always has one; the normal flow has one once the backend
410
+ * shippings loaded (the choice IS persisted on the cart and charged). */
284
411
  private shippingMajor;
285
412
  /** Total to charge — items + shipping (express). */
286
413
  private payTotalLabel;
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@vio-live/web-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Vio Web SDK — in-site shoppable + native checkout, designed for editorial commerce sites",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
9
  "sideEffects": [
10
- "./dist/**"
10
+ "./dist/ui/index.js",
11
+ "./dist/react/index.js"
11
12
  ],
12
13
  "exports": {
13
14
  ".": {
@@ -21,6 +22,10 @@
21
22
  "./ui": {
22
23
  "types": "./dist/ui/index.d.ts",
23
24
  "import": "./dist/ui/index.js"
25
+ },
26
+ "./react": {
27
+ "types": "./dist/react/index.d.ts",
28
+ "import": "./dist/react/index.js"
24
29
  }
25
30
  },
26
31
  "files": [
@@ -40,8 +45,18 @@
40
45
  "graphql-request": "^7.1.0",
41
46
  "lit": "^3.2.0"
42
47
  },
48
+ "peerDependencies": {
49
+ "react": ">=18"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "react": {
53
+ "optional": true
54
+ }
55
+ },
43
56
  "devDependencies": {
57
+ "@lit/react": "^1.0.8",
44
58
  "@types/node": "^22.10.0",
59
+ "@types/react": "^19.2.17",
45
60
  "tsup": "^8.5.1",
46
61
  "typescript": "^5.6.3",
47
62
  "vite": "^6.0.0",
@@ -65,6 +80,7 @@
65
80
  "checkout",
66
81
  "web-components",
67
82
  "lit",
83
+ "react",
68
84
  "klarna",
69
85
  "editorial-commerce"
70
86
  ],