@meta2d/core 1.1.20 → 1.1.22

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.
@@ -0,0 +1,12 @@
1
+ import { Pen } from "../pen";
2
+ interface HtmlPen extends Pen {
3
+ html: {
4
+ content: string;
5
+ iframe?: boolean;
6
+ _width: number;
7
+ _height: number;
8
+ };
9
+ calculative: any;
10
+ }
11
+ export declare function htmlDom(pen: HtmlPen): Path2D;
12
+ export {};
@@ -0,0 +1,66 @@
1
+ import { setElemPosition } from "../pen";
2
+ export function htmlDom(pen) {
3
+ const path = new Path2D();
4
+ const worldRect = pen.calculative.worldRect;
5
+ if (!pen.calculative.singleton) {
6
+ pen.calculative.singleton = {};
7
+ }
8
+ if (!pen.onDestroy) {
9
+ pen.onDestroy = destroy;
10
+ pen.onResize = onResize;
11
+ pen.onMove = setDomScale;
12
+ }
13
+ if (!pen.calculative.singleton.div) {
14
+ const context = pen.html.iframe
15
+ ? document.createElement('iframe')
16
+ : document.createElement('div');
17
+ if (pen.html.iframe) {
18
+ context.srcdoc = pen.html.content || '';
19
+ context.onload = () => {
20
+ context.style.overflow = 'hidden';
21
+ context.style.border = 'none';
22
+ context.scrolling = 'no';
23
+ };
24
+ }
25
+ else {
26
+ context.innerHTML = pen.html.content || '';
27
+ }
28
+ context.style.position = 'absolute';
29
+ context.style.outline = 'none';
30
+ context.style.overflow = 'hidden';
31
+ context.style.left = '-9999px';
32
+ context.style.top = '-9999px';
33
+ pen.calculative.canvas.externalElements.parentElement.appendChild(context);
34
+ onResize(pen);
35
+ setElemPosition(pen, context);
36
+ pen.calculative.singleton.div = context;
37
+ }
38
+ setDomScale(pen);
39
+ return path;
40
+ }
41
+ function destroy(pen) {
42
+ if (pen.calculative.singleton && pen.calculative.singleton.div) {
43
+ pen.calculative.singleton.div.remove();
44
+ delete pen.calculative.singleton.div;
45
+ }
46
+ }
47
+ function onResize(pen) {
48
+ const { width, height } = window.meta2d.getPenRect(pen);
49
+ pen.calculative.singleton._width = width;
50
+ pen.calculative.singleton._height = height;
51
+ }
52
+ function setDomScale(pen) {
53
+ requestAnimationFrame(() => {
54
+ const worldRect = pen.calculative.worldRect;
55
+ const store = pen.calculative.canvas.store;
56
+ const div = pen.calculative.singleton.div;
57
+ if (!div)
58
+ return;
59
+ div.style.width = pen.calculative.singleton._width + 'px';
60
+ div.style.height = pen.calculative.singleton._height + 'px';
61
+ div.style.left = worldRect.x + store.data.x - 1 / 2 * pen.calculative.singleton._width + 1 / 2 * worldRect.width + 'px';
62
+ div.style.top = worldRect.y + store.data.y - 1 / 2 * pen.calculative.singleton._height + 1 / 2 * worldRect.height + 'px';
63
+ div.style.scale = pen.calculative.canvas.store.data.scale;
64
+ });
65
+ }
66
+ //# sourceMappingURL=htmlDom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"htmlDom.js","sourceRoot":"","sources":["../../../../packages/core/src/diagrams/htmlDom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,eAAe,EAAC,MAAM,QAAQ,CAAC;AAY5C,MAAM,UAAU,OAAO,CAAC,GAAY;IAClC,MAAM,IAAI,GAAG,IAAI,MAAM,EAAE,CAAC;IAC1B,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC;IAE5C,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;QAC/B,GAAG,CAAC,WAAW,CAAC,SAAS,GAAG,EAAE,CAAC;IACjC,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;QACnB,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC;QACxB,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACxB,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC;IAC3B,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QACnC,MAAM,OAAO,GAAgB,GAAG,CAAC,IAAI,C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GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC;QACxH,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC;QACzH,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -17,6 +17,7 @@ export * from './iframe';
17
17
  export * from './video';
18
18
  export * from './form';
19
19
  export * from './sceneContainer';
20
+ export * from './htmlDom';
20
21
  import { rectangle } from './rectangle';
21
22
  import { circle } from './circle';
22
23
  import { svgPath } from './svgPath';
@@ -38,10 +39,12 @@ import { mindNode, mindNodeAnchors } from './mindNode';
38
39
  import { mindLine, mindLineAnchors } from './mindLine';
