canvasengine 2.0.0-beta.1 → 2.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -841,7 +841,6 @@ var KeyboardControls = class extends Directive {
841
841
  registerDirective("controls", KeyboardControls);
842
842
 
843
843
  // src/directives/Scheduler.ts
844
- import Stats from "stats.js";
845
844
  var Scheduler = class extends Directive {
846
845
  constructor() {
847
846
  super(...arguments);
@@ -852,7 +851,6 @@ var Scheduler = class extends Directive {
852
851
  this.requestedDelay = 0;
853
852
  this.lastTimestamp = 0;
854
853
  this._stop = false;
855
- this.stats = new Stats();
856
854
  }
857
855
  onInit(element) {
858
856
  this.tick = element.propObservables?.tick;
@@ -867,20 +865,15 @@ var Scheduler = class extends Directive {
867
865
  this.lastTimestamp = this.lastTimestamp || this.timestamp;
868
866
  this.deltaTime = preciseNow() - this.timestamp;
869
867
  this.timestamp = timestamp;
870
- this.stats.begin();
871
868
  this.tick.set({
872
869
  timestamp: this.timestamp,
873
870
  deltaTime: this.deltaTime,
874
871
  frame: this.frame,
875
872
  deltaRatio: ~~this.deltaTime / ~~fps2ms(this.fps)
876
873
  });
877
- this.stats.end();
878
874
  this.lastTimestamp = this.timestamp;
879
875
  this.frame++;
880
876
  }
881
- showPanel() {
882
- this.stats.showPanel(0);
883
- }
884
877
  /**
885
878
  * start the schedule
886
879
  * @return {Scheduler} returns this scheduler instance
@@ -889,7 +882,6 @@ var Scheduler = class extends Directive {
889
882
  if (options.maxFps) this.maxFps = options.maxFps;
890
883
  if (options.fps) this.fps = options.fps;
891
884
  if (options.delay) this.requestedDelay = options.delay;
892
- this.showPanel();
893
885
  const requestAnimationFrame = (fn) => {
894
886
  if (isBrowser()) {
895
887
  window.requestAnimationFrame(fn.bind(this));
@@ -2125,8 +2117,8 @@ import {
2125
2117
  // src/engine/animation.ts
2126
2118
  import { effect as effect6, signal as signal4 } from "@signe/reactive";
2127
2119
  import { animate as animatePopmotion } from "popmotion";
2128
- function isAnimatedSignal(signal8) {
2129
- return signal8.animatedState !== void 0;
2120
+ function isAnimatedSignal(signal6) {
2121
+ return signal6.animatedState !== void 0;
2130
2122
  }
2131
2123
  function animatedSignal(initialValue, options = {}) {
2132
2124
  const state = {
@@ -2417,14 +2409,13 @@ var CanvasSprite = class extends DisplayObject(PixiSprite) {
2417
2409
  let frame = sprites[this.frameIndex];
2418
2410
  const nextFrame = sprites[this.frameIndex + 1];
2419
2411
  for (let _sprite of this.currentAnimationContainer.children) {
2420
- let applyTransformValue2 = function(prop, alias) {
2412
+ let applyTransformValue = function(prop, alias) {
2421
2413
  const optionProp = alias || prop;
2422
2414
  const val = getVal(optionProp);
2423
2415
  if (val !== void 0) {
2424
2416
  self[prop] = val;
2425
2417
  }
2426
2418
  };
2427
- var applyTransformValue = applyTransformValue2;
2428
2419
  const sprite = _sprite;
2429
2420
  if (!frame || frame.frameY == void 0 || frame.frameX == void 0) {
2430
2421
  continue;
@@ -2464,12 +2455,12 @@ var CanvasSprite = class extends DisplayObject(PixiSprite) {
2464
2455
  applyTransform("scale");
2465
2456
  applyTransform("skew");
2466
2457
  applyTransform("pivot");
2467
- applyTransformValue2("alpha", "opacity");
2468
- applyTransformValue2("x");
2469
- applyTransformValue2("y");
2470
- applyTransformValue2("angle");
2471
- applyTransformValue2("rotation");
2472
- applyTransformValue2("visible");
2458
+ applyTransformValue("alpha", "opacity");
2459
+ applyTransformValue("x");
2460
+ applyTransformValue("y");
2461
+ applyTransformValue("angle");
2462
+ applyTransformValue("rotation");
2463
+ applyTransformValue("visible");
2473
2464
  }
2474
2465
  if (!nextFrame) {
2475
2466
  this.time = 0;
@@ -2627,10 +2618,6 @@ function Text(props) {
2627
2618
  return createComponent("Text", props);
2628
2619
  }
2629
2620
 
2630
- // src/components/Tilemap/index.ts
2631
- import { TiledLayerType, TiledParserFile } from "@rpgjs/tiled";
2632
- import { effect as effect9, signal as signal6 } from "@signe/reactive";
2633
-
2634
2621
  // src/components/TilingSprite.ts
2635
2622
  import { TilingSprite as PixiTilingSprite, Texture as Texture3 } from "pixi.js";
2636
2623
  var CanvasTilingSprite = class extends DisplayObject(PixiTilingSprite) {
@@ -2658,298 +2645,9 @@ function TilingSprite(props) {
2658
2645
  return createComponent("TilingSprite", props);
2659
2646
  }
2660
2647
 
2661
- // src/components/Tilemap/TileLayer.ts
2662
- import { CompositeTilemap, POINT_STRUCT_SIZE, settings } from "@pixi/tilemap";
2663
- import { Layer } from "@rpgjs/tiled";
2664
-
2665
- // src/components/Tilemap/Tile.ts
2666
- import { AnimatedSprite, groupD8 } from "pixi.js";
2667
- var Tile = class _Tile extends AnimatedSprite {
2668
- constructor(tile, tileSet) {
2669
- super(_Tile.getTextures(tile, tileSet));
2670
- this.tile = tile;
2671
- this.tileSet = tileSet;
2672
- this.animations = [];
2673
- this._x = 0;
2674
- this._y = 0;
2675
- this.properties = {};
2676
- this.animations = tile.animations || [];
2677
- this.properties = tile.properties;
2678
- this.textures = _Tile.getTextures(tile, tileSet);
2679
- this.texture = this.textures[0];
2680
- this.flip();
2681
- }
2682
- static getTextures(tile, tileSet) {
2683
- const textures = [];
2684
- if (tile.animations && tile.animations.length) {
2685
- tile.animations.forEach((frame) => {
2686
- textures.push(tileSet.textures[frame.tileid]);
2687
- });
2688
- } else {
2689
- textures.push(tileSet.textures[tile.gid - tileSet.firstgid]);
2690
- }
2691
- return textures;
2692
- }
2693
- get gid() {
2694
- return this.tile.gid;
2695
- }
2696
- setAnimation(frame) {
2697
- const size = this.animations.length;
2698
- if (size > 1) {
2699
- const offset = (this.animations[1].tileid - this.animations[0].tileid) * this.width;
2700
- frame.tileAnimX(offset, size);
2701
- }
2702
- }
2703
- flip() {
2704
- let symmetry;
2705
- let i = 0;
2706
- const add = (symmetrySecond) => {
2707
- i++;
2708
- if (symmetry) symmetry = groupD8.add(symmetry, symmetrySecond);
2709
- else symmetry = symmetrySecond;
2710
- };
2711
- if (this.tile.horizontalFlip) {
2712
- add(groupD8.MIRROR_HORIZONTAL);
2713
- }
2714
- if (this.tile.verticalFlip) {
2715
- add(groupD8.MIRROR_VERTICAL);
2716
- }
2717
- if (this.tile.diagonalFlip) {
2718
- if (i % 2 == 0) {
2719
- add(groupD8.MAIN_DIAGONAL);
2720
- } else {
2721
- add(groupD8.REVERSE_DIAGONAL);
2722
- }
2723
- }
2724
- }
2725
- };
2726
-
2727
- // src/components/Tilemap/TileLayer.ts
2728
- settings.use32bitIndex = true;
2729
- var CanvasTileLayer = class _CanvasTileLayer extends DisplayObject(CompositeTilemap) {
2730
- constructor() {
2731
- super(...arguments);
2732
- this._tiles = {};
2733
- }
2734
- static findTileSet(gid, tileSets) {
2735
- let tileset;
2736
- for (let i = tileSets.length - 1; i >= 0; i--) {
2737
- tileset = tileSets[i];
2738
- if (tileset.firstgid && tileset.firstgid <= gid) {
2739
- break;
2740
- }
2741
- }
2742
- return tileset;
2743
- }
2744
- /** @internal */
2745
- createTile(x, y, options = {}) {
2746
- const { real, filter } = options;
2747
- const { tilewidth, tileheight, width } = this._layer;
2748
- if (real) {
2749
- x = Math.floor(x / tilewidth);
2750
- y = Math.floor(y / tileheight);
2751
- }
2752
- const i = x + y * width;
2753
- const tiledTile = this._layer.getTileByIndex(i);
2754
- if (!tiledTile || tiledTile && tiledTile.gid == 0) return;
2755
- const tileset = _CanvasTileLayer.findTileSet(
2756
- tiledTile.gid,
2757
- this.tileSets
2758
- );
2759
- if (!tileset) return;
2760
- const tile = new Tile(
2761
- tiledTile,
2762
- tileset
2763
- );
2764
- tile.x = x * tilewidth;
2765
- tile.y = y * tileheight + (tileheight - tile.texture.height);
2766
- tile._x = x;
2767
- tile._y = y;
2768
- if (tileset.tileoffset) {
2769
- tile.x += tileset.tileoffset.x ?? 0;
2770
- tile.y += tileset.tileoffset.y ?? 0;
2771
- }
2772
- if (filter) {
2773
- const ret = filter(tile);
2774
- if (!ret) return;
2775
- }
2776
- return tile;
2777
- }
2778
- /** @internal */
2779
- changeTile(x, y) {
2780
- const { tilewidth, tileheight } = this._layer;
2781
- x = Math.floor(x / tilewidth);
2782
- y = Math.floor(y / tileheight);
2783
- const oldTile = this._tiles[x + ";" + y];
2784
- const newTile = this.createTile(x, y);
2785
- if (!oldTile && newTile) {
2786
- this._addFrame(newTile, x, y);
2787
- } else {
2788
- if (newTile) {
2789
- const bufComposite = new CompositeTilemap();
2790
- const frame = bufComposite.tile(newTile.texture, newTile.x, newTile.y);
2791
- newTile.setAnimation(frame);
2792
- this._tiles[x + ";" + y] = newTile;
2793
- const pointsBufComposite = bufComposite.children[0].pointsBuf;
2794
- [0, 1, 4, 6, 7, 8].forEach((i) => {
2795
- if (this.pointsBuf) this.pointsBuf[oldTile.pointsBufIndex + i] = pointsBufComposite[i];
2796
- });
2797
- this.children[0].modificationMarker = 0;
2798
- this._addFrame(newTile, x, y);
2799
- this["modificationMarker"] = 0;
2800
- } else {
2801
- delete this._tiles[x + ";" + y];
2802
- if (this.pointsBuf) this.pointsBuf.splice(oldTile.pointsBufIndex, POINT_STRUCT_SIZE);
2803
- }
2804
- }
2805
- }
2806
- /** @internal */
2807
- get pointsBuf() {
2808
- const child = this.children[0];
2809
- if (!child) return null;
2810
- return child["pointsBuf"];
2811
- }
2812
- _addFrame(tile, x, y) {
2813
- const frame = this.tile(tile.texture, tile.x, tile.y, {
2814
- rotate: tile.texture.rotate
2815
- });
2816
- const pb = this.pointsBuf;
2817
- if (!pb) return null;
2818
- tile.pointsBufIndex = pb.length - POINT_STRUCT_SIZE;
2819
- tile.setAnimation(frame);
2820
- this._tiles[x + ";" + y] = tile;
2821
- }
2822
- onMount(args) {
2823
- const { props } = args;
2824
- this.tileSets = props.tilesets;
2825
- this._layer = new Layer({
2826
- ...props
2827
- }, this.tileSets);
2828
- super.onMount(args);
2829
- }
2830
- onUpdate(props) {
2831
- super.onUpdate(props);
2832
- if (!this.isMounted) return;
2833
- if (props.tileheight) this._layer.tileheight = props.tileheight;
2834
- if (props.tilewidth) this._layer.tilewidth = props.tilewidth;
2835
- if (props.width) this._layer.width = props.width;
2836
- if (props.height) this._layer.height = props.height;
2837
- if (props.parallaxX) this._layer.parallaxX = props.parallaxx;
2838
- if (props.parallaxY) this._layer.parallaxY = props.parallaxy;
2839
- this.removeChildren();
2840
- for (let y = 0; y < this._layer.height; y++) {
2841
- for (let x = 0; x < this._layer.width; x++) {
2842
- const tile = this.createTile(x, y);
2843
- if (tile) {
2844
- this._addFrame(tile, x, y);
2845
- }
2846
- }
2847
- }
2848
- }
2849
- };
2850
- registerComponent("CompositeTileLayer", CanvasTileLayer);
2851
- function CompositeTileLayer(props) {
2852
- return createComponent("CompositeTileLayer", props);
2853
- }
2854
-
2855
- // src/components/Tilemap/TileSet.ts
2856
- import { Tileset as TiledTilesetClass } from "@rpgjs/tiled";
2857
- import { Assets as Assets2, Rectangle as Rectangle3, Texture as Texture5 } from "pixi.js";
2858
- var TileSet = class extends TiledTilesetClass {
2859
- constructor(tileSet) {
2860
- super(tileSet);
2861
- this.textures = [];
2862
- this.tileGroups = {};
2863
- }
2864
- loadGroup() {
2865
- }
2866
- /** @internal */
2867
- async load(image) {
2868
- const texture = await Assets2.load(image);
2869
- for (let y = this.margin; y < this.image.height; y += this.tileheight + this.spacing) {
2870
- for (let x = this.margin; x < this.image.width; x += this.tilewidth + this.spacing) {
2871
- this.textures.push(
2872
- new Texture5({
2873
- source: texture.source,
2874
- frame: new Rectangle3(+x, +y, +this.tilewidth, +this.tileheight)
2875
- })
2876
- );
2877
- }
2878
- }
2879
- this.loadGroup();
2880
- return this;
2881
- }
2882
- };
2883
-
2884
- // src/components/Tilemap/index.ts
2885
- function TiledMap(props) {
2886
- const { map: map2 } = useProps(props);
2887
- const layers = signal6([]);
2888
- const objectLayer = props.objectLayer;
2889
- let tilesets = [];
2890
- let mapData = {};
2891
- const parseTmx = async (file, relativePath = "") => {
2892
- if (typeof file !== "string") {
2893
- return file;
2894
- }
2895
- const parser = new TiledParserFile(
2896
- file,
2897
- {
2898
- basePath: "",
2899
- staticDir: "",
2900
- relativePath
2901
- }
2902
- );
2903
- const data = await parser.parseFilePromise({
2904
- getOnlyBasename: false
2905
- });
2906
- return data;
2907
- };
2908
- effect9(async () => {
2909
- mapData = await parseTmx(map2());
2910
- for (let tileSet of mapData.tilesets) {
2911
- tilesets.push(await new TileSet(tileSet).load(tileSet.image.source));
2912
- }
2913
- layers.set(mapData.layers);
2914
- });
2915
- const createLayer = (layers2, props2 = {}) => {
2916
- return h(Container4, props2, loop(layers2, (layer) => {
2917
- switch (layer.type) {
2918
- case TiledLayerType.Tile:
2919
- return h(CompositeTileLayer, {
2920
- tilewidth: mapData.tilewidth,
2921
- tileheight: mapData.tileheight,
2922
- // @ts-ignore
2923
- width: mapData.width,
2924
- // @ts-ignore
2925
- height: mapData.height,
2926
- ...layer,
2927
- tilesets
2928
- });
2929
- case TiledLayerType.Image:
2930
- const { width, height, source } = layer.image;
2931
- return h(TilingSprite, {
2932
- image: source,
2933
- ...layer,
2934
- width: layer.repeatx ? layer.width * layer.tilewidth : width,
2935
- height: layer.repeaty ? layer.height * layer.tileheight : height
2936
- });
2937
- case TiledLayerType.Group:
2938
- return createLayer(signal6(layer.layers), layer);
2939
- case TiledLayerType.ObjectGroup:
2940
- const child = objectLayer?.(layer);
2941
- return h(Container4, layer, child);
2942
- default:
2943
- return h(Container4);
2944
- }
2945
- }));
2946
- };
2947
- return createLayer(layers);
2948
- }
2949
-
2950
2648
  // src/components/Viewport.ts
2951
2649
  import { Viewport as PixiViewport } from "pixi-viewport";
2952
- import { effect as effect10 } from "@signe/reactive";
2650
+ import { effect as effect9 } from "@signe/reactive";
2953
2651
  var EVENTS3 = [
2954
2652
  "bounce-x-end",
2955
2653
  "bounce-x-start",
@@ -3000,7 +2698,7 @@ var CanvasViewport = class extends DisplayObject(PixiViewport) {
3000
2698
  super.onMount(element);
3001
2699
  const { tick: tick2, renderer, canvasSize } = element.props.context;
3002
2700
  let isDragging = false;
3003
- effect10(() => {
2701
+ effect9(() => {
3004
2702
  this.screenWidth = canvasSize().width;
3005
2703
  this.screenHeight = canvasSize().height;
3006
2704
  });
@@ -3067,53 +2765,8 @@ function Viewport(props) {
3067
2765
  return createComponent("Viewport", props);
3068
2766
  }
3069
2767
 
3070
- // src/components/DrawMap/index.ts
3071
- import { effect as effect11, signal as signal7 } from "@signe/reactive";
3072
- function ImageMap(props) {
3073
- const { imageSource, tileData } = useProps(props);
3074
- const tiles = signal7([]);
3075
- effect11(async () => {
3076
- const data = await fetch(tileData()).then((response) => response.json());
3077
- const objects = data;
3078
- if (props.objects) {
3079
- objects.push(...props.objects(data));
3080
- }
3081
- tiles.set(objects);
3082
- });
3083
- const createLayeredTiles = () => {
3084
- const layers = [createTileLayer(0), createTileLayer(1, true), createTileLayer(2)];
3085
- return h(Container4, props, ...layers);
3086
- };
3087
- const createTileLayer = (layerIndex, sortableChildren = false) => {
3088
- return h(
3089
- Container4,
3090
- {
3091
- sortableChildren
3092
- },
3093
- loop(tiles, (object) => {
3094
- if (object.tag && layerIndex == 1) {
3095
- return object;
3096
- }
3097
- object.layerIndex || (object.layerIndex = 1);
3098
- if (object.layerIndex !== layerIndex) return null;
3099
- const [x, y, width, height] = object.rect;
3100
- const [drawX, drawY] = object.drawIn;
3101
- return h(Sprite2, {
3102
- image: imageSource(),
3103
- x: drawX,
3104
- y: drawY,
3105
- rectangle: { x, y, width, height },
3106
- zIndex: drawY + height - 70
3107
- // zIndex: 0
3108
- });
3109
- })
3110
- );
3111
- };
3112
- return createLayeredTiles();
3113
- }
3114
-
3115
2768
  // src/components/NineSliceSprite.ts
3116
- import { Assets as Assets3, NineSliceSprite as PixiNineSliceSprite } from "pixi.js";
2769
+ import { Assets as Assets2, NineSliceSprite as PixiNineSliceSprite } from "pixi.js";
3117
2770
  var CanvasNineSliceSprite = class extends DisplayObject(PixiNineSliceSprite) {
3118
2771
  constructor() {
3119
2772
  super({
@@ -3125,7 +2778,7 @@ var CanvasNineSliceSprite = class extends DisplayObject(PixiNineSliceSprite) {
3125
2778
  for (const [key, value] of Object.entries(props)) {
3126
2779
  if (value !== void 0) {
3127
2780
  if (key === "image") {
3128
- this.texture = await Assets3.load(value);
2781
+ this.texture = await Assets2.load(value);
3129
2782
  } else if (key in this) {
3130
2783
  this[key] = value;
3131
2784
  }
@@ -3148,120 +2801,6 @@ var bootstrapCanvas = async (rootElement, canvas) => {
3148
2801
  return canvasElement;
3149
2802
  };
3150
2803
 
3151
- // src/presets/Bar.ts
3152
- function componentToHex(c) {
3153
- var hex = c.toString(16);
3154
- return hex.length == 1 ? "0" + hex : hex;
3155
- }
3156
- function rgbToHex(r, g, b) {
3157
- return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
3158
- }
3159
- function Bar(opts) {
3160
- const {
3161
- width,
3162
- height,
3163
- value,
3164
- maxValue,
3165
- backgroundColor,
3166
- foregroundColor,
3167
- border,
3168
- innerMargin,
3169
- borderRadius
3170
- } = useProps(opts, {
3171
- backgroundColor: "#000000",
3172
- foregroundColor: "#FFFFFF",
3173
- innerMargin: 0,
3174
- borderRadius: 0
3175
- });
3176
- return h(
3177
- Graphics,
3178
- {
3179
- ...opts,
3180
- width,
3181
- height,
3182
- draw(g) {
3183
- if (borderRadius()) {
3184
- g.roundRect(0, 0, width(), height(), borderRadius());
3185
- } else {
3186
- g.rect(0, 0, width(), height());
3187
- }
3188
- if (border) {
3189
- g.stroke(border);
3190
- }
3191
- g.fill(backgroundColor());
3192
- }
3193
- },
3194
- h(Graphics, {
3195
- width,
3196
- height,
3197
- draw(g) {
3198
- const margin = innerMargin();
3199
- const _borderRadius = borderRadius();
3200
- const w = Math.max(
3201
- 0,
3202
- Math.min(
3203
- width() - 2 * margin,
3204
- value() / maxValue() * (width() - 2 * margin)
3205
- )
3206
- );
3207
- const h2 = height() - 2 * margin;
3208
- if (borderRadius) {
3209
- g.roundRect(margin, margin, w, h2, _borderRadius);
3210
- } else {
3211
- g.rect(margin, margin, w, h2);
3212
- }
3213
- const color = foregroundColor();
3214
- if (color.startsWith("rgba")) {
3215
- const [r, g2, b, a] = color.match(/\d+(\.\d+)?/g).map(Number);
3216
- g2.fill({ color: rgbToHex(r, g2, b), alpha: a });
3217
- } else {
3218
- g.fill(color);
3219
- }
3220
- }
3221
- })
3222
- );
3223
- }
3224
-
3225
- // src/presets/Particle.ts
3226
- import * as PIXI from "pixi.js";
3227
- import { FX } from "revolt-fx";
3228
- function Particle(options) {
3229
- const { emit, settings: settings2 = {} } = options;
3230
- const { name } = useProps(options);
3231
- const fx = new FX();
3232
- let element;
3233
- PIXI.Assets.add({ alias: "fx_settings", src: "/default-bundle.json" });
3234
- PIXI.Assets.add({
3235
- alias: "fx_spritesheet",
3236
- src: "/revoltfx-spritesheet.json"
3237
- });
3238
- tick(({ deltaRatio }) => {
3239
- fx.update(deltaRatio);
3240
- });
3241
- mount(async (_element) => {
3242
- element = _element;
3243
- const data = await PIXI.Assets.load(["fx_settings", "fx_spritesheet"]);
3244
- let fxSettings = { ...data.fx_settings };
3245
- if (settings2.emitters) {
3246
- const lastId = 1e4;
3247
- const emittersWithIds = settings2.emitters.map((emitter, index) => ({
3248
- ...emitter,
3249
- id: lastId + index
3250
- }));
3251
- fxSettings.emitters = [
3252
- ...fxSettings.emitters,
3253
- ...emittersWithIds
3254
- ];
3255
- }
3256
- fx.initBundle(fxSettings, true);
3257
- });
3258
- on(emit, () => {
3259
- const emitter = fx.getParticleEmitter(name());
3260
- emitter.init(element.componentInstance);
3261
- });
3262
- return h(Container4);
3263
- }
3264
-
3265
2804
  // src/utils/Ease.ts
3266
2805
  import {
3267
2806
  linear,
@@ -3295,24 +2834,95 @@ var Easing = {
3295
2834
  bounceInOut,
3296
2835
  bounceOut
3297
2836
  };
2837
+
2838
+ // src/utils/RadialGradient.ts
2839
+ import { Texture as Texture5, ImageSource, DOMAdapter, Matrix } from "pixi.js";
2840
+ var RadialGradient = class {
2841
+ constructor(x0, y0, x1, y1, x2, y2, focalPoint = 0) {
2842
+ this.x0 = x0;
2843
+ this.y0 = y0;
2844
+ this.x1 = x1;
2845
+ this.y1 = y1;
2846
+ this.x2 = x2;
2847
+ this.y2 = y2;
2848
+ this.focalPoint = focalPoint;
2849
+ this.gradient = null;
2850
+ this.texture = null;
2851
+ this.size = 600;
2852
+ this.size = x0;
2853
+ const halfSize = this.size * 0.5;
2854
+ this.canvas = DOMAdapter.get().createCanvas();
2855
+ this.canvas.width = this.size;
2856
+ this.canvas.height = this.size;
2857
+ this.ctx = this.canvas.getContext("2d");
2858
+ if (this.ctx) {
2859
+ this.gradient = this.ctx.createRadialGradient(
2860
+ halfSize * (1 - focalPoint),
2861
+ halfSize,
2862
+ 0,
2863
+ halfSize,
2864
+ halfSize,
2865
+ halfSize - 0.5
2866
+ );
2867
+ }
2868
+ }
2869
+ addColorStop(offset, color) {
2870
+ if (this.gradient) {
2871
+ this.gradient.addColorStop(offset, color);
2872
+ }
2873
+ }
2874
+ render({ translate } = {}) {
2875
+ const { x0, y0, x1, y1, x2, y2, focalPoint } = this;
2876
+ const defaultSize = this.size;
2877
+ if (this.ctx && this.gradient) {
2878
+ this.ctx.fillStyle = this.gradient;
2879
+ this.ctx.fillRect(0, 0, defaultSize, defaultSize);
2880
+ this.texture = new Texture5({
2881
+ source: new ImageSource({
2882
+ resource: this.canvas,
2883
+ addressModeU: "clamp-to-edge",
2884
+ addressModeV: "clamp-to-edge"
2885
+ })
2886
+ });
2887
+ const m = new Matrix();
2888
+ const dx = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
2889
+ const dy = Math.sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));
2890
+ const angle = Math.atan2(y1 - y0, x1 - x0);
2891
+ const scaleX = dx / defaultSize;
2892
+ const scaleY = dy / defaultSize;
2893
+ m.rotate(-angle);
2894
+ m.scale(scaleX, scaleY);
2895
+ if (translate) {
2896
+ m.translate(translate.x, translate.y);
2897
+ }
2898
+ this.transform = m;
2899
+ }
2900
+ return {
2901
+ texture: this.texture,
2902
+ matrix: this.transform
2903
+ };
2904
+ }
2905
+ };
2906
+
2907
+ // src/index.ts
2908
+ import { isObservable } from "rxjs";
3298
2909
  export {
3299
- Bar,
3300
2910
  Canvas2 as Canvas,
3301
2911
  Circle,
3302
2912
  Container4 as Container,
2913
+ DisplayObject,
2914
+ EVENTS2 as EVENTS,
3303
2915
  Easing,
3304
2916
  Ellipse,
3305
2917
  Graphics,
3306
2918
  Howler,
3307
- ImageMap,
3308
2919
  NineSliceSprite,
3309
- Particle,
3310
2920
  ParticlesEmitter,
2921
+ RadialGradient,
3311
2922
  Rect,
3312
2923
  Scene,
3313
2924
  Sprite2 as Sprite,
3314
2925
  Text,
3315
- TiledMap,
3316
2926
  TilingSprite,
3317
2927
  Triangle,
3318
2928
  Viewport,
@@ -3324,6 +2934,7 @@ export {
3324
2934
  h,
3325
2935
  isAnimatedSignal,
3326
2936
  isElement,
2937
+ isObservable,
3327
2938
  isPrimitive,
3328
2939
  isTrigger,
3329
2940
  loop,