modern-canvas 0.7.14 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +200 -111
- package/dist/index.d.cts +91 -20
- package/dist/index.d.mts +91 -20
- package/dist/index.d.ts +91 -20
- package/dist/index.js +52 -45
- package/dist/index.mjs +187 -109
- package/package.json +19 -15
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import { extend } from 'colord';
|
|
|
3
3
|
import namesPlugin from 'colord/plugins/names';
|
|
4
4
|
import { Path2D, Path2DSet, svgToDom, svgToPath2DSet, Matrix3 as Matrix3$1 } from 'modern-path2d';
|
|
5
5
|
import { Text } from 'modern-text';
|
|
6
|
-
import { loadYoga, BoxSizing, PositionType, Edge, Overflow, Gutter, Justify, Wrap, FlexDirection, Display, Direction, Align } from 'yoga-layout/load';
|
|
7
6
|
|
|
8
7
|
const customNodes = /* @__PURE__ */ new Map();
|
|
9
8
|
function customNode(name, defaultProperties) {
|
|
@@ -1740,7 +1739,7 @@ class Matrix3 extends Matrix {
|
|
|
1740
1739
|
constructor(array) {
|
|
1741
1740
|
super(3, 3, array);
|
|
1742
1741
|
}
|
|
1743
|
-
|
|
1742
|
+
affineInvert() {
|
|
1744
1743
|
const [
|
|
1745
1744
|
n11,
|
|
1746
1745
|
n21,
|
|
@@ -2192,10 +2191,10 @@ class Transform2D extends Matrix3 {
|
|
|
2192
2191
|
newPos.y = b * x + d * y + ty;
|
|
2193
2192
|
return newPos;
|
|
2194
2193
|
}
|
|
2195
|
-
|
|
2196
|
-
return this.clone().
|
|
2194
|
+
affineInverse() {
|
|
2195
|
+
return this.clone().affineInvert();
|
|
2197
2196
|
}
|
|
2198
|
-
|
|
2197
|
+
applyAffineInverse(pos, newPos) {
|
|
2199
2198
|
newPos = newPos || new Vector2();
|
|
2200
2199
|
const { a, b, c, d, tx, ty } = this.toObject();
|
|
2201
2200
|
const id = 1 / (a * d + c * -b);
|
|
@@ -2574,8 +2573,10 @@ attribute vec4 aBackgroundColor;
|
|
|
2574
2573
|
attribute vec4 aDisableWrapMode;
|
|
2575
2574
|
|
|
2576
2575
|
uniform mat3 projectionMatrix;
|
|
2577
|
-
uniform mat3
|
|
2576
|
+
uniform mat3 viewMatrix;
|
|
2578
2577
|
uniform vec4 modulate;
|
|
2578
|
+
uniform float canvasWidth;
|
|
2579
|
+
uniform float canvasHeight;
|
|
2579
2580
|
|
|
2580
2581
|
varying float vTextureId;
|
|
2581
2582
|
varying vec2 vUv;
|
|
@@ -2583,6 +2584,10 @@ varying vec4 vModulate;
|
|
|
2583
2584
|
varying vec4 vBackgroundColor;
|
|
2584
2585
|
varying vec4 vDisableWrapMode;
|
|
2585
2586
|
|
|
2587
|
+
vec2 roundPixels(vec2 position, vec2 targetSize) {
|
|
2588
|
+
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2586
2591
|
void main(void) {
|
|
2587
2592
|
mat3 modelMatrix = mat3(
|
|
2588
2593
|
1.0, 0.0, 0.0,
|
|
@@ -2590,8 +2595,9 @@ void main(void) {
|
|
|
2590
2595
|
0.0, 0.0, 1.0
|
|
2591
2596
|
);
|
|
2592
2597
|
vTextureId = aTextureId;
|
|
2593
|
-
|
|
2594
|
-
gl_Position = vec4((
|
|
2598
|
+
vec3 pos = projectionMatrix * viewMatrix * modelMatrix * vec3(aPosition, 1.0);
|
|
2599
|
+
gl_Position = vec4(roundPixels(pos.xy, vec2(canvasWidth, canvasHeight)), 0.0, 1.0);
|
|
2600
|
+
|
|
2595
2601
|
vUv = aUv;
|
|
2596
2602
|
vModulate = aModulate * modulate;
|
|
2597
2603
|
vBackgroundColor = aBackgroundColor;
|
|
@@ -2676,6 +2682,8 @@ void main(void) {
|
|
|
2676
2682
|
renderer2.program.updateUniforms(program, {
|
|
2677
2683
|
samplers,
|
|
2678
2684
|
modulate: [1, 1, 1, 1],
|
|
2685
|
+
canvasWidth: renderer2.gl.drawingBufferWidth,
|
|
2686
|
+
canvasHeight: renderer2.gl.drawingBufferHeight,
|
|
2679
2687
|
...renderer2.program.uniforms
|
|
2680
2688
|
});
|
|
2681
2689
|
renderer2.vertexArray.bind(vao ?? vertexArray);
|
|
@@ -3321,7 +3329,7 @@ class WebGLProgramModule extends WebGLModule {
|
|
|
3321
3329
|
boundProgram = null;
|
|
3322
3330
|
uniforms = {
|
|
3323
3331
|
projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
3324
|
-
|
|
3332
|
+
viewMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
|
3325
3333
|
};
|
|
3326
3334
|
create(options) {
|
|
3327
3335
|
const program = this.gl.createProgram();
|
|
@@ -3525,7 +3533,7 @@ ${gl.getShaderInfoLog(shader)}`);
|
|
|
3525
3533
|
this.boundProgram = null;
|
|
3526
3534
|
this.uniforms = {
|
|
3527
3535
|
projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
3528
|
-
|
|
3536
|
+
viewMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
|
3529
3537
|
};
|
|
3530
3538
|
}
|
|
3531
3539
|
free() {
|
|
@@ -3619,8 +3627,8 @@ class WebGLScissorModule extends WebGLModule {
|
|
|
3619
3627
|
use() {
|
|
3620
3628
|
const renderer = this._renderer;
|
|
3621
3629
|
const { pixelRatio, mask, viewport, screen, gl, program } = renderer;
|
|
3622
|
-
const {
|
|
3623
|
-
const rect = transformRectToAABB(
|
|
3630
|
+
const { viewMatrix } = program.uniforms;
|
|
3631
|
+
const rect = transformRectToAABB(viewMatrix, mask.last.mask);
|
|
3624
3632
|
const { x, y, width, height } = rect;
|
|
3625
3633
|
let scissorY;
|
|
3626
3634
|
if (viewport.boundViewport) {
|
|
@@ -6559,7 +6567,7 @@ let Viewport = class extends Node {
|
|
|
6559
6567
|
this.projection.flipY(flipY);
|
|
6560
6568
|
}
|
|
6561
6569
|
projection = new Projection2D();
|
|
6562
|
-
|
|
6570
|
+
canvasTransform = new Transform2D();
|
|
6563
6571
|
_framebufferIndex = 0;
|
|
6564
6572
|
_framebuffers = [
|
|
6565
6573
|
{ texture: new ViewportTexture(), needsUpload: false },
|
|
@@ -6674,7 +6682,7 @@ let Viewport = class extends Node {
|
|
|
6674
6682
|
render(renderer, next) {
|
|
6675
6683
|
const oldViewport = this._tree?.getCurrentViewport();
|
|
6676
6684
|
renderer.program.uniforms.projectionMatrix = this.projection.toArray(true);
|
|
6677
|
-
renderer.program.uniforms.
|
|
6685
|
+
renderer.program.uniforms.viewMatrix = this.canvasTransform.toArray(true);
|
|
6678
6686
|
this.activate(renderer);
|
|
6679
6687
|
renderer.clear();
|
|
6680
6688
|
super.render(renderer, next);
|
|
@@ -6689,11 +6697,11 @@ let Viewport = class extends Node {
|
|
|
6689
6697
|
getRect() {
|
|
6690
6698
|
return new Rect2(this.x, this.y, this.width, this.height);
|
|
6691
6699
|
}
|
|
6692
|
-
|
|
6693
|
-
return this.
|
|
6700
|
+
toCanvasGlobal(screenPos, newPos) {
|
|
6701
|
+
return this.canvasTransform.applyAffineInverse(screenPos, newPos);
|
|
6694
6702
|
}
|
|
6695
|
-
|
|
6696
|
-
return this.
|
|
6703
|
+
toCanvasScreen(globalPos, newPos) {
|
|
6704
|
+
return this.canvasTransform.apply(globalPos, newPos);
|
|
6697
6705
|
}
|
|
6698
6706
|
};
|
|
6699
6707
|
__decorateClass$P([
|
|
@@ -7231,35 +7239,28 @@ let Node2D = class extends CanvasItem {
|
|
|
7231
7239
|
getTransformOrigin() {
|
|
7232
7240
|
return new Vector2(0, 0);
|
|
7233
7241
|
}
|
|
7234
|
-
|
|
7242
|
+
updateTransform(cb) {
|
|
7235
7243
|
const origin = this.getTransformOrigin();
|
|
7236
|
-
const transform =
|
|
7237
|
-
transform.translate(-origin.x, -origin.y).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
|
|
7244
|
+
const transform = this.transform.identity().translate(-origin.x, -origin.y).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
|
|
7238
7245
|
cb?.(transform);
|
|
7239
7246
|
transform.translate(this.position.x, this.position.y).translate(origin.x, origin.y);
|
|
7240
|
-
return transform;
|
|
7241
|
-
}
|
|
7242
|
-
updateTransform() {
|
|
7243
|
-
this.transform.copy(this.getTransform());
|
|
7244
7247
|
}
|
|
7245
7248
|
updateGlobalTransform() {
|
|
7246
7249
|
this.updateTransform();
|
|
7247
7250
|
const parent = this.getParent();
|
|
7248
7251
|
if (parent?.globalTransform) {
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
|
|
7255
|
-
|
|
7256
|
-
|
|
7257
|
-
);
|
|
7258
|
-
this.
|
|
7259
|
-
|
|
7260
|
-
|
|
7261
|
-
);
|
|
7262
|
-
this.globalRotation = parent.globalRotation + this.rotation;
|
|
7252
|
+
const {
|
|
7253
|
+
globalPosition,
|
|
7254
|
+
globalScale,
|
|
7255
|
+
globalSkew,
|
|
7256
|
+
globalTransform,
|
|
7257
|
+
globalRotation
|
|
7258
|
+
} = parent;
|
|
7259
|
+
this._parentTransformDirtyId = globalTransform.dirtyId;
|
|
7260
|
+
this.globalPosition.set(globalPosition.x + this.position.x, globalPosition.y + this.position.y);
|
|
7261
|
+
this.globalScale.set(globalScale.x * this.scale.x, globalScale.y * this.scale.y);
|
|
7262
|
+
this.globalSkew.set(globalSkew.x * this.skew.x, globalSkew.y * this.skew.y);
|
|
7263
|
+
this.globalRotation = globalRotation + this.rotation;
|
|
7263
7264
|
parent.globalTransform.multiply(this.transform, this.globalTransform);
|
|
7264
7265
|
} else {
|
|
7265
7266
|
this.globalPosition.copy(this.position);
|
|
@@ -7308,7 +7309,7 @@ let Node2D = class extends CanvasItem {
|
|
|
7308
7309
|
}
|
|
7309
7310
|
}
|
|
7310
7311
|
toLocal(globalPos, newPos) {
|
|
7311
|
-
return this.globalTransform.
|
|
7312
|
+
return this.globalTransform.applyAffineInverse(globalPos, newPos);
|
|
7312
7313
|
}
|
|
7313
7314
|
toGlobal(localPos, newPos) {
|
|
7314
7315
|
return this.globalTransform.apply(localPos, newPos);
|
|
@@ -7335,7 +7336,7 @@ var __decorateClass$I = (decorators, target, key, kind) => {
|
|
|
7335
7336
|
return result;
|
|
7336
7337
|
};
|
|
7337
7338
|
let Camera2D = class extends Node2D {
|
|
7338
|
-
zoom = new Vector2(1, 1).on("update", () => this.
|
|
7339
|
+
zoom = new Vector2(1, 1).on("update", () => this.updateCanvasTransform());
|
|
7339
7340
|
maxZoom = new Vector2(6, 6);
|
|
7340
7341
|
minZoom = new Vector2(0.1, 0.1);
|
|
7341
7342
|
_screenOffset = { x: 0, y: 0 };
|
|
@@ -7422,14 +7423,26 @@ let Camera2D = class extends Node2D {
|
|
|
7422
7423
|
}
|
|
7423
7424
|
updateTransform() {
|
|
7424
7425
|
super.updateTransform();
|
|
7425
|
-
this.
|
|
7426
|
+
this.updateCanvasTransform();
|
|
7426
7427
|
}
|
|
7427
|
-
|
|
7428
|
+
updateCanvasTransform() {
|
|
7428
7429
|
const viewport = this.getViewport();
|
|
7429
7430
|
if (!viewport)
|
|
7430
7431
|
return;
|
|
7431
|
-
viewport.
|
|
7432
|
-
this.emit("
|
|
7432
|
+
viewport.canvasTransform.identity().scale(this.zoom.x, this.zoom.y).translate(this.position.x, this.position.y);
|
|
7433
|
+
this.emit("updateCanvasTransform");
|
|
7434
|
+
}
|
|
7435
|
+
toGlobal(screenPos, newPos) {
|
|
7436
|
+
const viewport = this.getViewport();
|
|
7437
|
+
if (!viewport)
|
|
7438
|
+
throw new Error("Failed to toGlobal, viewport is empty");
|
|
7439
|
+
return viewport.toCanvasGlobal(screenPos, newPos);
|
|
7440
|
+
}
|
|
7441
|
+
toScreen(globalPos, newPos) {
|
|
7442
|
+
const viewport = this.getViewport();
|
|
7443
|
+
if (!viewport)
|
|
7444
|
+
throw new Error("Failed to toScreen, viewport is empty");
|
|
7445
|
+
return viewport.toCanvasScreen(globalPos, newPos);
|
|
7433
7446
|
}
|
|
7434
7447
|
};
|
|
7435
7448
|
__decorateClass$I([
|
|
@@ -10032,9 +10045,9 @@ let BaseElement2D = class extends Node2D {
|
|
|
10032
10045
|
const [originX, originY] = parseCSSTransformOrigin(this.style.transformOrigin);
|
|
10033
10046
|
return new Vector2(originX * width, originY * height);
|
|
10034
10047
|
}
|
|
10035
|
-
|
|
10048
|
+
updateTransform(cb) {
|
|
10036
10049
|
const { width, height } = this.size;
|
|
10037
|
-
|
|
10050
|
+
super.updateTransform((transform) => {
|
|
10038
10051
|
parseCSSTransform(this.style.transform ?? "", width, height, transform);
|
|
10039
10052
|
cb?.(transform);
|
|
10040
10053
|
});
|
|
@@ -10223,7 +10236,7 @@ let BaseElement2D = class extends Node2D {
|
|
|
10223
10236
|
const pos = new Vector2(screenX, screenY);
|
|
10224
10237
|
const viewport = this.getViewport();
|
|
10225
10238
|
if (viewport) {
|
|
10226
|
-
viewport.
|
|
10239
|
+
viewport.toCanvasGlobal(pos, pos);
|
|
10227
10240
|
}
|
|
10228
10241
|
this.toLocal(pos, pos);
|
|
10229
10242
|
if (this._positionInput(pos, key)) {
|
|
@@ -10339,59 +10352,123 @@ Element2D = __decorateClass$k([
|
|
|
10339
10352
|
customNode("Element2D")
|
|
10340
10353
|
], Element2D);
|
|
10341
10354
|
|
|
10355
|
+
const edgeMap = {
|
|
10356
|
+
left: 0,
|
|
10357
|
+
// Edge.Left
|
|
10358
|
+
top: 1,
|
|
10359
|
+
// Edge.Top
|
|
10360
|
+
right: 2,
|
|
10361
|
+
// Edge.Right
|
|
10362
|
+
bottom: 3,
|
|
10363
|
+
// Edge.Bottom
|
|
10364
|
+
start: 4,
|
|
10365
|
+
// Edge.Start
|
|
10366
|
+
end: 5,
|
|
10367
|
+
// Edge.End
|
|
10368
|
+
horizontal: 6,
|
|
10369
|
+
// Edge.Horizontal
|
|
10370
|
+
vertical: 7,
|
|
10371
|
+
// Edge.Vertical
|
|
10372
|
+
all: 8
|
|
10373
|
+
// Edge.All
|
|
10374
|
+
};
|
|
10375
|
+
const gutterMap = {
|
|
10376
|
+
column: 0,
|
|
10377
|
+
// Gutter.Column
|
|
10378
|
+
row: 1,
|
|
10379
|
+
// Gutter.Row
|
|
10380
|
+
all: 2
|
|
10381
|
+
// Gutter.All
|
|
10382
|
+
};
|
|
10342
10383
|
const alignMap = {
|
|
10343
|
-
"auto":
|
|
10344
|
-
|
|
10345
|
-
"
|
|
10346
|
-
|
|
10347
|
-
"
|
|
10348
|
-
|
|
10349
|
-
"
|
|
10350
|
-
|
|
10351
|
-
"
|
|
10384
|
+
"auto": 0,
|
|
10385
|
+
// Align.Auto
|
|
10386
|
+
"flex-start": 1,
|
|
10387
|
+
// Align.FlexStart
|
|
10388
|
+
"center": 2,
|
|
10389
|
+
// Align.Center
|
|
10390
|
+
"flex-end": 3,
|
|
10391
|
+
// Align.FlexEnd
|
|
10392
|
+
"stretch": 4,
|
|
10393
|
+
// Align.Stretch
|
|
10394
|
+
"baseline": 5,
|
|
10395
|
+
// Align.Baseline
|
|
10396
|
+
"space-between": 6,
|
|
10397
|
+
// Align.SpaceBetween
|
|
10398
|
+
"space-around": 7,
|
|
10399
|
+
// Align.SpaceAround
|
|
10400
|
+
"space-evenly": 8
|
|
10401
|
+
// Align.SpaceEvenly
|
|
10352
10402
|
};
|
|
10353
10403
|
const displayMap = {
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10404
|
+
flex: 0,
|
|
10405
|
+
// Display.Flex
|
|
10406
|
+
none: 1,
|
|
10407
|
+
// Display.None
|
|
10408
|
+
contents: 2
|
|
10409
|
+
// Display.Contents
|
|
10357
10410
|
};
|
|
10358
10411
|
const directionMap = {
|
|
10359
|
-
inherit:
|
|
10360
|
-
|
|
10361
|
-
|
|
10412
|
+
inherit: 0,
|
|
10413
|
+
// Direction.Inherit
|
|
10414
|
+
ltr: 1,
|
|
10415
|
+
// Direction.LTR
|
|
10416
|
+
rtl: 2
|
|
10417
|
+
// Direction.RTL
|
|
10362
10418
|
};
|
|
10363
10419
|
const flexDirectionMap = {
|
|
10364
|
-
"column":
|
|
10365
|
-
|
|
10366
|
-
"
|
|
10367
|
-
|
|
10420
|
+
"column": 0,
|
|
10421
|
+
// FlexDirection.Column
|
|
10422
|
+
"column-reverse": 1,
|
|
10423
|
+
// FlexDirection.ColumnReverse
|
|
10424
|
+
"row": 2,
|
|
10425
|
+
// FlexDirection.Row
|
|
10426
|
+
"row-reverse": 3
|
|
10427
|
+
// FlexDirection.RowReverse
|
|
10368
10428
|
};
|
|
10369
10429
|
const flexWrapMap = {
|
|
10370
|
-
"no-wrap":
|
|
10371
|
-
|
|
10372
|
-
"
|
|
10430
|
+
"no-wrap": 0,
|
|
10431
|
+
// Wrap.NoWrap
|
|
10432
|
+
"wrap": 1,
|
|
10433
|
+
// Wrap.Wrap
|
|
10434
|
+
"Wrap-reverse": 2
|
|
10435
|
+
// Wrap.WrapReverse
|
|
10373
10436
|
};
|
|
10374
10437
|
const justifyMap = {
|
|
10375
|
-
"flex-start":
|
|
10376
|
-
|
|
10377
|
-
"
|
|
10378
|
-
|
|
10379
|
-
"
|
|
10380
|
-
|
|
10438
|
+
"flex-start": 0,
|
|
10439
|
+
// Justify.FlexStart
|
|
10440
|
+
"center": 1,
|
|
10441
|
+
// Justify.Center
|
|
10442
|
+
"flex-end": 2,
|
|
10443
|
+
// Justify.FlexEnd
|
|
10444
|
+
"space-between": 3,
|
|
10445
|
+
// Justify.SpaceBetween
|
|
10446
|
+
"space-around": 4,
|
|
10447
|
+
// Justify.SpaceAround
|
|
10448
|
+
"space-evenly": 5
|
|
10449
|
+
// Justify.SpaceEvenly
|
|
10381
10450
|
};
|
|
10382
10451
|
const overflowMap = {
|
|
10383
|
-
visible:
|
|
10384
|
-
|
|
10385
|
-
|
|
10452
|
+
visible: 0,
|
|
10453
|
+
// Overflow.Visible
|
|
10454
|
+
hidden: 1,
|
|
10455
|
+
// Overflow.Hidden
|
|
10456
|
+
scroll: 2
|
|
10457
|
+
// Overflow.Scroll
|
|
10386
10458
|
};
|
|
10387
10459
|
const positionTypeMap = {
|
|
10388
|
-
static:
|
|
10389
|
-
|
|
10390
|
-
|
|
10460
|
+
static: 0,
|
|
10461
|
+
// PositionType.Static
|
|
10462
|
+
relative: 1,
|
|
10463
|
+
// PositionType.Relative
|
|
10464
|
+
absolute: 2
|
|
10465
|
+
// PositionType.Absolute
|
|
10391
10466
|
};
|
|
10392
10467
|
const boxSizingMap = {
|
|
10393
|
-
"border-box":
|
|
10394
|
-
|
|
10468
|
+
"border-box": 0,
|
|
10469
|
+
// BoxSizing.BorderBox
|
|
10470
|
+
"content-box": 1
|
|
10471
|
+
// BoxSizing.ContentBox
|
|
10395
10472
|
};
|
|
10396
10473
|
class FlexLayout {
|
|
10397
10474
|
constructor(_element) {
|
|
@@ -10399,6 +10476,7 @@ class FlexLayout {
|
|
|
10399
10476
|
}
|
|
10400
10477
|
static _yoga;
|
|
10401
10478
|
static async load() {
|
|
10479
|
+
const { loadYoga } = await import('yoga-layout/load');
|
|
10402
10480
|
this._yoga = await loadYoga();
|
|
10403
10481
|
}
|
|
10404
10482
|
_node = FlexLayout._yoga.Node.create();
|
|
@@ -10445,19 +10523,19 @@ class FlexLayout {
|
|
|
10445
10523
|
this._node.setAspectRatio(value);
|
|
10446
10524
|
break;
|
|
10447
10525
|
case "borderTop":
|
|
10448
|
-
this._node.setBorder(
|
|
10526
|
+
this._node.setBorder(edgeMap.top, this._style.borderWidth);
|
|
10449
10527
|
break;
|
|
10450
10528
|
case "borderBottom":
|
|
10451
|
-
this._node.setBorder(
|
|
10529
|
+
this._node.setBorder(edgeMap.bottom, this._style.borderWidth);
|
|
10452
10530
|
break;
|
|
10453
10531
|
case "borderLeft":
|
|
10454
|
-
this._node.setBorder(
|
|
10532
|
+
this._node.setBorder(edgeMap.left, this._style.borderWidth);
|
|
10455
10533
|
break;
|
|
10456
10534
|
case "borderRight":
|
|
10457
|
-
this._node.setBorder(
|
|
10535
|
+
this._node.setBorder(edgeMap.right, this._style.borderWidth);
|
|
10458
10536
|
break;
|
|
10459
10537
|
case "border":
|
|
10460
|
-
this._node.setBorder(
|
|
10538
|
+
this._node.setBorder(edgeMap.all, this._style.borderWidth);
|
|
10461
10539
|
break;
|
|
10462
10540
|
case "direction":
|
|
10463
10541
|
this._node.setDirection(
|
|
@@ -10500,22 +10578,22 @@ class FlexLayout {
|
|
|
10500
10578
|
);
|
|
10501
10579
|
break;
|
|
10502
10580
|
case "gap":
|
|
10503
|
-
value !== void 0 && this._node.setGap(
|
|
10581
|
+
value !== void 0 && this._node.setGap(gutterMap.all, value);
|
|
10504
10582
|
break;
|
|
10505
10583
|
case "marginTop":
|
|
10506
|
-
this._node.setMargin(
|
|
10584
|
+
this._node.setMargin(edgeMap.top, value);
|
|
10507
10585
|
break;
|
|
10508
10586
|
case "marginBottom":
|
|
10509
|
-
this._node.setMargin(
|
|
10587
|
+
this._node.setMargin(edgeMap.bottom, value);
|
|
10510
10588
|
break;
|
|
10511
10589
|
case "marginLeft":
|
|
10512
|
-
this._node.setMargin(
|
|
10590
|
+
this._node.setMargin(edgeMap.left, value);
|
|
10513
10591
|
break;
|
|
10514
10592
|
case "marginRight":
|
|
10515
|
-
this._node.setMargin(
|
|
10593
|
+
this._node.setMargin(edgeMap.right, value);
|
|
10516
10594
|
break;
|
|
10517
10595
|
case "margin":
|
|
10518
|
-
this._node.setMargin(
|
|
10596
|
+
this._node.setMargin(edgeMap.all, value);
|
|
10519
10597
|
break;
|
|
10520
10598
|
case "maxHeight":
|
|
10521
10599
|
this._node.setMaxHeight(value);
|
|
@@ -10537,31 +10615,31 @@ class FlexLayout {
|
|
|
10537
10615
|
);
|
|
10538
10616
|
break;
|
|
10539
10617
|
case "paddingTop":
|
|
10540
|
-
this._node.setPadding(
|
|
10618
|
+
this._node.setPadding(edgeMap.top, this._style.paddingTop);
|
|
10541
10619
|
break;
|
|
10542
10620
|
case "paddingBottom":
|
|
10543
|
-
this._node.setPadding(
|
|
10621
|
+
this._node.setPadding(edgeMap.bottom, this._style.paddingBottom);
|
|
10544
10622
|
break;
|
|
10545
10623
|
case "paddingLeft":
|
|
10546
|
-
this._node.setPadding(
|
|
10624
|
+
this._node.setPadding(edgeMap.left, this._style.paddingLeft);
|
|
10547
10625
|
break;
|
|
10548
10626
|
case "paddingRight":
|
|
10549
|
-
this._node.setPadding(
|
|
10627
|
+
this._node.setPadding(edgeMap.right, this._style.paddingRight);
|
|
10550
10628
|
break;
|
|
10551
10629
|
case "padding":
|
|
10552
|
-
this._node.setPadding(
|
|
10630
|
+
this._node.setPadding(edgeMap.all, this._style.padding);
|
|
10553
10631
|
break;
|
|
10554
10632
|
case "top":
|
|
10555
|
-
this._node.setPosition(
|
|
10633
|
+
this._node.setPosition(edgeMap.top, this._style.top);
|
|
10556
10634
|
break;
|
|
10557
10635
|
case "bottom":
|
|
10558
|
-
this._node.setPosition(
|
|
10636
|
+
this._node.setPosition(edgeMap.bottom, this._style.bottom);
|
|
10559
10637
|
break;
|
|
10560
10638
|
case "left":
|
|
10561
|
-
this._node.setPosition(
|
|
10639
|
+
this._node.setPosition(edgeMap.left, this._style.left);
|
|
10562
10640
|
break;
|
|
10563
10641
|
case "right":
|
|
10564
|
-
this._node.setPosition(
|
|
10642
|
+
this._node.setPosition(edgeMap.right, this._style.right);
|
|
10565
10643
|
break;
|
|
10566
10644
|
case "position":
|
|
10567
10645
|
this._node.setPositionType(
|
|
@@ -10642,7 +10720,7 @@ let FlexElement2D = class extends BaseElement2D {
|
|
|
10642
10720
|
}
|
|
10643
10721
|
}
|
|
10644
10722
|
updateTransform() {
|
|
10645
|
-
this.calculateLayout(void 0, void 0,
|
|
10723
|
+
this.calculateLayout(void 0, void 0, directionMap.ltr);
|
|
10646
10724
|
const { left, top, width, height } = this._layout.getComputedLayout();
|
|
10647
10725
|
this.position.x = left;
|
|
10648
10726
|
this.position.y = top;
|
|
@@ -13425,7 +13503,7 @@ TwistTransition = __decorateClass$1([
|
|
|
13425
13503
|
customNode("TwistTransition")
|
|
13426
13504
|
], TwistTransition);
|
|
13427
13505
|
|
|
13428
|
-
class
|
|
13506
|
+
class GifLoader extends Loader {
|
|
13429
13507
|
install(assets) {
|
|
13430
13508
|
const handler = async (url) => {
|
|
13431
13509
|
const { decodeFrames } = await import('modern-gif');
|
|
@@ -13451,7 +13529,7 @@ class GIFLoader extends Loader {
|
|
|
13451
13529
|
}
|
|
13452
13530
|
}
|
|
13453
13531
|
|
|
13454
|
-
class
|
|
13532
|
+
class JsonLoader extends Loader {
|
|
13455
13533
|
install(assets) {
|
|
13456
13534
|
const handler = (url) => {
|
|
13457
13535
|
return assets.fetch(url).then((rep) => rep.json());
|
|
@@ -13783,7 +13861,7 @@ class Assets {
|
|
|
13783
13861
|
this._handled.clear();
|
|
13784
13862
|
}
|
|
13785
13863
|
}
|
|
13786
|
-
const assets = new Assets().use(new FontLoader()).use(new
|
|
13864
|
+
const assets = new Assets().use(new FontLoader()).use(new GifLoader()).use(new JsonLoader()).use(new LottieLoader()).use(new TextLoader()).use(new TextureLoader()).use(new VideoLoader());
|
|
13787
13865
|
|
|
13788
13866
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13789
13867
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -14228,4 +14306,4 @@ async function render(options) {
|
|
|
14228
14306
|
});
|
|
14229
14307
|
}
|
|
14230
14308
|
|
|
14231
|
-
export { AnimatedTexture, Animation, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BaseElement2D, BaseElement2DBackground, BaseElement2DFill, BaseElement2DForeground, BaseElement2DOutline, BaseElement2DShadow, BaseElement2DShape, BaseElement2DStyle, BaseElement2DText, Camera2D, CanvasContext, CanvasItem, CanvasItemEditor, CanvasTexture, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, Control, CoreObject, DEG_TO_RAD, DEVICE_PIXEL_RATIO, DropShadowEffect, Effect, EffectMaterial, Element2D, Element2DStyle, EmbossEffect, Engine, FlexElement2D, FlexElement2DStyle, FlexLayout, FontLoader,
|
|
14309
|
+
export { AnimatedTexture, Animation, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BaseElement2D, BaseElement2DBackground, BaseElement2DFill, BaseElement2DForeground, BaseElement2DOutline, BaseElement2DShadow, BaseElement2DShape, BaseElement2DStyle, BaseElement2DText, Camera2D, CanvasContext, CanvasItem, CanvasItemEditor, CanvasTexture, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, Control, CoreObject, DEG_TO_RAD, DEVICE_PIXEL_RATIO, DropShadowEffect, Effect, EffectMaterial, Element2D, Element2DStyle, EmbossEffect, Engine, FlexElement2D, FlexElement2DStyle, FlexLayout, FontLoader, GaussianBlurEffect, Geometry, GifLoader, GlitchEffect, GodrayEffect, GradientTexture, HTMLAudio, HTMLAudioContext, HTMLSound, IN_BROWSER, Image2D, ImageTexture, IndexBuffer, Input, InputEvent, JsonLoader, KawaseBlurEffect, KawaseTransition, KeyboardInputEvent, LeftEraseTransition, Loader, Lottie2D, LottieLoader, MainLoop, MaskEffect, Material, Matrix, Matrix2, Matrix3, Matrix4, MouseInputEvent, Node, Node2D, OutlineEffect, PI, PI_2, PixelateEffect, PixelsTexture, PointerInputEvent, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, Range, RawWeakMap, Rect2, RefCounted, Renderer, Resource, Ruler, SUPPORTS_AUDIO_CONTEXT, SUPPORTS_CLICK_EVENTS, SUPPORTS_CREATE_IMAGE_BITMAP, SUPPORTS_IMAGE_BITMAP, SUPPORTS_MOUSE_EVENTS, SUPPORTS_OFFLINE_AUDIO_CONTEXT, SUPPORTS_POINTER_EVENTS, SUPPORTS_RESIZE_OBSERVER, SUPPORTS_TOUCH_EVENTS, SUPPORTS_WEBGL2, SUPPORTS_WEBKIT_AUDIO_CONTEXT, SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT, SUPPORTS_WEB_AUDIO, SUPPORTS_WHEEL_EVENTS, Scaler, SceneTree, ScrollBar, TextLoader, Texture2D, TextureLoader, TextureRect2D, Ticker, TiltShiftTransition, Timeline, TimelineNode, Transform2D, TransformRect2D, Transition, TwistTransition, UvGeometry, UvMaterial, Vector, Vector2, Vector3, Vector4, VertexAttribute, VertexBuffer, Video2D, VideoLoader, VideoTexture, Viewport, ViewportTexture, WebAudio, WebAudioContext, WebGLBatch2DModule, WebGLBlendMode, WebGLBufferModule, WebGLFramebufferModule, WebGLMaskModule, WebGLModule, WebGLProgramModule, WebGLRenderer, WebGLScissorModule, WebGLState, WebGLStateModule, WebGLStencilModule, WebGLTextureModule, WebGLVertexArrayModule, WebGLViewportModule, WebSound, WheelInputEvent, Window, XScrollBar, YScrollBar, ZoomBlurEffect, alignMap, assets, boxSizingMap, clamp, clampFrag, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curves, customNode, customNodes, defaultOptions, determineCrossOrigin, directionMap, displayMap, ease, easeIn, easeInOut, easeOut, edgeMap, flexDirectionMap, flexWrapMap, frag$1 as frag, getDefaultCssPropertyValue, gutterMap, isCanvasElement, isElementNode, isImageElement, isPow2, isVideoElement, isWebgl2, justifyMap, lerp, linear, log2, mapWebGLBlendModes, nextPow2, nextTick, overflowMap, parseCSSFilter, parseCSSTransform, parseCSSTransformOrigin, parseCssFunctions, parseCssProperty, positionTypeMap, render, timingFunctions, uid };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-canvas",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"packageManager": "pnpm@9.15.1",
|
|
6
6
|
"description": "A JavaScript WebGL rendering engine.",
|
|
7
7
|
"author": "wxm",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"lottie-web": "^5",
|
|
59
|
-
"modern-gif": "^2"
|
|
59
|
+
"modern-gif": "^2",
|
|
60
|
+
"yoga-layout": "^3"
|
|
60
61
|
},
|
|
61
62
|
"peerDependenciesMeta": {
|
|
62
63
|
"lottie-web": {
|
|
@@ -64,32 +65,35 @@
|
|
|
64
65
|
},
|
|
65
66
|
"modern-gif": {
|
|
66
67
|
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"yoga-layout": {
|
|
70
|
+
"optional": true
|
|
67
71
|
}
|
|
68
72
|
},
|
|
69
73
|
"dependencies": {
|
|
70
74
|
"colord": "^2.9.3",
|
|
71
75
|
"earcut": "^3.0.2",
|
|
72
76
|
"modern-font": "^0.4.1",
|
|
73
|
-
"modern-idoc": "^0.8.
|
|
77
|
+
"modern-idoc": "^0.8.9",
|
|
74
78
|
"modern-path2d": "^1.4.8",
|
|
75
|
-
"modern-text": "^1.7.4"
|
|
76
|
-
"yoga-layout": "^3.2.1"
|
|
79
|
+
"modern-text": "^1.7.4"
|
|
77
80
|
},
|
|
78
81
|
"devDependencies": {
|
|
79
|
-
"@antfu/eslint-config": "^5.
|
|
82
|
+
"@antfu/eslint-config": "^5.2.1",
|
|
80
83
|
"@types/earcut": "^3.0.0",
|
|
81
|
-
"@types/node": "^24.
|
|
82
|
-
"bumpp": "^10.2.
|
|
84
|
+
"@types/node": "^24.3.0",
|
|
85
|
+
"bumpp": "^10.2.3",
|
|
83
86
|
"conventional-changelog-cli": "^5.0.0",
|
|
84
|
-
"eslint": "^9.
|
|
85
|
-
"lint-staged": "^16.1.
|
|
87
|
+
"eslint": "^9.33.0",
|
|
88
|
+
"lint-staged": "^16.1.5",
|
|
86
89
|
"lottie-web": "^5.13.0",
|
|
87
90
|
"modern-gif": "^2.0.4",
|
|
88
|
-
"simple-git-hooks": "^2.13.
|
|
89
|
-
"typescript": "^5.
|
|
90
|
-
"unbuild": "^3.6.
|
|
91
|
-
"vite": "^7.
|
|
92
|
-
"vitest": "^3.2.4"
|
|
91
|
+
"simple-git-hooks": "^2.13.1",
|
|
92
|
+
"typescript": "^5.9.2",
|
|
93
|
+
"unbuild": "^3.6.1",
|
|
94
|
+
"vite": "^7.1.3",
|
|
95
|
+
"vitest": "^3.2.4",
|
|
96
|
+
"yoga-layout": "^3.2.1"
|
|
93
97
|
},
|
|
94
98
|
"simple-git-hooks": {
|
|
95
99
|
"pre-commit": "pnpm lint-staged"
|