"use strict"; // ------------------------------------------------------------- // WARNING: this file is used by both the client and the server. // Do not use any browser or node-specific API! // ------------------------------------------------------------- var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.add = exports.remove = exports.SCRIPT_PROCESSING_END_HEADER_COMMENT = exports.SCRIPT_PROCESSING_END_COMMENT = exports.SCRIPT_PROCESSING_START_COMMENT = void 0; const regexp_escape_1 = __importDefault(require("../../utils/regexp-escape")); const internal_properties_1 = __importDefault(require("../../processing/dom/internal-properties")); const instruction_1 = __importDefault(require("./instruction")); const service_routes_1 = __importDefault(require("../../proxy/service-routes")); const json_1 = require("../../utils/json"); exports.SCRIPT_PROCESSING_START_COMMENT = '/*hammerhead|script|start*/'; exports.SCRIPT_PROCESSING_END_COMMENT = '/*hammerhead|script|end*/'; exports.SCRIPT_PROCESSING_END_HEADER_COMMENT = '/*hammerhead|script|processing-header-end*/'; const STRICT_MODE_PLACEHOLDER = '{strict-placeholder}'; const SW_SCOPE_HEADER_VALUE = '{sw-scope-header-value}'; const WORKER_SETTINGS_PLACEHOLDER = '{worker-settings}'; const IMPORT_WORKER_HAMMERHEAD = ` if (typeof importScripts !== "undefined" && /\\[native code]/g.test(importScripts.toString())) { var ${instruction_1.default.getWorkerSettings} = function () {return ${WORKER_SETTINGS_PLACEHOLDER}}; importScripts((location.origin || (location.protocol + "//" + location.host)) + "${service_routes_1.default.workerHammerhead}"); } `; const PROCESS_DOM_METHOD = `window['${internal_properties_1.default.processDomMethodName}'] && window['${internal_properties_1.default.processDomMethodName}']();`; function trim(val) { return val.replace(/\n(?!$)\s*/g, ''); } const PROXYLESS_HEADER = trim(` ${exports.SCRIPT_PROCESSING_START_COMMENT} ${STRICT_MODE_PLACEHOLDER} if (typeof window !== 'undefined' && window) { ${PROCESS_DOM_METHOD} } ${exports.SCRIPT_PROCESSING_END_HEADER_COMMENT} `); const HEADER = trim(` ${exports.SCRIPT_PROCESSING_START_COMMENT} ${STRICT_MODE_PLACEHOLDER} ${SW_SCOPE_HEADER_VALUE} if (typeof window !== 'undefined' && window){ ${PROCESS_DOM_METHOD} if (window.${instruction_1.default.getProperty} && typeof ${instruction_1.default.getProperty} === 'undefined') var ${instruction_1.default.getLocation} = window.${instruction_1.default.getLocation}, ${instruction_1.default.setLocation} = window.${instruction_1.default.setLocation}, ${instruction_1.default.setProperty} = window.${instruction_1.default.setProperty}, ${instruction_1.default.getProperty} = window.${instruction_1.default.getProperty}, ${instruction_1.default.callMethod} = window.${instruction_1.default.callMethod}, ${instruction_1.default.getEval} = window.${instruction_1.default.getEval}, ${instruction_1.default.processScript} = window.${instruction_1.default.processScript}, ${instruction_1.default.processHtml} = window.${instruction_1.default.processHtml}, ${instruction_1.default.getPostMessage} = window.${instruction_1.default.getPostMessage}, ${instruction_1.default.getProxyUrl} = window.${instruction_1.default.getProxyUrl}, ${instruction_1.default.restArray} = window.${instruction_1.default.restArray}, ${instruction_1.default.restObject} = window.${instruction_1.default.restObject}, ${instruction_1.default.arrayFrom} = window.${instruction_1.default.arrayFrom}; } else { if (typeof ${instruction_1.default.getProperty} === 'undefined') var ${instruction_1.default.getLocation} = function(l){return l}, ${instruction_1.default.setLocation} = function(l,v){return l = v}, ${instruction_1.default.setProperty} = function(o,p,v){return o[p] = v}, ${instruction_1.default.getProperty} = function(o,p){return o[p]}, ${instruction_1.default.callMethod} = function(o,p,a){return o[p].apply(o,a)}, ${instruction_1.default.getEval} = function(e){return e}, ${instruction_1.default.processScript} = function(s){return s}, ${instruction_1.default.processHtml} = function(h){return h}, ${instruction_1.default.getPostMessage} = function(w,p){return arguments.length===1?w.postMessage:p}, ${instruction_1.default.getProxyUrl} = function(u,d){return u}, ${instruction_1.default.restArray} = function(a,i){return Array.prototype.slice.call(a, i)}, ${instruction_1.default.restObject} = function(o,p){var k=Object.keys(o),n={};for(var i=0;i