@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.
@@ -0,0 +1,261 @@
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/modules/image.hooks.ts
22
+ var image_hooks_exports = {};
23
+ __export(image_hooks_exports, {
24
+ useImage: () => useImage
25
+ });
26
+ module.exports = __toCommonJS(image_hooks_exports);
27
+ var import_vue = require("vue");
28
+ var import_pixel3_utils = require("@mekari/pixel3-utils");
29
+ function useImage(props, emit) {
30
+ const {
31
+ id,
32
+ src,
33
+ alt,
34
+ srcPlaceholder,
35
+ srcset,
36
+ typeSrcset,
37
+ mediaSrcset,
38
+ layout,
39
+ width,
40
+ height,
41
+ sizes,
42
+ objectFit,
43
+ objectPosition,
44
+ errorText,
45
+ isLazy,
46
+ isShowLoading
47
+ } = (0, import_vue.toRefs)(props);
48
+ const intersected = (0, import_vue.ref)(false);
49
+ const loaded = (0, import_vue.ref)(false);
50
+ const failed = (0, import_vue.ref)(false);
51
+ const imageWrapperNode = (0, import_vue.ref)();
52
+ const imgNode = (0, import_vue.ref)();
53
+ const {
54
+ stop: disableIntersectionObserver
55
+ } = (0, import_pixel3_utils.useIntersectionObserver)(imageWrapperNode, ([{
56
+ isIntersecting
57
+ }]) => {
58
+ if (isIntersecting) {
59
+ intersected.value = true;
60
+ emit("intersect", getId);
61
+ }
62
+ });
63
+ const getId = id.value || (0, import_pixel3_utils.getUniqueId)("", "image").value;
64
+ const isVisible = (0, import_vue.computed)(() => {
65
+ return intersected.value || !isLazy.value;
66
+ });
67
+ const isLoading = (0, import_vue.computed)(() => {
68
+ return isShowLoading.value && isVisible.value && !loaded.value && !failed.value;
69
+ });
70
+ const srcImage = (0, import_vue.computed)(() => {
71
+ return isVisible.value && src.value ? src.value : srcPlaceholder.value;
72
+ });
73
+ const srcsetImage = (0, import_vue.computed)(() => {
74
+ return isVisible.value && srcset.value ? srcset.value : void 0;
75
+ });
76
+ const sizerSvg = (0, import_vue.computed)(() => {
77
+ if (layout.value !== "intrinsic") {
78
+ return "";
79
+ }
80
+ const backgroundColor = !intersected.value ? "background-color:#ffffff;" : "";
81
+ return `<svg
82
+ width="${width.value}"
83
+ height="${height.value}"
84
+ xmlns="http://www.w3.org/2000/svg"
85
+ style="${backgroundColor}"
86
+ >
87
+ <text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle">${errorText.value}</text>
88
+ </svg>`;
89
+ });
90
+ const sizerStyle = (0, import_vue.computed)(() => {
91
+ let style;
92
+ if (layout.value === "responsive") {
93
+ const quotient = height.value / width.value;
94
+ const paddingTop = isNaN(quotient) ? "100%" : `${quotient * 100}%`;
95
+ style = {
96
+ display: "block",
97
+ boxSizing: "border-box",
98
+ paddingTop
99
+ };
100
+ } else if (layout.value === "intrinsic") {
101
+ style = {
102
+ boxSizing: "border-box",
103
+ display: "block",
104
+ maxWidth: "100%"
105
+ };
106
+ }
107
+ return style;
108
+ });
109
+ const wrapperStyle = (0, import_vue.computed)(() => {
110
+ let style = {};
111
+ if (layout.value === "responsive") {
112
+ style = {
113
+ position: "relative",
114
+ display: "block",
115
+ overflow: "hidden",
116
+ boxSizing: "border-box",
117
+ margin: 0
118
+ };
119
+ } else if (layout.value === "intrinsic") {
120
+ style = {
121
+ position: "relative",
122
+ display: "inline-block",
123
+ overflow: "hidden",
124
+ boxSizing: "border-box",
125
+ maxWidth: "100%",
126
+ margin: 0
127
+ };
128
+ } else if (layout.value === "fixed") {
129
+ style = {
130
+ position: "relative",
131
+ display: "inline-block",
132
+ overflow: "hidden",
133
+ boxSizing: "border-box",
134
+ width: `${width.value}px`,
135
+ height: `${height.value}px`
136
+ };
137
+ } else if (layout.value === "fill") {
138
+ style = {
139
+ position: "absolute",
140
+ display: "block",
141
+ overflow: "hidden",
142
+ boxSizing: "border-box",
143
+ top: 0,
144
+ left: 0,
145
+ bottom: 0,
146
+ right: 0,
147
+ margin: 0
148
+ };
149
+ }
150
+ return style;
151
+ });
152
+ const rootAttrs = (0, import_vue.computed)(() => {
153
+ return {
154
+ "data-pixel-component": "MpImage",
155
+ ref: imageWrapperNode,
156
+ id: getId,
157
+ style: {
158
+ ...wrapperStyle.value
159
+ }
160
+ };
161
+ });
162
+ const sizerAttrs = (0, import_vue.computed)(() => {
163
+ return {
164
+ style: {
165
+ ...sizerStyle.value
166
+ }
167
+ };
168
+ });
169
+ const imgSizerAttrs = (0, import_vue.computed)(() => {
170
+ return {
171
+ src: `data:image/svg+xml;base64,${toBase64(sizerSvg.value)}`,
172
+ alt: "",
173
+ ariaHidden: true,
174
+ style: {
175
+ maxWidth: "100%",
176
+ display: "block",
177
+ border: "none",
178
+ margin: 0,
179
+ padding: 0
180
+ }
181
+ };
182
+ });
183
+ const sourceAttrs = (0, import_vue.computed)(() => {
184
+ return {
185
+ srcset: srcsetImage.value,
186
+ type: typeSrcset.value,
187
+ media: mediaSrcset.value
188
+ };
189
+ });
190
+ const imgAttrs = (0, import_vue.computed)(() => {
191
+ return {
192
+ ref: imgNode,
193
+ alt: alt.value ? alt.value : void 0,
194
+ src: srcImage.value ? srcImage.value : void 0,
195
+ sizes: sizes.value ? sizes.value : void 0,
196
+ decoding: "async",
197
+ // eslint-disable-next-line
198
+ style: {
199
+ position: "absolute",
200
+ display: "block",
201
+ top: 0,
202
+ left: 0,
203
+ bottom: 0,
204
+ right: 0,
205
+ boxSizing: "border-box",
206
+ padding: 0,
207
+ border: "none",
208
+ margin: "auto",
209
+ width: "0",
210
+ height: "0",
211
+ minWidth: "100%",
212
+ maxWidth: "100%",
213
+ minHeight: "100%",
214
+ maxHeight: "100%",
215
+ objectFit: objectFit.value ? objectFit.value : void 0,
216
+ objectPosition: objectPosition.value ? objectPosition.value : void 0
217
+ },
218
+ onLoad: handleLoad,
219
+ onError: handleError
220
+ };
221
+ });
222
+ function toBase64(str) {
223
+ console.log("STR", str);
224
+ if (typeof window === "undefined") {
225
+ return Buffer.from(str).toString("base64");
226
+ } else {
227
+ return window.btoa(str);
228
+ }
229
+ }
230
+ __name(toBase64, "toBase64");
231
+ function handleLoad() {
232
+ if (imgNode.value && imgNode.value.getAttribute("src") !== srcPlaceholder.value && !loaded.value) {
233
+ loaded.value = true;
234
+ emit("load", getId);
235
+ }
236
+ }
237
+ __name(handleLoad, "handleLoad");
238
+ function handleError(e) {
239
+ emit("error", getId, e);
240
+ failed.value = true;
241
+ }
242
+ __name(handleError, "handleError");
243
+ (0, import_vue.onUnmounted)(() => {
244
+ disableIntersectionObserver();
245
+ });
246
+ return {
247
+ rootAttrs,
248
+ sizerAttrs,
249
+ imgSizerAttrs,
250
+ sourceAttrs,
251
+ imgAttrs,
252
+ isLoading,
253
+ sizerStyle,
254
+ sizerSvg
255
+ };
256
+ }
257
+ __name(useImage, "useImage");
258
+ // Annotate the CommonJS export names for ESM import in node:
259
+ 0 && (module.exports = {
260
+ useImage
261
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ useImage
3
+ } from "../chunk-MC3PU33I.mjs";
4
+ import "../chunk-QZ7VFGWC.mjs";
5
+ export {
6
+ useImage
7
+ };
@@ -0,0 +1,78 @@
1
+ import { PropType, ExtractPropTypes } from 'vue';
2
+ import { ImageLayout, ImageObjectFit } from './image.type.mjs';
3
+
4
+ declare const imageProps: {
5
+ id: {
6
+ type: PropType<string>;
7
+ default: string;
8
+ };
9
+ src: {
10
+ type: PropType<string>;
11
+ default: string;
12
+ };
13
+ alt: {
14
+ type: PropType<string>;
15
+ default: string;
16
+ };
17
+ layout: {
18
+ type: PropType<ImageLayout>;
19
+ default: string;
20
+ };
21
+ width: {
22
+ type: PropType<number>;
23
+ default: number;
24
+ };
25
+ height: {
26
+ type: PropType<number>;
27
+ default: number;
28
+ };
29
+ sizes: {
30
+ type: PropType<string>;
31
+ default: string;
32
+ };
33
+ srcPlaceholder: {
34
+ type: PropType<string>;
35
+ default: string;
36
+ };
37
+ srcset: {
38
+ type: PropType<string>;
39
+ default: string;
40
+ };
41
+ typeSrcset: {
42
+ type: PropType<string>;
43
+ default: string;
44
+ };
45
+ mediaSrcset: {
46
+ type: PropType<string>;
47
+ default: string;
48
+ };
49
+ maxSrcset: {
50
+ type: PropType<number>;
51
+ default: number;
52
+ };
53
+ objectFit: {
54
+ type: PropType<ImageObjectFit>;
55
+ default: string;
56
+ };
57
+ objectPosition: {
58
+ type: PropType<string>;
59
+ default: string;
60
+ };
61
+ errorText: {
62
+ type: PropType<string>;
63
+ default: string;
64
+ };
65
+ isLazy: {
66
+ type: PropType<boolean>;
67
+ default: boolean;
68
+ };
69
+ isShowLoading: {
70
+ type: PropType<boolean>;
71
+ default: boolean;
72
+ };
73
+ };
74
+ declare const imageEmit: readonly ["intersect", "load", "error"];
75
+ type ImageProps = ExtractPropTypes<typeof imageProps>;
76
+ type ImageEmit = (event: (typeof imageEmit)[number], value?: unknown, value2?: unknown) => void;
77
+
78
+ export { ImageEmit, ImageProps, imageEmit, imageProps };
@@ -0,0 +1,78 @@
1
+ import { PropType, ExtractPropTypes } from 'vue';
2
+ import { ImageLayout, ImageObjectFit } from './image.type.js';
3
+
4
+ declare const imageProps: {
5
+ id: {
6
+ type: PropType<string>;
7
+ default: string;
8
+ };
9
+ src: {
10
+ type: PropType<string>;
11
+ default: string;
12
+ };
13
+ alt: {
14
+ type: PropType<string>;
15
+ default: string;
16
+ };
17
+ layout: {
18
+ type: PropType<ImageLayout>;
19
+ default: string;
20
+ };
21
+ width: {
22
+ type: PropType<number>;
23
+ default: number;
24
+ };
25
+ height: {
26
+ type: PropType<number>;
27
+ default: number;
28
+ };
29
+ sizes: {
30
+ type: PropType<string>;
31
+ default: string;
32
+ };
33
+ srcPlaceholder: {
34
+ type: PropType<string>;
35
+ default: string;
36
+ };
37
+ srcset: {
38
+ type: PropType<string>;
39
+ default: string;
40
+ };
41
+ typeSrcset: {
42
+ type: PropType<string>;
43
+ default: string;
44
+ };
45
+ mediaSrcset: {
46
+ type: PropType<string>;
47
+ default: string;
48
+ };
49
+ maxSrcset: {
50
+ type: PropType<number>;
51
+ default: number;
52
+ };
53
+ objectFit: {
54
+ type: PropType<ImageObjectFit>;
55
+ default: string;
56
+ };
57
+ objectPosition: {
58
+ type: PropType<string>;
59
+ default: string;
60
+ };
61
+ errorText: {
62
+ type: PropType<string>;
63
+ default: string;
64
+ };
65
+ isLazy: {
66
+ type: PropType<boolean>;
67
+ default: boolean;
68
+ };
69
+ isShowLoading: {
70
+ type: PropType<boolean>;
71
+ default: boolean;
72
+ };
73
+ };
74
+ declare const imageEmit: readonly ["intersect", "load", "error"];
75
+ type ImageProps = ExtractPropTypes<typeof imageProps>;
76
+ type ImageEmit = (event: (typeof imageEmit)[number], value?: unknown, value2?: unknown) => void;
77
+
78
+ export { ImageEmit, ImageProps, imageEmit, imageProps };
@@ -0,0 +1,102 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/modules/image.props.ts
21
+ var image_props_exports = {};
22
+ __export(image_props_exports, {
23
+ imageEmit: () => imageEmit,
24
+ imageProps: () => imageProps
25
+ });
26
+ module.exports = __toCommonJS(image_props_exports);
27
+ var imageProps = {
28
+ id: {
29
+ type: String,
30
+ default: ""
31
+ },
32
+ src: {
33
+ type: String,
34
+ default: ""
35
+ },
36
+ alt: {
37
+ type: String,
38
+ default: ""
39
+ },
40
+ layout: {
41
+ type: String,
42
+ default: "intrinsic"
43
+ },
44
+ width: {
45
+ type: Number,
46
+ default: 0
47
+ },
48
+ height: {
49
+ type: Number,
50
+ default: 0
51
+ },
52
+ sizes: {
53
+ type: String,
54
+ default: ""
55
+ },
56
+ srcPlaceholder: {
57
+ type: String,
58
+ default: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
59
+ },
60
+ srcset: {
61
+ type: String,
62
+ default: ""
63
+ },
64
+ typeSrcset: {
65
+ type: String,
66
+ default: ""
67
+ },
68
+ mediaSrcset: {
69
+ type: String,
70
+ default: ""
71
+ },
72
+ maxSrcset: {
73
+ type: Number,
74
+ default: 5
75
+ },
76
+ objectFit: {
77
+ type: String,
78
+ default: "fill"
79
+ },
80
+ objectPosition: {
81
+ type: String,
82
+ default: ""
83
+ },
84
+ errorText: {
85
+ type: String,
86
+ default: "Failed load image"
87
+ },
88
+ isLazy: {
89
+ type: Boolean,
90
+ default: true
91
+ },
92
+ isShowLoading: {
93
+ type: Boolean,
94
+ default: true
95
+ }
96
+ };
97
+ var imageEmit = ["intersect", "load", "error"];
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ imageEmit,
101
+ imageProps
102
+ });
@@ -0,0 +1,9 @@
1
+ import {
2
+ imageEmit,
3
+ imageProps
4
+ } from "../chunk-DPFH2SO2.mjs";
5
+ import "../chunk-QZ7VFGWC.mjs";
6
+ export {
7
+ imageEmit,
8
+ imageProps
9
+ };
@@ -0,0 +1,4 @@
1
+ type ImageLayout = 'intrinsic' | 'fixed' | 'fill' | 'responsive';
2
+ type ImageObjectFit = 'fill' | 'contain' | 'cover' | 'none' | 'scale-down';
3
+
4
+ export { ImageLayout, ImageObjectFit };
@@ -0,0 +1,4 @@
1
+ type ImageLayout = 'intrinsic' | 'fixed' | 'fill' | 'responsive';
2
+ type ImageObjectFit = 'fill' | 'contain' | 'cover' | 'none' | 'scale-down';
3
+
4
+ export { ImageLayout, ImageObjectFit };
@@ -0,0 +1,18 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/modules/image.type.ts
17
+ var image_type_exports = {};
18
+ module.exports = __toCommonJS(image_type_exports);
File without changes
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@mekari/pixel3-image",
3
+ "description": "Image component for mekari pixel 3",
4
+ "version": "0.0.7-dev.5",
5
+ "main": "dist/index.js",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "dependencies": {
11
+ "@mekari/pixel3-spinner": "0.0.7",
12
+ "@mekari/pixel3-styled-system": "0.0.5",
13
+ "@mekari/pixel3-utils": "0.0.5"
14
+ },
15
+ "peerDependencies": {
16
+ "vue": "^3.4.9"
17
+ },
18
+ "devDependencies": {
19
+ "vue": "^3.4.9"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "module": "dist/index.mjs",
25
+ "types": "dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "require": "./dist/index.js",
30
+ "default": "./dist/index.mjs"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "clean": "rimraf dist .turbo",
35
+ "build": "tsup && pnpm build:types",
36
+ "build:fast": "tsup",
37
+ "build:types": "tsup src --dts-only",
38
+ "types:check": "tsc --noEmit",
39
+ "replace-config": "clean-package",
40
+ "restore-config": "clean-package restore"
41
+ }
42
+ }