@uxf/core 10.0.0-beta.15 → 10.0.0-beta.25
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/package.json +1 -1
- package/utils/buildArray.d.ts +9 -21
- package/utils/buildArray.js +22 -23
- package/utils/buildArray.test.js +5 -5
- package/utils/image.d.ts +2 -0
- package/utils/image.js +16 -2
- package/utils/resizer.js +1 -1
package/package.json
CHANGED
package/utils/buildArray.d.ts
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
when: (condition: boolean, data: T) => {
|
|
12
|
-
add: (data: T) => {
|
|
13
|
-
add: any;
|
|
14
|
-
when: any;
|
|
15
|
-
get: () => T[];
|
|
16
|
-
};
|
|
17
|
-
when: any;
|
|
18
|
-
get: () => T[];
|
|
19
|
-
};
|
|
20
|
-
get: () => T[];
|
|
21
|
-
};
|
|
1
|
+
type Element<T> = T;
|
|
2
|
+
type WhenFn<T> = (when: boolean, element: Element<T>) => ProxiedArray<T>;
|
|
3
|
+
type AddFn<T> = (element: Element<T>) => ProxiedArray<T>;
|
|
4
|
+
type ProxiedArray<T> = {
|
|
5
|
+
when: WhenFn<T>;
|
|
6
|
+
add: AddFn<T>;
|
|
7
|
+
} & T[];
|
|
8
|
+
export declare function buildArray<T = unknown>(initial?: T[]): ProxiedArray<T>;
|
|
9
|
+
export {};
|
package/utils/buildArray.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildArray = void 0;
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return { add: add(array), when: when(array), get: get(array) };
|
|
4
|
+
function buildArray(initial) {
|
|
5
|
+
const initialArray = (initial ? [...initial] : []);
|
|
6
|
+
const proxiedArray = new Proxy(initialArray, {
|
|
7
|
+
get: (target, prop, receiver) => {
|
|
8
|
+
if ("add" === prop) {
|
|
9
|
+
return (element) => {
|
|
10
|
+
target.push(element);
|
|
11
|
+
return proxiedArray;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if ("when" === prop) {
|
|
15
|
+
return (when, element) => {
|
|
16
|
+
if (when) {
|
|
17
|
+
target.push(element);
|
|
18
|
+
}
|
|
19
|
+
return proxiedArray;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return Reflect.get(target, prop, receiver);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return proxiedArray;
|
|
27
26
|
}
|
|
28
27
|
exports.buildArray = buildArray;
|
package/utils/buildArray.test.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const buildArray_1 = require("./buildArray");
|
|
4
4
|
test("buildArray", () => {
|
|
5
|
-
expect((0, buildArray_1.buildArray)()
|
|
6
|
-
expect((0, buildArray_1.buildArray)().add("uxf")
|
|
7
|
-
expect((0, buildArray_1.buildArray)().add("ux").add("fans")
|
|
8
|
-
expect((0, buildArray_1.buildArray)().add("ux").when(true, "fans")
|
|
9
|
-
expect((0, buildArray_1.buildArray)().add("ux").when(false, "fans")
|
|
5
|
+
expect((0, buildArray_1.buildArray)()).toStrictEqual([]);
|
|
6
|
+
expect((0, buildArray_1.buildArray)().add("uxf")).toStrictEqual(["uxf"]);
|
|
7
|
+
expect((0, buildArray_1.buildArray)().add("ux").add("fans")).toStrictEqual(["ux", "fans"]);
|
|
8
|
+
expect((0, buildArray_1.buildArray)().add("ux").when(true, "fans")).toStrictEqual(["ux", "fans"]);
|
|
9
|
+
expect((0, buildArray_1.buildArray)().add("ux").when(false, "fans")).toStrictEqual(["ux"]);
|
|
10
10
|
});
|
package/utils/image.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export type Quality = number | Record<Format, number>;
|
|
|
6
6
|
export declare function getSvgImgUrl(src: ImageSource): string | undefined;
|
|
7
7
|
export declare function getImgQuality(quality: Quality | undefined, format: Format): number | undefined;
|
|
8
8
|
export declare function getImgUniqueIdentifier(src: ImageSource): string | undefined;
|
|
9
|
+
export declare function getImgElementHeight(src: ImageSource, width: number | undefined, height: number | undefined): number | undefined;
|
|
10
|
+
export declare function getImgElementWidth(src: ImageSource, width: number | undefined, height: number | undefined): number | undefined;
|
|
9
11
|
export declare function getImgSrcSet(src?: ImageSource, width?: Dimension, height?: Dimension, options?: ResizerImageProps): string | undefined;
|
|
10
12
|
interface ImageSourcesProps {
|
|
11
13
|
breakpointIndex?: number;
|
package/utils/image.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ImgSources = exports.getImgSrcSet = exports.getImgUniqueIdentifier = exports.getImgQuality = exports.getSvgImgUrl = void 0;
|
|
6
|
+
exports.ImgSources = exports.getImgSrcSet = exports.getImgElementWidth = exports.getImgElementHeight = exports.getImgUniqueIdentifier = exports.getImgQuality = exports.getSvgImgUrl = void 0;
|
|
7
7
|
const file_1 = require("./file");
|
|
8
8
|
const resizer_1 = require("./resizer");
|
|
9
9
|
const react_1 = __importDefault(require("react"));
|
|
@@ -41,6 +41,20 @@ function getImgUniqueIdentifier(src) {
|
|
|
41
41
|
return typeof src === "string" ? src : (_b = (_a = toImageResponse(src)) === null || _a === void 0 ? void 0 : _a.uuid) !== null && _b !== void 0 ? _b : (_c = toStaticImageData(src)) === null || _c === void 0 ? void 0 : _c.src;
|
|
42
42
|
}
|
|
43
43
|
exports.getImgUniqueIdentifier = getImgUniqueIdentifier;
|
|
44
|
+
function getImgElementHeight(src, width, height) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return typeof src === "string"
|
|
47
|
+
? height
|
|
48
|
+
: height !== null && height !== void 0 ? height : (Math.floor((((_a = src.height) !== null && _a !== void 0 ? _a : 0) / ((_b = src.width) !== null && _b !== void 0 ? _b : 0)) * (width || 0)) || undefined);
|
|
49
|
+
}
|
|
50
|
+
exports.getImgElementHeight = getImgElementHeight;
|
|
51
|
+
function getImgElementWidth(src, width, height) {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
return typeof src === "string"
|
|
54
|
+
? width
|
|
55
|
+
: width !== null && width !== void 0 ? width : (Math.floor(((_a = src.width) !== null && _a !== void 0 ? _a : 0) / ((_b = src.height) !== null && _b !== void 0 ? _b : 0)) * (height || 0) || undefined);
|
|
56
|
+
}
|
|
57
|
+
exports.getImgElementWidth = getImgElementWidth;
|
|
44
58
|
const HIDPI_SIZES = [3, 2, 1];
|
|
45
59
|
function getImgSrcSet(src, width, height, options = {}) {
|
|
46
60
|
var _a, _b;
|
|
@@ -72,7 +86,7 @@ function getImgSrcSet(src, width, height, options = {}) {
|
|
|
72
86
|
w = w || staticImageData.width;
|
|
73
87
|
}
|
|
74
88
|
if (typeof h === "number" || typeof w === "number") {
|
|
75
|
-
return HIDPI_SIZES.map((size) => (0, resizer_1.resizerImageUrl)(src, w * size, h * size, {
|
|
89
|
+
return HIDPI_SIZES.map((size) => (0, resizer_1.resizerImageUrl)(src, typeof w === "number" ? w * size : "auto", typeof h === "number" ? h * size : "auto", {
|
|
76
90
|
toFormat,
|
|
77
91
|
...options,
|
|
78
92
|
}) + (size > 1 ? ` ${size}x` : "")).join(", ");
|
package/utils/resizer.js
CHANGED
|
@@ -48,7 +48,7 @@ const resizerStaticImageUrl = (src, width = "auto", height = "auto", props = {},
|
|
|
48
48
|
};
|
|
49
49
|
const resizerImageUrl = (source, width = "auto", height = "auto", props = {}, version = 1) => {
|
|
50
50
|
var _a, _b;
|
|
51
|
-
if (source === null || source === undefined) {
|
|
51
|
+
if (source === null || source === undefined || source === "") {
|
|
52
52
|
return undefined;
|
|
53
53
|
}
|
|
54
54
|
if (typeof source === "string" || "src" in source) {
|