@leafer-in/robot 1.8.0 → 1.9.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.
package/dist/robot.cjs CHANGED
@@ -1,38 +1,22 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var draw = require('@leafer-ui/draw');
3
+ var draw = require("@leafer-ui/draw");
4
4
 
5
- /******************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
20
-
21
-
22
- function __decorate(decorators, target, key, desc) {
23
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
26
- return c > 3 && r && Object.defineProperty(target, key, r), r;
27
- }
28
-
29
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
30
- var e = new Error(message);
31
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
5
+ function __decorate(decorators, target, key, desc) {
6
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ }
10
+
11
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
12
+ var e = new Error(message);
13
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
14
  };
33
15
 
34
16
  class RobotData extends draw.UIData {
35
- get __drawAfterFill() { return true; }
17
+ get __drawAfterFill() {
18
+ return true;
19
+ }
36
20
  setRobot(value) {
37
21
  this._robot = value;
38
22
  this.__leaf.__updateRobot();
@@ -44,8 +28,12 @@ class RobotData extends draw.UIData {
44
28
  }
45
29
 
46
30
  exports.Robot = class Robot extends draw.UI {
47
- get __tag() { return 'Robot'; }
48
- get nowFrame() { return this.robotFrames && this.robotFrames[this.now]; }
31
+ get __tag() {
32
+ return "Robot";
33
+ }
34
+ get nowFrame() {
35
+ return this.robotFrames && this.robotFrames[this.now];
36
+ }
49
37
  constructor(data) {
50
38
  super(data);
51
39
  }
@@ -59,134 +47,113 @@ exports.Robot = class Robot extends draw.UI {
59
47
  this.pause();
60
48
  }
61
49
  __updateRobot() {
62
- const { robot } = this;
50
+ const {robot: robot} = this;
63
51
  this.robotFrames = [];
64
- if (!robot)
65
- return;
52
+ if (!robot) return;
66
53
  let start = 0;
67
- if (robot instanceof Array)
68
- robot.forEach(frame => this.__loadRobot(frame, start, start += frame.total || 1));
69
- else
70
- this.__loadRobot(robot, 0, robot.total);
54
+ if (draw.isArray(robot)) robot.forEach(frame => this.__loadRobot(frame, start, start += frame.total || 1)); else this.__loadRobot(robot, 0, robot.total);
71
55
  }
72
56
  __updateAction() {
73
57
  const action = this.actions[this.action];
74
58
  this.stop();
75
- if (this.__timer)
76
- clearTimeout(this.__timer);
77
- if (action === undefined)
78
- return;
79
- if (typeof action === 'number') {
59
+ if (this.__timer) clearTimeout(this.__timer);
60
+ if (draw.isUndefined(action)) return;
61
+ if (draw.isNumber(action)) {
80
62
  this.now = action;
81
- }
82
- else if (typeof action === 'object') {
83
- const isArray = action instanceof Array;
84
- const keyframes = isArray ? action : action.keyframes;
85
- this.__action = isArray ? undefined : action;
86
- const { length } = keyframes;
63
+ } else if (draw.isObject(action)) {
64
+ const isArr = draw.isArray(action);
65
+ const keyframes = isArr ? action : action.keyframes;
66
+ this.__action = isArr ? undefined : action;
67
+ const {length: length} = keyframes;
87
68
  if (length > 1) {
88
69
  const start = this.now = keyframes[0], end = keyframes[keyframes.length - 1];
89
70
  this.play();
90
71
  this.__runAction(start, end);
91
- }
92
- else if (length)
93
- this.now = keyframes[0];
72
+ } else if (length) this.now = keyframes[0];
94
73
  }
95
74
  }
96
75
  __loadRobot(frame, start, end) {
97
- for (let i = start; i < end; i++)
98
- this.robotFrames.push(undefined);
76
+ for (let i = start; i < end; i++) this.robotFrames.push(undefined);
99
77
  const image = draw.ImageManager.get(frame);
100
- if (image.ready)
101
- this.__createFrames(image, frame, start, end);
102
- else
103
- image.load(() => this.__createFrames(image, frame, start, end));
78
+ if (image.ready) this.__createFrames(image, frame, start, end); else image.load(() => this.__createFrames(image, frame, start, end));
104
79
  }
105
80
  __createFrames(image, frame, start, end) {
106
- const { offset, size, total } = frame;
107
- const { width, height } = size && (typeof size === 'number' ? { width: size, height: size } : size) || (total > 1 ? this : image);
81
+ const {offset: offset, size: size, total: total} = frame;
82
+ const {width: width, height: height} = size && (draw.isNumber(size) ? {
83
+ width: size,
84
+ height: size
85
+ } : size) || (total > 1 ? this : image);
108
86
  let x = offset ? offset.x : 0, y = offset ? offset.y : 0;
109
87
  for (let i = start; i < end; i++) {
110
- this.robotFrames[i] = { view: image.view, x, y, width, height };
111
- if (x + width >= image.width)
112
- x = 0, y += height;
113
- else
114
- x += width;
88
+ this.robotFrames[i] = {
89
+ view: image.view,
90
+ x: x,
91
+ y: y,
92
+ width: width,
93
+ height: height
94
+ };
95
+ if (x + width >= image.width) x = 0, y += height; else x += width;
115
96
  }
116
97
  this.__updateRobotBounds();
117
98
  this.forceRender();
118
- this.emitEvent(new draw.ImageEvent(draw.ImageEvent.LOADED, { image }));
99
+ this.emitEvent(new draw.ImageEvent(draw.ImageEvent.LOADED, {
100
+ image: image
101
+ }));
119
102
  }
120
103
  __runAction(start, end) {
121
- let { FPS, loop, __action: a } = this;
104
+ let {FPS: FPS, loop: loop, __action: a} = this;
122
105
  if (a) {
123
- if (a.FPS)
124
- FPS = a.FPS;
125
- if (a.loop !== undefined)
126
- loop = a.loop;
106
+ if (a.FPS) FPS = a.FPS;
107
+ if (!draw.isUndefined(a.loop)) loop = a.loop;
127
108
  }
128
109
  this.__timer = setTimeout(() => {
129
110
  if (this.running) {
130
111
  if (this.now === end) {
131
- if (!loop)
132
- return this.stop();
112
+ if (!loop) return this.stop();
133
113
  this.now = start;
134
- }
135
- else
136
- this.now++;
114
+ } else this.now++;
137
115
  this.__updateRobotBounds();
138
116
  }
139
117
  this.__runAction(start, end);
140
- }, 1000 / FPS);
118
+ }, 1e3 / FPS);
141
119
  }
142
120
  __updateRobotBounds() {
143
- const { nowFrame } = this;
121
+ const {nowFrame: nowFrame} = this;
144
122
  if (nowFrame) {
145
123
  const data = this.__;
146
124
  const width = nowFrame.width / data.pixelRatio;
147
125
  const height = nowFrame.height / data.pixelRatio;
148
- if (data.width !== width || data.height !== height)
149
- this.forceUpdate('width');
126
+ if (data.width !== width || data.height !== height) this.forceUpdate("width");
150
127
  data.__naturalWidth = width;
151
128
  data.__naturalHeight = height;
152
129
  }
153
130
  }
154
131
  __drawContent(canvas, _options) {
155
- const { nowFrame } = this, { width, height } = this.__;
156
- if (nowFrame)
157
- canvas.drawImage(nowFrame.view, nowFrame.x, nowFrame.y, nowFrame.width, nowFrame.height, 0, 0, width, height);
132
+ const {nowFrame: nowFrame} = this, {width: width, height: height} = this.__;
133
+ if (nowFrame) canvas.drawImage(nowFrame.view, nowFrame.x, nowFrame.y, nowFrame.width, nowFrame.height, 0, 0, width, height);
158
134
  }
159
135
  destroy() {
160
- if (this.robotFrames)
161
- this.robotFrames = null;
136
+ if (this.robotFrames) this.robotFrames = null;
162
137
  super.destroy();
163
138
  }
164
139
  };
165
- __decorate([
166
- draw.dataProcessor(RobotData)
167
- ], exports.Robot.prototype, "__", void 0);
168
- __decorate([
169
- draw.boundsType()
170
- ], exports.Robot.prototype, "robot", void 0);
171
- __decorate([
172
- draw.dataType()
173
- ], exports.Robot.prototype, "actions", void 0);
174
- __decorate([
175
- draw.dataType('')
176
- ], exports.Robot.prototype, "action", void 0);
177
- __decorate([
178
- draw.surfaceType(0)
179
- ], exports.Robot.prototype, "now", void 0);
180
- __decorate([
181
- draw.dataType(12)
182
- ], exports.Robot.prototype, "FPS", void 0);
183
- __decorate([
184
- draw.dataType(true)
185
- ], exports.Robot.prototype, "loop", void 0);
186
- exports.Robot = __decorate([
187
- draw.registerUI()
188
- ], exports.Robot);
189
140
 
190
- draw.Plugin.add('robot');
141
+ __decorate([ draw.dataProcessor(RobotData) ], exports.Robot.prototype, "__", void 0);
142
+
143
+ __decorate([ draw.boundsType() ], exports.Robot.prototype, "robot", void 0);
144
+
145
+ __decorate([ draw.dataType() ], exports.Robot.prototype, "actions", void 0);
146
+
147
+ __decorate([ draw.dataType("") ], exports.Robot.prototype, "action", void 0);
148
+
149
+ __decorate([ draw.surfaceType(0) ], exports.Robot.prototype, "now", void 0);
150
+
151
+ __decorate([ draw.dataType(12) ], exports.Robot.prototype, "FPS", void 0);
152
+
153
+ __decorate([ draw.dataType(true) ], exports.Robot.prototype, "loop", void 0);
154
+
155
+ exports.Robot = __decorate([ draw.registerUI() ], exports.Robot);
156
+
157
+ draw.Plugin.add("robot");
191
158
 
192
159
  exports.RobotData = RobotData;
package/dist/robot.esm.js CHANGED
@@ -1,36 +1,20 @@
1
- import { UIData, dataProcessor, boundsType, dataType, surfaceType, registerUI, UI, ImageManager, ImageEvent, Plugin } from '@leafer-ui/draw';
1
+ import { UIData, dataProcessor, boundsType, dataType, surfaceType, registerUI, UI, isArray, isUndefined, isNumber, isObject, ImageManager, ImageEvent, Plugin } from "@leafer-ui/draw";
2
2
 
3
- /******************************************************************************
4
- Copyright (c) Microsoft Corporation.
5
-
6
- Permission to use, copy, modify, and/or distribute this software for any
7
- purpose with or without fee is hereby granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */
17
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
18
-
19
-
20
- function __decorate(decorators, target, key, desc) {
21
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
22
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
23
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
24
- return c > 3 && r && Object.defineProperty(target, key, r), r;
25
- }
26
-
27
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
28
- var e = new Error(message);
29
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3
+ function __decorate(decorators, target, key, desc) {
4
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ }
8
+
9
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
10
+ var e = new Error(message);
11
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
30
12
  };
