@meta2d/core 1.1.17 → 1.1.18

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/src/core.d.ts CHANGED
@@ -359,6 +359,8 @@ export declare class Meta2d {
359
359
  */
360
360
  fitView(fit?: boolean, viewPadding?: Padding, fill?: boolean): void;
361
361
  fillView(): void;
362
+ scaleView(): void;
363
+ setFits(): void;
362
364
  trimPens(): void;
363
365
  /**
364
366
  * 放大到屏幕尺寸,并居中
package/src/core.js CHANGED
@@ -946,7 +946,7 @@ export class Meta2d {
946
946
  url.startsWith('data:image'))) {
947
947
  img.src = that.store.options.cdn + url;
948
948
  }
949
- img.crossOrigin = 'anonymous';
949
+ img.crossOrigin = that.store.options.crossOrigin || 'anonymous';
950
950
  img.onload = () => {
951
951
  resolve(img);
952
952
  };
@@ -4772,6 +4772,46 @@ export class Meta2d {
4772
4772
  this.canvas.canvasImageBottom.init();
4773
4773
  this.render(true);
4774
4774
  }
4775
+ scaleView() {
4776
+ const viewRadio = window.innerWidth / window.innerHeight;
4777
+ const rect = this.getRect();
4778
+ const radio = rect.width / rect.height;
4779
+ if (Math.abs(viewRadio - radio) < 0.001) {
4780
+ return;
4781
+ }
4782
+ let translate;
4783
+ if (viewRadio > radio) {
4784
+ translate = `scale(${viewRadio / radio},1)`;
4785
+ }
4786
+ else {
4787
+ translate = `scale(1,${radio / viewRadio})`;
4788
+ }
4789
+ this.canvas.parentElement.style.transform = translate;
4790
+ }
4791
+ setFits() {
4792
+ if (!this.store.data.fits) {
4793
+ const children = this.store.data.pens
4794
+ .filter((pen) => !pen.parentId)
4795
+ .map((pen) => pen.id);
4796
+ this.store.data.fits = [
4797
+ {
4798
+ bottom: true,
4799
+ bottomValue: 0,
4800
+ left: true,
4801
+ leftValue: 0,
4802
+ right: true,
4803
+ rightValue: 0,
4804
+ top: true,
4805
+ topValue: 0,
4806
+ x: 0,
4807
+ y: 0,
4808
+ height: 1,
4809
+ width: 1,
4810
+ children,
4811
+ },
4812
+ ];
4813
+ }
4814
+ }
4775
4815
  trimPens() {
4776
4816
  //去除空连线
4777
4817
  let pens = this.store.data.pens.filter((pen) => pen.name === 'line' && pen.anchors.length < 2);