@adobe/universal-editor-cors
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,1 +0,2 @@ | ||
(()=>{var e,t,n,r,o,i,a,s;(t=e||(e={})).Call="call",t.Reply="reply",t.Syn="syn",t.SynAck="synAck",t.Ack="ack",(r=n||(n={})).Fulfilled="fulfilled",r.Rejected="rejected",(i=o||(o={})).ConnectionDestroyed="ConnectionDestroyed",i.ConnectionTimeout="ConnectionTimeout",i.NoIframeSrc="NoIframeSrc",(a||(a={})).DataCloneError="DataCloneError",(s||(s={})).Message="message";const c=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});var l=(t,r,o)=>{const{localName:i,local:l,remote:d,originForSending:u,originForReceiving:p}=t;let g=!1;const f=t=>{if(t.source!==d||t.data.penpal!==e.Call)return;if("*"!==p&&t.origin!==p)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${p}`);const s=t.data,{methodName:l,args:f,id:m}=s;o(`${i}: Received ${l}() call`);const h=t=>r=>{if(o(`${i}: Sending ${l}() reply`),g)return void o(`${i}: Unable to send ${l}() reply due to destroyed connection`);const s={penpal:e.Reply,id:m,resolution:t,returnValue:r};t===n.Rejected&&r instanceof Error&&(s.returnValue=c(r),s.returnValueIsError=!0);try{d.postMessage(s,u)}catch(t){if(t.name===a.DataCloneError){const r={penpal:e.Reply,id:m,resolution:n.Rejected,returnValue:c(t),returnValueIsError:!0};d.postMessage(r,u)}throw t}};new Promise((e=>e(r[l].apply(r,f)))).then(h(n.Fulfilled),h(n.Rejected))};return l.addEventListener(s.Message,f),()=>{g=!0,l.removeEventListener(s.Message,f)}};let d=0;const u=e=>e?e.split("."):[],p=(e,t,n)=>{const r=u(t);return r.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t])),e),e},g=(e,t)=>{const n={};return Object.keys(e).forEach((r=>{const o=e[r],i=((e,t)=>{const n=u(t||"");return n.push(e),(e=>e.join("."))(n)})(r,t);"object"==typeof o&&Object.assign(n,g(o,i)),"function"==typeof o&&(n[i]=o)})),n},f=e=>{const t={};for(const n in e)p(t,n,e[n]);return t};var m,h=(t,r,i,a,c)=>{const{localName:l,local:u,remote:p,originForSending:g,originForReceiving:m}=r;let h=!1;c(`${l}: Connecting call sender`);const E=t=>(...r)=>{let i;c(`${l}: Sending ${t}() call`);try{p.closed&&(i=!0)}catch(e){i=!0}if(i&&a(),h){const e=new Error(`Unable to send ${t}() call due to destroyed connection`);throw e.code=o.ConnectionDestroyed,e}return new Promise(((o,i)=>{const a=++d,f=r=>{if(r.source!==p||r.data.penpal!==e.Reply||r.data.id!==a)return;if("*"!==m&&r.origin!==m)return void c(`${l} received message from origin ${r.origin} which did not match expected origin ${m}`);const d=r.data;c(`${l}: Received ${t}() reply`),u.removeEventListener(s.Message,f);let g=d.returnValue;d.returnValueIsError&&(g=(e=>{const t=new Error;return Object.keys(e).forEach((n=>t[n]=e[n])),t})(g)),(d.resolution===n.Fulfilled?o:i)(g)};u.addEventListener(s.Message,f);const h={penpal:e.Call,id:a,methodName:t,args:r};p.postMessage(h,g)}))},y=i.reduce(((e,t)=>(e[t]=E(t),e)),{});return Object.assign(t,f(y)),()=>{h=!0}},E=(e,t)=>{let n;return void 0!==e&&(n=window.setTimeout((()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=o.ConnectionTimeout,t(n)}),e)),()=>{clearTimeout(n)}},y=(t,n,r,o)=>{const{destroy:i,onDestroy:a}=r;return r=>{if(!(t instanceof RegExp?t.test(r.origin):"*"===t||t===r.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${r.origin} which did not match expected origin ${t}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const s="null"===r.origin?"*":r.origin,c={penpal:e.Ack,methodNames:Object.keys(n)};window.parent.postMessage(c,s);const d={localName:"Child",local:window,remote:window.parent,originForSending:s,originForReceiving:r.origin},u=l(d,n,o);a(u);const p={},g=h(p,d,r.data.methodNames,i,o);return a(g),p}},v=(t={})=>{const{parentOrigin:n="*",methods:r={},timeout:o,debug:i=!1}=t,a=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(i),c=((e,t)=>{const n=[];let r=!1;return{destroy(o){r||(r=!0,t(`${e}: Destroying connection`),n.forEach((e=>{e(o)})))},onDestroy(e){r?e():n.push(e)}}})("Child",a),{destroy:l,onDestroy:d}=c,u=g(r),p=y(n,u,c,a);return{promise:new Promise(((t,r)=>{const i=E(o,l),c=n=>{if((()=>{try{clearTimeout()}catch(e){return!1}return!0})()&&n.source===parent&&n.data&&n.data.penpal===e.SynAck){const e=p(n);e&&(window.removeEventListener(s.Message,c),i(),t(e))}};window.addEventListener(s.Message,c),(()=>{a("Child: Handshake - Sending SYN");const t={penpal:e.Syn},r=n instanceof RegExp?"*":n;window.parent.postMessage(t,r)})(),d((e=>{window.removeEventListener(s.Message,c),e&&r(e)}))})),destroy(){l()}}};function w(e,t,n){var r,o,i,a,s;function c(){var l=Date.now()-a;l<t&&l>=0?r=setTimeout(c,t-l):(r=null,n||(s=e.apply(i,o),i=o=null))}null==t&&(t=100);var l=function(){i=this,o=arguments,a=Date.now();var l=n&&!r;return r||(r=setTimeout(c,t)),l&&(s=e.apply(i,o),i=o=null),s};return l.clear=function(){r&&(clearTimeout(r),r=null)},l.flush=function(){r&&(s=e.apply(i,o),i=o=null,clearTimeout(r),r=null)},l}w.debounce=w,m=w;var b=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;const R=[];for(let e=0;e<256;++e)R.push((e+256).toString(16).slice(1));var T=function(e){if(!function(e){return"string"==typeof e&&b.test(e)}(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n};function A(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:case 3:return t^n^r;case 2:return t&n^t&r^n&r}}function C(e,t){return e<<t|e>>>32-t}var P,S,I=function(e,t,n){function r(e,t,n,r){var o;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}(e)),"string"==typeof t&&(t=T(t)),16!==(null===(o=t)||void 0===o?void 0:o.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let i=new Uint8Array(16+e.length);if(i.set(t),i.set(e,t.length),i=function(e){const t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const r=e.length/4+2,o=Math.ceil(r/16),i=new Array(o);for(let t=0;t<o;++t){const n=new Uint32Array(16);for(let r=0;r<16;++r)n[r]=e[64*t+4*r]<<24|e[64*t+4*r+1]<<16|e[64*t+4*r+2]<<8|e[64*t+4*r+3];i[t]=n}i[o-1][14]=8*(e.length-1)/Math.pow(2,32),i[o-1][14]=Math.floor(i[o-1][14]),i[o-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<o;++e){const r=new Uint32Array(80);for(let t=0;t<16;++t)r[t]=i[e][t];for(let e=16;e<80;++e)r[e]=C(r[e-3]^r[e-8]^r[e-14]^r[e-16],1);let o=n[0],a=n[1],s=n[2],c=n[3],l=n[4];for(let e=0;e<80;++e){const n=Math.floor(e/20),i=C(o,5)+A(n,a,s,c)+l+t[n]+r[e]>>>0;l=c,c=s,s=C(a,30)>>>0,a=o,o=i}n[0]=n[0]+o>>>0,n[1]=n[1]+a>>>0,n[2]=n[2]+s>>>0,n[3]=n[3]+c>>>0,n[4]=n[4]+l>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]}(i),i[6]=15&i[6]|80,i[8]=63&i[8]|128,n){r=r||0;for(let e=0;e<16;++e)n[r+e]=i[e];return n}return function(e,t=0){return(R[e[t+0]]+R[e[t+1]]+R[e[t+2]]+R[e[t+3]]+"-"+R[e[t+4]]+R[e[t+5]]+"-"+R[e[t+6]]+R[e[t+7]]+"-"+R[e[t+8]]+R[e[t+9]]+"-"+R[e[t+10]]+R[e[t+11]]+R[e[t+12]]+R[e[t+13]]+R[e[t+14]]+R[e[t+15]]).toLowerCase()}(i)}try{r.name="v5"}catch(e){}return r.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",r.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",r}();(S=P||(P={})).ID="itemID",S.TYPE="itemType",S.SCOPE="itemScope",S.PROP="itemProp";const L={UUID:"id",ID:P.ID.toLowerCase(),TYPE:P.TYPE.toLowerCase(),SCOPE:P.SCOPE.toLowerCase(),PROP:P.PROP.toLowerCase(),PARENTID:"parentid",EDITOR_BEHAVIOR:"data-editor-behavior"},O="universal-editor-message-bus.herokuapp.com",_="/gql",M="urn:auecon:",D={USER_INPUT_RELAY_MESSAGE:"REMOTE_APP_USER_INPUT",DEMO_APP_HOST:"ue-remote-app.adobe.net",GRAPHQL_HOST:O,GRAPHQL_PORT_PUBLIC:443,GRAPHQL_PORT_LOCAL:4e3,GRAPHQL_PATH:_,GRAPHQL_URL:`${O}:443${_}`,EDITABLE_SELECTOR:`[${L.TYPE}]`,CANVAS_PATH:"/canvas",PARENT_SELECTOR:`[${L.SCOPE}][${L.ID}]`,URN_PREFIX:M,META_SELECTOR:`meta[name^='${M}']`,DEMO_APP_HOST_PROD:"ue-remote-app-prod.adobe.net",FRAGMENT_TYPE:"reference",UNIFIED_SHELL_STAGE:"https://experience-stage.adobe.com",UNIFIED_SHELL_PROD:"https://experience.adobe.com",HEADLESS_CF_EDITOR_URL:"#/aem/cf/editor/editor",CONTAINER_SELECTOR:`[${L.SCOPE}][${L.TYPE}=container]`,COMPONENT_ITEM_TYPE:"component"};var N=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;const U=[];for(let e=0;e<256;++e)U.push((e+256).toString(16).slice(1));var $=function(e){if(!function(e){return"string"==typeof e&&N.test(e)}(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n};function k(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:case 3:return t^n^r;case 2:return t&n^t&r^n&r}}function H(e,t){return e<<t|e>>>32-t}!function(e,t,n){function r(e,t,n,r){var o;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}(e)),"string"==typeof t&&(t=$(t)),16!==(null===(o=t)||void 0===o?void 0:o.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let i=new Uint8Array(16+e.length);if(i.set(t),i.set(e,t.length),i=function(e){const t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const r=e.length/4+2,o=Math.ceil(r/16),i=new Array(o);for(let t=0;t<o;++t){const n=new Uint32Array(16);for(let r=0;r<16;++r)n[r]=e[64*t+4*r]<<24|e[64*t+4*r+1]<<16|e[64*t+4*r+2]<<8|e[64*t+4*r+3];i[t]=n}i[o-1][14]=8*(e.length-1)/Math.pow(2,32),i[o-1][14]=Math.floor(i[o-1][14]),i[o-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<o;++e){const r=new Uint32Array(80);for(let t=0;t<16;++t)r[t]=i[e][t];for(let e=16;e<80;++e)r[e]=H(r[e-3]^r[e-8]^r[e-14]^r[e-16],1);let o=n[0],a=n[1],s=n[2],c=n[3],l=n[4];for(let e=0;e<80;++e){const n=Math.floor(e/20),i=H(o,5)+k(n,a,s,c)+l+t[n]+r[e]>>>0;l=c,c=s,s=H(a,30)>>>0,a=o,o=i}n[0]=n[0]+o>>>0,n[1]=n[1]+a>>>0,n[2]=n[2]+s>>>0,n[3]=n[3]+c>>>0,n[4]=n[4]+l>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]}(i),i[6]=15&i[6]|80,i[8]=63&i[8]|128,n){r=r||0;for(let e=0;e<16;++e)n[r+e]=i[e];return n}return function(e,t=0){return(U[e[t+0]]+U[e[t+1]]+U[e[t+2]]+U[e[t+3]]+"-"+U[e[t+4]]+U[e[t+5]]+"-"+U[e[t+6]]+U[e[t+7]]+"-"+U[e[t+8]]+U[e[t+9]]+"-"+U[e[t+10]]+U[e[t+11]]+U[e[t+12]]+U[e[t+13]]+U[e[t+14]]+U[e[t+15]]).toLowerCase()}(i)}try{r.name="v5"}catch(e){}r.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",r.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8"}();const F={element:window.document},V=150,x="Component",j={viewport:{width:0,height:0},frame:{width:0,height:0},scroll:{x:0,y:0}},Y=({editor:e})=>{null==e||e.updateFrameDetails({details:j})},K=({target:e})=>{const t=e.documentElement;j.scroll.x=t.scrollLeft,j.scroll.y=t.scrollTop},G=({target:e})=>{const t=Math.max(e.document.documentElement.clientWidth||0,e.innerWidth||0),n=Math.max(e.document.documentElement.clientHeight||0,e.innerHeight||0),{width:r,height:o}=e.document.documentElement.getBoundingClientRect();j.viewport={width:t,height:n},j.frame={width:Math.ceil(r),height:Math.ceil(o)}},q=({editor:e})=>{const t=[];[...document.styleSheets].forEach((e=>{try{const{cssRules:n}=e;[...n].find((e=>e instanceof CSSFontFaceRule))&&e.href&&t.push(e.href)}catch(n){e.href&&t.push(e.href)}})),e.addCustomFonts(t)},B=({editor:e})=>{const t=F.element,n=(0,m.debounce)((()=>{const n=(e=>{const{scrollLeft:t,scrollTop:n}=e.documentElement,r=e.querySelectorAll(D.EDITABLE_SELECTOR)||[],o={editables:[],offset:{x:t,y:n},selected:{}};return r.forEach((e=>{const t=(e=>{const t=e.getAttribute(L.TYPE)||"",n=e.getAttribute(L.ID)||void 0,r=e.getAttribute(L.PROP)||void 0,o=t===D.COMPONENT_ITEM_TYPE||e.getAttribute(L.EDITOR_BEHAVIOR)===D.COMPONENT_ITEM_TYPE,i=!n&&r||o?((e,t)=>{let n;return n=t?e.closest(D.CONTAINER_SELECTOR):e.closest(D.PARENT_SELECTOR),(null==n?void 0:n.getAttribute(L.ID))||""})(e,o):"",a=I(`${n||i}_${r||""}`,I.URL),s=!!(o&&i&&n),c=t||x;return{rect:e.getBoundingClientRect(),itemtype:t,label:c,id:a,itemid:n,itemprop:r,parentid:i,isComponent:s}})(e);o.editables.push(t)})),o})(t);e.repaintEditables({editables:n})}),V);n(),window.removeEventListener("resize",n),window.addEventListener("resize",n),(({element:e,callback:t})=>{const n=new MutationObserver(t);n.observe(e,{attributes:!0,characterData:!0,childList:!0,subtree:!0,attributeOldValue:!0,characterDataOldValue:!0}),n.disconnect})({element:t,callback:n})},z=({editor:e})=>{const t=window;t.document.addEventListener("scroll",(0,m.debounce)((({target:t})=>{K({target:t}),Y({editor:e})}),V)),t.addEventListener("resize",(0,m.debounce)((({target:t})=>{G({target:t}),Y({editor:e})}),V)),t.addEventListener("orientationchange",(0,m.debounce)((({target:n})=>{K({target:t.document}),G({target:n}),Y({editor:e})}),V));const n=(0,m.debounce)((()=>{G({target:t}),Y({editor:e})}),V);new ResizeObserver(n).observe(t.document.body),requestAnimationFrame((()=>{K({target:t.document}),G({target:t}),Y({editor:e})}))},Q=({editor:e})=>{document.addEventListener("click",(t=>(({event:e,editor:t})=>{const n=e.target.closest("A");n&&(e.preventDefault(),t.navigateTo({href:n.href}))})({event:t,editor:e})),{capture:!0})},W=()=>{window.addEventListener("keydown",(({type:e,key:t,altKey:n,metaKey:r,shiftKey:o,ctrlKey:i})=>{const a={type:e,key:t,altKey:n,metaKey:r,shiftKey:o,ctrlKey:i};parent.postMessage({type:D.USER_INPUT_RELAY_MESSAGE,value:a},"*")}))},X="rgba(0, 0, 0, 0)",J=e=>{const t=window.getComputedStyle(e).backgroundColor,n=e.parentElement;return t===X&&n?J(n):t};var Z=function(e){var t,n=new Set,r=function(e,r){var o="function"==typeof e?e(t):e;if(!Object.is(o,t)){var i=t;t=(null!=r?r:"object"!=typeof o)?o:Object.assign({},t,o),n.forEach((function(e){return e(t,i)}))}},o=function(){return t},i={setState:r,getState:o,subscribe:function(e){return n.add(e),function(){return n.delete(e)}},destroy:function(){return n.clear()}};return t=e(r,o,i),i};const ee=({set:e},{mode:t})=>{e((e=>({...e,mode:t,isInEditor:"in-editor"===t})))},te=function(e){return e&&e.__esModule?e.default:e}((function(e){return e?Z(e):Z}))(((e,t)=>({mode:"regular",isInEditor:!1,setMode:ee.bind(null,{get:t,set:e})}))),ne=new RegExp(`^${D.URN_PREFIX}`),re={enableEditing:()=>{te.getState().setMode({mode:"in-editor"})},getEditableElement:e=>{const t=document.querySelector(e);if(!(t&&t instanceof HTMLElement))return;const n=window.getComputedStyle(t),r=J(t),o=r!==X?`${n.getPropertyValue("font-size")} ${n.getPropertyValue("font-family")}`:"";return{content:t.innerText,htmlContent:t.innerHTML,style:{font:n.getPropertyValue("font")||o,visibility:t.style.visibility,color:n.getPropertyValue("color"),textAlign:n.getPropertyValue("text-align"),textTransform:n.getPropertyValue("text-transform"),border:n.getPropertyValue("border"),padding:n.getPropertyValue("padding"),backgroundColor:r,width:n.getPropertyValue("width"),height:n.getPropertyValue("height")}}},updateField:async({selector:e,value:t})=>{const n=document.querySelector(e);return n&&(n.innerHTML=t),!0},removeField:({selector:e})=>{const t=document.querySelector(e);t&&t.remove()},getUrnMappings:()=>{const e=document.querySelectorAll(D.META_SELECTOR);return Array.from(e).reduce(((e,{name:t,content:n})=>({...e,[t.replace(ne,"")]:n})),{})}};(async()=>{const e=v({methods:re}),t=await e.promise;q({editor:t}),B({editor:t}),z({editor:t}),Q({editor:t}),W()})()})(); | ||
(()=>{var e,t,n,r,o,i,a,c;(t=e||(e={})).Call="call",t.Reply="reply",t.Syn="syn",t.SynAck="synAck",t.Ack="ack",(r=n||(n={})).Fulfilled="fulfilled",r.Rejected="rejected",(i=o||(o={})).ConnectionDestroyed="ConnectionDestroyed",i.ConnectionTimeout="ConnectionTimeout",i.NoIframeSrc="NoIframeSrc",(a||(a={})).DataCloneError="DataCloneError",(c||(c={})).Message="message";const s=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n});var l=(t,r,o)=>{const{localName:i,local:l,remote:d,originForSending:u,originForReceiving:p}=t;let g=!1;const f=t=>{if(t.source!==d||t.data.penpal!==e.Call)return;if("*"!==p&&t.origin!==p)return void o(`${i} received message from origin ${t.origin} which did not match expected origin ${p}`);const c=t.data,{methodName:l,args:f,id:m}=c;o(`${i}: Received ${l}() call`);const h=t=>r=>{if(o(`${i}: Sending ${l}() reply`),g)return void o(`${i}: Unable to send ${l}() reply due to destroyed connection`);const c={penpal:e.Reply,id:m,resolution:t,returnValue:r};t===n.Rejected&&r instanceof Error&&(c.returnValue=s(r),c.returnValueIsError=!0);try{d.postMessage(c,u)}catch(t){if(t.name===a.DataCloneError){const r={penpal:e.Reply,id:m,resolution:n.Rejected,returnValue:s(t),returnValueIsError:!0};d.postMessage(r,u)}throw t}};new Promise((e=>e(r[l].apply(r,f)))).then(h(n.Fulfilled),h(n.Rejected))};return l.addEventListener(c.Message,f),()=>{g=!0,l.removeEventListener(c.Message,f)}};let d=0;const u=e=>e?e.split("."):[],p=(e,t,n)=>{const r=u(t);return r.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t])),e),e},g=(e,t)=>{const n={};return Object.keys(e).forEach((r=>{const o=e[r],i=((e,t)=>{const n=u(t||"");return n.push(e),(e=>e.join("."))(n)})(r,t);"object"==typeof o&&Object.assign(n,g(o,i)),"function"==typeof o&&(n[i]=o)})),n},f=e=>{const t={};for(const n in e)p(t,n,e[n]);return t};var m,h=(t,r,i,a,s)=>{const{localName:l,local:u,remote:p,originForSending:g,originForReceiving:m}=r;let h=!1;s(`${l}: Connecting call sender`);const E=t=>(...r)=>{let i;s(`${l}: Sending ${t}() call`);try{p.closed&&(i=!0)}catch(e){i=!0}if(i&&a(),h){const e=new Error(`Unable to send ${t}() call due to destroyed connection`);throw e.code=o.ConnectionDestroyed,e}return new Promise(((o,i)=>{const a=++d,f=r=>{if(r.source!==p||r.data.penpal!==e.Reply||r.data.id!==a)return;if("*"!==m&&r.origin!==m)return void s(`${l} received message from origin ${r.origin} which did not match expected origin ${m}`);const d=r.data;s(`${l}: Received ${t}() reply`),u.removeEventListener(c.Message,f);let g=d.returnValue;d.returnValueIsError&&(g=(e=>{const t=new Error;return Object.keys(e).forEach((n=>t[n]=e[n])),t})(g)),(d.resolution===n.Fulfilled?o:i)(g)};u.addEventListener(c.Message,f);const h={penpal:e.Call,id:a,methodName:t,args:r};p.postMessage(h,g)}))},y=i.reduce(((e,t)=>(e[t]=E(t),e)),{});return Object.assign(t,f(y)),()=>{h=!0}},E=(e,t)=>{let n;return void 0!==e&&(n=window.setTimeout((()=>{const n=new Error(`Connection timed out after ${e}ms`);n.code=o.ConnectionTimeout,t(n)}),e)),()=>{clearTimeout(n)}},y=(t,n,r,o)=>{const{destroy:i,onDestroy:a}=r;return r=>{if(!(t instanceof RegExp?t.test(r.origin):"*"===t||t===r.origin))return void o(`Child: Handshake - Received SYN-ACK from origin ${r.origin} which did not match expected origin ${t}`);o("Child: Handshake - Received SYN-ACK, responding with ACK");const c="null"===r.origin?"*":r.origin,s={penpal:e.Ack,methodNames:Object.keys(n)};window.parent.postMessage(s,c);const d={localName:"Child",local:window,remote:window.parent,originForSending:c,originForReceiving:r.origin},u=l(d,n,o);a(u);const p={},g=h(p,d,r.data.methodNames,i,o);return a(g),p}},v=(t={})=>{const{parentOrigin:n="*",methods:r={},timeout:o,debug:i=!1}=t,a=(e=>(...t)=>{e&&console.log("[Penpal]",...t)})(i),s=((e,t)=>{const n=[];let r=!1;return{destroy(o){r||(r=!0,t(`${e}: Destroying connection`),n.forEach((e=>{e(o)})))},onDestroy(e){r?e():n.push(e)}}})("Child",a),{destroy:l,onDestroy:d}=s,u=g(r),p=y(n,u,s,a);return{promise:new Promise(((t,r)=>{const i=E(o,l),s=n=>{if((()=>{try{clearTimeout()}catch(e){return!1}return!0})()&&n.source===parent&&n.data&&n.data.penpal===e.SynAck){const e=p(n);e&&(window.removeEventListener(c.Message,s),i(),t(e))}};window.addEventListener(c.Message,s),(()=>{a("Child: Handshake - Sending SYN");const t={penpal:e.Syn},r=n instanceof RegExp?"*":n;window.parent.postMessage(t,r)})(),d((e=>{window.removeEventListener(c.Message,s),e&&r(e)}))})),destroy(){l()}}};function w(e,t,n){var r,o,i,a,c;function s(){var l=Date.now()-a;l<t&&l>=0?r=setTimeout(s,t-l):(r=null,n||(c=e.apply(i,o),i=o=null))}null==t&&(t=100);var l=function(){i=this,o=arguments,a=Date.now();var l=n&&!r;return r||(r=setTimeout(s,t)),l&&(c=e.apply(i,o),i=o=null),c};return l.clear=function(){r&&(clearTimeout(r),r=null)},l.flush=function(){r&&(c=e.apply(i,o),i=o=null,clearTimeout(r),r=null)},l}w.debounce=w,m=w;var R=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;const b=[];for(let e=0;e<256;++e)b.push((e+256).toString(16).slice(1));var A=function(e){if(!function(e){return"string"==typeof e&&R.test(e)}(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n};function T(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:case 3:return t^n^r;case 2:return t&n^t&r^n&r}}function P(e,t){return e<<t|e>>>32-t}var C,S,L=function(e,t,n){function r(e,t,n,r){var o;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}(e)),"string"==typeof t&&(t=A(t)),16!==(null===(o=t)||void 0===o?void 0:o.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let i=new Uint8Array(16+e.length);if(i.set(t),i.set(e,t.length),i=function(e){const t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const r=e.length/4+2,o=Math.ceil(r/16),i=new Array(o);for(let t=0;t<o;++t){const n=new Uint32Array(16);for(let r=0;r<16;++r)n[r]=e[64*t+4*r]<<24|e[64*t+4*r+1]<<16|e[64*t+4*r+2]<<8|e[64*t+4*r+3];i[t]=n}i[o-1][14]=8*(e.length-1)/Math.pow(2,32),i[o-1][14]=Math.floor(i[o-1][14]),i[o-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<o;++e){const r=new Uint32Array(80);for(let t=0;t<16;++t)r[t]=i[e][t];for(let e=16;e<80;++e)r[e]=P(r[e-3]^r[e-8]^r[e-14]^r[e-16],1);let o=n[0],a=n[1],c=n[2],s=n[3],l=n[4];for(let e=0;e<80;++e){const n=Math.floor(e/20),i=P(o,5)+T(n,a,c,s)+l+t[n]+r[e]>>>0;l=s,s=c,c=P(a,30)>>>0,a=o,o=i}n[0]=n[0]+o>>>0,n[1]=n[1]+a>>>0,n[2]=n[2]+c>>>0,n[3]=n[3]+s>>>0,n[4]=n[4]+l>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]}(i),i[6]=15&i[6]|80,i[8]=63&i[8]|128,n){r=r||0;for(let e=0;e<16;++e)n[r+e]=i[e];return n}return function(e,t=0){return(b[e[t+0]]+b[e[t+1]]+b[e[t+2]]+b[e[t+3]]+"-"+b[e[t+4]]+b[e[t+5]]+"-"+b[e[t+6]]+b[e[t+7]]+"-"+b[e[t+8]]+b[e[t+9]]+"-"+b[e[t+10]]+b[e[t+11]]+b[e[t+12]]+b[e[t+13]]+b[e[t+14]]+b[e[t+15]]).toLowerCase()}(i)}try{r.name="v5"}catch(e){}return r.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",r.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",r}();(S=C||(C={})).ID="itemID",S.TYPE="itemType",S.SCOPE="itemScope",S.PROP="itemProp";const I={UUID:"id",ID:C.ID.toLowerCase(),TYPE:C.TYPE.toLowerCase(),SCOPE:C.SCOPE.toLowerCase(),PROP:C.PROP.toLowerCase(),PARENTID:"parentid",EDITOR_BEHAVIOR:"data-editor-behavior"},O="universal-editor-message-bus.herokuapp.com",_="/gql",M="urn:auecon:",D={USER_INPUT_RELAY_MESSAGE:"REMOTE_APP_USER_INPUT",DEMO_APP_HOST:"ue-remote-app.adobe.net",GRAPHQL_HOST:O,GRAPHQL_PORT_PUBLIC:443,GRAPHQL_PORT_LOCAL:4e3,GRAPHQL_PATH:_,GRAPHQL_URL:`${O}:443${_}`,EDITABLE_SELECTOR:`[${I.TYPE}]`,CANVAS_PATH:"/canvas",PARENT_SELECTOR:`[${I.SCOPE}][${I.ID}]`,URN_PREFIX:M,META_SELECTOR:`meta[name^='${M}']`,DEMO_APP_HOST_PROD:"ue-remote-app-prod.adobe.net",FRAGMENT_TYPE:"reference",UNIFIED_SHELL_STAGE:"https://experience-stage.adobe.com",UNIFIED_SHELL_PROD:"https://experience.adobe.com",HEADLESS_CF_EDITOR_URL:"#/aem/cf/editor/editor",CONTAINER_SELECTOR:`[${I.TYPE}=container]`,COMPONENT_ITEM_TYPE:"component"};var $=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;const U=[];for(let e=0;e<256;++e)U.push((e+256).toString(16).slice(1));var N=function(e){if(!function(e){return"string"==typeof e&&$.test(e)}(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n};function k(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:case 3:return t^n^r;case 2:return t&n^t&r^n&r}}function H(e,t){return e<<t|e>>>32-t}!function(e,t,n){function r(e,t,n,r){var o;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}(e)),"string"==typeof t&&(t=N(t)),16!==(null===(o=t)||void 0===o?void 0:o.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let i=new Uint8Array(16+e.length);if(i.set(t),i.set(e,t.length),i=function(e){const t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const r=e.length/4+2,o=Math.ceil(r/16),i=new Array(o);for(let t=0;t<o;++t){const n=new Uint32Array(16);for(let r=0;r<16;++r)n[r]=e[64*t+4*r]<<24|e[64*t+4*r+1]<<16|e[64*t+4*r+2]<<8|e[64*t+4*r+3];i[t]=n}i[o-1][14]=8*(e.length-1)/Math.pow(2,32),i[o-1][14]=Math.floor(i[o-1][14]),i[o-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<o;++e){const r=new Uint32Array(80);for(let t=0;t<16;++t)r[t]=i[e][t];for(let e=16;e<80;++e)r[e]=H(r[e-3]^r[e-8]^r[e-14]^r[e-16],1);let o=n[0],a=n[1],c=n[2],s=n[3],l=n[4];for(let e=0;e<80;++e){const n=Math.floor(e/20),i=H(o,5)+k(n,a,c,s)+l+t[n]+r[e]>>>0;l=s,s=c,c=H(a,30)>>>0,a=o,o=i}n[0]=n[0]+o>>>0,n[1]=n[1]+a>>>0,n[2]=n[2]+c>>>0,n[3]=n[3]+s>>>0,n[4]=n[4]+l>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]}(i),i[6]=15&i[6]|80,i[8]=63&i[8]|128,n){r=r||0;for(let e=0;e<16;++e)n[r+e]=i[e];return n}return function(e,t=0){return(U[e[t+0]]+U[e[t+1]]+U[e[t+2]]+U[e[t+3]]+"-"+U[e[t+4]]+U[e[t+5]]+"-"+U[e[t+6]]+U[e[t+7]]+"-"+U[e[t+8]]+U[e[t+9]]+"-"+U[e[t+10]]+U[e[t+11]]+U[e[t+12]]+U[e[t+13]]+U[e[t+14]]+U[e[t+15]]).toLowerCase()}(i)}try{r.name="v5"}catch(e){}r.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",r.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8"}();const F={element:window.document},V=150,x="Component",j=e=>{const t=e.closest(D.PARENT_SELECTOR);return(null==t?void 0:t.getAttribute(I.ID))||""},Y={viewport:{width:0,height:0},frame:{width:0,height:0},scroll:{x:0,y:0}},K=({editor:e})=>{null==e||e.updateFrameDetails({details:Y})},G=({target:e})=>{const t=e.documentElement;Y.scroll.x=t.scrollLeft,Y.scroll.y=t.scrollTop},q=({target:e})=>{const t=Math.max(e.document.documentElement.clientWidth||0,e.innerWidth||0),n=Math.max(e.document.documentElement.clientHeight||0,e.innerHeight||0),{width:r,height:o}=e.document.documentElement.getBoundingClientRect();Y.viewport={width:t,height:n},Y.frame={width:Math.ceil(r),height:Math.ceil(o)}},B=({editor:e})=>{const t=[];[...document.styleSheets].forEach((e=>{try{const{cssRules:n}=e;[...n].find((e=>e instanceof CSSFontFaceRule))&&e.href&&t.push(e.href)}catch(n){e.href&&t.push(e.href)}})),e.addCustomFonts(t)},z=({editor:e})=>{const t=F.element,n=(0,m.debounce)((()=>{const n=(e=>{const{scrollLeft:t,scrollTop:n}=e.documentElement,r=e.querySelectorAll(D.EDITABLE_SELECTOR)||[],o={editables:[],offset:{x:t,y:n},selected:{}};return r.forEach((e=>{const t=(e=>{const t=e.getAttribute(I.TYPE)||"",n=e.getAttribute(I.ID)||void 0,r=e.getAttribute(I.PROP)||void 0,o=t===D.COMPONENT_ITEM_TYPE||e.getAttribute(I.EDITOR_BEHAVIOR)===D.COMPONENT_ITEM_TYPE,i=!n&&r?j(e):"",a=o&&n?(e=>{const t=e.closest(D.CONTAINER_SELECTOR),n=null==t?void 0:t.getAttribute(I.ID);if(n)return L(`${n}`,L.URL);const r=null==t?void 0:t.getAttribute(I.PROP),o=t&&j(t);return r&&o?L(`${o}_${r}`,L.URL):""})(e):"",c=L(`${n||i}${r?`_${r}`:""}`,L.URL),s=t||x;return{rect:e.getBoundingClientRect(),itemtype:t,label:s,id:c,itemid:n,itemprop:r,containerid:a,parentid:i}})(e);o.editables.push(t)})),o})(t);e.repaintEditables({editables:n})}),V);n(),window.removeEventListener("resize",n),window.addEventListener("resize",n),(({element:e,callback:t})=>{const n=new MutationObserver(t);n.observe(e,{attributes:!0,characterData:!0,childList:!0,subtree:!0,attributeOldValue:!0,characterDataOldValue:!0}),n.disconnect})({element:t,callback:n})},Q=({editor:e})=>{const t=window;t.document.addEventListener("scroll",(0,m.debounce)((({target:t})=>{G({target:t}),K({editor:e})}),V)),t.addEventListener("resize",(0,m.debounce)((({target:t})=>{q({target:t}),K({editor:e})}),V)),t.addEventListener("orientationchange",(0,m.debounce)((({target:n})=>{G({target:t.document}),q({target:n}),K({editor:e})}),V));const n=(0,m.debounce)((()=>{q({target:t}),K({editor:e})}),V);new ResizeObserver(n).observe(t.document.body),requestAnimationFrame((()=>{G({target:t.document}),q({target:t}),K({editor:e})}))},W=({editor:e})=>{document.addEventListener("click",(t=>(({event:e,editor:t})=>{const n=e.target.closest("A");n&&(e.preventDefault(),t.navigateTo({href:n.href}))})({event:t,editor:e})),{capture:!0})},X=()=>{window.addEventListener("keydown",(({type:e,key:t,altKey:n,metaKey:r,shiftKey:o,ctrlKey:i})=>{const a={type:e,key:t,altKey:n,metaKey:r,shiftKey:o,ctrlKey:i};parent.postMessage({type:D.USER_INPUT_RELAY_MESSAGE,value:a},"*")}))},J="rgba(0, 0, 0, 0)",Z=e=>{const t=window.getComputedStyle(e).backgroundColor,n=e.parentElement;return t===J&&n?Z(n):t};var ee=function(e){var t,n=new Set,r=function(e,r){var o="function"==typeof e?e(t):e;if(!Object.is(o,t)){var i=t;t=(null!=r?r:"object"!=typeof o)?o:Object.assign({},t,o),n.forEach((function(e){return e(t,i)}))}},o=function(){return t},i={setState:r,getState:o,subscribe:function(e){return n.add(e),function(){return n.delete(e)}},destroy:function(){return n.clear()}};return t=e(r,o,i),i};const te=({set:e},{mode:t})=>{e((e=>({...e,mode:t,isInEditor:"in-editor"===t})))},ne=function(e){return e&&e.__esModule?e.default:e}((function(e){return e?ee(e):ee}))(((e,t)=>({mode:"regular",isInEditor:!1,setMode:te.bind(null,{get:t,set:e})}))),re=new RegExp(`^${D.URN_PREFIX}`),oe={enableEditing:()=>{ne.getState().setMode({mode:"in-editor"})},getEditableElement:e=>{const t=document.querySelector(e);if(!(t&&t instanceof HTMLElement))return;const n=window.getComputedStyle(t),r=Z(t),o=r!==J?`${n.getPropertyValue("font-size")} ${n.getPropertyValue("font-family")}`:"";return{content:t.innerText,htmlContent:t.innerHTML,style:{font:n.getPropertyValue("font")||o,visibility:t.style.visibility,color:n.getPropertyValue("color"),textAlign:n.getPropertyValue("text-align"),textTransform:n.getPropertyValue("text-transform"),border:n.getPropertyValue("border"),padding:n.getPropertyValue("padding"),backgroundColor:r,width:n.getPropertyValue("width"),height:n.getPropertyValue("height")}}},updateField:async({selector:e,value:t})=>{const n=document.querySelector(e);return n&&(n.innerHTML=t),!0},removeField:({selector:e})=>{const t=document.querySelector(e);t&&t.remove()},getUrnMappings:()=>{const e=document.querySelectorAll(D.META_SELECTOR);return Array.from(e).reduce(((e,{name:t,content:n})=>({...e,[t.replace(re,"")]:n})),{})}};(async()=>{const e=v({methods:oe}),t=await e.promise;B({editor:t}),z({editor:t}),Q({editor:t}),W({editor:t}),X()})()})(); | ||
//# sourceMappingURL=universal-editor-embedded.js.map |
{ | ||
"name": "@adobe/universal-editor-cors", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Utility providing communication layer between edited App and Universal Editor.", | ||
@@ -5,0 +5,0 @@ "main": "dist/universal-editor-embedded.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
29589
66
0