@widgetic/embed-sdk 2.1.5 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -3
- package/dist/browser/chunks/api.js +1 -1
- package/dist/browser/chunks/core.js +1 -1
- package/dist/browser/chunks/renderers.js +1 -1
- package/dist/browser/chunks/scanner.js +1 -1
- package/dist/browser/chunks/security.js +1 -1
- package/dist/browser/chunks/workflows.js +1 -1
- package/dist/browser/embed-bootstrap.js +1 -1
- package/dist/browser/embed-sdk.js +1 -1
- package/dist/esm/chunks/api.js +1 -1
- package/dist/esm/chunks/core.js +1 -1
- package/dist/esm/chunks/renderers.js +1 -1
- package/dist/esm/chunks/scanner.js +1 -1
- package/dist/esm/chunks/security.js +1 -1
- package/dist/esm/chunks/workflows.js +1 -1
- package/dist/esm/embed-bootstrap.js +1 -1
- package/dist/esm/embed-sdk.js +1 -1
- package/dist/esm/types/core/constants.d.ts +1 -1
- package/dist/esm/types/core/version.d.ts +1 -1
- package/dist/esm/types/utils/embed-resize-request.d.ts +47 -0
- package/dist/esm/types/utils/published-host-resize.d.ts +56 -0
- package/dist/esm/types/workflows/workflow-host.d.ts +23 -6
- package/dist/esm/types/workflows/workflow-languages.d.ts +62 -0
- package/dist/esm/types/workflows/workflow-lookup.d.ts +7 -0
- package/dist/esm/types/workflows/workflow-stage.d.ts +16 -5
- package/dist/umd/embed-bootstrap.js +1 -1
- package/dist/umd/embed-sdk-workflows.js +1 -1
- package/dist/umd/embed-sdk.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t,i,o,s,n,r,d,a,l,u,c){"use strict";function h(e,t,i,o){return new(i||(i=Promise))((function(s,n){function r(e){try{a(o.next(e))}catch(e){n(e)}}function d(e){try{a(o.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,d)}a((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const g=/^[A-Za-z0-9_-]{1,64}$/;function f(e){const t=new Map;for(const i of e.nodes)t.has(i.id)||t.set(i.id,i);const i=new Map,o=new Map;for(const t of e.edges)p(i,t.source,t),p(o,t.target,t);return{graph:e,nodesById:t,outgoingBySource:i,incomingByTarget:o}}function p(e,t,i){const o=e.get(t);o?o.push(i):e.set(t,[i])}function m(e,t){return e.outgoingBySource.get(t)??[]}function v(e){return"composition"===e?.type}function w(e){return"condition"===e?.type}function b(e,t){const i=[];for(const s of m(e,t)){const t=e.nodesById.get(s.target);o=t,"trigger"===o?.type&&i.push(t)}var o;return i}function y(e,t,i){return m(e,t).find((e=>e.sourcePort===i))}const I={text:["is","isNot","contains","doesNotContain","startsWith","endsWith","isEmpty","isNotEmpty"],number:["is","isNot","greaterThan","atLeast","lessThan","atMost","isEmpty","isNotEmpty"],boolean:["is","isNot"]},k=["is","isNot","contains","doesNotContain","startsWith","endsWith","greaterThan","atLeast","lessThan","atMost","isEmpty","isNotEmpty"];function E(e){return null==e||"string"==typeof e&&""===e.trim()}function T(e){return null==e?"":String(e).trim().toLowerCase()}function A(e){if("number"==typeof e)return Number.isFinite(e)?e:void 0;if("string"==typeof e){const t=e.trim();if(""===t)return;const i=Number(t);return Number.isFinite(i)?i:void 0}}const S=new Set(["true","yes","1","on"]),O=new Set(["false","no","0","off"]);function C(e){if("boolean"==typeof e)return e;if("number"==typeof e)return 1===e||0!==e&&void 0;if("string"==typeof e){const t=e.trim().toLowerCase();if(S.has(t))return!0;if(O.has(t))return!1}}function N(e,t){const{operator:i}=e;if("isEmpty"===i)return E(t);if("isNotEmpty"===i)return!E(t);if(!function(e,t){return I[t].includes(e)}(i,e.field.type))return!1;switch(e.field.type){case"number":return function(e,t,i){const o=A(t),s=A(i);if("isNot"===e)return void 0===o||void 0===s||o!==s;if(void 0===o||void 0===s)return!1;switch(e){case"is":return o===s;case"greaterThan":return o>s;case"atLeast":return o>=s;case"lessThan":return o<s;case"atMost":return o<=s;default:return!1}}(i,t,e.value);case"boolean":return function(e,t,i){const o=C(t),s=C(i),n=void 0!==o&&void 0!==s&&o===s;return"is"===e?n:"isNot"===e&&!n}(i,t,e.value);default:return function(e,t,i){const o=T(t),s=T(i),n=E(t);switch(e){case"is":return!n&&o===s;case"isNot":return n||o!==s;case"contains":return!n&&""!==s&&o.includes(s);case"doesNotContain":return n||""===s||!o.includes(s);case"startsWith":return!n&&""!==s&&o.startsWith(s);case"endsWith":return!n&&""!==s&&o.endsWith(s);default:return!1}}(i,t,e.value)}}function H(e,t){if(0===e.tests.length)return!1;const i=e=>N(e,t(e.field));return"any"===e.match?e.tests.some(i):e.tests.every(i)}const _={seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5},W=["seconds","minutes","hours","days","weeks"],R=365*_.days;function P(e){return"string"==typeof e&&W.includes(e)}function $(e,t){if("after"===e.mode){const i=function(e,t){if("number"!=typeof e||!Number.isInteger(e)||e<1)return;if(!P(t))return;const i=e*_[t];return i<=R?i:void 0}(e.amount,e.unit);if(void 0===i||!Number.isFinite(t))return;return t+i}if("at"===e.mode){const t=Date.parse(e.at);return Number.isFinite(t)?t:void 0}}function M(e,t,i){const o=$(e,t);return void 0===o?void 0:Math.max(0,o-i)}function L(e,t){const i=e.trigger;switch(t.type){case"input":return"input"===i.kind&&i.table===t.table;case"action":return"action"===i.kind&&i.actionId===t.actionId;case"pageEvent":return"pageEvent"===i.kind&&i.name===t.name;case"scheduled":return"scheduled"===i.kind&&e.id===t.triggerId;default:return!1}}function x(e,t,i){const o=[t.id],s=[],n=function(e){const t="input"===e.type||"pageEvent"===e.type?e.values:void 0,i="input"===e.type?"input":"pageEvent"===e.type?"event":void 0;return e=>{if(t&&e.kind===i)return Object.prototype.hasOwnProperty.call(t,e.name)?t[e.name]:void 0}}(i);let r=y(e,t.id,"out");for(let t=0;t<=25&&r;t+=1){s.push(r.id);const t=e.nodesById.get(r.target);if(v(t))return{destination:t,passedNodeIds:o,takenEdgeIds:s};if(!w(t))break;o.push(t.id);const i=t.cases.find((e=>H(e,n)));r=y(e,t.id,i?i.id:"default")}return{passedNodeIds:o,takenEdgeIds:s}}function F(e,t,i,o={}){const s=o.index??f(e),n=s.nodesById.get(t.nodeId);if(!v(n))return{outcome:"ignored",reason:"unknown_position"};const r=[];for(const e of b(s,n.id)){if(!L(e,i))continue;r.push(e.id);const t=x(s,e,i);if(t.destination&&t.destination.id!==n.id)return{outcome:"moved",position:{nodeId:t.destination.id},firedTriggerId:e.id,passedNodeIds:t.passedNodeIds,takenEdgeIds:t.takenEdgeIds}}return r.length>0?{outcome:"stayed",firedTriggerIds:r}:{outcome:"ignored",reason:"no_matching_trigger"}}function B(e,t,i){e.some((e=>i(e,t)))||e.push(t)}function j(e,t,i,o){const s=[],n=y(e,t,"out");n&&s.push(n.target);const r=new Set;for(;s.length>0;){const t=s.pop();if(r.has(t))continue;r.add(t);const n=e.nodesById.get(t);if(w(n)){for(const e of n.cases)for(const t of e.tests)"input"===t.field.kind&&B(o,{table:i,column:t.field.name},((e,t)=>e.table===t.table&&e.column===t.column));for(const i of m(e,t))s.push(i.target)}}}function V(e,t,i={}){const o=i.index??f(e),s={inputTables:[],inputColumns:[],actionIds:[],pageEventNames:[],schedules:[]},n=(e,t)=>e===t;for(const e of b(o,t)){const t=e.trigger;switch(t.kind){case"input":if(""===t.table)break;B(s.inputTables,t.table,n),j(o,e.id,t.table,s.inputColumns);break;case"action":""!==t.actionId&&B(s.actionIds,t.actionId,n);break;case"pageEvent":""!==t.name&&B(s.pageEventNames,t.name,n);break;case"scheduled":s.schedules.push({triggerId:e.id,schedule:t.schedule})}}return s}class z{issues=[];report(e,t){this.issues.push({code:e,severity:"error",detail:t})}}function D(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function U(e){return"string"==typeof e&&g.test(e)?e:void 0}function q(e,t=200){return"string"==typeof e&&e.length<=t?e:void 0}function Z(e){return"text"===e||"number"===e||"boolean"===e?e:void 0}function G(e,t,i){if(!D(e))return void i.report("malformed",t);const o=function(e,t,i){if(!D(e))return void i.report("malformed",t);const o="input"===e.kind||"event"===e.kind?e.kind:void 0,s=q(e.name,64),n=Z(e.type);if(o&&void 0!==s&&n)return{kind:o,name:s,type:n};i.report("malformed",t)}(e.field,`${t}.field`,i),s=function(e){return"string"==typeof e&&k.includes(e)?e:void 0}(e.operator);let n;return s||i.report("malformed",`${t}.operator`),void 0!==e.value&&(n=function(e){return null===e||"boolean"==typeof e?e:"number"==typeof e?Number.isFinite(e)?e:void 0:q(e)}(e.value),void 0===n&&i.report("malformed",`${t}.value`)),o&&s?void 0===n?{field:o,operator:s}:{field:o,operator:s,value:n}:void 0}function Y(e,t,i){if(D(e))switch(e.kind){case"input":{const o=q(e.table);return void 0===o&&i.report("malformed",`${t}.table`),void 0===o?void 0:{kind:"input",table:o}}case"action":{const o=q(e.actionId);return void 0===o&&i.report("malformed",`${t}.actionId`),void 0===o?void 0:{kind:"action",actionId:o}}case"pageEvent":{const o=q(e.name,64);void 0===o&&i.report("malformed",`${t}.name`);const s=function(e,t,i){if(!Array.isArray(e)||e.length>100)return void i.report("malformed",t);const o=[];return e.forEach(((e,s)=>{const n=D(e)?q(e.name,64):void 0,r=D(e)?Z(e.type):void 0;void 0!==n&&r?o.push({name:n,type:r}):i.report("malformed",`${t}[${s}]`)})),o}(e.values,`${t}.values`,i);return void 0!==o&&s?{kind:"pageEvent",name:o,values:s}:void 0}case"scheduled":{const o=function(e,t,i){if(D(e)&&"after"===e.mode&&"number"==typeof e.amount&&P(e.unit)&&Number.isFinite(e.amount))return{mode:"after",amount:e.amount,unit:e.unit};if(D(e)&&"at"===e.mode){const t=q(e.at,64);if(void 0!==t)return{mode:"at",at:t}}i.report("malformed",t)}(e.schedule,`${t}.schedule`,i);return o?{kind:"scheduled",schedule:o}:void 0}default:return void i.report("unknown_trigger_kind",`${t}.kind`)}else i.report("malformed",t)}function J(e,t,i){if(!D(e))return void i.report("malformed",t);const o=U(e.id);o||i.report("bad_id",`${t}.id`);const s=function(e){if(void 0!==e)return D(e)&&"number"==typeof e.x&&"number"==typeof e.y&&Number.isFinite(e.x)&&Number.isFinite(e.y)?{x:e.x,y:e.y}:"invalid"}(e.position);"invalid"===s&&i.report("malformed",`${t}.position`);const n=o&&"invalid"!==s?s?{id:o,position:s}:{id:o}:void 0;switch(e.type){case"composition":{const o=q(e.compositionId,200);if(void 0===o&&i.report("malformed",`${t}.compositionId`),void 0!==e.startsHere&&"boolean"!=typeof e.startsHere)return void i.report("malformed",`${t}.startsHere`);if(!n||void 0===o)return;return!0===e.startsHere?{...n,type:"composition",compositionId:o,startsHere:!0}:{...n,type:"composition",compositionId:o}}case"trigger":{const o=Y(e.trigger,`${t}.trigger`,i);return n&&o?{...n,type:"trigger",trigger:o}:void 0}case"condition":{if(!Array.isArray(e.cases)||e.cases.length>100)return void i.report("malformed",`${t}.cases`);const o=[];return e.cases.forEach(((e,s)=>{const n=function(e,t,i){if(!D(e)||!Array.isArray(e.tests)||e.tests.length>100)return void i.report("malformed",t);const o=U(e.id),s="all"===e.match||"any"===e.match?e.match:void 0;let n;o||i.report("bad_id",`${t}.id`),s||i.report("malformed",`${t}.match`),void 0!==e.label&&(n=q(e.label),void 0===n&&i.report("malformed",`${t}.label`));const r=[];return e.tests.forEach(((e,o)=>{const s=G(e,`${t}.tests[${o}]`,i);s&&r.push(s)})),o&&s?void 0===n?{id:o,match:s,tests:r}:{id:o,label:n,match:s,tests:r}:void 0}(e,`${t}.cases[${s}]`,i);n&&o.push(n)})),n?{...n,type:"condition",cases:o}:void 0}default:return void i.report("unknown_node_type",`${t}.type`)}}function K(e){const t=new z;if(!D(e))return t.report("malformed","graph"),{issues:t.issues};if(1!==e.schemaVersion)return t.report("schema_version","schemaVersion"),{issues:t.issues};if(!Array.isArray(e.nodes)||!Array.isArray(e.edges))return t.report("malformed","nodes/edges"),{issues:t.issues};if(e.nodes.length>100||e.edges.length>300)return t.report("graph_too_large","nodes/edges"),{issues:t.issues};const i=[];e.nodes.forEach(((e,o)=>{const s=J(e,`nodes[${o}]`,t);s&&i.push(s)}));const o=[];return e.edges.forEach(((e,i)=>{const s=function(e,t,i){if(!D(e))return void i.report("malformed",t);const o=U(e.id),s=U(e.source),n=U(e.sourcePort),r=U(e.target);return o||i.report("bad_id",`${t}.id`),s&&n&&r||i.report("malformed",t),o&&s&&n&&r?{id:o,source:s,sourcePort:n,target:r}:void 0}(e,`edges[${i}]`,t);s&&o.push(s)})),t.issues.length>0?{issues:t.issues}:{graph:{schemaVersion:1,nodes:i,edges:o},issues:[]}}const Q=/^[A-Za-z0-9_.:-]{1,128}$/;function X(e){return`widgetic_workflow_${e}`}function ee(e){return"string"==typeof e&&Q.test(e)}function te(e){return"number"==typeof e&&Number.isFinite(e)&&e>=0}function ie(e,t){try{a.writeStoredValue(X(e),JSON.stringify({v:1,versionId:t.versionId,nodeId:t.nodeId,compositionId:t.compositionId,startedAt:t.startedAt,reachedAt:t.reachedAt}))}catch(t){i.log.debug("[workflows] The visitor's position could not be kept",{workflowId:e,error:t})}}function oe(e){a.removeStoredValue(X(e))}const se=/^[A-Za-z0-9_-]{1,64}$/,ne=new Set(["n","e","f"]);class re{constructor(e){this.pending=[],this.lastEventOf=new Map,this.flushTimer=null,this.stopped=!1,this.listening=!1,this.onPageHide=()=>{this.flushBeforeLeaving()},this.onVisibilityChange=()=>{"hidden"===document.visibilityState&&this.flushBeforeLeaving()},this.options=e}isStopped(){return this.stopped}start(){this.listening||this.stopped||(this.listening=!0,window.addEventListener("pagehide",this.onPageHide),document.addEventListener("visibilitychange",this.onVisibilityChange))}count(e,t,i=1){if(this.stopped||!this.options.token)return;if(!ne.has(e)||!se.test(t)||!Number.isInteger(i)||i<1)return;const o=`${e}:${t}`;let s=i;for(;s>0;){let i=this.lastEventOf.get(o);(!i||i.c>=50)&&(i={k:e,id:t,c:0},this.pending.push(i),this.lastEventOf.set(o,i));const n=Math.min(s,50-i.c);i.c+=n,s-=n}this.pending.length>=100?this.flush():null===this.flushTimer&&(this.flushTimer=setTimeout((()=>this.flush()),2e3))}flushBeforeLeaving(){if(!this.stopped&&this.options.token)for(;this.pending.length>0;){const e=this.takeBatch();if(!this.options.isActive())return void this.forgetPending();this.sendWithBeacon(e)}}dispose(){this.stopped=!0,this.forgetPending(),this.listening&&(window.removeEventListener("pagehide",this.onPageHide),document.removeEventListener("visibilitychange",this.onVisibilityChange),this.listening=!1)}takeBatch(){const e=this.pending.splice(0,100);for(const t of e){const e=`${t.k}:${t.id}`;this.lastEventOf.get(e)===t&&this.lastEventOf.delete(e)}return e}forgetPending(){null!==this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.pending=[],this.lastEventOf.clear()}flush(){if(null!==this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.stopped||0===this.pending.length)return;if(!this.options.isActive())return void this.forgetPending();const e=this.takeBatch();this.sendWithRequest(e),this.pending.length>0&&null===this.flushTimer&&(this.flushTimer=setTimeout((()=>this.flush()),2e3))}reportAddress(){return`${this.options.apiOrigin}/embed/workflows/${encodeURIComponent(this.options.workflowId)}/events`}reportBody(e){return JSON.stringify({versionId:this.options.versionId,token:this.options.token,events:e.map((e=>e.c>1?{k:e.k,id:e.id,c:e.c}:{k:e.k,id:e.id}))})}sendWithBeacon(e){try{const t=this.reportBody(e),o="undefined"!=typeof navigator?navigator.sendBeacon:void 0;if("function"==typeof o&&o.call(navigator,this.reportAddress(),new Blob([t],{type:"text/plain"})))return void i.log.debug("[workflows] Counts handed to the browser to send",{eventCount:e.length})}catch(e){i.log.debug("[workflows] The browser would not take counts to send as the page closes",{error:e})}this.sendWithRequest(e)}sendWithRequest(e){return h(this,void 0,void 0,(function*(){try{const t=yield fetch(this.reportAddress(),{method:"POST",mode:"cors",credentials:"omit",keepalive:!0,headers:{"Content-Type":"text/plain"},body:this.reportBody(e)});if(401===t.status)return i.log.warn("[workflows] The gateway refused the token for counts, so this embed stops reporting",{workflowId:this.options.workflowId}),void this.dispose();i.log.debug("[workflows] Counts sent",{eventCount:e.length,status:t.status})}catch(t){i.log.debug("[workflows] Counts could not be sent and were dropped",{eventCount:e.length,error:t})}}))}}const de=/^[A-Za-z0-9_-]{1,64}$/,ae=/^[A-Za-z0-9_.:-]{1,128}$/;function le(e){return de.test(e)}function ue(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function ce(e,t){return h(this,void 0,void 0,(function*(){const o=new AbortController,s=setTimeout((()=>o.abort()),1e4);try{const s=yield fetch(e,{method:"GET",mode:"cors",signal:o.signal});if(404===s.status)return{kind:"missing"};if(!s.ok)return{kind:"unreachable"};let n;try{n=yield s.json()}catch(e){return{kind:"unreadable"}}const r=function(e,t){var o;if(!ue(e)||!0!==e.success||!ue(e.data))return{kind:"unreadable"};const s=e.data;if("paused"===s.status)return{kind:"paused"};if("live"!==s.status)return{kind:"unreadable"};if("string"!=typeof s.versionId||!ae.test(s.versionId))return{kind:"unreadable"};const n=K(s.graph);if(!n.graph||n.issues.length>0)return i.log.warn("[workflows] The published graph could not be read, so the embed stays a plain embed",{workflowId:t,issueCount:n.issues.length,firstIssue:null===(o=n.issues[0])||void 0===o?void 0:o.code}),{kind:"unreadable"};const r={workflowId:"string"==typeof s.workflowId?s.workflowId:t,versionId:s.versionId,timezone:"string"==typeof s.timezone&&""!==s.timezone.trim()&&s.timezone.length<=64?s.timezone:"UTC",graph:n.graph};return"number"==typeof s.versionNumber&&Number.isInteger(s.versionNumber)&&(r.versionNumber=s.versionNumber),"string"==typeof s.publishedAt&&(r.publishedAt=s.publishedAt),"string"==typeof s.startCompositionId&&ae.test(s.startCompositionId)&&(r.startCompositionId=s.startCompositionId),"string"==typeof s.eventToken&&""!==s.eventToken&&s.eventToken.length<=2048&&(r.eventToken=s.eventToken),{kind:"live",workflow:r}}(n,t);return"live"===r.kind?{kind:"live",workflow:r.workflow}:r}catch(e){return i.log.debug("[workflows] A host could not be reached",{workflowId:t,error:e}),{kind:"unreachable"}}finally{clearTimeout(s)}}))}const he=new Map;function ge(e,t={}){var o,n;if(!le(e)||void 0!==t.versionId&&!ae.test(t.versionId))return Promise.resolve({status:"unavailable",reason:"not_found"});const r=`${e}|${null!==(o=t.versionId)&&void 0!==o?o:""}|${(null!==(n=t.origins)&&void 0!==n?n:[]).join(",")}`,d=he.get(r);if(d)return d;const a=function(e,t){return h(this,void 0,void 0,(function*(){var o;const n=null!==(o=t.origins)&&void 0!==o?o:s.publicEmbedApiOrigins(),r=t.versionId?`/embed/workflows/${encodeURIComponent(e)}/versions/${encodeURIComponent(t.versionId)}`:`/embed/workflows/${encodeURIComponent(e)}`;let d=!1,a=!1;for(const t of n){const i=yield ce(`${t}${r}`,e);if("live"===i.kind)return{status:"live",workflow:i.workflow,origin:t};if("paused"===i.kind)return{status:"paused"};"missing"===i.kind&&(d=!0),"unreadable"===i.kind&&(a=!0)}const l=d?"not_found":a?"unreadable":"unreachable";return i.log.debug("[workflows] The workflow is not available",{workflowId:e,reason:l}),{status:"unavailable",reason:l}}))}(e,t);return he.set(r,a),a.finally((()=>{he.get(r)===a&&he.delete(r)})),a}const fe={clicks:"click",submissions:"submit",plays:"play"},pe=new Set(["__proto__","constructor","prototype"]);function me(e){const t=e.detail;return"object"!=typeof t||null===t||Array.isArray(t)?{}:t}function ve(e,t){return("submissions"!==e.metric||"FORM"===t.tagName)&&(("plays"!==e.metric||"VIDEO"===t.tagName||"AUDIO"===t.tagName)&&(null!==e.selector?a.elementMatchesGoalTarget(t,e.selector):"clicks"!==e.metric||null!==t.closest('button, a, input[type="button"], input[type="submit"], [role="button"], [onclick], [data-click-track]')))}function we({stage:e,watch:o,emit:s}){var n;let r=!1;const d=[];if(o.inputTables.length>0){const t=new Map;for(const{table:e,column:i}of o.inputColumns){const o=null!==(n=t.get(e))&&void 0!==n?n:new Set;o.add(i),t.set(e,o)}const a=new Set,l=e=>{var n;if(r)return;const d=me(e),l=d.table;if("string"!=typeof l||!o.inputTables.includes(l))return;if("string"==typeof d.entryId&&""!==d.entryId){const e=`${l}:${d.entryId}`;if(a.has(e))return;if(a.add(e),a.size>100){const e=a.values().next().value;void 0!==e&&a.delete(e)}}const u=function(e,t){const i={};if("object"!=typeof e||null===e||Array.isArray(e))return i;for(const o of t){if(pe.has(o))continue;if(!Object.prototype.hasOwnProperty.call(e,o))continue;const t=e[o];"string"==typeof t?i[o]=t.length>200?t.slice(0,200):t:("number"==typeof t&&Number.isFinite(t)||"boolean"==typeof t)&&(i[o]=t)}return i}(d.values,null!==(n=t.get(l))&&void 0!==n?n:new Set);i.log.debug("[workflows] An entry was saved in a watched table",{table:l,valueCount:Object.keys(u).length}),s([{type:"input",table:l,values:u}])};e.addEventListener("widgetic:submitted",l),d.push((()=>e.removeEventListener("widgetic:submitted",l)))}if(o.actionIds.length>0){const n=e=>{if(r)return;const t=me(e);let n=null;"string"==typeof t.goalId?n=t.goalId:"string"==typeof t.metric&&""!==t.metric&&(n="string"==typeof t.goalTarget&&""!==t.goalTarget?`${t.metric}@${t.goalTarget}`:t.metric),null!==n&&o.actionIds.includes(n)&&(i.log.debug("[workflows] A widget reported a watched action",{actionId:n}),s([{type:"action",actionId:n}]))};e.addEventListener("widgetic:goal",n),d.push((()=>e.removeEventListener("widgetic:goal",n)));const l=[];for(const e of o.actionIds){const i=t.splitActionId(e);i&&(a=i.metric,Object.prototype.hasOwnProperty.call(fe,a))&&l.push({actionId:e,metric:i.metric,selector:i.selector})}if(l.length>0){let t=null,o=()=>{};const n=e=>{const t=e.target instanceof Element?e.target:null;if(!t)return[];const i=[];for(const o of l)fe[o.metric]===e.type&&ve(o,t)&&i.push({type:"action",actionId:o.actionId});return i},a=e=>{if(r)return;const t=n(e);0!==t.length&&(i.log.debug("[workflows] A watched action happened in the widget",{actionIds:t.map((e=>e.actionId))}),s(t))},u=()=>{var i;const s=e.querySelector("[data-widgetic-direct]"),n=null!==(i=null==s?void 0:s.shadowRoot)&&void 0!==i?i:null;if(!n||n===t)return;o();const r=new Set(l.map((e=>fe[e.metric])));for(const e of r)n.addEventListener(e,a,!0);t=n,o=()=>{for(const e of r)n.removeEventListener(e,a,!0);t=null,o=()=>{}}};e.addEventListener("widgetic:ready",u),d.push((()=>e.removeEventListener("widgetic:ready",u))),d.push((()=>o())),u()}}var a;return{stop:()=>{if(!r){r=!0;for(const e of d)try{e()}catch(e){i.log.debug("[workflows] A listener could not be removed",{error:e})}}}}}const be=50,ye=2e3,Ie=150,ke=5,Ee=300,Te=2e4;function Ae(e,t,i,o){const s=e.getAttribute(t);if(null===s||!/^\d+$/.test(s.trim()))return i;const n=Number.parseInt(s.trim(),10);return Number.isFinite(n)?Math.min(n,o):i}function Se(e,t,i){const o="number"==typeof i&&Number.isFinite(i)&&i>0?Math.min(t.maxHeight,Math.floor(i)):t.maxHeight,s=Math.min(t.minHeight,o);return Number.isNaN(e)?s:Math.max(s,Math.min(o,Math.ceil(e)))}function Oe(e,t,i){return null===e||t!==e&&Math.abs(t-e)>=i}const Ce=["width","height","resize","resize-mode","render-mode","use-iframe","theme","mode","colors","sandbox","autoload","adaptive","responsive"],Ne=["values","context","media-resolver"],He=["design","content","content-items","contentitems","items"];function _e(e){if("undefined"==typeof ResizeObserver)return null;try{return new ResizeObserver((t=>{e(t.map((e=>({target:e.target,height:e.contentRect.height}))))}))}catch(e){return i.log.debug("[workflows] The browser could not watch heights",{error:e}),null}}function We(e){return e.getBoundingClientRect().height}function Re(){try{return"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}catch(e){return!1}}function Pe(e){return"number"==typeof e&&Number.isFinite(e)&&e>0}class $e{constructor(e){var t;this.current=null,this.incoming=null,this.heightObserver=null,this.attributeObserver=null,this.autoscaleOn=!1,this.appliedHeight=null,this.debounceTimer=null,this.pendingHeight=null,this.destroyed=!1,this.warnedAboutFrameWithoutHeight=!1,this.host=e.host,this.services=e.services,this.prefersReducedMotion=null!==(t=e.prefersReducedMotion)&&void 0!==t?t:Re,this.widthOverride=e.widthOverride&&""!==e.widthOverride?e.widthOverride:null,this.viewportElement=document.createElement("div"),this.viewportElement.setAttribute("data-widgetic-workflow-viewport","1"),this.viewportElement.setAttribute("data-widgetic-internal","1"),this.viewportElement.style.display="block",this.observeMirroredAttributes()}currentStage(){var e,t;return null!==(t=null===(e=this.current)||void 0===e?void 0:e.element)&&void 0!==t?t:null}showFirstStage(e){if(this.current)return{stage:this.current.element,ready:Promise.resolve({status:"ready"})};this.viewportElement.isConnected||this.host.appendChild(this.viewportElement),this.holdRoomFor(e);const t=this.buildStage(e,!0);this.current=t;const i=this.waitUntilShown(t,null,(e=>{if("ready"===e.status&&!this.destroyed&&this.autoscaleOn&&this.current===t){const e=this.measure(t.element);Pe(e)&&this.applyHeight(e,"immediate")}}));return this.viewportElement.appendChild(t.element),this.services.hydrate(t.element),{stage:t.element,ready:i}}enableAutoscale(){var e,t;if(!this.destroyed&&!this.autoscaleOn&&(this.autoscaleOn=!0,this.viewportElement.style.position="relative",this.viewportElement.style.overflow="hidden",this.current&&this.positionAsLayer(this.current.element),this.heightObserver=(null!==(e=this.services.createHeightObserver)&&void 0!==e?e:_e)((e=>this.onHeightsReported(e))),this.current)){null===(t=this.heightObserver)||void 0===t||t.observe(this.current.element);const e=this.measure(this.current.element);Pe(e)&&this.applyHeight(e,"immediate")}}releaseAutoscale(){var e;if(this.destroyed)return;this.autoscaleOn=!1,this.clearHeightTimer(),null===(e=this.heightObserver)||void 0===e||e.disconnect(),this.heightObserver=null,this.appliedHeight=null;const t=this.viewportElement.style;for(const e of["position","overflow","height","min-height","transition"])t.removeProperty(e);this.current&&this.positionInFlow(this.current.element)}swapTo(e){return h(this,void 0,void 0,(function*(){var t,o,s;if(this.destroyed)return{status:"failed",reason:"stopped"};if(this.incoming)return{status:"failed",reason:"busy"};this.enableAutoscale();const r=this.buildStage(e,!1);this.incoming=r,this.hideBeside(r.element);const d=this.waitUntilShown(r,null!==(t=this.services.readyTimeoutMilliseconds)&&void 0!==t?t:8e3);this.viewportElement.appendChild(r.element),this.services.hydrate(r.element);const a=yield d;if(this.destroyed)return{status:"failed",reason:"stopped"};if(this.incoming=null,"failed"===a.status)return this.removeStage(r),"timeout"===a.reason&&n.dispatchPublishedHostError(this.host,e,"workflow_step_timeout"),i.log.debug("[workflows] The next composition could not be shown, so the visitor stays where they are",{compositionId:e,reason:a.reason}),Object.assign({status:"failed",reason:"stopped"===a.reason?"stopped":a.reason},a.code?{code:a.code}:{});const l=this.current;this.revealInPlace(r.element),this.current=r,null===(o=this.heightObserver)||void 0===o||o.observe(r.element);const u=this.measure(r.element);return Pe(u)&&this.applyHeight(u,"immediate"),l&&(null===(s=this.heightObserver)||void 0===s||s.unobserve(l.element),this.removeStage(l)),{status:"shown",stage:r.element}}))}destroy(){var e,t,i;if(this.destroyed)return;this.destroyed=!0,this.clearHeightTimer(),null===(e=this.heightObserver)||void 0===e||e.disconnect(),this.heightObserver=null,null===(t=this.attributeObserver)||void 0===t||t.disconnect(),this.attributeObserver=null;const o=[this.current,this.incoming];this.current=null,this.incoming=null;for(const e of o)e&&(null===(i=e.cancelWait)||void 0===i||i.call(e),this.removeStage(e));this.viewportElement.remove()}buildStage(e,t){var o,s,n;const r=document.createElement("widgetic");r.setAttribute("composition-id",e),r.setAttribute("data-widgetic-workflow-stage","1"),r.style.display="block";for(const e of Ce){const t=this.host.getAttribute(e);null!==t&&r.setAttribute(e,t)}this.widthOverride&&r.setAttribute("width",this.widthOverride);for(const e of Ne){const t=this.host.getAttribute(e);null!==t&&r.setAttribute(e,t)}const d=e===(null!==(o=this.host.getAttribute("composition-id"))&&void 0!==o?o:"").trim();d&&this.copyWhatThePageWroteForTheTagComposition(r);const a={element:r,compositionId:e,reportedHeight:!1,cancelWait:null,stopListening:()=>{}},l=e=>{var t;const i=null===(t=e.detail)||void 0===t?void 0:t.height;if("number"!=typeof i||!Pe(i))return;const o=r.querySelector("iframe");o&&(o.style.height=`${Math.ceil(i)}px`,a.reportedHeight=!0)};r.addEventListener("widgetic:resize",l),a.stopListening=()=>r.removeEventListener("widgetic:resize",l);try{null===(n=(s=this.services).onStageCreated)||void 0===n||n.call(s,r,{compositionId:e,isFirst:t,carriesPageContent:d})}catch(t){i.log.debug("[workflows] A listener for a new stage failed",{compositionId:e,error:t})}return a}copyWhatThePageWroteForTheTagComposition(e){for(const t of Array.from(this.host.attributes))u.isReservedHostAttribute(t.name)||e.setAttribute(t.name,t.value);for(const t of He){const i=this.host.getAttribute(t);null!==i&&e.setAttribute(t,i)}for(const t of u.declarativeChildrenOf(this.host))e.appendChild(t.cloneNode(!0))}observeMirroredAttributes(){const e="undefined"!=typeof MutationObserver?MutationObserver:null;if(e)try{this.attributeObserver=new e((e=>{e.some((e=>{var t;return"attributes"===e.type&&Ne.includes(null!==(t=e.attributeName)&&void 0!==t?t:"")}))&&this.mirrorAttributesToStages()})),this.attributeObserver.observe(this.host,{attributes:!0,attributeFilter:[...Ne]})}catch(e){this.attributeObserver=null,i.log.debug("[workflows] The tag cannot be watched for changes",{error:e})}}mirrorAttributesToStages(){for(const e of[this.current,this.incoming])if(e)for(const t of Ne){const i=this.host.getAttribute(t);null===i?e.element.removeAttribute(t):e.element.getAttribute(t)!==i&&e.element.setAttribute(t,i)}}waitUntilShown(e,t,o){return new Promise((s=>{const n=e.element;let r=null,d=!1;const a=t=>{if(!d){d=!0,null!==r&&clearTimeout(r),n.removeEventListener("widgetic:ready",l),n.removeEventListener("widgetic:error",u),n.removeEventListener("load",c,!0),e.cancelWait=null;try{null==o||o(t)}catch(t){i.log.debug("[workflows] A stage could not be settled",{compositionId:e.compositionId,error:t})}s(t)}},l=()=>a({status:"ready"}),u=e=>{var t;const i=null===(t=e.detail)||void 0===t?void 0:t.code;a(Object.assign({status:"failed",reason:"error"},"string"==typeof i?{code:i}:{}))},c=e=>{e.target instanceof HTMLIFrameElement&&a({status:"ready"})};n.addEventListener("widgetic:ready",l),n.addEventListener("widgetic:error",u),n.addEventListener("load",c,!0),e.cancelWait=()=>a({status:"failed",reason:"stopped"}),null!==t&&(r=setTimeout((()=>a({status:"failed",reason:"timeout"})),t))}))}removeStage(e){var t,o;e.stopListening(),e.element.querySelector("iframe")&&!e.reportedHeight&&this.noteFrameWithoutHeight(e.compositionId),e.element.remove();try{null===(o=(t=this.services).onStageRemoved)||void 0===o||o.call(t,e.element)}catch(t){i.log.debug("[workflows] A listener for a removed stage failed",{compositionId:e.compositionId,error:t})}}noteFrameWithoutHeight(e){this.warnedAboutFrameWithoutHeight||(this.warnedAboutFrameWithoutHeight=!0,i.log.debug("[workflows] A widget in a frame does not report its height (widgetic:resize), so the embed keeps the height of its frame",{compositionId:e}))}hideBeside(e){this.positionAsLayer(e),e.style.visibility="hidden",e.style.pointerEvents="none",e.setAttribute("aria-hidden","true")}revealInPlace(e){e.style.removeProperty("visibility"),e.style.removeProperty("pointer-events"),e.removeAttribute("aria-hidden")}positionAsLayer(e){e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="100%"}positionInFlow(e){for(const t of["position","top","left","width"])e.style.removeProperty(t)}measure(e){var t;try{return(null!==(t=this.services.measureStageHeight)&&void 0!==t?t:We)(e)}catch(e){return i.log.debug("[workflows] The height of a stage could not be read",{error:e}),0}}holdRoomFor(e){const t=l.readStoredAutoscaleHeight(e);if(null===t)return;const i=this.settings();this.viewportElement.style.minHeight=`${Se(t,i,this.overlayCap())}px`}settings(){return function(e,t={}){const i=Ae(e,"autoscale-min-height",be,Te),o=Ae(e,"autoscale-max-height",ye,Te);return{minHeight:i,maxHeight:Math.max(o,i),debounceDelay:Ae(e,"autoscale-debounce",Ie,5e3),threshold:Ae(e,"autoscale-threshold",ke,Te),animate:"false"!==e.getAttribute("autoscale-animate")&&!0!==t.prefersReducedMotion,animationDuration:Ae(e,"autoscale-animation-duration",Ee,5e3)}}(this.host,{prefersReducedMotion:this.prefersReducedMotion()})}overlayCap(){return this.host.hasAttribute(c.OVERLAY_HOST_ATTRIBUTE)?Math.floor(.9*window.innerHeight):null}onHeightsReported(e){if(!this.destroyed&&this.autoscaleOn&&this.current)for(const t of e)t.target===this.current.element&&Pe(t.height)&&this.applyHeight(t.height,"observed")}applyHeight(e,t){const i=this.settings(),o=Se(e,i,this.overlayCap());if("immediate"===t)return this.clearHeightTimer(),void this.setHeight(o,i);Oe(this.appliedHeight,o,i.threshold)?(this.pendingHeight=o,null!==this.debounceTimer&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout((()=>{this.debounceTimer=null;const e=this.pendingHeight;if(this.pendingHeight=null,null===e||this.destroyed||!this.autoscaleOn)return;const t=this.settings();Oe(this.appliedHeight,e,t.threshold)&&this.setHeight(e,t)}),i.debounceDelay)):o===this.appliedHeight&&this.clearHeightTimer()}setHeight(e,t){var i;const o=this.viewportElement.style,s=null!==this.appliedHeight&&this.appliedHeight!==e;if(o.setProperty("transition",t.animate&&s?`height ${t.animationDuration}ms ease`:"none"),o.height=`${e}px`,o.removeProperty("min-height"),this.appliedHeight=e,this.current){const t=Number.parseInt(null!==(i=this.host.getAttribute("height"))&&void 0!==i?i:"",10);l.writeStoredAutoscaleHeight(this.current.compositionId,e,Number.isFinite(t)?t:e)}}clearHeightTimer(){null!==this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingHeight=null}}function Me(e,s,r){var d;try{o.setDirectMountWorkflow(e,t.workflowWatchProperty(s,r)),null===(d=n.getPublishedHostBridge(e))||void 0===d||d.sendWorkflowWatch(r)}catch(e){i.log.debug("[workflows] A widget could not be told what to report",{compositionId:s,error:e})}}function Le(e){try{s.resolvePublishedEmbed(e).then((e=>{var t;const i="found"===e.status?null===(t=e.payload.direct)||void 0===t?void 0:t.moduleUrl:void 0;i&&o.warmDirectModule(i)})).catch((()=>{}))}catch(t){i.log.debug("[workflows] A composition could not be got ready",{compositionId:e,error:t})}}function xe(e){const t=window;if("function"==typeof t.requestIdleCallback){const i=t.requestIdleCallback((()=>e()),{timeout:5e3});return()=>{var e;return null===(e=t.cancelIdleCallback)||void 0===e?void 0:e.call(t,i)}}const i=setTimeout(e,1500);return()=>clearTimeout(i)}class Fe{constructor(e,t,o,s,n){this.host=e,this.workflowId=t,this.tagCompositionId=o,this.options=s,this.services=n,this.mode="loading",this.stages=new Map,this.pageEvents=new d.PageEventQueue,this.removeListeners=[],this.workflow=null,this.index=null,this.counts=null,this.position=null,this.stepping=!1,this.pendingStageNodeId=null,this.retryTimer=null,this.scheduleTimers=new Set,this.cancelIdleWork=null,this.readiedCompositions=new Set,this.displayBeforeMounting="",this.onPageEvent=e=>{if("ended"===this.mode||"plain"===this.mode)return;const t=d.readPageEvent(e.detail);t?"running"!==this.mode||this.stepping?this.pageEvents.add(t):this.hasEnded()||this.react([{type:"pageEvent",name:t.name,values:t.values}]):i.log.debug("[workflows] An event of the page was ignored: it is not one a workflow can wait for")},this.onVisibilityChange=()=>{"running"!==this.mode||this.stepping||this.hasEnded()||this.armSchedules()};const r=n.viewport;this.viewport=new $e(Object.assign(Object.assign(Object.assign({host:e},r.prefersReducedMotion?{prefersReducedMotion:r.prefersReducedMotion}:{}),s.width?{widthOverride:s.width}:{}),{services:Object.assign(Object.assign(Object.assign(Object.assign({hydrate:s.hydrate},r.createHeightObserver?{createHeightObserver:r.createHeightObserver}:{}),r.measureStageHeight?{measureStageHeight:r.measureStageHeight}:{}),void 0!==r.readyTimeoutMilliseconds?{readyTimeoutMilliseconds:r.readyTimeoutMilliseconds}:{}),{onStageCreated:e=>this.onStageCreated(e),onStageRemoved:e=>this.onStageRemoved(e)})}))}start(){var e;const t=function(e,t=Date.now()){const o=X(e),s=a.readStoredValue(o);if(null===s)return null;try{const o=JSON.parse(s);if("object"!=typeof o||null===o||Array.isArray(o))return null;const n=o;return 1!==n.v?null:ee(n.versionId)&&ee(n.nodeId)&&ee(n.compositionId)&&te(n.startedAt)&&te(n.reachedAt)?n.startedAt>t+864e5?null:t-n.startedAt>2592e6?(oe(e),i.log.debug("[workflows] The visitor's position is older than 30 days and was forgotten",{workflowId:e}),null):{versionId:n.versionId,nodeId:n.nodeId,compositionId:n.compositionId,startedAt:n.startedAt,reachedAt:Math.min(n.reachedAt,t)}:null}catch(t){return i.log.debug("[workflows] The kept position could not be read and is ignored",{workflowId:e,error:t}),null}}(this.workflowId),o=null!==(e=null==t?void 0:t.compositionId)&&void 0!==e?e:this.tagCompositionId;this.listenToThePage();const{ready:s}=this.viewport.showFirstStage(o);this.displayBeforeMounting=this.host.style.display,this.options.markMounted(this.host),this.run(t,o,s)}run(e,t,o){return h(this,void 0,void 0,(function*(){var s;try{const[n,r]=yield Promise.all([this.services.fetchWorkflow(this.workflowId),o]);if(this.hasEnded())return;let d=e,a=t;if("failed"===r.status){if("stopped"===r.reason)return;if(!e||e.compositionId===this.tagCompositionId)return void this.refuse(r.code);{i.log.debug("[workflows] The composition a returning visitor was on cannot be shown, so they start again",{compositionId:e.compositionId}),oe(this.workflowId),d=null;const t=yield this.viewport.swapTo(this.tagCompositionId);if(this.hasEnded())return;if("shown"!==t.status)return void this.refuse(null!==(s=r.code)&&void 0!==s?s:"failed"===t.status?t.code:void 0);a=this.tagCompositionId}}if("live"!==n.status)return i.log.debug("[workflows] The workflow is not running, so the tag is a plain embed",{workflowId:this.workflowId,status:n.status}),void(yield this.becomePlain(a));let l=n.workflow,u=n.origin;if(d&&d.versionId!==l.versionId){const e=yield this.services.fetchWorkflow(this.workflowId,{versionId:d.versionId});if(this.hasEnded())return;"live"===e.status&&e.workflow.versionId===d.versionId?(l=e.workflow,u=e.origin):(i.log.debug("[workflows] The version a visitor started on cannot be read, so they continue as a new visitor",{versionId:d.versionId}),oe(this.workflowId),d=null)}const c=f(l.graph);let h=d&&this.fitsTheGraph(d,l,c)?d:null;const g=null===h;if(null===h){d&&(i.log.debug("[workflows] The place a visitor was kept at is not in the workflow, so they continue as a new visitor"),oe(this.workflowId));const e=function(e,t){for(const i of e.nodes)if("composition"===i.type&&i.compositionId===t)return i}(l.graph,this.tagCompositionId);if(!e)return i.log.debug("[workflows] The composition of the tag is not a block of the workflow, so the tag is a plain embed",{compositionId:this.tagCompositionId}),void(yield this.becomePlain(a));if(a!==this.tagCompositionId){const e=yield this.viewport.swapTo(this.tagCompositionId);if(this.hasEnded())return;if("shown"!==e.status)return void(yield this.becomePlain(a))}const t=Date.now();h={versionId:l.versionId,nodeId:e.id,compositionId:this.tagCompositionId,startedAt:t,reachedAt:t}}this.activate(l,u,c,h,g)}catch(e){i.log.warn("[workflows] The workflow stopped working, so the tag stays as it is",{workflowId:this.workflowId,error:e}),this.becomePlainWithoutWaiting()}}))}fitsTheGraph(e,t,i){if(e.versionId!==t.versionId)return!1;const o=i.nodesById.get(e.nodeId);return v(o)&&o.compositionId===e.compositionId}activate(e,t,o,s,n){var r;this.workflow=e,this.index=o,this.position=s,this.mode="running";const d=this.services.createCounts({workflowId:this.workflowId,versionId:e.versionId,token:null!==(r=e.eventToken)&&void 0!==r?r:null,apiOrigin:t,isActive:()=>"ended"!==this.mode&&this.host.isConnected});d.start(),this.counts=d,n&&(ie(this.workflowId,s),d.count("n",s.nodeId)),i.log.debug("[workflows] The workflow runs",{workflowId:this.workflowId,versionId:e.versionId,isNewVisitor:n}),this.viewport.enableAutoscale();const a=this.viewport.currentStage();a&&this.armStage(a,s.nodeId),this.armSchedules(),this.getNextCompositionsReady(),this.drainPageEvents()}becomePlain(e){return h(this,void 0,void 0,(function*(){if(this.mode="plain",this.pageEvents.clear(),e!==this.tagCompositionId){const e=yield this.viewport.swapTo(this.tagCompositionId);if(this.hasEnded())return;"shown"!==e.status&&i.log.debug("[workflows] The composition of the tag could not be shown")}this.viewport.releaseAutoscale()}))}becomePlainWithoutWaiting(){"ended"!==this.mode&&(this.mode="plain",this.pageEvents.clear(),this.cancelRetry(),this.cancelSchedules(),this.viewport.releaseAutoscale())}refuse(t){const o=this.viewport.currentStage(),s=(null==o?void 0:o.getAttribute(e.REFUSED_HOST_ATTRIBUTE))||t||"NOT_FOUND";this.stop(),this.host.removeAttribute("data-widgetic-mounting"),this.host.removeAttribute("data-widgetic-mounted"),this.host.style.display=this.displayBeforeMounting,this.host.setAttribute(e.REFUSED_HOST_ATTRIBUTE,s),i.log.debug("[workflows] The composition of the tag cannot be shown",{workflowId:this.workflowId,reason:s})}listenToThePage(){this.host.addEventListener(d.WORKFLOW_EVENT_TYPE,this.onPageEvent),document.addEventListener("visibilitychange",this.onVisibilityChange),this.removeListeners.push((()=>this.host.removeEventListener(d.WORKFLOW_EVENT_TYPE,this.onPageEvent)),(()=>document.removeEventListener("visibilitychange",this.onVisibilityChange)))}drainPageEvents(){const e=this.pageEvents.take();for(let t=0;t<e.length;t+=1){if("running"!==this.mode)return;if(this.stepping){for(const i of e.slice(t))this.pageEvents.add(i);return}const i=e[t];this.react([{type:"pageEvent",name:i.name,values:i.values}])}}onStageCreated(e){if(this.stages.set(e,{signals:null,stopWatchingReady:null}),null!==this.pendingStageNodeId){const t=this.pendingStageNodeId;this.pendingStageNodeId=null,this.armStage(e,t)}}onStageRemoved(e){var t,i;const o=this.stages.get(e);null===(t=null==o?void 0:o.signals)||void 0===t||t.stop(),null===(i=null==o?void 0:o.stopWatchingReady)||void 0===i||i.call(o),this.stages.delete(e)}armStage(e,i){var o,s,n;const r=this.workflow,d=this.index;if(!r||!d)return;const a=d.nodesById.get(i);if(!v(a))return;const l=null!==(o=this.stages.get(e))&&void 0!==o?o:{signals:null,stopWatchingReady:null};null===(s=l.signals)||void 0===s||s.stop(),null===(n=l.stopWatchingReady)||void 0===n||n.call(l),this.stages.set(e,l);const u=V(r.graph,i,{index:d});l.signals=we({stage:e,watch:u,emit:t=>this.onSignals(e,t)});const c=t.buildWorkflowWatch(u);if(0===c.tables.length&&0===c.fields.length&&0===c.goals.length)return;const h=()=>this.services.deliverWatch(e,a.compositionId,c);h(),e.addEventListener("widgetic:ready",h),l.stopWatchingReady=()=>e.removeEventListener("widgetic:ready",h)}onSignals(e,t){"running"!==this.mode||this.stepping||this.hasEnded()||e===this.viewport.currentStage()&&this.react(t)}react(e){const t=this.workflow,o=this.index,s=this.position;if(t&&o&&s)for(const n of e){let e;try{e=F(t.graph,{nodeId:s.nodeId},n,{index:o})}catch(e){i.log.debug("[workflows] The engine could not decide on a signal",{signal:n.type,error:e});continue}if("moved"===e.outcome)return void this.moveOn(e,!1)}}moveOn(e,t){return h(this,void 0,void 0,(function*(){const o=this.index,s=this.position;if(!o||!s)return;const n=o.nodesById.get(e.position.nodeId);if(!v(n))return;let r;this.stepping=!0,this.cancelRetry(),this.cancelSchedules(),this.pendingStageNodeId=n.id;try{r=yield this.viewport.swapTo(n.compositionId)}catch(e){i.log.debug("[workflows] The next composition could not be built",{compositionId:n.compositionId,error:e}),r={status:"failed",reason:"error"}}this.pendingStageNodeId=null,this.stepping=!1,this.hasEnded()||("shown"===r.status?this.completeStep(e,n,s):this.failStep(e,n,s,t))}))}completeStep(e,t,o){const s=Object.assign(Object.assign({},o),{nodeId:t.id,compositionId:t.compositionId,reachedAt:Date.now()});this.position=s,ie(this.workflowId,s),this.countStep(o.nodeId,e,t.id),i.log.debug("[workflows] The visitor moved on",{from:o.compositionId,to:t.compositionId}),this.host.dispatchEvent(new CustomEvent(d.WORKFLOW_STEP_EVENT_TYPE,{detail:{workflowId:this.workflowId,from:o.compositionId,to:t.compositionId},bubbles:!0,composed:!0})),this.armSchedules(),this.getNextCompositionsReady(),this.drainPageEvents()}countStep(e,t,i){const o=this.counts,s=this.index;if(!o||!s)return;const n=m(s,e).find((e=>e.target===t.firedTriggerId));n&&o.count("e",n.id);for(const e of t.passedNodeIds)o.count("n",e);for(const e of t.takenEdgeIds)o.count("e",e);o.count("n",i)}failStep(e,t,o,s){var n;null===(n=this.counts)||void 0===n||n.count("f",t.id),i.log.debug("[workflows] The next composition could not be shown, so the visitor stays where they are",{compositionId:t.compositionId,isRetry:s}),this.armSchedules(),s||this.scheduleRetry(e,o.nodeId),this.drainPageEvents()}scheduleRetry(e,t){this.cancelRetry(),this.retryTimer=setTimeout((()=>{var i;this.retryTimer=null,"running"!==this.mode||this.stepping||this.hasEnded()||(null===(i=this.position)||void 0===i?void 0:i.nodeId)===t&&this.moveOn(e,!0)}),3e4)}cancelRetry(){null!==this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=null}armSchedules(){this.cancelSchedules();const e=this.workflow,t=this.index,o=this.position;if("running"===this.mode&&!this.stepping&&e&&t&&o)for(const{triggerId:s,schedule:n}of V(e.graph,o.nodeId,{index:t}).schedules){const e=M(n,o.reachedAt,Date.now());void 0!==e?this.waitFor(s,n,o.nodeId,e):i.log.debug("[workflows] A Scheduled trigger has no usable time and is ignored",{triggerId:s})}}waitFor(e,t,o,s){const n=setTimeout((()=>{this.scheduleTimers.delete(n);const s=this.position;if("running"!==this.mode||this.stepping||this.hasEnded()||!s||s.nodeId!==o)return;const r=M(t,s.reachedAt,Date.now());void 0!==r&&(r>0?this.waitFor(e,t,o,r):(i.log.debug("[workflows] A wait is over",{triggerId:e}),this.react([{type:"scheduled",triggerId:e}])))}),Math.min(s,432e5));this.scheduleTimers.add(n)}cancelSchedules(){for(const e of this.scheduleTimers)clearTimeout(e);this.scheduleTimers.clear()}getNextCompositionsReady(){var e,t;null===(e=this.cancelIdleWork)||void 0===e||e.call(this),this.cancelIdleWork=null;const i=null===(t=this.position)||void 0===t?void 0:t.nodeId;i&&(this.cancelIdleWork=this.services.whenIdle((()=>{var e;if(this.cancelIdleWork=null,"running"!==this.mode||this.hasEnded()||(null===(e=this.position)||void 0===e?void 0:e.nodeId)!==i)return;let t=0;for(const e of this.compositionsReachableFrom(i))if(!this.readiedCompositions.has(e)){if(t>=5)break;this.readiedCompositions.add(e),t+=1,this.services.prefetchComposition(e)}})))}compositionsReachableFrom(e){const t=this.index;if(!t)return[];const i=[],o=new Set;for(const s of b(t,e)){const e=[s.id];for(;e.length>0;){const s=e.pop();if(!o.has(s)){o.add(s);for(const o of m(t,s)){const s=t.nodesById.get(o.target);v(s)?i.includes(s.compositionId)||i.push(s.compositionId):w(s)&&e.push(s.id)}}}}return i}hasEnded(){return"ended"===this.mode||!this.host.isConnected&&(i.log.debug("[workflows] The tag left the page, so its workflow ends",{workflowId:this.workflowId}),this.stop(),!0)}stop(){var e,t,o,s,n;if("ended"!==this.mode){try{null===(e=this.counts)||void 0===e||e.flushBeforeLeaving()}catch(e){i.log.debug("[workflows] The last counts could not be sent",{error:e})}this.mode="ended",this.cancelRetry(),this.cancelSchedules(),null===(t=this.cancelIdleWork)||void 0===t||t.call(this),this.cancelIdleWork=null;for(const e of this.removeListeners.splice(0))e();for(const e of this.stages.values())null===(o=e.signals)||void 0===o||o.stop(),null===(s=e.stopWatchingReady)||void 0===s||s.call(e);this.stages.clear(),this.pageEvents.clear();try{null===(n=this.counts)||void 0===n||n.dispose()}catch(e){i.log.debug("[workflows] The counts could not be closed",{error:e})}this.viewport.destroy()}}}window.__widgeticEmbedWorkflows=Object.freeze({contractVersion:1,startWorkflowEmbed:function(e,t){var o,s,n;const d=(null!==(o=e.getAttribute("workflow-id"))&&void 0!==o?o:"").trim(),a=(null!==(s=e.getAttribute("composition-id"))&&void 0!==s?s:"").trim();if(!le(d)||""===a)return i.log.debug("[workflows] The tag is not a workflow embed, so it is embedded as it is",{workflowId:d,tagCompositionId:a}),null;const l={fetchWorkflow:ge,createCounts:e=>new re(e),deliverWatch:Me,prefetchComposition:Le,whenIdle:xe,viewport:{}},u=Object.assign(Object.assign(Object.assign({},l),t.services),{viewport:Object.assign(Object.assign({},l.viewport),null===(n=t.services)||void 0===n?void 0:n.viewport)}),c=new Fe(e,d,a,t,u);try{c.start()}catch(e){return i.log.warn("[workflows] The workflow could not start, so the tag is embedded as it is",{workflowId:d,error:e}),c.stop(),null}const h={stop:()=>c.stop()};return r.registerWorkflowEmbed(e,h),h}})}((window.__widgeticEmbedSharedServices||{}).hostBridgeMarkers,(window.__widgeticEmbedSharedServices||{}).hostWorkflowWatch,(window.__widgeticEmbedSharedServices||{}).logger,(window.__widgeticEmbedSharedServices||{}).mountDirectWidget,(window.__widgeticEmbedSharedServices||{}).publicEmbedLookup,(window.__widgeticEmbedSharedServices||{}).publishedHostBridge,(window.__widgeticEmbedSharedServices||{}).workflowEmbedRegistry,(window.__widgeticEmbedSharedServices||{}).workflowPageEvents,(window.__widgeticEmbedSharedServices||{}).abVisitor,(window.__widgeticEmbedSharedServices||{}).autoscaleManager,(window.__widgeticEmbedSharedServices||{}).declarativeEmbedParser,(window.__widgeticEmbedSharedServices||{}).publishedHostDisplay);
|
|
1
|
+
!function(t,e,o,i,s,n,r,d,a,l,u,c){"use strict";function h(t,e,o,i){return new(o||(o=Promise))((function(s,n){function r(t){try{a(i.next(t))}catch(t){n(t)}}function d(t){try{a(i.throw(t))}catch(t){n(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(r,d)}a((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const g=/^[A-Za-z0-9_-]{1,64}$/;function p(t){const e=new Map;for(const o of t.nodes)e.has(o.id)||e.set(o.id,o);const o=new Map,i=new Map;for(const e of t.edges)f(o,e.source,e),f(i,e.target,e);return{graph:t,nodesById:e,outgoingBySource:o,incomingByTarget:i}}function f(t,e,o){const i=t.get(e);i?i.push(o):t.set(e,[o])}function m(t,e){return t.outgoingBySource.get(e)??[]}function v(t){return"composition"===t?.type}function w(t){return"condition"===t?.type}function b(t,e){const o=[];for(const s of m(t,e)){const e=t.nodesById.get(s.target);i=e,"trigger"===i?.type&&o.push(e)}var i;return o}function y(t,e,o){return m(t,e).find((t=>t.sourcePort===o))}const I={text:["is","isNot","contains","doesNotContain","startsWith","endsWith","isEmpty","isNotEmpty"],number:["is","isNot","greaterThan","atLeast","lessThan","atMost","isEmpty","isNotEmpty"],boolean:["is","isNot"]},k=["is","isNot","contains","doesNotContain","startsWith","endsWith","greaterThan","atLeast","lessThan","atMost","isEmpty","isNotEmpty"];function T(t){return null==t||"string"==typeof t&&""===t.trim()}function E(t){return null==t?"":String(t).trim().toLowerCase()}function S(t){if("number"==typeof t)return Number.isFinite(t)?t:void 0;if("string"==typeof t){const e=t.trim();if(""===e)return;const o=Number(e);return Number.isFinite(o)?o:void 0}}const A=new Set(["true","yes","1","on"]),C=new Set(["false","no","0","off"]);function O(t){if("boolean"==typeof t)return t;if("number"==typeof t)return 1===t||0!==t&&void 0;if("string"==typeof t){const e=t.trim().toLowerCase();if(A.has(e))return!0;if(C.has(e))return!1}}function W(t,e){const{operator:o}=t;if("isEmpty"===o)return T(e);if("isNotEmpty"===o)return!T(e);if(!function(t,e){return I[e].includes(t)}(o,t.field.type))return!1;switch(t.field.type){case"number":return function(t,e,o){const i=S(e),s=S(o);if("isNot"===t)return void 0===i||void 0===s||i!==s;if(void 0===i||void 0===s)return!1;switch(t){case"is":return i===s;case"greaterThan":return i>s;case"atLeast":return i>=s;case"lessThan":return i<s;case"atMost":return i<=s;default:return!1}}(o,e,t.value);case"boolean":return function(t,e,o){const i=O(e),s=O(o),n=void 0!==i&&void 0!==s&&i===s;return"is"===t?n:"isNot"===t&&!n}(o,e,t.value);default:return function(t,e,o){const i=E(e),s=E(o),n=T(e);switch(t){case"is":return!n&&i===s;case"isNot":return n||i!==s;case"contains":return!n&&""!==s&&i.includes(s);case"doesNotContain":return n||""===s||!i.includes(s);case"startsWith":return!n&&""!==s&&i.startsWith(s);case"endsWith":return!n&&""!==s&&i.endsWith(s);default:return!1}}(o,e,t.value)}}function H(t,e){if(0===t.tests.length)return!1;const o=t=>W(t,e(t.field));return"any"===t.match?t.tests.some(o):t.tests.every(o)}const N={seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5},_=["seconds","minutes","hours","days","weeks"],M=365*N.days;function L(t){return"string"==typeof t&&_.includes(t)}function P(t,e){if("after"===t.mode){const o=function(t,e){if("number"!=typeof t||!Number.isInteger(t)||t<1)return;if(!L(e))return;const o=t*N[e];return o<=M?o:void 0}(t.amount,t.unit);if(void 0===o||!Number.isFinite(e))return;return e+o}if("at"===t.mode){const e=Date.parse(t.at);return Number.isFinite(e)?e:void 0}}function $(t,e,o){const i=P(t,e);return void 0===i?void 0:Math.max(0,i-o)}function R(t,e){const o=t.trigger;switch(e.type){case"input":return"input"===o.kind&&o.table===e.table;case"action":return"action"===o.kind&&o.actionId===e.actionId;case"pageEvent":return"pageEvent"===o.kind&&o.name===e.name;case"scheduled":return"scheduled"===o.kind&&t.id===e.triggerId;default:return!1}}function F(t,e,o){const i=[e.id],s=[],n=function(t){const e="input"===t.type||"pageEvent"===t.type?t.values:void 0,o="input"===t.type?"input":"pageEvent"===t.type?"event":void 0;return t=>{if(e&&t.kind===o)return Object.prototype.hasOwnProperty.call(e,t.name)?e[t.name]:void 0}}(o);let r=y(t,e.id,"out");for(let e=0;e<=25&&r;e+=1){s.push(r.id);const e=t.nodesById.get(r.target);if(v(e))return{destination:e,passedNodeIds:i,takenEdgeIds:s};if(!w(e))break;i.push(e.id);const o=e.cases.find((t=>H(t,n)));r=y(t,e.id,o?o.id:"default")}return{passedNodeIds:i,takenEdgeIds:s}}function B(t,e,o,i={}){const s=i.index??p(t),n=s.nodesById.get(e.nodeId);if(!v(n))return{outcome:"ignored",reason:"unknown_position"};const r=[];for(const t of b(s,n.id)){if(!R(t,o))continue;r.push(t.id);const e=F(s,t,o);if(e.destination&&e.destination.id!==n.id)return{outcome:"moved",position:{nodeId:e.destination.id},firedTriggerId:t.id,passedNodeIds:e.passedNodeIds,takenEdgeIds:e.takenEdgeIds}}return r.length>0?{outcome:"stayed",firedTriggerIds:r}:{outcome:"ignored",reason:"no_matching_trigger"}}function x(t,e,o){t.some((t=>o(t,e)))||t.push(e)}function j(t,e,o,i){const s=[],n=y(t,e,"out");n&&s.push(n.target);const r=new Set;for(;s.length>0;){const e=s.pop();if(r.has(e))continue;r.add(e);const n=t.nodesById.get(e);if(w(n)){for(const t of n.cases)for(const e of t.tests)"input"===e.field.kind&&x(i,{table:o,column:e.field.name},((t,e)=>t.table===e.table&&t.column===e.column));for(const o of m(t,e))s.push(o.target)}}}function z(t,e,o={}){const i=o.index??p(t),s={inputTables:[],inputColumns:[],actionIds:[],pageEventNames:[],schedules:[]},n=(t,e)=>t===e;for(const t of b(i,e)){const e=t.trigger;switch(e.kind){case"input":if(""===e.table)break;x(s.inputTables,e.table,n),j(i,t.id,e.table,s.inputColumns);break;case"action":""!==e.actionId&&x(s.actionIds,e.actionId,n);break;case"pageEvent":""!==e.name&&x(s.pageEventNames,e.name,n);break;case"scheduled":s.schedules.push({triggerId:t.id,schedule:e.schedule})}}return s}class V{issues=[];report(t,e){this.issues.push({code:t,severity:"error",detail:e})}}function D(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function U(t){return"string"==typeof t&&g.test(t)?t:void 0}function q(t,e=200){return"string"==typeof t&&t.length<=e?t:void 0}function Z(t){return"text"===t||"number"===t||"boolean"===t?t:void 0}function G(t,e,o){if(!D(t))return void o.report("malformed",e);const i=function(t,e,o){if(!D(t))return void o.report("malformed",e);const i="input"===t.kind||"event"===t.kind?t.kind:void 0,s=q(t.name,64),n=Z(t.type);if(i&&void 0!==s&&n)return{kind:i,name:s,type:n};o.report("malformed",e)}(t.field,`${e}.field`,o),s=function(t){return"string"==typeof t&&k.includes(t)?t:void 0}(t.operator);let n;return s||o.report("malformed",`${e}.operator`),void 0!==t.value&&(n=function(t){return null===t||"boolean"==typeof t?t:"number"==typeof t?Number.isFinite(t)?t:void 0:q(t)}(t.value),void 0===n&&o.report("malformed",`${e}.value`)),i&&s?void 0===n?{field:i,operator:s}:{field:i,operator:s,value:n}:void 0}function Y(t,e,o){if(D(t))switch(t.kind){case"input":{const i=q(t.table);return void 0===i&&o.report("malformed",`${e}.table`),void 0===i?void 0:{kind:"input",table:i}}case"action":{const i=q(t.actionId);return void 0===i&&o.report("malformed",`${e}.actionId`),void 0===i?void 0:{kind:"action",actionId:i}}case"pageEvent":{const i=q(t.name,64);void 0===i&&o.report("malformed",`${e}.name`);const s=function(t,e,o){if(!Array.isArray(t)||t.length>100)return void o.report("malformed",e);const i=[];return t.forEach(((t,s)=>{const n=D(t)?q(t.name,64):void 0,r=D(t)?Z(t.type):void 0;void 0!==n&&r?i.push({name:n,type:r}):o.report("malformed",`${e}[${s}]`)})),i}(t.values,`${e}.values`,o);return void 0!==i&&s?{kind:"pageEvent",name:i,values:s}:void 0}case"scheduled":{const i=function(t,e,o){if(D(t)&&"after"===t.mode&&"number"==typeof t.amount&&L(t.unit)&&Number.isFinite(t.amount))return{mode:"after",amount:t.amount,unit:t.unit};if(D(t)&&"at"===t.mode){const e=q(t.at,64);if(void 0!==e)return{mode:"at",at:e}}o.report("malformed",e)}(t.schedule,`${e}.schedule`,o);return i?{kind:"scheduled",schedule:i}:void 0}default:return void o.report("unknown_trigger_kind",`${e}.kind`)}else o.report("malformed",e)}function J(t,e,o){if(!D(t))return void o.report("malformed",e);const i=U(t.id);i||o.report("bad_id",`${e}.id`);const s=function(t){if(void 0!==t)return D(t)&&"number"==typeof t.x&&"number"==typeof t.y&&Number.isFinite(t.x)&&Number.isFinite(t.y)?{x:t.x,y:t.y}:"invalid"}(t.position);"invalid"===s&&o.report("malformed",`${e}.position`);const n=i&&"invalid"!==s?s?{id:i,position:s}:{id:i}:void 0;switch(t.type){case"composition":{const i=q(t.compositionId,200);if(void 0===i&&o.report("malformed",`${e}.compositionId`),void 0!==t.startsHere&&"boolean"!=typeof t.startsHere)return void o.report("malformed",`${e}.startsHere`);if(!n||void 0===i)return;return!0===t.startsHere?{...n,type:"composition",compositionId:i,startsHere:!0}:{...n,type:"composition",compositionId:i}}case"trigger":{const i=Y(t.trigger,`${e}.trigger`,o);return n&&i?{...n,type:"trigger",trigger:i}:void 0}case"condition":{if(!Array.isArray(t.cases)||t.cases.length>100)return void o.report("malformed",`${e}.cases`);const i=[];return t.cases.forEach(((t,s)=>{const n=function(t,e,o){if(!D(t)||!Array.isArray(t.tests)||t.tests.length>100)return void o.report("malformed",e);const i=U(t.id),s="all"===t.match||"any"===t.match?t.match:void 0;let n;i||o.report("bad_id",`${e}.id`),s||o.report("malformed",`${e}.match`),void 0!==t.label&&(n=q(t.label),void 0===n&&o.report("malformed",`${e}.label`));const r=[];return t.tests.forEach(((t,i)=>{const s=G(t,`${e}.tests[${i}]`,o);s&&r.push(s)})),i&&s?void 0===n?{id:i,match:s,tests:r}:{id:i,label:n,match:s,tests:r}:void 0}(t,`${e}.cases[${s}]`,o);n&&i.push(n)})),n?{...n,type:"condition",cases:i}:void 0}default:return void o.report("unknown_node_type",`${e}.type`)}}function K(t){const e=new V;if(!D(t))return e.report("malformed","graph"),{issues:e.issues};if(1!==t.schemaVersion)return e.report("schema_version","schemaVersion"),{issues:e.issues};if(!Array.isArray(t.nodes)||!Array.isArray(t.edges))return e.report("malformed","nodes/edges"),{issues:e.issues};if(t.nodes.length>100||t.edges.length>300)return e.report("graph_too_large","nodes/edges"),{issues:e.issues};const o=[];t.nodes.forEach(((t,i)=>{const s=J(t,`nodes[${i}]`,e);s&&o.push(s)}));const i=[];return t.edges.forEach(((t,o)=>{const s=function(t,e,o){if(!D(t))return void o.report("malformed",e);const i=U(t.id),s=U(t.source),n=U(t.sourcePort),r=U(t.target);return i||o.report("bad_id",`${e}.id`),s&&n&&r||o.report("malformed",e),i&&s&&n&&r?{id:i,source:s,sourcePort:n,target:r}:void 0}(t,`edges[${o}]`,e);s&&i.push(s)})),e.issues.length>0?{issues:e.issues}:{graph:{schemaVersion:1,nodes:o,edges:i},issues:[]}}const Q=/^[A-Za-z0-9_.:-]{1,128}$/;function X(t){return`widgetic_workflow_${t}`}function tt(t){return"string"==typeof t&&Q.test(t)}function et(t){return"number"==typeof t&&Number.isFinite(t)&&t>=0}function ot(t,e){try{a.writeStoredValue(X(t),JSON.stringify({v:1,versionId:e.versionId,nodeId:e.nodeId,compositionId:e.compositionId,startedAt:e.startedAt,reachedAt:e.reachedAt}))}catch(e){o.log.debug("[workflows] The visitor's position could not be kept",{workflowId:t,error:e})}}function it(t){a.removeStoredValue(X(t))}const st=/^[A-Za-z0-9_-]{1,64}$/,nt=new Set(["n","e","f"]);class rt{constructor(t){this.pending=[],this.lastEventOf=new Map,this.flushTimer=null,this.stopped=!1,this.listening=!1,this.onPageHide=()=>{this.flushBeforeLeaving()},this.onVisibilityChange=()=>{"hidden"===document.visibilityState&&this.flushBeforeLeaving()},this.options=t}isStopped(){return this.stopped}start(){this.listening||this.stopped||(this.listening=!0,window.addEventListener("pagehide",this.onPageHide),document.addEventListener("visibilitychange",this.onVisibilityChange))}count(t,e,o=1){if(this.stopped||!this.options.token)return;if(!nt.has(t)||!st.test(e)||!Number.isInteger(o)||o<1)return;const i=`${t}:${e}`;let s=o;for(;s>0;){let o=this.lastEventOf.get(i);(!o||o.c>=50)&&(o={k:t,id:e,c:0},this.pending.push(o),this.lastEventOf.set(i,o));const n=Math.min(s,50-o.c);o.c+=n,s-=n}this.pending.length>=100?this.flush():null===this.flushTimer&&(this.flushTimer=setTimeout((()=>this.flush()),2e3))}flushBeforeLeaving(){if(!this.stopped&&this.options.token)for(;this.pending.length>0;){const t=this.takeBatch();if(!this.options.isActive())return void this.forgetPending();this.sendWithBeacon(t)}}dispose(){this.stopped=!0,this.forgetPending(),this.listening&&(window.removeEventListener("pagehide",this.onPageHide),document.removeEventListener("visibilitychange",this.onVisibilityChange),this.listening=!1)}takeBatch(){const t=this.pending.splice(0,100);for(const e of t){const t=`${e.k}:${e.id}`;this.lastEventOf.get(t)===e&&this.lastEventOf.delete(t)}return t}forgetPending(){null!==this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.pending=[],this.lastEventOf.clear()}flush(){if(null!==this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.stopped||0===this.pending.length)return;if(!this.options.isActive())return void this.forgetPending();const t=this.takeBatch();this.sendWithRequest(t),this.pending.length>0&&null===this.flushTimer&&(this.flushTimer=setTimeout((()=>this.flush()),2e3))}reportAddress(){return`${this.options.apiOrigin}/embed/workflows/${encodeURIComponent(this.options.workflowId)}/events`}reportBody(t){return JSON.stringify({versionId:this.options.versionId,token:this.options.token,events:t.map((t=>t.c>1?{k:t.k,id:t.id,c:t.c}:{k:t.k,id:t.id}))})}sendWithBeacon(t){try{const e=this.reportBody(t),i="undefined"!=typeof navigator?navigator.sendBeacon:void 0;if("function"==typeof i&&i.call(navigator,this.reportAddress(),new Blob([e],{type:"text/plain"})))return void o.log.debug("[workflows] Counts handed to the browser to send",{eventCount:t.length})}catch(t){o.log.debug("[workflows] The browser would not take counts to send as the page closes",{error:t})}this.sendWithRequest(t)}sendWithRequest(t){return h(this,void 0,void 0,(function*(){try{const e=yield fetch(this.reportAddress(),{method:"POST",mode:"cors",credentials:"omit",keepalive:!0,headers:{"Content-Type":"text/plain"},body:this.reportBody(t)});if(401===e.status)return o.log.warn("[workflows] The gateway refused the token for counts, so this embed stops reporting",{workflowId:this.options.workflowId}),void this.dispose();o.log.debug("[workflows] Counts sent",{eventCount:t.length,status:e.status})}catch(e){o.log.debug("[workflows] Counts could not be sent and were dropped",{eventCount:t.length,error:e})}}))}}const dt=/^[a-z0-9]{1,8}(-[a-z0-9]{1,8}){0,4}$/,at=/^[A-Za-z0-9_.:-]{1,128}$/;function lt(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function ut(t){if("string"!=typeof t||t.length>35)return null;const e=t.toLowerCase();return dt.test(e)?e:null}function ct(){var t,e;try{if("undefined"==typeof navigator)return[];const o=String(null!==(t=navigator.language)&&void 0!==t?t:"").toLowerCase(),i=((null===(e=navigator.languages)||void 0===e?void 0:e.map((t=>String(t).toLowerCase())))||[o]).flatMap((t=>{const e=[t];return t.includes("-")&&e.push(t.split("-")[0]),e}));return[...new Set(i)].filter((t=>""!==t))}catch(t){return o.log.debug("[workflows] The languages of the browser could not be read",{error:t}),[]}}function ht(t,e,o){if(!e||0===o.length||!Object.prototype.hasOwnProperty.call(e,t))return t;const i=e[t],{language:s}=function(t,e){const o=Object.keys(e.compositions);for(const e of t)if(o.includes(e))return{language:e,match:"exact"};for(const e of t){const t=e.split("-")[0],i=o.find((e=>e.startsWith(`${t}-`)||e===t));if(void 0!==i)return{language:i,match:"family"}}return{language:e.rootLanguage,match:"root"}}(o,i);return s===i.rootLanguage?t:i.compositions[s]||t}const gt=/^[A-Za-z0-9_-]{1,64}$/,pt=/^[A-Za-z0-9_.:-]{1,128}$/;function ft(t){return gt.test(t)}function mt(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function vt(t,e){var i;if(!mt(t)||!0!==t.success||!mt(t.data))return{kind:"unreadable"};const s=t.data;if("paused"===s.status)return{kind:"paused"};if("live"!==s.status)return{kind:"unreadable"};if("string"!=typeof s.versionId||!pt.test(s.versionId))return{kind:"unreadable"};const n=K(s.graph);if(!n.graph||n.issues.length>0)return o.log.warn("[workflows] The published graph could not be read, so the embed stays a plain embed",{workflowId:e,issueCount:n.issues.length,firstIssue:null===(i=n.issues[0])||void 0===i?void 0:i.code}),{kind:"unreadable"};const r={workflowId:"string"==typeof s.workflowId?s.workflowId:e,versionId:s.versionId,timezone:"string"==typeof s.timezone&&""!==s.timezone.trim()&&s.timezone.length<=64?s.timezone:"UTC",graph:n.graph};"number"==typeof s.versionNumber&&Number.isInteger(s.versionNumber)&&(r.versionNumber=s.versionNumber),"string"==typeof s.publishedAt&&(r.publishedAt=s.publishedAt),"string"==typeof s.startCompositionId&&pt.test(s.startCompositionId)&&(r.startCompositionId=s.startCompositionId);const d=function(t){if(!lt(t))return;const e=Object.create(null);let o=0;for(const[i,s]of Object.entries(t)){if(o>=64)break;if(!at.test(i)||!lt(s))continue;const t=ut(s.rootLanguage);if(null===t||!lt(s.compositions))continue;const n=Object.create(null);let r=0;for(const[t,e]of Object.entries(s.compositions)){if(r>=128)break;const o=ut(t);null!==o&&"string"==typeof e&&at.test(e)&&(n[o]=e,r+=1)}0!==r&&(e[i]={rootLanguage:t,compositions:n},o+=1)}return 0===o?void 0:e}(s.translations);return d&&(r.translations=d),"string"==typeof s.eventToken&&""!==s.eventToken&&s.eventToken.length<=2048&&(r.eventToken=s.eventToken),{kind:"live",workflow:r}}function wt(t,e){return h(this,void 0,void 0,(function*(){const i=new AbortController,s=setTimeout((()=>i.abort()),1e4);try{const o=yield fetch(t,{method:"GET",mode:"cors",signal:i.signal});if(404===o.status)return{kind:"missing"};if(!o.ok)return{kind:"unreachable"};let s;try{s=yield o.json()}catch(t){return{kind:"unreadable"}}const n=vt(s,e);return"live"===n.kind?{kind:"live",workflow:n.workflow}:n}catch(t){return o.log.debug("[workflows] A host could not be reached",{workflowId:e,error:t}),{kind:"unreachable"}}finally{clearTimeout(s)}}))}const bt=new Map;function yt(t,e={}){var i,n;if(!ft(t)||void 0!==e.versionId&&!pt.test(e.versionId))return Promise.resolve({status:"unavailable",reason:"not_found"});const r=`${t}|${null!==(i=e.versionId)&&void 0!==i?i:""}|${(null!==(n=e.origins)&&void 0!==n?n:[]).join(",")}`,d=bt.get(r);if(d)return d;const a=function(t,e){return h(this,void 0,void 0,(function*(){var i;const n=null!==(i=e.origins)&&void 0!==i?i:s.publicEmbedApiOrigins(),r=e.versionId?`/embed/workflows/${encodeURIComponent(t)}/versions/${encodeURIComponent(e.versionId)}`:`/embed/workflows/${encodeURIComponent(t)}`;let d=!1,a=!1;for(const e of n){const o=yield wt(`${e}${r}`,t);if("live"===o.kind)return{status:"live",workflow:o.workflow,origin:e};if("paused"===o.kind)return{status:"paused"};"missing"===o.kind&&(d=!0),"unreadable"===o.kind&&(a=!0)}const l=d?"not_found":a?"unreadable":"unreachable";return o.log.debug("[workflows] The workflow is not available",{workflowId:t,reason:l}),{status:"unavailable",reason:l}}))}(t,e);return bt.set(r,a),a.finally((()=>{bt.get(r)===a&&bt.delete(r)})),a}const It={clicks:"click",submissions:"submit",plays:"play"},kt=new Set(["__proto__","constructor","prototype"]);function Tt(t){const e=t.detail;return"object"!=typeof e||null===e||Array.isArray(e)?{}:e}function Et(t,e){return("submissions"!==t.metric||"FORM"===e.tagName)&&(("plays"!==t.metric||"VIDEO"===e.tagName||"AUDIO"===e.tagName)&&(null!==t.selector?a.elementMatchesGoalTarget(e,t.selector):"clicks"!==t.metric||null!==e.closest('button, a, input[type="button"], input[type="submit"], [role="button"], [onclick], [data-click-track]')))}function St({stage:t,watch:i,emit:s}){var n;let r=!1;const d=[];if(i.inputTables.length>0){const e=new Map;for(const{table:t,column:o}of i.inputColumns){const i=null!==(n=e.get(t))&&void 0!==n?n:new Set;i.add(o),e.set(t,i)}const a=new Set,l=t=>{var n;if(r)return;const d=Tt(t),l=d.table;if("string"!=typeof l||!i.inputTables.includes(l))return;if("string"==typeof d.entryId&&""!==d.entryId){const t=`${l}:${d.entryId}`;if(a.has(t))return;if(a.add(t),a.size>100){const t=a.values().next().value;void 0!==t&&a.delete(t)}}const u=function(t,e){const o={};if("object"!=typeof t||null===t||Array.isArray(t))return o;for(const i of e){if(kt.has(i))continue;if(!Object.prototype.hasOwnProperty.call(t,i))continue;const e=t[i];"string"==typeof e?o[i]=e.length>200?e.slice(0,200):e:("number"==typeof e&&Number.isFinite(e)||"boolean"==typeof e)&&(o[i]=e)}return o}(d.values,null!==(n=e.get(l))&&void 0!==n?n:new Set);o.log.debug("[workflows] An entry was saved in a watched table",{table:l,valueCount:Object.keys(u).length}),s([{type:"input",table:l,values:u}])};t.addEventListener("widgetic:submitted",l),d.push((()=>t.removeEventListener("widgetic:submitted",l)))}if(i.actionIds.length>0){const n=t=>{if(r)return;const e=Tt(t);let n=null;"string"==typeof e.goalId?n=e.goalId:"string"==typeof e.metric&&""!==e.metric&&(n="string"==typeof e.goalTarget&&""!==e.goalTarget?`${e.metric}@${e.goalTarget}`:e.metric),null!==n&&i.actionIds.includes(n)&&(o.log.debug("[workflows] A widget reported a watched action",{actionId:n}),s([{type:"action",actionId:n}]))};t.addEventListener("widgetic:goal",n),d.push((()=>t.removeEventListener("widgetic:goal",n)));const l=[];for(const t of i.actionIds){const o=e.splitActionId(t);o&&(a=o.metric,Object.prototype.hasOwnProperty.call(It,a))&&l.push({actionId:t,metric:o.metric,selector:o.selector})}if(l.length>0){let e=null,i=()=>{};const n=t=>{const e=t.target instanceof Element?t.target:null;if(!e)return[];const o=[];for(const i of l)It[i.metric]===t.type&&Et(i,e)&&o.push({type:"action",actionId:i.actionId});return o},a=t=>{if(r)return;const e=n(t);0!==e.length&&(o.log.debug("[workflows] A watched action happened in the widget",{actionIds:e.map((t=>t.actionId))}),s(e))},u=()=>{var o;const s=t.querySelector("[data-widgetic-direct]"),n=null!==(o=null==s?void 0:s.shadowRoot)&&void 0!==o?o:null;if(!n||n===e)return;i();const r=new Set(l.map((t=>It[t.metric])));for(const t of r)n.addEventListener(t,a,!0);e=n,i=()=>{for(const t of r)n.removeEventListener(t,a,!0);e=null,i=()=>{}}};t.addEventListener("widgetic:ready",u),d.push((()=>t.removeEventListener("widgetic:ready",u))),d.push((()=>i())),u()}}var a;return{stop:()=>{if(!r){r=!0;for(const t of d)try{t()}catch(t){o.log.debug("[workflows] A listener could not be removed",{error:t})}}}}}const At=50,Ct=2e3,Ot=150,Wt=5,Ht=300,Nt=2e4;function _t(t,e,o,i){const s=t.getAttribute(e);if(null===s||!/^\d+$/.test(s.trim()))return o;const n=Number.parseInt(s.trim(),10);return Number.isFinite(n)?Math.min(n,i):o}function Mt(t,e,o){const i="number"==typeof o&&Number.isFinite(o)&&o>0?Math.min(e.maxHeight,Math.floor(o)):e.maxHeight,s=Math.min(e.minHeight,i);return Number.isNaN(t)?s:Math.max(s,Math.min(i,Math.ceil(t)))}function Lt(t,e,o){return null===t||e!==t&&Math.abs(e-t)>=o}const Pt=["width","height","resize","resize-mode","render-mode","use-iframe","theme","mode","colors","sandbox","autoload","adaptive","responsive"],$t=["values","context","media-resolver"],Rt=["design","content","content-items","contentitems","items"];function Ft(t){if("undefined"==typeof ResizeObserver)return null;try{return new ResizeObserver((e=>{t(e.map((t=>({target:t.target,height:t.contentRect.height}))))}))}catch(t){return o.log.debug("[workflows] The browser could not watch heights",{error:t}),null}}function Bt(t){return t.getBoundingClientRect().height}function xt(){try{return"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}catch(t){return!1}}function jt(t){return"number"==typeof t&&Number.isFinite(t)&&t>0}class zt{constructor(t){var e;this.current=null,this.incoming=null,this.heightObserver=null,this.attributeObserver=null,this.autoscaleOn=!1,this.appliedHeight=null,this.debounceTimer=null,this.pendingHeight=null,this.destroyed=!1,this.warnedAboutFrameWithoutHeight=!1,this.host=t.host,this.services=t.services,this.prefersReducedMotion=null!==(e=t.prefersReducedMotion)&&void 0!==e?e:xt,this.widthOverride=t.widthOverride&&""!==t.widthOverride?t.widthOverride:null,this.viewportElement=document.createElement("div"),this.viewportElement.setAttribute("data-widgetic-workflow-viewport","1"),this.viewportElement.setAttribute("data-widgetic-internal","1"),this.viewportElement.style.display="block",this.observeMirroredAttributes()}currentStage(){var t,e;return null!==(e=null===(t=this.current)||void 0===t?void 0:t.element)&&void 0!==e?e:null}currentCompositionId(){var t,e;return null!==(e=null===(t=this.current)||void 0===t?void 0:t.compositionId)&&void 0!==e?e:null}showFirstStage(t,e=t){if(this.current)return{stage:this.current.element,ready:Promise.resolve({status:"ready"})};this.viewportElement.isConnected||this.host.appendChild(this.viewportElement),this.holdRoomFor(t);const o=this.buildStage(t,!0,e);this.current=o;const i=this.waitUntilShown(o,null,(t=>{if("ready"===t.status&&!this.destroyed&&this.autoscaleOn&&this.current===o){const t=this.measure(o.element);jt(t)&&this.applyHeight(t,"immediate")}}));return this.viewportElement.appendChild(o.element),this.services.hydrate(o.element),{stage:o.element,ready:i}}enableAutoscale(){var t,e;if(!this.destroyed&&!this.autoscaleOn&&(this.autoscaleOn=!0,this.viewportElement.style.position="relative",this.viewportElement.style.overflow="hidden",this.current&&this.positionAsLayer(this.current.element),this.heightObserver=(null!==(t=this.services.createHeightObserver)&&void 0!==t?t:Ft)((t=>this.onHeightsReported(t))),this.current)){null===(e=this.heightObserver)||void 0===e||e.observe(this.current.element);const t=this.measure(this.current.element);jt(t)&&this.applyHeight(t,"immediate")}}releaseAutoscale(){var t;if(this.destroyed)return;this.autoscaleOn=!1,this.clearHeightTimer(),null===(t=this.heightObserver)||void 0===t||t.disconnect(),this.heightObserver=null,this.appliedHeight=null;const e=this.viewportElement.style;for(const t of["position","overflow","height","min-height","transition"])e.removeProperty(t);this.current&&this.positionInFlow(this.current.element)}swapTo(t){return h(this,arguments,void 0,(function*(t,e=t){var i,s,r;if(this.destroyed)return{status:"failed",reason:"stopped"};if(this.incoming)return{status:"failed",reason:"busy"};this.enableAutoscale();const d=this.buildStage(t,!1,e);this.incoming=d,this.hideBeside(d.element);const a=this.waitUntilShown(d,null!==(i=this.services.readyTimeoutMilliseconds)&&void 0!==i?i:8e3);this.viewportElement.appendChild(d.element),this.services.hydrate(d.element);const l=yield a;if(this.destroyed)return{status:"failed",reason:"stopped"};if(this.incoming=null,"failed"===l.status)return this.removeStage(d),"timeout"===l.reason&&n.dispatchPublishedHostError(this.host,t,"workflow_step_timeout"),o.log.debug("[workflows] The next composition could not be shown, so the visitor stays where they are",{compositionId:t,reason:l.reason}),Object.assign({status:"failed",reason:"stopped"===l.reason?"stopped":l.reason},l.code?{code:l.code}:{});const u=this.current;this.revealInPlace(d.element),this.current=d,null===(s=this.heightObserver)||void 0===s||s.observe(d.element);const c=this.measure(d.element);return jt(c)&&this.applyHeight(c,"immediate"),u&&(null===(r=this.heightObserver)||void 0===r||r.unobserve(u.element),this.removeStage(u)),{status:"shown",stage:d.element}}))}destroy(){var t,e,o;if(this.destroyed)return;this.destroyed=!0,this.clearHeightTimer(),null===(t=this.heightObserver)||void 0===t||t.disconnect(),this.heightObserver=null,null===(e=this.attributeObserver)||void 0===e||e.disconnect(),this.attributeObserver=null;const i=[this.current,this.incoming];this.current=null,this.incoming=null;for(const t of i)t&&(null===(o=t.cancelWait)||void 0===o||o.call(t),this.removeStage(t));this.viewportElement.remove()}buildStage(t,e,i){var s,n,r;const d=document.createElement("widgetic");d.setAttribute("composition-id",t),d.setAttribute("data-widgetic-workflow-stage","1"),d.style.display="block";for(const t of Pt){const e=this.host.getAttribute(t);null!==e&&d.setAttribute(t,e)}this.widthOverride&&d.setAttribute("width",this.widthOverride);for(const t of $t){const e=this.host.getAttribute(t);null!==e&&d.setAttribute(t,e)}const a=i===(null!==(s=this.host.getAttribute("composition-id"))&&void 0!==s?s:"").trim();a&&this.copyWhatThePageWroteForTheTagComposition(d);const l={element:d,compositionId:t,standsFor:i,reportedHeight:!1,cancelWait:null,stopListening:()=>{}},u=t=>{var e;const o=null===(e=t.detail)||void 0===e?void 0:e.height;if("number"!=typeof o||!jt(o))return;const i=d.querySelector("iframe");i&&(i.style.height=`${Math.ceil(o)}px`,l.reportedHeight=!0)};d.addEventListener("widgetic:resize",u),l.stopListening=()=>d.removeEventListener("widgetic:resize",u);try{null===(r=(n=this.services).onStageCreated)||void 0===r||r.call(n,d,{compositionId:t,standsFor:i,isFirst:e,carriesPageContent:a})}catch(e){o.log.debug("[workflows] A listener for a new stage failed",{compositionId:t,error:e})}return l}copyWhatThePageWroteForTheTagComposition(t){for(const e of Array.from(this.host.attributes))u.isReservedHostAttribute(e.name)||t.setAttribute(e.name,e.value);for(const e of Rt){const o=this.host.getAttribute(e);null!==o&&t.setAttribute(e,o)}for(const e of u.declarativeChildrenOf(this.host))t.appendChild(e.cloneNode(!0))}observeMirroredAttributes(){const t="undefined"!=typeof MutationObserver?MutationObserver:null;if(t)try{this.attributeObserver=new t((t=>{t.some((t=>{var e;return"attributes"===t.type&&$t.includes(null!==(e=t.attributeName)&&void 0!==e?e:"")}))&&this.mirrorAttributesToStages()})),this.attributeObserver.observe(this.host,{attributes:!0,attributeFilter:[...$t]})}catch(t){this.attributeObserver=null,o.log.debug("[workflows] The tag cannot be watched for changes",{error:t})}}mirrorAttributesToStages(){for(const t of[this.current,this.incoming])if(t)for(const e of $t){const o=this.host.getAttribute(e);null===o?t.element.removeAttribute(e):t.element.getAttribute(e)!==o&&t.element.setAttribute(e,o)}}waitUntilShown(t,e,i){return new Promise((s=>{const n=t.element;let r=null,d=!1;const a=e=>{if(!d){d=!0,null!==r&&clearTimeout(r),n.removeEventListener("widgetic:ready",l),n.removeEventListener("widgetic:error",u),n.removeEventListener("load",c,!0),t.cancelWait=null;try{null==i||i(e)}catch(e){o.log.debug("[workflows] A stage could not be settled",{compositionId:t.compositionId,error:e})}s(e)}},l=()=>a({status:"ready"}),u=t=>{var e;const o=null===(e=t.detail)||void 0===e?void 0:e.code;a(Object.assign({status:"failed",reason:"error"},"string"==typeof o?{code:o}:{}))},c=t=>{t.target instanceof HTMLIFrameElement&&a({status:"ready"})};n.addEventListener("widgetic:ready",l),n.addEventListener("widgetic:error",u),n.addEventListener("load",c,!0),t.cancelWait=()=>a({status:"failed",reason:"stopped"}),null!==e&&(r=setTimeout((()=>a({status:"failed",reason:"timeout"})),e))}))}removeStage(t){var e,i;t.stopListening(),t.element.querySelector("iframe")&&!t.reportedHeight&&this.noteFrameWithoutHeight(t.compositionId),t.element.remove();try{null===(i=(e=this.services).onStageRemoved)||void 0===i||i.call(e,t.element)}catch(e){o.log.debug("[workflows] A listener for a removed stage failed",{compositionId:t.compositionId,error:e})}}noteFrameWithoutHeight(t){this.warnedAboutFrameWithoutHeight||(this.warnedAboutFrameWithoutHeight=!0,o.log.debug("[workflows] A widget in a frame does not report its height (widgetic:resize), so the embed keeps the height of its frame",{compositionId:t}))}hideBeside(t){this.positionAsLayer(t),t.style.visibility="hidden",t.style.pointerEvents="none",t.setAttribute("aria-hidden","true")}revealInPlace(t){t.style.removeProperty("visibility"),t.style.removeProperty("pointer-events"),t.removeAttribute("aria-hidden")}positionAsLayer(t){t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%"}positionInFlow(t){for(const e of["position","top","left","width"])t.style.removeProperty(e)}measure(t){var e;try{return(null!==(e=this.services.measureStageHeight)&&void 0!==e?e:Bt)(t)}catch(t){return o.log.debug("[workflows] The height of a stage could not be read",{error:t}),0}}holdRoomFor(t){const e=l.readStoredAutoscaleHeight(t);if(null===e)return;const o=this.settings();this.viewportElement.style.minHeight=`${Mt(e,o,this.overlayCap())}px`}settings(){return function(t,e={}){const o=_t(t,"autoscale-min-height",At,Nt),i=_t(t,"autoscale-max-height",Ct,Nt);return{minHeight:o,maxHeight:Math.max(i,o),debounceDelay:_t(t,"autoscale-debounce",Ot,5e3),threshold:_t(t,"autoscale-threshold",Wt,Nt),animate:"false"!==t.getAttribute("autoscale-animate")&&!0!==e.prefersReducedMotion,animationDuration:_t(t,"autoscale-animation-duration",Ht,5e3)}}(this.host,{prefersReducedMotion:this.prefersReducedMotion()})}overlayCap(){return this.host.hasAttribute(c.OVERLAY_HOST_ATTRIBUTE)?Math.floor(.9*window.innerHeight):null}onHeightsReported(t){if(!this.destroyed&&this.autoscaleOn&&this.current)for(const e of t)e.target===this.current.element&&jt(e.height)&&this.applyHeight(e.height,"observed")}applyHeight(t,e){const o=this.settings(),i=Mt(t,o,this.overlayCap());if("immediate"===e)return this.clearHeightTimer(),void this.setHeight(i,o);Lt(this.appliedHeight,i,o.threshold)?(this.pendingHeight=i,null!==this.debounceTimer&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout((()=>{this.debounceTimer=null;const t=this.pendingHeight;if(this.pendingHeight=null,null===t||this.destroyed||!this.autoscaleOn)return;const e=this.settings();Lt(this.appliedHeight,t,e.threshold)&&this.setHeight(t,e)}),o.debounceDelay)):i===this.appliedHeight&&this.clearHeightTimer()}setHeight(t,e){var o;const i=this.viewportElement.style,s=null!==this.appliedHeight&&this.appliedHeight!==t;if(i.setProperty("transition",e.animate&&s?`height ${e.animationDuration}ms ease`:"none"),i.height=`${t}px`,i.removeProperty("min-height"),this.appliedHeight=t,this.current){const e=Number.parseInt(null!==(o=this.host.getAttribute("height"))&&void 0!==o?o:"",10);l.writeStoredAutoscaleHeight(this.current.compositionId,t,Number.isFinite(e)?e:t)}}clearHeightTimer(){null!==this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null),this.pendingHeight=null}}function Vt(t,s,r){var d;try{i.setDirectMountWorkflow(t,e.workflowWatchProperty(s,r)),null===(d=n.getPublishedHostBridge(t))||void 0===d||d.sendWorkflowWatch(r)}catch(t){o.log.debug("[workflows] A widget could not be told what to report",{compositionId:s,error:t})}}function Dt(t){try{s.resolvePublishedEmbed(t).then((t=>{var e;const o="found"===t.status?null===(e=t.payload.direct)||void 0===e?void 0:e.moduleUrl:void 0;o&&i.warmDirectModule(o)})).catch((()=>{}))}catch(e){o.log.debug("[workflows] A composition could not be got ready",{compositionId:t,error:e})}}function Ut(t){const e=window;if("function"==typeof e.requestIdleCallback){const o=e.requestIdleCallback((()=>t()),{timeout:5e3});return()=>{var t;return null===(t=e.cancelIdleCallback)||void 0===t?void 0:t.call(e,o)}}const o=setTimeout(t,1500);return()=>clearTimeout(o)}class qt{constructor(t,e,i,s,n){this.host=t,this.workflowId=e,this.tagCompositionId=i,this.options=s,this.services=n,this.mode="loading",this.stages=new Map,this.pageEvents=new d.PageEventQueue,this.removeListeners=[],this.workflow=null,this.index=null,this.counts=null,this.position=null,this.stepping=!1,this.pendingStageNodeId=null,this.retryTimer=null,this.scheduleTimers=new Set,this.cancelIdleWork=null,this.readiedCompositions=new Set,this.displayBeforeMounting="",this.hostIsMarkedMounted=!1,this.copiesThatCannotBeShown=new Set,this.cancelWaitForAnswer=null,this.onPageEvent=t=>{if("ended"===this.mode||"plain"===this.mode)return;const e=d.readPageEvent(t.detail);e?"running"!==this.mode||this.stepping?this.pageEvents.add(e):this.hasEnded()||this.react([{type:"pageEvent",name:e.name,values:e.values}]):o.log.debug("[workflows] An event of the page was ignored: it is not one a workflow can wait for")},this.onVisibilityChange=()=>{"running"!==this.mode||this.stepping||this.hasEnded()||this.armSchedules()},this.visitorLanguages=this.readVisitorLanguages();const r=n.viewport;this.viewport=new zt(Object.assign(Object.assign(Object.assign({host:t},r.prefersReducedMotion?{prefersReducedMotion:r.prefersReducedMotion}:{}),s.width?{widthOverride:s.width}:{}),{services:Object.assign(Object.assign(Object.assign(Object.assign({hydrate:s.hydrate},r.createHeightObserver?{createHeightObserver:r.createHeightObserver}:{}),r.measureStageHeight?{measureStageHeight:r.measureStageHeight}:{}),void 0!==r.readyTimeoutMilliseconds?{readyTimeoutMilliseconds:r.readyTimeoutMilliseconds}:{}),{onStageCreated:(t,e)=>this.onStageCreated(t,e.compositionId),onStageRemoved:t=>this.onStageRemoved(t)})}))}readVisitorLanguages(){try{const t=this.services.visitorLanguages();return Array.isArray(t)?t.filter((t=>"string"==typeof t)):[]}catch(t){return o.log.debug("[workflows] The languages of the visitor could not be read",{error:t}),[]}}start(){var t;const e=function(t,e=Date.now()){const i=X(t),s=a.readStoredValue(i);if(null===s)return null;try{const i=JSON.parse(s);if("object"!=typeof i||null===i||Array.isArray(i))return null;const n=i;return 1!==n.v?null:tt(n.versionId)&&tt(n.nodeId)&&tt(n.compositionId)&&et(n.startedAt)&&et(n.reachedAt)?n.startedAt>e+864e5?null:e-n.startedAt>2592e6?(it(t),o.log.debug("[workflows] The visitor's position is older than 30 days and was forgotten",{workflowId:t}),null):{versionId:n.versionId,nodeId:n.nodeId,compositionId:n.compositionId,startedAt:n.startedAt,reachedAt:Math.min(n.reachedAt,e)}:null}catch(e){return o.log.debug("[workflows] The kept position could not be read and is ignored",{workflowId:t,error:e}),null}}(this.workflowId),i=null!==(t=null==e?void 0:e.compositionId)&&void 0!==t?t:this.tagCompositionId;this.listenToThePage(),this.displayBeforeMounting=this.host.style.display,this.run(e,i)}run(t,e){return h(this,void 0,void 0,(function*(){var i;try{const s=this.services.fetchWorkflow(this.workflowId);this.readiedCompositions.add(e),this.services.prefetchComposition(e);const n=yield this.waitForAnswer(s);if(this.hasEnded())return;const r=this.compositionToShow("live"===(null==n?void 0:n.status)?n.workflow:null,e),d=this.showFirstComposition(r,e),[a,l]=yield Promise.all([s,d]);if(this.hasEnded())return;let u=l;if("failed"===u.status&&"stopped"!==u.reason&&r!==e&&(u=yield this.fallBackToTheComposition(r,e),this.hasEnded()))return;let c=t,h=e;if("failed"===u.status){if("stopped"===u.reason)return;if(!t||t.compositionId===this.tagCompositionId)return void this.refuse(u.code);{o.log.debug("[workflows] The composition a returning visitor was on cannot be shown, so they start again",{compositionId:t.compositionId}),it(this.workflowId),c=null;const e=yield this.swapToComposition(this.tagCompositionId,"live"===a.status?a.workflow:null);if(this.hasEnded())return;if("shown"!==e.status)return void this.refuse(null!==(i=u.code)&&void 0!==i?i:"failed"===e.status?e.code:void 0);h=this.tagCompositionId}}if("live"!==a.status)return o.log.debug("[workflows] The workflow is not running, so the tag is a plain embed",{workflowId:this.workflowId,status:a.status}),void(yield this.becomePlain());let g=a.workflow,f=a.origin;if(c&&c.versionId!==g.versionId){const t=yield this.services.fetchWorkflow(this.workflowId,{versionId:c.versionId});if(this.hasEnded())return;"live"===t.status&&t.workflow.versionId===c.versionId?(g=t.workflow,f=t.origin):(o.log.debug("[workflows] The version a visitor started on cannot be read, so they continue as a new visitor",{versionId:c.versionId}),it(this.workflowId),c=null)}const m=p(g.graph);let v=c&&this.fitsTheGraph(c,g,m)?c:null;const w=null===v;if(null===v){c&&(o.log.debug("[workflows] The place a visitor was kept at is not in the workflow, so they continue as a new visitor"),it(this.workflowId));const t=function(t,e){for(const o of t.nodes)if("composition"===o.type&&o.compositionId===e)return o}(g.graph,this.tagCompositionId);if(!t)return o.log.debug("[workflows] The composition of the tag is not a block of the workflow, so the tag is a plain embed",{compositionId:this.tagCompositionId}),void(yield this.becomePlain());const e=Date.now();v={versionId:g.versionId,nodeId:t.id,compositionId:this.tagCompositionId,startedAt:e,reachedAt:e}}const b=yield this.showThePlace(v.compositionId,g,h);if(this.hasEnded())return;if("plain"===b)return void(yield this.becomePlain());this.activate(g,f,m,v,w)}catch(t){o.log.warn("[workflows] The workflow stopped working, so the tag stays as it is",{workflowId:this.workflowId,error:t}),this.becomePlainWithoutWaiting(),this.makeSureTheTagCompositionIsShown()}}))}waitForAnswer(t){const e=this.services.firstCompositionWaitMilliseconds;return new Promise(((o,i)=>{let s=null;const n=t=>{null!==s&&clearTimeout(s),s=null,this.cancelWaitForAnswer=null,o(t)};this.cancelWaitForAnswer=()=>n(null),s=setTimeout((()=>n(null)),Number.isFinite(e)?Math.max(0,e):0),t.then(n,(t=>{null!==s&&clearTimeout(s),s=null,this.cancelWaitForAnswer=null,i(t)}))}))}showFirstComposition(t,e){t!==e&&o.log.debug("[workflows] A composition is shown in the visitor's language",{compositionId:e,copyId:t});const{ready:i}=this.viewport.showFirstStage(t,e);return this.markHostMounted(),i}markHostMounted(){this.hostIsMarkedMounted||(this.hostIsMarkedMounted=!0,this.options.markMounted(this.host))}makeSureTheTagCompositionIsShown(){if("ended"!==this.mode&&null===this.viewport.currentStage())try{this.viewport.showFirstStage(this.tagCompositionId),this.markHostMounted()}catch(t){o.log.debug("[workflows] The composition of the tag could not be shown",{error:t})}}compositionToShow(t,e){if(!t)return e;const o=ht(e,t.translations,this.visitorLanguages);return this.copiesThatCannotBeShown.has(o)?e:o}noteThatTheCopyCannotBeShown(t,e){this.copiesThatCannotBeShown.has(t)||(this.copiesThatCannotBeShown.add(t),o.log.debug("[workflows] The copy of a composition in the visitor's language cannot be shown, so the composition itself is",{compositionId:e,copyId:t}))}fallBackToTheComposition(t,e){return h(this,void 0,void 0,(function*(){this.noteThatTheCopyCannotBeShown(t,e);const o=yield this.viewport.swapTo(e);return"shown"===o.status?{status:"ready"}:Object.assign({status:"failed",reason:"busy"===o.reason?"error":o.reason},o.code?{code:o.code}:{})}))}swapToComposition(t,e){return h(this,void 0,void 0,(function*(){const i=this.compositionToShow(e,t);i!==t&&o.log.debug("[workflows] A composition is shown in the visitor's language",{compositionId:t,copyId:i});const s=yield this.viewport.swapTo(i,t);return"shown"===s.status||i===t||"stopped"===s.reason||"busy"===s.reason?s:this.hasEnded()?{status:"failed",reason:"stopped"}:(this.noteThatTheCopyCannotBeShown(i,t),this.viewport.swapTo(t))}))}showThePlace(t,e,o){return h(this,void 0,void 0,(function*(){const i=this.compositionToShow(e,t);if(o===t&&this.viewport.currentCompositionId()===i)return"shown";return"shown"===(yield this.swapToComposition(t,e)).status||o===t?"shown":"plain"}))}fitsTheGraph(t,e,o){if(t.versionId!==e.versionId)return!1;const i=o.nodesById.get(t.nodeId);return v(i)&&i.compositionId===t.compositionId}activate(t,e,i,s,n){var r;this.workflow=t,this.index=i,this.position=s,this.mode="running";const d=this.services.createCounts({workflowId:this.workflowId,versionId:t.versionId,token:null!==(r=t.eventToken)&&void 0!==r?r:null,apiOrigin:e,isActive:()=>"ended"!==this.mode&&this.host.isConnected});d.start(),this.counts=d,n&&(ot(this.workflowId,s),d.count("n",s.nodeId)),o.log.debug("[workflows] The workflow runs",{workflowId:this.workflowId,versionId:t.versionId,isNewVisitor:n}),this.viewport.enableAutoscale();const a=this.viewport.currentStage();a&&this.armStage(a,s.nodeId),this.armSchedules(),this.getNextCompositionsReady(),this.drainPageEvents()}becomePlain(){return h(this,void 0,void 0,(function*(){if(this.mode="plain",this.pageEvents.clear(),this.viewport.currentCompositionId()!==this.tagCompositionId){const t=yield this.viewport.swapTo(this.tagCompositionId);if(this.hasEnded())return;"shown"!==t.status&&o.log.debug("[workflows] The composition of the tag could not be shown")}this.viewport.releaseAutoscale()}))}becomePlainWithoutWaiting(){"ended"!==this.mode&&(this.mode="plain",this.pageEvents.clear(),this.cancelRetry(),this.cancelSchedules(),this.viewport.releaseAutoscale())}refuse(e){const i=this.viewport.currentStage(),s=(null==i?void 0:i.getAttribute(t.REFUSED_HOST_ATTRIBUTE))||e||"NOT_FOUND";this.stop(),this.host.removeAttribute("data-widgetic-mounting"),this.host.removeAttribute("data-widgetic-mounted"),this.host.style.display=this.displayBeforeMounting,this.host.setAttribute(t.REFUSED_HOST_ATTRIBUTE,s),o.log.debug("[workflows] The composition of the tag cannot be shown",{workflowId:this.workflowId,reason:s})}listenToThePage(){this.host.addEventListener(d.WORKFLOW_EVENT_TYPE,this.onPageEvent),document.addEventListener("visibilitychange",this.onVisibilityChange),this.removeListeners.push((()=>this.host.removeEventListener(d.WORKFLOW_EVENT_TYPE,this.onPageEvent)),(()=>document.removeEventListener("visibilitychange",this.onVisibilityChange)))}drainPageEvents(){const t=this.pageEvents.take();for(let e=0;e<t.length;e+=1){if("running"!==this.mode)return;if(this.stepping){for(const o of t.slice(e))this.pageEvents.add(o);return}const o=t[e];this.react([{type:"pageEvent",name:o.name,values:o.values}])}}onStageCreated(t,e){this.stages.set(t,{compositionId:e,signals:null,stopWatchingReady:null}),null!==this.pendingStageNodeId&&this.armStage(t,this.pendingStageNodeId)}onStageRemoved(t){var e,o;const i=this.stages.get(t);null===(e=null==i?void 0:i.signals)||void 0===e||e.stop(),null===(o=null==i?void 0:i.stopWatchingReady)||void 0===o||o.call(i),this.stages.delete(t)}armStage(t,o){var i,s,n;const r=this.workflow,d=this.index;if(!r||!d)return;const a=d.nodesById.get(o);if(!v(a))return;const l=null!==(i=this.stages.get(t))&&void 0!==i?i:{compositionId:a.compositionId,signals:null,stopWatchingReady:null};null===(s=l.signals)||void 0===s||s.stop(),null===(n=l.stopWatchingReady)||void 0===n||n.call(l),this.stages.set(t,l);const u=z(r.graph,o,{index:d});l.signals=St({stage:t,watch:u,emit:e=>this.onSignals(t,e)});const c=e.buildWorkflowWatch(u);if(0===c.tables.length&&0===c.fields.length&&0===c.goals.length)return;const h=()=>this.services.deliverWatch(t,l.compositionId,c);h(),t.addEventListener("widgetic:ready",h),l.stopWatchingReady=()=>t.removeEventListener("widgetic:ready",h)}onSignals(t,e){"running"!==this.mode||this.stepping||this.hasEnded()||t===this.viewport.currentStage()&&this.react(e)}react(t){const e=this.workflow,i=this.index,s=this.position;if(e&&i&&s)for(const n of t){let t;try{t=B(e.graph,{nodeId:s.nodeId},n,{index:i})}catch(t){o.log.debug("[workflows] The engine could not decide on a signal",{signal:n.type,error:t});continue}if("moved"===t.outcome)return void this.moveOn(t,!1)}}moveOn(t,e){return h(this,void 0,void 0,(function*(){const i=this.index,s=this.position;if(!i||!s)return;const n=i.nodesById.get(t.position.nodeId);if(!v(n))return;let r;this.stepping=!0,this.cancelRetry(),this.cancelSchedules(),this.pendingStageNodeId=n.id;try{r=yield this.swapToComposition(n.compositionId,this.workflow)}catch(t){o.log.debug("[workflows] The next composition could not be built",{compositionId:n.compositionId,error:t}),r={status:"failed",reason:"error"}}this.pendingStageNodeId=null,this.stepping=!1,this.hasEnded()||("shown"===r.status?this.completeStep(t,n,s):this.failStep(t,n,s,e))}))}completeStep(t,e,i){const s=Object.assign(Object.assign({},i),{nodeId:e.id,compositionId:e.compositionId,reachedAt:Date.now()});this.position=s,ot(this.workflowId,s),this.countStep(i.nodeId,t,e.id),o.log.debug("[workflows] The visitor moved on",{from:i.compositionId,to:e.compositionId}),this.host.dispatchEvent(new CustomEvent(d.WORKFLOW_STEP_EVENT_TYPE,{detail:{workflowId:this.workflowId,from:i.compositionId,to:e.compositionId},bubbles:!0,composed:!0})),this.armSchedules(),this.getNextCompositionsReady(),this.drainPageEvents()}countStep(t,e,o){const i=this.counts,s=this.index;if(!i||!s)return;const n=m(s,t).find((t=>t.target===e.firedTriggerId));n&&i.count("e",n.id);for(const t of e.passedNodeIds)i.count("n",t);for(const t of e.takenEdgeIds)i.count("e",t);i.count("n",o)}failStep(t,e,i,s){var n;null===(n=this.counts)||void 0===n||n.count("f",e.id),o.log.debug("[workflows] The next composition could not be shown, so the visitor stays where they are",{compositionId:e.compositionId,isRetry:s}),this.armSchedules(),s||this.scheduleRetry(t,i.nodeId),this.drainPageEvents()}scheduleRetry(t,e){this.cancelRetry(),this.retryTimer=setTimeout((()=>{var o;this.retryTimer=null,"running"!==this.mode||this.stepping||this.hasEnded()||(null===(o=this.position)||void 0===o?void 0:o.nodeId)===e&&this.moveOn(t,!0)}),3e4)}cancelRetry(){null!==this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=null}armSchedules(){this.cancelSchedules();const t=this.workflow,e=this.index,i=this.position;if("running"===this.mode&&!this.stepping&&t&&e&&i)for(const{triggerId:s,schedule:n}of z(t.graph,i.nodeId,{index:e}).schedules){const t=$(n,i.reachedAt,Date.now());void 0!==t?this.waitFor(s,n,i.nodeId,t):o.log.debug("[workflows] A Scheduled trigger has no usable time and is ignored",{triggerId:s})}}waitFor(t,e,i,s){const n=setTimeout((()=>{this.scheduleTimers.delete(n);const s=this.position;if("running"!==this.mode||this.stepping||this.hasEnded()||!s||s.nodeId!==i)return;const r=$(e,s.reachedAt,Date.now());void 0!==r&&(r>0?this.waitFor(t,e,i,r):(o.log.debug("[workflows] A wait is over",{triggerId:t}),this.react([{type:"scheduled",triggerId:t}])))}),Math.min(s,432e5));this.scheduleTimers.add(n)}cancelSchedules(){for(const t of this.scheduleTimers)clearTimeout(t);this.scheduleTimers.clear()}getNextCompositionsReady(){var t,e;null===(t=this.cancelIdleWork)||void 0===t||t.call(this),this.cancelIdleWork=null;const o=null===(e=this.position)||void 0===e?void 0:e.nodeId;o&&(this.cancelIdleWork=this.services.whenIdle((()=>{var t;if(this.cancelIdleWork=null,"running"!==this.mode||this.hasEnded()||(null===(t=this.position)||void 0===t?void 0:t.nodeId)!==o)return;let e=0;for(const t of this.compositionsReachableFrom(o)){const o=this.compositionToShow(this.workflow,t);if(!this.readiedCompositions.has(o)){if(e>=5)break;this.readiedCompositions.add(o),e+=1,this.services.prefetchComposition(o)}}})))}compositionsReachableFrom(t){const e=this.index;if(!e)return[];const o=[],i=new Set;for(const s of b(e,t)){const t=[s.id];for(;t.length>0;){const s=t.pop();if(!i.has(s)){i.add(s);for(const i of m(e,s)){const s=e.nodesById.get(i.target);v(s)?o.includes(s.compositionId)||o.push(s.compositionId):w(s)&&t.push(s.id)}}}}return o}hasEnded(){return"ended"===this.mode||!this.host.isConnected&&(o.log.debug("[workflows] The tag left the page, so its workflow ends",{workflowId:this.workflowId}),this.stop(),!0)}stop(){var t,e,i,s,n,r;if("ended"!==this.mode){try{null===(t=this.counts)||void 0===t||t.flushBeforeLeaving()}catch(t){o.log.debug("[workflows] The last counts could not be sent",{error:t})}this.mode="ended",null===(e=this.cancelWaitForAnswer)||void 0===e||e.call(this),this.cancelRetry(),this.cancelSchedules(),null===(i=this.cancelIdleWork)||void 0===i||i.call(this),this.cancelIdleWork=null;for(const t of this.removeListeners.splice(0))t();for(const t of this.stages.values())null===(s=t.signals)||void 0===s||s.stop(),null===(n=t.stopWatchingReady)||void 0===n||n.call(t);this.stages.clear(),this.pageEvents.clear();try{null===(r=this.counts)||void 0===r||r.dispose()}catch(t){o.log.debug("[workflows] The counts could not be closed",{error:t})}this.viewport.destroy()}}}window.__widgeticEmbedWorkflows=Object.freeze({contractVersion:1,startWorkflowEmbed:function(t,e){var i,s,n;const d=(null!==(i=t.getAttribute("workflow-id"))&&void 0!==i?i:"").trim(),a=(null!==(s=t.getAttribute("composition-id"))&&void 0!==s?s:"").trim();if(!ft(d)||""===a)return o.log.debug("[workflows] The tag is not a workflow embed, so it is embedded as it is",{workflowId:d,tagCompositionId:a}),null;const l={fetchWorkflow:yt,createCounts:t=>new rt(t),deliverWatch:Vt,prefetchComposition:Dt,whenIdle:Ut,visitorLanguages:ct,firstCompositionWaitMilliseconds:2e3,viewport:{}},u=Object.assign(Object.assign(Object.assign({},l),e.services),{viewport:Object.assign(Object.assign({},l.viewport),null===(n=e.services)||void 0===n?void 0:n.viewport)}),c=new qt(t,d,a,e,u);try{c.start()}catch(t){return o.log.warn("[workflows] The workflow could not start, so the tag is embedded as it is",{workflowId:d,error:t}),c.stop(),null}const h={stop:()=>c.stop()};return r.registerWorkflowEmbed(t,h),h}})}((window.__widgeticEmbedSharedServices||{}).hostBridgeMarkers,(window.__widgeticEmbedSharedServices||{}).hostWorkflowWatch,(window.__widgeticEmbedSharedServices||{}).logger,(window.__widgeticEmbedSharedServices||{}).mountDirectWidget,(window.__widgeticEmbedSharedServices||{}).publicEmbedLookup,(window.__widgeticEmbedSharedServices||{}).publishedHostBridge,(window.__widgeticEmbedSharedServices||{}).workflowEmbedRegistry,(window.__widgeticEmbedSharedServices||{}).workflowPageEvents,(window.__widgeticEmbedSharedServices||{}).abVisitor,(window.__widgeticEmbedSharedServices||{}).autoscaleManager,(window.__widgeticEmbedSharedServices||{}).declarativeEmbedParser,(window.__widgeticEmbedSharedServices||{}).publishedHostDisplay);
|