v1.5.0
AtheraStudio Code
- (function () {
- "use strict";
-
- var A = window.Athera;
- var util = A.util;
- var fs = A.fs;
-
- var PREVIEWABLE = ["html", "htm", "xhtml", "php", "phtml", "svg"];
- var dataCache = new Map();
- var missing = new Set();
- var buildId = 0;
-
- var HELPER = "(function(){var B=__B__;" +
- "function send(m){m.__athera=B;try{parent.postMessage(m,'*')}catch(e){}}" +
- "document.addEventListener('click',function(e){var a=e.target.closest&&e.target.closest('a[href]');if(!a)return;" +
- "var h=a.getAttribute('href');if(!h||h.charAt(0)==='#'||/^(javascript|mailto|tel):/i.test(h))return;e.preventDefault();" +
- "if(/^([a-z]+:)?\\/\\//i.test(h)){window.open(h,'_blank','noopener');return}send({type:'nav',href:h})},true);" +
- "document.addEventListener('submit',function(e){var f=e.target;if(!f||f.tagName!=='FORM')return;var a=f.getAttribute('action')||'';" +
- "if(/^([a-z]+:)?\\/\\//i.test(a))return;e.preventDefault();var m=(f.getAttribute('method')||'GET').toUpperCase();var d=new FormData(f);" +
- "if(e.submitter&&e.submitter.name)d.append(e.submitter.name,e.submitter.value||'');var p=new URLSearchParams();" +
- "d.forEach(function(v,k){p.append(k,typeof v==='string'?v:(v&&v.name)||'')});send({type:'submit',action:a,method:m,data:p.toString()})},true);" +
- "var y=__Y__;if(y)addEventListener('load',function(){scrollTo(0,y)});" +
- "var t;addEventListener('scroll',function(){clearTimeout(t);t=setTimeout(function(){send({type:'scroll',y:scrollY})},120)},{passive:true});" +
- "if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',function(){send({type:'ready'})});else send({type:'ready'});" +
- "function seen(){var b=document.body;if(!b)return false;var L=b.querySelectorAll('*'),i,e,r,c,k;" +
- "for(i=0;i<L.length&&i<1500;i++){e=L[i];if(/^(SCRIPT|STYLE|LINK|META|NOSCRIPT|TEMPLATE|BR|HEAD|TITLE)$/.test(e.tagName))continue;" +
- "r=e.getBoundingClientRect();if(r.width<2||r.height<2)continue;" +
- "if(e.checkVisibility&&!e.checkVisibility({checkOpacity:true,checkVisibilityCSS:true,opacityProperty:true,visibilityProperty:true}))continue;" +
- "c=getComputedStyle(e);if(c.visibility==='hidden'||+c.opacity<0.05)continue;" +
- "if(/^(IMG|CANVAS|SVG|VIDEO|IFRAME|INPUT|TEXTAREA|SELECT|BUTTON|OBJECT|EMBED)$/i.test(e.tagName))return true;" +
- "for(k=e.firstChild;k;k=k.nextSibling)if(k.nodeType===3&&k.nodeValue.trim())return true;" +
- "if(c.backgroundImage!=='none'||(c.backgroundColor!=='rgba(0, 0, 0, 0)'&&c.backgroundColor!=='transparent'&&c.backgroundColor!=='rgb(255, 255, 255)'))return true}" +
- "return false}" +
- "var pd=0;function pt(){if(pd)return;pd=1;setTimeout(function(){requestAnimationFrame(function(){send({type:'painted',blank:!seen()})})},500)}" +
- "addEventListener('load',pt);setTimeout(pt,4000);" +
- "})();";
-
-
- function pageHook(B) {
- function send(m) {
- m.__athera = B;
- try { parent.postMessage(m, "*"); } catch (e) { }
- }
-
- var group = 0;
- var timers = {};
- var tallies = {};
- var orig = {};
-
- function clip(s, n) {
- s = String(s);
- return s.length > n ? s.slice(0, n) + "…" : s;
- }
-
- function describe(el) {
- var s = "<" + el.tagName.toLowerCase();
- if (el.id) s += " id=\"" + el.id + "\"";
- if (el.className && typeof el.className === "string") s += " class=\"" + el.className + "\"";
- return s + ">";
- }
-
- function fmt(v, depth, seen, top) {
- try {
- var t = typeof v;
- if (t === "string") return top ? v : JSON.stringify(clip(v, 200));
- if (t === "undefined" || v === null || t === "number" || t === "boolean") return String(v);
- if (t === "bigint") return v + "n";
- if (t === "symbol") return v.toString();
- if (t === "function") return "ƒ " + (v.name || "anonymous") + "()";
- if (v instanceof Error) return clip(v.stack || (v.name + ": " + v.message), 1500);
- if (v.nodeType === 1) return describe(v);
- if (v.nodeType) return "#" + (v.nodeName || "node");
- if (v === window) return "Window";
- if (seen.indexOf(v) >= 0) return "[Circular]";
- if (v instanceof Date) return isNaN(v) ? "Invalid Date" : v.toISOString();
- if (v instanceof RegExp) return String(v);
- if (typeof Promise !== "undefined" && v instanceof Promise) return "Promise {…}";
- if (depth > 2) return Array.isArray(v) ? "[…]" : "{…}";
- seen = seen.concat([v]);
- var out = [], n = 0, i;
- if (Array.isArray(v)) {
- for (i = 0; i < v.length && i < 30; i++) out.push(fmt(v[i], depth + 1, seen, false));
- if (v.length > 30) out.push("… " + (v.length - 30) + " more");
- return "[" + out.join(", ") + "]";
- }
- if (typeof Map !== "undefined" && v instanceof Map) {
- v.forEach(function (val, key) {
- if (n++ < 30) out.push(fmt(key, depth + 1, seen, false) + " => " + fmt(val, depth + 1, seen, false));
- });
- return "Map(" + v.size + ") {" + out.join(", ") + "}";
- }
- if (typeof Set !== "undefined" && v instanceof Set) {
- v.forEach(function (val) {
- if (n++ < 30) out.push(fmt(val, depth + 1, seen, false));
- });
- return "Set(" + v.size + ") {" + out.join(", ") + "}";
- }
- var keys = Object.keys(v);
- for (i = 0; i < keys.length && i < 30; i++) out.push(keys[i] + ": " + fmt(v[keys[i]], depth + 1, seen, false));
- if (keys.length > 30) out.push("… " + (keys.length - 30) + " more");
- var name = v.constructor && v.constructor.name;
- return (name && name !== "Object" ? name + " " : "") + "{" + out.join(", ") + "}";
- } catch (e) {
- return "[?]";
- }
- }
-
- function render(list) {
- var a = [].slice.call(list), first = a[0];
- if (typeof first === "string" && a.length > 1 && /%[sdifoOjc%]/.test(first)) {
- var i = 1;
- var head = first.replace(/%([sdifoOjc%])/g, function (m, c) {
- if (c === "%") return "%";
- if (i >= a.length) return m;
- var v = a[i++];
- if (c === "c") return "";
- if (c === "d") return String(Number(v));
- if (c === "i") return String(parseInt(v, 10));
- if (c === "f") return String(parseFloat(v));
- if (c === "s") return typeof v === "string" ? v : fmt(v, 1, [], false);
- return fmt(v, 0, [], false);
- });
- return [head].concat(a.slice(i).map(function (v) { return fmt(v, 0, [], true); })).join(" ");
- }
- return a.map(function (v) { return fmt(v, 0, [], true); }).join(" ");
- }
-
- function emit(level, list, extra) {
- var m = { type: "console", level: level, text: render(list), group: group, stack: clip(new Error().stack || "", 1500) };
- if (extra) for (var k in extra) m[k] = extra[k];
- send(m);
- }
-
- function key(l) {
- return l === undefined ? "default" : String(l);
- }
-
- ["log", "info", "debug", "warn", "error", "table", "dir"].forEach(function (name) {
- orig[name] = console[name];
- console[name] = function () {
- emit(name === "table" || name === "dir" ? "log" : name, arguments);
- return orig[name] && orig[name].apply(console, arguments);
- };
- });
-
- var oAssert = console.assert;
- console.assert = function (ok) {
- if (!ok) emit("error", [].slice.call(arguments, 1), { kind: "assert" });
- return oAssert && oAssert.apply(console, arguments);
- };
-
- var oClear = console.clear;
- console.clear = function () {
- send({ type: "console-clear" });
- return oClear && oClear.apply(console, arguments);
- };
-
- ["group", "groupCollapsed"].forEach(function (name) {
- var o = console[name];
- console[name] = function () {
- if (arguments.length) emit("log", arguments);
- group++;
- return o && o.apply(console, arguments);
- };
- });
- var oEnd = console.groupEnd;
- console.groupEnd = function () {
- if (group > 0) group--;
- return oEnd && oEnd.apply(console, arguments);
- };
-
- var oTime = console.time, oTimeEnd = console.timeEnd, oTimeLog = console.timeLog, oCount = console.count;
- console.time = function (l) {
- timers[key(l)] = performance.now();
- return oTime && oTime.apply(console, arguments);
- };
- console.timeLog = function (l) {
- var k = key(l);
- if (k in timers) emit("log", [k + ": " + (performance.now() - timers[k]).toFixed(2) + " ms"]);
- return oTimeLog && oTimeLog.apply(console, arguments);
- };
- console.timeEnd = function (l) {
- var k = key(l);
- if (k in timers) {
- emit("log", [k + ": " + (performance.now() - timers[k]).toFixed(2) + " ms"]);
- delete timers[k];
- }
- return oTimeEnd && oTimeEnd.apply(console, arguments);
- };
- console.count = function (l) {
- var k = key(l);
- tallies[k] = (tallies[k] || 0) + 1;
- emit("log", [k + ": " + tallies[k]]);
- return oCount && oCount.apply(console, arguments);
- };
-
- addEventListener("error", function (e) {
- var t = e.target;
- if (t && t !== window && t.nodeType === 1) {
- send({ type: "console", level: "error", kind: "resource", url: clip(t.currentSrc || t.src || t.href || t.tagName.toLowerCase(), 200), group: 0 });
- return;
- }
- send({
- type: "console", level: "error", kind: "exception", text: e.message || "", line: e.lineno || 0, col: e.colno || 0,
- file: e.filename || "", stack: clip((e.error && e.error.stack) || "", 1500), group: 0
- });
- }, true);
-
- addEventListener("unhandledrejection", function (e) {
- var r = e.reason;
- send({
- type: "console", level: "error", kind: "exception", text: "Promise: " + ((r && r.message) || fmt(r, 0, [], true)),
- line: 0, col: 0, file: "", stack: clip((r && r.stack) || "", 1500), group: 0
- });
- });
-
- if (window.fetch) {
- var oFetch = window.fetch;
- window.fetch = function (input, init) {
- var method = String((init && init.method) || (input && input.method) || "GET").toUpperCase();
- var url = clip(typeof input === "string" ? input : (input && input.url) || String(input), 200);
- return oFetch.apply(window, arguments).then(function (res) {
- if (!res.ok) send({ type: "console", level: "warn", kind: "http", method: method, url: url, status: res.status, group: 0 });
- return res;
- }, function (err) {
- send({ type: "console", level: "error", kind: "fetch", method: method, url: url, error: String((err && err.message) || err), group: 0 });
- throw err;
- });
- };
- }
-
- if (window.XMLHttpRequest) {
- var oOpen = XMLHttpRequest.prototype.open, oSend = XMLHttpRequest.prototype.send;
- XMLHttpRequest.prototype.open = function (method, url) {
- this.__athInfo = { method: String(method).toUpperCase(), url: clip(url, 200) };
- return oOpen.apply(this, arguments);
- };
- XMLHttpRequest.prototype.send = function () {
- var x = this, info = x.__athInfo, aborted = false;
- if (info) {
- x.addEventListener("abort", function () { aborted = true; });
- x.addEventListener("loadend", function () {
- if (aborted) return;
- if (x.status >= 400) send({ type: "console", level: "warn", kind: "http", method: info.method, url: info.url, status: x.status, group: 0 });
- else if (x.status === 0) send({ type: "console", level: "error", kind: "fetch", method: info.method, url: info.url, error: "Network error", group: 0 });
- });
- }
- return oSend.apply(this, arguments);
- };
- }
-
- var ai = (function () {
- var hoverStyle = null;
- var hovered = [];
- var picking = null;
- var STYLE_KEYS = ["display", "position", "top", "left", "width", "height", "margin", "padding", "color", "background-color",
- "font-family", "font-size", "font-weight", "line-height", "text-align", "overflow", "z-index", "opacity", "visibility",
- "flex-direction", "justify-content", "align-items", "gap", "grid-template-columns", "border", "border-radius", "box-shadow"];
-
- function esc(s) {
- return window.CSS && CSS.escape ? CSS.escape(s) : String(s).replace(/[^\w-]/g, "\\$&");
- }
-
- function selectorOf(el) {
- if (!el || el.nodeType !== 1) return "";
- if (el.id && document.querySelectorAll("#" + esc(el.id)).length === 1) return "#" + esc(el.id);
- var parts = [];
- while (el && el.nodeType === 1 && el !== document.documentElement && parts.length < 5) {
- if (el.id && document.querySelectorAll("#" + esc(el.id)).length === 1) { parts.unshift("#" + esc(el.id)); break; }
- var p = el.tagName.toLowerCase();
- var cls = [].slice.call(el.classList || []).filter(function (c) { return c.indexOf("ath-") !== 0; }).slice(0, 2);
- if (cls.length) p += "." + cls.map(esc).join(".");
- var parent = el.parentElement;
- if (parent) {
- var same = [].filter.call(parent.children, function (c) { return c.tagName === el.tagName; });
- if (same.length > 1) p += ":nth-of-type(" + (same.indexOf(el) + 1) + ")";
- }
- parts.unshift(p);
- el = parent;
- }
- return parts.join(" > ");
- }
-
- function all(selector) {
- try { return [].slice.call(document.querySelectorAll(selector)); } catch (e) { throw new Error("Invalid CSS selector: " + selector); }
- }
-
- function one(selector) {
- if (!selector) throw new Error("A CSS selector is required.");
- var list = all(selector);
- if (!list.length) throw new Error("No element matches " + selector);
- return list[0];
- }
-
- function rect(el) {
- var r = el.getBoundingClientRect();
- return { x: Math.round(r.left + scrollX), y: Math.round(r.top + scrollY), w: Math.round(r.width), h: Math.round(r.height) };
- }
-
- function shown(el) {
- if (!el.isConnected) return false;
- var r = el.getBoundingClientRect();
- if (r.width < 1 || r.height < 1) return false;
- if (el.checkVisibility && !el.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true })) return false;
- var c = getComputedStyle(el);
- return c.visibility !== "hidden" && +c.opacity > 0.02;
- }
-
- function rgba(s) {
- var m = /rgba?\(([^)]+)\)/.exec(s || "");
- if (!m) return null;
- var p = m[1].split(/[\s,/]+/).filter(Boolean).map(parseFloat);
- return [p[0], p[1], p[2], p.length > 3 ? p[3] : 1];
- }
-
- function background(el) {
- while (el && el.nodeType === 1) {
- var c = getComputedStyle(el);
- if (c.backgroundImage && c.backgroundImage !== "none") return null;
- var bg = rgba(c.backgroundColor);
- if (bg && bg[3] > 0.95) return bg;
- el = el.parentElement;
- }
- return [255, 255, 255, 1];
- }
-
- function luminance(c) {
- var v = c.slice(0, 3).map(function (x) {
- x /= 255;
- return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
- });
- return 0.2126 * v[0] + 0.7152 * v[1] + 0.0722 * v[2];
- }
-
- function contrast(el) {
- var fg = rgba(getComputedStyle(el).color);
- var bg = background(el);
- if (!fg || !bg) return null;
- var a = luminance(fg) + 0.05, b = luminance(bg) + 0.05;
- return Math.round((Math.max(a, b) / Math.min(a, b)) * 100) / 100;
- }
-
- function short(v, n) {
- v = String(v == null ? "" : v);
- if (/^data:/i.test(v)) return "[inline " + v.slice(5, v.indexOf(";") > 0 ? v.indexOf(";") : 20) + "]";
- return v.length > n ? v.slice(0, n) + "…" : v;
- }
-
- function textOf(el, n) {
- return short((el.innerText || el.textContent || "").replace(/\s+/g, " ").trim(), n || 80);
- }
-
- function attrsOf(el) {
- var out = {};
- [].forEach.call(el.attributes, function (a) {
- if (/^on/i.test(a.name) || a.name === "style" && a.value.length > 200) return;
- if (/^(id|class|href|src|alt|title|type|name|value|role|for|action|method|placeholder|lang|rel|target|width|height|style|tabindex)$/.test(a.name) || /^(aria|data)-/.test(a.name)) out[a.name] = short(a.value, 160);
- });
- return out;
- }
-
- function stylesOf(el) {
- var c = getComputedStyle(el);
- var out = {};
- STYLE_KEYS.forEach(function (k) { out[k] = c.getPropertyValue(k); });
- return out;
- }
-
- function describe(el, n) {
- var r = el.getBoundingClientRect();
- var W = document.documentElement.clientWidth;
- return {
- selector: selectorOf(el),
- tag: el.tagName.toLowerCase(),
- attributes: attrsOf(el),
- text: textOf(el, n || 160),
- box: rect(el),
- visible: shown(el),
- overflowsViewport: r.right > W + 1 || r.left < -1,
- contrast: contrast(el),
- styles: stylesOf(el)
- };
- }
-
- function external(href) {
- return /^([a-z][a-z0-9+.-]*:)?\/\//i.test(href || "") || /^(javascript|mailto|tel|data|blob):/i.test(href || "");
- }
-
- function line(el, depth) {
- var s = new Array(depth + 1).join(" ") + el.tagName.toLowerCase();
- if (el.id) s += "#" + el.id;
- var cls = [].slice.call(el.classList || []).slice(0, 3);
- if (cls.length) s += "." + cls.join(".");
- ["href", "src", "alt", "type", "name", "role", "aria-label", "action", "for"].forEach(function (k) {
- if (el.hasAttribute(k)) s += " " + k + "=\"" + short(el.getAttribute(k), 50) + "\"";
- });
- if (/^(H[1-6]|A|BUTTON|LABEL|P|LI|TITLE|SUMMARY|FIGCAPTION|TH|OPTION)$/.test(el.tagName)) {
- var t = textOf(el, 70);
- if (t) s += " \"" + t + "\"";
- }
- if (!shown(el)) s += " [hidden]";
- return s;
- }
-
- function outline(max) {
- var KEEP = /^(HEADER|NAV|MAIN|FOOTER|SECTION|ARTICLE|ASIDE|FORM|FIELDSET|H1|H2|H3|H4|H5|H6|A|BUTTON|IMG|PICTURE|VIDEO|IFRAME|INPUT|SELECT|TEXTAREA|LABEL|UL|OL|TABLE|DIALOG|DETAILS|FIGURE|P)$/;
- var out = [];
- var chars = 0;
- var limit = Math.max(1000, Math.min(20000, max || 6000));
- var head = document.querySelector("meta[name=viewport]");
- out.push("title \"" + short(document.title, 80) + "\" lang=\"" + (document.documentElement.getAttribute("lang") || "") + "\" viewport-meta=" + (head ? "\"" + head.getAttribute("content") + "\"" : "missing"));
- function walk(el, depth) {
- if (chars > limit || !el || el.nodeType !== 1) return;
- if (/^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE|svg|SVG|PATH|LINK|META)$/.test(el.tagName) || el.hasAttribute("data-ath-pick")) return;
- var keep = KEEP.test(el.tagName) || el.id || el.hasAttribute("role");
- var next = depth;
- if (keep) {
- var l = line(el, depth);
- out.push(l);
- chars += l.length + 1;
- next = depth + 1;
- if (/^(P|A|BUTTON|LABEL|H[1-6])$/.test(el.tagName)) return;
- }
- for (var c = el.firstElementChild; c; c = c.nextElementSibling) walk(c, next);
- }
- walk(document.body, 0);
- if (chars > limit) out.push("[outline cut]");
- return out.join("\n");
- }
-
- function labelled(el) {
- if (el.getAttribute("aria-label") || el.getAttribute("aria-labelledby") || el.getAttribute("title")) return true;
- if (el.id && document.querySelector("label[for=\"" + esc(el.id) + "\"]")) return true;
- return !!el.closest("label");
- }
-
- function layoutCheck() {
- var W = document.documentElement.clientWidth;
- var H = innerHeight;
- var issues = [];
- function add(type, severity, detail, el) {
- if (issues.filter(function (i) { return i.type === type; }).length >= 8) return;
- var item = { type: type, severity: severity, detail: detail };
- if (el) item.selector = selectorOf(el);
- issues.push(item);
- }
- var docW = Math.max(document.documentElement.scrollWidth, document.body ? document.body.scrollWidth : 0);
- if (docW > W + 1) {
- add("horizontal_overflow", "high", "page is " + docW + "px wide in a " + W + "px viewport");
- var els = document.body ? document.body.querySelectorAll("*") : [];
- for (var i = 0; i < els.length && i < 4000; i++) {
- var e = els[i];
- if (!shown(e)) continue;
- var r = e.getBoundingClientRect();
- var pr = e.parentElement ? e.parentElement.getBoundingClientRect() : { right: 0 };
- if (r.right > W + 1 && pr.right <= W + 1 && getComputedStyle(e).position !== "fixed") add("overflow_source", "high", "right edge at " + Math.round(r.right) + "px", e);
- }
- }
- if (!document.querySelector("meta[name=viewport]")) add("missing_viewport_meta", "high", "no <meta name=\"viewport\">");
- if (!document.documentElement.getAttribute("lang")) add("missing_lang", "medium", "<html> has no lang attribute");
- if (!document.title.trim()) add("missing_title", "medium", "empty <title>");
- var h1 = document.querySelectorAll("h1").length;
- if (h1 !== 1) add("h1_count", "medium", h1 + " h1 elements");
- var last = 0;
- [].forEach.call(document.querySelectorAll("h1,h2,h3,h4,h5,h6"), function (h) {
- var lvl = +h.tagName[1];
- if (last && lvl > last + 1) add("heading_skip", "low", "h" + last + " followed by h" + lvl, h);
- last = lvl;
- });
- [].forEach.call(document.querySelectorAll("img"), function (img) {
- if (!img.hasAttribute("alt")) add("img_no_alt", "medium", short(img.getAttribute("src") || "", 60), img);
- else if (!img.getAttribute("width") && !img.getAttribute("height") && shown(img) && !img.style.aspectRatio) add("img_no_size", "low", "no width/height (layout shift)", img);
- });
- [].forEach.call(document.querySelectorAll("a[href], button, [role=button]"), function (el) {
- if (!shown(el)) return;
- var name = (el.innerText || "").trim() || el.getAttribute("aria-label") || el.getAttribute("title") || (el.querySelector("img[alt]") ? el.querySelector("img[alt]").getAttribute("alt") : "");
- if (!name.trim()) add(el.tagName === "A" ? "empty_link" : "empty_button", "medium", "no accessible name", el);
- var r = el.getBoundingClientRect();
- var inline = el.tagName === "A" && el.closest("p, li, td, dd") && getComputedStyle(el).display === "inline";
- if (!inline && (r.width < 24 || r.height < 24)) add("small_tap_target", "medium", Math.round(r.width) + "x" + Math.round(r.height) + "px", el);
- });
- [].forEach.call(document.querySelectorAll("input, select, textarea"), function (el) {
- if (/^(hidden|submit|button|reset|image)$/i.test(el.type || "")) return;
- if (!labelled(el)) add("unlabelled_field", "medium", (el.name || el.type || el.tagName.toLowerCase()), el);
- });
- var checked = 0;
- var walker = document.body ? document.body.querySelectorAll("*") : [];
- for (var j = 0; j < walker.length && checked < 400; j++) {
- var t = walker[j];
- if (/^(SCRIPT|STYLE|NOSCRIPT)$/.test(t.tagName)) continue;
- var direct = false;
- for (var k = t.firstChild; k; k = k.nextSibling) if (k.nodeType === 3 && k.nodeValue.trim()) { direct = true; break; }
- if (!direct || !shown(t)) continue;
- checked++;
- var ratio = contrast(t);
- if (ratio == null) continue;
- var cs = getComputedStyle(t);
- var large = parseFloat(cs.fontSize) >= 24 || (parseFloat(cs.fontSize) >= 18.66 && +cs.fontWeight >= 700);
- if (ratio < (large ? 3 : 4.5)) add("low_contrast", "medium", "ratio " + ratio + " (" + cs.color + " on background)", t);
- }
- [].forEach.call(document.querySelectorAll("body *"), function (el) {
- if (issues.filter(function (i) { return i.type === "offscreen"; }).length >= 5) return;
- var c = getComputedStyle(el);
- if (c.position !== "absolute" && c.position !== "fixed") return;
- var r = el.getBoundingClientRect();
- if (r.width > 4 && r.height > 4 && r.right > 0 && r.left < 0 && shown(el)) add("offscreen", "low", "partly left of the viewport", el);
- });
- return { viewport: { w: W, h: H }, documentWidth: docW, issues: issues };
- }
-
- function setValue(el, value) {
- var proto = Object.getPrototypeOf(el);
- var desc = Object.getOwnPropertyDescriptor(proto, "value");
- if (desc && desc.set) desc.set.call(el, value);
- else el.value = value;
- el.dispatchEvent(new Event("input", { bubbles: true }));
- el.dispatchEvent(new Event("change", { bubbles: true }));
- }
-
- function clearHover() {
- hovered.forEach(function (el) { el.removeAttribute("data-ath-hover"); });
- hovered = [];
- }
-
- function buildHoverStyle() {
- if (hoverStyle) return hoverStyle.count;
- var rules = [];
- function scan(list, wrap) {
- [].forEach.call(list || [], function (r) {
- if (r.selectorText && r.selectorText.indexOf(":hover") >= 0) {
- rules.push(wrap(r.selectorText.replace(/:hover/g, "[data-ath-hover]") + "{" + r.style.cssText + "}"));
- } else if (r.cssRules && r.media) {
- scan(r.cssRules, function (inner) { return wrap("@media " + r.media.mediaText + "{" + inner + "}"); });
- }
- });
- }
- [].forEach.call(document.styleSheets, function (sheet) {
- try { scan(sheet.cssRules, function (x) { return x; }); } catch (e) { }
- });
- hoverStyle = document.createElement("style");
- hoverStyle.setAttribute("data-ath-pick", "");
- hoverStyle.textContent = rules.join("\n");
- hoverStyle.count = rules.length;
- (document.head || document.documentElement).appendChild(hoverStyle);
- return rules.length;
- }
-
- function screenshot(opts) {
- return new Promise(function (resolve, reject) {
- var W = document.documentElement.clientWidth;
- var full = !!opts.fullPage;
- var docH = Math.min(Math.max(document.documentElement.scrollHeight, innerHeight), 12000);
- var H = full ? docH : innerHeight;
- var clone = document.documentElement.cloneNode(true);
- var src = document.querySelectorAll("input, textarea, select");
- var dst = clone.querySelectorAll("input, textarea, select");
- for (var i = 0; i < src.length && i < dst.length; i++) {
- var s = src[i], d = dst[i];
- if (s.tagName === "TEXTAREA") d.textContent = s.value;
- else if (s.tagName === "SELECT") [].forEach.call(d.options, function (o, j) { if (s.options[j] && s.options[j].selected) o.setAttribute("selected", ""); else o.removeAttribute("selected"); });
- else if (/^(checkbox|radio)$/i.test(s.type)) { if (s.checked) d.setAttribute("checked", ""); else d.removeAttribute("checked"); }
- else d.setAttribute("value", s.value);
- }
- var cs = document.querySelectorAll("canvas");
- var cd = clone.querySelectorAll("canvas");
- for (var c = 0; c < cs.length && c < cd.length; c++) {
- try {
- var img = document.createElement("img");
- img.src = cs[c].toDataURL();
- img.setAttribute("style", "width:" + cs[c].offsetWidth + "px;height:" + cs[c].offsetHeight + "px");
- cd[c].parentNode.replaceChild(img, cd[c]);
- } catch (e) { }
- }
- [].forEach.call(clone.querySelectorAll("script, noscript, iframe, [data-ath-pick]:not(style)"), function (n) { n.parentNode.removeChild(n); });
- var xml = new XMLSerializer().serializeToString(clone);
- var svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" + W + "\" height=\"" + H + "\"><foreignObject x=\"0\" y=\"" + (full ? 0 : -scrollY) + "\" width=\"" + W + "\" height=\"" + docH + "\">" + xml + "</foreignObject></svg>";
- var image = new Image();
- image.onload = function () {
- try {
- var scale = Math.min(1, (opts.maxWidth || 1024) / W);
- var canvas = document.createElement("canvas");
- canvas.width = Math.max(1, Math.round(W * scale));
- canvas.height = Math.max(1, Math.round(H * scale));
- var g = canvas.getContext("2d");
- var bg = getComputedStyle(document.body || document.documentElement).backgroundColor;
- g.fillStyle = !rgba(bg) || rgba(bg)[3] === 0 ? "#ffffff" : bg;
- g.fillRect(0, 0, canvas.width, canvas.height);
- g.drawImage(image, 0, 0, canvas.width, canvas.height);
- var url = canvas.toDataURL("image/png");
- var mime = "image/png";
- if (url.length > 1800000) { url = canvas.toDataURL("image/jpeg", 0.82); mime = "image/jpeg"; }
- resolve({ mime: mime, data: url.slice(url.indexOf(",") + 1), width: canvas.width, height: canvas.height, scale: Math.round(scale * 100) / 100 });
- } catch (e) {
- reject(new Error("Screenshot failed: " + e.message));
- }
- };
- image.onerror = function () { reject(new Error("Screenshot failed: the page could not be rendered.")); };
- image.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg);
- });
- }
-
- function info(el) {
- var d = describe(el, 300);
- d.outerHTML = short(el.outerHTML.replace(/data:[^"')\s]{40,}/g, "[inline]"), 3000);
- d.classes = [].slice.call(el.classList || []);
- d.id = el.id || "";
- return d;
- }
-
- function pick() {
- if (picking) return { picking: true };
- var boxEl = document.createElement("div");
- boxEl.setAttribute("data-ath-pick", "");
- boxEl.style.cssText = "position:fixed;pointer-events:none;z-index:2147483647;border:2px solid #2563eb;background:rgba(37,99,235,.12);border-radius:3px;left:0;top:0;width:0;height:0";
- var tip = document.createElement("div");
- tip.setAttribute("data-ath-pick", "");
- tip.style.cssText = "position:fixed;pointer-events:none;z-index:2147483647;font:12px/1.4 system-ui,sans-serif;background:#1e293b;color:#fff;padding:2px 6px;border-radius:4px;max-width:80vw;white-space:nowrap;overflow:hidden;text-overflow:ellipsis";
- document.documentElement.appendChild(boxEl);
- document.documentElement.appendChild(tip);
- var target = null;
- function move(e) {
- var el = e.target;
- if (!el || el.nodeType !== 1 || el.hasAttribute("data-ath-pick")) return;
- target = el;
- var r = el.getBoundingClientRect();
- boxEl.style.left = r.left + "px";
- boxEl.style.top = r.top + "px";
- boxEl.style.width = r.width + "px";
- boxEl.style.height = r.height + "px";
- tip.textContent = selectorOf(el) + " " + Math.round(r.width) + "×" + Math.round(r.height);
- tip.style.left = Math.max(0, r.left) + "px";
- tip.style.top = (r.top > 24 ? r.top - 22 : r.bottom + 4) + "px";
- }
- function block(e) {
- e.preventDefault();
- e.stopPropagation();
- e.stopImmediatePropagation();
- }
- function click(e) {
- block(e);
- var el = e.target && e.target.nodeType === 1 ? e.target : target;
- stop();
- send({ type: "ai-picked", info: el ? info(el) : null });
- }
- function key(e) {
- if (e.key !== "Escape") return;
- block(e);
- stop();
- send({ type: "ai-picked", info: null });
- }
- function stop() {
- removeEventListener("mousemove", move, true);
- removeEventListener("click", click, true);
- removeEventListener("mousedown", block, true);
- removeEventListener("pointerdown", block, true);
- removeEventListener("mouseup", block, true);
- removeEventListener("keydown", key, true);
- if (boxEl.parentNode) boxEl.parentNode.removeChild(boxEl);
- if (tip.parentNode) tip.parentNode.removeChild(tip);
- picking = null;
- }
- addEventListener("mousemove", move, true);
- addEventListener("click", click, true);
- addEventListener("mousedown", block, true);
- addEventListener("pointerdown", block, true);
- addEventListener("mouseup", block, true);
- addEventListener("keydown", key, true);
- picking = { stop: stop };
- return { picking: true };
- }
-
- function act(action, a) {
- var el;
- switch (action) {
- case "state":
- return {
- title: document.title,
- lang: document.documentElement.getAttribute("lang") || "",
- viewport: { w: document.documentElement.clientWidth, h: innerHeight },
- scroll: { x: Math.round(scrollX), y: Math.round(scrollY), max: Math.max(0, document.documentElement.scrollHeight - innerHeight) },
- documentHeight: document.documentElement.scrollHeight,
- readyState: document.readyState,
- focused: document.activeElement && document.activeElement !== document.body ? selectorOf(document.activeElement) : "",
- hovered: hovered.length ? selectorOf(hovered[0]) : ""
- };
- case "outline":
- return outline(a.max);
- case "inspect":
- var list = all(a.selector);
- return { count: list.length, items: list.slice(0, Math.max(1, Math.min(10, a.max || 5))).map(function (x) { return describe(x); }) };
- case "layout_check":
- return layoutCheck();
- case "screenshot":
- return screenshot(a);
- case "scroll":
- if (a.selector) one(a.selector).scrollIntoView({ block: "center" });
- else scrollTo(0, Math.max(0, +a.y || 0));
- return { y: Math.round(scrollY) };
- case "click":
- el = one(a.selector);
- var link = el.closest("a[href]");
- if (link && external(link.getAttribute("href"))) throw new Error("Refused: the link leads outside the project (" + short(link.getAttribute("href"), 80) + ").");
- var form = el.closest("form");
- if (form && /^(submit|image)$/i.test(el.type || (el.tagName === "BUTTON" ? "submit" : "")) && external(form.getAttribute("action"))) throw new Error("Refused: the form is sent outside the project.");
- el.scrollIntoView({ block: "center" });
- el.click();
- return { clicked: selectorOf(el), tag: el.tagName.toLowerCase(), navigates: !!link || !!form };
- case "type":
- el = one(a.selector);
- el.focus();
- if (el.isContentEditable) {
- el.textContent = String(a.text == null ? "" : a.text);
- el.dispatchEvent(new Event("input", { bubbles: true }));
- } else if ("value" in el) {
- setValue(el, (a.append ? el.value : "") + String(a.text == null ? "" : a.text));
- } else {
- throw new Error("The element cannot receive text.");
- }
- return { typed: selectorOf(el), value: short(el.value != null ? el.value : el.textContent, 120) };
- case "select":
- el = one(a.selector);
- if (el.tagName !== "SELECT") throw new Error("The element is not a <select>.");
- var opt = [].find.call(el.options, function (o) { return o.value === String(a.value); }) || [].find.call(el.options, function (o) { return o.text.trim() === String(a.value).trim(); });
- if (!opt) throw new Error("No option with value or label " + a.value);
- setValue(el, opt.value);
- return { selected: opt.value, label: opt.text };
- case "hover":
- clearHover();
- if (!a.selector) return { hovered: "" };
- el = one(a.selector);
- var rules = buildHoverStyle();
- for (var n = el; n && n.nodeType === 1; n = n.parentElement) {
- n.setAttribute("data-ath-hover", "");
- hovered.push(n);
- }
- ["pointerover", "pointerenter", "mouseover", "mouseenter", "mousemove"].forEach(function (type) {
- el.dispatchEvent(new MouseEvent(type, { bubbles: type.indexOf("enter") < 0, cancelable: true }));
- });
- return { hovered: selectorOf(el), simulatedHoverRules: rules };
- case "focus":
- el = one(a.selector);
- el.focus();
- return { focused: selectorOf(el), active: document.activeElement === el };
- case "pick":
- return pick();
- case "pick_cancel":
- if (picking) picking.stop();
- return { picking: false };
- default:
- throw new Error("Unknown action " + action);
- }
- }
-
- return { act: act };
- })();
-
- addEventListener("message", function (e) {
- var d = e.data;
- if (e.source !== parent || !d || d.__athera !== B || d.type !== "ai") return;
- Promise.resolve().then(function () { return ai.act(String(d.action), d.args || {}); }).then(function (result) {
- send({ type: "ai-result", id: d.id, ok: true, result: result });
- }, function (err) {
- send({ type: "ai-result", id: d.id, ok: false, error: String((err && err.message) || err) });
- });
- });
-
- addEventListener("message", function (e) {
- var d = e.data;
- if (e.source !== parent || !d || d.__athera !== B || d.type !== "eval") return;
- try {
- var r = (0, eval)(d.code);
- send({ type: "console", level: "result", text: fmt(r, 0, [], false), group: 0 });
- } catch (err) {
- send({ type: "console", level: "error", kind: "eval", text: err && err.message ? (err.name || "Error") + ": " + err.message : String(err), group: 0 });
- }
- });
- }
-
- var FRAME = /(athera-src\/[^\s:()]+|[^\s()@]+):(\d+):(\d+)\)?\s*$/;
- var PHP_ERR = /<b>(Warning|Notice|Deprecated|Fatal error|Parse error|Strict Standards|Recoverable fatal error)<\/b>:\s+([\s\S]*?) in <b>([^<]+)<\/b> on line <b>(\d+)<\/b>/g;
- var PHP_LOG = /^PHP (Warning|Notice|Deprecated|Fatal error|Parse error|Strict Standards|Recoverable fatal error):\s+([\s\S]*?) in (\S+) on line (\d+)/;
-
- var DEVICES = [
- { group: "preview.device_mobile", items: [
- ["iPhone SE", 375, 667, "iphone", 2], ["iPhone 16", 393, 852, "iphone", 3], ["iPhone 16 Pro Max", 440, 956, "iphone", 3],
- ["Pixel 9", 412, 915, "android", 2.625, "Pixel 9"], ["Pixel 9 Pro", 412, 915, "android", 2.625, "Pixel 9 Pro"],
- ["Pixel 10", 412, 915, "android", 2.625, "Pixel 10"], ["Samsung Galaxy A55", 412, 892, "android", 2.625, "SM-A556B"]
- ] },
- { group: "preview.device_foldables", items: [
- ["Pixel 9 Pro Fold", 791, 820, "android", 2.625, "Pixel 9 Pro Fold"], ["Galaxy Z Fold 6", 773, 900, "android", 2.4, "SM-F956B"]
- ] },
- { group: "preview.device_tablets", items: [
- ["iPad Mini", 744, 1133, "ipad", 2], ["iPad Pro 13", 1032, 1376, "ipad", 2], ["Surface Pro 10", 912, 1368, "windows", 2]
- ] },
- { group: "preview.device_displays", items: [
- ["Nest Hub Max", 1280, 800, "hub", 1]
- ] }
- ];
-
- var CHROME = "Chrome/130.0.0.0";
-
- function profileOf(d) {
- if (!d) return null;
- var kind = d[3], model = d[5] || "";
- if (kind === "iphone") {
- return { ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1",
- platform: "iPhone", vendor: "Apple Computer, Inc.", touch: 5, dpr: d[4], ch: false, mobile: true, os: "iOS" };
- }
- if (kind === "ipad") {
- return { ua: "Mozilla/5.0 (iPad; CPU OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1",
- platform: "iPad", vendor: "Apple Computer, Inc.", touch: 5, dpr: d[4], ch: false, mobile: false, os: "iOS" };
- }
- if (kind === "android") {
- return { ua: "Mozilla/5.0 (Linux; Android 15; " + model + ") AppleWebKit/537.36 (KHTML, like Gecko) " + CHROME + " Mobile Safari/537.36",
- platform: "Linux armv81", vendor: "Google Inc.", touch: 5, dpr: d[4], ch: true, mobile: true, os: "Android" };
- }
- if (kind === "windows") {
- return { ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + CHROME + " Safari/537.36",
- platform: "Win32", vendor: "Google Inc.", touch: 10, dpr: d[4], ch: true, mobile: false, os: "Windows" };
- }
- return { ua: "Mozilla/5.0 (Linux; Android 12; Nest Hub Max) AppleWebKit/537.36 (KHTML, like Gecko) " + CHROME + " Safari/537.36 CrKey/1.56.500000",
- platform: "Linux armv8l", vendor: "Google Inc.", touch: 10, dpr: d[4], ch: true, mobile: false, os: "Android" };
- }
-
- function profileScript(p) {
- var json = JSON.stringify(p).replace(/</g, "\\u003c");
- return "(function(p){function d(o,k,v){try{Object.defineProperty(o,k,{get:function(){return v},configurable:true})}catch(e){}}" +
- "d(navigator,'userAgent',p.ua);d(navigator,'appVersion',p.ua.replace(/^Mozilla\\//,''));d(navigator,'platform',p.platform);" +
- "d(navigator,'vendor',p.vendor);d(navigator,'maxTouchPoints',p.touch);" +
- "d(navigator,'userAgentData',p.ch?{mobile:p.mobile,platform:p.os,brands:[{brand:'Chromium',version:'130'}],getHighEntropyValues:function(){return Promise.resolve({})}}:undefined);" +
- "d(window,'devicePixelRatio',p.dpr);if(p.touch&&!('ontouchstart' in window))d(window,'ontouchstart',null);" +
- "})(" + json + ");\n";
- }
-
- var deviceName = A.store.get("previewDevice", null);
- var override = null;
- var ready = { id: 0, ready: false };
- var rotated = !!A.store.get("previewRotated", false);
- var deviceBox = null;
- var deviceLabel = null;
- var deviceBtn = null;
-
- function findDevice(name) {
- for (var g = 0; g < DEVICES.length; g++) {
- for (var i = 0; i < DEVICES[g].items.length; i++) {
- if (DEVICES[g].items[i][0] === name) return DEVICES[g].items[i];
- }
- }
- return null;
- }
-
- function deviceSize() {
- if (override) return { w: override.w, h: override.h, name: override.name };
- var d = findDevice(deviceName);
- if (!d) return null;
- return rotated ? { w: d[2], h: d[1], name: d[0] } : { w: d[1], h: d[2], name: d[0] };
- }
-
- function fitDevice() {
- var size = deviceSize();
- if (!size || !deviceBox) return;
- var box = deviceBox.getBoundingClientRect();
- if (box.width < 40 || box.height < 40) return;
- var s = Math.min(1, (box.width - 24) / size.w, (box.height - 44) / size.h);
- s = Math.max(0.1, s);
- pv.frame.style.setProperty("--ath-device-scale", s.toFixed(4));
- deviceLabel.textContent = size.name + " · " + size.w + " × " + size.h + (s < 1 ? " · " + Math.round(s * 100) + "%" : "");
- }
-
- function applyDevice() {
- var size = deviceSize();
- deviceBox.classList.toggle("is-device", !!size);
- deviceLabel.hidden = !size;
- deviceBtn.classList.toggle("is-active", !!size);
- if (size) {
- pv.frame.style.width = size.w + "px";
- pv.frame.style.height = size.h + "px";
- fitDevice();
- } else {
- pv.frame.style.width = "";
- pv.frame.style.height = "";
- pv.frame.style.removeProperty("--ath-device-scale");
- }
- renderDeviceMenu();
- }
-
- function pickDevice(name) {
- deviceName = name;
- override = null;
- A.store.set("previewDevice", name);
- applyDevice();
- A.emit("preview-viewport", { by: "user", size: deviceSize() });
- if (pv.open) pv.build();
- }
-
- function renderDeviceMenu() {
- var menu = document.getElementById("device-menu");
- if (!menu) return;
- menu.innerHTML = "";
-
- var list = util.el("div", { class: "ath-device-list" });
- menu.appendChild(list);
-
- function item(label, active, size, onClick, icon, target, disabled) {
- var node = util.el("button", {
- type: "button",
- class: "orb-dropdown-item ath-device-item" + (active ? " is-current" : ""),
- role: "menuitemradio",
- "aria-checked": active ? "true" : "false",
- disabled: disabled ? true : null,
- html: (active ? A.icon("check") : icon ? A.icon(icon) : '<span class="ath-device-ph"></span>') +
- "<span>" + util.esc(label) + "</span>" + (size ? '<span class="ath-device-size">' + util.esc(size) + "</span>" : "")
- });
- node.addEventListener("click", onClick);
- (target || list).appendChild(node);
- }
-
- item(A.t("preview.device_default"), !deviceName, "", function () { pickDevice(null); });
- DEVICES.forEach(function (g) {
- list.appendChild(util.el("div", { class: "ath-accent-label" }, A.t(g.group)));
- g.items.forEach(function (d) {
- item(d[0], d[0] === deviceName, d[1] + " × " + d[2], function () { pickDevice(d[0]); });
- });
- });
- menu.appendChild(util.el("div", { class: "orb-dropdown-divider" }));
- item(A.t("preview.device_rotate"), false, "", function () {
- rotated = !rotated;
- A.store.set("previewRotated", rotated);
- applyDevice();
- A.emit("preview-viewport", { by: "user", size: deviceSize() });
- }, "redo", menu, !deviceName);
- }
-
- var RETRY_DELAYS = [2000, 5000, 10000];
- var READY_WAIT = 5000;
- var retry = { n: 0, timer: 0, wait: 0, ok: false, problem: false, expect: false, kind: "" };
- var lastFailure = null;
-
- function stopRetry() {
- clearTimeout(retry.timer);
- clearTimeout(retry.wait);
- retry.timer = 0;
- retry.wait = 0;
- }
-
- function isBlankHtml(html) {
- var h = String(html || "").replace(/<style[\s\S]*?<\/style>/gi, "");
- var text = h.replace(/<[^>]*>/g, "").replace(/ |\s/g, "");
- return !text && !/<(img|canvas|svg|video|audio|iframe|input|object|embed|textarea|select|button|script)\b/i.test(h);
- }
-
- function scheduleRetry(kind, tab, text) {
- stopRetry();
- retry.kind = kind;
- if (retry.n >= RETRY_DELAYS.length) {
- showLoading(false);
- if (kind === "paint") A.console.add({ level: "warn", text: text, source: "js", group: 0 });
- if (kind !== "php" && kind !== "paint") {
- pv.frame.hidden = false;
- pv.frame.srcdoc = messagePage(A.t("preview.failed_title"), text + "\n\n" + A.t("preview.failed_hint"));
- }
- return;
- }
- var ms = RETRY_DELAYS[retry.n];
- showLoading(true, A.t("preview.retrying", { s: ms / 1000, n: retry.n + 1, total: RETRY_DELAYS.length }));
- retry.timer = setTimeout(function () {
- retry.timer = 0;
- showLoading(false);
- if (!pv.open || pv.target !== tab || (retry.ok && kind !== "paint")) return;
- retry.n++;
- if (kind === "php" && retry.n >= 2 && A.php) A.php.restart();
- pv.buildOnce();
- }, ms);
- }
-
- var extraErrors = [];
- var phpFound = [];
- var phpUsed = false;
-
- var pv = (A.preview = {
- open: false,
- target: null,
- scroll: {},
- routes: {},
- pathRoutes: {},
- errors: [],
- scripts: [],
- lastHtml: "",
-
- init: function (pane) {
- pv.pane = pane;
- pv.frame = pane.querySelector("iframe");
- pv.titleEl = pane.querySelector("[data-preview-title]");
- pv.statusEl = pane.querySelector("[data-preview-status]");
- pv.emptyEl = pane.querySelector("[data-preview-empty]");
-
- pv.loadingEl = util.el("div", { class: "ath-preview-loading", hidden: true }, [
- util.el("span", { class: "ath-spinner" }),
- util.el("span", {}, "")
- ]);
- deviceBox = pane.querySelector(".ath-preview-body");
- deviceBox.appendChild(pv.loadingEl);
- deviceLabel = util.el("div", { class: "ath-device-label", hidden: true });
- deviceBox.appendChild(deviceLabel);
- deviceBtn = pane.querySelector("[data-preview-device]");
- if (!findDevice(deviceName)) deviceName = null;
- applyDevice();
- if (window.ResizeObserver) new ResizeObserver(fitDevice).observe(deviceBox);
- A.on("lang", renderDeviceMenu);
- A.console.init(pane.querySelector("[data-console]"), { jump: jumpTo, evaluate: evalInPage });
- pane.querySelector("[data-preview-refresh]").addEventListener("click", function () {
- dataCache.clear();
- if (A.php) A.php.rescan();
- if (pv.target && pv.routes[pv.target.id]) pv.routes[pv.target.id] = { query: pv.routes[pv.target.id].query || "" };
- pv.build();
- });
- A.on("settings", function (keys) { if (pv.open && (keys.indexOf("phpRuntime") >= 0 || keys.indexOf("mysqlEmulation") >= 0)) pv.build(); });
- pane.querySelector("[data-preview-window]").addEventListener("click", pv.openWindow);
- pv.statusEl.addEventListener("click", function () { A.console.setOpen(true); });
-
- var later = util.debounce(function () { pv.build(); }, 350);
- A.on("doc-change", function () { if (pv.open && pv.target && A.settings.get("livePreview")) later(); });
- A.on("saved", function () { if (pv.open) later(); });
- A.on("active-change", function (tab) {
- if (tab && pv.canPreview(tab.name)) pv.target = tab;
- if (pv.target && A.tabs.list.indexOf(pv.target) < 0) pv.target = null;
- if (pv.open) pv.build();
- });
- A.on("workspace", function () { dataCache.clear(); });
- A.on("lang", function () { if (pv.open) pv.build(); });
- window.addEventListener("message", onMessage);
- },
-
- userAgent: function () {
- var prof = profileOf(findDevice(deviceName));
- return prof ? prof.ua : "";
- },
-
- canPreview: function (name) {
- return PREVIEWABLE.indexOf(util.ext(name)) >= 0;
- },
-
- setOpen: function (open) {
- pv.open = open;
- document.body.classList.toggle("ath-no-preview", !open);
- A.store.set("preview", open);
- if (open) {
- var t = A.tabs.active;
- if (t && pv.canPreview(t.name)) pv.target = t;
- pv.build();
- } else {
- stopRetry();
- showLoading(false);
- pv.frame.removeAttribute("srcdoc");
- pv.frame.hidden = true;
- }
- A.emit("preview-toggle", open);
- },
-
- toggle: function () {
- pv.setOpen(!pv.open);
- },
-
- build: function () {
- stopRetry();
- retry.n = 0;
- showLoading(false);
- return pv.buildOnce();
- },
-
- buildOnce: async function () {
- var id = ++buildId;
- retry.ok = false;
- retry.problem = false;
- clearTimeout(retry.wait);
- var tab = pv.target;
- if (tab && A.tabs.list.indexOf(tab) < 0) tab = pv.target = null;
- if (!tab) {
- stopRetry();
- showLoading(false);
- pv.errors = [];
- pv.scripts = [];
- A.console.reset();
- A.console.setVisible(false);
- renderStatus();
- pv.titleEl.textContent = A.t("preview.title");
- pv.emptyEl.hidden = false;
- pv.frame.hidden = true;
- pv.lastHtml = "";
- return;
- }
- var html = null, problem = null;
- try {
- html = await render(tab);
- } catch (e) {
- problem = { kind: "error", text: (e && e.message) || String(e) };
- html = messagePage(A.t("preview.failed_title"), problem.text);
- }
- if (id !== buildId || html == null) return;
- if (!problem && lastFailure) problem = { kind: "php", text: lastFailure };
- if (!problem && phpUsed && isBlankHtml(html)) problem = { kind: "blank", text: A.t("preview.blank") };
- retry.problem = !!problem;
- retry.expect = !problem && !isBlankHtml(html);
- pv.errors = extraErrors.slice();
- var gone = [];
- missing.forEach(function (p) {
- var text = A.t("preview.missing", { path: p });
- pv.errors.push(text);
- gone.push({ level: "error", text: text, source: "js", group: 0 });
- });
- renderStatus();
- var route = pv.routes[tab.id];
- pv.titleEl.textContent = tab.name + (phpUsed && route && route.query ? "?" + route.query : "");
- if (phpUsed && A.php.version) pv.titleEl.setAttribute("data-badge", "PHP " + A.php.version.split(".").slice(0, 2).join("."));
- else pv.titleEl.removeAttribute("data-badge");
- pv.emptyEl.hidden = true;
- pv.frame.hidden = false;
- pv.lastHtml = html;
- var doc = injectHelper(html, Math.round(pv.scroll[tab.id] || 0), id);
- pv.scripts = scanScripts(doc);
- A.console.reset();
- A.console.setVisible(true);
- A.console.addMany(phpFound.concat(gone));
- if (retry.n > 0) {
- pv.frame.hidden = true;
- void pv.frame.offsetWidth;
- pv.frame.hidden = false;
- }
- pv.frame.srcdoc = doc;
- ready = { id: id, ready: false };
- A.emit("preview-build", { id: id, target: tab.path != null ? tab.path : tab.name });
- if (problem) {
- scheduleRetry(problem.kind, tab, problem.text);
- } else {
- retry.wait = setTimeout(function () {
- if (id === buildId && !retry.ok) scheduleRetry("load", tab, A.t("preview.not_ready"));
- }, READY_WAIT);
- }
- },
-
- buildId: function () {
- return buildId;
- },
-
- status: function () {
- return { id: ready.id, ready: ready.ready && ready.id === buildId, building: ready.id !== buildId, target: pv.target ? (pv.target.path != null ? pv.target.path : pv.target.name) : null, route: pv.target ? pv.routes[pv.target.id] || null : null, open: pv.open };
- },
-
- missing: function () {
- return Array.from(missing);
- },
-
- post: function (msg) {
- if (!pv.frame || pv.frame.hidden || !pv.frame.contentWindow) return false;
- pv.frame.contentWindow.postMessage(Object.assign({}, msg, { __athera: buildId }), "*");
- return true;
- },
-
- frameSize: function () {
- var size = deviceSize();
- if (size) return { w: size.w, h: size.h, name: size.name, device: true };
- var r = pv.frame ? pv.frame.getBoundingClientRect() : { width: 0, height: 0 };
- return { w: Math.round(r.width), h: Math.round(r.height), name: "", device: false };
- },
-
- setViewport: function (w, h, name) {
- override = { w: Math.round(w), h: Math.round(h), name: name || "" };
- applyDevice();
- A.emit("preview-viewport", { by: "ai", size: deviceSize() });
- return deviceSize();
- },
-
- clearViewport: function () {
- if (!override) return;
- override = null;
- applyDevice();
- A.emit("preview-viewport", { by: "ai", size: deviceSize() });
- },
-
- hasViewportOverride: function () {
- return !!override;
- },
-
- openRoute: async function (path, query, method, body) {
- var route = { query: query || "", method: method || "GET", body: body || "" };
- if (!pv.open) pv.setOpen(true);
- var tab = A.tabs.byPath(path);
- if (tab && tab === pv.target) {
- pv.routes[tab.id] = route;
- return pv.build();
- }
- pv.pathRoutes[path] = route;
- tab = await A.tabs.openPath(path, { focusEditor: false });
- if (tab && pv.target !== tab && pv.canPreview(tab.name)) {
- pv.target = tab;
- pv.build();
- }
- return tab;
- },
-
- openWindow: function () {
- if (!pv.lastHtml) return;
- var url = URL.createObjectURL(new Blob([pv.lastHtml], { type: "text/html" }));
- window.open(url, "_blank");
- setTimeout(function () { URL.revokeObjectURL(url); }, 60000);
- }
- });
-
- function header(headers, name) {
- var v = headers && headers[name];
- return v ? [].concat(v)[0] : "";
- }
-
- function scriptDir(tab) {
- return tab.path != null ? util.dirname(tab.path) : "";
- }
-
- function showLoading(on, text) {
- pv.loadingEl.hidden = !on;
- pv.loadingEl.lastChild.textContent = text || A.t("php.loading");
- }
-
- function messagePage(title, text) {
- return "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><style>body{font:14px/1.6 system-ui,sans-serif;margin:0;padding:32px;color:#0f172a}" +
- "h1{font-size:18px;margin:0 0 8px}pre{white-space:pre-wrap;background:#f1f5f9;padding:12px;border-radius:8px;font-size:12.5px}</style></head><body>" +
- "<h1>" + util.esc(title) + "</h1>" + (text ? "<pre>" + util.esc(text) + "</pre>" : "") + "</body></html>";
- }
-
- function usesPhpRuntime(tab) {
- return /^(php|phtml)$/.test(util.ext(tab.name)) && A.settings.get("phpRuntime");
- }
-
- async function runPhp(tab, depth) {
- if (tab.path != null && pv.pathRoutes[tab.path]) {
- pv.routes[tab.id] = pv.pathRoutes[tab.path];
- delete pv.pathRoutes[tab.path];
- }
- var route = pv.routes[tab.id] || {};
- if (!A.php.isReady()) showLoading(true);
- var res;
- try {
- res = await A.php.run(tab, route, function (done, total) {
- showLoading(true, A.t("php.syncing", { done: done, total: total }));
- });
- } catch (e) {
- showLoading(false);
- lastFailure = e.message;
- return messagePage(A.t("php.failed_title"), e.message);
- }
- showLoading(false);
- if (route.method === "POST") pv.routes[tab.id] = { query: route.query || "" };
- phpFound = phpDiagnostics(res);
- phpFound.forEach(function (e) {
- if (e.level === "error") extraErrors.push("PHP: " + e.text + (e.label ? " (" + e.label + ")" : ""));
- });
- var location = header(res.headers, "location");
- if (res.status >= 300 && res.status < 400 && location) {
- if (/^([a-z]+:)?\/\//i.test(location)) return messagePage(A.t("php.redirect_external", { url: location }), "");
- if ((depth || 0) >= 5) return messagePage(A.t("php.redirect_loop"), location);
- var moved = navigate(tab, location, "GET", "", true);
- if (moved === "same") return runPhp(tab, (depth || 0) + 1);
- return moved === "other" ? null : messagePage(A.t("php.redirect_missing", { url: location }), "");
- }
- var type = header(res.headers, "content-type");
- if (type && !/html/i.test(type)) {
- return "<!DOCTYPE html><html><head><meta charset=\"utf-8\"></head><body><pre style=\"white-space:pre-wrap;font:12.5px/1.5 monospace;margin:16px\">" +
- util.esc(res.html) + "</pre></body></html>";
- }
- return res.html;
- }
-
- function navigate(fromTab, href, method, body, internal) {
- var clean = href.split("#")[0];
- var qi = clean.indexOf("?");
- var pathPart = qi >= 0 ? clean.slice(0, qi) : clean;
- var query = qi >= 0 ? clean.slice(qi + 1) : "";
- var target = pathPart ? util.resolve(scriptDir(fromTab), pathPart) : fromTab.path;
- var route = { query: query, method: method || "GET", body: body || "" };
- if (!pathPart || target === fromTab.path) {
- pv.routes[fromTab.id] = route;
- if (!internal) pv.build();
- return "same";
- }
- if (!target || !pv.canPreview(target) || !fs.provider) return "none";
- pv.pathRoutes[target] = route;
- fs.provider.exists(target).then(function (ok) {
- if (ok) A.tabs.openPath(target);
- else A.ui.toast(A.t("preview.page_not_found", { path: target }), "warning");
- });
- return "other";
- }
-
- async function render(tab) {
- var src = A.tabs.textOf(tab);
- var ext = util.ext(tab.name);
- missing.clear();
- lastFailure = null;
- extraErrors = [];
- phpFound = [];
- phpUsed = false;
- if (usesPhpRuntime(tab)) {
- phpUsed = true;
- src = await runPhp(tab, 0);
- if (src == null) return null;
- } else if (ext === "php" || ext === "phtml") {
- src = stripPhp(src);
- }
- if (ext === "svg") return src;
- var hasDoctype = /^\s*<!doctype/i.test(src);
- var doc = new DOMParser().parseFromString(src, "text/html");
- if (tab.path != null && fs.provider) {
- try { await inlineAssets(doc, util.dirname(tab.path)); } catch (e) { console.warn(e); }
- }
- return (hasDoctype ? "<!DOCTYPE html>\n" : "") + doc.documentElement.outerHTML;
- }
-
- function injectHelper(html, y, id) {
- var prof = profileOf(findDevice(deviceName));
- var tag = "<script>" + (prof ? profileScript(prof) : "") + HELPER.replace("__Y__", String(y)).replace("__B__", String(id)) +
- "\n(" + pageHook.toString() + ")(" + id + ");\n//# sourceURL=athera-hook</script>";
- var m = /<head(\s[^>]*)?>/i.exec(html);
- if (m) return html.slice(0, m.index + m[0].length) + tag + html.slice(m.index + m[0].length);
- return tag + html;
- }
-
- function stripPhp(src) {
- var vars = {};
- var STR = /^\s*(["'])((?:\\.|(?!\1)[^\\])*)\1\s*;?\s*$/;
- function unquote(s) { return s.replace(/\\(.)/g, "$1"); }
- function echo(expr) {
- var v = /^\s*(htmlspecialchars\s*\(\s*)?\$(\w+)\s*\)?\s*;?\s*$/.exec(expr);
- if (v && Object.prototype.hasOwnProperty.call(vars, v[2])) return v[1] ? util.esc(vars[v[2]]) : vars[v[2]];
- var s = STR.exec(expr);
- return s ? unquote(s[2]) : "⟨php⟩";
- }
- return src.replace(/<\?(=|php\b)?([\s\S]*?)(\?>|$)/gi, function (all, kind, code) {
- if (kind === "=") return echo(code);
- code.replace(/\$(\w+)\s*=\s*(["'])((?:\\.|(?!\2)[^\\])*)\2\s*;/g, function (m, name, q, val) {
- vars[name] = unquote(val);
- });
- var e = /^\s*echo\s+([\s\S]*?)\s*$/i.exec(code);
- return e ? echo(e[1]) : "";
- });
- }
-
- async function readText(path) {
- var live = A.tabs.contentOf(path);
- if (live != null) return live;
- try { return await fs.provider.readText(path); } catch (e) { missing.add(path); return null; }
- }
-
- async function dataUrl(path) {
- var live = A.tabs.contentOf(path);
- if (live != null) return "data:" + fs.mime(path) + ";charset=utf-8," + encodeURIComponent(live);
- var file;
- try { file = await fs.provider.readFile(path); } catch (e) { missing.add(path); return null; }
- var stamp = file.lastModified + ":" + file.size;
- var hit = dataCache.get(path);
- if (hit && hit.stamp === stamp) return hit.url;
- var url = await new Promise(function (resolve) {
- var r = new FileReader();
- r.onload = function () { resolve(r.result); };
- r.onerror = function () { resolve(null); };
- r.readAsDataURL(new Blob([file], { type: fs.mime(path) }));
- });
- if (url) dataCache.set(path, { stamp: stamp, url: url });
- return url;
- }
-
- async function rewriteCss(css, baseDir) {
- var re = /url\(\s*(['"]?)([^'")]+)\1\s*\)/gi, m, jobs = [];
- while ((m = re.exec(css))) {
- var p = util.resolve(baseDir, m[2]);
- if (p && !/^data:/i.test(m[2].trim())) jobs.push({ text: m[0], path: p });
- }
- for (var j of jobs) {
- var url = (await dataUrl(j.path)) || "data:,";
- css = css.split(j.text).join('url("' + url + '")');
- }
- return css;
- }
-
- async function rewriteSrcset(value, dir) {
- var parts = value.split(",");
- for (var i = 0; i < parts.length; i++) {
- var bits = parts[i].trim().split(/\s+/);
- var p = util.resolve(dir, bits[0]);
- if (p) bits[0] = (await dataUrl(p)) || "data:,";
- parts[i] = bits.join(" ");
- }
- return parts.join(", ");
- }
-
- async function inlineAssets(doc, dir) {
- for (var link of doc.querySelectorAll('link[rel~="stylesheet"][href]')) {
- var cssPath = util.resolve(dir, link.getAttribute("href"));
- if (!cssPath) continue;
- var css = await readText(cssPath);
- if (css == null) { link.removeAttribute("href"); continue; }
- var style = doc.createElement("style");
- if (link.media) style.media = link.media;
- style.setAttribute("data-ath-href", link.getAttribute("href"));
- style.textContent = await rewriteCss(css, util.dirname(cssPath));
- link.replaceWith(style);
- }
-
- for (var script of doc.querySelectorAll("script[src]")) {
- var jsPath = util.resolve(dir, script.getAttribute("src"));
- if (!jsPath) continue;
- var js = await readText(jsPath);
- if (js == null) { script.removeAttribute("src"); continue; }
- var s = doc.createElement("script");
- for (var attr of script.attributes) if (attr.name !== "src") s.setAttribute(attr.name, attr.value);
- s.setAttribute("data-ath-src", script.getAttribute("src"));
- s.setAttribute("data-ath-path", jsPath);
- s.textContent = js.replace(/<\/script/gi, "<\\/script") + (isJsType(script.getAttribute("type")) ? "\n//# sourceURL=" + sourceName(jsPath) : "");
- script.replaceWith(s);
- }
-
- var mediaAttrs = [["img", "src"], ["source", "src"], ["video", "src"], ["video", "poster"], ["audio", "src"],
- ["track", "src"], ["embed", "src"], ["input", "src"], ["object", "data"], ['link[rel~="icon"]', "href"]];
- for (var pair of mediaAttrs) {
- for (var node of doc.querySelectorAll(pair[0] + "[" + pair[1] + "]")) {
- var p = util.resolve(dir, node.getAttribute(pair[1]));
- if (!p) continue;
- var url = await dataUrl(p);
- if (url) node.setAttribute(pair[1], url);
- else node.removeAttribute(pair[1]);
- }
- }
- for (var n of doc.querySelectorAll("img[srcset], source[srcset]")) {
- n.setAttribute("srcset", await rewriteSrcset(n.getAttribute("srcset"), dir));
- }
- for (var st of doc.querySelectorAll("style")) {
- if (!st.hasAttribute("data-ath-href")) st.textContent = await rewriteCss(st.textContent, dir);
- }
- for (var el of doc.querySelectorAll("[style]")) {
- var v = el.getAttribute("style");
- if (/url\(/i.test(v)) el.setAttribute("style", await rewriteCss(v, dir));
- }
- }
-
- function onMessage(e) {
- if (!pv.frame || e.source !== pv.frame.contentWindow || !e.data || e.data.__athera !== buildId) return;
- var d = e.data;
- if (d.type === "scroll" && pv.target) pv.scroll[pv.target.id] = d.y;
- if (d.type === "ready") {
- ready = { id: buildId, ready: true };
- A.emit("preview-ready", { id: buildId });
- }
- if (d.type === "ai-result" || d.type === "ai-picked") A.emit("preview-ai", d);
- if (d.type === "ready" && !retry.problem) {
- retry.ok = true;
- if (retry.kind !== "paint") {
- stopRetry();
- showLoading(false);
- }
- }
- if (d.type === "painted" && !retry.problem && d.blank && retry.expect && pv.target) {
- scheduleRetry("paint", pv.target, A.t("preview.blank_render"));
- }
- if (d.type === "console-clear") A.console.reset();
- if (d.type === "console") {
- var entry = toEntry(d);
- if (entry.level === "error" && d.kind !== "eval") {
- pv.errors.push(entry.text + (entry.label ? " (" + entry.label + ")" : ""));
- renderStatus();
- }
- A.console.add(entry);
- A.emit("preview-console", entry);
- }
- if (d.type === "nav" && pv.target) {
- A.emit("preview-nav", { href: d.href, method: "GET" });
- navigate(pv.target, d.href, "GET", "");
- }
- if (d.type === "submit" && pv.target) {
- A.emit("preview-nav", { href: d.action, method: d.method });
- if (d.method === "POST") navigate(pv.target, d.action, "POST", d.data);
- else navigate(pv.target, d.action.split("?")[0] + "?" + d.data, "GET", "");
- }
- }
-
- function renderStatus() {
- var n = pv.errors.length;
- pv.statusEl.hidden = !n;
- pv.statusEl.innerHTML = n ? A.icon("warning") + "<span>" + util.esc(A.tn("preview.problems", n)) + "</span>" : "";
- pv.statusEl.title = pv.errors.join("\n");
- }
-
- function isJsType(type) {
- return !type || /^(module|(text|application)\/(x-)?(javascript|ecmascript))$/i.test(String(type).trim());
- }
-
- function sourceName(path) {
- return "athera-src/" + encodeURI(path).replace(/[()]/g, function (c) { return "%" + c.charCodeAt(0).toString(16).toUpperCase(); });
- }
-
- function unattr(v) {
- return v.replace(/"/g, "\"").replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " ").replace(/&/g, "&");
- }
-
- function scanScripts(doc) {
- var out = [], re = /<script\b[^>]*\bdata-ath-path="([^"]*)"[^>]*>/gi, m;
- while ((m = re.exec(doc))) {
- var start = m.index + m[0].length;
- var stop = doc.indexOf("</script", start);
- if (stop < 0) stop = doc.length;
- var before = doc.slice(0, start);
- var first = before.split("\n").length;
- out.push({
- path: unattr(m[1]),
- start: first,
- end: first + doc.slice(start, stop).split("\n").length - 1,
- col0: start - (before.lastIndexOf("\n") + 1)
- });
- }
- return out;
- }
-
- function frameOf(stack) {
- var lines = String(stack || "").split("\n");
- for (var i = 0; i < lines.length; i++) {
- if (lines[i].indexOf("athera-hook") >= 0) continue;
- var m = FRAME.exec(lines[i]);
- if (m) return { file: m[1], line: +m[2], col: +m[3] };
- }
- return null;
- }
-
- function scriptAt(line) {
- for (var i = 0; i < pv.scripts.length; i++) {
- if (line >= pv.scripts[i].start && line <= pv.scripts[i].end) return pv.scripts[i];
- }
- return null;
- }
-
- function mapScript(hit, path, line, col) {
- var rel = hit ? line - hit.start + 1 : line;
- if (rel < 1) rel = 1;
- var c = col || 1;
- if (hit && rel === 1) c = Math.max(1, c - hit.col0);
- return { path: path, line: rel, col: c, label: util.basename(path) + ":" + rel };
- }
-
- function locate(d) {
- var f = frameOf(d.stack);
- var file = f ? f.file : (d.file || "");
- var line = f ? f.line : (d.line || 0);
- var col = f ? f.col : (d.col || 0);
- var named = /athera-src\/([^\s:()]+)/.exec(file);
- if (named) {
- var path = file;
- try { path = decodeURIComponent(named[1]); } catch (e) { path = named[1]; }
- var mine = pv.scripts.filter(function (s) { return s.path === path; });
- var hit = null;
- for (var i = 0; i < mine.length; i++) if (line >= mine[i].start && line <= mine[i].end) hit = mine[i];
- return mapScript(hit, path, line, col);
- }
- if (!line) return null;
- var inside = scriptAt(line);
- if (inside) return mapScript(inside, inside.path, line, col);
- return { label: A.t("console.page") + ":" + line };
- }
-
- function toEntry(d) {
- var text = d.text || "";
- if (d.kind === "resource") text = A.t("console.resource_failed", { url: d.url });
- else if (d.kind === "http") text = A.t("console.http_status", { method: d.method, url: d.url, status: d.status });
- else if (d.kind === "fetch") text = A.t("console.fetch_failed", { method: d.method, url: d.url, error: d.error });
- else if (d.kind === "assert") text = A.t("console.assert") + (text ? ": " + text : "");
- var entry = { level: d.level || "log", text: text || A.t("preview.error"), source: "js", group: d.group || 0, kind: d.kind };
- var where = d.level === "result" || d.kind === "eval" ? null : locate(d);
- if (where) {
- entry.label = where.label;
- if (where.path) {
- entry.path = where.path;
- entry.line = where.line;
- entry.col = where.col;
- }
- }
- return entry;
- }
-
- function decodeHtml(s) {
- var box = document.createElement("textarea");
- box.innerHTML = s.replace(/<[^>]*>/g, "");
- return box.value.replace(/\s+$/, "");
- }
-
- function phpLocation(file, line) {
- var label = util.basename(file) + ":" + line;
- if (file.indexOf("/www/") !== 0) return { label: label };
- var path = file.slice(5);
- if (path.indexOf("__untitled/") === 0) return { path: "", line: +line, col: 1, label: pv.target ? pv.target.name + ":" + line : label };
- return { path: path, line: +line, col: 1, label: label };
- }
-
- function phpEntry(kind, message, file, line) {
- var where = phpLocation(file, line);
- return {
- level: /^(Warning|Notice|Deprecated|Strict Standards)$/.test(kind) ? "warn" : "error",
- text: kind + ": " + message,
- source: "php",
- group: 0,
- path: where.path,
- line: where.line,
- col: where.col,
- label: where.label
- };
- }
-
- function phpDiagnostics(res) {
- var out = [], m;
- var html = String(res.html || "");
- PHP_ERR.lastIndex = 0;
- while ((m = PHP_ERR.exec(html)) && out.length < 100) out.push(phpEntry(m[1], decodeHtml(m[2]), decodeHtml(m[3]), m[4]));
- String(res.errors || "").trim().split("\n").slice(0, 50).forEach(function (row) {
- if (!row.trim()) return;
- var g = PHP_LOG.exec(row);
- if (g) out.push(phpEntry(g[1], g[2], g[3], g[4]));
- else out.push({ level: "info", text: row, source: "php", group: 0 });
- });
- return out;
- }
-
- async function jumpTo(path, line, col) {
- var target = path;
- if (path === "") {
- if (!pv.target) return;
- target = pv.target.path;
- if (target == null) {
- A.tabs.activate(pv.target);
- requestAnimationFrame(function () { requestAnimationFrame(function () { A.editor.goTo(line, col); }); });
- return;
- }
- }
- var tab = await A.tabs.openPath(target);
- if (!tab || tab.kind !== "text") return;
- requestAnimationFrame(function () { requestAnimationFrame(function () { A.editor.goTo(line, col); }); });
- }
-
- function evalInPage(code) {
- if (!pv.frame || pv.frame.hidden || !pv.frame.contentWindow) return false;
- pv.frame.contentWindow.postMessage({ __athera: buildId, type: "eval", code: code }, "*");
- return true;
- }
- })();
-