@ulb-darmstadt/shacl-form 3.7.1 → 3.7.3

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.
@@ -0,0 +1,13 @@
1
+ import{A as e,G as t,I as n,J as r,L as i,P as a,a as o,dt as s,et as c,g as l,h as u,it as d,m as f,mt as p,n as m,o as h,ot as g,s as _,t as v,tt as y,x as b,y as x}from"./query-DXre6-Ec.js";function S(e,t){let n=document.createElement(`div`),r=!!(t.facet||t.in||t.class||t.datatype?.equals(s));n.classList.add(`query-editor`),n.dataset.queryFieldId=e.id,n.setAttribute(`part`,`query-editor`);let i=document.createElement(`label`);i.textContent=t.label,t.description&&(i.title=t.description.value),n.appendChild(i);let a=document.createElement(`div`);a.classList.add(`query-controls`),n.appendChild(a);let o,c=j(t),f,p,m=(e=``)=>{let n=document.createElement(`div`);n.classList.add(`query-value-row`);let r=new u;r.classList.add(`editor`,`query-choice`),r.clearable=!0,r.dense=t.config.theme.dense,r.placeholder=``,r.setAttribute(`exportparts`,`facet-count`);let i=document.createElement(`ul`);for(let e of c){let t=document.createElement(`li`);if(t.dataset.value=I(e.term),t.textContent=e.label,e.count!==void 0){let n=document.createElement(`span`);n.classList.add(`facet-count`),n.setAttribute(`part`,`facet-count`),n.dataset.count=String(e.count),t.append(` `,n)}i.appendChild(t)}return r.appendChild(i),r.value=e,n.appendChild(r),n},h=(e=[])=>{a.replaceChildren(),a.appendChild(m(e[0]??``))},g=(e,n=``)=>{let r=new l;return r.classList.add(`editor`,`query-range-bound`),r.type=F(t),r.label=e,r.clearable=!0,r.dense=t.config.theme.dense,r.value=n,r},_=e=>{a.replaceChildren();let r=C(t,o);r&&r[0]<r[1]&&(f=r);let i=p??A(r,e&&f);if(n.unavailable=!!(i&&i[0]===i[1]),n.unavailable)return;if(!i){a.append(g(`Minimum`,e?.min?.value),g(`Maximum`,e?.max?.value));return}(e?.min||e?.max)&&(p??=i);let s=new x;s.classList.add(`editor`,`query-range-slider`),s.dense=t.config.theme.dense,s.clearable=!0,s.range=``,s.setAttribute(`range`,``),s.min=String(i[0]),s.max=String(i[1]),s.step=String(w(t,i)),s.labelFormatter=e=>T(e,t);let c=e?.min?E(e.min,t):i[0],l=e?.max?E(e.max,t):i[1];s.value=JSON.stringify([k(c??i[0],i[0],i[1]),k(l??i[1],i[0],i[1])]),s.dataset.active=e?.min||e?.max?`true`:`false`,s.addEventListener(`change`,()=>{s.dataset.active=`true`,p??=[Number(s.min),Number(s.max)]}),a.appendChild(s)};return n.getQueryCriteria=()=>{if(v(e)){let n=a.querySelector(`rokit-slider`);if(n){if(n.dataset.active!==`true`)return[];let r=O(n.value);return r?[{field:e,operator:`range`,min:D(r[0],t),max:D(r[1],t)}]:[]}let r=a.querySelectorAll(`rokit-input`),i=N(r[0]?.value,t),o=N(r[1]?.value,t);return i||o?[{field:e,operator:`range`,min:i,max:o}]:[]}if(r)return Array.from(a.querySelectorAll(`rokit-select`)).flatMap(t=>{if(!t.value)return[];let n=c.find(e=>I(e.term)===t.value)?.term;return n?[{field:e,operator:`equals`,value:n}]:[]});let n=P(t)&&!t.class&&!t.nodeKind?.value.endsWith(`#IRI`)?`contains`:`equals`;return Array.from(a.querySelectorAll(`.query-value-row`)).flatMap(r=>{let i=r.querySelector(`.query-value`),a=r.querySelector(`.query-language`)?.value,o=N(i?.value,t,a);return o?[{field:e,operator:n,value:o}]:[]})},n.clearQueryCriteria=()=>{if(v(e)){p=void 0,f=void 0;let e=a.querySelector(`rokit-slider`);if(e)e.dataset.active=`false`,e.value=JSON.stringify([Number(e.min),Number(e.max)]);else for(let e of a.querySelectorAll(`rokit-input`))e.value=``}else if(r)for(let e of a.querySelectorAll(`rokit-select`))e.value=``;else for(let e of a.querySelectorAll(`.query-value`))e.value=``},n.setQueryFacet=i=>{let s=n.getQueryCriteria();if(o=i,r&&o?.buckets){let e=new Map(j(t).map(e=>[I(e.term),e])),n=new Map(s.flatMap(e=>e.value?[[I(e.value),e.value]]:[]));c=o.buckets.flatMap(n=>{let r=e.get(I(n.value));return t.in&&!r?[]:[{term:n.value,label:n.label??r?.label??n.value.value,count:n.count}]});for(let[t,r]of n)c.some(e=>I(e.term)===t)||c.push({term:r,label:e.get(t)?.label??r.value,count:0});let r=!1;if(n.size===0&&o.initialValue){let e=I(o.initialValue);c.some(t=>I(t.term)===e)&&(n.set(e,o.initialValue),r=!0)}return h([...n.keys()]),r}else if(v(e)){let e=s[0];_(e?{min:e.min,max:e.max}:void 0)}else if(!i)for(let e of a.querySelectorAll(`.query-value`))e.value=``;return!1},v(e)?_():r?h():(a.replaceChildren(),a.appendChild((()=>{let e=document.createElement(`div`);e.classList.add(`query-value-row`);let r=new l;r.classList.add(`editor`,`query-value`),r.type=F(t),r.clearable=!0,r.dense=t.config.theme.dense;let i;if(r.addEventListener(`input`,()=>{clearTimeout(i),i=setTimeout(()=>{n.dispatchEvent(new Event(`change`,{bubbles:!0}))},300)}),e.appendChild(r),t.datatype?.equals(d)){let n=t.languageIn?.length?document.createElement(`select`):document.createElement(`input`);if(n.classList.add(`lang-chooser`,`query-language`),n.title=`Language of the text`,n.setAttribute(`aria-label`,`Language of the text`),n instanceof HTMLSelectElement)for(let e of t.languageIn??[]){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.value,n.appendChild(t)}else n.maxLength=35,n.placeholder=`lang?`,n.value=t.config.languages.find(e=>e.length>0)??``;e.appendChild(n)}return e})())),n}function C(e,t){let n=t?.min?E(t.min,e):void 0,r=t?.max?E(t.max,e):void 0,i=e.minInclusive??(e.minExclusive===void 0?void 0:e.minExclusive+1),a=e.maxInclusive??(e.maxExclusive===void 0?void 0:e.maxExclusive-1),o=n!==void 0&&r!==void 0,s=o?n:n===void 0?i:i===void 0?n:Math.max(n,i),c=o?r:r===void 0?a:a===void 0?r:Math.min(r,a);return s!==void 0&&c!==void 0&&Number.isFinite(s)&&Number.isFinite(c)&&s<=c?[s,c]:void 0}function w(e,t){return e.datatype?.value===`http://www.w3.org/2001/XMLSchema#integer`?1:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?86400:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?1:Math.max((t[1]-t[0])/1e3,2**-52)}function T(e,t){return t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?f(e,!0):t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?f(e):String(Math.round(e*1e3)/1e3)}function E(e,t){if(t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`||t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`){let t=Date.parse(e.value);return Number.isFinite(t)?t/1e3:void 0}let n=Number(e.value);return Number.isFinite(n)?n:void 0}function D(e,t){let n=t.datatype;return n?.value===`http://www.w3.org/2001/XMLSchema#date`?p.literal(f(e,!0),n):n?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?p.literal(f(e),n):p.literal(String(e),n)}function O(e){try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===2&&t.every(Number.isFinite)?[Number(t[0]),Number(t[1])]:void 0}catch{return}}function k(e,t,n){return Math.min(n,Math.max(t,e))}function A(e,t){return e&&e[0]<e[1]?e:t||e}function j(e){if(e.datatype?.equals(s))return[{term:p.literal(`true`,s),label:`true`},{term:p.literal(`false`,s),label:`false`}];let n=[];return e.in?n=t(e.config.lists[e.in]??[],e.config.store,e.config.languages):e.class&&(n=r(e.class,e)),M(n)}function M(e){return e.flatMap(e=>[...typeof e.value==`string`?[]:[{term:e.value,label:e.label||e.value.value}],...M(e.children??[])])}function N(e,t,n){if(e)return t.class||t.nodeKind?.value.endsWith(`#IRI`)?p.namedNode(e):t.datatype?.equals(d)?n?p.literal(e,n):void 0:t.datatype?p.literal(e,t.datatype):p.literal(e)}function P(e){return!e.datatype||e.datatype.value===`http://www.w3.org/2001/XMLSchema#string`||e.datatype.equals(d)}function F(e){let t=e.datatype?.value;return[`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`].includes(t??``)?`number`:t===`http://www.w3.org/2001/XMLSchema#date`?`date`:t===`http://www.w3.org/2001/XMLSchema#dateTime`?`datetime-local`:`text`}function I(e){if(e.termType===`Literal`){let t=e;return`${e.termType}:${e.value}:${t.language}:${t.datatype?.value}`}return`${e.termType}:${e.value}`}var L=`form.mode-query { padding: 0; }
2
+ :host([loading]) form.mode-query > shacl-node { display: none; }
3
+ .mode-query shacl-property.query-unavailable { display: none; }
4
+ .mode-query .shacl-group:not(:has(shacl-property:not(.query-unavailable))), .mode-query shacl-node:not(:has(shacl-property:not(.query-unavailable))) { display: none; }
5
+ .query-editor { display: flex; align-items: center; width: 100%; padding: 3px 0; }
6
+ .query-editor > label { width: var(--label-width); flex-shrink: 0; padding-right: 1em; word-break: break-word; }
7
+ .query-controls { display: flex; flex: 1; min-width: 0; }
8
+ .query-controls > rokit-input, .query-controls > rokit-slider, .query-value-row > rokit-input, .query-value-row > rokit-select { min-height: 28px; width: 100%; flex-grow: 1; }
9
+ .query-value-row { display: flex; flex: 1; width: 100%; min-width: 0; gap: 4px; }
10
+ .query-language { min-height: 28px; flex: 0 0 auto; }
11
+ .query-range-slider[data-active='false'] { opacity: 0.7; }
12
+ .query-facet-error .query-editor > label { color: var(--shacl-error-color); }
13
+ `,R=0,z=class{constructor(e){this.stylesheet=new CSSStyleSheet,this.facetRequest=0,this.facetsApplied=!1,this.host=e,this.stylesheet.replaceSync(L),e.config.queryFacetProvider&&this.setFacetsPending(!0)}async initialize(){await this.emitQueryAndRefreshFacets()}handleChange(){this.emitQueryAndRefreshFacets()}getQuery(){let e=this.host.shape;return e?{rootShapeId:e.template.id.value,targetClass:e.template.targetClass?.value,criteria:Array.from(this.host.form.querySelectorAll(`.query-editor`)).flatMap(e=>e.getQueryCriteria())}:{rootShapeId:``,criteria:[]}}refreshFacets(){this.host.shape&&this.requestFacets(this.getQuery())}dispose(){this.facetAbortController?.abort(),this.setFacetsPending(!1),this.host.classList.remove(`query-facets-empty`)}async emitQueryAndRefreshFacets(){if(!this.host.shape)return;let e=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),t=this.getQuery(),n=this.host.config.queryFacetProvider;if(this.previousQuery&&n?.invalidatedFields){let r=new Set(n.invalidatedFields({previousQuery:this.previousQuery,query:t,fields:e}));for(let e of this.host.form.querySelectorAll(`.query-editor`))r.has(e.queryField.id)&&e.clearQueryCriteria?.();t=this.getQuery()}this.previousQuery=t,this.host.dispatchEvent(new CustomEvent(`query`,{bubbles:!0,composed:!0,detail:t})),await this.requestFacets(t)}async requestFacets(e){let t=this.host.config.queryFacetProvider;if(!t)return;this.facetAbortController?.abort();let n=new AbortController;this.facetAbortController=n;let r=++this.facetRequest;this.facetsApplied||this.setFacetsPending(!0);try{let i=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),a=await t.getFacets({query:e,fields:i,signal:n.signal});if(n.signal.aborted||r!==this.facetRequest)return;let o=this.applyFacets(a,!this.facetsApplied);this.facetsApplied=!0,this.setFacetsPending(!1),o&&(await new Promise(e=>setTimeout(e,0)),await this.emitQueryAndRefreshFacets())}catch(e){if(n.signal.aborted)return;this.setFacetsPending(!1),this.host.dispatchEvent(new CustomEvent(`queryerror`,{bubbles:!0,composed:!0,detail:e}))}}applyFacets(e,t){let n=new Map(e.map(e=>[e.fieldId,e])),r=!1;for(let e of Array.from(this.host.form.querySelectorAll(`.query-editor`))){let i=n.get(e.queryField.id);i?.initialValue&&!t&&(i={...i,initialValue:void 0});let a=e.setQueryFacet(i)===!0;r||=a;let o=a||e.getQueryCriteria().length>0,s=e.closest(`shacl-property`);s?.classList.toggle(`query-unavailable`,e.unavailable||i?.unavailable===!0||i?.count===0&&!o),s?.classList.toggle(`query-facet-error`,i?.error===!0)}let i=Array.from(this.host.form.querySelectorAll(`shacl-property`)).reverse();for(let e of i){if(e.querySelector(`:scope > .query-editor, :scope > .collapsible > .query-editor`))continue;let t=Array.from(e.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));e.classList.toggle(`query-unavailable`,!t)}let a=Array.from(this.host.form.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));return this.host.classList.toggle(`query-facets-empty`,!a),r}setFacetsPending(e){this.host.toggleAttribute(`loading`,e);let t=this.host.form.querySelector(`[part~="loading"]`);if(!e)t?.remove();else if(!t){let e=document.createElement(`div`);e.setAttribute(`part`,`loading`),e.textContent=this.host.config.attributes.loading,this.host.form.prepend(e)}}};async function B(t){let n=e=>{t.container.appendChild(e),e.unavailable&&t.classList.add(`query-unavailable`)},r=t.template;if(r.or?.length||r.xone?.length){let i=G(r);if(i){n(H(i,t.parent));return}let a=r.or?.length?r.or:r.xone;t.container.appendChild(e(a,t,r.config));return}let o=_(r);if(o){let e=t.parent.queryContext??{path:[],shapePath:[]},s=a(o);s.label=r.label,n(H(s,{queryContext:{path:[...e.path,i(r)],shapePath:[...e.shapePath,K(r)]}}));return}if(!r.nodeShapes.size){n(H(r,t.parent));return}if(V(r)){let e=a(r);e.facet=!0,e.nodeShapes=new Set;for(let t of r.nodeShapes)if(t.targetClass){e.class=t.targetClass;break}e.nodeKind??=g,n(H(e,t.parent));return}for(let e of r.nodeShapes){let n=new Set(t.parent.ancestorShapeIds);if(n.add(t.parent.template.id.value),n.has(e.id.value))continue;let a=t.parent.queryContext??{path:[],shapePath:[]},o=new m(e,void 0,r.nodeKind,r.label,!1,n,{path:[...a.path,i(r)],shapePath:[...a.shapePath,K(r)]}),s=document.createElement(`div`);s.classList.add(`property-instance`,`query-structure`),s.setAttribute(`part`,`property-instance`),r.config.hierarchyColorsStyleSheet!==void 0&&s.appendChild(h(!0)),s.appendChild(o),t.container.appendChild(s),await o.ready}}function V(e){return e.facet===void 0?Array.from(e.nodeShapes).some(e=>e.facet===!0):e.facet}function H(e,t){let n=t.queryContext??{path:[],shapePath:[]},r={id:`qf${(R++).toString(36)}`,path:[...n.path,i(e)],shapePath:[...n.shapePath,K(e)],fixedValue:e.hasValue,datatype:e.datatype?.value,discrete:e.facet===!0},a=b(e.path,e.datatype?.value)?.createQueryEditor?.(r,e)??S(r,e);return a.queryField=r,a.classList.add(`property-instance`,`query-editor`),a.dataset.path=e.path,a}async function U(e,t){if(!e.length)return;for(let t of e)await t.initializeQuery();let n=e[0];t.replaceWith(n);for(let t=1;t<e.length;t++)n.after(e[t]),n=e[t];n.dispatchEvent(new Event(`change`,{bubbles:!0}))}async function W(e,t,n){e.or=void 0,e.xone=void 0;let r=new o(e,t.parent);await r.initializeQuery(),n.replaceWith(r),r.dispatchEvent(new Event(`change`,{bubbles:!0}))}function G(e){let t=e.or??e.xone;if(!t?.length)return;let r=t.map(t=>{let r=a(e);return r.or=void 0,r.xone=void 0,n(r,e.config.store.getQuads(t,null,null,null)),r.nodeShapes.size===0?r.datatype:void 0});if(r.some(e=>!e||!y.has(e.value)))return;let i=a(e);return i.or=void 0,i.xone=void 0,i.datatype=r.find(e=>e&&c.has(e.value))??r[0],i}function K(e){return e.qualifiedValueShape||e.pathAlternatives?e.queryShapePathId??e.id.value:e.path}export{z as QueryModeController,U as activateNodeConstraintOption,W as activatePropertyConstraintOption,B as initializeQueryProperty};
@@ -1,4 +1,4 @@
1
- import{E as e,F as t,G as n,J as r,O as i,R as a,S as o,W as s,X as c,a as l,k as u,m as d,n as f,o as p,s as m,t as h,tt as g}from"./query-BKMrP7zm.js";import{DataFactory as _}from"n3";import{RokitInput as v,RokitSelect as y,RokitSlider as b,epochToDate as x}from"@ro-kit/ui-widgets";function S(e,t){let n=document.createElement(`div`),i=!!(t.facet||t.in||t.class||t.datatype?.equals(g));n.classList.add(`query-editor`),n.dataset.queryFieldId=e.id,n.setAttribute(`part`,`query-editor`);let a=document.createElement(`label`);a.textContent=t.label,t.description&&(a.title=t.description.value),n.appendChild(a);let o=document.createElement(`div`);o.classList.add(`query-controls`),n.appendChild(o);let s,c=j(t),l,u,d=(e=``)=>{let n=document.createElement(`div`);n.classList.add(`query-value-row`);let r=new y;r.classList.add(`editor`,`query-choice`),r.clearable=!0,r.dense=t.config.theme.dense,r.placeholder=``,r.setAttribute(`exportparts`,`facet-count`);let i=document.createElement(`ul`);for(let e of c){let t=document.createElement(`li`);if(t.dataset.value=I(e.term),t.textContent=e.label,e.count!==void 0){let n=document.createElement(`span`);n.classList.add(`facet-count`),n.setAttribute(`part`,`facet-count`),n.dataset.count=String(e.count),t.append(` `,n)}i.appendChild(t)}return r.appendChild(i),r.value=e,n.appendChild(r),n},f=(e=[])=>{o.replaceChildren(),o.appendChild(d(e[0]??``))},p=(e,n=``)=>{let r=new v;return r.classList.add(`editor`,`query-range-bound`),r.type=F(t),r.label=e,r.clearable=!0,r.dense=t.config.theme.dense,r.value=n,r},m=e=>{o.replaceChildren();let r=C(t,s);r&&r[0]<r[1]&&(l=r);let i=u??A(r,e&&l);if(n.unavailable=!!(i&&i[0]===i[1]),n.unavailable)return;if(!i){o.append(p(`Minimum`,e?.min?.value),p(`Maximum`,e?.max?.value));return}(e?.min||e?.max)&&(u??=i);let a=new b;a.classList.add(`editor`,`query-range-slider`),a.dense=t.config.theme.dense,a.clearable=!0,a.range=``,a.setAttribute(`range`,``),a.min=String(i[0]),a.max=String(i[1]),a.step=String(w(t,i)),a.labelFormatter=e=>T(e,t);let c=e?.min?E(e.min,t):i[0],d=e?.max?E(e.max,t):i[1];a.value=JSON.stringify([k(c??i[0],i[0],i[1]),k(d??i[1],i[0],i[1])]),a.dataset.active=e?.min||e?.max?`true`:`false`,a.addEventListener(`change`,()=>{a.dataset.active=`true`,u??=[Number(a.min),Number(a.max)]}),o.appendChild(a)};return n.getQueryCriteria=()=>{if(h(e)){let n=o.querySelector(`rokit-slider`);if(n){if(n.dataset.active!==`true`)return[];let r=O(n.value);return r?[{field:e,operator:`range`,min:D(r[0],t),max:D(r[1],t)}]:[]}let r=o.querySelectorAll(`rokit-input`),i=N(r[0]?.value,t),a=N(r[1]?.value,t);return i||a?[{field:e,operator:`range`,min:i,max:a}]:[]}if(i)return Array.from(o.querySelectorAll(`rokit-select`)).flatMap(t=>{if(!t.value)return[];let n=c.find(e=>I(e.term)===t.value)?.term;return n?[{field:e,operator:`equals`,value:n}]:[]});let n=P(t)&&!t.class&&!t.nodeKind?.value.endsWith(`#IRI`)?`contains`:`equals`;return Array.from(o.querySelectorAll(`.query-value-row`)).flatMap(r=>{let i=r.querySelector(`.query-value`),a=r.querySelector(`.query-language`)?.value,o=N(i?.value,t,a);return o?[{field:e,operator:n,value:o}]:[]})},n.clearQueryCriteria=()=>{if(h(e)){u=void 0,l=void 0;let e=o.querySelector(`rokit-slider`);if(e)e.dataset.active=`false`,e.value=JSON.stringify([Number(e.min),Number(e.max)]);else for(let e of o.querySelectorAll(`rokit-input`))e.value=``}else if(i)for(let e of o.querySelectorAll(`rokit-select`))e.value=``;else for(let e of o.querySelectorAll(`.query-value`))e.value=``},n.setQueryFacet=r=>{let a=n.getQueryCriteria();if(s=r,i&&s?.buckets){let e=new Map(j(t).map(e=>[I(e.term),e])),n=new Map(a.flatMap(e=>e.value?[[I(e.value),e.value]]:[]));c=s.buckets.flatMap(n=>{let r=e.get(I(n.value));return t.in&&!r?[]:[{term:n.value,label:n.label??r?.label??n.value.value,count:n.count}]});for(let[t,r]of n)c.some(e=>I(e.term)===t)||c.push({term:r,label:e.get(t)?.label??r.value,count:0});let r=!1;if(n.size===0&&s.initialValue){let e=I(s.initialValue);c.some(t=>I(t.term)===e)&&(n.set(e,s.initialValue),r=!0)}return f([...n.keys()]),r}else if(h(e)){let e=a[0];m(e?{min:e.min,max:e.max}:void 0)}else if(!r)for(let e of o.querySelectorAll(`.query-value`))e.value=``;return!1},h(e)?m():i?f():(o.replaceChildren(),o.appendChild((()=>{let e=document.createElement(`div`);e.classList.add(`query-value-row`);let i=new v;i.classList.add(`editor`,`query-value`),i.type=F(t),i.clearable=!0,i.dense=t.config.theme.dense;let a;if(i.addEventListener(`input`,()=>{clearTimeout(a),a=setTimeout(()=>{n.dispatchEvent(new Event(`change`,{bubbles:!0}))},300)}),e.appendChild(i),t.datatype?.equals(r)){let n=t.languageIn?.length?document.createElement(`select`):document.createElement(`input`);if(n.classList.add(`lang-chooser`,`query-language`),n.title=`Language of the text`,n.setAttribute(`aria-label`,`Language of the text`),n instanceof HTMLSelectElement)for(let e of t.languageIn??[]){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.value,n.appendChild(t)}else n.maxLength=35,n.placeholder=`lang?`,n.value=t.config.languages.find(e=>e.length>0)??``;e.appendChild(n)}return e})())),n}function C(e,t){let n=t?.min?E(t.min,e):void 0,r=t?.max?E(t.max,e):void 0,i=e.minInclusive??(e.minExclusive===void 0?void 0:e.minExclusive+1),a=e.maxInclusive??(e.maxExclusive===void 0?void 0:e.maxExclusive-1),o=n!==void 0&&r!==void 0,s=o?n:n===void 0?i:i===void 0?n:Math.max(n,i),c=o?r:r===void 0?a:a===void 0?r:Math.min(r,a);return s!==void 0&&c!==void 0&&Number.isFinite(s)&&Number.isFinite(c)&&s<=c?[s,c]:void 0}function w(e,t){return e.datatype?.value===`http://www.w3.org/2001/XMLSchema#integer`?1:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?86400:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?1:Math.max((t[1]-t[0])/1e3,2**-52)}function T(e,t){return t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?x(e,!0):t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?x(e):String(Math.round(e*1e3)/1e3)}function E(e,t){if(t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`||t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`){let t=Date.parse(e.value);return Number.isFinite(t)?t/1e3:void 0}let n=Number(e.value);return Number.isFinite(n)?n:void 0}function D(e,t){let n=t.datatype;return n?.value===`http://www.w3.org/2001/XMLSchema#date`?_.literal(x(e,!0),n):n?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?_.literal(x(e),n):_.literal(String(e),n)}function O(e){try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===2&&t.every(Number.isFinite)?[Number(t[0]),Number(t[1])]:void 0}catch{return}}function k(e,t,n){return Math.min(n,Math.max(t,e))}function A(e,t){return e&&e[0]<e[1]?e:t||e}function j(e){if(e.datatype?.equals(g))return[{term:_.literal(`true`,g),label:`true`},{term:_.literal(`false`,g),label:`false`}];let n=[];return e.in?n=t(e.config.lists[e.in]??[],e.config.store,e.config.languages):e.class&&(n=a(e.class,e)),M(n)}function M(e){return e.flatMap(e=>[...typeof e.value==`string`?[]:[{term:e.value,label:e.label||e.value.value}],...M(e.children??[])])}function N(e,t,n){if(e)return t.class||t.nodeKind?.value.endsWith(`#IRI`)?_.namedNode(e):t.datatype?.equals(r)?n?_.literal(e,n):void 0:t.datatype?_.literal(e,t.datatype):_.literal(e)}function P(e){return!e.datatype||e.datatype.value===`http://www.w3.org/2001/XMLSchema#string`||e.datatype.equals(r)}function F(e){let t=e.datatype?.value;return[`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`].includes(t??``)?`number`:t===`http://www.w3.org/2001/XMLSchema#date`?`date`:t===`http://www.w3.org/2001/XMLSchema#dateTime`?`datetime-local`:`text`}function I(e){if(e.termType===`Literal`){let t=e;return`${e.termType}:${e.value}:${t.language}:${t.datatype?.value}`}return`${e.termType}:${e.value}`}var L=`form.mode-query { padding: 0; }
1
+ import{E as e,G as t,I as n,K as r,O as i,S as a,Y as o,Z as s,a as c,k as l,m as u,n as d,nt as f,o as p,s as m,t as h,z as g}from"./query-B9ouD_FF.js";import{DataFactory as _}from"n3";import{RokitInput as v,RokitSelect as y,RokitSlider as b,epochToDate as x}from"@ro-kit/ui-widgets";function S(e,t){let n=document.createElement(`div`),r=!!(t.facet||t.in||t.class||t.datatype?.equals(f));n.classList.add(`query-editor`),n.dataset.queryFieldId=e.id,n.setAttribute(`part`,`query-editor`);let i=document.createElement(`label`);i.textContent=t.label,t.description&&(i.title=t.description.value),n.appendChild(i);let a=document.createElement(`div`);a.classList.add(`query-controls`),n.appendChild(a);let s,c=j(t),l,u,d=(e=``)=>{let n=document.createElement(`div`);n.classList.add(`query-value-row`);let r=new y;r.classList.add(`editor`,`query-choice`),r.clearable=!0,r.dense=t.config.theme.dense,r.placeholder=``,r.setAttribute(`exportparts`,`facet-count`);let i=document.createElement(`ul`);for(let e of c){let t=document.createElement(`li`);if(t.dataset.value=I(e.term),t.textContent=e.label,e.count!==void 0){let n=document.createElement(`span`);n.classList.add(`facet-count`),n.setAttribute(`part`,`facet-count`),n.dataset.count=String(e.count),t.append(` `,n)}i.appendChild(t)}return r.appendChild(i),r.value=e,n.appendChild(r),n},p=(e=[])=>{a.replaceChildren(),a.appendChild(d(e[0]??``))},m=(e,n=``)=>{let r=new v;return r.classList.add(`editor`,`query-range-bound`),r.type=F(t),r.label=e,r.clearable=!0,r.dense=t.config.theme.dense,r.value=n,r},g=e=>{a.replaceChildren();let r=C(t,s);r&&r[0]<r[1]&&(l=r);let i=u??A(r,e&&l);if(n.unavailable=!!(i&&i[0]===i[1]),n.unavailable)return;if(!i){a.append(m(`Minimum`,e?.min?.value),m(`Maximum`,e?.max?.value));return}(e?.min||e?.max)&&(u??=i);let o=new b;o.classList.add(`editor`,`query-range-slider`),o.dense=t.config.theme.dense,o.clearable=!0,o.range=``,o.setAttribute(`range`,``),o.min=String(i[0]),o.max=String(i[1]),o.step=String(w(t,i)),o.labelFormatter=e=>T(e,t);let c=e?.min?E(e.min,t):i[0],d=e?.max?E(e.max,t):i[1];o.value=JSON.stringify([k(c??i[0],i[0],i[1]),k(d??i[1],i[0],i[1])]),o.dataset.active=e?.min||e?.max?`true`:`false`,o.addEventListener(`change`,()=>{o.dataset.active=`true`,u??=[Number(o.min),Number(o.max)]}),a.appendChild(o)};return n.getQueryCriteria=()=>{if(h(e)){let n=a.querySelector(`rokit-slider`);if(n){if(n.dataset.active!==`true`)return[];let r=O(n.value);return r?[{field:e,operator:`range`,min:D(r[0],t),max:D(r[1],t)}]:[]}let r=a.querySelectorAll(`rokit-input`),i=N(r[0]?.value,t),o=N(r[1]?.value,t);return i||o?[{field:e,operator:`range`,min:i,max:o}]:[]}if(r)return Array.from(a.querySelectorAll(`rokit-select`)).flatMap(t=>{if(!t.value)return[];let n=c.find(e=>I(e.term)===t.value)?.term;return n?[{field:e,operator:`equals`,value:n}]:[]});let n=P(t)&&!t.class&&!t.nodeKind?.value.endsWith(`#IRI`)?`contains`:`equals`;return Array.from(a.querySelectorAll(`.query-value-row`)).flatMap(r=>{let i=r.querySelector(`.query-value`),a=r.querySelector(`.query-language`)?.value,o=N(i?.value,t,a);return o?[{field:e,operator:n,value:o}]:[]})},n.clearQueryCriteria=()=>{if(h(e)){u=void 0,l=void 0;let e=a.querySelector(`rokit-slider`);if(e)e.dataset.active=`false`,e.value=JSON.stringify([Number(e.min),Number(e.max)]);else for(let e of a.querySelectorAll(`rokit-input`))e.value=``}else if(r)for(let e of a.querySelectorAll(`rokit-select`))e.value=``;else for(let e of a.querySelectorAll(`.query-value`))e.value=``},n.setQueryFacet=i=>{let o=n.getQueryCriteria();if(s=i,r&&s?.buckets){let e=new Map(j(t).map(e=>[I(e.term),e])),n=new Map(o.flatMap(e=>e.value?[[I(e.value),e.value]]:[]));c=s.buckets.flatMap(n=>{let r=e.get(I(n.value));return t.in&&!r?[]:[{term:n.value,label:n.label??r?.label??n.value.value,count:n.count}]});for(let[t,r]of n)c.some(e=>I(e.term)===t)||c.push({term:r,label:e.get(t)?.label??r.value,count:0});let r=!1;if(n.size===0&&s.initialValue){let e=I(s.initialValue);c.some(t=>I(t.term)===e)&&(n.set(e,s.initialValue),r=!0)}return p([...n.keys()]),r}else if(h(e)){let e=o[0];g(e?{min:e.min,max:e.max}:void 0)}else if(!i)for(let e of a.querySelectorAll(`.query-value`))e.value=``;return!1},h(e)?g():r?p():(a.replaceChildren(),a.appendChild((()=>{let e=document.createElement(`div`);e.classList.add(`query-value-row`);let r=new v;r.classList.add(`editor`,`query-value`),r.type=F(t),r.clearable=!0,r.dense=t.config.theme.dense;let i;if(r.addEventListener(`input`,()=>{clearTimeout(i),i=setTimeout(()=>{n.dispatchEvent(new Event(`change`,{bubbles:!0}))},300)}),e.appendChild(r),t.datatype?.equals(o)){let n=t.languageIn?.length?document.createElement(`select`):document.createElement(`input`);if(n.classList.add(`lang-chooser`,`query-language`),n.title=`Language of the text`,n.setAttribute(`aria-label`,`Language of the text`),n instanceof HTMLSelectElement)for(let e of t.languageIn??[]){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.value,n.appendChild(t)}else n.maxLength=35,n.placeholder=`lang?`,n.value=t.config.languages.find(e=>e.length>0)??``;e.appendChild(n)}return e})())),n}function C(e,t){let n=t?.min?E(t.min,e):void 0,r=t?.max?E(t.max,e):void 0,i=e.minInclusive??(e.minExclusive===void 0?void 0:e.minExclusive+1),a=e.maxInclusive??(e.maxExclusive===void 0?void 0:e.maxExclusive-1),o=n!==void 0&&r!==void 0,s=o?n:n===void 0?i:i===void 0?n:Math.max(n,i),c=o?r:r===void 0?a:a===void 0?r:Math.min(r,a);return s!==void 0&&c!==void 0&&Number.isFinite(s)&&Number.isFinite(c)&&s<=c?[s,c]:void 0}function w(e,t){return e.datatype?.value===`http://www.w3.org/2001/XMLSchema#integer`?1:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?86400:e.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?1:Math.max((t[1]-t[0])/1e3,2**-52)}function T(e,t){return t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`?x(e,!0):t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?x(e):String(Math.round(e*1e3)/1e3)}function E(e,t){if(t.datatype?.value===`http://www.w3.org/2001/XMLSchema#date`||t.datatype?.value===`http://www.w3.org/2001/XMLSchema#dateTime`){let t=Date.parse(e.value);return Number.isFinite(t)?t/1e3:void 0}let n=Number(e.value);return Number.isFinite(n)?n:void 0}function D(e,t){let n=t.datatype;return n?.value===`http://www.w3.org/2001/XMLSchema#date`?_.literal(x(e,!0),n):n?.value===`http://www.w3.org/2001/XMLSchema#dateTime`?_.literal(x(e),n):_.literal(String(e),n)}function O(e){try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===2&&t.every(Number.isFinite)?[Number(t[0]),Number(t[1])]:void 0}catch{return}}function k(e,t,n){return Math.min(n,Math.max(t,e))}function A(e,t){return e&&e[0]<e[1]?e:t||e}function j(e){if(e.datatype?.equals(f))return[{term:_.literal(`true`,f),label:`true`},{term:_.literal(`false`,f),label:`false`}];let t=[];return e.in?t=n(e.config.lists[e.in]??[],e.config.store,e.config.languages):e.class&&(t=g(e.class,e)),M(t)}function M(e){return e.flatMap(e=>[...typeof e.value==`string`?[]:[{term:e.value,label:e.label||e.value.value}],...M(e.children??[])])}function N(e,t,n){if(e)return t.class||t.nodeKind?.value.endsWith(`#IRI`)?_.namedNode(e):t.datatype?.equals(o)?n?_.literal(e,n):void 0:t.datatype?_.literal(e,t.datatype):_.literal(e)}function P(e){return!e.datatype||e.datatype.value===`http://www.w3.org/2001/XMLSchema#string`||e.datatype.equals(o)}function F(e){let t=e.datatype?.value;return[`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`].includes(t??``)?`number`:t===`http://www.w3.org/2001/XMLSchema#date`?`date`:t===`http://www.w3.org/2001/XMLSchema#dateTime`?`datetime-local`:`text`}function I(e){if(e.termType===`Literal`){let t=e;return`${e.termType}:${e.value}:${t.language}:${t.datatype?.value}`}return`${e.termType}:${e.value}`}var L=`form.mode-query { padding: 0; }
2
2
  :host([loading]) form.mode-query > shacl-node { display: none; }
