@openmockup-studio/player 0.0.0-stage → 0.2.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/embed.js ADDED
@@ -0,0 +1,106 @@
1
+ // src/options.ts
2
+ var e = (e, t) => e === null ? t : e !== "false" && e !== "0", t = (e) => e === null || e === "" || Number.isNaN(Number(e)) ? void 0 : Number(e);
3
+ function n(n) {
4
+ let r = (e) => n.getAttribute(e), i = {}, a = {}, o = r("trigger");
5
+ if (o && o !== "scene") {
6
+ let e = {
7
+ load: "load",
8
+ click: "click",
9
+ hover: "hover",
10
+ scroll: "scroll",
11
+ inview: "in-view",
12
+ "in-view": "in-view",
13
+ mousemove: "cursor-move",
14
+ "cursor-move": "cursor-move",
15
+ none: "none"
16
+ }[o];
17
+ e && (i.trigger = e);
18
+ }
19
+ let s = r("trigger-loop");
20
+ s !== null && (i.loop = s === "pingpong" ? "pingpong" : e(s, !0) ? "loop" : "none");
21
+ let c = t(r("trigger-delay"));
22
+ c !== void 0 && (i.delay = c / 1e3);
23
+ let l = t(r("trigger-speed"));
24
+ l !== void 0 && (i.speed = l), e(r("cursor-enabled"), !0) || (a.follow = 0);
25
+ let u = t(r("cursor-amount"));
26
+ u !== void 0 && (a.follow = u / 100);
27
+ let d = r("cursor-mode");
28
+ (d === "device" || d === "camera") && (a.mode = d);
29
+ let f = t(r("zoom-amount"));
30
+ f !== void 0 && e(r("zoom-enabled"), !0) && (r("zoom-mode") === "dolly" ? a.dolly = f / 100 : a.zoom = f / 100);
31
+ let p = t(r("shake-intensity"));
32
+ p !== void 0 && e(r("shake-enabled"), !0) && (a.shake = p / 100), Object.keys(a).length && (i.cursor = a);
33
+ let m = t(r("camera-zoom"));
34
+ m && (i.cameraZoom = m);
35
+ let h = navigator.connection, g = !!h?.saveData || /(^|-)2g$/.test(h?.effectiveType ?? "");
36
+ return {
37
+ src: r("src"),
38
+ mockupId: r("mockup-id") ?? r("uid"),
39
+ base: r("base") ?? "https://irgtrjmgflkcsye5.public.blob.vercel-storage.com/scenes",
40
+ poster: r("poster"),
41
+ loader: e(r("loader"), !1),
42
+ progressive: e(r("progressive"), !0),
43
+ lowBandwidth: r("low-bandwidth") === null ? g : e(r("low-bandwidth"), g),
44
+ theme: r("theme") === "dark" ? "dark" : "light",
45
+ backgroundColor: r("background-color")?.trim() || null,
46
+ overrides: i
47
+ };
48
+ }
49
+ function r(e) {
50
+ return e.src ? e.src : e.mockupId ? `${e.base.replace(/\/$/, "")}/${e.mockupId}/project.json` : null;
51
+ }
52
+ // src/embed.ts
53
+ var i = "mockup-embed", a = class extends HTMLElement {
54
+ static get observedAttributes() {
55
+ return [
56
+ "src",
57
+ "mockup-id",
58
+ "aspect-ratio",
59
+ "width",
60
+ "height",
61
+ "poster",
62
+ "theme"
63
+ ];
64
+ }
65
+ player = null;
66
+ observer = null;
67
+ poster = null;
68
+ loading = !1;
69
+ connectedCallback() {
70
+ this.style.display ||= "block", this.style.position ||= "relative", this.style.overflow = "hidden", this.applySize(), this.showPoster();
71
+ let e = n(this);
72
+ e.lowBandwidth || (e.overrides.trigger === "load" || this.getAttribute("trigger") === "load" ? this.load() : (this.observer = new IntersectionObserver((e) => {
73
+ e.some((e) => e.isIntersecting) && (this.observer?.disconnect(), this.observer = null, this.load());
74
+ }, { rootMargin: "200px" }), this.observer.observe(this)));
75
+ }
76
+ disconnectedCallback() {
77
+ this.observer?.disconnect(), this.observer = null, this.player?.dispose(), this.player = null;
78
+ }
79
+ attributeChangedCallback(e) {
80
+ (e === "aspect-ratio" || e === "width" || e === "height") && this.applySize(), e === "poster" && this.showPoster();
81
+ }
82
+ applySize() {
83
+ let e = this.getAttribute("width"), t = this.getAttribute("height"), n = this.getAttribute("aspect-ratio"), r = (e) => /^\d+(\.\d+)?$/.test(e) ? `${e}px` : e;
84
+ e && (this.style.width = r(e)), t && (this.style.height = r(t)), n && !t && (this.style.aspectRatio = n), !e && !this.style.width && (this.style.width = "100%"), n || t || this.style.height || (this.style.aspectRatio = "16 / 9");
85
+ }
86
+ showPoster() {
87
+ let e = this.getAttribute("poster");
88
+ e && (this.poster || (this.poster = document.createElement("img"), this.poster.alt = "", this.poster.style.cssText = "position:absolute;inset:0;width:100%;height:100%;object-fit:cover;transition:opacity .4s", this.prepend(this.poster)), this.poster.src = e);
89
+ }
90
+ async load() {
91
+ if (this.loading || this.player) return;
92
+ this.loading = !0;
93
+ let e = n(this), t = r(e);
94
+ if (!t) console.warn(`<${i}> needs a src or mockup-id attribute.`);
95
+ else try {
96
+ let n = await import("./runtime-RiyRiexX.js").then((e) => e.t);
97
+ this.player = await n.mount(this, e, t), this.poster && (this.poster.style.opacity = "0", setTimeout(() => this.poster?.remove(), 450));
98
+ } catch (e) {
99
+ console.error(`<${i}> failed to load`, e);
100
+ } finally {
101
+ this.loading = !1;
102
+ }
103
+ }
104
+ };
105
+ typeof customElements < "u" && !customElements.get(i) && customElements.define(i, a);
106
+ export { a as MockupEmbed };
@@ -0,0 +1,10 @@
1
+ // \0rolldown/runtime.js
2
+ var e = Object.defineProperty, t = (t, n) => {
3
+ let r = {};
4
+ for (var i in t) e(r, i, {
5
+ get: t[i],
6
+ enumerable: !0
7
+ });
8
+ return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
+ };
10
+ export { t };