modern-canvas 0.1.4 → 0.1.6
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 +79 -29
- package/dist/index.d.cts +36 -12
- package/dist/index.d.mts +36 -12
- package/dist/index.d.ts +36 -12
- package/dist/index.js +35 -35
- package/dist/index.mjs +80 -31
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extend, colord } from 'colord';
|
|
2
2
|
import namesPlugin from 'colord/plugins/names';
|
|
3
|
-
import { Path2D,
|
|
3
|
+
import { Path2D, CurvePath, BoundingBox } from 'modern-path2d';
|
|
4
4
|
import { getDefaultTextStyle, getDefaultTransformStyle } from 'modern-idoc';
|
|
5
5
|
import { textDefaultStyle, Text } from 'modern-text';
|
|
6
6
|
|
|
@@ -246,6 +246,45 @@ class EventEmitter {
|
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
class RawWeakMap {
|
|
250
|
+
_map = /* @__PURE__ */ new WeakMap();
|
|
251
|
+
_toRaw(value) {
|
|
252
|
+
if (value && typeof value === "object") {
|
|
253
|
+
if ("__v_raw" in value) {
|
|
254
|
+
value = value.__v_raw;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Removes the specified element from the WeakMap.
|
|
261
|
+
* @returns true if the element was successfully removed, or false if it was not present.
|
|
262
|
+
*/
|
|
263
|
+
delete(key) {
|
|
264
|
+
return this._map.delete(this._toRaw(key));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* @returns a specified element.
|
|
268
|
+
*/
|
|
269
|
+
get(key) {
|
|
270
|
+
return this._map.get(this._toRaw(key));
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* @returns a boolean indicating whether an element with the specified key exists or not.
|
|
274
|
+
*/
|
|
275
|
+
has(key) {
|
|
276
|
+
return this._map.has(this._toRaw(key));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Adds a new element with a specified key and value.
|
|
280
|
+
* @param key Must be an object or symbol.
|
|
281
|
+
*/
|
|
282
|
+
set(key, value) {
|
|
283
|
+
this._map.set(this._toRaw(key), this._toRaw(value));
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
249
288
|
const customNodes = /* @__PURE__ */ new Map();
|
|
250
289
|
function customNode(options) {
|
|
251
290
|
let tag;
|
|
@@ -272,7 +311,7 @@ function customNode(options) {
|
|
|
272
311
|
};
|
|
273
312
|
}
|
|
274
313
|
|
|
275
|
-
const declarationMap =
|
|
314
|
+
const declarationMap = new RawWeakMap();
|
|
276
315
|
function getDeclarations(constructor) {
|
|
277
316
|
let declarations = declarationMap.get(constructor);
|
|
278
317
|
if (!declarations) {
|
|
@@ -537,7 +576,7 @@ class Geometry extends Resource {
|
|
|
537
576
|
indexBuffer;
|
|
538
577
|
instanceCount;
|
|
539
578
|
mode;
|
|
540
|
-
_materialWeakMap =
|
|
579
|
+
_materialWeakMap = new RawWeakMap();
|
|
541
580
|
constructor(options = {}) {
|
|
542
581
|
super();
|
|
543
582
|
this.vertexAttributes = new Map(Object.entries(options?.vertexAttributes ?? {}));
|
|
@@ -3386,8 +3425,8 @@ class CanvasContext extends Path2D {
|
|
|
3386
3425
|
lineWidth;
|
|
3387
3426
|
miterLimit;
|
|
3388
3427
|
_defaultStyle = Texture.EMPTY;
|
|
3389
|
-
|
|
3390
|
-
|
|
3428
|
+
_stroke = [];
|
|
3429
|
+
_fille = [];
|
|
3391
3430
|
stroke() {
|
|
3392
3431
|
let texture = this._defaultStyle;
|
|
3393
3432
|
if (this.strokeStyle) {
|
|
@@ -3398,8 +3437,8 @@ class CanvasContext extends Path2D {
|
|
|
3398
3437
|
}
|
|
3399
3438
|
}
|
|
3400
3439
|
if (this.curves.length) {
|
|
3401
|
-
this.
|
|
3402
|
-
|
|
3440
|
+
this._stroke.push({
|
|
3441
|
+
path: new Path2D(this),
|
|
3403
3442
|
texture,
|
|
3404
3443
|
textureTransform: this.textureTransform,
|
|
3405
3444
|
style: {
|
|
@@ -3410,6 +3449,7 @@ class CanvasContext extends Path2D {
|
|
|
3410
3449
|
miterLimit: this.miterLimit ?? 10
|
|
3411
3450
|
}
|
|
3412
3451
|
});
|
|
3452
|
+
this.currentCurve = new CurvePath();
|
|
3413
3453
|
this.curves = [this.currentCurve];
|
|
3414
3454
|
}
|
|
3415
3455
|
}
|
|
@@ -3428,14 +3468,29 @@ class CanvasContext extends Path2D {
|
|
|
3428
3468
|
texture = new ColorTexture(this.fillStyle);
|
|
3429
3469
|
}
|
|
3430
3470
|
}
|
|
3431
|
-
this.
|
|
3432
|
-
|
|
3471
|
+
this._fille.push({
|
|
3472
|
+
path: new Path2D(this),
|
|
3433
3473
|
texture,
|
|
3434
3474
|
textureTransform: this.textureTransform
|
|
3435
3475
|
});
|
|
3476
|
+
this.currentCurve = new CurvePath();
|
|
3436
3477
|
this.curves = [this.currentCurve];
|
|
3437
3478
|
}
|
|
3479
|
+
copy(source) {
|
|
3480
|
+
super.copy(source);
|
|
3481
|
+
this.strokeStyle = source.strokeStyle;
|
|
3482
|
+
this.fillStyle = source.fillStyle;
|
|
3483
|
+
this.textureTransform = source.textureTransform;
|
|
3484
|
+
this.lineCap = source.lineCap;
|
|
3485
|
+
this.lineJoin = source.lineJoin;
|
|
3486
|
+
this.lineWidth = source.lineWidth;
|
|
3487
|
+
this.miterLimit = source.miterLimit;
|
|
3488
|
+
this._stroke = source._stroke.slice();
|
|
3489
|
+
this._fille = source._fille.slice();
|
|
3490
|
+
return this;
|
|
3491
|
+
}
|
|
3438
3492
|
reset() {
|
|
3493
|
+
super.reset();
|
|
3439
3494
|
this.strokeStyle = void 0;
|
|
3440
3495
|
this.fillStyle = void 0;
|
|
3441
3496
|
this.textureTransform = void 0;
|
|
@@ -3443,9 +3498,9 @@ class CanvasContext extends Path2D {
|
|
|
3443
3498
|
this.lineJoin = void 0;
|
|
3444
3499
|
this.lineWidth = void 0;
|
|
3445
3500
|
this.miterLimit = void 0;
|
|
3446
|
-
this.
|
|
3447
|
-
this.
|
|
3448
|
-
this
|
|
3501
|
+
this._stroke.length = 0;
|
|
3502
|
+
this._fille.length = 0;
|
|
3503
|
+
return this;
|
|
3449
3504
|
}
|
|
3450
3505
|
buildUvs(start, vertices, uvs, texture, textureTransform) {
|
|
3451
3506
|
if (texture) {
|
|
@@ -3483,15 +3538,11 @@ class CanvasContext extends Path2D {
|
|
|
3483
3538
|
uvs = [];
|
|
3484
3539
|
texture = void 0;
|
|
3485
3540
|
};
|
|
3486
|
-
for (let len = this.
|
|
3541
|
+
for (let len = this._stroke.length, i = 0; i < len; i++) {
|
|
3487
3542
|
startUv = vertices.length;
|
|
3488
|
-
const graphics = this.
|
|
3543
|
+
const graphics = this._stroke[i];
|
|
3489
3544
|
texture ??= graphics.texture;
|
|
3490
|
-
|
|
3491
|
-
for (let len2 = graphics.shapes.length, i2 = 0; i2 < len2; i2++) {
|
|
3492
|
-
graphics.shapes[i2].getAdaptivePointArray(points);
|
|
3493
|
-
}
|
|
3494
|
-
strokeTriangulate(points, {
|
|
3545
|
+
graphics.path.strokeTriangulate({
|
|
3495
3546
|
vertices,
|
|
3496
3547
|
indices,
|
|
3497
3548
|
lineStyle: graphics.style,
|
|
@@ -3501,19 +3552,17 @@ class CanvasContext extends Path2D {
|
|
|
3501
3552
|
this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
|
|
3502
3553
|
push("stroke");
|
|
3503
3554
|
}
|
|
3504
|
-
for (let len = this.
|
|
3505
|
-
const graphics = this.
|
|
3555
|
+
for (let len = this._fille.length, i = 0; i < len; i++) {
|
|
3556
|
+
const graphics = this._fille[i];
|
|
3506
3557
|
texture ??= graphics.texture;
|
|
3507
3558
|
if (texture !== graphics.texture) {
|
|
3508
3559
|
push("fill");
|
|
3509
3560
|
}
|
|
3510
3561
|
startUv = vertices.length;
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
});
|
|
3516
|
-
}
|
|
3562
|
+
graphics.path.fillTriangulate({
|
|
3563
|
+
vertices,
|
|
3564
|
+
indices
|
|
3565
|
+
});
|
|
3517
3566
|
this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
|
|
3518
3567
|
}
|
|
3519
3568
|
if (vertices.length) {
|
|
@@ -4448,7 +4497,7 @@ let Animation2D = class extends Node {
|
|
|
4448
4497
|
easing;
|
|
4449
4498
|
_keyframes = [];
|
|
4450
4499
|
_starting = false;
|
|
4451
|
-
_startProps =
|
|
4500
|
+
_startProps = new RawWeakMap();
|
|
4452
4501
|
constructor(options) {
|
|
4453
4502
|
super();
|
|
4454
4503
|
this._onUpdateTime = this._onUpdateTime.bind(this);
|
|
@@ -9299,7 +9348,7 @@ class Renderer {
|
|
|
9299
9348
|
view;
|
|
9300
9349
|
pixelRatio = DEVICE_PIXEL_RATIO;
|
|
9301
9350
|
screen = { x: 0, y: 0, width: 0, height: 0 };
|
|
9302
|
-
related =
|
|
9351
|
+
related = new RawWeakMap();
|
|
9303
9352
|
getRelated(source, createFn) {
|
|
9304
9353
|
let related = this.related.get(source);
|
|
9305
9354
|
if (related)
|
|
@@ -10371,7 +10420,7 @@ class WebGLProgramModule extends WebGLModule {
|
|
|
10371
10420
|
return {
|
|
10372
10421
|
attributes: /* @__PURE__ */ new Map(),
|
|
10373
10422
|
uniforms: /* @__PURE__ */ new Map(),
|
|
10374
|
-
boundUniforms:
|
|
10423
|
+
boundUniforms: new RawWeakMap()
|
|
10375
10424
|
};
|
|
10376
10425
|
});
|
|
10377
10426
|
}
|
|
@@ -11529,4 +11578,4 @@ async function render(options) {
|
|
|
11529
11578
|
});
|
|
11530
11579
|
}
|
|
11531
11580
|
|
|
11532
|
-
export { Animation2D, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BlurEffect, CanvasContext, CanvasItem, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, DEG_TO_RAD, DEVICE_PIXEL_RATIO, Effect, EffectMaterial, EmbossEffect, Engine, EventEmitter, FontLoader, Geometry, GifLoader, GlitchEffect, GodrayEffect, Graphics2D, HTMLAudio, HTMLAudioContext, HTMLSound, IN_BROWSER, Image2D, Image2DResource, ImageTexture, IndexBuffer, Input, InternalMode, JsonLoader, KawaseEffect, LeftEraseEffect, Loader, Lottie2D, LottieLoader, MainLoop, MaskEffect, Material, Matrix, Matrix2, Matrix3, Matrix4, MouseInputEvent, Node, Node2D, PI, PI_2, PixelateEffect, PixelsTexture, PointerInputEvent, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, Reference, RenderStack, Renderer, Resource, 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, SceneTree, Style2D, Style2DBackgroundModule, Style2DFilterModule, Style2DModule, Style2DTextModule, Style2DTransformModule, Text2D, TextLoader, Texture, TextureLoader, Ticker, TiltShiftEffect, Timer, Transform2D, TwistEffect, UIInputEvent, 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, ZoomBlurEffect, _Object, assets, clamp, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curves, customNode, customNodes, defaultOptions, defineProperty, determineCrossOrigin, ease, easeIn, easeInOut, easeOut, getDeclarations, getDefaultCssPropertyValue, isCanvasElement, isElementNode, isImageElement, isPow2, isVideoElement, isWebgl2, lerp, linear, log2, mapWebGLBlendModes, nextPow2, nextTick, parseCssFunctions, parseCssProperty, property, protectedProperty, render, timingFunctions, uid };
|
|
11581
|
+
export { Animation2D, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BlurEffect, CanvasContext, CanvasItem, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, DEG_TO_RAD, DEVICE_PIXEL_RATIO, Effect, EffectMaterial, EmbossEffect, Engine, EventEmitter, FontLoader, Geometry, GifLoader, GlitchEffect, GodrayEffect, Graphics2D, HTMLAudio, HTMLAudioContext, HTMLSound, IN_BROWSER, Image2D, Image2DResource, ImageTexture, IndexBuffer, Input, InternalMode, JsonLoader, KawaseEffect, LeftEraseEffect, Loader, Lottie2D, LottieLoader, MainLoop, MaskEffect, Material, Matrix, Matrix2, Matrix3, Matrix4, MouseInputEvent, Node, Node2D, PI, PI_2, PixelateEffect, PixelsTexture, PointerInputEvent, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, RawWeakMap, Reference, RenderStack, Renderer, Resource, 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, SceneTree, Style2D, Style2DBackgroundModule, Style2DFilterModule, Style2DModule, Style2DTextModule, Style2DTransformModule, Text2D, TextLoader, Texture, TextureLoader, Ticker, TiltShiftEffect, Timer, Transform2D, TwistEffect, UIInputEvent, 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, ZoomBlurEffect, _Object, assets, clamp, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curves, customNode, customNodes, defaultOptions, defineProperty, determineCrossOrigin, ease, easeIn, easeInOut, easeOut, getDeclarations, getDefaultCssPropertyValue, isCanvasElement, isElementNode, isImageElement, isPow2, isVideoElement, isWebgl2, lerp, linear, log2, mapWebGLBlendModes, nextPow2, nextTick, parseCssFunctions, parseCssProperty, property, protectedProperty, 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.1.
|
|
4
|
+
"version": "0.1.6",
|
|
5
5
|
"packageManager": "pnpm@9.15.1",
|
|
6
6
|
"description": "A JavaScript WebGL rendering engine.",
|
|
7
7
|
"author": "wxm",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"earcut": "^3.0.1",
|
|
72
72
|
"modern-font": "^0.3.5",
|
|
73
73
|
"modern-idoc": "^0.1.5",
|
|
74
|
-
"modern-path2d": "^1.2.
|
|
74
|
+
"modern-path2d": "^1.2.3",
|
|
75
75
|
"modern-text": "^1.2.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|