31
13
 
32
14
  class RobotData extends UIData {
33
- get __drawAfterFill() { return true; }
15
+ get __drawAfterFill() {
16
+ return true;
17
+ }
34
18
  setRobot(value) {
35
19
  this._robot = value;
36
20
  this.__leaf.__updateRobot();
@@ -42,8 +26,12 @@ class RobotData extends UIData {
42
26
  }
43
27
 
44
28
  let Robot = class Robot extends UI {
45
- get __tag() { return 'Robot'; }
46
- get nowFrame() { return this.robotFrames && this.robotFrames[this.now]; }
29
+ get __tag() {
30
+ return "Robot";
31
+ }
32
+ get nowFrame() {
33
+ return this.robotFrames && this.robotFrames[this.now];
34
+ }
47
35
  constructor(data) {
48
36
  super(data);
49
37
  }
@@ -57,134 +45,113 @@ let Robot = class Robot extends UI {
57
45
  this.pause();
58
46
  }
59
47
  __updateRobot() {
60
- const { robot } = this;
48
+ const {robot: robot} = this;
61
49
  this.robotFrames = [];
62
- if (!robot)
63
- return;
50
+ if (!robot) return;
64
51
  let start = 0;
65
- if (robot instanceof Array)
66
- robot.forEach(frame => this.__loadRobot(frame, start, start += frame.total || 1));
67
- else
68
- this.__loadRobot(robot, 0, robot.total);
52
+ if (isArray(robot)) robot.forEach(frame => this.__loadRobot(frame, start, start += frame.total || 1)); else this.__loadRobot(robot, 0, robot.total);
69
53
  }
70
54
  __updateAction() {
71
55
  const action = this.actions[this.action];
72
56
  this.stop();
73
- if (this.__timer)
74
- clearTimeout(this.__timer);
75
- if (action === undefined)
76
- return;
77
- if (typeof action === 'number') {
57
+ if (this.__timer) clearTimeout(this.__timer);
58
+ if (isUndefined(action)) return;
59
+ if (isNumber(action)) {
78
60
  this.now = action;
79
- }
80
- else if (typeof action === 'object') {
81
- const isArray = action instanceof Array;
82
- const keyframes = isArray ? action : action.keyframes;
83
- this.__action = isArray ? undefined : action;
84
- const { length } = keyframes;
61
+ } else if (isObject(action)) {
62
+ const isArr = isArray(action);
63
+ const keyframes = isArr ? action : action.keyframes;
64
+ this.__action = isArr ? undefined : action;
65
+ const {length: length} = keyframes;
85
66
  if (length > 1) {
86
67
  const start = this.now = keyframes[0], end = keyframes[keyframes.length - 1];
87
68
  this.play();
88
69
  this.__runAction(start, end);
89
- }
90
- else if (length)
91
- this.now = keyframes[0];
70
+ } else if (length) this.now = keyframes[0];
92
71
  }
93
72
  }
94
73
  __loadRobot(frame, start, end) {
95
- for (let i = start; i < end; i++)
96
- this.robotFrames.push(undefined);
74
+ for (let i = start; i < end; i++) this.robotFrames.push(undefined);
97
75
  const image = ImageManager.get(frame);
98
- if (image.ready)
99
- this.__createFrames(image, frame, start, end);
100
- else
101
- image.load(() => this.__createFrames(image, frame, start, end));
76
+ if (image.ready) this.__createFrames(image, frame, start, end); else image.load(() => this.__createFrames(image, frame, start, end));
102
77
  }
103
78
  __createFrames(image, frame, start, end) {
104
- const { offset, size, total } = frame;
105
- const { width, height } = size && (typeof size === 'number' ? { width: size, height: size } : size) || (total > 1 ? this : image);
79
+ const {offset: offset, size: size, total: total} = frame;
80
+ const {width: width, height: height} = size && (isNumber(size) ? {
81
+ width: size,
82
+ height: size
83
+ } : size) || (total > 1 ? this : image);
106
84
  let x = offset ? offset.x : 0, y = offset ? offset.y : 0;
107
85
  for (let i = start; i < end; i++) {
108
- this.robotFrames[i] = { view: image.view, x, y, width, height };
109
- if (x + width >= image.width)
110
- x = 0, y += height;
111
- else
112
- x += width;
86
+ this.robotFrames[i] = {
87
+ view: image.view,
88
+ x: x,
89
+ y: y,
90
+ width: width,
91
+ height: height
92
+ };
93
+ if (x + width >= image.width) x = 0, y += height; else x += width;
113
94
  }
114
95
  this.__updateRobotBounds();
115
96
  this.forceRender();
116
- this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
97
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, {
98
+ image: image
99
+ }));
117
100
  }
118
101
  __runAction(start, end) {
119
- let { FPS, loop, __action: a } = this;
102
+ let {FPS: FPS, loop: loop, __action: a} = this;
120
103
  if (a) {
121
- if (a.FPS)
122
- FPS = a.FPS;
123
- if (a.loop !== undefined)
124
- loop = a.loop;
104
+ if (a.FPS) FPS = a.FPS;
105
+ if (!isUndefined(a.loop)) loop = a.loop;
125
106
  }
126
107
  this.__timer = setTimeout(() => {
127
108
  if (this.running) {
128
109
  if (this.now === end) {
129
- if (!loop)
130
- return this.stop();
110
+ if (!loop) return this.stop();
131
111
  this.now = start;
132
- }
133
- else
134
- this.now++;
112
+ } else this.now++;
135
113
  this.__updateRobotBounds();
136
114
  }
137
115
  this.__runAction(start, end);
138
- }, 1000 / FPS);
116
+ }, 1e3 / FPS);
139
117
  }
