lecodes-cli 0.19.0 → 0.19.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 (254) hide show
  1. package/dist/index.js +730 -235
  2. package/package.json +14 -13
  3. package/runtime/scene-harness.json +1 -1
  4. package/runtime/sdk-types.json +1 -1
  5. package/src/api.ts +302 -0
  6. package/src/browserAuth.ts +87 -0
  7. package/src/cmgenTool.ts +104 -0
  8. package/src/commands/app.ts +891 -0
  9. package/src/commands/appAndroid.ts +603 -0
  10. package/src/commands/appDesktop.ts +326 -0
  11. package/src/commands/appDesktopMac.ts +470 -0
  12. package/src/commands/appIcon.ts +187 -0
  13. package/src/commands/appShared.ts +448 -0
  14. package/src/commands/appTemplates.ts +883 -0
  15. package/src/commands/appTemplatesAndroid.ts +599 -0
  16. package/src/commands/appTemplatesGradlew.ts +9 -0
  17. package/src/commands/assets.ts +28 -0
  18. package/src/commands/clone.ts +60 -0
  19. package/src/commands/compile.ts +253 -0
  20. package/src/commands/create.ts +59 -0
  21. package/src/commands/design.ts +863 -0
  22. package/src/commands/designTemplates.ts +11 -0
  23. package/src/commands/desktop.ts +122 -0
  24. package/src/commands/dev.ts +214 -0
  25. package/src/commands/diff.ts +59 -0
  26. package/src/commands/init.ts +191 -0
  27. package/src/commands/install.ts +198 -0
  28. package/src/commands/lightmap.ts +290 -0
  29. package/src/commands/link.ts +147 -0
  30. package/src/commands/login.ts +24 -0
  31. package/src/commands/navmesh.ts +225 -0
  32. package/src/commands/pn.ts +305 -0
  33. package/src/commands/projectTemplates.ts +129 -0
  34. package/src/commands/pull.ts +109 -0
  35. package/src/commands/push.ts +173 -0
  36. package/src/commands/render.ts +414 -0
  37. package/src/commands/scene.ts +148 -0
  38. package/src/commands/shaders.ts +157 -0
  39. package/src/commands/status.ts +29 -0
  40. package/src/commands/test.ts +370 -0
  41. package/src/commands/thumbs.ts +178 -0
  42. package/src/commands/types.ts +87 -0
  43. package/src/commands/update.ts +190 -0
  44. package/src/compile/assetIcons.ts +214 -0
  45. package/src/compile/collect.ts +46 -0
  46. package/src/compile/collectLocal.ts +37 -0
  47. package/src/compile/designCompile.ts +104 -0
  48. package/src/compile/fonts.ts +156 -0
  49. package/src/compile/headlessBundle.ts +129 -0
  50. package/src/compile/nativeStack.ts +21 -0
  51. package/src/compile/projectCompile.ts +109 -0
  52. package/src/compile/sceneCompile.ts +113 -0
  53. package/src/compile/screenEntry.ts +127 -0
  54. package/src/compile/shaders.ts +245 -0
  55. package/src/config.ts +42 -0
  56. package/src/designMeta.ts +35 -0
  57. package/src/desktopRenderer.ts +532 -0
  58. package/src/desktopScript.ts +276 -0
  59. package/src/dev/clientTemplates.ts +160 -0
  60. package/src/dev/devServer.ts +292 -0
  61. package/src/dev/wsServer.ts +144 -0
  62. package/src/distRoot.ts +20 -0
  63. package/src/ignore.ts +163 -0
  64. package/src/index.ts +491 -0
  65. package/src/lecodes-3d-editor.d.ts +41 -0
  66. package/src/lecodes-assets.d.ts +7 -0
  67. package/src/lecodes-design.d.ts +191 -0
  68. package/src/lecodes-renderer.d.ts +131 -0
  69. package/src/localFiles.ts +144 -0
  70. package/src/manifest.ts +46 -0
  71. package/src/matcTool.ts +137 -0
  72. package/src/peers.ts +40 -0
  73. package/src/project.ts +61 -0
  74. package/src/projectEnv.ts +94 -0
  75. package/src/qrcode-terminal.d.ts +9 -0
  76. package/src/releases.ts +125 -0
  77. package/src/serverDiff.ts +78 -0
  78. package/src/textDiff.ts +103 -0
  79. package/src/types.ts +0 -0
  80. package/src/util.ts +146 -0
  81. package/runtime/sdk/animate/animate.ts +0 -238
  82. package/runtime/sdk/animate/bezier.ts +0 -138
  83. package/runtime/sdk/animate/easings.ts +0 -126
  84. package/runtime/sdk/canvas/Canvas.ts +0 -305
  85. package/runtime/sdk/compile/aspectMacro.ts +0 -86
  86. package/runtime/sdk/compile/assetIconMacro.ts +0 -384
  87. package/runtime/sdk/compile/assetMacro.ts +0 -146
  88. package/runtime/sdk/compile/assetName.ts +0 -50
  89. package/runtime/sdk/compile/bundler.ts +0 -287
  90. package/runtime/sdk/compile/compileProject.ts +0 -129
  91. package/runtime/sdk/compile/detectEntry.ts +0 -128
  92. package/runtime/sdk/compile/fontMacro.ts +0 -459
  93. package/runtime/sdk/compile/fontRegistry.ts +0 -78
  94. package/runtime/sdk/compile/header.ts +0 -67
  95. package/runtime/sdk/compile/index.ts +0 -100
  96. package/runtime/sdk/compile/libraryImports.ts +0 -52
  97. package/runtime/sdk/compile/liteMaterial.ts +0 -247
  98. package/runtime/sdk/compile/sceneEditor.ts +0 -88
  99. package/runtime/sdk/compile/serverSplit.ts +0 -233
  100. package/runtime/sdk/compile/serverTypes.ts +0 -227
  101. package/runtime/sdk/compile/sfnt.ts +0 -98
  102. package/runtime/sdk/compile/shaderSchema.ts +0 -202
  103. package/runtime/sdk/compile/shaderTargets.ts +0 -81
  104. package/runtime/sdk/compile/sourcemap.ts +0 -25
  105. package/runtime/sdk/core/Aspect.ts +0 -568
  106. package/runtime/sdk/core/InspectorUI.ts +0 -212
  107. package/runtime/sdk/core/StateMachine.ts +0 -308
  108. package/runtime/sdk/core/color.ts +0 -66
  109. package/runtime/sdk/core/compWrite.ts +0 -42
  110. package/runtime/sdk/core/events.ts +0 -38
  111. package/runtime/sdk/core/fields.ts +0 -120
  112. package/runtime/sdk/core/registry.ts +0 -23
  113. package/runtime/sdk/core/signals.ts +0 -277
  114. package/runtime/sdk/core/time.ts +0 -84
  115. package/runtime/sdk/g2/Camera2D.ts +0 -40
  116. package/runtime/sdk/g2/CharacterController2D.ts +0 -276
  117. package/runtime/sdk/g2/Node2D.ts +0 -267
  118. package/runtime/sdk/g2/OneWay2D.ts +0 -66
  119. package/runtime/sdk/g2/Physics2D.ts +0 -346
  120. package/runtime/sdk/g2/Scene2D.ts +0 -209
  121. package/runtime/sdk/g2/Shape2D.ts +0 -259
  122. package/runtime/sdk/g2/Sprite.ts +0 -89
  123. package/runtime/sdk/g2/SpriteAnimation.ts +0 -171
  124. package/runtime/sdk/g2/SpriteSheet.ts +0 -166
  125. package/runtime/sdk/g2/Texture2D.ts +0 -47
  126. package/runtime/sdk/g2/Tilemap.ts +0 -41
  127. package/runtime/sdk/g2/Tileset.ts +0 -71
  128. package/runtime/sdk/g2/Trigger2D.ts +0 -77
  129. package/runtime/sdk/g2/autotile.ts +0 -433
  130. package/runtime/sdk/g2/cells.ts +0 -91
  131. package/runtime/sdk/g2/defineScene2d.ts +0 -381
  132. package/runtime/sdk/g2/groups2d.ts +0 -106
  133. package/runtime/sdk/g2/loop.ts +0 -50
  134. package/runtime/sdk/g2/scenarios2d.ts +0 -69
  135. package/runtime/sdk/g2/touch.ts +0 -83
  136. package/runtime/sdk/gl/Camera.ts +0 -160
  137. package/runtime/sdk/gl/CameraPlace.ts +0 -52
  138. package/runtime/sdk/gl/CharacterController.ts +0 -238
  139. package/runtime/sdk/gl/Gearbox.ts +0 -212
  140. package/runtime/sdk/gl/Geometry.ts +0 -279
  141. package/runtime/sdk/gl/IK.ts +0 -193
  142. package/runtime/sdk/gl/InstancedMesh.ts +0 -132
  143. package/runtime/sdk/gl/Light.ts +0 -107
  144. package/runtime/sdk/gl/Lightmap.ts +0 -256
  145. package/runtime/sdk/gl/Material.ts +0 -260
  146. package/runtime/sdk/gl/Mesh.ts +0 -83
  147. package/runtime/sdk/gl/Model.ts +0 -124
  148. package/runtime/sdk/gl/NavAgent.ts +0 -337
  149. package/runtime/sdk/gl/NavMesh.ts +0 -397
  150. package/runtime/sdk/gl/Node.ts +0 -350
  151. package/runtime/sdk/gl/Noise.ts +0 -30
  152. package/runtime/sdk/gl/Particles.ts +0 -676
  153. package/runtime/sdk/gl/Physics.ts +0 -222
  154. package/runtime/sdk/gl/Plane.ts +0 -53
  155. package/runtime/sdk/gl/Ragdoll.ts +0 -270
  156. package/runtime/sdk/gl/Ray.ts +0 -16
  157. package/runtime/sdk/gl/Scene.ts +0 -486
  158. package/runtime/sdk/gl/Shape.ts +0 -409
  159. package/runtime/sdk/gl/Terrain.ts +0 -1092
  160. package/runtime/sdk/gl/Texture.ts +0 -63
  161. package/runtime/sdk/gl/Trigger.ts +0 -45
  162. package/runtime/sdk/gl/Vehicle.ts +0 -473
  163. package/runtime/sdk/gl/Wheel.ts +0 -240
  164. package/runtime/sdk/gl/animation/AnimationClip.ts +0 -204
  165. package/runtime/sdk/gl/animation/Animator.ts +0 -120
  166. package/runtime/sdk/gl/animation/Layer.ts +0 -31
  167. package/runtime/sdk/gl/animation/Loop.ts +0 -30
  168. package/runtime/sdk/gl/animation/Playback.ts +0 -44
  169. package/runtime/sdk/gl/animation/core.ts +0 -336
  170. package/runtime/sdk/gl/controls.ts +0 -95
  171. package/runtime/sdk/gl/physicsEvents.ts +0 -20
  172. package/runtime/sdk/gl/scenarios.ts +0 -291
  173. package/runtime/sdk/gl/state.ts +0 -6
  174. package/runtime/sdk/gl/terrainMesh.ts +0 -219
  175. package/runtime/sdk/gl/touch.ts +0 -68
  176. package/runtime/sdk/inject.ts +0 -197
  177. package/runtime/sdk/math/Mathf.ts +0 -118
  178. package/runtime/sdk/math/mat4.ts +0 -278
  179. package/runtime/sdk/math/quat.ts +0 -232
  180. package/runtime/sdk/math/vec.ts +0 -255
  181. package/runtime/sdk/net/codec.ts +0 -119
  182. package/runtime/sdk/net/core.ts +0 -384
  183. package/runtime/sdk/net/index.ts +0 -181
  184. package/runtime/sdk/net/replication.ts +0 -622
  185. package/runtime/sdk/plugins/camera.ts +0 -81
  186. package/runtime/sdk/plugins/geolocation.ts +0 -123
  187. package/runtime/sdk/plugins/oauth.ts +0 -61
  188. package/runtime/sdk/plugins/permission.ts +0 -7
  189. package/runtime/sdk/plugins/push.ts +0 -132
  190. package/runtime/sdk/plugins/qr.ts +0 -73
  191. package/runtime/sdk/plugins/service.ts +0 -47
  192. package/runtime/sdk/runtime/app.ts +0 -101
  193. package/runtime/sdk/runtime/appEvents.ts +0 -54
  194. package/runtime/sdk/runtime/channel.ts +0 -61
  195. package/runtime/sdk/runtime/clipboard.ts +0 -20
  196. package/runtime/sdk/runtime/datetime.ts +0 -329
  197. package/runtime/sdk/runtime/device.ts +0 -293
  198. package/runtime/sdk/runtime/fetch.ts +0 -77
  199. package/runtime/sdk/runtime/files.ts +0 -23
  200. package/runtime/sdk/runtime/input.ts +0 -175
  201. package/runtime/sdk/runtime/media.ts +0 -111
  202. package/runtime/sdk/runtime/misc.ts +0 -16
  203. package/runtime/sdk/runtime/net.ts +0 -36
  204. package/runtime/sdk/runtime/rpc.ts +0 -218
  205. package/runtime/sdk/runtime/service.ts +0 -83
  206. package/runtime/sdk/runtime/share.ts +0 -9
  207. package/runtime/sdk/runtime/storage.ts +0 -13
  208. package/runtime/sdk/runtime/touch.ts +0 -76
  209. package/runtime/sdk/scene/defineScene.ts +0 -1353
  210. package/runtime/sdk/scene/editorPlugins.ts +0 -110
  211. package/runtime/sdk/scene/gizmos.ts +0 -148
  212. package/runtime/sdk/scene/grammar.ts +0 -120
  213. package/runtime/sdk/scene/material.ts +0 -188
  214. package/runtime/sdk/server/auth/appConfig.ts +0 -12
  215. package/runtime/sdk/server/auth/global.ts +0 -80
  216. package/runtime/sdk/server/auth/host.ts +0 -318
  217. package/runtime/sdk/server/auth/models.ts +0 -83
  218. package/runtime/sdk/server/auth/types.ts +0 -50
  219. package/runtime/sdk/server/channel.ts +0 -56
  220. package/runtime/sdk/server/context.ts +0 -36
  221. package/runtime/sdk/server/db/defineDb.ts +0 -237
  222. package/runtime/sdk/server/db/fields.ts +0 -132
  223. package/runtime/sdk/server/db/httpTransport.ts +0 -93
  224. package/runtime/sdk/server/db/index.ts +0 -7
  225. package/runtime/sdk/server/db/marci/query.ts +0 -412
  226. package/runtime/sdk/server/db/types.ts +0 -202
  227. package/runtime/sdk/server/errors.ts +0 -12
  228. package/runtime/sdk/server/host.ts +0 -74
  229. package/runtime/sdk/server/inject.ts +0 -13
  230. package/runtime/sdk/server/runtime.ts +0 -133
  231. package/runtime/sdk/server/validate.ts +0 -87
  232. package/runtime/sdk/ui/NativeView.ts +0 -142
  233. package/runtime/sdk/ui/UI.ts +0 -39
  234. package/runtime/sdk/ui/UIBottomSheet.ts +0 -139
  235. package/runtime/sdk/ui/UIButton.ts +0 -101
  236. package/runtime/sdk/ui/UIContainer.ts +0 -60
  237. package/runtime/sdk/ui/UIImage.ts +0 -83
  238. package/runtime/sdk/ui/UIInput.ts +0 -185
  239. package/runtime/sdk/ui/UIModal.ts +0 -139
  240. package/runtime/sdk/ui/UINode.ts +0 -830
  241. package/runtime/sdk/ui/UIPager.ts +0 -362
  242. package/runtime/sdk/ui/UIPopover.ts +0 -100
  243. package/runtime/sdk/ui/UIScreen.ts +0 -123
  244. package/runtime/sdk/ui/UIScrollable.ts +0 -87
  245. package/runtime/sdk/ui/UISpacer.ts +0 -14
  246. package/runtime/sdk/ui/UITabs.ts +0 -236
  247. package/runtime/sdk/ui/UIText.ts +0 -51
  248. package/runtime/sdk/ui/UIVideo.ts +0 -88
  249. package/runtime/sdk/ui/UIVirtualizedList.ts +0 -241
  250. package/runtime/sdk/ui/UIWidget.ts +0 -127
  251. package/runtime/sdk/ui/fonts.ts +0 -13
  252. package/runtime/sdk/ui/presentable.ts +0 -117
  253. package/runtime/sdk/ui/router.ts +0 -132
  254. package/runtime/sdk/ui/theme.ts +0 -84
