@telia-ace/widget-site 1.1.123-rc.24 → 1.1.123-rc.26
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 +7 -7
- package/index.mjs +9 -9
- package/index.umd.js +7 -7
- 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(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){(this._widgetAPIHandlers.get(t)||[]).forEach(i=>{i()}),this._widgetAPIHandlers.set(t,[])}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});if(!i){const s=this._widgetAPIHandlers.get(t)||[];s.push(()=>{const r=Object.values(this._api.getWidgets()).find(a=>{var d;return((d=a.widget)==null?void 0:d.name)===t});e(r==null?void 0:r.api)}),this._widgetAPIHandlers.set(t,s);return}e(i.api)}}const $="1.1.123-rc.
|
|
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){(this._widgetAPIHandlers.get(t)||[]).forEach(i=>{i()}),this._widgetAPIHandlers.set(t,[])}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});if(!i){const s=this._widgetAPIHandlers.get(t)||[];s.push(()=>{const r=Object.values(this._api.getWidgets()).find(a=>{var d;return((d=a.widget)==null?void 0:d.name)===t});e(r==null?void 0:r.api)}),this._widgetAPIHandlers.set(t,s);return}e(i.api)}}const $="1.1.123-rc.26";class z{constructor(t){this._site=t}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 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"&&B(i.value,t)).forEach(i=>{let s={widgetId:""};try{s=JSON.parse(i.action.data)}catch{s={widgetId:""}}e.push(s.widgetId)}),e}}const B=(n,t)=>{if(n==="*"||n==="/*"||n===t)return!0;if(n.endsWith("/*")){const s=n.slice(0,-2);return t.startsWith(s)}return!1},W=(n,t)=>{const e=s=>`ace_${n.substring(0,7)}-${s}`;return Object.entries(t).reduce((s,[r,a])=>{const[d,c]=r.split("-");if(e(c)!=r)return s;try{const o=JSON.parse(a);s[c]=o.value}catch{return s}return s},{})},u="https://widgets.ace.teliacompany.net/v1",U="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 y 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 z(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")||U}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;const{type:e,data:i}=t.data;if(e==="widget-minimize")this._widgets[i.widgetId].toggleExpand();else if(e==="widget-activated"){this._widgets[i.widgetId].executeMessageQueue();const r=this._widgets[i.widgetId];r&&(this._loadedVersions[i.widgetId]=i.version,this._environment.executePreloadedHandlers(((s=r.widget)==null?void 0:s.name)||""));try{const a=JSON.parse(i.storage),d=W(i.widgetId,a);typeof d.open=="boolean"&&(r.disableAnimations(),r.toggleExpand(d.open),setTimeout(()=>{r.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)){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",y);const O=n=>{const t=window.location.pathname;return n.triggers.reduce((i,s)=>(s.shouldActivate(t).forEach(a=>{const d=i.find(o=>o.id===a),c=((n==null?void 0:n.widgets)||[]).find(o=>o.id===a);!d&&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,d,c,o,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((d=n.colors)==null?void 0:d.interactiveTextOnDestructiveBackground,"--text-on-destructive-color",t),g((c=n.colors)==null?void 0:c.interactivePrimaryBackground,"--interactive-primary-background",t),g((o=n.colors)==null?void 0:o.interactiveTextOnPrimaryBackground,"--interactive-text-on-primary-background",t),g((l=n.colors)==null?void 0:l.focusColor,"--focus-color",t)},j=(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(d=>`${d.name}="${d.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 {
|
|
@@ -60,7 +60,7 @@ svg {
|
|
|
60
60
|
bottom: 20px;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
:host(.hidden) {
|
|
63
|
+
:host(.ace-hidden) {
|
|
64
64
|
display: none;
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -209,7 +209,7 @@ svg {
|
|
|
209
209
|
</svg>
|
|
210
210
|
</span>
|
|
211
211
|
</button>
|
|
212
|
-
</div>`;class L 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,d,c;const t=(d=(a=this.widget)==null?void 0:a.configuration)==null?void 0:d.branding,e=(c=t==null?void 0:t.graphics)==null?void 0:c.trigger;if(e){const o=document.createElement("img");return o.src=e,o.classList.add("trigger-icon"),o.alt="",o}const i={type:"Telia"},s=async o=>V,{type:r}=i;switch(r){case"Telia":{const o=await s();if(o){const l=document.createElement("ace-icon");return l.classList.add("trigger-icon"),l.svg=o.svg,l.size="lg",l}return null}default:return null}}toggle(){this._onClicked()}hide(){this.classList.add("hidden")}show(){this.classList.remove("hidden")}_renderButtonLabel(){var s,r,a,d,c,o,l,h;if(!(((d=(a=(r=(s=this.widget)==null?void 0:s.configuration)==null?void 0:r.branding)==null?void 0:a.other)==null?void 0:d.showButtonLabel)||!1))return null;const e=((h=(l=(o=(c=this.widget)==null?void 0:c.configuration)==null?void 0:o.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,d,c,o,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=(o=(c=(d=this.widget)==null?void 0:d.configuration)==null?void 0:c.branding)==null?void 0:o.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",L);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)}setZIndex(t){this.widgetEl.setZIndex(t)}setFullscreenMode(t){this.widgetEl.dispatch("set-fullscreen-mode",{value:t})}}const R="https://widgets.ace.teliacompany.net/v1",k=document.createElement("template");var v;const w=(v=document.querySelector("script[nonce]"))==null?void 0:v.getAttribute("nonce");k.innerHTML=`<style ${w?`nonce="${w}"`:""}>
|
|
212
|
+
</div>`;class L 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,d,c;const t=(d=(a=this.widget)==null?void 0:a.configuration)==null?void 0:d.branding,e=(c=t==null?void 0:t.graphics)==null?void 0:c.trigger;if(e){const o=document.createElement("img");return o.src=e,o.classList.add("trigger-icon"),o.alt="",o}const i={type:"Telia"},s=async o=>V,{type:r}=i;switch(r){case"Telia":{const o=await s();if(o){const l=document.createElement("ace-icon");return l.classList.add("trigger-icon"),l.svg=o.svg,l.size="lg",l}return null}default:return null}}toggle(){this._onClicked()}hide(){this.classList.add("ace-hidden")}show(){this.classList.remove("ace-hidden")}_renderButtonLabel(){var s,r,a,d,c,o,l,h;if(!(((d=(a=(r=(s=this.widget)==null?void 0:s.configuration)==null?void 0:r.branding)==null?void 0:a.other)==null?void 0:d.showButtonLabel)||!1))return null;const e=((h=(l=(o=(c=this.widget)==null?void 0:c.configuration)==null?void 0:o.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,d,c,o,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=(o=(c=(d=this.widget)==null?void 0:d.configuration)==null?void 0:c.branding)==null?void 0:o.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",L);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)}setZIndex(t){this.widgetEl.setZIndex(t)}setFullscreenMode(t){this.widgetEl.dispatch("set-fullscreen-mode",{value:t})}}const R="https://widgets.ace.teliacompany.net/v1",k=document.createElement("template");var v;const w=(v=document.querySelector("script[nonce]"))==null?void 0:v.getAttribute("nonce");k.innerHTML=`<style ${w?`nonce="${w}"`:""}>
|
|
213
213
|
@keyframes slideDown {
|
|
214
214
|
from {
|
|
215
215
|
transform: translateY(0);
|
|
@@ -252,7 +252,7 @@ svg {
|
|
|
252
252
|
box-shadow: rgba(0, 0, 0, 0.16) 0px 5px 40px;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
:host(.expanded.activated) .widget-frame-container {
|
|
255
|
+
:host(.ace-expanded.activated) .widget-frame-container {
|
|
256
256
|
pointer-events: all;
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -273,14 +273,14 @@ svg {
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
:host(.expanded) .widget-frame-container {
|
|
276
|
+
:host(.ace-expanded) .widget-frame-container {
|
|
277
277
|
opacity: 1;
|
|
278
278
|
animation: slideUp 0.3s linear;
|
|
279
279
|
display: block;
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
:host(.hidden) .widget-frame-container {
|
|
282
|
+
:host(.ace-hidden) .widget-frame-container {
|
|
283
283
|
animation: slideDown 0.3s linear;
|
|
284
284
|
display: none;
|
|
285
285
|
}
|
|
286
|
-
</style>`;const I=document.createElement("template");I.innerHTML='<div class="widget-frame-container"></div>';class S extends HTMLElement{constructor(){super(),this.widget=null,this.activated=!1,this.active=!1,this.iframeEl=null,this.trigger=null,this._messageQueue=[],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(k.content.cloneNode(!0)),this.shadow.appendChild(I.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("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(){this.widget=await this._loadWidget(this.widgetId),window.addEventListener("message",t=>{var e,i;((e=t.data)==null?void 0:e.type)==="widget-set-active"&&typeof((i=t.data.data)==null?void 0:i.active)=="boolean"&&(this.active=t.data.data.active)}),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")}_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.render()}_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;"),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){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())}setZIndex(t){this.zIndex=t,this.render()}render(){var i,s;if(!this.iframeEl)return;this.isExpanded()?(this.classList.add("expanded"),this.classList.remove("hidden")):this.classList.remove("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))}}window.customElements.get("ace-widget")||window.customElements.define("ace-widget",S);window.customElements.get("ace-trigger")||window.customElements.define("ace-trigger",L);exports.SiteComponent=y;exports.WidgetComponent=S;
|
|
286
|
+
</style>`;const I=document.createElement("template");I.innerHTML='<div class="widget-frame-container"></div>';class S extends HTMLElement{constructor(){super(),this.widget=null,this.activated=!1,this.active=!1,this.iframeEl=null,this.trigger=null,this._messageQueue=[],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(k.content.cloneNode(!0)),this.shadow.appendChild(I.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(){this.widget=await this._loadWidget(this.widgetId),window.addEventListener("message",t=>{var e,i;((e=t.data)==null?void 0:e.type)==="widget-set-active"&&typeof((i=t.data.data)==null?void 0:i.active)=="boolean"&&(this.active=t.data.data.active)}),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")}_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.render()}_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;"),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){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())}setZIndex(t){this.zIndex=t,this.render()}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))}}window.customElements.get("ace-widget")||window.customElements.define("ace-widget",S);window.customElements.get("ace-trigger")||window.customElements.define("ace-trigger",L);exports.SiteComponent=y;exports.WidgetComponent=S;
|
package/index.mjs
CHANGED
|
@@ -58,7 +58,7 @@ class I {
|
|
|
58
58
|
e(i.api);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
const S = "1.1.123-rc.
|
|
61
|
+
const S = "1.1.123-rc.26";
|
|
62
62
|
class T {
|
|
63
63
|
constructor(t) {
|
|
64
64
|
this._site = t;
|
|
@@ -412,7 +412,7 @@ E.innerHTML = `<style ${m ? `nonce="${m}"` : ""}>
|
|
|
412
412
|
bottom: 20px;
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
-
:host(.hidden) {
|
|
415
|
+
:host(.ace-hidden) {
|
|
416
416
|
display: none;
|
|
417
417
|
}
|
|
418
418
|
|
|
@@ -640,10 +640,10 @@ class A extends HTMLElement {
|
|
|
640
640
|
this._onClicked();
|
|
641
641
|
}
|
|
642
642
|
hide() {
|
|
643
|
-
this.classList.add("hidden");
|
|
643
|
+
this.classList.add("ace-hidden");
|
|
644
644
|
}
|
|
645
645
|
show() {
|
|
646
|
-
this.classList.remove("hidden");
|
|
646
|
+
this.classList.remove("ace-hidden");
|
|
647
647
|
}
|
|
648
648
|
_renderButtonLabel() {
|
|
649
649
|
var s, r, a, d, c, o, l, h;
|
|
@@ -729,7 +729,7 @@ L.innerHTML = `<style ${w ? `nonce="${w}"` : ""}>
|
|
|
729
729
|
box-shadow: rgba(0, 0, 0, 0.16) 0px 5px 40px;
|
|
730
730
|
}
|
|
731
731
|
|
|
732
|
-
:host(.expanded.activated) .widget-frame-container {
|
|
732
|
+
:host(.ace-expanded.activated) .widget-frame-container {
|
|
733
733
|
pointer-events: all;
|
|
734
734
|
}
|
|
735
735
|
|
|
@@ -750,13 +750,13 @@ L.innerHTML = `<style ${w ? `nonce="${w}"` : ""}>
|
|
|
750
750
|
}
|
|
751
751
|
}
|
|
752
752
|
|
|
753
|
-
:host(.expanded) .widget-frame-container {
|
|
753
|
+
:host(.ace-expanded) .widget-frame-container {
|
|
754
754
|
opacity: 1;
|
|
755
755
|
animation: slideUp 0.3s linear;
|
|
756
756
|
display: block;
|
|
757
757
|
}
|
|
758
758
|
|
|
759
|
-
:host(.hidden) .widget-frame-container {
|
|
759
|
+
:host(.ace-hidden) .widget-frame-container {
|
|
760
760
|
animation: slideDown 0.3s linear;
|
|
761
761
|
display: none;
|
|
762
762
|
}
|
|
@@ -776,7 +776,7 @@ class R extends HTMLElement {
|
|
|
776
776
|
return this.getAttribute("expanded") || "false";
|
|
777
777
|
}
|
|
778
778
|
set expanded(t) {
|
|
779
|
-
this.setAttribute("expanded", t), t === "false" && this.classList.toggle("hidden", !0);
|
|
779
|
+
this.setAttribute("expanded", t), t === "false" && this.classList.toggle("ace-hidden", !0);
|
|
780
780
|
}
|
|
781
781
|
get widgetId() {
|
|
782
782
|
return this.getAttribute("widgetid") || "";
|
|
@@ -900,7 +900,7 @@ class R extends HTMLElement {
|
|
|
900
900
|
var i, s;
|
|
901
901
|
if (!this.iframeEl)
|
|
902
902
|
return;
|
|
903
|
-
this.isExpanded() ? (this.classList.add("expanded"), this.classList.remove("hidden")) : this.classList.remove("expanded");
|
|
903
|
+
this.isExpanded() ? (this.classList.add("ace-expanded"), this.classList.remove("ace-hidden")) : this.classList.remove("ace-expanded");
|
|
904
904
|
const t = this.activated ? "block" : "none";
|
|
905
905
|
this.iframeEl.style.setProperty("display", t), this.activated ? this.classList.add("activated") : this.classList.remove("activated");
|
|
906
906
|
const e = this._getContainerEl();
|
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 S,T,$;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){(this._widgetAPIHandlers.get(t)||[]).forEach(i=>{i()}),this._widgetAPIHandlers.set(t,[])}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});if(!i){const s=this._widgetAPIHandlers.get(t)||[];s.push(()=>{const n=Object.values(this._api.getWidgets()).find(a=>{var d;return((d=a.widget)==null?void 0:d.name)===t});e(n==null?void 0:n.api)}),this._widgetAPIHandlers.set(t,s);return}e(i.api)}}const z="1.1.123-rc.
|
|
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 S,T,$;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){(this._widgetAPIHandlers.get(t)||[]).forEach(i=>{i()}),this._widgetAPIHandlers.set(t,[])}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});if(!i){const s=this._widgetAPIHandlers.get(t)||[];s.push(()=>{const n=Object.values(this._api.getWidgets()).find(a=>{var d;return((d=a.widget)==null?void 0:d.name)===t});e(n==null?void 0:n.api)}),this._widgetAPIHandlers.set(t,s);return}e(i.api)}}const z="1.1.123-rc.26";class M{constructor(t){this._site=t}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 B{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=(r,t)=>{if(r==="*"||r==="/*"||r===t)return!0;if(r.endsWith("/*")){const s=r.slice(0,-2);return t.startsWith(s)}return!1},U=(r,t)=>{const e=s=>`ace_${r.substring(0,7)}-${s}`;return Object.entries(t).reduce((s,[n,a])=>{const[d,c]=n.split("-");if(e(c)!=n)return s;try{const o=JSON.parse(a);s[c]=o.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;const{type:e,data:i}=t.data;if(e==="widget-minimize")this._widgets[i.widgetId].toggleExpand();else if(e==="widget-activated"){this._widgets[i.widgetId].executeMessageQueue();const n=this._widgets[i.widgetId];n&&(this._loadedVersions[i.widgetId]=i.version,this._environment.executePreloadedHandlers(((s=n.widget)==null?void 0:s.name)||""));try{const a=JSON.parse(i.storage),d=U(i.widgetId,a);typeof d.open=="boolean"&&(n.disableAnimations(),n.toggleExpand(d.open),setTimeout(()=>{n.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 B(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)){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 d=i.find(o=>o.id===a),c=((r==null?void 0:r.widgets)||[]).find(o=>o.id===a);!d&&c&&i.push({id:a})}),i),[])},g=(r,t,e)=>{r&&e.style.setProperty(t,r)},j=(r,t)=>{var e,i,s,n,a,d,c,o,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((d=r.colors)==null?void 0:d.interactiveTextOnDestructiveBackground,"--text-on-destructive-color",t),g((c=r.colors)==null?void 0:c.interactivePrimaryBackground,"--interactive-primary-background",t),g((o=r.colors)==null?void 0:o.interactiveTextOnPrimaryBackground,"--interactive-text-on-primary-background",t),g((l=r.colors)==null?void 0:l.focusColor,"--focus-color",t)},V=(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(d=>`${d.name}="${d.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"),v=(S=document.querySelector("script[nonce]"))==null?void 0:S.getAttribute("nonce");b.innerHTML=`<style ${v?`nonce="${v}"`:""}>
|
|
4
4
|
:host {
|
|
@@ -60,7 +60,7 @@ svg {
|
|
|
60
60
|
bottom: 20px;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
:host(.hidden) {
|
|
63
|
+
:host(.ace-hidden) {
|
|
64
64
|
display: none;
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -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,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&&j(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,d,c;const t=(d=(a=this.widget)==null?void 0:a.configuration)==null?void 0:d.branding,e=(c=t==null?void 0:t.graphics)==null?void 0:c.trigger;if(e){const o=document.createElement("img");return o.src=e,o.classList.add("trigger-icon"),o.alt="",o}const i={type:"Telia"},s=async o=>N,{type:n}=i;switch(n){case"Telia":{const o=await s();if(o){const l=document.createElement("ace-icon");return l.classList.add("trigger-icon"),l.svg=o.svg,l.size="lg",l}return null}default:return null}}toggle(){this._onClicked()}hide(){this.classList.add("hidden")}show(){this.classList.remove("hidden")}_renderButtonLabel(){var s,n,a,d,c,o,l,p;if(!(((d=(a=(n=(s=this.widget)==null?void 0:s.configuration)==null?void 0:n.branding)==null?void 0:a.other)==null?void 0:d.showButtonLabel)||!1))return null;const e=((p=(l=(o=(c=this.widget)==null?void 0:c.configuration)==null?void 0:o.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,d,c,o,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=(o=(c=(d=this.widget)==null?void 0:d.configuration)==null?void 0:c.branding)==null?void 0:o.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",y);class R{constructor(t){this.widgetEl=t}open(){this.widgetEl.toggleExpand(!0)}close(){this.widgetEl.toggleExpand(!1)}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"),L=($=document.querySelector("script[nonce]"))==null?void 0:$.getAttribute("nonce");A.innerHTML=`<style ${L?`nonce="${L}"`:""}>
|
|
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&&j(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,d,c;const t=(d=(a=this.widget)==null?void 0:a.configuration)==null?void 0:d.branding,e=(c=t==null?void 0:t.graphics)==null?void 0:c.trigger;if(e){const o=document.createElement("img");return o.src=e,o.classList.add("trigger-icon"),o.alt="",o}const i={type:"Telia"},s=async o=>N,{type:n}=i;switch(n){case"Telia":{const o=await s();if(o){const l=document.createElement("ace-icon");return l.classList.add("trigger-icon"),l.svg=o.svg,l.size="lg",l}return null}default:return null}}toggle(){this._onClicked()}hide(){this.classList.add("ace-hidden")}show(){this.classList.remove("ace-hidden")}_renderButtonLabel(){var s,n,a,d,c,o,l,p;if(!(((d=(a=(n=(s=this.widget)==null?void 0:s.configuration)==null?void 0:n.branding)==null?void 0:a.other)==null?void 0:d.showButtonLabel)||!1))return null;const e=((p=(l=(o=(c=this.widget)==null?void 0:c.configuration)==null?void 0:o.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,d,c,o,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=(o=(c=(d=this.widget)==null?void 0:d.configuration)==null?void 0:c.branding)==null?void 0:o.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",y);class R{constructor(t){this.widgetEl=t}open(){this.widgetEl.toggleExpand(!0)}close(){this.widgetEl.toggleExpand(!1)}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"),L=($=document.querySelector("script[nonce]"))==null?void 0:$.getAttribute("nonce");A.innerHTML=`<style ${L?`nonce="${L}"`:""}>
|
|
213
213
|
@keyframes slideDown {
|
|
214
214
|
from {
|
|
215
215
|
transform: translateY(0);
|
|
@@ -252,7 +252,7 @@ svg {
|
|
|
252
252
|
box-shadow: rgba(0, 0, 0, 0.16) 0px 5px 40px;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
:host(.expanded.activated) .widget-frame-container {
|
|
255
|
+
:host(.ace-expanded.activated) .widget-frame-container {
|
|
256
256
|
pointer-events: all;
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -273,14 +273,14 @@ svg {
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
:host(.expanded) .widget-frame-container {
|
|
276
|
+
:host(.ace-expanded) .widget-frame-container {
|
|
277
277
|
opacity: 1;
|
|
278
278
|
animation: slideUp 0.3s linear;
|
|
279
279
|
display: block;
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
:host(.hidden) .widget-frame-container {
|
|
282
|
+
:host(.ace-hidden) .widget-frame-container {
|
|
283
283
|
animation: slideDown 0.3s linear;
|
|
284
284
|
display: none;
|
|
285
285
|
}
|
|
286
|
-
</style>`;const k=document.createElement("template");k.innerHTML='<div class="widget-frame-container"></div>';class I extends HTMLElement{constructor(){super(),this.widget=null,this.activated=!1,this.active=!1,this.iframeEl=null,this.trigger=null,this._messageQueue=[],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(k.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("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(){this.widget=await this._loadWidget(this.widgetId),window.addEventListener("message",t=>{var e,i;((e=t.data)==null?void 0:e.type)==="widget-set-active"&&typeof((i=t.data.data)==null?void 0:i.active)=="boolean"&&(this.active=t.data.data.active)}),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")}_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.render()}_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;"),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){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())}setZIndex(t){this.zIndex=t,this.render()}render(){var i,s;if(!this.iframeEl)return;this.isExpanded()?(this.classList.add("expanded"),this.classList.remove("hidden")):this.classList.remove("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))}}window.customElements.get("ace-widget")||window.customElements.define("ace-widget",I),window.customElements.get("ace-trigger")||window.customElements.define("ace-trigger",C),h.SiteComponent=w,h.WidgetComponent=I,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
|
286
|
+
</style>`;const k=document.createElement("template");k.innerHTML='<div class="widget-frame-container"></div>';class I extends HTMLElement{constructor(){super(),this.widget=null,this.activated=!1,this.active=!1,this.iframeEl=null,this.trigger=null,this._messageQueue=[],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(k.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(){this.widget=await this._loadWidget(this.widgetId),window.addEventListener("message",t=>{var e,i;((e=t.data)==null?void 0:e.type)==="widget-set-active"&&typeof((i=t.data.data)==null?void 0:i.active)=="boolean"&&(this.active=t.data.data.active)}),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")}_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.render()}_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;"),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){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())}setZIndex(t){this.zIndex=t,this.render()}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))}}window.customElements.get("ace-widget")||window.customElements.define("ace-widget",I),window.customElements.get("ace-trigger")||window.customElements.define("ace-trigger",C),h.SiteComponent=w,h.WidgetComponent=I,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|