@kanonak-protocol/sdk 3.28.4 → 3.28.5
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/chunk-QYWXCEHO.js +50 -0
- package/dist/index.js +1 -1
- package/dist/look/LookRenderer.d.ts +24 -2
- package/dist/transformations/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-GHMIWHWF.js +0 -47
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import{a as P}from"./chunk-NIGFQYVA.js";import{a as U}from"./chunk-QIIQ4G2Q.js";import{c as R,d as p,g as K,j as k,k as T,l as g}from"./chunk-W6T7MOKY.js";function z(i){let e=i.replace(/\r\n/g,`
|
|
2
|
+
`).split(`
|
|
3
|
+
`),t=[],n=0;for(;n<e.length;){let s=e[n];if(s.trim()===""){n++;continue}let r=/^(\s*)```(\S*)\s*$/.exec(s);if(r){let u=r[2],c=[];for(n++;n<e.length&&!/^(\s*)```\s*$/.test(e[n]);)c.push(e[n]),n++;n++;let f=J(c.join(`
|
|
4
|
+
`)),d=u?` class="language-${Q(u)}"`:"";t.push(`<pre><code${d}>${f}</code></pre>`);continue}let o=/^(#{1,6})\s+(.*)$/.exec(s);if(o){let u=o[1].length,c=L(o[2].trim());t.push(`<h${u}>${c}</h${u}>`),n++;continue}if(s.includes("|")&&n+1<e.length&&Y(e[n+1])){let u=N(s),c=ue(e[n+1]);n+=2;let f=[];for(;n<e.length&&e[n].trim()!==""&&e[n].includes("|");)f.push(N(e[n])),n++;t.push(fe(u,c,f));continue}if(/^\s*[-*]\s+/.test(s)){let u=[];for(;n<e.length&&/^\s*[-*]\s+/.test(e[n]);){let c=[e[n].replace(/^\s*[-*]\s+/,"")];for(n++;n<e.length&&e[n].trim()!==""&&!/^\s*[-*]\s+/.test(e[n])&&!/^\s*\d+\.\s+/.test(e[n]);)c.push(e[n]),n++;n<e.length&&e[n].trim()===""&&n++,u.push(`<li>${L(c.join(" ").trim())}</li>`)}t.push(`<ul>
|
|
5
|
+
${u.join(`
|
|
6
|
+
`)}
|
|
7
|
+
</ul>`);continue}if(/^\s*\d+\.\s+/.test(s)){let u=[];for(;n<e.length&&/^\s*\d+\.\s+/.test(e[n]);){let c=[e[n].replace(/^\s*\d+\.\s+/,"")];for(n++;n<e.length&&e[n].trim()!==""&&!/^\s*\d+\.\s+/.test(e[n])&&!/^\s*[-*]\s+/.test(e[n]);)c.push(e[n]),n++;n<e.length&&e[n].trim()===""&&n++,u.push(`<li>${L(c.join(" ").trim())}</li>`)}t.push(`<ol>
|
|
8
|
+
${u.join(`
|
|
9
|
+
`)}
|
|
10
|
+
</ol>`);continue}let a=[s];for(n++;n<e.length&&e[n].trim()!==""&&!/^(#{1,6})\s+/.test(e[n])&&!/^(\s*)```/.test(e[n])&&!/^\s*[-*]\s+/.test(e[n])&&!/^\s*\d+\.\s+/.test(e[n])&&!(e[n].includes("|")&&n+1<e.length&&Y(e[n+1]));)a.push(e[n]),n++;t.push(`<p>${L(a.join(" "))}</p>`)}return t.join(`
|
|
11
|
+
`)}function Y(i){return i.includes("-")?/^[\s|:-]+$/.test(i):!1}function N(i){let e=i.trim();return e.startsWith("|")&&(e=e.slice(1)),e.endsWith("|")&&(e=e.slice(0,-1)),e.split("|").map(t=>t.trim())}function ue(i){return N(i).map(e=>{let t=e.startsWith(":"),n=e.endsWith(":");return t&&n?"center":n?"right":t?"left":null})}function fe(i,e,t){let n=o=>{let a=e[o];return a?` style="text-align:${a}"`:""},s=i.map((o,a)=>`<th${n(a)}>${L(o)}</th>`).join(""),r=t.map(o=>`<tr>${o.map((u,c)=>`<td${n(c)}>${L(u)}</td>`).join("")}</tr>`).join(`
|
|
12
|
+
`);return`<table>
|
|
13
|
+
<thead><tr>${s}</tr></thead>
|
|
14
|
+
<tbody>
|
|
15
|
+
${r}
|
|
16
|
+
</tbody>
|
|
17
|
+
</table>`}function L(i){let e=J(i);return e=e.replace(/`([^`\n]+)`/g,(t,n)=>`<code>${n}</code>`),e=e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(t,n,s)=>`<a href="${Q(s)}">${n}</a>`),e=e.replace(/\*\*([^*\n]+)\*\*/g,(t,n)=>`<strong>${n}</strong>`),e=e.replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g,(t,n,s)=>`${n}<em>${s}</em>`),e=e.replace(/(^|[\s(])_([^_\n]+)_(?=[\s).,;:!?]|$)/g,(t,n,s)=>`${n}<em>${s}</em>`),e}function J(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Q(i){return i.replace(/"/g,""").replace(/&/g,"&")}var C={publisher:"kanonak.org",package_:"derivation",name:"look"},V={publisher:"kanonak.org",package_:"derivation",name:"tokens"},O={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},I={publisher:"kanonak.org",package_:"core-rdf",name:"label"},X={publisher:"kanonak.org",package_:"core-rdf",name:"comment"},le={publisher:"kanonak.org",package_:"look",name:"Hero"},pe={publisher:"kanonak.org",package_:"look",name:"PropertyList"},de={publisher:"kanonak.org",package_:"look",name:"BadgeRow"},ke={publisher:"kanonak.org",package_:"look",name:"ChipRow"},ge={publisher:"kanonak.org",package_:"look",name:"ReferenceList"},Z={publisher:"kanonak.org",package_:"look",name:"Markdown"},F={publisher:"kanonak.org",package_:"look",name:"NavGroup"},B={publisher:"kanonak.org",package_:"look",name:"NavLink"},ee={publisher:"kanonak.org",package_:"look",name:"target"},he={publisher:"kanonak.org",package_:"look",name:"ResourceGrid"};var A={publisher:"kanonak.org",package_:"look",name:"bands"},me={publisher:"kanonak.org",package_:"look",name:"title"},be={publisher:"kanonak.org",package_:"look",name:"eyebrow"},je={publisher:"kanonak.org",package_:"look",name:"subtitle"},ne={publisher:"kanonak.org",package_:"look",name:"badges"},v={publisher:"kanonak.org",package_:"look",name:"source"},_e={publisher:"kanonak.org",package_:"look",name:"chips"},G={publisher:"kanonak.org",package_:"look",name:"entries"},Re={publisher:"kanonak.org",package_:"look",name:"urlForm"},x=class{constructor(e){this.catalog=e}catalog;findCascadedLook(e){let t=M(e);if(t)return{declaration:t,sourceClass:{publisher:w(e),package_:(e.namespace||"").split("/")[1]?.split("@")[0]??"",name:e.name}};let n=new Set,s=S(e);for(;s.length>0;){let r=s.shift(),o=E(r.subject);if(n.has(o))continue;n.add(o);let a=m(this.catalog,r.subject);if(!a)continue;let u=M(a);if(u)return{declaration:u,sourceClass:{publisher:r.subject.publisher,package_:r.subject.package_,name:r.subject.name}};for(let c of D(a))s.push(c)}if(!n.has(E(O))){let r=m(this.catalog,O);if(r){let o=M(r);if(o)return{declaration:o,sourceClass:{...O}}}}}findCascadedTokens(e){let t=new Map;for(let[r,o]of H(e))t.has(r)||t.set(r,o);let n=new Set,s=S(e);for(;s.length>0;){let r=s.shift(),o=E(r.subject);if(n.has(o))continue;n.add(o);let a=oe(this.catalog,r.subject);if(a.length!==0)for(let u of a){for(let[c,f]of H(u))t.has(c)||t.set(c,f);for(let c of D(u))s.push(c)}}if(!n.has(E(O))){let r=oe(this.catalog,O);for(let o of r)for(let[a,u]of H(o))t.has(a)||t.set(a,u)}return t}renderStylesheet(e){let t=this.findCascadedTokens(e),n=[];for(let[o,a]of t)n.push(` --kan-${o}: ${a};`);let s=n.length>0?`:root {
|
|
18
|
+
${n.join(`
|
|
19
|
+
`)}
|
|
20
|
+
}`:":root { /* no tokens resolved */ }",r=this.findBaseStylesheet(w(e))??"";return`${s}
|
|
21
|
+
${r}`}findBaseStylesheet(e){let t="kanonak.org/site/content",n,s;for(let o of this.catalog){if(!(o instanceof R)||o.name!=="base-stylesheet")continue;let a=o.namespace||"";a.startsWith(`${e}/look-styles@`)?n=o:a.startsWith("kanonak.org/look-styles@")&&(s=o)}let r=n??s;if(r)for(let o of r.statement){let a=o.predicate?.subject;if(!a)continue;if(`${a.publisher}/${a.package_}/${a.name}`===t&&o instanceof K)return o.object}}renderHtml(e){let t=this.findCascadedLook(e);if(!t)return`<!-- LookRenderer: no derivation.look found for ${e.namespace}/${e.name} -->`;let n=te(t.declaration);if(n.length===0)return"<!-- LookRenderer: look declaration has no bands -->";let s=w(e),r=[];for(let o of n)r.push(this.renderBand(o,e,s));return r.join(`
|
|
22
|
+
`)}renderDocument(e){let t=this.renderHtml(e),n=this.readPropertyValueText(e,I)??e.name,s=`${e.name}.css`,r=this.hasSvgDerivation(e)?`<figure class="kan-figure"><img src="${l(e.name)}.svg" alt=""></figure>
|
|
23
|
+
`:"",o=w(e),a=this.renderNavGroup(e,o);return`<!doctype html>
|
|
24
|
+
<html lang="en">
|
|
25
|
+
<head>
|
|
26
|
+
<meta charset="utf-8">
|
|
27
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
28
|
+
<title>${l(n)}</title>
|
|
29
|
+
<link rel="stylesheet" href="${l(s)}">
|
|
30
|
+
</head>
|
|
31
|
+
<body>
|
|
32
|
+
${a}
|
|
33
|
+
<main class="kan-main">
|
|
34
|
+
${r}${t}
|
|
35
|
+
</main>
|
|
36
|
+
</body>
|
|
37
|
+
</html>
|
|
38
|
+
`}hasSvgDerivation(e){let t=new Set,n=S(e);for(;n.length>0;){let s=n.shift(),r=E(s.subject);if(t.has(r))continue;t.add(r);let o=m(this.catalog,s.subject);if(o){for(let a of o.statement)if(a instanceof g&&j(a,"kanonak.org","derivation","derivations")){for(let u of a.object??[])if(u instanceof U)for(let c of u.statement){if(!(c instanceof k)||!j(c,"kanonak.org","derivation","format")||!(c.object instanceof p))continue;let f=c.object.subject;if(f.publisher==="kanonak.org"&&f.package_==="formats"&&f.name==="svg")return!0}}for(let a of D(o))n.push(a)}}return!1}renderBand(e,t,n){let s=se(e);return s?b(s,le)?this.renderHero(e,t,n):b(s,pe)?this.renderPropertyList(e,t,n):b(s,de)?this.renderBadgeRow(e,t,n):b(s,ke)?this.renderChipRow(e,t,n):b(s,ge)?this.renderReferenceList(e,t,n):b(s,Z)?this.renderMarkdown(e,t):b(s,F)?this.renderNavGroup(t,n):b(s,he)?this.renderResourceGrid(e,n,t):`<!-- LookRenderer: unsupported band ${s.publisher}/${s.package_}/${s.name} -->`:"<!-- LookRenderer: band has no rdf:type -->"}renderResourceGrid(e,t,n){let s=h(e,v);if(!s)return"<!-- LookRenderer.ResourceGrid: no look.source -->";let r=m(this.catalog,s),o=r?S(r).some(c=>{let f=c.subject.name;return f==="ObjectProperty"||f==="DatatypeProperty"||f==="Property"}):!1,a=[];if(o&&n){let c=this.readPropertyValueReferences(n,s);for(let f of c){let d=m(this.catalog,{publisher:f.subject.publisher,package_:f.subject.package_,name:f.subject.name,...f.subject.version?{version:f.subject.version}:{}});d&&a.push(d)}}else a=this.findInstancesOfClass(s);if(a.length===0)return`<!-- LookRenderer.ResourceGrid: no resources for ${s.publisher}/${s.package_}/${s.name} -->`;let u=[];for(let c of a){let f=$(c,I)??c.name,d=$(c,X),_=c.namespace||"",ae=_.split("/")[1]?.split("@")[0]??"",W=_.split("@")[1]??"",q=W?this.parseVersion(W):void 0,ie=P.formatResourceUrl({publisher:w(c),package_:ae,name:c.name,...q?{version:q}:{}},"=",{contextPublisher:t}),ce=d?`<p class="kan-resource-card-subtitle">${l(d)}</p>`:"";u.push(`<a class="kan-resource-card" href="${l(ie)}"><h3 class="kan-resource-card-title">${l(f)}</h3>${ce}</a>`)}return`<section class="kan-resource-grid">
|
|
39
|
+
${u.join(`
|
|
40
|
+
`)}
|
|
41
|
+
</section>`}parseVersion(e){let t=e.split(".").map(Number);if(!(t.length!==3||t.some(n=>Number.isNaN(n))))return{major:t[0],minor:t[1],patch:t[2]}}findInstancesOfClass(e){let t=[];for(let n of this.catalog){if(!(n instanceof R))continue;S(n).map(o=>o.subject).some(o=>o.publisher===e.publisher&&o.package_===e.package_&&o.name===e.name)&&t.push(n)}return t}renderNavGroup(e,t){let n=this.findNavGroupForPublisher(t);if(!n)return"";let s=y(n,G);if(!(s instanceof g))return"";let r=s.object??[];if(r.length===0)return"";let o=[];for(let a of r){if(!(a instanceof p))continue;let u=m(this.catalog,{publisher:a.subject.publisher,package_:a.subject.package_,name:a.subject.name}),{href:c,label:f}=this.resolveNavEntry(a,u,t),d=`/${e.namespace?.split("/")[1]?.split("@")[0]}/${(e.namespace||"").split("@")[1]}/${e.name}`,_=c===d?' aria-current="page"':"";o.push(`<li><a class="kan-nav-link" href="${l(c)}"${_}>${l(f)}</a></li>`)}return`<nav class="kan-site-nav"><ul>
|
|
42
|
+
${o.join(`
|
|
43
|
+
`)}
|
|
44
|
+
</ul></nav>`}resolveNavEntry(e,t,n){if(t&&S(t).map(u=>u.subject).some(u=>u.publisher===B.publisher&&u.package_===B.package_&&u.name===B.name)){let u=$(t,I),c=y(t,ee);if(c instanceof k&&c.object instanceof p){let f=c.object,d=this.readLabelForUri({publisher:f.subject.publisher,package_:f.subject.package_,name:f.subject.name});return{href:this.urlForReference(f,ee,n),label:u??d??f.subject.name}}}let s=P.formatResourceUrl({publisher:e.subject.publisher,package_:e.subject.package_,...e.subject.version?{version:e.subject.version}:{},name:e.subject.name},"*",{contextPublisher:n}),r=t?$(t,I)??e.subject.name:e.subject.name;return{href:s,label:r}}findNavGroupForPublisher(e){for(let t of this.catalog){if(!(t instanceof R)||!(t.namespace||"").startsWith(`${e}/`))continue;if(S(t).map(o=>o.subject).some(o=>o.publisher===F.publisher&&o.package_===F.package_&&o.name===F.name))return t}}renderMarkdown(e,t){let n=h(e,v);if(!n)return"<!-- LookRenderer.Markdown: no look.source -->";let s=this.readPropertyValueText(t,n);return s?`<section class="kan-markdown">
|
|
45
|
+
${z(s)}
|
|
46
|
+
</section>`:""}renderRawMarkdown(e){let t=this.findCascadedLook(e);if(!t)return;let n=te(t.declaration),s=[];for(let r of n){let o=se(r);if(!o||!b(o,Z))continue;let a=h(r,v);if(!a)continue;let u=this.readPropertyValueText(e,a);u&&s.push(u)}return s.length>0?s.join(`
|
|
47
|
+
|
|
48
|
+
`):void 0}renderHero(e,t,n){let s=['<header class="kan-hero">'],r=h(e,be);if(r){let f=this.readPropertyValueText(t,r);f&&s.push(`<span class="kan-hero-eyebrow">${l(f)}</span>`)}let o=h(e,me),a="";o&&(a=this.readPropertyValueText(t,o)??""),a||(a=t.name),s.push(`<h1 class="kan-hero-title">${l(a)}</h1>`);let u=h(e,je);if(u){let f=this.readPropertyValueText(t,u);f&&s.push(`<p class="kan-hero-subtitle">${l(f)}</p>`)}let c=h(e,ne);if(c){let f=this.readPropertyValueReferences(t,c);if(f.length>0){let d=f.map(_=>this.renderBadge(_,ne,n)).join("");s.push(`<div class="kan-hero-badges">${d}</div>`)}}return s.push("</header>"),s.join(`
|
|
49
|
+
`)}renderPropertyList(e,t,n){let s=h(e,v);if(!s)return"<!-- LookRenderer: PropertyList missing look.source -->";let r=this.readLabelForUri(s)??s.name,o=y(t,s),a=this.gatherValueItems(o),u=a.length>0?a.map(c=>`<li>${this.renderInlineValue(c,v,n)}</li>`).join(""):'<li class="kan-empty">(no values)</li>';return['<section class="kan-property-list">',`<h3 class="kan-property-list-title">${l(r)}</h3>`,`<ul class="kan-property-list-items">${u}</ul>`,"</section>"].join(`
|
|
50
|
+
`)}renderBadgeRow(e,t,n){let s=h(e,v);if(!s)return"<!-- LookRenderer: BadgeRow missing look.source -->";let r=this.readPropertyValueReferences(t,s);return r.length===0?"":`<div class="kan-badge-row">${r.map(a=>this.renderBadge(a,v,n)).join("")}</div>`}renderChipRow(e,t,n){let s=re(e,_e);if(s.length===0)return"<!-- LookRenderer: ChipRow has no look.chips -->";let r=[];for(let o of s){let a=y(t,o);if(!a)continue;let u=this.readLabelForUri(o)??o.name,c=this.renderStatementInlineValue(a,o,n);c&&r.push(`<span class="kan-chip"><span class="kan-chip-key">${l(u)}</span> <span class="kan-chip-val">${c}</span></span>`)}return r.length===0?"":`<div class="kan-chip-row">${r.join("")}</div>`}renderReferenceList(e,t,n){let s=re(e,G);if(s.length===0)return"<!-- LookRenderer: ReferenceList has no look.entries -->";let r=[];for(let o of s){let a=this.readPropertyValueReferences(t,o);if(a.length===0)continue;let u=this.readLabelForUri(o)??o.name,c=a.map(f=>this.renderReferenceLink(f,G,n)).join(", ");r.push(`<dt>${l(u)}</dt><dd>${c}</dd>`)}return r.length===0?"":`<dl class="kan-reference-list">${r.join("")}</dl>`}readPropertyValueText(e,t){let n=y(e,t);if(n){if(n instanceof K)return n.object;if(n instanceof k){let s=n.object;return this.readLabelForUri({publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name})??s.subject.name}if(n instanceof g)return(n.object??[]).map(r=>r instanceof p?this.readLabelForUri({publisher:r.subject.publisher,package_:r.subject.package_,name:r.subject.name})??r.subject.name:r instanceof U?r.name??"":String(r)).filter(r=>r).join(", ")}}readPropertyValueReferences(e,t){let n=y(e,t);if(!n)return[];if(n instanceof k)return[n.object];if(n instanceof g){let s=[];for(let r of n.object??[])r instanceof p&&s.push(r);return s}return[]}gatherValueItems(e){return e?e instanceof g?e.object??[]:e instanceof k?[e.object]:e instanceof T?[e.object]:e instanceof K?[e.object]:[]:[]}renderInlineValue(e,t,n){return e instanceof p?this.renderReferenceLink(e,t,n):e instanceof U?l(e.name??"(embedded)"):typeof e=="string"?l(e):typeof e=="number"||typeof e=="boolean"?l(String(e)):""}renderStatementInlineValue(e,t,n){return e instanceof K?l(e.object):e instanceof k?this.renderReferenceLink(e.object,t,n):e instanceof g?(e.object??[]).map(r=>this.renderInlineValue(r,t,n)).filter(r=>r).join(", "):""}renderReferenceLink(e,t,n){let s=this.readLabelForUri({publisher:e.subject.publisher,package_:e.subject.package_,name:e.subject.name})??e.subject.name,r=this.urlForReference(e,t,n);return`<a class="kan-link" href="${l(r)}">${l(s)}</a>`}renderBadge(e,t,n){let s=this.readLabelForUri({publisher:e.subject.publisher,package_:e.subject.package_,name:e.subject.name})??e.subject.name,r=this.readCommentForUri({publisher:e.subject.publisher,package_:e.subject.package_,name:e.subject.name}),o=this.urlForReference(e,t,n),a=r?` title="${l(r)}"`:"";return`<a class="kan-badge" href="${l(o)}"${a}>${l(s)}</a>`}urlForReference(e,t,n){let s=t?this.getUrlFormForProperty(t):"=";return P.formatResourceUrl({publisher:e.subject.publisher,package_:e.subject.package_,...e.subject.version?{version:e.subject.version}:{},name:e.subject.name},s,{contextPublisher:n})}getUrlFormForProperty(e){let t=m(this.catalog,e);if(!t)return"=";let n=$(t,Re);return n==="*"||n==="^"||n==="~"||n==="="?n:"="}readLabelForUri(e){let t=m(this.catalog,e);if(t)return $(t,I)}readCommentForUri(e){let t=m(this.catalog,e);if(t)return $(t,X)}};function H(i){let e=new Map;for(let t of i.statement){if(!(t instanceof T)||!j(t,V.publisher,V.package_,V.name))continue;let n=t.object;for(let s of n.statement){if(!(s instanceof K))continue;let r=s.predicate?.subject?.name;if(!r)continue;let o=s.object;e.has(r)||e.set(r,o)}}return e}function M(i){for(let e of i.statement)if(e instanceof T&&j(e,C.publisher,C.package_,C.name))return e.object}function te(i){for(let e of i.statement){if(!(e instanceof g)||!j(e,A.publisher,A.package_,A.name))continue;let t=[];for(let n of e.object??[])n instanceof U&&t.push(n);return t}return[]}function se(i){for(let e of i.statement)if(e instanceof k&&e.predicate?.subject?.name==="type"&&e.object instanceof p){let t=e.object.subject;return{publisher:t.publisher,package_:t.package_,name:t.name}}}function h(i,e){for(let t of i.statement)if(t instanceof k&&j(t,e.publisher,e.package_,e.name)&&t.object instanceof p){let n=t.object.subject;return{publisher:n.publisher,package_:n.package_,name:n.name}}}function re(i,e){for(let t of i.statement){if(!(t instanceof g)||!j(t,e.publisher,e.package_,e.name))continue;let n=[];for(let s of t.object??[])s instanceof p&&n.push({publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name});return n}return[]}function y(i,e){for(let t of i.statement)if(j(t,e.publisher,e.package_,e.name))return t}function $(i,e){for(let t of i.statement)if(t instanceof K&&j(t,e.publisher,e.package_,e.name))return t.object}function S(i){let e=[];for(let t of i.statement)if(t instanceof k){if(t.predicate?.subject?.name!=="type")continue;t.object instanceof p&&e.push(t.object)}else if(t instanceof g){if(t.predicate?.subject?.name!=="type")continue;for(let n of t.object??[])n instanceof p&&e.push(n)}return e}function D(i){let e=[];for(let t of i.statement)if(t instanceof k){if(t.predicate?.subject?.name!=="subClassOf")continue;t.object instanceof p&&e.push(t.object)}else if(t instanceof g){if(t.predicate?.subject?.name!=="subClassOf")continue;for(let n of t.object??[])n instanceof p&&e.push(n)}return e}function oe(i,e){let t=[];for(let n of i){if(!(n instanceof R)||n.name!==e.name)continue;(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&t.push(n)}return t}function m(i,e){let t="version"in e?e.version:void 0;if(t){let n=`${e.publisher}/${e.package_}@${t.major}.${t.minor}.${t.patch}`;for(let s of i)if(s instanceof R&&s.name===e.name&&s.namespace===n)return s}for(let n of i){if(!(n instanceof R)||n.name!==e.name)continue;if((n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))return n}}function j(i,e,t,n){let s=i.predicate?.subject;return s?s.publisher===e&&s.package_===t&&s.name===n:!1}function b(i,e){return i.publisher===e.publisher&&i.package_===e.package_&&i.name===e.name}function E(i){return`${i.publisher}/${i.package_}/${i.name}`}function w(i){let e=i.namespace||"",t=e.indexOf("/");return t>=0?e.substring(0,t):e}function l(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}export{z as a,x as b};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Ze,b as Qe,c as et,d as tt,e as rt,f as nt,g as ot,h as at,i as it,j as st}from"./chunk-JLFC6WKB.js";import{b as Yt}from"./chunk-
|
|
1
|
+
import{a as Ze,b as Qe,c as et,d as tt,e as rt,f as nt,g as ot,h as at,i as it,j as st}from"./chunk-JLFC6WKB.js";import{b as Yt}from"./chunk-QYWXCEHO.js";import{a as qe,b as Ye,c as Xe,d as b,e as S,f as i}from"./chunk-POFL6NMI.js";import{a as qt}from"./chunk-BQOD26BC.js";import{a as Te,b as je,c as Le,d as Fe,e as Ne}from"./chunk-AZSZXLEH.js";import{a as Be,b as De,c as Oe,d as Ae}from"./chunk-AV4AVTI6.js";import{a as lt,b as dt,c as ut,d as pt}from"./chunk-TWIWVG7W.js";import{a as Je,b as mt,c as ft,d as yt,e as ht}from"./chunk-4TJZIM7A.js";import{a as gt}from"./chunk-NIGFQYVA.js";import{A as Mt,B as zt,C as Gt,D as Wt,E as Jt,a as kt,b as bt,c as St,d as Ct,e as Pt,f as Rt,g as wt,h as xt,i as $t,j as vt,k as Et,l as Kt,m as Bt,n as It,o as Tt,p as jt,q as Lt,r as Ft,s as Nt,t as Dt,u as Ot,v as At,w as Ut,x as Vt,y as Ht,z as _t}from"./chunk-MV2LZFUK.js";import"./chunk-FJ35VIV6.js";import{a as F,b as D,c as Me,e as We}from"./chunk-QIIQ4G2Q.js";import{a as Ue,b as j,c as L,d as N,e as He,f as _e,g as O,h as A,i as U,j as V,k as H,l as _}from"./chunk-W6T7MOKY.js";import{a as Ie}from"./chunk-MYITGTGJ.js";import{a as Pe,b as Re,c as we,d as xe,e as $e,f as ve,g as Ee,h as Ke}from"./chunk-FQHALFRR.js";import{b as ze,c as Ge}from"./chunk-5ILSX24H.js";import{a as Ve}from"./chunk-FUUTGGJS.js";import{a as ct}from"./chunk-ODIECDN7.js";import{VersionOperator as oo}from"@kanonak-protocol/types/document/models/enums";import{existsSync as fr,readFileSync as yr}from"fs";import{homedir as gr}from"os";import{join as hr}from"path";import{execFile as Xt}from"child_process";import{promisify as Zt}from"util";var C=Zt(Xt),P="kanonak",R="/usr/bin/security",p=class{async get(e){let r=i(e);try{let{stdout:n}=await C(R,["find-generic-password","-s",P,"-a",r,"-w"],{timeout:1e4});try{return JSON.parse(n.trim())}catch{throw new Error(`Stored credential for '${r}' is corrupted (not valid JSON).
|
|
2
2
|
Run 'kanonak logout ${r}' then 'kanonak login ${r}' to fix.`)}}catch(n){if(X(n,44))return null;throw new Error(`macOS Keychain read failed for '${r}': ${w(n)}
|
|
3
3
|
The Keychain may be locked or inaccessible.
|
|
4
4
|
Try unlocking it via Keychain Access.app or running 'security unlock-keychain'.`)}}async store(e,r){let n=i(e),o=JSON.stringify(r);try{await C(R,["add-generic-password","-s",P,"-a",n,"-U","-w",o],{timeout:1e4})}catch(a){throw new Error(`macOS Keychain write failed for '${n}': ${w(a)}
|
|
@@ -42,8 +42,11 @@ export declare class LookRenderer {
|
|
|
42
42
|
constructor(catalog: Kanonak[]);
|
|
43
43
|
/**
|
|
44
44
|
* Walk the instance's type chain (BFS) looking for the first class
|
|
45
|
-
* that declares `derivation.look`.
|
|
46
|
-
*
|
|
45
|
+
* that declares `derivation.look`. Checks the instance itself first
|
|
46
|
+
* so instance-level look declarations override class-level ones —
|
|
47
|
+
* the same instance-replace semantics derivation.derivations uses.
|
|
48
|
+
* Falls through to `rdfs.Resource` at the root if nothing closer
|
|
49
|
+
* declares one.
|
|
47
50
|
*/
|
|
48
51
|
findCascadedLook(instance: SubjectKanonak): ResolvedLook | undefined;
|
|
49
52
|
/**
|
|
@@ -103,6 +106,25 @@ export declare class LookRenderer {
|
|
|
103
106
|
*/
|
|
104
107
|
private hasSvgDerivation;
|
|
105
108
|
private renderBand;
|
|
109
|
+
/**
|
|
110
|
+
* Render a ResourceGrid band — enumerates every instance of the class
|
|
111
|
+
* named by `look.source` and emits a grid of cards. Each card shows
|
|
112
|
+
* the instance's rdfs.label as title, rdfs.comment as subtitle, and
|
|
113
|
+
* links to the instance's canonical URL.
|
|
114
|
+
*
|
|
115
|
+
* This is the minimal viable implementation. The look vocabulary's
|
|
116
|
+
* stated full design ("renders the resource's own derivation.look in
|
|
117
|
+
* compact variant") is deferred — that requires a variant system.
|
|
118
|
+
*/
|
|
119
|
+
private renderResourceGrid;
|
|
120
|
+
private parseVersion;
|
|
121
|
+
/**
|
|
122
|
+
* Find every SubjectKanonak in the catalog whose declared `rdf:type` set
|
|
123
|
+
* includes the given class URI (canonical, version-agnostic). Used by
|
|
124
|
+
* ResourceGrid to enumerate instances for the grid. Skips the class
|
|
125
|
+
* itself and other classes.
|
|
126
|
+
*/
|
|
127
|
+
private findInstancesOfClass;
|
|
106
128
|
/**
|
|
107
129
|
* Render the publisher's site navigation. The instance is the page
|
|
108
130
|
* the band is being rendered on; the NavGroup itself is discovered
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as E,c as F,d as f,f as M}from"../chunk-2JQMUZWN.js";import{a as X,b as ye}from"../chunk-
|
|
1
|
+
import{b as E,c as F,d as f,f as M}from"../chunk-2JQMUZWN.js";import{a as X,b as ye}from"../chunk-QYWXCEHO.js";import{a as Oe}from"../chunk-BQOD26BC.js";import"../chunk-TWIWVG7W.js";import"../chunk-NIGFQYVA.js";import{a as Ue}from"../chunk-FJ35VIV6.js";import{a as C,c as Re,e as Ce}from"../chunk-QIIQ4G2Q.js";import{b as K,c as w,d as b,g as L,h as U,i as O,j,k as T,l as S}from"../chunk-W6T7MOKY.js";import{a as Le}from"../chunk-MYITGTGJ.js";import"../chunk-5ILSX24H.js";import"../chunk-FUUTGGJS.js";var gt="kanonak.org",yt="document-ast",m=t=>({publisher:gt,package_:yt,name:t}),k={Document:m("Document"),Block:m("Block"),Inline:m("Inline"),StructuredValue:m("StructuredValue"),Heading:m("Heading"),Paragraph:m("Paragraph"),RawBlock:m("RawBlock"),Text:m("Text"),StructuredMap:m("StructuredMap"),StructuredEntry:m("StructuredEntry"),StructuredList:m("StructuredList"),StringScalar:m("StringScalar"),IntegerScalar:m("IntegerScalar"),EscapeHint:m("EscapeHint"),MediaType:m("MediaType"),metadata:m("metadata"),children:m("children"),level:m("level"),inlines:m("inlines"),text:m("text"),entries:m("entries"),key:m("key"),value:m("value"),escapeHint:m("escapeHint"),items:m("items"),stringValue:m("stringValue"),integerValue:m("integerValue"),rawContent:m("rawContent"),mediaType:m("mediaType"),mimeType:m("mimeType"),ESC_RAW:m("esc-raw"),ESC_YAML_SAFE:m("esc-yaml-safe"),ESC_TOML_STRING:m("esc-toml-string"),ESC_TOML_MULTILINE:m("esc-toml-multiline"),ESC_JSON:m("esc-json"),ESC_DYNAMODB_BOOL:m("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:m("esc-dynamodb-number"),ESC_DYNAMODB_NULL:m("esc-dynamodb-null"),TEXT_PLAIN:m("text-plain"),TEXT_MARKDOWN:m("text-markdown"),TEXT_HTML:m("text-html"),TEXT_CSS:m("text-css"),APPLICATION_JSON:m("application-json"),TEXT_YAML:m("text-yaml"),IMAGE_SVG_XML:m("image-svg-xml"),ResourceLink:m("ResourceLink"),target:m("target"),linkLabel:m("linkLabel"),PropertyList:m("PropertyList"),propertyEntries:m("propertyEntries"),PropertyEntry:m("PropertyEntry"),propertyKey:m("propertyKey"),propertyValue:m("propertyValue"),Table:m("Table"),tableColumnLabels:m("tableColumnLabels"),tableRows:m("tableRows"),TableRow:m("TableRow"),tableCells:m("tableCells")};function Ne(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Y=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(e,n){let r=kt(e.metadata,n),a=wt(e.children),u=["---",...r,"---","",a].join(`
|
|
2
2
|
`);return n?.trailingNewline&&(u.endsWith(`
|
|
3
3
|
`)||(u+=`
|
|
4
4
|
`)),u}};function kt(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(ue(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(ue(c),l);let i=(e?.metadataKeys??t.entries.map(c=>c.key)).map(ue),u=[];for(let c of i){let l=n.get(c);if(!l)continue;let p=r.get(c),y=ue(p??c),h=Ie(l.value,l.escapeHint);h!==void 0&&u.push(`${y}: ${h}`)}return u}function ue(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function Ie(t,e){switch(t.kind){case"StringScalar":return ht(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let a=Ie(r,e);a!==void 0&&n.push(a)}return n.join(", ")}case"StructuredMap":return;default:return}}function ht(t,e){return!e||Ne(e,k.ESC_RAW)?t:Ne(e,k.ESC_YAML_SAFE)?bt(t):t}function bt(t){return t.includes(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "3.28.
|
|
3
|
+
"version": "3.28.5",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"yaml-parser"
|
|
114
114
|
],
|
|
115
115
|
"dependencies": {
|
|
116
|
-
"@kanonak-protocol/types": "^3.28.
|
|
116
|
+
"@kanonak-protocol/types": "^3.28.5",
|
|
117
117
|
"ignore": "^7.0.5",
|
|
118
118
|
"js-yaml": "^4.1.0",
|
|
119
119
|
"yaml": "^2.7.0"
|
package/dist/chunk-GHMIWHWF.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import{a as F}from"./chunk-NIGFQYVA.js";import{a as S}from"./chunk-QIIQ4G2Q.js";import{c as R,d as p,g as j,j as d,k as w,l as g}from"./chunk-W6T7MOKY.js";function W(i){let e=i.replace(/\r\n/g,`
|
|
2
|
-
`).split(`
|
|
3
|
-
`),t=[],n=0;for(;n<e.length;){let s=e[n];if(s.trim()===""){n++;continue}let r=/^(\s*)```(\S*)\s*$/.exec(s);if(r){let c=r[2],u=[];for(n++;n<e.length&&!/^(\s*)```\s*$/.test(e[n]);)u.push(e[n]),n++;n++;let f=q(u.join(`
|
|
4
|
-
`)),b=c?` class="language-${Y(c)}"`:"";t.push(`<pre><code${b}>${f}</code></pre>`);continue}let o=/^(#{1,6})\s+(.*)$/.exec(s);if(o){let c=o[1].length,u=K(o[2].trim());t.push(`<h${c}>${u}</h${c}>`),n++;continue}if(s.includes("|")&&n+1<e.length&&G(e[n+1])){let c=P(s),u=se(e[n+1]);n+=2;let f=[];for(;n<e.length&&e[n].trim()!==""&&e[n].includes("|");)f.push(P(e[n])),n++;t.push(re(c,u,f));continue}if(/^\s*[-*]\s+/.test(s)){let c=[];for(;n<e.length&&/^\s*[-*]\s+/.test(e[n]);){let u=[e[n].replace(/^\s*[-*]\s+/,"")];for(n++;n<e.length&&e[n].trim()!==""&&!/^\s*[-*]\s+/.test(e[n])&&!/^\s*\d+\.\s+/.test(e[n]);)u.push(e[n]),n++;n<e.length&&e[n].trim()===""&&n++,c.push(`<li>${K(u.join(" ").trim())}</li>`)}t.push(`<ul>
|
|
5
|
-
${c.join(`
|
|
6
|
-
`)}
|
|
7
|
-
</ul>`);continue}if(/^\s*\d+\.\s+/.test(s)){let c=[];for(;n<e.length&&/^\s*\d+\.\s+/.test(e[n]);){let u=[e[n].replace(/^\s*\d+\.\s+/,"")];for(n++;n<e.length&&e[n].trim()!==""&&!/^\s*\d+\.\s+/.test(e[n])&&!/^\s*[-*]\s+/.test(e[n]);)u.push(e[n]),n++;n<e.length&&e[n].trim()===""&&n++,c.push(`<li>${K(u.join(" ").trim())}</li>`)}t.push(`<ol>
|
|
8
|
-
${c.join(`
|
|
9
|
-
`)}
|
|
10
|
-
</ol>`);continue}let a=[s];for(n++;n<e.length&&e[n].trim()!==""&&!/^(#{1,6})\s+/.test(e[n])&&!/^(\s*)```/.test(e[n])&&!/^\s*[-*]\s+/.test(e[n])&&!/^\s*\d+\.\s+/.test(e[n])&&!(e[n].includes("|")&&n+1<e.length&&G(e[n+1]));)a.push(e[n]),n++;t.push(`<p>${K(a.join(" "))}</p>`)}return t.join(`
|
|
11
|
-
`)}function G(i){return i.includes("-")?/^[\s|:-]+$/.test(i):!1}function P(i){let e=i.trim();return e.startsWith("|")&&(e=e.slice(1)),e.endsWith("|")&&(e=e.slice(0,-1)),e.split("|").map(t=>t.trim())}function se(i){return P(i).map(e=>{let t=e.startsWith(":"),n=e.endsWith(":");return t&&n?"center":n?"right":t?"left":null})}function re(i,e,t){let n=o=>{let a=e[o];return a?` style="text-align:${a}"`:""},s=i.map((o,a)=>`<th${n(a)}>${K(o)}</th>`).join(""),r=t.map(o=>`<tr>${o.map((c,u)=>`<td${n(u)}>${K(c)}</td>`).join("")}</tr>`).join(`
|
|
12
|
-
`);return`<table>
|
|
13
|
-
<thead><tr>${s}</tr></thead>
|
|
14
|
-
<tbody>
|
|
15
|
-
${r}
|
|
16
|
-
</tbody>
|
|
17
|
-
</table>`}function K(i){let e=q(i);return e=e.replace(/`([^`\n]+)`/g,(t,n)=>`<code>${n}</code>`),e=e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(t,n,s)=>`<a href="${Y(s)}">${n}</a>`),e=e.replace(/\*\*([^*\n]+)\*\*/g,(t,n)=>`<strong>${n}</strong>`),e=e.replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g,(t,n,s)=>`${n}<em>${s}</em>`),e=e.replace(/(^|[\s(])_([^_\n]+)_(?=[\s).,;:!?]|$)/g,(t,n,s)=>`${n}<em>${s}</em>`),e}function q(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Y(i){return i.replace(/"/g,""").replace(/&/g,"&")}var N={publisher:"kanonak.org",package_:"derivation",name:"look"},C={publisher:"kanonak.org",package_:"derivation",name:"tokens"},L={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},E={publisher:"kanonak.org",package_:"core-rdf",name:"label"},oe={publisher:"kanonak.org",package_:"core-rdf",name:"comment"},ae={publisher:"kanonak.org",package_:"look",name:"Hero"},ie={publisher:"kanonak.org",package_:"look",name:"PropertyList"},ce={publisher:"kanonak.org",package_:"look",name:"BadgeRow"},ue={publisher:"kanonak.org",package_:"look",name:"ChipRow"},fe={publisher:"kanonak.org",package_:"look",name:"ReferenceList"},z={publisher:"kanonak.org",package_:"look",name:"Markdown"},T={publisher:"kanonak.org",package_:"look",name:"NavGroup"},V={publisher:"kanonak.org",package_:"look",name:"NavLink"},J={publisher:"kanonak.org",package_:"look",name:"target"},B={publisher:"kanonak.org",package_:"look",name:"bands"},le={publisher:"kanonak.org",package_:"look",name:"title"},pe={publisher:"kanonak.org",package_:"look",name:"eyebrow"},de={publisher:"kanonak.org",package_:"look",name:"subtitle"},Q={publisher:"kanonak.org",package_:"look",name:"badges"},v={publisher:"kanonak.org",package_:"look",name:"source"},ge={publisher:"kanonak.org",package_:"look",name:"chips"},A={publisher:"kanonak.org",package_:"look",name:"entries"},ke={publisher:"kanonak.org",package_:"look",name:"urlForm"},D=class{constructor(e){this.catalog=e}catalog;findCascadedLook(e){let t=new Set,n=U(e);for(;n.length>0;){let s=n.shift(),r=O(s.subject);if(t.has(r))continue;t.add(r);let o=_(this.catalog,s.subject);if(!o)continue;let a=X(o);if(a)return{declaration:a,sourceClass:{publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name}};for(let c of M(o))n.push(c)}if(!t.has(O(L))){let s=_(this.catalog,L);if(s){let r=X(s);if(r)return{declaration:r,sourceClass:{...L}}}}}findCascadedTokens(e){let t=new Map;for(let[r,o]of H(e))t.has(r)||t.set(r,o);let n=new Set,s=U(e);for(;s.length>0;){let r=s.shift(),o=O(r.subject);if(n.has(o))continue;n.add(o);let a=te(this.catalog,r.subject);if(a.length!==0)for(let c of a){for(let[u,f]of H(c))t.has(u)||t.set(u,f);for(let u of M(c))s.push(u)}}if(!n.has(O(L))){let r=te(this.catalog,L);for(let o of r)for(let[a,c]of H(o))t.has(a)||t.set(a,c)}return t}renderStylesheet(e){let t=this.findCascadedTokens(e),n=[];for(let[o,a]of t)n.push(` --kan-${o}: ${a};`);let s=n.length>0?`:root {
|
|
18
|
-
${n.join(`
|
|
19
|
-
`)}
|
|
20
|
-
}`:":root { /* no tokens resolved */ }",r=this.findBaseStylesheet(x(e))??"";return`${s}
|
|
21
|
-
${r}`}findBaseStylesheet(e){let t="kanonak.org/site/content",n,s;for(let o of this.catalog){if(!(o instanceof R)||o.name!=="base-stylesheet")continue;let a=o.namespace||"";a.startsWith(`${e}/look-styles@`)?n=o:a.startsWith("kanonak.org/look-styles@")&&(s=o)}let r=n??s;if(r)for(let o of r.statement){let a=o.predicate?.subject;if(!a)continue;if(`${a.publisher}/${a.package_}/${a.name}`===t&&o instanceof j)return o.object}}renderHtml(e){let t=this.findCascadedLook(e);if(!t)return`<!-- LookRenderer: no derivation.look found for ${e.namespace}/${e.name} -->`;let n=Z(t.declaration);if(n.length===0)return"<!-- LookRenderer: look declaration has no bands -->";let s=x(e),r=[];for(let o of n)r.push(this.renderBand(o,e,s));return r.join(`
|
|
22
|
-
`)}renderDocument(e){let t=this.renderHtml(e),n=this.readPropertyValueText(e,E)??e.name,s=`${e.name}.css`,r=this.hasSvgDerivation(e)?`<figure class="kan-figure"><img src="${l(e.name)}.svg" alt=""></figure>
|
|
23
|
-
`:"",o=x(e),a=this.renderNavGroup(e,o);return`<!doctype html>
|
|
24
|
-
<html lang="en">
|
|
25
|
-
<head>
|
|
26
|
-
<meta charset="utf-8">
|
|
27
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
28
|
-
<title>${l(n)}</title>
|
|
29
|
-
<link rel="stylesheet" href="${l(s)}">
|
|
30
|
-
</head>
|
|
31
|
-
<body>
|
|
32
|
-
${a}
|
|
33
|
-
<main class="kan-main">
|
|
34
|
-
${r}${t}
|
|
35
|
-
</main>
|
|
36
|
-
</body>
|
|
37
|
-
</html>
|
|
38
|
-
`}hasSvgDerivation(e){let t=new Set,n=U(e);for(;n.length>0;){let s=n.shift(),r=O(s.subject);if(t.has(r))continue;t.add(r);let o=_(this.catalog,s.subject);if(o){for(let a of o.statement)if(a instanceof g&&k(a,"kanonak.org","derivation","derivations")){for(let c of a.object??[])if(c instanceof S)for(let u of c.statement){if(!(u instanceof d)||!k(u,"kanonak.org","derivation","format")||!(u.object instanceof p))continue;let f=u.object.subject;if(f.publisher==="kanonak.org"&&f.package_==="formats"&&f.name==="svg")return!0}}for(let a of M(o))n.push(a)}}return!1}renderBand(e,t,n){let s=ee(e);return s?m(s,ae)?this.renderHero(e,t,n):m(s,ie)?this.renderPropertyList(e,t,n):m(s,ce)?this.renderBadgeRow(e,t,n):m(s,ue)?this.renderChipRow(e,t,n):m(s,fe)?this.renderReferenceList(e,t,n):m(s,z)?this.renderMarkdown(e,t):m(s,T)?this.renderNavGroup(t,n):`<!-- LookRenderer: unsupported band ${s.publisher}/${s.package_}/${s.name} -->`:"<!-- LookRenderer: band has no rdf:type -->"}renderNavGroup(e,t){let n=this.findNavGroupForPublisher(t);if(!n)return"";let s=$(n,A);if(!(s instanceof g))return"";let r=s.object??[];if(r.length===0)return"";let o=[];for(let a of r){if(!(a instanceof p))continue;let c=_(this.catalog,{publisher:a.subject.publisher,package_:a.subject.package_,name:a.subject.name}),{href:u,label:f}=this.resolveNavEntry(a,c,t),b=`/${e.namespace?.split("/")[1]?.split("@")[0]}/${(e.namespace||"").split("@")[1]}/${e.name}`,I=u===b?' aria-current="page"':"";o.push(`<li><a class="kan-nav-link" href="${l(u)}"${I}>${l(f)}</a></li>`)}return`<nav class="kan-site-nav"><ul>
|
|
39
|
-
${o.join(`
|
|
40
|
-
`)}
|
|
41
|
-
</ul></nav>`}resolveNavEntry(e,t,n){if(t&&U(t).map(c=>c.subject).some(c=>c.publisher===V.publisher&&c.package_===V.package_&&c.name===V.name)){let c=y(t,E),u=$(t,J);if(u instanceof d&&u.object instanceof p){let f=u.object,b=this.readLabelForUri({publisher:f.subject.publisher,package_:f.subject.package_,name:f.subject.name});return{href:this.urlForReference(f,J,n),label:c??b??f.subject.name}}}let s=F.formatResourceUrl({publisher:e.subject.publisher,package_:e.subject.package_,...e.subject.version?{version:e.subject.version}:{},name:e.subject.name},"*",{contextPublisher:n}),r=t?y(t,E)??e.subject.name:e.subject.name;return{href:s,label:r}}findNavGroupForPublisher(e){for(let t of this.catalog){if(!(t instanceof R)||!(t.namespace||"").startsWith(`${e}/`))continue;if(U(t).map(o=>o.subject).some(o=>o.publisher===T.publisher&&o.package_===T.package_&&o.name===T.name))return t}}renderMarkdown(e,t){let n=h(e,v);if(!n)return"<!-- LookRenderer.Markdown: no look.source -->";let s=this.readPropertyValueText(t,n);return s?`<section class="kan-markdown">
|
|
42
|
-
${W(s)}
|
|
43
|
-
</section>`:""}renderRawMarkdown(e){let t=this.findCascadedLook(e);if(!t)return;let n=Z(t.declaration),s=[];for(let r of n){let o=ee(r);if(!o||!m(o,z))continue;let a=h(r,v);if(!a)continue;let c=this.readPropertyValueText(e,a);c&&s.push(c)}return s.length>0?s.join(`
|
|
44
|
-
|
|
45
|
-
`):void 0}renderHero(e,t,n){let s=['<header class="kan-hero">'],r=h(e,pe);if(r){let f=this.readPropertyValueText(t,r);f&&s.push(`<span class="kan-hero-eyebrow">${l(f)}</span>`)}let o=h(e,le),a="";o&&(a=this.readPropertyValueText(t,o)??""),a||(a=t.name),s.push(`<h1 class="kan-hero-title">${l(a)}</h1>`);let c=h(e,de);if(c){let f=this.readPropertyValueText(t,c);f&&s.push(`<p class="kan-hero-subtitle">${l(f)}</p>`)}let u=h(e,Q);if(u){let f=this.readPropertyValueReferences(t,u);if(f.length>0){let b=f.map(I=>this.renderBadge(I,Q,n)).join("");s.push(`<div class="kan-hero-badges">${b}</div>`)}}return s.push("</header>"),s.join(`
|
|
46
|
-
`)}renderPropertyList(e,t,n){let s=h(e,v);if(!s)return"<!-- LookRenderer: PropertyList missing look.source -->";let r=this.readLabelForUri(s)??s.name,o=$(t,s),a=this.gatherValueItems(o),c=a.length>0?a.map(u=>`<li>${this.renderInlineValue(u,v,n)}</li>`).join(""):'<li class="kan-empty">(no values)</li>';return['<section class="kan-property-list">',`<h3 class="kan-property-list-title">${l(r)}</h3>`,`<ul class="kan-property-list-items">${c}</ul>`,"</section>"].join(`
|
|
47
|
-
`)}renderBadgeRow(e,t,n){let s=h(e,v);if(!s)return"<!-- LookRenderer: BadgeRow missing look.source -->";let r=this.readPropertyValueReferences(t,s);return r.length===0?"":`<div class="kan-badge-row">${r.map(a=>this.renderBadge(a,v,n)).join("")}</div>`}renderChipRow(e,t,n){let s=ne(e,ge);if(s.length===0)return"<!-- LookRenderer: ChipRow has no look.chips -->";let r=[];for(let o of s){let a=$(t,o);if(!a)continue;let c=this.readLabelForUri(o)??o.name,u=this.renderStatementInlineValue(a,o,n);u&&r.push(`<span class="kan-chip"><span class="kan-chip-key">${l(c)}</span> <span class="kan-chip-val">${u}</span></span>`)}return r.length===0?"":`<div class="kan-chip-row">${r.join("")}</div>`}renderReferenceList(e,t,n){let s=ne(e,A);if(s.length===0)return"<!-- LookRenderer: ReferenceList has no look.entries -->";let r=[];for(let o of s){let a=this.readPropertyValueReferences(t,o);if(a.length===0)continue;let c=this.readLabelForUri(o)??o.name,u=a.map(f=>this.renderReferenceLink(f,A,n)).join(", ");r.push(`<dt>${l(c)}</dt><dd>${u}</dd>`)}return r.length===0?"":`<dl class="kan-reference-list">${r.join("")}</dl>`}readPropertyValueText(e,t){let n=$(e,t);if(n){if(n instanceof j)return n.object;if(n instanceof d){let s=n.object;return this.readLabelForUri({publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name})??s.subject.name}if(n instanceof g)return(n.object??[]).map(r=>r instanceof p?this.readLabelForUri({publisher:r.subject.publisher,package_:r.subject.package_,name:r.subject.name})??r.subject.name:r instanceof S?r.name??"":String(r)).filter(r=>r).join(", ")}}readPropertyValueReferences(e,t){let n=$(e,t);if(!n)return[];if(n instanceof d)return[n.object];if(n instanceof g){let s=[];for(let r of n.object??[])r instanceof p&&s.push(r);return s}return[]}gatherValueItems(e){return e?e instanceof g?e.object??[]:e instanceof d?[e.object]:e instanceof w?[e.object]:e instanceof j?[e.object]:[]:[]}renderInlineValue(e,t,n){return e instanceof p?this.renderReferenceLink(e,t,n):e instanceof S?l(e.name??"(embedded)"):typeof e=="string"?l(e):typeof e=="number"||typeof e=="boolean"?l(String(e)):""}renderStatementInlineValue(e,t,n){return e instanceof j?l(e.object):e instanceof d?this.renderReferenceLink(e.object,t,n):e instanceof g?(e.object??[]).map(r=>this.renderInlineValue(r,t,n)).filter(r=>r).join(", "):""}renderReferenceLink(e,t,n){let s=this.readLabelForUri({publisher:e.subject.publisher,package_:e.subject.package_,name:e.subject.name})??e.subject.name,r=this.urlForReference(e,t,n);return`<a class="kan-link" href="${l(r)}">${l(s)}</a>`}renderBadge(e,t,n){let s=this.readLabelForUri({publisher:e.subject.publisher,package_:e.subject.package_,name:e.subject.name})??e.subject.name,r=this.readCommentForUri({publisher:e.subject.publisher,package_:e.subject.package_,name:e.subject.name}),o=this.urlForReference(e,t,n),a=r?` title="${l(r)}"`:"";return`<a class="kan-badge" href="${l(o)}"${a}>${l(s)}</a>`}urlForReference(e,t,n){let s=t?this.getUrlFormForProperty(t):"=";return F.formatResourceUrl({publisher:e.subject.publisher,package_:e.subject.package_,...e.subject.version?{version:e.subject.version}:{},name:e.subject.name},s,{contextPublisher:n})}getUrlFormForProperty(e){let t=_(this.catalog,e);if(!t)return"=";let n=y(t,ke);return n==="*"||n==="^"||n==="~"||n==="="?n:"="}readLabelForUri(e){let t=_(this.catalog,e);if(t)return y(t,E)}readCommentForUri(e){let t=_(this.catalog,e);if(t)return y(t,oe)}};function H(i){let e=new Map;for(let t of i.statement){if(!(t instanceof w)||!k(t,C.publisher,C.package_,C.name))continue;let n=t.object;for(let s of n.statement){if(!(s instanceof j))continue;let r=s.predicate?.subject?.name;if(!r)continue;let o=s.object;e.has(r)||e.set(r,o)}}return e}function X(i){for(let e of i.statement)if(e instanceof w&&k(e,N.publisher,N.package_,N.name))return e.object}function Z(i){for(let e of i.statement){if(!(e instanceof g)||!k(e,B.publisher,B.package_,B.name))continue;let t=[];for(let n of e.object??[])n instanceof S&&t.push(n);return t}return[]}function ee(i){for(let e of i.statement)if(e instanceof d&&e.predicate?.subject?.name==="type"&&e.object instanceof p){let t=e.object.subject;return{publisher:t.publisher,package_:t.package_,name:t.name}}}function h(i,e){for(let t of i.statement)if(t instanceof d&&k(t,e.publisher,e.package_,e.name)&&t.object instanceof p){let n=t.object.subject;return{publisher:n.publisher,package_:n.package_,name:n.name}}}function ne(i,e){for(let t of i.statement){if(!(t instanceof g)||!k(t,e.publisher,e.package_,e.name))continue;let n=[];for(let s of t.object??[])s instanceof p&&n.push({publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name});return n}return[]}function $(i,e){for(let t of i.statement)if(k(t,e.publisher,e.package_,e.name))return t}function y(i,e){for(let t of i.statement)if(t instanceof j&&k(t,e.publisher,e.package_,e.name))return t.object}function U(i){let e=[];for(let t of i.statement)if(t instanceof d){if(t.predicate?.subject?.name!=="type")continue;t.object instanceof p&&e.push(t.object)}else if(t instanceof g){if(t.predicate?.subject?.name!=="type")continue;for(let n of t.object??[])n instanceof p&&e.push(n)}return e}function M(i){let e=[];for(let t of i.statement)if(t instanceof d){if(t.predicate?.subject?.name!=="subClassOf")continue;t.object instanceof p&&e.push(t.object)}else if(t instanceof g){if(t.predicate?.subject?.name!=="subClassOf")continue;for(let n of t.object??[])n instanceof p&&e.push(n)}return e}function te(i,e){let t=[];for(let n of i){if(!(n instanceof R)||n.name!==e.name)continue;(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&t.push(n)}return t}function _(i,e){let t="version"in e?e.version:void 0;if(t){let n=`${e.publisher}/${e.package_}@${t.major}.${t.minor}.${t.patch}`;for(let s of i)if(s instanceof R&&s.name===e.name&&s.namespace===n)return s}for(let n of i){if(!(n instanceof R)||n.name!==e.name)continue;if((n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))return n}}function k(i,e,t,n){let s=i.predicate?.subject;return s?s.publisher===e&&s.package_===t&&s.name===n:!1}function m(i,e){return i.publisher===e.publisher&&i.package_===e.package_&&i.name===e.name}function O(i){return`${i.publisher}/${i.package_}/${i.name}`}function x(i){let e=i.namespace||"",t=e.indexOf("/");return t>=0?e.substring(0,t):e}function l(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}export{W as a,D as b};
|