aptechka 0.1.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/.prettierignore +16 -0
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +4 -0
- package/.vscode/launch.json +11 -0
- package/.vscode/settings.json +18 -0
- package/README.md +0 -0
- package/index.html +32 -0
- package/package.json +272 -0
- package/public/vite.svg +1 -0
- package/src/packages/animation/Animated.ts +189 -0
- package/src/packages/animation/Damped.ts +39 -0
- package/src/packages/animation/Tweened.ts +51 -0
- package/src/packages/animation/index.ts +10 -0
- package/src/packages/attribute/index.ts +59 -0
- package/src/packages/canvas-2d/index.ts +137 -0
- package/src/packages/controls/Controls.ts +15 -0
- package/src/packages/controls/KeyboardControls.ts +63 -0
- package/src/packages/controls/LinearControls.ts +27 -0
- package/src/packages/controls/User.ts +20 -0
- package/src/packages/controls/WheelControls.ts +92 -0
- package/src/packages/controls/index.ts +5 -0
- package/src/packages/css-unit-parser/index.ts +32 -0
- package/src/packages/custom-element/index.ts +19 -0
- package/src/packages/device/Device.ts +113 -0
- package/src/packages/device/Viewport.ts +67 -0
- package/src/packages/device/index.ts +2 -0
- package/src/packages/element-constructor/ElementConstructor.ts +577 -0
- package/src/packages/element-constructor/htmlTags.ts +679 -0
- package/src/packages/element-constructor/index.ts +4 -0
- package/src/packages/element-constructor/specialObjects.ts +8 -0
- package/src/packages/element-constructor/svgTags.ts +588 -0
- package/src/packages/en3/attachments/En3SourceManager.ts +116 -0
- package/src/packages/en3/core/en3.ts +306 -0
- package/src/packages/en3/index.ts +52 -0
- package/src/packages/en3/instances/en3LazyLoader.ts +22 -0
- package/src/packages/en3/libs/MeshoptDecoder.js +138 -0
- package/src/packages/en3/loaders/en3GLTFLoader.ts +54 -0
- package/src/packages/en3/loaders/en3TextureLoader.ts +3 -0
- package/src/packages/en3/objects/En3Clip.ts +53 -0
- package/src/packages/en3/objects/En3ClipHelpers.ts +12 -0
- package/src/packages/en3/objects/En3GLTF.ts +35 -0
- package/src/packages/en3/objects/En3Image.ts +18 -0
- package/src/packages/en3/objects/En3ImageLike.ts +101 -0
- package/src/packages/en3/objects/En3SourceConsumer.ts +5 -0
- package/src/packages/en3/objects/En3Video.ts +88 -0
- package/src/packages/en3/test/En3HTML.ts +55 -0
- package/src/packages/en3/test/En3ModifiedMaterial.ts +221 -0
- package/src/packages/en3/test/En3Raycaster.ts +187 -0
- package/src/packages/en3/utils/coverTexture.ts +29 -0
- package/src/packages/en3/utils/dispose.ts +27 -0
- package/src/packages/en3/utils/traverseMaterials.ts +10 -0
- package/src/packages/en3/utils/traverseMeshes.ts +9 -0
- package/src/packages/image/index.ts +19 -0
- package/src/packages/intersector/index.ts +83 -0
- package/src/packages/ladder/index.ts +112 -0
- package/src/packages/layout-box/index.ts +417 -0
- package/src/packages/loading/index.ts +131 -0
- package/src/packages/measurer/CumulativeOffsetLeft.ts +8 -0
- package/src/packages/measurer/CumulativeOffsetTop.ts +8 -0
- package/src/packages/measurer/Meaurer.ts +38 -0
- package/src/packages/measurer/index.ts +3 -0
- package/src/packages/media/index.ts +38 -0
- package/src/packages/morph/Link.ts +32 -0
- package/src/packages/morph/Morph.ts +246 -0
- package/src/packages/morph/index.ts +10 -0
- package/src/packages/notifier/index.ts +41 -0
- package/src/packages/order/index.ts +14 -0
- package/src/packages/resizer/index.ts +55 -0
- package/src/packages/router/Link.ts +33 -0
- package/src/packages/router/Route.ts +152 -0
- package/src/packages/router/RouteElement.ts +34 -0
- package/src/packages/router/Router.ts +190 -0
- package/src/packages/router/index.ts +13 -0
- package/src/packages/scroll/ScrollElement.ts +618 -0
- package/src/packages/scroll/ScrollUserElement.ts +21 -0
- package/src/packages/scroll/ScrollbarElement.ts +170 -0
- package/src/packages/scroll/index.ts +2 -0
- package/src/packages/scroll-entries/index.ts +74 -0
- package/src/packages/source/SourceClass.ts +77 -0
- package/src/packages/source/SourceElement.ts +177 -0
- package/src/packages/source/SourceManager.ts +61 -0
- package/src/packages/source/SourceSet.ts +52 -0
- package/src/packages/source/index.ts +8 -0
- package/src/packages/store/Composed.ts +33 -0
- package/src/packages/store/Derived.ts +24 -0
- package/src/packages/store/DerivedArray.ts +36 -0
- package/src/packages/store/Resource.ts +38 -0
- package/src/packages/store/Store.ts +144 -0
- package/src/packages/store/StoreRegistry.ts +105 -0
- package/src/packages/store/index.ts +23 -0
- package/src/packages/ticker/index.ts +173 -0
- package/src/packages/utils/array.ts +3 -0
- package/src/packages/utils/attributes.ts +19 -0
- package/src/packages/utils/browser.ts +2 -0
- package/src/packages/utils/canvas.ts +46 -0
- package/src/packages/utils/collisions.ts +12 -0
- package/src/packages/utils/coordinates.ts +40 -0
- package/src/packages/utils/decoding.ts +11 -0
- package/src/packages/utils/dev.ts +5 -0
- package/src/packages/utils/dom.ts +48 -0
- package/src/packages/utils/easings.ts +69 -0
- package/src/packages/utils/file.ts +17 -0
- package/src/packages/utils/function.ts +29 -0
- package/src/packages/utils/index.ts +61 -0
- package/src/packages/utils/layout.ts +22 -0
- package/src/packages/utils/math.ts +74 -0
- package/src/packages/utils/number.ts +26 -0
- package/src/packages/utils/object.ts +108 -0
- package/src/packages/utils/string.ts +49 -0
- package/src/packages/utils/ts-shape.ts +25 -0
- package/src/packages/utils/ts-utility.ts +47 -0
- package/src/packages/video/index.ts +39 -0
- package/src/playground/index.ts +0 -0
- package/tsconfig.json +31 -0
- package/vite.config.ts +65 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export function findParentElement<T extends typeof Element>(
|
|
2
|
+
element: Element | null,
|
|
3
|
+
Constructor: T
|
|
4
|
+
): T | null {
|
|
5
|
+
if (!element) {
|
|
6
|
+
return null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let parent = element.parentElement as T | null
|
|
10
|
+
|
|
11
|
+
if (!(element.parentElement instanceof Constructor)) {
|
|
12
|
+
parent = findParentElement(element.parentElement, Constructor)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return parent as T
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type ElementOrSelector<T extends HTMLElement = HTMLElement> = string | T
|
|
19
|
+
|
|
20
|
+
export function getElement<T extends HTMLElement>(
|
|
21
|
+
elementOrSelector: ElementOrSelector<T>,
|
|
22
|
+
from = document
|
|
23
|
+
) {
|
|
24
|
+
return typeof elementOrSelector === 'string'
|
|
25
|
+
? from.querySelector<T>(elementOrSelector)
|
|
26
|
+
: elementOrSelector
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function findScrollParentElement(
|
|
30
|
+
node: Node | null,
|
|
31
|
+
_initial: Node | null = null
|
|
32
|
+
): HTMLElement {
|
|
33
|
+
_initial = _initial || node
|
|
34
|
+
|
|
35
|
+
if (!node || !(node instanceof HTMLElement)) {
|
|
36
|
+
return document.body
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (_initial !== node) {
|
|
40
|
+
const computedStyle = getComputedStyle(node)
|
|
41
|
+
|
|
42
|
+
if (computedStyle.overflow.includes('auto') || computedStyle.overflow.includes('scroll')) {
|
|
43
|
+
return node
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return findScrollParentElement(node.parentNode, _initial)
|
|
48
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export type EasingFunction = (t: number) => number
|
|
2
|
+
|
|
3
|
+
export const linear: EasingFunction = (t: number) => {
|
|
4
|
+
return t
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const easeInQuad: EasingFunction = (t: number) => {
|
|
8
|
+
return t * t
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const easeOutQuad: EasingFunction = (t: number) => {
|
|
12
|
+
return t * (2 - t)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const easeInOutQuad: EasingFunction = (t: number) => {
|
|
16
|
+
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const easeInCubic: EasingFunction = (t: number) => {
|
|
20
|
+
return t * t * t
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const easeOutCubic: EasingFunction = (t: number) => {
|
|
24
|
+
return --t * t * t + 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const easeInOutCubic: EasingFunction = (t: number) => {
|
|
28
|
+
return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const easeInQuart: EasingFunction = (t: number) => {
|
|
32
|
+
return t * t * t * t
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const easeOutQuart: EasingFunction = (t: number) => {
|
|
36
|
+
return 1 - --t * t * t * t
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const easeInOutQuart: EasingFunction = (t: number) => {
|
|
40
|
+
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const easeInQuint: EasingFunction = (t: number) => {
|
|
44
|
+
return t * t * t * t * t
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const easeOutQuint: EasingFunction = (t: number) => {
|
|
48
|
+
return 1 + --t * t * t * t * t
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const easeInOutQuint: EasingFunction = (t: number) => {
|
|
52
|
+
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const easeInExpo: EasingFunction = (t: number) => {
|
|
56
|
+
return t === 0 ? 0 : 2 ** (10 * (t - 1))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const easeOutExpo: EasingFunction = (t: number) => {
|
|
60
|
+
return t === 1 ? 1 : 1 - 2 ** (-10 * t)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const easeInOutExpo: EasingFunction = (t: number) => {
|
|
64
|
+
return t === 0 || t === 1
|
|
65
|
+
? t
|
|
66
|
+
: t < 0.5
|
|
67
|
+
? 0.5 * 2 ** (10 * 2 * (t - 0.5))
|
|
68
|
+
: 0.5 * (2 - Math.abs(2 ** (-10 * 2 * (t - 0.5))))
|
|
69
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function createJSONAndSave(filename: string, dataObjToWrite: object) {
|
|
2
|
+
const blob = new Blob([JSON.stringify(dataObjToWrite)], { type: 'application/json' })
|
|
3
|
+
const link = document.createElement('a')
|
|
4
|
+
|
|
5
|
+
link.download = filename + '.json'
|
|
6
|
+
link.href = window.URL.createObjectURL(blob)
|
|
7
|
+
link.dataset.downloadurl = ['application/json', link.download, link.href].join(':')
|
|
8
|
+
|
|
9
|
+
const evt = new MouseEvent('click', {
|
|
10
|
+
view: window,
|
|
11
|
+
bubbles: true,
|
|
12
|
+
cancelable: true,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
link.dispatchEvent(evt)
|
|
16
|
+
link.remove()
|
|
17
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const debounce = <F extends (...args: Parameters<F>) => ReturnType<F>>(
|
|
2
|
+
callback: F,
|
|
3
|
+
delay = 100
|
|
4
|
+
): ((...args: Parameters<F>) => void) => {
|
|
5
|
+
let timeout: ReturnType<typeof setTimeout>
|
|
6
|
+
|
|
7
|
+
return (...args: Parameters<F>): void => {
|
|
8
|
+
clearTimeout(timeout)
|
|
9
|
+
timeout = setTimeout(() => callback(...args), delay)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const throttle = <F extends (...args: Parameters<F>) => ReturnType<F>>(
|
|
14
|
+
callback: F,
|
|
15
|
+
delay = 0
|
|
16
|
+
): ((...args: Parameters<F>) => void) => {
|
|
17
|
+
let wait = false
|
|
18
|
+
|
|
19
|
+
return (...args: Parameters<F>): void => {
|
|
20
|
+
if (!wait) {
|
|
21
|
+
wait = true
|
|
22
|
+
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
callback(...args)
|
|
25
|
+
wait = false
|
|
26
|
+
}, delay)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export { insert } from './array'
|
|
2
|
+
export { parseAttribute, parseAttributeValue } from './attributes'
|
|
3
|
+
export { isBrowser } from './browser'
|
|
4
|
+
export { measureText, fixPosition, cover } from './canvas'
|
|
5
|
+
export { dotRectCollision, dotCircleCollision } from './collisions'
|
|
6
|
+
export { screenToCartesian, normalize, getPointerPosition } from './coordinates'
|
|
7
|
+
export { encode, decode } from './decoding'
|
|
8
|
+
export { resizeInterval } from './dev'
|
|
9
|
+
export {
|
|
10
|
+
findParentElement,
|
|
11
|
+
getElement,
|
|
12
|
+
findScrollParentElement,
|
|
13
|
+
type ElementOrSelector,
|
|
14
|
+
} from './dom'
|
|
15
|
+
export {
|
|
16
|
+
linear,
|
|
17
|
+
easeInQuad,
|
|
18
|
+
easeOutQuad,
|
|
19
|
+
easeInOutQuad,
|
|
20
|
+
easeInCubic,
|
|
21
|
+
easeOutCubic,
|
|
22
|
+
easeInOutCubic,
|
|
23
|
+
easeInQuart,
|
|
24
|
+
easeOutQuart,
|
|
25
|
+
easeInOutQuart,
|
|
26
|
+
easeInQuint,
|
|
27
|
+
easeOutQuint,
|
|
28
|
+
easeInOutQuint,
|
|
29
|
+
easeInExpo,
|
|
30
|
+
easeOutExpo,
|
|
31
|
+
easeInOutExpo,
|
|
32
|
+
type EasingFunction,
|
|
33
|
+
} from './easings'
|
|
34
|
+
export { createJSONAndSave } from './file'
|
|
35
|
+
export { debounce, throttle } from './function'
|
|
36
|
+
export { getCumulativePosition, getCumulativeOffsetLeft, getCumulativeOffsetTop } from './layout'
|
|
37
|
+
export {
|
|
38
|
+
lerp,
|
|
39
|
+
damp,
|
|
40
|
+
step,
|
|
41
|
+
round,
|
|
42
|
+
clamp,
|
|
43
|
+
mapRange,
|
|
44
|
+
smoothstep,
|
|
45
|
+
smootherstep,
|
|
46
|
+
calculateDistance,
|
|
47
|
+
calculateDistanceWithRadius,
|
|
48
|
+
} from './math'
|
|
49
|
+
export { fix, roundTo, generateId } from './number'
|
|
50
|
+
export { isObject, cloneDeep, mergeDeep, isNullish, compareObjects, pick, omit } from './object'
|
|
51
|
+
export { kebabToCamel, camelToKebab, snakeToDotted, toPascalCase, capitalize } from './string'
|
|
52
|
+
export type { Axes2D, Axes3D, Dot2D, Rect2D, Circle, Dot3D, Rect3D } from './ts-shape'
|
|
53
|
+
export type {
|
|
54
|
+
NestedKeys,
|
|
55
|
+
NestedValueOf,
|
|
56
|
+
DeepOmit,
|
|
57
|
+
DeepPartial,
|
|
58
|
+
Requiredish,
|
|
59
|
+
WithRequired,
|
|
60
|
+
Split,
|
|
61
|
+
} from './ts-utility'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const getCumulativePosition = (
|
|
2
|
+
target: HTMLElement,
|
|
3
|
+
from: 'offsetLeft' | 'offsetTop' = 'offsetLeft',
|
|
4
|
+
stopElement?: HTMLElement
|
|
5
|
+
): number => {
|
|
6
|
+
let acc = 0
|
|
7
|
+
|
|
8
|
+
do {
|
|
9
|
+
acc += target[from] || 0
|
|
10
|
+
target = target.offsetParent as HTMLElement
|
|
11
|
+
} while (target && target !== stopElement)
|
|
12
|
+
|
|
13
|
+
return acc
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const getCumulativeOffsetLeft = (target: HTMLElement, stopElement?: HTMLElement) => {
|
|
17
|
+
return getCumulativePosition(target, 'offsetLeft', stopElement)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const getCumulativeOffsetTop = (target: HTMLElement, stopElement?: HTMLElement) => {
|
|
21
|
+
return getCumulativePosition(target, 'offsetTop', stopElement)
|
|
22
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Dot2D } from './ts-shape.js'
|
|
2
|
+
|
|
3
|
+
export function lerp(a: number, b: number, c: number) {
|
|
4
|
+
return (1 - c) * a + c * b
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function damp(a: number, b: number, c: number, dt: number) {
|
|
8
|
+
return lerp(a, b, 1 - Math.exp(-c * dt))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function step(edge: number, value: number, x = 0, y = 1): number {
|
|
12
|
+
return value < edge ? x : y
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function round(number: number, precision: number = 5): number {
|
|
16
|
+
return +number.toFixed(precision)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function clamp(number: number, min: number = 0, max: number = 0) {
|
|
20
|
+
return Math.max(min, Math.min(number, max))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function mapRange(value: number, rangeA: [number, number], rangeB: [number, number]) {
|
|
24
|
+
const ratio = (value - rangeA[0]) / (rangeA[1] - rangeA[0])
|
|
25
|
+
|
|
26
|
+
const mappedValue = ratio * (rangeB[1] - rangeB[0]) + rangeB[0]
|
|
27
|
+
|
|
28
|
+
const clampedValue = clamp(mappedValue, rangeB[0], rangeB[1])
|
|
29
|
+
|
|
30
|
+
return clampedValue
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// https://github.com/mrdoob/three.js/blob/dev/src/math/MathUtils.js#L84
|
|
34
|
+
export function smoothstep(x: number, min: number, max: number) {
|
|
35
|
+
if (x <= min) return 0
|
|
36
|
+
if (x >= max) return 1
|
|
37
|
+
|
|
38
|
+
x = (x - min) / (max - min)
|
|
39
|
+
|
|
40
|
+
return x * x * (3 - 2 * x)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// https://github.com/mrdoob/three.js/blob/dev/src/math/MathUtils.js#L95
|
|
44
|
+
export function smootherstep(x: number, min: number, max: number) {
|
|
45
|
+
if (x <= min) return 0
|
|
46
|
+
if (x >= max) return 1
|
|
47
|
+
|
|
48
|
+
x = (x - min) / (max - min)
|
|
49
|
+
|
|
50
|
+
return x * x * x * (x * (x * 6 - 15) + 10)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function calculateDistance(d1: Dot2D, d2: Dot2D) {
|
|
54
|
+
const xDistance = d2.x - d1.x
|
|
55
|
+
const yDistance = d2.y - d1.y
|
|
56
|
+
|
|
57
|
+
const distance = Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2))
|
|
58
|
+
|
|
59
|
+
return distance
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function calculateDistanceWithRadius(
|
|
63
|
+
x1: number,
|
|
64
|
+
y1: number,
|
|
65
|
+
r1: number,
|
|
66
|
+
x2: number,
|
|
67
|
+
y2: number,
|
|
68
|
+
r2: number,
|
|
69
|
+
) {
|
|
70
|
+
const dx = x2 - x1
|
|
71
|
+
const dy = y2 - y1
|
|
72
|
+
const distance = Math.sqrt(dx * dx + dy * dy) - (r1 + r2)
|
|
73
|
+
return distance
|
|
74
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const precision = [
|
|
2
|
+
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000,
|
|
3
|
+
]
|
|
4
|
+
|
|
5
|
+
export function fix(number: number, n: number = 5): number {
|
|
6
|
+
return ((0.5 + number * precision[n]) << 0) / precision[n]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function roundTo(number: number, to: number) {
|
|
10
|
+
return Math.round(number / to) * to
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function generateId(
|
|
14
|
+
length: number,
|
|
15
|
+
characters = 'abcdefghijklmnopqrstuvwxyz0123456789',
|
|
16
|
+
): string {
|
|
17
|
+
const charactersLength = characters.length
|
|
18
|
+
const key = crypto.getRandomValues(new Uint8Array(length))
|
|
19
|
+
|
|
20
|
+
let generatedKey = ''
|
|
21
|
+
for (let i = 0; i < length; i++) {
|
|
22
|
+
generatedKey += characters.charAt(key[i] % charactersLength)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return generatedKey
|
|
26
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export function isObject(value: any): value is object {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function cloneDeep<T>(obj: T): T {
|
|
6
|
+
if (obj === null || typeof obj !== 'object') {
|
|
7
|
+
return obj
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (obj instanceof Date) {
|
|
11
|
+
return new Date(obj.getTime()) as any
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (obj instanceof Node) {
|
|
15
|
+
return obj
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const clonedObj: any = Array.isArray(obj) ? [] : {}
|
|
19
|
+
|
|
20
|
+
for (const key in obj) {
|
|
21
|
+
if (obj.hasOwnProperty(key)) {
|
|
22
|
+
clonedObj[key] = cloneDeep(obj[key])
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return clonedObj
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function mergeDeep(target: object, source: object, isObjectFunction = isObject): object {
|
|
30
|
+
for (const key in source) {
|
|
31
|
+
if (isObjectFunction((source as any)[key])) {
|
|
32
|
+
if (!(target as any)[key]) Object.assign(target, { [key]: {} })
|
|
33
|
+
mergeDeep((target as any)[key], (source as any)[key], isObjectFunction)
|
|
34
|
+
} else {
|
|
35
|
+
Object.assign(target, { [key]: (source as any)[key] })
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return target
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isNullish(value: any) {
|
|
43
|
+
return value === null || typeof value === 'undefined'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function compareObjects(obj1: any, obj2: any): boolean {
|
|
47
|
+
if (typeof obj1 !== typeof obj2) {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if ([obj1, obj2].some((v) => isNullish(v))) {
|
|
52
|
+
return obj1 === obj2
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Array.isArray(obj1)) {
|
|
56
|
+
const maxArray = (obj1.length > obj2.length ? obj1 : obj2) as Array<any>
|
|
57
|
+
const minArray = (obj1.length > obj2.length ? obj2 : obj1) as Array<any>
|
|
58
|
+
return maxArray.every((item, index) => compareObjects(item, minArray[index]))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
typeof obj1 !== 'object' ||
|
|
63
|
+
obj1 instanceof Node ||
|
|
64
|
+
(typeof obj1 === 'object' && obj1.constructor.toString().startsWith('class'))
|
|
65
|
+
) {
|
|
66
|
+
return obj1 === obj2
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (const key in obj1) {
|
|
70
|
+
if (!obj2.hasOwnProperty(key)) {
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof obj1[key] === 'object' && typeof obj2[key] === 'object') {
|
|
75
|
+
if (!compareObjects(obj1[key], obj2[key])) {
|
|
76
|
+
return false
|
|
77
|
+
}
|
|
78
|
+
} else if (obj1[key] !== obj2[key]) {
|
|
79
|
+
return false
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return true
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function pick<T extends object, R extends keyof T>(object: T, keys: Array<R>): Pick<T, R> {
|
|
87
|
+
const result = {} as Pick<T, R>
|
|
88
|
+
|
|
89
|
+
for (const key in object) {
|
|
90
|
+
if (keys.includes(key as any)) {
|
|
91
|
+
;(result as any)[key] = object[key]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return result
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function omit<T extends object, R extends keyof T>(object: T, keys: Array<R>): Omit<T, R> {
|
|
99
|
+
const result = {} as Omit<T, R>
|
|
100
|
+
|
|
101
|
+
for (const key in object) {
|
|
102
|
+
if (!keys.includes(key as any)) {
|
|
103
|
+
;(result as any)[key] = object[key]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return result
|
|
108
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function kebabToCamel(kebab: string, capitalize = false) {
|
|
2
|
+
let camel = ''
|
|
3
|
+
|
|
4
|
+
kebab.split('-').forEach((part, i) => {
|
|
5
|
+
if (i === 0 && !capitalize) {
|
|
6
|
+
camel += part
|
|
7
|
+
} else {
|
|
8
|
+
const firstLetter = part[0]
|
|
9
|
+
const restLetters = part.slice(1)
|
|
10
|
+
const capitalized = firstLetter.toUpperCase() + restLetters
|
|
11
|
+
|
|
12
|
+
camel += capitalized
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
return camel
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function camelToKebab(camelCaseString: string) {
|
|
20
|
+
return camelCaseString.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function snakeToDotted(snake: string) {
|
|
24
|
+
return snake.split('_').join('.')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function toPascalCase(str: string) {
|
|
28
|
+
if (/^[a-z\d]+$/i.test(str)) {
|
|
29
|
+
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
30
|
+
}
|
|
31
|
+
return str
|
|
32
|
+
.replace(/([a-z\d])([a-z\d]*)/gi, (_, g1, g2) => g1.toUpperCase() + g2.toLowerCase())
|
|
33
|
+
.replace(/[^a-z\d]/gi, '')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function capitalize(string: string, everyWord = false) {
|
|
37
|
+
const cfl = (string: string) => {
|
|
38
|
+
return string.slice(0, 1).toUpperCase() + string.slice(1)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (everyWord) {
|
|
42
|
+
return string
|
|
43
|
+
.split(' ')
|
|
44
|
+
.map((v) => cfl(v))
|
|
45
|
+
.join(' ')
|
|
46
|
+
} else {
|
|
47
|
+
return cfl(string)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type Axes2D = 'x' | 'y'
|
|
2
|
+
|
|
3
|
+
export type Axes3D = Axes2D | 'z'
|
|
4
|
+
|
|
5
|
+
export type Dot2D = {
|
|
6
|
+
x: number
|
|
7
|
+
y: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type Rect2D = Dot2D & {
|
|
11
|
+
width: number
|
|
12
|
+
height: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type Circle = Dot2D & {
|
|
16
|
+
radius: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type Dot3D = Dot2D & {
|
|
20
|
+
z: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type Rect3D = Rect2D & {
|
|
24
|
+
depth: number
|
|
25
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type NestedKeys<T> = T extends Node
|
|
2
|
+
? ''
|
|
3
|
+
: T extends object
|
|
4
|
+
? {
|
|
5
|
+
[K in keyof T]: T[K] extends infer U
|
|
6
|
+
? `${Extract<K, string>}${NestedKeys<U> extends '' ? '' : '.'}${NestedKeys<U>}`
|
|
7
|
+
: never
|
|
8
|
+
}[keyof T]
|
|
9
|
+
: ''
|
|
10
|
+
|
|
11
|
+
export type NestedValueOf<Obj, Key extends string> = Obj extends object
|
|
12
|
+
? Key extends `${infer Parent}.${infer Leaf}`
|
|
13
|
+
? Parent extends keyof Obj
|
|
14
|
+
? NestedValueOf<Obj[Parent], Leaf>
|
|
15
|
+
: never
|
|
16
|
+
: Key extends keyof Obj
|
|
17
|
+
? Obj[Key]
|
|
18
|
+
: never
|
|
19
|
+
: never
|
|
20
|
+
|
|
21
|
+
type Tail<T extends any[]> = ((...t: T) => void) extends (h: any, ...r: infer R) => void ? R : never
|
|
22
|
+
|
|
23
|
+
export type DeepOmit<T, Path extends string[]> = T extends object
|
|
24
|
+
? Path['length'] extends 1
|
|
25
|
+
? Omit<T, Path[0]>
|
|
26
|
+
: {
|
|
27
|
+
[K in keyof T]: K extends Path[0] ? DeepOmit<T[K], Tail<Path>> : T[K]
|
|
28
|
+
}
|
|
29
|
+
: T
|
|
30
|
+
|
|
31
|
+
export type DeepPartial<T> = {
|
|
32
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type Requiredish<T> = {
|
|
36
|
+
[K in keyof Required<T>]: T[K]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }
|
|
40
|
+
|
|
41
|
+
export type Split<S extends string, D extends string> = string extends S
|
|
42
|
+
? string[]
|
|
43
|
+
: S extends ''
|
|
44
|
+
? []
|
|
45
|
+
: S extends `${infer T}${D}${infer U}`
|
|
46
|
+
? [T, ...Split<U, D>]
|
|
47
|
+
: [S]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { define } from '$packages/custom-element'
|
|
2
|
+
import { SourceElement } from '$packages/source'
|
|
3
|
+
|
|
4
|
+
@define('e-video')
|
|
5
|
+
export class VideoElement extends SourceElement<HTMLVideoElement> {
|
|
6
|
+
protected override connectedCallback() {
|
|
7
|
+
super.connectedCallback()
|
|
8
|
+
|
|
9
|
+
this.captureEvent.subscribe(() => {
|
|
10
|
+
if (this.hasAttribute('e-autoplay')) {
|
|
11
|
+
this.consumerElement.play()
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
this.releaseEvent.subscribe(() => {
|
|
16
|
+
if (this.hasAttribute('e-autoplay')) {
|
|
17
|
+
this.consumerElement.pause()
|
|
18
|
+
|
|
19
|
+
if (this.hasAttribute('replay')) {
|
|
20
|
+
this.consumerElement.currentTime = 0
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected override createConsumer() {
|
|
27
|
+
return document.createElement('video')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected override consumeSource(url: string | null) {
|
|
31
|
+
this.consumerElement.src = url || ''
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare global {
|
|
36
|
+
interface HTMLElementTagNameMap {
|
|
37
|
+
'e-video': VideoElement
|
|
38
|
+
}
|
|
39
|
+
}
|
|
File without changes
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
|
|
15
|
+
"strict": true,
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"noFallthroughCasesInSwitch": true,
|
|
19
|
+
"noImplicitOverride": true,
|
|
20
|
+
|
|
21
|
+
"experimentalDecorators": true,
|
|
22
|
+
"allowJs": true,
|
|
23
|
+
|
|
24
|
+
"types": ["vite/client"],
|
|
25
|
+
"baseUrl": "./",
|
|
26
|
+
"paths": {
|
|
27
|
+
"$packages/*": ["src/packages/*"],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
"include": ["src"]
|
|
31
|
+
}
|