@vitraun/webar 0.1.0 → 0.1.2

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/LICENSE.txt ADDED
@@ -0,0 +1,10 @@
1
+ Vitraun — software license
2
+
3
+ Copyright (c) Vitraun. All rights reserved.
4
+
5
+ This package is proprietary. Redistribution, modification, sublicensing,
6
+ or use beyond the rights expressly granted in your written agreement with
7
+ Vitraun is prohibited unless Vitraun authorizes otherwise in writing.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. For
10
+ licensing inquiries, contact Vitraun.
package/README.md CHANGED
@@ -1,13 +1,5 @@
1
1
  # @vitraun/webar
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@vitraun/webar.svg)](https://www.npmjs.com/package/@vitraun/webar)
4
- [![npm downloads](https://img.shields.io/npm/dw/@vitraun/webar.svg)](https://www.npmjs.com/package/@vitraun/webar)
5
- [![CI](https://img.shields.io/github/actions/workflow/status/clagils/tryon-new-version/ci.yml?branch=main)](https://github.com/clagils/tryon-new-version/actions)
6
- [![Coverage](https://img.shields.io/codecov/c/github/clagils/tryon-new-version/main.svg)](https://codecov.io/gh/clagils/tryon-new-version)
7
- [![Bundle size](https://img.shields.io/bundlephobia/minzip/@vitraun/webar)](https://bundlephobia.com/package/@vitraun/webar)
8
- [![License](https://img.shields.io/npm/l/@vitraun/webar.svg)](https://www.npmjs.com/package/@vitraun/webar)
9
- [![TypeScript](https://img.shields.io/badge/types-TypeScript-blue.svg)](https://www.typescriptlang.org/)
10
-
11
3
  Web Component package for Vitraun Virtual Try-On (`<vitraun-vto>`), distributed as npm + CDN bundle.
12
4
 
13
5
  ## Install (npm)
@@ -18,24 +10,46 @@ npm i @vitraun/webar
18
10
 
19
11
  ```ts
20
12
  import '@vitraun/webar'
13
+
14
+ // In React / TSX you can write `auto-open={true}` (no spread needed).
21
15
  ```
22
16
 
23
17
  ```html
24
18
  <vitraun-vto
25
- merchant-id="MRCT-KEY-000001"
26
- env="prod"
27
- lang="pt-BR"
28
- platform="web"
29
- isolated-sku="8028997081552"
30
- apply-skus="SKU001,SKU002"
19
+ merchant-id="vtrn-mch-key-..."
20
+ widget-id="vtrn-wdg-key-..."
21
+ lang="en"
22
+ auto-open
31
23
  ></vitraun-vto>
32
24
  ```
33
25
 
34
- Required attributes: **`merchant-id`**, **`env`**. The **`env`** value selects Vitraun hosts: `https://api.{env}.vitraun.com/v1/tryon/init` and `https://app.{env}.vitraun.com/{lang}/virtual-tryon` for the iframe.
26
+ **Try-On app origin (`data-base-url`)** is baked into the published bundle from `constants/default-widget-base-url.js` (default dev app origin). Retailers do not need to set it. Use `**data-base-url`** only to override (staging, self-hosted). Rebuild with `VITRAUN_WIDGET_EMBEDDED_BASE_URL=<origin>` when the default dev host is wrong for your setup.
27
+
28
+ The **widget script** itself should be loaded from your **CDN**, from **[jsDelivr](https://www.jsdelivr.com/)** (mirror npm), or via `import '@vitraun/webar'` — not from the Try-On Next.js app.
29
+
30
+ ### jsDelivr (`@vitraun/webar` only)
31
+
32
+ After **`npm publish`** of `@vitraun/webar`, files under `dist/` are available on jsDelivr (paths match the tarball):
33
+
34
+ ```text
35
+ https://cdn.jsdelivr.net/npm/@vitraun/webar@<version>/dist/widget.min.js
36
+ https://cdn.jsdelivr.net/npm/@vitraun/webar@<version>/dist/events.min.js
37
+ ```
38
+
39
+ Example (`<version>` = published semver, e.g. `0.1.2`):
40
+
41
+ ```html
42
+ <script src="https://cdn.jsdelivr.net/npm/@vitraun/webar@0.1.2/dist/widget.min.js"></script>
43
+ <script type="module">
44
+ import { subscribeVitraunVTOEvents } from 'https://cdn.jsdelivr.net/npm/@vitraun/webar@0.1.2/dist/events.min.js'
45
+ </script>
46
+ ```
47
+
48
+ The `package.json` field **`jsdelivr`** points to `dist/widget.min.js` so the default short URL `https://cdn.jsdelivr.net/npm/@vitraun/webar` resolves to the widget bundle when supported by jsDelivr.
35
49
 
36
- The **widget script** itself should be loaded from your **CDN** (or from npm/unpkg/jsDelivr during development), not from the Try-On Next.js app.
50
+ Optional attribute `**auto-open`**: when present (or `auto-open="true"`), the element calls `open()` after it connects, so hosts do not need a `useLayoutEffect` or script callback.
37
51
 
38
- Optional attribute **`debug`**: when `true`, the widget logs diagnostic messages to the browser console (`[vitraun-vto]` prefix).
52
+ Optional attribute `**console**`: when `true`, the widget shows an Events console button that opens a modal with captured Try-On events.
39
53
 
40
54
  ## Events and logs helpers
41
55
 
@@ -66,24 +80,9 @@ import { useVitraunVTOEventLogs } from '@vitraun/webar/react'
66
80
  const { events, clearEvents } = useVitraunVTOEventLogs(containerRef.current)
67
81
  ```
68
82
 
69
- ## jsDelivr (npm mirror)
70
-
71
- After publishing **`@vitraun/webar-cdn`** (workspace `vto-npm/cdn`, built from this package’s `dist/`), use [jsDelivr](https://www.jsdelivr.com/) URLs such as `https://cdn.jsdelivr.net/npm/@vitraun/webar-cdn@<version>/widget.min.js` — see [`../cdn/README.md`](../cdn/README.md).
72
-
73
- ## CDN and npm (same package, two browser bundles)
74
-
75
- **`npm publish`** ships **`dist/widget.min.js`** and **`dist/events.min.js`** inside `@vitraun/webar`. **`npm run deploy:cdn`** uploads **only those two files** to the versioned prefix (`@vitraun/webar@<version>/`), matching what retailers get from the tarball.
76
-
77
- | File | Role |
78
- |------|------|
79
- | **`widget.min.js`** | IIFE — `<script src="...">`; registers `<vitraun-vto>`. |
80
- | **`events.min.js`** | ESM — optional; `import` behind `type="module"` for `subscribeVitraunVTOEvents` and constants (re-exported from `@vitraun/core`). |
81
-
82
- **`widget-runtime.min.js`** stays in the **npm** package for `import '@vitraun/webar'` (dynamic import from `dist/index.min.js`). It is **not** uploaded by the default CDN script so shops on CDN only deal with these two assets.
83
-
84
83
  ## Use via CDN (HTML puro)
85
84
 
86
- After each release, publish both assets (S3 + CloudFront, R2, etc.). This repo ships an **AWS S3** helper (AWS CLI):
85
+ Publish `dist/widget.min.js` and `dist/widget-runtime.min.js` to your CDN after each release (S3 + CloudFront, R2, etc.). This repo ships an **AWS S3** helper that uses the AWS CLI:
87
86
 
88
87
  ```bash
89
88
  npm run build
@@ -94,61 +93,15 @@ npm run deploy:cdn
94
93
 
95
94
  See `config/cdn-upload.env.example` for all variables (optional root prefix, dry-run, region).
96
95
 
97
- **Minimum (widget only):**
98
-
99
96
  ```html
100
- <script src="https://cdn.example.com/@vitraun/webar@0.1.0/widget.min.js"></script>
97
+ <script src="https://cdn.example.com/@vitraun/webar@0.1.0/dist/widget.min.js"></script>
101
98
  <vitraun-vto
102
99
  merchant-id="vtrn-mch-key-..."
103
- env="prod"
104
- lang="en-US"
105
- platform="web"
100
+ widget-id="vtrn-wdg-key-..."
101
+ lang="en"
106
102
  ></vitraun-vto>
107
103
  <script>
108
104
  document.querySelector('vitraun-vto')?.open()
109
105
  </script>
110
106
  ```
111
107
 
112
- **With event helpers (second file, ESM):**
113
-
114
- ```html
115
- <script src="https://cdn.example.com/@vitraun/webar@0.1.0/widget.min.js"></script>
116
- <script type="module">
117
- import { subscribeVitraunVTOEvents } from 'https://cdn.example.com/@vitraun/webar@0.1.0/events.min.js'
118
- const el = document.querySelector('vitraun-vto')
119
- const stop = subscribeVitraunVTOEvents(el, (entry) => {
120
- console.log(entry.type, entry.detail)
121
- })
122
- </script>
123
- ```
124
-
125
- ## Build outputs (`dist/`)
126
-
127
- After `npm run build`, `dist/` contains **only** the integration bundles (JS + types):
128
-
129
- - `dist/index.min.js` (ESM npm entry)
130
- - `dist/index.d.ts` (types)
131
- - `dist/events.min.js`, `dist/react.min.js`, `dist/react.d.ts`
132
- - `dist/widget-runtime.min.js` (ESM runtime loaded by npm entry)
133
- - `dist/widget.min.js` (IIFE for script tag)
134
-
135
- MediaPipe/WASM and the `.task` model are **not** placed under `webar/dist`. They are downloaded into the Try-On app (`vto-front`) via `scripts/vendor-webar-engine-assets.mjs` into `public/webar-assets/` (iframe origin). **Requires network access** on `npm install` / `prebuild` in `vto-front`.
136
-
137
- ## What gets published to npm
138
-
139
- The **npm tarball** lists `package.json` → `files`. For **browser** integration without a bundler, the same two CDN artifacts are **`dist/widget.min.js`** and **`dist/events.min.js`** (same version prefix on S3 after `deploy:cdn`). **`widget-runtime.min.js`** backs the ESM entry `import '@vitraun/webar'`. Heavy engine assets are served from the hosted Try-On app.
140
-
141
- ## Monorepo layout
142
-
143
- This package lives under `vto-npm/webar` and depends on **`@vitraun/core`** for shared event contracts. See the repo root `vto-npm/README.md` for workspace layout.
144
-
145
- The canonical widget source file lives at `vto-npm/core/src/widget.js` (resolved at build time via `webar/constants/widget-source-path.js`).
146
-
147
- Public API compatibility is documented in `docs/public-api-contract.md` (repo root).
148
-
149
- Architecture and embed flow (iframe, `postMessage`, `virtual-tryon-embed-init`, heartbeat): [`../docs/webar-widget-iframe-flow.md`](../docs/webar-widget-iframe-flow.md) (pt-BR).
150
-
151
- ## Versioning
152
-
153
- - `@vitraun/webar` follows semver for its public exports and hook signatures.
154
- - `@vitraun/core` ships shared contracts; coordinate major bumps when event payloads change.
package/dist/index.min.js CHANGED
@@ -1 +1 @@
1
- var a=["addToCart","removeFromCart","redirectToCart","analysisFinished"],T=["statusChange","vtoUsage"],u=e=>Array.isArray(e)?e:[],V=(e={})=>{let n=u(e.eventTypes).filter(t=>typeof t=="string"&&t.trim());if(n.length>0)return[...new Set(n)];let i=e.includeStatusChange===!0,s=e.includeVtoUsage===!0,r=[...a];return i&&r.push("statusChange"),s&&r.push("vtoUsage"),[...new Set(r)]},E=e=>{let n=e;return{type:e.type,detail:n.detail,timestamp:new Date().toISOString(),nativeEvent:e}},o=(e,n,i={})=>{if(!e||typeof e.addEventListener!="function")return()=>{};if(typeof n!="function")return()=>{};let s=V(i);if(s.length===0)return()=>{};let r=t=>{n(E(t))};return s.forEach(t=>{e.addEventListener(t,r)}),()=>{s.forEach(t=>{e.removeEventListener(t,r)})}};var c=typeof window<"u"&&typeof HTMLElement<"u"&&typeof customElements<"u";c&&import("./widget-runtime.min.js");export{a as VITRAUN_VTO_DEFAULT_EVENT_TYPES,T as VITRAUN_VTO_EXTRA_EVENT_TYPES,E as createVitraunEventLogEntry,o as subscribeVitraunVTOEvents};
1
+ var u=(e=globalThis)=>e==null?!1:typeof e.window<"u"&&typeof e.HTMLElement<"u"&&typeof e.customElements<"u";var a=["addToCart","removeFromCart","redirectToCart","analysisFinished"],T=["statusChange","vtoUsage"],V=e=>Array.isArray(e)?e:[],f=(e={})=>{let n=V(e.eventTypes).filter(t=>typeof t=="string"&&t.trim());if(n.length>0)return[...new Set(n)];let s=e.includeStatusChange===!0,i=e.includeVtoUsage===!0,r=[...a];return s&&r.push("statusChange"),i&&r.push("vtoUsage"),[...new Set(r)]},E=e=>{let n=e;return{type:e.type,detail:n.detail,timestamp:new Date().toISOString(),nativeEvent:e}},o=(e,n,s={})=>{if(!e||typeof e.addEventListener!="function")return()=>{};if(typeof n!="function")return()=>{};let i=f(s);if(i.length===0)return()=>{};let r=t=>{n(E(t))};return i.forEach(t=>{e.addEventListener(t,r)}),()=>{i.forEach(t=>{e.removeEventListener(t,r)})}};u()&&import("./widget-runtime.min.js");export{a as VITRAUN_VTO_DEFAULT_EVENT_TYPES,T as VITRAUN_VTO_EXTRA_EVENT_TYPES,E as createVitraunEventLogEntry,o as subscribeVitraunVTOEvents};
package/package.json CHANGED
@@ -1,22 +1,14 @@
1
1
  {
2
2
  "name": "@vitraun/webar",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Vitraun WebAR widget as Web Component",
5
- "license": "UNLICENSED",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/clagils/tryon-new-version.git",
9
- "directory": "vto-npm/webar"
10
- },
11
- "homepage": "https://github.com/clagils/tryon-new-version/tree/main/vto-npm/webar",
12
- "bugs": {
13
- "url": "https://github.com/clagils/tryon-new-version/issues"
14
- },
5
+ "license": "SEE LICENSE IN LICENSE.txt",
15
6
  "publishConfig": {
16
7
  "access": "public"
17
8
  },
18
9
  "private": false,
19
10
  "type": "module",
11
+ "jsdelivr": "dist/widget.min.js",
20
12
  "main": "./dist/index.min.js",
21
13
  "module": "./dist/index.min.js",
22
14
  "types": "./dist/index.d.ts",
@@ -37,6 +29,7 @@
37
29
  "./events": "./dist/events.min.js"
38
30
  },
39
31
  "files": [
32
+ "LICENSE.txt",
40
33
  "dist/index.min.js",
41
34
  "dist/index.d.ts",
42
35
  "dist/events.min.js",
@@ -52,16 +45,24 @@
52
45
  "bundle:js": "node ./scripts/bundle-dist.mjs",
53
46
  "typecheck": "tsc -p tsconfig.json --noEmit",
54
47
  "lint": "eslint \"src/**/*.js\"",
48
+ "test": "vitest run",
49
+ "test:coverage": "vitest run --coverage",
55
50
  "clean": "rm -rf dist",
56
51
  "deploy:cdn": "node ./scripts/upload-cdn-assets.mjs"
57
52
  },
58
53
  "devDependencies": {
59
- "@vitraun/core": "0.1.0",
54
+ "@testing-library/react": "^16.3.2",
60
55
  "@types/node": "^20",
61
56
  "@types/react": "^19.2.14",
57
+ "@vitest/coverage-v8": "^3.2.4",
58
+ "@vitraun/core": "^0.1.0",
62
59
  "esbuild": "^0.25.9",
63
60
  "eslint": "^9.39.1",
64
- "typescript": "^5.9.3"
61
+ "jsdom": "^26.1.0",
62
+ "react": "^19.2.5",
63
+ "react-dom": "^19.2.5",
64
+ "typescript": "^5.9.3",
65
+ "vitest": "^3.2.4"
65
66
  },
66
67
  "peerDependencies": {
67
68
  "react": ">=18",