140
118
  __updateRobotBounds() {
141
- const { nowFrame } = this;
119
+ const {nowFrame: nowFrame} = this;
142
120
  if (nowFrame) {
143
121
  const data = this.__;
144
122
  const width = nowFrame.width / data.pixelRatio;
145
123
  const height = nowFrame.height / data.pixelRatio;
146
- if (data.width !== width || data.height !== height)
147
- this.forceUpdate('width');
124
+ if (data.width !== width || data.height !== height) this.forceUpdate("width");
148
125
  data.__naturalWidth = width;
149
126
  data.__naturalHeight = height;
150
127
  }
151
128
  }
152
129
  __drawContent(canvas, _options) {
153
- const { nowFrame } = this, { width, height } = this.__;
154
- if (nowFrame)
155
- canvas.drawImage(nowFrame.view, nowFrame.x, nowFrame.y, nowFrame.width, nowFrame.height, 0, 0, width, height);
130
+ const {nowFrame: nowFrame} = this, {width: width, height: height} = this.__;
131
+ if (nowFrame) canvas.drawImage(nowFrame.view, nowFrame.x, nowFrame.y, nowFrame.width, nowFrame.height, 0, 0, width, height);
156
132
  }
157
133
  destroy() {
158
- if (this.robotFrames)
159
- this.robotFrames = null;
134
+ if (this.robotFrames) this.robotFrames = null;
160
135
  super.destroy();
161
136
  }
