@mailwoman/core 3.0.0 → 4.1.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.
Files changed (71) hide show
  1. package/out/decoder/build-tree.d.ts +21 -4
  2. package/out/decoder/build-tree.d.ts.map +1 -1
  3. package/out/decoder/build-tree.js +38 -9
  4. package/out/decoder/build-tree.js.map +1 -1
  5. package/out/decoder/calibration.d.ts +50 -0
  6. package/out/decoder/calibration.d.ts.map +1 -0
  7. package/out/decoder/calibration.js +74 -0
  8. package/out/decoder/calibration.js.map +1 -0
  9. package/out/decoder/containment.d.ts +31 -2
  10. package/out/decoder/containment.d.ts.map +1 -1
  11. package/out/decoder/containment.js +36 -3
  12. package/out/decoder/containment.js.map +1 -1
  13. package/out/decoder/index.d.ts +2 -0
  14. package/out/decoder/index.d.ts.map +1 -1
  15. package/out/decoder/index.js +2 -0
  16. package/out/decoder/index.js.map +1 -1
  17. package/out/decoder/serialize-json.d.ts +4 -0
  18. package/out/decoder/serialize-json.d.ts.map +1 -1
  19. package/out/decoder/serialize-json.js +10 -0
  20. package/out/decoder/serialize-json.js.map +1 -1
  21. package/out/decoder/serialize-xml.d.ts.map +1 -1
  22. package/out/decoder/serialize-xml.js +6 -0
  23. package/out/decoder/serialize-xml.js.map +1 -1
  24. package/out/decoder/types.d.ts +46 -0
  25. package/out/decoder/types.d.ts.map +1 -1
  26. package/out/decoder/validate-tree.d.ts +39 -0
  27. package/out/decoder/validate-tree.d.ts.map +1 -0
  28. package/out/decoder/validate-tree.js +79 -0
  29. package/out/decoder/validate-tree.js.map +1 -0
  30. package/out/pipeline/runtime-pipeline.d.ts +17 -1
  31. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  32. package/out/pipeline/runtime-pipeline.js +76 -16
  33. package/out/pipeline/runtime-pipeline.js.map +1 -1
  34. package/out/pipeline/span-logit-aggregation.d.ts +4 -2
  35. package/out/pipeline/span-logit-aggregation.d.ts.map +1 -1
  36. package/out/pipeline/span-logit-aggregation.js +11 -2
  37. package/out/pipeline/span-logit-aggregation.js.map +1 -1
  38. package/out/pipeline/types.d.ts +12 -3
  39. package/out/pipeline/types.d.ts.map +1 -1
  40. package/out/resolver/index.d.ts +1 -1
  41. package/out/resolver/index.d.ts.map +1 -1
  42. package/out/resolver/resolve.d.ts.map +1 -1
  43. package/out/resolver/resolve.js +162 -10
  44. package/out/resolver/resolve.js.map +1 -1
  45. package/out/resolver/types.d.ts +125 -0
  46. package/out/resolver/types.d.ts.map +1 -1
  47. package/out/resolver/types.js.map +1 -1
  48. package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
  49. package/out/resources/whosonfirst/PlacetypeDataSource.js +3 -1
  50. package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
  51. package/out/resources/whosonfirst/placetypes/graph.d.ts +47 -0
  52. package/out/resources/whosonfirst/placetypes/graph.d.ts.map +1 -0
  53. package/out/resources/whosonfirst/placetypes/graph.js +0 -0
  54. package/out/resources/whosonfirst/placetypes/graph.js.map +1 -0
  55. package/out/resources/whosonfirst/placetypes/index.d.ts +2 -0
  56. package/out/resources/whosonfirst/placetypes/index.d.ts.map +1 -1
  57. package/out/resources/whosonfirst/placetypes/index.js +2 -0
  58. package/out/resources/whosonfirst/placetypes/index.js.map +1 -1
  59. package/out/resources/whosonfirst/placetypes/mermaid.d.ts +35 -3
  60. package/out/resources/whosonfirst/placetypes/mermaid.d.ts.map +1 -1
  61. package/out/resources/whosonfirst/placetypes/mermaid.js +87 -15
  62. package/out/resources/whosonfirst/placetypes/mermaid.js.map +1 -1
  63. package/out/resources/whosonfirst/placetypes/tree.d.ts +30 -0
  64. package/out/resources/whosonfirst/placetypes/tree.d.ts.map +1 -0
  65. package/out/resources/whosonfirst/placetypes/tree.js +28 -0
  66. package/out/resources/whosonfirst/placetypes/tree.js.map +1 -0
  67. package/out/tokenization/Graph.d.ts +1 -1
  68. package/out/tokenization/Graph.d.ts.map +1 -1
  69. package/out/tokenization/Graph.js +5 -1
  70. package/out/tokenization/Graph.js.map +1 -1
  71. package/package.json +8 -2
