mdld-parse 1.1.1 → 1.1.2

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.
@@ -1,4 +1,4 @@
1
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
1
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
2
2
  function _typeof(o) {
3
3
  "@babel/helpers - typeof";
4
4
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -7,8 +7,7 @@ function _typeof(o) {
7
7
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
8
8
  }, _typeof(o);
9
9
  }
10
- //#endregion
11
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
10
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
12
11
  function toPrimitive(t, r) {
13
12
  if ("object" != _typeof(t) || !t) return t;
14
13
  var e = t[Symbol.toPrimitive];
@@ -19,14 +18,12 @@ function toPrimitive(t, r) {
19
18
  }
20
19
  return ("string" === r ? String : Number)(t);
21
20
  }
22
- //#endregion
23
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
21
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
24
22
  function toPropertyKey(t) {
25
23
  var i = toPrimitive(t, "string");
26
24
  return "symbol" == _typeof(i) ? i : i + "";
27
25
  }
28
- //#endregion
29
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
26
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
30
27
  function _defineProperty(e, r, t) {
31
28
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
32
29
  value: t,
@@ -35,10 +32,9 @@ function _defineProperty(e, r, t) {
35
32
  writable: !0
36
33
  }) : e[r] = t, e;
37
34
  }
38
- //#endregion
39
- //#region src/graph.js
35
+ // src/graph.js
40
36
  /**
41
- * <quad-graph> — zero-dependency RDF quad graph renderer (ESM, Canvas2D, ~650 LOC).
37
+ * <quad-graph> — zero-dependency RDF quad graph renderer (ESM, Canvas2D, ~670 LOC).
42
38
  *
43
39
  * import './quad-graph.js'
44
40
  * const element = document.createElement('quad-graph');
@@ -135,7 +131,8 @@ var Layout = class {
135
131
  this.theta = n > 5e4 ? 1.2 : n > 5e3 ? 1 : .85;
136
132
  this.relink();
137
133
  }
138
- /** Hubs get longer links (room for their leaves) and weaker springs (d3-style 1/min(deg)). */
134
+ /** Hubs get longer links (room for their leaves) and weaker springs (d3-style 1/min(deg)).
135
+ rdf:type edges use normal force for structure but are hidden visually. */
139
136
  relink() {
140
137
  const { ls, lt, deg, linkDist } = this, m = ls.length;
141
138
  this.len = new Float32Array(m);
@@ -386,17 +383,28 @@ canvas{position:absolute;inset:0;width:100%;height:100%;display:block;cursor:gra
386
383
  .hud{position:absolute;left:8px;top:6px;font:11px/1.2 system-ui,sans-serif;opacity:.6;pointer-events:none;display:flex;gap:8px;align-items:center;color:#ccc}
387
384
  .bar{width:44px;height:3px;border-radius:2px;background:#444;overflow:hidden}.bar i{display:block;height:100%;width:0;background:#1D9E75}
388
385
  .tip{position:absolute;left:0;top:0;pointer-events:none;max-width:320px;padding:6px 9px;border-radius:7px;font:12px/1.4 system-ui,sans-serif;background:#2a2a2a;color:#eee;border:1px solid #444;box-shadow:0 4px 16px #0003;display:none;z-index:2;overflow-wrap:anywhere}
389
- .tip b{display:block}.tip small{display:block;opacity:.6}`;
386
+ .tip b{display:block}.tip small{display:block;opacity:.6}
387
+ .graphs{position:absolute;right:8px;top:6px;font:11px/1.2 system-ui,sans-serif;background:#222;border:1px solid #444;border-radius:6px;padding:4px 8px;max-height:200px;overflow-y:auto;max-width:260px;opacity:.9;z-index:3}
388
+ .graphs.collapsed{max-width:auto}
389
+ .graphs.collapsed .graphs-list{display:none}
390
+ .graphs-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:4px;font-weight:600;color:#aaa}
391
+ .graphs-item{display:flex;align-items:center;gap:6px;padding:2px 0;cursor:pointer}
392
+ .graphs-item:hover{color:#fff}
393
+ .graphs-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:140px;flex:1}
394
+ .graphs-hidden{opacity:0.4}`;
390
395
  var QuadGraph = class extends Base {
391
396
  constructor() {
392
397
  super();
393
398
  const root = this.attachShadow({ mode: "open" });
394
- root.innerHTML = `<style>${CSS}</style><canvas></canvas><div class="hud"><span></span><div class="bar"><i></i></div></div><div class="tip"></div>`;
399
+ root.innerHTML = `<style>${CSS}</style><canvas></canvas><div class="hud"><span></span><div class="bar"><i></i></div></div><div class="tip"></div><div class="graphs"><div class="graphs-header"><span>Graphs</span><span class="graphs-toggle" style="cursor:pointer">▼</span></div><div class="graphs-list"></div></div>`;
395
400
  this._cv = root.querySelector("canvas");
396
401
  this._g2 = this._cv.getContext("2d");
397
402
  this._stat = root.querySelector(".hud span");
398
403
  this._bar = root.querySelector(".bar i");
399
404
  this._tip = root.querySelector(".tip");
405
+ this._graphsPanel = root.querySelector(".graphs");
406
+ this._graphsList = root.querySelector(".graphs-list");
407
+ this._graphsToggle = root.querySelector(".graphs-toggle");
400
408
  this._quads = [];
401
409
  this._pfx = [];
402
410
  this._L = new Layout();
@@ -437,6 +445,11 @@ var QuadGraph = class extends Base {
437
445
  this._pc = [];
438
446
  this._fill = [];
439
447
  this._ring = [];
448
+ this._graphs = [];
449
+ this._edgeGraph = /* @__PURE__ */ new Uint16Array(0);
450
+ this._nodeGraphs = [];
451
+ this._visibleGraphs = /* @__PURE__ */ new Set();
452
+ this._nodeVisible = /* @__PURE__ */ new Uint8Array(0);
440
453
  this._pOff = this._pList = this._cOff = this._cList = this._order = this._off = this._adj = /* @__PURE__ */ new Int32Array(0);
441
454
  this._bind();
442
455
  }
@@ -562,6 +575,7 @@ var QuadGraph = class extends Base {
562
575
  _ingest() {
563
576
  const ids = /* @__PURE__ */ new Map(), names = [], litN = [], typ = [], ls = [], lt = [], lp = [], lab = /* @__PURE__ */ new Map(), lits = /* @__PURE__ */ new Map();
564
577
  const classes = [null], classIdx = /* @__PURE__ */ new Map(), preds = [], predIdx = /* @__PURE__ */ new Map(), seen = /* @__PURE__ */ new Set();
578
+ const graphs = [], graphIdx = /* @__PURE__ */ new Map(), edgeGraph = [], nodeGraphs = [];
565
579
  const idOf = (t) => t.termType === "BlankNode" ? "_:" + t.value : t.value;
566
580
  const node = (id) => {
567
581
  let i = ids.get(id);
@@ -571,11 +585,20 @@ var QuadGraph = class extends Base {
571
585
  names.push(id);
572
586
  litN.push(0);
573
587
  typ.push(0);
588
+ nodeGraphs.push(/* @__PURE__ */ new Set());
574
589
  }
575
590
  return i;
576
591
  };
592
+ const graphOf = (g) => g.termType === "DefaultGraph" ? "default" : g.value;
577
593
  for (const q of this._quads) {
578
594
  if (!q || !q.subject || !q.predicate || !q.object) continue;
595
+ const g = graphOf(q.graph);
596
+ let gi = graphIdx.get(g);
597
+ if (gi === void 0) {
598
+ gi = graphs.length;
599
+ graphIdx.set(g, gi);
600
+ graphs.push(g);
601
+ }
579
602
  const o = q.object, p = q.predicate.value, sid = idOf(q.subject), si = node(sid);
580
603
  if (o.termType === "Literal") {
581
604
  litN[si]++;
@@ -604,6 +627,9 @@ var QuadGraph = class extends Base {
604
627
  ls.push(si);
605
628
  lt.push(ti);
606
629
  lp.push(pi);
630
+ edgeGraph.push(gi);
631
+ nodeGraphs[si].add(gi);
632
+ nodeGraphs[ti].add(gi);
607
633
  if (p === RDF_TYPE && o.termType === "NamedNode" && !typ[si]) {
608
634
  let c = classIdx.get(o.value);
609
635
  if (c === void 0) {
@@ -616,9 +642,44 @@ var QuadGraph = class extends Base {
616
642
  }
617
643
  for (let c = 1; c < classes.length; c++) {
618
644
  const i = ids.get(classes[c]);
619
- if (!typ[i]) typ[i] = c;
645
+ if (i !== void 0 && !typ[i]) typ[i] = c;
620
646
  }
621
647
  const n = names.length, m = ls.length, LS = Int32Array.from(ls), LT = Int32Array.from(lt), LP = Int32Array.from(lp);
648
+ const isType = new Uint8Array(m);
649
+ for (let e = 0; e < m; e++) if (preds[LP[e]] === RDF_TYPE) isType[e] = 1;
650
+ this._visibleGraphs = new Set(graphs.map((_, i) => i));
651
+ this._nodeVisible = new Uint8Array(n);
652
+ for (let i = 0; i < n; i++) {
653
+ this._nodeVisible[i] = 0;
654
+ for (const g of nodeGraphs[i]) if (this._visibleGraphs.has(g)) {
655
+ this._nodeVisible[i] = 1;
656
+ break;
657
+ }
658
+ }
659
+ if (graphs.length > 1) {
660
+ this._graphsPanel.classList.remove("collapsed");
661
+ this._graphsToggle.textContent = "▼";
662
+ this._graphsList.innerHTML = "";
663
+ graphs.map((_, i) => i).sort((a, b) => graphs[a].localeCompare(graphs[b])).forEach((i) => {
664
+ const g = graphs[i];
665
+ const div = document.createElement("div");
666
+ div.className = "graphs-item";
667
+ div.dataset.idx = i;
668
+ const dot = document.createElement("span");
669
+ dot.textContent = "●";
670
+ dot.style.color = this._visibleGraphs.has(i) ? "#1D9E75" : "#666";
671
+ const name = document.createElement("span");
672
+ name.className = "graphs-name";
673
+ name.textContent = g === "default" ? "default" : this._shortenGraphName(g);
674
+ name.title = g;
675
+ div.append(dot, name);
676
+ div.onclick = () => this._toggleGraph(i);
677
+ this._graphsList.appendChild(div);
678
+ });
679
+ } else {
680
+ this._graphsPanel.classList.add("collapsed");
681
+ this._graphsToggle.textContent = "▶";
682
+ }
622
683
  const off = new Int32Array(n + 1);
623
684
  for (let e = 0; e < m; e++) {
624
685
  off[LS[e] + 1]++;
@@ -681,6 +742,10 @@ var QuadGraph = class extends Base {
681
742
  _preds: preds,
682
743
  _bend: bend,
683
744
  _lp: LP,
745
+ _isType: isType,
746
+ _graphs: graphs,
747
+ _edgeGraph: Uint16Array.from(edgeGraph),
748
+ _nodeGraphs: nodeGraphs,
684
749
  _pOff: pOff,
685
750
  _pList: pList,
686
751
  _cOff: cOff,
@@ -716,6 +781,34 @@ var QuadGraph = class extends Base {
716
781
  } catch {}
717
782
  return s;
718
783
  }
784
+ _shortenGraphName(iri) {
785
+ const curie = this._curie(iri);
786
+ if (curie !== iri && curie.length <= 30) return curie;
787
+ if (iri.length <= 30) return iri;
788
+ const mid = Math.floor((iri.length - 10) / 2);
789
+ return iri.slice(0, 5) + "..." + iri.slice(-mid - 5);
790
+ }
791
+ _toggleGraph(idx) {
792
+ if (this._visibleGraphs.has(idx)) this._visibleGraphs.delete(idx);
793
+ else this._visibleGraphs.add(idx);
794
+ const n = this._L.n, nv = this._nodeVisible;
795
+ if (!n || !this._nodeGraphs.length) return;
796
+ for (let i = 0; i < n; i++) {
797
+ nv[i] = 0;
798
+ for (const g of this._nodeGraphs[i]) if (this._visibleGraphs.has(g)) {
799
+ nv[i] = 1;
800
+ break;
801
+ }
802
+ }
803
+ this._graphsList.querySelectorAll(".graphs-item").forEach((div) => {
804
+ const i = parseInt(div.dataset.idx, 10);
805
+ const dot = div.querySelector("span:first-child");
806
+ dot.style.color = this._visibleGraphs.has(i) ? "#1D9E75" : "#666";
807
+ div.classList.toggle("graphs-hidden", !this._visibleGraphs.has(i));
808
+ });
809
+ this._dirty = true;
810
+ this._wake();
811
+ }
719
812
  _label(i) {
720
813
  var _this$_lc;
721
814
  return (_this$_lc = this._lc)[i] ?? (_this$_lc[i] = this._lab.get(this._names[i])?.[0] ?? this._curie(this._names[i]));
@@ -827,7 +920,8 @@ var QuadGraph = class extends Base {
827
920
  const now = performance.now();
828
921
  if (now - this._ht > 150 || !more) {
829
922
  this._ht = now;
830
- const s = `${L.n.toLocaleString()} nodes · ${L.ls.length.toLocaleString()} links`;
923
+ const gcount = this._graphs.length;
924
+ const s = `${L.n.toLocaleString()} nodes · ${L.ls.length.toLocaleString()} links${gcount > 1 ? ` · ${gcount} graphs` : ""}`;
831
925
  if (s !== this._st) this._stat.textContent = this._st = s;
832
926
  this._bar.style.width = (more ? Math.min(1, L.alpha) * 100 : 0) + "%";
833
927
  }
@@ -840,10 +934,13 @@ var QuadGraph = class extends Base {
840
934
  if (!L.n) return;
841
935
  if (performance.now() - this._tt > 1e3) this._theme();
842
936
  const { x, y, r, ls, lt } = L, k = v.k, inv = 1 / k, E = ls.length, sel = this._sel, bend = this._bend;
937
+ this._isType;
843
938
  const x0 = -v.x * inv, y0 = -v.y * inv, x1 = (W - v.x) * inv, y1 = (H - v.y) * inv;
844
939
  g.setTransform(d * k, 0, 0, d * k, d * v.x, d * v.y);
845
940
  g.lineCap = "round";
846
941
  const addEdge = (e, ap) => {
942
+ if (!this._nodeVisible[ls[e]] || !this._nodeVisible[lt[e]]) return;
943
+ if (!this._visibleGraphs.has(this._edgeGraph[e])) return;
847
944
  const s = ls[e], t = lt[e], sx = x[s], sy = y[s], tx = x[t], ty = y[t];
848
945
  if (sx < x0 && tx < x0 || sx > x1 && tx > x1 || sy < y0 && ty < y0 || sy > y1 && ty > y1) return;
849
946
  const dx = tx - sx, dy = ty - sy, len = Math.sqrt(dx * dx + dy * dy) || 1e-6, ux = dx / len, uy = dy / len;
@@ -865,12 +962,13 @@ var QuadGraph = class extends Base {
865
962
  const ap = arrows ? new Path2D() : null;
866
963
  g.beginPath();
867
964
  for (let a = this._pOff[p]; a < this._pOff[p + 1]; a++) addEdge(this._pList[a], ap);
868
- g.globalAlpha = base;
869
- g.strokeStyle = this._pc[p];
965
+ const isTypePred = this._preds[p] === RDF_TYPE;
966
+ g.globalAlpha = isTypePred ? base * .33 : base;
967
+ g.strokeStyle = isTypePred ? "#666" : this._pc[p];
870
968
  g.stroke();
871
969
  if (ap) {
872
- g.globalAlpha = Math.min(1, base * 1.5);
873
- g.fillStyle = this._pc[p];
970
+ g.globalAlpha = Math.min(1, (isTypePred ? base * .25 : base) * 1.5);
971
+ g.fillStyle = isTypePred ? "#666" : this._pc[p];
874
972
  g.fill(ap);
875
973
  }
876
974
  }
@@ -880,7 +978,9 @@ var QuadGraph = class extends Base {
880
978
  for (let cl = 0; cl < this._fill.length; cl++) {
881
979
  g.beginPath();
882
980
  for (let a = this._cOff[cl]; a < this._cOff[cl + 1]; a++) {
883
- const i = this._cList[a], px = x[i], py = y[i], ri = r[i];
981
+ const i = this._cList[a];
982
+ if (!this._nodeVisible[i]) continue;
983
+ const px = x[i], py = y[i], ri = r[i];
884
984
  if (px + ri < x0 || px - ri > x1 || py + ri < y0 || py - ri > y1) continue;
885
985
  if (ri * k < 1) {
886
986
  const h = .9 * inv;
@@ -954,6 +1054,7 @@ var QuadGraph = class extends Base {
954
1054
  return true;
955
1055
  };
956
1056
  const put = (i, force) => {
1057
+ if (!this._nodeVisible[i]) return -1;
957
1058
  const sx = x[i] * k + v.x, sy = y[i] * k + v.y, rs = r[i] * k;
958
1059
  if (sx < -60 || sx > W + 60 || sy < -10 || sy > H + 30) return -1;
959
1060
  if (!force && rs < 2) return 0;
@@ -981,6 +1082,8 @@ var QuadGraph = class extends Base {
981
1082
  g.globalAlpha = .9;
982
1083
  g.lineWidth = 1;
983
1084
  for (let e = 0, cnt = 0; e < ls.length && cnt < 150; e++) {
1085
+ if (this._isType[e]) continue;
1086
+ if (!this._visibleGraphs.has(this._edgeGraph[e])) continue;
984
1087
  const s = ls[e], t = lt[e], dx = (x[t] - x[s]) * k, dy = (y[t] - y[s]) * k, len = Math.sqrt(dx * dx + dy * dy);
985
1088
  if (len < 70) continue;
986
1089
  const b = this._bend[e] * k, mx = (x[s] + x[t]) / 2 * k + v.x - dy / len * b, my = (y[s] + y[t]) / 2 * k + v.y + dx / len * b;
@@ -1055,10 +1158,13 @@ var QuadGraph = class extends Base {
1055
1158
  t.append(e);
1056
1159
  };
1057
1160
  add("b", this._label(i));
1058
- add("small", this._names[i]);
1059
1161
  const c = this._typ[i];
1060
1162
  if (c && this._classes[c] !== this._names[i]) add("small", "a " + this._curie(this._classes[c]));
1061
- for (const [p, val] of this._lits.get(i) || []) add("div", this._curie(p) + ": " + (val.length > 80 ? val.slice(0, 80) + "…" : val));
1163
+ add("small", this._names[i]);
1164
+ for (const [p, val] of this._lits.get(i) || []) {
1165
+ const short = val.length > 200 ? val.slice(0, 200) + "…" : val;
1166
+ add("div", this._curie(p) + ": " + short);
1167
+ }
1062
1168
  add("small", this._L.deg[i] + " links");
1063
1169
  }
1064
1170
  t.style.display = "block";
@@ -1190,6 +1296,10 @@ var QuadGraph = class extends Base {
1190
1296
  }
1191
1297
  this._showTip(-1);
1192
1298
  });
1299
+ this._graphsToggle.addEventListener("click", () => {
1300
+ this._graphsPanel.classList.toggle("collapsed");
1301
+ this._graphsToggle.textContent = this._graphsPanel.classList.contains("collapsed") ? "▶" : "▼";
1302
+ });
1193
1303
  cv.addEventListener("dblclick", (e) => {
1194
1304
  const p = this._xy(e), i = this._pick(p.x, p.y);
1195
1305
  if (i >= 0) {
@@ -1215,5 +1325,4 @@ _defineProperty(QuadGraph, "observedAttributes", [
1215
1325
  "labels"
1216
1326
  ]);
1217
1327
  if (typeof customElements !== "undefined" && !customElements.get("quad-graph")) customElements.define("quad-graph", QuadGraph);
1218
- //#endregion
1219
1328
  export { Layout, QuadGraph, QuadGraph as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdld-parse",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Write RDF knowledge graphs as plain Markdown. Parse to quads, generate back, merge documents. The human-friendly semantic web format.",
5
5
  "keywords": [
6
6
  "rdf",
@@ -50,19 +50,19 @@
50
50
  "url": "https://github.com/davay42/mdld-parse/issues"
51
51
  },
52
52
  "devDependencies": {
53
- "@unocss/extractor-pug": "^66.10.2",
54
- "@vitejs/plugin-vue": "^6.0.8",
55
- "@vueuse/core": "^14.4.0",
56
- "codejar": "^4.3.0",
57
- "markdown-it": "^15.0.2",
58
- "n3": "^2.7.12",
53
+ "@unocss/extractor-pug": "^66.13.0",
54
+ "@vitejs/plugin-vue": "^6.0.11",
55
+ "@vueuse/core": "^15.0.0",
56
+ "codejar": "^5.0.0",
57
+ "markdown-it": "^15.0.3",
58
+ "n3": "^2.13.12",
59
59
  "rdfa-parse": "^1.0.1",
60
- "shiki": "^4.4.3",
61
- "unocss": "^66.10.2",
62
- "vite": "^8.3.0",
63
- "vite-plugin-singlefile": "^2.3.3",
60
+ "shiki": "^4.6.0",
61
+ "unocss": "^66.13.0",
62
+ "vite": "^8.3.8",
63
+ "vite-plugin-singlefile": "^2.3.4",
64
64
  "vscode-textmate": "^9.3.2",
65
65
  "vue": "^3.6.0-beta.17"
66
66
  },
67
- "packageManager": "pnpm@11.26.0+sha512.fc0e2bf890b9f983611f1ab68c0637bce914390653699f83c1a78b005ed25f2c81e77920c8fd8eee2ecf0b58b28cdcb00a84d97f69bcf7c56b2f344710238664"
68
- }
67
+ "packageManager": "pnpm@12.21.0+sha512.66fd8278ee28935ce951792d34367ff3af5c432a2756445823029533835b8da529bbe0be5130afd56ed0713fb8789e47bad82d93bd5ae2fe54b15562d6276ef0"
68
+ }