162
137
  };
163
- __decorate([
164
- dataProcessor(RobotData)
165
- ], Robot.prototype, "__", void 0);
166
- __decorate([
167
- boundsType()
168
- ], Robot.prototype, "robot", void 0);
169
- __decorate([
170
- dataType()
171
- ], Robot.prototype, "actions", void 0);
172
- __decorate([
173
- dataType('')
174
- ], Robot.prototype, "action", void 0);
175
- __decorate([
176
- surfaceType(0)
177
- ], Robot.prototype, "now", void 0);
178
- __decorate([
179
- dataType(12)
180
- ], Robot.prototype, "FPS", void 0);
181
- __decorate([
182
- dataType(true)
183
- ], Robot.prototype, "loop", void 0);
184
- Robot = __decorate([
185
- registerUI()
186
- ], Robot);
187
138
 
188
- Plugin.add('robot');
139
+ __decorate([ dataProcessor(RobotData) ], Robot.prototype, "__", void 0);
140
+
141
+ __decorate([ boundsType() ], Robot.prototype, "robot", void 0);
142
+
143
+ __decorate([ dataType() ], Robot.prototype, "actions", void 0);
144
+
145
+ __decorate([ dataType("") ], Robot.prototype, "action", void 0);
146
+
147
+ __decorate([ surfaceType(0) ], Robot.prototype, "now", void 0);
148
+
149
+ __decorate([ dataType(12) ], Robot.prototype, "FPS", void 0);
150
+
151
+ __decorate([ dataType(true) ], Robot.prototype, "loop", void 0);
152
+
153
+ Robot = __decorate([ registerUI() ], Robot);
154
+
155
+ Plugin.add("robot");
189
156
 
