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wnPropertyNames.config'\\n\\nclass Sandbox {\\n  public sandbox: HTMLIFrameElement\\n  public shadowWindow!: ShadowWindow\\n  public window!: Window\\n  public document!: Document\\n  public content!: Document\\n  public windowOwnPropertyNames: Array<string> = windowOwnPropertyNames\\n  private white: boolean\\n\\n  constructor (white = false, properties: string[] = ['*'], setting = 'allow-scripts allow-same-origin') {\\n    const sandbox = this.sandbox = document.createElement('iframe')\\n    sandbox.src = 'about:blank'\\n    sandbox.style.display = 'none'\\n    this.windowOwnPropertyNames = this.windowOwnPropertyNames.concat(properties)\\n    this.white = white\\n    this.set(setting)\\n    this.enter()\\n    this.shadow()\\n\\n    if (!white) this.exit()\\n\\n    return this\\n  }\\n\\n  static getWindowOwnPropertyNames () {\\n    return windowOwnPropertyNames\\n  }\\n\\n  static debugger (isee: string, model = { 'safe-context': 'safe' }) {\\n    let msg = 'I know the danger!'\\n    if (isee === msg) {\\n      this.prototype['open debugger'] = true\\n      if (model['safe-context'] === 'unsafe') {\\n        this.prototype['unsafe-context'] = true\\n      } else {\\n        console.warn(`%c Sandbox: Opening the 'debugger' will result in a risk of losing security!`, 'font-size: 32px; color: red')\\n      }\\n    } else {\\n      console.log(`Sandbox: Opening 'debugger' input '${msg}'`)\\n    }\\n  }\\n\\n  private shadow () {\\n    const contentWindow = this.sandbox.contentWindow as ShadowWindow\\n    const contentDocument = this.sandbox.contentDocument as Document\\n    this.window = contentWindow\\n    this.content = this.document = contentDocument\\n\\n    if (this.white) return this\\n\\n    const globalProperty = this.getProtoProperty(this.window)\\n    const ShadowObject = this.window.Object as ObjectConstructor\\n    const allowAllProperty = ~this.windowOwnPropertyNames.indexOf('*')\\n\\n    this.shadowWindow = new contentWindow.Object() as ShadowWindow\\n    for (let k of globalProperty) {\\n      if (this.window[k] + '' !== '[object Window]' && (allowAllProperty || ~this.windowOwnPropertyNames.indexOf(k))) {\\n        this.shadowWindow[k] = this.window[k]\\n      } else {\\n        try {\\n          ShadowObject.defineProperty(this.shadowWindow, k, {\\n            configurable: true,\\n            enumerable: true,\\n            writable: true,\\n            get () {\\n              console.error(`Sandbox Error: Unauthorized use of window['${k}'].`)\\n              return null\\n            }\\n          })\\n          this.delProtoProperty(this.window, k)\\n        } catch (e) {\\n          //\\n        }\\n      }\\n    }\\n\\n    this.shadowWindow.shadowWindow = this.shadowWindow\\n    this.shadowWindow.window = this.shadowWindow\\n\\n    return this\\n  }\\n\\n  public getProtoProperty (object: object) {\\n    let propertyNames = Object.getOwnPropertyNames(object)\\n    if (object['__proto__']) return propertyNames.concat(this.getProtoProperty(object['__proto__'] as object))\\n    return propertyNames\\n  }\\n\\n  public delProtoProperty (object: object, name: string) {\\n    if (!object) return false\\n    if (object['__proto__']) {\\n      if (object['__proto__'].hasOwnProperty(name)) {\\n        return delete object['__proto__'][name]\\n      } else {\\n        return this.delProtoProperty(object['__proto__'], name)\\n      }\\n    } else {\\n      return delete object[name]\\n    }\\n  }\\n\\n  public set (allow: string) {\\n    this.sandbox.setAttribute('sandbox', allow)\\n  }\\n\\n  public reset (allow: string) {\\n    this.exit()\\n    this.set(allow)\\n    this.enter()\\n    this.shadow()\\n\\n    return this\\n  }\\n\\n  public open () {\\n    this.content.open()\\n    return this\\n  }\\n\\n  public write (context = '<head><meta charset=\\\"utf-8\\\"></head>') {\\n    this.content.write(context)\\n    return this\\n  }\\n\\n  public close () {\\n    this.content.close()\\n    return this\\n  }\\n\\n  public enter () {\\n    const documentElement = document.documentElement as HTMLHtmlElement\\n    documentElement.appendChild(this.sandbox)\\n  }\\n\\n  public exit () {\\n    if (this['open debugger']) return\\n    const parentNode = this.sandbox.parentNode as HTMLHtmlElement\\n    parentNode && parentNode.removeChild(this.sandbox)\\n  }\\n}\\n\\nexport {\\n  Sandbox\\n}\\n\"]}","code":"'use strict';\r\nimport windowOwnPropertyNames from './windowOwnPropertyNames.config';\r\nvar Sandbox = /** @class */ (function () {\r\n    function Sandbox(white, properties, setting) {\r\n        if (white === void 0) { white = false; }\r\n        if (properties === void 0) { properties = ['*']; }\r\n        if (setting === void 0) { setting = 'allow-scripts allow-same-origin'; }\r\n        this.windowOwnPropertyNames = windowOwnPropertyNames;\r\n        var sandbox = this.sandbox = document.createElement('iframe');\r\n        sandbox.src = 'about:blank';\r\n        sandbox.style.display = 'none';\r\n        this.windowOwnPropertyNames = this.windowOwnPropertyNames.concat(properties);\r\n        this.white = white;\r\n        this.set(setting);\r\n        this.enter();\r\n        this.shadow();\r\n        if (!white)\r\n            this.exit();\r\n        return this;\r\n    }\r\n    Sandbox.getWindowOwnPropertyNames = function () {\r\n        return windowOwnPropertyNames;\r\n    };\r\n    Sandbox.debugger = function (isee, model) {\r\n        if (model === void 0) { model = { 'safe-context': 'safe' }; }\r\n        var msg = 'I know the danger!';\r\n        if (isee === msg) {\r\n            this.prototype['open debugger'] = true;\r\n            if (model['safe-context'] === 'unsafe') {\r\n                this.prototype['unsafe-context'] = true;\r\n            }\r\n            else {\r\n                console.warn(\"%c Sandbox: Opening the 'debugger' will result in a risk of losing security!\", 'font-size: 32px; color: red');\r\n            }\r\n        }\r\n        else {\r\n            console.log(\"Sandbox: Opening 'debugger' input '\" + msg + \"'\");\r\n        }\r\n    };\r\n    Sandbox.prototype.shadow = function () {\r\n        var contentWindow = this.sandbox.contentWindow;\r\n        var contentDocument = this.sandbox.contentDocument;\r\n        this.window = contentWindow;\r\n        this.content = this.document = contentDocument;\r\n        if (this.white)\r\n            return this;\r\n        var globalProperty = this.getProtoProperty(this.window);\r\n        var ShadowObject = this.window.Object;\r\n        var allowAllProperty = ~this.windowOwnPropertyNames.indexOf('*');\r\n        this.shadowWindow = new contentWindow.Object();\r\n        var _loop_1 = function (k) {\r\n            if (this_1.window[k] + '' !== '[object Window]' && (allowAllProperty || ~this_1.windowOwnPropertyNames.indexOf(k))) {\r\n                this_1.shadowWindow[k] = this_1.window[k];\r\n            }\r\n            else {\r\n                try {\r\n                    ShadowObject.defineProperty(this_1.shadowWindow, k, {\r\n                        configurable: true,\r\n                        enumerable: true,\r\n                        writable: true,\r\n                        get: function () {\r\n                            console.error(\"Sandbox Error: Unauthorized use of window['\" + k + \"'].\");\r\n                            return null;\r\n                        }\r\n                    });\r\n                    this_1.delProtoProperty(this_1.window, k);\r\n                }\r\n                catch (e) {\r\n                    //\r\n                }\r\n            }\r\n        };\r\n        var this_1 = this;\r\n        for (var _i = 0, globalProperty_1 = globalProperty; _i < globalProperty_1.length; _i++) {\r\n            var k = globalProperty_1[_i];\r\n            _loop_1(k);\r\n        }\r\n        this.shadowWindow.shadowWindow = this.shadowWindow;\r\n        this.shadowWindow.window = this.shadowWindow;\r\n        return this;\r\n    };\r\n    Sandbox.prototype.getProtoProperty = function (object) {\r\n        var propertyNames = Object.getOwnPropertyNames(object);\r\n        if (object['__proto__'])\r\n            return propertyNames.concat(this.getProtoProperty(object['__proto__']));\r\n        return propertyNames;\r\n    };\r\n    Sandbox.prototype.delProtoProperty = function (object, name) {\r\n        if (!object)\r\n            return false;\r\n        if (object['__proto__']) {\r\n            if (object['__proto__'].hasOwnProperty(name)) {\r\n                return delete object['__proto__'][name];\r\n            }\r\n            else {\r\n                return this.delProtoProperty(object['__proto__'], name);\r\n            }\r\n        }\r\n        else {\r\n            return delete object[name];\r\n        }\r\n    };\r\n    Sandbox.prototype.set = function (allow) {\r\n        this.sandbox.setAttribute('sandbox', allow);\r\n    };\r\n    Sandbox.prototype.reset = function (allow) {\r\n        this.exit();\r\n        this.set(allow);\r\n        this.enter();\r\n        this.shadow();\r\n        return this;\r\n    };\r\n    Sandbox.prototype.open = function () {\r\n        this.content.open();\r\n        return this;\r\n    };\r\n    Sandbox.prototype.write = function (context) {\r\n        if (context === void 0) { context = '<head><meta charset=\"utf-8\"></head>'; }\r\n        this.content.write(context);\r\n        return this;\r\n    };\r\n    Sandbox.prototype.close = function () {\r\n        this.content.close();\r\n        return this;\r\n    };\r\n    Sandbox.prototype.enter = function () {\r\n        var documentElement = document.documentElement;\r\n        documentElement.appendChild(this.sandbox);\r\n    };\r\n    Sandbox.prototype.exit = function () {\r\n        if (this['open debugger'])\r\n            return;\r\n        var parentNode = this.sandbox.parentNode;\r\n        parentNode && parentNode.removeChild(this.sandbox);\r\n    };\r\n    return Sandbox;\r\n}());\r\nexport { Sandbox };\r\n//# sourceMappingURL=index.js.map","dts":{"name":"/Users/ioing/libdev/shadow-function/dist/typings/sandbox/index.d.ts","writeByteOrderMark":false,"text":"declare class Sandbox {\r\n    sandbox: HTMLIFrameElement;\r\n    shadowWindow: ShadowWindow;\r\n    window: Window;\r\n    document: Document;\r\n    content: Document;\r\n    windowOwnPropertyNames: Array<string>;\r\n    private white;\r\n    constructor(white?: boolean, properties?: string[], setting?: string);\r\n    static getWindowOwnPropertyNames(): string[];\r\n    static debugger(isee: string, model?: {\r\n        'safe-context': string;\r\n    }): void;\r\n    private shadow;\r\n    getProtoProperty(object: object): any;\r\n    delProtoProperty(object: object, name: string): any;\r\n    set(allow: string): void;\r\n    reset(allow: string): this;\r\n    open(): this;\r\n    write(context?: string): this;\r\n    close(): this;\r\n    enter(): void;\r\n    exit(): void;\r\n}\r\nexport { Sandbox };\r\n"}}
