@mce/bigesj 0.16.7 → 0.17.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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { plugin } from './plugin';
2
2
  export * from './composables';
3
3
  export * from './convert';
4
- export * from './editorOptions';
5
4
  export * from './loaders';
5
+ export * from './options';
6
6
  export * from './plugin';
7
7
  export default plugin;
package/dist/index.js CHANGED
@@ -1093,8 +1093,8 @@ function signedArea(data, start, end, dim) {
1093
1093
  }
1094
1094
  return sum;
1095
1095
  }
1096
- function drawPoint(ctx, x, y, options = {}) {
1097
- const { radius = 1 } = options;
1096
+ function drawPoint(ctx, x, y, options2 = {}) {
1097
+ const { radius = 1 } = options2;
1098
1098
  ctx.moveTo(x, y);
1099
1099
  ctx.arc(x, y, radius, 0, Math.PI * 2);
1100
1100
  }
@@ -2624,7 +2624,7 @@ function cubicBezierP3(t, p) {
2624
2624
  function cubicBezier(t, p0, p1, p2, p3) {
2625
2625
  return cubicBezierP0(t, p0) + cubicBezierP1(t, p1) + cubicBezierP2(t, p2) + cubicBezierP3(t, p3);
2626
2626
  }
2627
- function fillTriangulate(pointArray, options = {}) {
2627
+ function fillTriangulate(pointArray, options2 = {}) {
2628
2628
  let {
2629
2629
  vertices = [],
2630
2630
  indices = [],
@@ -2632,7 +2632,7 @@ function fillTriangulate(pointArray, options = {}) {
2632
2632
  verticesStride = 2,
2633
2633
  verticesOffset = vertices.length / verticesStride,
2634
2634
  indicesOffset = indices.length
2635
- } = options;
2635
+ } = options2;
2636
2636
  const triangles = earcut(pointArray, holes, 2);
2637
2637
  if (triangles.length) {
2638
2638
  for (let i = 0; i < triangles.length; i += 3) {
@@ -2938,7 +2938,7 @@ function quadraticBezier(t, p0, p1, p2) {
2938
2938
  }
2939
2939
  const closePointEps = 1e-4;
2940
2940
  const curveEps = 1e-4;
2941
- function strokeTriangulate(points, options = {}) {
2941
+ function strokeTriangulate(points, options2 = {}) {
2942
2942
  const {
2943
2943
  vertices = [],
2944
2944
  indices = [],
@@ -2951,7 +2951,7 @@ function strokeTriangulate(points, options = {}) {
2951
2951
  },
2952
2952
  flipAlignment = false,
2953
2953
  closed = true
2954
- } = options;
2954
+ } = options2;
2955
2955
  const eps = closePointEps;
2956
2956
  if (points.length === 0) {
2957
2957
  return { vertices, indices };
@@ -3503,16 +3503,16 @@ class Curve {
3503
3503
  getFillVertices(_options) {
3504
3504
  return this.getAdaptiveVertices();
3505
3505
  }
3506
- fillTriangulate(options) {
3506
+ fillTriangulate(options2) {
3507
3507
  return fillTriangulate(
3508
- this.getFillVertices(options),
3509
- options
3508
+ this.getFillVertices(options2),
3509
+ options2
3510
3510
  );
3511
3511
  }
3512
- strokeTriangulate(options) {
3512
+ strokeTriangulate(options2) {
3513
3513
  return strokeTriangulate(
3514
3514
  this.getAdaptiveVertices(),
3515
- options
3515
+ options2
3516
3516
  );
3517
3517
  }
3518
3518
  toCommands() {
@@ -4043,15 +4043,15 @@ class LineCurve extends Curve {
4043
4043
  { type: "L", x: p2.x, y: p2.y }
4044
4044
  ];
4045
4045
  }
4046
- getFillVertices(options = {}) {
4046
+ getFillVertices(options2 = {}) {
4047
4047
  const minX = Math.min(this.p1.x, this.p2.x);
4048
4048
  const maxX = Math.max(this.p1.x, this.p2.x);
4049
4049
  const minY = Math.min(this.p1.y, this.p2.y);
4050
4050
  const maxY = Math.max(this.p1.y, this.p2.y);
4051
4051
  const x = minX;
4052
4052
  const y = minY;
4053
- const width = maxX - minX || options.style?.strokeWidth || 0;
4054
- const height = maxY - minY || options.style?.strokeWidth || 0;
4053
+ const width = maxX - minX || options2.style?.strokeWidth || 0;
4054
+ const height = maxY - minY || options2.style?.strokeWidth || 0;
4055
4055
  return [
4056
4056
  x,
4057
4057
  y,
@@ -4158,16 +4158,16 @@ class CompositeCurve extends Curve {
4158
4158
  });
4159
4159
  return output;
4160
4160
  }
4161
- strokeTriangulate(options) {
4161
+ strokeTriangulate(options2) {
4162
4162
  if (this.curves.length === 1) {
4163
- return this.curves[0].strokeTriangulate(options);
4163
+ return this.curves[0].strokeTriangulate(options2);
4164
4164
  } else {
4165
- return super.strokeTriangulate(options);
4165
+ return super.strokeTriangulate(options2);
4166
4166
  }
4167
4167
  }
4168
- getFillVertices(options) {
4168
+ getFillVertices(options2) {
4169
4169
  if (this.curves.length === 1) {
4170
- return this.curves[0].getFillVertices(options);
4170
+ return this.curves[0].getFillVertices(options2);
4171
4171
  } else {
4172
4172
  const output = [];
4173
4173
  let offset;
@@ -4176,7 +4176,7 @@ class CompositeCurve extends Curve {
4176
4176
  if (curve instanceof LineCurve) {
4177
4177
  arr = curve.getAdaptiveVertices();
4178
4178
  } else {
4179
- arr = curve.getFillVertices(options);
4179
+ arr = curve.getFillVertices(options2);
4180
4180
  }
4181
4181
  output.push(...arr);
4182
4182
  if (offset) {
@@ -4585,9 +4585,9 @@ class CurvePath extends CompositeCurve {
4585
4585
  super.getAdaptiveVertices(output)
4586
4586
  );
4587
4587
  }
4588
- getFillVertices(options) {
4588
+ getFillVertices(options2) {
4589
4589
  return this._closeVertices(
4590
- super.getFillVertices(options)
4590
+ super.getFillVertices(options2)
4591
4591
  );
4592
4592
  }
4593
4593
  _setCurrentPoint(point) {
@@ -4986,12 +4986,12 @@ class Path2D extends CompositeCurve {
4986
4986
  });
4987
4987
  return { min: min.finite(), max: max.finite() };
4988
4988
  }
4989
- strokeTriangulate(options) {
4990
- const indices = options?.indices ?? [];
4991
- const vertices = options?.vertices ?? [];
4989
+ strokeTriangulate(options2) {
4990
+ const indices = options2?.indices ?? [];
4991
+ const vertices = options2?.vertices ?? [];
4992
4992
  this.curves.forEach((curve) => {
4993
4993
  curve.strokeTriangulate({
4994
- ...options,
4994
+ ...options2,
4995
4995
  indices,
4996
4996
  vertices,
4997
4997
  style: { ...this.style }
@@ -4999,12 +4999,12 @@ class Path2D extends CompositeCurve {
4999
4999
  });
5000
5000
  return { indices, vertices };
5001
5001
  }
5002
- fillTriangulate(options) {
5002
+ fillTriangulate(options2) {
5003
5003
  const _options = {
5004
- ...options,
5004
+ ...options2,
5005
5005
  style: {
5006
5006
  ...this.style,
5007
- ...options?.style
5007
+ ...options2?.style
5008
5008
  }
5009
5009
  };
5010
5010
  const indices = _options.indices ?? [];
@@ -5030,7 +5030,7 @@ class Path2D extends CompositeCurve {
5030
5030
  }
5031
5031
  }
5032
5032
  fillTriangulate(_pointArray, {
5033
- ...options,
5033
+ ...options2,
5034
5034
  indices,
5035
5035
  vertices,
5036
5036
  holes,
@@ -5040,7 +5040,7 @@ class Path2D extends CompositeCurve {
5040
5040
  } else {
5041
5041
  this.curves.forEach((curve) => {
5042
5042
  curve.fillTriangulate({
5043
- ...options,
5043
+ ...options2,
5044
5044
  indices,
5045
5045
  vertices,
5046
5046
  style: { ...this.style }
@@ -5210,8 +5210,8 @@ ${content}
5210
5210
  toSvg() {
5211
5211
  return new DOMParser().parseFromString(this.toSvgString(), "image/svg+xml").documentElement;
5212
5212
  }
5213
- toCanvas(options = {}) {
5214
- const { pixelRatio = 2, ...style } = options;
5213
+ toCanvas(options2 = {}) {
5214
+ const { pixelRatio = 2, ...style } = options2;
5215
5215
  const { left, top, width, height } = this.getBoundingBox();
5216
5216
  const canvas = document.createElement("canvas");
5217
5217
  canvas.width = width * pixelRatio;
@@ -5466,22 +5466,22 @@ async function convertShapeElementToSvg(el) {
5466
5466
  </svg>`;
5467
5467
  return doc;
5468
5468
  }
5469
- function resolveOptions(options) {
5469
+ function resolveOptions(options2) {
5470
5470
  return {
5471
5471
  width: 0,
5472
5472
  height: 0,
5473
5473
  strokeWidth: 0,
5474
- ...options,
5475
- variables: { ...options.variables }
5474
+ ...options2,
5475
+ variables: { ...options2.variables }
5476
5476
  };
5477
5477
  }
5478
- function _createPresetShape(node, options) {
5478
+ function _createPresetShape(node, options2) {
5479
5479
  const shape = parsePresetShapeDefinition(node);
5480
5480
  return {
5481
5481
  ...shape,
5482
5482
  cate: Number(node.attr("@cate") ?? 0),
5483
5483
  title: node.attr("@title") ?? node.name,
5484
- svg: shape.generateSvgString(resolveOptions(options))
5484
+ svg: shape.generateSvgString(resolveOptions(options2))
5485
5485
  };
5486
5486
  }
5487
5487
  let root;
@@ -5492,13 +5492,13 @@ async function getRoot() {
5492
5492
  }
5493
5493
  return root;
5494
5494
  }
5495
- async function createPresetShape(name, options = {}) {
5495
+ async function createPresetShape(name, options2 = {}) {
5496
5496
  const node = (await getRoot()).find(name);
5497
5497
  return _createPresetShape(node, {
5498
5498
  width: 18,
5499
5499
  height: 18,
5500
5500
  strokeWidth: 1,
5501
- ...options
5501
+ ...options2
5502
5502
  });
5503
5503
  }
5504
5504
  function parseCssStyleLinearGradient(linearGradient) {
@@ -5837,7 +5837,6 @@ async function convertElement(el, parent, context) {
5837
5837
  }
5838
5838
  switch (el.type) {
5839
5839
  case "image":
5840
- element.name = element.name ?? "图片";
5841
5840
  meta.inCanvasIs = "Element2D";
5842
5841
  meta.inPptIs = "Picture";
5843
5842
  meta.lockAspectRatio = true;
@@ -5848,7 +5847,7 @@ async function convertElement(el, parent, context) {
5848
5847
  if (el.clipUrl) {
5849
5848
  meta.rawForegroundImage = el.url;
5850
5849
  }
5851
- if (el.maskUrl) {
5850
+ if (el.maskUrl && el.maskUrl !== el.url) {
5852
5851
  style.maskImage = el.maskUrl;
5853
5852
  }
5854
5853
  if (el.cropping) {
@@ -5866,7 +5865,6 @@ async function convertElement(el, parent, context) {
5866
5865
  }
5867
5866
  break;
5868
5867
  case "svg": {
5869
- element.name = element.name ?? "SVG";
5870
5868
  meta.inCanvasIs = "Element2D";
5871
5869
  meta.inPptIs = "Picture";
5872
5870
  meta.lockAspectRatio = true;
@@ -5877,7 +5875,6 @@ async function convertElement(el, parent, context) {
5877
5875
  break;
5878
5876
  }
5879
5877
  case "text": {
5880
- element.name = element.name ?? "文字";
5881
5878
  meta.inCanvasIs = "Element2D";
5882
5879
  meta.inPptIs = "Shape";
5883
5880
  if (style.writingMode === "horizontal-tb") {
@@ -5902,7 +5899,6 @@ async function convertElement(el, parent, context) {
5902
5899
  break;
5903
5900
  }
5904
5901
  case "com":
5905
- element.name = element.name ?? "组合";
5906
5902
  meta.inCanvasIs = "Element2D";
5907
5903
  meta.inPptIs = "GroupShape";
5908
5904
  element.children.push(
@@ -5919,7 +5915,6 @@ async function convertElement(el, parent, context) {
5919
5915
  );
5920
5916
  break;
5921
5917
  case "shape": {
5922
- element.name = element.name ?? "形状";
5923
5918
  meta.inCanvasIs = "Element2D";
5924
5919
  meta.inPptIs = "Shape";
5925
5920
  const svg = await convertShapeElementToSvg(el);
@@ -5952,12 +5947,10 @@ async function convertElement(el, parent, context) {
5952
5947
  break;
5953
5948
  }
5954
5949
  case "anim":
5955
- element.name = element.name ?? "Lottie";
5956
5950
  meta.inCanvasIs = "Lottie2D";
5957
5951
  element.src = el.url;
5958
5952
  break;
5959
5953
  case "video":
5960
- element.name = element.name ?? "视频";
5961
5954
  meta.inCanvasIs = "Video2D";
5962
5955
  element.src = el.src;
5963
5956
  break;
@@ -6017,11 +6010,11 @@ async function convertLayout(layout, isFrame = true, context) {
6017
6010
  meta
6018
6011
  };
6019
6012
  }
6020
- async function convertDoc(doc, options = {}) {
6013
+ async function convertDoc(doc, options2 = {}) {
6021
6014
  const {
6022
6015
  gap = 0,
6023
6016
  included
6024
- } = options;
6017
+ } = options2;
6025
6018
  let data;
6026
6019
  let raw = {};
6027
6020
  if (doc.content) {
@@ -6177,14 +6170,14 @@ async function convertImageElementToUrl(el) {
6177
6170
  effectCanvas = canvas1;
6178
6171
  }
6179
6172
  stroke?.forEach(({ width: width2, color }) => {
6180
- effectCanvas = new ImageStroke().use((ctx2, image, options) => {
6173
+ effectCanvas = new ImageStroke().use((ctx2, image, options2) => {
6181
6174
  const [, ctx1] = createCanvas(image.width, image.height);
6182
6175
  ctx1.drawImage(image, 0, 0);
6183
6176
  const paths = getContours(ctx1);
6184
- const x = options.thickness;
6185
- const y = options.thickness;
6186
- ctx2.strokeStyle = options.color;
6187
- ctx2.lineWidth = options.thickness * 2;
6177
+ const x = options2.thickness;
6178
+ const y = options2.thickness;
6179
+ ctx2.strokeStyle = options2.color;
6180
+ ctx2.lineWidth = options2.thickness * 2;
6188
6181
  ctx2.lineJoin = "round";
6189
6182
  paths.forEach((path) => {
6190
6183
  ctx2.beginPath();
@@ -6239,18 +6232,18 @@ class ImageStroke {
6239
6232
  this.method = method;
6240
6233
  return this;
6241
6234
  }
6242
- make(image, options) {
6235
+ make(image, options2) {
6243
6236
  const { canvas } = this;
6244
6237
  const ctx = this.canvas.getContext("2d");
6245
- const strokeSize = options.thickness * 2;
6238
+ const strokeSize = options2.thickness * 2;
6246
6239
  const [resultWidth, resultHeight] = [image.width, image.height].map((val) => val + strokeSize);
6247
6240
  if (resultWidth !== canvas.width || resultHeight !== canvas.height) {
6248
6241
  canvas.width = resultWidth;
6249
6242
  canvas.height = resultHeight;
6250
6243
  }
6251
6244
  ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
6252
- this.method(ctx, image, options);
6253
- ctx.drawImage(image, options.thickness, options.thickness);
6245
+ this.method(ctx, image, options2);
6246
+ ctx.drawImage(image, options2.thickness, options2.thickness);
6254
6247
  return canvas;
6255
6248
  }
6256
6249
  }
@@ -6378,7 +6371,7 @@ function bidTidLoader(editor, api) {
6378
6371
  doc.children.push(element);
6379
6372
  }
6380
6373
  });
6381
- left += width + config.value.frameGap;
6374
+ left += width + config.value.canvas.frame.gap;
6382
6375
  });
6383
6376
  return doc;
6384
6377
  }
@@ -6402,11 +6395,11 @@ function bigeLoader() {
6402
6395
  }
6403
6396
  };
6404
6397
  }
6405
- function plugin(options = {}) {
6398
+ function plugin(options2 = {}) {
6406
6399
  const {
6407
6400
  font,
6408
6401
  api
6409
- } = options;
6402
+ } = options2;
6410
6403
  const _api = {
6411
6404
  fonts: "/new/design/fonts",
6412
6405
  bid: "/new/udesign/info/%d",
@@ -6477,23 +6470,37 @@ async function setupFonts(editor, api) {
6477
6470
  await loadBigeFonts(api.fonts, true);
6478
6471
  });
6479
6472
  }
6480
- const editorOptions = {
6481
- checkerboard: true,
6482
- checkerboardStyle: "grid",
6483
- pixelGrid: true,
6484
- camera: true,
6485
- ruler: true,
6486
- scrollbar: true,
6487
- statusbar: true,
6488
- frameGap: 48,
6489
- zoomToFit: "width",
6490
- typographyStrategy: "autoHeight",
6473
+ const options = {
6491
6474
  locale: { locale: "zhHans" },
6492
- defaultFont: { family: "SourceHanSansCN-Normal", src: "https://bige.cdn.bcebos.com/files/202006/cBNrzOsE_rAQB.woff" },
6493
- transformControls: {
6494
- handleShape: "circle",
6495
- handleStrategy: "point",
6496
- rotator: true
6475
+ viewport: {
6476
+ camera: { enabled: true },
6477
+ zoom: { strategy: "containWidth" },
6478
+ screenPadding: { left: 110, top: 60, right: 110, bottom: 60 }
6479
+ },
6480
+ canvas: {
6481
+ checkerboard: { enabled: true, style: "grid" },
6482
+ pixelGrid: { enabled: true },
6483
+ frame: { outline: false }
6484
+ },
6485
+ ui: {
6486
+ ruler: { visible: true },
6487
+ scrollbar: { visible: true },
6488
+ statusbar: { visible: true }
6489
+ },
6490
+ interaction: {
6491
+ transform: {
6492
+ handleShape: "circle",
6493
+ handleStyle: "8-points",
6494
+ lockAspectRatioStrategy: "diagonal",
6495
+ rotator: true
6496
+ }
6497
+ },
6498
+ typography: {
6499
+ strategy: "autoHeight",
6500
+ defaultFont: {
6501
+ family: "SourceHanSansCN-Normal",
6502
+ src: "https://bige.cdn.bcebos.com/files/202006/cBNrzOsE_rAQB.woff"
6503
+ }
6497
6504
  }
6498
6505
  };
6499
6506
  export {
@@ -6511,9 +6518,9 @@ export {
6511
6518
  convertTextStyle,
6512
6519
  croppingToCropRect,
6513
6520
  plugin as default,
6514
- editorOptions,
6515
6521
  getStyle,
6516
6522
  getTextContents,
6523
+ options,
6517
6524
  parseAnimations,
6518
6525
  plugin,
6519
6526
  transformToCropRect,
@@ -0,0 +1,2 @@
1
+ import type { Options } from 'mce';
2
+ export declare const options: Options;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mce/bigesj",
3
3
  "type": "module",
4
- "version": "0.16.7",
4
+ "version": "0.17.0",
5
5
  "description": "Plugin for mce",
6
6
  "author": "wxm",
7
7
  "license": "MIT",
@@ -49,7 +49,7 @@
49
49
  "modern-openxml": "^1.10.1"
50
50
  },
51
51
  "devDependencies": {
52
- "mce": "0.16.7"
52
+ "mce": "0.17.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "mce": "^0"
@@ -1 +0,0 @@
1
- export declare const editorOptions: Partial<Mce.Options>;