@lisergia/utilities 0.0.0 → 2.0.0
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/.turbo/turbo-build.log +20 -0
- package/CHANGELOG.md +20 -0
- package/dist/index.cjs +162 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.mts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +159 -0
- package/dist/index.mjs +159 -0
- package/package.json +9 -7
- package/tsconfig.json +3 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @lisergia/utilities@1.0.0 build
|
|
4
|
+
> tsup src/index.ts --format cjs,esm --dts
|
|
5
|
+
|
|
6
|
+
[1G[0K[34mCLI[39m Building entry: src/index.ts
|
|
7
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
|
+
[34mCLI[39m tsup v8.5.0
|
|
9
|
+
[34mCLI[39m Target: node16
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m4.41 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 37ms
|
|
14
|
+
[32mESM[39m [1mdist/index.js [22m[32m4.21 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 37ms
|
|
16
|
+
DTS Build start
|
|
17
|
+
DTS ⚡️ Build success in 1047ms
|
|
18
|
+
DTS dist/index.d.cts 1.05 KB
|
|
19
|
+
DTS dist/index.d.ts 1.05 KB
|
|
20
|
+
[1G[0K⠙[1G[0K
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @lisergia/utilities
|
|
2
|
+
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Update build and serving of npm packages.
|
|
8
|
+
- Updating build and serving of npm packages.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- @lisergia/config-tsconfig@2.0.0
|
|
15
|
+
|
|
16
|
+
## 1.0.0
|
|
17
|
+
|
|
18
|
+
### Major Changes
|
|
19
|
+
|
|
20
|
+
- 9c70654: Initial release of Lisergia packages.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
CanvasUtils: () => CanvasUtils,
|
|
25
|
+
DOMUtils: () => DOMUtils,
|
|
26
|
+
Detection: () => Detection,
|
|
27
|
+
DetectionManager: () => DetectionManager,
|
|
28
|
+
MathUtils: () => MathUtils
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
|
|
32
|
+
// src/Polyfill.ts
|
|
33
|
+
var HTMLElementPrototype = HTMLElement.prototype;
|
|
34
|
+
var NodeListPrototype = NodeList.prototype;
|
|
35
|
+
if (!HTMLElementPrototype.forEach) {
|
|
36
|
+
HTMLElementPrototype.forEach = function(callback, thisArg) {
|
|
37
|
+
thisArg = thisArg || window;
|
|
38
|
+
callback.call(thisArg, this, this, this);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (!NodeListPrototype.filter) {
|
|
42
|
+
NodeListPrototype.filter = Array.prototype.filter;
|
|
43
|
+
}
|
|
44
|
+
if (!NodeListPrototype.find) {
|
|
45
|
+
NodeListPrototype.find = Array.prototype.find;
|
|
46
|
+
}
|
|
47
|
+
if (!NodeListPrototype.map) {
|
|
48
|
+
NodeListPrototype.map = Array.prototype.map;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/Canvas.ts
|
|
52
|
+
function trim(canvas) {
|
|
53
|
+
const context = canvas.getContext("2d");
|
|
54
|
+
const copy = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
|
55
|
+
const pixels = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
56
|
+
const length = pixels.data.length;
|
|
57
|
+
const bound = {
|
|
58
|
+
bottom: null,
|
|
59
|
+
left: null,
|
|
60
|
+
right: null,
|
|
61
|
+
top: null
|
|
62
|
+
};
|
|
63
|
+
let x;
|
|
64
|
+
let y;
|
|
65
|
+
for (let i = 0; i < length; i += 4) {
|
|
66
|
+
if (pixels.data[i + 3] !== 0) {
|
|
67
|
+
x = i / 4 % canvas.width;
|
|
68
|
+
y = ~~(i / 4 / canvas.width);
|
|
69
|
+
if (bound.top === null) {
|
|
70
|
+
bound.top = y;
|
|
71
|
+
}
|
|
72
|
+
if (bound.left === null) {
|
|
73
|
+
bound.left = x;
|
|
74
|
+
} else if (x < bound.left) {
|
|
75
|
+
bound.left = x;
|
|
76
|
+
}
|
|
77
|
+
if (bound.right === null) {
|
|
78
|
+
bound.right = x;
|
|
79
|
+
} else if (bound.right < x) {
|
|
80
|
+
bound.right = x;
|
|
81
|
+
}
|
|
82
|
+
if (bound.bottom === null) {
|
|
83
|
+
bound.bottom = y;
|
|
84
|
+
} else if (bound.bottom < y) {
|
|
85
|
+
bound.bottom = y;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const trimHeight = bound.bottom - bound.top;
|
|
90
|
+
const trimWidth = bound.right - bound.left;
|
|
91
|
+
const trimmed = context.getImageData(bound.left, bound.top, trimWidth, trimHeight);
|
|
92
|
+
copy.canvas.width = trimWidth;
|
|
93
|
+
copy.canvas.height = trimHeight;
|
|
94
|
+
copy.putImageData(trimmed, 0, 0);
|
|
95
|
+
return copy.canvas;
|
|
96
|
+
}
|
|
97
|
+
var CanvasUtils = {
|
|
98
|
+
trim
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/Detection.ts
|
|
102
|
+
var DetectionManager = class {
|
|
103
|
+
isMobile() {
|
|
104
|
+
return !document.documentElement.classList.contains("desktop");
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var Detection = new DetectionManager();
|
|
108
|
+
|
|
109
|
+
// src/DOM.ts
|
|
110
|
+
function getBounds(element, top = 0) {
|
|
111
|
+
const box = element.getBoundingClientRect();
|
|
112
|
+
return {
|
|
113
|
+
bottom: box.bottom,
|
|
114
|
+
height: box.height,
|
|
115
|
+
left: box.left,
|
|
116
|
+
top: box.top + top,
|
|
117
|
+
width: box.width
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
var DOMUtils = {
|
|
121
|
+
getBounds
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// src/Math.ts
|
|
125
|
+
function lerp(start, end, time) {
|
|
126
|
+
return start + (end - start) * time;
|
|
127
|
+
}
|
|
128
|
+
function clamp(value, min, max) {
|
|
129
|
+
return Math.min(Math.max(value, min), max);
|
|
130
|
+
}
|
|
131
|
+
function random(min, max) {
|
|
132
|
+
return Math.random() * (max - min) + min;
|
|
133
|
+
}
|
|
134
|
+
function map(value, inMin, inMax, outMin, outMax, clamp2 = false) {
|
|
135
|
+
let mapped = (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
|
136
|
+
if (clamp2) {
|
|
137
|
+
const [minOut, maxOut] = outMin < outMax ? [outMin, outMax] : [outMax, outMin];
|
|
138
|
+
mapped = Math.min(Math.max(mapped, minOut), maxOut);
|
|
139
|
+
}
|
|
140
|
+
return mapped;
|
|
141
|
+
}
|
|
142
|
+
var MathUtils = {
|
|
143
|
+
clamp,
|
|
144
|
+
lerp,
|
|
145
|
+
map,
|
|
146
|
+
random
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// src/Text.ts
|
|
150
|
+
var Text_exports = {};
|
|
151
|
+
__reExport(Text_exports, require("gsap/src/SplitText"));
|
|
152
|
+
|
|
153
|
+
// src/index.ts
|
|
154
|
+
__reExport(index_exports, Text_exports, module.exports);
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
CanvasUtils,
|
|
158
|
+
DOMUtils,
|
|
159
|
+
Detection,
|
|
160
|
+
DetectionManager,
|
|
161
|
+
MathUtils
|
|
162
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * from 'gsap/src/SplitText';
|
|
2
|
+
|
|
3
|
+
declare function trim(canvas: HTMLCanvasElement): HTMLCanvasElement;
|
|
4
|
+
declare const CanvasUtils: {
|
|
5
|
+
trim: typeof trim;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
declare class DetectionManager {
|
|
9
|
+
isMobile(): boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const Detection: DetectionManager;
|
|
12
|
+
|
|
13
|
+
interface DOMRectBounds {
|
|
14
|
+
bottom: number;
|
|
15
|
+
height: number;
|
|
16
|
+
left: number;
|
|
17
|
+
top: number;
|
|
18
|
+
width: number;
|
|
19
|
+
}
|
|
20
|
+
declare function getBounds(element: HTMLElement, top?: number): DOMRectBounds;
|
|
21
|
+
declare const DOMUtils: {
|
|
22
|
+
getBounds: typeof getBounds;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
declare function lerp(start: number, end: number, time: number): number;
|
|
26
|
+
declare function clamp(value: number, min: number, max: number): number;
|
|
27
|
+
declare function random(min: number, max: number): number;
|
|
28
|
+
declare function map(value: number, inMin: number, inMax: number, outMin: number, outMax: number, clamp?: boolean): number;
|
|
29
|
+
declare const MathUtils: {
|
|
30
|
+
clamp: typeof clamp;
|
|
31
|
+
lerp: typeof lerp;
|
|
32
|
+
map: typeof map;
|
|
33
|
+
random: typeof random;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { CanvasUtils, type DOMRectBounds, DOMUtils, Detection, DetectionManager, MathUtils };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * from 'gsap/src/SplitText';
|
|
2
|
+
|
|
3
|
+
declare function trim(canvas: HTMLCanvasElement): HTMLCanvasElement;
|
|
4
|
+
declare const CanvasUtils: {
|
|
5
|
+
trim: typeof trim;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
declare class DetectionManager {
|
|
9
|
+
isMobile(): boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const Detection: DetectionManager;
|
|
12
|
+
|
|
13
|
+
interface DOMRectBounds {
|
|
14
|
+
bottom: number;
|
|
15
|
+
height: number;
|
|
16
|
+
left: number;
|
|
17
|
+
top: number;
|
|
18
|
+
width: number;
|
|
19
|
+
}
|
|
20
|
+
declare function getBounds(element: HTMLElement, top?: number): DOMRectBounds;
|
|
21
|
+
declare const DOMUtils: {
|
|
22
|
+
getBounds: typeof getBounds;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
declare function lerp(start: number, end: number, time: number): number;
|
|
26
|
+
declare function clamp(value: number, min: number, max: number): number;
|
|
27
|
+
declare function random(min: number, max: number): number;
|
|
28
|
+
declare function map(value: number, inMin: number, inMax: number, outMin: number, outMax: number, clamp?: boolean): number;
|
|
29
|
+
declare const MathUtils: {
|
|
30
|
+
clamp: typeof clamp;
|
|
31
|
+
lerp: typeof lerp;
|
|
32
|
+
map: typeof map;
|
|
33
|
+
random: typeof random;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { CanvasUtils, type DOMRectBounds, DOMUtils, Detection, DetectionManager, MathUtils };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * from 'gsap/src/SplitText';
|
|
2
|
+
|
|
3
|
+
declare function trim(canvas: HTMLCanvasElement): HTMLCanvasElement;
|
|
4
|
+
declare const CanvasUtils: {
|
|
5
|
+
trim: typeof trim;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
declare class DetectionManager {
|
|
9
|
+
isMobile(): boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const Detection: DetectionManager;
|
|
12
|
+
|
|
13
|
+
interface DOMRectBounds {
|
|
14
|
+
bottom: number;
|
|
15
|
+
height: number;
|
|
16
|
+
left: number;
|
|
17
|
+
top: number;
|
|
18
|
+
width: number;
|
|
19
|
+
}
|
|
20
|
+
declare function getBounds(element: HTMLElement, top?: number): DOMRectBounds;
|
|
21
|
+
declare const DOMUtils: {
|
|
22
|
+
getBounds: typeof getBounds;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
declare function lerp(start: number, end: number, time: number): number;
|
|
26
|
+
declare function clamp(value: number, min: number, max: number): number;
|
|
27
|
+
declare function random(min: number, max: number): number;
|
|
28
|
+
declare function map(value: number, inMin: number, inMax: number, outMin: number, outMax: number, clamp?: boolean): number;
|
|
29
|
+
declare const MathUtils: {
|
|
30
|
+
clamp: typeof clamp;
|
|
31
|
+
lerp: typeof lerp;
|
|
32
|
+
map: typeof map;
|
|
33
|
+
random: typeof random;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { CanvasUtils, type DOMRectBounds, DOMUtils, Detection, DetectionManager, MathUtils };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
CanvasUtils: () => CanvasUtils,
|
|
23
|
+
DOMUtils: () => DOMUtils,
|
|
24
|
+
Detection: () => Detection,
|
|
25
|
+
DetectionManager: () => DetectionManager,
|
|
26
|
+
MathUtils: () => MathUtils
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// src/Polyfill.ts
|
|
30
|
+
var HTMLElementPrototype = HTMLElement.prototype;
|
|
31
|
+
var NodeListPrototype = NodeList.prototype;
|
|
32
|
+
if (!HTMLElementPrototype.forEach) {
|
|
33
|
+
HTMLElementPrototype.forEach = function(callback, thisArg) {
|
|
34
|
+
thisArg = thisArg || window;
|
|
35
|
+
callback.call(thisArg, this, this, this);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (!NodeListPrototype.filter) {
|
|
39
|
+
NodeListPrototype.filter = Array.prototype.filter;
|
|
40
|
+
}
|
|
41
|
+
if (!NodeListPrototype.find) {
|
|
42
|
+
NodeListPrototype.find = Array.prototype.find;
|
|
43
|
+
}
|
|
44
|
+
if (!NodeListPrototype.map) {
|
|
45
|
+
NodeListPrototype.map = Array.prototype.map;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/Canvas.ts
|
|
49
|
+
function trim(canvas) {
|
|
50
|
+
const context = canvas.getContext("2d");
|
|
51
|
+
const copy = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
|
52
|
+
const pixels = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
53
|
+
const length = pixels.data.length;
|
|
54
|
+
const bound = {
|
|
55
|
+
bottom: null,
|
|
56
|
+
left: null,
|
|
57
|
+
right: null,
|
|
58
|
+
top: null
|
|
59
|
+
};
|
|
60
|
+
let x;
|
|
61
|
+
let y;
|
|
62
|
+
for (let i = 0; i < length; i += 4) {
|
|
63
|
+
if (pixels.data[i + 3] !== 0) {
|
|
64
|
+
x = i / 4 % canvas.width;
|
|
65
|
+
y = ~~(i / 4 / canvas.width);
|
|
66
|
+
if (bound.top === null) {
|
|
67
|
+
bound.top = y;
|
|
68
|
+
}
|
|
69
|
+
if (bound.left === null) {
|
|
70
|
+
bound.left = x;
|
|
71
|
+
} else if (x < bound.left) {
|
|
72
|
+
bound.left = x;
|
|
73
|
+
}
|
|
74
|
+
if (bound.right === null) {
|
|
75
|
+
bound.right = x;
|
|
76
|
+
} else if (bound.right < x) {
|
|
77
|
+
bound.right = x;
|
|
78
|
+
}
|
|
79
|
+
if (bound.bottom === null) {
|
|
80
|
+
bound.bottom = y;
|
|
81
|
+
} else if (bound.bottom < y) {
|
|
82
|
+
bound.bottom = y;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const trimHeight = bound.bottom - bound.top;
|
|
87
|
+
const trimWidth = bound.right - bound.left;
|
|
88
|
+
const trimmed = context.getImageData(bound.left, bound.top, trimWidth, trimHeight);
|
|
89
|
+
copy.canvas.width = trimWidth;
|
|
90
|
+
copy.canvas.height = trimHeight;
|
|
91
|
+
copy.putImageData(trimmed, 0, 0);
|
|
92
|
+
return copy.canvas;
|
|
93
|
+
}
|
|
94
|
+
var CanvasUtils = {
|
|
95
|
+
trim
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/Detection.ts
|
|
99
|
+
var DetectionManager = class {
|
|
100
|
+
isMobile() {
|
|
101
|
+
return !document.documentElement.classList.contains("desktop");
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var Detection = new DetectionManager();
|
|
105
|
+
|
|
106
|
+
// src/DOM.ts
|
|
107
|
+
function getBounds(element, top = 0) {
|
|
108
|
+
const box = element.getBoundingClientRect();
|
|
109
|
+
return {
|
|
110
|
+
bottom: box.bottom,
|
|
111
|
+
height: box.height,
|
|
112
|
+
left: box.left,
|
|
113
|
+
top: box.top + top,
|
|
114
|
+
width: box.width
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
var DOMUtils = {
|
|
118
|
+
getBounds
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/Math.ts
|
|
122
|
+
function lerp(start, end, time) {
|
|
123
|
+
return start + (end - start) * time;
|
|
124
|
+
}
|
|
125
|
+
function clamp(value, min, max) {
|
|
126
|
+
return Math.min(Math.max(value, min), max);
|
|
127
|
+
}
|
|
128
|
+
function random(min, max) {
|
|
129
|
+
return Math.random() * (max - min) + min;
|
|
130
|
+
}
|
|
131
|
+
function map(value, inMin, inMax, outMin, outMax, clamp2 = false) {
|
|
132
|
+
let mapped = (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
|
133
|
+
if (clamp2) {
|
|
134
|
+
const [minOut, maxOut] = outMin < outMax ? [outMin, outMax] : [outMax, outMin];
|
|
135
|
+
mapped = Math.min(Math.max(mapped, minOut), maxOut);
|
|
136
|
+
}
|
|
137
|
+
return mapped;
|
|
138
|
+
}
|
|
139
|
+
var MathUtils = {
|
|
140
|
+
clamp,
|
|
141
|
+
lerp,
|
|
142
|
+
map,
|
|
143
|
+
random
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/Text.ts
|
|
147
|
+
var Text_exports = {};
|
|
148
|
+
__reExport(Text_exports, SplitText_star);
|
|
149
|
+
import * as SplitText_star from "gsap/src/SplitText";
|
|
150
|
+
|
|
151
|
+
// src/index.ts
|
|
152
|
+
__reExport(index_exports, Text_exports);
|
|
153
|
+
export {
|
|
154
|
+
CanvasUtils,
|
|
155
|
+
DOMUtils,
|
|
156
|
+
Detection,
|
|
157
|
+
DetectionManager,
|
|
158
|
+
MathUtils
|
|
159
|
+
};
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
CanvasUtils: () => CanvasUtils,
|
|
23
|
+
DOMUtils: () => DOMUtils,
|
|
24
|
+
Detection: () => Detection,
|
|
25
|
+
DetectionManager: () => DetectionManager,
|
|
26
|
+
MathUtils: () => MathUtils
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// src/Polyfill.ts
|
|
30
|
+
var HTMLElementPrototype = HTMLElement.prototype;
|
|
31
|
+
var NodeListPrototype = NodeList.prototype;
|
|
32
|
+
if (!HTMLElementPrototype.forEach) {
|
|
33
|
+
HTMLElementPrototype.forEach = function(callback, thisArg) {
|
|
34
|
+
thisArg = thisArg || window;
|
|
35
|
+
callback.call(thisArg, this, this, this);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (!NodeListPrototype.filter) {
|
|
39
|
+
NodeListPrototype.filter = Array.prototype.filter;
|
|
40
|
+
}
|
|
41
|
+
if (!NodeListPrototype.find) {
|
|
42
|
+
NodeListPrototype.find = Array.prototype.find;
|
|
43
|
+
}
|
|
44
|
+
if (!NodeListPrototype.map) {
|
|
45
|
+
NodeListPrototype.map = Array.prototype.map;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/Canvas.ts
|
|
49
|
+
function trim(canvas) {
|
|
50
|
+
const context = canvas.getContext("2d");
|
|
51
|
+
const copy = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
|
52
|
+
const pixels = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
53
|
+
const length = pixels.data.length;
|
|
54
|
+
const bound = {
|
|
55
|
+
bottom: null,
|
|
56
|
+
left: null,
|
|
57
|
+
right: null,
|
|
58
|
+
top: null
|
|
59
|
+
};
|
|
60
|
+
let x;
|
|
61
|
+
let y;
|
|
62
|
+
for (let i = 0; i < length; i += 4) {
|
|
63
|
+
if (pixels.data[i + 3] !== 0) {
|
|
64
|
+
x = i / 4 % canvas.width;
|
|
65
|
+
y = ~~(i / 4 / canvas.width);
|
|
66
|
+
if (bound.top === null) {
|
|
67
|
+
bound.top = y;
|
|
68
|
+
}
|
|
69
|
+
if (bound.left === null) {
|
|
70
|
+
bound.left = x;
|
|
71
|
+
} else if (x < bound.left) {
|
|
72
|
+
bound.left = x;
|
|
73
|
+
}
|
|
74
|
+
if (bound.right === null) {
|
|
75
|
+
bound.right = x;
|
|
76
|
+
} else if (bound.right < x) {
|
|
77
|
+
bound.right = x;
|
|
78
|
+
}
|
|
79
|
+
if (bound.bottom === null) {
|
|
80
|
+
bound.bottom = y;
|
|
81
|
+
} else if (bound.bottom < y) {
|
|
82
|
+
bound.bottom = y;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const trimHeight = bound.bottom - bound.top;
|
|
87
|
+
const trimWidth = bound.right - bound.left;
|
|
88
|
+
const trimmed = context.getImageData(bound.left, bound.top, trimWidth, trimHeight);
|
|
89
|
+
copy.canvas.width = trimWidth;
|
|
90
|
+
copy.canvas.height = trimHeight;
|
|
91
|
+
copy.putImageData(trimmed, 0, 0);
|
|
92
|
+
return copy.canvas;
|
|
93
|
+
}
|
|
94
|
+
var CanvasUtils = {
|
|
95
|
+
trim
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/Detection.ts
|
|
99
|
+
var DetectionManager = class {
|
|
100
|
+
isMobile() {
|
|
101
|
+
return !document.documentElement.classList.contains("desktop");
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var Detection = new DetectionManager();
|
|
105
|
+
|
|
106
|
+
// src/DOM.ts
|
|
107
|
+
function getBounds(element, top = 0) {
|
|
108
|
+
const box = element.getBoundingClientRect();
|
|
109
|
+
return {
|
|
110
|
+
bottom: box.bottom,
|
|
111
|
+
height: box.height,
|
|
112
|
+
left: box.left,
|
|
113
|
+
top: box.top + top,
|
|
114
|
+
width: box.width
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
var DOMUtils = {
|
|
118
|
+
getBounds
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/Math.ts
|
|
122
|
+
function lerp(start, end, time) {
|
|
123
|
+
return start + (end - start) * time;
|
|
124
|
+
}
|
|
125
|
+
function clamp(value, min, max) {
|
|
126
|
+
return Math.min(Math.max(value, min), max);
|
|
127
|
+
}
|
|
128
|
+
function random(min, max) {
|
|
129
|
+
return Math.random() * (max - min) + min;
|
|
130
|
+
}
|
|
131
|
+
function map(value, inMin, inMax, outMin, outMax, clamp2 = false) {
|
|
132
|
+
let mapped = (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
|
133
|
+
if (clamp2) {
|
|
134
|
+
const [minOut, maxOut] = outMin < outMax ? [outMin, outMax] : [outMax, outMin];
|
|
135
|
+
mapped = Math.min(Math.max(mapped, minOut), maxOut);
|
|
136
|
+
}
|
|
137
|
+
return mapped;
|
|
138
|
+
}
|
|
139
|
+
var MathUtils = {
|
|
140
|
+
clamp,
|
|
141
|
+
lerp,
|
|
142
|
+
map,
|
|
143
|
+
random
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/Text.ts
|
|
147
|
+
var Text_exports = {};
|
|
148
|
+
__reExport(Text_exports, SplitText_star);
|
|
149
|
+
import * as SplitText_star from "gsap/src/SplitText";
|
|
150
|
+
|
|
151
|
+
// src/index.ts
|
|
152
|
+
__reExport(index_exports, Text_exports);
|
|
153
|
+
export {
|
|
154
|
+
CanvasUtils,
|
|
155
|
+
DOMUtils,
|
|
156
|
+
Detection,
|
|
157
|
+
DetectionManager,
|
|
158
|
+
MathUtils
|
|
159
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lisergia/utilities",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
10
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
|
6
11
|
},
|
|
7
|
-
"main": "./src/index.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"src"
|
|
10
|
-
],
|
|
11
12
|
"dependencies": {
|
|
13
|
+
"@lisergia/config-tsconfig": "2.0.0",
|
|
12
14
|
"gsap": "^3.13.0"
|
|
13
15
|
}
|
|
14
16
|
}
|
package/tsconfig.json
ADDED