@car-cutter/react-webplayer 0.7.0 → 0.9.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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./shared-Df-jUuiC.cjs");require("react/jsx-runtime");const W=require("react"),y=require("react-dom");var S=Object.defineProperty,L=(e,t,r)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,O=(e,t,r)=>(L(e,typeof t!="symbol"?t+"":t,r),r);const I={stringify:e=>e,parse:e=>e},V={stringify:e=>`${e}`,parse:e=>parseFloat(e)},M={stringify:e=>e?"true":"false",parse:e=>/^[ty1-9]/i.test(e)},D={stringify:e=>e.name,parse:(e,t,r)=>{const s=(()=>{if(typeof window<"u"&&e in window)return window[e];if(typeof global<"u"&&e in global)return global[e]})();return typeof s=="function"?s.bind(r):void 0}},R={stringify:e=>JSON.stringify(e),parse:e=>JSON.parse(e)},N={string:I,number:V,boolean:M,function:D,json:R};function w(e){return e.replace(/([a-z0-9])([A-Z])/g,(t,r,s)=>`${r}-${s.toLowerCase()}`)}const b=Symbol.for("r2wc.render"),T=Symbol.for("r2wc.connected"),u=Symbol.for("r2wc.context"),l=Symbol.for("r2wc.props");function G(e,t,r){var s,A,P;t.props||(t.props=e.propTypes?Object.keys(e.propTypes):[]);const m=Array.isArray(t.props)?t.props.slice():Object.keys(t.props),p={},f={},d={};for(const i of m){p[i]=Array.isArray(t.props)?"string":t.props[i];const o=w(i);f[i]=o,d[o]=i}class g extends HTMLElement{constructor(){super(),O(this,s,!0),O(this,A),O(this,P,{}),O(this,"container"),t.shadow?this.container=this.attachShadow({mode:t.shadow}):this.container=this,this[l].container=this.container;for(const o of m){const _=f[o],c=this.getAttribute(_),a=p[o],E=a?N[a]:null;E!=null&&E.parse&&c&&(this[l][o]=E.parse(c,_,this))}}static get observedAttributes(){return Object.keys(d)}connectedCallback(){this[T]=!0,this[b]()}disconnectedCallback(){this[T]=!1,this[u]&&r.unmount(this[u]),delete this[u]}attributeChangedCallback(o,_,c){const a=d[o],E=p[a],h=E?N[E]:null;a in p&&h!=null&&h.parse&&c&&(this[l][a]=h.parse(c,o,this),this[b]())}[(s=T,A=u,P=l,b)](){this[T]&&(this[u]?r.update(this[u],this[l]):this[u]=r.mount(this.container,e,this[l]))}}for(const i of m){const o=f[i],_=p[i];Object.defineProperty(g.prototype,i,{enumerable:!0,configurable:!0,get(){return this[l][i]},set(c){this[l][i]=c;const a=_?N[_]:null;if(a!=null&&a.stringify){const E=a.stringify(c,o,this);this.getAttribute(o)!==E&&this.setAttribute(o,E)}else this[b]()}})}return g}function F(e,t,r){const s=W.createElement(t,r);return y.render(s,e),{container:e,ReactComponent:t}}function v({container:e,ReactComponent:t},r){const s=W.createElement(t,r);y.render(s,e)}function Y({container:e}){y.unmountComponentAtNode(e)}function C(e,t={}){return G(e,t,{mount:F,update:v,unmount:Y})}const j=C(n.WebPlayerWithInjectedStyles,{shadow:"open",props:{compositionUrl:"string",hideCategories:"boolean",infiniteCarrousel:"boolean",permanentGallery:"boolean",minMediaWidth:"number",maxMediaWidth:"number",mediaLoadStrategy:"string",preventFullScreen:"boolean",eventPrefix:"string",reverse360:"boolean"}}),k=C(n.WebPlayerCustomMedia,{shadow:"closed",props:{index:"number",thumbnailSrc:"string"}}),$=C(n.WebPlayerIcon,{shadow:"closed",props:{name:"string"}});function B(){customElements.define(n.WEB_PLAYER_WC_TAG,j),customElements.define(n.WEB_PLAYER_CUSTOM_MEDIA_WC_TAG,k),customElements.define(n.WEB_PLAYER_ICON_WC_TAG,$)}function H(){n.checkCustomElementsDefinition()||B()}H();exports.DEFAULT_EVENT_PREFIX=n.DEFAULT_EVENT_PREFIX;exports.EVENT_COMPOSITION_LOADED=n.EVENT_COMPOSITION_LOADED;exports.EVENT_COMPOSITION_LOADING=n.EVENT_COMPOSITION_LOADING;exports.EVENT_COMPOSITION_LOAD_ERROR=n.EVENT_COMPOSITION_LOAD_ERROR;exports.EVENT_EXTEND_MODE_OFF=n.EVENT_EXTEND_MODE_OFF;exports.EVENT_EXTEND_MODE_ON=n.EVENT_EXTEND_MODE_ON;exports.EVENT_GALLERY_CLOSE=n.EVENT_GALLERY_CLOSE;exports.EVENT_GALLERY_OPEN=n.EVENT_GALLERY_OPEN;exports.EVENT_HOTSPOTS_OFF=n.EVENT_HOTSPOTS_OFF;exports.EVENT_HOTSPOTS_ON=n.EVENT_HOTSPOTS_ON;exports.EVENT_ITEM_CHANGE=n.EVENT_ITEM_CHANGE;exports.WEB_PLAYER_ICON_WC_TAG=n.WEB_PLAYER_ICON_WC_TAG;exports.WEB_PLAYER_WC_TAG=n.WEB_PLAYER_WC_TAG;exports.WebPlayer=n.WebPlayer;exports.WebPlayerCustomMedia=n.WebPlayerCustomMedia$1;exports.WebPlayerIcon=n.WebPlayerIcon$1;exports.generateCompositionUrl=n.generateCompositionUrl;
@@ -0,0 +1,169 @@
1
+ import { FC } from 'react';
2
+ import { PropsWithChildren } from 'react';
3
+
4
+ declare type AspectRatio = `${number}:${number}`;
5
+
6
+ declare type Category = {
7
+ id: string;
8
+ title: string;
9
+ items: Item[];
10
+ };
11
+
12
+ export declare type Composition = {
13
+ aspectRatio: AspectRatio;
14
+ imageHdWidth: MediaWidth;
15
+ imageSubWidths: MediaWidth[];
16
+ categories: Category[];
17
+ };
18
+
19
+ export declare const DEFAULT_EVENT_PREFIX = "cc-webplayer:" satisfies string;
20
+
21
+ export declare const EVENT_COMPOSITION_LOAD_ERROR = "composition-load-error";
22
+
23
+ export declare const EVENT_COMPOSITION_LOADED = "composition-loaded";
24
+
25
+ export declare const EVENT_COMPOSITION_LOADING = "composition-loading";
26
+
27
+ export declare const EVENT_EXTEND_MODE_OFF = "extend-mode-off";
28
+
29
+ export declare const EVENT_EXTEND_MODE_ON = "extend-mode-on";
30
+
31
+ export declare const EVENT_GALLERY_CLOSE = "gallery-close";
32
+
33
+ export declare const EVENT_GALLERY_OPEN = "gallery-open";
34
+
35
+ export declare const EVENT_HOTSPOTS_OFF = "hotspots-off";
36
+
37
+ export declare const EVENT_HOTSPOTS_ON = "hotspots-on";
38
+
39
+ export declare const EVENT_ITEM_CHANGE = "item-change";
40
+
41
+ /**
42
+ * Generates a URL for fetching the composition JSON for a given customer and vehicle.
43
+ *
44
+ * @param {string} hashedCustomerId - The ID of the customer (hashed with SHA-256).
45
+ * @param {string} vin - The Vehicle Identification Number.
46
+ * @returns {string} The URL to fetch the composition JSON.
47
+ */
48
+ export declare function generateCompositionUrl(
49
+ hashedCustomerId: string,
50
+ vin: string
51
+ ): string {
52
+ return `https://cdn.car-cutter.com/gallery/${hashedCustomerId}/${vin}/composition_v3.json`;
53
+ }
54
+
55
+ declare type Hotspot = {
56
+ title: string;
57
+ icon?: string;
58
+ description?: string;
59
+ position: {
60
+ x: number;
61
+ y: number;
62
+ };
63
+ detail?: {
64
+ type: "image" | "link" | "pdf";
65
+ src: string;
66
+ };
67
+ };
68
+
69
+ declare type ImageItem = { type: "image" } & ImageWithHotspots;
70
+
71
+ declare type ImageWithHotspots = {
72
+ src: string;
73
+ hotspots?: Hotspot[];
74
+ };
75
+
76
+ export declare type Item = ImageItem | VideoItem | ThreeSixtyItem;
77
+
78
+ export declare type MediaLoadStrategy = "quality" | "balanced" | "speed";
79
+
80
+ declare type MediaWidth = number;
81
+
82
+ declare type ThreeSixtyItem = {
83
+ type: "360";
84
+ images: ImageWithHotspots[];
85
+ };
86
+
87
+ declare type VideoItem = {
88
+ type: "video";
89
+ src: string;
90
+ poster?: string;
91
+ };
92
+
93
+ export declare const WEB_PLAYER_ICON_WC_TAG = "cc-webplayer-icon";
94
+
95
+ export declare const WEB_PLAYER_WC_TAG = "cc-webplayer";
96
+
97
+ export declare const WebPlayer: FC<WebPlayerProps>;
98
+
99
+ export declare const WebPlayerCustomMedia: FC<PropsWithChildren<WebPlayerCustomMediaProps>>;
100
+
101
+ export declare type WebPlayerCustomMediaProps = {
102
+ index: number;
103
+ thumbnailSrc?: string;
104
+ };
105
+
106
+ export declare const WebPlayerIcon: FC<PropsWithChildren<WebPlayerIconProps>>;
107
+
108
+ declare type WebPlayerIconName =
109
+ | "UI_ARROW_RIGHT" // Right arrow navigation (is mirrored on X axis for left arrow)
110
+ | "UI_BURGER" // Toggle Burger menu
111
+ | "UI_CLOSE" // Exit zoom, details or full screen
112
+ | "UI_EXTEND" // Extend the view (and go full screen if possible)
113
+ | "UI_GALLERY" // Toggle gallery view
114
+ | "UI_HOTSPOTS" // Toggle Hotspots
115
+ | "UI_IMAGE" // Hotspot with detail image
116
+ | "UI_MINUS" // Reduce zoom
117
+ | "UI_PAUSE" // Pause video
118
+ | "UI_PLAY" // Play video
119
+ | "UI_PLUS" // Increase zoom
120
+ | "UI_REDUCE" // Reducing an extended view
121
+ | "UI_360" // 360-degree view
122
+ | "UI_VOLUME" // Video volume
123
+ | "UI_VOLUME_OFF" // Muted video
124
+ | "CONTROLS_PREV" // Go to previous media
125
+ | "CONTROLS_NEXT" // Go to next media
126
+ // eslint-disable-next-line @typescript-eslint/ban-types
127
+ | (string & {});
128
+
129
+ export declare type WebPlayerIconProps = {
130
+ name: WebPlayerIconName;
131
+ };
132
+
133
+ export declare type WebPlayerProps = PropsWithChildren<WebPlayerProps_2> & {
134
+ onCompositionLoading?: (url: string) => void;
135
+ onCompositionLoaded?: (composition: Composition) => void;
136
+ onCompositionLoadError?: (error: unknown) => void;
137
+ onItemChange?: (props: {
138
+ index: number;
139
+ item: Item;
140
+ }) => void;
141
+ onExtendModeOn?: () => void;
142
+ onExtendModeOff?: () => void;
143
+ onHotspotsOn?: () => void;
144
+ onHotspotsOff?: () => void;
145
+ onGalleryOpen?: () => void;
146
+ onGalleryClose?: () => void;
147
+ } & Pick<React.HTMLAttributes<HTMLElement>, "className" | "style">;
148
+
149
+ declare type WebPlayerProps_2 = {
150
+ compositionUrl: string;
151
+
152
+ // Layout
153
+ hideCategories?: boolean;
154
+ infiniteCarrousel?: boolean;
155
+ permanentGallery?: boolean;
156
+
157
+ // Medias loading
158
+ mediaLoadStrategy?: MediaLoadStrategy;
159
+ minMediaWidth?: MediaWidth;
160
+ maxMediaWidth?: MediaWidth;
161
+ preloadRange?: number;
162
+
163
+ // Miscelaneous
164
+ preventFullScreen?: boolean;
165
+ eventPrefix?: string;
166
+ reverse360?: boolean;
167
+ };
168
+
169
+ export { }
package/dist/legacy.js ADDED
@@ -0,0 +1,176 @@
1
+ import { W, a as S, b as w, c as I, d as L, e as M, f as D } from "./shared-Bn2By-os.js";
2
+ import { D as oe, j as re, E as se, k as ie, n as ae, m as ce, r as le, q as pe, p as ue, o as me, l as fe, g as Ee, h as be, i as he, s as de } from "./shared-Bn2By-os.js";
3
+ import "react/jsx-runtime";
4
+ import P from "react";
5
+ import g from "react-dom";
6
+ var V = Object.defineProperty, R = (e, t, n) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, f = (e, t, n) => (R(e, typeof t != "symbol" ? t + "" : t, n), n);
7
+ const v = {
8
+ stringify: (e) => e,
9
+ parse: (e) => e
10
+ }, j = {
11
+ stringify: (e) => `${e}`,
12
+ parse: (e) => parseFloat(e)
13
+ }, k = {
14
+ stringify: (e) => e ? "true" : "false",
15
+ parse: (e) => /^[ty1-9]/i.test(e)
16
+ }, x = {
17
+ stringify: (e) => e.name,
18
+ parse: (e, t, n) => {
19
+ const s = (() => {
20
+ if (typeof window < "u" && e in window)
21
+ return window[e];
22
+ if (typeof global < "u" && e in global)
23
+ return global[e];
24
+ })();
25
+ return typeof s == "function" ? s.bind(n) : void 0;
26
+ }
27
+ }, F = {
28
+ stringify: (e) => JSON.stringify(e),
29
+ parse: (e) => JSON.parse(e)
30
+ }, O = {
31
+ string: v,
32
+ number: j,
33
+ boolean: k,
34
+ function: x,
35
+ json: F
36
+ };
37
+ function G(e) {
38
+ return e.replace(
39
+ /([a-z0-9])([A-Z])/g,
40
+ (t, n, s) => `${n}-${s.toLowerCase()}`
41
+ );
42
+ }
43
+ const E = Symbol.for("r2wc.render"), b = Symbol.for("r2wc.connected"), p = Symbol.for("r2wc.context"), l = Symbol.for("r2wc.props");
44
+ function $(e, t, n) {
45
+ var s, T, N;
46
+ t.props || (t.props = e.propTypes ? Object.keys(e.propTypes) : []);
47
+ const h = Array.isArray(t.props) ? t.props.slice() : Object.keys(t.props), m = {}, d = {}, y = {};
48
+ for (const r of h) {
49
+ m[r] = Array.isArray(t.props) ? "string" : t.props[r];
50
+ const o = G(r);
51
+ d[r] = o, y[o] = r;
52
+ }
53
+ class A extends HTMLElement {
54
+ constructor() {
55
+ super(), f(this, s, !0), f(this, T), f(this, N, {}), f(this, "container"), t.shadow ? this.container = this.attachShadow({
56
+ mode: t.shadow
57
+ }) : this.container = this, this[l].container = this.container;
58
+ for (const o of h) {
59
+ const u = d[o], c = this.getAttribute(u), i = m[o], a = i ? O[i] : null;
60
+ a != null && a.parse && c && (this[l][o] = a.parse(c, u, this));
61
+ }
62
+ }
63
+ static get observedAttributes() {
64
+ return Object.keys(y);
65
+ }
66
+ connectedCallback() {
67
+ this[b] = !0, this[E]();
68
+ }
69
+ disconnectedCallback() {
70
+ this[b] = !1, this[p] && n.unmount(this[p]), delete this[p];
71
+ }
72
+ attributeChangedCallback(o, u, c) {
73
+ const i = y[o], a = m[i], _ = a ? O[a] : null;
74
+ i in m && _ != null && _.parse && c && (this[l][i] = _.parse(c, o, this), this[E]());
75
+ }
76
+ [(s = b, T = p, N = l, E)]() {
77
+ this[b] && (this[p] ? n.update(this[p], this[l]) : this[p] = n.mount(
78
+ this.container,
79
+ e,
80
+ this[l]
81
+ ));
82
+ }
83
+ }
84
+ for (const r of h) {
85
+ const o = d[r], u = m[r];
86
+ Object.defineProperty(A.prototype, r, {
87
+ enumerable: !0,
88
+ configurable: !0,
89
+ get() {
90
+ return this[l][r];
91
+ },
92
+ set(c) {
93
+ this[l][r] = c;
94
+ const i = u ? O[u] : null;
95
+ if (i != null && i.stringify) {
96
+ const a = i.stringify(c, o, this);
97
+ this.getAttribute(o) !== a && this.setAttribute(o, a);
98
+ } else
99
+ this[E]();
100
+ }
101
+ });
102
+ }
103
+ return A;
104
+ }
105
+ function Y(e, t, n) {
106
+ const s = P.createElement(t, n);
107
+ return g.render(s, e), {
108
+ container: e,
109
+ ReactComponent: t
110
+ };
111
+ }
112
+ function H({ container: e, ReactComponent: t }, n) {
113
+ const s = P.createElement(t, n);
114
+ g.render(s, e);
115
+ }
116
+ function U({ container: e }) {
117
+ g.unmountComponentAtNode(e);
118
+ }
119
+ function C(e, t = {}) {
120
+ return $(e, t, { mount: Y, update: H, unmount: U });
121
+ }
122
+ const B = C(W, {
123
+ shadow: "open",
124
+ props: {
125
+ compositionUrl: "string",
126
+ hideCategories: "boolean",
127
+ infiniteCarrousel: "boolean",
128
+ permanentGallery: "boolean",
129
+ minMediaWidth: "number",
130
+ maxMediaWidth: "number",
131
+ mediaLoadStrategy: "string",
132
+ preventFullScreen: "boolean",
133
+ eventPrefix: "string",
134
+ reverse360: "boolean"
135
+ }
136
+ }), J = C(S, {
137
+ shadow: "closed",
138
+ props: {
139
+ index: "number",
140
+ thumbnailSrc: "string"
141
+ }
142
+ }), X = C(w, {
143
+ shadow: "closed",
144
+ props: {
145
+ name: "string"
146
+ }
147
+ });
148
+ function q() {
149
+ customElements.define(L, B), customElements.define(
150
+ M,
151
+ J
152
+ ), customElements.define(D, X);
153
+ }
154
+ function z() {
155
+ I() || q();
156
+ }
157
+ z();
158
+ export {
159
+ oe as DEFAULT_EVENT_PREFIX,
160
+ re as EVENT_COMPOSITION_LOADED,
161
+ se as EVENT_COMPOSITION_LOADING,
162
+ ie as EVENT_COMPOSITION_LOAD_ERROR,
163
+ ae as EVENT_EXTEND_MODE_OFF,
164
+ ce as EVENT_EXTEND_MODE_ON,
165
+ le as EVENT_GALLERY_CLOSE,
166
+ pe as EVENT_GALLERY_OPEN,
167
+ ue as EVENT_HOTSPOTS_OFF,
168
+ me as EVENT_HOTSPOTS_ON,
169
+ fe as EVENT_ITEM_CHANGE,
170
+ D as WEB_PLAYER_ICON_WC_TAG,
171
+ L as WEB_PLAYER_WC_TAG,
172
+ Ee as WebPlayer,
173
+ be as WebPlayerCustomMedia,
174
+ he as WebPlayerIcon,
175
+ de as generateCompositionUrl
176
+ };