39
40
  import { form } from './form';
40
41
  import { sceneContainer } from './sceneContainer';
42
+ import { htmlDom } from "./htmlDom";
41
43
  export declare function commonPens(): {
42
44
  rectangle: typeof rectangle;
43
45
  square: typeof rectangle;
44
46
  circle: typeof circle;
47
+ htmlDom: typeof htmlDom;
45
48
  svgPath: typeof svgPath;
46
49
  diamond: typeof diamond;
47
50
  triangle: typeof triangle;
@@ -17,6 +17,7 @@ export * from './iframe';
17
17
  export * from './video';
18
18
  export * from './form';
19
19
  export * from './sceneContainer';
20
+ export * from './htmlDom';
20
21
  import { rectangle, square } from './rectangle';
21
22
  import { circle } from './circle';
22
23
  import { svgPath } from './svgPath';
@@ -39,11 +40,13 @@ import { mindNode, mindNodeAnchors } from './mindNode';
39
40
  import { mindLine, mindLineAnchors } from './mindLine';
40
41
  import { form } from './form';
41
42
  import { sceneContainer } from './sceneContainer';
43
+ import { htmlDom } from "./htmlDom";
42
44
  export function commonPens() {
43
45
  return {
44
46
  rectangle,
45
47
  square,
46
48
  circle,
49
+ htmlDom,
47
50
  svgPath,
48
51
  diamond,
49
52
  triangle,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/diagrams/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC7D,OA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AE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,SAAS;QACT,MAAM;QACN,MAAM;QACN,OAAO;QACP,OAAO;QACP,OAAO;QACP,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,OAAO;QACP,SAAS;QACT,UAAU;QACV,WAAW;QACX,OAAO;QACP,KAAK;QACL,IAAI;QACJ,MAAM;QACN,IAAI;QACJ,MAAM;QACN,KAAK;QACL,GAAG;QACH,QAAQ;QACR,QAAQ;QACR,SAAS,EAAC,SAAS;QACnB,IAAI;QACJ,OAAO,EAAC,SAAS;QACjB,cAAc;KACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,QAAQ,EAAE,eAAe;QACzB,QAAQ,EAAE,eAAe;QACzB,SAAS,EAAE,gBAAgB;QAC3B,QAAQ,EAAE,eAAe;QACzB,QAAQ,EAAE,eAAe;KAC1B,CAAC;AACJ,CAAC"}
package/src/options.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare enum KeydownType {
6
6
  Document = 0,
7
7
  Canvas = 1
8
8
  }
9
+ export declare const TRANSPARENT_COLOR = "#FFFFFF00";
9
10
  export interface Options {
10
11
  color?: string;
11
12
  activeColor?: string;
package/src/options.js CHANGED
@@ -4,6 +4,7 @@ export var KeydownType;
4
4
  KeydownType[KeydownType["Document"] = 0] = "Document";
5
5
  KeydownType[KeydownType["Canvas"] = 1] = "Canvas";
6
6
  })(KeydownType || (KeydownType = {}));
7
+ export const TRANSPARENT_COLOR = '#FFFFFF00';
7
8
  export const defaultOptions = {
8
9
  fontFamily: '"Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial',
9
10
  fontSize: 12,
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../packages/core/src/options.ts"],"names":[],"mappings":"AAIA,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,8CAAS,CAAA;IACT,qDAAQ,CAAA;IACR,iDAAM,CAAA;AACR,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;AAyID,MAAM,CAAC,MAAM,cAAc,GAAY;IACrC,UAAU,EACR,2EAA2E;IAC7E,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,GAAG;IACf,SAAS,EAAE,QAAQ;IACnB,YAAY,EAAE,QAAQ;IACtB,KAAK,EAAE,SAAS;IAChB,WAAW,EAAE,SAAS;IACtB,UAAU,EAAE,uBAAuB;IACnC,WAAW,EAAE,SAAS;IACtB,gBAAgB,EAAE,SAAS;IAC3B,YAAY,EAAE,CAAC;IACf,gBAAgB,EAAE,MAAM;IACxB,SAAS,EAAE,uBAAuB;IAClC,YAAY,EAAE,SAAS;IACvB,SAAS,EAAE,SAAS;IACpB,YAAY,EAAE,YAAY;IAC1B,WAAW,EAAE,WAAW;IACxB,UAAU,EAAE,UAAU;IACtB,WAAW,EAAE,SAAS;IACtB,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,EAAE;IACZ,OAAO,EAAE,WAAW,CAAC,QAAQ;IAC7B,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,SAAS;IACpB,eAAe,EAAE,OAAO;IACxB,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,EAAE;IAChB,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,EAAE;IACnB,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,KAAK;IACpB,YAAY,EAAE,SAAS;IACvB,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,CAAC;IAChB,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,CAAC;IACd,cAAc,EAAE;QACd;YACE,CAAC,EAAE,GAAG;YACN,CAAC,EAAE,CAAC;SACL;QACD;YACE,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,GAAG;SACP;QACD;YACE,CAAC,EAAE,GAAG;YACN,CAAC,EAAE,CAAC;SACL;QACD;YACE,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,GAAG;SACP;KACF;IACD,gBAAgB,EAAE,IAAI;IACtB,iBAAiB,EAAE,IAAI;IACvB,gBAAgB,EAAE,IAAI;IACtB,gBAAgB,EAAE,KAAK;IACvB,iBAAiB,EAAE,CAAC;IACpB,oBAAoB,EAAE,KAAK;IAC3B,WAAW,EAAE,IAAI;IACjB,GAAG,EAAE,EAAE;IACP,aAAa,EAAE,EAAE;IACjB,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,EAAE;IACb,eAAe,EAAC,CAAC,WAAW,CAAC;IAC7B,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,EAAE;IACnB,cAAc,EAAE,EAAE;IAClB,aAAa,EAAC,IAAI;IAClB,aAAa,EAAC,EAAE;CACjB,CAAC"}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../packages/core/src/options.ts"],"names":[],"mappings":"AAIA,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,8CAAS,CAAA;IACT,qDAAQ,CAAA;IACR,iDAAM,CAAA;AACR,CA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,GAAG;SACP;QACD;YACE,CAAC,EAAE,GAAG;YACN,CAAC,EAAE,CAAC;SACL;QACD;YACE,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,GAAG;SACP;KACF;IACD,gBAAgB,EAAE,IAAI;IACtB,iBAAiB,EAAE,IAAI;IACvB,gBAAgB,EAAE,IAAI;IACtB,gBAAgB,EAAE,KAAK;IACvB,iBAAiB,EAAE,CAAC;IACpB,oBAAoB,EAAE,KAAK;IAC3B,WAAW,EAAE,IAAI;IACjB,GAAG,EAAE,EAAE;IACP,aAAa,EAAE,EAAE;IACjB,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,EAAE;IACb,eAAe,EAAC,CAAC,WAAW,CAAC;IAC7B,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,EAAE;IACnB,cAAc,EAAE,EAAE;IAClB,aAAa,EAAC,IAAI;IAClB,aAAa,EAAC,EAAE;CACjB,CAAC"}
package/src/pen/render.js CHANGED
@@ -10,6 +10,7 @@ import { renderFromArrow, renderToArrow } from './arrow';
10
10
  import { Gradient, PenType } from '../pen';
11
11
  import { pSBC, rgba, cubicBezierY } from '../utils';
12
12
  import { isEmptyText } from '../utils/tool';
13
+ import { TRANSPARENT_COLOR } from "../options";
13
14
  const LINE = "line";
14
15
  const REPEAT = "repeat";
15
16
  /**
@@ -216,53 +217,141 @@ function getGradientR(angle, width, height) {
216
217
  return r;
217
218
  }
218
219
  function formatGradient(color) {
219
- if (typeof color == 'string' && color.startsWith('linear-gradient')) {
220
- let arr = color.slice(16, -2).split('deg,');
221
- if (arr.length > 1) {
222
- let _arr = arr[1].split('%,');
223
- const colors = [];
224
- _arr.forEach((stap) => {
225
- if (/rgba?/.test(stap)) {
226
- let _arr = stap.split(') ');
227
- colors.push({
228
- color: rgbaToHex(_arr[0] + ')'),
229
- i: parseFloat(_arr[1]) / 100,
230
- });
231
- }
232
- else {
233
- let _arr = stap.split(' ');
234
- if (_arr.length > 2) {
235
- colors.push({
236
- color: _arr[1],
237
- i: parseFloat(_arr[2]) / 100,
238
- });
239
- }
240
- else {
241
- colors.push({
242
- color: _arr[0],
243
- i: parseFloat(_arr[1]) / 100,
244
- });
245
- }
246
- }
247
- });
248
- return {
249
- angle: parseFloat(arr[0]),
250
- colors,
251
- };
220
+ if (typeof color !== 'string' || !color.startsWith('linear-gradient')) {
221
+ return {
222
+ angle: 0,
223
+ colors: [],
224
+ };
225
+ }
226
+ const start = color.indexOf('(');
227
+ const end = color.lastIndexOf(')');
228
+ if (start === -1 || end === -1 || end <= start) {
229
+ return { angle: 0, colors: [] };
230
+ }
231
+ const inner = color.slice(start + 1, end).trim();
232
+ const parts = splitByCommaRespectingParens(inner);
233
+ if (parts.length === 0) {
234
+ return { angle: 0, colors: [] };
235
+ }
236
+ let angle = 0;
237
+ let colorStartIndex = 0;
238
+ const firstPart = parts[0].trim();
239
+ if (firstPart.endsWith('deg')) {
240
+ angle = parseFloat(firstPart);
241
+ colorStartIndex = 1;
242
+ }
243
+ else if (firstPart.startsWith('to ')) {
244
+ angle = directionToAngle(firstPart);
245
+ colorStartIndex = 1;
246
+ }
247
+ const rawStops = [];
248
+ for (let i = colorStartIndex; i < parts.length; i++) {
249
+ const stop = parseColorStop(parts[i].trim());
250
+ if (stop) {
251
+ rawStops.push(stop);
252
+ }
253
+ }
254
+ if (rawStops.length === 0) {
255
+ return { angle, colors: [] };
256
+ }
257
+ fillMissingOffsets(rawStops);
258
+ const colors = rawStops.map((stop) => ({
259
+ color: stop.color,
260
+ i: stop.offset / 100,
261
+ }));
262
+ return { angle, colors };
263
+ }
264
+ function splitByCommaRespectingParens(str) {
265
+ const parts = [];
266
+ let current = '';
267
+ let depth = 0;
268
+ for (let i = 0; i < str.length; i++) {
269
+ const char = str[i];
270
+ if (char === '(') {
271
+ depth++;
272
+ current += char;
273
+ }
274
+ else if (char === ')') {
275
+ depth--;
276
+ current += char;
277
+ }
278
+ else if (char === ',' && depth === 0) {
279
+ parts.push(current);
280
+ current = '';
252
281
  }
253
282
  else {
254
- return {
255
- angle: parseFloat(arr[0]),
256
- colors: [],
257
- };
283
+ current += char;
258
284
  }
259
285
  }
260
- else {
286
+ if (current.trim()) {
287
+ parts.push(current);
288
+ }
289
+ return parts;
290
+ }
291
+ function parseColorStop(str) {
292
+ if (!str)
293
+ return null;
294
+ const percentMatch = str.match(/^(.+?)\s+(\d+(?:\.\d+)?%)\s*$/);
295
+ if (percentMatch) {
261
296
  return {
262
- angle: 0,
263
- colors: [],
297
+ color: normalizeColor(percentMatch[1].trim()),
298
+ offset: parseFloat(percentMatch[2]),
264
299
  };
265
300
  }
301
+ return { color: normalizeColor(str) };
302
+ }
303
+ function normalizeColor(color) {
304
+ if (/^rgba?\s*\(/.test(color)) {
305
+ return rgbaToHex(color);
306
+ }
307
+ return color;
308
+ }
309
+ function directionToAngle(dir) {
310
+ const map = {
311
+ 'to top': 90,
312
+ 'to right': 180,
313
+ 'to bottom': 270,
314
+ 'to left': 0,
315
+ 'to top right': 135,
316
+ 'to right top': 135,
317
+ 'to bottom right': 225,
318
+ 'to right bottom': 225,
319
+ 'to bottom left': 315,
320
+ 'to left bottom': 315,
321
+ 'to top left': 45,
322
+ 'to left top': 45,
323
+ };
324
+ return map[dir] ?? 0;
325
+ }
326
+ function fillMissingOffsets(stops) {
327
+ if (stops.length === 0)
328
+ return;
329
+ if (stops[0].offset == null) {
330
+ stops[0].offset = 0;
331
+ }
332
+ if (stops[stops.length - 1].offset == null) {
333
+ stops[stops.length - 1].offset = 100;
334
+ }
335
+ let i = 0;
336
+ while (i < stops.length) {
337
+ if (stops[i].offset == null) {
338
+ let prevIndex = i - 1;
339
+ let nextIndex = i + 1;
340
+ while (nextIndex < stops.length && stops[nextIndex].offset == null) {
341
+ nextIndex++;
342
+ }
343
+ const prevOffset = stops[prevIndex].offset;
344
+ const nextOffset = stops[nextIndex].offset;
345
+ const gap = nextIndex - prevIndex;
346
+ for (let j = 1; j < gap; j++) {
347
+ stops[prevIndex + j].offset = prevOffset + (nextOffset - prevOffset) * (j / gap);
348
+ }
349
+ i = nextIndex;
350
+ }
351
+ else {
352
+ i++;
353
+ }
354
+ }
266
355
  }
267
356
  function rgbaToHex(value) {
268
357
  if (/rgba?/.test(value)) {
@@ -1268,6 +1357,12 @@ export function renderPen(ctx, pen, download) {
1268
1357
  }
1269
1358
  else {
1270
1359
  let back;
1360
+ const backgroundStr = pen.calculative.background || '';
1361
+ if (typeof backgroundStr === 'string' && backgroundStr.startsWith('linear-gradient')) {
1362
+ //让background为linear开头的兼容到gradientColors
1363
+ pen.calculative.gradientColors = backgroundStr;
1364
+ pen.calculative.bkType = Gradient.Linear;
1365
+ }
1271
1366
  if (pen.calculative.bkType === Gradient.Linear) {
1272
1367
  if (pen.calculative.gradientColors) {
1273
1368
  // if (!pen.type) {
@@ -1743,32 +1838,27 @@ export function ctxDrawLinePath(canUsePath = true, ctx, pen, store) {
1743
1838
  setCtxLineAnimate(ctx, pen, store);
1744
1839
  ctx.beginPath();
1745
1840
  if (path instanceof Path2D) {
1746
- if (pen.lineName === 'polyline' || pen.lineName === 'line') {
1747
- if (pen.lineAnimateType === LineAnimateType.Arrow ||
1748
- pen.lineAnimateType === LineAnimateType.WaterDrop) {
1749
- //箭头动画
1750
- const _path = drawArrow(pen);
1751
- ctx.stroke(_path);
1752
- ctx.fill(_path);
1753
- }
1754
- else {
1755
- if (pen.calculative.gradientSmooth ||
1756
- pen.calculative.lineSmooth) {
1757
- if (!pen.calculative.gradientAnimatePath) {
1758
- pen.calculative.gradientAnimatePath =
1759
- getGradientAnimatePath(pen);
1760
- }
1761
- if (pen.calculative.gradientAnimatePath instanceof Path2D) {
1762
- ctx.stroke(pen.calculative.gradientAnimatePath);
1763
- }
1841
+ if (pen.lineAnimateType === LineAnimateType.Arrow ||
1842
+ pen.lineAnimateType === LineAnimateType.WaterDrop) {
1843
+ //箭头动画
1844
+ const _path = drawArrow(pen);
1845
+ ctx.stroke(_path);
1846
+ ctx.fill(_path);
1847
+ }
1848
+ else {
1849
+ if (pen.calculative.gradientSmooth ||
1850
+ pen.calculative.lineSmooth) {
1851
+ if (!pen.calculative.gradientAnimatePath) {
1852
+ pen.calculative.gradientAnimatePath =
1853
+ getGradientAnimatePath(pen);
1764
1854
  }
1765
- else {
1766
- ctx.stroke(path);
1855
+ if (pen.calculative.gradientAnimatePath instanceof Path2D) {
1856
+ ctx.stroke(pen.calculative.gradientAnimatePath);
1767
1857
  }
1768
1858
  }
1769
- }
1770
- else {
1771
- ctx.stroke(path);
1859
+ else {
1860
+ ctx.stroke(path);
1861
+ }
1772
1862
  }
1773
1863
  }
1774
1864
  else {
@@ -1794,7 +1884,9 @@ export function ctxDrawLinePath(canUsePath = true, ctx, pen, store) {
1794
1884
  * 设置线条动画,ctx 的 strokeStyle lineDash 等属性更改
1795
1885
  */
1796
1886
  export function setCtxLineAnimate(ctx, pen, store) {
1797
- ctx.strokeStyle = pen.animateColor || store.styles.animateColor;
1887
+ ctx.strokeStyle = pen.lineAnimateType === LineAnimateType.Custom ?
1888
+ pen.animateColor || TRANSPARENT_COLOR
1889
+ : (pen.animateColor || store.styles.animateColor);
1798
1890
  if (pen.animateShadow) {
1799
1891
  ctx.shadowBlur = pen.animateShadowBlur || pen.animateLineWidth || 6;
1800
1892
  ctx.shadowColor =
@@ -1966,7 +2058,7 @@ function lineAnimatePenRender(tracks) {
1966
2058
  height: viewHeight,
1967
2059
  rotate: state.rotate,
1968
2060
  };
1969
- meta2d.setValue({ id: targetPen.id, ...data });
2061
+ meta2d.setValue({ id: targetPen.id, ...data }, { render: false, doEvent: false, history: false });
1970
2062
  };
1971
2063
  }
1972
2064
  function lineAnimateIconRender(icon) {