3
3
  .mode-query shacl-property.query-unavailable { display: none; }
4
4
  .mode-query .shacl-group:not(:has(shacl-property:not(.query-unavailable))), .mode-query shacl-node:not(:has(shacl-property:not(.query-unavailable))) { display: none; }
@@ -10,4 +10,4 @@ import{E as e,F as t,G as n,J as r,O as i,R as a,S as o,W as s,X as c,a as l,k a
10
10
  .query-language { min-height: 28px; flex: 0 0 auto; }
11
11
  .query-range-slider[data-active='false'] { opacity: 0.7; }
12
12
  .query-facet-error .query-editor > label { color: var(--shacl-error-color); }
13
- `,R=0,z=class{constructor(e){this.stylesheet=new CSSStyleSheet,this.facetRequest=0,this.facetsApplied=!1,this.host=e,this.stylesheet.replaceSync(L),e.config.queryFacetProvider&&this.setFacetsPending(!0)}async initialize(){await this.emitQueryAndRefreshFacets()}handleChange(){this.emitQueryAndRefreshFacets()}getQuery(){let e=this.host.shape;return e?{rootShapeId:e.template.id.value,targetClass:e.template.targetClass?.value,criteria:Array.from(this.host.form.querySelectorAll(`.query-editor`)).flatMap(e=>e.getQueryCriteria())}:{rootShapeId:``,criteria:[]}}refreshFacets(){this.host.shape&&this.requestFacets(this.getQuery())}dispose(){this.facetAbortController?.abort(),this.setFacetsPending(!1),this.host.classList.remove(`query-facets-empty`)}async emitQueryAndRefreshFacets(){if(!this.host.shape)return;let e=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),t=this.getQuery(),n=this.host.config.queryFacetProvider;if(this.previousQuery&&n?.invalidatedFields){let r=new Set(n.invalidatedFields({previousQuery:this.previousQuery,query:t,fields:e}));for(let e of this.host.form.querySelectorAll(`.query-editor`))r.has(e.queryField.id)&&e.clearQueryCriteria?.();t=this.getQuery()}this.previousQuery=t,this.host.dispatchEvent(new CustomEvent(`query`,{bubbles:!0,composed:!0,detail:t})),await this.requestFacets(t)}async requestFacets(e){let t=this.host.config.queryFacetProvider;if(!t)return;this.facetAbortController?.abort();let n=new AbortController;this.facetAbortController=n;let r=++this.facetRequest;this.facetsApplied||this.setFacetsPending(!0);try{let i=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),a=await t.getFacets({query:e,fields:i,signal:n.signal});if(n.signal.aborted||r!==this.facetRequest)return;let o=this.applyFacets(a,!this.facetsApplied);this.facetsApplied=!0,this.setFacetsPending(!1),o&&(await new Promise(e=>setTimeout(e,0)),await this.emitQueryAndRefreshFacets())}catch(e){if(n.signal.aborted)return;this.setFacetsPending(!1),this.host.dispatchEvent(new CustomEvent(`queryerror`,{bubbles:!0,composed:!0,detail:e}))}}applyFacets(e,t){let n=new Map(e.map(e=>[e.fieldId,e])),r=!1;for(let e of Array.from(this.host.form.querySelectorAll(`.query-editor`))){let i=n.get(e.queryField.id);i?.initialValue&&!t&&(i={...i,initialValue:void 0});let a=e.setQueryFacet(i)===!0;r||=a;let o=a||e.getQueryCriteria().length>0,s=e.closest(`shacl-property`);s?.classList.toggle(`query-unavailable`,e.unavailable||i?.unavailable===!0||i?.count===0&&!o),s?.classList.toggle(`query-facet-error`,i?.error===!0)}let i=Array.from(this.host.form.querySelectorAll(`shacl-property`)).reverse();for(let e of i){if(e.querySelector(`:scope > .query-editor, :scope > .collapsible > .query-editor`))continue;let t=Array.from(e.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));e.classList.toggle(`query-unavailable`,!t)}let a=Array.from(this.host.form.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));return this.host.classList.toggle(`query-facets-empty`,!a),r}setFacetsPending(e){this.host.toggleAttribute(`loading`,e);let t=this.host.form.querySelector(`[part~="loading"]`);if(!e)t?.remove();else if(!t){let e=document.createElement(`div`);e.setAttribute(`part`,`loading`),e.textContent=this.host.config.attributes.loading,this.host.form.prepend(e)}}};async function B(t){let n=e=>{t.container.appendChild(e),e.unavailable&&t.classList.add(`query-unavailable`)},r=t.template;if(r.or?.length||r.xone?.length){let e=G(r);if(e){n(H(e,t.parent));return}let i=r.or?.length?r.or:r.xone;t.container.appendChild(o(i,t,r.config));return}let i=m(r);if(i){let a=t.parent.queryContext??{path:[],shapePath:[]},o=e(i);o.label=r.label,n(H(o,{queryContext:{path:[...a.path,u(r)],shapePath:[...a.shapePath,K(r)]}}));return}if(!r.nodeShapes.size){n(H(r,t.parent));return}if(V(r)){let i=e(r);i.facet=!0,i.nodeShapes=new Set;for(let e of r.nodeShapes)if(e.targetClass){i.class=e.targetClass;break}i.nodeKind??=c,n(H(i,t.parent));return}for(let e of r.nodeShapes){let n=new Set(t.parent.ancestorShapeIds);if(n.add(t.parent.template.id.value),n.has(e.id.value))continue;let i=t.parent.queryContext??{path:[],shapePath:[]},a=new f(e,void 0,r.nodeKind,r.label,!1,n,{path:[...i.path,u(r)],shapePath:[...i.shapePath,K(r)]}),o=document.createElement(`div`);o.classList.add(`property-instance`,`query-structure`),o.setAttribute(`part`,`property-instance`),r.config.hierarchyColorsStyleSheet!==void 0&&o.appendChild(p(!0)),o.appendChild(a),t.container.appendChild(o),await a.ready}}function V(e){return e.facet===void 0?Array.from(e.nodeShapes).some(e=>e.facet===!0):e.facet}function H(e,t){let n=t.queryContext??{path:[],shapePath:[]},r={id:`qf${(R++).toString(36)}`,path:[...n.path,u(e)],shapePath:[...n.shapePath,K(e)],fixedValue:e.hasValue,datatype:e.datatype?.value,discrete:e.facet===!0},i=d(e.path,e.datatype?.value)?.createQueryEditor?.(r,e)??S(r,e);return i.queryField=r,i.classList.add(`property-instance`,`query-editor`),i.dataset.path=e.path,i}async function U(e,t){if(!e.length)return;for(let t of e)await t.initializeQuery();let n=e[0];t.replaceWith(n);for(let t=1;t<e.length;t++)n.after(e[t]),n=e[t];n.dispatchEvent(new Event(`change`,{bubbles:!0}))}async function W(e,t,n){e.or=void 0,e.xone=void 0;let r=new l(e,t.parent);await r.initializeQuery(),n.replaceWith(r),r.dispatchEvent(new Event(`change`,{bubbles:!0}))}function G(t){let r=t.or??t.xone;if(!r?.length)return;let a=r.map(n=>{let r=e(t);return r.or=void 0,r.xone=void 0,i(r,t.config.store.getQuads(n,null,null,null)),r.nodeShapes.size===0?r.datatype:void 0});if(a.some(e=>!e||!n.has(e.value)))return;let o=e(t);return o.or=void 0,o.xone=void 0,o.datatype=a.find(e=>e&&s.has(e.value))??a[0],o}function K(e){return e.qualifiedValueShape||e.pathAlternatives?e.queryShapePathId??e.id.value:e.path}export{z as QueryModeController,U as activateNodeConstraintOption,W as activatePropertyConstraintOption,B as initializeQueryProperty};
13
+ `,R=0,z=class{constructor(e){this.stylesheet=new CSSStyleSheet,this.facetRequest=0,this.facetsApplied=!1,this.host=e,this.stylesheet.replaceSync(L),e.config.queryFacetProvider&&this.setFacetsPending(!0)}async initialize(){await this.emitQueryAndRefreshFacets()}handleChange(){this.emitQueryAndRefreshFacets()}getQuery(){let e=this.host.shape;return e?{rootShapeId:e.template.id.value,targetClass:e.template.targetClass?.value,criteria:Array.from(this.host.form.querySelectorAll(`.query-editor`)).flatMap(e=>e.getQueryCriteria())}:{rootShapeId:``,criteria:[]}}refreshFacets(){this.host.shape&&this.requestFacets(this.getQuery())}dispose(){this.facetAbortController?.abort(),this.setFacetsPending(!1),this.host.classList.remove(`query-facets-empty`)}async emitQueryAndRefreshFacets(){if(!this.host.shape)return;let e=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),t=this.getQuery(),n=this.host.config.queryFacetProvider;if(this.previousQuery&&n?.invalidatedFields){let r=new Set(n.invalidatedFields({previousQuery:this.previousQuery,query:t,fields:e}));for(let e of this.host.form.querySelectorAll(`.query-editor`))r.has(e.queryField.id)&&e.clearQueryCriteria?.();t=this.getQuery()}this.previousQuery=t,this.host.dispatchEvent(new CustomEvent(`query`,{bubbles:!0,composed:!0,detail:t})),await this.requestFacets(t)}async requestFacets(e){let t=this.host.config.queryFacetProvider;if(!t)return;this.facetAbortController?.abort();let n=new AbortController;this.facetAbortController=n;let r=++this.facetRequest;this.facetsApplied||this.setFacetsPending(!0);try{let i=Array.from(this.host.form.querySelectorAll(`.query-editor`)).map(e=>e.queryField),a=await t.getFacets({query:e,fields:i,signal:n.signal});if(n.signal.aborted||r!==this.facetRequest)return;let o=this.applyFacets(a,!this.facetsApplied);this.facetsApplied=!0,this.setFacetsPending(!1),o&&(await new Promise(e=>setTimeout(e,0)),await this.emitQueryAndRefreshFacets())}catch(e){if(n.signal.aborted)return;this.setFacetsPending(!1),this.host.dispatchEvent(new CustomEvent(`queryerror`,{bubbles:!0,composed:!0,detail:e}))}}applyFacets(e,t){let n=new Map(e.map(e=>[e.fieldId,e])),r=!1;for(let e of Array.from(this.host.form.querySelectorAll(`.query-editor`))){let i=n.get(e.queryField.id);i?.initialValue&&!t&&(i={...i,initialValue:void 0});let a=e.setQueryFacet(i)===!0;r||=a;let o=a||e.getQueryCriteria().length>0,s=e.closest(`shacl-property`);s?.classList.toggle(`query-unavailable`,e.unavailable||i?.unavailable===!0||i?.count===0&&!o),s?.classList.toggle(`query-facet-error`,i?.error===!0)}let i=Array.from(this.host.form.querySelectorAll(`shacl-property`)).reverse();for(let e of i){if(e.querySelector(`:scope > .query-editor, :scope > .collapsible > .query-editor`))continue;let t=Array.from(e.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));e.classList.toggle(`query-unavailable`,!t)}let a=Array.from(this.host.form.querySelectorAll(`.query-editor`)).some(e=>!e.closest(`shacl-property`)?.classList.contains(`query-unavailable`));return this.host.classList.toggle(`query-facets-empty`,!a),r}setFacetsPending(e){this.host.toggleAttribute(`loading`,e);let t=this.host.form.querySelector(`[part~="loading"]`);if(!e)t?.remove();else if(!t){let e=document.createElement(`div`);e.setAttribute(`part`,`loading`),e.textContent=this.host.config.attributes.loading,this.host.form.prepend(e)}}};async function B(t){let n=e=>{t.container.appendChild(e),e.unavailable&&t.classList.add(`query-unavailable`)},r=t.template;if(r.or?.length||r.xone?.length){let e=G(r);if(e){n(H(e,t.parent));return}let i=r.or?.length?r.or:r.xone;t.container.appendChild(a(i,t,r.config));return}let i=m(r);if(i){let a=t.parent.queryContext??{path:[],shapePath:[]},o=e(i);o.label=r.label,n(H(o,{queryContext:{path:[...a.path,l(r)],shapePath:[...a.shapePath,K(r)]}}));return}if(!r.nodeShapes.size){n(H(r,t.parent));return}if(V(r)){let i=e(r);i.facet=!0,i.nodeShapes=new Set;for(let e of r.nodeShapes)if(e.targetClass){i.class=e.targetClass;break}i.nodeKind??=s,n(H(i,t.parent));return}for(let e of r.nodeShapes){let n=new Set(t.parent.ancestorShapeIds);if(n.add(t.parent.template.id.value),n.has(e.id.value))continue;let i=t.parent.queryContext??{path:[],shapePath:[]},a=new d(e,void 0,r.nodeKind,r.label,!1,n,{path:[...i.path,l(r)],shapePath:[...i.shapePath,K(r)]}),o=document.createElement(`div`);o.classList.add(`property-instance`,`query-structure`),o.setAttribute(`part`,`property-instance`),r.config.hierarchyColorsStyleSheet!==void 0&&o.appendChild(p(!0)),o.appendChild(a),t.container.appendChild(o),await a.ready}}function V(e){return e.facet===void 0?Array.from(e.nodeShapes).some(e=>e.facet===!0):e.facet}function H(e,t){let n=t.queryContext??{path:[],shapePath:[]},r={id:`qf${(R++).toString(36)}`,path:[...n.path,l(e)],shapePath:[...n.shapePath,K(e)],fixedValue:e.hasValue,datatype:e.datatype?.value,discrete:e.facet===!0},i=u(e.path,e.datatype?.value)?.createQueryEditor?.(r,e)??S(r,e);return i.queryField=r,i.classList.add(`property-instance`,`query-editor`),i.dataset.path=e.path,i}async function U(e,t){if(!e.length)return;for(let t of e)await t.initializeQuery();let n=e[0];t.replaceWith(n);for(let t=1;t<e.length;t++)n.after(e[t]),n=e[t];n.dispatchEvent(new Event(`change`,{bubbles:!0}))}async function W(e,t,n){e.or=void 0,e.xone=void 0;let r=new c(e,t.parent);await r.initializeQuery(),n.replaceWith(r),r.dispatchEvent(new Event(`change`,{bubbles:!0}))}function G(n){let a=n.or??n.xone;if(!a?.length)return;let o=a.map(t=>{let r=e(n);return r.or=void 0,r.xone=void 0,i(r,n.config.store.getQuads(t,null,null,null)),r.nodeShapes.size===0?r.datatype:void 0});if(o.some(e=>!e||!r.has(e.value)))return;let s=e(n);return s.or=void 0,s.xone=void 0,s.datatype=o.find(e=>e&&t.has(e.value))??o[0],s}function K(e){return e.qualifiedValueShape||e.pathAlternatives?e.queryShapePathId??e.id.value:e.path}export{z as QueryModeController,U as activateNodeConstraintOption,W as activatePropertyConstraintOption,B as initializeQueryProperty};
@@ -0,0 +1,92 @@
1
+ import{BlankNode as e,DataFactory as t,Literal as n,NamedNode as r,Store as i,StreamParser as a,Writer as o,termFromId as s,termToId as c}from"n3";import{RdfXmlParser as l}from"rdfxml-streaming-parser";import ee from"jsonld";import{RokitButton as u,RokitCollapsible as d,RokitDialog as f}from"@ro-kit/ui-widgets";import{v4 as p}from"uuid";var m=`http://www.w3.org/ns/shacl#`,h=`http://datashapes.org/dash#`,te=`http://www.w3.org/2001/XMLSchema#`,ne=`http://www.w3.org/1999/02/22-rdf-syntax-ns#`,re=`http://www.w3.org/2000/01/rdf-schema#`,ie=`http://www.w3.org/ns/oa#`,ae=`http://purl.org/dc/terms/`,g=t.namedNode(`loaded-shapes`),_=t.namedNode(`loaded-data`),v=t.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#type`),y=t.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#first`),b=t.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#rest`),x=t.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#nil`),S=t.namedNode(`http://www.w3.org/1999/02/22-rdf-syntax-ns#langString`),C=t.namedNode(`http://purl.org/dc/terms/conformsTo`),oe=t.namedNode(`http://www.w3.org/2000/01/rdf-schema#subClassOf`),w=t.namedNode(`http://www.w3.org/2002/07/owl#imports`),se=t.namedNode(`http://www.w3.org/2004/02/skos/core#broader`),ce=t.namedNode(`http://www.w3.org/2004/02/skos/core#narrower`),le=t.namedNode(`http://www.w3.org/ns/shacl#NodeShape`),ue=t.namedNode(`http://www.w3.org/ns/shacl#IRI`),de=t.namedNode(`http://www.w3.org/ns/shacl#property`),T=t.namedNode(`http://www.w3.org/ns/shacl#class`),fe=t.namedNode(`http://www.w3.org/ns/shacl#node`),pe=t.namedNode(`http://www.w3.org/ns/shacl#message`),E=t.namedNode(`http://www.w3.org/ns/shacl#targetClass`),me=t.namedNode(`http://www.w3.org/ns/shacl#nodeKind`),he=t.namedNode(`http://www.w3.org/2001/XMLSchema#string`),ge=t.namedNode(`http://www.w3.org/2001/XMLSchema#boolean`),_e=new Set([`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#int`,`http://www.w3.org/2001/XMLSchema#short`,`http://www.w3.org/2001/XMLSchema#byte`,`http://www.w3.org/2001/XMLSchema#unsignedInt`,`http://www.w3.org/2001/XMLSchema#unsignedShort`,`http://www.w3.org/2001/XMLSchema#unsignedByte`,`http://www.w3.org/2001/XMLSchema#long`,`http://www.w3.org/2001/XMLSchema#unsignedLong`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`,`http://www.w3.org/2001/XMLSchema#date`,`http://www.w3.org/2001/XMLSchema#dateTime`]),ve=new Set([`http://www.w3.org/2001/XMLSchema#integer`,`http://www.w3.org/2001/XMLSchema#int`,`http://www.w3.org/2001/XMLSchema#short`,`http://www.w3.org/2001/XMLSchema#byte`,`http://www.w3.org/2001/XMLSchema#unsignedInt`,`http://www.w3.org/2001/XMLSchema#unsignedShort`,`http://www.w3.org/2001/XMLSchema#unsignedByte`,`http://www.w3.org/2001/XMLSchema#long`,`http://www.w3.org/2001/XMLSchema#unsignedLong`,`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`]),ye=new Set([`http://www.w3.org/2001/XMLSchema#float`,`http://www.w3.org/2001/XMLSchema#double`,`http://www.w3.org/2001/XMLSchema#decimal`]);function D(e,t,n=m,r){let i=``,a=be(e,t,n,r);return a&&(i=a.value),i}function be(e,t,n=m,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 xe(e){e.querySelector(`.editor`)?.focus()}function O(e,t){return D(e,`prefLabel`,`http://www.w3.org/2004/02/skos/core#`,t)||D(e,`label`,`http://www.w3.org/2000/01/rdf-schema#`,t)||D(e,`title`,`http://purl.org/dc/terms/`,t)||D(e,`name`,`http://xmlns.com/foaf/0.1/`,t)}function k(e,t,n){let r=[];for(let i of e)r.push({value:i,label:O(t.getQuads(i,null,null,null),n),children:[]});return r}function A(e,t){for(let n in t){let r=t[n];e.startsWith(r)&&(e=e.slice(r.length))}return e}function Se(e,n,r=new Map){r.set(g.id,g),r.set(_.id,_);let i=e.config.valuesGraphId??t.defaultGraph();r.set(i.id,i);for(let t of e.owlImports)Ce(t,n,r);return e.parent&&Se(e.parent,n,r),[...r.values()]}function Ce(e,t,n){if(!n.has(e.id)){n.set(e.id,e);for(let r of t.getObjects(null,w,e))r.termType===`NamedNode`&&Ce(r,t,n)}}function we(e,t,n,r){return r.flatMap(r=>e.getSubjects(t,n,r))}function j(e,t,n,r){return r.flatMap(r=>e.getObjects(t,n,r))}function M(e,t){if(t.in){let e=t.config.lists[t.in];return k(e?.length?e:[],t.config.store,t.config.languages)}else{let n=Se(t,t.config.store),r=we(t.config.store,v,e,n),i=new Map,a=new Map;for(let e of r)i.set(e.id,{value:e,label:O(t.config.store.getQuads(e,null,null,null),t.config.languages),children:[]});for(let e of r){for(let r of j(t.config.store,e,se,n))i.has(r.id)&&a.set(e.id,r.id);for(let r of j(t.config.store,e,ce,n))i.has(r.id)&&a.set(r.id,e.id);for(let r of j(t.config.store,e,oe,n))i.has(r.id)&&a.set(e.id,r.id)}for(let[e,t]of a.entries())i.get(t)?.children?.push(i.get(e));let o=[];for(let[e,t]of i.entries())a.has(e)||o.push(t);for(let r of we(t.config.store,oe,e,n))o.push(...M(r,t));return o}}function N(e){let t;try{t=new URL(e)}catch{return!1}return t.protocol===`http:`||t.protocol===`https:`}function Te(e){let t=new Uint8Array(e),n=32768,r=``;for(let e=0;e<t.length;e+=n)r+=String.fromCharCode(...t.subarray(e,e+n));return btoa(r)}function P(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 Ee(e,t){let n;for(let r of t)n=P(e,n,r);return n?n.value:``}var F=/^(-?\d{4,}-\d{2}-\d{2})(Z|[+-]\d{2}:\d{2})?$/,De=/^(-?\d{4,}-\d{2}-\d{2})T(\d{2}:\d{2})(?::(\d{2})(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/,Oe=/^(-?\d{4,}-\d{2}-\d{2}T\d{2}:\d{2})(?::(\d{2})(\.\d+)?)?$/;function ke(e){let t=e.match(F);if(!t){let t=e.match(De);return t?{value:t[1],suffix:t[5]||``}:void 0}return{value:t[1],suffix:t[2]||``}}function Ae(e){let t=e.match(De);if(!t){let t=e.match(F);return t?{value:`${t[1]}T00:00:00`,suffix:t[2]||``}:void 0}return{value:`${t[1]}T${t[2]}:${t[3]||`00`}`,suffix:t[5]||``}}function je(e,t=``){let n=e.match(F);return n?`${n[1]}${t}`:e}function Me(e,t=``){let n=e.match(Oe);return n?`${n[1]}:${n[2]||`00`}${n[3]||``}${t}`:e}function Ne(e){let t=new Set;for(let n of e.getObjects(null,T,g))t.add(n.value);for(let n of e.getObjects(null,E,g))t.add(n.value);return t}function Pe(e,t){return e instanceof Set?[...t].filter(t=>!e.has(t)):[...t].filter(t=>!e.includes(t))}function Fe(e,{remove:t=!1,ignoreErrors:n=!1}={}){let r={},i=n?()=>!0:(e,t)=>{throw Error(`${e.value} ${t}`)},a=e.getQuads(null,ne+`rest`,ne+`nil`,null),o=t?[...a]:[];return a.forEach(n=>{let a=[],s=!1,c,l,ee=n.graph,u=n.subject;for(;u&&!s;){let t=e.getQuads(null,null,u,null),n=e.getQuads(u,null,null,null).filter(e=>!e.predicate.equals(v)),r,d=null,f=null,p=null;for(let e=0;e<n.length&&!s;e++)r=n[e],r.graph.equals(ee)?c?s=i(u,`has non-list arcs out`):r.predicate.value===`http://www.w3.org/1999/02/22-rdf-syntax-ns#first`?d?s=i(u,`has multiple rdf:first arcs`):o.push(d=r):r.predicate.value===`http://www.w3.org/1999/02/22-rdf-syntax-ns#rest`?f?s=i(u,`has multiple rdf:rest arcs`):o.push(f=r):t.length?s=i(u,`can't be subject and object`):(c=r,l=`subject`):s=i(u,`not confined to single graph`);for(let e=0;e<t.length&&!s;++e)r=t[e],c?s=i(u,`can't have coreferences`):r.predicate.value===`http://www.w3.org/1999/02/22-rdf-syntax-ns#rest`?p?s=i(u,`has incoming rdf:rest arcs`):p=r:(c=r,l=`object`);d?a.unshift(d.object):s=i(u,`has no list head`),u=p&&p.subject}s?t=!1:c&&(r[c[l].value]=a)}),t&&e.removeQuads(o),r}var I={},L={};async function R(e){return`rdf`in e?z(e.rdf):e.rdfUrlResolver?z(await e.rdfUrlResolver(e.url)):Ie(e.url,e.proxy)}async function Ie(e,t){return e in I||(I[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),[])})()),I[e]}async function z(e){if(!e.trim())return[];let n=Le(e);if(n===`json`)try{e=await ee.toRDF(JSON.parse(e),{format:`application/n-quads`})}catch(e){console.error(e)}let r=[];return await new Promise((i,o)=>{let s=n===`xml`?new l:new a;s.on(`data`,e=>{r.push(t.quad(e.subject,e.predicate,e.object,e.graph))}).on(`error`,e=>{o(e)}).on(`prefix`,(e,t)=>{e&&(L[e]=t)}).on(`end`,()=>{i(null)}),s.write(e),s.end()}),r}function Le(e){return/^\s*[\\[{]/.test(e)?`json`:/^\s*<\?xml/.test(e)?`xml`:`ttl`}var Re={[`${m}name`]:(e,t)=>{let n=t;e.name=P(e.config.languages,e.name,n)},[`${m}description`]:(e,t)=>{let n=t;e.description=P(e.config.languages,e.description,n)},[`${m}path`]:(e,t)=>{if(t.termType===`NamedNode`){e.path=t.value;return}let n=e.config.store.getQuads(t,null,null,null),r=n.filter(e=>e.predicate.value===`${m}alternativePath`);if(n.length!==1||r.length!==1){console.warn(`ignoring unsupported or malformed SHACL property path`,t.value);return}let i=e.config.lists[r[0].object.value];if(!i||i.length<2||i.some(e=>e.termType!==`NamedNode`)){console.warn(`ignoring sh:alternativePath without at least two predicate IRI members`,t.value);return}e.pathAlternatives=i.map(e=>e.value),e.path=e.pathAlternatives[0]},[`${m}group`]:(e,t)=>{e.group=t.id},[`${m}datatype`]:(e,t)=>{e.datatype=t},[`${m}nodeKind`]:(e,t)=>{e.nodeKind=t},[`${m}minCount`]:(e,t)=>{e.minCount=parseInt(t.value)},[`${m}maxCount`]:(e,t)=>{e.maxCount=parseInt(t.value)},[`${m}minLength`]:(e,t)=>{e.minLength=parseInt(t.value)},[`${m}maxLength`]:(e,t)=>{e.maxLength=parseInt(t.value)},[`${m}minInclusive`]:(e,t)=>{e.minInclusive=parseInt(t.value)},[`${m}maxInclusive`]:(e,t)=>{e.maxInclusive=parseInt(t.value)},[`${m}minExclusive`]:(e,t)=>{e.minExclusive=parseInt(t.value)},[`${m}maxExclusive`]:(e,t)=>{e.maxExclusive=parseInt(t.value)},[`${m}pattern`]:(e,t)=>{e.pattern=t.value},[`${m}order`]:(e,t)=>{e.order=parseInt(t.value)},[`${h}singleLine`]:(e,t)=>{e.singleLine=t.value===`true`},[`${h}readonly`]:(e,t)=>{e.readonly=t.value===`true`},[`${h}facet`]:(e,t)=>{e.facet=t.value===`true`||t.value===`1`},[`${ie}styleClass`]:(e,t)=>{e.cssClass=t.value},[`${m}in`]:(e,t)=>{e.in=t.value},[`${m}languageIn`]:(e,t)=>{e.languageIn=e.config.lists[t.value],e.datatype=S},[`${m}defaultValue`]:(e,t)=>{e.defaultValue=t},[`${m}hasValue`]:(e,t)=>{e.hasValue=t},[`${m}node`]:(e,t)=>{e.node=t,e.nodeShapes.add(e.config.getNodeTemplate(t,e))},[`${m}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))},[`${m}qualifiedValueShape`]:(e,t)=>{let n=e.config.getNodeTemplate(t,e);e.qualifiedValueShape=n,e.nodeShapes.add(n)},[`${m}qualifiedMinCount`]:(e,t)=>{e.qualifiedMinCount=parseInt(t.value)},[`${m}qualifiedMaxCount`]:(e,t)=>{e.qualifiedMaxCount=parseInt(t.value)},[w.id]:(e,t)=>{e.owlImports.add(t)},[T.id]:(e,t)=>{e.class=t;let n=e.config.store.getSubjects(E,t,null);n.length>0&&(e.node=n[0])},[`${m}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)},[`${m}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)}},ze=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 B(e){return Math.max(e.minCount??0,e.qualifiedMinCount??0)}function Be(e){return Math.min(e.maxCount??2**53-1,e.qualifiedMaxCount??2**53-1)}function V(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.pathAlternatives&&(t.pathAlternatives=[...e.pathAlternatives]),e.pathAlternativeBranches&&(t.pathAlternativeBranches={...e.pathAlternativeBranches}),e.or&&(t.or=[...e.or]),e.xone&&(t.xone=[...e.xone]),t}function H(e,t){for(let n of t)Re[n.predicate.id]?.call(e,e,n.object);return e.label=e.name?.value||O(t,e.config.languages),e.label||=e.pathAlternatives?e.pathAlternatives.map(e=>A(e,L)).join(` / `):e.path?A(e.path,L):`unknown`,e}function Ve(e,t,n=!1){let r=t,i=e,a=We(e),o=We(t),s=a&&U(t),c=o&&U(e);s&&(e.nodeShapes.clear(),e.node=void 0);for(let a in t)if(a!==`parent`&&a!==`config`&&a!==`id`){let o=r[a];if(o!==void 0&&o!==``){if(a===`label`)continue;if(a===`name`||a===`description`||a===`group`||a===`order`)(n||i[a]===void 0||i[a]===``)&&(i[a]=o);else if(a===`minCount`)e.minCount=Math.max(e.minCount??0,t.minCount);else if(a===`maxCount`)e.maxCount=Math.min(e.maxCount??2**53-1,t.maxCount);else if(a===`qualifiedMinCount`)e.qualifiedMinCount=Math.max(e.qualifiedMinCount??0,t.qualifiedMinCount);else if(a===`qualifiedMaxCount`)e.qualifiedMaxCount=Math.min(e.qualifiedMaxCount??2**53-1,t.qualifiedMaxCount);else if(a===`nodeShapes`&&c)continue;else if(a===`node`&&c)continue;else if(a===`pathAlternatives`)continue;else if(Array.isArray(o)){let e=i[a];Array.isArray(e)?e.push(...o):i[a]=[...o]}else if(o instanceof Set&&o.size){let e=i[a];i[a]=new Set([...e instanceof Set?e:[],...o])}else i[a]=o}}e.name&&(e.label=e.name.value)}function He(e){return e.pathAlternatives?`alternative:${JSON.stringify(e.pathAlternatives)}`:e.path}function Ue(e){return e.pathAlternatives?[...e.pathAlternatives]:e.path}function We(e){return e.nodeShapes.size>0&&e.qualifiedValueShape===void 0&&e.name===void 0&&e.description===void 0&&!U(e)}function U(e){return e.in!==void 0||e.datatype!==void 0||e.languageIn!==void 0||e.class!==void 0||e.hasValue!==void 0||e.defaultValue!==void 0}var Ge=(function(){let e=typeof document<`u`&&document.createElement(`link`).relList;return e&&e.supports&&e.supports(`modulepreload`)?`modulepreload`:`preload`})(),Ke=function(e){return`/`+e},qe={},W=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Ke(t,n),t=s(t),t in qe)return;qe[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Ge,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function Je(e,t,n,r,i){let a=document.createElement(`div`);a.classList.add(`shacl-or-constraint`),a.setAttribute(`part`,`constraint`);let o=[];if(t instanceof $){let r=[],i=!1;e.length&&(i=n.store.countQuads(e[0],de,null,null)>0);for(let a=0;a<e.length;a++)if(i){let i=n.store.getObjects(e[a],de,null),s=[],c=``;for(let e of i){let r=new Y(n.getPropertyTemplate(e,t.template),t);s.push(r),c+=(c.length>0?` / `:``)+r.template.label}r.push(s),o.push({label:c,value:a.toString()})}else{let i=e[a],s=new Y(n.getPropertyTemplate(i,t.template),t);r.push([s]),o.push({label:s.template.label,value:a.toString()})}let s=n.theme.createListEditor(`Please choose`,null,!1,o);s.setAttribute(`part`,`constraint-editor`);let c=s.querySelector(`.editor`);c.onchange=async()=>{if(c.value){let e=r[parseInt(c.value)];if(n.queryMode){let{activateNodeConstraintOption:t}=await W(async()=>{let{activateNodeConstraintOption:e}=await import(`./mode-DiqnS4uq.js`);return{activateNodeConstraintOption:e}},[]);await t(e,a);return}let i;if(e.length){for(let n of e)await n.bindValues(t.nodeId,!1);i=e[0],a.replaceWith(e[0]),i.updateControls()}for(let t=1;t<e.length;t++)i.after(e[t]),i=e[t],i.updateControls()}},a.appendChild(s)}else{let s=[];for(let t=0;t<e.length;t++){let r=n.store.getQuads(e[t],null,null,null);if(r.length){s.push(r);let e=O(r,n.languages);for(let t of r)t.predicate.equals(fe)&&(e||=O(n.store.getQuads(t.object,null,null,null),n.languages));o.push({label:e||A(r[0].predicate.value,L)+` = `+A(r[0].object.value,L),value:(s.length-1).toString()})}}let c=n.theme.createListEditor(t.template.label+`?`,null,!1,o,t.template);c.setAttribute(`part`,`constraint-editor`);let l=c.querySelector(`.editor`);l.onchange=async()=>{if(l.value){let e=H(V(i??t.template),s[parseInt(l.value)]);if(e.or=void 0,e.xone=void 0,n.queryMode){let{activatePropertyConstraintOption:n}=await W(async()=>{let{activatePropertyConstraintOption:e}=await import(`./mode-DiqnS4uq.js`);return{activatePropertyConstraintOption:e}},[]);await n(e,t,a);return}if(r||Be(t.template)>1){let n=await Z(e,void 0,!0,!1,t.parent);n.dataset.path=t.template.path,r&&(n.dataset.predicate=r),a.replaceWith(n),n.dispatchEvent(new Event(`change`,{bubbles:!0,cancelable:!0}));return}e.pathAlternatives=void 0;let o=new Y(e,t.parent);t.replaceWith(o),await o.updateControls()}},a.appendChild(c)}return a}function Ye(e,t,n,r=!1){let i=document.createElement(`div`);i.classList.add(`alternative-path-constraint`),i.setAttribute(`part`,`constraint`),i.dataset.path=e.template.path;let a=e.template.pathAlternatives.map((e,t)=>({label:A(e,L),value:t.toString()})),o=e.template.config.theme.createListEditor(`${e.template.label}: path`,null,!1,a,e.template);o.setAttribute(`part`,`constraint-editor`);let s=o.querySelector(`.editor`);return s.onchange=async()=>{if(s.value===``)return;let r=e.template.pathAlternatives[parseInt(s.value)],a=await e.addPropertyInstance(t,n,!0,r,!1);a&&(i.replaceWith(a),a.dispatchEvent(new Event(`change`,{bubbles:!0,cancelable:!0})))},i.appendChild(o),Lt(i,e.template.label,e.template.config.theme.dense,e.template.config.hierarchyColorsStyleSheet!==void 0,r),i}function Xe(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,v,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,E,i,null).length>0)return e}if(t.predicate.equals(T)){for(let n of r)if(t.object.equals(n))return e}}else if(t.predicate.equals(me)&&t.object.equals(ue))return e}}return console.error(`couldn't resolve sh:or/sh:xone on property for value`,t),[]}function Ze(e,t,n){for(let r of e){let e=!1,i=n.store.getObjects(r,de,null);for(let r of i){let i=n.store.getObjects(r,`${m}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 Qe=`:host {
2
+ --shacl-font-family: inherit;
3
+ --shacl-font-size: 14px;
4
+ --shacl-text-color: #333;
5
+ --shacl-muted-color: #555;
6
+ --shacl-border-color: #DDD;
7
+ --shacl-bg: #FFF;
8
+ --shacl-row-alt-bg: #F8F8F8;
9
+ --shacl-error-color: #C00;
10
+ --shacl-label-width: 8em;
11
+ --linked-icon: url('data:image/svg+xml;utf8,<svg viewBox="-1 -1 18 18" xmlns="http://www.w3.org/2000/svg"><path d="m13.4 7.6-6.3 6.3a4 4 0 0 1-5.7-5.7l6.6-6.6a2.75 2.75 0 0 1 3.9 3.9l-6.6 6.6a1.5 1.5 0 0 1-2.1-2.1l6-6" fill="none" stroke="black" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg>');
12
+ }
13
+ 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); }
14
+ form.mode-edit { padding-left: 1em; }
15
+ form, form * { box-sizing: border-box; }
16
+ shacl-node, .collapsible::part(content) { display: flex; flex-direction: column; width: 100%; position: relative; }
17
+ shacl-node .remove-button { margin-top: 1px; }
18
+ 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; }
19
+ shacl-node .add-button::part(button)::before { content: '+ ' }
20
+ shacl-node .link-button::part(button)::before { content: ''; display: inline-block; width: 1em; height: 1em; background-color: currentColor; -webkit-mask: var(--linked-icon) center / contain no-repeat; mask: var(--linked-icon) center / contain no-repeat; }
21
+ shacl-node h1 { font-size: 16px; border-bottom: 1px solid #AAA; margin-top: 4px; color: var(--shacl-muted-color); }
22
+ shacl-property:not(:has(>.collapsible)), shacl-property>.collapsible::part(content) { display: flex; flex-direction: column; align-items: end; position: relative; }
23
+ shacl-property:not(.may-add) > .add-button-wrapper, shacl-property:not(.may-add) > .collapsible > .add-button-wrapper { display: none; }
24
+ shacl-property:not(.may-remove) > .property-instance > .remove-button-wrapper > .remove-button:not(.persistent) { visibility: hidden; }
25
+ shacl-property:not(.may-remove) > .collapsible > .property-instance > .remove-button-wrapper > .remove-button:not(.persistent) { visibility: hidden; }
26
+ shacl-property:not(.may-remove) > .shacl-or-constraint > .remove-button-wrapper > .remove-button:not(.persistent),
27
+ shacl-property:not(.may-remove) > .alternative-path-constraint > .remove-button-wrapper > .remove-button:not(.persistent),
28
+ shacl-property:not(.may-remove) > .collapsible > .alternative-path-constraint > .remove-button-wrapper > .remove-button:not(.persistent) { visibility: hidden; }
29
+ .mode-view .shacl-group:not(:has(shacl-property)) { display: none; }
30
+ .property-instance, .shacl-or-constraint, .alternative-path-constraint { display: flex; align-items: center; padding: 4px 0; width: 100%; position: relative; }
31
+ .shacl-or-constraint > div, .alternative-path-constraint > div { display: flex; align-items: flex-start; }
32
+ .shacl-or-constraint > div:first-child, .alternative-path-constraint > div:first-child { flex-grow: 1 }
33
+ .shacl-or-constraint label, .alternative-path-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; }
34
+ .property-instance label[title] { cursor: help; text-decoration: underline dashed #AAA; }
35
+ .property-instance.linked label:after, label.linked:after { content: ''; position: absolute; top: 50%; right: 2px; width: 1.1em; height: 1.1em; transform: translateY(-50%); background-color: currentColor; -webkit-mask: var(--linked-icon) center / contain no-repeat; mask: var(--linked-icon) center / contain no-repeat; }
36
+ .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; }
37
+ .mode-edit .add-button-wrapper.required > .add-button::before, .add-button-wrapper.required > .link-button::before { left: -0.5em; }
38
+ .property-instance.valid::before { content: ''; position: absolute; left: calc(var(--label-width) - 1em); top: 50%; transform: translateY(-50%); 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>'); }
39
+ .editor:not([type='checkbox']) { flex-grow: 1; }
40
+ textarea.editor { resize: vertical; }
41
+ .lang-chooser { border: 0; background-color: #e9e9ed; padding: 2px 4px; align-self: flex-start; }
42
+ .validation-error { position: absolute; left: calc(var(--label-width) - 1em); top: 50%; transform: translateY(-50%); color: var(--shacl-error-color); cursor: help; }
43
+ .validation-error::before { content: '\\26a0' }
44
+ .validation-error.node { left: -1em; top: calc(4px + 0.45em); transform: none; }
45
+ .property-instance:has(> .editor:is(textarea, rokit-textarea)).valid::before,
46
+ .property-instance:has(> .editor:is(textarea, rokit-textarea)) > .validation-error {
47
+ top: calc(4px + 0.45em);
48
+ transform: none;
49
+ }
50
+ .invalid > .editor { border-color: red !important; }
51
+ .ml-0 { margin-left: 0 !important; }
52
+ .pr-0 { padding-right: 0 !important; }
53
+ .mode-view .property-instance:not(:first-child) > label { visibility: hidden; }
54
+ .mode-view .property-instance label { width: var(--label-width); }
55
+
56
+ .d-flex { display: flex; }
57
+ .lang { opacity: 0.65; font-size: 0.6em; }
58
+ a, a:visited { color: inherit; }
59
+ h3 { margin-top: 0; }
60
+
61
+ .fadeIn, .fadeOut { animation: fadeIn 0.2s ease-out; }
62
+ .fadeOut { animation-direction: reverse; animation-timing-function: ease-out;}
63
+ @keyframes fadeIn {
64
+ 0% { opacity: 0; transform: scaleY(0.8); }
65
+ 100% { opacity: 1; transform: scaleY(1); }
66
+ }
67
+ .collapsible::part(label) { font-weight: 600; }
68
+ .collapsible > .property-instance:nth-child(even) { background-color: var(--shacl-row-alt-bg); }
69
+ .collapsible > .property-instance > shacl-node > h1 { display: none; }
70
+ .ref-link { cursor: pointer; }
71
+ .ref-link:hover { text-decoration: underline; }
72
+ .node-id-display { color: var(--shacl-muted-color); font-size: 11px; }
73
+ /* hierarchy colors */
74
+ .colorize { --hierarchy-color-width: 3px; padding: 0 1px 0 calc(1px + var(--hierarchy-color-width)); align-self: stretch; position: relative; }
75
+ .colorize::before {
76
+ content: '';
77
+ position: absolute;
78
+ width: var(--hierarchy-color-width);
79
+ top: 0; bottom: 0; left: 0;
80
+ --index: mod(var(--hierarchy-level), var(--hierarchy-colors-length));
81
+ background: linear-gradient(var(--hierarchy-colors)) no-repeat 0 calc(var(--index) * 100% / (var(--hierarchy-colors-length) - 1)) / 100% calc(1px * infinity);
82
+ }
83
+ .property-instance:not(:has(shacl-node)) > .colorize::before { background: 0; }
84
+ .colorize:not(:has(.remove-button)) { padding-left: calc(8px + var(--hierarchy-color-width)); }
85
+ .mode-view .property-instance > .colorize { order: -1; }
86
+ .link-option { padding: 10px; }
87
+ .link-option:hover { background-color: #F5F5F5; cursor: pointer; }
88
+ rokit-dialog.link-chooser::part(dialog) { min-height: min(434px, 90vh); width: min(90vw, 600px); }
89
+ rokit-select::part(facet-count) { color: var(--shacl-muted-color); }
90
+ rokit-select::part(facet-count)::after { content: attr(data-count); color: inherit; display: inline-block; font-family: monospace; margin-left: 7px; font-size: 12px; }
91
+ `,$e=class{constructor(e){this.dense=!0;let t=Qe;e&&(t+=`
92
+ `+e),this.stylesheet=new CSSStyleSheet,this.stylesheet.replaceSync(t)}apply(e){}setDense(e){this.dense=e}createViewer(e,t,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=t.value,c=null;if(t instanceof r){let e=i.config.store.getQuads(s,null,null,null);if(e.length){let t=O(e,i.config.languages);t&&(s=t)}}else t instanceof n&&(t.language?(c=document.createElement(`span`),c.classList.add(`lang`),c.innerText=`@${t.language}`):t.datatype.value===`http://www.w3.org/2001/XMLSchema#date`?s=new Date(Date.parse(t.value)).toDateString():t.datatype.value===`http://www.w3.org/2001/XMLSchema#dateTime`&&(s=new Date(Date.parse(t.value)).toLocaleString()));let l;return N(t.value)?(l=document.createElement(`a`),l.setAttribute(`href`,t.value)):l=document.createElement(`div`),l.classList.add(`d-flex`),l.innerText=s,c&&l.appendChild(c),a.appendChild(l),a}};function et(e,t,r){if(r){let r=B(e)>0;if(e.class&&!e.hasValue)return e.config.theme.createListEditor(e.label,t,r,M(e.class,e),e);if(e.in){let n=e.config.lists[e.in];if(n?.length){let i=k(n,e.config.store,e.config.languages);return e.config.theme.createListEditor(e.label,t,r,i,e)}else console.error(`list not found:`,e.in,`existing lists:`,e.config.lists)}if(e.datatype?.equals(S)||e.languageIn?.length||e.datatype===void 0&&t instanceof n&&t.language)return e.config.theme.createLangStringEditor(e.label,t,r,e);switch(e.datatype?.value.replace(te,``)){case`integer`:case`float`:case`double`:case`decimal`:return e.config.theme.createNumberEditor(e.label,t,r,e);case`date`:case`dateTime`:return e.config.theme.createDateEditor(e.label,t,r,e);case`boolean`:return e.config.theme.createBooleanEditor(e.label,t,r,e);case`base64Binary`:return e.config.theme.createFileEditor(e.label,t,r,e)}return e.config.theme.createTextEditor(e.label,t,r,e)}else return t?e.config.theme.createViewer(e.label,t,e):document.createElement(`div`)}function tt(e,t){e.rdfTerm=t??void 0,e.rdfTermState=t?st(e):void 0}function nt(e,t){e.rdfTerms=new Map;for(let n of t)e.rdfTerms.set(rt(n),n)}function rt(e){return c(e)}function it(e){let t=e.rdfTerms?.get(e.value);if(t)return t;if(!(!e.rdfTerm||!ct(e.rdfTermState,st(e))))return e.rdfTerm}function G(i){let a=it(i);if(a)return a;let o=i.shaclDatatype,s=i.dataset.value||i.value;if((i.type===`file`||i.getAttribute(`type`)===`file`)&&i.binaryData)s=i.binaryData;else if(i.type===`checkbox`||i.getAttribute(`type`)===`checkbox`)return i.checked||parseInt(i.dataset.minCount||`0`)>0?t.literal(i.checked?`true`:`false`,o):void 0;if(!s)return;let c=i.dataset.nodeKind,l=at(s);if(i.dataset.link)return t.fromTerm(JSON.parse(i.dataset.link));if(i.dataset.class)return l instanceof r||l instanceof e?l:t.namedNode(s);if(c===`http://www.w3.org/ns/shacl#IRI`)return l instanceof r?l:t.namedNode(s);if(c===`http://www.w3.org/ns/shacl#BlankNode`)return l instanceof e?l:t.blankNode(s);if(c===`http://www.w3.org/ns/shacl#BlankNodeOrIRI`)return l instanceof r||l instanceof e?l:t.namedNode(s);if(l instanceof r||l instanceof e||l instanceof n&&!i.dataset.lang&&(!o||o instanceof r&&he.equals(o)))return l;if(i.dataset.lang)o=i.dataset.lang;else if(o instanceof r&&ye.has(o.value)){let e=ot(s,o.value);if(e===void 0)return;s=e}else i.type===`number`?s=parseFloat(s):i.type===`datetime-local`?s=Me(s,i.dataset.xsdTemporalSuffix):i.type===`date`&&o instanceof r&&o.value===`http://www.w3.org/2001/XMLSchema#date`&&(s=je(s,i.dataset.xsdTemporalSuffix));return t.literal(s,o)}function at(i){let a=i;if(i.startsWith(`<`)&&i.endsWith(`>`))a=i.slice(1,-1);else if(!i.startsWith(`_:`)&&!i.startsWith(`"`))return;let o=s(a,t);return o instanceof r||o instanceof e||o instanceof n?o:void 0}function ot(e,t){let n=e.replace(`,`,`.`);return(t===`http://www.w3.org/2001/XMLSchema#decimal`?/^[-+]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)$/:/^[-+]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][-+]?[0-9]+)?$/).test(n)?n:void 0}function st(e){return{value:e.value,language:e.dataset.lang,checked:e.checked,binaryData:e.binaryData}}function ct(e,t){return e?.value===t.value&&e.language===t.language&&e.checked===t.checked&&e.binaryData===t.binaryData}function lt(e,t,n){if(t===`application/ld+json`)return ut(e);{let r=new o({format:t,prefixes:n});r.addQuads(e);let i=``;return r.end((e,t)=>{e&&console.error(e),i=t}),i}}function ut(e){let t=[];for(let r of e){let e={"@id":r.subject.id};if(r.predicate.equals(v))e[`@type`]=r.object.id;else{let t=r.object.value;r.object instanceof n?r.object.language?t={"@language":r.object.language,"@value":r.object.value}:r.object.datatype&&r.object.datatype.value!==`http://www.w3.org/2001/XMLSchema##string`&&(t={"@type":r.object.datatype.value,"@value":r.object.value}):t={"@id":r.object.id},e[r.predicate.value]=t}t.push(e)}return JSON.stringify(t)}var K={};function dt(e){e.predicate===void 0&&e.datatype===void 0?console.warn(`not registering plugin because it does neither define "predicate" nor "datatype"`,e):K[`${e.predicate}^${e.datatype}`]=e}function ft(){return Object.entries(K).map(e=>e[1])}function pt(e,t){let n=K[`${e}^${t}`];return n||(n=K[`${e}^undefined`],n)?n:K[`undefined^${t}`]}var mt=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)}};function ht(e){let t=new Set;for(let n of e.getQuads(null,C,null,_))n.subject.termType===`NamedNode`&&t.add(n.subject.value);if(t.size===1)return t.values().next().value}function gt(e,n){let r=t.namedNode(n);for(let t of e.getObjects(r,C,_))if(t.termType===`NamedNode`&&e.getQuads(t,v,le,null).length>0)return t}async function _t(e,t){let n={store:new i,importedUrls:[],atts:e},r=[];if(e.shapes?r.push(q(R({rdf:e.shapes}),n,g)):e.shapesUrl&&r.push(q(R({url:e.shapesUrl,proxy:n.atts.proxy,rdfUrlResolver:n.atts.rdfUrlResolver}),n,g)),e.values?r.push(q(R({rdf:e.values}),n,_,t)):e.valuesUrl&&r.push(q(R({url:e.valuesUrl,proxy:n.atts.proxy,rdfUrlResolver:n.atts.rdfUrlResolver}),n,_,t)),await Promise.all(r),e.classInstanceProvider)try{let t=Ne(n.store),r=await e.classInstanceProvider(t);r&&await q(R({rdf:r}),n,g)}catch(e){console.error(`failed loading class instances`,e)}if(e.valuesSubject||=ht(n.store)||null,e.valuesSubject&&n.store.countQuads(null,null,null,g)===0){let t=[...n.store.getObjects(e.valuesSubject,v,_),...n.store.getObjects(e.valuesSubject,C,_)],r=[];for(let e of t){let t=vt(e.value);!t&&e.value.startsWith(`urn:`)&&n.atts.proxy&&(t=e.value),t&&n.importedUrls.indexOf(t)<0&&(n.importedUrls.push(t),r.push(q(R({url:t,proxy:n.atts.proxy,rdfUrlResolver:n.atts.rdfUrlResolver}),n,g)))}try{await Promise.allSettled(r)}catch(e){console.warn(e)}}return n.store}async function q(e,n,r,i){let a=await e,o=[];for(let e of a){i?.add(e);let a=r;if(n.atts.valuesSubject&&_.equals(r)&&e.graph.id&&e.graph.id!==n.atts.valuesSubject&&(a=e.graph),n.store.add(t.quad(e.subject,e.predicate,e.object,a)),n.atts.loadOwlImports&&w.equals(e.predicate)){let r=vt(e.object.value);r&&n.importedUrls.indexOf(r)<0&&(n.importedUrls.push(r),o.push(q(R({url:r,proxy:n.atts.proxy,rdfUrlResolver:n.atts.rdfUrlResolver}),n,t.namedNode(r))))}}await Promise.allSettled(o)}function vt(e){if(N(e))return e;let t=e.split(`:`);if(t.length===2){let n=L[t[0]];if(n&&(e=e.replace(`${t[0]}:`,n),N(e)))return e}return null}async function yt(e){if(e.template.nodeShapes.size===0)return;let t=e.template.config.resourceLinkProvider;if((!t||t&&!t.lazyLoad)&&(await wt(e.template),xt(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 wt(e.template),n.classList.remove(`loading`));let r=xt(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 f,t.classList.add(`link-chooser`),t.closable=!0,e.template.config.form.appendChild(t)),t.title=`Link existing `+e.template.label,bt(t,e,r),t.open=!0}}),n}function bt(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.value,n.addEventListener(`click`,async()=>{await St(i,t),e.open=!1}),r.appendChild(n)}e.replaceChildren(r)}function xt(e){let n=e.template.config,r=Ct(e.template),a=new Set(Array.from(e.querySelectorAll(`:scope > .property-instance > shacl-node, :scope > .collapsible > .property-instance > shacl-node`)).map(e=>e.nodeId.id)),o=new Map;for(let t of n.form.querySelectorAll(`shacl-node:not([part~="linked-node"])`)){if(!r.has(t.template.id.value)||a.has(t.nodeId.id))continue;let s=new i;t.toRDF(s),o.set(t.nodeId.id,{value:t.nodeId,label:O([...s.getQuads(t.nodeId,null,null,null),...n.store.getQuads(t.nodeId,null,null,null)],n.languages)||n.providedResourceLabels[t.nodeId.value],template:e.template})}if(n.resourceLinkProvider)for(let i of r)for(let r of n.providedConformingResourceIds[i]??[]){let i=t.namedNode(r);!a.has(i.id)&&!o.has(i.id)&&o.set(i.id,{value:i,label:n.providedResourceLabels[r]||O(n.store.getQuads(i,null,null,null),n.languages),template:e.template})}return[...o.values()]}async function St(e,t){let n=e.value.value;if(e.value.termType===`NamedNode`&&e.template.config.providedResources[n]?.length>0){let t={store:e.template.config.store,importedUrls:[],atts:{loadOwlImports:!1}};await q(R({rdf:e.template.config.providedResources[n]}),t,g),e.template.config.providedResources[n]=``}let r=await Z(e.template,e.value,!0,!0);t.container.insertBefore(r,t.querySelector(`:scope > .add-button-wrapper`)),await t.updateControls()}function Ct(e){return new Set(Array.from(e.nodeShapes,e=>e.id.value))}async function wt(e){let t=e.config.resourceLinkProvider;if(!t)return;let n=Ct(e);if(n.size===0)return;let r=Pe(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 Tt(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 Tt(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;let e=await R({rdf:i.resourceRDF});n.providedResourceLabels[i.resourceId]=O(e.filter(e=>e.subject.value===i.resourceId),n.languages),t&&await q(Promise.resolve(e),r,g)}return e}for(let e of r)n.providedResources[e]||(n.providedResources[e]=``)}catch(e){console.error(`failed loading resources`,e)}}return[]}async function Et(e){let t=new Set;for(let n of e.store.getQuads(null,null,null,_))Dt(n.object,e.store)&&t.add(n.object.value);await Tt(t,!0,e)}function Dt(e,t){return e.termType===`NamedNode`&&t.countQuads(e,null,null,null)===0}var J=`:scope > .add-button-wrapper, :scope > .collapsible > .add-button-wrapper`,Ot=`:scope > .property-instance, :scope > .shacl-or-constraint, :scope > .alternative-path-constraint, :scope > shacl-node, :scope > .collapsible > .property-instance, :scope > .collapsible > .alternative-path-constraint`,Y=class extends HTMLElement{constructor(e,t){if(super(),this.rdfListNodes=new WeakMap,this.rdfListGroups=new WeakMap,this.template=e,this.parent=t,this.rdfListItemTemplate=jt(e),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 d;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.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.pathAlternatives??[this.template.path]).flatMap(t=>this.template.config.store.getQuads(e,t,null,this.parent.linked?null:_));t&&(r=await this.filterValidValues(r,e)),r=r.filter(e=>this.parent.shouldBindPropertyValue(e));for(let e of r){this.parent.linked||this.template.config.store.delete(e);let t=!_.equals(e.graph)||this.template.config.providedResources[e.object.value]!==void 0;(this.rdfListItemTemplate?await this.bindRdfList(e.object,t):await this.addPropertyInstance(e.object,t,this.template.config.providedResources[e.object.value]!==void 0,e.predicate.value))&&this.parent.recordBoundPropertyValue(e),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 initializeQuery(){let{initializeQueryProperty:e}=await W(async()=>{let{initializeQueryProperty:e}=await import(`./mode-DiqnS4uq.js`);return{initializeQueryProperty:e}},[]);await e(this)}async addPropertyInstance(e,t,n=!1,r,i=!0){if(this.rdfListItemTemplate)return this.addRdfListItem(e,t,n,i);let a;if(this.template.pathAlternatives&&!r)this.template.config.editMode&&(a=Ye(this,e,t,n));else{let i=r?this.template.pathAlternativeBranches?.[r]:void 0,o=r&&(r!==this.template.path||i)?V(this.template):this.template;if(r&&(o.path=r),i&&(Ve(o,i,!0),o.label=i.name?.value||i.label||o.label),o.or?.length||o.xone?.length){let t=o.or?.length?o.or:o.xone,i=!1;if(e){let n=Xe(t,e,o.config);n.length&&(a=await Z(H(V(o),n),e,!this.parent.linked,this.parent.linked,this.parent),i=!0)}!i&&o.config.editMode&&(a=Je(t,this,o.config,r,o),Lt(a,``,o.config.theme.dense,o.config.hierarchyColorsStyleSheet!==void 0,n))}else a=await Z(o,e,n,t||this.parent.linked,this.parent)}return a&&(a.dataset.path=this.template.path,r&&(a.dataset.predicate=r),i&&this.container.insertBefore(a,this.querySelector(J))),a}async updateControls(){this.template.config.editMode&&!this.parent.linked&&!this.querySelector(J)&&this.container.appendChild(await this.createAddControls());let e=this.rdfListItemTemplate?+(B(this.template)>0):B(this.template),t=this.rdfListItemTemplate?this.rdfListItemTemplate.nodeShapes.size===0: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(J)?.classList.toggle(`required`,i<e);let a;a=e>0?i>e:!t||i>1;let o=this.rdfListItemTemplate!==void 0&&this.querySelector(`:scope > .property-instance.linked, :scope > .collapsible > .property-instance.linked`)!==null,s=new Set(kt(this).map(e=>this.rdfListGroups.get(e))).size,c=this.rdfListItemTemplate!==void 0&&!o&&s<=1||i<Be(this.template);this.classList.toggle(`may-remove`,a),this.classList.toggle(`may-add`,c)}instanceCount(){return this.querySelectorAll(Ot).length}refreshClassInstances(){if(!(!this.template.class||this.template.hasValue||!this.template.config.editMode))for(let e of this.querySelectorAll(`:scope > .property-instance, :scope > .collapsible > .property-instance`)){let t=e.querySelector(`:scope > .editor`);if(!t||t.dataset.class!==this.template.class.value)continue;let n=G(t),r=M(this.template.class,this.template);n&&!Ft(r,n)&&r.push({value:n,children:[]});let i=It(r);if(t.dataset.classInstances===i)continue;let a=this.template.config.theme.createListEditor(this.template.label,n??null,B(this.template)>0,r,this.template).querySelector(`.editor`);a.dataset.classInstances=i,t.replaceWith(a)}}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(e,n){if(this.rdfListItemTemplate){this.rdfListToRDF(e,n);return}for(let r of this.querySelectorAll(`:scope > .property-instance, :scope > .collapsible > .property-instance`)){let i=t.namedNode(r.dataset.predicate??this.template.path);if(r.firstChild instanceof $){let t=r.firstChild.toRDF(e);e.addQuad(n,i,t,this.template.config.valuesGraphId)}else if(this.template.config.editMode)for(let t of r.querySelectorAll(`:scope > .editor`)){let r=G(t);r&&e.addQuad(n,i,r,this.template.config.valuesGraphId)}else{let t=G(r);t&&e.addQuad(n,i,t,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=this.rdfListItemTemplate?void 0:await yt(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(),this.template.nodeShapes.size&&this.dispatchEvent(new Event(`change`,{bubbles:!0,cancelable:!0})),setTimeout(()=>{xe(e),e.classList.remove(`fadeIn`)},200))}),e.appendChild(n),e}async bindRdfList(e,t){if(e.termType!==`NamedNode`&&e.termType!==`BlankNode`)return;let n=e,r=new Set,i;for(;!n.equals(x)&&!r.has(n.id);){r.add(n.id);let a=t?null:_,o=this.template.config.store.getQuads(n,y,null,a)[0];if(!o)break;let s=this.template.config.store.getQuads(n,b,null,a)[0];t||(this.template.config.store.delete(o),s&&this.template.config.store.delete(s));let c=await this.addRdfListItem(o.object,t,!1,!0,n,X(e));if(i||=c,!s||s.object.termType!==`NamedNode`&&s.object.termType!==`BlankNode`)break;n=s.object}return i}async addRdfListItem(e,t=!1,n=!1,r=!0,i,a){let o=V(this.rdfListItemTemplate);o.label=this.template.label;let s=await Z(o,e,n,t||this.parent.linked,this.parent);s.dataset.path=this.template.path;let c=kt(this).map(e=>this.rdfListGroups.get(e)).find(e=>e!==void 0),l=i??this.createRdfListNode(c===void 0);return this.rdfListNodes.set(s,l),this.rdfListGroups.set(s,a??c??X(l)),r&&this.container.insertBefore(s,this.querySelector(J)),s}createRdfListNode(e){return e&&this.template.nodeKind?.value===`http://www.w3.org/ns/shacl#IRI`?t.namedNode(this.template.config.attributes.valuesNamespace+p()):t.blankNode()}rdfListToRDF(e,n){let r=new Map;for(let n of kt(this)){let i=this.rdfListNodes.get(n)??t.blankNode(),a=this.rdfListGroups.get(n)??X(i),o=n.classList.contains(`linked`),s;if(!o&&n.firstChild instanceof $)s=n.firstChild.toRDF(e);else if(!o&&this.template.config.editMode){let e=n.querySelector(`:scope > .editor`);s=e?G(e):void 0}else o||(s=G(n));if(o||s){let e=r.get(a)??[];e.push({instance:n,node:i,value:s,linked:o}),r.set(a,e)}}let i=new Set([...r.values()].flatMap(e=>e.map(e=>X(e.node)))),a=new Map([...r.values()].flatMap(e=>e.filter(e=>!e.linked&&e.value).map(e=>[X(e.node),X(e.value)]))),o=new Set([...r.values()].filter(e=>e[0]?.linked).map(e=>X(e[0].node)));this.removePreservedRdfList(e,n,i,a,o);for(let i of r.values())e.addQuad(n,t.namedNode(this.template.path),i[0].node,this.template.config.valuesGraphId),!i[0].linked&&(this.template.class&&e.addQuad(i[0].node,v,this.template.class,this.template.config.valuesGraphId),i.forEach(({node:t,value:n},r)=>{e.addQuad(t,y,n,this.template.config.valuesGraphId),e.addQuad(t,b,i[r+1]?.node??x,this.template.config.valuesGraphId)}))}removePreservedRdfList(e,n,r,i,a){if(this.template.config.attributes.preserveUnmappedValues===null)return;let o=this.template.config.originalValues,s=o.getObjects(n,t.namedNode(this.template.path),null),c=new Map,l=[];for(let t of s){if(t.termType!==`NamedNode`&&t.termType!==`BlankNode`||a.has(X(t)))continue;let n=t,r=new Set;for(;!n.equals(x)&&!r.has(n.id);){r.add(n.id),c.set(X(n),n);let t=o.getQuads(n,b,null,null)[0];for(let t of e.getQuads(n,y,null,null)){e.delete(t);let r=i.get(X(n));t.object.termType===`BlankNode`&&X(t.object)!==r&&l.push(t.object)}for(let t of e.getQuads(n,b,null,null))e.delete(t);if(!t||t.object.termType!==`NamedNode`&&t.object.termType!==`BlankNode`)break;n=t.object}}for(let t of c.values())if(t.termType===`BlankNode`&&!r.has(X(t))&&e.countQuads(null,null,t,null)===0)for(let n of e.getQuads(t,null,null,null))e.delete(n),n.object.termType===`BlankNode`&&l.push(n.object);At(e,l)}};function kt(e){return Array.from(e.querySelectorAll(`:scope > .property-instance, :scope > .collapsible > .property-instance`))}function X(e){return`${e.termType}:${e.value}`}function At(e,t){let n=new Set;for(;t.length;){let r=t.pop();if(!(n.has(r.id)||e.countQuads(null,null,r,null)>0)){n.add(r.id);for(let n of e.getQuads(r,null,null,null))e.delete(n),n.object.termType===`BlankNode`&&t.push(n.object)}}}function jt(e){if(e.maxCount!==1||e.nodeShapes.size!==1||!Mt(e.nodeKind)||!Pt(e.config.store,e.id,[`path`,`minCount`,`maxCount`,`node`,`nodeKind`,`class`]))return;let t=[...e.nodeShapes][0],n=e.config.store.countQuads(t.id,`${m}property`,null,null),r=e.config.store.getObjects(e.id,`${m}node`,null);if(r.length!==1||!r[0].equals(t.id)||n!==2||Object.keys(t.properties).length!==2||t.extendedShapes.size||t.or?.length||t.xone?.length||t.nodeKind||t.targetClass||!Pt(e.config.store,t.id,[`property`]))return;let i=t.properties[y.value],a=t.properties[b.value];if(i?.length!==1||a?.length!==1||i[0].minCount!==1||i[0].maxCount!==1||a[0].minCount!==1||a[0].maxCount!==1||i[0].or?.length||i[0].xone?.length||i[0].hasValue||!Pt(e.config.store,a[0].id,[`path`,`minCount`,`maxCount`,`or`]))return;let o=a[0].or;if(o?.length!==2)return;let s=!1,c=!1;for(let n of o){let r=e.config.store.getQuads(n,null,null,null).filter(e=>e.predicate.value.startsWith(`http://www.w3.org/ns/shacl#`)&&!Nt.has(e.predicate.value));s||=r.length===1&&r[0].predicate.value===`http://www.w3.org/ns/shacl#hasValue`&&r[0].object.equals(x),c||=r.length===1&&r[0].predicate.value===`http://www.w3.org/ns/shacl#node`&&r[0].object.equals(t.id)}return s&&c?i[0]:void 0}function Mt(e){return e===void 0||[`http://www.w3.org/ns/shacl#IRI`,`http://www.w3.org/ns/shacl#BlankNode`,`http://www.w3.org/ns/shacl#BlankNodeOrIRI`].includes(e.value)}var Nt=new Set([`${m}name`,`${m}description`,`${m}order`,`${m}group`,`${m}message`,`${m}severity`]);function Pt(e,t,n){let r=new Set(n.map(e=>m+e));return e.getQuads(t,null,null,null).every(e=>!e.predicate.value.startsWith(`http://www.w3.org/ns/shacl#`)||r.has(e.predicate.value)||Nt.has(e.predicate.value))}function Ft(e,t){return e.some(e=>typeof e.value!=`string`&&e.value.equals(t)||Ft(e.children??[],t))}function It(e){return JSON.stringify(e.map(e=>[typeof e.value==`string`?e.value:`${e.value.termType}:${e.value.value}`,e.label,It(e.children??[])]))}async function Z(e,t,n=!1,r=!1,i){let a;if(e.nodeShapes.size){a=document.createElement(`div`),a.classList.add(`property-instance`),a.setAttribute(`part`,`property-instance`);let n=new Set(i?.ancestorShapeIds??[]);i&&n.add(i.template.id.value);for(let i of e.nodeShapes){let o=new $(i,t,e.nodeKind,e.label,r,n);a.appendChild(o),await o.ready}}else{let n=pt(e.path,e.datatype?.value);a=n?e.config.editMode&&!r?n.createEditor(e,t):n.createViewer(e,t):et(e,t||null,e.config.editMode&&!r),a.childNodes.length>0&&(a.classList.add(`property-instance`),a.setAttribute(`part`,`property-instance`)),r&&a.classList.add(`linked`)}return e.config.editMode&&(!r||n)?Lt(a,e.label,e.config.theme.dense,e.config.hierarchyColorsStyleSheet!==void 0,n):e.config.hierarchyColorsStyleSheet!==void 0&&a.appendChild(Rt(!0)),t&&!e.config.editMode&&tt(a,t),a.dataset.path=e.path,a}function Lt(e,t,n,r,i=!1){let a=Rt(r),o=new u;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 Rt(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`,Y);function zt(e,t){let n=e,r=t.store.getQuads(e,null,null,null),i=D(r,`label`,re,t.languages);i&&(n=i);let a;if(t.attributes.collapse!==null)a=new d,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=parseInt(D(r,`order`)??``)||0;return{element:a,order:o}}var Bt={[`${m}node`]:(e,t)=>{e.extendedShapes.add(new Vt(t,e.config,e))},[`${m}and`]:(e,t)=>{for(let n of e.config.lists[t.value])e.extendedShapes.add(new Vt(n,e.config,e))},[`${m}property`]:(e,t)=>{let n=e.config.getPropertyTemplate(t,e),r=He(n);if(r){let t=e.properties[r];if(t||(t=[],e.properties[r]=t),n.qualifiedValueShape)t.push(n);else{let i;for(let t=0;t<e.properties[r].length&&!i;t++)e.properties[r][t].qualifiedValueShape||(i=e.properties[r][t]);i?Ve(i,n):t.push(n)}}},[`${m}nodeKind`]:(e,t)=>{e.nodeKind=t},[`${m}targetClass`]:(e,t)=>{e.targetClass=t},[`${h}facet`]:(e,t)=>{e.facet=t.value===`true`||t.value===`1`},[`${m}or`]:(e,t)=>{e.or=e.config.lists[t.value]},[`${m}xone`]:(e,t)=>{e.xone=e.config.lists[t.value]},[w.id]:(e,t)=>{e.owlImports.add(t)},[`${ae}title`]:(e,t)=>{let n=t;e.label=P(e.config.languages,e.label,n)},[`${re}label`]:(e,t)=>{let n=t;e.label=P(e.config.languages,e.label,n)}},Vt=class{constructor(e,t,n){this.extendedShapes=new Set,this.properties={},this.owlImports=new Set,this.merged=!1,this.id=e,this.config=t,this.parent=n,t.registerNodeTemplate(this),Ht(this,this.config.store.getQuads(e,null,null,null))}};function Ht(e,t){for(let n of t)Bt[n.predicate.id]?.call(e,e,n.object);return Ut(e),e}function Ut(e){let t=Object.values(e.properties).flat().filter(e=>e.pathAlternatives?.length),n=new Set;for(let r of t){let t={};r.pathAlternatives.every(n=>{let r=e.properties[n];return r?.length!==1||Wt(r[0])?!1:(t[n]=r[0],!0)})&&(r.pathAlternativeBranches=t,r.pathAlternatives.forEach(e=>n.add(e)))}for(let t of n)delete e.properties[t]}function Wt(e){return e.minCount!==void 0||e.maxCount!==void 0||e.qualifiedMinCount!==void 0||e.qualifiedMaxCount!==void 0||e.qualifiedValueShape!==void 0}function Gt(e){if(!e.merged){e.merged=!0;for(let t of Object.values(e.properties))for(let n of t){let[t,r]=Q(e,He(n)),i=t.some(e=>e.qualifiedValueShape!==void 0),a=Kt(t),o=i?a:r;if(t.length>1&&o){let e=t[t.length-1];a&&(e.queryShapePathId=t[0].id.value);for(let n=t.length-2;n>=0;n--){let r=t[n],i=a?e.qualifiedValueShape:void 0;delete r.parent.properties[He(r)],Ve(e,r,!0),i&&e.nodeShapes.delete(i)}Jt(e)}}}}function Kt(e){if(e.length<2)return!1;for(let t=0;t<e.length-1;t++){let n=e[t],r=e[t+1];if(!n.qualifiedValueShape||!r.qualifiedValueShape||!qt(n.parent,r.parent)||!qt(n.qualifiedValueShape,r.qualifiedValueShape))return!1}return!0}function qt(e,t){let n=[...e.extendedShapes],r=new Set;for(;n.length;){let e=n.pop();if(e.id.equals(t.id))return!0;r.has(e)||(r.add(e),n.push(...e.extendedShapes))}return!1}function Jt(e){for(let t of[`xone`,`or`]){let n=e[t];if(!n?.length)continue;let r=n.filter(t=>Yt(t,e));r.length>0&&r.length<n.length&&(r.length===1?(e[t]=void 0,H(e,e.config.store.getQuads(r[0],null,null,null))):e[t]=r)}}function Yt(e,t){let n=t.config.store.getQuads(e,null,null,null);return Xt(n,`http://www.w3.org/ns/shacl#datatype`,t.datatype)&&Xt(n,T.id,t.class)&&Xt(n,`http://www.w3.org/ns/shacl#nodeKind`,t.nodeKind)}function Xt(e,t,n){if(!n)return!0;let r=!1;for(let i of e)if(i.predicate.value===t&&(r=!0,i.object.equals(n)))return!0;return!r}function Q(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 o of a[0].nodeShapes)if(qt(o,e)){let[e,a]=Q(o,t,n,r,i);i||=a}}for(let a of e.extendedShapes){let[e,o]=Q(a,t,n,r,i);i||=o}}return[r,i]}var $=class e extends HTMLElement{constructor(n,r,a,o,s,c=new Set,l,ee=Zt.create()){super(),this.template=n,this.linked=s??!1,this.ancestorShapeIds=c,this.queryContext=l,this.bindingContext=ee,this.setAttribute(`part`,`node`);let u=r;u||=(!a&&n.nodeKind&&(a=n.nodeKind),a===void 0&&n.config.attributes.valuesNamespace||a?.value===`http://www.w3.org/ns/shacl#IRI`?t.namedNode(n.config.attributes.valuesNamespace+p()):t.blankNode(p())),this.nodeId=u;let d=JSON.stringify([n.id,this.nodeId]);if(r&&n.config.renderedNodes.has(d)){o||=`Link`;let e=document.createElement(`label`);e.innerText=o,e.classList.add(`linked`),this.appendChild(e);let t=this.getAttribute(`part`);this.setAttribute(`part`,`${t?t+` `:``}linked-node`),this.dataset.nodeId=this.nodeId.id;let n=document.createElement(`a`),a=r.termType===`BlankNode`?`_:`+r.value:r.value,s=Array.from(this.template.config.form.querySelectorAll(`shacl-node:not([part~="linked-node"])`)).find(e=>e.nodeId.equals(r)),c=new i;s?.toRDF(c),n.innerText=O([...c.getQuads(r,null,null,null),...this.template.config.store.getQuads(r,null,null,null)],this.template.config.languages)||a,n.classList.add(`ref-link`),n.onclick=()=>{this.template.config.form.querySelector(`shacl-node[data-node-id='${a}']:not([part~='linked-node'])`)?.scrollIntoView()},this.appendChild(n),this.style.flexDirection=`row`,this.ready=Promise.resolve()}else{n.config.renderedNodes.add(d);let t=this.ancestorShapeIds,i=this.template.id.value,a=this.queryContext,c=this.bindingContext;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)}Gt(n),this.ready=(async()=>{let l=new Set(t);l.add(i);for(let e of Object.values(n.properties))for(let t of e)await this.addPropertyInstance(t,r,e.length>1);for(let t of n.extendedShapes){let n=new e(t,r,void 0,void 0,s,l,a,c.forInheritedShape());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),o){let e=document.createElement(`h1`);e.innerText=o,e.setAttribute(`part`,`node-title`),this.prepend(e)}})()}}shouldBindPropertyValue(e){return!this.linked||!this.bindingContext.wasBoundByDescendant(e)}recordBoundPropertyValue(e){this.linked&&this.bindingContext.record(e)}toRDF(e,n,r=``){if(n||=this.nodeId,!this.linked){for(let t of this.querySelectorAll(`:scope > shacl-node, :scope > .shacl-group > shacl-node, :scope > shacl-property, :scope > .shacl-group > shacl-property`))t.toRDF(e,n);this.template.targetClass&&e.addQuad(n,v,this.template.targetClass,this.template.config.valuesGraphId),r&&e.addQuad(n,t.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}']`);if(!t){let n=zt(e.group,e.config);t=n.element,$t(this,t,n.order)}r=t}else console.warn(`ignoring unknown group reference`,e.group,`existing groups:`,e.config.groups);let i=new Y(e,this);e.config.queryMode?await i.initializeQuery():await i.bindValues(t,n),(e.config.editMode&&!this.linked||e.config.queryMode||i.instanceCount()>0)&&($t(r||this,i,e.order),!e.config.queryMode&&!this.linked&&await i.updateControls())}async tryResolve(e,t,n){let r=!1;if(t){let i=Ze(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))}},Zt=class e{constructor(e){this.boundValues=new Set,this.inheritedValues=new Set(e)}static create(){return new e([])}wasBoundByDescendant(e){return this.inheritedValues.has(this.key(e))}record(e){this.boundValues.add(this.key(e))}forInheritedShape(){return new e([...this.inheritedValues,...this.boundValues])}key(e){return`${e.predicate.id}\0${e.object.id}`}},Qt=new WeakMap;function $t(e,t,n=0){Qt.set(t,n);let r=Array.from(e.children).find(e=>e!==t&&(Qt.get(e)??0)>n);e.insertBefore(t,r??null)}window.customElements.define(`shacl-node`,$);function en(e){return e.discrete!==!0&&e.datatype!==void 0&&_e.has(e.datatype)}export{pe as $,Ie as A,O as B,W as C,Re as D,V as E,Te as F,ye as G,ke as H,k as I,te as J,ve as K,Fe as L,z as M,L as N,H as O,I as P,le as Q,Ee as R,Je as S,B as T,_ as U,Ae as V,C as W,v as X,S as Y,ue as Z,lt as _,Y as a,rt as b,Et as c,q as d,E as et,_t as f,dt as g,ft as h,Gt as i,R as j,Ue as k,gt as l,pt as m,$ as n,ge as nt,Rt as o,mt as p,m as q,Vt as r,jt as s,en as t,g as tt,ht as u,tt as v,ze as w,$e as x,nt as y,M as z};