@cher-ami/compose
Advanced tools
Comparing version 0.15.2 to 0.15.3
@@ -1,2 +0,2 @@ | ||
import e from"@cher-ami/debug";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},t.apply(this,arguments)}const n=[],i=e("compose:Component"),r="data-component",s="data-component-id";class a{get isMounted(){return this._isMounted}constructor(e,t,i){this.name=void 0,this.$root=void 0,this.props=void 0,this.id=void 0,this._isMounted=!1,this.observer=void 0,this._beforeMount(),this.props=t,this.$root=e,this.name=i||a.getComponentName(this.$root),this.id=(()=>{let e;do{e=1e6*Math.random()|0}while(n.includes(e));return n.push(e),e})(),this.$root.setAttribute(s,`${this.id}`),window.setTimeout(()=>this.init(),0)}init(){this._mounted(),this._watchChildren()}beforeMount(){}_beforeMount(){this.beforeMount()}mounted(){}_mounted(){i("🟢 mounted",this.name),this.mounted(),this._isMounted=!0}unmounted(){}_unmounted(){this.unmounted(),this._isMounted=!1,this.onChildrenComponents(e=>{null==e||e._unmounted()}),i("🔴 unmounted",this.name)}add(e,n,i){var r;const s=i||(null==e?void 0:e.attrName),o=null==(r=a.getDomElement(this.$root,s))?void 0:r[0];if(o)return new e(o,t({},n,{key:0,parentId:this.id}),s)}addAll(e,n,i){const r=[],s=i||(null==e?void 0:e.attrName),o=a.getDomElement(this.$root,s);if(!o.length)return r;for(let i=0;i<o.length;i++){const a=new e(o[i],t({},n,{key:i,parentId:this.id}),s);r.push(a)}return r}find(e,t=(e=>null==(e=this.$root)||null==(e=e.classList)?void 0:e[0])()){if(t&&e&&this.$root)return this.$root.querySelector(`.${t}_${e}`)||void 0}findAll(e,t=(e=>null==(e=this.$root)||null==(e=e.classList)?void 0:e[0])()){if(!t||!e||!this.$root)return;const n=this.$root.querySelectorAll(`.${t}_${e}`);return Array.from(n||[])}_playInRef(e,t){return new Promise((n,i)=>{t.reject=()=>i(),this.playIn(e,n)})}playIn(e,t){t()}_playOutRef(e,t){return new Promise((n,i)=>{t.reject=()=>{i(),this._unmounted()},this.playOut(e,n)})}playOut(e,t){t()}static getDomElement(e,t){return Array.from((null==e?void 0:e.querySelectorAll(`*[${r}=${t}]`))||[])}onChildrenComponents(e){var t;null==(t=Object.keys(this))||t.forEach(t=>{const n=null==this?void 0:this[t];Array.isArray(n)?n.forEach(t=>{t instanceof a&&e(t)}):n instanceof a&&e(n)})}static getComponentName(e){return null==e||null==e.getAttribute?void 0:e.getAttribute(r)}static getComponentId(e){return(null==e||null==e.getAttribute?void 0:e.getAttribute(s))&&parseInt(e.getAttribute(s))}_watchChildren(){this.observer=new MutationObserver(e=>{for(const n of e)for(const e of n.removedNodes){var t;const n=a.getComponentId(e),i=null==(t=e.parentNode)?void 0:t.querySelector(`*[${s}='${n}']`);n&&i||this.onChildrenComponents(e=>{e&&n===(null==e?void 0:e.id)&&null!=e&&e.isMounted&&(e._unmounted(),e.observer.disconnect())})}}),this.$root&&this.observer.observe(this.$root,{subtree:!0,childList:!0})}}const o=e("compose:Stack"),h=new DOMParser,l="data-page-transition-url";class u extends a{addPages(){return{}}get pages(){return this._pages}constructor({$root:e,props:t,history:n}){var i;super(e,t),i=this,this.forcePageReloadIfDocumentIsFetching=!1,this.forcePageReload=!1,this.disableLinksDuringTransitions=!1,this.disableHistoryDuringTransitions=!1,this.keepPageNumberDuringTransitions=1,this.enableCache=!0,this._pages=void 0,this.$clickedLink=void 0,this.currentUrl=null,this.currentPage=void 0,this.prevPage=void 0,this.isFirstPage=!0,this.$pageContainer=void 0,this.$pageWrapper=void 0,this.playInPromiseRef={reject:void 0},this.playOutPromiseRef={reject:void 0},this._pageIsAnimating=!1,this._fetching=!1,this._cache=void 0,this.history=void 0,this.removeHistory=void 0,this.handleLinks=e=>{var t;if(!e)return;this.$clickedLink=e.currentTarget;const n=null==e||null==(t=e.currentTarget)?void 0:t.getAttribute(l);this.forcePageReload&&window.open(n,"_self"),e.preventDefault(),this.disableLinksDuringTransitions&&this._pageIsAnimating||this.history.push(n)},this.handleHistory=async function(e){if(i.disableHistoryDuringTransitions&&i._pageIsAnimating)return;const t=e;if(o("handleHistory > requestUrl",t),t&&t!==i.currentUrl){if(i.forcePageReloadIfDocumentIsFetching&&i._fetching||i.forcePageReload)return o("handleHistory > security, force page reload..."),void window.open(t,"_self");if(i.currentUrl=t,i._pageIsAnimating){o(`\n handleHistory > New request while page is animating.\n For security: \n - Reject PlayOut & PlayIn anim promises;\n - Keep ${i.keepPageNumberDuringTransitions} page(s) inside the wrapper div.\n `),null==i.playOutPromiseRef.reject||i.playOutPromiseRef.reject(),null==i.playInPromiseRef.reject||i.playInPromiseRef.reject(),i._pageIsAnimating=!1;const e=i.$pageWrapper.querySelectorAll(":scope > *");if(o("$pageWrapper content before remove",e),e.length>i.keepPageNumberDuringTransitions){for(let t=0;t<e.length-i.keepPageNumberDuringTransitions;t+=1)e[t].remove();o("$pageWrapper after remove",i.$pageWrapper.querySelectorAll(":scope > *"))}await new Promise(e=>setTimeout(e,1))}try{const e=await i.pageTransitionsMiddleware({currentPage:i.prepareCurrentPage(),mountNewPage:()=>i.prepareMountNewPage(t)});i.isFirstPage=!1,i.prevPage=i.currentPage,i.currentPage=e,i.updateLinks()}catch(e){throw new Error("Error on page transition middleware")}}},this.parseDOM=e=>"string"==typeof e?h.parseFromString(e,"text/html"):e,this.history=n,this.$pageContainer=this.getPageContainer(),this.$pageWrapper=this.getPageWrapper(this.$pageContainer),this._pages=this.addPages(),this.currentPage=this.getFirstCurrentPage(),this._cache={},this.start()}start(){this.handleHistory(window.location.pathname||"/"),this.initHistoryEvent(),this.listenLinks()}updateLinks(){this.unlistenLinks(),this.listenLinks()}stop(){this.removeHistoryEvent(),this.unlistenLinks()}listenLinks(){const e=this.getLinksWithAttr();null==e||e.forEach(e=>{null==e||e.addEventListener("click",this.handleLinks)})}unlistenLinks(){const e=this.getLinksWithAttr();null==e||e.forEach(e=>{null==e||e.removeEventListener("click",this.handleLinks)})}initHistoryEvent(){var e;this.removeHistory=null==(e=this.history)?void 0:e.listen(({location:e})=>{this.handleHistory(e.pathname)})}removeHistoryEvent(){this.removeHistory()}prepareCurrentPage(){const e=this.currentPage,n=()=>{e.$pageRoot.remove()};return this.isFirstPage?null:t({},e,{playOut:(t,i=!0)=>e.instance._playOutRef.bind(e.instance)(t,this.playOutPromiseRef).then(()=>{e.instance._unmounted(),i&&n()}).catch(()=>{}),remove:n})}async prepareMountNewPage(e){var t;const{$pageRoot:n,pageName:i,instance:r}=this.currentPage,s=e=>{var t;return null==(t=e._playInRef.bind(e)(i,this.playInPromiseRef).then(()=>{this._pageIsAnimating=!1}))||null==t.catch?void 0:t.catch(()=>{})};if(this.isFirstPage)return this.addInCache(e,document.title,n,i,r,()=>s(r)),{$pageRoot:n,pageName:i,instance:r,playIn:()=>s(r)};const a=null==(t=this._cache)?void 0:t[e];if(a){o("Use cache",a);const{title:e,$pageRoot:t,pageName:n}=a,i=this.createPageInstance(n,t);return o("Create new page instance from cache information",i),this.addPageInDOM(t),this.updateMetas(e),{$pageRoot:t,pageName:n,instance:i,playIn:()=>s(i)}}try{const t=await this.fetchNewDocument(e,new AbortController),n=this.getPageWrapper(t.body),i=this.getPageRoot(n),r=this.getPageName(i),a=this.createPageInstance(r,i);return this.addPageInDOM(i),this.updateMetas(t.title),this.addInCache(e,t.title,i,r,a,()=>s(a)),{$pageRoot:i,pageName:r,instance:a,playIn:()=>s(a)}}catch(t){throw new Error(`Fetch new document failed on url: ${e}`)}}pageTransitionsMiddleware({currentPage:e,mountNewPage:n}){var i=this;return new Promise(async function(r){try{await i.beforeFetch();const s=await n(),a=t({},e,{playOut:(t,n=!0)=>null==e?void 0:e.playOut(s.pageName,n)}),o=()=>{r(s)};return i._pageIsAnimating=!0,await new Promise(e=>setTimeout(e,0)),i.pageTransitions(a,s,o)}catch(e){console.error("mountNewPage failed",e)}})}async pageTransitions(e,t,n){await e.playOut(),await t.playIn(),n()}beforeFetch(){return Promise.resolve()}getPageContainer(e=document.body){return e.querySelector("*[data-page-transition-container]")}getPageWrapper(e){return e.querySelector("*[data-page-transition-wrapper]")}getPageRoot(e){return e.children[0]}getPageName(e){for(const t of Object.keys(this._pages))if(t==e.getAttribute(r))return t}createPageInstance(e,t){o("getPageInstance > pageName:",e);const n=this._pages[e];return n?new n(t,{},e):null}getFirstCurrentPage(){const e=this.getPageRoot(this.$pageWrapper),t=this.getPageName(e),n=this.createPageInstance(t,e);return{$pageRoot:e,pageName:t,instance:n,playIn:()=>n._playInRef(),playOut:()=>n._playOutRef()}}addPageInDOM(e){this.$pageWrapper.appendChild(e)}updateMetas(e){void 0!==typeof document&&(document.title=e)}addInCache(e,n,i,r,s,a){this.enableCache?this._cache=t({},this._cache,{[e]:{title:n,$pageRoot:i,pageName:r,instance:s,playIn:a}}):o("cache is disable, return")}getLinksWithAttr(){var e;return Array.from(null==(e=this.$pageContainer)?void 0:e.querySelectorAll(`*[${l}]`))}async fetchNewDocument(e,t){this._fetching&&(t.abort(),o("this._fetching = true, abort"),this._fetching=!1),this._fetching=!0;const n=await fetch(e,{signal:t.signal,mode:"same-origin",method:"GET",credentials:"same-origin"});if(n.status>=200&&n.status<300){const e=await n.text();return this._fetching=!1,this.parseDOM(e)}throw this._fetching=!1,new Error("Something went wrong")}}export{a as Component,u as Stack}; | ||
import t from"@cher-ami/debug";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},e.apply(this,arguments)}const n=[],i=t("compose:Component"),r="data-component",a="data-component-id";class s{get isMounted(){return this._isMounted}constructor(t,e,i){this.name=void 0,this.$root=void 0,this.props=void 0,this.id=void 0,this._isMounted=!1,this.observer=void 0,this._beforeMount(),this.props=e,this.$root=t,this.name=i||s.getComponentName(this.$root),this.id=(()=>{let t;do{t=1e6*Math.random()|0}while(n.includes(t));return n.push(t),t})(),this.$root.setAttribute(a,`${this.id}`),window.setTimeout(()=>this.init(),0)}init(){this._mounted(),this._watchChildren()}beforeMount(){}_beforeMount(){this.beforeMount()}mounted(){}_mounted(){i("🟢 mounted",this.name),this.mounted(),this._isMounted=!0}unmounted(){}_unmounted(){this.unmounted(),this._isMounted=!1,this.onChildrenComponents(t=>{null==t||t._unmounted()}),i("🔴 unmounted",this.name)}add(t,n,i){var r;const a=i||(null==t?void 0:t.attrName),o=null==(r=s.getDomElement(this.$root,a))?void 0:r[0];if(o)return new t(o,e({},n,{key:0,parentId:this.id}),a)}addAll(t,n,i){const r=[],a=i||(null==t?void 0:t.attrName),o=s.getDomElement(this.$root,a);if(!o.length)return r;for(let i=0;i<o.length;i++){const s=new t(o[i],e({},n,{key:i,parentId:this.id}),a);r.push(s)}return r}find(t,e=(t=>null==(t=this.$root)||null==(t=t.classList)?void 0:t[0])()){if(e&&t&&this.$root)return this.$root.querySelector(`.${e}_${t}`)||void 0}findAll(t,e=(t=>null==(t=this.$root)||null==(t=t.classList)?void 0:t[0])()){if(!e||!t||!this.$root)return;const n=this.$root.querySelectorAll(`.${e}_${t}`);return Array.from(n||[])}_playInRef(t,e){return new Promise((n,i)=>{e.reject=()=>i(),this.playIn(t,n)})}playIn(t,e){e()}_playOutRef(t,e){return new Promise((n,i)=>{e.reject=()=>{i(),this._unmounted()},this.playOut(t,n)})}playOut(t,e){e()}static getDomElement(t,e){return Array.from((null==t?void 0:t.querySelectorAll(`*[${r}=${e}]`))||[])}onChildrenComponents(t){var e;null==(e=Object.keys(this))||e.forEach(e=>{const n=null==this?void 0:this[e];Array.isArray(n)?n.forEach(e=>{e instanceof s&&t(e)}):n instanceof s&&t(n)})}static getComponentName(t){return null==t||null==t.getAttribute?void 0:t.getAttribute(r)}static getComponentId(t){return(null==t||null==t.getAttribute?void 0:t.getAttribute(a))&&parseInt(t.getAttribute(a))}_watchChildren(){this.observer=new MutationObserver(t=>{for(const n of t)for(const t of n.removedNodes){var e;const n=s.getComponentId(t),i=null==(e=t.parentNode)?void 0:e.querySelector(`*[${a}='${n}']`);n&&i||this.onChildrenComponents(t=>{t&&n===(null==t?void 0:t.id)&&null!=t&&t.isMounted&&(t._unmounted(),t.observer.disconnect())})}}),this.$root&&this.observer.observe(this.$root,{subtree:!0,childList:!0})}}const o=(t,e)=>{if(t===e)return!0;if(null==t||"object"!=typeof t||null==e||"object"!=typeof e)return!1;let n=Object.keys(t),i=Object.keys(e);if(n.length!==i.length)return!1;for(let r of n)if(!i.includes(r)||!o(t[r],e[r]))return!1;return!0},h=t("compose:Stack"),l=new DOMParser,c="data-page-transition-url";class u extends s{addPages(){return{}}get pages(){return this._pages}constructor({$root:t,props:e,history:n}){var i;super(t,e),i=this,this.forcePageReloadIfDocumentIsFetching=!1,this.forcePageReload=!1,this.disableLinksDuringTransitions=!1,this.disableHistoryDuringTransitions=!1,this.keepPageNumberDuringTransitions=1,this.enableCache=!0,this.locationHistory=[],this._pages=void 0,this.$clickedLink=void 0,this.currentUrl=null,this.currentLocation=null,this.currentPage=void 0,this.prevPage=void 0,this.isFirstPage=!0,this.$pageContainer=void 0,this.$pageWrapper=void 0,this.playInPromiseRef={reject:void 0},this.playOutPromiseRef={reject:void 0},this._pageIsAnimating=!1,this._fetching=!1,this._cache=void 0,this.history=void 0,this.removeHistory=void 0,this.handleLinks=t=>{var e,n;if(!t)return;this.$clickedLink=t.currentTarget;const i=null==t||null==(e=t.currentTarget)?void 0:e.getAttribute(c),r=null==t||null==(n=t.currentTarget)?void 0:n.getAttribute("data-page-transition-partial");this.forcePageReload&&window.open(i,"_self"),t.preventDefault(),this.disableLinksDuringTransitions&&this._pageIsAnimating||this.history.push(i,{partial:"true"===r})},this.handleHistory=async function(t,e){var n;if(i.disableHistoryDuringTransitions&&i._pageIsAnimating)return;const r="POP"===e,a=i.locationHistory[i.locationHistory.length-1],s=t.pathname,l=null==(n=t.state)?void 0:n.partial,c={path:t.pathname,search:t.search};let u={path:t.pathname,search:t.search};if(l&&(u.partial=!0),h("handleHistory > location value & current location",c,i.currentLocation),!s||o(c,i.currentLocation)||l&&!r||r&&a.partial&&c.path===a.path)return i.currentLocation=u,void i.locationHistory.push(i.currentLocation);if(i.forcePageReloadIfDocumentIsFetching&&i._fetching||i.forcePageReload)return h("handleHistory > security, force page reload..."),void window.open(s,"_self");if(i.currentUrl=s,i._pageIsAnimating){h(`\n handleHistory > New request while page is animating.\n For security: \n - Reject PlayOut & PlayIn anim promises;\n - Keep ${i.keepPageNumberDuringTransitions} page(s) inside the wrapper div.\n `),null==i.playOutPromiseRef.reject||i.playOutPromiseRef.reject(),null==i.playInPromiseRef.reject||i.playInPromiseRef.reject(),i._pageIsAnimating=!1;const t=i.$pageWrapper.querySelectorAll(":scope > *");if(h("$pageWrapper content before remove",t),t.length>i.keepPageNumberDuringTransitions){for(let e=0;e<t.length-i.keepPageNumberDuringTransitions;e+=1)t[e].remove();h("$pageWrapper after remove",i.$pageWrapper.querySelectorAll(":scope > *"))}await new Promise(t=>setTimeout(t,1))}try{const t=await i.pageTransitionsMiddleware({currentPage:i.prepareCurrentPage(),mountNewPage:()=>i.prepareMountNewPage(s,c)});i.isFirstPage=!1,i.prevPage=i.currentPage,i.currentPage=t,i.updateLinks()}catch(t){throw new Error("Error on page transition middleware")}i.currentLocation=u,i.locationHistory.push(i.currentLocation)},this.parseDOM=t=>"string"==typeof t?l.parseFromString(t,"text/html"):t,this.history=n,this.$pageContainer=this.getPageContainer(),this.$pageWrapper=this.getPageWrapper(this.$pageContainer),this._pages=this.addPages(),this.currentPage=this.getFirstCurrentPage(),this._cache={},this.start()}start(){this.handleHistory(window.location||"/"),this.initHistoryEvent(),this.listenLinks()}updateLinks(){this.unlistenLinks(),this.listenLinks()}stop(){this.removeHistoryEvent(),this.unlistenLinks()}listenLinks(){const t=this.getLinksWithAttr();null==t||t.forEach(t=>{null==t||t.addEventListener("click",this.handleLinks)})}unlistenLinks(){const t=this.getLinksWithAttr();null==t||t.forEach(t=>{null==t||t.removeEventListener("click",this.handleLinks)})}initHistoryEvent(){var t;this.removeHistory=null==(t=this.history)?void 0:t.listen(t=>{const{location:e,action:n}=t;h("history.listen",t),this.handleHistory(e,n)})}removeHistoryEvent(){this.removeHistory()}prepareCurrentPage(){const t=this.currentPage,n=()=>{t.$pageRoot.remove()};return this.isFirstPage?null:e({},t,{playOut:(e,i=!0)=>t.instance._playOutRef.bind(t.instance)(e,this.playOutPromiseRef).then(()=>{t.instance._unmounted(),i&&n()}).catch(()=>{}),remove:n})}async prepareMountNewPage(t,e){var n;const{$pageRoot:i,pageName:r,instance:a}=this.currentPage,s=t=>{var e;return null==(e=t._playInRef.bind(t)(r,this.playInPromiseRef).then(()=>{this._pageIsAnimating=!1}))||null==e.catch?void 0:e.catch(()=>{})};if(this.isFirstPage)return this.addInCache(t,document.title,i,r,a,()=>s(a)),{$pageRoot:i,pageName:r,instance:a,playIn:()=>s(a)};const l=null==(n=this._cache)?void 0:n[t];if(l&&o(e,this.currentLocation)){h("Use cache",l);const{title:t,$pageRoot:e,pageName:n}=l,i=this.createPageInstance(n,e);return h("Create new page instance from cache information",i),this.addPageInDOM(e),this.updateMetas(t),{$pageRoot:e,pageName:n,instance:i,playIn:()=>s(i)}}try{const e=await this.fetchNewDocument(t,new AbortController),n=this.getPageWrapper(e.body),i=this.getPageRoot(n),r=this.getPageName(i),a=this.createPageInstance(r,i);return this.addPageInDOM(i),this.updateMetas(e.title),this.addInCache(t,e.title,i,r,a,()=>s(a)),{$pageRoot:i,pageName:r,instance:a,playIn:()=>s(a)}}catch(e){throw new Error(`Fetch new document failed on url: ${t}`)}}pageTransitionsMiddleware({currentPage:t,mountNewPage:n}){var i=this;return new Promise(async function(r){try{await i.beforeFetch();const a=await n(),s=e({},t,{playOut:(e,n=!0)=>null==t?void 0:t.playOut(a.pageName,n)}),o=()=>{r(a)};return i._pageIsAnimating=!0,await new Promise(t=>setTimeout(t,0)),i.pageTransitions(s,a,o)}catch(t){console.error("mountNewPage failed",t)}})}async pageTransitions(t,e,n){await t.playOut(),await e.playIn(),n()}beforeFetch(){return Promise.resolve()}getPageContainer(t=document.body){return t.querySelector("*[data-page-transition-container]")}getPageWrapper(t){return t.querySelector("*[data-page-transition-wrapper]")}getPageRoot(t){return t.children[0]}getPageName(t){for(const e of Object.keys(this._pages))if(e==t.getAttribute(r))return e}createPageInstance(t,e){h("getPageInstance > pageName:",t);const n=this._pages[t];return n?new n(e,{},t):null}getFirstCurrentPage(){const t=this.getPageRoot(this.$pageWrapper),e=this.getPageName(t),n=this.createPageInstance(e,t);return{$pageRoot:t,pageName:e,instance:n,playIn:()=>n._playInRef(),playOut:()=>n._playOutRef()}}addPageInDOM(t){this.$pageWrapper.appendChild(t)}updateMetas(t){void 0!==typeof document&&(document.title=t)}addInCache(t,n,i,r,a,s){this.enableCache?this._cache=e({},this._cache,{[t]:{title:n,$pageRoot:i,pageName:r,instance:a,playIn:s}}):h("cache is disable, return")}getLinksWithAttr(){var t;return Array.from(null==(t=this.$pageContainer)?void 0:t.querySelectorAll(`*[${c}]`))}async fetchNewDocument(t,e){this._fetching&&(e.abort(),h("this._fetching = true, abort"),this._fetching=!1),this._fetching=!0;const n=await fetch(t,{signal:e.signal,mode:"same-origin",method:"GET",credentials:"same-origin"});if(n.status>=200&&n.status<300){const t=await n.text();return this._fetching=!1,this.parseDOM(t)}throw this._fetching=!1,new Error("Something went wrong")}}export{s as Component,u as Stack}; | ||
//# sourceMappingURL=index.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import e from"@cher-ami/debug";function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key))?i:String(i),r)}var i}function n(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},r.apply(this,arguments)}function i(e,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},i(e,t)}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=[],s=e("compose:Component"),c="data-component",l="data-component-id",f=/*#__PURE__*/function(){function e(t,n,r){var i=this;this.name=void 0,this.$root=void 0,this.props=void 0,this.id=void 0,this._isMounted=!1,this.observer=void 0,this._beforeMount(),this.props=n,this.$root=t,this.name=r||e.getComponentName(this.$root),this.id=function(){var e;do{e=1e6*Math.random()|0}while(u.includes(e));return u.push(e),e}(),this.$root.setAttribute(l,""+this.id),window.setTimeout(function(){return i.init()},0)}var t=e.prototype;return t.init=function(){this._mounted(),this._watchChildren()},t.beforeMount=function(){},t._beforeMount=function(){this.beforeMount()},t.mounted=function(){},t._mounted=function(){s("🟢 mounted",this.name),this.mounted(),this._isMounted=!0},t.unmounted=function(){},t._unmounted=function(){this.unmounted(),this._isMounted=!1,this.onChildrenComponents(function(e){null==e||e._unmounted()}),s("🔴 unmounted",this.name)},t.add=function(t,n,i){var o,a=i||(null==t?void 0:t.attrName),u=null==(o=e.getDomElement(this.$root,a))?void 0:o[0];if(u)return new t(u,r({},n,{key:0,parentId:this.id}),a)},t.addAll=function(t,n,i){var o=[],a=i||(null==t?void 0:t.attrName),u=e.getDomElement(this.$root,a);if(!u.length)return o;for(var s=0;s<u.length;s++){var c=new t(u[s],r({},n,{key:s,parentId:this.id}),a);o.push(c)}return o},t.find=function(e,t){var n;if(void 0===t&&(t=null==(n=this.$root)||null==(n=n.classList)?void 0:n[0]),t&&e&&this.$root)return this.$root.querySelector("."+t+"_"+e)||void 0},t.findAll=function(e,t){var n;if(void 0===t&&(t=null==(n=this.$root)||null==(n=n.classList)?void 0:n[0]),t&&e&&this.$root){var r=this.$root.querySelectorAll("."+t+"_"+e);return Array.from(r||[])}},t._playInRef=function(e,t){var n=this;return new Promise(function(r,i){t.reject=function(){return i()},n.playIn(e,r)})},t.playIn=function(e,t){t()},t._playOutRef=function(e,t){var n=this;return new Promise(function(r,i){t.reject=function(){i(),n._unmounted()},n.playOut(e,r)})},t.playOut=function(e,t){t()},e.getDomElement=function(e,t){return Array.from((null==e?void 0:e.querySelectorAll("*["+c+"="+t+"]"))||[])},t.onChildrenComponents=function(t){var n,r=this;null==(n=Object.keys(this))||n.forEach(function(n){var i=null==r?void 0:r[n];Array.isArray(i)?i.forEach(function(n){n instanceof e&&t(n)}):i instanceof e&&t(i)})},e.getComponentName=function(e){return null==e||null==e.getAttribute?void 0:e.getAttribute(c)},e.getComponentId=function(e){return(null==e||null==e.getAttribute?void 0:e.getAttribute(l))&&parseInt(e.getAttribute(l))},t._watchChildren=function(){var t=this;this.observer=new MutationObserver(function(n){for(var r,i=a(n);!(r=i()).done;)for(var o,u=function(){var n,r=o.value,i=e.getComponentId(r),a=null==(n=r.parentNode)?void 0:n.querySelector("*["+l+"='"+i+"']");if(i&&a)return 1;t.onChildrenComponents(function(e){e&&i===(null==e?void 0:e.id)&&null!=e&&e.isMounted&&(e._unmounted(),e.observer.disconnect())})},s=a(r.value.removedNodes);!(o=s()).done;)u()}),this.$root&&this.observer.observe(this.$root,{subtree:!0,childList:!0})},n(e,[{key:"isMounted",get:function(){return this._isMounted}}]),e}();function p(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var h=e("compose:Stack"),g=new DOMParser,d="data-page-transition-url",m=/*#__PURE__*/function(e){var t,o;o=e,(t=u).prototype=Object.create(o.prototype),t.prototype.constructor=t,i(t,o);var a=u.prototype;function u(t){var n,r=t.history;return(n=e.call(this,t.$root,t.props)||this).forcePageReloadIfDocumentIsFetching=!1,n.forcePageReload=!1,n.disableLinksDuringTransitions=!1,n.disableHistoryDuringTransitions=!1,n.keepPageNumberDuringTransitions=1,n.enableCache=!0,n._pages=void 0,n.$clickedLink=void 0,n.currentUrl=null,n.currentPage=void 0,n.prevPage=void 0,n.isFirstPage=!0,n.$pageContainer=void 0,n.$pageWrapper=void 0,n.playInPromiseRef={reject:void 0},n.playOutPromiseRef={reject:void 0},n._pageIsAnimating=!1,n._fetching=!1,n._cache=void 0,n.history=void 0,n.removeHistory=void 0,n.handleLinks=function(e){var t;if(e){n.$clickedLink=e.currentTarget;var r=null==e||null==(t=e.currentTarget)?void 0:t.getAttribute(d);n.forcePageReload&&window.open(r,"_self"),e.preventDefault(),n.disableLinksDuringTransitions&&n._pageIsAnimating||n.history.push(r)}},n.handleHistory=function(e){try{var t=function(){return p(function(){return Promise.resolve(n.pageTransitionsMiddleware({currentPage:n.prepareCurrentPage(),mountNewPage:function(){return n.prepareMountNewPage(r)}})).then(function(e){n.isFirstPage=!1,n.prevPage=n.currentPage,n.currentPage=e,n.updateLinks()})},function(){throw new Error("Error on page transition middleware")})};if(n.disableHistoryDuringTransitions&&n._pageIsAnimating)return Promise.resolve();var r=e;if(h("handleHistory > requestUrl",r),!r||r===n.currentUrl)return Promise.resolve();if(n.forcePageReloadIfDocumentIsFetching&&n._fetching||n.forcePageReload)return h("handleHistory > security, force page reload..."),window.open(r,"_self"),Promise.resolve();n.currentUrl=r;var i=function(){if(n._pageIsAnimating){h("\n handleHistory > New request while page is animating.\n For security: \n - Reject PlayOut & PlayIn anim promises;\n - Keep "+n.keepPageNumberDuringTransitions+" page(s) inside the wrapper div.\n "),null==n.playOutPromiseRef.reject||n.playOutPromiseRef.reject(),null==n.playInPromiseRef.reject||n.playInPromiseRef.reject(),n._pageIsAnimating=!1;var e=n.$pageWrapper.querySelectorAll(":scope > *");if(h("$pageWrapper content before remove",e),e.length>n.keepPageNumberDuringTransitions){for(var t=0;t<e.length-n.keepPageNumberDuringTransitions;t+=1)e[t].remove();h("$pageWrapper after remove",n.$pageWrapper.querySelectorAll(":scope > *"))}return Promise.resolve(new Promise(function(e){return setTimeout(e,1)})).then(function(){})}}();return Promise.resolve(i&&i.then?i.then(t):t())}catch(e){return Promise.reject(e)}},n.parseDOM=function(e){return"string"==typeof e?g.parseFromString(e,"text/html"):e},n.history=r,n.$pageContainer=n.getPageContainer(),n.$pageWrapper=n.getPageWrapper(n.$pageContainer),n._pages=n.addPages(),n.currentPage=n.getFirstCurrentPage(),n._cache={},n.start(),n}return a.addPages=function(){return{}},a.start=function(){this.handleHistory(window.location.pathname||"/"),this.initHistoryEvent(),this.listenLinks()},a.updateLinks=function(){this.unlistenLinks(),this.listenLinks()},a.stop=function(){this.removeHistoryEvent(),this.unlistenLinks()},a.listenLinks=function(){var e=this,t=this.getLinksWithAttr();null==t||t.forEach(function(t){null==t||t.addEventListener("click",e.handleLinks)})},a.unlistenLinks=function(){var e=this,t=this.getLinksWithAttr();null==t||t.forEach(function(t){null==t||t.removeEventListener("click",e.handleLinks)})},a.initHistoryEvent=function(){var e,t=this;this.removeHistory=null==(e=this.history)?void 0:e.listen(function(e){t.handleHistory(e.location.pathname)})},a.removeHistoryEvent=function(){this.removeHistory()},a.prepareCurrentPage=function(){var e=this,t=this.currentPage,n=function(){t.$pageRoot.remove()};return this.isFirstPage?null:r({},t,{playOut:function(r,i){return void 0===i&&(i=!0),t.instance._playOutRef.bind(t.instance)(r,e.playOutPromiseRef).then(function(){t.instance._unmounted(),i&&n()}).catch(function(){})},remove:n})},a.prepareMountNewPage=function(e){try{var t,n=this,r=n.currentPage,i=r.$pageRoot,o=r.pageName,a=r.instance,u=function(e){var t;return null==(t=e._playInRef.bind(e)(o,n.playInPromiseRef).then(function(){n._pageIsAnimating=!1}))||null==t.catch?void 0:t.catch(function(){})};if(n.isFirstPage)return n.addInCache(e,document.title,i,o,a,function(){return u(a)}),Promise.resolve({$pageRoot:i,pageName:o,instance:a,playIn:function(){return u(a)}});var s=null==(t=n._cache)?void 0:t[e];if(s){h("Use cache",s);var c=s.title,l=s.$pageRoot,f=s.pageName,g=n.createPageInstance(f,l);return h("Create new page instance from cache information",g),n.addPageInDOM(l),n.updateMetas(c),Promise.resolve({$pageRoot:l,pageName:f,instance:g,playIn:function(){return u(g)}})}return Promise.resolve(p(function(){return Promise.resolve(n.fetchNewDocument(e,new AbortController)).then(function(t){var r=n.getPageWrapper(t.body),i=n.getPageRoot(r),o=n.getPageName(i),a=n.createPageInstance(o,i);return n.addPageInDOM(i),n.updateMetas(t.title),n.addInCache(e,t.title,i,o,a,function(){return u(a)}),{$pageRoot:i,pageName:o,instance:a,playIn:function(){return u(a)}}})},function(){throw new Error("Fetch new document failed on url: "+e)}))}catch(e){return Promise.reject(e)}},a.pageTransitionsMiddleware=function(e){var t=this,n=e.currentPage,i=e.mountNewPage;return new Promise(function(e){try{return Promise.resolve(p(function(){return Promise.resolve(t.beforeFetch()).then(function(){return Promise.resolve(i()).then(function(i){var o=r({},n,{playOut:function(e,t){return void 0===t&&(t=!0),null==n?void 0:n.playOut(i.pageName,t)}}),a=function(){e(i)};return t._pageIsAnimating=!0,Promise.resolve(new Promise(function(e){return setTimeout(e,0)})).then(function(){return t.pageTransitions(o,i,a)})})})},function(e){console.error("mountNewPage failed",e)}))}catch(e){return Promise.reject(e)}})},a.pageTransitions=function(e,t,n){try{return Promise.resolve(e.playOut()).then(function(){return Promise.resolve(t.playIn()).then(function(){n()})})}catch(e){return Promise.reject(e)}},a.beforeFetch=function(){return Promise.resolve()},a.getPageContainer=function(e){return void 0===e&&(e=document.body),e.querySelector("*[data-page-transition-container]")},a.getPageWrapper=function(e){return e.querySelector("*[data-page-transition-wrapper]")},a.getPageRoot=function(e){return e.children[0]},a.getPageName=function(e){for(var t=0,n=Object.keys(this._pages);t<n.length;t++){var r=n[t];if(r==e.getAttribute(c))return r}},a.createPageInstance=function(e,t){h("getPageInstance > pageName:",e);var n=this._pages[e];return n?new n(t,{},e):null},a.getFirstCurrentPage=function(){var e=this.getPageRoot(this.$pageWrapper),t=this.getPageName(e),n=this.createPageInstance(t,e);return{$pageRoot:e,pageName:t,instance:n,playIn:function(){return n._playInRef()},playOut:function(){return n._playOutRef()}}},a.addPageInDOM=function(e){this.$pageWrapper.appendChild(e)},a.updateMetas=function(e){void 0!==typeof document&&(document.title=e)},a.addInCache=function(e,t,n,i,o,a){var u;this.enableCache?this._cache=r({},this._cache,((u={})[e]={title:t,$pageRoot:n,pageName:i,instance:o,playIn:a},u)):h("cache is disable, return")},a.getLinksWithAttr=function(){var e;return Array.from(null==(e=this.$pageContainer)?void 0:e.querySelectorAll("*["+d+"]"))},a.fetchNewDocument=function(e,t){try{var n=this;return n._fetching&&(t.abort(),h("this._fetching = true, abort"),n._fetching=!1),n._fetching=!0,Promise.resolve(fetch(e,{signal:t.signal,mode:"same-origin",method:"GET",credentials:"same-origin"})).then(function(e){if(e.status>=200&&e.status<300)return Promise.resolve(e.text()).then(function(e){return n._fetching=!1,n.parseDOM(e)});throw n._fetching=!1,new Error("Something went wrong")})}catch(e){return Promise.reject(e)}},n(u,[{key:"pages",get:function(){return this._pages}}]),u}(f);export{f as Component,m as Stack}; | ||
import e from"@cher-ami/debug";function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key))?i:String(i),r)}var i}function n(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},r.apply(this,arguments)}function i(e,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},i(e,t)}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=[],s=e("compose:Component"),c="data-component",l="data-component-id",f=/*#__PURE__*/function(){function e(t,n,r){var i=this;this.name=void 0,this.$root=void 0,this.props=void 0,this.id=void 0,this._isMounted=!1,this.observer=void 0,this._beforeMount(),this.props=n,this.$root=t,this.name=r||e.getComponentName(this.$root),this.id=function(){var e;do{e=1e6*Math.random()|0}while(u.includes(e));return u.push(e),e}(),this.$root.setAttribute(l,""+this.id),window.setTimeout(function(){return i.init()},0)}var t=e.prototype;return t.init=function(){this._mounted(),this._watchChildren()},t.beforeMount=function(){},t._beforeMount=function(){this.beforeMount()},t.mounted=function(){},t._mounted=function(){s("🟢 mounted",this.name),this.mounted(),this._isMounted=!0},t.unmounted=function(){},t._unmounted=function(){this.unmounted(),this._isMounted=!1,this.onChildrenComponents(function(e){null==e||e._unmounted()}),s("🔴 unmounted",this.name)},t.add=function(t,n,i){var o,a=i||(null==t?void 0:t.attrName),u=null==(o=e.getDomElement(this.$root,a))?void 0:o[0];if(u)return new t(u,r({},n,{key:0,parentId:this.id}),a)},t.addAll=function(t,n,i){var o=[],a=i||(null==t?void 0:t.attrName),u=e.getDomElement(this.$root,a);if(!u.length)return o;for(var s=0;s<u.length;s++){var c=new t(u[s],r({},n,{key:s,parentId:this.id}),a);o.push(c)}return o},t.find=function(e,t){var n;if(void 0===t&&(t=null==(n=this.$root)||null==(n=n.classList)?void 0:n[0]),t&&e&&this.$root)return this.$root.querySelector("."+t+"_"+e)||void 0},t.findAll=function(e,t){var n;if(void 0===t&&(t=null==(n=this.$root)||null==(n=n.classList)?void 0:n[0]),t&&e&&this.$root){var r=this.$root.querySelectorAll("."+t+"_"+e);return Array.from(r||[])}},t._playInRef=function(e,t){var n=this;return new Promise(function(r,i){t.reject=function(){return i()},n.playIn(e,r)})},t.playIn=function(e,t){t()},t._playOutRef=function(e,t){var n=this;return new Promise(function(r,i){t.reject=function(){i(),n._unmounted()},n.playOut(e,r)})},t.playOut=function(e,t){t()},e.getDomElement=function(e,t){return Array.from((null==e?void 0:e.querySelectorAll("*["+c+"="+t+"]"))||[])},t.onChildrenComponents=function(t){var n,r=this;null==(n=Object.keys(this))||n.forEach(function(n){var i=null==r?void 0:r[n];Array.isArray(i)?i.forEach(function(n){n instanceof e&&t(n)}):i instanceof e&&t(i)})},e.getComponentName=function(e){return null==e||null==e.getAttribute?void 0:e.getAttribute(c)},e.getComponentId=function(e){return(null==e||null==e.getAttribute?void 0:e.getAttribute(l))&&parseInt(e.getAttribute(l))},t._watchChildren=function(){var t=this;this.observer=new MutationObserver(function(n){for(var r,i=a(n);!(r=i()).done;)for(var o,u=function(){var n,r=o.value,i=e.getComponentId(r),a=null==(n=r.parentNode)?void 0:n.querySelector("*["+l+"='"+i+"']");if(i&&a)return 1;t.onChildrenComponents(function(e){e&&i===(null==e?void 0:e.id)&&null!=e&&e.isMounted&&(e._unmounted(),e.observer.disconnect())})},s=a(r.value.removedNodes);!(o=s()).done;)u()}),this.$root&&this.observer.observe(this.$root,{subtree:!0,childList:!0})},n(e,[{key:"isMounted",get:function(){return this._isMounted}}]),e}(),p=function e(t,n){if(t===n)return!0;if(null==t||"object"!=typeof t||null==n||"object"!=typeof n)return!1;var r=Object.keys(t),i=Object.keys(n);if(r.length!==i.length)return!1;for(var o=0,a=r;o<a.length;o++){var u=a[o];if(!i.includes(u)||!e(t[u],n[u]))return!1}return!0};function h(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var g=e("compose:Stack"),d=new DOMParser,v="data-page-transition-url",m=/*#__PURE__*/function(e){var t,o;o=e,(t=u).prototype=Object.create(o.prototype),t.prototype.constructor=t,i(t,o);var a=u.prototype;function u(t){var n,r=t.history;return(n=e.call(this,t.$root,t.props)||this).forcePageReloadIfDocumentIsFetching=!1,n.forcePageReload=!1,n.disableLinksDuringTransitions=!1,n.disableHistoryDuringTransitions=!1,n.keepPageNumberDuringTransitions=1,n.enableCache=!0,n.locationHistory=[],n._pages=void 0,n.$clickedLink=void 0,n.currentUrl=null,n.currentLocation=null,n.currentPage=void 0,n.prevPage=void 0,n.isFirstPage=!0,n.$pageContainer=void 0,n.$pageWrapper=void 0,n.playInPromiseRef={reject:void 0},n.playOutPromiseRef={reject:void 0},n._pageIsAnimating=!1,n._fetching=!1,n._cache=void 0,n.history=void 0,n.removeHistory=void 0,n.handleLinks=function(e){var t,r;if(e){n.$clickedLink=e.currentTarget;var i=null==e||null==(t=e.currentTarget)?void 0:t.getAttribute(v),o=null==e||null==(r=e.currentTarget)?void 0:r.getAttribute("data-page-transition-partial");n.forcePageReload&&window.open(i,"_self"),e.preventDefault(),n.disableLinksDuringTransitions&&n._pageIsAnimating||n.history.push(i,{partial:"true"===o})}},n.handleHistory=function(e,t){try{var r,i=function(){function e(e){n.currentLocation=l,n.locationHistory.push(n.currentLocation)}var t=h(function(){return Promise.resolve(n.pageTransitionsMiddleware({currentPage:n.prepareCurrentPage(),mountNewPage:function(){return n.prepareMountNewPage(u,c)}})).then(function(e){n.isFirstPage=!1,n.prevPage=n.currentPage,n.currentPage=e,n.updateLinks()})},function(){throw new Error("Error on page transition middleware")});return t&&t.then?t.then(e):e()};if(n.disableHistoryDuringTransitions&&n._pageIsAnimating)return Promise.resolve();var o="POP"===t,a=n.locationHistory[n.locationHistory.length-1],u=e.pathname,s=null==(r=e.state)?void 0:r.partial,c={path:e.pathname,search:e.search},l={path:e.pathname,search:e.search};if(s&&(l.partial=!0),g("handleHistory > location value & current location",c,n.currentLocation),!u||p(c,n.currentLocation)||s&&!o||o&&a.partial&&c.path===a.path)return n.currentLocation=l,n.locationHistory.push(n.currentLocation),Promise.resolve();if(n.forcePageReloadIfDocumentIsFetching&&n._fetching||n.forcePageReload)return g("handleHistory > security, force page reload..."),window.open(u,"_self"),Promise.resolve();n.currentUrl=u;var f=function(){if(n._pageIsAnimating){g("\n handleHistory > New request while page is animating.\n For security: \n - Reject PlayOut & PlayIn anim promises;\n - Keep "+n.keepPageNumberDuringTransitions+" page(s) inside the wrapper div.\n "),null==n.playOutPromiseRef.reject||n.playOutPromiseRef.reject(),null==n.playInPromiseRef.reject||n.playInPromiseRef.reject(),n._pageIsAnimating=!1;var e=n.$pageWrapper.querySelectorAll(":scope > *");if(g("$pageWrapper content before remove",e),e.length>n.keepPageNumberDuringTransitions){for(var t=0;t<e.length-n.keepPageNumberDuringTransitions;t+=1)e[t].remove();g("$pageWrapper after remove",n.$pageWrapper.querySelectorAll(":scope > *"))}return Promise.resolve(new Promise(function(e){return setTimeout(e,1)})).then(function(){})}}();return Promise.resolve(f&&f.then?f.then(i):i())}catch(e){return Promise.reject(e)}},n.parseDOM=function(e){return"string"==typeof e?d.parseFromString(e,"text/html"):e},n.history=r,n.$pageContainer=n.getPageContainer(),n.$pageWrapper=n.getPageWrapper(n.$pageContainer),n._pages=n.addPages(),n.currentPage=n.getFirstCurrentPage(),n._cache={},n.start(),n}return a.addPages=function(){return{}},a.start=function(){this.handleHistory(window.location||"/"),this.initHistoryEvent(),this.listenLinks()},a.updateLinks=function(){this.unlistenLinks(),this.listenLinks()},a.stop=function(){this.removeHistoryEvent(),this.unlistenLinks()},a.listenLinks=function(){var e=this,t=this.getLinksWithAttr();null==t||t.forEach(function(t){null==t||t.addEventListener("click",e.handleLinks)})},a.unlistenLinks=function(){var e=this,t=this.getLinksWithAttr();null==t||t.forEach(function(t){null==t||t.removeEventListener("click",e.handleLinks)})},a.initHistoryEvent=function(){var e,t=this;this.removeHistory=null==(e=this.history)?void 0:e.listen(function(e){var n=e.location,r=e.action;g("history.listen",e),t.handleHistory(n,r)})},a.removeHistoryEvent=function(){this.removeHistory()},a.prepareCurrentPage=function(){var e=this,t=this.currentPage,n=function(){t.$pageRoot.remove()};return this.isFirstPage?null:r({},t,{playOut:function(r,i){return void 0===i&&(i=!0),t.instance._playOutRef.bind(t.instance)(r,e.playOutPromiseRef).then(function(){t.instance._unmounted(),i&&n()}).catch(function(){})},remove:n})},a.prepareMountNewPage=function(e,t){try{var n,r=this,i=r.currentPage,o=i.$pageRoot,a=i.pageName,u=i.instance,s=function(e){var t;return null==(t=e._playInRef.bind(e)(a,r.playInPromiseRef).then(function(){r._pageIsAnimating=!1}))||null==t.catch?void 0:t.catch(function(){})};if(r.isFirstPage)return r.addInCache(e,document.title,o,a,u,function(){return s(u)}),Promise.resolve({$pageRoot:o,pageName:a,instance:u,playIn:function(){return s(u)}});var c=null==(n=r._cache)?void 0:n[e];if(c&&p(t,r.currentLocation)){g("Use cache",c);var l=c.title,f=c.$pageRoot,d=c.pageName,v=r.createPageInstance(d,f);return g("Create new page instance from cache information",v),r.addPageInDOM(f),r.updateMetas(l),Promise.resolve({$pageRoot:f,pageName:d,instance:v,playIn:function(){return s(v)}})}return Promise.resolve(h(function(){return Promise.resolve(r.fetchNewDocument(e,new AbortController)).then(function(t){var n=r.getPageWrapper(t.body),i=r.getPageRoot(n),o=r.getPageName(i),a=r.createPageInstance(o,i);return r.addPageInDOM(i),r.updateMetas(t.title),r.addInCache(e,t.title,i,o,a,function(){return s(a)}),{$pageRoot:i,pageName:o,instance:a,playIn:function(){return s(a)}}})},function(){throw new Error("Fetch new document failed on url: "+e)}))}catch(e){return Promise.reject(e)}},a.pageTransitionsMiddleware=function(e){var t=this,n=e.currentPage,i=e.mountNewPage;return new Promise(function(e){try{return Promise.resolve(h(function(){return Promise.resolve(t.beforeFetch()).then(function(){return Promise.resolve(i()).then(function(i){var o=r({},n,{playOut:function(e,t){return void 0===t&&(t=!0),null==n?void 0:n.playOut(i.pageName,t)}}),a=function(){e(i)};return t._pageIsAnimating=!0,Promise.resolve(new Promise(function(e){return setTimeout(e,0)})).then(function(){return t.pageTransitions(o,i,a)})})})},function(e){console.error("mountNewPage failed",e)}))}catch(e){return Promise.reject(e)}})},a.pageTransitions=function(e,t,n){try{return Promise.resolve(e.playOut()).then(function(){return Promise.resolve(t.playIn()).then(function(){n()})})}catch(e){return Promise.reject(e)}},a.beforeFetch=function(){return Promise.resolve()},a.getPageContainer=function(e){return void 0===e&&(e=document.body),e.querySelector("*[data-page-transition-container]")},a.getPageWrapper=function(e){return e.querySelector("*[data-page-transition-wrapper]")},a.getPageRoot=function(e){return e.children[0]},a.getPageName=function(e){for(var t=0,n=Object.keys(this._pages);t<n.length;t++){var r=n[t];if(r==e.getAttribute(c))return r}},a.createPageInstance=function(e,t){g("getPageInstance > pageName:",e);var n=this._pages[e];return n?new n(t,{},e):null},a.getFirstCurrentPage=function(){var e=this.getPageRoot(this.$pageWrapper),t=this.getPageName(e),n=this.createPageInstance(t,e);return{$pageRoot:e,pageName:t,instance:n,playIn:function(){return n._playInRef()},playOut:function(){return n._playOutRef()}}},a.addPageInDOM=function(e){this.$pageWrapper.appendChild(e)},a.updateMetas=function(e){void 0!==typeof document&&(document.title=e)},a.addInCache=function(e,t,n,i,o,a){var u;this.enableCache?this._cache=r({},this._cache,((u={})[e]={title:t,$pageRoot:n,pageName:i,instance:o,playIn:a},u)):g("cache is disable, return")},a.getLinksWithAttr=function(){var e;return Array.from(null==(e=this.$pageContainer)?void 0:e.querySelectorAll("*["+v+"]"))},a.fetchNewDocument=function(e,t){try{var n=this;return n._fetching&&(t.abort(),g("this._fetching = true, abort"),n._fetching=!1),n._fetching=!0,Promise.resolve(fetch(e,{signal:t.signal,mode:"same-origin",method:"GET",credentials:"same-origin"})).then(function(e){if(e.status>=200&&e.status<300)return Promise.resolve(e.text()).then(function(e){return n._fetching=!1,n.parseDOM(e)});throw n._fetching=!1,new Error("Something went wrong")})}catch(e){return Promise.reject(e)}},n(u,[{key:"pages",get:function(){return this._pages}}]),u}(f);export{f as Component,m as Stack}; | ||
//# sourceMappingURL=index.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@cher-ami/debug")):"function"==typeof define&&define.amd?define(["exports","@cher-ami/debug"],t):t((e||self).compose={},e.debug)}(this,function(e,t){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=/*#__PURE__*/n(t);function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key))?i:String(i),r)}var i}function o(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a.apply(this,arguments)}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l=[],f=r.default("compose:Component"),p="data-component",h="data-component-id",d=/*#__PURE__*/function(){function e(t,n,r){var i=this;this.name=void 0,this.$root=void 0,this.props=void 0,this.id=void 0,this._isMounted=!1,this.observer=void 0,this._beforeMount(),this.props=n,this.$root=t,this.name=r||e.getComponentName(this.$root),this.id=function(){var e;do{e=1e6*Math.random()|0}while(l.includes(e));return l.push(e),e}(),this.$root.setAttribute(h,""+this.id),window.setTimeout(function(){return i.init()},0)}var t=e.prototype;return t.init=function(){this._mounted(),this._watchChildren()},t.beforeMount=function(){},t._beforeMount=function(){this.beforeMount()},t.mounted=function(){},t._mounted=function(){f("🟢 mounted",this.name),this.mounted(),this._isMounted=!0},t.unmounted=function(){},t._unmounted=function(){this.unmounted(),this._isMounted=!1,this.onChildrenComponents(function(e){null==e||e._unmounted()}),f("🔴 unmounted",this.name)},t.add=function(t,n,r){var i,o=r||(null==t?void 0:t.attrName),u=null==(i=e.getDomElement(this.$root,o))?void 0:i[0];if(u)return new t(u,a({},n,{key:0,parentId:this.id}),o)},t.addAll=function(t,n,r){var i=[],o=r||(null==t?void 0:t.attrName),u=e.getDomElement(this.$root,o);if(!u.length)return i;for(var s=0;s<u.length;s++){var c=new t(u[s],a({},n,{key:s,parentId:this.id}),o);i.push(c)}return i},t.find=function(e,t){var n;if(void 0===t&&(t=null==(n=this.$root)||null==(n=n.classList)?void 0:n[0]),t&&e&&this.$root)return this.$root.querySelector("."+t+"_"+e)||void 0},t.findAll=function(e,t){var n;if(void 0===t&&(t=null==(n=this.$root)||null==(n=n.classList)?void 0:n[0]),t&&e&&this.$root){var r=this.$root.querySelectorAll("."+t+"_"+e);return Array.from(r||[])}},t._playInRef=function(e,t){var n=this;return new Promise(function(r,i){t.reject=function(){return i()},n.playIn(e,r)})},t.playIn=function(e,t){t()},t._playOutRef=function(e,t){var n=this;return new Promise(function(r,i){t.reject=function(){i(),n._unmounted()},n.playOut(e,r)})},t.playOut=function(e,t){t()},e.getDomElement=function(e,t){return Array.from((null==e?void 0:e.querySelectorAll("*["+p+"="+t+"]"))||[])},t.onChildrenComponents=function(t){var n,r=this;null==(n=Object.keys(this))||n.forEach(function(n){var i=null==r?void 0:r[n];Array.isArray(i)?i.forEach(function(n){n instanceof e&&t(n)}):i instanceof e&&t(i)})},e.getComponentName=function(e){return null==e||null==e.getAttribute?void 0:e.getAttribute(p)},e.getComponentId=function(e){return(null==e||null==e.getAttribute?void 0:e.getAttribute(h))&&parseInt(e.getAttribute(h))},t._watchChildren=function(){var t=this;this.observer=new MutationObserver(function(n){for(var r,i=c(n);!(r=i()).done;)for(var o,a=function(){var n,r=o.value,i=e.getComponentId(r),a=null==(n=r.parentNode)?void 0:n.querySelector("*["+h+"='"+i+"']");if(i&&a)return 1;t.onChildrenComponents(function(e){e&&i===(null==e?void 0:e.id)&&null!=e&&e.isMounted&&(e._unmounted(),e.observer.disconnect())})},u=c(r.value.removedNodes);!(o=u()).done;)a()}),this.$root&&this.observer.observe(this.$root,{subtree:!0,childList:!0})},o(e,[{key:"isMounted",get:function(){return this._isMounted}}]),e}();function g(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var m=r.default("compose:Stack"),v=new DOMParser,y="data-page-transition-url",P=/*#__PURE__*/function(e){var t,n;n=e,(t=i).prototype=Object.create(n.prototype),t.prototype.constructor=t,u(t,n);var r=i.prototype;function i(t){var n,r=t.history;return(n=e.call(this,t.$root,t.props)||this).forcePageReloadIfDocumentIsFetching=!1,n.forcePageReload=!1,n.disableLinksDuringTransitions=!1,n.disableHistoryDuringTransitions=!1,n.keepPageNumberDuringTransitions=1,n.enableCache=!0,n._pages=void 0,n.$clickedLink=void 0,n.currentUrl=null,n.currentPage=void 0,n.prevPage=void 0,n.isFirstPage=!0,n.$pageContainer=void 0,n.$pageWrapper=void 0,n.playInPromiseRef={reject:void 0},n.playOutPromiseRef={reject:void 0},n._pageIsAnimating=!1,n._fetching=!1,n._cache=void 0,n.history=void 0,n.removeHistory=void 0,n.handleLinks=function(e){var t;if(e){n.$clickedLink=e.currentTarget;var r=null==e||null==(t=e.currentTarget)?void 0:t.getAttribute(y);n.forcePageReload&&window.open(r,"_self"),e.preventDefault(),n.disableLinksDuringTransitions&&n._pageIsAnimating||n.history.push(r)}},n.handleHistory=function(e){try{var t=function(){return g(function(){return Promise.resolve(n.pageTransitionsMiddleware({currentPage:n.prepareCurrentPage(),mountNewPage:function(){return n.prepareMountNewPage(r)}})).then(function(e){n.isFirstPage=!1,n.prevPage=n.currentPage,n.currentPage=e,n.updateLinks()})},function(){throw new Error("Error on page transition middleware")})};if(n.disableHistoryDuringTransitions&&n._pageIsAnimating)return Promise.resolve();var r=e;if(m("handleHistory > requestUrl",r),!r||r===n.currentUrl)return Promise.resolve();if(n.forcePageReloadIfDocumentIsFetching&&n._fetching||n.forcePageReload)return m("handleHistory > security, force page reload..."),window.open(r,"_self"),Promise.resolve();n.currentUrl=r;var i=function(){if(n._pageIsAnimating){m("\n handleHistory > New request while page is animating.\n For security: \n - Reject PlayOut & PlayIn anim promises;\n - Keep "+n.keepPageNumberDuringTransitions+" page(s) inside the wrapper div.\n "),null==n.playOutPromiseRef.reject||n.playOutPromiseRef.reject(),null==n.playInPromiseRef.reject||n.playInPromiseRef.reject(),n._pageIsAnimating=!1;var e=n.$pageWrapper.querySelectorAll(":scope > *");if(m("$pageWrapper content before remove",e),e.length>n.keepPageNumberDuringTransitions){for(var t=0;t<e.length-n.keepPageNumberDuringTransitions;t+=1)e[t].remove();m("$pageWrapper after remove",n.$pageWrapper.querySelectorAll(":scope > *"))}return Promise.resolve(new Promise(function(e){return setTimeout(e,1)})).then(function(){})}}();return Promise.resolve(i&&i.then?i.then(t):t())}catch(e){return Promise.reject(e)}},n.parseDOM=function(e){return"string"==typeof e?v.parseFromString(e,"text/html"):e},n.history=r,n.$pageContainer=n.getPageContainer(),n.$pageWrapper=n.getPageWrapper(n.$pageContainer),n._pages=n.addPages(),n.currentPage=n.getFirstCurrentPage(),n._cache={},n.start(),n}return r.addPages=function(){return{}},r.start=function(){this.handleHistory(window.location.pathname||"/"),this.initHistoryEvent(),this.listenLinks()},r.updateLinks=function(){this.unlistenLinks(),this.listenLinks()},r.stop=function(){this.removeHistoryEvent(),this.unlistenLinks()},r.listenLinks=function(){var e=this,t=this.getLinksWithAttr();null==t||t.forEach(function(t){null==t||t.addEventListener("click",e.handleLinks)})},r.unlistenLinks=function(){var e=this,t=this.getLinksWithAttr();null==t||t.forEach(function(t){null==t||t.removeEventListener("click",e.handleLinks)})},r.initHistoryEvent=function(){var e,t=this;this.removeHistory=null==(e=this.history)?void 0:e.listen(function(e){t.handleHistory(e.location.pathname)})},r.removeHistoryEvent=function(){this.removeHistory()},r.prepareCurrentPage=function(){var e=this,t=this.currentPage,n=function(){t.$pageRoot.remove()};return this.isFirstPage?null:a({},t,{playOut:function(r,i){return void 0===i&&(i=!0),t.instance._playOutRef.bind(t.instance)(r,e.playOutPromiseRef).then(function(){t.instance._unmounted(),i&&n()}).catch(function(){})},remove:n})},r.prepareMountNewPage=function(e){try{var t,n=this,r=n.currentPage,i=r.$pageRoot,o=r.pageName,a=r.instance,u=function(e){var t;return null==(t=e._playInRef.bind(e)(o,n.playInPromiseRef).then(function(){n._pageIsAnimating=!1}))||null==t.catch?void 0:t.catch(function(){})};if(n.isFirstPage)return n.addInCache(e,document.title,i,o,a,function(){return u(a)}),Promise.resolve({$pageRoot:i,pageName:o,instance:a,playIn:function(){return u(a)}});var s=null==(t=n._cache)?void 0:t[e];if(s){m("Use cache",s);var c=s.title,l=s.$pageRoot,f=s.pageName,p=n.createPageInstance(f,l);return m("Create new page instance from cache information",p),n.addPageInDOM(l),n.updateMetas(c),Promise.resolve({$pageRoot:l,pageName:f,instance:p,playIn:function(){return u(p)}})}return Promise.resolve(g(function(){return Promise.resolve(n.fetchNewDocument(e,new AbortController)).then(function(t){var r=n.getPageWrapper(t.body),i=n.getPageRoot(r),o=n.getPageName(i),a=n.createPageInstance(o,i);return n.addPageInDOM(i),n.updateMetas(t.title),n.addInCache(e,t.title,i,o,a,function(){return u(a)}),{$pageRoot:i,pageName:o,instance:a,playIn:function(){return u(a)}}})},function(){throw new Error("Fetch new document failed on url: "+e)}))}catch(e){return Promise.reject(e)}},r.pageTransitionsMiddleware=function(e){var t=this,n=e.currentPage,r=e.mountNewPage;return new Promise(function(e){try{return Promise.resolve(g(function(){return Promise.resolve(t.beforeFetch()).then(function(){return Promise.resolve(r()).then(function(r){var i=a({},n,{playOut:function(e,t){return void 0===t&&(t=!0),null==n?void 0:n.playOut(r.pageName,t)}}),o=function(){e(r)};return t._pageIsAnimating=!0,Promise.resolve(new Promise(function(e){return setTimeout(e,0)})).then(function(){return t.pageTransitions(i,r,o)})})})},function(e){console.error("mountNewPage failed",e)}))}catch(e){return Promise.reject(e)}})},r.pageTransitions=function(e,t,n){try{return Promise.resolve(e.playOut()).then(function(){return Promise.resolve(t.playIn()).then(function(){n()})})}catch(e){return Promise.reject(e)}},r.beforeFetch=function(){return Promise.resolve()},r.getPageContainer=function(e){return void 0===e&&(e=document.body),e.querySelector("*[data-page-transition-container]")},r.getPageWrapper=function(e){return e.querySelector("*[data-page-transition-wrapper]")},r.getPageRoot=function(e){return e.children[0]},r.getPageName=function(e){for(var t=0,n=Object.keys(this._pages);t<n.length;t++){var r=n[t];if(r==e.getAttribute(p))return r}},r.createPageInstance=function(e,t){m("getPageInstance > pageName:",e);var n=this._pages[e];return n?new n(t,{},e):null},r.getFirstCurrentPage=function(){var e=this.getPageRoot(this.$pageWrapper),t=this.getPageName(e),n=this.createPageInstance(t,e);return{$pageRoot:e,pageName:t,instance:n,playIn:function(){return n._playInRef()},playOut:function(){return n._playOutRef()}}},r.addPageInDOM=function(e){this.$pageWrapper.appendChild(e)},r.updateMetas=function(e){void 0!==typeof document&&(document.title=e)},r.addInCache=function(e,t,n,r,i,o){var u;this.enableCache?this._cache=a({},this._cache,((u={})[e]={title:t,$pageRoot:n,pageName:r,instance:i,playIn:o},u)):m("cache is disable, return")},r.getLinksWithAttr=function(){var e;return Array.from(null==(e=this.$pageContainer)?void 0:e.querySelectorAll("*["+y+"]"))},r.fetchNewDocument=function(e,t){try{var n=this;return n._fetching&&(t.abort(),m("this._fetching = true, abort"),n._fetching=!1),n._fetching=!0,Promise.resolve(fetch(e,{signal:t.signal,mode:"same-origin",method:"GET",credentials:"same-origin"})).then(function(e){if(e.status>=200&&e.status<300)return Promise.resolve(e.text()).then(function(e){return n._fetching=!1,n.parseDOM(e)});throw n._fetching=!1,new Error("Something went wrong")})}catch(e){return Promise.reject(e)}},o(i,[{key:"pages",get:function(){return this._pages}}]),i}(d);e.Component=d,e.Stack=P}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@cher-ami/debug")):"function"==typeof define&&define.amd?define(["exports","@cher-ami/debug"],t):t((e||self).compose={},e.debug)}(this,function(e,t){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=/*#__PURE__*/n(t);function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key))?i:String(i),r)}var i}function o(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a.apply(this,arguments)}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l=[],f=r.default("compose:Component"),p="data-component",h="data-component-id",g=/*#__PURE__*/function(){function e(t,n,r){var i=this;this.name=void 0,this.$root=void 0,this.props=void 0,this.id=void 0,this._isMounted=!1,this.observer=void 0,this._beforeMount(),this.props=n,this.$root=t,this.name=r||e.getComponentName(this.$root),this.id=function(){var e;do{e=1e6*Math.random()|0}while(l.includes(e));return l.push(e),e}(),this.$root.setAttribute(h,""+this.id),window.setTimeout(function(){return i.init()},0)}var t=e.prototype;return t.init=function(){this._mounted(),this._watchChildren()},t.beforeMount=function(){},t._beforeMount=function(){this.beforeMount()},t.mounted=function(){},t._mounted=function(){f("🟢 mounted",this.name),this.mounted(),this._isMounted=!0},t.unmounted=function(){},t._unmounted=function(){this.unmounted(),this._isMounted=!1,this.onChildrenComponents(function(e){null==e||e._unmounted()}),f("🔴 unmounted",this.name)},t.add=function(t,n,r){var i,o=r||(null==t?void 0:t.attrName),u=null==(i=e.getDomElement(this.$root,o))?void 0:i[0];if(u)return new t(u,a({},n,{key:0,parentId:this.id}),o)},t.addAll=function(t,n,r){var i=[],o=r||(null==t?void 0:t.attrName),u=e.getDomElement(this.$root,o);if(!u.length)return i;for(var s=0;s<u.length;s++){var c=new t(u[s],a({},n,{key:s,parentId:this.id}),o);i.push(c)}return i},t.find=function(e,t){var n;if(void 0===t&&(t=null==(n=this.$root)||null==(n=n.classList)?void 0:n[0]),t&&e&&this.$root)return this.$root.querySelector("."+t+"_"+e)||void 0},t.findAll=function(e,t){var n;if(void 0===t&&(t=null==(n=this.$root)||null==(n=n.classList)?void 0:n[0]),t&&e&&this.$root){var r=this.$root.querySelectorAll("."+t+"_"+e);return Array.from(r||[])}},t._playInRef=function(e,t){var n=this;return new Promise(function(r,i){t.reject=function(){return i()},n.playIn(e,r)})},t.playIn=function(e,t){t()},t._playOutRef=function(e,t){var n=this;return new Promise(function(r,i){t.reject=function(){i(),n._unmounted()},n.playOut(e,r)})},t.playOut=function(e,t){t()},e.getDomElement=function(e,t){return Array.from((null==e?void 0:e.querySelectorAll("*["+p+"="+t+"]"))||[])},t.onChildrenComponents=function(t){var n,r=this;null==(n=Object.keys(this))||n.forEach(function(n){var i=null==r?void 0:r[n];Array.isArray(i)?i.forEach(function(n){n instanceof e&&t(n)}):i instanceof e&&t(i)})},e.getComponentName=function(e){return null==e||null==e.getAttribute?void 0:e.getAttribute(p)},e.getComponentId=function(e){return(null==e||null==e.getAttribute?void 0:e.getAttribute(h))&&parseInt(e.getAttribute(h))},t._watchChildren=function(){var t=this;this.observer=new MutationObserver(function(n){for(var r,i=c(n);!(r=i()).done;)for(var o,a=function(){var n,r=o.value,i=e.getComponentId(r),a=null==(n=r.parentNode)?void 0:n.querySelector("*["+h+"='"+i+"']");if(i&&a)return 1;t.onChildrenComponents(function(e){e&&i===(null==e?void 0:e.id)&&null!=e&&e.isMounted&&(e._unmounted(),e.observer.disconnect())})},u=c(r.value.removedNodes);!(o=u()).done;)a()}),this.$root&&this.observer.observe(this.$root,{subtree:!0,childList:!0})},o(e,[{key:"isMounted",get:function(){return this._isMounted}}]),e}(),d=function e(t,n){if(t===n)return!0;if(null==t||"object"!=typeof t||null==n||"object"!=typeof n)return!1;var r=Object.keys(t),i=Object.keys(n);if(r.length!==i.length)return!1;for(var o=0,a=r;o<a.length;o++){var u=a[o];if(!i.includes(u)||!e(t[u],n[u]))return!1}return!0};function m(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var v=r.default("compose:Stack"),y=new DOMParser,P="data-page-transition-url",b=/*#__PURE__*/function(e){var t,n;n=e,(t=i).prototype=Object.create(n.prototype),t.prototype.constructor=t,u(t,n);var r=i.prototype;function i(t){var n,r=t.history;return(n=e.call(this,t.$root,t.props)||this).forcePageReloadIfDocumentIsFetching=!1,n.forcePageReload=!1,n.disableLinksDuringTransitions=!1,n.disableHistoryDuringTransitions=!1,n.keepPageNumberDuringTransitions=1,n.enableCache=!0,n.locationHistory=[],n._pages=void 0,n.$clickedLink=void 0,n.currentUrl=null,n.currentLocation=null,n.currentPage=void 0,n.prevPage=void 0,n.isFirstPage=!0,n.$pageContainer=void 0,n.$pageWrapper=void 0,n.playInPromiseRef={reject:void 0},n.playOutPromiseRef={reject:void 0},n._pageIsAnimating=!1,n._fetching=!1,n._cache=void 0,n.history=void 0,n.removeHistory=void 0,n.handleLinks=function(e){var t,r;if(e){n.$clickedLink=e.currentTarget;var i=null==e||null==(t=e.currentTarget)?void 0:t.getAttribute(P),o=null==e||null==(r=e.currentTarget)?void 0:r.getAttribute("data-page-transition-partial");n.forcePageReload&&window.open(i,"_self"),e.preventDefault(),n.disableLinksDuringTransitions&&n._pageIsAnimating||n.history.push(i,{partial:"true"===o})}},n.handleHistory=function(e,t){try{var r,i=function(){function e(e){n.currentLocation=l,n.locationHistory.push(n.currentLocation)}var t=m(function(){return Promise.resolve(n.pageTransitionsMiddleware({currentPage:n.prepareCurrentPage(),mountNewPage:function(){return n.prepareMountNewPage(u,c)}})).then(function(e){n.isFirstPage=!1,n.prevPage=n.currentPage,n.currentPage=e,n.updateLinks()})},function(){throw new Error("Error on page transition middleware")});return t&&t.then?t.then(e):e()};if(n.disableHistoryDuringTransitions&&n._pageIsAnimating)return Promise.resolve();var o="POP"===t,a=n.locationHistory[n.locationHistory.length-1],u=e.pathname,s=null==(r=e.state)?void 0:r.partial,c={path:e.pathname,search:e.search},l={path:e.pathname,search:e.search};if(s&&(l.partial=!0),v("handleHistory > location value & current location",c,n.currentLocation),!u||d(c,n.currentLocation)||s&&!o||o&&a.partial&&c.path===a.path)return n.currentLocation=l,n.locationHistory.push(n.currentLocation),Promise.resolve();if(n.forcePageReloadIfDocumentIsFetching&&n._fetching||n.forcePageReload)return v("handleHistory > security, force page reload..."),window.open(u,"_self"),Promise.resolve();n.currentUrl=u;var f=function(){if(n._pageIsAnimating){v("\n handleHistory > New request while page is animating.\n For security: \n - Reject PlayOut & PlayIn anim promises;\n - Keep "+n.keepPageNumberDuringTransitions+" page(s) inside the wrapper div.\n "),null==n.playOutPromiseRef.reject||n.playOutPromiseRef.reject(),null==n.playInPromiseRef.reject||n.playInPromiseRef.reject(),n._pageIsAnimating=!1;var e=n.$pageWrapper.querySelectorAll(":scope > *");if(v("$pageWrapper content before remove",e),e.length>n.keepPageNumberDuringTransitions){for(var t=0;t<e.length-n.keepPageNumberDuringTransitions;t+=1)e[t].remove();v("$pageWrapper after remove",n.$pageWrapper.querySelectorAll(":scope > *"))}return Promise.resolve(new Promise(function(e){return setTimeout(e,1)})).then(function(){})}}();return Promise.resolve(f&&f.then?f.then(i):i())}catch(e){return Promise.reject(e)}},n.parseDOM=function(e){return"string"==typeof e?y.parseFromString(e,"text/html"):e},n.history=r,n.$pageContainer=n.getPageContainer(),n.$pageWrapper=n.getPageWrapper(n.$pageContainer),n._pages=n.addPages(),n.currentPage=n.getFirstCurrentPage(),n._cache={},n.start(),n}return r.addPages=function(){return{}},r.start=function(){this.handleHistory(window.location||"/"),this.initHistoryEvent(),this.listenLinks()},r.updateLinks=function(){this.unlistenLinks(),this.listenLinks()},r.stop=function(){this.removeHistoryEvent(),this.unlistenLinks()},r.listenLinks=function(){var e=this,t=this.getLinksWithAttr();null==t||t.forEach(function(t){null==t||t.addEventListener("click",e.handleLinks)})},r.unlistenLinks=function(){var e=this,t=this.getLinksWithAttr();null==t||t.forEach(function(t){null==t||t.removeEventListener("click",e.handleLinks)})},r.initHistoryEvent=function(){var e,t=this;this.removeHistory=null==(e=this.history)?void 0:e.listen(function(e){var n=e.location,r=e.action;v("history.listen",e),t.handleHistory(n,r)})},r.removeHistoryEvent=function(){this.removeHistory()},r.prepareCurrentPage=function(){var e=this,t=this.currentPage,n=function(){t.$pageRoot.remove()};return this.isFirstPage?null:a({},t,{playOut:function(r,i){return void 0===i&&(i=!0),t.instance._playOutRef.bind(t.instance)(r,e.playOutPromiseRef).then(function(){t.instance._unmounted(),i&&n()}).catch(function(){})},remove:n})},r.prepareMountNewPage=function(e,t){try{var n,r=this,i=r.currentPage,o=i.$pageRoot,a=i.pageName,u=i.instance,s=function(e){var t;return null==(t=e._playInRef.bind(e)(a,r.playInPromiseRef).then(function(){r._pageIsAnimating=!1}))||null==t.catch?void 0:t.catch(function(){})};if(r.isFirstPage)return r.addInCache(e,document.title,o,a,u,function(){return s(u)}),Promise.resolve({$pageRoot:o,pageName:a,instance:u,playIn:function(){return s(u)}});var c=null==(n=r._cache)?void 0:n[e];if(c&&d(t,r.currentLocation)){v("Use cache",c);var l=c.title,f=c.$pageRoot,p=c.pageName,h=r.createPageInstance(p,f);return v("Create new page instance from cache information",h),r.addPageInDOM(f),r.updateMetas(l),Promise.resolve({$pageRoot:f,pageName:p,instance:h,playIn:function(){return s(h)}})}return Promise.resolve(m(function(){return Promise.resolve(r.fetchNewDocument(e,new AbortController)).then(function(t){var n=r.getPageWrapper(t.body),i=r.getPageRoot(n),o=r.getPageName(i),a=r.createPageInstance(o,i);return r.addPageInDOM(i),r.updateMetas(t.title),r.addInCache(e,t.title,i,o,a,function(){return s(a)}),{$pageRoot:i,pageName:o,instance:a,playIn:function(){return s(a)}}})},function(){throw new Error("Fetch new document failed on url: "+e)}))}catch(e){return Promise.reject(e)}},r.pageTransitionsMiddleware=function(e){var t=this,n=e.currentPage,r=e.mountNewPage;return new Promise(function(e){try{return Promise.resolve(m(function(){return Promise.resolve(t.beforeFetch()).then(function(){return Promise.resolve(r()).then(function(r){var i=a({},n,{playOut:function(e,t){return void 0===t&&(t=!0),null==n?void 0:n.playOut(r.pageName,t)}}),o=function(){e(r)};return t._pageIsAnimating=!0,Promise.resolve(new Promise(function(e){return setTimeout(e,0)})).then(function(){return t.pageTransitions(i,r,o)})})})},function(e){console.error("mountNewPage failed",e)}))}catch(e){return Promise.reject(e)}})},r.pageTransitions=function(e,t,n){try{return Promise.resolve(e.playOut()).then(function(){return Promise.resolve(t.playIn()).then(function(){n()})})}catch(e){return Promise.reject(e)}},r.beforeFetch=function(){return Promise.resolve()},r.getPageContainer=function(e){return void 0===e&&(e=document.body),e.querySelector("*[data-page-transition-container]")},r.getPageWrapper=function(e){return e.querySelector("*[data-page-transition-wrapper]")},r.getPageRoot=function(e){return e.children[0]},r.getPageName=function(e){for(var t=0,n=Object.keys(this._pages);t<n.length;t++){var r=n[t];if(r==e.getAttribute(p))return r}},r.createPageInstance=function(e,t){v("getPageInstance > pageName:",e);var n=this._pages[e];return n?new n(t,{},e):null},r.getFirstCurrentPage=function(){var e=this.getPageRoot(this.$pageWrapper),t=this.getPageName(e),n=this.createPageInstance(t,e);return{$pageRoot:e,pageName:t,instance:n,playIn:function(){return n._playInRef()},playOut:function(){return n._playOutRef()}}},r.addPageInDOM=function(e){this.$pageWrapper.appendChild(e)},r.updateMetas=function(e){void 0!==typeof document&&(document.title=e)},r.addInCache=function(e,t,n,r,i,o){var u;this.enableCache?this._cache=a({},this._cache,((u={})[e]={title:t,$pageRoot:n,pageName:r,instance:i,playIn:o},u)):v("cache is disable, return")},r.getLinksWithAttr=function(){var e;return Array.from(null==(e=this.$pageContainer)?void 0:e.querySelectorAll("*["+P+"]"))},r.fetchNewDocument=function(e,t){try{var n=this;return n._fetching&&(t.abort(),v("this._fetching = true, abort"),n._fetching=!1),n._fetching=!0,Promise.resolve(fetch(e,{signal:t.signal,mode:"same-origin",method:"GET",credentials:"same-origin"})).then(function(e){if(e.status>=200&&e.status<300)return Promise.resolve(e.text()).then(function(e){return n._fetching=!1,n.parseDOM(e)});throw n._fetching=!1,new Error("Something went wrong")})}catch(e){return Promise.reject(e)}},o(i,[{key:"pages",get:function(){return this._pages}}]),i}(g);e.Component=g,e.Stack=b}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -31,2 +31,7 @@ import { Component } from "./Component"; | ||
}; | ||
type TLocation = { | ||
path: string; | ||
search: string; | ||
partial?: boolean; | ||
}; | ||
/** | ||
@@ -65,2 +70,3 @@ * Stack | ||
enableCache: boolean; | ||
locationHistory: TLocation[]; | ||
/** | ||
@@ -82,2 +88,7 @@ * Register pages from parent class | ||
/** | ||
* the current search to request | ||
* @protected | ||
*/ | ||
protected currentLocation: TLocation; | ||
/** | ||
* current page {IPage} | ||
@@ -84,0 +95,0 @@ */ |
{ | ||
"name": "@cher-ami/compose", | ||
"version": "0.15.2", | ||
"version": "0.15.3", | ||
"description": "Compose is a small and type-safe library that links your javascript to your DOM.", | ||
@@ -5,0 +5,0 @@ "author": "Willy Brauner", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
378306
47
808
5