canvasengine 1.3.0 → 2.0.1-beta.1

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 (125) hide show
  1. package/.cursorrules +0 -0
  2. package/.github/workflows/ci.yml +29 -0
  3. package/README.md +79 -0
  4. package/dist/compiler/vite.js +119 -0
  5. package/dist/compiler/vite.js.map +1 -0
  6. package/dist/index.d.ts +846 -0
  7. package/dist/index.js +3340 -0
  8. package/dist/index.js.map +1 -0
  9. package/index.d.ts +6 -0
  10. package/logo.png +0 -0
  11. package/package.json +84 -18
  12. package/src/compiler/grammar.pegjs +180 -0
  13. package/src/compiler/vite.ts +166 -0
  14. package/src/components/Canvas.ts +134 -0
  15. package/src/components/Container.ts +46 -0
  16. package/src/components/DisplayObject.ts +458 -0
  17. package/src/components/DrawMap/index.ts +65 -0
  18. package/src/components/Graphic.ts +147 -0
  19. package/src/components/NineSliceSprite.ts +46 -0
  20. package/src/components/ParticleEmitter.ts +39 -0
  21. package/src/components/Scene.ts +6 -0
  22. package/src/components/Sprite.ts +493 -0
  23. package/src/components/Text.ts +145 -0
  24. package/src/components/Tilemap/Tile.ts +79 -0
  25. package/src/components/Tilemap/TileGroup.ts +207 -0
  26. package/src/components/Tilemap/TileLayer.ts +163 -0
  27. package/src/components/Tilemap/TileSet.ts +41 -0
  28. package/src/components/Tilemap/index.ts +80 -0
  29. package/src/components/TilingSprite.ts +39 -0
  30. package/src/components/Viewport.ts +159 -0
  31. package/src/components/index.ts +12 -0
  32. package/src/components/types/DisplayObject.ts +68 -0
  33. package/src/components/types/MouseEvent.ts +3 -0
  34. package/src/components/types/Spritesheet.ts +389 -0
  35. package/src/components/types/index.ts +4 -0
  36. package/src/directives/Drag.ts +84 -0
  37. package/src/directives/KeyboardControls.ts +922 -0
  38. package/src/directives/Scheduler.ts +112 -0
  39. package/src/directives/Sound.ts +91 -0
  40. package/src/directives/Transition.ts +45 -0
  41. package/src/directives/ViewportCull.ts +40 -0
  42. package/src/directives/ViewportFollow.ts +26 -0
  43. package/src/directives/index.ts +7 -0
  44. package/src/engine/animation.ts +113 -0
  45. package/src/engine/bootstrap.ts +19 -0
  46. package/src/engine/directive.ts +23 -0
  47. package/src/engine/reactive.ts +379 -0
  48. package/src/engine/signal.ts +138 -0
  49. package/src/engine/trigger.ts +40 -0
  50. package/src/engine/utils.ts +135 -0
  51. package/src/hooks/addContext.ts +6 -0
  52. package/src/hooks/useProps.ts +155 -0
  53. package/src/hooks/useRef.ts +21 -0
  54. package/src/index.ts +14 -0
  55. package/src/presets/Bar.ts +89 -0
  56. package/src/presets/Button.ts +0 -0
  57. package/src/presets/Joystick.ts +286 -0
  58. package/src/presets/NightAmbiant.ts +122 -0
  59. package/src/presets/Particle.ts +53 -0
  60. package/src/utils/Ease.ts +33 -0
  61. package/src/utils/RadialGradient.ts +86 -0
  62. package/starter/assets/logo.png +0 -0
  63. package/starter/components/app.ce +18 -0
  64. package/starter/components/hello.ce +35 -0
  65. package/starter/index.html +21 -0
  66. package/starter/main.ts +6 -0
  67. package/starter/package.json +20 -0
  68. package/starter/tsconfig.json +32 -0
  69. package/starter/vite.config.ts +12 -0
  70. package/tsconfig.json +32 -0
  71. package/tsconfig.node.json +10 -0
  72. package/tsup.config.ts +28 -0
  73. package/vitest.config.ts +12 -0
  74. package/.gitattributes +0 -22
  75. package/.npmignore +0 -163
  76. package/canvasengine-1.3.0.all.min.js +0 -21
  77. package/canvasengine.js +0 -5802
  78. package/core/DB.js +0 -24
  79. package/core/ModelServer.js +0 -348
  80. package/core/Users.js +0 -190
  81. package/core/engine-common.js +0 -952
  82. package/doc/cocoonjs.md +0 -36
  83. package/doc/doc-lang.yml +0 -43
  84. package/doc/doc-router.yml +0 -14
  85. package/doc/doc-tuto.yml +0 -9
  86. package/doc/doc.yml +0 -39
  87. package/doc/element.md +0 -37
  88. package/doc/entity.md +0 -90
  89. package/doc/extend.md +0 -47
  90. package/doc/get_started.md +0 -19
  91. package/doc/images/entity.png +0 -0
  92. package/doc/multitouch.md +0 -58
  93. package/doc/nodejs.md +0 -142
  94. package/doc/scene.md +0 -44
  95. package/doc/text.md +0 -156
  96. package/examples/server/client.html +0 -31
  97. package/examples/server/server.js +0 -16
  98. package/examples/tiled_server/client.html +0 -52
  99. package/examples/tiled_server/images/tiles_spritesheet.png +0 -0
  100. package/examples/tiled_server/server/map.json +0 -50
  101. package/examples/tiled_server/server/map.tmx +0 -16
  102. package/examples/tiled_server/server/server.js +0 -16
  103. package/extends/Animation.js +0 -910
  104. package/extends/Effect.js +0 -252
  105. package/extends/Gleed2d.js +0 -252
  106. package/extends/Hit.js +0 -1509
  107. package/extends/Input.js +0 -699
  108. package/extends/Marshal.js +0 -716
  109. package/extends/Scrolling.js +0 -388
  110. package/extends/Soundmanager2.js +0 -5466
  111. package/extends/Spritesheet.js +0 -196
  112. package/extends/Text.js +0 -366
  113. package/extends/Tiled.js +0 -403
  114. package/extends/Window.js +0 -575
  115. package/extends/gamepad.js +0 -397
  116. package/extends/socket.io.min.js +0 -2
  117. package/extends/swf/soundmanager2.swf +0 -0
  118. package/extends/swf/soundmanager2_debug.swf +0 -0
  119. package/extends/swf/soundmanager2_flash9.swf +0 -0
  120. package/extends/swf/soundmanager2_flash9_debug.swf +0 -0
  121. package/extends/swf/soundmanager2_flash_xdomain.zip +0 -0
  122. package/extends/workers/transition.js +0 -43
  123. package/index.js +0 -46
  124. package/license.txt +0 -19
  125. package/readme.md +0 -483
