@accelerated-agency/visual-editor 0.1.6 → 0.1.8
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/dist/bridge-channel-ISTPKGMY.js +1 -10
- package/dist/chunk-WCSTG2IY.js +1 -5
- package/dist/index.js +651 -743
- package/dist/vite.cjs +2084 -0
- package/dist/vite.js +42 -11
- package/package.json +5 -4
package/dist/vite.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
1
5
|
// src/visualEditorProxyPlugin.ts
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { fileURLToPath } from "url";
|
|
5
6
|
var popupHideCss = `<style id="__ce_popup_hide">#CybotCookiebotDialog,#CybotCookiebotDialogBodyUnderlay,#onetrust-consent-sdk,#onetrust-banner-sdk,.cc-window,.cc-banner,.cc-overlay,#cookie-notice,#cookie-banner,#cookie-consent,.cookie-notice,.cookie-banner,.cookie-consent,.cookie-popup,.cookie-bar,.cookie-message,.cookie-alert,.gdpr-banner,.gdpr-consent,.gdpr-popup,.gdpr-overlay,#gdpr-consent,#gdpr-banner,.consent-banner,.consent-popup,.consent-overlay,#consent-banner,#consent-popup,[class*="cookie-consent"],[class*="cookie-banner"],[class*="cookie-notice"],[class*="CookieConsent"],[class*="CookieBanner"],[id*="cookie-consent"],[id*="cookie-banner"],[id*="cookie-notice"],[aria-label*="cookie" i],[aria-label*="consent" i],.klaro,.klaro .cookie-modal,#usercentrics-root,.trustarc-banner,#truste-consent-track,#hs-eu-cookie-confirmation,.osano-cm-window,.osano-cm-dialog,.evidon-banner,#_evidon_banner,.js-cookie-consent,.cookie-disclaimer,.shopify-section-cookies,#shopify-section-cookies,#shopify-pc__banner,#shopify-pc__modal,.privacy-banner,.privacy-popup,[data-testid="cookie-banner"],[data-testid="consent-banner"],.amgdprcookie-bar-container,[data-amcookie-js="bar"],.amgdprjs-bar-template,.amgdprcookie-modal-container,.amgdprcookie-modal-overlay,#cmplz-cookiebanner-container,.cmplz-cookiebanner,#iubenda-cs-banner,.iubenda-cs-container,#qc-cmp2-container,.qc-cmp2-consent-info,#didomi-host,.didomi-popup-container,.didomi-notice,#termly-code-snippet-support,[class*="termly"],[class*="gdprcookie"],[class*="amgdpr"],[id*="gdpr-cookie"],[class*="cookie-modal"],[id*="cookie-modal"],[class*="cookieConsent"],[id*="cookieConsent"],.klaviyo-form,.klaviyo-modal,.klaviyo-popup,[class*="klaviyo"],.privy-popup,.privy-flyout,[id*="privy"],#PopupSignupForm,.popup-signup,.newsletter-popup,.newsletter-modal,[class*="newsletter-popup"],[class*="newsletter-modal"],[id*="newsletter-popup"],.email-popup,.email-modal,[class*="email-popup"],[class*="email-modal"],.signup-popup,.signup-modal,[class*="signup-popup"],[class*="signup-modal"],.subscribe-popup,.subscribe-modal,[class*="subscribe-popup"],#mc_embed_signup,.mc-modal,.mc-banner,.mc-closeModal,.omniconvert-popup,[class*="omniconvert"],.optinmonster-popup,[id*="om-"][class*="campaign"],.sumo-overlay,.sumome-overlay,[class*="sumome"],.hustle-modal,.hustle-popup,[class*="hustle-"],.popup-overlay,.popup-modal,.modal-overlay,[class*="exit-intent"],[class*="exitintent"],.wheelio-popup,[class*="wheelio"],.spin-wheel-popup,.justuno-popup,[class*="justuno"],.wisepops,.wisepops-overlay,[class*="wisepops"],.elegantmodal,.elegant-popup,#zipify-popup,[class*="zipify"],.age-gate,.age-verification,.age-popup,[class*="age-gate"],[class*="age-verif"],[class*="popup-overlay"],[class*="modal-overlay"],[class*="popup-backdrop"]{display:none!important;visibility:hidden!important;opacity:0!important;pointer-events:none!important;height:0!important;overflow:hidden!important;}body.klaviyo-open,body.modal-open,body.popup-open,body.no-scroll,body.noscroll{overflow:auto!important;position:static!important;}</style>`;
|
|
6
7
|
var AI_SYSTEM_PROMPT = `You are a CRO expert. Return JSON only with: hypothesis, mutations, summary. Keep 2-6 precise mutations and only valid selectors from snapshot.`;
|
|
7
8
|
var BRIDGE_SCRIPT = `(function(){if(window.__CONVERSION_BRIDGE_LOADED__)return;window.__CONVERSION_BRIDGE_LOADED__=true;var CHANNEL='conversion-editor';var highlightEl=null;function send(payload){window.parent.postMessage({channel:CHANNEL,payload:payload},'*');}function qs(selector){try{return document.querySelector(selector);}catch(_){return null;}}function getSelector(el){if(!el||el.nodeType!==1)return'';if(el.id)return'#'+CSS.escape(el.id);var parts=[];var current=el;var depth=0;while(current&¤t.nodeType===1&&depth<5){var part=current.tagName.toLowerCase();if(current.classList&¤t.classList.length){part+='.'+Array.from(current.classList).slice(0,2).map(function(c){return CSS.escape(c);}).join('.');}var parent=current.parentElement;if(parent){var siblings=Array.from(parent.children).filter(function(s){return s.tagName===current.tagName;});if(siblings.length>1)part+=':nth-of-type('+(siblings.indexOf(current)+1)+')';}parts.unshift(part);current=parent;depth+=1;}return parts.join(' > ');}function payloadOf(el){var rect=el.getBoundingClientRect();var style=window.getComputedStyle(el);return{selector:getSelector(el),tagName:el.tagName.toLowerCase(),textContent:(el.textContent||'').trim().slice(0,500),computedStyles:{color:style.color,backgroundColor:style.backgroundColor,fontSize:style.fontSize,fontWeight:style.fontWeight,lineHeight:style.lineHeight,display:style.display},rect:{top:rect.top,left:rect.left,width:rect.width,height:rect.height}};}function applyMutation(m){var el=qs(m.selector);if(!el)return;switch(m.action){case'setStyle':if(m.property)el.style[m.property]=m.value;break;case'setText':el.textContent=m.value;break;case'setHTML':el.innerHTML=m.value;break;case'setAttribute':if(m.property)el.setAttribute(m.property,m.value);break;case'hide':el.style.display='none';break;case'show':el.style.display='';break;case'insertHTML':if(m.position)el.insertAdjacentHTML(m.position,m.value||'');break;case'insertSection':if(m.position)el.insertAdjacentHTML(m.position,m.sectionHtml||m.value||'');break;case'reorderElement':if(!m.targetSelector)break;var target=qs(m.targetSelector);if(!target||!target.parentNode||!el.parentNode)break;if(m.insertPosition==='before')target.parentNode.insertBefore(el,target);else target.parentNode.insertBefore(el,target.nextSibling);break;default:break;}}function revertMutation(m){var el=qs(m.selector);if(!el)return;switch(m.action){case'setStyle':if(m.property)el.style[m.property]=m.previous||'';break;case'setText':el.textContent=m.previous||'';break;case'setHTML':el.innerHTML=m.previous||'';break;case'setAttribute':if(m.property){if(m.previous!=null)el.setAttribute(m.property,m.previous);else el.removeAttribute(m.property);}break;case'hide':case'show':el.style.display=m.previous||'';break;default:break;}}function captureSnapshot(){var elements=Array.from(document.querySelectorAll('h1,h2,h3,p,button,a,input,select,img,section,div')).slice(0,700).map(function(el){var rect=el.getBoundingClientRect();var cs=window.getComputedStyle(el);return{selector:getSelector(el),parentSelector:el.parentElement?getSelector(el.parentElement):null,tagName:el.tagName.toLowerCase(),textContent:(el.textContent||'').trim().slice(0,300),attributes:Array.from(el.attributes||[]).reduce(function(acc,a){acc[a.name]=a.value;return acc;},{}),computedStyles:{color:cs.color,backgroundColor:cs.backgroundColor,fontSize:cs.fontSize,fontWeight:cs.fontWeight,display:cs.display},childrenCount:el.children?el.children.length:0,aboveFold:rect.top<window.innerHeight,depth:(function(){var d=0,p=el.parentElement;while(p&&d<25){d++;p=p.parentElement;}return d;})()};});send({type:'snapshotCaptured',snapshot:{url:window.location.href,title:document.title,viewport:{width:window.innerWidth,height:window.innerHeight},elements:elements}});}function captureTree(){function toNode(el,depth){var rect=el.getBoundingClientRect();var tag=el.tagName.toLowerCase();var type='generic';if(tag==='section')type='section';else if(tag==='img')type='image';else if(tag==='a')type='link';else if(tag==='button')type='button';else if(tag==='form')type='form';else if(['p','h1','h2','h3','h4','h5','h6','span'].indexOf(tag)>=0)type='text';else if(['div','main','article','aside','header','footer','nav'].indexOf(tag)>=0)type='container';var children=Array.from(el.children||[]).slice(0,50).map(function(c){return toNode(c,depth+1);});return{id:getSelector(el),selector:getSelector(el),tagName:tag,label:(el.getAttribute('aria-label')||el.getAttribute('id')||el.className||tag).toString().slice(0,80),type:type,children:children,depth:depth,isAboveFold:rect.top<window.innerHeight,rect:{top:rect.top,left:rect.left,width:rect.width,height:rect.height}};}send({type:'pageTreeCaptured',tree:[toNode(document.body,0)]});}window.addEventListener('message',function(e){var msg=e.data;if(!msg||msg.channel!==CHANNEL||!msg.payload)return;var p=msg.payload;switch(p.type){case'ping':send({type:'pong'});break;case'applyMutation':applyMutation(p.mutation);break;case'applyMutationBatch':(p.mutations||[]).forEach(applyMutation);break;case'revert':revertMutation(p.mutation);break;case'clearAllMutations':window.location.reload();break;case'captureSnapshot':captureSnapshot();break;case'validateSelectors':send({type:'selectorsValidated',results:(p.selectors||[]).map(function(s){var el=qs(s);return{selector:s,found:!!el,tagName:el?el.tagName.toLowerCase():null};})});break;case'scrollToElement':case'selectElement':var target=qs(p.selector);if(target){target.scrollIntoView({behavior:'smooth',block:'center'});send({type:'elementSelected',element:payloadOf(target)});}break;case'hoverElement':var h=qs(p.selector);if(h){if(highlightEl)highlightEl.style.outline='';h.style.outline='2px solid #3b82f6';highlightEl=h;}break;case'capturePageTree':captureTree();break;default:break;}});document.addEventListener('click',function(e){var el=e.target;if(!(el instanceof Element))return;send({type:'elementSelected',element:payloadOf(el)});},true);send({type:'bridgeReady'});})();`;
|
|
@@ -1771,9 +1772,17 @@ function createVisualEditorMiddleware(options) {
|
|
|
1771
1772
|
const enableGenerateTestApi = options?.enableGenerateTestApi ?? true;
|
|
1772
1773
|
const allowedFrameOrigins = options?.allowedFrameOrigins ?? ["*"];
|
|
1773
1774
|
function setFrameHeaders(req, res) {
|
|
1775
|
+
res.removeHeader("X-Frame-Options");
|
|
1774
1776
|
const requestOrigin = req.headers?.["origin"] || req.headers?.["referer"] || "";
|
|
1775
1777
|
if (allowedFrameOrigins.includes("*")) {
|
|
1776
|
-
|
|
1778
|
+
let frameOrigin = "*";
|
|
1779
|
+
if (requestOrigin) {
|
|
1780
|
+
try {
|
|
1781
|
+
frameOrigin = new URL(requestOrigin).origin;
|
|
1782
|
+
} catch {
|
|
1783
|
+
frameOrigin = "*";
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1777
1786
|
res.setHeader("Content-Security-Policy", `frame-ancestors 'self' ${frameOrigin}`);
|
|
1778
1787
|
} else {
|
|
1779
1788
|
res.setHeader(
|
|
@@ -1785,6 +1794,7 @@ function createVisualEditorMiddleware(options) {
|
|
|
1785
1794
|
return async (req, res, next) => {
|
|
1786
1795
|
const pathname = (req.url || "").split("?")[0];
|
|
1787
1796
|
if (pathname === "/bridge.js") {
|
|
1797
|
+
res.removeHeader("X-Frame-Options");
|
|
1788
1798
|
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
1789
1799
|
res.setHeader("Cache-Control", "no-store");
|
|
1790
1800
|
res.end(BRIDGE_SCRIPT);
|
|
@@ -1901,6 +1911,23 @@ function createVisualEditorMiddleware(options) {
|
|
|
1901
1911
|
}
|
|
1902
1912
|
return;
|
|
1903
1913
|
}
|
|
1914
|
+
const isRootProxyPath = pathname === "/api/proxy" || pathname.startsWith("/api/proxy/");
|
|
1915
|
+
if (!isRootProxyPath && pathname.includes("api/proxy")) {
|
|
1916
|
+
if ((req.method || "GET").toUpperCase() === "OPTIONS") {
|
|
1917
|
+
res.statusCode = 204;
|
|
1918
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
1919
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, OPTIONS");
|
|
1920
|
+
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
1921
|
+
res.end();
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
res.statusCode = 200;
|
|
1925
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
1926
|
+
res.setHeader("Cache-Control", "no-store");
|
|
1927
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
1928
|
+
res.end("{}");
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1904
1931
|
if (pathname.startsWith("/api/proxy")) {
|
|
1905
1932
|
try {
|
|
1906
1933
|
const url = new URL(req.url || "", "http://localhost");
|
|
@@ -1992,14 +2019,20 @@ function createVisualEditorMiddleware(options) {
|
|
|
1992
2019
|
const escapedOrigin = origin.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1993
2020
|
const proxyBase = `/api/proxy?password=${encodeURIComponent(password)}&url=`;
|
|
1994
2021
|
html = html.replace(
|
|
1995
|
-
new RegExp(`(href|
|
|
1996
|
-
(
|
|
2022
|
+
new RegExp(`(href|action)="${escapedOrigin}(/[^"]*)"`, "g"),
|
|
2023
|
+
(match, attr, urlPath) => {
|
|
2024
|
+
const lastSegment = urlPath.split("?")[0].split("#")[0].split("/").pop() || "";
|
|
2025
|
+
if (attr === "href" && /\.\w{1,5}$/.test(lastSegment)) {
|
|
2026
|
+
return match;
|
|
2027
|
+
}
|
|
2028
|
+
return `${attr}="${proxyBase}${encodeURIComponent(origin + urlPath)}"`;
|
|
2029
|
+
}
|
|
1997
2030
|
);
|
|
1998
2031
|
if (html.includes("</head>")) {
|
|
1999
2032
|
html = html.replace("</head>", `${popupHideCss}
|
|
2000
2033
|
</head>`);
|
|
2001
2034
|
}
|
|
2002
|
-
const runtimeProxyScript = `<script>(function(){try{var TARGET_ORIGIN=${JSON.stringify(origin)};var TARGET_PAGE_URL=${JSON.stringify(targetUrl)};
|
|
2035
|
+
const runtimeProxyScript = `<script>(function(){try{var TARGET_ORIGIN=${JSON.stringify(origin)};var TARGET_PAGE_URL=${JSON.stringify(targetUrl)};function isSkippable(raw){if(!raw||typeof raw!=="string")return true;return raw.startsWith("data:")||raw.startsWith("blob:")||raw.startsWith("javascript:")||raw.startsWith("#")||raw.startsWith("http")||raw.startsWith("//");}function toAbsoluteOriginUrl(raw){if(isSkippable(raw))return raw;try{var base=raw.startsWith("/")?TARGET_ORIGIN:TARGET_PAGE_URL;var abs=new URL(raw,base);if(abs.origin!==TARGET_ORIGIN)return raw;return abs.toString();}catch(_){return raw;}}if(window.fetch){var _fetch=window.fetch.bind(window);window.fetch=function(input,init){try{if(typeof input==="string"){input=toAbsoluteOriginUrl(input);}else if(input&&input.url){var next=toAbsoluteOriginUrl(input.url);if(next!==input.url){input=new Request(next,input);}}}catch(_){}return _fetch(input,init);};}if(window.XMLHttpRequest&&window.XMLHttpRequest.prototype&&window.XMLHttpRequest.prototype.open){var _open=window.XMLHttpRequest.prototype.open;window.XMLHttpRequest.prototype.open=function(method,url){try{arguments[1]=toAbsoluteOriginUrl(url);}catch(_){}return _open.apply(this,arguments);};}if(window.navigator&&window.navigator.serviceWorker&&typeof window.navigator.serviceWorker.register==="function"){window.navigator.serviceWorker.register=function(){return Promise.resolve({scope:"disabled-in-editor-proxy"});};}}catch(_){}})();</script>`;
|
|
2003
2036
|
if (html.includes("</head>")) {
|
|
2004
2037
|
html = html.replace("</head>", `${runtimeProxyScript}
|
|
2005
2038
|
</head>`);
|
|
@@ -2038,7 +2071,5 @@ function visualEditorProxyPlugin(options) {
|
|
|
2038
2071
|
}
|
|
2039
2072
|
};
|
|
2040
2073
|
}
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
visualEditorProxyPlugin
|
|
2044
|
-
};
|
|
2074
|
+
|
|
2075
|
+
export { createVisualEditorMiddleware, visualEditorProxyPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@accelerated-agency/visual-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Conversion visual editor as a reusable React package",
|
|
6
6
|
"type": "module",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"./vite": {
|
|
15
15
|
"import": "./dist/vite.js",
|
|
16
|
+
"require": "./dist/vite.cjs",
|
|
16
17
|
"default": "./dist/vite.js"
|
|
17
18
|
}
|
|
18
19
|
},
|
|
@@ -21,10 +22,10 @@
|
|
|
21
22
|
],
|
|
22
23
|
"sideEffects": false,
|
|
23
24
|
"scripts": {
|
|
24
|
-
"dev": "tsup
|
|
25
|
+
"dev": "tsup --watch",
|
|
25
26
|
"clean": "rm -rf dist",
|
|
26
|
-
"build": "
|
|
27
|
-
"watch": "tsup
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"watch": "tsup --watch"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
31
|
"react": ">=18",
|