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.
Files changed (115) hide show
  1. package/.prettierignore +16 -0
  2. package/.prettierrc +9 -0
  3. package/.vscode/extensions.json +4 -0
  4. package/.vscode/launch.json +11 -0
  5. package/.vscode/settings.json +18 -0
  6. package/README.md +0 -0
  7. package/index.html +32 -0
  8. package/package.json +272 -0
  9. package/public/vite.svg +1 -0
  10. package/src/packages/animation/Animated.ts +189 -0
  11. package/src/packages/animation/Damped.ts +39 -0
  12. package/src/packages/animation/Tweened.ts +51 -0
  13. package/src/packages/animation/index.ts +10 -0
  14. package/src/packages/attribute/index.ts +59 -0
  15. package/src/packages/canvas-2d/index.ts +137 -0
  16. package/src/packages/controls/Controls.ts +15 -0
  17. package/src/packages/controls/KeyboardControls.ts +63 -0
  18. package/src/packages/controls/LinearControls.ts +27 -0
  19. package/src/packages/controls/User.ts +20 -0
  20. package/src/packages/controls/WheelControls.ts +92 -0
  21. package/src/packages/controls/index.ts +5 -0
  22. package/src/packages/css-unit-parser/index.ts +32 -0
  23. package/src/packages/custom-element/index.ts +19 -0
  24. package/src/packages/device/Device.ts +113 -0
  25. package/src/packages/device/Viewport.ts +67 -0
  26. package/src/packages/device/index.ts +2 -0
  27. package/src/packages/element-constructor/ElementConstructor.ts +577 -0
  28. package/src/packages/element-constructor/htmlTags.ts +679 -0
  29. package/src/packages/element-constructor/index.ts +4 -0
  30. package/src/packages/element-constructor/specialObjects.ts +8 -0
  31. package/src/packages/element-constructor/svgTags.ts +588 -0
  32. package/src/packages/en3/attachments/En3SourceManager.ts +116 -0
  33. package/src/packages/en3/core/en3.ts +306 -0
  34. package/src/packages/en3/index.ts +52 -0
  35. package/src/packages/en3/instances/en3LazyLoader.ts +22 -0
  36. package/src/packages/en3/libs/MeshoptDecoder.js +138 -0
  37. package/src/packages/en3/loaders/en3GLTFLoader.ts +54 -0
  38. package/src/packages/en3/loaders/en3TextureLoader.ts +3 -0
  39. package/src/packages/en3/objects/En3Clip.ts +53 -0
  40. package/src/packages/en3/objects/En3ClipHelpers.ts +12 -0
  41. package/src/packages/en3/objects/En3GLTF.ts +35 -0
  42. package/src/packages/en3/objects/En3Image.ts +18 -0
  43. package/src/packages/en3/objects/En3ImageLike.ts +101 -0
  44. package/src/packages/en3/objects/En3SourceConsumer.ts +5 -0
  45. package/src/packages/en3/objects/En3Video.ts +88 -0
  46. package/src/packages/en3/test/En3HTML.ts +55 -0
  47. package/src/packages/en3/test/En3ModifiedMaterial.ts +221 -0
  48. package/src/packages/en3/test/En3Raycaster.ts +187 -0
  49. package/src/packages/en3/utils/coverTexture.ts +29 -0
  50. package/src/packages/en3/utils/dispose.ts +27 -0
  51. package/src/packages/en3/utils/traverseMaterials.ts +10 -0
  52. package/src/packages/en3/utils/traverseMeshes.ts +9 -0
  53. package/src/packages/image/index.ts +19 -0
  54. package/src/packages/intersector/index.ts +83 -0
  55. package/src/packages/ladder/index.ts +112 -0
  56. package/src/packages/layout-box/index.ts +417 -0
  57. package/src/packages/loading/index.ts +131 -0
  58. package/src/packages/measurer/CumulativeOffsetLeft.ts +8 -0
  59. package/src/packages/measurer/CumulativeOffsetTop.ts +8 -0
  60. package/src/packages/measurer/Meaurer.ts +38 -0
  61. package/src/packages/measurer/index.ts +3 -0
  62. package/src/packages/media/index.ts +38 -0
  63. package/src/packages/morph/Link.ts +32 -0
  64. package/src/packages/morph/Morph.ts +246 -0
  65. package/src/packages/morph/index.ts +10 -0
  66. package/src/packages/notifier/index.ts +41 -0
  67. package/src/packages/order/index.ts +14 -0
  68. package/src/packages/resizer/index.ts +55 -0
  69. package/src/packages/router/Link.ts +33 -0
  70. package/src/packages/router/Route.ts +152 -0
  71. package/src/packages/router/RouteElement.ts +34 -0
  72. package/src/packages/router/Router.ts +190 -0
  73. package/src/packages/router/index.ts +13 -0
  74. package/src/packages/scroll/ScrollElement.ts +618 -0
  75. package/src/packages/scroll/ScrollUserElement.ts +21 -0
  76. package/src/packages/scroll/ScrollbarElement.ts +170 -0
  77. package/src/packages/scroll/index.ts +2 -0
  78. package/src/packages/scroll-entries/index.ts +74 -0
  79. package/src/packages/source/SourceClass.ts +77 -0
  80. package/src/packages/source/SourceElement.ts +177 -0
  81. package/src/packages/source/SourceManager.ts +61 -0
  82. package/src/packages/source/SourceSet.ts +52 -0
  83. package/src/packages/source/index.ts +8 -0
  84. package/src/packages/store/Composed.ts +33 -0
  85. package/src/packages/store/Derived.ts +24 -0
  86. package/src/packages/store/DerivedArray.ts +36 -0
  87. package/src/packages/store/Resource.ts +38 -0
  88. package/src/packages/store/Store.ts +144 -0
  89. package/src/packages/store/StoreRegistry.ts +105 -0
  90. package/src/packages/store/index.ts +23 -0
  91. package/src/packages/ticker/index.ts +173 -0
  92. package/src/packages/utils/array.ts +3 -0
  93. package/src/packages/utils/attributes.ts +19 -0
  94. package/src/packages/utils/browser.ts +2 -0
  95. package/src/packages/utils/canvas.ts +46 -0
  96. package/src/packages/utils/collisions.ts +12 -0
  97. package/src/packages/utils/coordinates.ts +40 -0
  98. package/src/packages/utils/decoding.ts +11 -0
  99. package/src/packages/utils/dev.ts +5 -0
  100. package/src/packages/utils/dom.ts +48 -0
  101. package/src/packages/utils/easings.ts +69 -0
  102. package/src/packages/utils/file.ts +17 -0
  103. package/src/packages/utils/function.ts +29 -0
  104. package/src/packages/utils/index.ts +61 -0
  105. package/src/packages/utils/layout.ts +22 -0
  106. package/src/packages/utils/math.ts +74 -0
  107. package/src/packages/utils/number.ts +26 -0
  108. package/src/packages/utils/object.ts +108 -0
  109. package/src/packages/utils/string.ts +49 -0
  110. package/src/packages/utils/ts-shape.ts +25 -0
  111. package/src/packages/utils/ts-utility.ts +47 -0
  112. package/src/packages/video/index.ts +39 -0
  113. package/src/playground/index.ts +0 -0
  114. package/tsconfig.json +31 -0
  115. package/vite.config.ts +65 -0