@@ -1,716 +0,0 @@
1
- /**
2
- * Copyright (c) 2009-2011 Ivo Wetzel.
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- * THE SOFTWARE.
21
- */
22
- (function(array, undefined) {
23
-
24
- var BitStream = (function() {
25
-
26
- // Some Lookup tables
27
- var chrTable = new array(255);
28
- for(var i = 0; i < 256; i++) {
29
- chrTable[i] = String.fromCharCode(i);
30
- }
31
-
32
- var maskTable = new array(8),
33
- powTable = new array(8);
34
-
35
- for(var i = 0; i < 9; i++) {
36
- maskTable[i] = ~((powTable[i] = Math.pow(2, i) - 1) ^ 0xFF);
37
- }
38
-
39
- var stream = '',
40
- value = 0,
41
- left = 8,
42
- index = 0,
43
- max = 0;
44
-
45
- return {
46
-
47
- open: function(data) {
48
-
49
- left = 8;
50
-
51
- if (data !== undefined) {
52
- max = data.length;
53
- index = 0;
54
- stream = data;
55
- value = stream.charCodeAt(index);
56
-
57
- } else {
58
- value = 0;
59
- stream = '';
60
- }
61
-
62
- },
63
-
64
- close: function() {
65
-
66
- if (value > 0) {
67
- stream += chrTable[value];
68
- }
69
-
70
- return stream;
71
-
72
- },
73
-
74
- writeRaw: function(raw) {
75
-
76
- if (left !== 8) {
77
- stream += chrTable[value];
78
- value = 0;
79
- left = 8;
80
- }
81
-
82
- stream += raw;
83
- },
84
-
85
- readRaw: function(count) {
86
-
87
- if (left !== 8) {
88
- index++;
89
- value = 0;
90
- left = 8;
91
- }
92
-
93
- var data = stream.substr(index, count);
94
-
95
- index += count;
96
- value = stream.charCodeAt(index);
97
- return data;
98
-
99
- },
100
-
101
- write: function write(val, count) {
102
-
103
- var overflow = count - left,
104
- use = left < count ? left : count,
105
- shift = left - use;
106
-
107
- if (overflow > 0) {
108
- value += val >> overflow << shift;
109
-
110
- } else {
111
- value += val << shift;
112
- }
113
-
114
- left -= use;
115
-
116
- if (left === 0) {
117
-
118
- stream += chrTable[value];
119
- left = 8;
120
- value = 0;
121
-
122
- if (overflow > 0) {
123
- write(val & powTable[overflow], overflow);
124
- }
125
-
126
- }
127
-
128
- },
129
-
130
- read: function read(count) {
131
-
132
- if (index >= max) {
133
- return null;
134
- }
135
-
136
- var overflow = count - left,
137
- use = left < count ? left : count,
138
- shift = left - use;
139
-
140
- var val = (value & maskTable[left]) >> shift;
141
- left -= use;
142
-
143
- if (left === 0) {
144
-
145
- value = stream.charCodeAt(++index);
146
- left = 8;
147
-
148
- if (overflow > 0) {
149
- val = val << overflow | read(overflow);
150
- }
151
-
152
- }
153
-
154
- return val;
155
-
156
- }
157
-
158
- };
159
-
160
- })();
161
-
162
- // Shorthands
163
- var write = BitStream.write,
164
- read = BitStream.read,
165
- writeRaw = BitStream.writeRaw,
166
- readRaw = BitStream.readRaw,
167
- open = BitStream.open,
168
- close = BitStream.close;
169
-
170
- // Encoder ----------------------------------------------------------------
171
- function _encode(value, top) {
172
-
173
- // Numbers
174
- if (typeof value === 'number') {
175
-
176
- var type = value !== (value | 0),
177
- sign = 0;
178
-
179
- if (value < 0) {
180
- value = -value;
181
- sign = 1;
182
- }
183
-
184
- write(1 + type, 3);
185
-
186
- // Float
187
- if (type) {
188
-
189
- var shift = 1,
190
- step = 10;
191
-
192
- while(step <= value) {
193
- shift++;
194
- step *= 10;
195
- }
196
-
197
- // Ensure we don't lose precision
198
- shift = (8 - shift) + 1;
199
- value = Math.round(value * (1000000000 / step));
200
-
201
- // Figure out the smallest exp for value
202
- while(value / 10 === ((value / 10) | 0)) {
203
- value /= 10;
204
- shift--;
205
- }
206
-
207
- }
208
-
209
- // 2 size 0-3: 0 = < 16 1 = < 256 2 = < 65536 3 >
210
- if (value < 2) {
211
- write(value, 4);
212
-
213
- } else if (value < 16) {
214
- write(1, 3);
215
- write(value, 4);
216
-
217
- } else if (value < 256) {
218
- write(2, 3);
219
- write(value, 8);
220
-
221
- } else if (value < 4096) {
222
- write(3, 3);
223
- write(value >> 8 & 0xff, 4);
224
- write(value & 0xff, 8);
225
-
226
- } else if (value < 65536) {
227
- write(4, 3);
228
- write(value >> 8 & 0xff, 8);
229
- write(value & 0xff, 8);
230
-
231
- } else if (value < 1048576) {
232
- write(5, 3);
233
- write(value >> 16 & 0xff, 4);
234
- write(value >> 8 & 0xff, 8);
235
- write(value & 0xff, 8);
236
-
237
- } else if (value < 16777216) {
238
- write(6, 3);
239
- write(value >> 16 & 0xff, 8);
240
- write(value >> 8 & 0xff, 8);
241
- write(value & 0xff, 8);
242
-
243
- } else {
244
- write(7, 3);
245
- write(value >> 24 & 0xff, 8);
246
- write(value >> 16 & 0xff, 8);
247
- write(value >> 8 & 0xff, 8);
248
- write(value & 0xff, 8);
249
- }
250
-
251
- write(sign, 1);
252
-
253
- if (type) {
254
- write(shift, 4);
255
- }
256
-
257
- // Strings
258
- } else if (typeof value === 'string') {
259
-
260
- var l = value.length;
261
- write(3, 3);
262
-
263
- if (l > 65535) {
264
- write(31, 5);
265
- write(l >> 24 & 0xff, 8);
266
- write(l >> 16 & 0xff, 8);
267
- write(l >> 8 & 0xff, 8);
268
- write(l & 0xff, 8);
269
-
270
- } else if (l > 255) {
271
- write(30, 5);
272
- write(l >> 8 & 0xff, 8);
273
- write(l & 0xff, 8);
274
-
275
- } else if (l > 28) {
276
- write(29, 5);
277
- write(l, 8);
278
-
279
- } else {
280
- write(l, 5);
281
- }
282
-
283
- writeRaw(value);
284
-
285
- // Booleans
286
- } else if (typeof value === 'boolean') {
287
- write(+value, 5);
288
-
289
- // Null
290
- } else if (value === null) {
291
- write(2, 5);
292
-
293
- // Arrays
294
- } else if (value instanceof array) {
295
-
296
- write(4, 3);
297
- for(var i = 0, l = value.length; i < l; i++) {
298
- _encode(value[i]);
299
- }
300
-
301
- if (!top) {
302
- write(6, 3);
303
- }
304
-
305
- // Object
306
- } else {
307
-
308
- write(5, 3);
309
- for(var e in value) {
310
- _encode(e);
311
- _encode(value[e]);
312
- }
313
-
314
- if (!top) {
315
- write(6, 3);
316
- }
317
-
318
- }
319
-
320
- }
321
-
322
- function encode(value) {
323
- open();
324
- _encode(value, true);
325
- write(0, 3);
326
- write(3, 2);
327
- return close();
328
- }
329
-
330
- var powTable = new array(16);
331
- for(var i = 0; i < 16; i++) {
332
- powTable[i] = Math.pow(10, i);
333
- }
334
-
335
-
336
- // Decoder ----------------------------------------------------------------
337
- function decode(string) {
338
-
339
- var stack = [], i = -1,
340
- type, top, value, obj,
341
- getKey = false, key, isObj, decoded;
342
-
343
- open(string);
344
- while(true) {
345
-
346
- // Grab type
347
- type = read(3);
348
-
349
- // Null / Bool / EOS
350
- if (type === 0) {
351
-
352
- value = read(2);
353
-
354
- // Null
355
- if (value === 2) {
356
- value = null;
357
-
358
- // A boolean
359
- } else if (value < 2) {
360
- value = !!value;
361
-
362
- // End of stream
363
- } else if (value === 3) {
364
- break;
365
- }
366
-
367
- // Integer / Float
368
- } else if (type === 1 || type === 2) {
369
-
370
- switch(read(3)) {
371
- case 0:
372
- value = read(1);
373
- break;
374
-
375
- case 1:
376
- value = read(4);
377
- break;
378
-
379
- case 2:
380
- value = read(8);
381
- break;
382
-
383
- case 3:
384
- value = (read(4) << 8)
385
- + read(8);
386
-
387
- break;
388
-
389
- case 4:
390
- value = (read(8) << 8)
391
- + read(8);
392
-
393
- break;
394
-
395
- case 5:
396
- value = (read(4) << 16)
397
- + (read(8) << 8)
398
- + read(8);
399
-
400
- break;
401
-
402
- case 6:
403
- value = (read(8) << 16)
404
- + (read(8) << 8)
405
- + read(8);
406
-
407
- break;
408
-
409
- case 7:
410
- value = (read(8) << 24)
411
- + (read(8) << 16)
412
- + (read(8) << 8)
413
- + read(8);
414
-
415
- break;
416
- }
417
-
418
- if (read(1)) {
419
- value = -value;
420
- }
421
-
422
- if (type === 2) {
423
- value /= powTable[read(4)];
424
- }
425
-
426
- // String
427
- } else if (type === 3) {
428
-
429
- var size = read(5);
430
- switch(size) {
431
- case 31:
432
- size = (read(8) << 24)
433
- + (read(8) << 16)
434
- + (read(8) << 8)
435
- + read(8);
436
-
437
- break;
438
-
439
- case 30:
440
- size = (read(8) << 8)
441
- + read(8);
442
-
443
- break;
444
-
445
- case 29:
446
- size = read(8);
447
- break;
448
-
449
- }
450
-
451
- value = readRaw(size);
452
-
453
- if (getKey) {
454
- key = value;
455
- getKey = false;
456
- continue;
457
- }
458
-
459
- // Open Array / Objects
460
- } else if (type === 4 || type === 5) {
461
-
462
- getKey = type === 5;
463
- value = getKey ? {} : [];
464
-
465
- if (decoded === undefined) {
466
- decoded = value;
467
-
468
- } else {
469
-
470
- if (isObj) {
471
- top[key] = value;
472
-
473
- } else {
474
- top.push(value);
475
- }
476
- }
477
-
478
- top = stack[++i] = value;
479
- isObj = !(top instanceof Array);
480
- continue;
481
-
482
- // Close Array / Object
483
- } else if (type === 6) {
484
- top = stack[--i];
485
- getKey = isObj = !(top instanceof Array);
486
- continue;
487
- }
488
-
489
-
490
- // Assign value to top of stack or return value
491
- if (isObj) {
492
- top[key] = value;
493
- getKey = true;
494
-
495
- } else if (top !== undefined) {
496
- top.push(value);
497
-
498
- } else {
499
- return value;
500
- }
501
-
502
- }
503
-
504
- return decoded;
505
-
506
- }
507
-
508
- // Exports
509
- if (typeof window === 'undefined') {
510
- exports.encode = encode;
511
- exports.decode = decode;
512
-
513
- } else {
514
- window.BISON = {
515
- encode: encode,
516
- decode: decode
517
- };
518
- }
519
-
520
- })(Array);
521
-
522
- /**
523
- @doc save
524
- @class Marshal The marshaling library converts collections of JS objects into a BISON format, allowing them to be stored in localStorage. This data may subsequently be read and the original objects reconstituted.
525
-
526
- BISON : https://github.com/BonsaiDen/BiSON.js/
527
- Inspired of Ruby : http://www.ruby-doc.org/core-1.9.3/Marshal.html
528
-
529
- @static
530
- @example
531
- To write :
532
-
533
- Class.create("Foo", {
534
- bar: 2
535
- });
536
- Class.create("Test", {
537
- qux: 5
538
- });
539
- var foo = Class.new("Foo"),
540
- test = Class.new("Test");
541
- Marshal.dump(foo, "save_name");
542
- test.qux = 10;
543
- Marshal.dump(test, "save_name");
544
-
545
- Read the save from above :
546
-
547
- Class.create("Foo", {
548
- bar: 2
549
- });
550
- Class.create("Test", {
551
- qux: 5
552
- });
553
- var foo = Class.new("Foo"),
554
- test = Class.new("Test");
555
- foo = Marshal.load("save_name");
556
- test = Marshal.load("save_name");
557
- console.log(test.qux); // 10
558
-
559
- */
560
- Marshal = {
561
- _pointer: {},
562
- _cache: {},
563
- _stack_dump: [],
564
-
565
- _decode: function(val) {
566
- if (navigator.appName == 'Microsoft Internet Explorer') {
567
- try {
568
- return JSON.parse(val);
569
- }
570
- catch (e) {
571
-
572
- }
573
- }
574
- else {
575
- return BISON.decode(val);
576
- }
577
- },
578
-
579
- _encode: function(val) {
580
- if (navigator.appName == 'Microsoft Internet Explorer') {
581
- try {
582
- return JSON.stringify(val);
583
- }
584
- catch (e) {
585
-
586
- }
587
- }
588
- else {
589
- return BISON.encode(val);
590
- }
591
- },
592
-
593
- /**
594
- @doc save/
595
- @method exist Testing the existence of save in localStorage
596
- @param {String} name Save name
597
- @return Class
598
- */
599
- exist: function(file) {
600
- return localStorage && localStorage[file];
601
- },
602
-
603
- _recursiveData: function(data, type) {
604
- var _class_name, _class = {}, new_class = {}, val;
605
-
606
- if (data instanceof Object) {
607
- for (var method in data) {
608
- val = data[method];
609
- if (typeof val != "function") {
610
- if (val instanceof Array) {
611
- new_class[method] = [];
612
- for (var i=0 ; i < val.length ; i++) {
613
- new_class[method][i] = this._recursiveData(val[i], type);
614
- }
615
- }
616
- else if (val instanceof Object) {
617
- new_class[method] = this._recursiveData(val, type);
618
- }
619
- else if (val !== undefined) {
620
- new_class[method] = val;
621
- }
622
- }
623
- }
624
- }
625
- else {
626
- if (typeof data != "function" && data !== undefined) {
627
- return data;
628
- }
629
- }
630
-
631
- if (type == "load") {
632
- if (new_class.__name__) {
633
- _class = Class.New(data.__name__, false);
634
- for (var method in new_class) {
635
- if (typeof _class[method] != "function") {
636
- _class[method] = new_class[method];
637
- }
638
- }
639
- }
640
- else {
641
-
642
- _class = new_class;
643
- }
644
- }
645
- else {
646
- _class = new_class;
647
- }
648
-
649
- return _class;
650
- },
651
-
652
-
653
- /**
654
- @doc save/
655
- @method load Load data and restores the properties of the class the order of the stack of Marshal
656
- @param {String} name Save name
657
- @return Class
658
- */
659
- load: function(file) {
660
- var data, _class, _class_name;
661
-
662
- if (this._pointer[file] === undefined) {
663
- this._pointer[file] = 0;
664
- }
665
-
666
- if (this._cache[file]) {
667
- data = this._cache[file];
668
- }
669
- else if (localStorage) {
670
- data = this._decode(localStorage[file]) || [];
671
- this._cache[file] = data;
672
- }
673
- _class = this._recursiveData(data[this._pointer[file]], "load");
674
- if (!Marshal.exist(file)) {
675
- return false;
676
- }
677
-
678
- this._pointer[file]++;
679
- return _class;
680
- },
681
- /**
682
- @doc save/
683
- @method dump Saves the properties of a class in localStorage. The order is important for recovery with load method
684
- @param {Class} _class Class
685
- @param {String} name Save name
686
- */
687
- dump: function(_class, file) {
688
- var storage = [], new_data = {};
689
- if (typeof _class == "number" ||
690
- typeof _class == "string" ||
691
- _class instanceof Array) {
692
- new_data = _class;
693
- }
694
- else {
695
- new_data = this._recursiveData(_class, "save");
696
- }
697
- this._stack_dump.push(new_data);
698
- if (localStorage) {
699
- localStorage[file] = this._encode(this._stack_dump);
700
- }
701
-
702
- },
703
-
704
- /**
705
- @doc save/
706
- @method remove Remove save
707
- @param {String} name Save name
708
- */
709
- remove: function(file) {
710
- if (localStorage) {
711
- localStorage.removeItem(file);
712
- return true;
713
- }
714
- return false;
715
- }
716
- };