@lisergia/utilities 4.0.0 → 6.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/CHANGELOG.md +25 -0
- package/dist/index.cjs +127 -2
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +124 -1
- package/package.json +2 -3
- package/src/Tempus.ts +23 -0
- package/src/index.ts +1 -0
- package/dist/index.d.mts +0 -34
- package/dist/index.mjs +0 -123
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @lisergia/utilities
|
|
2
2
|
|
|
3
|
+
## 6.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Fix Prettier dependency.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @lisergia/config-tsconfig@6.0.0
|
|
13
|
+
|
|
14
|
+
## 5.0.0
|
|
15
|
+
|
|
16
|
+
### Major Changes
|
|
17
|
+
|
|
18
|
+
- - Add Tempus utilities.
|
|
19
|
+
- Remove module type from packages.
|
|
20
|
+
- Add Prettier configuration as dependency.
|
|
21
|
+
- Move Front End and Back End packages to separate repositories.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
- @lisergia/config-tsconfig@5.0.0
|
|
27
|
+
|
|
3
28
|
## 4.0.0
|
|
4
29
|
|
|
5
30
|
### Major Changes
|
package/dist/index.cjs
CHANGED
|
@@ -24,7 +24,9 @@ __export(index_exports, {
|
|
|
24
24
|
DOMUtils: () => DOMUtils,
|
|
25
25
|
Detection: () => Detection,
|
|
26
26
|
DetectionManager: () => DetectionManager,
|
|
27
|
-
MathUtils: () => MathUtils
|
|
27
|
+
MathUtils: () => MathUtils,
|
|
28
|
+
TempusUtils: () => TempusUtils,
|
|
29
|
+
TempusUtilsManager: () => TempusUtilsManager
|
|
28
30
|
});
|
|
29
31
|
module.exports = __toCommonJS(index_exports);
|
|
30
32
|
|
|
@@ -144,11 +146,134 @@ var MathUtils = {
|
|
|
144
146
|
map,
|
|
145
147
|
random
|
|
146
148
|
};
|
|
149
|
+
|
|
150
|
+
// ../../node_modules/tempus/dist/tempus.mjs
|
|
151
|
+
var index = 0;
|
|
152
|
+
function getUID() {
|
|
153
|
+
return index++;
|
|
154
|
+
}
|
|
155
|
+
var isClient = typeof window !== "undefined";
|
|
156
|
+
var originalRAF = isClient && window.requestAnimationFrame;
|
|
157
|
+
var originalCancelRAF = isClient && window.cancelAnimationFrame;
|
|
158
|
+
var Framerate = class {
|
|
159
|
+
callbacks;
|
|
160
|
+
fps;
|
|
161
|
+
time;
|
|
162
|
+
lastTickDate;
|
|
163
|
+
constructor(fps = Number.POSITIVE_INFINITY) {
|
|
164
|
+
this.callbacks = [];
|
|
165
|
+
this.fps = fps;
|
|
166
|
+
this.time = 0;
|
|
167
|
+
this.lastTickDate = performance.now();
|
|
168
|
+
}
|
|
169
|
+
get executionTime() {
|
|
170
|
+
return 1e3 / this.fps;
|
|
171
|
+
}
|
|
172
|
+
dispatch(time, deltaTime) {
|
|
173
|
+
var _a;
|
|
174
|
+
for (let i = 0; i < this.callbacks.length; i++) {
|
|
175
|
+
(_a = this.callbacks[i]) == null ? void 0 : _a.callback(time, deltaTime);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
raf(time, deltaTime) {
|
|
179
|
+
this.time += deltaTime;
|
|
180
|
+
if (this.fps === Number.POSITIVE_INFINITY) {
|
|
181
|
+
this.dispatch(time, deltaTime);
|
|
182
|
+
} else if (this.time >= this.executionTime) {
|
|
183
|
+
this.time = this.time % this.executionTime;
|
|
184
|
+
const deltaTime2 = time - this.lastTickDate;
|
|
185
|
+
this.lastTickDate = time;
|
|
186
|
+
this.dispatch(time, deltaTime2);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
add({ callback, priority }) {
|
|
190
|
+
if (typeof callback !== "function")
|
|
191
|
+
console.error("Tempus.add: callback is not a function");
|
|
192
|
+
const uid = getUID();
|
|
193
|
+
this.callbacks.push({ callback, priority, uid });
|
|
194
|
+
this.callbacks.sort((a, b) => a.priority - b.priority);
|
|
195
|
+
return () => this.remove(uid);
|
|
196
|
+
}
|
|
197
|
+
remove(uid) {
|
|
198
|
+
this.callbacks = this.callbacks.filter(({ uid: u }) => uid !== u);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var TempusImpl = class {
|
|
202
|
+
framerates;
|
|
203
|
+
time;
|
|
204
|
+
constructor() {
|
|
205
|
+
this.framerates = {};
|
|
206
|
+
this.time = isClient ? performance.now() : 0;
|
|
207
|
+
if (!isClient) return;
|
|
208
|
+
requestAnimationFrame(this.raf);
|
|
209
|
+
}
|
|
210
|
+
add(callback, { priority = 0, fps = Number.POSITIVE_INFINITY } = {}) {
|
|
211
|
+
if (!isClient) return;
|
|
212
|
+
if (typeof fps === "number") {
|
|
213
|
+
if (!this.framerates[fps]) this.framerates[fps] = new Framerate(fps);
|
|
214
|
+
return this.framerates[fps].add({ callback, priority });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
raf = (time) => {
|
|
218
|
+
if (!isClient) return;
|
|
219
|
+
requestAnimationFrame(this.raf, true);
|
|
220
|
+
const deltaTime = time - this.time;
|
|
221
|
+
this.time = time;
|
|
222
|
+
for (const framerate of Object.values(this.framerates)) {
|
|
223
|
+
framerate.raf(time, deltaTime);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
patch() {
|
|
227
|
+
if (!isClient) return;
|
|
228
|
+
window.requestAnimationFrame = (callback, { priority = 0, fps = Number.POSITIVE_INFINITY } = {}) => {
|
|
229
|
+
if (callback === this.raf || !callback.toString().includes("requestAnimationFrame(")) {
|
|
230
|
+
return originalRAF(callback);
|
|
231
|
+
}
|
|
232
|
+
if (!callback.__tempusPatched) {
|
|
233
|
+
callback.__tempusPatched = true;
|
|
234
|
+
callback.__tempusUnsubscribe = this.add(callback, { priority, fps });
|
|
235
|
+
}
|
|
236
|
+
return callback.__tempusUnsubscribe;
|
|
237
|
+
};
|
|
238
|
+
window.cancelAnimationFrame = (callback) => {
|
|
239
|
+
if (typeof callback === "function") {
|
|
240
|
+
callback == null ? void 0 : callback();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
return originalCancelRAF(callback);
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
unpatch() {
|
|
247
|
+
if (!isClient) return;
|
|
248
|
+
window.requestAnimationFrame = originalRAF;
|
|
249
|
+
window.cancelAnimationFrame = originalCancelRAF;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
var Tempus = new TempusImpl();
|
|
253
|
+
|
|
254
|
+
// src/Tempus.ts
|
|
255
|
+
var TempusUtilsManager = class {
|
|
256
|
+
cache = /* @__PURE__ */ new Map();
|
|
257
|
+
add(callback, options) {
|
|
258
|
+
const cancel = Tempus.add(callback, options);
|
|
259
|
+
this.cache.set(callback, cancel);
|
|
260
|
+
}
|
|
261
|
+
remove(callback) {
|
|
262
|
+
const cancel = this.cache.get(callback);
|
|
263
|
+
if (cancel) {
|
|
264
|
+
cancel();
|
|
265
|
+
this.cache.delete(callback);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
var TempusUtils = new TempusUtilsManager();
|
|
147
270
|
// Annotate the CommonJS export names for ESM import in node:
|
|
148
271
|
0 && (module.exports = {
|
|
149
272
|
CanvasUtils,
|
|
150
273
|
DOMUtils,
|
|
151
274
|
Detection,
|
|
152
275
|
DetectionManager,
|
|
153
|
-
MathUtils
|
|
276
|
+
MathUtils,
|
|
277
|
+
TempusUtils,
|
|
278
|
+
TempusUtilsManager
|
|
154
279
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TempusCallback, TempusOptions } from 'tempus';
|
|
2
|
+
|
|
1
3
|
declare function trim(canvas: HTMLCanvasElement): HTMLCanvasElement;
|
|
2
4
|
declare const CanvasUtils: {
|
|
3
5
|
trim: typeof trim;
|
|
@@ -31,4 +33,11 @@ declare const MathUtils: {
|
|
|
31
33
|
random: typeof random;
|
|
32
34
|
};
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
declare class TempusUtilsManager {
|
|
37
|
+
cache: Map<any, any>;
|
|
38
|
+
add(callback: TempusCallback, options?: TempusOptions): void;
|
|
39
|
+
remove(callback: TempusCallback): void;
|
|
40
|
+
}
|
|
41
|
+
declare const TempusUtils: TempusUtilsManager;
|
|
42
|
+
|
|
43
|
+
export { CanvasUtils, type DOMRectBounds, DOMUtils, Detection, DetectionManager, MathUtils, TempusUtils, TempusUtilsManager };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TempusCallback, TempusOptions } from 'tempus';
|
|
2
|
+
|
|
1
3
|
declare function trim(canvas: HTMLCanvasElement): HTMLCanvasElement;
|
|
2
4
|
declare const CanvasUtils: {
|
|
3
5
|
trim: typeof trim;
|
|
@@ -31,4 +33,11 @@ declare const MathUtils: {
|
|
|
31
33
|
random: typeof random;
|
|
32
34
|
};
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
declare class TempusUtilsManager {
|
|
37
|
+
cache: Map<any, any>;
|
|
38
|
+
add(callback: TempusCallback, options?: TempusOptions): void;
|
|
39
|
+
remove(callback: TempusCallback): void;
|
|
40
|
+
}
|
|
41
|
+
declare const TempusUtils: TempusUtilsManager;
|
|
42
|
+
|
|
43
|
+
export { CanvasUtils, type DOMRectBounds, DOMUtils, Detection, DetectionManager, MathUtils, TempusUtils, TempusUtilsManager };
|
package/dist/index.js
CHANGED
|
@@ -114,10 +114,133 @@ var MathUtils = {
|
|
|
114
114
|
map,
|
|
115
115
|
random
|
|
116
116
|
};
|
|
117
|
+
|
|
118
|
+
// ../../node_modules/tempus/dist/tempus.mjs
|
|
119
|
+
var index = 0;
|
|
120
|
+
function getUID() {
|
|
121
|
+
return index++;
|
|
122
|
+
}
|
|
123
|
+
var isClient = typeof window !== "undefined";
|
|
124
|
+
var originalRAF = isClient && window.requestAnimationFrame;
|
|
125
|
+
var originalCancelRAF = isClient && window.cancelAnimationFrame;
|
|
126
|
+
var Framerate = class {
|
|
127
|
+
callbacks;
|
|
128
|
+
fps;
|
|
129
|
+
time;
|
|
130
|
+
lastTickDate;
|
|
131
|
+
constructor(fps = Number.POSITIVE_INFINITY) {
|
|
132
|
+
this.callbacks = [];
|
|
133
|
+
this.fps = fps;
|
|
134
|
+
this.time = 0;
|
|
135
|
+
this.lastTickDate = performance.now();
|
|
136
|
+
}
|
|
137
|
+
get executionTime() {
|
|
138
|
+
return 1e3 / this.fps;
|
|
139
|
+
}
|
|
140
|
+
dispatch(time, deltaTime) {
|
|
141
|
+
var _a;
|
|
142
|
+
for (let i = 0; i < this.callbacks.length; i++) {
|
|
143
|
+
(_a = this.callbacks[i]) == null ? void 0 : _a.callback(time, deltaTime);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
raf(time, deltaTime) {
|
|
147
|
+
this.time += deltaTime;
|
|
148
|
+
if (this.fps === Number.POSITIVE_INFINITY) {
|
|
149
|
+
this.dispatch(time, deltaTime);
|
|
150
|
+
} else if (this.time >= this.executionTime) {
|
|
151
|
+
this.time = this.time % this.executionTime;
|
|
152
|
+
const deltaTime2 = time - this.lastTickDate;
|
|
153
|
+
this.lastTickDate = time;
|
|
154
|
+
this.dispatch(time, deltaTime2);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
add({ callback, priority }) {
|
|
158
|
+
if (typeof callback !== "function")
|
|
159
|
+
console.error("Tempus.add: callback is not a function");
|
|
160
|
+
const uid = getUID();
|
|
161
|
+
this.callbacks.push({ callback, priority, uid });
|
|
162
|
+
this.callbacks.sort((a, b) => a.priority - b.priority);
|
|
163
|
+
return () => this.remove(uid);
|
|
164
|
+
}
|
|
165
|
+
remove(uid) {
|
|
166
|
+
this.callbacks = this.callbacks.filter(({ uid: u }) => uid !== u);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var TempusImpl = class {
|
|
170
|
+
framerates;
|
|
171
|
+
time;
|
|
172
|
+
constructor() {
|
|
173
|
+
this.framerates = {};
|
|
174
|
+
this.time = isClient ? performance.now() : 0;
|
|
175
|
+
if (!isClient) return;
|
|
176
|
+
requestAnimationFrame(this.raf);
|
|
177
|
+
}
|
|
178
|
+
add(callback, { priority = 0, fps = Number.POSITIVE_INFINITY } = {}) {
|
|
179
|
+
if (!isClient) return;
|
|
180
|
+
if (typeof fps === "number") {
|
|
181
|
+
if (!this.framerates[fps]) this.framerates[fps] = new Framerate(fps);
|
|
182
|
+
return this.framerates[fps].add({ callback, priority });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
raf = (time) => {
|
|
186
|
+
if (!isClient) return;
|
|
187
|
+
requestAnimationFrame(this.raf, true);
|
|
188
|
+
const deltaTime = time - this.time;
|
|
189
|
+
this.time = time;
|
|
190
|
+
for (const framerate of Object.values(this.framerates)) {
|
|
191
|
+
framerate.raf(time, deltaTime);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
patch() {
|
|
195
|
+
if (!isClient) return;
|
|
196
|
+
window.requestAnimationFrame = (callback, { priority = 0, fps = Number.POSITIVE_INFINITY } = {}) => {
|
|
197
|
+
if (callback === this.raf || !callback.toString().includes("requestAnimationFrame(")) {
|
|
198
|
+
return originalRAF(callback);
|
|
199
|
+
}
|
|
200
|
+
if (!callback.__tempusPatched) {
|
|
201
|
+
callback.__tempusPatched = true;
|
|
202
|
+
callback.__tempusUnsubscribe = this.add(callback, { priority, fps });
|
|
203
|
+
}
|
|
204
|
+
return callback.__tempusUnsubscribe;
|
|
205
|
+
};
|
|
206
|
+
window.cancelAnimationFrame = (callback) => {
|
|
207
|
+
if (typeof callback === "function") {
|
|
208
|
+
callback == null ? void 0 : callback();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
return originalCancelRAF(callback);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
unpatch() {
|
|
215
|
+
if (!isClient) return;
|
|
216
|
+
window.requestAnimationFrame = originalRAF;
|
|
217
|
+
window.cancelAnimationFrame = originalCancelRAF;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
var Tempus = new TempusImpl();
|
|
221
|
+
|
|
222
|
+
// src/Tempus.ts
|
|
223
|
+
var TempusUtilsManager = class {
|
|
224
|
+
cache = /* @__PURE__ */ new Map();
|
|
225
|
+
add(callback, options) {
|
|
226
|
+
const cancel = Tempus.add(callback, options);
|
|
227
|
+
this.cache.set(callback, cancel);
|
|
228
|
+
}
|
|
229
|
+
remove(callback) {
|
|
230
|
+
const cancel = this.cache.get(callback);
|
|
231
|
+
if (cancel) {
|
|
232
|
+
cancel();
|
|
233
|
+
this.cache.delete(callback);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var TempusUtils = new TempusUtilsManager();
|
|
117
238
|
export {
|
|
118
239
|
CanvasUtils,
|
|
119
240
|
DOMUtils,
|
|
120
241
|
Detection,
|
|
121
242
|
DetectionManager,
|
|
122
|
-
MathUtils
|
|
243
|
+
MathUtils,
|
|
244
|
+
TempusUtils,
|
|
245
|
+
TempusUtilsManager
|
|
123
246
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lisergia/utilities",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
|
-
"module": "./dist/index.mjs",
|
|
6
5
|
"types": "./dist/index.d.ts",
|
|
7
6
|
"type": "module",
|
|
8
7
|
"scripts": {
|
|
@@ -10,7 +9,7 @@
|
|
|
10
9
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
|
11
10
|
},
|
|
12
11
|
"dependencies": {
|
|
13
|
-
"@lisergia/config-tsconfig": "
|
|
12
|
+
"@lisergia/config-tsconfig": "6.0.0",
|
|
14
13
|
"gsap": "^3.13.0",
|
|
15
14
|
"tsup": "^8.5.0"
|
|
16
15
|
}
|
package/src/Tempus.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Tempus, { TempusCallback, TempusOptions } from 'tempus'
|
|
2
|
+
|
|
3
|
+
export class TempusUtilsManager {
|
|
4
|
+
cache = new Map()
|
|
5
|
+
|
|
6
|
+
add(callback: TempusCallback, options?: TempusOptions) {
|
|
7
|
+
const cancel = Tempus.add(callback, options)
|
|
8
|
+
|
|
9
|
+
this.cache.set(callback, cancel)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
remove(callback: TempusCallback) {
|
|
13
|
+
const cancel = this.cache.get(callback)
|
|
14
|
+
|
|
15
|
+
if (cancel) {
|
|
16
|
+
cancel()
|
|
17
|
+
|
|
18
|
+
this.cache.delete(callback)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const TempusUtils = new TempusUtilsManager()
|
package/src/index.ts
CHANGED
package/dist/index.d.mts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
declare function trim(canvas: HTMLCanvasElement): HTMLCanvasElement;
|
|
2
|
-
declare const CanvasUtils: {
|
|
3
|
-
trim: typeof trim;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
declare class DetectionManager {
|
|
7
|
-
isMobile(): boolean;
|
|
8
|
-
}
|
|
9
|
-
declare const Detection: DetectionManager;
|
|
10
|
-
|
|
11
|
-
interface DOMRectBounds {
|
|
12
|
-
bottom: number;
|
|
13
|
-
height: number;
|
|
14
|
-
left: number;
|
|
15
|
-
top: number;
|
|
16
|
-
width: number;
|
|
17
|
-
}
|
|
18
|
-
declare function getBounds(element: HTMLElement, top?: number): DOMRectBounds;
|
|
19
|
-
declare const DOMUtils: {
|
|
20
|
-
getBounds: typeof getBounds;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
declare function lerp(start: number, end: number, time: number): number;
|
|
24
|
-
declare function clamp(value: number, min: number, max: number): number;
|
|
25
|
-
declare function random(min: number, max: number): number;
|
|
26
|
-
declare function map(value: number, inMin: number, inMax: number, outMin: number, outMax: number, clamp?: boolean): number;
|
|
27
|
-
declare const MathUtils: {
|
|
28
|
-
clamp: typeof clamp;
|
|
29
|
-
lerp: typeof lerp;
|
|
30
|
-
map: typeof map;
|
|
31
|
-
random: typeof random;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export { CanvasUtils, type DOMRectBounds, DOMUtils, Detection, DetectionManager, MathUtils };
|
package/dist/index.mjs
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// src/Polyfill.ts
|
|
2
|
-
var HTMLElementPrototype = HTMLElement.prototype;
|
|
3
|
-
var NodeListPrototype = NodeList.prototype;
|
|
4
|
-
if (!HTMLElementPrototype.forEach) {
|
|
5
|
-
HTMLElementPrototype.forEach = function(callback, thisArg) {
|
|
6
|
-
thisArg = thisArg || window;
|
|
7
|
-
callback.call(thisArg, this, this, this);
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
if (!NodeListPrototype.filter) {
|
|
11
|
-
NodeListPrototype.filter = Array.prototype.filter;
|
|
12
|
-
}
|
|
13
|
-
if (!NodeListPrototype.find) {
|
|
14
|
-
NodeListPrototype.find = Array.prototype.find;
|
|
15
|
-
}
|
|
16
|
-
if (!NodeListPrototype.map) {
|
|
17
|
-
NodeListPrototype.map = Array.prototype.map;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// src/Canvas.ts
|
|
21
|
-
function trim(canvas) {
|
|
22
|
-
const context = canvas.getContext("2d");
|
|
23
|
-
const copy = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
|
24
|
-
const pixels = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
25
|
-
const length = pixels.data.length;
|
|
26
|
-
const bound = {
|
|
27
|
-
bottom: null,
|
|
28
|
-
left: null,
|
|
29
|
-
right: null,
|
|
30
|
-
top: null
|
|
31
|
-
};
|
|
32
|
-
let x;
|
|
33
|
-
let y;
|
|
34
|
-
for (let i = 0; i < length; i += 4) {
|
|
35
|
-
if (pixels.data[i + 3] !== 0) {
|
|
36
|
-
x = i / 4 % canvas.width;
|
|
37
|
-
y = ~~(i / 4 / canvas.width);
|
|
38
|
-
if (bound.top === null) {
|
|
39
|
-
bound.top = y;
|
|
40
|
-
}
|
|
41
|
-
if (bound.left === null) {
|
|
42
|
-
bound.left = x;
|
|
43
|
-
} else if (x < bound.left) {
|
|
44
|
-
bound.left = x;
|
|
45
|
-
}
|
|
46
|
-
if (bound.right === null) {
|
|
47
|
-
bound.right = x;
|
|
48
|
-
} else if (bound.right < x) {
|
|
49
|
-
bound.right = x;
|
|
50
|
-
}
|
|
51
|
-
if (bound.bottom === null) {
|
|
52
|
-
bound.bottom = y;
|
|
53
|
-
} else if (bound.bottom < y) {
|
|
54
|
-
bound.bottom = y;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const trimHeight = bound.bottom - bound.top;
|
|
59
|
-
const trimWidth = bound.right - bound.left;
|
|
60
|
-
const trimmed = context.getImageData(bound.left, bound.top, trimWidth, trimHeight);
|
|
61
|
-
copy.canvas.width = trimWidth;
|
|
62
|
-
copy.canvas.height = trimHeight;
|
|
63
|
-
copy.putImageData(trimmed, 0, 0);
|
|
64
|
-
return copy.canvas;
|
|
65
|
-
}
|
|
66
|
-
var CanvasUtils = {
|
|
67
|
-
trim
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// src/Detection.ts
|
|
71
|
-
var DetectionManager = class {
|
|
72
|
-
isMobile() {
|
|
73
|
-
return !document.documentElement.classList.contains("desktop");
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var Detection = new DetectionManager();
|
|
77
|
-
|
|
78
|
-
// src/DOM.ts
|
|
79
|
-
function getBounds(element, top = 0) {
|
|
80
|
-
const box = element.getBoundingClientRect();
|
|
81
|
-
return {
|
|
82
|
-
bottom: box.bottom,
|
|
83
|
-
height: box.height,
|
|
84
|
-
left: box.left,
|
|
85
|
-
top: box.top + top,
|
|
86
|
-
width: box.width
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
var DOMUtils = {
|
|
90
|
-
getBounds
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// src/Math.ts
|
|
94
|
-
function lerp(start, end, time) {
|
|
95
|
-
return start + (end - start) * time;
|
|
96
|
-
}
|
|
97
|
-
function clamp(value, min, max) {
|
|
98
|
-
return Math.min(Math.max(value, min), max);
|
|
99
|
-
}
|
|
100
|
-
function random(min, max) {
|
|
101
|
-
return Math.random() * (max - min) + min;
|
|
102
|
-
}
|
|
103
|
-
function map(value, inMin, inMax, outMin, outMax, clamp2 = false) {
|
|
104
|
-
let mapped = (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
|
105
|
-
if (clamp2) {
|
|
106
|
-
const [minOut, maxOut] = outMin < outMax ? [outMin, outMax] : [outMax, outMin];
|
|
107
|
-
mapped = Math.min(Math.max(mapped, minOut), maxOut);
|
|
108
|
-
}
|
|
109
|
-
return mapped;
|
|
110
|
-
}
|
|
111
|
-
var MathUtils = {
|
|
112
|
-
clamp,
|
|
113
|
-
lerp,
|
|
114
|
-
map,
|
|
115
|
-
random
|
|
116
|
-
};
|
|
117
|
-
export {
|
|
118
|
-
CanvasUtils,
|
|
119
|
-
DOMUtils,
|
|
120
|
-
Detection,
|
|
121
|
-
DetectionManager,
|
|
122
|
-
MathUtils
|
|
123
|
-
};
|