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,29 +0,0 @@
1
- import { Dot2D } from '$packages/utils'
2
- import { Texture } from 'three'
3
-
4
- /**
5
- * texture.matrixAutoUpdate must be false
6
- */
7
- export function coverTexture(texture: Texture, planeSize: Dot2D, aspect?: number) {
8
- const width = planeSize.x
9
- const height = planeSize.y
10
- const _aspect = aspect || texture.image.width / texture.image.height
11
-
12
- let sx = 0
13
- let sy = 0
14
- let tx = texture.offset.x
15
- let ty = texture.offset.y
16
- let r = texture.rotation
17
- let cx = texture.center.x
18
- let cy = texture.center.y
19
-
20
- if (width / height > _aspect) {
21
- sx = 1
22
- sy = (height / width) * _aspect
23
- } else {
24
- sy = 1
25
- sx = width / height / _aspect
26
- }
27
-
28
- texture.matrix.setUvTransform(tx, ty, sx, sy, r, cx, cy)
29
- }
@@ -1,27 +0,0 @@
1
- import { Material, Mesh, Object3D } from 'three'
2
-
3
- export function dispose(object3d: Object3D) {
4
- const cleanMaterial = (material: Material) => {
5
- material.dispose()
6
-
7
- for (const key of Object.keys(material)) {
8
- const value = material[key as keyof Material]
9
-
10
- if (value && typeof value === 'object' && 'minFilter' in value) {
11
- value.dispose()
12
- }
13
- }
14
- }
15
-
16
- object3d.traverse((object: Object3D) => {
17
- if (!(object instanceof Mesh)) return
18
-
19
- object.geometry.dispose()
20
-
21
- if (!Array.isArray(object.material) && object.material.isMaterial) {
22
- cleanMaterial(object.material)
23
- } else if (Array.isArray(object.material)) {
24
- for (const material of object.material) cleanMaterial(material)
25
- }
26
- })
27
- }
@@ -1,10 +0,0 @@
1
- import { Mesh, Material, Object3D } from 'three'
2
-
3
- export function traverseMaterials(object: Object3D, callback: (material: Material) => void) {
4
- object.traverse((node: Object3D) => {
5
- if (node instanceof Mesh && node.material) {
6
- const materials = Array.isArray(node.material) ? node.material : [node.material]
7
- materials.forEach(callback)
8
- }
9
- })
10
- }
@@ -1,9 +0,0 @@
1
- import { Mesh, Object3D } from 'three'
2
-
3
- export function traverseMeshes(object: Object3D, callback: (mesh: Mesh) => void) {
4
- object.traverse((node: Object3D) => {
5
- if (node instanceof Mesh) {
6
- callback(node)
7
- }
8
- })
9
- }
@@ -1,19 +0,0 @@
1
- import { define } from '$packages/custom-element'
2
- import { SourceElement } from '$packages/source'
3
-
4
- @define('e-image')
5
- export class ImageElement extends SourceElement<HTMLImageElement> {
6
- protected override createConsumer() {
7
- return document.createElement('img')
8
- }
9
-
10
- protected override consumeSource(url: string | null) {
11
- this.consumerElement.src = url || ''
12
- }
13
- }
14
-
15
- declare global {
16
- interface HTMLElementTagNameMap {
17
- 'e-image': ImageElement
18
- }
19
- }
@@ -1,83 +0,0 @@
1
- import { isBrowser } from '$packages/utils'
2
-
3
- export type IntersectorCallback = (entry: IntersectionObserverEntry) => void
4
-
5
- interface IntersectorSubscriber {
6
- element: Element
7
- callback: IntersectorCallback
8
- entry: IntersectionObserverEntry | null
9
- }
10
-
11
- export class Intersector {
12
- #subscribers: Array<IntersectorSubscriber> = []
13
- #intersectionObserver: IntersectionObserver = null!
14
-
15
- constructor() {
16
- if (isBrowser) {
17
- this.#intersectionObserver = new IntersectionObserver(this.#intersectionListener)
18
- }
19
- }
20
-
21
- public subscribe(elementOrSelector: HTMLElement | string, callback: IntersectorCallback) {
22
- const element =
23
- typeof elementOrSelector === 'string'
24
- ? document.querySelector<HTMLElement>(elementOrSelector)
25
- : elementOrSelector
26
-
27
- if (!element) {
28
- return
29
- }
30
-
31
- const alreadyObserved = this.#subscribers.find((sub) => sub.element === element)
32
-
33
- if (!alreadyObserved) {
34
- this.#intersectionObserver.observe(element)
35
- } else {
36
- const alreadyIntersected = this.#subscribers.find((s) => s.element === element && s.entry)
37
-
38
- if (alreadyIntersected?.entry!.isIntersecting) {
39
- callback(alreadyIntersected.entry)
40
- }
41
- }
42
-
43
- this.#subscribers.push({
44
- element,
45
- callback,
46
- entry: alreadyObserved?.entry || null,
47
- })
48
-
49
- return () => {
50
- this.unsubscribe(callback)
51
- }
52
- }
53
-
54
- public unsubscribe(callback: IntersectorCallback) {
55
- const subscriber = this.#subscribers.find((sub) => sub.callback === callback)
56
-
57
- if (subscriber) {
58
- this.#subscribers = this.#subscribers.filter((sub) => sub.callback === callback)
59
-
60
- if (!this.#subscribers.find((sub) => sub.element === subscriber.element)) {
61
- this.#intersectionObserver.unobserve(subscriber.element)
62
- }
63
- }
64
- }
65
-
66
- #intersectionListener: IntersectionObserverCallback = (entries) => {
67
- const matches = this.#subscribers.map((subscriber) => {
68
- return {
69
- subscriber,
70
- entry: entries.find((entry) => entry.target === subscriber.element),
71
- }
72
- })
73
-
74
- matches.forEach((match) => {
75
- if (match.entry) {
76
- match.subscriber.entry = match.entry
77
- match.subscriber.callback(match.entry)
78
- }
79
- })
80
- }
81
- }
82
-
83
- export const intersector = new Intersector()
@@ -1,112 +0,0 @@
1
- import { Store } from '$packages/store'
2
-
3
- export type LadderDefaultStepName = number | string
4
-
5
- export type LadderOperation = '+' | '*' | '/' | '-'
6
-
7
- export type LadderStep<T> = [LadderOperation, T]
8
-
9
- export type LadderSteps<K, T> = Map<K, LadderStep<T>>
10
-
11
- export type LadderDefaultValueType = { [key: string]: number }
12
-
13
- export class Ladder<
14
- V extends LadderDefaultValueType = LadderDefaultValueType,
15
- K extends LadderDefaultStepName = LadderDefaultStepName
16
- > extends Store<V> {
17
- #base: V
18
- #steps: LadderSteps<K, V>
19
- #bindings: Set<V>
20
-
21
- constructor(base: V) {
22
- super(base, {
23
- equalityCheck: () => false,
24
- })
25
-
26
- this.#base = { ...base }
27
- this.#steps = new Map()
28
- this.#bindings = new Set()
29
- }
30
-
31
- public get base() {
32
- return this.#base
33
- }
34
-
35
- public get steps() {
36
- return this.#steps
37
- }
38
-
39
- public override close() {
40
- super.close()
41
- this.#bindings.clear()
42
- this.#steps.clear()
43
- }
44
-
45
- public bind(sub: V) {
46
- this.#bindings.add(sub)
47
- }
48
-
49
- public unbind(sub: V) {
50
- this.#bindings.delete(sub)
51
- }
52
-
53
- public deleteStep(stepName: K) {
54
- this.steps.delete(stepName)
55
- }
56
-
57
- public getStepValue(stepName: K) {
58
- return this.steps.get(stepName)![1]
59
- }
60
-
61
- public setStep(stepName: K, action: LadderOperation, value: Partial<V>) {
62
- const readyValue = {} as V
63
-
64
- for (const key in this.current) {
65
- ;(readyValue[key] as any) = value[key] || 0
66
- }
67
-
68
- this.steps.set(stepName, [action, readyValue])
69
- }
70
-
71
- public calculate() {
72
- const calculated = {} as V
73
-
74
- for (const key in this.base) {
75
- calculated[key] = this.base[key]
76
- }
77
-
78
- for (const item of this.steps) {
79
- const step = item[1]
80
-
81
- if (step[0] === '+') {
82
- for (const key in this.base) {
83
- const value = step[1][key] as number
84
- ;(calculated[key] as any) += value
85
- }
86
- } else if (step[0] === '*') {
87
- for (const key in this.base) {
88
- const value = step[1][key] as number
89
- ;(calculated[key] as any) *= value
90
- }
91
- } else if (step[0] === '/') {
92
- for (const key in this.base) {
93
- const value = step[1][key] as number
94
- ;(calculated[key] as any) /= value
95
- }
96
- } else if (step[0] === '-') {
97
- for (const key in this.base) {
98
- const value = step[1][key] as number
99
- ;(calculated[key] as any) -= value
100
- }
101
- }
102
- }
103
-
104
- for (const sub of this.#bindings) {
105
- for (const key in calculated) {
106
- sub[key] = calculated[key]
107
- }
108
- }
109
-
110
- this.current = calculated
111
- }
112
- }
@@ -1,417 +0,0 @@
1
- import { cssUnitParser } from '$packages/css-unit-parser'
2
- import { Ladder } from '$packages/ladder'
3
- import { TICK_ORDER } from '$packages/order'
4
- import { resizer } from '$packages/resizer'
5
- import { scrollEnties } from '$packages/scroll-entries'
6
- import { StoreCallback, StoreEntry } from '$packages/store'
7
- import { ticker } from '$packages/ticker'
8
- import {
9
- ElementOrSelector,
10
- Axes3D,
11
- Axes2D,
12
- isBrowser,
13
- getCumulativeOffsetLeft,
14
- getCumulativeOffsetTop,
15
- } from '$packages/utils'
16
-
17
- export function decomposeCSSMatrix(matrix: WebKitCSSMatrix) {
18
- const scaleX = Math.sqrt(
19
- matrix.m11 * matrix.m11 + matrix.m12 * matrix.m12 + matrix.m13 * matrix.m13
20
- )
21
- const scaleY = Math.sqrt(
22
- matrix.m21 * matrix.m21 + matrix.m22 * matrix.m22 + matrix.m23 * matrix.m23
23
- )
24
- const scaleZ = Math.sqrt(
25
- matrix.m31 * matrix.m31 + matrix.m32 * matrix.m32 + matrix.m33 * matrix.m33
26
- )
27
-
28
- const rotationX = Math.atan2(matrix.m32, matrix.m33)
29
- const rotationY = Math.atan2(
30
- -matrix.m31,
31
- Math.sqrt(matrix.m32 * matrix.m32 + matrix.m33 * matrix.m33)
32
- )
33
- const rotationZ = Math.atan2(matrix.m21, matrix.m11)
34
-
35
- const translationX = matrix.m41
36
- const translationY = matrix.m42
37
- const translationZ = matrix.m43
38
-
39
- return {
40
- scaleX,
41
- scaleY,
42
- scaleZ,
43
- rotationX,
44
- rotationY,
45
- rotationZ,
46
- translationX,
47
- translationY,
48
- translationZ,
49
- }
50
- }
51
-
52
- export interface LayoutBoxOptions {
53
- containerElement?: ElementOrSelector
54
- cartesian?: boolean
55
- scrollAxis?: Axes3D | 'auto'
56
- frontSide?: LayoutBoxFrontSide
57
- sizeStep?: boolean
58
- positionStep?: boolean
59
- culling?: boolean
60
- }
61
-
62
- export interface LayoutBoxScrollStepCallbackReturn {
63
- axis: Axes2D
64
- value: number
65
- }
66
-
67
- export type LayoutBoxXYZ = { x: number; y: number; z: number }
68
-
69
- export type LayoutBoxScrollStepCallback = () => LayoutBoxScrollStepCallbackReturn
70
- export type LayoutBoxStepCallback = StoreCallback<StoreEntry<LayoutBoxXYZ>>
71
-
72
- export type LayoutBoxFrontSide = 'left' | 'top'
73
-
74
- export interface LayoutBoxBindedObject {
75
- position?: LayoutBoxXYZ
76
- scale?: LayoutBoxXYZ
77
- rotation?: LayoutBoxXYZ
78
- }
79
-
80
- export class LayoutBox {
81
- #element: HTMLElement = null!
82
- #containerElement: HTMLElement = null!
83
- #scrollStepSetterCallbacks: Array<LayoutBoxScrollStepCallback> = []
84
-
85
- #scrollAxis: Axes3D | 'auto' = 'auto'
86
- #frontSide: LayoutBoxFrontSide = 'top'
87
-
88
- #isCartesian = false
89
- #isSizeStep = true
90
- #isPositionStep = true
91
-
92
- #width = 0
93
- #height = 0
94
- #depth = 0
95
-
96
- #top = 0
97
- #left = 0
98
- #front = 0
99
-
100
- #x = 0
101
- #y = 0
102
- #z = 0
103
-
104
- #CSSTranslation = { x: 0, y: 0, z: 0 }
105
- #CSSRotation = { x: 0, y: 0, z: 0 }
106
- #CSSScale = { x: 1, y: 1, z: 1 }
107
-
108
- #rotation = new Ladder({ x: 0, y: 0, z: 0 })
109
- #position = new Ladder({ x: 0, y: 0, z: 0 })
110
- #scale = new Ladder({ x: 0, y: 0, z: 0 })
111
-
112
- constructor(element: ElementOrSelector, options?: LayoutBoxOptions) {
113
- if (isBrowser) {
114
- this.#element = this.#getElement(element) || document.body
115
- this.#containerElement = this.#getElement(options?.containerElement) || document.body
116
-
117
- this.#scrollAxis = options?.scrollAxis || 'auto'
118
- this.#frontSide = options?.frontSide || 'top'
119
-
120
- this.#isCartesian = options?.cartesian || false
121
- this.#isSizeStep = options?.sizeStep !== undefined ? options.sizeStep : true
122
- this.#isPositionStep = options?.positionStep !== undefined ? options.positionStep : true
123
-
124
- this.#scale.setStep('_size', '+', {
125
- x: 1,
126
- y: 1,
127
- z: 1,
128
- })
129
-
130
- this.#position.setStep('_position', '+', {
131
- x: 0,
132
- y: 0,
133
- z: 0,
134
- })
135
-
136
- this.#scale.setStep('_scale', '*', {
137
- x: 1,
138
- y: 1,
139
- z: 1,
140
- })
141
-
142
- this.#position.setStep('_translation', '+', {
143
- x: 0,
144
- y: 0,
145
- z: 0,
146
- })
147
-
148
- this.#rotation.setStep('_rotation', '+', {
149
- x: 0,
150
- y: 0,
151
- z: 0,
152
- })
153
-
154
- addEventListener('DOMContentLoaded', () => {
155
- const scrollEntries = scrollEnties.getAll(this.element)
156
-
157
- scrollEntries.forEach((entry) => {
158
- this.setScrollStep(() => {
159
- return entry
160
- })
161
- })
162
- })
163
-
164
- ticker.subscribe(this.#tickListener, {
165
- order: TICK_ORDER.LAYOUT_BOX,
166
- culling: options?.culling ? this.element : undefined,
167
- })
168
-
169
- resizer.subscribe(this.#resizeListener, TICK_ORDER.LAYOUT_BOX)
170
- }
171
- }
172
-
173
- public get element() {
174
- return this.#element
175
- }
176
-
177
- public get containerElement() {
178
- return this.#containerElement
179
- }
180
-
181
- public get position() {
182
- return this.#position.current
183
- }
184
-
185
- public get rotation() {
186
- return this.#rotation.current
187
- }
188
-
189
- public get scale() {
190
- return this.#scale.current
191
- }
192
-
193
- public get left() {
194
- return this.#left
195
- }
196
-
197
- public get top() {
198
- return this.#top
199
- }
200
-
201
- public get front() {
202
- return this.#front
203
- }
204
-
205
- public get width() {
206
- return this.#width
207
- }
208
-
209
- public get height() {
210
- return this.#height
211
- }
212
-
213
- public get depth() {
214
- return this.#depth
215
- }
216
-
217
- public bindObject(object: LayoutBoxBindedObject) {
218
- object.position && this.#position.bind(object.position)
219
- object.rotation && this.#rotation.bind(object.rotation)
220
- object.scale && this.#scale.bind(object.scale)
221
- }
222
-
223
- public unbindObject(object: LayoutBoxBindedObject) {
224
- object.position && this.#position.unbind(object.position)
225
- object.rotation && this.#rotation.unbind(object.rotation)
226
- object.scale && this.#scale.unbind(object.scale)
227
- }
228
-
229
- public setScrollStep(callback: LayoutBoxScrollStepCallback) {
230
- if (!this.#scrollStepSetterCallbacks.includes(callback)) {
231
- this.#scrollStepSetterCallbacks.push(callback)
232
- }
233
-
234
- return () => this.deleteScrollStep(callback)
235
- }
236
-
237
- public deleteScrollStep(callback: LayoutBoxScrollStepCallback) {
238
- this.#scrollStepSetterCallbacks = this.#scrollStepSetterCallbacks.filter((s) => s !== callback)
239
- }
240
-
241
- public destroy() {
242
- ticker.unsubscribe(this.#tickListener)
243
- resizer.unsubscribe(this.#resizeListener)
244
-
245
- this.#position.close()
246
- this.#rotation.close()
247
- this.#scale.close()
248
- }
249
-
250
- public setPositionStep(...args: Parameters<Ladder['setStep']>) {
251
- this.#position.setStep(...args)
252
- }
253
-
254
- public setRotationStep(...args: Parameters<Ladder['setStep']>) {
255
- this.#rotation.setStep(...args)
256
- }
257
-
258
- public setScaleStep(...args: Parameters<Ladder['setStep']>) {
259
- this.#scale.setStep(...args)
260
- }
261
-
262
- public deletePositionStep(...args: Parameters<Ladder['deleteStep']>) {
263
- this.#position.deleteStep(...args)
264
- }
265
-
266
- public deleteRotationStep(...args: Parameters<Ladder['deleteStep']>) {
267
- this.#rotation.deleteStep(...args)
268
- }
269
-
270
- public deleteScaleStep(...args: Parameters<Ladder['deleteStep']>) {
271
- this.#scale.deleteStep(...args)
272
- }
273
-
274
- #recalculate() {
275
- this.#scale.calculate()
276
- this.#position.calculate()
277
- this.#rotation.calculate()
278
- }
279
-
280
- #composeSteps() {
281
- this.#scale.setStep('_size', '+', {
282
- x: this.#isSizeStep ? this.#width : 1,
283
- y: this.#isSizeStep ? this.#height : 1,
284
- z: this.#isSizeStep ? this.#depth : 1,
285
- })
286
-
287
- const xPosition = this.#isPositionStep ? this.#x : 0
288
- const yPosition = this.#isPositionStep ? this.#y : 0
289
- const zPosition = this.#isPositionStep ? this.#z : 0
290
-
291
- this.#position.setStep('_position', '+', {
292
- x: xPosition,
293
- y: yPosition,
294
- z: zPosition,
295
- })
296
-
297
- this.#scale.setStep('_scale', '*', {
298
- x: this.#CSSScale.x,
299
- y: this.#CSSScale.y,
300
- z: this.#CSSScale.z,
301
- })
302
-
303
- this.#position.setStep('_translation', '+', {
304
- x: this.#CSSTranslation.x,
305
- y: this.#CSSTranslation.y,
306
- z: this.#CSSTranslation.z,
307
- })
308
-
309
- this.#rotation.setStep('_rotation', '+', {
310
- x: this.#CSSRotation.x,
311
- y: this.#CSSRotation.y,
312
- z: this.#CSSRotation.z,
313
- })
314
- }
315
-
316
- #updateDimensions() {
317
- const computed = getComputedStyle(this.#element)
318
-
319
- this.#width = Math.max(this.#element.clientWidth, 1)
320
-
321
- this.#height = Math.max(this.#element.clientHeight, 1)
322
-
323
- this.#depth = Math.max(cssUnitParser.parse(computed.getPropertyValue('--depth') || '0px'), 1)
324
-
325
- const vl = getCumulativeOffsetLeft(this.#containerElement)
326
- const vt = getCumulativeOffsetTop(this.#containerElement)
327
- const vw = this.#containerElement.clientWidth
328
- const vh = this.#containerElement.clientHeight
329
-
330
- this.#left = getCumulativeOffsetLeft(this.#element) - vl
331
- this.#top = getCumulativeOffsetTop(this.#element) - vt
332
-
333
- if (this.#scrollAxis === 'z') {
334
- const nl = this.#left / vw
335
- const nt = this.#top / vh
336
-
337
- this.#left = (nl - Math.floor(nl)) * vw
338
- this.#top = (nt - Math.floor(nt)) * vh
339
-
340
- if (this.#frontSide === 'left') {
341
- this.#front = getCumulativeOffsetLeft(this.#element) - vl - this.#left
342
- } else {
343
- this.#front = getCumulativeOffsetTop(this.#element) - vt - this.#top
344
- }
345
- }
346
-
347
- this.#left += this.#element.clientLeft
348
- this.#top += this.#element.clientTop
349
-
350
- if (this.#isCartesian) {
351
- const viewHalfWidth = Math.round(vw / 2)
352
- const viewHalfHeight = Math.round(vh / 2)
353
-
354
- const thisHalfWidth = this.#width ? Math.round(this.#width / 2) : 0
355
- const thisHalfHeight = this.#height ? Math.round(this.#height / 2) : 0
356
-
357
- const positionX = this.#left - viewHalfWidth + thisHalfWidth
358
- const positionY = (this.#top - viewHalfHeight + thisHalfHeight) * -1
359
- this.#x = positionX
360
- this.#y = positionY
361
- } else {
362
- this.#x = this.#left
363
- this.#y = this.#top
364
- }
365
-
366
- this.#z = this.#front * -1
367
-
368
- const cssMatrix = new WebKitCSSMatrix(computed.transform)
369
- const decomposedMatrix = decomposeCSSMatrix(cssMatrix)
370
-
371
- this.#CSSTranslation.x = decomposedMatrix.translationX
372
- this.#CSSTranslation.y = decomposedMatrix.translationY
373
- this.#CSSTranslation.z = decomposedMatrix.translationZ
374
-
375
- this.#CSSScale.x = decomposedMatrix.scaleX
376
- this.#CSSScale.y = decomposedMatrix.scaleY
377
- this.#CSSScale.z = decomposedMatrix.scaleZ
378
-
379
- this.#CSSRotation.x = decomposedMatrix.rotationX
380
- this.#CSSRotation.y = decomposedMatrix.rotationY
381
- this.#CSSRotation.z = decomposedMatrix.rotationZ
382
-
383
- this.#composeSteps()
384
- this.#recalculate()
385
- }
386
-
387
- #updateScrollPosition() {
388
- for (let index = 0; index < this.#scrollStepSetterCallbacks.length; index++) {
389
- const callbackReturn = this.#scrollStepSetterCallbacks[index]()
390
-
391
- let axis = callbackReturn.axis as Axes3D
392
-
393
- if (this.#scrollAxis !== 'auto') {
394
- axis = this.#scrollAxis
395
- }
396
-
397
- this.#position.setStep(`_scroll_${index}`, '+', {
398
- [axis]: callbackReturn.value * (axis === 'x' ? -1 : this.#isCartesian ? 1 : -1),
399
- })
400
- }
401
- }
402
-
403
- #getElement(element: string | HTMLElement | undefined) {
404
- return typeof element === 'string' ? document.querySelector<HTMLElement>(element) : element
405
- }
406
-
407
- #resizeListener = () => {
408
- if (isBrowser) {
409
- this.#updateDimensions()
410
- }
411
- }
412
-
413
- #tickListener = () => {
414
- this.#updateScrollPosition()
415
- this.#recalculate()
416
- }
417
- }