data-preview 1.0.2 → 1.0.3

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.
@@ -1,23 +1,23 @@
1
- const ee = (() => {
2
- const g = {
1
+ const te = (() => {
2
+ const b = {
3
3
  imgPad: 8,
4
4
  maxWRatio: 0.9,
5
5
  maxHRatio: 0.85,
6
6
  delayHide: 120,
7
7
  longPressDuration: 480,
8
8
  badgeOffset: 6
9
- }, y = 16, x = 12;
10
- let h, i, H, d, m, p, r, E = null, w = null, M = null, L = null, B = 0, u = null;
11
- const v = /* @__PURE__ */ new Map();
12
- let b = window.matchMedia("(pointer: coarse)").matches;
13
- const _ = window.matchMedia("(prefers-color-scheme: dark)");
9
+ }, y = 16, g = 12;
10
+ let h, i, L, u, m, p, r, M = null, T = null, k = null, P = null, _ = 0, l = null, v = null;
11
+ const w = /* @__PURE__ */ new Map();
12
+ let x = window.matchMedia("(pointer: coarse)").matches;
13
+ const z = window.matchMedia("(prefers-color-scheme: dark)");
14
14
  window.matchMedia("(pointer: coarse)").addEventListener("change", (e) => {
15
- b = e.matches;
15
+ x = e.matches;
16
16
  });
17
- function J() {
18
- h || (h = T("div", {
17
+ function K() {
18
+ h || (h = H("div", {
19
19
  style: "position:fixed;inset:0;z-index:99999;pointer-events:none;"
20
- }), r = T("div", {
20
+ }), r = H("div", {
21
21
  style: `
22
22
  position:fixed;
23
23
  width:24px;height:24px;
@@ -33,7 +33,7 @@ const ee = (() => {
33
33
  user-select:none;
34
34
  backdrop-filter:blur(4px);
35
35
  `
36
- }), r.textContent = "🖼️", i = T("div", {
36
+ }), r.textContent = "🖼️", i = H("div", {
37
37
  style: `
38
38
  position:fixed;
39
39
  border-radius:12px;
@@ -45,7 +45,7 @@ const ee = (() => {
45
45
  z-index:100000;
46
46
  will-change:transform,opacity;
47
47
  `
48
- }), p = T("button", {
48
+ }), p = H("button", {
49
49
  style: `
50
50
  position:absolute;top:6px;right:6px;
51
51
  width:26px;height:26px;
@@ -55,156 +55,157 @@ const ee = (() => {
55
55
  opacity:0;transition:opacity 0.15s;
56
56
  `
57
57
  }), p.textContent = "✕", p.setAttribute("aria-label", "关闭预览"), p.addEventListener("click", (e) => {
58
- e.stopPropagation(), O();
58
+ e.stopPropagation(), D();
59
59
  }), p.addEventListener("touchend", (e) => {
60
- e.stopPropagation(), O();
61
- }), H = T("div", { style: "position:relative;" }), d = T("img", { style: "display:block;", alt: "preview" }), m = T("div", { style: "font-size:11px;padding:5px 10px;white-space:nowrap;" }), H.append(d, p), i.append(H, m), h.append(r, i), document.body.appendChild(h), r.addEventListener("mouseenter", () => {
62
- if (clearTimeout(E), clearTimeout(w), !u) return;
63
- const e = D(u), n = I(u);
64
- e && q(e, n);
60
+ e.stopPropagation(), D();
61
+ }), L = H("div", { style: "position:relative;" }), u = H("img", { style: "display:block;", alt: "preview" }), m = H("div", { style: "font-size:11px;padding:5px 10px;white-space:nowrap;" }), L.append(u, p), i.append(L, m), h.append(r, i), document.body.appendChild(h), r.addEventListener("mouseenter", () => {
62
+ if (clearTimeout(M), clearTimeout(T), !l) return;
63
+ const e = R(l), n = N(l);
64
+ e && Q(e, n);
65
65
  }), r.addEventListener("mouseleave", () => {
66
- i.style.opacity !== "1" && A();
66
+ i.style.opacity !== "1" && O();
67
67
  }), r.addEventListener("click", () => {
68
- i.style.opacity === "1" && O();
68
+ i.style.opacity === "1" && D();
69
69
  }), i.addEventListener("mouseenter", () => {
70
- clearTimeout(E), clearTimeout(w), b || (p.style.opacity = "1");
70
+ clearTimeout(M), clearTimeout(T), x || (p.style.opacity = "1");
71
71
  }), i.addEventListener("mouseleave", () => {
72
- b || (p.style.opacity = "0"), A();
73
- }), z(), _.addEventListener("change", z));
72
+ x || (p.style.opacity = "0"), O();
73
+ }), A(), z.addEventListener("change", A));
74
74
  }
75
- function z() {
76
- const e = _.matches;
75
+ function A() {
76
+ const e = z.matches;
77
77
  i.style.background = e ? "#1c1c1e" : "#ffffff", i.style.border = e ? "1px solid rgba(255,255,255,.12)" : "1px solid rgba(0,0,0,.1)", i.style.boxShadow = e ? "0 12px 40px rgba(0,0,0,.55),0 2px 8px rgba(0,0,0,.3)" : "0 8px 32px rgba(0,0,0,.18),0 2px 8px rgba(0,0,0,.08)", m.style.background = e ? "rgba(255,255,255,.06)" : "rgba(0,0,0,.04)", m.style.color = e ? "rgba(255,255,255,.4)" : "rgba(0,0,0,.4)", m.style.borderTop = e ? "1px solid rgba(255,255,255,.08)" : "1px solid rgba(0,0,0,.06)", p.style.background = e ? "rgba(255,255,255,.15)" : "rgba(0,0,0,.15)", p.style.color = e ? "rgba(255,255,255,.8)" : "rgba(0,0,0,.6)";
78
78
  }
79
- function R(e) {
80
- const n = e.getBoundingClientRect(), t = g.badgeOffset;
79
+ function j(e) {
80
+ const n = e.getBoundingClientRect(), t = b.badgeOffset;
81
81
  r.style.left = n.right - 24 - t + "px", r.style.top = n.top + t + "px";
82
82
  }
83
- function j(e, n) {
84
- const t = g.imgPad * 2, o = m.offsetHeight || 22, s = Math.floor(window.innerWidth * g.maxWRatio) - t, c = Math.floor(window.innerHeight * g.maxHRatio) - t - o, f = e / n;
85
- let a, l;
86
- return f >= 1 ? (a = Math.min(s, e), l = a / f, l > c && (l = c, a = l * f)) : (l = Math.min(c, n), a = l * f, a > s && (a = s, l = a / f)), { pw: Math.round(a), ph: Math.round(l) };
83
+ function q(e, n) {
84
+ const t = b.imgPad * 2, o = m.offsetHeight || 22, s = Math.floor(window.innerWidth * b.maxWRatio) - t, d = Math.floor(window.innerHeight * b.maxHRatio) - t - o, f = e / n;
85
+ let a, c;
86
+ return f >= 1 ? (a = Math.min(s, e), c = a / f, c > d && (c = d, a = c * f)) : (c = Math.min(d, n), a = c * f, a > s && (a = s, c = a / f)), { pw: Math.round(a), ph: Math.round(c) };
87
87
  }
88
- function K(e, n) {
89
- if (!u) return;
90
- const t = u.getBoundingClientRect(), o = g.imgPad, s = m.offsetHeight || 22, { pw: c, ph: f } = j(e, n), a = c + o * 2, l = f + o * 2 + s, k = window.innerWidth, G = window.innerHeight;
91
- let C;
92
- t.left - x >= a + y ? C = t.left - x - a : k - t.right - x >= a + y ? C = t.right + x : C = S(t.left + (t.width - a) / 2, y, k - a - y);
88
+ function U(e, n) {
89
+ if (!l) return;
90
+ const t = l.getBoundingClientRect(), o = b.imgPad, s = m.offsetHeight || 22, { pw: d, ph: f } = q(e, n), a = d + o * 2, c = f + o * 2 + s, S = window.innerWidth, J = window.innerHeight;
93
91
  let W;
94
- G - t.bottom - x >= l + y ? W = t.bottom + x : t.top - x >= l + y ? W = t.top - x - l : W = S(t.top + (t.height - l) / 2, y, G - l - y), i.style.left = C + "px", i.style.top = W + "px", i.style.width = a + "px", H.style.padding = o + "px", d.style.width = c + "px", d.style.height = f + "px";
92
+ t.left - g >= a + y ? W = t.left - g - a : S - t.right - g >= a + y ? W = t.right + g : W = C(t.left + (t.width - a) / 2, y, S - a - y);
93
+ let B;
94
+ J - t.bottom - g >= c + y ? B = t.bottom + g : t.top - g >= c + y ? B = t.top - g - c : B = C(t.top + (t.height - c) / 2, y, J - c - y), i.style.left = W + "px", i.style.top = B + "px", i.style.width = a + "px", L.style.padding = o + "px", u.style.width = d + "px", u.style.height = f + "px";
95
95
  }
96
- function U(e, n) {
97
- const t = g.imgPad, o = m.offsetHeight || 22, { pw: s, ph: c } = j(e, n), f = s + t * 2, a = c + t * 2 + o, l = window.innerWidth, k = window.innerHeight;
98
- i.style.left = S((l - f) / 2, y, l - f - y) + "px", i.style.top = S((k - a) / 2, y, k - a - y) + "px", i.style.width = f + "px", H.style.padding = t + "px", d.style.width = s + "px", d.style.height = c + "px";
96
+ function V(e, n) {
97
+ const t = b.imgPad, o = m.offsetHeight || 22, { pw: s, ph: d } = q(e, n), f = s + t * 2, a = d + t * 2 + o, c = window.innerWidth, S = window.innerHeight;
98
+ i.style.left = C((c - f) / 2, y, c - f - y) + "px", i.style.top = C((S - a) / 2, y, S - a - y) + "px", i.style.width = f + "px", L.style.padding = t + "px", u.style.width = s + "px", u.style.height = d + "px";
99
99
  }
100
- function V(e) {
101
- clearTimeout(w), !(u === e && r.style.opacity === "1") && (u = e, R(e), r.style.opacity = "1", r.style.pointerEvents = "auto", h.style.pointerEvents = "auto");
100
+ function X(e) {
101
+ v !== e && (clearTimeout(T), !(l === e && r.style.opacity === "1") && (l = e, j(e), r.style.opacity = "1", r.style.pointerEvents = "auto", h.style.pointerEvents = "auto"));
102
102
  }
103
- function q(e, n) {
104
- const t = ++B;
103
+ function Q(e, n) {
104
+ if (v && l === v) return;
105
+ const t = ++_;
105
106
  m.textContent = n || "";
106
- function o(s, c) {
107
- t === B && (b ? U(s, c) : K(s, c), i.style.opacity = "1", i.style.transform = "scale(1)", i.style.pointerEvents = "auto", b && (p.style.opacity = "1"), r.textContent = "✕", r.style.background = "rgba(220,60,60,0.75)", m.textContent = n || s + " × " + c);
107
+ function o(s, d) {
108
+ t === _ && (x ? V(s, d) : U(s, d), i.style.opacity = "1", i.style.transform = "scale(1)", i.style.pointerEvents = "auto", x && (p.style.opacity = "1"), r.textContent = "✕", r.style.background = "rgba(220,60,60,0.75)", m.textContent = n || s + " × " + d);
108
109
  }
109
- if (v.get(e) === "loaded" && d.src === e) {
110
- o(d.naturalWidth, d.naturalHeight);
110
+ if (w.get(e) === "loaded" && u.src === e) {
111
+ o(u.naturalWidth, u.naturalHeight);
111
112
  return;
112
113
  }
113
- d.src = e, d.onload = () => {
114
- v.set(e, "loaded"), o(d.naturalWidth, d.naturalHeight);
115
- }, d.onerror = () => {
116
- v.set(e, "error");
114
+ u.src = e, u.onload = () => {
115
+ w.set(e, "loaded"), o(u.naturalWidth, u.naturalHeight);
116
+ }, u.onerror = () => {
117
+ w.set(e, "error");
117
118
  };
118
119
  }
119
- function A() {
120
- clearTimeout(E), E = setTimeout(() => {
121
- i.style.opacity = "0", i.style.transform = "scale(0.95)", i.style.pointerEvents = "none", r.style.opacity = "0", r.style.pointerEvents = "none", r.textContent = "🖼️", r.style.background = "rgba(0,0,0,0.45)", h.style.pointerEvents = "none", p.style.opacity = "0", u = null;
122
- }, g.delayHide);
123
- }
124
120
  function O() {
125
- clearTimeout(E), clearTimeout(w), ++B, i.style.opacity = "0", i.style.transform = "scale(0.95)", i.style.pointerEvents = "none", r.style.opacity = "0", r.style.pointerEvents = "none", r.textContent = "🖼️", r.style.background = "rgba(0,0,0,0.45)", h.style.pointerEvents = "none", p.style.opacity = "0", u = null;
121
+ clearTimeout(M), M = setTimeout(() => {
122
+ i.style.opacity = "0", i.style.transform = "scale(0.95)", i.style.pointerEvents = "none", r.style.opacity = "0", r.style.pointerEvents = "none", r.textContent = "🖼️", r.style.background = "rgba(0,0,0,0.45)", h.style.pointerEvents = "none", p.style.opacity = "0", l = null;
123
+ }, b.delayHide);
126
124
  }
127
- function Q(e) {
128
- if (!e || v.has(e)) return;
129
- v.set(e, "loading");
125
+ function D() {
126
+ clearTimeout(M), clearTimeout(T), ++_, l && (v = l), i.style.opacity = "0", i.style.transform = "scale(0.95)", i.style.pointerEvents = "none", r.style.opacity = "0", r.style.pointerEvents = "none", r.textContent = "🖼️", r.style.background = "rgba(0,0,0,0.45)", h.style.pointerEvents = "none", p.style.opacity = "0", l = null;
127
+ }
128
+ function F(e) {
129
+ if (!e || w.has(e)) return;
130
+ w.set(e, "loading");
130
131
  const n = new Image();
131
- n.onload = () => v.set(e, "loaded"), n.onerror = () => v.set(e, "error"), n.src = e;
132
+ n.onload = () => w.set(e, "loaded"), n.onerror = () => w.set(e, "error"), n.src = e;
132
133
  }
133
- function F() {
134
- u && r.style.opacity === "1" && R(u);
134
+ function I() {
135
+ l && r.style.opacity === "1" && j(l);
135
136
  }
136
- function D(e) {
137
+ function R(e) {
137
138
  var n;
138
139
  return e.dataset.previewSrc || e.src || e.currentSrc || ((n = e.querySelector("img")) == null ? void 0 : n.src) || null;
139
140
  }
140
- function I(e) {
141
+ function N(e) {
141
142
  return e.dataset.previewLabel || e.alt || e.title || null;
142
143
  }
143
- function P(e) {
144
+ function E(e) {
144
145
  if (e._dpBound) return;
145
146
  const n = {
146
147
  mouseenter() {
147
- b || (clearTimeout(w), !(u === e && r.style.opacity === "1") && (Q(D(e)), V(e)));
148
+ x || v !== e && (clearTimeout(T), !(l === e && r.style.opacity === "1") && (F(R(e)), X(e)));
148
149
  },
149
150
  mouseleave(t) {
150
- b || e.contains(t.relatedTarget) || (w = setTimeout(() => {
151
- u === e && A();
152
- }, g.delayHide));
151
+ x || e.contains(t.relatedTarget) || (v === e && (v = null), T = setTimeout(() => {
152
+ l === e && O();
153
+ }, b.delayHide));
153
154
  },
154
155
  touchstart(t) {
155
- if (!b) return;
156
- const o = D(e);
157
- o && (Q(o), M = setTimeout(() => {
158
- u = e, q(o, I(e));
159
- }, g.longPressDuration));
156
+ if (!x) return;
157
+ const o = R(e);
158
+ o && (F(o), k = setTimeout(() => {
159
+ l = e, Q(o, N(e));
160
+ }, b.longPressDuration));
160
161
  },
161
162
  touchend() {
162
- clearTimeout(M);
163
+ clearTimeout(k);
163
164
  },
164
165
  touchmove() {
165
- clearTimeout(M);
166
+ clearTimeout(k);
166
167
  },
167
168
  touchcancel() {
168
- clearTimeout(M);
169
+ clearTimeout(k);
169
170
  },
170
171
  contextmenu(t) {
171
- b && t.preventDefault();
172
+ x && t.preventDefault();
172
173
  }
173
174
  };
174
175
  Object.entries(n).forEach(([t, o]) => e.addEventListener(t, o)), e._dpBound = !0, e._dpHandlers = n;
175
176
  }
176
- function N(e) {
177
+ function G(e) {
177
178
  e._dpBound && (Object.entries(e._dpHandlers).forEach(
178
179
  ([n, t]) => e.removeEventListener(n, t)
179
180
  ), e._dpBound = !1, e._dpHandlers = null, e._dpMoveTimer = null);
180
181
  }
181
- function X(e) {
182
- document.querySelectorAll(e).forEach((n) => P(n));
182
+ function Y(e) {
183
+ document.querySelectorAll(e).forEach((n) => E(n));
183
184
  }
184
- function Y(e = "[data-preview]") {
185
- J(), document.querySelectorAll(e).forEach((n) => P(n)), window.addEventListener("scroll", F, !0), L = new MutationObserver((n) => {
185
+ function Z(e = "[data-preview]") {
186
+ K(), document.querySelectorAll(e).forEach((n) => E(n)), window.addEventListener("scroll", I, !0), P = new MutationObserver((n) => {
186
187
  n.forEach((t) => {
187
188
  t.addedNodes.forEach((o) => {
188
- var s, c;
189
- o.nodeType === 1 && ((s = o.matches) != null && s.call(o, e) && P(o), (c = o.querySelectorAll) == null || c.call(o, e).forEach((f) => P(f)));
189
+ var s, d;
190
+ o.nodeType === 1 && ((s = o.matches) != null && s.call(o, e) && E(o), (d = o.querySelectorAll) == null || d.call(o, e).forEach((f) => E(f)));
190
191
  });
191
192
  });
192
- }), L.observe(document.body, { childList: !0, subtree: !0 });
193
+ }), P.observe(document.body, { childList: !0, subtree: !0 });
193
194
  }
194
- function Z() {
195
- L == null || L.disconnect(), L = null, document.querySelectorAll("[data-preview]").forEach((e) => N(e)), window.removeEventListener("scroll", F, !0), _.removeEventListener("change", z), h == null || h.remove(), h = i = H = d = m = p = r = null, v.clear(), clearTimeout(E), clearTimeout(w), clearTimeout(M);
195
+ function $() {
196
+ P == null || P.disconnect(), P = null, document.querySelectorAll("[data-preview]").forEach((e) => G(e)), window.removeEventListener("scroll", I, !0), z.removeEventListener("change", A), h == null || h.remove(), h = i = L = u = m = p = r = null, w.clear(), clearTimeout(M), clearTimeout(T), clearTimeout(k), v = null;
196
197
  }
197
- function T(e, n = {}) {
198
+ function H(e, n = {}) {
198
199
  const t = document.createElement(e);
199
200
  return Object.entries(n).forEach(([o, s]) => {
200
201
  o === "style" ? t.style.cssText = s : t[o] = s;
201
202
  }), t;
202
203
  }
203
- function S(e, n, t) {
204
+ function C(e, n, t) {
204
205
  return Math.max(n, Math.min(e, t));
205
206
  }
206
- return { init: Y, bind: P, unbind: N, bindAll: X, destroy: Z, config: g };
207
+ return { init: Z, bind: E, unbind: G, bindAll: Y, destroy: $, config: b };
207
208
  })();
208
209
  export {
209
- ee as default
210
+ te as default
210
211
  };
@@ -1,4 +1,4 @@
1
- (function(S,p){typeof exports=="object"&&typeof module<"u"?module.exports=p():typeof define=="function"&&define.amd?define(p):(S=typeof globalThis<"u"?globalThis:S||self,S.DataPreview=p())})(this,(function(){"use strict";return(()=>{const p={imgPad:8,maxWRatio:.9,maxHRatio:.85,delayHide:120,longPressDuration:480,badgeOffset:6},h=16,x=12;let m,i,H,d,b,u,r,P=null,w=null,L=null,E=null,_=0,f=null;const v=new Map;let g=window.matchMedia("(pointer: coarse)").matches;const z=window.matchMedia("(prefers-color-scheme: dark)");window.matchMedia("(pointer: coarse)").addEventListener("change",e=>{g=e.matches});function K(){m||(m=T("div",{style:"position:fixed;inset:0;z-index:99999;pointer-events:none;"}),r=T("div",{style:`
1
+ (function(C,p){typeof exports=="object"&&typeof module<"u"?module.exports=p():typeof define=="function"&&define.amd?define(p):(C=typeof globalThis<"u"?globalThis:C||self,C.DataPreview=p())})(this,(function(){"use strict";return(()=>{const p={imgPad:8,maxWRatio:.9,maxHRatio:.85,delayHide:120,longPressDuration:480,badgeOffset:6},h=16,g=12;let m,o,P,u,b,f,r,L=null,T=null,k=null,M=null,z=0,l=null,v=null;const w=new Map;let x=window.matchMedia("(pointer: coarse)").matches;const A=window.matchMedia("(prefers-color-scheme: dark)");window.matchMedia("(pointer: coarse)").addEventListener("change",e=>{x=e.matches});function U(){m||(m=H("div",{style:"position:fixed;inset:0;z-index:99999;pointer-events:none;"}),r=H("div",{style:`
2
2
  position:fixed;
3
3
  width:24px;height:24px;
4
4
  border-radius:6px;
@@ -12,7 +12,7 @@
12
12
  z-index:100001;
13
13
  user-select:none;
14
14
  backdrop-filter:blur(4px);
15
- `}),r.textContent="🖼️",i=T("div",{style:`
15
+ `}),r.textContent="🖼️",o=H("div",{style:`
16
16
  position:fixed;
17
17
  border-radius:12px;
18
18
  overflow:hidden;
@@ -22,11 +22,11 @@
22
22
  pointer-events:none;
23
23
  z-index:100000;
24
24
  will-change:transform,opacity;
25
- `}),u=T("button",{style:`
25
+ `}),f=H("button",{style:`
26
26
  position:absolute;top:6px;right:6px;
27
27
  width:26px;height:26px;
28
28
  border-radius:50%;border:none;cursor:pointer;
29
29
  display:flex;align-items:center;justify-content:center;
30
30
  font-size:13px;line-height:1;z-index:1;
31
31
  opacity:0;transition:opacity 0.15s;
32
- `}),u.textContent="✕",u.setAttribute("aria-label","关闭预览"),u.addEventListener("click",e=>{e.stopPropagation(),O()}),u.addEventListener("touchend",e=>{e.stopPropagation(),O()}),H=T("div",{style:"position:relative;"}),d=T("img",{style:"display:block;",alt:"preview"}),b=T("div",{style:"font-size:11px;padding:5px 10px;white-space:nowrap;"}),H.append(d,u),i.append(H,b),m.append(r,i),document.body.appendChild(m),r.addEventListener("mouseenter",()=>{if(clearTimeout(P),clearTimeout(w),!f)return;const e=j(f),n=N(f);e&&Q(e,n)}),r.addEventListener("mouseleave",()=>{i.style.opacity!=="1"&&D()}),r.addEventListener("click",()=>{i.style.opacity==="1"&&O()}),i.addEventListener("mouseenter",()=>{clearTimeout(P),clearTimeout(w),g||(u.style.opacity="1")}),i.addEventListener("mouseleave",()=>{g||(u.style.opacity="0"),D()}),A(),z.addEventListener("change",A))}function A(){const e=z.matches;i.style.background=e?"#1c1c1e":"#ffffff",i.style.border=e?"1px solid rgba(255,255,255,.12)":"1px solid rgba(0,0,0,.1)",i.style.boxShadow=e?"0 12px 40px rgba(0,0,0,.55),0 2px 8px rgba(0,0,0,.3)":"0 8px 32px rgba(0,0,0,.18),0 2px 8px rgba(0,0,0,.08)",b.style.background=e?"rgba(255,255,255,.06)":"rgba(0,0,0,.04)",b.style.color=e?"rgba(255,255,255,.4)":"rgba(0,0,0,.4)",b.style.borderTop=e?"1px solid rgba(255,255,255,.08)":"1px solid rgba(0,0,0,.06)",u.style.background=e?"rgba(255,255,255,.15)":"rgba(0,0,0,.15)",u.style.color=e?"rgba(255,255,255,.8)":"rgba(0,0,0,.6)"}function R(e){const n=e.getBoundingClientRect(),t=p.badgeOffset;r.style.left=n.right-24-t+"px",r.style.top=n.top+t+"px"}function q(e,n){const t=p.imgPad*2,o=b.offsetHeight||22,s=Math.floor(window.innerWidth*p.maxWRatio)-t,c=Math.floor(window.innerHeight*p.maxHRatio)-t-o,y=e/n;let a,l;return y>=1?(a=Math.min(s,e),l=a/y,l>c&&(l=c,a=l*y)):(l=Math.min(c,n),a=l*y,a>s&&(a=s,l=a/y)),{pw:Math.round(a),ph:Math.round(l)}}function U(e,n){if(!f)return;const t=f.getBoundingClientRect(),o=p.imgPad,s=b.offsetHeight||22,{pw:c,ph:y}=q(e,n),a=c+o*2,l=y+o*2+s,k=window.innerWidth,J=window.innerHeight;let W;t.left-x>=a+h?W=t.left-x-a:k-t.right-x>=a+h?W=t.right+x:W=C(t.left+(t.width-a)/2,h,k-a-h);let B;J-t.bottom-x>=l+h?B=t.bottom+x:t.top-x>=l+h?B=t.top-x-l:B=C(t.top+(t.height-l)/2,h,J-l-h),i.style.left=W+"px",i.style.top=B+"px",i.style.width=a+"px",H.style.padding=o+"px",d.style.width=c+"px",d.style.height=y+"px"}function V(e,n){const t=p.imgPad,o=b.offsetHeight||22,{pw:s,ph:c}=q(e,n),y=s+t*2,a=c+t*2+o,l=window.innerWidth,k=window.innerHeight;i.style.left=C((l-y)/2,h,l-y-h)+"px",i.style.top=C((k-a)/2,h,k-a-h)+"px",i.style.width=y+"px",H.style.padding=t+"px",d.style.width=s+"px",d.style.height=c+"px"}function X(e){clearTimeout(w),!(f===e&&r.style.opacity==="1")&&(f=e,R(e),r.style.opacity="1",r.style.pointerEvents="auto",m.style.pointerEvents="auto")}function Q(e,n){const t=++_;b.textContent=n||"";function o(s,c){t===_&&(g?V(s,c):U(s,c),i.style.opacity="1",i.style.transform="scale(1)",i.style.pointerEvents="auto",g&&(u.style.opacity="1"),r.textContent="✕",r.style.background="rgba(220,60,60,0.75)",b.textContent=n||s+" × "+c)}if(v.get(e)==="loaded"&&d.src===e){o(d.naturalWidth,d.naturalHeight);return}d.src=e,d.onload=()=>{v.set(e,"loaded"),o(d.naturalWidth,d.naturalHeight)},d.onerror=()=>{v.set(e,"error")}}function D(){clearTimeout(P),P=setTimeout(()=>{i.style.opacity="0",i.style.transform="scale(0.95)",i.style.pointerEvents="none",r.style.opacity="0",r.style.pointerEvents="none",r.textContent="🖼️",r.style.background="rgba(0,0,0,0.45)",m.style.pointerEvents="none",u.style.opacity="0",f=null},p.delayHide)}function O(){clearTimeout(P),clearTimeout(w),++_,i.style.opacity="0",i.style.transform="scale(0.95)",i.style.pointerEvents="none",r.style.opacity="0",r.style.pointerEvents="none",r.textContent="🖼️",r.style.background="rgba(0,0,0,0.45)",m.style.pointerEvents="none",u.style.opacity="0",f=null}function F(e){if(!e||v.has(e))return;v.set(e,"loading");const n=new Image;n.onload=()=>v.set(e,"loaded"),n.onerror=()=>v.set(e,"error"),n.src=e}function I(){f&&r.style.opacity==="1"&&R(f)}function j(e){var n;return e.dataset.previewSrc||e.src||e.currentSrc||((n=e.querySelector("img"))==null?void 0:n.src)||null}function N(e){return e.dataset.previewLabel||e.alt||e.title||null}function M(e){if(e._dpBound)return;const n={mouseenter(){g||(clearTimeout(w),!(f===e&&r.style.opacity==="1")&&(F(j(e)),X(e)))},mouseleave(t){g||e.contains(t.relatedTarget)||(w=setTimeout(()=>{f===e&&D()},p.delayHide))},touchstart(t){if(!g)return;const o=j(e);o&&(F(o),L=setTimeout(()=>{f=e,Q(o,N(e))},p.longPressDuration))},touchend(){clearTimeout(L)},touchmove(){clearTimeout(L)},touchcancel(){clearTimeout(L)},contextmenu(t){g&&t.preventDefault()}};Object.entries(n).forEach(([t,o])=>e.addEventListener(t,o)),e._dpBound=!0,e._dpHandlers=n}function G(e){e._dpBound&&(Object.entries(e._dpHandlers).forEach(([n,t])=>e.removeEventListener(n,t)),e._dpBound=!1,e._dpHandlers=null,e._dpMoveTimer=null)}function Y(e){document.querySelectorAll(e).forEach(n=>M(n))}function Z(e="[data-preview]"){K(),document.querySelectorAll(e).forEach(n=>M(n)),window.addEventListener("scroll",I,!0),E=new MutationObserver(n=>{n.forEach(t=>{t.addedNodes.forEach(o=>{var s,c;o.nodeType===1&&((s=o.matches)!=null&&s.call(o,e)&&M(o),(c=o.querySelectorAll)==null||c.call(o,e).forEach(y=>M(y)))})})}),E.observe(document.body,{childList:!0,subtree:!0})}function $(){E==null||E.disconnect(),E=null,document.querySelectorAll("[data-preview]").forEach(e=>G(e)),window.removeEventListener("scroll",I,!0),z.removeEventListener("change",A),m==null||m.remove(),m=i=H=d=b=u=r=null,v.clear(),clearTimeout(P),clearTimeout(w),clearTimeout(L)}function T(e,n={}){const t=document.createElement(e);return Object.entries(n).forEach(([o,s])=>{o==="style"?t.style.cssText=s:t[o]=s}),t}function C(e,n,t){return Math.max(n,Math.min(e,t))}return{init:Z,bind:M,unbind:G,bindAll:Y,destroy:$,config:p}})()}));
32
+ `}),f.textContent="✕",f.setAttribute("aria-label","关闭预览"),f.addEventListener("click",e=>{e.stopPropagation(),j()}),f.addEventListener("touchend",e=>{e.stopPropagation(),j()}),P=H("div",{style:"position:relative;"}),u=H("img",{style:"display:block;",alt:"preview"}),b=H("div",{style:"font-size:11px;padding:5px 10px;white-space:nowrap;"}),P.append(u,f),o.append(P,b),m.append(r,o),document.body.appendChild(m),r.addEventListener("mouseenter",()=>{if(clearTimeout(L),clearTimeout(T),!l)return;const e=R(l),n=G(l);e&&F(e,n)}),r.addEventListener("mouseleave",()=>{o.style.opacity!=="1"&&O()}),r.addEventListener("click",()=>{o.style.opacity==="1"&&j()}),o.addEventListener("mouseenter",()=>{clearTimeout(L),clearTimeout(T),x||(f.style.opacity="1")}),o.addEventListener("mouseleave",()=>{x||(f.style.opacity="0"),O()}),D(),A.addEventListener("change",D))}function D(){const e=A.matches;o.style.background=e?"#1c1c1e":"#ffffff",o.style.border=e?"1px solid rgba(255,255,255,.12)":"1px solid rgba(0,0,0,.1)",o.style.boxShadow=e?"0 12px 40px rgba(0,0,0,.55),0 2px 8px rgba(0,0,0,.3)":"0 8px 32px rgba(0,0,0,.18),0 2px 8px rgba(0,0,0,.08)",b.style.background=e?"rgba(255,255,255,.06)":"rgba(0,0,0,.04)",b.style.color=e?"rgba(255,255,255,.4)":"rgba(0,0,0,.4)",b.style.borderTop=e?"1px solid rgba(255,255,255,.08)":"1px solid rgba(0,0,0,.06)",f.style.background=e?"rgba(255,255,255,.15)":"rgba(0,0,0,.15)",f.style.color=e?"rgba(255,255,255,.8)":"rgba(0,0,0,.6)"}function q(e){const n=e.getBoundingClientRect(),t=p.badgeOffset;r.style.left=n.right-24-t+"px",r.style.top=n.top+t+"px"}function Q(e,n){const t=p.imgPad*2,i=b.offsetHeight||22,s=Math.floor(window.innerWidth*p.maxWRatio)-t,d=Math.floor(window.innerHeight*p.maxHRatio)-t-i,y=e/n;let a,c;return y>=1?(a=Math.min(s,e),c=a/y,c>d&&(c=d,a=c*y)):(c=Math.min(d,n),a=c*y,a>s&&(a=s,c=a/y)),{pw:Math.round(a),ph:Math.round(c)}}function V(e,n){if(!l)return;const t=l.getBoundingClientRect(),i=p.imgPad,s=b.offsetHeight||22,{pw:d,ph:y}=Q(e,n),a=d+i*2,c=y+i*2+s,S=window.innerWidth,K=window.innerHeight;let B;t.left-g>=a+h?B=t.left-g-a:S-t.right-g>=a+h?B=t.right+g:B=W(t.left+(t.width-a)/2,h,S-a-h);let _;K-t.bottom-g>=c+h?_=t.bottom+g:t.top-g>=c+h?_=t.top-g-c:_=W(t.top+(t.height-c)/2,h,K-c-h),o.style.left=B+"px",o.style.top=_+"px",o.style.width=a+"px",P.style.padding=i+"px",u.style.width=d+"px",u.style.height=y+"px"}function X(e,n){const t=p.imgPad,i=b.offsetHeight||22,{pw:s,ph:d}=Q(e,n),y=s+t*2,a=d+t*2+i,c=window.innerWidth,S=window.innerHeight;o.style.left=W((c-y)/2,h,c-y-h)+"px",o.style.top=W((S-a)/2,h,S-a-h)+"px",o.style.width=y+"px",P.style.padding=t+"px",u.style.width=s+"px",u.style.height=d+"px"}function Y(e){v!==e&&(clearTimeout(T),!(l===e&&r.style.opacity==="1")&&(l=e,q(e),r.style.opacity="1",r.style.pointerEvents="auto",m.style.pointerEvents="auto"))}function F(e,n){if(v&&l===v)return;const t=++z;b.textContent=n||"";function i(s,d){t===z&&(x?X(s,d):V(s,d),o.style.opacity="1",o.style.transform="scale(1)",o.style.pointerEvents="auto",x&&(f.style.opacity="1"),r.textContent="✕",r.style.background="rgba(220,60,60,0.75)",b.textContent=n||s+" × "+d)}if(w.get(e)==="loaded"&&u.src===e){i(u.naturalWidth,u.naturalHeight);return}u.src=e,u.onload=()=>{w.set(e,"loaded"),i(u.naturalWidth,u.naturalHeight)},u.onerror=()=>{w.set(e,"error")}}function O(){clearTimeout(L),L=setTimeout(()=>{o.style.opacity="0",o.style.transform="scale(0.95)",o.style.pointerEvents="none",r.style.opacity="0",r.style.pointerEvents="none",r.textContent="🖼️",r.style.background="rgba(0,0,0,0.45)",m.style.pointerEvents="none",f.style.opacity="0",l=null},p.delayHide)}function j(){clearTimeout(L),clearTimeout(T),++z,l&&(v=l),o.style.opacity="0",o.style.transform="scale(0.95)",o.style.pointerEvents="none",r.style.opacity="0",r.style.pointerEvents="none",r.textContent="🖼️",r.style.background="rgba(0,0,0,0.45)",m.style.pointerEvents="none",f.style.opacity="0",l=null}function I(e){if(!e||w.has(e))return;w.set(e,"loading");const n=new Image;n.onload=()=>w.set(e,"loaded"),n.onerror=()=>w.set(e,"error"),n.src=e}function N(){l&&r.style.opacity==="1"&&q(l)}function R(e){var n;return e.dataset.previewSrc||e.src||e.currentSrc||((n=e.querySelector("img"))==null?void 0:n.src)||null}function G(e){return e.dataset.previewLabel||e.alt||e.title||null}function E(e){if(e._dpBound)return;const n={mouseenter(){x||v!==e&&(clearTimeout(T),!(l===e&&r.style.opacity==="1")&&(I(R(e)),Y(e)))},mouseleave(t){x||e.contains(t.relatedTarget)||(v===e&&(v=null),T=setTimeout(()=>{l===e&&O()},p.delayHide))},touchstart(t){if(!x)return;const i=R(e);i&&(I(i),k=setTimeout(()=>{l=e,F(i,G(e))},p.longPressDuration))},touchend(){clearTimeout(k)},touchmove(){clearTimeout(k)},touchcancel(){clearTimeout(k)},contextmenu(t){x&&t.preventDefault()}};Object.entries(n).forEach(([t,i])=>e.addEventListener(t,i)),e._dpBound=!0,e._dpHandlers=n}function J(e){e._dpBound&&(Object.entries(e._dpHandlers).forEach(([n,t])=>e.removeEventListener(n,t)),e._dpBound=!1,e._dpHandlers=null,e._dpMoveTimer=null)}function Z(e){document.querySelectorAll(e).forEach(n=>E(n))}function $(e="[data-preview]"){U(),document.querySelectorAll(e).forEach(n=>E(n)),window.addEventListener("scroll",N,!0),M=new MutationObserver(n=>{n.forEach(t=>{t.addedNodes.forEach(i=>{var s,d;i.nodeType===1&&((s=i.matches)!=null&&s.call(i,e)&&E(i),(d=i.querySelectorAll)==null||d.call(i,e).forEach(y=>E(y)))})})}),M.observe(document.body,{childList:!0,subtree:!0})}function ee(){M==null||M.disconnect(),M=null,document.querySelectorAll("[data-preview]").forEach(e=>J(e)),window.removeEventListener("scroll",N,!0),A.removeEventListener("change",D),m==null||m.remove(),m=o=P=u=b=f=r=null,w.clear(),clearTimeout(L),clearTimeout(T),clearTimeout(k),v=null}function H(e,n={}){const t=document.createElement(e);return Object.entries(n).forEach(([i,s])=>{i==="style"?t.style.cssText=s:t[i]=s}),t}function W(e,n,t){return Math.max(n,Math.min(e,t))}return{init:$,bind:E,unbind:J,bindAll:Z,destroy:ee,config:p}})()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-preview",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "AI-native semantic preview runtime for modern web.",
5
5
  "keywords": ["image preview", "big image", "semantic protocol", "ai-native","data preview protocol"],
6
6
  "type": "module",