@ulb-darmstadt/shacl-form
Version:
SHACL form generator
89 lines (87 loc) • 56.6 kB
JavaScript
import{DataFactory as e,Literal as t,NamedNode as n,Store as r,StreamParser as i,Writer as a}from"n3";import{RdfXmlParser as o}from"rdfxml-streaming-parser";import s from"jsonld";import{RokitButton as c,RokitCollapsible as l,RokitDialog as u,RokitInput as d,RokitSelect as f,RokitTextArea as p}from"@ro-kit/ui-widgets";import{v4 as m}from"uuid";import{Validator as ee}from"shacl-engine";var h=`http://www.w3.org/ns/shacl#`,te=`http://datashapes.org/dash#`,g=`http://www.w3.org/2001/XMLSchema#`,_=`http://www.w3.org/1999/02/22-rdf-syntax-ns#`,v=`http://www.w3.org/2000/01/rdf-schema#`,ne=`http://www.w3.org/2004/02/skos/core#`,re=`http://www.w3.org/2002/07/owl#`,ie=`http://www.w3.org/ns/oa#`,y=`http://purl.org/dc/terms/`,b=e.namedNode(`loaded-shapes`),x=e.namedNode(`loaded-data`),S=e.namedNode(_+`type`),ae=e.namedNode(_+`langString`),C=e.namedNode(y+`conformsTo`),oe=e.namedNode(v+`subClassOf`),w=e.namedNode(re+`imports`),se=e.namedNode(ne+`broader`),ce=e.namedNode(ne+`narrower`),T=e.namedNode(h+`NodeShape`),le=e.namedNode(h+`IRI`),E=e.namedNode(h+`property`),D=e.namedNode(h+`class`),ue=e.namedNode(h+`node`),O=e.namedNode(h+`targetClass`),de=e.namedNode(h+`nodeKind`),fe=e.namedNode(g+`string`),pe=e.namedNode(g+`boolean`);function k(e,t,n=h,r){let i=``,a=me(e,t,n,r);return a&&(i=a.value),i}function me(e,t,n=h,r){let i,a=n+t;if(r?.length){for(let t of r)for(let n of e)if(n.predicate.value===a){if(n.object.id.endsWith(`@${t}`))return n.object;n.object.id.indexOf(`@`)<0?i=n.object:i||=n.object}}else for(let t of e)if(t.predicate.value===a)return t.object;return i}function he(e){e.querySelector(`.editor`)?.focus()}function A(e,t){return k(e,`prefLabel`,`http://www.w3.org/2004/02/skos/core#`,t)||k(e,`label`,`http://www.w3.org/2000/01/rdf-schema#`,t)||k(e,`title`,`http://purl.org/dc/terms/`,t)||k(e,`name`,`http://xmlns.com/foaf/0.1/`,t)}function ge(e,t,n){let r=[];for(let i of e)r.push({value:i,label:A(t.getQuads(i,null,null,null),n),children:[]});return r}function j(e,t){for(let n in t){let r=t[n];e.startsWith(r)&&(e=e.slice(r.length))}return e}function _e(e,t,n,r,i=new Set){for(let a of t.owlImports)i.has(a.id)||(i.add(a.id),r.push(...n.getSubjects(S,e,a)));t.parent&&_e(e,t.parent,n,r,i)}function ve(e,t){if(t.in){let e=t.config.lists[t.in];return ge(e?.length?e:[],t.config.store,t.config.languages)}else{let n=t.config.store.getSubjects(S,e,b);n.push(...t.config.store.getSubjects(S,e,x)),_e(e,t,t.config.store,n);let r=new Map,i=new Map;for(let e of n)r.set(e.id,{value:e,label:A(t.config.store.getQuads(e,null,null,null),t.config.languages),children:[]});for(let e of n){for(let n of t.config.store.getObjects(e,se,null))r.has(n.id)&&i.set(e.id,n.id);for(let n of t.config.store.getObjects(e,ce,null))r.has(n.id)&&i.set(n.id,e.id);for(let n of t.config.store.getObjects(e,oe,null))r.has(n.id)&&i.set(e.id,n.id)}for(let[e,t]of i.entries())r.get(t)?.children?.push(r.get(e));let a=[];for(let[e,t]of r.entries())i.has(e)||a.push(t);for(let n of t.config.store.getSubjects(oe,e,null))a.push(...ve(n,t));return a}}function M(e){let t;try{t=new URL(e)}catch{return!1}return t.protocol===`http:`||t.protocol===`https:`}function N(e,t,n){if(t===void 0)return n;if(n===void 0)return t;let r=e.indexOf(t.language);if(r<0)return n;let i=e.indexOf(n.language);return i<0||i>r?t:n}function ye(e,t){let n;for(let r of t)n=N(e,n,r);return n?n.value:``}function be(e){let t=new Set;for(let n of e.getObjects(null,D,b))t.add(n.value);for(let n of e.getObjects(null,O,b))t.add(n.value);return t}function xe(e,t){return e instanceof Set?[...t].filter(t=>!e.has(t)):[...t].filter(t=>!e.includes(t))}function Se(e,{remove:t=!1,ignoreErrors:n=!1}={}){let r={},i=n?(()=>!0):((e,t)=>{throw Error(`${e.value} ${t}`)}),a=e.getQuads(null,_+`rest`,_+`nil`,null),o=t?[...a]:[];return a.forEach(n=>{let a=[],s=!1,c,l,u=n.graph,d=n.subject;for(;d&&!s;){let t=e.getQuads(null,null,d,null),n=e.getQuads(d,null,null,null).filter(e=>!e.predicate.equals(S)),r,f=null,p=null,m=null;for(let e=0;e<n.length&&!s;e++)r=n[e],r.graph.equals(u)?c?s=i(d,`has non-list arcs out`):r.predicate.value===`http://www.w3.org/1999/02/22-rdf-syntax-ns#first`?f?s=i(d,`has multiple rdf:first arcs`):o.push(f=r):r.predicate.value===`http://www.w3.org/1999/02/22-rdf-syntax-ns#rest`?p?s=i(d,`has multiple rdf:rest arcs`):o.push(p=r):t.length?s=i(d,`can't be subject and object`):(c=r,l=`subject`):s=i(d,`not confined to single graph`);for(let e=0;e<t.length&&!s;++e)r=t[e],c?s=i(d,`can't have coreferences`):r.predicate.value===`http://www.w3.org/1999/02/22-rdf-syntax-ns#rest`?m?s=i(d,`has incoming rdf:rest arcs`):m=r:(c=r,l=`object`);f?a.unshift(f.object):s=i(d,`has no list head`),d=m&&m.subject}s?t=!1:c&&(r[c[l].value]=a)}),t&&e.removeQuads(o),r}var P={},F={};function I(e){let t=new Set;for(let n of e.getQuads(null,C,null,x))n.subject.termType===`NamedNode`&&t.add(n.subject.value);if(t.size===1)return t.values().next().value}function Ce(t,n){let r=e.namedNode(n);for(let e of t.getObjects(r,C,x))if(e.termType===`NamedNode`&&t.getQuads(e,S,T,null).length>0)return e}async function we(e){let t={store:new r,importedUrls:[],atts:e},n=[];if(e.shapes?n.push(L(z(e.shapes),t,b)):e.shapesUrl&&n.push(L(R(e.shapesUrl,t.atts.proxy),t,b)),e.values?n.push(L(z(e.values),t,x)):e.valuesUrl&&n.push(L(R(e.valuesUrl,t.atts.proxy),t,x)),await Promise.all(n),e.classInstanceProvider)try{let n=be(t.store),r=await e.classInstanceProvider(n);r&&await L(z(r),t,b)}catch(e){console.error(`failed loading class instances`,e)}if(e.valuesSubject||=I(t.store)||null,e.valuesSubject&&t.store.countQuads(null,null,null,b)===0){let n=[...t.store.getObjects(e.valuesSubject,S,x),...t.store.getObjects(e.valuesSubject,C,x)],r=[];for(let e of n){let n=Te(e.value);!n&&e.value.startsWith(`urn:`)&&t.atts.proxy&&(n=e.value),n&&t.importedUrls.indexOf(n)<0&&(t.importedUrls.push(n),r.push(L(R(n,t.atts.proxy),t,b)))}try{await Promise.allSettled(r)}catch(e){console.warn(e)}}return t.store}async function L(t,n,r){let i=await t,a=[];for(let t of i){let i=r;if(n.atts.valuesSubject&&x.equals(r)&&t.graph.id&&t.graph.id!==n.atts.valuesSubject&&(i=t.graph),n.store.add(e.quad(t.subject,t.predicate,t.object,i)),n.atts.loadOwlImports&&w.equals(t.predicate)){let r=Te(t.object.value);r&&n.importedUrls.indexOf(r)<0&&(n.importedUrls.push(r),a.push(L(R(r,n.atts.proxy),n,e.namedNode(r))))}}await Promise.allSettled(a)}async function R(e,t){return e in P||(P[e]=(async()=>{let n=e;t&&(n=t+encodeURIComponent(e));let r=await fetch(n,{headers:{Accept:`text/turtle, application/trig, application/n-triples, application/n-quads, text/n3, application/ld+json`}});return r.ok?z(await r.text()):(console.warn(`failed fetching RDF from`,e),[])})()),P[e]}async function z(t){if(!t.trim())return[];let n=Ee(t);if(n===`json`)try{t=await s.toRDF(JSON.parse(t),{format:`application/n-quads`})}catch(e){console.error(e)}let r=[];return await new Promise((a,s)=>{let c=n===`xml`?new o:new i;c.on(`data`,t=>{r.push(e.quad(t.subject,t.predicate,t.object,t.graph))}).on(`error`,e=>{s(e)}).on(`prefix`,(e,t)=>{e&&(F[e]=t)}).on(`end`,()=>{a(null)}),c.write(t),c.end()}),r}function Te(e){if(M(e))return e;let t=e.split(`:`);if(t.length===2){let n=F[t[0]];if(n&&(e=e.replace(`${t[0]}:`,n),M(e)))return e}return null}function Ee(e){return/^\s*[\\[{]/.test(e)?`json`:/^\s*<\?xml/.test(e)?`xml`:`ttl`}var De={[`${h}name`]:(e,t)=>{let n=t;e.name=N(e.config.languages,e.name,n)},[`${h}description`]:(e,t)=>{let n=t;e.description=N(e.config.languages,e.description,n)},[`${h}path`]:(e,t)=>{e.path=t.value},[`${h}group`]:(e,t)=>{e.group=t.id},[`${h}datatype`]:(e,t)=>{e.datatype=t},[`${h}nodeKind`]:(e,t)=>{e.nodeKind=t},[`${h}minCount`]:(e,t)=>{e.minCount=parseInt(t.value)},[`${h}maxCount`]:(e,t)=>{e.maxCount=parseInt(t.value)},[`${h}minLength`]:(e,t)=>{e.minLength=parseInt(t.value)},[`${h}maxLength`]:(e,t)=>{e.maxLength=parseInt(t.value)},[`${h}minInclusive`]:(e,t)=>{e.minInclusive=parseInt(t.value)},[`${h}maxInclusive`]:(e,t)=>{e.maxInclusive=parseInt(t.value)},[`${h}minExclusive`]:(e,t)=>{e.minExclusive=parseInt(t.value)},[`${h}maxExclusive`]:(e,t)=>{e.maxExclusive=parseInt(t.value)},[`${h}pattern`]:(e,t)=>{e.pattern=t.value},[`${h}order`]:(e,t)=>{e.order=parseInt(t.value)},[`${te}singleLine`]:(e,t)=>{e.singleLine=t.value===`true`},[`${te}readonly`]:(e,t)=>{e.readonly=t.value===`true`},[`${ie}styleClass`]:(e,t)=>{e.cssClass=t.value},[`${h}in`]:(e,t)=>{e.in=t.value},[`${h}languageIn`]:(e,t)=>{e.languageIn=e.config.lists[t.value],e.datatype=ae},[`${h}defaultValue`]:(e,t)=>{e.defaultValue=t},[`${h}hasValue`]:(e,t)=>{e.hasValue=t},[`${h}node`]:(e,t)=>{e.node=t,e.nodeShapes.add(e.config.getNodeTemplate(t,e))},[`${h}and`]:(e,t)=>{e.and=t.value;let n=e.config.lists[e.and];if(n?.length)for(let t of n)e.nodeShapes.add(e.config.getNodeTemplate(t,e))},[`${h}qualifiedValueShape`]:(e,t)=>{let n=e.config.getNodeTemplate(t,e);e.qualifiedValueShape=n,e.nodeShapes.add(n)},[`${h}qualifiedMinCount`]:(e,t)=>{e.qualifiedMinCount=parseInt(t.value)},[`${h}qualifiedMaxCount`]:(e,t)=>{e.qualifiedMaxCount=parseInt(t.value)},[w.id]:(e,t)=>{e.owlImports.add(t)},[D.id]:(e,t)=>{e.class=t;let n=e.config.store.getSubjects(O,t,null);n.length>0&&(e.node=n[0])},[`${h}or`]:(e,t)=>{let n=e.config.lists[t.value];n?.length?e.or=n:console.error(`list for sh:or not found:`,t.value,`existing lists:`,e.config.lists)},[`${h}xone`]:(e,t)=>{let n=e.config.lists[t.value];n?.length?e.xone=n:console.error(`list for sh:xone not found:`,t.value,`existing lists:`,e.config.lists)}},B=class{constructor(e,t){this.label=``,this.nodeShapes=new Set,this.owlImports=new Set,this.id=e,this.parent=t,this.config=t.config,this.config.registerPropertyTemplate(this),H(this,this.config.store.getQuads(e,null,null,null))}};function V(e){return Math.max(e.minCount??0,e.qualifiedMinCount??0)}function Oe(e){return Math.min(e.maxCount??2**53-1,e.qualifiedMaxCount??2**53-1)}function ke(e){let t=Object.assign({},e);return t.nodeShapes=new Set(e.nodeShapes),t.owlImports=new Set(e.owlImports),e.languageIn&&(t.languageIn=[...e.languageIn]),e.or&&(t.or=[...e.or]),e.xone&&(t.xone=[...e.xone]),t}function H(e,t){for(let n of t)De[n.predicate.id]?.call(e,e,n.object);return e.label=e.name?.value||A(t,e.config.languages),e.label||=e.path?j(e.path,F):`unknown`,e}function Ae(e,t){let n=t,r=e;for(let e in t)if(e!==`parent`&&e!==`config`&&e!==`id`){let t=n[e];if(t!==void 0&&t!==``)if(Array.isArray(t)){let n=r[e];Array.isArray(n)?n.push(...t):r[e]=[...t]}else if(t instanceof Set&&t.size){let n=r[e];r[e]=new Set([...n instanceof Set?n:[],...t])}else r[e]=t}}function je(e,t,n){let r=document.createElement(`div`);r.classList.add(`shacl-or-constraint`),r.setAttribute(`part`,`constraint`);let i=[];if(t instanceof q){let a=[],o=!1;e.length&&(o=n.store.countQuads(e[0],E,null,null)>0);for(let r=0;r<e.length;r++)if(o){let o=n.store.getObjects(e[r],E,null),s=[],c=``;for(let e of o){let r=new G(n.getPropertyTemplate(e,t.template),t);s.push(r),c+=(c.length>0?` / `:``)+r.template.label}a.push(s),i.push({label:c,value:r.toString()})}else{let o=e[r],s=new G(n.getPropertyTemplate(o,t.template),t);a.push([s]),i.push({label:s.template.label,value:r.toString()})}let s=n.theme.createListEditor(`Please choose`,null,!1,i);s.setAttribute(`part`,`constraint-editor`);let c=s.querySelector(`.editor`);c.onchange=()=>{if(c.value){let e=a[parseInt(c.value)],t;e.length&&(t=e[0],r.replaceWith(e[0]),t.updateControls());for(let n=1;n<e.length;n++)t.after(e[n]),t=e[n],t.updateControls()}},r.appendChild(s)}else{let a=[];for(let t=0;t<e.length;t++){let r=n.store.getQuads(e[t],null,null,null);if(r.length){a.push(r);let e=A(r,n.languages);for(let t of r)t.predicate.equals(ue)&&(e=A(n.store.getQuads(t.object,null,null,null),n.languages));i.push({label:e||j(r[0].predicate.value,F)+` = `+j(r[0].object.value,F),value:t.toString()})}}let o=n.theme.createListEditor(t.template.label+`?`,null,!1,i,t.template);o.setAttribute(`part`,`constraint-editor`);let s=o.querySelector(`.editor`);s.onchange=async()=>{if(s.value){let e=await K(H(ke(t.template),a[parseInt(s.value)]),void 0,!0),n=e.querySelector(`:scope > label`);n&&n.classList.add(`persistent`),r.replaceWith(e)}},r.appendChild(o)}return r}function Me(e,t,n){if(t.termType===`Literal`){let r=t.datatype;for(let t of e){let e=n.store.getQuads(t,null,null,null);for(let t of e)if(t.predicate.value===`http://www.w3.org/ns/shacl#datatype`&&t.object.equals(r))return e}}else{let r=n.store.getObjects(t,S,null);for(let t of e){let e=n.store.getQuads(t,null,null,null);for(let t of e)if(r.length>0){if(t.predicate.value===`http://www.w3.org/ns/shacl#node`){for(let i of r)if(n.store.getQuads(t.object,O,i,null).length>0)return e}if(t.predicate.equals(D)){for(let n of r)if(t.object.equals(n))return e}}else if(t.predicate.equals(de)&&t.object.equals(le))return e}}return console.error(`couldn't resolve sh:or/sh:xone on property for value`,t),[]}function Ne(e,t,n){for(let r of e){let e=!1,i=n.store.getObjects(r,E,null);for(let r of i){let i=n.store.getObjects(r,`${h}path`,null);for(let r of i)if(e=n.store.countQuads(t,r,null,null)>0,e)break}if(e)return i}return console.error(`couldn't resolve sh:or/sh:xone on node for value`,t),[]}var Pe=`:host {
--shacl-font-family: inherit;
--shacl-font-size: 14px;
--shacl-text-color: #333;
--shacl-muted-color: #555;
--shacl-border-color: #DDD;
--shacl-bg: #FFF;
--shacl-row-alt-bg: #F8F8F8;
--shacl-error-color: #C00;
--shacl-label-width: 8em;
}
form { display:block; --label-width: var(--shacl-label-width, 8em); --caret-size: 10px; font-family: var(--shacl-font-family); font-size: var(--shacl-font-size); color: var(--shacl-text-color); background-color: var(--shacl-bg); }
form.mode-edit { padding-left: 1em; }
form, form * { box-sizing: border-box; }
shacl-node, .collapsible::part(content) { display: flex; flex-direction: column; width: 100%; position: relative; }
shacl-node .remove-button { margin-top: 1px; }
shacl-node .add-button-wrapper { display: flex; width: 100%; justify-content: flex-end; gap: 20px; padding-right: 24px; color: var(--shacl-muted-color); font-size: 14px; }
shacl-node .add-button::part(button)::before { content: '+ ' }
shacl-node .link-button::part(button)::before { content: 'đź”— '; font-size: 10px; }
shacl-node h1 { font-size: 16px; border-bottom: 1px solid #AAA; margin-top: 4px; color: var(--shacl-muted-color); }
shacl-property:not(:has(>.collapsible)), shacl-property>.collapsible::part(content) { display: flex; flex-direction: column; align-items: end; position: relative; }
shacl-property:not(.may-add) > .add-button-wrapper, shacl-property:not(.may-add) > .collapsible > .add-button-wrapper { display: none; }
shacl-property:not(.may-remove) > .property-instance > .remove-button-wrapper > .remove-button:not(.persistent) { visibility: hidden; }
shacl-property:not(.may-remove) > .collapsible > .property-instance > .remove-button-wrapper > .remove-button:not(.persistent) { visibility: hidden; }
shacl-property:not(.may-remove) > .shacl-or-constraint > .remove-button-wrapper > .remove-button:not(.persistent) { visibility: hidden; }
.mode-view .shacl-group:not(:has(shacl-property)) { display: none; }
.property-instance, .shacl-or-constraint { display: flex; align-items: flex-start; padding: 4px 0; width: 100%; position: relative; }
.shacl-or-constraint > div { display: flex; align-items: flex-start; }
.shacl-or-constraint > div:first-child { flex-grow: 1 }
.shacl-or-constraint label { display: inline-block; word-break: break-word; width: var(--label-width); line-height: 1em; padding-top: 0.15em; padding-right: 1em; flex-shrink: 0; position: relative; }
.property-instance label[title] { cursor: help; text-decoration: underline dashed #AAA; }
.property-instance.linked label:after, label.linked:after { content: '\\1F517'; font-size: 0.6em; position: absolute; top: 3px; right: 3px; }
.mode-edit .property-instance label.required::before, .add-button-wrapper.required > .add-button::before, .add-button-wrapper.required > .link-button::before { color: var(--shacl-error-color); content: '\\2736'; font-size: 0.6rem; position: absolute; left: -1.4em; }
.mode-edit .add-button-wrapper.required > .add-button::before, .add-button-wrapper.required > .link-button::before { left: -0.5em; }
.mode-edit .property-instance label.required::before { top: 0.15rem; }
.property-instance.valid::before { content: ''; position: absolute; left: calc(var(--label-width) - 1em); top:0.5em; width: 0.9em; height: 0.9em; background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 1024 1024" fill="green" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M866.133333 258.133333L362.666667 761.6l-204.8-204.8L98.133333 618.666667 362.666667 881.066667l563.2-563.2z"/></svg>'); }
.editor:not([type='checkbox']) { flex-grow: 1; }
textarea.editor { resize: vertical; }
.lang-chooser { border: 0; background-color: #e9e9ed; padding: 2px 4px; align-self: flex-start; }
.validation-error { position: absolute; left: calc(var(--label-width) - 1em); color: var(--shacl-error-color); cursor: help; }
.validation-error::before { content: '\\26a0' }
.validation-error.node { left: -1em; }
.invalid > .editor { border-color: red !important; }
.ml-0 { margin-left: 0 !important; }
.pr-0 { padding-right: 0 !important; }
.mode-view .property-instance:not(:first-child) > label { visibility: hidden; }
.mode-view .property-instance label { width: var(--label-width); }
.d-flex { display: flex; }
.lang { opacity: 0.65; font-size: 0.6em; }
a, a:visited { color: inherit; }
h3 { margin-top: 0; }
.fadeIn, .fadeOut { animation: fadeIn 0.2s ease-out; }
.fadeOut { animation-direction: reverse; animation-timing-function: ease-out;}
@keyframes fadeIn {
0% { opacity: 0; transform: scaleY(0.8); }
100% { opacity: 1; transform: scaleY(1); }
}
.collapsible::part(label) { font-weight: 600; }
.collapsible > .property-instance:nth-child(even) { background-color: var(--shacl-row-alt-bg); }
.collapsible > .property-instance > shacl-node > h1 { display: none; }
.ref-link { cursor: pointer; }
.ref-link:hover { text-decoration: underline; }
.node-id-display { color: var(--shacl-muted-color); font-size: 11px; }
/* hierarchy colors */
.colorize { --hierarchy-color-width: 3px; padding: 0 1px 0 calc(1px + var(--hierarchy-color-width)); align-self: stretch; position: relative; }
.colorize::before {
content: '';
position: absolute;
width: var(--hierarchy-color-width);
top: 0; bottom: 0; left: 0;
--index: mod(var(--hierarchy-level), var(--hierarchy-colors-length));
background: linear-gradient(var(--hierarchy-colors)) no-repeat 0 calc(var(--index) * 100% / (var(--hierarchy-colors-length) - 1)) / 100% calc(1px * infinity);
}
.property-instance:not(:has(shacl-node)) > .colorize::before { background: 0; }
.colorize:not(:has(.remove-button)) { padding-left: calc(8px + var(--hierarchy-color-width)); }
.mode-view .property-instance > .colorize { order: -1; }
.link-option { padding: 10px; }
.link-option:hover { background-color: #F5F5F5; cursor: pointer; }
rokit-dialog.link-chooser::part(dialog) { min-height: min(434px, 90vh); width: min(90vw, 600px); }
`,Fe=class{constructor(e){this.dense=!0;let t=Pe;e&&(t+=`
`+e),this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t)}apply(e){}setDense(e){this.dense=e}createViewer(e,r,i){let a=document.createElement(`div`),o=document.createElement(`label`);o.textContent=`${e}:`,i.description&&o.setAttribute(`title`,i.description.value),a.appendChild(o);let s=r.value,c=null;if(r instanceof n){let e=i.config.store.getQuads(s,null,null,null);if(e.length){let t=A(e,i.config.languages);t&&(s=t)}}else r instanceof t&&(r.language?(c=document.createElement(`span`),c.classList.add(`lang`),c.innerText=`@${r.language}`):r.datatype.value===`http://www.w3.org/2001/XMLSchema#date`?s=new Date(Date.parse(r.value)).toDateString():r.datatype.value===`http://www.w3.org/2001/XMLSchema#dateTime`&&(s=new Date(Date.parse(r.value)).toLocaleString()));let l;return M(r.value)?(l=document.createElement(`a`),l.setAttribute(`href`,r.value)):l=document.createElement(`div`),l.classList.add(`d-flex`),l.innerText=s,c&&l.appendChild(c),a.appendChild(l),a}};function Ie(e,n,r){if(r){let r=V(e)>0;if(e.class&&!e.hasValue)return e.config.theme.createListEditor(e.label,n,r,ve(e.class,e),e);if(e.in){let t=e.config.lists[e.in];if(t?.length){let i=ge(t,e.config.store,e.config.languages);return e.config.theme.createListEditor(e.label,n,r,i,e)}else console.error(`list not found:`,e.in,`existing lists:`,e.config.lists)}if(e.datatype?.equals(ae)||e.languageIn?.length||e.datatype===void 0&&n instanceof t&&n.language)return e.config.theme.createLangStringEditor(e.label,n,r,e);switch(e.datatype?.value.replace(g,``)){case`integer`:case`float`:case`double`:case`decimal`:return e.config.theme.createNumberEditor(e.label,n,r,e);case`date`:case`dateTime`:return e.config.theme.createDateEditor(e.label,n,r,e);case`boolean`:return e.config.theme.createBooleanEditor(e.label,n,r,e);case`base64Binary`:return e.config.theme.createFileEditor(e.label,n,r,e)}return e.config.theme.createTextEditor(e.label,n,r,e)}else return n?e.config.theme.createViewer(e.label,n,e):document.createElement(`div`)}function Le(e,t,n){if(t===`application/ld+json`)return Re(e);{let r=new a({format:t,prefixes:n});r.addQuads(e);let i=``;return r.end((e,t)=>{e&&console.error(e),i=t}),i}}function Re(e){let n=[];for(let r of e){let e={"@id":r.subject.id};if(r.predicate===S)e[`@type`]=r.object.id;else{let n=r.object.value;r.object instanceof t?r.object.language?n={"@language":r.object.language,"@value":r.object.value}:r.object.datatype&&r.object.datatype.value!==`http://www.w3.org/2001/XMLSchema##string`&&(n={"@type":r.object.datatype.value,"@value":r.object.value}):n={"@id":r.object.id},e[r.predicate.value]=n}n.push(e)}return JSON.stringify(n)}function ze(t){let r=t.shaclDatatype,i=t.dataset.value||t.value;if(t.type===`checkbox`||t.getAttribute(`type`)===`checkbox`){if(t.checked||parseInt(t.dataset.minCount||`0`)>0)return e.literal(t.checked?`true`:`false`,r)}else if(i){if(i.startsWith(`<`)&&i.endsWith(`>`)&&i.indexOf(`:`)>-1)return e.namedNode(i.substring(1,i.length-1));if(t.dataset.class||t.dataset.nodeKind===`http://www.w3.org/ns/shacl#IRI`)return e.namedNode(i);if(t.dataset.link)return JSON.parse(t.dataset.link);if(t.dataset.lang?r=t.dataset.lang:t.type===`number`?i=parseFloat(i):t.type===`file`&&t.binaryData?i=t.binaryData:t.type===`datetime-local`&&(i=new Date(i).toISOString().slice(0,19)),(!r||r instanceof n&&fe.equals(r))&&typeof i==`string`){let t=i.split(`^^`);t.length===2&&t[0].startsWith(`"`)&&t[0].endsWith(`"`)&&t[1].split(`:`).length===2?(i=t[0].substring(1,t[0].length-1),r=e.namedNode(t[1])):(t=i.split(`@`),t.length===2&&t[0].startsWith(`"`)&&t[0].endsWith(`"`)?(i=t[0].substring(1,t[0].length-1),r=t[1]):i.startsWith(`"`)&&i.endsWith(`"`)&&(i=i.substring(1,i.length-1)))}return e.literal(i,r)}}var U={};function Be(e){e.predicate===void 0&&e.datatype===void 0?console.warn(`not registering plugin because it does neither define "predicate" nor "datatype"`,e):U[`${e.predicate}^${e.datatype}`]=e}function Ve(){return Object.entries(U).map(e=>e[1])}function He(e,t){let n=U[`${e}^${t}`];return n||(n=U[`${e}^undefined`],n)?n:U[`undefined^${t}`]}var Ue=class{constructor(e,t){this.predicate=e.predicate,this.datatype=e.datatype,t&&(this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t))}createViewer(e,t){return e.config.theme.createViewer(e.label,t,e)}};async function We(e){if(e.template.nodeShapes.size===0)return;let t=e.template.config.resourceLinkProvider;if((!t||t&&!t.lazyLoad)&&(await Je(e.template),Ke(e).length===0))return;let n=e.template.config.theme.createButton(e.template.label,!1);n.title=`Link existing `+e.template.label,n.classList.add(`link-button`),n.setAttribute(`text`,``);let r=n.getAttribute(`part`);return n.setAttribute(`part`,`${r?r+` `:``}link-button`),n.addEventListener(`click`,async()=>{t?.lazyLoad&&(n.classList.add(`loading`),await Je(e.template),n.classList.remove(`loading`));let r=Ke(e);if(r.length===0)n.innerText=`No linkable resources found`,n.setAttribute(`disabled`,``),setTimeout(()=>n.remove(),2e3);else{let t=e.template.config.form.querySelector(`#dialog`);t||(t=new u,t.classList.add(`link-chooser`),t.closable=!0,e.template.config.form.appendChild(t)),t.title=`Link existing `+e.template.label,Ge(t,e,r),t.open=!0}}),n}function Ge(e,t,n){let r=document.createElement(`div`);for(let i of n){let n=document.createElement(`div`);n.classList.add(`link-option`),n.title=`Link this resource`,n.innerText=i.label||i.value,n.addEventListener(`click`,()=>{qe(i.value,t),e.open=!1}),r.appendChild(n)}e.replaceChildren(r)}function Ke(t){let n=[];if(t.template.config.resourceLinkProvider){for(let r of t.template.nodeShapes)if(t.template.config.providedConformingResourceIds[r.id.value])for(let i of t.template.config.providedConformingResourceIds[r.id.value])t.querySelector(`:scope > .property-instance > shacl-node[data-node-id='${i}'], :scope > .collapsible > .property-instance > shacl-node[data-node-id='${i}']`)===null&&n.push({value:i,label:A(t.template.config.store.getQuads(e.namedNode(i),null,null,null),t.template.config.languages),children:[]})}return n}async function qe(t,n){let r=e.namedNode(t);if(Ze(r,n.template.config.store)){if(n.template.config.providedResources[t]?.length>0){let e={store:n.template.config.store,importedUrls:[],atts:{loadOwlImports:!1}};await L(z(n.template.config.providedResources[t]),e,b),n.template.config.providedResources[t]=``}let e=await K(n.template,r,!0,!0);n.container.insertBefore(e,n.querySelector(`:scope > .add-button-wrapper`)),await n.updateControls()}}async function Je(e){let t=e.config.resourceLinkProvider;if(!t)return;let n=new Set(Array.from(e.nodeShapes).map(e=>e.id.value));if(n.size===0)return;let r=xe(Object.keys(e.config.providedConformingResourceIds),n);if(r.length!==0)try{let n=await t.listConformingResources(r,e);if(n){for(let t of Object.keys(n)){let r=new Set(n[t]);e.config.providedConformingResourceIds[t]=r,await Ye(r,!1,e.config)}for(let t of r)e.config.providedConformingResourceIds[t]||(e.config.providedConformingResourceIds[t]=new Set)}}catch(e){console.error(`failed loading conforming resources`,e)}}async function Ye(e,t,n){if(n.resourceLinkProvider&&e.size>0){let r=[];for(let t of e)n.providedResources[t]||r.push(t);if(r.length===0)return[];try{let e=await n.resourceLinkProvider.loadResources(r);if(e){let r={store:n.store,importedUrls:[],atts:{loadOwlImports:!1}};for(let i of e)n.providedResources[i.resourceId]=i.resourceRDF,t&&await L(z(i.resourceRDF),r,b);return e}for(let e of r)n.providedResources[e]||(n.providedResources[e]=``)}catch(e){console.error(`failed loading resources`,e)}}return[]}async function Xe(e){let t=new Set;for(let n of e.store.getQuads(null,null,null,x))Ze(n.object,e.store)&&t.add(n.object.value);await Ye(t,!0,e)}function Ze(e,t){return e.termType===`NamedNode`&&t.countQuads(e,null,null,null)===0}var W=`:scope > .add-button-wrapper, :scope > .collapsible > .add-button-wrapper`,Qe=`:scope > .property-instance, :scope > .shacl-or-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance`,G=class extends HTMLElement{constructor(e,t){if(super(),this.template=e,this.parent=t,this.container=this,this.setAttribute(`part`,`property`),this.template.nodeShapes.size&&this.template.config.attributes.collapse!==null&&(this.template.maxCount===void 0||this.template.maxCount>1)){let t=new l;t.classList.add(`collapsible`,`shacl-group`),t.open=e.config.attributes.collapse===`open`,t.label=this.template.label,t.setAttribute(`part`,`collapsible`),this.container=t,this.appendChild(this.container)}this.template.order!==void 0&&(this.style.order=`${this.template.order}`),this.template.cssClass&&this.classList.add(this.template.cssClass),e.config.editMode&&!t.linked&&this.addEventListener(`change`,async()=>{await this.updateControls()})}async bindValues(e,t){if(this.template.path){let n=!1;if(e){let r=this.template.config.store.getQuads(e,this.template.path,null,this.parent.linked?null:x);t&&(r=await this.filterValidValues(r,e));for(let e of r)this.parent.linked||this.template.config.store.delete(e),await this.addPropertyInstance(e.object,!x.equals(e.graph)||this.template.config.providedResources[e.object.value]!==void 0,this.template.config.providedResources[e.object.value]!==void 0),this.template.hasValue&&e.object.equals(this.template.hasValue)&&(n=!0)}this.template.config.editMode&&this.template.hasValue&&!n&&!this.parent.linked&&await this.addPropertyInstance(this.template.hasValue)}}async addPropertyInstance(e,t,n=!1){let r;if(this.template.or?.length||this.template.xone?.length){let t=this.template.or?.length?this.template.or:this.template.xone,n=!1;if(e){let i=Me(t,e,this.template.config);i.length&&(r=await K(H(ke(this.template),i),e,!this.parent.linked,this.parent.linked,this.parent),n=!0)}!n&&this.template.config.editMode&&(r=je(t,this,this.template.config),$e(r,``,this.template.config.theme.dense,this.template.config.hierarchyColorsStyleSheet!==void 0))}else r=await K(this.template,e,n,t||this.parent.linked,this.parent);return r&&this.container.insertBefore(r,this.querySelector(W)),r}async updateControls(){this.template.config.editMode&&!this.parent.linked&&!this.querySelector(W)&&this.container.appendChild(await this.createAddControls());let e=V(this.template),t=this.template.nodeShapes.size===0,n=this.querySelector(`:scope > .add-button-wrapper > .link-button, :scope > .collapsible > .add-button-wrapper > .link-button`)===null,r=t||!this.hasRecursiveNodeShape(),i=this.instanceCount();i===0&&r&&(t||n&&e>0)&&(await this.addPropertyInstance(),i=1),t||this.querySelector(W)?.classList.toggle(`required`,i<e);let a;a=e>0?i>e:!t||i>1;let o=i<Oe(this.template);this.classList.toggle(`may-remove`,a),this.classList.toggle(`may-add`,o)}instanceCount(){return this.querySelectorAll(Qe).length}hasRecursiveNodeShape(){let e=new Set;this.parent.ancestorShapeIds.forEach(t=>e.add(t)),e.add(this.parent.template.id.value);for(let t of this.template.nodeShapes)if(e.has(t.id.value))return!0;return!1}toRDF(t,n){let r=e.namedNode(this.template.path);for(let e of this.querySelectorAll(`:scope > .property-instance, :scope > .collapsible > .property-instance`))if(e.firstChild instanceof q){let i=e.firstChild.toRDF(t);t.addQuad(n,r,i,this.template.config.valuesGraphId)}else if(this.template.config.editMode)for(let i of e.querySelectorAll(`:scope > .editor`)){let e=ze(i);e&&t.addQuad(n,r,e,this.template.config.valuesGraphId)}else{let i=ze(e);i&&t.addQuad(n,r,i,this.template.config.valuesGraphId)}}async filterValidValues(e,t){let n=this.template.id,r=[t];if(this.template.qualifiedValueShape){n=this.template.qualifiedValueShape.id,r=[];for(let t of e)r.push(t.object)}let i=await this.template.config.validator.validate({dataset:this.template.config.store,terms:r},[{terms:[n]}]),a=new Set;for(let e of i.results){let t=this.template.qualifiedValueShape?e.focusNode:e.value;t?.ptrs?.length&&a.add(t.ptrs[0]._term.id)}return e.filter(e=>!a.has(e.object.id))}async createAddControls(){let e=document.createElement(`div`);e.classList.add(`add-button-wrapper`),e.setAttribute(`part`,`add-controls`);let t=await We(this);t&&e.appendChild(t);let n=this.template.config.theme.createButton(this.template.label,!1);n.title=`Add `+this.template.label,n.classList.add(`add-button`),n.setAttribute(`text`,``);let r=n.getAttribute(`part`);return n.setAttribute(`part`,`${r?r+` `:``}add-button`),n.addEventListener(`click`,async()=>{let e=await this.addPropertyInstance();e&&(e.classList.add(`fadeIn`),await this.updateControls(),setTimeout(()=>{he(e),e.classList.remove(`fadeIn`)},200))}),e.appendChild(n),e}};async function K(e,n,r=!1,i=!1,a){let o;if(e.nodeShapes.size){o=document.createElement(`div`),o.classList.add(`property-instance`),o.setAttribute(`part`,`property-instance`);let t=new Set(a?.ancestorShapeIds??[]);a&&t.add(a.template.id.value);for(let r of e.nodeShapes){let a=new q(r,n,e.nodeKind,e.label,i,t);o.appendChild(a),await a.ready}}else{let t=He(e.path,e.datatype?.value);o=t?e.config.editMode&&!i?t.createEditor(e,n):t.createViewer(e,n):Ie(e,n||null,e.config.editMode&&!i),o.childNodes.length>0&&(o.classList.add(`property-instance`),o.setAttribute(`part`,`property-instance`)),i&&o.classList.add(`linked`)}return e.config.editMode&&(!i||r)?$e(o,e.label,e.config.theme.dense,e.config.hierarchyColorsStyleSheet!==void 0,r):e.config.hierarchyColorsStyleSheet!==void 0&&o.appendChild(et(!0)),n&&!e.config.editMode&&(n instanceof t?(o.dataset.value=n.value,n.language.length>0?o.dataset.lang=n.language:o.shaclDatatype=n.datatype):o.dataset.value=`<`+n.value+`>`),o.dataset.path=e.path,o}function $e(e,t,n,r,i=!1){let a=et(r),o=new c;o.classList.add(`remove-button`,`clear`),o.title=`Remove `+t,o.dense=n,o.icon=!0;let s=o.getAttribute(`part`);o.setAttribute(`part`,`${s?s+` `:``}remove-button`),o.addEventListener(`click`,()=>{e.classList.remove(`fadeIn`),e.classList.add(`fadeOut`),setTimeout(()=>{let t=e.parentElement;e.remove(),t?.dispatchEvent(new Event(`change`,{bubbles:!0,cancelable:!0}))},200)}),i&&o.classList.add(`persistent`),a.appendChild(o),e.appendChild(a)}function et(e){let t=document.createElement(`div`);return t.className=`remove-button-wrapper`,t.setAttribute(`part`,`remove-controls`),e&&t.classList.add(`colorize`),t}window.customElements.define(`shacl-property`,G);function tt(e,t){let n=e,r=t.store.getQuads(e,null,null,null),i=k(r,`label`,v,t.languages);i&&(n=i);let a;if(t.attributes.collapse!==null)a=new l,a.classList.add(`collapsible`),a.open=t.attributes.collapse===`open`,a.label=n,a.setAttribute(`part`,`group collapsible`);else{a=document.createElement(`div`);let e=document.createElement(`h1`);e.innerText=n,e.setAttribute(`part`,`group-title`),a.appendChild(e),a.setAttribute(`part`,`group`)}a.dataset.subject=e,a.classList.add(`shacl-group`);let o=k(r,`order`);return o&&(a.style.order=o),a}var q=class t extends HTMLElement{constructor(n,r,i,a,o,s=new Set){super(),this.template=n,this.linked=o??!1,this.ancestorShapeIds=s,this.setAttribute(`part`,`node`);let c=r;c||=(!i&&n.nodeKind&&(i=n.nodeKind),i===void 0&&n.config.attributes.valuesNamespace||i?.value===`http://www.w3.org/ns/shacl#IRI`?e.namedNode(n.config.attributes.valuesNamespace+m()):e.blankNode(m())),this.nodeId=c;let l=JSON.stringify([n.id,r]);if(r&&n.config.renderedNodes.has(l)){a||=`Link`;let e=document.createElement(`label`);e.innerText=a,e.classList.add(`linked`),this.appendChild(e);let t=this.getAttribute(`part`);this.setAttribute(`part`,`${t?t+` `:``}linked-node`);let n=document.createElement(`a`),i=r.termType===`BlankNode`?`_:`+r.value:r.value;n.innerText=i,n.classList.add(`ref-link`),n.onclick=()=>{this.template.config.form.querySelector(`shacl-node[data-node-id='${i}']`)?.scrollIntoView()},this.appendChild(n),this.style.flexDirection=`row`,this.ready=Promise.resolve()}else{r&&n.config.renderedNodes.add(l);let e=this.ancestorShapeIds,i=this.template.id.value;if(this.dataset.nodeId=this.nodeId.id,this.template.config.attributes.showNodeIds!==null){let e=document.createElement(`div`);e.innerText=`id: ${this.nodeId.id}`,e.classList.add(`node-id-display`),this.appendChild(e)}this.ready=(async()=>{let s=new Set(e);s.add(i);for(let[e,t]of Object.entries(n.properties))for(let e of t)await this.addPropertyInstance(e,r,t.length>1);for(let e of n.extendedShapes){let n=new t(e,r,void 0,void 0,o,s);this.prepend(n),await n.ready}if(n.or?.length&&await this.tryResolve(n.or,r,n.config),n.xone?.length&&await this.tryResolve(n.xone,r,n.config),a){let e=document.createElement(`h1`);e.innerText=a,e.setAttribute(`part`,`node-title`),this.prepend(e)}})()}}toRDF(t,n,r=``){if(n||=this.nodeId,!this.linked){for(let e of this.querySelectorAll(`:scope > shacl-node, :scope > .shacl-group > shacl-node, :scope > shacl-property, :scope > .shacl-group > shacl-property`))e.toRDF(t,n);this.template.targetClass&&t.addQuad(n,S,this.template.targetClass,this.template.config.valuesGraphId),r&&t.addQuad(n,e.namedNode(r),this.template.id,this.template.config.valuesGraphId)}return n}async addPropertyInstance(e,t,n){let r=null;if(e.group)if(e.config.groups.indexOf(e.group)>-1){let t=this.querySelector(`:scope > .shacl-group[data-subject='${e.group}']`);t||(t=tt(e.group,e.config),this.appendChild(t)),r=t}else console.warn(`ignoring unknown group reference`,e.group,`existing groups:`,e.config.groups);let i=new G(e,this);await i.bindValues(t,n),(e.config.editMode||i.instanceCount()>0)&&(r?r.appendChild(i):this.appendChild(i),await i.updateControls())}async tryResolve(e,t,n){let r=!1;if(t){let i=Ne(e,t,n);if(i.length){for(let e of i)await this.addPropertyInstance(n.getPropertyTemplate(e,this.template),t);r=!0}}r||this.appendChild(je(e,this,n))}};window.customElements.define(`shacl-node`,q);var nt=`
.editor:not([type='checkbox']) { border: 1px solid var(--shacl-border-color, #DDD); }
.property-instance label { display: inline-flex; word-break: break-word; line-height: 1em; padding-top: 0.15em; padding-right: 1em; flex-shrink: 0; position: relative; }
.property-instance:not(:first-child) > label:not(.persistent) { visibility: hidden; max-height: 0; }
.mode-edit .property-instance label { width: var(--label-width); }
`,J=class extends Fe{constructor(e){super(e||nt),this.idCtr=0}createDefaultTemplate(r,i,a,o,s){if(o.id=`e${this.idCtr++}`,o.classList.add(`editor`),o.setAttribute(`part`,`editor`),s?.datatype?o.shaclDatatype=s.datatype:i instanceof t&&(o.shaclDatatype=i.datatype),s&&V(s)>0&&(o.dataset.minCount=String(V(s))),s?.class&&(o.dataset.class=s.class.value),s?.nodeKind)o.dataset.nodeKind=s.nodeKind.value;else if(i&&(i instanceof n||s?.nodeKind?.equals(le))&&(o.dataset.nodeKind=h+`IRI`,s)){let t=A(s.config.store.getQuads(i,null,null,null),s.config.languages);t&&(o.dataset.value=`<`+i.value+`>`,i=e.literal(t))}(s?.hasValue&&i||s?.readonly)&&(o.disabled=!0),s?.datatype?.equals(pe)?o.checked=i?.value===`true`||s?.defaultValue?.value===`true`:o.value=i?.value||s?.defaultValue?.value||``;let c=document.createElement(`label`);c.htmlFor=o.id,c.innerText=r,c.setAttribute(`part`,`label`),s?.description&&c.setAttribute(`title`,s.description.value);let l=s?.description?s.description.value:s?.pattern?s.pattern:null;l&&o.setAttribute(`placeholder`,l),a&&(o.setAttribute(`required`,`true`),c.classList.add(`required`));let u=document.createElement(`div`);return u.setAttribute(`part`,`field`),u.appendChild(c),u.appendChild(o),u}createDateEditor(e,t,n,r){let i=new d;r.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?(i.type=`datetime-local`,i.setAttribute(`step`,`1`)):i.type=`date`,i.clearable=!0,i.dense=this.dense,i.classList.add(`pr-0`);let a=this.createDefaultTemplate(e,null,n,i,r);if(t)try{let e=new Date(t.value).toISOString();e=r.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?e.slice(0,19):e.slice(0,10),i.value=e}catch(e){console.error(e,t)}return a}createTextEditor(e,t,n,r){let i;return r.singleLine===!1?(i=new p,i.resize=`auto`):i=new d,i.dense=this.dense,r.pattern&&(i.pattern=r.pattern),r.minLength&&(i.minLength=r.minLength),r.maxLength&&(i.maxLength=r.maxLength),this.createDefaultTemplate(e,t,n,i,r)}createLangStringEditor(e,n,r,i){let a=this.createTextEditor(e,n,r,i),o=a.querySelector(`:scope .editor`),s;if(i.languageIn?.length){s=document.createElement(`select`);for(let e of i.languageIn){let t=document.createElement(`option`);t.innerText=e.value,s.appendChild(t)}}else s=document.createElement(`input`),s.maxLength=5,s.size=5,s.placeholder=`lang?`;return s.title=`Language of the text`,s.classList.add(`lang-chooser`),s.setAttribute(`part`,`lang-chooser`),s.slot=`suffix`,o.addEventListener(`change`,()=>{s.required=o.value!==``}),s.addEventListener(`change`,e=>{e.stopPropagation(),o&&(o.dataset.lang=s.value,o.dispatchEvent(new Event(`change`,{bubbles:!0})))}),n instanceof t&&(s.value=n.language),o.dataset.lang=s.value,o.appendChild(s),a}createBooleanEditor(e,n,r,i){let a=document.createElement(`input`);a.type=`checkbox`,a.classList.add(`ml-0`);let o=this.createDefaultTemplate(e,null,r,a,i);return a.removeAttribute(`required`),o.querySelector(`:scope label`)?.classList.remove(`required`),n instanceof t&&(a.checked=n.value===`true`),o}createFileEditor(e,t,n,r){let i=document.createElement(`input`);return i.type=`file`,i.addEventListener(`change`,e=>{if(i.files?.length){e.stopPropagation();let t=new FileReader;t.readAsDataURL(i.files[0]),t.onload=()=>{i.binaryData=btoa(t.result),i.parentElement?.dispatchEvent(new Event(`change`,{bubbles:!0}))}}else i.binaryData=void 0}),this.createDefaultTemplate(e,t,n,i,r)}createNumberEditor(e,t,n,r){let i=new d;i.type=`number`,i.clearable=!0,i.dense=this.dense,i.classList.add(`pr-0`);let a=r.minInclusive===void 0?r.minExclusive===void 0?void 0:r.minExclusive+1:r.minInclusive,o=r.maxInclusive===void 0?r.maxExclusive===void 0?void 0:r.maxExclusive-1:r.maxInclusive;return a!==void 0&&(i.min=String(a)),o!==void 0&&(i.max=String(o)),r.datatype?.value!==`http://www.w3.org/2001/XMLSchema#integer`&&(i.step=`any`),this.createDefaultTemplate(e,t,n,i,r)}createListEditor(e,t,r,i,a){let o=new f;o.clearable=!0,o.dense=this.dense;let s=this.createDefaultTemplate(e,null,r,o,a),c=document.createElement(`ul`),l=!0,u=(e,t)=>{let r=document.createElement(`li`);if(typeof e.value==`string`?(r.dataset.value=e.value,r.innerText=e.label?e.label:e.value):(r.dataset.value=e.value.id,e.value instanceof n&&(r.dataset.value=`<`+r.dataset.value+`>`),r.innerText=e.label?e.label:e.value.value),t.appendChild(r),e.children?.length){l=!1;let t=document.createElement(`ul`);r.appendChild(t);for(let n of e.children)u(n,t)}};for(let e of i)u(e,c);return l||(o.collapse=!0),o.appendChild(c),t=t??a?.defaultValue??null,t&&(o.value=t.id,t instanceof n&&(o.value=`<`+o.value+`>`)),s}createButton(e,t){let n=new c;return n.dense=this.dense,n.innerHTML=e,t?(n.setAttribute(`primary`,``),n.setAttribute(`part`,`button primary`)):n.setAttribute(`part`,`button`),n}},rt={[`${h}node`]:(e,t)=>{e.extendedShapes.add(new Y(t,e.config,e))},[`${h}and`]:(e,t)=>{for(let n of e.config.lists[t.value])e.extendedShapes.add(new Y(n,e.config,e))},[`${h}property`]:(e,t)=>{let n=e.config.getPropertyTemplate(t,e);if(n.path){let t=e.properties[n.path];if(t||(t=[],e.properties[n.path]=t),n.qualifiedValueShape)t.push(n);else{let r;for(let t=0;t<e.properties[n.path].length&&!r;t++)e.properties[n.path][t].qualifiedValueShape||(r=e.properties[n.path][t]);r?Ae(r,n):t.push(n)}}},[`${h}nodeKind`]:(e,t)=>{e.nodeKind=t},[`${h}targetClass`]:(e,t)=>{e.targetClass=t},[`${h}or`]:(e,t)=>{e.or=e.config.lists[t.value]},[`${h}xone`]:(e,t)=>{e.xone=e.config.lists[t.value]},[w.id]:(e,t)=>{e.owlImports.add(t)},[`${y}title`]:(e,t)=>{let n=t;e.label=N(e.config.languages,e.label,n)},[`${v}label`]:(e,t)=>{let n=t;e.label=N(e.config.languages,e.label,n)}},Y=class{constructor(e,t,n){this.extendedShapes=new Set,this.properties={},this.owlImports=new Set,this.id=e,this.config=t,this.parent=n,t.registerNodeTemplate(this),it(this,this.config.store.getQuads(e,null,null,null))}};function it(e,t){for(let n of t)rt[n.predicate.id]?.call(e,e,n.object);return e}function at(e){for(let t of Object.values(e.properties))for(let n of t){let[t,r]=X(e,n.path);if(t.length>1&&r){let e=t[t.length-1];for(let n=t.length-2;n>=0;n--){let r=t[n];delete r.parent.properties[r.path],Ae(e,r)}}}}function X(e,t,n=new Set,r=[],i=!1){if(!n.has(e.id.value)){n.add(e.id.value);let a=e.properties[t];if(a?.length===1){r.push(a[0]),i||=a[0].maxCount===1;for(let e of a[0].nodeShapes){let[a,o]=X(e,t,n,r,i);i||=o}}for(let a of e.extendedShapes){let[e,o]=X(a,t,n,r,i);i||=o}}return[r,i]}var Z=class{constructor(){this.shapes=null,this.shapesUrl=null,this.shapeSubject=null,this.values=null,this.valuesUrl=null,this.valueSubject=null,this.valuesSubject=null,this.valuesNamespace=``,this.valuesGraph=null,this.view=null,this.language=null,this.loading=`Loading…`,this.proxy=null,this.ignoreOwlImports=null,this.collapse=null,this.hierarchyColors=null,this.submitButton=null,this.generateNodeShapeReference=C.value,this.showNodeIds=null,this.showRootShapeLabel=null,this.dense=`true`,this.useShadowRoot=`true`}},ot=`#4c93d785, #f85e9a85, #00327385, #87001f85`,Q=class{constructor(t){this.attributes=new Z,this.editMode=!0,this.lists={},this.groups=[],this.renderedNodes=new Set,this._store=new r,this._nodeTemplates={},this._propertyTemplates={},this.validator=new ee(this._store,{details:!0,factory:e}),this.providedConformingResourceIds={},this.providedResources={},this.form=t,this._theme=new J,this.languages=[...new Set(navigator.languages.flatMap(e=>e.length>2?[e.toLocaleLowerCase(),e.substring(0,2)]:e)),``]}reset(){this.lists={},this.groups=[],this.renderedNodes.clear(),this.providedConformingResourceIds={},this.providedResources={},this._nodeTemplates={},this._propertyTemplates={}}updateAttributes(t){let n=new Z;if(Object.keys(n).forEach(e=>{let r=t.dataset[e];r!==void 0&&(n[e]=r)}),this.editMode=n.view===null,this.theme.setDense(n.dense===`true`),this.attributes=n,this.attributes.valueSubject&&!this.attributes.valuesSubject&&(this.attributes.valuesSubject=this.attributes.valueSubject),n.language){let e=this.languages.indexOf(n.language);e>-1&&this.languages.splice(e,1),this.languages.unshift(n.language)}if(n.valuesGraph&&(this.valuesGraphId=e.namedNode(n.valuesGraph)),n.hierarchyColors!=null){let e=n.hierarchyColors.length?n.hierarchyColors:ot,t=`:host { --hierarchy-colors: ${e}; --hierarchy-colors-length: ${e.split(`,`).length} }`;for(let e=8;e>=0;e--){let n=`shacl-property { --hierarchy-level: ${e} }`;for(let t=0;t<e;t++)n=`shacl-property `+n;t=t+`
`+n}this.hierarchyColorsStyleSheet=new CSSStyleSheet,this.hierarchyColorsStyleSheet.replaceSync(t)}}static dataAttributes(){let e=new Z;return Object.keys(e).map(e=>(e=e.replace(/[A-Z]/g,e=>`-`+e.toLowerCase()),`data-`+e))}buildTemplateKey(e,t){let n=e.value;return t&&(t instanceof B?n+=`*`+t.id.value:n+=`*`+this.buildTemplateKey(t.id,t.parent)),n}registerNodeTemplate(e){this._nodeTemplates[this.buildTemplateKey(e.id,e.parent)]=e}registerPropertyTemplate(e){this._propertyTemplates[this.buildTemplateKey(e.id,e.parent)]=e}getNodeTemplateIds(){let e=new Set;for(let t of Object.values(this._nodeTemplates))e.add(t.id.value);return e}getNodeTemplate(e,t){let n=this.buildTemplateKey(e,t),r=this._nodeTemplates[n];return r||=new Y(e,this,t),r}getPropertyTemplate(e,t){let n=this.buildTemplateKey(e,t),r=this._propertyTemplates[n];return r||=new B(e,t),r}get nodeTemplates(){return Object.values(this._nodeTemplates)}get theme(){return this._theme}set theme(e){this._theme=e,e.setDense(this.attributes.dense===`true`)}get store(){return this._store}set store(t){this._store=t,this.lists=Se(t,{ignoreErrors:!0}),this.groups=[],t.forSubjects(e=>{this.groups.push(e.id)},S,`${h}PropertyGroup`,null),this.validator=new ee(t,{details:!0,factory:e})}},st=200,$=class extends HTMLElement{static get observedAttributes(){return Q.dataAttributes()}constructor(){super(),this.shape=null,this.styleElement=null,this.form=document.createElement(`form`),this.form.setAttribute(`part`,`form`),this.config=new Q(this.form),this.form.addEventListener(`change`,e=>{e.stopPropagation(),this.config.editMode&&this.validate(!0).then(e=>{this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,cancelable:!1,composed:!0,detail:{valid:e.conforms,report:e}}))}).catch(e=>{console.warn(e)})})}connectedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),this.initialize()}attributeChangedCallback(){this.config.updateAttributes(this),this.ensureRenderRoot(),this.initialize()}initialize(){clearTimeout(this.initDebounceTimeout),this.setAttribute(`loading`,``),this.form.replaceChildren(document.createTextNode(this.config.attributes.loading)),this.initDebounceTimeout=setTimeout(async()=>{try{this.config.reset(),this.config.store=await we({shapes:this.config.attributes.shapes,shapesUrl:this.config.attributes.shapesUrl,values:this.config.attributes.values,valuesUrl:this.config.attributes.valuesUrl,valuesSubject:this.config.attributes.valuesSubject,loadOwlImports:this.config.attributes.ignoreOwlImports===null,classInstanceProvider:this.config.classInstanceProvider,proxy:this.config.attributes.proxy}),this.config.resourceLinkProvider&&await Xe(this.config),this.config.attributes.valuesSubject||(this.config.attributes.valuesSubject=I(this.config.store)||null),this.form.replaceChildren();let t=this.findRootShaclShapeSubject();if(t){this.form.classList.forEach(e=>{this.form.classList.remove(e)}),this.form.classList.toggle(`mode-edit`,this.config.editMode),this.form.classList.toggle(`mode-view`,!this.config.editMode),this.config.theme.apply(this.form);let n=[this.config.theme.stylesheet];this.config.hierarchyColorsStyleSheet&&n.push(this.config.hierarchyColorsStyleSheet);for(let e of Ve())e.stylesheet&&n.push(e.stylesheet);this.applyStyles(n);let r=new Y(t,this.config);for(let e of this.config.nodeTemplates)at(e);if(this.shape=new q(r,this.config.attributes.valuesSubject?e.namedNode(this.config.attributes.valuesSubject):void 0),this.form.appendChild(this.shape),this.config.attributes.showRootShapeLabel!==null&&r.label){let e=document.createElement(`h3`);e.innerText=r.label.value,this.form.prepend(e)}if(this.config.editMode){if(this.config.attributes.submitButton!==null){let e=this.config.theme.createButton(this.config.attributes.submitButton||`Submit`,!0);e.classList.add(`submit-button`);let t=e.getAttribute(`part`);e.setAttribute(`part`,`${t?t+` `:``}submit-button`),e.addEventListener(`click`,e=>{e.preventDefault(),this.form.reportValidity()&&this.validate().then(e=>{if(e?.conforms)this.dispatchEvent(new Event(`submit`,{bubbles:!0,cancelable:!0}));else{let e=this.form.querySelector(`:scope .invalid > .editor`);e?e.focus():this.form.querySelector(`:scope .invalid`)?.scrollIntoView()}})}),this.form.appendChild(e)}(async()=>{await this.shape?.ready,this.config.attributes.valuesSubject&&this.removeFromDataGraph(e.namedNode(t