@mekari/pixel3-image 0.0.7-dev.5
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/chunk-DPFH2SO2.mjs +77 -0
- package/dist/chunk-LQRQ2LTW.mjs +48 -0
- package/dist/chunk-MC3PU33I.mjs +240 -0
- package/dist/chunk-QZ7VFGWC.mjs +6 -0
- package/dist/image.d.mts +167 -0
- package/dist/image.d.ts +167 -0
- package/dist/image.js +373 -0
- package/dist/image.mjs +9 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +375 -0
- package/dist/index.mjs +9 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/modules/image.hooks.d.mts +76 -0
- package/dist/modules/image.hooks.d.ts +76 -0
- package/dist/modules/image.hooks.js +261 -0
- package/dist/modules/image.hooks.mjs +7 -0
- package/dist/modules/image.props.d.mts +78 -0
- package/dist/modules/image.props.d.ts +78 -0
- package/dist/modules/image.props.js +102 -0
- package/dist/modules/image.props.mjs +9 -0
- package/dist/modules/image.type.d.mts +4 -0
- package/dist/modules/image.type.d.ts +4 -0
- package/dist/modules/image.type.js +18 -0
- package/dist/modules/image.type.mjs +0 -0
- package/package.json +42 -0
package/dist/image.js
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/image.tsx
|
|
22
|
+
var image_exports = {};
|
|
23
|
+
__export(image_exports, {
|
|
24
|
+
MpImage: () => MpImage
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(image_exports);
|
|
27
|
+
var import_vue2 = require("vue");
|
|
28
|
+
var import_vue3 = require("vue");
|
|
29
|
+
var import_pixel3_spinner = require("@mekari/pixel3-spinner");
|
|
30
|
+
var import_patterns = require("@mekari/pixel3-styled-system/patterns");
|
|
31
|
+
|
|
32
|
+
// src/modules/image.props.ts
|
|
33
|
+
var imageProps = {
|
|
34
|
+
id: {
|
|
35
|
+
type: String,
|
|
36
|
+
default: ""
|
|
37
|
+
},
|
|
38
|
+
src: {
|
|
39
|
+
type: String,
|
|
40
|
+
default: ""
|
|
41
|
+
},
|
|
42
|
+
alt: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: ""
|
|
45
|
+
},
|
|
46
|
+
layout: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: "intrinsic"
|
|
49
|
+
},
|
|
50
|
+
width: {
|
|
51
|
+
type: Number,
|
|
52
|
+
default: 0
|
|
53
|
+
},
|
|
54
|
+
height: {
|
|
55
|
+
type: Number,
|
|
56
|
+
default: 0
|
|
57
|
+
},
|
|
58
|
+
sizes: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: ""
|
|
61
|
+
},
|
|
62
|
+
srcPlaceholder: {
|
|
63
|
+
type: String,
|
|
64
|
+
default: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
|
|
65
|
+
},
|
|
66
|
+
srcset: {
|
|
67
|
+
type: String,
|
|
68
|
+
default: ""
|
|
69
|
+
},
|
|
70
|
+
typeSrcset: {
|
|
71
|
+
type: String,
|
|
72
|
+
default: ""
|
|
73
|
+
},
|
|
74
|
+
mediaSrcset: {
|
|
75
|
+
type: String,
|
|
76
|
+
default: ""
|
|
77
|
+
},
|
|
78
|
+
maxSrcset: {
|
|
79
|
+
type: Number,
|
|
80
|
+
default: 5
|
|
81
|
+
},
|
|
82
|
+
objectFit: {
|
|
83
|
+
type: String,
|
|
84
|
+
default: "fill"
|
|
85
|
+
},
|
|
86
|
+
objectPosition: {
|
|
87
|
+
type: String,
|
|
88
|
+
default: ""
|
|
89
|
+
},
|
|
90
|
+
errorText: {
|
|
91
|
+
type: String,
|
|
92
|
+
default: "Failed load image"
|
|
93
|
+
},
|
|
94
|
+
isLazy: {
|
|
95
|
+
type: Boolean,
|
|
96
|
+
default: true
|
|
97
|
+
},
|
|
98
|
+
isShowLoading: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
default: true
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/modules/image.hooks.ts
|
|
105
|
+
var import_vue = require("vue");
|
|
106
|
+
var import_pixel3_utils = require("@mekari/pixel3-utils");
|
|
107
|
+
function useImage(props, emit) {
|
|
108
|
+
const {
|
|
109
|
+
id,
|
|
110
|
+
src,
|
|
111
|
+
alt,
|
|
112
|
+
srcPlaceholder,
|
|
113
|
+
srcset,
|
|
114
|
+
typeSrcset,
|
|
115
|
+
mediaSrcset,
|
|
116
|
+
layout,
|
|
117
|
+
width,
|
|
118
|
+
height,
|
|
119
|
+
sizes,
|
|
120
|
+
objectFit,
|
|
121
|
+
objectPosition,
|
|
122
|
+
errorText,
|
|
123
|
+
isLazy,
|
|
124
|
+
isShowLoading
|
|
125
|
+
} = (0, import_vue.toRefs)(props);
|
|
126
|
+
const intersected = (0, import_vue.ref)(false);
|
|
127
|
+
const loaded = (0, import_vue.ref)(false);
|
|
128
|
+
const failed = (0, import_vue.ref)(false);
|
|
129
|
+
const imageWrapperNode = (0, import_vue.ref)();
|
|
130
|
+
const imgNode = (0, import_vue.ref)();
|
|
131
|
+
const {
|
|
132
|
+
stop: disableIntersectionObserver
|
|
133
|
+
} = (0, import_pixel3_utils.useIntersectionObserver)(imageWrapperNode, ([{
|
|
134
|
+
isIntersecting
|
|
135
|
+
}]) => {
|
|
136
|
+
if (isIntersecting) {
|
|
137
|
+
intersected.value = true;
|
|
138
|
+
emit("intersect", getId);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const getId = id.value || (0, import_pixel3_utils.getUniqueId)("", "image").value;
|
|
142
|
+
const isVisible = (0, import_vue.computed)(() => {
|
|
143
|
+
return intersected.value || !isLazy.value;
|
|
144
|
+
});
|
|
145
|
+
const isLoading = (0, import_vue.computed)(() => {
|
|
146
|
+
return isShowLoading.value && isVisible.value && !loaded.value && !failed.value;
|
|
147
|
+
});
|
|
148
|
+
const srcImage = (0, import_vue.computed)(() => {
|
|
149
|
+
return isVisible.value && src.value ? src.value : srcPlaceholder.value;
|
|
150
|
+
});
|
|
151
|
+
const srcsetImage = (0, import_vue.computed)(() => {
|
|
152
|
+
return isVisible.value && srcset.value ? srcset.value : void 0;
|
|
153
|
+
});
|
|
154
|
+
const sizerSvg = (0, import_vue.computed)(() => {
|
|
155
|
+
if (layout.value !== "intrinsic") {
|
|
156
|
+
return "";
|
|
157
|
+
}
|
|
158
|
+
const backgroundColor = !intersected.value ? "background-color:#ffffff;" : "";
|
|
159
|
+
return `<svg
|
|
160
|
+
width="${width.value}"
|
|
161
|
+
height="${height.value}"
|
|
162
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
163
|
+
style="${backgroundColor}"
|
|
164
|
+
>
|
|
165
|
+
<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle">${errorText.value}</text>
|
|
166
|
+
</svg>`;
|
|
167
|
+
});
|
|
168
|
+
const sizerStyle = (0, import_vue.computed)(() => {
|
|
169
|
+
let style;
|
|
170
|
+
if (layout.value === "responsive") {
|
|
171
|
+
const quotient = height.value / width.value;
|
|
172
|
+
const paddingTop = isNaN(quotient) ? "100%" : `${quotient * 100}%`;
|
|
173
|
+
style = {
|
|
174
|
+
display: "block",
|
|
175
|
+
boxSizing: "border-box",
|
|
176
|
+
paddingTop
|
|
177
|
+
};
|
|
178
|
+
} else if (layout.value === "intrinsic") {
|
|
179
|
+
style = {
|
|
180
|
+
boxSizing: "border-box",
|
|
181
|
+
display: "block",
|
|
182
|
+
maxWidth: "100%"
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return style;
|
|
186
|
+
});
|
|
187
|
+
const wrapperStyle = (0, import_vue.computed)(() => {
|
|
188
|
+
let style = {};
|
|
189
|
+
if (layout.value === "responsive") {
|
|
190
|
+
style = {
|
|
191
|
+
position: "relative",
|
|
192
|
+
display: "block",
|
|
193
|
+
overflow: "hidden",
|
|
194
|
+
boxSizing: "border-box",
|
|
195
|
+
margin: 0
|
|
196
|
+
};
|
|
197
|
+
} else if (layout.value === "intrinsic") {
|
|
198
|
+
style = {
|
|
199
|
+
position: "relative",
|
|
200
|
+
display: "inline-block",
|
|
201
|
+
overflow: "hidden",
|
|
202
|
+
boxSizing: "border-box",
|
|
203
|
+
maxWidth: "100%",
|
|
204
|
+
margin: 0
|
|
205
|
+
};
|
|
206
|
+
} else if (layout.value === "fixed") {
|
|
207
|
+
style = {
|
|
208
|
+
position: "relative",
|
|
209
|
+
display: "inline-block",
|
|
210
|
+
overflow: "hidden",
|
|
211
|
+
boxSizing: "border-box",
|
|
212
|
+
width: `${width.value}px`,
|
|
213
|
+
height: `${height.value}px`
|
|
214
|
+
};
|
|
215
|
+
} else if (layout.value === "fill") {
|
|
216
|
+
style = {
|
|
217
|
+
position: "absolute",
|
|
218
|
+
display: "block",
|
|
219
|
+
overflow: "hidden",
|
|
220
|
+
boxSizing: "border-box",
|
|
221
|
+
top: 0,
|
|
222
|
+
left: 0,
|
|
223
|
+
bottom: 0,
|
|
224
|
+
right: 0,
|
|
225
|
+
margin: 0
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
return style;
|
|
229
|
+
});
|
|
230
|
+
const rootAttrs = (0, import_vue.computed)(() => {
|
|
231
|
+
return {
|
|
232
|
+
"data-pixel-component": "MpImage",
|
|
233
|
+
ref: imageWrapperNode,
|
|
234
|
+
id: getId,
|
|
235
|
+
style: {
|
|
236
|
+
...wrapperStyle.value
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
const sizerAttrs = (0, import_vue.computed)(() => {
|
|
241
|
+
return {
|
|
242
|
+
style: {
|
|
243
|
+
...sizerStyle.value
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
const imgSizerAttrs = (0, import_vue.computed)(() => {
|
|
248
|
+
return {
|
|
249
|
+
src: `data:image/svg+xml;base64,${toBase64(sizerSvg.value)}`,
|
|
250
|
+
alt: "",
|
|
251
|
+
ariaHidden: true,
|
|
252
|
+
style: {
|
|
253
|
+
maxWidth: "100%",
|
|
254
|
+
display: "block",
|
|
255
|
+
border: "none",
|
|
256
|
+
margin: 0,
|
|
257
|
+
padding: 0
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
const sourceAttrs = (0, import_vue.computed)(() => {
|
|
262
|
+
return {
|
|
263
|
+
srcset: srcsetImage.value,
|
|
264
|
+
type: typeSrcset.value,
|
|
265
|
+
media: mediaSrcset.value
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
const imgAttrs = (0, import_vue.computed)(() => {
|
|
269
|
+
return {
|
|
270
|
+
ref: imgNode,
|
|
271
|
+
alt: alt.value ? alt.value : void 0,
|
|
272
|
+
src: srcImage.value ? srcImage.value : void 0,
|
|
273
|
+
sizes: sizes.value ? sizes.value : void 0,
|
|
274
|
+
decoding: "async",
|
|
275
|
+
// eslint-disable-next-line
|
|
276
|
+
style: {
|
|
277
|
+
position: "absolute",
|
|
278
|
+
display: "block",
|
|
279
|
+
top: 0,
|
|
280
|
+
left: 0,
|
|
281
|
+
bottom: 0,
|
|
282
|
+
right: 0,
|
|
283
|
+
boxSizing: "border-box",
|
|
284
|
+
padding: 0,
|
|
285
|
+
border: "none",
|
|
286
|
+
margin: "auto",
|
|
287
|
+
width: "0",
|
|
288
|
+
height: "0",
|
|
289
|
+
minWidth: "100%",
|
|
290
|
+
maxWidth: "100%",
|
|
291
|
+
minHeight: "100%",
|
|
292
|
+
maxHeight: "100%",
|
|
293
|
+
objectFit: objectFit.value ? objectFit.value : void 0,
|
|
294
|
+
objectPosition: objectPosition.value ? objectPosition.value : void 0
|
|
295
|
+
},
|
|
296
|
+
onLoad: handleLoad,
|
|
297
|
+
onError: handleError
|
|
298
|
+
};
|
|
299
|
+
});
|
|
300
|
+
function toBase64(str) {
|
|
301
|
+
console.log("STR", str);
|
|
302
|
+
if (typeof window === "undefined") {
|
|
303
|
+
return Buffer.from(str).toString("base64");
|
|
304
|
+
} else {
|
|
305
|
+
return window.btoa(str);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
__name(toBase64, "toBase64");
|
|
309
|
+
function handleLoad() {
|
|
310
|
+
if (imgNode.value && imgNode.value.getAttribute("src") !== srcPlaceholder.value && !loaded.value) {
|
|
311
|
+
loaded.value = true;
|
|
312
|
+
emit("load", getId);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
__name(handleLoad, "handleLoad");
|
|
316
|
+
function handleError(e) {
|
|
317
|
+
emit("error", getId, e);
|
|
318
|
+
failed.value = true;
|
|
319
|
+
}
|
|
320
|
+
__name(handleError, "handleError");
|
|
321
|
+
(0, import_vue.onUnmounted)(() => {
|
|
322
|
+
disableIntersectionObserver();
|
|
323
|
+
});
|
|
324
|
+
return {
|
|
325
|
+
rootAttrs,
|
|
326
|
+
sizerAttrs,
|
|
327
|
+
imgSizerAttrs,
|
|
328
|
+
sourceAttrs,
|
|
329
|
+
imgAttrs,
|
|
330
|
+
isLoading,
|
|
331
|
+
sizerStyle,
|
|
332
|
+
sizerSvg
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
__name(useImage, "useImage");
|
|
336
|
+
|
|
337
|
+
// src/image.tsx
|
|
338
|
+
var MpImage = (0, import_vue3.defineComponent)({
|
|
339
|
+
name: "MpImage",
|
|
340
|
+
props: imageProps,
|
|
341
|
+
emits: ["intersect", "load", "error"],
|
|
342
|
+
setup(props, {
|
|
343
|
+
slots,
|
|
344
|
+
emit
|
|
345
|
+
}) {
|
|
346
|
+
const {
|
|
347
|
+
rootAttrs,
|
|
348
|
+
sizerAttrs,
|
|
349
|
+
imgSizerAttrs,
|
|
350
|
+
sourceAttrs,
|
|
351
|
+
imgAttrs,
|
|
352
|
+
isLoading,
|
|
353
|
+
sizerStyle
|
|
354
|
+
} = useImage(props, emit);
|
|
355
|
+
return () => {
|
|
356
|
+
const children = slots.default && slots.default();
|
|
357
|
+
return (0, import_vue2.createVNode)("div", rootAttrs.value, [isLoading.value && (0, import_vue2.createVNode)("div", {
|
|
358
|
+
"class": (0, import_patterns.flex)({
|
|
359
|
+
alignItems: "center",
|
|
360
|
+
justifyContent: "center",
|
|
361
|
+
zIndex: "1",
|
|
362
|
+
position: "absolute",
|
|
363
|
+
width: "full",
|
|
364
|
+
height: "full"
|
|
365
|
+
})
|
|
366
|
+
}, [children ? children : (0, import_vue2.createVNode)(import_pixel3_spinner.MpSpinner, null, null)]), sizerStyle.value && (0, import_vue2.createVNode)("div", sizerAttrs.value, [(0, import_vue2.createVNode)("img", imgSizerAttrs.value, null)]), (0, import_vue2.createVNode)("picture", null, [(0, import_vue2.createVNode)("source", sourceAttrs.value, null), (0, import_vue2.createVNode)("img", imgAttrs.value, null)])]);
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
371
|
+
0 && (module.exports = {
|
|
372
|
+
MpImage
|
|
373
|
+
});
|
package/dist/image.mjs
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED