revas 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +61 -1
  2. package/dist/chunk-JPUKLNW3.js +1710 -0
  3. package/dist/chunk-JPUKLNW3.js.map +1 -0
  4. package/dist/revas-common.cjs +1768 -0
  5. package/dist/revas-common.cjs.map +1 -0
  6. package/dist/revas-common.d.cts +363 -0
  7. package/dist/revas-common.d.ts +363 -0
  8. package/dist/revas-common.js +3 -0
  9. package/dist/revas-common.js.map +1 -0
  10. package/dist/revas.cjs +1881 -0
  11. package/dist/revas.cjs.map +1 -0
  12. package/dist/revas.d.cts +13 -0
  13. package/dist/revas.d.ts +13 -0
  14. package/dist/revas.js +108 -1967
  15. package/dist/revas.js.map +1 -1
  16. package/package.json +58 -45
  17. package/.eslintcache +0 -1
  18. package/common.d.ts +0 -1
  19. package/common.js +0 -1
  20. package/dist/revas.common.js +0 -1861
  21. package/dist/revas.common.js.map +0 -1
  22. package/dist/revas.es.js +0 -1932
  23. package/dist/revas.es.js.map +0 -1
  24. package/dist/types/develop/App.d.ts +0 -8
  25. package/dist/types/develop/Intro/About.d.ts +0 -2
  26. package/dist/types/develop/Intro/Animation.d.ts +0 -2
  27. package/dist/types/develop/Intro/Component.d.ts +0 -2
  28. package/dist/types/develop/Intro/Entry.d.ts +0 -6
  29. package/dist/types/develop/Intro/Gesture.d.ts +0 -2
  30. package/dist/types/develop/Intro/Interactable.d.ts +0 -10
  31. package/dist/types/develop/Intro/Navbar.d.ts +0 -6
  32. package/dist/types/develop/Intro/Panel.d.ts +0 -14
  33. package/dist/types/develop/Intro/Style.d.ts +0 -2
  34. package/dist/types/develop/Intro/index.d.ts +0 -2
  35. package/dist/types/develop/Music/Player.d.ts +0 -79
  36. package/dist/types/develop/Music/data.d.ts +0 -8
  37. package/dist/types/develop/Music/index.d.ts +0 -23
  38. package/dist/types/develop/Music/styles.d.ts +0 -19
  39. package/dist/types/develop/Timeline/data.d.ts +0 -5
  40. package/dist/types/develop/Timeline/index.d.ts +0 -11
  41. package/dist/types/develop/common/back.d.ts +0 -2
  42. package/dist/types/develop/common/simple-router.d.ts +0 -44
  43. package/dist/types/develop/serviceWorker.d.ts +0 -7
  44. package/dist/types/index.d.ts +0 -1
  45. package/dist/types/revas/common.d.ts +0 -24
  46. package/dist/types/revas/components/Context.d.ts +0 -12
  47. package/dist/types/revas/components/Image.d.ts +0 -20
  48. package/dist/types/revas/components/LinearGradient.d.ts +0 -38
  49. package/dist/types/revas/components/ListView.d.ts +0 -22
  50. package/dist/types/revas/components/ScrollView.d.ts +0 -43
  51. package/dist/types/revas/components/Text.d.ts +0 -16
  52. package/dist/types/revas/components/Touchable.d.ts +0 -34
  53. package/dist/types/revas/components/View.d.ts +0 -3
  54. package/dist/types/revas/components/common/Scroller.d.ts +0 -35
  55. package/dist/types/revas/components/common/drawImage.d.ts +0 -3
  56. package/dist/types/revas/components/common/drawText.d.ts +0 -17
  57. package/dist/types/revas/components/common/imageLoader.d.ts +0 -2
  58. package/dist/types/revas/core/Animated.d.ts +0 -59
  59. package/dist/types/revas/core/Canvas.d.ts +0 -17
  60. package/dist/types/revas/core/Container.d.ts +0 -18
  61. package/dist/types/revas/core/Node.d.ts +0 -46
  62. package/dist/types/revas/core/css-layout/index.d.ts +0 -9
  63. package/dist/types/revas/core/draw.d.ts +0 -4
  64. package/dist/types/revas/core/offscreen.d.ts +0 -11
  65. package/dist/types/revas/core/reconciler.d.ts +0 -5
  66. package/dist/types/revas/core/touch.d.ts +0 -3
  67. package/dist/types/revas/core/utils.d.ts +0 -22
  68. package/dist/types/revas/core/yoga-layout/index.d.ts +0 -3
  69. package/dist/types/revas/core/yoga-layout/init.d.ts +0 -3
  70. package/dist/types/revas/core/yoga-layout/style.d.ts +0 -3
  71. package/dist/types/revas/index.d.ts +0 -2
  72. package/dist/types/revas/web/index.d.ts +0 -1
  73. package/dist/types/revas/web/render.d.ts +0 -7
  74. package/doc/API.md +0 -241
  75. package/doc/README-zh.md +0 -266
  76. package/public/favicon.ico +0 -0
  77. package/public/index.html +0 -64
  78. package/public/logo192.png +0 -0
  79. package/public/logo512.png +0 -0
  80. package/public/manifest.json +0 -25
  81. package/public/robots.txt +0 -2
  82. package/public/stats.min.js +0 -5
  83. package/public/touch-emulator.js +0 -363
  84. package/rollup.config.ts +0 -44
  85. package/tsconfig.json +0 -30
