sard-uniapp 1.2.1-alpha2 → 1.2.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.
package/changelog.md CHANGED
@@ -1,4 +1,10 @@
1
- ## [1.2.1-alpha2](https://github.com/sutras/sard-uniapp/compare/v1.2.0...v1.2.1-alpha2) (2024-07-12)
1
+ ## [1.2.2](https://github.com/sutras/sard-uniapp/compare/v1.2.0...v1.2.2) (2024-07-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 修复pnpm非扁平化依赖包下lwa依赖问题 close [#32](https://github.com/sutras/sard-uniapp/issues/32) ([5868e16](https://github.com/sutras/sard-uniapp/commit/5868e16587e8664705789e2e791c264f2a7d22f5))
7
+ * lwa copy ([7dc350a](https://github.com/sutras/sard-uniapp/commit/7dc350a09f3d10e4bf9f08733e70e1ec73d15b26))
2
8
 
3
9
 
4
10
 
@@ -5,9 +5,8 @@
5
5
  <script>
6
6
  import { mergeDefaults as _mergeDefaults, defineComponent as _defineComponent } from "vue";
7
7
  import { computed, onUnmounted, ref, watch } from "vue";
8
- import { addSeparator } from "../../utils";
8
+ import { addSeparator, createAnimation } from "../../utils";
9
9
  import { countToPropsDefaults } from "./common";
10
- import { createAnimation } from "lwa";
11
10
  export default _defineComponent({
12
11
  ...{
13
12
  options: {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "sard-uniapp",
3
3
  "name": "sard-uniapp",
4
4
  "displayName": "sard-uniapp",
5
- "version": "1.2.1-alpha2",
5
+ "version": "1.2.2",
6
6
  "type": "module",
7
7
  "description": "sard-uniapp 是一套基于 Uniapp + Vue3 框架开发的兼容多端的 UI 组件库",
8
8
  "keywords": [
@@ -26,8 +26,7 @@
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@dcloudio/types": "^3.4.8",
29
- "vue": "^3.4.27",
30
- "lwa": "0.2.3-alpha"
29
+ "vue": "^3.4.27"
31
30
  },
32
31
  "devDependencies": {
33
32
  "@sard/uniapp-cli": "workspace:*",
@@ -1,6 +1,5 @@
1
1
  import { computed, onScopeDispose, ref, unref } from 'vue';
2
- import { random } from '../utils';
3
- import { ticker } from 'lwa';
2
+ import { random, ticker } from '../utils';
4
3
  const defaultOptions = {
5
4
  minSpeed: 0.1,
6
5
  maxSpeed: 0.4,
package/utils/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from './dom';
5
5
  export * from './file';
6
6
  export * from './is';
7
7
  export * from './utils';
8
+ export * from './lwa.slim';
package/utils/index.js CHANGED
@@ -5,3 +5,4 @@ export * from './dom';
5
5
  export * from './file';
6
6
  export * from './is';
7
7
  export * from './utils';
8
+ export * from './lwa.slim';
@@ -0,0 +1,348 @@
1
+ declare function add(tick: () => void): void
2
+
3
+ declare interface AnimatedTarget {
4
+ target: object
5
+ index: number
6
+ total: number
7
+ }
8
+
9
+ declare type BaseValue = number | string
10
+
11
+ declare interface Between {
12
+ from: number
13
+ to: number
14
+ round: number
15
+ }
16
+
17
+ export declare function createAnimation(
18
+ target: string | unknown[] | object,
19
+ keyframes: Properties | Properties[],
20
+ options?: TweenOptions & TimelineOptions,
21
+ ): {
22
+ play: () => void
23
+ pause: () => void
24
+ finish: () => void
25
+ restart: () => void
26
+ seek: (nextPosition: number) => void
27
+ progress: (p: number) => void
28
+ tick: () => void
29
+ getPosition(): number
30
+ getDuration(): number
31
+ getProgress(): number
32
+ isReverse(): boolean
33
+ add: {
34
+ (
35
+ target: string | unknown[] | object,
36
+ keyframes: Properties | Properties[],
37
+ options?: TweenOptions,
38
+ position?: number | string,
39
+ ): any
40
+ (
41
+ target: string | unknown[] | object,
42
+ keyframes: Properties | Properties[],
43
+ position?: number | string,
44
+ ): any
45
+ (target: TimelineEventTarget, position?: number | string): any
46
+ }
47
+ remove: (target: TimelineEventTarget) => void
48
+ clear: () => void
49
+ events: TimelineEvent[]
50
+ on: <
51
+ U extends
52
+ | 'pause'
53
+ | 'play'
54
+ | 'complete'
55
+ | 'update'
56
+ | 'begin'
57
+ | 'loopBegin'
58
+ | 'loopComplete',
59
+ >(
60
+ type: U,
61
+ callback: {
62
+ begin: () => void
63
+ loopBegin: () => void
64
+ complete: () => void
65
+ loopComplete: () => void
66
+ pause: () => void
67
+ play: () => void
68
+ update: (position: number, progress: number) => void
69
+ }[U],
70
+ ) => void
71
+ off: <
72
+ U extends
73
+ | 'pause'
74
+ | 'play'
75
+ | 'complete'
76
+ | 'update'
77
+ | 'begin'
78
+ | 'loopBegin'
79
+ | 'loopComplete',
80
+ >(
81
+ type: U,
82
+ callback?:
83
+ | {
84
+ begin: () => void
85
+ loopBegin: () => void
86
+ complete: () => void
87
+ loopComplete: () => void
88
+ pause: () => void
89
+ play: () => void
90
+ update: (position: number, progress: number) => void
91
+ }[U]
92
+ | undefined,
93
+ ) => void
94
+ once: <
95
+ U extends
96
+ | 'pause'
97
+ | 'play'
98
+ | 'complete'
99
+ | 'update'
100
+ | 'begin'
101
+ | 'loopBegin'
102
+ | 'loopComplete',
103
+ >(
104
+ type: U,
105
+ callback: {
106
+ begin: () => void
107
+ loopBegin: () => void
108
+ complete: () => void
109
+ loopComplete: () => void
110
+ pause: () => void
111
+ play: () => void
112
+ update: (position: number, progress: number) => void
113
+ }[U],
114
+ ) => void
115
+ }
116
+
117
+ export declare function createTimeline(options?: TimelineOptions): {
118
+ play: () => void
119
+ pause: () => void
120
+ finish: () => void
121
+ restart: () => void
122
+ seek: (nextPosition: number) => void
123
+ progress: (p: number) => void
124
+ tick: () => void
125
+ getPosition(): number
126
+ getDuration(): number
127
+ getProgress(): number
128
+ isReverse(): boolean
129
+ add: {
130
+ (
131
+ target: string | unknown[] | object,
132
+ keyframes: Properties | Properties[],
133
+ options?: TweenOptions,
134
+ position?: number | string,
135
+ ): any
136
+ (
137
+ target: string | unknown[] | object,
138
+ keyframes: Properties | Properties[],
139
+ position?: number | string,
140
+ ): any
141
+ (target: TimelineEventTarget, position?: number | string): any
142
+ }
143
+ remove: (target: TimelineEventTarget) => void
144
+ clear: () => void
145
+ events: TimelineEvent[]
146
+ on: <
147
+ U extends
148
+ | 'pause'
149
+ | 'play'
150
+ | 'complete'
151
+ | 'update'
152
+ | 'begin'
153
+ | 'loopBegin'
154
+ | 'loopComplete',
155
+ >(
156
+ type: U,
157
+ callback: {
158
+ begin: () => void
159
+ loopBegin: () => void
160
+ complete: () => void
161
+ loopComplete: () => void
162
+ pause: () => void
163
+ play: () => void
164
+ update: (position: number, progress: number) => void
165
+ }[U],
166
+ ) => void
167
+ off: <
168
+ U extends
169
+ | 'pause'
170
+ | 'play'
171
+ | 'complete'
172
+ | 'update'
173
+ | 'begin'
174
+ | 'loopBegin'
175
+ | 'loopComplete',
176
+ >(
177
+ type: U,
178
+ callback?:
179
+ | {
180
+ begin: () => void
181
+ loopBegin: () => void
182
+ complete: () => void
183
+ loopComplete: () => void
184
+ pause: () => void
185
+ play: () => void
186
+ update: (position: number, progress: number) => void
187
+ }[U]
188
+ | undefined,
189
+ ) => void
190
+ once: <
191
+ U extends
192
+ | 'pause'
193
+ | 'play'
194
+ | 'complete'
195
+ | 'update'
196
+ | 'begin'
197
+ | 'loopBegin'
198
+ | 'loopComplete',
199
+ >(
200
+ type: U,
201
+ callback: {
202
+ begin: () => void
203
+ loopBegin: () => void
204
+ complete: () => void
205
+ loopComplete: () => void
206
+ pause: () => void
207
+ play: () => void
208
+ update: (position: number, progress: number) => void
209
+ }[U],
210
+ ) => void
211
+ }
212
+
213
+ declare type Direction =
214
+ | 'normal'
215
+ | 'reverse'
216
+ | 'alternate'
217
+ | 'alternate-reverse'
218
+
219
+ export declare type Easing =
220
+ | keyof typeof easings
221
+ | FunctionalValue<(k: number) => number>
222
+
223
+ export declare type Easings = {
224
+ linear: (...args: any[]) => (p: number) => number
225
+ } & {
226
+ [p in EasingStuffNames as `${'easeIn' | 'easeOut' | 'easeInOut'}${p}`]: (
227
+ ...args: any[]
228
+ ) => (p: number) => number
229
+ }
230
+
231
+ export declare const easings: Easings
232
+
233
+ declare type EasingStuffNames =
234
+ | 'Quad'
235
+ | 'Cubic'
236
+ | 'Quart'
237
+ | 'Quint'
238
+ | 'Sine'
239
+ | 'Expo'
240
+ | 'Circ'
241
+ | 'Elastic'
242
+ | 'Back'
243
+ | 'Bounce'
244
+
245
+ declare type FunctionalValue<T> = (
246
+ target: object,
247
+ index: number,
248
+ total: number,
249
+ ) => T
250
+
251
+ declare type MayFunctionValue<T> = T | FunctionalValue<T>
252
+
253
+ declare interface ObjectValue extends TweenOptions {
254
+ value: BaseValue | SpecialValue
255
+ }
256
+
257
+ export declare interface Properties {
258
+ [p: string]: Value
259
+ }
260
+
261
+ declare function remove(tick: () => void): void
262
+
263
+ declare type SingleValue = BaseValue | SpecialValue | ObjectValue
264
+
265
+ declare class SpecialValue {}
266
+
267
+ export declare const ticker: {
268
+ add: typeof add
269
+ remove: typeof remove
270
+ }
271
+
272
+ export declare type Timeline = ReturnType<typeof createTimeline>
273
+
274
+ declare interface TimelineCallbackOptions {
275
+ begin?: () => void
276
+ loopBegin?: () => void
277
+ complete?: () => void
278
+ loopComplete?: () => void
279
+ pause?: () => void
280
+ play?: () => void
281
+ update?: (position: number, progress: number) => void
282
+ }
283
+
284
+ declare interface TimelineEvent {
285
+ target: TimelineEventTarget
286
+ position: number | string
287
+ begin: number
288
+ end: number
289
+ }
290
+
291
+ declare interface TimelineEventTarget {
292
+ getDuration: () => number
293
+ seek: (position: number) => void
294
+ tweens?: Tween[]
295
+ events?: TimelineEvent[]
296
+ }
297
+
298
+ export declare interface TimelineOptions extends TimelineCallbackOptions {
299
+ externalTicker?: boolean
300
+ autoplay?: boolean
301
+ direction?: Direction
302
+ loop?: number
303
+ }
304
+
305
+ declare interface Tween<T extends {} = {}, U = {}> {
306
+ animatedTarget: AnimatedTarget & U
307
+ prop: string
308
+ duration: number
309
+ delay: number
310
+ endDelay: number
311
+ begin: number
312
+ end: number
313
+ easing: (k: number) => number
314
+ data: T
315
+ from: unknown
316
+ to: unknown
317
+ withoutFrom: boolean
318
+ round: number
319
+ unit: string
320
+ operator: string
321
+ between: Between[]
322
+ }
323
+
324
+ export declare interface TweenOptions {
325
+ duration?: number | FunctionalValue<number>
326
+ delay?: number | FunctionalValue<number>
327
+ endDelay?: number | FunctionalValue<number>
328
+ easing?: Easing
329
+ round?: number | FunctionalValue<number>
330
+ }
331
+
332
+ declare type Value = MayFunctionValue<SingleValue | SingleValue[]>
333
+
334
+ export declare function withFrom(
335
+ from: MayFunctionValue<BaseValue>,
336
+ to: MayFunctionValue<BaseValue>,
337
+ ): WithFromValue
338
+
339
+ declare class WithFromValue extends SpecialValue {
340
+ from: MayFunctionValue<BaseValue>
341
+ to: MayFunctionValue<BaseValue>
342
+ constructor(
343
+ from: MayFunctionValue<BaseValue>,
344
+ to: MayFunctionValue<BaseValue>,
345
+ )
346
+ }
347
+
348
+ export {}
@@ -0,0 +1,816 @@
1
+ /* lwa 0.2.3 | MIT license | https://github.com/sutras/lwa */
2
+ var __defProp = Object.defineProperty
3
+ var __pow = Math.pow
4
+ var __defNormalProp = (obj, key, value) =>
5
+ key in obj
6
+ ? __defProp(obj, key, {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value,
11
+ })
12
+ : (obj[key] = value)
13
+ var __publicField = (obj, key, value) =>
14
+ __defNormalProp(obj, typeof key !== 'symbol' ? key + '' : key, value)
15
+ function getAnimationFrameController() {
16
+ if (typeof requestAnimationFrame === 'function') {
17
+ return {
18
+ request: requestAnimationFrame,
19
+ cancel: cancelAnimationFrame,
20
+ }
21
+ }
22
+ const fps = 60
23
+ const callbacks = []
24
+ let id2 = 1
25
+ let cursor = 0
26
+ let timer
27
+ function playAll() {
28
+ timer = void 0
29
+ const cloned = callbacks.slice()
30
+ cursor += callbacks.length
31
+ callbacks.length = 0
32
+ cloned.forEach((callback) => {
33
+ if (callback !== 0) {
34
+ callback(Date.now())
35
+ }
36
+ })
37
+ }
38
+ return {
39
+ request(handler) {
40
+ callbacks.push(handler)
41
+ if (!timer) {
42
+ timer = setTimeout(playAll, 1e3 / fps)
43
+ }
44
+ return id2++
45
+ },
46
+ cancel(id22) {
47
+ callbacks[id22 - cursor] = 0
48
+ },
49
+ }
50
+ }
51
+ const { request, cancel } = getAnimationFrameController()
52
+ const ticks = /* @__PURE__ */ new Set()
53
+ let id = 0
54
+ let paused = true
55
+ function add(tick) {
56
+ ticks.add(tick)
57
+ run()
58
+ }
59
+ function remove(tick) {
60
+ ticks.delete(tick)
61
+ }
62
+ function step() {
63
+ if (ticks.size === 0) {
64
+ stop()
65
+ } else {
66
+ new Set(ticks).forEach((tick) => tick())
67
+ id = request(step)
68
+ }
69
+ }
70
+ function run() {
71
+ if (paused) {
72
+ paused = false
73
+ id = request(step)
74
+ }
75
+ }
76
+ function stop() {
77
+ if (!paused) {
78
+ paused = true
79
+ cancel(id)
80
+ }
81
+ }
82
+ const ticker = {
83
+ add,
84
+ remove,
85
+ }
86
+ const easings = {
87
+ linear: () => (p) => p,
88
+ }
89
+ const easingStuff = {
90
+ Sine: () => (p) => 1 - Math.cos((p * Math.PI) / 2),
91
+ Expo: () => (p) => p ? Math.pow(1024, p - 1) : 0,
92
+ Circ: () => (p) => 1 - Math.sqrt(1 - p * p),
93
+ Elastic: () => (p) =>
94
+ p === 0 || p === 1
95
+ ? p
96
+ : -Math.pow(2, 10 * p - 10) *
97
+ Math.sin(((p * 10 - 10.75) * 2 * Math.PI) / 3),
98
+ Back: () => (p) => {
99
+ const s = 1.70158
100
+ return p * p * ((s + 1) * p - s)
101
+ },
102
+ Bounce: () => (p) => {
103
+ p = 1 - p
104
+ const s = 7.5625
105
+ const k = 2.75
106
+ return (
107
+ 1 -
108
+ (p < 1 / k
109
+ ? s * p * p
110
+ : p < 2 / k
111
+ ? s * (p -= 1.5 / k) * p + 0.75
112
+ : p < 2.5 / k
113
+ ? s * (p -= 2.25 / k) * p + 0.9375
114
+ : s * (p -= 2.625 / k) * p + 0.984375)
115
+ )
116
+ },
117
+ }
118
+ const powerNames = ['Quad', 'Cubic', 'Quart', 'Quint']
119
+ powerNames.forEach((name, i) => {
120
+ easingStuff[name] = () => (p) => Math.pow(p, i + 2)
121
+ })
122
+ Object.keys(easingStuff).forEach((name) => {
123
+ const easeIn = easingStuff[name]
124
+ easings['easeIn' + name] = easeIn
125
+ easings['easeOut' + name] = (a, b) => (p) => 1 - easeIn(a, b)(1 - p)
126
+ easings['easeInOut' + name] = (a, b) => (p) =>
127
+ p < 0.5 ? easeIn(a, b)(p * 2) / 2 : 1 - easeIn(a, b)(2 - 2 * p) / 2
128
+ })
129
+ const rNum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/
130
+ const rUnit =
131
+ /%|px|rpx|em|rem|vw|vh|deg|rad|turn|ex|ch|vmin|vmax|pc|pt|in|cm|mm/
132
+ const rCssNumVal = new RegExp(
133
+ '^([+\\-*/%]=|)(' + rNum.source + ')(' + rUnit.source + '|)$',
134
+ 'i',
135
+ )
136
+ const rTimelinePos = new RegExp('^([<>]|)([+-]=|)(' + rNum.source + '|)(%|)$')
137
+ function isNumber(target) {
138
+ return typeof target === 'number'
139
+ }
140
+ function isString(target) {
141
+ return typeof target === 'string'
142
+ }
143
+ function isObject(target) {
144
+ return target !== null && typeof target === 'object'
145
+ }
146
+ function isFunction(target) {
147
+ return typeof target === 'function'
148
+ }
149
+ function isArrayLike(target) {
150
+ let l
151
+ return (
152
+ isObject(target) &&
153
+ Number.isInteger((l = target.length)) &&
154
+ l < __pow(2, 32)
155
+ )
156
+ }
157
+ function isArray(target) {
158
+ return Array.isArray(target)
159
+ }
160
+ function minmax(n, min, max) {
161
+ return n < min ? min : n > max ? max : n
162
+ }
163
+ function toArray(target) {
164
+ return Array.isArray(target) ? target : [target]
165
+ }
166
+ const defaultEasing = 'easeInOutQuad'
167
+ function getEasing(ease) {
168
+ return isFunction(ease) ? ease : () => (easings[ease] || easings.linear)(0, 0)
169
+ }
170
+ function createEmitter() {
171
+ const events = {}
172
+ function on(type, callback) {
173
+ let callbacks = events[type]
174
+ if (!callbacks) {
175
+ callbacks = events[type] = /* @__PURE__ */ new Set()
176
+ }
177
+ callbacks.add(callback)
178
+ }
179
+ function off(type, callback) {
180
+ if (callback) {
181
+ const callbacks = events[type]
182
+ if (callbacks) {
183
+ callbacks.delete(callback)
184
+ if (callbacks.size === 0) {
185
+ delete events[type]
186
+ }
187
+ }
188
+ } else {
189
+ delete events[type]
190
+ }
191
+ }
192
+ function once(type, callback) {
193
+ on(type, function fn(...args) {
194
+ callback(...args)
195
+ off(type, fn)
196
+ })
197
+ }
198
+ function emit(type, ...args) {
199
+ const callbacks = events[type]
200
+ if (callbacks) {
201
+ callbacks.forEach((callback) => {
202
+ callback(...args)
203
+ })
204
+ }
205
+ }
206
+ return {
207
+ on,
208
+ off,
209
+ once,
210
+ emit,
211
+ }
212
+ }
213
+ const TERMINATE = Symbol()
214
+ class SpecialValue {}
215
+ class WithFromValue extends SpecialValue {
216
+ constructor(from, to) {
217
+ super()
218
+ __publicField(this, 'from')
219
+ __publicField(this, 'to')
220
+ this.from = from
221
+ this.to = to
222
+ }
223
+ }
224
+ const plugins = []
225
+ function parseTarget(target) {
226
+ const result = []
227
+ if (!isArray(target)) {
228
+ target = [target]
229
+ }
230
+ target.flat().forEach((item) => {
231
+ if (item) {
232
+ if (isString(item)) {
233
+ result.push(...Array.from(document.querySelectorAll(item)))
234
+ } else if (isArrayLike(item)) {
235
+ result.push(...Array.from(item))
236
+ } else if (isObject(item) || isFunction(item)) {
237
+ result.push(item)
238
+ }
239
+ }
240
+ })
241
+ return Array.from(new Set(result))
242
+ }
243
+ function getFuncValue(value, animatedTarget) {
244
+ return isFunction(value)
245
+ ? value(animatedTarget.target, animatedTarget.index, animatedTarget.total)
246
+ : value
247
+ }
248
+ function getTweenValue(position, tween) {
249
+ const { duration, delay, begin, easing, between } = tween
250
+ function getBetweenValue(between2) {
251
+ const { from, to, round } = between2
252
+ let value =
253
+ position <= begin + delay
254
+ ? from
255
+ : position >= begin + delay + duration
256
+ ? to
257
+ : from + easing((position - begin - delay) / duration) * (to - from)
258
+ if (round) {
259
+ value = Math.round(value * round) / round
260
+ }
261
+ return value
262
+ }
263
+ return between.map((item) => getBetweenValue(item))
264
+ }
265
+ function getAnimatedTargets(targets) {
266
+ return targets.map((target, i) => ({
267
+ target,
268
+ index: i,
269
+ total: targets.length,
270
+ }))
271
+ }
272
+ function structureValue(value, animatedTarget) {
273
+ value = getFuncValue(value, animatedTarget)
274
+ if (isArray(value)) {
275
+ return value.map((value2) => structureValue(value2, animatedTarget)[0])
276
+ }
277
+ if (isNumber(value) || isString(value) || value instanceof SpecialValue) {
278
+ value = { value }
279
+ }
280
+ return [value]
281
+ }
282
+ function normalizeTweens(
283
+ animatedTarget,
284
+ objectValues,
285
+ prop,
286
+ options,
287
+ beginTime,
288
+ animationProperties,
289
+ averageDuration,
290
+ ) {
291
+ const l = objectValues.length
292
+ let endTime = beginTime || 0
293
+ let prevTween
294
+ averageDuration =
295
+ (averageDuration != null ? averageDuration : options.duration) / l
296
+ function normalizeTween(objectValue, index, prevTween2) {
297
+ var _a, _b, _c, _d, _e, _f, _g
298
+ const duration = getFuncValue(
299
+ (_a = objectValue.duration) != null ? _a : averageDuration,
300
+ animatedTarget,
301
+ )
302
+ const delay = getFuncValue(
303
+ (_b = objectValue.delay) != null ? _b : index === 0 ? options.delay : 0,
304
+ animatedTarget,
305
+ )
306
+ const endDelay = getFuncValue(
307
+ (_c = objectValue.endDelay) != null
308
+ ? _c
309
+ : index === l - 1
310
+ ? options.endDelay
311
+ : 0,
312
+ animatedTarget,
313
+ )
314
+ const easing = getFuncValue(
315
+ getEasing((_d = objectValue.easing) != null ? _d : options.easing),
316
+ animatedTarget,
317
+ )
318
+ const round = getFuncValue(
319
+ (_e = objectValue.round) != null ? _e : options.round,
320
+ animatedTarget,
321
+ )
322
+ const total = delay + duration + endDelay
323
+ const begin = endTime
324
+ const end = begin + total
325
+ endTime += total
326
+ if (!prevTween2) {
327
+ let values
328
+ prevTween2 = (values = animationProperties[prop])
329
+ ? values[values.length - 1]
330
+ : void 0
331
+ }
332
+ const value = objectValue.value
333
+ let to
334
+ let from
335
+ const withFromValue = value instanceof WithFromValue
336
+ if (withFromValue) {
337
+ from = getFuncValue(value.from, animatedTarget)
338
+ to = getFuncValue(value.to, animatedTarget)
339
+ } else {
340
+ to = value
341
+ }
342
+ if (!withFromValue && prevTween2) {
343
+ from = prevTween2.to
344
+ }
345
+ let withoutFrom = false
346
+ if (from === void 0) {
347
+ from = animatedTarget.target[prop]
348
+ withoutFrom = true
349
+ }
350
+ let operator = ''
351
+ let unit = ''
352
+ if (isString(to)) {
353
+ const parts = rCssNumVal.exec(to)
354
+ if (parts) {
355
+ operator = parts[1]
356
+ to = parseFloat(parts[2]) || 0
357
+ unit = parts[3]
358
+ }
359
+ }
360
+ const tween = {
361
+ animatedTarget,
362
+ prop,
363
+ duration,
364
+ delay,
365
+ endDelay,
366
+ begin,
367
+ end,
368
+ easing,
369
+ data: {},
370
+ from,
371
+ to,
372
+ withoutFrom,
373
+ round,
374
+ unit,
375
+ operator,
376
+ between: [],
377
+ }
378
+ for (let i = 0, l2 = plugins.length; i < l2; i++) {
379
+ const retValue =
380
+ (_g = (_f = plugins[i]).init) == null
381
+ ? void 0
382
+ : _g.call(_f, tween, TERMINATE)
383
+ if (retValue === TERMINATE) {
384
+ break
385
+ }
386
+ }
387
+ return tween
388
+ }
389
+ const tweens = objectValues
390
+ .map(
391
+ (objectValue, index) =>
392
+ (prevTween = normalizeTween(objectValue, index, prevTween)),
393
+ )
394
+ .sort((a, b) => a.begin - b.begin)
395
+ return {
396
+ endTime,
397
+ tweens,
398
+ }
399
+ }
400
+ function getOneKeyframeTween(
401
+ animatedTarget,
402
+ properties,
403
+ options,
404
+ beginTime,
405
+ animationProperties,
406
+ averageDuration,
407
+ ) {
408
+ let props = {}
409
+ for (let p in properties) {
410
+ const value = properties[p]
411
+ if (value !== null && value !== void 0) {
412
+ props[p] = normalizeTweens(
413
+ animatedTarget,
414
+ structureValue(value, animatedTarget),
415
+ p,
416
+ options,
417
+ beginTime,
418
+ animationProperties,
419
+ averageDuration,
420
+ )
421
+ }
422
+ }
423
+ return props
424
+ }
425
+ function getAnimationProperties(animatedTarget, keyframes, options) {
426
+ const animationProperties = {}
427
+ const averageDuration =
428
+ getFuncValue(options.duration, animatedTarget) / keyframes.length
429
+ let endTime = 0
430
+ keyframes.forEach((properties) => {
431
+ const oneKeyframeTween = getOneKeyframeTween(
432
+ animatedTarget,
433
+ properties,
434
+ options,
435
+ endTime,
436
+ animationProperties,
437
+ averageDuration,
438
+ )
439
+ for (let p in oneKeyframeTween) {
440
+ endTime = Math.max(endTime, oneKeyframeTween[p].endTime)
441
+ animationProperties[p] = (animationProperties[p] || []).concat(
442
+ oneKeyframeTween[p].tweens,
443
+ )
444
+ }
445
+ })
446
+ return animationProperties
447
+ }
448
+ function createAnimation$1(tweens) {
449
+ function seek(position) {
450
+ var _a, _b
451
+ let currTween
452
+ for (let i = 0, tween; (tween = tweens[i++]); ) {
453
+ if (tween.begin <= position && tween.end >= position) {
454
+ currTween = tween
455
+ break
456
+ }
457
+ if (position > tween.end) {
458
+ if (!tweens[i + 1] || tweens[i + 1].begin > position) {
459
+ currTween = tween
460
+ }
461
+ }
462
+ }
463
+ if (currTween) {
464
+ let value = getTweenValue(position, currTween)
465
+ let currentValue
466
+ for (let i = plugins.length - 1; i >= 0; i--) {
467
+ currentValue =
468
+ (_b = (_a = plugins[i]).update) == null
469
+ ? void 0
470
+ : _b.call(_a, currTween, value, TERMINATE)
471
+ if (currentValue === TERMINATE) {
472
+ return
473
+ }
474
+ if (currentValue !== void 0) {
475
+ value = currentValue
476
+ }
477
+ }
478
+ }
479
+ }
480
+ function getDuration() {
481
+ return Math.max(...tweens.map((tween) => tween.end))
482
+ }
483
+ return {
484
+ seek,
485
+ getDuration,
486
+ tweens,
487
+ }
488
+ }
489
+ function getAnimations(animationTargets, keyframes, options) {
490
+ return animationTargets
491
+ .map((animatedTarget) => {
492
+ const animationProperties = getAnimationProperties(
493
+ animatedTarget,
494
+ keyframes,
495
+ options,
496
+ )
497
+ return Object.keys(animationProperties).map((p) =>
498
+ createAnimation$1(animationProperties[p]),
499
+ )
500
+ })
501
+ .flat()
502
+ }
503
+ const defaultTweenOptions = {
504
+ duration: 500,
505
+ delay: 0,
506
+ endDelay: 0,
507
+ easing: defaultEasing,
508
+ round: 0,
509
+ }
510
+ function createAnimations(target, keyframes, options) {
511
+ const tweenOptions = Object.assign({}, defaultTweenOptions, options)
512
+ return getAnimations(
513
+ getAnimatedTargets(parseTarget(target)),
514
+ isArray(keyframes) ? keyframes : [keyframes],
515
+ tweenOptions,
516
+ )
517
+ }
518
+ function withFrom(from, to) {
519
+ return new WithFromValue(from, to)
520
+ }
521
+ function use(plugin) {
522
+ toArray(plugin).forEach((plugin2) => {
523
+ if (!plugins.includes(plugin2)) {
524
+ plugins.push(plugin2)
525
+ plugins.sort((a, b) => b.order - a.order)
526
+ }
527
+ })
528
+ }
529
+ const DIRECTION_ALTERNATE_REVERSE = 'alternate-reverse'
530
+ const DIRECTION_REVERSE = 'reverse'
531
+ const DIRECTION_ALTERNATE = 'alternate'
532
+ function isReverse(direction) {
533
+ return (
534
+ direction === DIRECTION_REVERSE || direction === DIRECTION_ALTERNATE_REVERSE
535
+ )
536
+ }
537
+ function isAlternate(direction) {
538
+ return (
539
+ direction === DIRECTION_ALTERNATE ||
540
+ direction === DIRECTION_ALTERNATE_REVERSE
541
+ )
542
+ }
543
+ function isTimelineEventTarget(target) {
544
+ return isObject(target) && 'getDuration' in target && 'seek' in target
545
+ }
546
+ const defaultTimelineOptions = {
547
+ externalTicker: false,
548
+ autoplay: true,
549
+ direction: 'normal',
550
+ loop: 1,
551
+ }
552
+ const callbackNames = [
553
+ 'begin',
554
+ 'loopBegin',
555
+ 'complete',
556
+ 'loopComplete',
557
+ 'pause',
558
+ 'play',
559
+ 'update',
560
+ ]
561
+ function createTimeline(options) {
562
+ const mergedOptions = Object.assign({}, defaultTimelineOptions, options)
563
+ const { externalTicker, autoplay, direction, loop } = mergedOptions
564
+ let firstTime = false
565
+ let paused2 = true
566
+ let prevTickTime = 0
567
+ let position = 0
568
+ let currentLoop = loop
569
+ let reverse = isReverse(direction)
570
+ let duration = 0
571
+ let events = []
572
+ const emitter = createEmitter()
573
+ callbackNames.forEach((name) => {
574
+ if (mergedOptions[name]) {
575
+ emitter.on(name, mergedOptions[name])
576
+ }
577
+ })
578
+ function isCompleted() {
579
+ return currentLoop === 0 && position === duration
580
+ }
581
+ function seek(nextPosition) {
582
+ let finished = false
583
+ if (nextPosition >= duration) {
584
+ nextPosition = duration
585
+ finished = true
586
+ } else if (nextPosition < 0) {
587
+ nextPosition = 0
588
+ }
589
+ position = nextPosition
590
+ const seekPosition = reverse ? duration - position : position
591
+ events.forEach(({ target, begin }) => {
592
+ target.seek(seekPosition - begin)
593
+ })
594
+ emitter.emit(
595
+ 'update',
596
+ seekPosition,
597
+ duration === 0 ? 0 : position / duration,
598
+ )
599
+ if (finished) {
600
+ emitter.emit('loopComplete')
601
+ if (--currentLoop < 0) {
602
+ currentLoop = 0
603
+ }
604
+ if (currentLoop === 0) {
605
+ pause()
606
+ emitter.emit('complete')
607
+ } else {
608
+ if (!paused2) {
609
+ if (isAlternate(direction)) {
610
+ reverse = !reverse
611
+ }
612
+ start()
613
+ }
614
+ }
615
+ }
616
+ }
617
+ function progress(p) {
618
+ seek(minmax(p, 0, 1) * duration)
619
+ }
620
+ function tick() {
621
+ if (!paused2) {
622
+ let currTime = Date.now()
623
+ seek(currTime - prevTickTime + position)
624
+ prevTickTime = currTime
625
+ }
626
+ }
627
+ function start() {
628
+ if (!firstTime) {
629
+ firstTime = true
630
+ emitter.emit('begin')
631
+ } else {
632
+ position = 0
633
+ }
634
+ emitter.emit('loopBegin')
635
+ play()
636
+ }
637
+ function play() {
638
+ if (!firstTime) {
639
+ start()
640
+ } else {
641
+ if (paused2) {
642
+ paused2 = false
643
+ if (isCompleted()) {
644
+ if (isAlternate(direction)) {
645
+ reverse = !reverse
646
+ }
647
+ restart()
648
+ } else {
649
+ prevTickTime = Date.now()
650
+ if (!externalTicker) {
651
+ ticker.add(tick)
652
+ }
653
+ emitter.emit('play')
654
+ }
655
+ }
656
+ }
657
+ }
658
+ function pause() {
659
+ if (!paused2) {
660
+ paused2 = true
661
+ if (!externalTicker) {
662
+ ticker.remove(tick)
663
+ }
664
+ emitter.emit('pause')
665
+ }
666
+ }
667
+ function restart() {
668
+ pause()
669
+ position = 0
670
+ firstTime = false
671
+ currentLoop = loop
672
+ reverse = isReverse(direction)
673
+ play()
674
+ }
675
+ function finish() {
676
+ if (!isCompleted()) {
677
+ seek(duration)
678
+ }
679
+ }
680
+ function add2(target, positionOrKeyframes, optionsOrPosition, position2) {
681
+ if (isTimelineEventTarget(target)) {
682
+ position2 = positionOrKeyframes != null ? positionOrKeyframes : '>'
683
+ let begin = duration
684
+ if (isNumber(position2)) {
685
+ begin = position2
686
+ } else {
687
+ const { begin: prevBegin, end: prevEnd } = events[
688
+ events.length - 1
689
+ ] || {
690
+ begin: 0,
691
+ end: 0,
692
+ }
693
+ const prevDuration = prevEnd - prevBegin
694
+ const [, bracket, relative, num, unit] = rTimelinePos.exec(
695
+ position2,
696
+ ) || [, '>', '', '', '']
697
+ begin = bracket === '<' ? prevBegin : bracket === '>' ? prevEnd : begin
698
+ let value = +num
699
+ if (unit === '%') {
700
+ value = ((bracket ? prevDuration : duration) / 100) * +num
701
+ }
702
+ begin += relative === '-=' ? -value : value
703
+ }
704
+ begin = Math.max(0, begin)
705
+ const end = begin + target.getDuration()
706
+ events.push({ target, position: position2, begin, end })
707
+ duration = Math.max(duration, end)
708
+ } else {
709
+ if (isNumber(optionsOrPosition) || isString(optionsOrPosition)) {
710
+ position2 = optionsOrPosition
711
+ optionsOrPosition = void 0
712
+ }
713
+ const animations = createAnimations(
714
+ target,
715
+ positionOrKeyframes,
716
+ optionsOrPosition,
717
+ )
718
+ animations.forEach((animation, index) => {
719
+ add2(animation, index === 0 ? position2 : '<')
720
+ })
721
+ }
722
+ return timeline
723
+ }
724
+ function remove2(target) {
725
+ const index = events.findIndex((e) => e.target === target)
726
+ if (index !== -1) {
727
+ events.splice(index, 1)
728
+ update()
729
+ }
730
+ }
731
+ function update() {
732
+ const oldEvents = [...events]
733
+ events = []
734
+ duration = 0
735
+ oldEvents.forEach((event) => {
736
+ add2(event.target, event.position)
737
+ })
738
+ }
739
+ function clear() {
740
+ pause()
741
+ duration = 0
742
+ events = []
743
+ }
744
+ if (autoplay && loop !== 0) {
745
+ start()
746
+ }
747
+ const timeline = {
748
+ play,
749
+ pause,
750
+ finish,
751
+ restart,
752
+ seek,
753
+ progress,
754
+ tick: () => {
755
+ if (externalTicker) {
756
+ tick()
757
+ }
758
+ },
759
+ getPosition() {
760
+ return position
761
+ },
762
+ getDuration() {
763
+ return duration
764
+ },
765
+ getProgress() {
766
+ return duration === 0 ? 0 : position / duration
767
+ },
768
+ isReverse() {
769
+ return reverse
770
+ },
771
+ add: add2,
772
+ remove: remove2,
773
+ clear,
774
+ events,
775
+ on: emitter.on,
776
+ off: emitter.off,
777
+ once: emitter.once,
778
+ }
779
+ return timeline
780
+ }
781
+ function definePlugin(plugin) {
782
+ return plugin
783
+ }
784
+ const updatePlugin = definePlugin({
785
+ order: 100,
786
+ update(tween, value, terminate) {
787
+ const { animatedTarget, prop, unit } = tween
788
+ let val = isArray(value) ? value[0] : value
789
+ if (unit) {
790
+ val += unit
791
+ }
792
+ animatedTarget.target[prop] = val
793
+ return terminate
794
+ },
795
+ })
796
+ const initPlugin = definePlugin({
797
+ order: 0,
798
+ init(tween, terminate) {
799
+ if (tween.between.length === 0) {
800
+ const to = toArray(tween.to)
801
+ const from = toArray(tween.from)
802
+ tween.between = to.map((value, i) => ({
803
+ from: +from[i] || 0,
804
+ to: +value || 0,
805
+ round: tween.round,
806
+ }))
807
+ return terminate
808
+ }
809
+ },
810
+ })
811
+ use(updatePlugin)
812
+ use(initPlugin)
813
+ function createAnimation(target, keyframes, options) {
814
+ return createTimeline(options).add(target, keyframes, options)
815
+ }
816
+ export { createAnimation, createTimeline, easings, ticker, withFrom }