@telia-ace/widget-site 1.1.148-rc.0 → 1.1.148-rc.2
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/index.js +4 -4
- package/index.mjs +153 -153
- package/index.umd.js +4 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class T{constructor(t){this._api=t,this._bootstrapped=!1,this._widgetAPIHandlers=new Map,window.ace=window.ace||{_c:[],_w:[],widget:function(i
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class T{constructor(t){this._api=t,this._bootstrapped=!1,this._widgetAPIHandlers=new Map,window.ace=window.ace||{_c:[],_w:[],widget:function(e,i){window.ace._w.push([e,i])},configure:function(e){window.ace._c.push(e)}}}bootstrap(){this._bootstrap()}_bootstrap(){const t=globalThis.ace;globalThis.ace=this,this._bootstrapped=!0,((t==null?void 0:t._w)||[]).forEach(([e,i])=>{this.widget(e,i)}),((t==null?void 0:t._c)||[]).forEach(e=>{this.configure(e)})}executePreloadedHandlers(t,e){const i=e?[t,e]:[t];i.flatMap(r=>this._widgetAPIHandlers.get(r)||[]).forEach(r=>{r()}),i.forEach(r=>this._widgetAPIHandlers.set(r,[]))}configure(t){if(!this._bootstrapped)throw new Error("ace environment not bootstrapped");t(this._api)}version(){return this._api.version()}widget(t,e){const i=Object.values(this._api.getWidgets()).find(s=>{var r;return((r=s.widget)==null?void 0:r.name)===t||s.widgetId===t});if(!i){const s=this._widgetAPIHandlers.get(t)||[];s.push(()=>{const r=Object.values(this._api.getWidgets()).find(a=>{var o;return((o=a.widget)==null?void 0:o.name)===t||a.widgetId===t});e(r==null?void 0:r.api)}),this._widgetAPIHandlers.set(t,s);return}e(i.api)}}const z="1.1.148-rc.2";class ${constructor(t){this._site=t}async activate(t,e){let i=this._site._widgets[t];if(i||(this._site.addWidgetEl(t),i=this._site._widgets[t]),!i){console.warn(`[ACE] Widget "${t}" not found`);return}i.manuallyActivated=!0,e!=null&&e.onClose&&(i._onCloseCallback=e.onClose),e!=null&&e.hideTrigger&&i.setTriggerVisible(!1),i.isActivated()||await i.activate()}storagePolicy(t){Object.entries(this._site._widgets).forEach(([e,i])=>{i.dispatch("set-storage-policies",{policies:t})})}disallowStorageKey(t){Object.entries(this._site._widgets).forEach(([e,i])=>{i.dispatch("disallow-storage-key",{storageKey:t})})}getWidgets(){return this._site._widgets}version(){const t=z;return{widgets:this._site.getWidgetsVersions(),sites:t}}}class M{constructor(t,e){this.triggerType=t,this.condition=e,this.triggerType=t,this.condition=e}shouldActivate(t){if(this.triggerType!=="visit"||this.condition.type!=="url")return[];const e=[];return this.condition.outputs.filter(i=>i.action.type==="render_widget"&&W(i.value,t)).forEach(i=>{let s={widgetId:""};try{s=JSON.parse(i.action.data)}catch{s={widgetId:""}}e.push(s.widgetId)}),e}}const W=(n,t)=>{if(n==="*"||n==="/*"||n===t)return!0;if(n.endsWith("/*")){const s=n.slice(0,-2);return t===s||t.startsWith(s+"/")}return!1},U=(n,t)=>{const e=s=>`ace_${n.substring(0,7)}-${s}`;return Object.entries(t).reduce((s,[r,a])=>{const[o,c]=r.split("-");if(e(c)!=r)return s;try{const d=JSON.parse(a);s[c]=d.value}catch{return s}return s},{})},u="https://widgets.ace.teliacompany.net/v1",B="https://embed.webprovisions.io",H=()=>{if(typeof window<"u"){const n=history.pushState,t=history.replaceState;history.pushState=function(...e){n.apply(history,e),window.dispatchEvent(new Event("locationchange"))},history.replaceState=function(...e){t.apply(history,e),window.dispatchEvent(new Event("locationchange"))}}};class v extends HTMLElement{constructor(){var t;super(),this._site=null,this._widgets={},this._loadedVersions={},this._path=((t=window==null?void 0:window.location)==null?void 0:t.pathname)||"",this._api=new $(this),this._environment=new T(this._api),this.routeChangeListener=()=>{this._path=window.location.pathname,this.render()},this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["siteid","apiurl","embedurl"]}get siteId(){return this.getAttribute("siteid")||""}set siteId(t){this.setAttribute("siteid",t)}get apiUrl(){return this.getAttribute("apiurl")||u}set apiUrl(t){this.setAttribute("apiurl",t)}get embedUrl(){return this.getAttribute("embedurl")||B}set embedUrl(t){this.setAttribute("embedurl",t)}async connectedCallback(){H(),await this._loadSite(),this.render(),this._environment.bootstrap(),window.addEventListener("locationchange",this.routeChangeListener),window.addEventListener("message",t=>{var s,r;const{type:e,data:i}=t.data;if(e==="widget-minimize")this._widgets[i.widgetId].toggleExpand();else if(e==="widget-maximize")(s=this._widgets[i.widgetId])==null||s.setMaximized(i.value);else if(e==="widget-activated"){this._widgets[i.widgetId].executeMessageQueue();const a=this._widgets[i.widgetId];a&&(this._loadedVersions[i.widgetId]=i.version,this._environment.executePreloadedHandlers(((r=a.widget)==null?void 0:r.name)||"",i.widgetId));try{const o=JSON.parse(i.storage),c=U(i.widgetId,o);typeof c.open=="boolean"&&(a.disableAnimations(),a.toggleExpand(c.open),setTimeout(()=>{a.enableAnimations()},600))}catch{console.warn("unable to parse widget storage")}}})}disconnectedCallback(){window.removeEventListener("locationchange",this.routeChangeListener)}attributeChangedCallback(t,e,i){this.render()}async _loadSite(){var s;const e=await(await fetch(`${this.apiUrl}/site/${this.siteId}`)).json(),i=location.hostname;if(!((e==null?void 0:e.hosts)||[]).includes(i)){console.warn(`the host "${i}" needs to be configured as an allowed host in order to install widgets.`);return}this._site=e,this._site&&(this._site.triggers=this._site.triggers.map(r=>new M(r.triggerType,r.condition))),(((s=this._site)==null?void 0:s.widgets)||[]).forEach(async r=>{this.addWidgetEl(r.id)})}addWidgetEl(t){const e=`ace-widget_${t}`;let i=document.getElementById(e);i||(i=document.createElement("ace-widget"),i.id=e,i.widgetId=t,this.apiUrl!==u&&(i.apiUrl=this.apiUrl),document.body.appendChild(i)),this._widgets={...this._widgets,[t]:i}}getWidgetsVersions(){return this._loadedVersions}render(){if(!this._site){this.shadow.innerHTML="";return}const t=O(this._site);for(const[e,i]of Object.entries(this._widgets)){if(i.manuallyActivated)continue;const s=t.find(r=>r.id===e);s&&!i.isActivated()?i.activate():!s&&i.isActivated()&&i.deactivate()}this.shadow.innerHTML=""}}window.customElements.get("ace-site")||window.customElements.define("ace-site",v);const O=n=>{const t=window.location.pathname;return n.triggers.reduce((i,s)=>(s.shouldActivate(t).forEach(a=>{const o=i.find(d=>d.id===a),c=((n==null?void 0:n.widgets)||[]).find(d=>d.id===a);!o&&c&&i.push({id:a})}),i),[])},g=(n,t,e)=>{n&&e.style.setProperty(t,n)},P=(n,t)=>{var e,i,s,r,a,o,c,d,l;g((e=n.colors)==null?void 0:e.primaryBackground,"--primary-background",t),g((i=n.colors)==null?void 0:i.textOnPrimaryBackground,"--text-on-primary-background",t),g((s=n.colors)==null?void 0:s.secondaryBackground,"--secondary-background",t),g((r=n.colors)==null?void 0:r.textOnSecondaryBackground,"--text-on-secondary-background",t),g((a=n.colors)==null?void 0:a.interactiveDestructiveBackground,"--destructive-color",t),g((o=n.colors)==null?void 0:o.interactiveTextOnDestructiveBackground,"--text-on-destructive-color",t),g((c=n.colors)==null?void 0:c.interactivePrimaryBackground,"--interactive-primary-background",t),g((d=n.colors)==null?void 0:d.interactiveTextOnPrimaryBackground,"--interactive-text-on-primary-background",t),g((l=n.colors)==null?void 0:l.focusColor,"--focus-color",t)},V=(n={})=>{const{content:t="",title:e,attributes:i=[]}=n;let s="";const r=[{name:"xmlns",value:"http://www.w3.org/2000/svg"},{name:"fill",value:"currentColor"},...i];return e&&(s=`<title>${e}</title>`),`<svg ${r.map(o=>`${o.name}="${o.value}"`).join(" ")}>${s}${t}</svg>`},_=document.createElement("template");_.innerHTML=`<span
|
|
2
2
|
class="ace-icon__container"
|
|
3
3
|
></span>`;const x=document.createElement("template");var f;const p=(f=document.querySelector("script[nonce]"))==null?void 0:f.getAttribute("nonce");x.innerHTML=`<style ${p?`nonce="${p}"`:""}>
|
|
4
4
|
:host {
|
|
@@ -34,7 +34,7 @@ svg {
|
|
|
34
34
|
min-width: var(--size-lg);
|
|
35
35
|
width: var(--size-lg);
|
|
36
36
|
}
|
|
37
|
-
</style>`;class E extends HTMLElement{get svg(){return this.getAttribute("svg")||""}set svg(t){this.setAttribute("svg",t)}get size(){return this.getAttribute("size")||""}set size(t){this.setAttribute("size",t),this.classList.remove("ace-icon--sm","ace-icon--md","ace--icon-lg"),this.classList.add(`ace-icon--${t}`)}static get observedAttributes(){return["svg","size"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(x.content.cloneNode(!0)),this.shadow.appendChild(_.content.cloneNode(!0))}attributeChangedCallback(t,i
|
|
37
|
+
</style>`;class E extends HTMLElement{get svg(){return this.getAttribute("svg")||""}set svg(t){this.setAttribute("svg",t)}get size(){return this.getAttribute("size")||""}set size(t){this.setAttribute("size",t),this.classList.remove("ace-icon--sm","ace-icon--md","ace--icon-lg"),this.classList.add(`ace-icon--${t}`)}static get observedAttributes(){return["svg","size"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(x.content.cloneNode(!0)),this.shadow.appendChild(_.content.cloneNode(!0))}attributeChangedCallback(t,e,i){this.render()}render(){var e;const t=(e=this.shadowRoot)==null?void 0:e.querySelector(".ace-icon__container");if(t){const i=V({content:this.svg,attributes:[{name:"viewBox",value:"0 0 64 64"}],title:void 0});t.innerHTML=i}}}window.customElements.get("ace-icon")||window.customElements.define("ace-icon",E);const j={name:"question",svg:'<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M32 4C16.536 4 4 16.536 4 32C4 47.464 16.536 60 32 60C47.464 60 60 47.464 60 32C59.9827 16.5432 47.4568 4.01731 32 4ZM32 55.6923C18.9151 55.6923 8.30769 45.0849 8.30769 32C8.30769 18.9151 18.9151 8.30769 32 8.30769C45.0849 8.30769 55.6923 18.9151 55.6923 32C55.6775 45.0788 45.0788 55.6775 32 55.6923Z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M31.9423 37.5723L36.311 32.9068L36.7354 32.4448C39.7555 29.1161 40.7645 27.0647 40.7645 24.5087C40.7645 23.1091 40.4251 21.7942 39.7041 20.6491C38.3044 18.3587 35.6323 16.9166 32.2816 16.9166C28.7565 16.9166 25.3125 18.7414 23.2581 21.6772L23.1201 21.8791C22.8232 22.3032 22.696 22.6849 22.696 22.9818C22.696 23.7029 23.926 25.9932 25.2833 25.9932C25.5378 25.9932 25.7922 25.9084 26.0467 25.7388C26.2588 25.5691 26.5981 25.2298 27.0647 24.7208C28.8885 22.6849 30.1185 21.9215 31.7726 21.9215C33.6813 21.9215 35.081 23.1939 35.081 24.8905C35.081 26.375 34.2751 27.7746 32.3664 29.8529L28.2523 34.2216C27.9554 34.6033 27.7857 34.9426 27.7857 35.282C27.7857 35.6213 27.9978 36.1726 28.4219 36.8937C29.0581 37.8692 29.7368 38.3782 30.4578 38.3782C30.9244 38.3782 31.3909 38.1237 31.9423 37.5723ZM30.882 47.4972C29.2278 47.4972 27.6585 44.7403 27.6585 43.6799C27.6585 42.1954 30.0761 40.6261 32.4089 40.6261C33.6389 40.6261 34.2751 41.1775 34.2751 42.3227C34.2751 44.0616 33.4692 45.843 32.4513 46.7761C31.9423 47.2427 31.4334 47.4972 30.882 47.4972Z"/></svg>'},C=document.createElement("template");var b;const m=(b=document.querySelector("script[nonce]"))==null?void 0:b.getAttribute("nonce");C.innerHTML=`<style ${m?`nonce="${m}"`:""}>
|
|
38
38
|
:host {
|
|
39
39
|
position: fixed;
|
|
40
40
|
display: flex;
|
|
@@ -209,7 +209,7 @@ svg {
|
|
|
209
209
|
</svg>
|
|
210
210
|
</span>
|
|
211
211
|
</button>
|
|
212
|
-
</div>`;class k extends HTMLElement{constructor(){super(),this.widget=null,this.loaded=!1,this.active=!1,this._onClicked=()=>{this.active=!this.active;const t={detail:{widgetId:this.widgetId},bubbles:!0,composed:!0};this.dispatchEvent(new CustomEvent("toggle",t)),this.render()},this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(C.content.cloneNode(!0)),this.shadow.appendChild(A.content.cloneNode(!0))}static get observedAttributes(){return["widgetid","apiurl"]}get widgetId(){return this.getAttribute("widgetid")||""}set widgetId(t){this.setAttribute("widgetid",t)}get apiUrl(){return this.getAttribute("apiurl")||""}set apiUrl(t){this.setAttribute("apiurl",t)}async connectedCallback(){this.widget=await this._loadWidget(this.widgetId),this.icon=await this._renderSymbol(),this.loaded=!0,this.render()}attributeChangedCallback(t,i
|
|
212
|
+
</div>`;class k extends HTMLElement{constructor(){super(),this.widget=null,this.loaded=!1,this.active=!1,this._onClicked=()=>{this.active=!this.active;const t={detail:{widgetId:this.widgetId},bubbles:!0,composed:!0};this.dispatchEvent(new CustomEvent("toggle",t)),this.render()},this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(C.content.cloneNode(!0)),this.shadow.appendChild(A.content.cloneNode(!0))}static get observedAttributes(){return["widgetid","apiurl"]}get widgetId(){return this.getAttribute("widgetid")||""}set widgetId(t){this.setAttribute("widgetid",t)}get apiUrl(){return this.getAttribute("apiurl")||""}set apiUrl(t){this.setAttribute("apiurl",t)}async connectedCallback(){this.widget=await this._loadWidget(this.widgetId),this.icon=await this._renderSymbol(),this.loaded=!0,this.render()}attributeChangedCallback(t,e,i){this.render()}setActive(t){this.active=t,this.render()}_applyBranding(){var t,e;(e=(t=this.widget)==null?void 0:t.configuration)!=null&&e.branding&&P(this.widget.configuration.branding,this)}async _loadWidget(t){const i=await(await fetch(`${this.apiUrl}/widget/${t}`)).json(),s=JSON.parse(i.configuration);return{...i,configuration:s}}async _renderSymbol(){var a,o,c;const t=(o=(a=this.widget)==null?void 0:a.configuration)==null?void 0:o.branding,e=(c=t==null?void 0:t.graphics)==null?void 0:c.trigger;if(e){const d=document.createElement("img");return d.src=e,d.classList.add("trigger-icon"),d.alt="",d}const i={type:"Telia"},s=async d=>j,{type:r}=i;switch(r){case"Telia":{const d=await s();if(d){const l=document.createElement("ace-icon");return l.classList.add("trigger-icon"),l.svg=d.svg,l.size="lg",l}return null}default:return null}}toggle(){this._onClicked()}hide(){this.classList.add("ace-hidden"),this.style.display="none"}show(){this.classList.remove("ace-hidden"),this.style.display=""}_renderButtonLabel(){var s,r,a,o,c,d,l,h;if(!(((o=(a=(r=(s=this.widget)==null?void 0:s.configuration)==null?void 0:r.branding)==null?void 0:a.other)==null?void 0:o.showButtonLabel)||!1))return null;const e=((h=(l=(d=(c=this.widget)==null?void 0:c.configuration)==null?void 0:d.branding)==null?void 0:l.other)==null?void 0:h.buttonLabelText)||"Widget trigger",i=document.createElement("button");return i.setAttribute("type","button"),i.setAttribute("aria-label",e),i.classList.add("trigger-label"),i.addEventListener("click",this._onClicked),i.innerHTML=e,i}render(){var s,r,a,o,c,d,l;this._applyBranding(),this.classList.add("bottom-right"),this.classList.toggle("active",this.active);const t=(s=this.shadowRoot)==null?void 0:s.querySelector(".trigger-container"),e=this._renderButtonLabel();(r=t==null?void 0:t.querySelector(".trigger-label"))==null||r.remove(),t&&e&&t.prepend(e);const i=(a=this.shadowRoot)==null?void 0:a.querySelector("#trigger-btn");if(i){const h=((l=(d=(c=(o=this.widget)==null?void 0:o.configuration)==null?void 0:c.branding)==null?void 0:d.other)==null?void 0:l.buttonLabelText)||"Widget trigger";i.classList.toggle("active",this.active),i.classList.toggle("rendered",this.loaded),i.addEventListener("click",this._onClicked),i.setAttribute("type","button"),i.setAttribute("aria-label",h),this.icon&&i.prepend(this.icon)}}}window.customElements.get("ace-trigger")||window.customElements.define("ace-trigger",k);window.customElements.get("ace-icon")||window.customElements.define("ace-icon",E);class N{constructor(t){this.widgetEl=t}open(){this.widgetEl.toggleExpand(!0)}close(){this.widgetEl.toggleExpand(!1)}onClose(t){this.widgetEl._onCloseCallback=t}setZIndex(t){this.widgetEl.setZIndex(t)}setFullscreenMode(t){this.widgetEl.dispatch("set-fullscreen-mode",{value:t})}}const R="https://widgets.ace.teliacompany.net/v1",L=document.createElement("template");var y;const w=(y=document.querySelector("script[nonce]"))==null?void 0:y.getAttribute("nonce");L.innerHTML=`<style ${w?`nonce="${w}"`:""}>
|
|
213
213
|
@keyframes slideDown {
|
|
214
214
|
from {
|
|
215
215
|
transform: translateY(0);
|
|
@@ -292,4 +292,4 @@ svg {
|
|
|
292
292
|
animation: slideDown 0.3s linear;
|
|
293
293
|
display: none;
|
|
294
294
|
}
|
|
295
|
-
</style>`;const S=document.createElement("template");S.innerHTML='<div class="widget-frame-container"></div>';class I extends HTMLElement{constructor(){super(),this.widget=null,this.activated=!1,this.manuallyActivated=!1,this.triggerHidden=!1,this.active=!1,this.iframeEl=null,this.trigger=null,this._messageQueue=[],this._onCloseCallback=null,this.api=new N(this),this.zIndex=-1,this.trigger=document.createElement("ace-trigger"),this.trigger.widgetId=this.widgetId,this.trigger.apiUrl=this.apiUrl,this.trigger.id=`ace-trigger_${this.widgetId}`,this.trigger.addEventListener("toggle",t=>{this.toggleExpand()}),this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(L.content.cloneNode(!0)),this.shadow.appendChild(S.content.cloneNode(!0))}static get observedAttributes(){return["widgetid","apiurl","expanded"]}get expanded(){return this.getAttribute("expanded")||"false"}set expanded(t){this.setAttribute("expanded",t),t==="false"&&this.classList.toggle("ace-hidden",!0)}get widgetId(){return this.getAttribute("widgetid")||""}set widgetId(t){this.trigger&&(this.trigger.widgetId=t,this.trigger.id=`ace-trigger_${t}`),this.setAttribute("widgetid",t)}get apiUrl(){return this.getAttribute("apiurl")||R}set apiUrl(t){this.trigger&&(this.trigger.apiUrl=t),this.setAttribute("apiurl",t)}attributeChangedCallback(t,i
|
|
295
|
+
</style>`;const S=document.createElement("template");S.innerHTML='<div class="widget-frame-container"></div>';class I extends HTMLElement{constructor(){super(),this.widget=null,this.activated=!1,this.manuallyActivated=!1,this.triggerHidden=!1,this.active=!1,this.iframeEl=null,this.trigger=null,this._messageQueue=[],this._onCloseCallback=null,this.api=new N(this),this.zIndex=-1,this.trigger=document.createElement("ace-trigger"),this.trigger.widgetId=this.widgetId,this.trigger.apiUrl=this.apiUrl,this.trigger.id=`ace-trigger_${this.widgetId}`,this.trigger.addEventListener("toggle",t=>{this.toggleExpand()}),this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(L.content.cloneNode(!0)),this.shadow.appendChild(S.content.cloneNode(!0))}static get observedAttributes(){return["widgetid","apiurl","expanded"]}get expanded(){return this.getAttribute("expanded")||"false"}set expanded(t){this.setAttribute("expanded",t),t==="false"&&this.classList.toggle("ace-hidden",!0)}get widgetId(){return this.getAttribute("widgetid")||""}set widgetId(t){this.trigger&&(this.trigger.widgetId=t,this.trigger.id=`ace-trigger_${t}`),this.setAttribute("widgetid",t)}get apiUrl(){return this.getAttribute("apiurl")||R}set apiUrl(t){this.trigger&&(this.trigger.apiUrl=t),this.setAttribute("apiurl",t)}attributeChangedCallback(t,e,i){this.render()}async connectedCallback(){var t;this.widget=await this._loadWidget(this.widgetId),console.log("[ACE] allowedOrigins:",(t=this.widget)==null?void 0:t.allowedOrigins),window.addEventListener("message",e=>{var i,s,r,a,o;this.iframeEl&&!this._isAllowedOrigin(e.origin)||(((i=e.data)==null?void 0:i.type)==="widget-set-active"?typeof((s=e.data.data)==null?void 0:s.active)=="boolean"&&(this.active=e.data.data.active):((r=e.data)==null?void 0:r.type)==="widget-maximize"&&((a=e.data.data)==null?void 0:a.widgetId)===this.widgetId&&typeof((o=e.data.data)==null?void 0:o.value)=="boolean"&&this.setMaximized(e.data.data.value))}),this.render()}isActivated(){return this.activated}disableAnimations(){const t=this._getContainerEl();t&&(t.style.animationDuration="0ms")}enableAnimations(){const t=this._getContainerEl();t&&(t.style.animationDuration="300ms")}_isAllowedOrigin(t){var s;const e=new URL(this.apiUrl).origin;if(t===e)return!0;const i=(s=this.widget)==null?void 0:s.allowedOrigins;return!i||i.length===0?!1:i.some(r=>t===`https://${r}`)}_getContainerEl(){var t;return((t=this.shadowRoot)==null?void 0:t.querySelector(".widget-frame-container"))||null}async activate(){var e;this.widget||(this.widget=await this._loadWidget(this.widgetId)),this._createIFrame(),this.activated=!0;const t=(((e=window.ace)==null?void 0:e.applications)||[]).find(i=>i.id===this.widgetId);t&&(t.storage.get("open")&&t.appendToDOM(),t.trigger.showTrigger()),this.render()}async _loadWidget(t){return await(await fetch(`${this.apiUrl}/widget/${t}`)).json()}dispatch(t,e={}){var s;const i={type:t,data:e};if(e.widgetId||(e.widgetId=this.widgetId),!this.iframeEl){this._messageQueue.push(i);return}(s=this.iframeEl.contentWindow)==null||s.postMessage(i,"*")}async deactivate(){this.activated=!1,this.manuallyActivated=!1,this.render()}setTriggerVisible(t){this.triggerHidden=!t,this.trigger&&(t?this.trigger.show():this.trigger.hide())}_createIFrame(){var s;if(!((s=this.widget)!=null&&s.distributionName)||this.iframeEl||!this.widget.linked)return;const t={display:"block",border:"none",opacity:"1","color-scheme":"none",background:"none transparent !important",margin:"0px","max-height":"100%","max-width":"100vw",transform:"translateY(0px)",transition:"none 0s ease 0s !important",visibility:"visible","z-index":"999999999 !important",width:"100%",height:"100%","border-radius":"0.7rem"},e=document.createElement("iframe");Object.entries(t).forEach(([r,a])=>{e.style.setProperty(r,a)});const i=this.apiUrl.replace("/v1","").replace("/api","");e.src=`${i}/${this.widget.organization}/${this.widget.id}?inline=true&fullscreen=true`,e.title=this.getIFrameTitle(),e.setAttribute("allow","camera; microphone; display-capture; autoplay"),this.iframeEl=e}getIFrameTitle(){var e,i;let t=(e=this.widget)==null?void 0:e.configuration;if(typeof t=="string")try{t=JSON.parse(t)}catch{t={}}return((i=t==null?void 0:t.texts)==null?void 0:i["iframe.title"])||"ACE Widget"}executeMessageQueue(){this._messageQueue.forEach(t=>{this.dispatch(t.type,t.data)}),this._messageQueue=[]}isExpanded(){return this.expanded==="true"}toggleExpand(t){const e=this.isExpanded();typeof t!="boolean"?this.expanded=this.isExpanded()?"false":"true":this.isExpanded()!==t&&(this.expanded=t?"true":"false"),this.dispatch("set-open",{value:this.isExpanded()}),this.trigger&&this.trigger.setActive(this.isExpanded()),e&&!this.isExpanded()&&this._onCloseCallback&&this._onCloseCallback()}setZIndex(t){this.zIndex=t,this.render()}setMaximized(t){this.classList.toggle("ace-maximized",t),this.dispatch("set-maximized-mode",{value:t})}render(){var i,s;if(!this.iframeEl)return;this.isExpanded()?(this.classList.add("ace-expanded"),this.classList.remove("ace-hidden")):this.classList.remove("ace-expanded");const t=this.activated?"block":"none";this.iframeEl.style.setProperty("display",t),this.activated?this.classList.add("activated"):this.classList.remove("activated");const e=this._getContainerEl();e&&e.childNodes.length===0&&e.appendChild(this.iframeEl),e&&this.zIndex!==-1&&(e.style.zIndex=this.zIndex.toString()),this.trigger&&((i=this.shadowRoot)==null?void 0:i.querySelectorAll("ace-trigger").length)===0&&((s=this.shadowRoot)==null||s.insertBefore(this.trigger,this.shadowRoot.firstChild)),this.trigger&&this.triggerHidden&&this.trigger.hide()}}window.customElements.get("ace-widget")||window.customElements.define("ace-widget",I);window.customElements.get("ace-trigger")||window.customElements.define("ace-trigger",k);exports.SiteComponent=v;exports.WidgetComponent=I;
|
package/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
class
|
|
1
|
+
class I {
|
|
2
2
|
constructor(t) {
|
|
3
3
|
this._api = t, this._bootstrapped = !1, this._widgetAPIHandlers = /* @__PURE__ */ new Map(), window.ace = window.ace || {
|
|
4
4
|
_c: [],
|
|
5
5
|
_w: [],
|
|
6
|
-
widget: function(
|
|
7
|
-
window.ace._w.push([
|
|
6
|
+
widget: function(e, i) {
|
|
7
|
+
window.ace._w.push([e, i]);
|
|
8
8
|
},
|
|
9
|
-
configure: function(
|
|
10
|
-
window.ace._c.push(
|
|
9
|
+
configure: function(e) {
|
|
10
|
+
window.ace._c.push(e);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
13
|
}
|
|
@@ -16,19 +16,19 @@ class S {
|
|
|
16
16
|
}
|
|
17
17
|
_bootstrap() {
|
|
18
18
|
const t = globalThis.ace;
|
|
19
|
-
globalThis.ace = this, this._bootstrapped = !0, ((t == null ? void 0 : t._w) || []).forEach(([
|
|
20
|
-
this.widget(
|
|
21
|
-
}), ((t == null ? void 0 : t._c) || []).forEach((
|
|
22
|
-
this.configure(
|
|
19
|
+
globalThis.ace = this, this._bootstrapped = !0, ((t == null ? void 0 : t._w) || []).forEach(([e, i]) => {
|
|
20
|
+
this.widget(e, i);
|
|
21
|
+
}), ((t == null ? void 0 : t._c) || []).forEach((e) => {
|
|
22
|
+
this.configure(e);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
executePreloadedHandlers(t,
|
|
26
|
-
const
|
|
27
|
-
|
|
25
|
+
executePreloadedHandlers(t, e) {
|
|
26
|
+
const i = e ? [t, e] : [t];
|
|
27
|
+
i.flatMap(
|
|
28
28
|
(r) => this._widgetAPIHandlers.get(r) || []
|
|
29
29
|
).forEach((r) => {
|
|
30
30
|
r();
|
|
31
|
-
}),
|
|
31
|
+
}), i.forEach((r) => this._widgetAPIHandlers.set(r, []));
|
|
32
32
|
}
|
|
33
33
|
configure(t) {
|
|
34
34
|
if (!this._bootstrapped)
|
|
@@ -38,52 +38,52 @@ class S {
|
|
|
38
38
|
version() {
|
|
39
39
|
return this._api.version();
|
|
40
40
|
}
|
|
41
|
-
widget(t,
|
|
42
|
-
const
|
|
41
|
+
widget(t, e) {
|
|
42
|
+
const i = Object.values(this._api.getWidgets()).find(
|
|
43
43
|
(s) => {
|
|
44
44
|
var r;
|
|
45
45
|
return ((r = s.widget) == null ? void 0 : r.name) === t || s.widgetId === t;
|
|
46
46
|
}
|
|
47
47
|
);
|
|
48
|
-
if (!
|
|
48
|
+
if (!i) {
|
|
49
49
|
const s = this._widgetAPIHandlers.get(t) || [];
|
|
50
50
|
s.push(() => {
|
|
51
51
|
const r = Object.values(this._api.getWidgets()).find(
|
|
52
52
|
(a) => {
|
|
53
|
-
var
|
|
54
|
-
return ((
|
|
53
|
+
var o;
|
|
54
|
+
return ((o = a.widget) == null ? void 0 : o.name) === t || a.widgetId === t;
|
|
55
55
|
}
|
|
56
56
|
);
|
|
57
|
-
|
|
57
|
+
e(r == null ? void 0 : r.api);
|
|
58
58
|
}), this._widgetAPIHandlers.set(t, s);
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
i
|
|
61
|
+
e(i.api);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
const
|
|
64
|
+
const S = "1.1.148-rc.2";
|
|
65
65
|
class T {
|
|
66
66
|
constructor(t) {
|
|
67
67
|
this._site = t;
|
|
68
68
|
}
|
|
69
|
-
async activate(t,
|
|
70
|
-
let
|
|
71
|
-
if (
|
|
69
|
+
async activate(t, e) {
|
|
70
|
+
let i = this._site._widgets[t];
|
|
71
|
+
if (i || (this._site.addWidgetEl(t), i = this._site._widgets[t]), !i) {
|
|
72
72
|
console.warn(`[ACE] Widget "${t}" not found`);
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
i.manuallyActivated = !0, e != null && e.onClose && (i._onCloseCallback = e.onClose), e != null && e.hideTrigger && i.setTriggerVisible(!1), i.isActivated() || await i.activate();
|
|
76
76
|
}
|
|
77
77
|
storagePolicy(t) {
|
|
78
|
-
Object.entries(this._site._widgets).forEach(([
|
|
79
|
-
|
|
78
|
+
Object.entries(this._site._widgets).forEach(([e, i]) => {
|
|
79
|
+
i.dispatch("set-storage-policies", {
|
|
80
80
|
policies: t
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
disallowStorageKey(t) {
|
|
85
|
-
Object.entries(this._site._widgets).forEach(([
|
|
86
|
-
|
|
85
|
+
Object.entries(this._site._widgets).forEach(([e, i]) => {
|
|
86
|
+
i.dispatch("disallow-storage-key", {
|
|
87
87
|
storageKey: t
|
|
88
88
|
});
|
|
89
89
|
});
|
|
@@ -92,7 +92,7 @@ class T {
|
|
|
92
92
|
return this._site._widgets;
|
|
93
93
|
}
|
|
94
94
|
version() {
|
|
95
|
-
const t =
|
|
95
|
+
const t = S;
|
|
96
96
|
return {
|
|
97
97
|
widgets: this._site.getWidgetsVersions(),
|
|
98
98
|
sites: t
|
|
@@ -100,24 +100,24 @@ class T {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
class z {
|
|
103
|
-
constructor(t,
|
|
104
|
-
this.triggerType = t, this.condition =
|
|
103
|
+
constructor(t, e) {
|
|
104
|
+
this.triggerType = t, this.condition = e, this.triggerType = t, this.condition = e;
|
|
105
105
|
}
|
|
106
106
|
shouldActivate(t) {
|
|
107
107
|
if (this.triggerType !== "visit" || this.condition.type !== "url")
|
|
108
108
|
return [];
|
|
109
|
-
const
|
|
110
|
-
return this.condition.outputs.filter((
|
|
109
|
+
const e = [];
|
|
110
|
+
return this.condition.outputs.filter((i) => i.action.type === "render_widget" && $(i.value, t)).forEach((i) => {
|
|
111
111
|
let s = { widgetId: "" };
|
|
112
112
|
try {
|
|
113
|
-
s = JSON.parse(
|
|
113
|
+
s = JSON.parse(i.action.data);
|
|
114
114
|
} catch {
|
|
115
115
|
s = {
|
|
116
116
|
widgetId: ""
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
}),
|
|
119
|
+
e.push(s.widgetId);
|
|
120
|
+
}), e;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
const $ = (n, t) => {
|
|
@@ -129,15 +129,15 @@ const $ = (n, t) => {
|
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
131
|
}, M = (n, t) => {
|
|
132
|
-
const
|
|
132
|
+
const e = (s) => `ace_${n.substring(0, 7)}-${s}`;
|
|
133
133
|
return Object.entries(t).reduce(
|
|
134
134
|
(s, [r, a]) => {
|
|
135
|
-
const [
|
|
136
|
-
if (
|
|
135
|
+
const [o, c] = r.split("-");
|
|
136
|
+
if (e(c) != r)
|
|
137
137
|
return s;
|
|
138
138
|
try {
|
|
139
|
-
const
|
|
140
|
-
s[c] =
|
|
139
|
+
const d = JSON.parse(a);
|
|
140
|
+
s[c] = d.value;
|
|
141
141
|
} catch {
|
|
142
142
|
return s;
|
|
143
143
|
}
|
|
@@ -148,17 +148,17 @@ const $ = (n, t) => {
|
|
|
148
148
|
}, u = "https://widgets.ace.teliacompany.net/v1", U = "https://embed.webprovisions.io", W = () => {
|
|
149
149
|
if (typeof window < "u") {
|
|
150
150
|
const n = history.pushState, t = history.replaceState;
|
|
151
|
-
history.pushState = function(...
|
|
152
|
-
n.apply(history,
|
|
153
|
-
}, history.replaceState = function(...
|
|
154
|
-
t.apply(history,
|
|
151
|
+
history.pushState = function(...e) {
|
|
152
|
+
n.apply(history, e), window.dispatchEvent(new Event("locationchange"));
|
|
153
|
+
}, history.replaceState = function(...e) {
|
|
154
|
+
t.apply(history, e), window.dispatchEvent(new Event("locationchange"));
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
};
|
|
158
158
|
class B extends HTMLElement {
|
|
159
159
|
constructor() {
|
|
160
160
|
var t;
|
|
161
|
-
super(), this._site = null, this._widgets = {}, this._loadedVersions = {}, this._path = ((t = window == null ? void 0 : window.location) == null ? void 0 : t.pathname) || "", this._api = new T(this), this._environment = new
|
|
161
|
+
super(), this._site = null, this._widgets = {}, this._loadedVersions = {}, this._path = ((t = window == null ? void 0 : window.location) == null ? void 0 : t.pathname) || "", this._api = new T(this), this._environment = new I(this._api), this.routeChangeListener = () => {
|
|
162
162
|
this._path = window.location.pathname, this.render();
|
|
163
163
|
}, this.shadow = this.attachShadow({ mode: "open" });
|
|
164
164
|
}
|
|
@@ -186,20 +186,20 @@ class B extends HTMLElement {
|
|
|
186
186
|
async connectedCallback() {
|
|
187
187
|
W(), await this._loadSite(), this.render(), this._environment.bootstrap(), window.addEventListener("locationchange", this.routeChangeListener), window.addEventListener("message", (t) => {
|
|
188
188
|
var s, r;
|
|
189
|
-
const { type:
|
|
190
|
-
if (
|
|
191
|
-
this._widgets[
|
|
192
|
-
else if (
|
|
193
|
-
(s = this._widgets[
|
|
194
|
-
else if (
|
|
195
|
-
this._widgets[
|
|
196
|
-
const a = this._widgets[
|
|
197
|
-
a && (this._loadedVersions[
|
|
189
|
+
const { type: e, data: i } = t.data;
|
|
190
|
+
if (e === "widget-minimize")
|
|
191
|
+
this._widgets[i.widgetId].toggleExpand();
|
|
192
|
+
else if (e === "widget-maximize")
|
|
193
|
+
(s = this._widgets[i.widgetId]) == null || s.setMaximized(i.value);
|
|
194
|
+
else if (e === "widget-activated") {
|
|
195
|
+
this._widgets[i.widgetId].executeMessageQueue();
|
|
196
|
+
const a = this._widgets[i.widgetId];
|
|
197
|
+
a && (this._loadedVersions[i.widgetId] = i.version, this._environment.executePreloadedHandlers(
|
|
198
198
|
((r = a.widget) == null ? void 0 : r.name) || "",
|
|
199
|
-
|
|
199
|
+
i.widgetId
|
|
200
200
|
));
|
|
201
201
|
try {
|
|
202
|
-
const
|
|
202
|
+
const o = JSON.parse(i.storage), c = M(i.widgetId, o);
|
|
203
203
|
typeof c.open == "boolean" && (a.disableAnimations(), a.toggleExpand(c.open), setTimeout(() => {
|
|
204
204
|
a.enableAnimations();
|
|
205
205
|
}, 600));
|
|
@@ -212,32 +212,32 @@ class B extends HTMLElement {
|
|
|
212
212
|
disconnectedCallback() {
|
|
213
213
|
window.removeEventListener("locationchange", this.routeChangeListener);
|
|
214
214
|
}
|
|
215
|
-
attributeChangedCallback(t,
|
|
215
|
+
attributeChangedCallback(t, e, i) {
|
|
216
216
|
this.render();
|
|
217
217
|
}
|
|
218
218
|
async _loadSite() {
|
|
219
219
|
var s;
|
|
220
|
-
const
|
|
221
|
-
if (!((
|
|
220
|
+
const e = await (await fetch(`${this.apiUrl}/site/${this.siteId}`)).json(), i = location.hostname;
|
|
221
|
+
if (!((e == null ? void 0 : e.hosts) || []).includes(i)) {
|
|
222
222
|
console.warn(
|
|
223
|
-
`the host "${
|
|
223
|
+
`the host "${i}" needs to be configured as an allowed host in order to install widgets.`
|
|
224
224
|
);
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
|
-
this._site =
|
|
227
|
+
this._site = e, this._site && (this._site.triggers = this._site.triggers.map(
|
|
228
228
|
(r) => new z(r.triggerType, r.condition)
|
|
229
229
|
)), (((s = this._site) == null ? void 0 : s.widgets) || []).forEach(async (r) => {
|
|
230
230
|
this.addWidgetEl(r.id);
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
233
|
addWidgetEl(t) {
|
|
234
|
-
const
|
|
235
|
-
let
|
|
236
|
-
|
|
234
|
+
const e = `ace-widget_${t}`;
|
|
235
|
+
let i = document.getElementById(
|
|
236
|
+
e
|
|
237
237
|
);
|
|
238
|
-
|
|
238
|
+
i || (i = document.createElement("ace-widget"), i.id = e, i.widgetId = t, this.apiUrl !== u && (i.apiUrl = this.apiUrl), document.body.appendChild(i)), this._widgets = {
|
|
239
239
|
...this._widgets,
|
|
240
|
-
[t]:
|
|
240
|
+
[t]: i
|
|
241
241
|
};
|
|
242
242
|
}
|
|
243
243
|
getWidgetsVersions() {
|
|
@@ -249,13 +249,13 @@ class B extends HTMLElement {
|
|
|
249
249
|
return;
|
|
250
250
|
}
|
|
251
251
|
const t = H(this._site);
|
|
252
|
-
for (const [
|
|
253
|
-
if (
|
|
252
|
+
for (const [e, i] of Object.entries(this._widgets)) {
|
|
253
|
+
if (i.manuallyActivated)
|
|
254
254
|
continue;
|
|
255
255
|
const s = t.find(
|
|
256
|
-
(r) => r.id ===
|
|
256
|
+
(r) => r.id === e
|
|
257
257
|
);
|
|
258
|
-
s && !
|
|
258
|
+
s && !i.isActivated() ? i.activate() : !s && i.isActivated() && i.deactivate();
|
|
259
259
|
}
|
|
260
260
|
this.shadow.innerHTML = "";
|
|
261
261
|
}
|
|
@@ -263,20 +263,20 @@ class B extends HTMLElement {
|
|
|
263
263
|
window.customElements.get("ace-site") || window.customElements.define("ace-site", B);
|
|
264
264
|
const H = (n) => {
|
|
265
265
|
const t = window.location.pathname;
|
|
266
|
-
return n.triggers.reduce((
|
|
267
|
-
const
|
|
268
|
-
(
|
|
266
|
+
return n.triggers.reduce((i, s) => (s.shouldActivate(t).forEach((a) => {
|
|
267
|
+
const o = i.find((d) => d.id === a), c = ((n == null ? void 0 : n.widgets) || []).find(
|
|
268
|
+
(d) => d.id === a
|
|
269
269
|
);
|
|
270
|
-
!
|
|
270
|
+
!o && c && i.push({
|
|
271
271
|
id: a
|
|
272
272
|
});
|
|
273
|
-
}),
|
|
274
|
-
}, g = (n, t,
|
|
275
|
-
n &&
|
|
273
|
+
}), i), []);
|
|
274
|
+
}, g = (n, t, e) => {
|
|
275
|
+
n && e.style.setProperty(t, n);
|
|
276
276
|
}, O = (n, t) => {
|
|
277
|
-
var
|
|
278
|
-
g((
|
|
279
|
-
(
|
|
277
|
+
var e, i, s, r, a, o, c, d, l;
|
|
278
|
+
g((e = n.colors) == null ? void 0 : e.primaryBackground, "--primary-background", t), g(
|
|
279
|
+
(i = n.colors) == null ? void 0 : i.textOnPrimaryBackground,
|
|
280
280
|
"--text-on-primary-background",
|
|
281
281
|
t
|
|
282
282
|
), g(
|
|
@@ -292,7 +292,7 @@ const H = (n) => {
|
|
|
292
292
|
"--destructive-color",
|
|
293
293
|
t
|
|
294
294
|
), g(
|
|
295
|
-
(
|
|
295
|
+
(o = n.colors) == null ? void 0 : o.interactiveTextOnDestructiveBackground,
|
|
296
296
|
"--text-on-destructive-color",
|
|
297
297
|
t
|
|
298
298
|
), g(
|
|
@@ -300,21 +300,21 @@ const H = (n) => {
|
|
|
300
300
|
"--interactive-primary-background",
|
|
301
301
|
t
|
|
302
302
|
), g(
|
|
303
|
-
(
|
|
303
|
+
(d = n.colors) == null ? void 0 : d.interactiveTextOnPrimaryBackground,
|
|
304
304
|
"--interactive-text-on-primary-background",
|
|
305
305
|
t
|
|
306
306
|
), g((l = n.colors) == null ? void 0 : l.focusColor, "--focus-color", t);
|
|
307
307
|
}, P = (n = {}) => {
|
|
308
|
-
const { content: t = "", title:
|
|
308
|
+
const { content: t = "", title: e, attributes: i = [] } = n;
|
|
309
309
|
let s = "";
|
|
310
310
|
const r = [
|
|
311
311
|
{ name: "xmlns", value: "http://www.w3.org/2000/svg" },
|
|
312
312
|
{ name: "fill", value: "currentColor" },
|
|
313
|
-
...
|
|
313
|
+
...i
|
|
314
314
|
];
|
|
315
|
-
return
|
|
316
|
-
},
|
|
317
|
-
|
|
315
|
+
return e && (s = `<title>${e}</title>`), `<svg ${r.map((o) => `${o.name}="${o.value}"`).join(" ")}>${s}${t}</svg>`;
|
|
316
|
+
}, v = document.createElement("template");
|
|
317
|
+
v.innerHTML = `<span
|
|
318
318
|
class="ace-icon__container"
|
|
319
319
|
></span>`;
|
|
320
320
|
const _ = document.createElement("template");
|
|
@@ -372,16 +372,16 @@ class x extends HTMLElement {
|
|
|
372
372
|
return ["svg", "size"];
|
|
373
373
|
}
|
|
374
374
|
constructor() {
|
|
375
|
-
super(), this.shadow = this.attachShadow({ mode: "open" }), this.shadow.appendChild(_.content.cloneNode(!0)), this.shadow.appendChild(
|
|
375
|
+
super(), this.shadow = this.attachShadow({ mode: "open" }), this.shadow.appendChild(_.content.cloneNode(!0)), this.shadow.appendChild(v.content.cloneNode(!0));
|
|
376
376
|
}
|
|
377
|
-
attributeChangedCallback(t,
|
|
377
|
+
attributeChangedCallback(t, e, i) {
|
|
378
378
|
this.render();
|
|
379
379
|
}
|
|
380
380
|
render() {
|
|
381
|
-
var
|
|
382
|
-
const t = (
|
|
381
|
+
var e;
|
|
382
|
+
const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".ace-icon__container");
|
|
383
383
|
if (t) {
|
|
384
|
-
const
|
|
384
|
+
const i = P({
|
|
385
385
|
content: this.svg,
|
|
386
386
|
attributes: [
|
|
387
387
|
{
|
|
@@ -391,7 +391,7 @@ class x extends HTMLElement {
|
|
|
391
391
|
],
|
|
392
392
|
title: void 0
|
|
393
393
|
});
|
|
394
|
-
t.innerHTML =
|
|
394
|
+
t.innerHTML = i;
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
}
|
|
@@ -612,39 +612,39 @@ class A extends HTMLElement {
|
|
|
612
612
|
async connectedCallback() {
|
|
613
613
|
this.widget = await this._loadWidget(this.widgetId), this.icon = await this._renderSymbol(), this.loaded = !0, this.render();
|
|
614
614
|
}
|
|
615
|
-
attributeChangedCallback(t,
|
|
615
|
+
attributeChangedCallback(t, e, i) {
|
|
616
616
|
this.render();
|
|
617
617
|
}
|
|
618
618
|
setActive(t) {
|
|
619
619
|
this.active = t, this.render();
|
|
620
620
|
}
|
|
621
621
|
_applyBranding() {
|
|
622
|
-
var t,
|
|
623
|
-
(
|
|
622
|
+
var t, e;
|
|
623
|
+
(e = (t = this.widget) == null ? void 0 : t.configuration) != null && e.branding && O(this.widget.configuration.branding, this);
|
|
624
624
|
}
|
|
625
625
|
async _loadWidget(t) {
|
|
626
|
-
const
|
|
626
|
+
const i = await (await fetch(`${this.apiUrl}/widget/${t}`)).json(), s = JSON.parse(i.configuration);
|
|
627
627
|
return {
|
|
628
|
-
...
|
|
628
|
+
...i,
|
|
629
629
|
configuration: s
|
|
630
630
|
};
|
|
631
631
|
}
|
|
632
632
|
async _renderSymbol() {
|
|
633
|
-
var a,
|
|
634
|
-
const t = (
|
|
635
|
-
if (
|
|
636
|
-
const
|
|
637
|
-
return
|
|
633
|
+
var a, o, c;
|
|
634
|
+
const t = (o = (a = this.widget) == null ? void 0 : a.configuration) == null ? void 0 : o.branding, e = (c = t == null ? void 0 : t.graphics) == null ? void 0 : c.trigger;
|
|
635
|
+
if (e) {
|
|
636
|
+
const d = document.createElement("img");
|
|
637
|
+
return d.src = e, d.classList.add("trigger-icon"), d.alt = "", d;
|
|
638
638
|
}
|
|
639
|
-
const
|
|
639
|
+
const i = {
|
|
640
640
|
type: "Telia"
|
|
641
|
-
}, s = async (
|
|
641
|
+
}, s = async (d) => V, { type: r } = i;
|
|
642
642
|
switch (r) {
|
|
643
643
|
case "Telia": {
|
|
644
|
-
const
|
|
645
|
-
if (
|
|
644
|
+
const d = await s();
|
|
645
|
+
if (d) {
|
|
646
646
|
const l = document.createElement("ace-icon");
|
|
647
|
-
return l.classList.add("trigger-icon"), l.svg =
|
|
647
|
+
return l.classList.add("trigger-icon"), l.svg = d.svg, l.size = "lg", l;
|
|
648
648
|
}
|
|
649
649
|
return null;
|
|
650
650
|
}
|
|
@@ -662,21 +662,21 @@ class A extends HTMLElement {
|
|
|
662
662
|
this.classList.remove("ace-hidden"), this.style.display = "";
|
|
663
663
|
}
|
|
664
664
|
_renderButtonLabel() {
|
|
665
|
-
var s, r, a,
|
|
666
|
-
if (!(((
|
|
665
|
+
var s, r, a, o, c, d, l, h;
|
|
666
|
+
if (!(((o = (a = (r = (s = this.widget) == null ? void 0 : s.configuration) == null ? void 0 : r.branding) == null ? void 0 : a.other) == null ? void 0 : o.showButtonLabel) || !1))
|
|
667
667
|
return null;
|
|
668
|
-
const
|
|
669
|
-
return
|
|
668
|
+
const e = ((h = (l = (d = (c = this.widget) == null ? void 0 : c.configuration) == null ? void 0 : d.branding) == null ? void 0 : l.other) == null ? void 0 : h.buttonLabelText) || "Widget trigger", i = document.createElement("button");
|
|
669
|
+
return i.setAttribute("type", "button"), i.setAttribute("aria-label", e), i.classList.add("trigger-label"), i.addEventListener("click", this._onClicked), i.innerHTML = e, i;
|
|
670
670
|
}
|
|
671
671
|
render() {
|
|
672
|
-
var s, r, a,
|
|
672
|
+
var s, r, a, o, c, d, l;
|
|
673
673
|
this._applyBranding(), this.classList.add("bottom-right"), this.classList.toggle("active", this.active);
|
|
674
|
-
const t = (s = this.shadowRoot) == null ? void 0 : s.querySelector(".trigger-container"),
|
|
675
|
-
(r = t == null ? void 0 : t.querySelector(".trigger-label")) == null || r.remove(), t &&
|
|
676
|
-
const
|
|
677
|
-
if (
|
|
678
|
-
const h = ((l = (
|
|
679
|
-
|
|
674
|
+
const t = (s = this.shadowRoot) == null ? void 0 : s.querySelector(".trigger-container"), e = this._renderButtonLabel();
|
|
675
|
+
(r = t == null ? void 0 : t.querySelector(".trigger-label")) == null || r.remove(), t && e && t.prepend(e);
|
|
676
|
+
const i = (a = this.shadowRoot) == null ? void 0 : a.querySelector("#trigger-btn");
|
|
677
|
+
if (i) {
|
|
678
|
+
const h = ((l = (d = (c = (o = this.widget) == null ? void 0 : o.configuration) == null ? void 0 : c.branding) == null ? void 0 : d.other) == null ? void 0 : l.buttonLabelText) || "Widget trigger";
|
|
679
|
+
i.classList.toggle("active", this.active), i.classList.toggle("rendered", this.loaded), i.addEventListener("click", this._onClicked), i.setAttribute("type", "button"), i.setAttribute("aria-label", h), this.icon && i.prepend(this.icon);
|
|
680
680
|
}
|
|
681
681
|
}
|
|
682
682
|
}
|
|
@@ -703,8 +703,8 @@ class j {
|
|
|
703
703
|
}
|
|
704
704
|
}
|
|
705
705
|
const N = "https://widgets.ace.teliacompany.net/v1", k = document.createElement("template");
|
|
706
|
-
var
|
|
707
|
-
const w = (
|
|
706
|
+
var y;
|
|
707
|
+
const w = (y = document.querySelector("script[nonce]")) == null ? void 0 : y.getAttribute("nonce");
|
|
708
708
|
k.innerHTML = `<style ${w ? `nonce="${w}"` : ""}>
|
|
709
709
|
@keyframes slideDown {
|
|
710
710
|
from {
|
|
@@ -818,14 +818,14 @@ class R extends HTMLElement {
|
|
|
818
818
|
set apiUrl(t) {
|
|
819
819
|
this.trigger && (this.trigger.apiUrl = t), this.setAttribute("apiurl", t);
|
|
820
820
|
}
|
|
821
|
-
attributeChangedCallback(t,
|
|
821
|
+
attributeChangedCallback(t, e, i) {
|
|
822
822
|
this.render();
|
|
823
823
|
}
|
|
824
824
|
async connectedCallback() {
|
|
825
825
|
var t;
|
|
826
|
-
this.widget = await this._loadWidget(this.widgetId), console.log("[ACE] allowedOrigins:", (t = this.widget) == null ? void 0 : t.allowedOrigins), window.addEventListener("message", (
|
|
827
|
-
var
|
|
828
|
-
this.iframeEl && !this._isAllowedOrigin(
|
|
826
|
+
this.widget = await this._loadWidget(this.widgetId), console.log("[ACE] allowedOrigins:", (t = this.widget) == null ? void 0 : t.allowedOrigins), window.addEventListener("message", (e) => {
|
|
827
|
+
var i, s, r, a, o;
|
|
828
|
+
this.iframeEl && !this._isAllowedOrigin(e.origin) || (((i = e.data) == null ? void 0 : i.type) === "widget-set-active" ? typeof ((s = e.data.data) == null ? void 0 : s.active) == "boolean" && (this.active = e.data.data.active) : ((r = e.data) == null ? void 0 : r.type) === "widget-maximize" && ((a = e.data.data) == null ? void 0 : a.widgetId) === this.widgetId && typeof ((o = e.data.data) == null ? void 0 : o.value) == "boolean" && this.setMaximized(e.data.data.value));
|
|
829
829
|
}), this.render();
|
|
830
830
|
}
|
|
831
831
|
isActivated() {
|
|
@@ -841,11 +841,11 @@ class R extends HTMLElement {
|
|
|
841
841
|
}
|
|
842
842
|
_isAllowedOrigin(t) {
|
|
843
843
|
var s;
|
|
844
|
-
const
|
|
845
|
-
if (t ===
|
|
844
|
+
const e = new URL(this.apiUrl).origin;
|
|
845
|
+
if (t === e)
|
|
846
846
|
return !0;
|
|
847
|
-
const
|
|
848
|
-
return !
|
|
847
|
+
const i = (s = this.widget) == null ? void 0 : s.allowedOrigins;
|
|
848
|
+
return !i || i.length === 0 ? !1 : i.some((r) => t === `https://${r}`);
|
|
849
849
|
}
|
|
850
850
|
_getContainerEl() {
|
|
851
851
|
var t;
|
|
@@ -854,27 +854,27 @@ class R extends HTMLElement {
|
|
|
854
854
|
)) || null;
|
|
855
855
|
}
|
|
856
856
|
async activate() {
|
|
857
|
-
var
|
|
857
|
+
var e;
|
|
858
858
|
this.widget || (this.widget = await this._loadWidget(this.widgetId)), this._createIFrame(), this.activated = !0;
|
|
859
|
-
const t = (((
|
|
860
|
-
(
|
|
859
|
+
const t = (((e = window.ace) == null ? void 0 : e.applications) || []).find(
|
|
860
|
+
(i) => i.id === this.widgetId
|
|
861
861
|
);
|
|
862
862
|
t && (t.storage.get("open") && t.appendToDOM(), t.trigger.showTrigger()), this.render();
|
|
863
863
|
}
|
|
864
864
|
async _loadWidget(t) {
|
|
865
865
|
return await (await fetch(`${this.apiUrl}/widget/${t}`)).json();
|
|
866
866
|
}
|
|
867
|
-
dispatch(t,
|
|
867
|
+
dispatch(t, e = {}) {
|
|
868
868
|
var s;
|
|
869
|
-
const
|
|
869
|
+
const i = {
|
|
870
870
|
type: t,
|
|
871
|
-
data:
|
|
871
|
+
data: e
|
|
872
872
|
};
|
|
873
|
-
if (
|
|
874
|
-
this._messageQueue.push(
|
|
873
|
+
if (e.widgetId || (e.widgetId = this.widgetId), !this.iframeEl) {
|
|
874
|
+
this._messageQueue.push(i);
|
|
875
875
|
return;
|
|
876
876
|
}
|
|
877
|
-
(s = this.iframeEl.contentWindow) == null || s.postMessage(
|
|
877
|
+
(s = this.iframeEl.contentWindow) == null || s.postMessage(i, "*");
|
|
878
878
|
}
|
|
879
879
|
async deactivate() {
|
|
880
880
|
this.activated = !1, this.manuallyActivated = !1, this.render();
|
|
@@ -902,26 +902,26 @@ class R extends HTMLElement {
|
|
|
902
902
|
width: "100%",
|
|
903
903
|
height: "100%",
|
|
904
904
|
"border-radius": "0.7rem"
|
|
905
|
-
},
|
|
905
|
+
}, e = document.createElement("iframe");
|
|
906
906
|
Object.entries(t).forEach(([r, a]) => {
|
|
907
|
-
|
|
907
|
+
e.style.setProperty(r, a);
|
|
908
908
|
});
|
|
909
|
-
const
|
|
910
|
-
|
|
909
|
+
const i = this.apiUrl.replace("/v1", "").replace("/api", "");
|
|
910
|
+
e.src = `${i}/${this.widget.organization}/${this.widget.id}?inline=true&fullscreen=true`, e.title = this.getIFrameTitle(), e.setAttribute(
|
|
911
911
|
"allow",
|
|
912
912
|
"camera; microphone; display-capture; autoplay"
|
|
913
|
-
), this.iframeEl =
|
|
913
|
+
), this.iframeEl = e;
|
|
914
914
|
}
|
|
915
915
|
getIFrameTitle() {
|
|
916
|
-
var
|
|
917
|
-
let t = (
|
|
916
|
+
var e, i;
|
|
917
|
+
let t = (e = this.widget) == null ? void 0 : e.configuration;
|
|
918
918
|
if (typeof t == "string")
|
|
919
919
|
try {
|
|
920
920
|
t = JSON.parse(t);
|
|
921
921
|
} catch {
|
|
922
922
|
t = {};
|
|
923
923
|
}
|
|
924
|
-
return ((
|
|
924
|
+
return ((i = t == null ? void 0 : t.texts) == null ? void 0 : i["iframe.title"]) || "ACE Widget";
|
|
925
925
|
}
|
|
926
926
|
executeMessageQueue() {
|
|
927
927
|
this._messageQueue.forEach((t) => {
|
|
@@ -932,10 +932,10 @@ class R extends HTMLElement {
|
|
|
932
932
|
return this.expanded === "true";
|
|
933
933
|
}
|
|
934
934
|
toggleExpand(t) {
|
|
935
|
-
const
|
|
935
|
+
const e = this.isExpanded();
|
|
936
936
|
typeof t != "boolean" ? this.expanded = this.isExpanded() ? "false" : "true" : this.isExpanded() !== t && (this.expanded = t ? "true" : "false"), this.dispatch("set-open", {
|
|
937
937
|
value: this.isExpanded()
|
|
938
|
-
}), this.trigger && this.trigger.setActive(this.isExpanded()),
|
|
938
|
+
}), this.trigger && this.trigger.setActive(this.isExpanded()), e && !this.isExpanded() && this._onCloseCallback && this._onCloseCallback();
|
|
939
939
|
}
|
|
940
940
|
setZIndex(t) {
|
|
941
941
|
this.zIndex = t, this.render();
|
|
@@ -944,14 +944,14 @@ class R extends HTMLElement {
|
|
|
944
944
|
this.classList.toggle("ace-maximized", t), this.dispatch("set-maximized-mode", { value: t });
|
|
945
945
|
}
|
|
946
946
|
render() {
|
|
947
|
-
var
|
|
947
|
+
var i, s;
|
|
948
948
|
if (!this.iframeEl)
|
|
949
949
|
return;
|
|
950
950
|
this.isExpanded() ? (this.classList.add("ace-expanded"), this.classList.remove("ace-hidden")) : this.classList.remove("ace-expanded");
|
|
951
951
|
const t = this.activated ? "block" : "none";
|
|
952
952
|
this.iframeEl.style.setProperty("display", t), this.activated ? this.classList.add("activated") : this.classList.remove("activated");
|
|
953
|
-
const
|
|
954
|
-
|
|
953
|
+
const e = this._getContainerEl();
|
|
954
|
+
e && e.childNodes.length === 0 && e.appendChild(this.iframeEl), e && this.zIndex !== -1 && (e.style.zIndex = this.zIndex.toString()), this.trigger && ((i = this.shadowRoot) == null ? void 0 : i.querySelectorAll("ace-trigger").length) === 0 && ((s = this.shadowRoot) == null || s.insertBefore(this.trigger, this.shadowRoot.firstChild)), this.trigger && this.triggerHidden && this.trigger.hide();
|
|
955
955
|
}
|
|
956
956
|
}
|
|
957
957
|
window.customElements.get("ace-widget") || window.customElements.define("ace-widget", R);
|
package/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(h,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(h=typeof globalThis<"u"?globalThis:h||self,u(h["@telia-ace/widget-site"]={}))})(this,(function(h){"use strict";var I,T,z;class u{constructor(t){this._api=t,this._bootstrapped=!1,this._widgetAPIHandlers=new Map,window.ace=window.ace||{_c:[],_w:[],widget:function(i
|
|
1
|
+
(function(h,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(h=typeof globalThis<"u"?globalThis:h||self,u(h["@telia-ace/widget-site"]={}))})(this,(function(h){"use strict";var I,T,z;class u{constructor(t){this._api=t,this._bootstrapped=!1,this._widgetAPIHandlers=new Map,window.ace=window.ace||{_c:[],_w:[],widget:function(e,i){window.ace._w.push([e,i])},configure:function(e){window.ace._c.push(e)}}}bootstrap(){this._bootstrap()}_bootstrap(){const t=globalThis.ace;globalThis.ace=this,this._bootstrapped=!0,((t==null?void 0:t._w)||[]).forEach(([e,i])=>{this.widget(e,i)}),((t==null?void 0:t._c)||[]).forEach(e=>{this.configure(e)})}executePreloadedHandlers(t,e){const i=e?[t,e]:[t];i.flatMap(n=>this._widgetAPIHandlers.get(n)||[]).forEach(n=>{n()}),i.forEach(n=>this._widgetAPIHandlers.set(n,[]))}configure(t){if(!this._bootstrapped)throw new Error("ace environment not bootstrapped");t(this._api)}version(){return this._api.version()}widget(t,e){const i=Object.values(this._api.getWidgets()).find(s=>{var n;return((n=s.widget)==null?void 0:n.name)===t||s.widgetId===t});if(!i){const s=this._widgetAPIHandlers.get(t)||[];s.push(()=>{const n=Object.values(this._api.getWidgets()).find(a=>{var o;return((o=a.widget)==null?void 0:o.name)===t||a.widgetId===t});e(n==null?void 0:n.api)}),this._widgetAPIHandlers.set(t,s);return}e(i.api)}}const $="1.1.148-rc.2";class M{constructor(t){this._site=t}async activate(t,e){let i=this._site._widgets[t];if(i||(this._site.addWidgetEl(t),i=this._site._widgets[t]),!i){console.warn(`[ACE] Widget "${t}" not found`);return}i.manuallyActivated=!0,e!=null&&e.onClose&&(i._onCloseCallback=e.onClose),e!=null&&e.hideTrigger&&i.setTriggerVisible(!1),i.isActivated()||await i.activate()}storagePolicy(t){Object.entries(this._site._widgets).forEach(([e,i])=>{i.dispatch("set-storage-policies",{policies:t})})}disallowStorageKey(t){Object.entries(this._site._widgets).forEach(([e,i])=>{i.dispatch("disallow-storage-key",{storageKey:t})})}getWidgets(){return this._site._widgets}version(){const t=$;return{widgets:this._site.getWidgetsVersions(),sites:t}}}class W{constructor(t,e){this.triggerType=t,this.condition=e,this.triggerType=t,this.condition=e}shouldActivate(t){if(this.triggerType!=="visit"||this.condition.type!=="url")return[];const e=[];return this.condition.outputs.filter(i=>i.action.type==="render_widget"&&U(i.value,t)).forEach(i=>{let s={widgetId:""};try{s=JSON.parse(i.action.data)}catch{s={widgetId:""}}e.push(s.widgetId)}),e}}const U=(r,t)=>{if(r==="*"||r==="/*"||r===t)return!0;if(r.endsWith("/*")){const s=r.slice(0,-2);return t===s||t.startsWith(s+"/")}return!1},B=(r,t)=>{const e=s=>`ace_${r.substring(0,7)}-${s}`;return Object.entries(t).reduce((s,[n,a])=>{const[o,c]=n.split("-");if(e(c)!=n)return s;try{const d=JSON.parse(a);s[c]=d.value}catch{return s}return s},{})},m="https://widgets.ace.teliacompany.net/v1",H="https://embed.webprovisions.io",O=()=>{if(typeof window<"u"){const r=history.pushState,t=history.replaceState;history.pushState=function(...e){r.apply(history,e),window.dispatchEvent(new Event("locationchange"))},history.replaceState=function(...e){t.apply(history,e),window.dispatchEvent(new Event("locationchange"))}}};class w extends HTMLElement{constructor(){var t;super(),this._site=null,this._widgets={},this._loadedVersions={},this._path=((t=window==null?void 0:window.location)==null?void 0:t.pathname)||"",this._api=new M(this),this._environment=new u(this._api),this.routeChangeListener=()=>{this._path=window.location.pathname,this.render()},this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["siteid","apiurl","embedurl"]}get siteId(){return this.getAttribute("siteid")||""}set siteId(t){this.setAttribute("siteid",t)}get apiUrl(){return this.getAttribute("apiurl")||m}set apiUrl(t){this.setAttribute("apiurl",t)}get embedUrl(){return this.getAttribute("embedurl")||H}set embedUrl(t){this.setAttribute("embedurl",t)}async connectedCallback(){O(),await this._loadSite(),this.render(),this._environment.bootstrap(),window.addEventListener("locationchange",this.routeChangeListener),window.addEventListener("message",t=>{var s,n;const{type:e,data:i}=t.data;if(e==="widget-minimize")this._widgets[i.widgetId].toggleExpand();else if(e==="widget-maximize")(s=this._widgets[i.widgetId])==null||s.setMaximized(i.value);else if(e==="widget-activated"){this._widgets[i.widgetId].executeMessageQueue();const a=this._widgets[i.widgetId];a&&(this._loadedVersions[i.widgetId]=i.version,this._environment.executePreloadedHandlers(((n=a.widget)==null?void 0:n.name)||"",i.widgetId));try{const o=JSON.parse(i.storage),c=B(i.widgetId,o);typeof c.open=="boolean"&&(a.disableAnimations(),a.toggleExpand(c.open),setTimeout(()=>{a.enableAnimations()},600))}catch{console.warn("unable to parse widget storage")}}})}disconnectedCallback(){window.removeEventListener("locationchange",this.routeChangeListener)}attributeChangedCallback(t,e,i){this.render()}async _loadSite(){var s;const e=await(await fetch(`${this.apiUrl}/site/${this.siteId}`)).json(),i=location.hostname;if(!((e==null?void 0:e.hosts)||[]).includes(i)){console.warn(`the host "${i}" needs to be configured as an allowed host in order to install widgets.`);return}this._site=e,this._site&&(this._site.triggers=this._site.triggers.map(n=>new W(n.triggerType,n.condition))),(((s=this._site)==null?void 0:s.widgets)||[]).forEach(async n=>{this.addWidgetEl(n.id)})}addWidgetEl(t){const e=`ace-widget_${t}`;let i=document.getElementById(e);i||(i=document.createElement("ace-widget"),i.id=e,i.widgetId=t,this.apiUrl!==m&&(i.apiUrl=this.apiUrl),document.body.appendChild(i)),this._widgets={...this._widgets,[t]:i}}getWidgetsVersions(){return this._loadedVersions}render(){if(!this._site){this.shadow.innerHTML="";return}const t=P(this._site);for(const[e,i]of Object.entries(this._widgets)){if(i.manuallyActivated)continue;const s=t.find(n=>n.id===e);s&&!i.isActivated()?i.activate():!s&&i.isActivated()&&i.deactivate()}this.shadow.innerHTML=""}}window.customElements.get("ace-site")||window.customElements.define("ace-site",w);const P=r=>{const t=window.location.pathname;return r.triggers.reduce((i,s)=>(s.shouldActivate(t).forEach(a=>{const o=i.find(d=>d.id===a),c=((r==null?void 0:r.widgets)||[]).find(d=>d.id===a);!o&&c&&i.push({id:a})}),i),[])},g=(r,t,e)=>{r&&e.style.setProperty(t,r)},V=(r,t)=>{var e,i,s,n,a,o,c,d,l;g((e=r.colors)==null?void 0:e.primaryBackground,"--primary-background",t),g((i=r.colors)==null?void 0:i.textOnPrimaryBackground,"--text-on-primary-background",t),g((s=r.colors)==null?void 0:s.secondaryBackground,"--secondary-background",t),g((n=r.colors)==null?void 0:n.textOnSecondaryBackground,"--text-on-secondary-background",t),g((a=r.colors)==null?void 0:a.interactiveDestructiveBackground,"--destructive-color",t),g((o=r.colors)==null?void 0:o.interactiveTextOnDestructiveBackground,"--text-on-destructive-color",t),g((c=r.colors)==null?void 0:c.interactivePrimaryBackground,"--interactive-primary-background",t),g((d=r.colors)==null?void 0:d.interactiveTextOnPrimaryBackground,"--interactive-text-on-primary-background",t),g((l=r.colors)==null?void 0:l.focusColor,"--focus-color",t)},j=(r={})=>{const{content:t="",title:e,attributes:i=[]}=r;let s="";const n=[{name:"xmlns",value:"http://www.w3.org/2000/svg"},{name:"fill",value:"currentColor"},...i];return e&&(s=`<title>${e}</title>`),`<svg ${n.map(o=>`${o.name}="${o.value}"`).join(" ")}>${s}${t}</svg>`},f=document.createElement("template");f.innerHTML=`<span
|
|
2
2
|
class="ace-icon__container"
|
|
3
3
|
></span>`;const b=document.createElement("template"),y=(I=document.querySelector("script[nonce]"))==null?void 0:I.getAttribute("nonce");b.innerHTML=`<style ${y?`nonce="${y}"`:""}>
|
|
4
4
|
:host {
|
|
@@ -34,7 +34,7 @@ svg {
|
|
|
34
34
|
min-width: var(--size-lg);
|
|
35
35
|
width: var(--size-lg);
|
|
36
36
|
}
|
|
37
|
-
</style>`;class v extends HTMLElement{get svg(){return this.getAttribute("svg")||""}set svg(t){this.setAttribute("svg",t)}get size(){return this.getAttribute("size")||""}set size(t){this.setAttribute("size",t),this.classList.remove("ace-icon--sm","ace-icon--md","ace--icon-lg"),this.classList.add(`ace-icon--${t}`)}static get observedAttributes(){return["svg","size"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(b.content.cloneNode(!0)),this.shadow.appendChild(f.content.cloneNode(!0))}attributeChangedCallback(t,i
|
|
37
|
+
</style>`;class v extends HTMLElement{get svg(){return this.getAttribute("svg")||""}set svg(t){this.setAttribute("svg",t)}get size(){return this.getAttribute("size")||""}set size(t){this.setAttribute("size",t),this.classList.remove("ace-icon--sm","ace-icon--md","ace--icon-lg"),this.classList.add(`ace-icon--${t}`)}static get observedAttributes(){return["svg","size"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(b.content.cloneNode(!0)),this.shadow.appendChild(f.content.cloneNode(!0))}attributeChangedCallback(t,e,i){this.render()}render(){var e;const t=(e=this.shadowRoot)==null?void 0:e.querySelector(".ace-icon__container");if(t){const i=j({content:this.svg,attributes:[{name:"viewBox",value:"0 0 64 64"}],title:void 0});t.innerHTML=i}}}window.customElements.get("ace-icon")||window.customElements.define("ace-icon",v);const N={name:"question",svg:'<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M32 4C16.536 4 4 16.536 4 32C4 47.464 16.536 60 32 60C47.464 60 60 47.464 60 32C59.9827 16.5432 47.4568 4.01731 32 4ZM32 55.6923C18.9151 55.6923 8.30769 45.0849 8.30769 32C8.30769 18.9151 18.9151 8.30769 32 8.30769C45.0849 8.30769 55.6923 18.9151 55.6923 32C55.6775 45.0788 45.0788 55.6775 32 55.6923Z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M31.9423 37.5723L36.311 32.9068L36.7354 32.4448C39.7555 29.1161 40.7645 27.0647 40.7645 24.5087C40.7645 23.1091 40.4251 21.7942 39.7041 20.6491C38.3044 18.3587 35.6323 16.9166 32.2816 16.9166C28.7565 16.9166 25.3125 18.7414 23.2581 21.6772L23.1201 21.8791C22.8232 22.3032 22.696 22.6849 22.696 22.9818C22.696 23.7029 23.926 25.9932 25.2833 25.9932C25.5378 25.9932 25.7922 25.9084 26.0467 25.7388C26.2588 25.5691 26.5981 25.2298 27.0647 24.7208C28.8885 22.6849 30.1185 21.9215 31.7726 21.9215C33.6813 21.9215 35.081 23.1939 35.081 24.8905C35.081 26.375 34.2751 27.7746 32.3664 29.8529L28.2523 34.2216C27.9554 34.6033 27.7857 34.9426 27.7857 35.282C27.7857 35.6213 27.9978 36.1726 28.4219 36.8937C29.0581 37.8692 29.7368 38.3782 30.4578 38.3782C30.9244 38.3782 31.3909 38.1237 31.9423 37.5723ZM30.882 47.4972C29.2278 47.4972 27.6585 44.7403 27.6585 43.6799C27.6585 42.1954 30.0761 40.6261 32.4089 40.6261C33.6389 40.6261 34.2751 41.1775 34.2751 42.3227C34.2751 44.0616 33.4692 45.843 32.4513 46.7761C31.9423 47.2427 31.4334 47.4972 30.882 47.4972Z"/></svg>'},_=document.createElement("template"),x=(T=document.querySelector("script[nonce]"))==null?void 0:T.getAttribute("nonce");_.innerHTML=`<style ${x?`nonce="${x}"`:""}>
|
|
38
38
|
:host {
|
|
39
39
|
position: fixed;
|
|
40
40
|
display: flex;
|
|
@@ -209,7 +209,7 @@ svg {
|
|
|
209
209
|
</svg>
|
|
210
210
|
</span>
|
|
211
211
|
</button>
|
|
212
|
-
</div>`;class C extends HTMLElement{constructor(){super(),this.widget=null,this.loaded=!1,this.active=!1,this._onClicked=()=>{this.active=!this.active;const t={detail:{widgetId:this.widgetId},bubbles:!0,composed:!0};this.dispatchEvent(new CustomEvent("toggle",t)),this.render()},this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(_.content.cloneNode(!0)),this.shadow.appendChild(E.content.cloneNode(!0))}static get observedAttributes(){return["widgetid","apiurl"]}get widgetId(){return this.getAttribute("widgetid")||""}set widgetId(t){this.setAttribute("widgetid",t)}get apiUrl(){return this.getAttribute("apiurl")||""}set apiUrl(t){this.setAttribute("apiurl",t)}async connectedCallback(){this.widget=await this._loadWidget(this.widgetId),this.icon=await this._renderSymbol(),this.loaded=!0,this.render()}attributeChangedCallback(t,i
|
|
212
|
+
</div>`;class C extends HTMLElement{constructor(){super(),this.widget=null,this.loaded=!1,this.active=!1,this._onClicked=()=>{this.active=!this.active;const t={detail:{widgetId:this.widgetId},bubbles:!0,composed:!0};this.dispatchEvent(new CustomEvent("toggle",t)),this.render()},this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(_.content.cloneNode(!0)),this.shadow.appendChild(E.content.cloneNode(!0))}static get observedAttributes(){return["widgetid","apiurl"]}get widgetId(){return this.getAttribute("widgetid")||""}set widgetId(t){this.setAttribute("widgetid",t)}get apiUrl(){return this.getAttribute("apiurl")||""}set apiUrl(t){this.setAttribute("apiurl",t)}async connectedCallback(){this.widget=await this._loadWidget(this.widgetId),this.icon=await this._renderSymbol(),this.loaded=!0,this.render()}attributeChangedCallback(t,e,i){this.render()}setActive(t){this.active=t,this.render()}_applyBranding(){var t,e;(e=(t=this.widget)==null?void 0:t.configuration)!=null&&e.branding&&V(this.widget.configuration.branding,this)}async _loadWidget(t){const i=await(await fetch(`${this.apiUrl}/widget/${t}`)).json(),s=JSON.parse(i.configuration);return{...i,configuration:s}}async _renderSymbol(){var a,o,c;const t=(o=(a=this.widget)==null?void 0:a.configuration)==null?void 0:o.branding,e=(c=t==null?void 0:t.graphics)==null?void 0:c.trigger;if(e){const d=document.createElement("img");return d.src=e,d.classList.add("trigger-icon"),d.alt="",d}const i={type:"Telia"},s=async d=>N,{type:n}=i;switch(n){case"Telia":{const d=await s();if(d){const l=document.createElement("ace-icon");return l.classList.add("trigger-icon"),l.svg=d.svg,l.size="lg",l}return null}default:return null}}toggle(){this._onClicked()}hide(){this.classList.add("ace-hidden"),this.style.display="none"}show(){this.classList.remove("ace-hidden"),this.style.display=""}_renderButtonLabel(){var s,n,a,o,c,d,l,p;if(!(((o=(a=(n=(s=this.widget)==null?void 0:s.configuration)==null?void 0:n.branding)==null?void 0:a.other)==null?void 0:o.showButtonLabel)||!1))return null;const e=((p=(l=(d=(c=this.widget)==null?void 0:c.configuration)==null?void 0:d.branding)==null?void 0:l.other)==null?void 0:p.buttonLabelText)||"Widget trigger",i=document.createElement("button");return i.setAttribute("type","button"),i.setAttribute("aria-label",e),i.classList.add("trigger-label"),i.addEventListener("click",this._onClicked),i.innerHTML=e,i}render(){var s,n,a,o,c,d,l;this._applyBranding(),this.classList.add("bottom-right"),this.classList.toggle("active",this.active);const t=(s=this.shadowRoot)==null?void 0:s.querySelector(".trigger-container"),e=this._renderButtonLabel();(n=t==null?void 0:t.querySelector(".trigger-label"))==null||n.remove(),t&&e&&t.prepend(e);const i=(a=this.shadowRoot)==null?void 0:a.querySelector("#trigger-btn");if(i){const p=((l=(d=(c=(o=this.widget)==null?void 0:o.configuration)==null?void 0:c.branding)==null?void 0:d.other)==null?void 0:l.buttonLabelText)||"Widget trigger";i.classList.toggle("active",this.active),i.classList.toggle("rendered",this.loaded),i.addEventListener("click",this._onClicked),i.setAttribute("type","button"),i.setAttribute("aria-label",p),this.icon&&i.prepend(this.icon)}}}window.customElements.get("ace-trigger")||window.customElements.define("ace-trigger",C),window.customElements.get("ace-icon")||window.customElements.define("ace-icon",v);class R{constructor(t){this.widgetEl=t}open(){this.widgetEl.toggleExpand(!0)}close(){this.widgetEl.toggleExpand(!1)}onClose(t){this.widgetEl._onCloseCallback=t}setZIndex(t){this.widgetEl.setZIndex(t)}setFullscreenMode(t){this.widgetEl.dispatch("set-fullscreen-mode",{value:t})}}const q="https://widgets.ace.teliacompany.net/v1",A=document.createElement("template"),k=(z=document.querySelector("script[nonce]"))==null?void 0:z.getAttribute("nonce");A.innerHTML=`<style ${k?`nonce="${k}"`:""}>
|
|
213
213
|
@keyframes slideDown {
|
|
214
214
|
from {
|
|
215
215
|
transform: translateY(0);
|
|
@@ -292,4 +292,4 @@ svg {
|
|
|
292
292
|
animation: slideDown 0.3s linear;
|
|
293
293
|
display: none;
|
|
294
294
|
}
|
|
295
|
-
</style>`;const L=document.createElement("template");L.innerHTML='<div class="widget-frame-container"></div>';class S extends HTMLElement{constructor(){super(),this.widget=null,this.activated=!1,this.manuallyActivated=!1,this.triggerHidden=!1,this.active=!1,this.iframeEl=null,this.trigger=null,this._messageQueue=[],this._onCloseCallback=null,this.api=new R(this),this.zIndex=-1,this.trigger=document.createElement("ace-trigger"),this.trigger.widgetId=this.widgetId,this.trigger.apiUrl=this.apiUrl,this.trigger.id=`ace-trigger_${this.widgetId}`,this.trigger.addEventListener("toggle",t=>{this.toggleExpand()}),this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(A.content.cloneNode(!0)),this.shadow.appendChild(L.content.cloneNode(!0))}static get observedAttributes(){return["widgetid","apiurl","expanded"]}get expanded(){return this.getAttribute("expanded")||"false"}set expanded(t){this.setAttribute("expanded",t),t==="false"&&this.classList.toggle("ace-hidden",!0)}get widgetId(){return this.getAttribute("widgetid")||""}set widgetId(t){this.trigger&&(this.trigger.widgetId=t,this.trigger.id=`ace-trigger_${t}`),this.setAttribute("widgetid",t)}get apiUrl(){return this.getAttribute("apiurl")||q}set apiUrl(t){this.trigger&&(this.trigger.apiUrl=t),this.setAttribute("apiurl",t)}attributeChangedCallback(t,i
|
|
295
|
+
</style>`;const L=document.createElement("template");L.innerHTML='<div class="widget-frame-container"></div>';class S extends HTMLElement{constructor(){super(),this.widget=null,this.activated=!1,this.manuallyActivated=!1,this.triggerHidden=!1,this.active=!1,this.iframeEl=null,this.trigger=null,this._messageQueue=[],this._onCloseCallback=null,this.api=new R(this),this.zIndex=-1,this.trigger=document.createElement("ace-trigger"),this.trigger.widgetId=this.widgetId,this.trigger.apiUrl=this.apiUrl,this.trigger.id=`ace-trigger_${this.widgetId}`,this.trigger.addEventListener("toggle",t=>{this.toggleExpand()}),this.shadow=this.attachShadow({mode:"open"}),this.shadow.appendChild(A.content.cloneNode(!0)),this.shadow.appendChild(L.content.cloneNode(!0))}static get observedAttributes(){return["widgetid","apiurl","expanded"]}get expanded(){return this.getAttribute("expanded")||"false"}set expanded(t){this.setAttribute("expanded",t),t==="false"&&this.classList.toggle("ace-hidden",!0)}get widgetId(){return this.getAttribute("widgetid")||""}set widgetId(t){this.trigger&&(this.trigger.widgetId=t,this.trigger.id=`ace-trigger_${t}`),this.setAttribute("widgetid",t)}get apiUrl(){return this.getAttribute("apiurl")||q}set apiUrl(t){this.trigger&&(this.trigger.apiUrl=t),this.setAttribute("apiurl",t)}attributeChangedCallback(t,e,i){this.render()}async connectedCallback(){var t;this.widget=await this._loadWidget(this.widgetId),console.log("[ACE] allowedOrigins:",(t=this.widget)==null?void 0:t.allowedOrigins),window.addEventListener("message",e=>{var i,s,n,a,o;this.iframeEl&&!this._isAllowedOrigin(e.origin)||(((i=e.data)==null?void 0:i.type)==="widget-set-active"?typeof((s=e.data.data)==null?void 0:s.active)=="boolean"&&(this.active=e.data.data.active):((n=e.data)==null?void 0:n.type)==="widget-maximize"&&((a=e.data.data)==null?void 0:a.widgetId)===this.widgetId&&typeof((o=e.data.data)==null?void 0:o.value)=="boolean"&&this.setMaximized(e.data.data.value))}),this.render()}isActivated(){return this.activated}disableAnimations(){const t=this._getContainerEl();t&&(t.style.animationDuration="0ms")}enableAnimations(){const t=this._getContainerEl();t&&(t.style.animationDuration="300ms")}_isAllowedOrigin(t){var s;const e=new URL(this.apiUrl).origin;if(t===e)return!0;const i=(s=this.widget)==null?void 0:s.allowedOrigins;return!i||i.length===0?!1:i.some(n=>t===`https://${n}`)}_getContainerEl(){var t;return((t=this.shadowRoot)==null?void 0:t.querySelector(".widget-frame-container"))||null}async activate(){var e;this.widget||(this.widget=await this._loadWidget(this.widgetId)),this._createIFrame(),this.activated=!0;const t=(((e=window.ace)==null?void 0:e.applications)||[]).find(i=>i.id===this.widgetId);t&&(t.storage.get("open")&&t.appendToDOM(),t.trigger.showTrigger()),this.render()}async _loadWidget(t){return await(await fetch(`${this.apiUrl}/widget/${t}`)).json()}dispatch(t,e={}){var s;const i={type:t,data:e};if(e.widgetId||(e.widgetId=this.widgetId),!this.iframeEl){this._messageQueue.push(i);return}(s=this.iframeEl.contentWindow)==null||s.postMessage(i,"*")}async deactivate(){this.activated=!1,this.manuallyActivated=!1,this.render()}setTriggerVisible(t){this.triggerHidden=!t,this.trigger&&(t?this.trigger.show():this.trigger.hide())}_createIFrame(){var s;if(!((s=this.widget)!=null&&s.distributionName)||this.iframeEl||!this.widget.linked)return;const t={display:"block",border:"none",opacity:"1","color-scheme":"none",background:"none transparent !important",margin:"0px","max-height":"100%","max-width":"100vw",transform:"translateY(0px)",transition:"none 0s ease 0s !important",visibility:"visible","z-index":"999999999 !important",width:"100%",height:"100%","border-radius":"0.7rem"},e=document.createElement("iframe");Object.entries(t).forEach(([n,a])=>{e.style.setProperty(n,a)});const i=this.apiUrl.replace("/v1","").replace("/api","");e.src=`${i}/${this.widget.organization}/${this.widget.id}?inline=true&fullscreen=true`,e.title=this.getIFrameTitle(),e.setAttribute("allow","camera; microphone; display-capture; autoplay"),this.iframeEl=e}getIFrameTitle(){var e,i;let t=(e=this.widget)==null?void 0:e.configuration;if(typeof t=="string")try{t=JSON.parse(t)}catch{t={}}return((i=t==null?void 0:t.texts)==null?void 0:i["iframe.title"])||"ACE Widget"}executeMessageQueue(){this._messageQueue.forEach(t=>{this.dispatch(t.type,t.data)}),this._messageQueue=[]}isExpanded(){return this.expanded==="true"}toggleExpand(t){const e=this.isExpanded();typeof t!="boolean"?this.expanded=this.isExpanded()?"false":"true":this.isExpanded()!==t&&(this.expanded=t?"true":"false"),this.dispatch("set-open",{value:this.isExpanded()}),this.trigger&&this.trigger.setActive(this.isExpanded()),e&&!this.isExpanded()&&this._onCloseCallback&&this._onCloseCallback()}setZIndex(t){this.zIndex=t,this.render()}setMaximized(t){this.classList.toggle("ace-maximized",t),this.dispatch("set-maximized-mode",{value:t})}render(){var i,s;if(!this.iframeEl)return;this.isExpanded()?(this.classList.add("ace-expanded"),this.classList.remove("ace-hidden")):this.classList.remove("ace-expanded");const t=this.activated?"block":"none";this.iframeEl.style.setProperty("display",t),this.activated?this.classList.add("activated"):this.classList.remove("activated");const e=this._getContainerEl();e&&e.childNodes.length===0&&e.appendChild(this.iframeEl),e&&this.zIndex!==-1&&(e.style.zIndex=this.zIndex.toString()),this.trigger&&((i=this.shadowRoot)==null?void 0:i.querySelectorAll("ace-trigger").length)===0&&((s=this.shadowRoot)==null||s.insertBefore(this.trigger,this.shadowRoot.firstChild)),this.trigger&&this.triggerHidden&&this.trigger.hide()}}window.customElements.get("ace-widget")||window.customElements.define("ace-widget",S),window.customElements.get("ace-trigger")||window.customElements.define("ace-trigger",C),h.SiteComponent=w,h.WidgetComponent=S,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|