@place-framework/place-block-image 1.0.2 → 1.0.4
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 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c);var l=`image-`,u={LAZY:`lazy`,LOADED:`loaded`,WRAPPER_SUFFIX:`wrapper`},d=e=>e.replace(/^https?:\/\/[^/]+/,``).replace(/^[/\\]+/,``).replace(/\.[^/.]+$/,``).toLowerCase().replace(/[^a-z0-9/-]/g,`-`).replace(/\//g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``);function f(e,t){return t?e.replace(RegExp(`^${t.replace(/\//g,`\\/`)}\\/?`),``):e}function p(e,t,n){return e?`${t}${d(f(e,n))}`:``}function m(e,t,n,r=``){return[`${t}${u.WRAPPER_SUFFIX}`,p(e,t,n),r].filter(Boolean).join(` `)}function h(e,t){return e?t?`${u.LAZY} ${u.LOADED}`:u.LAZY:``}function g(e,t,n=.1){let r=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting&&(t(),r.unobserve(e.target))})},{threshold:n});return r.observe(e),r}var _=({src:e,alt:t,imagePrefix:n=l,lazy:r=!1,className:i=``,...a})=>{let o=(0,c.useRef)(null),[s,u]=(0,c.useState)(r?``:e),[d,f]=(0,c.useState)(!r),p=typeof __PLUGIN_ASSET_PATH__<`u`?__PLUGIN_ASSET_PATH__:``;(0,c.useEffect)(()=>{if(!r||d||!o.current)return;let t=g(o.current,()=>{u(e),f(!0)});return()=>t.disconnect()},[e,r,d]);let _=m(e,n,p,i),v=h(r,d);return c.default.createElement(`picture`,{className:_},c.default.createElement(`img`,{ref:o,src:s,alt:t,className:v,...a}))};exports.PlaceBlockImage=_,exports.default=_;
|
|
@@ -1,67 +1,57 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return t ? e.replace(new RegExp(`^${t.replace(/\//g, "\\/")}\\/?`), "") : e;
|
|
1
|
+
import e, { useEffect as t, useRef as n, useState as r } from "react";
|
|
2
|
+
//#region src/constants/index.ts
|
|
3
|
+
var i = "image-", a = {
|
|
4
|
+
LAZY: "lazy",
|
|
5
|
+
LOADED: "loaded",
|
|
6
|
+
WRAPPER_SUFFIX: "wrapper"
|
|
7
|
+
}, o = (e) => e.replace(/^https?:\/\/[^/]+/, "").replace(/^[/\\]+/, "").replace(/\.[^/.]+$/, "").toLowerCase().replace(/[^a-z0-9/-]/g, "-").replace(/\//g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
8
|
+
function s(e, t) {
|
|
9
|
+
return t ? e.replace(RegExp(`^${t.replace(/\//g, "\\/")}\\/?`), "") : e;
|
|
11
10
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
11
|
+
function c(e, t, n) {
|
|
12
|
+
return e ? `${t}${o(s(e, n))}` : "";
|
|
14
13
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
function l(e, t, n, r = "") {
|
|
15
|
+
return [
|
|
16
|
+
`${t}${a.WRAPPER_SUFFIX}`,
|
|
17
|
+
c(e, t, n),
|
|
18
|
+
r
|
|
19
|
+
].filter(Boolean).join(" ");
|
|
21
20
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
21
|
+
function u(e, t) {
|
|
22
|
+
return e ? t ? `${a.LAZY} ${a.LOADED}` : a.LAZY : "";
|
|
24
23
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{ threshold: n }
|
|
33
|
-
);
|
|
34
|
-
return r.observe(e), r;
|
|
24
|
+
function d(e, t, n = .1) {
|
|
25
|
+
let r = new IntersectionObserver((e) => {
|
|
26
|
+
e.forEach((e) => {
|
|
27
|
+
e.isIntersecting && (t(), r.unobserve(e.target));
|
|
28
|
+
});
|
|
29
|
+
}, { threshold: n });
|
|
30
|
+
return r.observe(e), r;
|
|
35
31
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
className: A,
|
|
60
|
-
...s
|
|
61
|
-
}
|
|
62
|
-
));
|
|
63
|
-
};
|
|
64
|
-
export {
|
|
65
|
-
b as PlaceBlockImage,
|
|
66
|
-
b as default
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/react/PlaceBlockImage.tsx
|
|
34
|
+
var f = ({ src: a, alt: o, imagePrefix: s = i, lazy: c = !1, className: f = "", ...p }) => {
|
|
35
|
+
let m = n(null), [h, g] = r(c ? "" : a), [_, v] = r(!c), y = typeof __PLUGIN_ASSET_PATH__ < "u" ? __PLUGIN_ASSET_PATH__ : "";
|
|
36
|
+
t(() => {
|
|
37
|
+
if (!c || _ || !m.current) return;
|
|
38
|
+
let e = d(m.current, () => {
|
|
39
|
+
g(a), v(!0);
|
|
40
|
+
});
|
|
41
|
+
return () => e.disconnect();
|
|
42
|
+
}, [
|
|
43
|
+
a,
|
|
44
|
+
c,
|
|
45
|
+
_
|
|
46
|
+
]);
|
|
47
|
+
let b = l(a, s, y, f), x = u(c, _);
|
|
48
|
+
return /* @__PURE__ */ e.createElement("picture", { className: b }, /* @__PURE__ */ e.createElement("img", {
|
|
49
|
+
ref: m,
|
|
50
|
+
src: h,
|
|
51
|
+
alt: o,
|
|
52
|
+
className: x,
|
|
53
|
+
...p
|
|
54
|
+
}));
|
|
67
55
|
};
|
|
56
|
+
//#endregion
|
|
57
|
+
export { f as PlaceBlockImage, f as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
let e=require("vue");var t=`image-`,n={LAZY:`lazy`,LOADED:`loaded`,WRAPPER_SUFFIX:`wrapper`},r=e=>e.replace(/^https?:\/\/[^/]+/,``).replace(/^[/\\]+/,``).replace(/\.[^/.]+$/,``).toLowerCase().replace(/[^a-z0-9/-]/g,`-`).replace(/\//g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``);function i(e,t){return t?e.replace(RegExp(`^${t.replace(/\//g,`\\/`)}\\/?`),``):e}function a(e,t,n){return e?`${t}${r(i(e,n))}`:``}function o(e,t,r,i=``){return[`${t}${n.WRAPPER_SUFFIX}`,a(e,t,r),i].filter(Boolean).join(` `)}function s(e,t){return e?t?`${n.LAZY} ${n.LOADED}`:n.LAZY:``}function c(e,t,n=.1){let r=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting&&(t(),r.unobserve(e.target))})},{threshold:n});return r.observe(e),r}var l=[`src`,`alt`],u=(0,e.defineComponent)({inheritAttrs:!1,__name:`PlaceBlockImage`,props:{src:{type:String,required:!0},alt:{type:String,required:!0},imagePrefix:{type:String,default:()=>t},lazy:{type:Boolean,default:!1}},setup(t){let n=(0,e.useAttrs)(),r=t,i=(0,e.computed)(()=>{let{class:e,...t}=n;return t}),a=(0,e.ref)(null),u=(0,e.ref)(r.lazy?``:r.src),d=(0,e.ref)(!r.lazy),f=null,p=typeof __PLUGIN_ASSET_PATH__<`u`?__PLUGIN_ASSET_PATH__:``,m=(0,e.computed)(()=>o(r.src,r.imagePrefix,p)),h=(0,e.computed)(()=>s(r.lazy,d.value)),g=()=>{!r.lazy||d.value||!a.value||(f=c(a.value,()=>{u.value=r.src,d.value=!0}))},_=()=>{f&&=(f.disconnect(),null)};return(0,e.onMounted)(()=>{g()}),(0,e.onUnmounted)(()=>{_()}),(0,e.watch)(()=>r.src,e=>{r.lazy?d.value||(_(),g()):u.value=e}),(0,e.watch)(d,e=>{e&&(u.value=r.src,_())}),(r,o)=>((0,e.openBlock)(),(0,e.createElementBlock)(`picture`,{class:(0,e.normalizeClass)([m.value,(0,e.unref)(n).class])},[(0,e.createElementVNode)(`img`,(0,e.mergeProps)({ref_key:`imgRef`,ref:a,src:u.value,alt:t.alt,class:h.value},i.value),null,16,l)],2))}});module.exports=u;
|
|
@@ -1,83 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return r ? t.replace(new RegExp(`^${r.replace(/\//g, "\\/")}\\/?`), "") : t;
|
|
1
|
+
import { computed as e, createElementBlock as t, createElementVNode as n, defineComponent as r, mergeProps as i, normalizeClass as a, onMounted as o, onUnmounted as s, openBlock as c, ref as l, unref as u, useAttrs as d, watch as f } from "vue";
|
|
2
|
+
//#region src/constants/index.ts
|
|
3
|
+
var p = "image-", m = {
|
|
4
|
+
LAZY: "lazy",
|
|
5
|
+
LOADED: "loaded",
|
|
6
|
+
WRAPPER_SUFFIX: "wrapper"
|
|
7
|
+
}, h = (e) => e.replace(/^https?:\/\/[^/]+/, "").replace(/^[/\\]+/, "").replace(/\.[^/.]+$/, "").toLowerCase().replace(/[^a-z0-9/-]/g, "-").replace(/\//g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
8
|
+
function g(e, t) {
|
|
9
|
+
return t ? e.replace(RegExp(`^${t.replace(/\//g, "\\/")}\\/?`), "") : e;
|
|
11
10
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
11
|
+
function _(e, t, n) {
|
|
12
|
+
return e ? `${t}${h(g(e, n))}` : "";
|
|
14
13
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
function v(e, t, n, r = "") {
|
|
15
|
+
return [
|
|
16
|
+
`${t}${m.WRAPPER_SUFFIX}`,
|
|
17
|
+
_(e, t, n),
|
|
18
|
+
r
|
|
19
|
+
].filter(Boolean).join(" ");
|
|
21
20
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
21
|
+
function y(e, t) {
|
|
22
|
+
return e ? t ? `${m.LAZY} ${m.LOADED}` : m.LAZY : "";
|
|
24
23
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{ threshold: e }
|
|
33
|
-
);
|
|
34
|
-
return a.observe(t), a;
|
|
24
|
+
function b(e, t, n = .1) {
|
|
25
|
+
let r = new IntersectionObserver((e) => {
|
|
26
|
+
e.forEach((e) => {
|
|
27
|
+
e.isIntersecting && (t(), r.unobserve(e.target));
|
|
28
|
+
});
|
|
29
|
+
}, { threshold: n });
|
|
30
|
+
return r.observe(e), r;
|
|
35
31
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/vue/PlaceBlockImage.vue?vue&type=script&setup=true&lang.ts
|
|
34
|
+
var x = ["src", "alt"], S = /* @__PURE__ */ r({
|
|
35
|
+
inheritAttrs: !1,
|
|
36
|
+
__name: "PlaceBlockImage",
|
|
37
|
+
props: {
|
|
38
|
+
src: {
|
|
39
|
+
type: String,
|
|
40
|
+
required: !0
|
|
41
|
+
},
|
|
42
|
+
alt: {
|
|
43
|
+
type: String,
|
|
44
|
+
required: !0
|
|
45
|
+
},
|
|
46
|
+
imagePrefix: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: () => p
|
|
49
|
+
},
|
|
50
|
+
lazy: {
|
|
51
|
+
type: Boolean,
|
|
52
|
+
default: !1
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
setup(r) {
|
|
56
|
+
let p = d(), m = r, h = e(() => {
|
|
57
|
+
let { class: e, ...t } = p;
|
|
58
|
+
return t;
|
|
59
|
+
}), g = l(null), _ = l(m.lazy ? "" : m.src), S = l(!m.lazy), C = null, w = typeof __PLUGIN_ASSET_PATH__ < "u" ? __PLUGIN_ASSET_PATH__ : "", T = e(() => v(m.src, m.imagePrefix, w)), E = e(() => y(m.lazy, S.value)), D = () => {
|
|
60
|
+
!m.lazy || S.value || !g.value || (C = b(g.value, () => {
|
|
61
|
+
_.value = m.src, S.value = !0;
|
|
62
|
+
}));
|
|
63
|
+
}, O = () => {
|
|
64
|
+
C &&= (C.disconnect(), null);
|
|
65
|
+
};
|
|
66
|
+
return o(() => {
|
|
67
|
+
D();
|
|
68
|
+
}), s(() => {
|
|
69
|
+
O();
|
|
70
|
+
}), f(() => m.src, (e) => {
|
|
71
|
+
m.lazy ? S.value || (O(), D()) : _.value = e;
|
|
72
|
+
}), f(S, (e) => {
|
|
73
|
+
e && (_.value = m.src, O());
|
|
74
|
+
}), (e, o) => (c(), t("picture", { class: a([T.value, u(p).class]) }, [n("img", i({
|
|
75
|
+
ref_key: "imgRef",
|
|
76
|
+
ref: g,
|
|
77
|
+
src: _.value,
|
|
78
|
+
alt: r.alt,
|
|
79
|
+
class: E.value
|
|
80
|
+
}, h.value), null, 16, x)], 2));
|
|
81
|
+
}
|
|
80
82
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
83
|
+
//#endregion
|
|
84
|
+
export { S as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@place-framework/place-block-image",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A utility package for generating CSS custom properties from image dimensions to prevent layout shift",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"@types/glob": "^8.1.0",
|
|
49
49
|
"@types/node": "^20.0.0",
|
|
50
50
|
"@types/react": "^18.0.0",
|
|
51
|
-
"@vitejs/plugin-vue": "^
|
|
51
|
+
"@vitejs/plugin-vue": "^6.0.7",
|
|
52
52
|
"typescript": "^5.0.0",
|
|
53
|
-
"vite": "^
|
|
53
|
+
"vite": "^8.0.16"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"glob": "^10.0.0",
|