@strifeapp/strife 0.1.0-preview.6 → 0.2.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.esm.js +1 -1
- package/package.json +3 -3
package/README.md
ADDED
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={CONNECT:1,HSHK:2,EU:4,SYNC:8};class t extends MessageChannel{constructor(){super(),this.broadcastChannel=new BroadcastChannel('app.broadcast');switch(this.port1.addEventListener('message',(t=>{t.data.cmd===e.CONNECT&&this.onConnected(t)}),{once:!0}),this.port1.start(),this._ready=new Promise(((e,t)=>{this.readyResolve=e,this.readyReject=t})),this._ready.then((()=>{console.log(`SENDING MESSAGE FROM SDK IN WINDOW ${window.name}`),window.top.postMessage({cmd:e.HSHK,context:{name:window.name,height:document.body.scrollHeight}},'*',[this.port2])})),window.addEventListener('beforeunload',(()=>{console.log('unload'),this.send({foo:'bar'})})),window.addEventListener('click',(()=>{this.send({cmd:e.EU,updates:[{action:'click',lastUserInteraction:(new Date).valueOf(),context:window.name}]})}),!1),document.readyState){case'loading':case'interactive':document.onreadystatechange=()=>{'complete'===document.readyState&&this.readyResolve()};break;case'complete':this.readyResolve()}}subscribe(e){if(null==e)throw new Error('Parameter can not be null!');this.broadcastChannel.addEventListener('message',e),this.port1.addEventListener('message',e),this.port1.addEventListener('message',(e=>this.broadcastChannel.postMessage(e.data)))}send(e){this.port1.postMessage(e),this.broadcastChannel.postMessage(e)}onConnected(e){return e}}var s=new t;const i={NONE:8,EDIT:16,RESET:32,INIT:64,SYNC:128},r=()=>s,n=[];s.subscribe((({data:t})=>{try{t.cmd===e.SYNC?(t.sync.forEach((e=>{switch(e.action){case i.INIT:n.forEach((({self:t,handler:s})=>{const i=e.data.find((e=>e.propertyName===t.dataset.propertyName));e.currentPath===window.location.pathname&&i&&(t.dataset.placeholder=i.placeholder)}));break;case i.EDIT:case i.RESET:n.forEach((({self:t,handler:s})=>{if(e.currentPath===window.location.pathname&&(e.action===i.RESET||e.data.some((e=>e.name===t.dataset.propertyName)))){const i=e.data.find((e=>e.name===t.dataset.propertyName))?.value;s(i)}}))}})),s.send({cmd:e.EU,updates:[{action:i.SYNC,context:{name:window.name,height:document.body.scrollHeight}}]})):t.cmd===e.EU&&t.action===i.FOCUS&&t.updates.forEach((e=>{n.forEach((({self:t})=>{e.propertyName===t.dataset.propertyName&&e.currentPath===window.location.pathname&&t.scrollIntoView({behavior:'smooth',block:'center'})}))}))}catch(e){console.error(e)}}));const o=(e,t)=>(n.push({self:e,handler:t}),s),a=new CSSStyleSheet;a.replaceSync(':root {\n --str-placeholder-text-opacity: 0.3;\n --str-placeholder-background-color: #0099ff;\n --str-placeholder-background-opacity: 0.8;\n}\n\n[is]:not([is=\'str-template-cpnt\'] [is]):hover {\n outline: solid 1px #0099ff;\n cursor: pointer;\n}\nimg.previewing {\n --img-previewing-url: \'\';\n --img-previewing-size: 100%;\n --img-previewing-position: 0px 0px;\n background-image: var(--img-previewing-url);\n background-repeat: no-repeat;\n background-position: var(--img-previewing-position);\n background-size: var(--img-previewing-size);\n}\nimg.previewing.previewing--empty {\n background-image: repeating-linear-gradient(45deg, var(--str-placeholder-background-color) 0, transparent 1px, transparent 0, transparent 50%);\n background-repeat: repeat;\n background-position: 0 0;\n background-size: 15px 15px;\n outline: solid 1px var(--str-placeholder-background-color);\n opacity: var(--str-placeholder-background-opacity);\n}\n\n\n\n:where([is^="str-h"]:empty, [is^="str-textarea"]:empty, [is^="str-address"]:empty)::before {\n color: inherit;\n\n opacity: var(--str-placeholder-text-opacity);\n\n content: attr(data-placeholder);\n}');class c extends HTMLHeadingElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-h1-cpnt',c,{extends:'h1'}),customElements.define('str-h2-cpnt',class extends c{},{extends:'h2'}),customElements.define('str-h3-cpnt',class extends c{},{extends:'h3'}),customElements.define('str-h4-cpnt',class extends c{},{extends:'h4'}),customElements.define('str-h5-cpnt',class extends c{},{extends:'h5'}),customElements.define('str-h6-cpnt',class extends c{},{extends:'h6'});class d extends HTMLElement{constructor(){super(),this.tabIndex=0}async connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-address-cpnt',d,{extends:'address'});class h extends HTMLAnchorElement{constructor(){super(),this.tabIndex=0}async connectedCallback(){o(this,(e=>this.href=e))}}customElements.define('str-anchor-cpnt',h,{extends:'a'});const l='https://images.nimbleinitiatives.com/AS3SX_-B59mU1hdDS7B_YfI5Lu9Ut-kLpdaAhraKgy4/w:1/h:1/aHR0cHM6Ly9zdHJpZmUuYi1jZG4ubmV0L3RyYW5zcGFyZW50MXgxLnBuZw.png';customElements.define('str-picture-cpnt',class extends HTMLPictureElement{_propertyMedia;_currentSrc;constructor(){super(),this.image=this.querySelector('img'),this.sources=[...this.querySelectorAll('source')],this.tabIndex=0,this.image.complete?this.init():(this.image.addEventListener('load',(e=>{this.init()}),{once:!0}),this.image.addEventListener('error',(e=>{this.init()}),{once:!0})),this._initied=new Promise(((e,t)=>{this.loadedResolve=e,this.loadedReject=t}))}connectedCallback(){}init(){this.initPreview(),o(this,(e=>{this.render(this,e)}))}initPreview(){console.groupCollapsed('[STR-PICTURE-CPNT ('+window.name+') INIT DEBUG]'),this.image.currentSrc||console.warn('img[currentSrc] is empty.'),this._currentSrc=this.sources.find((e=>{if(this.image.currentSrc)return e.srcset===this.image.currentSrc;{const t=window.matchMedia(e.media);return console.log('Trying to match media...',e.media,'matches=',t.matches),t.matches}})),this._currentSrc?(this._propertyMedia=this._currentSrc.dataset?.propertyMedia,console.log('currentSrc set to ',this._currentSrc,' and property media set to ',this._propertyMedia),this.offsetWidth<this._currentSrc.width&&console.log('container width ('+this.offsetWidth+'px) is smaller than given source width ('+this._currentSrc.width+'px). Image is scaled to',(this.offsetWidth/this._currentSrc.width*100).toFixed(0),'%'),!this.image.currentSrc&&this._currentSrc.width&&this._currentSrc.height&&(this.image.classList.add('previewing--empty'),console.log('Image was empty on load.')),this.image.classList.add('previewing'),this.image.style.maxWidth='100%',this.image.style.width=this._currentSrc.width+'px',this.image.style.aspectRatio=this._currentSrc.width/this._currentSrc.height,console.log('image width (max 100%) and aspect ratio set to',this.image.style.width,this.image.style.aspectRatio),this.image.style.setProperty('--img-previewing-url',`url(${this.image.currentSrc||this._currentSrc.srcset})`),console.log('CSS variable --img-previewing-url set to',this.image.currentSrc||this._currentSrc.srcset||'null','[IS TRANSPARENT PIXEL:]',(this.image.currentSrc||this._currentSrc.srcset)===l),this.image.style.setProperty('--img-previewing-size','100%'),this.image.style.setProperty('--img-previewing-position','0px,0px'),this.image.src=l,this.sources.forEach((e=>{e.srcset=l})),this.image.addEventListener('load',(e=>{this.loadedResolve()}),{once:!0})):console.warn('currentSrc could not be set (null)'),console.groupEnd()}render(e,t,s){this._initied.then((()=>{if(console.groupCollapsed('[STR-PICTURE-CPNT ('+window.name+') RENDER DEBUG]'),this._propertyMedia&&t&&t[this._propertyMedia]&&t[this._propertyMedia].source&&t[this._propertyMedia].source.crop){const e=this.image.offsetWidth/t[this._propertyMedia].width,s=this.image.offsetWidth/2-t[this._propertyMedia].source.originalWidth*(t[this._propertyMedia].source.crop.zoom*e)*t[this._propertyMedia].source.crop.focusX,i=this.image.offsetHeight/2-t[this._propertyMedia].source.originalHeight*(t[this._propertyMedia].source.crop.zoom*e)*t[this._propertyMedia].source.crop.focusY,r=t[this._propertyMedia].source.originalWidth/this.image.offsetWidth*(t[this._propertyMedia].source.crop.zoom*e);this.image.style.setProperty('--img-previewing-url',`url(${t[this._propertyMedia].source.originalPreview})`),console.log('CSS variable --img-previewing-url set to',t[this._propertyMedia].source.originalPreview||'null','[IS TRANSPARENT PIXEL:]',t[this._propertyMedia].source.originalPreview===l),this.image.style.setProperty('--img-previewing-size',100*r+'%'),this.image.style.setProperty('--img-previewing-position',`${s}px ${i}px`),t[this._propertyMedia].source.originalPreview?this.image.classList.remove('previewing--empty'):this.image.classList.add('previewing--empty'),console.log('Received render request with result',t[this._propertyMedia]),console.log('Calculating: Rendered size',(100*e).toFixed(0),'%'),console.log('Calculating: Translate X',s),console.log('Calculating: Translate Y',i),console.log('Calculating: Zoom',r)}else console.warn('Received invalid result and render aborted');console.groupEnd()}))}disconnectedCallback(){}},{extends:'picture'}),customElements.define('str-img-cpnt',class extends HTMLImageElement{constructor(){super(),this.tabIndex=0,this.complete?this.init():(this.addEventListener('load',(e=>{this.init()}),{once:!0}),this.addEventListener('error',(e=>{this.init()}),{once:!0})),this._loaded=new Promise(((e,t)=>{this.loadedResolve=e,this.loadedReject=t}))}connectedCallback(){}init(){this.initPreview(),o(this,(e=>{this.render(this,e)}))}initPreview(){this.classList.add('previewing'),this.src||this.classList.add('previewing--empty'),this.style.width=this.width+'px',this.style.height=this.height+'px',this.style.setProperty('--img-previewing-url',`url(${this.src})`),this.style.setProperty('--img-previewing-size','100%'),this.style.setProperty('--img-previewing-position','0px,0px'),this.src='https://images.nimbleinitiatives.com/AS3SX_-B59mU1hdDS7B_YfI5Lu9Ut-kLpdaAhraKgy4/w:1/h:1/aHR0cHM6Ly9zdHJpZmUuYi1jZG4ubmV0L3RyYW5zcGFyZW50MXgxLnBuZw.png',this.addEventListener('load',(e=>{this.loadedResolve()}),{once:!0})}render(e,t,s){this._loaded.then((()=>{if(t&&t.source){const e=this.offsetWidth/t.width,s=this.offsetWidth/2-t.source.originalWidth*(t.source.crop.zoom*e)*t.source.crop.focusX,i=this.offsetHeight/2-t.source.originalHeight*(t.source.crop.zoom*e)*t.source.crop.focusY,r=t.source.originalWidth/this.offsetWidth*(t.source.crop.zoom*e);this.style.setProperty('--img-previewing-url',`url(${t.source.originalPreview})`),this.style.setProperty('--img-previewing-size',100*r+'%'),this.style.setProperty('--img-previewing-position',`${s}px ${i}px`),t.source.originalPreview?this.classList.remove('previewing--empty'):this.classList.add('previewing--empty')}}))}disconnectedCallback(){}},{extends:'img'}),customElements.define('strife-blocks-cpnt',class extends HTMLDivElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this,(e=>this.textContent=e))}},{extends:'div'});class p extends HTMLElement{constructor(){super(),this.tabIndex=0}async connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-strong-cpnt',p,{extends:'strong'});class m extends HTMLElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this)}}customElements.define('str-template-cpnt',m),customElements.define('str-textarea-cpnt',class extends HTMLDivElement{constructor(){super(),this.tabIndex=0}async connectedCallback(){o(this,(e=>{this.innerHTML=e}))}},{extends:'div'});class g extends HTMLSpanElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-span-cpnt',g,{extends:'span'});class u extends HTMLParagraphElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-p-cpnt',u,{extends:'p'}),document.adoptedStyleSheets=[a];export{i as ACTION,e as CMD,r as default,o as useState};
|
|
1
|
+
const e={CONNECT:1,HSHK:2,EU:4,SYNC:8};class t extends MessageChannel{constructor(){super(),this.broadcastChannel=new BroadcastChannel('app.broadcast');switch(this.port1.addEventListener('message',(t=>{t.data.cmd===e.CONNECT&&this.onConnected(t)}),{once:!0}),this.port1.start(),this._ready=new Promise(((e,t)=>{this.readyResolve=e,this.readyReject=t})),this._ready.then((()=>{console.log(`SENDING MESSAGE FROM SDK IN WINDOW ${window.name}`),window.top.postMessage({cmd:e.HSHK,context:{name:window.name,height:document.body.scrollHeight}},'*',[this.port2])})),window.addEventListener('beforeunload',(()=>{console.log('unload'),this.send({foo:'bar'})})),window.addEventListener('click',(()=>{this.send({cmd:e.EU,updates:[{action:'click',lastUserInteraction:(new Date).valueOf(),context:window.name}]})}),!1),document.readyState){case'loading':case'interactive':document.onreadystatechange=()=>{'complete'===document.readyState&&this.readyResolve()};break;case'complete':this.readyResolve()}}subscribe(e){if(null==e)throw new Error('Parameter can not be null!');this.broadcastChannel.addEventListener('message',e),this.port1.addEventListener('message',e),this.port1.addEventListener('message',(e=>this.broadcastChannel.postMessage(e.data)))}send(e){this.port1.postMessage(e),this.broadcastChannel.postMessage(e)}onConnected(e){return e}}var s=new t;const n={NONE:8,EDIT:16,RESET:32,INIT:64,SYNC:128},i=()=>s,r=[];s.subscribe((({data:t})=>{try{t.cmd===e.SYNC?(t.sync.forEach((e=>{switch(e.action){case n.INIT:r.forEach((({self:t,handler:s})=>{const n=e.data.find((e=>e.propertyName===t.dataset.field));e.currentPath===window.location.pathname&&n&&(t.dataset.placeholder=n.placeholder)}));break;case n.EDIT:case n.RESET:r.forEach((({self:t,handler:s})=>{if(e.currentPath===window.location.pathname&&(e.action===n.RESET||e.data.some((e=>e.name===t.dataset.field)))){const n=e.data.findIndex((e=>e.name===t.dataset.field));n>=0&&s(e.data[n].value,e.context)}}))}})),s.send({cmd:e.EU,updates:[{action:n.SYNC,context:{name:window.name,height:document.body.scrollHeight}}]})):t.cmd===e.EU&&t.action===n.FOCUS&&t.updates.forEach((e=>{r.forEach((({self:t})=>{e.propertyName===t.dataset.field&&e.currentPath===window.location.pathname&&t.scrollIntoView({behavior:'smooth',block:'center'})}))}))}catch(e){console.error(e)}}));const a=(e,t)=>(r.push({self:e,handler:t}),s),o=new CSSStyleSheet;o.replaceSync(':root {\n --str-placeholder-text-opacity: 0.3;\n --str-placeholder-background-color: #0099ff;\n --str-placeholder-background-opacity: 0.8;\n}\nimg.previewing {\n --img-previewing-url: \'\';\n --img-previewing-size: 100%;\n --img-previewing-position: 0px 0px;\n background-image: var(--img-previewing-url);\n background-repeat: no-repeat;\n background-position: var(--img-previewing-position);\n background-size: var(--img-previewing-size);\n}\nimg.previewing.previewing--empty {\n background-image: repeating-linear-gradient(45deg, var(--str-placeholder-background-color) 0, transparent 1px, transparent 0, transparent 50%);\n background-repeat: repeat;\n background-position: 0 0;\n background-size: 15px 15px;\n outline: solid 1px var(--str-placeholder-background-color);\n opacity: var(--str-placeholder-background-opacity);\n}\n\n\n\n:where([is^="str-h"]:empty, [is^="str-textarea"]:empty, [is^="str-address"]:empty, [is^="str-anchor"]:empty, [is^="str-p"]:empty)::before {\n color: inherit;\n\n opacity: var(--str-placeholder-text-opacity);\n\n content: attr(data-placeholder);\n}\n\n::view-transition-old(root),\n::view-transition-new(root) {\n animation-duration: 0.5s;\n}');class d extends HTMLAnchorElement{constructor(){super(),this.tabIndex=0}connectedCallback(){a(this,(e=>this.render(e)))}render(e){if(e){this.href=e.href;const t=this.childNodes;if(0===t.length)this.textContent=e.text;else for(const s of t)s.nodeType===Node.TEXT_NODE&&(s.nodeValue=e.text);'_blank'===e.target&&(this.target=e.target)}}}customElements.define('str-anchor',d,{extends:'a'});const c='https://cdn.strife.app/AS3SX_-B59mU1hdDS7B_YfI5Lu9Ut-kLpdaAhraKgy4/w:1/h:1/aHR0cHM6Ly9zdHJpZmUuYi1jZG4ubmV0L3RyYW5zcGFyZW50MXgxLnBuZw.png',l=e=>e.startsWith('http://')||e.startsWith('https://')?e:'https:'+e;customElements.define('str-picture',class extends HTMLPictureElement{_propertyMedia;_currentSrc;constructor(){super(),this.image=this.querySelector('img'),this.sources=[...this.querySelectorAll('source')],this.tabIndex=0,this.image.complete?this.init():(this.image.addEventListener('load',(e=>{this.init()}),{once:!0}),this.image.addEventListener('error',(e=>{this.init()}),{once:!0})),this._initied=new Promise(((e,t)=>{this.loadedResolve=e,this.loadedReject=t}))}connectedCallback(){}init(){this.initPreview(),a(this,(e=>{this.render(e)}))}initPreview(){this._currentSrc=this.sources.find((e=>{if(this.image.currentSrc){const t=new URL(l(this.image.currentSrc)),s=new URL(l(e.srcset));return t.href===s.href}return window.matchMedia(e.media).matches})),this._currentSrc&&(this._propertyMedia=this._currentSrc.dataset?.propertyMedia,this.offsetWidth,this._currentSrc.width,!this.image.currentSrc&&this._currentSrc.width&&this._currentSrc.height&&this.image.classList.add('previewing--empty'),this.image.classList.add('previewing'),this.image.style.maxWidth='100%',this.image.style.width=this._currentSrc.width+'px',this.image.style.aspectRatio=this._currentSrc.width/this._currentSrc.height,this.image.style.setProperty('--img-previewing-url',`url(${this.image.currentSrc||this._currentSrc.srcset})`),this.image.style.setProperty('--img-previewing-size','100%'),this.image.style.setProperty('--img-previewing-position','0px,0px'),this.image.src=c,this.sources.forEach((e=>{e.srcset=c})),this.image.addEventListener('load',(e=>{this.loadedResolve()}),{once:!0}))}render(e){this._initied.then((()=>{if(this._propertyMedia&&e&&e[this._propertyMedia]&&e[this._propertyMedia].source&&e[this._propertyMedia].source.crop){const t=this.image.offsetWidth/e[this._propertyMedia].width,s=this.image.offsetWidth/2-e[this._propertyMedia].source.originalWidth*(e[this._propertyMedia].source.crop.zoom*t)*e[this._propertyMedia].source.crop.focusX,n=this.image.offsetHeight/2-e[this._propertyMedia].source.originalHeight*(e[this._propertyMedia].source.crop.zoom*t)*e[this._propertyMedia].source.crop.focusY,i=e[this._propertyMedia].source.originalWidth/this.image.offsetWidth*(e[this._propertyMedia].source.crop.zoom*t);this.image.style.setProperty('--img-previewing-url',`url(${e[this._propertyMedia].source.originalPreview})`),this.image.style.setProperty('--img-previewing-size',100*i+'%'),this.image.style.setProperty('--img-previewing-position',`${s}px ${n}px`),e[this._propertyMedia].source.originalPreview?this.image.classList.remove('previewing--empty'):this.image.classList.add('previewing--empty')}}))}disconnectedCallback(){}},{extends:'picture'}),customElements.define('str-img',class extends HTMLImageElement{constructor(){super(),this.tabIndex=0,this.complete?this.init():(this.addEventListener('load',(e=>{this.init()}),{once:!0}),this.addEventListener('error',(e=>{this.init()}),{once:!0})),this._loaded=new Promise(((e,t)=>{this.loadedResolve=e,this.loadedReject=t}))}connectedCallback(){}init(){this.initPreview(),a(this,(e=>{this.render(e)}))}initPreview(){this.classList.add('previewing'),this.src||this.classList.add('previewing--empty'),this.style.width=this.width+'px',this.style.height=this.height+'px',this.style.setProperty('--img-previewing-url',`url(${this.src})`),this.style.setProperty('--img-previewing-size','100%'),this.style.setProperty('--img-previewing-position','0px,0px'),this.src='https://cdn.strife.app/AS3SX_-B59mU1hdDS7B_YfI5Lu9Ut-kLpdaAhraKgy4/w:1/h:1/aHR0cHM6Ly9zdHJpZmUuYi1jZG4ubmV0L3RyYW5zcGFyZW50MXgxLnBuZw.png',this.addEventListener('load',(e=>{this.loadedResolve()}),{once:!0})}render(e){this._loaded.then((()=>{if(e&&e.source&&e.source.crop){const t=this.offsetWidth/e.width,s=this.offsetWidth/2-e.source.originalWidth*(e.source.crop.zoom*t)*e.source.crop.focusX,n=this.offsetHeight/2-e.source.originalHeight*(e.source.crop.zoom*t)*e.source.crop.focusY,i=e.source.originalWidth/this.offsetWidth*(e.source.crop.zoom*t);this.style.setProperty('--img-previewing-url',`url(${e.source.originalPreview})`),this.style.setProperty('--img-previewing-size',100*i+'%'),this.style.setProperty('--img-previewing-position',`${s}px ${n}px`),e.source.originalPreview?this.classList.remove('previewing--empty'):this.classList.add('previewing--empty')}else e&&e.draft?(this.style.setProperty('--img-previewing-url',`url(${e.draft+'?cb='+Date.now()})`),this.style.setProperty('--img-previewing-size','100%'),this.style.setProperty('--img-previewing-position','0px,0px'),this.classList.remove('previewing--empty')):this.classList.add('previewing--empty')}))}disconnectedCallback(){}},{extends:'img'});class h extends HTMLTimeElement{constructor(){super(),this.tabIndex=0}connectedCallback(){a(this,(e=>this.render(e)))}render(e){e&&(this.textContent=((e,t)=>{if(!t)return e;const s=new Date(e);if(isNaN(s))return'Invalid Date';const n=s.getFullYear(),i=String(n).slice(-2),r=String(s.getMonth()+1).padStart(2,'0'),a=new Intl.DateTimeFormat('en-US',{month:'short'}).format(s),o={yyyy:n,yy:i,MMMM:new Intl.DateTimeFormat('en-US',{month:'long'}).format(s),MMM:a,MM:r,dd:String(s.getDate()).padStart(2,'0'),d:String(s.getDate()),hh:String(s.getHours()).padStart(2,'0'),mm:String(s.getMinutes()).padStart(2,'0'),ss:String(s.getSeconds()).padStart(2,'0')},d=new RegExp(Object.keys(o).join('|'),'g');return t.replace(d,(e=>o[e]))})(e,this.dataset.format))}}customElements.define('str-time',h,{extends:'time'});const m=e=>{a(e,(t=>{p(e,t)}))},p=(e,t)=>{e.textContent=t};customElements.define('str-address',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'address'}),customElements.define('str-p',class extends HTMLParagraphElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'p'}),customElements.define('str-span',class extends HTMLSpanElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'span'}),customElements.define('str-strong',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'strong'}),customElements.define('str-h1',class extends HTMLHeadingElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'h1'}),customElements.define('str-h2',class extends HTMLHeadingElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'h2'}),customElements.define('str-h3',class extends HTMLHeadingElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'h3'}),customElements.define('str-h4',class extends HTMLHeadingElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'h4'}),customElements.define('str-h5',class extends HTMLHeadingElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'h5'}),customElements.define('str-h6',class extends HTMLHeadingElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'h6'}),customElements.define('str-abbr',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'abbr'}),customElements.define('str-b',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'b'}),customElements.define('str-button',class extends HTMLButtonElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'button'}),customElements.define('str-cite',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'cite'}),customElements.define('str-code',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'code'}),customElements.define('str-dfn',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'dfn'}),customElements.define('str-em',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'em'}),customElements.define('str-i',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'i'}),customElements.define('str-label',class extends HTMLLabelElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'label'}),customElements.define('str-mark',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'mark'}),customElements.define('str-q',class extends HTMLQuoteElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'q'}),customElements.define('str-sub',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'sub'}),customElements.define('str-sup',class extends HTMLElement{connectedCallback(){m(this)}render(e){p(this,e)}},{extends:'sup'});const u=t=>{a(t,((e,s)=>{g(t,e,s)})),s.send({cmd:e.EU,updates:[{action:n.INIT,context:{propertyName:t.dataset.field}}]})},g=(e,t,s)=>{document.startViewTransition?document.startViewTransition((()=>{f(e,t,s)})):f(e,t,s)},f=(t,i,r)=>{const a=((e,t)=>{t.iterate||t.model;var s=t.templates.find((e=>e.collection===t.model['@metadata']['@collection']));let n=e;e.includes('.')&&(n=e.split('.')[0]);const i=s?.editors.find((e=>e.editor.propertyName===n)),r=i?.editor.type;if(e!==n)switch(r){case'chapters':const[s,r]=e.split('.').slice(1),a=t.model[n][Number(s)],o=t.templates.find((e=>e.normalizedName===a['@strife']?.template))?.editors.find((e=>e.editor.propertyName===r));return o?.editor.type;case'collection':const[d,c]=e.split('.').slice(1),l=t.templates.find((e=>e.collection===t.iterate['@metadata']['@collection']))?.editors.find((e=>e.editor.propertyName===c));return l?.editor.type;case'content-template':const[h]=e.split('.').slice(1),m=t.templates.find((e=>e.normalizedName===i.editor.attributes.templateId))?.editors.find((e=>e.editor.propertyName===h));return m?.editor.type}return r})(t.dataset.field,r);switch(t.innerHTML='',a){case'collection':((e,t,s)=>{t.documents&&t.documents.forEach(((t,n)=>{let i=document.getElementById(`collection_${e.dataset.field}`).content;e.appendChild(i.cloneNode(!0)),e.querySelectorAll(`[is^="str-"]:not([data-field^="${e.dataset.field}."])`).forEach((i=>{const r=i.dataset.field;var a;i.dataset.field=`${e.dataset.field}.${n}.${r}`,i.render((a=t,r?.split('.').reduce(((e,t)=>e?.[t]),a)),{templates:s.templates,model:s.model,iterate:t})}))}))})(t,i,r);break;case'chapters':((e,t,s)=>{t.forEach(((t,n)=>{let i=document.getElementById(t['@strife'].template).content;e.appendChild(i.cloneNode(!0)),e.querySelectorAll(`[is^="str-"]:not([data-field^="${e.dataset.field}."])`).forEach(((i,r)=>{const a=i.dataset.field;i.dataset.field=`${e.dataset.field}.${n}.${a}`,i.render(t[a],s)}))}))})(t,i,r);break;case'html':t.innerHTML=i;break;case'text':t.textContent=i;break;default:t.innerHTML=`<p>Unsupported container type: ${a} for ${t.tagName}</p>`}switch(a){case'collection':case'chapters':setTimeout((()=>{s.send({cmd:e.EU,updates:[{action:n.SYNC,context:{name:window.name,height:document.body.scrollHeight}}]})}),300)}};customElements.define('str-div',class extends HTMLDivElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'div'}),customElements.define('str-ul',class extends HTMLUListElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'ul'}),customElements.define('str-ol',class extends HTMLOListElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'ol'}),customElements.define('str-section',class extends HTMLElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'section'}),customElements.define('str-header',class extends HTMLElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'header'}),customElements.define('str-footer',class extends HTMLElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'footer'}),customElements.define('str-nav',class extends HTMLElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'nav'}),customElements.define('str-article',class extends HTMLElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'article'}),customElements.define('str-main',class extends HTMLElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'main'}),customElements.define('str-aside',class extends HTMLElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'aside'}),customElements.define('str-blockquote',class extends HTMLElement{connectedCallback(){u(this)}render(e,t){g(this,e,t)}},{extends:'blockquote'}),document.adoptedStyleSheets=[o];export{n as ACTION,e as CMD,i as default,a as useState};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strifeapp/strife",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1-alpha",
|
|
4
|
+
"description": "The Strife SDK for JavaScript.",
|
|
4
5
|
"keywords": [],
|
|
5
6
|
"files": [
|
|
6
7
|
"dist"
|
|
@@ -9,8 +10,7 @@
|
|
|
9
10
|
"module": "dist/index.esm.js",
|
|
10
11
|
"unpkg": "dist/index.esm.js",
|
|
11
12
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"postversion": "npx rollup -c -i index.js -o dist/index.esm.js"
|
|
13
|
+
"build": "npx rollup -c -i index.js -o dist/index.esm.js"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"rollup": "^2.64.0",
|