@meta2d/core 1.1.20 → 1.1.21

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/pen/render.js CHANGED
@@ -216,53 +216,141 @@ function getGradientR(angle, width, height) {
216
216
  return r;
217
217
  }
218
218
  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
- };
219
+ if (typeof color !== 'string' || !color.startsWith('linear-gradient')) {
220
+ return {
221
+ angle: 0,
222
+ colors: [],
223
+ };
224
+ }
225
+ const start = color.indexOf('(');
226
+ const end = color.lastIndexOf(')');
227
+ if (start === -1 || end === -1 || end <= start) {
228
+ return { angle: 0, colors: [] };
229
+ }
230
+ const inner = color.slice(start + 1, end).trim();
231
+ const parts = splitByCommaRespectingParens(inner);
232
+ if (parts.length === 0) {
233
+ return { angle: 0, colors: [] };
234
+ }
235
+ let angle = 0;
236
+ let colorStartIndex = 0;
237
+ const firstPart = parts[0].trim();
238
+ if (firstPart.endsWith('deg')) {
239
+ angle = parseFloat(firstPart);
240
+ colorStartIndex = 1;
241
+ }
242
+ else if (firstPart.startsWith('to ')) {
243
+ angle = directionToAngle(firstPart);
244
+ colorStartIndex = 1;
245
+ }
246
+ const rawStops = [];
247
+ for (let i = colorStartIndex; i < parts.length; i++) {
248
+ const stop = parseColorStop(parts[i].trim());
249
+ if (stop) {
250
+ rawStops.push(stop);
251
+ }
252
+ }
253
+ if (rawStops.length === 0) {
254
+ return { angle, colors: [] };
255
+ }
256
+ fillMissingOffsets(rawStops);
257
+ const colors = rawStops.map((stop) => ({
258
+ color: stop.color,
259
+ i: stop.offset / 100,
260
+ }));
261
+ return { angle, colors };
262
+ }
263
+ function splitByCommaRespectingParens(str) {
264
+ const parts = [];
265
+ let current = '';
266
+ let depth = 0;
267
+ for (let i = 0; i < str.length; i++) {
268
+ const char = str[i];
269
+ if (char === '(') {
270
+ depth++;
271
+ current += char;
272
+ }
273
+ else if (char === ')') {
274
+ depth--;
275
+ current += char;
276
+ }
277
+ else if (char === ',' && depth === 0) {
278
+ parts.push(current);
279
+ current = '';
252
280
  }
253
281
  else {
254
- return {
255
- angle: parseFloat(arr[0]),
256
- colors: [],
257
- };
282
+ current += char;
258
283
  }
259
284
  }
260
- else {
285
+ if (current.trim()) {
286
+ parts.push(current);
287
+ }
288
+ return parts;
289
+ }
290
+ function parseColorStop(str) {
291
+ if (!str)
292
+ return null;
293
+ const percentMatch = str.match(/^(.+?)\s+(\d+(?:\.\d+)?%)\s*$/);
294
+ if (percentMatch) {
261
295
  return {
262
- angle: 0,
263
- colors: [],
296
+ color: normalizeColor(percentMatch[1].trim()),
297
+ offset: parseFloat(percentMatch[2]),
264
298
  };
265
299
  }
300
+ return { color: normalizeColor(str) };
301
+ }
302
+ function normalizeColor(color) {
303
+ if (/^rgba?\s*\(/.test(color)) {
304
+ return rgbaToHex(color);
305
+ }
306
+ return color;
307
+ }
308
+ function directionToAngle(dir) {
309
+ const map = {
310
+ 'to top': 90,
311
+ 'to right': 180,
312
+ 'to bottom': 270,
313
+ 'to left': 0,
314
+ 'to top right': 135,
315
+ 'to right top': 135,
316
+ 'to bottom right': 225,
317
+ 'to right bottom': 225,
318
+ 'to bottom left': 315,
319
+ 'to left bottom': 315,
320
+ 'to top left': 45,
321
+ 'to left top': 45,
322
+ };
323
+ return map[dir] ?? 0;
324
+ }
325
+ function fillMissingOffsets(stops) {
326
+ if (stops.length === 0)
327
+ return;
328
+ if (stops[0].offset == null) {
329
+ stops[0].offset = 0;
330
+ }
331
+ if (stops[stops.length - 1].offset == null) {
332
+ stops[stops.length - 1].offset = 100;
333
+ }
334
+ let i = 0;
335
+ while (i < stops.length) {
336
+ if (stops[i].offset == null) {
337
+ let prevIndex = i - 1;
338
+ let nextIndex = i + 1;
339
+ while (nextIndex < stops.length && stops[nextIndex].offset == null) {
340
+ nextIndex++;
341
+ }
342
+ const prevOffset = stops[prevIndex].offset;
343
+ const nextOffset = stops[nextIndex].offset;
344
+ const gap = nextIndex - prevIndex;
345
+ for (let j = 1; j < gap; j++) {
346
+ stops[prevIndex + j].offset = prevOffset + (nextOffset - prevOffset) * (j / gap);
347
+ }
348
+ i = nextIndex;
349
+ }
350
+ else {
351
+ i++;
352
+ }
353
+ }
266
354
  }
267
355
  function rgbaToHex(value) {
268
356
  if (/rgba?/.test(value)) {
@@ -1268,6 +1356,12 @@ export function renderPen(ctx, pen, download) {
1268
1356
  }
1269
1357
  else {
1270
1358
  let back;
1359
+ const backgroundStr = pen.calculative.background || '';
1360
+ if (typeof backgroundStr === 'string' && backgroundStr.startsWith('linear-gradient')) {
1361
+ //让background为linear开头的兼容到gradientColors
1362
+ pen.calculative.gradientColors = backgroundStr;
1363
+ pen.calculative.bkType = Gradient.Linear;
1364
+ }
1271
1365
  if (pen.calculative.bkType === Gradient.Linear) {
1272
1366
  if (pen.calculative.gradientColors) {
1273
1367
  // if (!pen.type) {