@@ -1,238 +0,0 @@
1
- // animate self-implements its matrix decompose/recompose; these are just the numeric-array shapes.
2
- type mat4 = Float32Array | number[]
3
- type quat = Float32Array | number[]
4
- type vec2 = Float32Array | number[]
5
- type vec3 = Float32Array | number[]
6
- import type { Easing } from "./easings"
7
-
8
- type AnimateProps = number | string | vec2 | vec3 | quat
9
-
10
- export type AnimateOptions<T> = {
11
- from: T,
12
- to: T,
13
- duration: number,
14
- onUpdate(val: T): void,
15
- onComplete?(): void,
16
- easing?: Easing,
17
- }
18
-
19
- export const animate = <T extends AnimateProps>(options: AnimateOptions<T>): number => {
20
-
21
- let onRawUpdate
22
- if (typeof options.to === "number") {
23
- const { onUpdate, from, to } = options as AnimateOptions<number>
24
- onRawUpdate = (t: number) => onUpdate(from + (to - from) * t)
25
- } else if (options.to === "string") {
26
- // TODO: Make color animate here
27
- const { onUpdate, from, to } = options as AnimateOptions<string>
28
- onRawUpdate = (t: number) => onUpdate(from)
29
-
30
- // onRawUpdate = (val: number) => onUpdate(from + (to - from) * val)
31
- } else if (options.to.length === 2) {
32
- const { onUpdate, from, to } = options as AnimateOptions<vec2>
33
- const tempVec = new Float32Array(3)
34
- onRawUpdate = (t: number) => onUpdate(lerp2(tempVec, from, to, t))
35
-
36
- } else if (options.to.length === 3) {
37
- const { onUpdate, from, to } = options as AnimateOptions<vec3>
38
- const tempVec = new Float32Array(3)
39
-
40
- onRawUpdate = (t: number) => onUpdate(lerp(tempVec, from, to, t))
41
- } else if (options.to.length === 4) {
42
- const { onUpdate, from, to } = options as AnimateOptions<quat>
43
-
44
- const tempQuat = new Float32Array(4)
45
- onRawUpdate = (t: number) => onUpdate(slerp(tempQuat, from, to, t))
46
- } else {
47
- onRawUpdate = () => {}
48
- }
49
-
50
- const animationId = _creatorUtils.animate(val => {
51
- const _val = options.easing? options.easing(val): val
52
- onRawUpdate(_val)
53
- if (val === 1 && options.onComplete) {
54
- options.onComplete()
55
- }
56
- }, options.duration)
57
-
58
- return animationId
59
- }
60
-
61
- export const stopAnimation = (id: number): void => _creatorUtils.stopAnimation(id)
62
- export const pauseAnimation = (id: number): void => _creatorUtils.pauseAnimation(id)
63
- export const resumeAnimation = (id: number): void => _creatorUtils.resumeAnimation(id)
64
-
65
- export const animateMat4 = (options: AnimateOptions<mat4>): number => {
66
- const fromPosition = new Float32Array(3)
67
- const fromQuaternion = new Float32Array(4)
68
- const fromScale = new Float32Array(3)
69
- const toPosition = new Float32Array(3)
70
- const toQuaternion = new Float32Array(4)
71
- const toScale = new Float32Array(3)
72
- decompose(fromQuaternion, fromPosition, fromScale, (options as AnimateOptions<mat4>).from)
73
- decompose(toQuaternion, toPosition, toScale, (options as AnimateOptions<mat4>).to)
74
-
75
- const tempPosition = new Float32Array(3)
76
- const tempQuat = new Float32Array(4)
77
- const tempScale = new Float32Array(3)
78
- const tempMat = new Float32Array(16)
79
-
80
- const onUpdate = (options as AnimateOptions<mat4>).onUpdate
81
- const onRawUpdate = (t: number) => {
82
- lerp(tempPosition, fromPosition, toPosition, t)
83
- slerp(tempQuat, fromQuaternion, toQuaternion, t)
84
- lerp(tempScale, fromScale, toScale, t)
85
-
86
- onUpdate(fromRotationTranslationScale(tempMat, tempQuat, tempPosition, tempScale))
87
- }
88
-
89
- const animationId = _creatorUtils.animate(val => {
90
- const _val = options.easing? options.easing(val): val
91
- onRawUpdate(_val)
92
- if (val === 1 && options.onComplete) {
93
- options.onComplete()
94
- }
95
- }, options.duration)
96
-
97
- return animationId
98
- }
99
-
100
- const EPSILON = 1e-6;
101
- function slerp(out: quat, a: quat, b: quat, t: number) {
102
- const ax = a[0], ay = a[1], az = a[2], aw = a[3];
103
- let bx = b[0], by = b[1], bz = b[2], bw = b[3];
104
- let omega, cosom, sinom, scale0, scale1;
105
- cosom = ax * bx + ay * by + az * bz + aw * bw;
106
- if (cosom < 0) {
107
- cosom = -cosom;
108
- bx = -bx;
109
- by = -by;
110
- bz = -bz;
111
- bw = -bw;
112
- }
113
- if (1 - cosom > EPSILON) {
114
- omega = Math.acos(cosom);
115
- sinom = Math.sin(omega);
116
- scale0 = Math.sin((1 - t) * omega) / sinom;
117
- scale1 = Math.sin(t * omega) / sinom;
118
- } else {
119
- scale0 = 1 - t;
120
- scale1 = t;
121
- }
122
- out[0] = scale0 * ax + scale1 * bx;
123
- out[1] = scale0 * ay + scale1 * by;
124
- out[2] = scale0 * az + scale1 * bz;
125
- out[3] = scale0 * aw + scale1 * bw;
126
- return out;
127
- }
128
- function lerp(out: vec3, a: vec3, b: vec3, t: number) {
129
- const ax = a[0];
130
- const ay = a[1];
131
- const az = a[2];
132
- out[0] = ax + t * (b[0] - ax);
133
- out[1] = ay + t * (b[1] - ay);
134
- out[2] = az + t * (b[2] - az);
135
- return out;
136
- }
137
-
138
- function lerp2(out: vec2, a: vec2, b: vec2, t: number) {
139
- const ax = a[0];
140
- const ay = a[1];
141
- const az = a[2];
142
- out[0] = ax + t * (b[0] - ax);
143
- out[1] = ay + t * (b[1] - ay);
144
- return out;
145
- }
146
- function fromRotationTranslationScale(out: mat4, q: quat, v: vec3, s: vec3) {
147
- const x = q[0], y = q[1], z = q[2], w = q[3];
148
- const x2 = x + x;
149
- const y2 = y + y;
150
- const z2 = z + z;
151
- const xx = x * x2;
152
- const xy = x * y2;
153
- const xz = x * z2;
154
- const yy = y * y2;
155
- const yz = y * z2;
156
- const zz = z * z2;
157
- const wx = w * x2;
158
- const wy = w * y2;
159
- const wz = w * z2;
160
- const sx = s[0];
161
- const sy = s[1];
162
- const sz = s[2];
163
- out[0] = (1 - (yy + zz)) * sx;
164
- out[1] = (xy + wz) * sx;
165
- out[2] = (xz - wy) * sx;
166
- out[3] = 0;
167
- out[4] = (xy - wz) * sy;
168
- out[5] = (1 - (xx + zz)) * sy;
169
- out[6] = (yz + wx) * sy;
170
- out[7] = 0;
171
- out[8] = (xz + wy) * sz;
172
- out[9] = (yz - wx) * sz;
173
- out[10] = (1 - (xx + yy)) * sz;
174
- out[11] = 0;
175
- out[12] = v[0];
176
- out[13] = v[1];
177
- out[14] = v[2];
178
- out[15] = 1;
179
- return out;
180
- }
181
-
182
- function decompose(out_r: mat4, out_t: vec3, out_s: vec3, mat: mat4) {
183
- out_t[0] = mat[12];
184
- out_t[1] = mat[13];
185
- out_t[2] = mat[14];
186
- const m11 = mat[0];
187
- const m12 = mat[1];
188
- const m13 = mat[2];
189
- const m21 = mat[4];
190
- const m22 = mat[5];
191
- const m23 = mat[6];
192
- const m31 = mat[8];
193
- const m32 = mat[9];
194
- const m33 = mat[10];
195
- out_s[0] = Math.hypot(m11, m12, m13);
196
- out_s[1] = Math.hypot(m21, m22, m23);
197
- out_s[2] = Math.hypot(m31, m32, m33);
198
- const is1 = 1 / out_s[0];
199
- const is2 = 1 / out_s[1];
200
- const is3 = 1 / out_s[2];
201
- const sm11 = m11 * is1;
202
- const sm12 = m12 * is2;
203
- const sm13 = m13 * is3;
204
- const sm21 = m21 * is1;
205
- const sm22 = m22 * is2;
206
- const sm23 = m23 * is3;
207
- const sm31 = m31 * is1;
208
- const sm32 = m32 * is2;
209
- const sm33 = m33 * is3;
210
- const trace = sm11 + sm22 + sm33;
211
- let S = 0;
212
- if (trace > 0) {
213
- S = Math.sqrt(trace + 1) * 2;
214
- out_r[3] = 0.25 * S;
215
- out_r[0] = (sm23 - sm32) / S;
216
- out_r[1] = (sm31 - sm13) / S;
217
- out_r[2] = (sm12 - sm21) / S;
218
- } else if (sm11 > sm22 && sm11 > sm33) {
219
- S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
220
- out_r[3] = (sm23 - sm32) / S;
221
- out_r[0] = 0.25 * S;
222
- out_r[1] = (sm12 + sm21) / S;
223
- out_r[2] = (sm31 + sm13) / S;
224
- } else if (sm22 > sm33) {
225
- S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
226
- out_r[3] = (sm31 - sm13) / S;
227
- out_r[0] = (sm12 + sm21) / S;
228
- out_r[1] = 0.25 * S;
229
- out_r[2] = (sm23 + sm32) / S;
230
- } else {
231
- S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
232
- out_r[3] = (sm12 - sm21) / S;
233
- out_r[0] = (sm31 + sm13) / S;
234
- out_r[1] = (sm23 + sm32) / S;
235
- out_r[2] = 0.25 * S;
236
- }
237
- return out_r;
238
- }
@@ -1,138 +0,0 @@
1
- /*
2
- Bezier function generator
3
-
4
- Gaëtan Renaudeau's BezierEasing
5
- https://github.com/gre/bezier-easing/blob/master/src/index.js
6
- https://github.com/gre/bezier-easing/blob/master/LICENSE
7
- You're a hero
8
-
9
- Use
10
-
11
- const easeOut = cubicBezier(.17,.67,.83,.67);
12
- const x = easeOut(0.5); // returns 0.627...
13
- */
14
-
15
- import type { Easing } from "./easings"
16
-
17
- const a = (a1: number, a2: number) => 1.0 - 3.0 * a2 + 3.0 * a1
18
- const b = (a1: number, a2: number) => 3.0 * a2 - 6.0 * a1
19
- const c = (a1: number) => 3.0 * a1
20
-
21
- // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
22
- const calcBezier = (t: number, a1: number, a2: number) =>
23
- ((a(a1, a2) * t + b(a1, a2)) * t + c(a1)) * t
24
-
25
- // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
26
- const getSlope = (t: number, a1: number, a2: number) =>
27
- 3.0 * a(a1, a2) * t * t + 2.0 * b(a1, a2) * t + c(a1)
28
-
29
- const subdivisionPrecision = 0.0000001
30
- const subdivisionMaxIterations = 10
31
-
32
- function binarySubdivide(
33
- aX: number,
34
- aA: number,
35
- aB: number,
36
- mX1: number,
37
- mX2: number
38
- ) {
39
- let currentX: number
40
- let currentT: number
41
- let i: number = 0
42
-
43
- do {
44
- currentT = aA + (aB - aA) / 2.0
45
- currentX = calcBezier(currentT, mX1, mX2) - aX
46
- if (currentX > 0.0) {
47
- aB = currentT
48
- } else {
49
- aA = currentT
50
- }
51
- } while (
52
- Math.abs(currentX) > subdivisionPrecision &&
53
- ++i < subdivisionMaxIterations
54
- )
55
-
56
- return currentT
57
- }
58
-
59
- const newtonIterations = 8
60
- const newtonMinSlope = 0.001
61
- function newtonRaphsonIterate(
62
- aX: number,
63
- aGuessT: number,
64
- mX1: number,
65
- mX2: number
66
- ) {
67
- for (let i = 0; i < newtonIterations; ++i) {
68
- const currentSlope = getSlope(aGuessT, mX1, mX2)
69
- if (currentSlope === 0.0) {
70
- return aGuessT
71
- }
72
- const currentX = calcBezier(aGuessT, mX1, mX2) - aX
73
- aGuessT -= currentX / currentSlope
74
- }
75
- return aGuessT
76
- }
77
-
78
- const kSplineTableSize = 11
79
- const kSampleStepSize = 1.0 / (kSplineTableSize - 1.0)
80
-
81
- const linear: Easing = p => p
82
-
83
- export function cubicBezier(
84
- mX1: number,
85
- mY1: number,
86
- mX2: number,
87
- mY2: number
88
- ): Easing {
89
- // If this is a linear gradient, return linear easing
90
- if (mX1 === mY1 && mX2 === mY2) return linear
91
-
92
- // Precompute samples table
93
- const sampleValues = new Float32Array(kSplineTableSize)
94
-
95
- for (let i = 0; i < kSplineTableSize; ++i) {
96
- sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2)
97
- }
98
-
99
- function getTForX(aX: number) {
100
- let intervalStart = 0.0
101
- let currentSample = 1
102
- const lastSample = kSplineTableSize - 1
103
-
104
- for (
105
- ;
106
- currentSample !== lastSample && sampleValues[currentSample] <= aX;
107
- ++currentSample
108
- ) {
109
- intervalStart += kSampleStepSize
110
- }
111
- --currentSample
112
-
113
- // Interpolate to provide an initial guess for t
114
- const dist =
115
- (aX - sampleValues[currentSample]) /
116
- (sampleValues[currentSample + 1] - sampleValues[currentSample])
117
- const guessForT = intervalStart + dist * kSampleStepSize
118
-
119
- const initialSlope = getSlope(guessForT, mX1, mX2)
120
- if (initialSlope >= newtonMinSlope) {
121
- return newtonRaphsonIterate(aX, guessForT, mX1, mX2)
122
- } else if (initialSlope === 0.0) {
123
- return guessForT
124
- } else {
125
- return binarySubdivide(
126
- aX,
127
- intervalStart,
128
- intervalStart + kSampleStepSize,
129
- mX1,
130
- mX2
131
- )
132
- }
133
- }
134
-
135
- // If animation is at start/end, return t without easing
136
- return (t: number) =>
137
- t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2)
138
- }
@@ -1,126 +0,0 @@
1
- export type Easing = (v: number) => number
2
- export type EasingModifier = (easing: Easing) => Easing
3
-
4
- const DEFAULT_OVERSHOOT_STRENGTH = 1.525
5
- const BOUNCE_FIRST_THRESHOLD = 4.0 / 11.0
6
- const BOUNCE_SECOND_THRESHOLD = 8.0 / 11.0
7
- const BOUNCE_THIRD_THRESHOLD = 9.0 / 10.0
8
-
9
- // helper constants
10
- const ca = 4356.0 / 361.0
11
- const cb = 35442.0 / 1805.0
12
- const cc = 16061.0 / 1805.0
13
-
14
- export function linear(p: number): number {
15
- return p
16
- }
17
-
18
- export function bounceOut(p: number): number {
19
- if (p === 1 || p === 0) return p
20
- const p2 = p * p
21
-
22
- return p < BOUNCE_FIRST_THRESHOLD
23
- ? 7.5625 * p2
24
- : p < BOUNCE_SECOND_THRESHOLD
25
- ? 9.075 * p2 - 9.9 * p + 3.4
26
- : p < BOUNCE_THIRD_THRESHOLD
27
- ? ca * p2 - cb * p + cc
28
- : 10.8 * p * p - 20.52 * p + 10.72
29
- }
30
-
31
- export function bounceInOut(p: number): number {
32
- return p < 0.5
33
- ? 0.5 * (1.0 - bounceOut(1.0 - p * 2.0))
34
- : 0.5 * bounceOut(p * 2.0 - 1.0) + 0.5
35
- }
36
-
37
- // Accepts an easing function and returns a new one that outputs reversed values.
38
- // Turns easeIn into easeOut.
39
- export function reverseEasing(easing: Easing): Easing {
40
- return p => 1 - easing(1 - p)
41
- }
42
-
43
- // Accepts an easing function and returns a new one that outputs mirrored values for
44
- // the second half of the animation. Turns easeIn into easeInOut.
45
- export function mirrorEasing(easing: Easing): Easing {
46
- return p => (p <= 0.5 ? easing(2 * p) / 2 : (2 - easing(2 * (1 - p))) / 2)
47
- }
48
-
49
- // Creates an easing function that is based on the exponent of the provided `power`.
50
- // The higher the `power`, the stronger the easing.
51
- export function createExpoIn(power: number): Easing {
52
- return p => p ** power
53
- }
54
-
55
- // Creates an easing function that has a stronger overshoot the higher the provided `power`.
56
- export function createBackIn(power: number): Easing {
57
- return p => p * p * ((power + 1) * p - power)
58
- }
59
-
60
- // Creates an easing function that pulls back a little before moving, and then
61
- // has a `createBackIn`-based overshoot
62
- export function createAnticipate(power: number): Easing {
63
- const backEasing = createBackIn(power)
64
-
65
- return p =>
66
- (p *= 2) < 1
67
- ? 0.5 * backEasing(p)
68
- : 0.5 * (2 - Math.pow(2, -10 * (p - 1)))
69
- }
70
-
71
- export function bounceIn(p: number): number {
72
- return 1 - bounceOut(1 - p)
73
- }
74
-
75
- export function easeIn(p: number): number {
76
- return p * p
77
- }
78
-
79
- export function easeOut(p: number): number {
80
- return 1 - easeIn(1 - p)
81
- }
82
-
83
- export function easeInOut(p: number): number {
84
- return p <= 0.5
85
- ? easeIn(2 * p) / 2
86
- : (2 - easeIn(2 * (1 - p))) / 2
87
- }
88
-
89
- export function circIn(p: number): number {
90
- return 1 - Math.sin(Math.acos(p))
91
- }
92
-
93
- export function circOut(p: number): number {
94
- return 1 - circIn(1 - p)
95
- }
96
-
97
- export function circInOut(p: number): number {
98
- return p <= 0.5
99
- ? circOut(2 * p) / 2
100
- : (2 - circOut(2 * (1 - p))) / 2
101
- }
102
-
103
- export function backIn(p: number): number {
104
- const power = DEFAULT_OVERSHOOT_STRENGTH
105
- return p * p * ((power + 1) * p - power)
106
- }
107
-
108
- export function backOut(p: number): number {
109
- return 1 - backIn(1 - p)
110
- }
111
-
112
- export function backInOut(p: number): number {
113
- return p <= 0.5
114
- ? backIn(2 * p) / 2
115
- : (2 - backIn(2 * (1 - p))) / 2
116
- }
117
-
118
- export function anticipate(p: number): number {
119
- const doubled = p * 2
120
-
121
- if (doubled < 1) {
122
- return 0.5 * backIn(doubled)
123
- }
124
-
125
- return 0.5 * (2 - Math.pow(2, -10 * (doubled - 1)))
126
- }