@@ -3,19 +3,81 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
+ import { rgb } from "d3-color";
7
+ import { interpolateViridis } from "d3-scale-chromatic";
8
+ import { PlacetypeRoles } from "./definition.js";
6
9
  import { Placetype } from "./Placetype.js";
7
10
  /**
8
- * Colors for placetype roles.
11
+ * Mermaid's `classDef` parser uses commas to separate style properties, so an `rgb(r, g, b)` value
12
+ * (which d3-scale-chromatic emits for several interpolators, e.g. `interpolateRainbow`,
13
+ * `interpolateTurbo`, `interpolateSinebow`) breaks the parse. Convert any d3-color-recognised input
14
+ * to hex before embedding. `d3-color` already handles hex/rgb/rgba/hsl/named inputs.
15
+ */
16
+ function toMermaidColor(input) {
17
+ const parsed = rgb(input);
18
+ return Number.isNaN(parsed.r) ? input : parsed.formatHex();
19
+ }
20
+ /**
21
+ * Hand-tuned default colors for placetype roles. Used when no `interpolator` is passed to
22
+ * {@linkcode generateMermaidMarkup}. Each entry pairs a fill with a darker stroke and a text color
23
+ * chosen for contrast against the fill.
9
24
  */
10
25
  export const PlacetypeRoleColor = {
11
26
  common: "#0066cc",
12
27
  common_optional: "#00cc66",
13
28
  optional: "#ffcc00",
14
29
  };
30
+ const PlacetypeRoleStroke = {
31
+ common: "#004d99",
32
+ common_optional: "#009933",
33
+ optional: "#cca300",
34
+ };
35
+ const PlacetypeRoleText = {
36
+ common: "white",
37
+ common_optional: "white",
38
+ optional: "black",
39
+ };
40
+ const HAND_TUNED_PALETTE = Object.fromEntries(PlacetypeRoles.map((role) => [
41
+ role,
42
+ { fill: PlacetypeRoleColor[role], stroke: PlacetypeRoleStroke[role], text: PlacetypeRoleText[role] },
43
+ ]));
44
+ /**
45
+ * Walk the (filtered) subtree once to determine the deepest reachable descendant. Mirrors the
46
+ * structure of the emit-walk in {@linkcode generateMermaidMarkup} so the depths it computes line up
47
+ * with the edges that will be emitted. Cycles in the DAG are guarded by the `visited` set.
48
+ */
49
+ function measureMaxDepth(root, roles) {
50
+ let maxDepth = 0;
51
+ const visited = new Set();
52
+ const walk = (node, depth) => {
53
+ for (const child of node.findChildren(roles)) {
54
+ const childDepth = depth + 1;
55
+ if (childDepth > maxDepth)
56
+ maxDepth = childDepth;
57
+ if (visited.has(child.name))
58
+ continue;
59
+ visited.add(child.name);
60
+ walk(child, childDepth);
61
+ }
62
+ };
63
+ walk(root, 0);
64
+ return maxDepth;
65
+ }
15
66
  /**
16
67
  * Generate a Mermaid flowchart markup for a placetype and its descendants.
68
+ *
69
+ * The walk is a recursive `findChildren` traversal — every emitted edge is a real direct-parent →
70
+ * direct-child relationship. WOF placetypes form a DAG (e.g. `borough` has both `country` and
71
+ * `macroregion` as parents), so a child can legitimately appear on multiple edges; the `visited`
72
+ * set prevents the subtree below it from being re-emitted.
73
+ *
74
+ * Edges are colored by depth from the root via
75
+ * {@linkcode GenerateMermaidMarkupOptions.edgeInterpolator} (default: viridis), so any lineage path
76
+ * traces a smooth gradient down the chart. Node fills always use the hand-tuned role palette.
17
77
  */
