@openmockup-studio/player 0.0.0-stage → 0.1.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,103 @@
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 = navigator.connection, h = !!m?.saveData || /(^|-)2g$/.test(m?.effectiveType ?? "");
34
+ return {
35
+ src: r("src"),
36
+ mockupId: r("mockup-id") ?? r("uid"),
37
+ base: r("base") ?? "",
38
+ poster: r("poster"),
39
+ loader: e(r("loader"), !1),
40
+ progressive: e(r("progressive"), !0),
41
+ lowBandwidth: r("low-bandwidth") === null ? h : e(r("low-bandwidth"), h),
42
+ theme: r("theme") === "dark" ? "dark" : "light",
43
+ overrides: i
44
+ };
45
+ }
46
+ function r(e) {
47
+ return e.src ? e.src : e.mockupId ? `${e.base.replace(/\/$/, "")}/${e.mockupId}/project.json` : null;
48
+ }
49
+ // src/embed.ts
50
+ var i = "mockup-embed", a = class extends HTMLElement {
51
+ static get observedAttributes() {
52
+ return [
53
+ "src",
54
+ "mockup-id",
55
+ "aspect-ratio",
56
+ "width",
57
+ "height",
58
+ "poster",
59
+ "theme"
60
+ ];
61
+ }
62
+ player = null;
63
+ observer = null;
64
+ poster = null;
65
+ loading = !1;
66
+ connectedCallback() {
67
+ this.style.display ||= "block", this.style.position ||= "relative", this.style.overflow = "hidden", this.applySize(), this.showPoster();
68
+ let e = n(this);
69
+ e.lowBandwidth || (e.overrides.trigger === "load" || this.getAttribute("trigger") === "load" ? this.load() : (this.observer = new IntersectionObserver((e) => {
70
+ e.some((e) => e.isIntersecting) && (this.observer?.disconnect(), this.observer = null, this.load());
71
+ }, { rootMargin: "200px" }), this.observer.observe(this)));
72
+ }
73
+ disconnectedCallback() {
74
+ this.observer?.disconnect(), this.observer = null, this.player?.dispose(), this.player = null;
75
+ }
76
+ attributeChangedCallback(e) {
77
+ (e === "aspect-ratio" || e === "width" || e === "height") && this.applySize(), e === "poster" && this.showPoster();
78
+ }
79
+ applySize() {
80
+ let e = this.getAttribute("width"), t = this.getAttribute("height"), n = this.getAttribute("aspect-ratio"), r = (e) => /^\d+(\.\d+)?$/.test(e) ? `${e}px` : e;
81
+ 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");
82
+ }
83
+ showPoster() {
84
+ let e = this.getAttribute("poster");
85
+ 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);
86
+ }
87
+ async load() {
88
+ if (this.loading || this.player) return;
89
+ this.loading = !0;
90
+ let e = n(this), t = r(e);
91
+ if (!t) console.warn(`<${i}> needs a src or mockup-id attribute.`);
92
+ else try {
93
+ let n = await import("./runtime-D-Di0bkW.js").then((e) => e.t);
94
+ this.player = await n.mount(this, e, t), this.poster && (this.poster.style.opacity = "0", setTimeout(() => this.poster?.remove(), 450));
95
+ } catch (e) {
96
+ console.error(`<${i}> failed to load`, e);
97
+ } finally {
98
+ this.loading = !1;
99
+ }
100
+ }
101
+ };
102
+ typeof customElements < "u" && !customElements.get(i) && customElements.define(i, a);
103
+ 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 };