@@ -1,1861 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var React = require('react');
8
- var tslib = require('tslib');
9
- var ReactReconciler = _interopDefault(require('react-reconciler'));
10
- var bezier = _interopDefault(require('bezier-easing'));
11
- var Yoga = _interopDefault(require('yoga-layout-wasm/asm'));
12
-
13
- function View(props) {
14
- return React.createElement('View', props);
15
- }
16
-
17
- function noop() { }
18
- var EMPTY_OBJECT = Object.freeze({});
19
- var EMPTY_ARRAY = Object.freeze([]);
20
- function flatten(array) {
21
- var flattend = [];
22
- (function flat(array) {
23
- array.forEach(function (el) {
24
- if (Array.isArray(el)) {
25
- flat(el);
26
- }
27
- else {
28
- flattend.push(el);
29
- }
30
- });
31
- })(array);
32
- return flattend;
33
- }
34
- var now = typeof performance === 'object' && typeof performance.now === 'function' ? function () { return performance.now(); } : function () { return Date.now(); };
35
- function observeAnimatedValue(value, observer, defaultValue) {
36
- if (value === undefined) {
37
- return defaultValue;
38
- }
39
- if (value && value.getValue) {
40
- return value.getValue(observer);
41
- }
42
- return value;
43
- }
44
- function applyAnimated(style, callback) {
45
- if (style.animated) {
46
- // Animated Styles
47
- for (var key in style) {
48
- style[key] = observeAnimatedValue(style[key], callback);
49
- }
50
- }
51
- return style;
52
- }
53
- function getMergedStyleFromNode(node, callback) {
54
- var _a = node.props.style, style = _a === void 0 ? EMPTY_ARRAY : _a;
55
- return applyAnimated(Object.assign.apply(Object, tslib.__spreadArrays([{}], flatten([style]))), callback);
56
- }
57
- function getFrameFromNode(node) {
58
- var frame = node.frame;
59
- return frame;
60
- }
61
- function sortByZIndexAscending(a, b) {
62
- var styleA = getMergedStyleFromNode(a);
63
- var styleB = getMergedStyleFromNode(b);
64
- return (styleA.zIndex || 0) - (styleB.zIndex || 0);
65
- }
66
- function clamp(n, min, max) {
67
- return Math.min(Math.max(n, min), max);
68
- }
69
- var ASTRAL_RANGE = /\ud83c[\udffb-\udfff](?=\ud83c[\udffb-\udfff])|(?:[^\ud800-\udfff][\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]?|[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?)*/g;
70
- var WORD_RANGE = /\w+|\ud83c[\udffb-\udfff](?=\ud83c[\udffb-\udfff])|(?:[^\ud800-\udfff][\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]?|[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?)*/g;
71
- function getChars(str) {
72
- return str.match(ASTRAL_RANGE) || EMPTY_ARRAY;
73
- }
74
- function getWords(str) {
75
- return str.match(WORD_RANGE) || EMPTY_ARRAY;
76
- }
77
- function setShadow(canvas, color, x, y, blur) {
78
- if (x === void 0) { x = 0; }
79
- if (y === void 0) { y = 0; }
80
- if (blur === void 0) { blur = 0; }
81
- if (color && (x || y || blur)) {
82
- var ctx_1 = canvas.context;
83
- var shadowBlur_1 = ctx_1.shadowBlur, shadowColor_1 = ctx_1.shadowColor, shadowOffsetX_1 = ctx_1.shadowOffsetX, shadowOffsetY_1 = ctx_1.shadowOffsetY;
84
- ctx_1.shadowBlur = blur;
85
- ctx_1.shadowColor = color;
86
- ctx_1.shadowOffsetX = x;
87
- ctx_1.shadowOffsetY = y;
88
- return function resetShadow() {
89
- ctx_1.shadowBlur = shadowBlur_1;
90
- ctx_1.shadowColor = shadowColor_1;
91
- ctx_1.shadowOffsetX = shadowOffsetX_1;
92
- ctx_1.shadowOffsetY = shadowOffsetY_1;
93
- };
94
- }
95
- return noop;
96
- }
97
- function pushOpacity(canvas, opacity) {
98
- if (opacity !== null && opacity < 1 && opacity >= 0) {
99
- var cachedOpacity_1 = canvas.context.globalAlpha || 1;
100
- canvas.context.globalAlpha = cachedOpacity_1 * opacity;
101
- return function popOpacity() {
102
- canvas.context.globalAlpha = cachedOpacity_1;
103
- };
104
- }
105
- return noop;
106
- }
107
- var adapter = {
108
- createImage: function () { return new Image(); },
109
- };
110
-
111
- var DEFAULT_MEASURE = [[], 0];
112
- function measureLines(canvas, chars, boxWidth, numberOfLines) {
113
- var lines = [];
114
- var width = 0;
115
- var text = '';
116
- var cursor = -1;
117
- function pushLine(charWidth, char, force) {
118
- if (charWidth === void 0) { charWidth = 0; }
119
- if (char === void 0) { char = ''; }
120
- if (force === void 0) { force = false; }
121
- if (force || text) {
122
- lines.push({ width: width, text: text });
123
- }
124
- if (cursor < chars.length && numberOfLines > 0 && lines.length >= numberOfLines) {
125
- var lastLine = lines[lines.length - 1];
126
- lastLine.text = lastLine.text.slice(0, -2) + "...";
127
- lastLine.width = canvas.context.measureText(lastLine.text).width;
128
- cursor = chars.length + 1;
129
- }
130
- else {
131
- width = charWidth;
132
- text = char.trim();
133
- }
134
- }
135
- while (cursor++ <= chars.length) {
136
- if (chars.length > cursor) {
137
- var char = chars[cursor];
138
- if (char === '\n') {
139
- pushLine(0, '', true);
140
- }
141
- else {
142
- var charWidth = canvas.context.measureText(char).width;
143
- if (charWidth + width > boxWidth) {
144
- pushLine(charWidth, char);
145
- }
146
- else {
147
- width += charWidth;
148
- text += char;
149
- }
150
- }
151
- }
152
- else {
153
- pushLine();
154
- }
155
- }
156
- return lines;
157
- }
158
- function splitContent(content, wordBreak) {
159
- switch (wordBreak) {
160
- case 'break-all':
161
- return getChars(content);
162
- case 'keep-all':
163
- return [content];
164
- default:
165
- return getWords(content);
166
- }
167
- }
168
- function applyTextStyle(canvas, options) {
169
- var _a = options.textStyle, fontStyle = _a.fontStyle, fontWeight = _a.fontWeight, fontSize = _a.fontSize, fontFamily = _a.fontFamily, textBaseline = _a.textBaseline, color = _a.color;
170
- // Apply Styles
171
- canvas.context.font = fontStyle + " " + fontWeight + " " + fontSize + "px " + fontFamily;
172
- canvas.context.fillStyle = color;
173
- canvas.context.textBaseline = textBaseline;
174
- }
175
- function measureText(canvas, options) {
176
- var lines = measureLines(canvas, splitContent(options.content, options.textStyle.wordBreak), options.frame.width, options.numberOfLines);
177
- return [lines, options.textStyle.lineHeight * lines.length];
178
- }
179
- function drawText(canvas, options, lines) {
180
- var style = options.textStyle, frame = options.frame;
181
- // Shadow:
182
- var resetShadow = setShadow(canvas, style.textShadowColor, style.textShadowOffsetX, style.textShadowOffsetY, style.textShadowBlur);
183
- for (var i = 0; i < lines.length; i++) {
184
- var line = lines[i];
185
- var x = frame.x;
186
- switch (style.textAlign) {
187
- case 'center':
188
- x = x + frame.width / 2 - line.width / 2;
189
- break;
190
- case 'right':
191
- x = x + frame.width - line.width;
192
- break;
193
- }
194
- canvas.context.fillText(line.text, x, style.lineHeight * (i + 0.5) + frame.y);
195
- }
196
- resetShadow();
197
- }
198
-
199
- var Text = /** @class */ (function (_super) {
200
- tslib.__extends(Text, _super);
201
- function Text() {
202
- var _this = _super !== null && _super.apply(this, arguments) || this;
203
- _this.state = { height: 0 };
204
- _this._measured = DEFAULT_MEASURE;
205
- _this.drawText = function (canvas, node) {
206
- var content = getTextFromNode(node);
207
- if (content) {
208
- var options = {
209
- numberOfLines: node.props.numberOfLines || 0,
210
- textStyle: getTextStyleFromNode(node),
211
- frame: getFrameFromNode(node),
212
- content: content,
213
- };
214
- applyTextStyle(canvas, options);
215
- if (textPropsChanged(options, _this._drawed)) {
216
- _this._measured = measureText(canvas, options);
217
- _this._drawed = options;
218
- }
219
- var _a = _this._measured, lines = _a[0], height = _a[1];
220
- if (height !== _this.state.height) {
221
- _this.setState({ height: height });
222
- }
223
- else {
224
- drawText(canvas, options, lines);
225
- }
226
- }
227
- };
228
- return _this;
229
- }
230
- Text.prototype.render = function () {
231
- var _a = this.props, children = _a.children, numberOfLines = _a.numberOfLines, others = tslib.__rest(_a, ["children", "numberOfLines"]);
232
- return React.createElement('View', others, React.createElement('Text', {
233
- content: children,
234
- customDrawer: this.drawText,
235
- textStyle: others.style,
236
- style: this.state,
237
- numberOfLines: numberOfLines,
238
- $ready: Boolean(this._drawed),
239
- }));
240
- };
241
- return Text;
242
- }(React.Component));
243
- var TEXT_STYLES_LIST = [
244
- 'fontStyle',
245
- 'fontWeight',
246
- 'fontSize',
247
- 'fontFamily',
248
- 'textBaseline',
249
- 'wordBreak',
250
- 'lineHeight',
251
- ];
252
- var DEFAULT_TEXTSTYLE = {
253
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue'",
254
- fontWeight: 'normal',
255
- fontSize: 14,
256
- color: '#000',
257
- fontStyle: 'normal',
258
- textBaseline: 'middle',
259
- };
260
- function textStyleChanged(left, right) {
261
- for (var i = 0; i < TEXT_STYLES_LIST.length; i++) {
262
- var item = TEXT_STYLES_LIST[i];
263
- if (left[item] !== right[item]) {
264
- return true;
265
- }
266
- }
267
- return false;
268
- }
269
- function textPropsChanged(left, right) {
270
- if (!right) {
271
- return true;
272
- }
273
- if (left.content !== right.content) {
274
- return true;
275
- }
276
- if (left.numberOfLines !== right.numberOfLines) {
277
- return true;
278
- }
279
- if (left.frame.width !== right.frame.width) {
280
- return true;
281
- }
282
- return textStyleChanged(left.textStyle, right.textStyle);
283
- }
284
- function getTextFromNode(node) {
285
- var frame = getFrameFromNode(node);
286
- if (frame.width > 0) {
287
- var content = node.props.content;
288
- if (typeof content === 'string') {
289
- return content;
290
- }
291
- else if (Array.isArray(content)) {
292
- return content.join('');
293
- }
294
- }
295
- return '';
296
- }
297
- function getTextStyleFromNode(node) {
298
- var style = Object.assign.apply(Object, tslib.__spreadArrays([{}, DEFAULT_TEXTSTYLE], flatten([node.props.textStyle])));
299
- style.lineHeight = style.lineHeight || style.fontSize * 1.1;
300
- return applyAnimated(style);
301
- }
302
- // TODO: nested text support
303
-
304
- var Frame = /** @class */ (function () {
305
- function Frame(x, y, width, height) {
306
- if (x === void 0) { x = 0; }
307
- if (y === void 0) { y = 0; }
308
- if (width === void 0) { width = 0; }
309
- if (height === void 0) { height = 0; }
310
- this.x = x;
311
- this.y = y;
312
- this.width = width;
313
- this.height = height;
314
- }
315
- return Frame;
316
- }());
317
- var Node = /** @class */ (function () {
318
- function Node(type, props) {
319
- this.type = type;
320
- this.props = props;
321
- this.children = [];
322
- this.frame = new Frame();
323
- }
324
- Object.defineProperty(Node.prototype, "$ready", {
325
- get: function () {
326
- if (this.props.$ready === false) {
327
- return false;
328
- }
329
- for (var i = 0; i < this.children.length; i++) {
330
- var child = this.children[i];
331
- if (child.$ready === false) {
332
- return false;
333
- }
334
- }
335
- return true;
336
- },
337
- enumerable: false,
338
- configurable: true
339
- });
340
- return Node;
341
- }());
342
-
343
- function checkAndRemove(parent, child) {
344
- var index = parent.children.indexOf(child);
345
- if (index >= 0) {
346
- parent.children.splice(index, 1);
347
- }
348
- }
349
- function appendChild(parent, child) {
350
- checkAndRemove(parent, child);
351
- parent.children.push(child);
352
- child.parent = parent;
353
- }
354
- var unused = {
355
- unhideTextInstance: function () {
356
- // noop
357
- },
358
- mountEventComponent: function () {
359
- // noop
360
- },
361
- getFundamentalComponentInstance: function () {
362
- throw new Error('Not yet implemented.');
363
- },
364
- mountFundamentalComponent: function () {
365
- throw new Error('Not yet implemented.');
366
- },
367
- shouldUpdateFundamentalComponent: function () {
368
- throw new Error('Not yet implemented.');
369
- },
370
- unmountFundamentalComponent: function () {
371
- throw new Error('Not yet implemented.');
372
- },
373
- getInstanceFromNode: function () {
374
- throw new Error('Not yet implemented.');
375
- },
376
- isOpaqueHydratingObject: function () {
377
- throw new Error('Not yet implemented');
378
- },
379
- makeOpaqueHydratingObject: function () {
380
- throw new Error('Not yet implemented.');
381
- },
382
- makeClientIdInDEV: function () {
383
- throw new Error('Not yet implemented');
384
- },
385
- beforeActiveInstanceBlur: function () {
386
- // noop
387
- },
388
- afterActiveInstanceBlur: function () {
389
- // noop
390
- },
391
- preparePortalMount: function () {
392
- // noop
393
- },
394
- };
395
- var renderer = ReactReconciler(tslib.__assign(tslib.__assign({ supportsHydration: false, supportsPersistence: false, supportsMutation: true, isPrimaryRenderer: false }, unused), { createInstance: function (type, props) {
396
- return new Node(type, props);
397
- },
398
- createTextInstance: function () {
399
- throw new Error('Revas: string cannot be child out of <Text/>');
400
- },
401
- appendChild: appendChild, appendInitialChild: appendChild, appendChildToContainer: function (container, instance) {
402
- if (instance.type !== 'Root') {
403
- throw new Error("wrong root instance type: " + instance.type);
404
- }
405
- container.setRoot(instance);
406
- },
407
- removeChild: function (parent, child) {
408
- checkAndRemove(parent, child);
409
- child.parent = void 0;
410
- },
411
- removeChildFromContainer: function (container) {
412
- container.setRoot();
413
- },
414
- insertBefore: function (parent, child, before) {
415
- checkAndRemove(parent, child);
416
- var beforeIndex = parent.children.indexOf(before);
417
- parent.children.splice(beforeIndex, 0, child);
418
- child.parent = parent;
419
- },
420
- insertInContainerBefore: function () {
421
- throw new Error("shouldn't be here: insertInContainerBefore");
422
- },
423
- clearContainer: function () {
424
- // TODO implement this
425
- },
426
- finalizeInitialChildren: function () {
427
- return false;
428
- },
429
- getPublicInstance: function (instance) {
430
- return instance;
431
- },
432
- prepareUpdate: function () {
433
- return true;
434
- },
435
- commitUpdate: function (instance, updatePayload, type, oldProps, newProps) {
436
- instance.props = newProps;
437
- },
438
- prepareForCommit: function () {
439
- return null;
440
- },
441
- resetAfterCommit: function (container) {
442
- container.draw(true);
443
- }, resetTextContent: noop, getRootHostContext: function () {
444
- return {};
445
- },
446
- getChildHostContext: function (parentHostContext) {
447
- return parentHostContext;
448
- },
449
- shouldSetTextContent: function () {
450
- return false;
451
- }, shouldDeprioritizeSubtree: function () { return false; }, scheduleDeferredCallback: noop, cancelDeferredCallback: noop, setTimeout: setTimeout,
452
- clearTimeout: clearTimeout, noTimeout: -1, now: now }));
453
-
454
- var CachedImage = /** @class */ (function () {
455
- function CachedImage(src) {
456
- var _this = this;
457
- this.src = src;
458
- this.image = adapter.createImage();
459
- this.targets = [];
460
- this._ready = false;
461
- this.onload = function () {
462
- _this._ready = true;
463
- renderer.batchedUpdates(function () {
464
- _this.targets.forEach(function (target) { return target(_this.image); });
465
- });
466
- };
467
- this.onerror = function () { };
468
- if (!this.image) {
469
- throw new Error('Revas: createImage must be initialized');
470
- }
471
- this.image.onload = this.onload;
472
- this.image.onerror = this.onerror;
473
- this.image.src = src;
474
- }
475
- Object.defineProperty(CachedImage.prototype, "empty", {
476
- get: function () {
477
- return this.targets.length === 0;
478
- },
479
- enumerable: false,
480
- configurable: true
481
- });
482
- CachedImage.prototype.add = function (target) {
483
- if (this.targets.indexOf(target) < 0) {
484
- this.targets.push(target);
485
- if (this._ready) {
486
- target(this.image);
487
- }
488
- }
489
- };
490
- CachedImage.prototype.remove = function (target) {
491
- var index = this.targets.indexOf(target);
492
- this.targets.splice(index, 1);
493
- };
494
- return CachedImage;
495
- }());
496
- var cache = new Map();
497
- function get(src, target) {
498
- if (!cache.has(src)) {
499
- cache.set(src, new CachedImage(src));
500
- }
501
- var cached = cache.get(src);
502
- target && cached.add(target);
503
- return cached.image;
504
- }
505
- function remove(src, target) {
506
- if (cache.has(src)) {
507
- var cached = cache.get(src);
508
- cached.remove(target);
509
- if (cached.empty) {
510
- cache.delete(src);
511
- }
512
- }
513
- }
514
-
515
- function drawImage(canvas, node, flags) {
516
- var image = get(node.props.src);
517
- if (image.height <= 0) {
518
- return;
519
- }
520
- var frame = getFrameFromNode(node);
521
- var width = frame.width, height = frame.height, x = frame.x, y = frame.y;
522
- if (width <= 0 || height <= 0) {
523
- return;
524
- }
525
- var style = getMergedStyleFromNode(node);
526
- var actualSize = {
527
- width: image.width,
528
- height: image.height,
529
- };
530
- var focusPoint = style.focusPoint || {
531
- x: actualSize.width * 0.5,
532
- y: actualSize.height * 0.5,
533
- };
534
- var hasClip = flags.hasRadius && !flags.hasClip;
535
- if (hasClip) {
536
- canvas.context.save();
537
- canvas.context.clip();
538
- }
539
- if (style.resizeMode === 'contain') {
540
- var scale = Math.min(width / actualSize.width, height / actualSize.height) || 1;
541
- var scaledSize = {
542
- width: actualSize.width * scale,
543
- height: actualSize.height * scale,
544
- };
545
- // Clip the image to rectangle (sx, sy, sw, sh).
546
- var sw = Math.round(actualSize.width);
547
- var sh = Math.round(actualSize.height);
548
- // Scale the image to dimensions (dw, dh).
549
- var dw = Math.round(scaledSize.width);
550
- var dh = Math.round(scaledSize.height);
551
- // Draw the image on the canvas at coordinates (dx, dy).
552
- var dx = Math.round((width - scaledSize.width) / 2 + x);
553
- var dy = Math.round((height - scaledSize.height) / 2 + y);
554
- canvas.context.drawImage(image, 0, 0, sw, sh, dx, dy, dw, dh);
555
- }
556
- else {
557
- var scale = Math.max(width / actualSize.width, height / actualSize.height) || 1;
558
- var scaledSize = {
559
- width: actualSize.width * scale,
560
- height: actualSize.height * scale,
561
- };
562
- // Clip the image to rectangle (sx, sy, sw, sh).
563
- var sx = Math.round(clamp(width * 0.5 - focusPoint.x * scale, width - scaledSize.width, 0)) * (-1 / scale);
564
- var sy = Math.round(clamp(height * 0.5 - focusPoint.y * scale, height - scaledSize.height, 0)) * (-1 / scale);
565
- var sw = Math.round(actualSize.width - sx * 2);
566
- var sh = Math.round(actualSize.height - sy * 2);
567
- // Scale the image to dimensions (dw, dh).
568
- var dw = Math.round(width);
569
- var dh = Math.round(height);
570
- // Draw the image on the canvas at coordinates (dx, dy).
571
- var dx = Math.round(x);
572
- var dy = Math.round(y);
573
- canvas.context.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh);
574
- }
575
- if (hasClip) {
576
- canvas.context.restore();
577
- }
578
- }
579
-
580
- var DEFAULT_STYLE = { path: true };
581
- function ImageView(props) {
582
- var src = props.src, style = props.style;
583
- var _a = React.useState(false), ready = _a[0], setReady = _a[1];
584
- React.useEffect(function () {
585
- if (src) {
586
- var onReady_1 = function () { return setReady(true); };
587
- get(src, onReady_1);
588
- return function () { return remove(src, onReady_1); };
589
- }
590
- }, [src]);
591
- return React.createElement('Image', tslib.__assign(tslib.__assign({ customDrawer: ready ? drawImage : void 0 }, props), { style: [DEFAULT_STYLE, style], $ready: ready }));
592
- }
593
-
594
- var AnimatedNode = /** @class */ (function () {
595
- function AnimatedNode() {
596
- }
597
- AnimatedNode.prototype.interpolate = function (inRange, outRange, ease) {
598
- if (ease === void 0) { ease = Easing.linear; }
599
- return new AnimatedInterpolate(this, inRange, outRange, ease);
600
- };
601
- return AnimatedNode;
602
- }());
603
- var AnimatedValue = /** @class */ (function (_super) {
604
- tslib.__extends(AnimatedValue, _super);
605
- function AnimatedValue(_value) {
606
- var _this = _super.call(this) || this;
607
- _this._value = _value;
608
- return _this;
609
- }
610
- AnimatedValue.prototype.setValue = function (value) {
611
- this._value = value;
612
- if (this._observer) {
613
- var observer = this._observer;
614
- this._observer = void 0;
615
- observer();
616
- }
617
- };
618
- AnimatedValue.prototype.getValue = function (observer) {
619
- if (observer) {
620
- this._observer = observer;
621
- }
622
- return this._value;
623
- };
624
- return AnimatedValue;
625
- }(AnimatedNode));
626
- var AnimatedInterpolate = /** @class */ (function (_super) {
627
- tslib.__extends(AnimatedInterpolate, _super);
628
- function AnimatedInterpolate(source, inRange, outRange, ease) {
629
- var _this = _super.call(this) || this;
630
- _this.source = source;
631
- _this.inRange = inRange;
632
- _this.outRange = outRange;
633
- _this.ease = ease;
634
- return _this;
635
- }
636
- // TODO: Check inRange is asc
637
- AnimatedInterpolate.prototype.getValue = function (observer) {
638
- var value = this.source.getValue(observer);
639
- var len = this.inRange.length;
640
- var i = 1;
641
- for (; i < len; i++) {
642
- var x1 = this.inRange[i];
643
- if (value < x1 || i === len - 1) {
644
- var x0 = this.inRange[i - 1];
645
- var y0 = this.outRange[i - 1];
646
- var y1 = this.outRange[i];
647
- var percent = (value - x0) / (x1 - x0);
648
- var result = (y1 - y0) * this.ease(percent) + y0;
649
- return result;
650
- }
651
- }
652
- return 0;
653
- };
654
- return AnimatedInterpolate;
655
- }(AnimatedNode));
656
- var AnimatedTiming = /** @class */ (function () {
657
- function AnimatedTiming(value, config) {
658
- var _this = this;
659
- this.value = value;
660
- this.config = config;
661
- this._startTime = 0;
662
- this._startValue = 0;
663
- this._next = 0;
664
- this._loop = function () {
665
- var duration = Date.now() - _this._startTime;
666
- if (duration < _this.config.duration) {
667
- var percent = duration / _this.config.duration;
668
- var inc = _this._ease(percent) * (_this.config.to - _this._startValue);
669
- _this.value.setValue(_this._startValue + inc);
670
- _this._next = requestAnimationFrame(_this._loop);
671
- }
672
- else {
673
- _this.value.setValue(_this.config.to);
674
- _this._onEnd && requestAnimationFrame(_this._onEnd);
675
- }
676
- };
677
- }
678
- Object.defineProperty(AnimatedTiming.prototype, "_ease", {
679
- get: function () {
680
- return this.config.ease || Easing.linear;
681
- },
682
- enumerable: false,
683
- configurable: true
684
- });
685
- AnimatedTiming.prototype.start = function (onEnd) {
686
- this._startTime = Date.now();
687
- this._startValue = this.value.getValue();
688
- this._onEnd = onEnd;
689
- this._next = requestAnimationFrame(this._loop);
690
- return this;
691
- };
692
- AnimatedTiming.prototype.stop = function () {
693
- cancelAnimationFrame(this._next);
694
- return this;
695
- };
696
- AnimatedTiming.prototype.promise = function () {
697
- var _this = this;
698
- return new Promise(function (resolve) { return (_this._onEnd = resolve); });
699
- };
700
- return AnimatedTiming;
701
- }());
702
- function timing(value, config) {
703
- return new AnimatedTiming(value, config);
704
- }
705
- var ease;
706
- function getEase() {
707
- if (!ease) {
708
- ease = bezier(0.42, 0, 1, 1);
709
- }
710
- return ease;
711
- }
712
- var Easing = {
713
- linear: function (t) {
714
- return t;
715
- },
716
- ease: function (t) {
717
- return getEase()(t);
718
- },
719
- /**
720
- * Runs an easing function forwards.
721
- */
722
- in: function (easing) {
723
- if (easing === void 0) { easing = getEase(); }
724
- return easing;
725
- },
726
- /**
727
- * Runs an easing function backwards.
728
- */
729
- out: function (easing) {
730
- if (easing === void 0) { easing = getEase(); }
731
- return function (t) { return 1 - easing(1 - t); };
732
- },
733
- /**
734
- * Makes any easing function symmetrical. The easing function will run
735
- * forwards for half of the duration, then backwards for the rest of the
736
- * duration.
737
- */
738
- inOut: function (easing) {
739
- if (easing === void 0) { easing = getEase(); }
740
- return function (t) {
741
- if (t < 0.5) {
742
- return easing(t * 2) / 2;
743
- }
744
- return 1 - easing((1 - t) * 2) / 2;
745
- };
746
- },
747
- bounce: function (t) {
748
- if (t < 1 / 2.75) {
749
- return 7.5625 * t * t;
750
- }
751
- if (t < 2 / 2.75) {
752
- var t2_1 = t - 1.5 / 2.75;
753
- return 7.5625 * t2_1 * t2_1 + 0.75;
754
- }
755
- if (t < 2.5 / 2.75) {
756
- var t2_2 = t - 2.25 / 2.75;
757
- return 7.5625 * t2_2 * t2_2 + 0.9375;
758
- }
759
- var t2 = t - 2.625 / 2.75;
760
- return 7.5625 * t2 * t2 + 0.984375;
761
- },
762
- elastic: function (bounciness) {
763
- if (bounciness === void 0) { bounciness = 1; }
764
- var p = bounciness * Math.PI;
765
- return function (t) { return 1 - Math.pow(Math.cos((t * Math.PI) / 2), 3) * Math.cos(t * p); };
766
- },
767
- };
768
-
769
- var Touchable = /** @class */ (function (_super) {
770
- tslib.__extends(Touchable, _super);
771
- function Touchable() {
772
- var _this = _super !== null && _super.apply(this, arguments) || this;
773
- _this._style = {
774
- opacity: new AnimatedValue(1),
775
- animated: true
776
- };
777
- _this._tid = '';
778
- _this._onTouchStart = function (e) {
779
- _this._tid = Object.keys(e.touches)[0];
780
- _this._start = e.touches[_this._tid];
781
- _this._style.opacity.setValue(_this.props.activeOpacity);
782
- _this.props.onPressIn && _this.props.onPressIn();
783
- };
784
- _this._onTouchEnd = function (e) {
785
- if (_this._start && e.touches[_this._tid]) {
786
- if (Math.abs(_this._start.x - e.touches[_this._tid].x) < 3 &&
787
- Math.abs(_this._start.y - e.touches[_this._tid].y) < 3) {
788
- _this.props.onPress && _this.props.onPress();
789
- }
790
- }
791
- _this._style.opacity.setValue(1);
792
- _this.props.onPressOut && _this.props.onPressOut();
793
- };
794
- return _this;
795
- }
796
- Touchable.prototype.render = function () {
797
- return React.createElement('Touchable', tslib.__assign(tslib.__assign({ onTouchStart: this._onTouchStart, onTouchEnd: this._onTouchEnd }, this.props), { style: [
798
- this.props.style,
799
- this._style
800
- ] }));
801
- };
802
- Touchable.defaultProps = {
803
- activeOpacity: 0.7
804
- };
805
- return Touchable;
806
- }(React.Component));
807
-
808
- var Handler = /** @class */ (function () {
809
- function Handler() {
810
- this.offset = 0;
811
- this.velocity = 0;
812
- this.max = -1;
813
- this.paging = 0;
814
- this._last = -1;
815
- }
816
- Handler.prototype.capture = function (value) {
817
- if (this._last < 0) {
818
- this._last = value;
819
- }
820
- };
821
- Handler.prototype.onMove = function (value, duration) {
822
- if (this._last >= 0 && duration > 0) {
823
- var move = this._last - value;
824
- this.velocity = move / duration;
825
- this._last = value;
826
- this.change(move);
827
- }
828
- };
829
- Handler.prototype.onEnd = function () {
830
- if (this._last >= 0) {
831
- this._last = -1;
832
- }
833
- };
834
- Handler.prototype.afterEnd = function (duration) {
835
- if (this._last < 0) {
836
- var absv = Math.abs(this.velocity);
837
- if (this.paging > 0 && absv <= 0.5 && this.offset < this.max) {
838
- // start reset to paging
839
- var distance = Math.round(this.offset / this.paging + this.velocity) * this.paging - this.offset;
840
- this.velocity = clamp(distance / 2000 + friction(this.velocity, duration, 0.01), -0.5, 0.5);
841
- if (Math.abs(distance) > 0.5 || absv > 0.05) {
842
- var move = this.velocity * duration;
843
- this.change(move);
844
- return true;
845
- }
846
- else {
847
- // end to paging
848
- this.change(distance);
849
- }
850
- }
851
- else if (absv > 0.05) {
852
- // scroll for free
853
- this.velocity = friction(this.velocity, duration, 0.002);
854
- var move = this.velocity * duration;
855
- this.change(move);
856
- return true;
857
- }
858
- else {
859
- this.velocity = 0;
860
- }
861
- }
862
- return false;
863
- };
864
- Handler.prototype.change = function (move) {
865
- var _offset = clamp(this.offset + move, 0, this.max > 0 ? this.max : 0);
866
- // check validate
867
- if (_offset !== this.offset) {
868
- this.offset = _offset;
869
- }
870
- else if (this._last < 0) {
871
- this.velocity = 0;
872
- }
873
- };
874
- return Handler;
875
- }());
876
- var Scroller = /** @class */ (function () {
877
- function Scroller(listener) {
878
- var _this = this;
879
- this.listener = listener;
880
- this._timestamp = 0;
881
- this._x = new Handler();
882
- this._y = new Handler();
883
- this._tid = '';
884
- this.horizontal = false;
885
- this.touchStart = function (e) {
886
- if (!_this._tid) {
887
- _this._tid = Object.keys(e.touches)[0];
888
- _this._timestamp = e.timestamp;
889
- var _a = e.touches[_this._tid], x = _a.x, y = _a.y;
890
- _this.horizontal ? _this._x.capture(x) : _this._y.capture(y);
891
- _this.emit('start');
892
- }
893
- };
894
- this.touchMove = function (e) {
895
- if (_this._tid && e.touches[_this._tid] && _this._check(e)) {
896
- var _a = e.touches[_this._tid], x = _a.x, y = _a.y;
897
- var duration = e.timestamp - _this._timestamp;
898
- _this._timestamp = e.timestamp;
899
- _this.horizontal ? _this._x.onMove(x, duration) : _this._y.onMove(y, duration);
900
- _this.emit('scroll');
901
- _this._sign(e);
902
- }
903
- };
904
- this.touchEnd = function () {
905
- if (_this._tid) {
906
- _this._tid = '';
907
- _this._timestamp = Date.now();
908
- _this._x.onEnd();
909
- _this._y.onEnd();
910
- _this._timer = requestAnimationFrame(_this.afterEnd);
911
- }
912
- };
913
- this.afterEnd = function () {
914
- var timestamp = Date.now();
915
- var duration = timestamp - _this._timestamp;
916
- _this._timestamp = timestamp;
917
- if (_this.horizontal ? _this._x.afterEnd(duration) : _this._y.afterEnd(duration)) {
918
- _this.emit('scroll');
919
- _this._timer = requestAnimationFrame(_this.afterEnd);
920
- }
921
- else {
922
- _this.emit('end');
923
- }
924
- };
925
- }
926
- Object.defineProperty(Scroller.prototype, "maxX", {
927
- get: function () {
928
- return this._x.max;
929
- },
930
- set: function (value) {
931
- this._x.max = value;
932
- },
933
- enumerable: false,
934
- configurable: true
935
- });
936
- Object.defineProperty(Scroller.prototype, "maxY", {
937
- get: function () {
938
- return this._y.max;
939
- },
940
- set: function (value) {
941
- this._y.max = value;
942
- },
943
- enumerable: false,
944
- configurable: true
945
- });
946
- Object.defineProperty(Scroller.prototype, "pagingX", {
947
- set: function (value) {
948
- this._x.paging = value;
949
- },
950
- enumerable: false,
951
- configurable: true
952
- });
953
- Object.defineProperty(Scroller.prototype, "pagingY", {
954
- set: function (value) {
955
- this._y.paging = value;
956
- },
957
- enumerable: false,
958
- configurable: true
959
- });
960
- Scroller.prototype._sign = function (e) {
961
- var _this = this;
962
- e.scroll = tslib.__assign(tslib.__assign({}, e.scroll), { x: true, y: true });
963
- var stopPropagation = e.scroll.stopPropagation || noop;
964
- if (this.horizontal) {
965
- if (this._x.velocity > 0) {
966
- e.scroll.y = false;
967
- stopPropagation();
968
- }
969
- if (this._x.offset > 0 && this._x.offset < this._x.max) {
970
- e.scroll.x = false;
971
- }
972
- }
973
- else {
974
- if (this._y.velocity > 0) {
975
- e.scroll.x = false;
976
- stopPropagation();
977
- }
978
- if (this._y.offset > 0 && this._y.offset < this._y.max) {
979
- e.scroll.y = false;
980
- }
981
- }
982
- e.stopPropagation = function () {
983
- _this.touchEnd();
984
- stopPropagation();
985
- };
986
- };
987
- Scroller.prototype._check = function (e) {
988
- if (this.horizontal && e.scroll && e.scroll.x === false) {
989
- return this.touchEnd();
990
- }
991
- if (!this.horizontal && e.scroll && e.scroll.y === false) {
992
- return this.touchEnd();
993
- }
994
- return true;
995
- };
996
- Scroller.prototype.emit = function (type) {
997
- this.listener({
998
- type: type,
999
- x: this._x.offset,
1000
- vx: this._x.velocity,
1001
- y: this._y.offset,
1002
- vy: this._y.velocity,
1003
- timestamp: this._timestamp,
1004
- tid: this._tid,
1005
- });
1006
- };
1007
- Scroller.prototype.cancel = function () {
1008
- cancelAnimationFrame(this._timer);
1009
- this._tid = '';
1010
- this._timestamp = Date.now();
1011
- this._x.onEnd();
1012
- this._y.onEnd();
1013
- };
1014
- return Scroller;
1015
- }());
1016
- function friction(v, duration, factor) {
1017
- return v - Math.min(duration * factor, 1) * v;
1018
- }
1019
-
1020
- var ScrollView = /** @class */ (function (_super) {
1021
- tslib.__extends(ScrollView, _super);
1022
- function ScrollView() {
1023
- var _this = _super !== null && _super.apply(this, arguments) || this;
1024
- _this._height = -1;
1025
- _this._contentHeight = -1;
1026
- _this._width = -1;
1027
- _this._contentWidth = -1;
1028
- _this._innerStyle = {
1029
- translateX: new AnimatedValue(0),
1030
- translateY: new AnimatedValue(0),
1031
- position: 'absolute',
1032
- animated: true,
1033
- };
1034
- _this._offset = { x: 0, y: 0 };
1035
- _this._scroller = new Scroller(function (e) {
1036
- var _a = _this._offset, _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c;
1037
- _this.props.horizontal ?
1038
- _this._innerStyle.translateX.setValue(x - e.x) :
1039
- _this._innerStyle.translateY.setValue(y - e.y);
1040
- switch (e.type) {
1041
- case 'scroll':
1042
- return _this.props.onScroll && _this.props.onScroll(e);
1043
- case 'start':
1044
- return _this.props.onScrollStart && _this.props.onScrollStart(e);
1045
- case 'end':
1046
- return _this.props.onScrollEnd && _this.props.onScrollEnd(e);
1047
- }
1048
- });
1049
- _this._onLayout = function (frame) {
1050
- if (_this._width !== frame.width || _this._height !== frame.height) {
1051
- _this._height = frame.height;
1052
- _this._width = frame.width;
1053
- _this._checkLayout();
1054
- if (_this.props.paging) {
1055
- if (_this.props.horizontal) {
1056
- _this._scroller.pagingX = _this.props.paging === true ? frame.width : _this.props.paging;
1057
- }
1058
- else {
1059
- _this._scroller.pagingY = _this.props.paging === true ? frame.height : _this.props.paging;
1060
- }
1061
- }
1062
- }
1063
- _this.props.onLayout && _this.props.onLayout(frame);
1064
- };
1065
- _this._onContentLayout = function (frame) {
1066
- var _a = _this._offset, _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c;
1067
- var width = frame.width + x;
1068
- var height = frame.height + y;
1069
- if (_this._contentWidth !== width || _this._contentHeight !== height) {
1070
- _this._contentHeight = height;
1071
- _this._contentWidth = width;
1072
- _this._checkLayout();
1073
- }
1074
- };
1075
- _this._checkLayout = function () {
1076
- var maxX = _this._contentWidth - _this._width;
1077
- var maxY = _this._contentHeight - _this._height;
1078
- if ((maxX > 0 && maxX !== _this._scroller.maxX) || (maxY > 0 && maxY !== _this._scroller.maxY)) {
1079
- _this._scroller.maxX = maxX;
1080
- _this._scroller.maxY = maxY;
1081
- _this._scroller.emit('none');
1082
- }
1083
- };
1084
- return _this;
1085
- }
1086
- ScrollView.prototype.componentWillUnmount = function () {
1087
- this._scroller.cancel();
1088
- };
1089
- ScrollView.prototype.render = function () {
1090
- var _a;
1091
- var _b = this.props, children = _b.children, horizontal = _b.horizontal, offset = _b.offset, others = tslib.__rest(_b, ["children", "horizontal", "offset"]);
1092
- this._scroller.horizontal = horizontal;
1093
- if (offset) {
1094
- this._offset = offset;
1095
- this._scroller.emit('none');
1096
- }
1097
- return React.createElement('Scrollable', tslib.__assign(tslib.__assign({}, others), { onLayout: this._onLayout }), React.createElement('ScrollContent', {
1098
- onTouchStart: this._scroller.touchStart,
1099
- onTouchMove: this._scroller.touchMove,
1100
- onTouchEnd: this._scroller.touchEnd,
1101
- onLayout: this._onContentLayout,
1102
- style: [
1103
- this._innerStyle,
1104
- (_a = {
1105
- flexDirection: horizontal ? 'row' : 'column'
1106
- },
1107
- _a[horizontal ? 'height' : 'width'] = '100%',
1108
- _a),
1109
- ],
1110
- children: children,
1111
- }));
1112
- };
1113
- return ScrollView;
1114
- }(React.Component));
1115
-
1116
- var ListView = /** @class */ (function (_super) {
1117
- tslib.__extends(ListView, _super);
1118
- function ListView() {
1119
- var _this = _super !== null && _super.apply(this, arguments) || this;
1120
- _this.state = {
1121
- start: 0,
1122
- end: 1,
1123
- };
1124
- _this._height = 0;
1125
- _this.checkVisible = function (y) {
1126
- if (_this._height > 0) {
1127
- var itemHeight = _this.props.itemHeight;
1128
- var _a = _this.state, _start = _a.start, _end = _a.end;
1129
- var start = Math.max(0, Math.floor((y - 10) / itemHeight));
1130
- var end = Math.floor((y + _this._height + 10) / itemHeight);
1131
- if (start !== _start || end !== _end) {
1132
- _this.setState({ start: start, end: end });
1133
- }
1134
- }
1135
- };
1136
- _this._onScroll = function (e) {
1137
- _this.checkVisible(e.y);
1138
- _this.props.onScroll && _this.props.onScroll(e);
1139
- };
1140
- _this._onLayout = function (frame) {
1141
- if (_this._height !== frame.height) {
1142
- _this._height = frame.height;
1143
- }
1144
- // this._width = frame.width
1145
- };
1146
- _this.renderItem = function (item, i) {
1147
- var _a = _this.props, data = _a.data, renderItem = _a.renderItem;
1148
- var index = i + _this.state.start;
1149
- return React.createElement(React.Fragment, { key: index }, renderItem(item, index, data));
1150
- };
1151
- return _this;
1152
- }
1153
- ListView.prototype.componentDidMount = function () {
1154
- this.checkVisible(0);
1155
- };
1156
- ListView.prototype.render = function () {
1157
- var _a = this.props, data = _a.data, itemHeight = _a.itemHeight;
1158
- var _b = this.state, start = _b.start, end = _b.end;
1159
- // console.log(start, end, this._height);
1160
- return React.createElement(ScrollView, tslib.__assign(tslib.__assign({}, this.props), { onScroll: this._onScroll, onLayout: this._onLayout, offset: { y: start * itemHeight } }), data.slice(start, end + 1).map(this.renderItem));
1161
- };
1162
- return ListView;
1163
- }(React.Component));
1164
-
1165
- var DEFAULT_STYLE$1 = { path: true };
1166
- function LinearGradient(props) {
1167
- return React.createElement('LinearGradient', tslib.__assign(tslib.__assign({}, props), { style: [DEFAULT_STYLE$1, props.style], customDrawer: drawGradient }));
1168
- }
1169
- function drawGradient(canvas, node) {
1170
- var colors = node.props.colors;
1171
- if (colors && colors.length > 0) {
1172
- var _a = node.props, _b = _a.start, start = _b === void 0 ? { x: 0, y: 0 } : _b, _c = _a.end, end = _c === void 0 ? { x: 1, y: 0 } : _c;
1173
- var frame = getFrameFromNode(node);
1174
- var grad = canvas.context.createLinearGradient(start.x * frame.width + frame.x, start.y * frame.height + frame.y, end.x * frame.width + frame.x, end.y * frame.height + frame.y);
1175
- for (var i = 0; i < colors.length; i++) {
1176
- grad.addColorStop(i / (colors.length - 1), colors[i]);
1177
- }
1178
- canvas.context.fillStyle = grad;
1179
- canvas.context.fill();
1180
- }
1181
- }
1182
-
1183
- var AppContext = React.createContext({
1184
- clientWidth: 0,
1185
- clientHeight: 0,
1186
- deviceRatio: 1,
1187
- });
1188
- function withContext(comp) {
1189
- comp.contextType = AppContext;
1190
- return comp;
1191
- }
1192
- function Root(props) {
1193
- return React.createElement(AppContext.Provider, { value: props }, React.createElement('Root', props));
1194
- }
1195
-
1196
- var yoga = {};
1197
- var promise = Yoga.init().then(function (y) {
1198
- Object.assign(yoga, y);
1199
- });
1200
-
1201
- function funcName(key) {
1202
- return "set" + key[0].toUpperCase() + key.substr(1);
1203
- }
1204
- function checkAndRun(yoga, key) {
1205
- var values = [];
1206
- for (var _i = 2; _i < arguments.length; _i++) {
1207
- values[_i - 2] = arguments[_i];
1208
- }
1209
- if (yoga[key]) {
1210
- yoga[key].apply(yoga, values);
1211
- }
1212
- else {
1213
- throw new Error("ReCanvas: No Such Style Func - " + key);
1214
- }
1215
- }
1216
- function parseValue(func, value) {
1217
- if (typeof value === 'number') {
1218
- return [func, value];
1219
- }
1220
- else if (value === 'auto') {
1221
- return [func + "Auto"];
1222
- }
1223
- else if (value.endsWith('%')) {
1224
- return [func + "Percent", Number(value.slice(0, -1))];
1225
- }
1226
- else {
1227
- throw new Error("ReCanvas: No Such Style Value - " + value);
1228
- }
1229
- }
1230
- function parseEnum(func, enums, value) {
1231
- if (enums[value] !== undefined) {
1232
- return [func, enums[value]];
1233
- }
1234
- else {
1235
- throw new Error("ReCanvas: No Such Style Value - " + value);
1236
- }
1237
- }
1238
- function parseEdge(func, edge, value) {
1239
- if (typeof value === 'number') {
1240
- return [func, edge, value];
1241
- }
1242
- else if (value === 'auto') {
1243
- return [func + "Auto", edge];
1244
- }
1245
- else if (value.endsWith('%')) {
1246
- return [func + "Percent", edge, Number(value.slice(0, -1))];
1247
- }
1248
- else {
1249
- throw new Error("ReCanvas: No Such Style Value - " + value);
1250
- }
1251
- }
1252
- var STYLE_MAP = {};
1253
- function init() {
1254
- var ALIGN_ENUM = {
1255
- auto: yoga.ALIGN_AUTO,
1256
- baseline: yoga.ALIGN_BASELINE,
1257
- center: yoga.ALIGN_CENTER,
1258
- 'flex-end': yoga.ALIGN_FLEX_END,
1259
- 'flex-start': yoga.ALIGN_FLEX_START,
1260
- 'space-around': yoga.ALIGN_SPACE_AROUND,
1261
- 'space-between': yoga.ALIGN_SPACE_BETWEEN,
1262
- stretch: yoga.ALIGN_STRETCH,
1263
- };
1264
- var AVAILABLE = {
1265
- VALUE: [
1266
- 'flex',
1267
- 'width',
1268
- 'height',
1269
- 'minWidth',
1270
- 'maxWidth',
1271
- 'minHeight',
1272
- 'maxHeight',
1273
- 'flexGrow',
1274
- 'flexShrink',
1275
- 'aspectRatio',
1276
- ],
1277
- ENUM: [
1278
- {
1279
- key: 'justifyContent',
1280
- enum: {
1281
- center: yoga.JUSTIFY_CENTER,
1282
- 'flex-end': yoga.JUSTIFY_FLEX_END,
1283
- 'flex-start': yoga.JUSTIFY_FLEX_START,
1284
- 'space-around': yoga.JUSTIFY_SPACE_AROUND,
1285
- 'space-between': yoga.JUSTIFY_SPACE_BETWEEN,
1286
- 'space-evenly': yoga.JUSTIFY_SPACE_EVENLY,
1287
- },
1288
- },
1289
- { key: 'alignItems', enum: ALIGN_ENUM },
1290
- { key: 'alignSelf', enum: ALIGN_ENUM },
1291
- { key: 'alignContent', enum: ALIGN_ENUM },
1292
- {
1293
- key: 'flexWrap',
1294
- enum: {
1295
- 'no-wrap': yoga.WRAP_NO_WRAP,
1296
- wrap: yoga.WRAP_WRAP,
1297
- 'wrap-reverse': yoga.WRAP_WRAP_REVERSE,
1298
- },
1299
- },
1300
- {
1301
- key: 'flexDirection',
1302
- enum: {
1303
- column: yoga.FLEX_DIRECTION_COLUMN,
1304
- 'column-reverse': yoga.FLEX_DIRECTION_COLUMN_REVERSE,
1305
- count: yoga.FLEX_DIRECTION_COUNT,
1306
- row: yoga.FLEX_DIRECTION_ROW,
1307
- 'row-reverse': yoga.FLEX_DIRECTION_ROW_REVERSE,
1308
- },
1309
- },
1310
- {
1311
- key: 'position',
1312
- remap: 'positionType',
1313
- enum: {
1314
- relative: yoga.POSITION_TYPE_RELATIVE,
1315
- absolute: yoga.POSITION_TYPE_ABSOLUTE,
1316
- count: yoga.POSITION_TYPE_COUNT,
1317
- },
1318
- },
1319
- ],
1320
- EDGE: [
1321
- { key: 'padding', remap: 'padding', edge: yoga.EDGE_ALL },
1322
- { key: 'paddingLeft', remap: 'padding', edge: yoga.EDGE_LEFT },
1323
- { key: 'paddingRight', remap: 'padding', edge: yoga.EDGE_RIGHT },
1324
- { key: 'paddingTop', remap: 'padding', edge: yoga.EDGE_TOP },
1325
- { key: 'paddingBottom', remap: 'padding', edge: yoga.EDGE_BOTTOM },
1326
- { key: 'left', remap: 'position', edge: yoga.EDGE_LEFT },
1327
- { key: 'right', remap: 'position', edge: yoga.EDGE_RIGHT },
1328
- { key: 'top', remap: 'position', edge: yoga.EDGE_TOP },
1329
- { key: 'bottom', remap: 'position', edge: yoga.EDGE_BOTTOM },
1330
- { key: 'margin', remap: 'margin', edge: yoga.EDGE_ALL },
1331
- { key: 'marginLeft', remap: 'margin', edge: yoga.EDGE_LEFT },
1332
- { key: 'marginRight', remap: 'margin', edge: yoga.EDGE_RIGHT },
1333
- { key: 'marginTop', remap: 'margin', edge: yoga.EDGE_TOP },
1334
- { key: 'marginBottom', remap: 'margin', edge: yoga.EDGE_BOTTOM },
1335
- { key: 'borderWidth', remap: 'border', edge: yoga.EDGE_ALL },
1336
- { key: 'borderLeftWidth', remap: 'border', edge: yoga.EDGE_LEFT },
1337
- { key: 'borderRightWidth', remap: 'border', edge: yoga.EDGE_RIGHT },
1338
- { key: 'borderTopWidth', remap: 'border', edge: yoga.EDGE_TOP },
1339
- { key: 'borderBottomWidth', remap: 'border', edge: yoga.EDGE_BOTTOM },
1340
- ],
1341
- };
1342
- AVAILABLE.VALUE.forEach(function (key) {
1343
- var func = funcName(key);
1344
- STYLE_MAP[key] = function (value) { return parseValue(func, value); };
1345
- });
1346
- AVAILABLE.ENUM.forEach(function (item) {
1347
- var func = funcName(item.remap || item.key);
1348
- var enums = item.enum;
1349
- STYLE_MAP[item.key] = function (value) { return parseEnum(func, enums, value); };
1350
- });
1351
- AVAILABLE.EDGE.forEach(function (item) {
1352
- var func = funcName(item.remap);
1353
- var edge = item.edge;
1354
- STYLE_MAP[item.key] = function (value) { return parseEdge(func, edge, value); };
1355
- });
1356
- }
1357
- promise.then(init);
1358
- // function _apply(yoga: Yoga.YogaNode, style: any) {
1359
- // for (const key in style) {
1360
- // const func = STYLE_MAP[key]
1361
- // func && checkAndRun(yoga, ...func(style[key]))
1362
- // }
1363
- // }
1364
- var cache$1 = new WeakMap();
1365
- function _apply(yoga, style) {
1366
- if (style) {
1367
- if (!cache$1.has(style)) {
1368
- var _styles = [];
1369
- for (var key in style) {
1370
- var func = STYLE_MAP[key];
1371
- func && _styles.push(func(style[key]));
1372
- }
1373
- cache$1.set(style, _styles);
1374
- }
1375
- var styles = cache$1.get(style);
1376
- for (var i = 0; i < styles.length; i++) {
1377
- checkAndRun.apply(void 0, tslib.__spreadArrays([yoga], styles[i]));
1378
- }
1379
- }
1380
- }
1381
- function apply(yoga, style) {
1382
- if (style) {
1383
- flatten([style]).forEach(function (s) { return _apply(yoga, s); });
1384
- }
1385
- }
1386
-
1387
- function _updateLayout(node) {
1388
- var yoga$1 = yoga.Node.create();
1389
- var children = [];
1390
- apply(yoga$1, node.props.style);
1391
- for (var i = 0; i < node.children.length; i++) {
1392
- var child = node.children[i];
1393
- var _a = _updateLayout(child), f = _a[0], y = _a[1];
1394
- var index = children.push(f);
1395
- yoga$1.insertChild(y, index - 1);
1396
- }
1397
- function process(x, y) {
1398
- if (x === void 0) { x = 0; }
1399
- if (y === void 0) { y = 0; }
1400
- var _a = yoga$1.getComputedLayout(), left = _a.left, top = _a.top, width = _a.width, height = _a.height;
1401
- node.frame = new Frame(x + left, y + top, width, height);
1402
- node.props.onLayout && node.props.onLayout(node.frame);
1403
- for (var i = 0; i < children.length; i++) {
1404
- children[i](node.frame.x, node.frame.y);
1405
- }
1406
- yoga$1.free();
1407
- }
1408
- return [process, yoga$1];
1409
- }
1410
- function updateLayout(root) {
1411
- var _a = _updateLayout(root), process = _a[0], yoga$1 = _a[1];
1412
- var _b = root.props, clientWidth = _b.clientWidth, clientHeight = _b.clientHeight, RTL = _b.RTL;
1413
- yoga$1.calculateLayout(clientWidth, clientHeight, RTL ? yoga.DIRECTION_RTL : yoga.DIRECTION_LTR);
1414
- return process;
1415
- }
1416
-
1417
- var MAX_SIZE = 30;
1418
- var cache$2 = new Map();
1419
- var ids = [];
1420
- function getCache(id) {
1421
- return cache$2.get(id);
1422
- }
1423
- function createCache(style, w, h, id) {
1424
- if (ids.length >= MAX_SIZE) {
1425
- var expiredId = ids.shift();
1426
- var canvas = cache$2.get(expiredId).canvas;
1427
- var cached = {
1428
- canvas: adapter.resetOffscreenCanvas(canvas, w, h),
1429
- id: id,
1430
- style: style,
1431
- };
1432
- cache$2.delete(expiredId);
1433
- cache$2.set(cached.id, cached);
1434
- ids.push(cached.id);
1435
- return cached;
1436
- }
1437
- else {
1438
- var cached = {
1439
- canvas: adapter.createOffscreenCanvas(w, h),
1440
- id: id,
1441
- style: style,
1442
- };
1443
- cache$2.set(cached.id, cached);
1444
- ids.push(cached.id);
1445
- return cached;
1446
- }
1447
- }
1448
- var idCache = new WeakMap();
1449
- var __ID = 0;
1450
- function autoCacheId(node) {
1451
- if (idCache.has(node)) {
1452
- return idCache.get(node);
1453
- }
1454
- else {
1455
- var id = "$$auto_id-" + __ID++;
1456
- idCache.set(node, id);
1457
- return id;
1458
- }
1459
- }
1460
-
1461
- function getRadius(style) {
1462
- return {
1463
- tl: style.borderTopLeftRadius || style.borderRadius || 0,
1464
- tr: style.borderTopRightRadius || style.borderRadius || 0,
1465
- bl: style.borderBottomLeftRadius || style.borderRadius || 0,
1466
- br: style.borderBottomRightRadius || style.borderRadius || 0,
1467
- };
1468
- }
1469
- function drawNode(canvas, node, container) {
1470
- var style = getMergedStyleFromNode(node, container.draw);
1471
- var frame = getFrameFromNode(node);
1472
- if (style.opacity <= 0) {
1473
- return;
1474
- }
1475
- // flags
1476
- var hasTransform = style.translateX || style.translateY || style.rotate || style.scaleX || style.scaleY || style.scale;
1477
- var hasClip = style.overflow === 'hidden';
1478
- if (hasClip) {
1479
- canvas.context.save();
1480
- }
1481
- else if (hasTransform) {
1482
- canvas.transform.save();
1483
- }
1484
- // Area Range
1485
- // Opacity:
1486
- var popOpacity = pushOpacity(canvas, style.opacity);
1487
- // Translation:
1488
- if (style.translateX || style.translateY) {
1489
- canvas.transform.translate(style.translateX || 0, style.translateY || 0);
1490
- }
1491
- // Rotate && Scale
1492
- if (style.rotate || style.scaleX || style.scaleY || style.scale) {
1493
- // Origin Center
1494
- var originX = frame.x + frame.width / 2;
1495
- var originY = frame.y + frame.height / 2;
1496
- canvas.transform.translate(originX, originY);
1497
- if (style.rotate) {
1498
- canvas.transform.rotate(style.rotate);
1499
- }
1500
- if (style.scaleX || style.scaleY || style.scale) {
1501
- canvas.transform.scale(style.scaleX || style.scale, style.scaleY || style.scale);
1502
- }
1503
- canvas.transform.translate(-originX, -originY);
1504
- }
1505
- if (node.props.cache && adapter.createOffscreenCanvas && frame.height > 0 && frame.width > 0) {
1506
- drawCache(canvas, node, container, style, frame, hasClip);
1507
- }
1508
- else {
1509
- drawContent(canvas, node, container, style, frame, hasClip);
1510
- }
1511
- popOpacity();
1512
- if (hasClip) {
1513
- canvas.context.restore();
1514
- }
1515
- else if (hasTransform) {
1516
- canvas.transform.restore();
1517
- }
1518
- }
1519
- function drawCache(canvas, node, container, style, frame, hasClip) {
1520
- var cachedId = node.props.cache === true ? autoCacheId(node) : node.props.cache;
1521
- var cached = getCache(cachedId);
1522
- var _a = cached ? cached.style : style, _b = _a.shadowBlur, shadowBlur = _b === void 0 ? 0 : _b, _c = _a.shadowOffsetX, shadowOffsetX = _c === void 0 ? 0 : _c, _d = _a.shadowOffsetY, shadowOffsetY = _d === void 0 ? 0 : _d;
1523
- var spread = shadowBlur * 2;
1524
- var x = frame.x + shadowOffsetX - shadowBlur;
1525
- var y = frame.y + shadowOffsetY - shadowBlur;
1526
- var w = frame.width + spread;
1527
- var h = frame.height + spread;
1528
- if (!cached) {
1529
- if (!node.$ready && !node.props.forceCache) {
1530
- return drawContent(canvas, node, container, style, frame, hasClip);
1531
- }
1532
- cached = createCache(style, w, h, cachedId);
1533
- cached.canvas.transform.translate(-x, -y);
1534
- drawContent(cached.canvas, node, container, style, frame, hasClip);
1535
- cached.canvas.transform.translate(x, y);
1536
- }
1537
- canvas.context.drawImage(cached.canvas.element, x, y, w, h);
1538
- }
1539
- function drawContent(canvas, node, container, style, frame, hasClip) {
1540
- var hasBG = style.backgroundColor && style.backgroundColor !== 'transparent';
1541
- var hasBorder = style.borderColor && style.borderWidth > 0;
1542
- var hasRadius = style.borderRadius ||
1543
- style.borderTopLeftRadius ||
1544
- style.borderTopRightRadius ||
1545
- style.borderBottomLeftRadius ||
1546
- style.borderBottomRightRadius;
1547
- // consts
1548
- var useFrame = hasBG || hasBorder || hasClip || style.path;
1549
- var usePath = hasRadius || hasClip || style.path;
1550
- if (useFrame) {
1551
- var ctx = canvas.context;
1552
- if (usePath) {
1553
- // Draw Path
1554
- ctx.beginPath();
1555
- if (hasRadius) {
1556
- var radius = getRadius(style);
1557
- ctx.moveTo(frame.x + radius.tl, frame.y);
1558
- ctx.arcTo(frame.x + frame.width, frame.y, frame.x + frame.width, frame.y + frame.height, radius.tr);
1559
- ctx.arcTo(frame.x + frame.width, frame.y + frame.height, frame.x, frame.y + frame.height, radius.br);
1560
- ctx.arcTo(frame.x, frame.y + frame.height, frame.x, frame.y, radius.bl);
1561
- ctx.arcTo(frame.x, frame.y, frame.x + frame.width, frame.y, radius.tl);
1562
- }
1563
- else {
1564
- ctx.rect(frame.x, frame.y, frame.width, frame.height);
1565
- }
1566
- ctx.closePath();
1567
- if (hasClip) {
1568
- ctx.clip();
1569
- }
1570
- }
1571
- if (hasBG || hasBorder) {
1572
- // Shadow:
1573
- var resetShadow = setShadow(canvas, style.shadowColor, style.shadowOffsetX, style.shadowOffsetY, style.shadowBlur);
1574
- // Background color & Shadow
1575
- if (hasBG) {
1576
- ctx.fillStyle = style.backgroundColor;
1577
- if (usePath) {
1578
- ctx.fill();
1579
- }
1580
- else {
1581
- ctx.fillRect(frame.x, frame.y, frame.width, frame.height);
1582
- }
1583
- }
1584
- // Border with border radius:
1585
- if (hasBorder) {
1586
- ctx.lineWidth = style.borderWidth;
1587
- ctx.strokeStyle = style.borderColor;
1588
- if (usePath) {
1589
- ctx.stroke();
1590
- }
1591
- else {
1592
- ctx.strokeRect(frame.x, frame.y, frame.width, frame.height);
1593
- }
1594
- }
1595
- resetShadow();
1596
- }
1597
- }
1598
- if (node.props.customDrawer) {
1599
- node.props.customDrawer(canvas, node, { hasRadius: hasRadius, hasClip: hasClip });
1600
- }
1601
- // Draw child layers, sorted by their z-index.
1602
- node.children
1603
- .slice()
1604
- .sort(sortByZIndexAscending)
1605
- .forEach(function drawChild(child) {
1606
- drawNode(canvas, child, container);
1607
- });
1608
- }
1609
-
1610
- function scaled(x, c, s) {
1611
- if (s === void 0) { s = 1; }
1612
- if (!s && s === 1)
1613
- return x;
1614
- return ((s - 1) * c + x) / s;
1615
- }
1616
- function findNodeByPoint(node, x, y) {
1617
- if (node.props.pointerEvents === 'none')
1618
- return;
1619
- var children = node.children.slice().sort(sortByZIndexAscending).reverse();
1620
- var style = getMergedStyleFromNode(node);
1621
- var frame = getFrameFromNode(node);
1622
- // tranlate
1623
- var scaleX = style.scaleX || style.scale;
1624
- var scaleY = style.scaleY || style.scale;
1625
- var originX = frame.width / 2 + frame.x;
1626
- var originY = frame.height / 2 + frame.y;
1627
- x -= style.translateX || 0;
1628
- y -= style.translateY || 0;
1629
- x = scaled(x, originX, scaleX);
1630
- y = scaled(y, originY, scaleY);
1631
- if (frame.x < x && frame.y < y
1632
- && x <= frame.x + frame.width
1633
- && y <= frame.y + frame.height) {
1634
- for (var i = 0; i < children.length; i++) {
1635
- var target = findNodeByPoint(children[i], x, y);
1636
- if (target)
1637
- return target;
1638
- }
1639
- if (node.props.pointerEvents === 'box-none')
1640
- return;
1641
- return node;
1642
- }
1643
- }
1644
- var eventNodeHolder = {};
1645
- function getNodeByTouch(root, type, touch) {
1646
- if (type === 'touchstart') {
1647
- var target = findNodeByPoint(root, touch.x, touch.y);
1648
- eventNodeHolder[touch.identifier] = target || root;
1649
- return eventNodeHolder[touch.identifier];
1650
- }
1651
- else if (type === 'touchmove') {
1652
- return eventNodeHolder[touch.identifier] || root;
1653
- }
1654
- else if (type === 'touchend') {
1655
- var target = eventNodeHolder[touch.identifier];
1656
- delete eventNodeHolder[touch.identifier];
1657
- return target || root;
1658
- }
1659
- return root;
1660
- }
1661
- var LISTENER_MAP = {
1662
- touchstart: 'onTouchStart',
1663
- touchmove: 'onTouchMove',
1664
- touchend: 'onTouchEnd'
1665
- };
1666
- function emitTouch(node, e) {
1667
- var funcName = LISTENER_MAP[e.type];
1668
- if (funcName) {
1669
- while (node) {
1670
- if (node.props[funcName]
1671
- && node.props.pointerEvents !== 'box-none'
1672
- && node.props[funcName](e) === false)
1673
- return;
1674
- node = node.parent;
1675
- }
1676
- }
1677
- }
1678
-
1679
- // import { updateLayout } from './css-layout'
1680
- var Container = /** @class */ (function () {
1681
- function Container() {
1682
- var _this = this;
1683
- this._ready = false;
1684
- this._next = false;
1685
- this._reflow = false;
1686
- this.handleTouch = function (evt) {
1687
- var _root = _this._root;
1688
- if (_root) {
1689
- var emitted_1 = new WeakSet();
1690
- Object.values(evt.touches).forEach(function (touch) {
1691
- var node = getNodeByTouch(_root, evt.type, touch);
1692
- // check if node is unmounted
1693
- if (node.parent && !emitted_1.has(node)) {
1694
- emitted_1.add(node);
1695
- emitTouch(node, evt);
1696
- }
1697
- });
1698
- }
1699
- };
1700
- this.draw = function (reflow) {
1701
- if (reflow === void 0) { reflow = false; }
1702
- _this._reflow = _this._reflow || reflow;
1703
- if (!_this._ready) {
1704
- _this._next = true;
1705
- return;
1706
- }
1707
- _this._ready = false;
1708
- var _a = _this, _root = _a._root, canvas = _a.canvas;
1709
- if (canvas) {
1710
- // if not unmounted
1711
- if (_this._reflow) {
1712
- updateLayout(_root)();
1713
- _this._reflow = false;
1714
- }
1715
- canvas.context.clearRect(0, 0, _this.width, _this.height);
1716
- drawNode(canvas, _root, _this);
1717
- requestAnimationFrame(_this.ready);
1718
- }
1719
- };
1720
- this.ready = function () {
1721
- _this._ready = true;
1722
- if (_this._next) {
1723
- _this._next = false;
1724
- _this.draw();
1725
- }
1726
- };
1727
- promise.then(this.ready);
1728
- }
1729
- Object.defineProperty(Container.prototype, "canvas", {
1730
- get: function () {
1731
- var _a;
1732
- return (_a = this._root) === null || _a === void 0 ? void 0 : _a.props.canvas;
1733
- },
1734
- enumerable: false,
1735
- configurable: true
1736
- });
1737
- Object.defineProperty(Container.prototype, "width", {
1738
- get: function () {
1739
- var _a;
1740
- return ((_a = this._root) === null || _a === void 0 ? void 0 : _a.props.clientWidth) || 0;
1741
- },
1742
- enumerable: false,
1743
- configurable: true
1744
- });
1745
- Object.defineProperty(Container.prototype, "height", {
1746
- get: function () {
1747
- var _a;
1748
- return ((_a = this._root) === null || _a === void 0 ? void 0 : _a.props.clientHeight) || 0;
1749
- },
1750
- enumerable: false,
1751
- configurable: true
1752
- });
1753
- Object.defineProperty(Container.prototype, "scale", {
1754
- get: function () {
1755
- var _a;
1756
- return ((_a = this._root) === null || _a === void 0 ? void 0 : _a.props.deviceRatio) || 1;
1757
- },
1758
- enumerable: false,
1759
- configurable: true
1760
- });
1761
- Container.prototype.setRoot = function (root) {
1762
- this._root = root;
1763
- };
1764
- return Container;
1765
- }());
1766
-
1767
- var RevasCanvas = /** @class */ (function () {
1768
- function RevasCanvas(context) {
1769
- this.transform = new Transform(context);
1770
- }
1771
- Object.defineProperty(RevasCanvas.prototype, "context", {
1772
- get: function () {
1773
- return this.transform.context;
1774
- },
1775
- enumerable: false,
1776
- configurable: true
1777
- });
1778
- Object.defineProperty(RevasCanvas.prototype, "element", {
1779
- get: function () {
1780
- return this.context.canvas;
1781
- },
1782
- enumerable: false,
1783
- configurable: true
1784
- });
1785
- return RevasCanvas;
1786
- }());
1787
- var Transform = /** @class */ (function () {
1788
- function Transform(context) {
1789
- this.context = context;
1790
- this._stack = [];
1791
- this._canGetTransform = false;
1792
- this._canGetTransform = Boolean(context.getTransform);
1793
- }
1794
- Transform.prototype.save = function () {
1795
- if (this._canGetTransform) {
1796
- this._stack.push(this.context.getTransform());
1797
- }
1798
- else {
1799
- this.context.save();
1800
- }
1801
- };
1802
- Transform.prototype.restore = function () {
1803
- if (this._canGetTransform) {
1804
- if (this._stack.length > 0) {
1805
- this.context.setTransform(this._stack.pop());
1806
- }
1807
- }
1808
- else {
1809
- this.context.restore();
1810
- }
1811
- };
1812
- Transform.prototype.translate = function (x, y) {
1813
- this.context.translate(x, y);
1814
- };
1815
- Transform.prototype.rotate = function (rad) {
1816
- this.context.rotate(rad);
1817
- };
1818
- Transform.prototype.scale = function (sx, sy) {
1819
- this.context.scale(sx, sy);
1820
- };
1821
- return Transform;
1822
- }());
1823
-
1824
- exports.AnimatedInterpolate = AnimatedInterpolate;
1825
- exports.AnimatedNode = AnimatedNode;
1826
- exports.AnimatedTiming = AnimatedTiming;
1827
- exports.AnimatedValue = AnimatedValue;
1828
- exports.AppContext = AppContext;
1829
- exports.Container = Container;
1830
- exports.EMPTY_ARRAY = EMPTY_ARRAY;
1831
- exports.EMPTY_OBJECT = EMPTY_OBJECT;
1832
- exports.Easing = Easing;
1833
- exports.Frame = Frame;
1834
- exports.Image = ImageView;
1835
- exports.LinearGradient = LinearGradient;
1836
- exports.ListView = ListView;
1837
- exports.Node = Node;
1838
- exports.RevasCanvas = RevasCanvas;
1839
- exports.Root = Root;
1840
- exports.ScrollView = ScrollView;
1841
- exports.Text = Text;
1842
- exports.Touchable = Touchable;
1843
- exports.Transform = Transform;
1844
- exports.View = View;
1845
- exports.adapter = adapter;
1846
- exports.applyAnimated = applyAnimated;
1847
- exports.clamp = clamp;
1848
- exports.flatten = flatten;
1849
- exports.getChars = getChars;
1850
- exports.getFrameFromNode = getFrameFromNode;
1851
- exports.getMergedStyleFromNode = getMergedStyleFromNode;
1852
- exports.getWords = getWords;
1853
- exports.noop = noop;
1854
- exports.now = now;
1855
- exports.pushOpacity = pushOpacity;
1856
- exports.renderer = renderer;
1857
- exports.setShadow = setShadow;
1858
- exports.sortByZIndexAscending = sortByZIndexAscending;
1859
- exports.timing = timing;
1860
- exports.withContext = withContext;
1861
- //# sourceMappingURL=revas.common.js.map