modern-canvas 0.1.1 → 0.1.2

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.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { extend, colord } from 'colord';
2
2
  import namesPlugin from 'colord/plugins/names';
3
3
  import earcut from 'earcut';
4
- import { textDefaultStyle, measureText, renderText } from 'modern-text';
4
+ import { getDefaultTextStyle, getDefaultTransformStyle } from 'modern-idoc';
5
+ import { textDefaultStyle, Text } from 'modern-text';
5
6
 
6
7
  const PI = Math.PI;
7
8
  const PI_2 = PI * 2;
@@ -6256,61 +6257,22 @@ function getComputedFilterColorMatrix() {
6256
6257
  return m;
6257
6258
  }
6258
6259
 
6259
- class Style2DOffsetModule extends Style2DModule {
6260
- install(Style2D) {
6261
- defineProperty(Style2D, "offsetPath");
6262
- defineProperty(Style2D, "offsetAnchor");
6263
- defineProperty(Style2D, "offsetDistance");
6264
- defineProperty(Style2D, "offsetPosition");
6265
- Style2D.prototype.getComputedOffset = getComputedOffset;
6266
- }
6267
- }
6268
- function getComputedOffset() {
6269
- const offsetPath = this.offsetPath;
6270
- if (!offsetPath)
6271
- return;
6272
- if (offsetPath.startsWith("path")) {
6273
- const path = offsetPath.match(/path\(["'](.+)["']\)/)?.[1];
6274
- if (!path)
6275
- return;
6276
- path.split(" ").forEach((arg) => {
6277
- });
6278
- } else if (offsetPath.startsWith("ray")) ; else if (offsetPath.startsWith("url")) ; else if (offsetPath.startsWith("circle")) ; else if (offsetPath.startsWith("ellipse")) ; else if (offsetPath.startsWith("insett")) ; else if (offsetPath.startsWith("polygon")) ; else if (offsetPath.startsWith("rect")) ; else if (offsetPath.startsWith("xywh")) ;
6279
- }
6280
-
6281
6260
  class Style2DTextModule extends Style2DModule {
6282
6261
  install(Style2D) {
6283
- defineProperty(Style2D, "color", { default: "#000000" });
6284
- defineProperty(Style2D, "fontSize", { default: 14 });
6285
- defineProperty(Style2D, "fontWeight", { default: "normal" });
6286
- defineProperty(Style2D, "fontFamily", { default: "sans-serif" });
6287
- defineProperty(Style2D, "fontStyle", { default: "normal" });
6288
- defineProperty(Style2D, "fontKerning", { default: "normal" });
6289
- defineProperty(Style2D, "textWrap", { default: "wrap" });
6290
- defineProperty(Style2D, "textAlign", { default: "start" });
6291
- defineProperty(Style2D, "verticalAlign", { default: "middle" });
6292
- defineProperty(Style2D, "textTransform", { default: "none" });
6293
- defineProperty(Style2D, "textDecoration", { default: null });
6294
- defineProperty(Style2D, "textStrokeWidth", { default: 0 });
6295
- defineProperty(Style2D, "textStrokeColor", { default: "#000000" });
6262
+ const style = getDefaultTextStyle();
6263
+ for (const key in style) {
6264
+ defineProperty(Style2D, key, { default: style[key] });
6265
+ }
6296
6266
  defineProperty(Style2D, "direction", { default: "inherit" });
6297
- defineProperty(Style2D, "lineHeight", { default: 1 });
6298
- defineProperty(Style2D, "letterSpacing", { default: 0 });
6299
- defineProperty(Style2D, "writingMode", { default: "horizontal-tb" });
6300
6267
  }
6301
6268
  }
6302
6269
 
6303
6270
  class Style2DTransformModule extends Style2DModule {
6304
6271
  install(Style2D) {
6305
- defineProperty(Style2D, "left", { default: 0 });
6306
- defineProperty(Style2D, "top", { default: 0 });
6307
- defineProperty(Style2D, "width", { default: 0 });
6308
- defineProperty(Style2D, "height", { default: 0 });
6309
- defineProperty(Style2D, "rotate", { default: 0 });
6310
- defineProperty(Style2D, "scaleX", { default: 1 });
6311
- defineProperty(Style2D, "scaleY", { default: 1 });
6312
- defineProperty(Style2D, "transform");
6313
- defineProperty(Style2D, "transformOrigin", { default: "center" });
6272
+ const style = getDefaultTransformStyle();
6273
+ for (const key in style) {
6274
+ defineProperty(Style2D, key, { default: style[key] });
6275
+ }
6314
6276
  Style2D.prototype.getComputedTransform = getComputedTransform;
6315
6277
  Style2D.prototype.getComputedTransformOrigin = getComputedTransformOrigin;
6316
6278
  }
@@ -6319,7 +6281,11 @@ function getComputedTransform() {
6319
6281
  const transform = new Transform2D();
6320
6282
  const transform3d = new Transform2D(false);
6321
6283
  const transform2d = new Transform2D(false).scale(this.scaleX, this.scaleY).translate(this.left, this.top).rotate(this.rotate * DEG_TO_RAD);
6322
- parseCssFunctions(this.transform ?? "", { width: this.width, height: this.height }).forEach(({ name, args }) => {
6284
+ let _transform = this.transform;
6285
+ if (!_transform || _transform === "none") {
6286
+ _transform = "";
6287
+ }
6288
+ parseCssFunctions(_transform, { width: this.width, height: this.height }).forEach(({ name, args }) => {
6323
6289
  const values = args.map((arg) => arg.normalizedIntValue);
6324
6290
  transform.identity();
6325
6291
  switch (name) {
@@ -6430,15 +6396,6 @@ function getComputedTransformOrigin() {
6430
6396
  });
6431
6397
  }
6432
6398
 
6433
- const modules = {
6434
- __proto__: null,
6435
- Style2DBackgroundModule: Style2DBackgroundModule,
6436
- Style2DFilterModule: Style2DFilterModule,
6437
- Style2DOffsetModule: Style2DOffsetModule,
6438
- Style2DTextModule: Style2DTextModule,
6439
- Style2DTransformModule: Style2DTransformModule
6440
- };
6441
-
6442
6399
  var __defProp$r = Object.defineProperty;
6443
6400
  var __decorateClass$r = (decorators, target, key, kind) => {
6444
6401
  var result = void 0 ;
@@ -6492,7 +6449,12 @@ __decorateClass$r([
6492
6449
  __decorateClass$r([
6493
6450
  property({ default: "visible" })
6494
6451
  ], Style2D.prototype, "overflow");
6495
- Object.values(modules).forEach((Module) => {
6452
+ [
6453
+ Style2DBackgroundModule,
6454
+ Style2DFilterModule,
6455
+ Style2DTextModule,
6456
+ Style2DTransformModule
6457
+ ].forEach((Module) => {
6496
6458
  new Module().install(Style2D);
6497
6459
  });
6498
6460
 
@@ -7551,6 +7513,9 @@ var __decorateClass$k = (decorators, target, key, kind) => {
7551
7513
  const textStyles = new Set(Object.keys(textDefaultStyle));
7552
7514
  let Text2D = class extends Node2D {
7553
7515
  effects;
7516
+ measureDom;
7517
+ fonts;
7518
+ text = new Text();
7554
7519
  texture = new Texture(document.createElement("canvas"));
7555
7520
  _subTextsCount = 0;
7556
7521
  constructor(options) {
@@ -7561,6 +7526,8 @@ let Text2D = class extends Node2D {
7561
7526
  super._onUpdateProperty(key, value, oldValue);
7562
7527
  switch (key) {
7563
7528
  case "content":
7529
+ case "effects":
7530
+ case "fonts":
7564
7531
  case "split":
7565
7532
  this._updateSplit();
7566
7533
  this.requestRedraw();
@@ -7572,6 +7539,13 @@ let Text2D = class extends Node2D {
7572
7539
  });
7573
7540
  }
7574
7541
  }
7542
+ _updateText() {
7543
+ this.text.style = this.style.toJSON();
7544
+ this.text.content = this.content ?? "";
7545
+ this.text.effects = this.effects;
7546
+ this.text.fonts = this.fonts;
7547
+ this.text.measureDom = this.measureDom;
7548
+ }
7575
7549
  _onUpdateStyleProperty(key, value, oldValue) {
7576
7550
  if (key === "height")
7577
7551
  return;
@@ -7615,13 +7589,8 @@ let Text2D = class extends Node2D {
7615
7589
  }
7616
7590
  }
7617
7591
  measure() {
7618
- const result = measureText({
7619
- content: this.content,
7620
- style: {
7621
- ...this.style.toJSON(),
7622
- height: void 0
7623
- }
7624
- });
7592
+ this._updateText();
7593
+ const result = this.text.measure();
7625
7594
  if (!this.style.width)
7626
7595
  this.style.width = result.boundingBox.width;
7627
7596
  if (!this.style.height)
@@ -7665,12 +7634,10 @@ let Text2D = class extends Node2D {
7665
7634
  if (onText2DRender) {
7666
7635
  onText2DRender();
7667
7636
  } else {
7668
- renderText({
7669
- view: this.texture.source,
7637
+ this._updateText();
7638
+ this.text.render({
7670
7639
  pixelRatio: this.pixelRatio,
7671
- content: this.content,
7672
- effects: this.effects,
7673
- style: this.style.toJSON()
7640
+ view: this.texture.source
7674
7641
  });
7675
7642
  }
7676
7643
  this.texture.requestUpload();
@@ -7695,6 +7662,12 @@ __decorateClass$k([
7695
7662
  __decorateClass$k([
7696
7663
  property()
7697
7664
  ], Text2D.prototype, "effects", 2);
7665
+ __decorateClass$k([
7666
+ protectedProperty()
7667
+ ], Text2D.prototype, "measureDom", 2);
7668
+ __decorateClass$k([
7669
+ protectedProperty()
7670
+ ], Text2D.prototype, "fonts", 2);
7698
7671
  Text2D = __decorateClass$k([
7699
7672
  customNode("Text2D")
7700
7673
  ], Text2D);
@@ -13718,7 +13691,8 @@ class Engine extends SceneTree {
13718
13691
  } else {
13719
13692
  this.resize(
13720
13693
  width || this.gl.drawingBufferWidth || this.view?.clientWidth || 200,
13721
- height || this.gl.drawingBufferHeight || this.view?.clientHeight || 200
13694
+ height || this.gl.drawingBufferHeight || this.view?.clientHeight || 200,
13695
+ !view
13722
13696
  );
13723
13697
  }
13724
13698
  }
@@ -13853,4 +13827,4 @@ async function render(options) {
13853
13827
  });
13854
13828
  }
13855
13829
 
13856
- export { Animation2D, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BlurEffect, Bounds, CanvasContext, CanvasItem, Circle, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, DEG_TO_RAD, DEVICE_PIXEL_RATIO, Effect, EffectMaterial, Ellipse, 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, Path2D, PixelateEffect, PixelsTexture, Point, PointerInputEvent, Polygon, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, Rectangle, Reference, RenderStack, Renderer, Resource, RoundedRectangle, 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, SVGPath, SceneTree, Star, Style2D, Style2DBackgroundModule, Style2DFilterModule, Style2DModule, Style2DOffsetModule, Style2DTextModule, Style2DTransformModule, Text2D, TextLoader, Texture, TextureLoader, Ticker, TiltShiftEffect, Timer, Transform2D, Triangle, 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, buildAdaptiveBezier, buildAdaptiveQuadratic, buildArc, buildArcTo, buildArcToSvg, buildCircle, buildLine, buildPolygon, buildRectangle, buildTriangle, clamp, closePointEps, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curveEps, 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, squaredDistanceToLineSegment, timingFunctions, uid };
13830
+ export { Animation2D, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BlurEffect, Bounds, CanvasContext, CanvasItem, Circle, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, DEG_TO_RAD, DEVICE_PIXEL_RATIO, Effect, EffectMaterial, Ellipse, 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, Path2D, PixelateEffect, PixelsTexture, Point, PointerInputEvent, Polygon, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, Rectangle, Reference, RenderStack, Renderer, Resource, RoundedRectangle, 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, SVGPath, SceneTree, Star, Style2D, Style2DBackgroundModule, Style2DFilterModule, Style2DModule, Style2DTextModule, Style2DTransformModule, Text2D, TextLoader, Texture, TextureLoader, Ticker, TiltShiftEffect, Timer, Transform2D, Triangle, 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, buildAdaptiveBezier, buildAdaptiveQuadratic, buildArc, buildArcTo, buildArcToSvg, buildCircle, buildLine, buildPolygon, buildRectangle, buildTriangle, clamp, closePointEps, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curveEps, 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, squaredDistanceToLineSegment, 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.1",
4
+ "version": "0.1.2",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",
@@ -70,7 +70,7 @@
70
70
  "colord": "^2.9.3",
71
71
  "earcut": "^3.0.1",
72
72
  "modern-font": "^0.3.5",
73
- "modern-idoc": "^0.1.4",
73
+ "modern-idoc": "^0.1.5",
74
74
  "modern-path2d": "^1.0.1",
75
75
  "modern-text": "^1.0.7"
76
76
  },