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