@meta2d/core 1.1.15 → 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
  };
@@ -4505,7 +4505,16 @@ export class Meta2d {
4505
4505
  if (this.store.options.unFill) {
4506
4506
  return; //不自适应
4507
4507
  }
4508
- const rect = this.getRect();
4508
+ let rect = {
4509
+ x: this.store.data.origin.x,
4510
+ y: this.store.data.origin.y,
4511
+ width: this.store.data.width * this.store.data.scale,
4512
+ height: this.store.data.height * this.store.data.scale,
4513
+ };
4514
+ if (isNaN(rect.width) || isNaN(rect.height)) {
4515
+ rect = this.getRect();
4516
+ }
4517
+ // const rect = this.getRect();
4509
4518
  const wGap = this.canvas.width - rect.width;
4510
4519
  const hGap = this.canvas.height - rect.height;
4511
4520
  //宽度拉伸
@@ -4763,6 +4772,46 @@ export class Meta2d {
4763
4772
  this.canvas.canvasImageBottom.init();
4764
4773
  this.render(true);
4765
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
+ }
4766
4815
  trimPens() {
4767
4816
  //去除空连线
4768
4817
  let pens = this.store.data.pens.filter((pen) => pen.name === 'line' && pen.anchors.length < 2);