18
- export function generateMermaidMarkup(placetype, roles) {
78
+ export function generateMermaidMarkup(placetype, options = {}) {
79
+ const { roles, edgeInterpolator = interpolateViridis } = options;
80
+ const palette = HAND_TUNED_PALETTE;
19
81
  const lines = [
20
82
  "---",
21
83
  "config:",
@@ -24,21 +86,31 @@ export function generateMermaidMarkup(placetype, roles) {
24
86
  "---",
25
87
  "graph TD",
26
88
  " linkStyle default stroke-width: 5",
27
- ` classDef common fill:${PlacetypeRoleColor.common},stroke:#004d99,color:white,font-weight:bold`,
28
- ` classDef common_optional fill:${PlacetypeRoleColor.common_optional},stroke:#009933,color:white,font-weight:bold`,
29
- ` classDef optional fill:${PlacetypeRoleColor.optional},stroke:#cca300,color:black,font-weight:bold`,
89
+ ...PlacetypeRoles.map((role) => ` classDef ${role} fill:${palette[role].fill},stroke:${palette[role].stroke},color:${palette[role].text},font-weight:bold`),
90
+ // The root is never the target of an emitted edge, so declare it standalone so it picks
91
+ // up the role classDef and renders alongside the others.
92
+ ` ${placetype.name}:::${placetype.role}`,
30
93
  ];
31
- const descendants = placetype.findDescendants(roles);
32
- for (const [idx, descendant] of descendants.entries()) {
33
- lines.push(` ${placetype.name} --> ${descendant.name}:::${descendant.role}`);
34
- lines.push(` linkStyle ${idx} stroke:${PlacetypeRoleColor[descendant.role]}`);
35
- }
36
- for (const descendant of descendants) {
37
- const children = descendant.findChildren(roles);
38
- for (const child of children) {
39
- lines.push(` ${descendant.name} --> ${child.name}:::${child.role}`);
94
+ // Pre-compute max depth once so every edge's `t` is consistent across the second pass.
95
+ const maxDepth = measureMaxDepth(placetype, roles);
96
+ const visited = new Set();
97
+ let edgeIdx = 0;
98
+ const walk = (node, depth) => {
99
+ for (const child of node.findChildren(roles)) {
100
+ const childDepth = depth + 1;
101
+ // Single-level case: nothing to interpolate across, sample mid-gradient.
102
+ const t = maxDepth > 1 ? (childDepth - 1) / (maxDepth - 1) : 0.5;
103
+ const edgeColor = toMermaidColor(edgeInterpolator(t));
104
+ lines.push(` ${node.name} --> ${child.name}:::${child.role}`);
105
+ lines.push(` linkStyle ${edgeIdx} stroke:${edgeColor}`);
106
+ edgeIdx++;
107
+ if (visited.has(child.name))
108
+ continue;
109
+ visited.add(child.name);
110
+ walk(child, childDepth);
40
111
  }
41
- }
112
+ };
113
+ walk(placetype, 0);
42
114
  return lines.join("\n");
43
115
  }
44
116
  //# sourceMappingURL=mermaid.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mermaid.js","sourceRoot":"","sources":["../../../../resources/whosonfirst/placetypes/mermaid.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IACjC,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,SAAS;IAC1B,QAAQ,EAAE,SAAS;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E,KAAK,CAAC,CAAA;IAElD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IACjC,IAAI,OAAO,GAAG,CAAC,CAAA;IAEf,MAAM,IAAI,GAAG,CAAC,IAAe,EAAE,KAAa,EAAQ,EAAE;QACrD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9C,MAAM,UAAU,GAAG,KAAK,GAAG,CAAC,CAAA;YAC5B,yEAAyE;YACzE,MAAM,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;YAChE,MAAM,SAAS,GAAG,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAA;YAErD,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,QAAQ,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;YAC9D,KAAK,CAAC,IAAI,CAAC,eAAe,OAAO,WAAW,SAAS,EAAE,CAAC,CAAA;YACxD,OAAO,EAAE,CAAA;YAET,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;gBAAE,SAAQ;YACrC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACvB,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;QACxB,CAAC;IACF,CAAC,CAAA;IAED,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;IAElB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ import type { PlacetypeRole } from "./definition.js";
7
+ import { Placetype } from "./Placetype.js";
8
+ /**
9
+ * A node in the nested placetype tree produced by {@linkcode generatePlacetypeTree}.
10
+ *
11
+ * WOF placetypes form a DAG (a placetype can have multiple parents — `borough`, for example, is a
12
+ * direct child of both `country` and `macroregion`), so a tree projection rooted at a single
13
+ * placetype can list the same descendant under multiple branches. That repetition is expected.
14
+ */
15
+ export interface PlacetypeTreeNode {
16
+ name: string;
17
+ id: number;
18
+ role: PlacetypeRole;
19
+ children: PlacetypeTreeNode[];
20
+ }
21
+ /**
22
+ * Build a nested tree of a placetype and its descendants, optionally filtered by role.
23
+ *
24
+ * The traversal mirrors {@linkcode Placetype.findChildren} — direct children only at each level,
25
+ * recursively. The DAG-to-tree projection may repeat descendants under multiple parents; if you
26
+ * need each placetype to appear exactly once, use {@linkcode Placetype.findDescendants} for a flat
27
+ * de-duplicated set instead.
28
+ */
29
+ export declare function generatePlacetypeTree(placetype: Placetype, roles?: Iterable<PlacetypeRole> | null): PlacetypeTreeNode;
30
+ //# sourceMappingURL=tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../../resources/whosonfirst/placetypes/tree.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,aAAa,CAAA;IACnB,QAAQ,EAAE,iBAAiB,EAAE,CAAA;CAC7B;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,IAAI,GAAG,iBAAiB,CAIrH"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ import { Placetype } from "./Placetype.js";
7
+ /**
8
+ * Build a nested tree of a placetype and its descendants, optionally filtered by role.
9
+ *
10
+ * The traversal mirrors {@linkcode Placetype.findChildren} — direct children only at each level,
11
+ * recursively. The DAG-to-tree projection may repeat descendants under multiple parents; if you
12
+ * need each placetype to appear exactly once, use {@linkcode Placetype.findDescendants} for a flat
13
+ * de-duplicated set instead.
14
+ */
15
+ export function generatePlacetypeTree(placetype, roles) {
16
+ const roleSet = roles ? new Set(roles) : null;
17
+ return buildNode(placetype, roleSet);
18
+ }
19
+ function buildNode(placetype, roles) {
20
+ const children = placetype.findChildren(roles).map((child) => buildNode(child, roles));
21
+ return {
22
+ name: placetype.name,
23
+ id: placetype.id,
24
+ role: placetype.role,
25
+ children,
26
+ };
27
+ }
28
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../../resources/whosonfirst/placetypes/tree.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAgB1C;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAoB,EAAE,KAAsC;IACjG,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAE7C,OAAO,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;AACrC,CAAC;AAED,SAAS,SAAS,CAAC,SAAoB,EAAE,KAAgC;IACxE,MAAM,QAAQ,GAAG,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;IAEtF,OAAO;QACN,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,EAAE,EAAE,SAAS,CAAC,EAAE;QAChB,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,QAAQ;KACR,CAAA;AACF,CAAC"}
@@ -3,7 +3,7 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
- import { Sequence } from "@mailwoman/core/resources";
6
+ import { Sequence } from "../resources/set.js";
7
7
  export type GraphNodeCallback<G> = (node: G) => boolean;
8
8
  /**
9
9
  * A graph structure for storing relationships between nodes.
@@ -1 +1 @@
1
- {"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../tokenization/Graph.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAEpD,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAA;AAEvD;;GAEG;AACH,qBAAa,KAAK,CAAC,SAAS,SAAS,OAAO;IAC3C;;OAEG;IACI,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAiB;IAEpD;;OAEG;IACI,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAiB;IAErD;;OAEG;IACH,SAAgB,gBAAgB,sBAA4B;IAC5D;;OAEG;IACH,SAAgB,YAAY,sBAA4B;IAExD;;OAEG;IACH,SAAgB,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAA4B;IAExE,IAAW,WAAW,IAAI,SAAS,GAAG,IAAI,CAEzC;IAED,IAAW,eAAe,IAAI,SAAS,GAAG,IAAI,CAE7C;CACD"}
1
+ {"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../tokenization/Graph.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAA;AAEvD;;GAEG;AACH,qBAAa,KAAK,CAAC,SAAS,SAAS,OAAO;IAC3C;;OAEG;IACI,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAiB;IAEpD;;OAEG;IACI,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAiB;IAErD;;OAEG;IACH,SAAgB,gBAAgB,sBAA4B;IAC5D;;OAEG;IACH,SAAgB,YAAY,sBAA4B;IAExD;;OAEG;IACH,SAAgB,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAA4B;IAExE,IAAW,WAAW,IAAI,SAAS,GAAG,IAAI,CAEzC;IAED,IAAW,eAAe,IAAI,SAAS,GAAG,IAAI,CAE7C;CACD"}
@@ -3,7 +3,11 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
- import { Sequence } from "@mailwoman/core/resources";
6
+ // Import `Sequence` from its leaf module, NOT the `@mailwoman/core/resources` barrel: the barrel
7
+ // re-exports the libpostal/WOF dictionaries (top-level `readdir` + fast-glob, Node-only), which would
8
+ // drag the entire resource-loading layer into any browser bundle that touches tokenization — and
9
+ // `@mailwoman/phrase-grouper` touches it via `Span`. `Sequence` itself is a pure `extends Set`.
10
+ import { Sequence } from "../resources/set.js";
7
11
  /**
8
12
  * A graph structure for storing relationships between nodes.
9
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../tokenization/Graph.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAIpD;;GAEG;AACH,MAAM,OAAO,KAAK;IACjB;;OAEG;IACI,OAAO,GAAwB,IAAI,QAAQ,EAAE,CAAA;IAEpD;;OAEG;IACI,QAAQ,GAAwB,IAAI,QAAQ,EAAE,CAAA;IAErD;;OAEG;IACa,gBAAgB,GAAG,IAAI,QAAQ,EAAa,CAAA;IAC5D;;OAEG;IACa,YAAY,GAAG,IAAI,QAAQ,EAAa,CAAA;IAExD;;OAEG;IACa,OAAO,GAAwB,IAAI,QAAQ,EAAa,CAAA;IAExE,IAAW,WAAW;QACrB,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAA;IAC/B,CAAC;IAED,IAAW,eAAe;QACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAA;IACnC,CAAC;CACD"}
1
+ {"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../tokenization/Graph.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,iGAAiG;AACjG,sGAAsG;AACtG,iGAAiG;AACjG,gGAAgG;AAChG,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAI9C;;GAEG;AACH,MAAM,OAAO,KAAK;IACjB;;OAEG;IACI,OAAO,GAAwB,IAAI,QAAQ,EAAE,CAAA;IAEpD;;OAEG;IACI,QAAQ,GAAwB,IAAI,QAAQ,EAAE,CAAA;IAErD;;OAEG;IACa,gBAAgB,GAAG,IAAI,QAAQ,EAAa,CAAA;IAC5D;;OAEG;IACa,YAAY,GAAG,IAAI,QAAQ,EAAa,CAAA;IAExD;;OAEG;IACa,OAAO,GAAwB,IAAI,QAAQ,EAAa,CAAA;IAExE,IAAW,WAAW;QACrB,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAA;IAC/B,CAAC;IAED,IAAW,eAAe;QACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAA;IACnC,CAAC;CACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mailwoman/core",
3
- "version": "3.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Mailwoman core: tokenization, classification primitives, solver, formatter, resources, filters, solvers, utils.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -49,8 +49,10 @@
49
49
  }
50
50
  },
51
51
  "dependencies": {
52
- "axios": "^1.16.1",
52
+ "axios": "^1.17.0",
53
53
  "axios-cache-interceptor": "^1.12.0",
54
+ "d3-color": "^3.1.0",
55
+ "d3-scale-chromatic": "^3.1.0",
54
56
  "http-status-codes": "^2.3.0",
55
57
  "json-colorizer": "^3.0.1",
56
58
  "kysely": "^0.29.2",
@@ -58,6 +60,10 @@
58
60
  "pino-pretty": "^13.1.3",
59
61
  "table": "^6.9.0"
60
62
  },
63
+ "devDependencies": {
64
+ "@types/d3-color": "^3.1.3",
65
+ "@types/d3-scale-chromatic": "^3.1.0"
66
+ },
61
67
  "files": [
62
68
  "out/**/*.js",
63
69
  "out/**/*.js.map",