aptechka 0.1.1 → 0.1.2

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.
Files changed (296) hide show
  1. package/lib/Damped-1hlKSFaB.cjs +1 -0
  2. package/lib/Damped-523xgzT3.js +152 -0
  3. package/lib/SourceManager-3c3kr7oj.cjs +1 -0
  4. package/lib/SourceManager-F94MRde6.js +108 -0
  5. package/lib/Store-2hWEUGTj.js +135 -0
  6. package/lib/Store-WXFmsaEI.cjs +1 -0
  7. package/lib/WheelControls-F-xg5-oq.js +102 -0
  8. package/lib/WheelControls-Hp5NWRZY.cjs +1 -0
  9. package/lib/animation/Animated.d.ts +41 -0
  10. package/lib/animation/Damped.d.ts +11 -0
  11. package/lib/animation/Tweened.d.ts +16 -0
  12. package/lib/animation/index.cjs +1 -0
  13. package/lib/animation/index.d.ts +3 -0
  14. package/lib/animation/index.js +56 -0
  15. package/lib/attribute/index.cjs +1 -0
  16. package/lib/attribute/index.d.ts +8 -0
  17. package/lib/attribute/index.js +47 -0
  18. package/lib/attributes-_2U65GDl.cjs +1 -0
  19. package/lib/attributes-w0u-KiIb.js +10 -0
  20. package/lib/browser-QbF6EW-w.cjs +1 -0
  21. package/lib/browser-S4eq8AeN.js +4 -0
  22. package/lib/canvas-2d/index.cjs +5 -0
  23. package/lib/canvas-2d/index.d.ts +30 -0
  24. package/lib/canvas-2d/index.js +90 -0
  25. package/lib/controls/Controls.d.ts +9 -0
  26. package/lib/controls/KeyboardControls.d.ts +10 -0
  27. package/lib/controls/LinearControls.d.ts +11 -0
  28. package/lib/controls/User.d.ts +7 -0
  29. package/lib/controls/WheelControls.d.ts +17 -0
  30. package/lib/controls/index.cjs +1 -0
  31. package/lib/controls/index.d.ts +5 -0
  32. package/lib/controls/index.js +43 -0
  33. package/lib/css-unit-parser/index.cjs +8 -0
  34. package/lib/css-unit-parser/index.d.ts +6 -0
  35. package/lib/css-unit-parser/index.js +36 -0
  36. package/lib/custom-element/index.cjs +1 -0
  37. package/lib/custom-element/index.d.ts +8 -0
  38. package/lib/custom-element/index.js +16 -0
  39. package/lib/device/Device.d.ts +17 -0
  40. package/lib/device/Viewport.d.ts +27 -0
  41. package/lib/device/index.cjs +1 -0
  42. package/lib/device/index.d.ts +2 -0
  43. package/lib/device/index.js +123 -0
  44. package/lib/dom-QhWsdQS2.cjs +1 -0
  45. package/lib/dom-bHEwc_xV.js +24 -0
  46. package/lib/easings-_wFs9ZWc.cjs +1 -0
  47. package/lib/easings-uF-tgahf.js +19 -0
  48. package/lib/element-constructor/ElementConstructor.d.ts +76 -0
  49. package/lib/element-constructor/htmlTags.d.ts +113 -0
  50. package/lib/element-constructor/index.cjs +1 -0
  51. package/lib/element-constructor/index.d.ts +4 -0
  52. package/lib/element-constructor/index.js +1389 -0
  53. package/lib/element-constructor/specialObjects.d.ts +2 -0
  54. package/lib/element-constructor/svgTags.d.ts +64 -0
  55. package/lib/en3/attachments/En3SourceManager.d.ts +30 -0
  56. package/lib/en3/core/en3.d.ts +55 -0
  57. package/lib/en3/index.cjs +28 -0
  58. package/lib/en3/index.d.ts +18 -0
  59. package/lib/en3/index.js +3249 -0
  60. package/lib/en3/instances/en3LazyLoader.d.ts +7 -0
  61. package/lib/en3/libs/MeshoptDecoder.d.ts +1 -0
  62. package/lib/en3/loaders/en3GLTFLoader.d.ts +16 -0
  63. package/lib/en3/loaders/en3TextureLoader.d.ts +2 -0
  64. package/lib/en3/objects/En3Clip.d.ts +10 -0
  65. package/lib/en3/objects/En3ClipHelpers.d.ts +5 -0
  66. package/lib/en3/objects/En3GLTF.d.ts +9 -0
  67. package/lib/en3/objects/En3Image.d.ts +7 -0
  68. package/lib/en3/objects/En3ImageLike.d.ts +22 -0
  69. package/{src/packages/en3/objects/En3SourceConsumer.ts → lib/en3/objects/En3SourceConsumer.d.ts} +2 -3
  70. package/lib/en3/objects/En3Video.d.ts +12 -0
  71. package/lib/en3/test/En3HTML.d.ts +9 -0
  72. package/lib/en3/test/En3ModifiedMaterial.d.ts +32 -0
  73. package/lib/en3/test/En3Raycaster.d.ts +19 -0
  74. package/lib/en3/utils/coverTexture.d.ts +6 -0
  75. package/lib/en3/utils/dispose.d.ts +2 -0
  76. package/lib/en3/utils/traverseMaterials.d.ts +2 -0
  77. package/lib/en3/utils/traverseMeshes.d.ts +2 -0
  78. package/lib/function-QP7IreXR.cjs +1 -0
  79. package/lib/function-zwSFehNd.js +17 -0
  80. package/lib/image/index.cjs +1 -0
  81. package/lib/image/index.d.ts +10 -0
  82. package/lib/image/index.js +30 -0
  83. package/lib/intersector/index.cjs +1 -0
  84. package/lib/intersector/index.d.ts +8 -0
  85. package/lib/intersector/index.js +55 -0
  86. package/lib/ladder/index.cjs +1 -0
  87. package/lib/ladder/index.d.ts +21 -0
  88. package/lib/ladder/index.js +97 -0
  89. package/lib/layout-5SJlcXTY.js +12 -0
  90. package/lib/layout-box/index.cjs +1 -0
  91. package/lib/layout-box/index.d.ts +78 -0
  92. package/lib/layout-box/index.js +235 -0
  93. package/lib/layout-rZzbsLPd.cjs +1 -0
  94. package/lib/loading/index.cjs +1 -0
  95. package/lib/loading/index.d.ts +38 -0
  96. package/lib/loading/index.js +99 -0
  97. package/lib/math-FNUBmQPK.cjs +1 -0
  98. package/lib/math-_a3IpKOc.js +45 -0
  99. package/lib/measurer/CumulativeOffsetLeft.d.ts +4 -0
  100. package/lib/measurer/CumulativeOffsetTop.d.ts +4 -0
  101. package/lib/measurer/Meaurer.d.ts +8 -0
  102. package/lib/measurer/index.cjs +1 -0
  103. package/lib/measurer/index.d.ts +3 -0
  104. package/lib/measurer/index.js +48 -0
  105. package/lib/media/index.cjs +1 -0
  106. package/lib/media/index.d.ts +11 -0
  107. package/lib/media/index.js +33 -0
  108. package/lib/morph/Link.d.ts +6 -0
  109. package/lib/morph/Morph.d.ts +26 -0
  110. package/lib/morph/index.cjs +1 -0
  111. package/lib/morph/index.d.ts +1 -0
  112. package/lib/morph/index.js +182 -0
  113. package/lib/notifier/index.cjs +1 -0
  114. package/lib/notifier/index.d.ts +8 -0
  115. package/lib/notifier/index.js +38 -0
  116. package/lib/number-2bR0KBcX.cjs +1 -0
  117. package/lib/number-bCHB2GAD.js +31 -0
  118. package/lib/order/index.cjs +1 -0
  119. package/lib/order/index.d.ts +13 -0
  120. package/lib/order/index.js +5 -0
  121. package/lib/resizer/index.cjs +1 -0
  122. package/lib/resizer/index.d.ts +10 -0
  123. package/lib/resizer/index.js +45 -0
  124. package/lib/router/Link.d.ts +6 -0
  125. package/lib/router/Route.d.ts +15 -0
  126. package/lib/router/RouteElement.d.ts +14 -0
  127. package/lib/router/Router.d.ts +33 -0
  128. package/lib/router/index.cjs +1 -0
  129. package/lib/router/index.d.ts +3 -0
  130. package/lib/router/index.js +266 -0
  131. package/lib/scroll/ScrollElement.d.ts +40 -0
  132. package/lib/scroll/ScrollUserElement.d.ts +7 -0
  133. package/lib/scroll/ScrollbarElement.d.ts +13 -0
  134. package/lib/scroll/index.cjs +71 -0
  135. package/lib/scroll/index.d.ts +2 -0
  136. package/lib/scroll/index.js +444 -0
  137. package/lib/scroll-entries/index.cjs +1 -0
  138. package/lib/scroll-entries/index.d.ts +17 -0
  139. package/lib/scroll-entries/index.js +56 -0
  140. package/lib/source/SourceClass.d.ts +11 -0
  141. package/lib/source/SourceElement.d.ts +16 -0
  142. package/lib/source/SourceManager.d.ts +13 -0
  143. package/lib/source/SourceSet.d.ts +8 -0
  144. package/lib/source/index.cjs +5 -0
  145. package/lib/source/index.d.ts +4 -0
  146. package/lib/source/index.js +95 -0
  147. package/lib/store/Composed.d.ts +7 -0
  148. package/lib/store/Derived.d.ts +7 -0
  149. package/lib/store/DerivedArray.d.ts +7 -0
  150. package/lib/store/Resource.d.ts +11 -0
  151. package/lib/store/Store.d.ts +32 -0
  152. package/lib/store/StoreRegistry.d.ts +22 -0
  153. package/lib/store/index.cjs +1 -0
  154. package/lib/store/index.d.ts +6 -0
  155. package/lib/store/index.js +96 -0
  156. package/lib/string-GmxZA5Nq.js +31 -0
  157. package/lib/string-WmNOGq16.cjs +1 -0
  158. package/lib/ticker/index.cjs +1 -0
  159. package/lib/ticker/index.d.ts +19 -0
  160. package/lib/ticker/index.js +107 -0
  161. package/lib/utils/array.d.ts +1 -0
  162. package/lib/utils/attributes.d.ts +2 -0
  163. package/lib/utils/browser.d.ts +1 -0
  164. package/lib/utils/canvas.d.ts +6 -0
  165. package/lib/utils/collisions.d.ts +3 -0
  166. package/lib/utils/coordinates.d.ts +13 -0
  167. package/lib/utils/decoding.d.ts +2 -0
  168. package/lib/utils/dev.d.ts +3 -0
  169. package/lib/utils/dom.d.ts +4 -0
  170. package/lib/utils/easings.d.ts +17 -0
  171. package/lib/utils/file.d.ts +1 -0
  172. package/lib/utils/function.d.ts +2 -0
  173. package/lib/utils/index.cjs +1 -0
  174. package/lib/utils/index.d.ts +19 -0
  175. package/lib/utils/index.js +203 -0
  176. package/lib/utils/layout.d.ts +3 -0
  177. package/lib/utils/math.d.ts +11 -0
  178. package/lib/utils/number.d.ts +3 -0
  179. package/lib/utils/object.d.ts +7 -0
  180. package/lib/utils/string.d.ts +5 -0
  181. package/lib/utils/ts-shape.d.ts +19 -0
  182. package/lib/utils/ts-utility.d.ts +19 -0
  183. package/lib/video/index.cjs +1 -0
  184. package/lib/video/index.d.ts +11 -0
  185. package/lib/video/index.js +37 -0
  186. package/package.json +6 -5
  187. package/.github/workflows/publish.yml +0 -20
  188. package/.prettierignore +0 -16
  189. package/.prettierrc +0 -9
  190. package/index.html +0 -32
  191. package/public/vite.svg +0 -1
  192. package/src/packages/animation/Animated.ts +0 -189
  193. package/src/packages/animation/Damped.ts +0 -39
  194. package/src/packages/animation/Tweened.ts +0 -51
  195. package/src/packages/animation/index.ts +0 -10
  196. package/src/packages/attribute/index.ts +0 -59
  197. package/src/packages/canvas-2d/index.ts +0 -137
  198. package/src/packages/controls/Controls.ts +0 -15
  199. package/src/packages/controls/KeyboardControls.ts +0 -63
  200. package/src/packages/controls/LinearControls.ts +0 -27
  201. package/src/packages/controls/User.ts +0 -20
  202. package/src/packages/controls/WheelControls.ts +0 -92
  203. package/src/packages/controls/index.ts +0 -5
  204. package/src/packages/css-unit-parser/index.ts +0 -32
  205. package/src/packages/custom-element/index.ts +0 -19
  206. package/src/packages/device/Device.ts +0 -113
  207. package/src/packages/device/Viewport.ts +0 -67
  208. package/src/packages/device/index.ts +0 -2
  209. package/src/packages/element-constructor/ElementConstructor.ts +0 -577
  210. package/src/packages/element-constructor/htmlTags.ts +0 -679
  211. package/src/packages/element-constructor/index.ts +0 -4
  212. package/src/packages/element-constructor/specialObjects.ts +0 -8
  213. package/src/packages/element-constructor/svgTags.ts +0 -588
  214. package/src/packages/en3/attachments/En3SourceManager.ts +0 -116
  215. package/src/packages/en3/core/en3.ts +0 -306
  216. package/src/packages/en3/index.ts +0 -52
  217. package/src/packages/en3/instances/en3LazyLoader.ts +0 -22
  218. package/src/packages/en3/libs/MeshoptDecoder.js +0 -138
  219. package/src/packages/en3/loaders/en3GLTFLoader.ts +0 -54
  220. package/src/packages/en3/loaders/en3TextureLoader.ts +0 -3
  221. package/src/packages/en3/objects/En3Clip.ts +0 -53
  222. package/src/packages/en3/objects/En3ClipHelpers.ts +0 -12
  223. package/src/packages/en3/objects/En3GLTF.ts +0 -35
  224. package/src/packages/en3/objects/En3Image.ts +0 -18
  225. package/src/packages/en3/objects/En3ImageLike.ts +0 -101
  226. package/src/packages/en3/objects/En3Video.ts +0 -88
  227. package/src/packages/en3/test/En3HTML.ts +0 -55
  228. package/src/packages/en3/test/En3ModifiedMaterial.ts +0 -221
  229. package/src/packages/en3/test/En3Raycaster.ts +0 -187
  230. package/src/packages/en3/utils/coverTexture.ts +0 -29
  231. package/src/packages/en3/utils/dispose.ts +0 -27
  232. package/src/packages/en3/utils/traverseMaterials.ts +0 -10
  233. package/src/packages/en3/utils/traverseMeshes.ts +0 -9
  234. package/src/packages/image/index.ts +0 -19
  235. package/src/packages/intersector/index.ts +0 -83
  236. package/src/packages/ladder/index.ts +0 -112
  237. package/src/packages/layout-box/index.ts +0 -417
  238. package/src/packages/loading/index.ts +0 -131
  239. package/src/packages/measurer/CumulativeOffsetLeft.ts +0 -8
  240. package/src/packages/measurer/CumulativeOffsetTop.ts +0 -8
  241. package/src/packages/measurer/Meaurer.ts +0 -38
  242. package/src/packages/measurer/index.ts +0 -3
  243. package/src/packages/media/index.ts +0 -38
  244. package/src/packages/morph/Link.ts +0 -32
  245. package/src/packages/morph/Morph.ts +0 -246
  246. package/src/packages/morph/index.ts +0 -10
  247. package/src/packages/notifier/index.ts +0 -41
  248. package/src/packages/order/index.ts +0 -14
  249. package/src/packages/resizer/index.ts +0 -55
  250. package/src/packages/router/Link.ts +0 -33
  251. package/src/packages/router/Route.ts +0 -152
  252. package/src/packages/router/RouteElement.ts +0 -34
  253. package/src/packages/router/Router.ts +0 -190
  254. package/src/packages/router/index.ts +0 -13
  255. package/src/packages/scroll/ScrollElement.ts +0 -618
  256. package/src/packages/scroll/ScrollUserElement.ts +0 -21
  257. package/src/packages/scroll/ScrollbarElement.ts +0 -170
  258. package/src/packages/scroll/index.ts +0 -2
  259. package/src/packages/scroll-entries/index.ts +0 -74
  260. package/src/packages/source/SourceClass.ts +0 -77
  261. package/src/packages/source/SourceElement.ts +0 -177
  262. package/src/packages/source/SourceManager.ts +0 -61
  263. package/src/packages/source/SourceSet.ts +0 -52
  264. package/src/packages/source/index.ts +0 -8
  265. package/src/packages/store/Composed.ts +0 -33
  266. package/src/packages/store/Derived.ts +0 -24
  267. package/src/packages/store/DerivedArray.ts +0 -36
  268. package/src/packages/store/Resource.ts +0 -38
  269. package/src/packages/store/Store.ts +0 -144
  270. package/src/packages/store/StoreRegistry.ts +0 -105
  271. package/src/packages/store/index.ts +0 -23
  272. package/src/packages/ticker/index.ts +0 -173
  273. package/src/packages/utils/array.ts +0 -3
  274. package/src/packages/utils/attributes.ts +0 -19
  275. package/src/packages/utils/browser.ts +0 -2
  276. package/src/packages/utils/canvas.ts +0 -46
  277. package/src/packages/utils/collisions.ts +0 -12
  278. package/src/packages/utils/coordinates.ts +0 -40
  279. package/src/packages/utils/decoding.ts +0 -11
  280. package/src/packages/utils/dev.ts +0 -5
  281. package/src/packages/utils/dom.ts +0 -48
  282. package/src/packages/utils/easings.ts +0 -69
  283. package/src/packages/utils/file.ts +0 -17
  284. package/src/packages/utils/function.ts +0 -29
  285. package/src/packages/utils/index.ts +0 -61
  286. package/src/packages/utils/layout.ts +0 -22
  287. package/src/packages/utils/math.ts +0 -74
  288. package/src/packages/utils/number.ts +0 -26
  289. package/src/packages/utils/object.ts +0 -108
  290. package/src/packages/utils/string.ts +0 -49
  291. package/src/packages/utils/ts-shape.ts +0 -25
  292. package/src/packages/utils/ts-utility.ts +0 -47
  293. package/src/packages/video/index.ts +0 -39
  294. package/src/playground/index.ts +0 -0
  295. package/tsconfig.json +0 -31
  296. package/vite.config.ts +0 -78
