@weasel-js/diagram-formats 1.15.1 → 1.16.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.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { placedPagesOf, scenePoseAdapter, pageHolding, layoutPages, PAGES_DOC_KEY, pagesOf, nextPageId, addPage, documentOf, isAnnotationLayer, boundsOfPath, layoutTextPose, warmRender, renderSceneToPixels, planPixelRender, viewToMat3, createRasterSession, composeWorldPose, derivedDepOf, IDENTITY_POSE_COMPOSITION, pageName, derivedPartsOf, INHERIT, resolvePartPaint, createScene, mat3, effectivePose } from '@weasel-js/core';
2
2
  import { DIAGRAM_TYPES, FLOWCHART_NOTATION, sequenceLayout, diagramThemeFrom, dataEdgeStyle, dataRegionStyle, dataNodeStyle, DIAGRAM_THEME_KEY, diagramLabelOf, endLabelIdOf, sequenceRootOf, offPageSplits, diagramNotationOf, documentBoundsOf, DIAGRAM_TYPE_DOC_KEY, diagramTypeDocValue, themeDocValue, diagramTypeOfNotation, diagramShape, markShape, diagramScene, sequencePartOf, diagramEdgeOf, diagramContainerOf, NODE_STROKE_WIDTH, poolAxisOf, titleIdOf, sequenceSpecs, diagramThemeOf, layoutOwnsRoute, EDGE_STROKE_WIDTH, LAYOUTS, edgeIdOf, themeFont, layoutOwnsPort, DEFAULT_PORTS, LANE_STROKE_WIDTH } from '@weasel-js/diagram';
3
+ import { tryNormalizeHex, parseColor, normalizeHex, rgbaToHex } from '@weasel-js/paint';
4
+ import { deepEqual } from '@weasel-js/registry';
3
5
  import { svgNodesFromKit, svgLeafFromKit, warmSvg, serializeSvg, escapeAttr, svgPaintFromKit, svgStrokeFromKit } from '@weasel-js/svg';
4
6
  import { replayGitGraph, parseGanttEnd, parseGanttStart, formatGanttEnd, formatGanttStart, plotRootOf, plotSpecs } from '@weasel-js/plot';
5
7
  import { writePdf, registryFontSource } from '@weasel-js/pdf';
@@ -137,7 +139,6 @@ var Warnings = class {
137
139
  return [...this.seen].map((m) => this.listed.has(m) ? `${m}: ${[...this.listed.get(m)].join(", ")}.` : m);
138
140
  }
139
141
  };