@@ -0,0 +1,190 @@
1
+ import { URLPattern } from 'urlpattern-polyfill'
2
+ import { Notifier } from '$packages/notifier'
3
+ import { isBrowser, debounce } from '$packages/utils'
4
+ import { Route, RouteModule } from './Route'
5
+ import { Link } from './Link'
6
+
7
+ // @ts-ignore
8
+ globalThis.URLPattern = URLPattern
9
+
10
+ export interface RouterPreprocessorEntry {
11
+ pathname: string
12
+ resolve: () => void
13
+ reject: () => void
14
+ }
15
+
16
+ export type RouterPreprocessor = (entry: RouterPreprocessorEntry) => void
17
+
18
+ export interface RouterPostprocessorEntry {
19
+ pathname: string
20
+ }
21
+
22
+ export type RouterPostprocessor = (entry: RouterPostprocessorEntry) => void
23
+
24
+ export interface RouterAfterNavigationEntry {
25
+ pathname: string
26
+ }
27
+
28
+ export type RouterAfterNavigationCallback = (entry: RouterAfterNavigationEntry) => void
29
+
30
+ export type RouterHistoryAction = 'push' | 'replace' | 'none'
31
+
32
+ export interface RouterParameters {
33
+ rootElement?: HTMLElement
34
+ base?: string
35
+ }
36
+
37
+ export class Router {
38
+ public static active: Router
39
+
40
+ #rootElement: HTMLElement = null!
41
+ #base: string
42
+ #routes: Array<Route> = []
43
+ #lastRoute: Route | null = null
44
+ #links: Array<Link> = []
45
+ #candidatePathname: string | undefined
46
+ #currentPathname: string = null!
47
+
48
+ #navigationEvent = new Notifier<RouterAfterNavigationCallback>()
49
+
50
+ public preprocessor?: RouterPreprocessor
51
+ public postprocessor?: RouterPostprocessor
52
+
53
+ constructor(parameters?: RouterParameters) {
54
+ this.#base = parameters?.base || ''
55
+
56
+ Router.active = this
57
+
58
+ if (isBrowser) {
59
+ this.#rootElement = parameters?.rootElement || document.body
60
+ addEventListener('popstate', this.#popStateListener)
61
+ }
62
+ }
63
+
64
+ public get currentPathname() {
65
+ return this.#currentPathname
66
+ }
67
+
68
+ public get candidatePathname() {
69
+ return this.#candidatePathname
70
+ }
71
+
72
+ public get routes() {
73
+ return this.#routes
74
+ }
75
+
76
+ public navigationEvent(callback: RouterAfterNavigationCallback) {
77
+ return this.#navigationEvent.subscribe(callback)
78
+ }
79
+
80
+ public defineRoute(pattern: string, module: RouteModule) {
81
+ const route = new Route(pattern, module)
82
+ this.#routes.push(route)
83
+ this.#start()
84
+ }
85
+
86
+ public async navigate(pathname: string, action: RouterHistoryAction = 'push') {
87
+ if (this.#candidatePathname === pathname || this.#currentPathname === pathname) {
88
+ return
89
+ }
90
+
91
+ Router.active = this
92
+
93
+ this.#candidatePathname = pathname
94
+
95
+ const activeRoutes = this.#routes.filter((r) => r.isActive)
96
+
97
+ const newRoutes = this.#routes.filter(
98
+ (r) => !activeRoutes.includes(r) && r.testPathname(pathname)
99
+ )
100
+
101
+ const oldRoutes = activeRoutes.filter((r) => !r.testPathname(pathname))
102
+ const keepRoutes = activeRoutes.filter((r) => r.testPathname(pathname))
103
+
104
+ let isOkToSwitch = true
105
+
106
+ if (this.preprocessor) {
107
+ try {
108
+ await new Promise<void>((resolve, reject) => {
109
+ this.preprocessor?.({ pathname, resolve, reject })
110
+ })
111
+ } catch (e: any) {
112
+ if (e) {
113
+ console.error(e)
114
+ } else {
115
+ console.log('Route change canceled')
116
+ }
117
+ isOkToSwitch = false
118
+ }
119
+ }
120
+
121
+ if (isOkToSwitch && this.#candidatePathname === pathname) {
122
+ this.#lastRoute = keepRoutes[keepRoutes.length - 1]
123
+
124
+ oldRoutes.forEach((r) => {
125
+ r.close()
126
+ })
127
+
128
+ this.#currentPathname = pathname
129
+
130
+ for await (const route of newRoutes) {
131
+ await route.render(this.#lastRoute?.outlet || this.#rootElement, pathname)
132
+ this.#lastRoute = route
133
+ }
134
+
135
+ const fullPathname = this.#base + pathname + location.search
136
+
137
+ if (action === 'push') {
138
+ history.pushState(fullPathname, '', fullPathname)
139
+ } else if (action === 'replace') {
140
+ history.replaceState(fullPathname, '', fullPathname)
141
+ }
142
+
143
+ this.#updateLinks()
144
+
145
+ this.postprocessor?.({ pathname })
146
+ this.#navigationEvent.notify({ pathname })
147
+ }
148
+ }
149
+
150
+ #start = debounce(() => {
151
+ const slashesLength = (pathname: string) => {
152
+ return pathname.split('/').length
153
+ }
154
+
155
+ this.#routes = this.#routes.sort((a, b) => {
156
+ return slashesLength(a.pattern) - slashesLength(b.pattern)
157
+ })
158
+
159
+ this.navigate(location.pathname.replace(this.#base, ''))
160
+ }, 0)
161
+
162
+ #updateLinks() {
163
+ const activeRoutes = this.#routes.filter((r) => r.isActive)
164
+
165
+ const anchorElements = Array.from(
166
+ new Set(
167
+ [
168
+ ...this.#rootElement.querySelectorAll('a'),
169
+ ...activeRoutes.map((r) => r.getAnchorElements()).flat(),
170
+ ].filter((a) => a.getAttribute('href')?.startsWith('/'))
171
+ )
172
+ )
173
+
174
+ this.#links.forEach((link) => {
175
+ link.destroy()
176
+ })
177
+
178
+ this.#links = anchorElements.map((element) => {
179
+ const link = new Link(this, element)
180
+
181
+ return link
182
+ })
183
+ }
184
+
185
+ #popStateListener = (event: PopStateEvent) => {
186
+ if (event.state) {
187
+ this.navigate(event.state, 'none')
188
+ }
189
+ }
190
+ }
@@ -0,0 +1,13 @@
1
+ export {
2
+ Router,
3
+ type RouterPreprocessorEntry,
4
+ type RouterPreprocessor,
5
+ type RouterPostprocessor,
6
+ type RouterAfterNavigationCallback,
7
+ type RouterHistoryAction,
8
+ type RouterParameters,
9
+ } from './Router'
10
+
11
+ export { RouteElement, type RouteParameters, type RouteURLParams } from './RouteElement'
12
+
13
+ export { type RouteModule } from './Route'