@@ -1,39 +0,0 @@
1
- import { TickerCallbackEntry } from '$packages/ticker'
2
- import { damp, fix } from '$packages/utils'
3
- import { AnimatedOptions, Animated } from './Animated'
4
-
5
- export interface DampedOptions extends AnimatedOptions {
6
- damping?: number
7
- }
8
-
9
- export class Damped extends Animated {
10
- public damping: number
11
-
12
- constructor(options?: DampedOptions) {
13
- super({
14
- ...options,
15
- min: options?.min ?? -Infinity,
16
- max: options?.max ?? Infinity,
17
- })
18
-
19
- this.damping = options?.damping || 0
20
- }
21
-
22
- protected update() {
23
- if (this.damping) {
24
- this.listenAnimationFrame()
25
- } else {
26
- this.current = this.target
27
- this.unlistenAnimationFrame()
28
- }
29
- }
30
-
31
- protected handleAnimationFrame(e: TickerCallbackEntry) {
32
- if (fix(this.current, 4) === fix(this.target, 4)) {
33
- this.unlistenAnimationFrame()
34
- this.current = this.target
35
- }
36
-
37
- this.current = damp(this.current, this.target, this.damping, e.elapsed)
38
- }
39
- }
@@ -1,51 +0,0 @@
1
- import { TickerCallbackEntry } from '$packages/ticker'
2
- import { EasingFunction, linear } from '$packages/utils'
3
- import { AnimatedOptions, Animated } from './Animated'
4
-
5
- export interface TweenedOptions extends AnimatedOptions {
6
- easing?: EasingFunction
7
- }
8
-
9
- export class Tweened extends Animated {
10
- public easing: EasingFunction
11
-
12
- constructor(options?: TweenedOptions) {
13
- super({
14
- ...options,
15
- min: options?.min || 0,
16
- max: options?.max || 1000,
17
- })
18
-
19
- this.easing = options?.easing || linear
20
- }
21
-
22
- public start() {
23
- this.listenAnimationFrame()
24
- }
25
-
26
- public pause() {
27
- this.unlistenAnimationFrame()
28
- }
29
-
30
- public stop() {
31
- this.reset()
32
- }
33
-
34
- public override get max() {
35
- return super.max
36
- }
37
-
38
- protected update() {
39
- const normalized = (this.target - this.min) / (this.delta || 1)
40
- const eased = this.easing(normalized)
41
- this.current = this.min + eased * this.delta
42
- }
43
-
44
- protected handleAnimationFrame(e: TickerCallbackEntry) {
45
- this.shift(e.elapsed)
46
-
47
- if ((e.elapsed && this.current === 0) || this.current === this.delta) {
48
- this.unlistenAnimationFrame()
49
- }
50
- }
51
- }
@@ -1,10 +0,0 @@
1
- export {
2
- Animated,
3
- type AnimatedOptions,
4
- type AnimatedEdgeFunction,
5
- type AnimatedEntry,
6
- } from './Animated'
7
-
8
- export { Tweened, type TweenedOptions } from './Tweened'
9
-
10
- export { Damped, type DampedOptions } from './Damped'
@@ -1,59 +0,0 @@
1
- import { Store, StoreOptions } from '$packages/store'
2
- import { ElementOrSelector, isBrowser, getElement, parseAttributeValue } from '$packages/utils'
3
-
4
- export class Attribute<T extends string | number | boolean> extends Store<T> {
5
- #element: HTMLElement | null = null
6
- #name: string
7
- #mutationObserver: MutationObserver = null!
8
-
9
- constructor(
10
- elementOrSelector: ElementOrSelector,
11
- name: string,
12
- defaultValue: T,
13
- options?: StoreOptions<T>
14
- ) {
15
- super(defaultValue, options)
16
-
17
- this.#name = name
18
-
19
- this.subscribe((e) => {
20
- this.#element?.setAttribute(this.#name, e.current.toString())
21
- })
22
-
23
- if (isBrowser) {
24
- this.#element = getElement(elementOrSelector)!
25
-
26
- this.#mutationObserver = new MutationObserver((mutations) => {
27
- mutations.forEach((mutation) => {
28
- if (mutation.type === 'attributes' && mutation.attributeName === this.#name) {
29
- this.#tryUpdate()
30
- }
31
- })
32
- })
33
- }
34
- }
35
-
36
- public unobserve() {
37
- if (isBrowser) {
38
- this.#mutationObserver.disconnect()
39
- }
40
- }
41
-
42
- public observe() {
43
- if (isBrowser && this.#element) {
44
- this.#mutationObserver.observe(this.#element, {
45
- attributes: true,
46
- })
47
-
48
- this.#tryUpdate()
49
- }
50
- }
51
-
52
- #tryUpdate() {
53
- const value = this.#element!.getAttribute(this.#name)
54
-
55
- if (value != undefined) {
56
- this.current = parseAttributeValue(value) as T
57
- }
58
- }
59
- }
@@ -1,137 +0,0 @@
1
- import { define, CustomElement } from '$packages/custom-element'
2
- import { Notifier } from '$packages/notifier'
3
- import { resizer } from '$packages/resizer'
4
- import { ticker, TickerCallback } from '$packages/ticker'
5
- import { clamp } from '$packages/utils'
6
-
7
- export interface Canvas2DRenderDetail {
8
- pixelRatio: number
9
- width: number
10
- height: number
11
- element: HTMLElement
12
- canvasElement: HTMLElement
13
- context: CanvasRenderingContext2D
14
- timestamp: number
15
- elapsed: number
16
- }
17
-
18
- export type Canvas2DRenderCallback = (detail: Canvas2DRenderDetail) => void
19
-
20
- @define('canvas-2d')
21
- export class Canvas2DElement extends CustomElement {
22
- #renderEvent = new Notifier<Canvas2DRenderCallback>()
23
-
24
- #canvasElement: HTMLCanvasElement = null!
25
- #context: CanvasRenderingContext2D = null!
26
-
27
- #width = 0
28
- #height = 0
29
- #pixelRatio = 1
30
-
31
- #timestamp = 0
32
- #elapsed = 1
33
-
34
- public get renderEvent() {
35
- return this.#renderEvent
36
- }
37
-
38
- public get canvasElement() {
39
- return this.#canvasElement
40
- }
41
-
42
- public get context() {
43
- return this.#context
44
- }
45
-
46
- public get pixelRatio() {
47
- return this.#pixelRatio
48
- }
49
-
50
- public get width() {
51
- return this.#width
52
- }
53
-
54
- public get height() {
55
- return this.#height
56
- }
57
-
58
- public get detail(): Canvas2DRenderDetail {
59
- return {
60
- width: this.#width,
61
- height: this.#height,
62
- element: this,
63
- canvasElement: this.#canvasElement,
64
- pixelRatio: this.#pixelRatio,
65
- context: this.#context,
66
- timestamp: this.#timestamp,
67
- elapsed: this.#elapsed,
68
- }
69
- }
70
-
71
- protected connectedCallback() {
72
- this.style.display = 'block'
73
- this.style.width = '100%'
74
- this.style.height = '100%'
75
-
76
- this.#canvasElement = document.createElement('canvas')
77
-
78
- this.#canvasElement.style.cssText = `
79
- display: block;
80
- width: 100%;
81
- height: 100%;
82
- `
83
-
84
- this.#context = this.#canvasElement.getContext('2d')!
85
-
86
- this.appendChild(this.#canvasElement)
87
-
88
- resizer.subscribe(this.#resizeListener)
89
-
90
- if (!this.hasAttribute('static')) {
91
- ticker.subscribe(this.#tickListener, {
92
- culling: this,
93
- maxFPS: this.hasAttribute('fps') ? parseInt(this.getAttribute('fps')!) : undefined,
94
- })
95
- }
96
- }
97
-
98
- protected disconnectedCallback() {
99
- resizer.unsubscribe(this.#resizeListener)
100
- ticker.unsubscribe(this.#tickListener)
101
-
102
- this.#renderEvent.close()
103
- this.#canvasElement.remove()
104
- this.style.display = ''
105
- this.style.width = ''
106
- this.style.height = ''
107
- }
108
-
109
- #resizeListener = () => {
110
- this.#pixelRatio = clamp(devicePixelRatio, 1, 2)
111
-
112
- const rect = this.getBoundingClientRect()
113
-
114
- this.#width = rect.width
115
- this.#height = rect.height
116
-
117
- this.#canvasElement.width = this.#width * this.pixelRatio
118
- this.#canvasElement.height = this.#height * this.pixelRatio
119
-
120
- this.context.scale(this.pixelRatio, this.pixelRatio)
121
-
122
- this.renderEvent.notify(this.detail)
123
- }
124
-
125
- #tickListener: TickerCallback = (e) => {
126
- this.#timestamp = e.timestamp
127
- this.#elapsed = e.elapsed
128
-
129
- this.#renderEvent.notify(this.detail)
130
- }
131
- }
132
-
133
- declare global {
134
- interface HTMLElementTagNameMap {
135
- 'canvas-2d': Canvas2DElement
136
- }
137
- }
@@ -1,15 +0,0 @@
1
- import { Notifier } from '$packages/notifier'
2
-
3
- export type ControlsValue = number | 'max' | 'min'
4
- export type ControlsCallback = (value: ControlsValue) => void
5
-
6
- export abstract class Controls {
7
- #changeEvent = new Notifier<ControlsCallback>()
8
-
9
- public get changeEvent() {
10
- return this.#changeEvent
11
- }
12
-
13
- public abstract connect(): void
14
- public abstract disconnect(): void
15
- }
@@ -1,63 +0,0 @@
1
- import { isBrowser, getElement } from '$packages/utils'
2
- import { Controls } from './Controls'
3
- import { user } from './User'
4
-
5
- export interface KeyboardControlsOptions {
6
- element?: HTMLElement
7
- }
8
-
9
- export class KeyboardControls extends Controls {
10
- #element: HTMLElement | Window = null!
11
-
12
- constructor(options?: KeyboardControlsOptions) {
13
- super()
14
-
15
- if (isBrowser) {
16
- this.#element = options?.element ? getElement(options.element) || window : window
17
- }
18
- }
19
-
20
- public connect() {
21
- if (isBrowser) {
22
- this.#element.addEventListener('keydown', this.#keydownListener as EventListener)
23
- }
24
- }
25
-
26
- public disconnect() {
27
- if (isBrowser) {
28
- this.#element.removeEventListener('keydown', this.#keydownListener as EventListener)
29
- }
30
- }
31
-
32
- #keydownListener = (e: KeyboardEvent) => {
33
- const dir = e.shiftKey ? -1 : 1
34
-
35
- let interaction = true
36
-
37
- if (e.code === 'Space') {
38
- this.changeEvent.notify(dir * 500)
39
- } else if (e.code === 'ArrowLeft') {
40
- this.changeEvent.notify(-1 * 100)
41
- } else if (e.code === 'ArrowRight') {
42
- this.changeEvent.notify(1 * 100)
43
- } else if (e.code === 'ArrowUp') {
44
- this.changeEvent.notify(-1 * 100)
45
- } else if (e.code === 'ArrowDown') {
46
- this.changeEvent.notify(1 * 100)
47
- } else if (e.code === 'PageUp') {
48
- this.changeEvent.notify(-1 * 1000)
49
- } else if (e.code === 'PageDown') {
50
- this.changeEvent.notify(1 * 1000)
51
- } else if (e.code === 'Home') {
52
- this.changeEvent.notify('min')
53
- } else if (e.code === 'End') {
54
- this.changeEvent.notify('max')
55
- } else {
56
- interaction = false
57
- }
58
-
59
- if (interaction) {
60
- user.registerInteraction()
61
- }
62
- }
63
- }
@@ -1,27 +0,0 @@
1
- import { ticker, TickerCallback } from '$packages/ticker'
2
- import { Controls } from './Controls'
3
-
4
- export interface LinearControlsOptions {
5
- speed?: number
6
- }
7
-
8
- export class LinearControls extends Controls {
9
- speed: number
10
-
11
- constructor(options?: LinearControlsOptions) {
12
- super()
13
- this.speed = options?.speed || 1
14
- }
15
-
16
- public connect() {
17
- ticker.subscribe(this.#animationFrameCallback)
18
- }
19
-
20
- public disconnect() {
21
- ticker.unsubscribe(this.#animationFrameCallback)
22
- }
23
-
24
- #animationFrameCallback: TickerCallback = (e) => {
25
- this.changeEvent.notify(e.elapsed * this.speed)
26
- }
27
- }
@@ -1,20 +0,0 @@
1
- class User {
2
- #idleTimeoutId: ReturnType<typeof setTimeout> | undefined
3
- #isIdle = true
4
-
5
- public get isIdle() {
6
- return this.#isIdle
7
- }
8
-
9
- public registerInteraction() {
10
- clearTimeout(this.#idleTimeoutId)
11
-
12
- this.#isIdle = false
13
-
14
- this.#idleTimeoutId = setTimeout(() => {
15
- this.#isIdle = true
16
- }, 2000)
17
- }
18
- }
19
-
20
- export const user = new User()
@@ -1,92 +0,0 @@
1
- import { Axes2D, isBrowser, getElement } from '$packages/utils'
2
- import { Controls } from './Controls'
3
- import { user } from './User'
4
-
5
- export interface WheelControlsOptions {
6
- axis?: Axes2D
7
- speed?: number
8
- debounce?: boolean
9
- element?: HTMLElement
10
- }
11
-
12
- export class WheelControls extends Controls {
13
- axis: Axes2D
14
- speed: number
15
- debounce: boolean
16
-
17
- #element: HTMLElement | Window = null!
18
-
19
- #timeout: ReturnType<typeof setTimeout> | undefined
20
- #prevEventDate: number
21
-
22
- constructor(options?: WheelControlsOptions) {
23
- super()
24
-
25
- this.axis = options?.axis || 'y'
26
- this.speed = options?.speed || 1
27
- this.debounce = options?.debounce || false
28
-
29
- this.#prevEventDate = Date.now()
30
-
31
- if (isBrowser) {
32
- this.#element = options?.element ? getElement(options.element) || window : window
33
- }
34
- }
35
-
36
- public connect() {
37
- if (isBrowser) {
38
- this.#element.addEventListener('wheel', this.#wheelListener as EventListener, {
39
- passive: false,
40
- })
41
- }
42
- }
43
-
44
- public disconnect() {
45
- if (isBrowser) {
46
- this.#element.removeEventListener('wheel', this.#wheelListener as EventListener)
47
- }
48
- }
49
-
50
- #wheelListener = (event: WheelEvent) => {
51
- let delta = 0
52
-
53
- if (
54
- (this.axis === 'x' && Math.abs(event.deltaY) > Math.abs(event.deltaX)) ||
55
- (this.axis === 'y' && Math.abs(event.deltaX) > Math.abs(event.deltaY))
56
- ) {
57
- return
58
- }
59
-
60
- delta = (this.axis === 'x' ? event.deltaX : event.deltaY) * this.speed
61
-
62
- user.registerInteraction()
63
- event.stopPropagation()
64
- event.preventDefault()
65
-
66
- if (this.debounce) {
67
- const now = Date.now()
68
-
69
- if (now - this.#prevEventDate > 40) {
70
- delta = 100 * Math.sign(delta)
71
- }
72
-
73
- this.#prevEventDate = now
74
-
75
- if (Math.abs(delta) < 100) {
76
- return
77
- }
78
-
79
- if (this.#timeout) {
80
- return
81
- }
82
-
83
- this.changeEvent.notify(delta)
84
-
85
- this.#timeout = setTimeout(() => {
86
- this.#timeout = undefined
87
- }, 80)
88
- } else {
89
- this.changeEvent.notify(delta)
90
- }
91
- }
92
- }
@@ -1,5 +0,0 @@
1
- export { Controls, type ControlsValue } from './Controls'
2
- export { KeyboardControls } from './KeyboardControls'
3
- export { LinearControls, type LinearControlsOptions } from './LinearControls'
4
- export { WheelControls, type WheelControlsOptions } from './WheelControls'
5
- export { user } from './User'
@@ -1,32 +0,0 @@
1
- class CSSUnitParser {
2
- #dummyElement: HTMLElement = null!
3
-
4
- public parse(value: string) {
5
- this.#createDummy()
6
-
7
- this.#dummyElement.style.left = value
8
- const computedWidth = getComputedStyle(this.#dummyElement).getPropertyValue('left')
9
-
10
- return parseFloat(computedWidth)
11
- }
12
-
13
- #createDummy() {
14
- if (!this.#dummyElement) {
15
- this.#dummyElement = document.createElement('div')
16
- this.#dummyElement.style.cssText = `
17
- position: fixed;
18
- top: 0;
19
- left: 0;
20
- width: 0;
21
- height: 0;
22
- visibility: hidden;
23
- `
24
- }
25
-
26
- if (!document.body.contains(this.#dummyElement)) {
27
- document.body.prepend(this.#dummyElement)
28
- }
29
- }
30
- }
31
-
32
- export const cssUnitParser = new CSSUnitParser()
@@ -1,19 +0,0 @@
1
- import { isBrowser } from '$packages/utils'
2
-
3
- export function define(name: string) {
4
- return function (Constructor: CustomElementConstructor) {
5
- if (isBrowser && !customElements.get(name)) {
6
- customElements.define(name, Constructor)
7
- }
8
- }
9
- }
10
-
11
- const HTMLElement = (
12
- isBrowser
13
- ? window.HTMLElement
14
- : class {
15
- attachShadow(..._: any): any {}
16
- }
17
- ) as typeof window.HTMLElement
18
-
19
- export class CustomElement extends HTMLElement {}
@@ -1,113 +0,0 @@
1
- import { RESIZE_ORDER } from '$packages/order'
2
- import { resizer } from '$packages/resizer'
3
- import { isBrowser } from '$packages/utils'
4
- import { TierResult, getGPUTier } from 'detect-gpu'
5
-
6
- export type DeviceOS = 'macOS' | 'iOS' | 'Windows' | 'Android' | 'Linux' | 'unknown'
7
-
8
- class Device {
9
- #OS = 'unknown'
10
- #gpu = 'unknown'
11
- #gpuTier = 0
12
- #gpuDetection: Promise<TierResult> = null!
13
- #isMobile = false
14
- #isTouch = false
15
- #isWebgl = false
16
- #isWebp = false
17
- #isApple = false
18
-
19
- constructor() {
20
- if (isBrowser) {
21
- this.#gpuDetection = getGPUTier()
22
-
23
- this.#gpuDetection.then((v) => {
24
- this.#gpu = v.gpu || 'unknown'
25
- this.#gpuTier = v.tier
26
- })
27
-
28
- resizer.subscribe(() => {
29
- this.#isMobile = /Mobi|Android/i.test(navigator.userAgent)
30
-
31
- this.#isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0
32
-
33
- setTimeout(() => {
34
- this.#isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0
35
- }, 0)
36
- }, RESIZE_ORDER.DEVICE)
37
-
38
- {
39
- const canvas = document.createElement('canvas')
40
- const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl')
41
- this.#isWebgl = (gl && gl instanceof WebGLRenderingContext) || false
42
- }
43
-
44
- {
45
- const canvas = document.createElement('canvas')
46
- if (canvas.getContext('2d')) {
47
- this.#isWebp = canvas.toDataURL('image/webp').indexOf('data:image/webp') == 0
48
- }
49
- }
50
-
51
- const userAgent = window.navigator.userAgent
52
- const platform =
53
- (window.navigator as any)?.userAgentData?.platform || window.navigator.platform
54
- const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K', 'macOS']
55
- const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']
56
- const iosPlatforms = ['iPhone', 'iPad', 'iPod']
57
-
58
- if (macosPlatforms.includes(platform)) {
59
- this.#OS = 'macOS'
60
- this.#isApple = true
61
- } else if (iosPlatforms.includes(platform)) {
62
- this.#OS = 'iOS'
63
- this.#isApple = true
64
- } else if (windowsPlatforms.includes(platform)) {
65
- this.#OS = 'Windows'
66
- } else if (/Android/.test(userAgent)) {
67
- this.#OS = 'Android'
68
- } else if (/Linux/.test(platform)) {
69
- this.#OS = 'Linux'
70
- } else {
71
- this.#OS = 'unknown'
72
- }
73
- }
74
- }
75
-
76
- public get OS() {
77
- return this.#OS
78
- }
79
-
80
- public get gpu() {
81
- return this.#gpu
82
- }
83
-
84
- public get gpuTier() {
85
- return this.#gpuTier
86
- }
87
-
88
- public get gpuDetection() {
89
- return this.#gpuDetection
90
- }
91
-
92
- public get isMobile() {
93
- return this.#isMobile
94
- }
95
-
96
- public get isTouch() {
97
- return this.#isTouch
98
- }
99
-
100
- public get isWebgl() {
101
- return this.#isWebgl
102
- }
103
-
104
- public get isWebp() {
105
- return this.#isWebp
106
- }
107
-
108
- public get isApple() {
109
- return this.#isApple
110
- }
111
- }
112
-
113
- export const device = new Device()