190
157
  export { Robot, RobotData };
@@ -1,2 +1,2 @@
1
- import{UIData as t,dataProcessor as o,boundsType as e,dataType as i,surfaceType as s,registerUI as r,UI as n,ImageManager as h,ImageEvent as a,Plugin as _}from"@leafer-ui/draw";function d(t,o,e,i){var s,r=arguments.length,n=r<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,o,e,i);else for(var h=t.length-1;h>=0;h--)(s=t[h])&&(n=(r<3?s(n):r>3?s(o,e,n):s(o,e))||n);return r>3&&n&&Object.defineProperty(o,e,n),n}"function"==typeof SuppressedError&&SuppressedError;class p extends t{get __drawAfterFill(){return!0}setRobot(t){this._robot=t,this.__leaf.__updateRobot()}setAction(t){this._action=t,this.__leaf.__updateAction()}}let c=class extends n{get __tag(){return"Robot"}get nowFrame(){return this.robotFrames&&this.robotFrames[this.now]}constructor(t){super(t)}play(){this.running=!0}pause(){this.running=!1}stop(){this.pause()}__updateRobot(){const{robot:t}=this;if(this.robotFrames=[],!t)return;let o=0;t instanceof Array?t.forEach((t=>this.__loadRobot(t,o,o+=t.total||1))):this.__loadRobot(t,0,t.total)}__updateAction(){const t=this.actions[this.action];if(this.stop(),this.__timer&&clearTimeout(this.__timer),void 0!==t)if("number"==typeof t)this.now=t;else if("object"==typeof t){const o=t instanceof Array,e=o?t:t.keyframes;this.__action=o?void 0:t;const{length:i}=e;if(i>1){const t=this.now=e[0],o=e[e.length-1];this.play(),this.__runAction(t,o)}else i&&(this.now=e[0])}}__loadRobot(t,o,e){for(let t=o;t<e;t++)this.robotFrames.push(void 0);const i=h.get(t);i.ready?this.__createFrames(i,t,o,e):i.load((()=>this.__createFrames(i,t,o,e)))}__createFrames(t,o,e,i){const{offset:s,size:r,total:n}=o,{width:h,height:_}=r&&("number"==typeof r?{width:r,height:r}:r)||(n>1?this:t);let d=s?s.x:0,p=s?s.y:0;for(let o=e;o<i;o++)this.robotFrames[o]={view:t.view,x:d,y:p,width:h,height:_},d+h>=t.width?(d=0,p+=_):d+=h;this.__updateRobotBounds(),this.forceRender(),this.emitEvent(new a(a.LOADED,{image:t}))}__runAction(t,o){let{FPS:e,loop:i,__action:s}=this;s&&(s.FPS&&(e=s.FPS),void 0!==s.loop&&(i=s.loop)),this.__timer=setTimeout((()=>{if(this.running){if(this.now===o){if(!i)return this.stop();this.now=t}else this.now++;this.__updateRobotBounds()}this.__runAction(t,o)}),1e3/e)}__updateRobotBounds(){const{nowFrame:t}=this;if(t){const o=this.__,e=t.width/o.pixelRatio,i=t.height/o.pixelRatio;o.width===e&&o.height===i||this.forceUpdate("width"),o.__naturalWidth=e,o.__naturalHeight=i}}__drawContent(t,o){const{nowFrame:e}=this,{width:i,height:s}=this.__;e&&t.drawImage(e.view,e.x,e.y,e.width,e.height,0,0,i,s)}destroy(){this.robotFrames&&(this.robotFrames=null),super.destroy()}};d([o(p)],c.prototype,"__",void 0),d([e()],c.prototype,"robot",void 0),d([i()],c.prototype,"actions",void 0),d([i("")],c.prototype,"action",void 0),d([s(0)],c.prototype,"now",void 0),d([i(12)],c.prototype,"FPS",void 0),d([i(!0)],c.prototype,"loop",void 0),c=d([r()],c),_.add("robot");export{c as Robot,p as RobotData};
1
+ import{UIData as t,dataProcessor as o,boundsType as e,dataType as i,surfaceType as s,registerUI as r,UI as h,isArray as n,isUndefined as a,isNumber as _,isObject as d,ImageManager as p,ImageEvent as c,Plugin as l}from"@leafer-ui/draw";function u(t,o,e,i){var s,r=arguments.length,h=r<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)h=Reflect.decorate(t,o,e,i);else for(var n=t.length-1;n>=0;n--)(s=t[n])&&(h=(r<3?s(h):r>3?s(o,e,h):s(o,e))||h);return r>3&&h&&Object.defineProperty(o,e,h),h}"function"==typeof SuppressedError&&SuppressedError;class f extends t{get __drawAfterFill(){return!0}setRobot(t){this._robot=t,this.__leaf.__updateRobot()}setAction(t){this._action=t,this.__leaf.__updateAction()}}let w=class extends h{get __tag(){return"Robot"}get nowFrame(){return this.robotFrames&&this.robotFrames[this.now]}constructor(t){super(t)}play(){this.running=!0}pause(){this.running=!1}stop(){this.pause()}__updateRobot(){const{robot:t}=this;if(this.robotFrames=[],!t)return;let o=0;n(t)?t.forEach(t=>this.__loadRobot(t,o,o+=t.total||1)):this.__loadRobot(t,0,t.total)}__updateAction(){const t=this.actions[this.action];if(this.stop(),this.__timer&&clearTimeout(this.__timer),!a(t))if(_(t))this.now=t;else if(d(t)){const o=n(t),e=o?t:t.keyframes;this.__action=o?void 0:t;const{length:i}=e;if(i>1){const t=this.now=e[0],o=e[e.length-1];this.play(),this.__runAction(t,o)}else i&&(this.now=e[0])}}__loadRobot(t,o,e){for(let t=o;t<e;t++)this.robotFrames.push(void 0);const i=p.get(t);i.ready?this.__createFrames(i,t,o,e):i.load(()=>this.__createFrames(i,t,o,e))}__createFrames(t,o,e,i){const{offset:s,size:r,total:h}=o,{width:n,height:a}=r&&(_(r)?{width:r,height:r}:r)||(h>1?this:t);let d=s?s.x:0,p=s?s.y:0;for(let o=e;o<i;o++)this.robotFrames[o]={view:t.view,x:d,y:p,width:n,height:a},d+n>=t.width?(d=0,p+=a):d+=n;this.__updateRobotBounds(),this.forceRender(),this.emitEvent(new c(c.LOADED,{image:t}))}__runAction(t,o){let{FPS:e,loop:i,__action:s}=this;s&&(s.FPS&&(e=s.FPS),a(s.loop)||(i=s.loop)),this.__timer=setTimeout(()=>{if(this.running){if(this.now===o){if(!i)return this.stop();this.now=t}else this.now++;this.__updateRobotBounds()}this.__runAction(t,o)},1e3/e)}__updateRobotBounds(){const{nowFrame:t}=this;if(t){const o=this.__,e=t.width/o.pixelRatio,i=t.height/o.pixelRatio;o.width===e&&o.height===i||this.forceUpdate("width"),o.__naturalWidth=e,o.__naturalHeight=i}}__drawContent(t,o){const{nowFrame:e}=this,{width:i,height:s}=this.__;e&&t.drawImage(e.view,e.x,e.y,e.width,e.height,0,0,i,s)}destroy(){this.robotFrames&&(this.robotFrames=null),super.destroy()}};u([o(f)],w.prototype,"__",void 0),u([e()],w.prototype,"robot",void 0),u([i()],w.prototype,"actions",void 0),u([i("")],w.prototype,"action",void 0),u([s(0)],w.prototype,"now",void 0),u([i(12)],w.prototype,"FPS",void 0),u([i(!0)],w.prototype,"loop",void 0),w=u([r()],w),l.add("robot");export{w as Robot,f as RobotData};
2
2
  //# sourceMappingURL=robot.esm.min.js.map