140
- var hex2 = (n) => Math.round(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
141
142
  var NAMED = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\xA0" };
142
143
  function decodeEntities(text3, hash = false) {
143
144
  const re = hash ? /[&#](#x[\da-f]+|#\d+|x[\da-f]+(?=;)|\d+|[a-z]+);/gi : /&(#x[\da-f]+|#\d+|[a-z]+);/gi;
@@ -456,8 +457,6 @@ function parseDot(text3) {
456
457
  return { kind: "edge", ends, attrs: attrList2(), line };
457
458
  }
458
459
  }
459
-
460
- // src/dot/values.ts
461
460
  function labelLines(label, self, graph) {
462
461
  if (label.html) return markupLines(label.value).filter((l, i, all) => l !== "" || i > 0 && i < all.length - 1);
463
462
  const lines = [""];
@@ -485,7 +484,7 @@ function hsvHex(h, s, v) {
485
484
  const k = (n + h * 6) % 6;
486
485
  return v - v * s * Math.max(0, Math.min(k, 4 - k, 1));
487
486
  };
488
- return `#${hex2(f(5))}${hex2(f(3))}${hex2(f(1))}`;
487
+ return rgbaToHex([f(5), f(3), f(1)]);
489
488
  }
490
489
  function dotColor(value) {
491
490
  const first = value.split(":")[0].split(";")[0].trim();
@@ -904,20 +903,26 @@ function graphOut(doc, opts, format, holdsPools = false) {
904
903
  if (page.data.edges.some((e) => e.waypoints !== void 0 && e.waypoints.length > 0)) {
905
904
  warnings.add(`${format} holds no routes; connectors' bends were dropped.`);
906
905
  }
906
+ if (page.data.edges.some((e) => dataEdgeStyle(e, theme).trim !== void 0)) {
907
+ warnings.add(`${format} draws a connector whole; trims were dropped.`);
908
+ }
907
909
  return { page, theme, ...tree, byId, edges: [...page.data.edges], warnings };
908
910
  }
909
911
  function hexColor(css) {
910
- const short = /^#([\da-f])([\da-f])([\da-f])([\da-f])?$/i.exec(css);
911
- if (short !== null) return `#${short.slice(1).filter(Boolean).map((d) => d + d).join("")}`;
912
- const rgb = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+)(%?))?\s*\)$/i.exec(css);
913
- if (rgb === null) return css;
914
- const alpha = rgb[4] === void 0 ? "" : hex2(Number(rgb[4]) / (rgb[5] === "%" ? 100 : 1));
915
- return `#${hex2(Number(rgb[1]) / 255)}${hex2(Number(rgb[2]) / 255)}${hex2(Number(rgb[3]) / 255)}${alpha}`;
912
+ if (css.startsWith("#")) return tryNormalizeHex(css) ?? css;
913
+ if (!/^rgba?\(/i.test(css)) return css;
914
+ let rgba;
915
+ try {
916
+ rgba = parseColor(css);
917
+ } catch {
918
+ return css;
919
+ }
920
+ return normalizeHex(rgbaToHex(rgba), /\/|(?:,[^,]*){3}/.test(css) ? "rgba" : "rgb");
916
921
  }
917
922
  function changed(style, base) {
918
923
  const out = {};
919
924
  for (const key of Object.keys(style)) {
920
- if (JSON.stringify(style[key]) !== JSON.stringify(base[key])) out[key] = style[key];
925
+ if (!deepEqual(style[key], base[key], { undefinedAsAbsent: true })) out[key] = style[key];
921
926
  }
922
927
  return out;
923
928
  }
@@ -1790,6 +1795,7 @@ function markerParts(end2, marker2, warn) {
1790
1795
  function edgeStyle(edge, theme, warn) {
1791
1796
  const style = dataEdgeStyle(edge, theme);
1792
1797
  const router = edge.router ?? "straight";
1798
+ if (style.trim !== void 0) warn("Trims on connectors were left out; they were written whole.");
1793
1799
  return [
1794
1800
  ["edgeStyle", router === "orthogonal" || router === "avoid" ? "orthogonalEdgeStyle" : "none"],
1795
1801
  ["curved", router === "bezier" ? 1 : void 0],
@@ -6748,7 +6754,7 @@ var ROUTERS = ["straight", "bezier", "orthogonal", "avoid"];
6748
6754
  var dataOf = (node) => node?.data ?? {};
6749
6755
  var traitOf = (node) => dataOf(node).diagram ?? null;
6750
6756
  var colorOf2 = (paint) => typeof paint?.paint?.color === "string" ? paint.paint.color : void 0;
6751
- var same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
6757
+ var same = (a, b) => deepEqual(a, b, { undefinedAsAbsent: true });
6752
6758
  var moved2 = (p, by) => ({ x: p.x - by.x, y: p.y - by.y });
6753
6759
  function kindOf2(node) {
6754
6760
  if (sequenceRootOf(node) !== null) return "sequence";
@@ -6850,6 +6856,7 @@ function readEdge3(node, labels, page, theme) {
6850
6856
  label: label === void 0 ? void 0 : colorOf2(dataOf(label).fill),
6851
6857
  width: stroke?.width,
6852
6858
  dash: stroke?.dash,
6859
+ trim: stroke?.trim,
6853
6860
  markerStart: stroke?.markerStart ?? null,
6854
6861
  markerEnd: stroke?.markerEnd ?? null
6855
6862
  }, {