@next2d/ui 1.14.20

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/dist/Job.js ADDED
@@ -0,0 +1,332 @@
1
+ import { Easing } from "./Easing";
2
+ import { EventDispatcher, Event } from "@next2d/events";
3
+ import { $setTimeout, $performance } from "@next2d/share";
4
+ /**
5
+ * @class
6
+ * @memberOf next2d.ui
7
+ * @extends EventDispatcher
8
+ */
9
+ export class Job extends EventDispatcher {
10
+ /**
11
+ * @param {object} target
12
+ * @param {object} [from=null]
13
+ * @param {object} [to=null]
14
+ * @param {number} [delay=0]
15
+ * @param {number} [duration=1]
16
+ * @param {function} [ease=null]
17
+ *
18
+ * @constructor
19
+ * @public
20
+ */
21
+ constructor(target, from = null, to = null, delay = 0, duration = 1, ease = null) {
22
+ super();
23
+ /**
24
+ * @type {object}
25
+ * @private
26
+ */
27
+ this._$target = target;
28
+ /**
29
+ * @type {number}
30
+ * @default 0
31
+ * @private
32
+ */
33
+ this._$delay = delay;
34
+ /**
35
+ * @type {number}
36
+ * @default 1
37
+ * @private
38
+ */
39
+ this._$duration = duration;
40
+ /**
41
+ * @type {function}
42
+ * @default Easing.linear
43
+ * @private
44
+ */
45
+ this._$ease = ease || Easing.linear;
46
+ /**
47
+ * @type {object}
48
+ * @default null
49
+ * @private
50
+ */
51
+ this._$from = from;
52
+ /**
53
+ * @type {array}
54
+ * @default null
55
+ * @private
56
+ */
57
+ this._$names = null;
58
+ /**
59
+ * @type {number}
60
+ * @default 0
61
+ * @private
62
+ */
63
+ this._$startTime = 0;
64
+ /**
65
+ * @type {boolean}
66
+ * @default false
67
+ * @private
68
+ */
69
+ this._$stopFlag = false;
70
+ /**
71
+ * @type {boolean}
72
+ * @default false
73
+ * @private
74
+ */
75
+ this._$forceStop = false;
76
+ /**
77
+ * @type {object}
78
+ * @default null
79
+ * @private
80
+ */
81
+ this._$to = to;
82
+ /**
83
+ * @type {number}
84
+ * @default 0
85
+ * @private
86
+ */
87
+ this._$currentTime = 0;
88
+ }
89
+ /**
90
+ * @description 指定されたクラスのストリングを返します。
91
+ * Returns the string representation of the specified class.
92
+ *
93
+ * @return {string}
94
+ * @default [class Job]
95
+ * @method
96
+ * @static
97
+ */
98
+ static toString() {
99
+ return "[class Job]";
100
+ }
101
+ /**
102
+ * @description 指定されたクラスの空間名を返します。
103
+ * Returns the space name of the specified class.
104
+ *
105
+ * @return {string}
106
+ * @default next2d.ui.Job
107
+ * @const
108
+ * @static
109
+ */
110
+ static get namespace() {
111
+ return "next2d.ui.Job";
112
+ }
113
+ /**
114
+ * @description 指定されたオブジェクトのストリングを返します。
115
+ * Returns the string representation of the specified object.
116
+ *
117
+ * @return {string}
118
+ * @default [object Job]
119
+ * @method
120
+ * @public
121
+ */
122
+ toString() {
123
+ return "[object Job]";
124
+ }
125
+ /**
126
+ * @description 指定されたオブジェクトの空間名を返します。
127
+ * Returns the space name of the specified object.
128
+ *
129
+ * @return {string}
130
+ * @default next2d.ui.Job
131
+ * @const
132
+ * @public
133
+ */
134
+ get namespace() {
135
+ return "next2d.ui.Job";
136
+ }
137
+ /**
138
+ * @member {function}
139
+ * @default Easing.linear
140
+ * @public
141
+ */
142
+ get ease() {
143
+ return this._$ease;
144
+ }
145
+ set ease(ease) {
146
+ if (typeof ease === "function") {
147
+ this._$ease = ease;
148
+ }
149
+ }
150
+ /**
151
+ * @member {number}
152
+ * @default 0
153
+ * @public
154
+ */
155
+ get delay() {
156
+ return this._$delay;
157
+ }
158
+ set delay(delay) {
159
+ this._$delay = delay;
160
+ }
161
+ /**
162
+ * @member {number}
163
+ * @default 1
164
+ * @public
165
+ */
166
+ get duration() {
167
+ return this._$duration;
168
+ }
169
+ set duration(duration) {
170
+ this._$duration = duration;
171
+ }
172
+ /**
173
+ * @member {object}
174
+ * @default null
175
+ * @public
176
+ */
177
+ get from() {
178
+ return this._$from;
179
+ }
180
+ set from(from) {
181
+ this._$from = from;
182
+ }
183
+ /**
184
+ * @member {object}
185
+ * @default null
186
+ * @public
187
+ */
188
+ get to() {
189
+ return this._$to;
190
+ }
191
+ set to(to) {
192
+ this._$to = to;
193
+ }
194
+ /**
195
+ * @member {object}
196
+ * @readonly
197
+ * @public
198
+ */
199
+ get target() {
200
+ return this._$target;
201
+ }
202
+ /**
203
+ * @return {void}
204
+ * @method
205
+ * @public
206
+ */
207
+ initialize() {
208
+ if (this._$forceStop) {
209
+ return;
210
+ }
211
+ // setup
212
+ this._$stopFlag = false;
213
+ this._$startTime = $performance.now();
214
+ this._$names = this.entries(this._$from);
215
+ // add event
216
+ this.addEventListener(Event.ENTER_FRAME, (event) => {
217
+ this._$update(event);
218
+ });
219
+ }
220
+ /**
221
+ * @param {object} object
222
+ * @return {array}
223
+ * @method
224
+ * @public
225
+ */
226
+ entries(object) {
227
+ const entries = Object.entries(object);
228
+ for (let idx = 0; idx < entries.length; ++idx) {
229
+ const values = entries[idx];
230
+ const value = values[1];
231
+ if (value && typeof value === "object") {
232
+ values[1] = this.entries(value);
233
+ }
234
+ }
235
+ return entries;
236
+ }
237
+ /**
238
+ * @return {Promise}
239
+ * @method
240
+ * @public
241
+ */
242
+ start() {
243
+ return new Promise((resolve) => {
244
+ if (!this.hasEventListener(Event.COMPLETE)) {
245
+ this.addEventListener(Event.COMPLETE, (event) => {
246
+ this.removeEventListener(Event.COMPLETE, event.listener);
247
+ resolve();
248
+ });
249
+ }
250
+ if (this._$delay) {
251
+ $setTimeout(() => {
252
+ this.initialize();
253
+ }, this._$delay * 1000);
254
+ return;
255
+ }
256
+ this.initialize();
257
+ });
258
+ }
259
+ /**
260
+ * @return {void}
261
+ * @method
262
+ * @public
263
+ */
264
+ stop() {
265
+ if (this.hasEventListener(Event.STOP)) {
266
+ this.dispatchEvent(new Event(Event.STOP));
267
+ }
268
+ if (this.hasEventListener(Event.ENTER_FRAME)) {
269
+ this.removeAllEventListener(Event.ENTER_FRAME);
270
+ }
271
+ if (this.hasEventListener(Event.UPDATE)) {
272
+ this.removeAllEventListener(Event.UPDATE);
273
+ }
274
+ if (this.hasEventListener(Event.COMPLETE)) {
275
+ this.removeAllEventListener(Event.COMPLETE);
276
+ }
277
+ this._$forceStop = true;
278
+ this._$stopFlag = true;
279
+ }
280
+ /**
281
+ * @param {Event} event
282
+ * @return {void}
283
+ * @method
284
+ * @private
285
+ */
286
+ _$update(event) {
287
+ if (this._$stopFlag) {
288
+ return;
289
+ }
290
+ this._$currentTime = ($performance.now() - this._$startTime) * 0.001;
291
+ if (this._$names) {
292
+ this._$updateProperty(this._$target, this._$from, this._$to, this._$names);
293
+ }
294
+ if (this.hasEventListener(Event.UPDATE)) {
295
+ this.dispatchEvent(new Event(Event.UPDATE));
296
+ }
297
+ if (this._$currentTime >= this._$duration) {
298
+ this.removeEventListener(Event.ENTER_FRAME, event.listener);
299
+ if (this.hasEventListener(Event.COMPLETE)) {
300
+ this.dispatchEvent(new Event(Event.COMPLETE));
301
+ }
302
+ }
303
+ }
304
+ /**
305
+ * @param {object} target
306
+ * @param {object} from
307
+ * @param {object} to
308
+ * @param {array} names
309
+ * @return {void}
310
+ * @method
311
+ * @private
312
+ */
313
+ _$updateProperty(target, from, to, names) {
314
+ for (let idx = 0; idx < names.length; ++idx) {
315
+ const values = names[idx];
316
+ const name = values[0];
317
+ const value = values[1];
318
+ if (value && typeof value === "object") {
319
+ this._$updateProperty(target[name], from[name], to[name], value);
320
+ continue;
321
+ }
322
+ // update
323
+ const fromValue = from[name];
324
+ if (this._$duration > this._$currentTime) {
325
+ target[name] = this._$ease(this._$currentTime, fromValue, to[name] - fromValue, this._$duration);
326
+ }
327
+ else {
328
+ target[name] = to[name];
329
+ }
330
+ }
331
+ }
332
+ }
@@ -0,0 +1,62 @@
1
+ import { Job } from "./Job";
2
+ /**
3
+ * @class
4
+ * @memberOf next2d.ui
5
+ */
6
+ export declare class Tween {
7
+ /**
8
+ * @description 指定されたクラスのストリングを返します。
9
+ * Returns the string representation of the specified class.
10
+ *
11
+ * @return {string}
12
+ * @default [class Tween]
13
+ * @method
14
+ * @static
15
+ */
16
+ static toString(): string;
17
+ /**
18
+ * @description 指定されたクラスの空間名を返します。
19
+ * Returns the space name of the specified class.
20
+ *
21
+ * @return {string}
22
+ * @default next2d.ui.Tween
23
+ * @const
24
+ * @static
25
+ */
26
+ static get namespace(): string;
27
+ /**
28
+ * @description 指定されたオブジェクトのストリングを返します。
29
+ * Returns the string representation of the specified object.
30
+ *
31
+ * @return {string}
32
+ * @default [object Tween]
33
+ * @method
34
+ * @public
35
+ */
36
+ toString(): string;
37
+ /**
38
+ * @description 指定されたオブジェクトの空間名を返します。
39
+ * Returns the space name of the specified object.
40
+ *
41
+ * @return {string}
42
+ * @default next2d.ui.Tween
43
+ * @const
44
+ * @public
45
+ */
46
+ get namespace(): string;
47
+ /**
48
+ * @description 新しいJobクラスを追加します
49
+ * Add a new Job class
50
+ *
51
+ * @param {object} target
52
+ * @param {object} from
53
+ * @param {object} to
54
+ * @param {number} [delay=0]
55
+ * @param {number} [duration=1]
56
+ * @param {function} [ease=null]
57
+ * @return {Job}
58
+ * @method
59
+ * @static
60
+ */
61
+ static add(target: any, from: any, to: any, delay?: number, duration?: number, ease?: Function | null): Job;
62
+ }
package/dist/Tween.js ADDED
@@ -0,0 +1,72 @@
1
+ import { Job } from "./Job";
2
+ /**
3
+ * @class
4
+ * @memberOf next2d.ui
5
+ */
6
+ export class Tween {
7
+ /**
8
+ * @description 指定されたクラスのストリングを返します。
9
+ * Returns the string representation of the specified class.
10
+ *
11
+ * @return {string}
12
+ * @default [class Tween]
13
+ * @method
14
+ * @static
15
+ */
16
+ static toString() {
17
+ return "[class Tween]";
18
+ }
19
+ /**
20
+ * @description 指定されたクラスの空間名を返します。
21
+ * Returns the space name of the specified class.
22
+ *
23
+ * @return {string}
24
+ * @default next2d.ui.Tween
25
+ * @const
26
+ * @static
27
+ */
28
+ static get namespace() {
29
+ return "next2d.ui.Tween";
30
+ }
31
+ /**
32
+ * @description 指定されたオブジェクトのストリングを返します。
33
+ * Returns the string representation of the specified object.
34
+ *
35
+ * @return {string}
36
+ * @default [object Tween]
37
+ * @method
38
+ * @public
39
+ */
40
+ toString() {
41
+ return "[object Tween]";
42
+ }
43
+ /**
44
+ * @description 指定されたオブジェクトの空間名を返します。
45
+ * Returns the space name of the specified object.
46
+ *
47
+ * @return {string}
48
+ * @default next2d.ui.Tween
49
+ * @const
50
+ * @public
51
+ */
52
+ get namespace() {
53
+ return "next2d.ui.Tween";
54
+ }
55
+ /**
56
+ * @description 新しいJobクラスを追加します
57
+ * Add a new Job class
58
+ *
59
+ * @param {object} target
60
+ * @param {object} from
61
+ * @param {object} to
62
+ * @param {number} [delay=0]
63
+ * @param {number} [duration=1]
64
+ * @param {function} [ease=null]
65
+ * @return {Job}
66
+ * @method
67
+ * @static
68
+ */
69
+ static add(target, from, to, delay = 0, duration = 1, ease = null) {
70
+ return new Job(target, from, to, delay, duration, ease);
71
+ }
72
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./Easing";
2
+ export * from "./Job";
3
+ export * from "./Tween";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./Easing";
2
+ export * from "./Job";
3
+ export * from "./Tween";
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@next2d/ui",
3
+ "version": "1.14.20",
4
+ "description": "Next2D UI Packages",
5
+ "author": "Toshiyuki Ienaga<ienaga@tvon.jp> (https://github.com/ienaga/)",
6
+ "license": "MIT",
7
+ "homepage": "https://next2d.app",
8
+ "bugs": "https://github.com/Next2D/Player/issues",
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "require": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ }
25
+ },
26
+ "keywords": [
27
+ "Next2D",
28
+ "Next2D UI"
29
+ ],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/Next2D/Player.git"
33
+ },
34
+ "peerDependencies": {
35
+ "@next2d/events": "1.14.20",
36
+ "@next2d/share": "1.14.20"
37
+ }
38
+ }