首页 > 其他分享 >devtools layers.js

devtools layers.js

时间:2024-11-25 18:02:57浏览次数:6  
标签:layers layerPayload return js && new devtools null model

 

 

import*as e from "../../ui/legacy/legacy.js";
import*as t from "../../ui/visual_logging/visual_logging.js";
import*as r from "../layer_viewer/layer_viewer.js";
import*as i from "../../core/common/common.js";
import*as a from "../../core/i18n/i18n.js";
import*as s from "../../core/sdk/sdk.js";
class n extends e.SplitWidget.SplitWidget {
    logTreeView;
    paintProfilerView;
    constructor(e) {
        super(!0, !1),
        this.element.setAttribute("jslog", `${t.pane("layers.paint-profiler").track({
            resize: !0
        })}`),
        this.logTreeView = new r.PaintProfilerView.PaintProfilerCommandLogView,
        this.setSidebarWidget(this.logTreeView),
        this.paintProfilerView = new r.PaintProfilerView.PaintProfilerView(e),
        this.setMainWidget(this.paintProfilerView),
        this.paintProfilerView.addEventListener("WindowChanged", this.onWindowChanged, this),
        this.logTreeView.focus()
    }
    reset() {
        this.paintProfilerView.setSnapshotAndLog(null, [], null)
    }
    profile(e) {
        function t(e, t) {
            this.logTreeView.setCommandLog(t || []),
            this.paintProfilerView.setSnapshotAndLog(e, t || [], null),
            e && e.release()
        }
        e.commandLog().then((r => t.call(this, e, r)))
    }
    setScale(e) {
        this.paintProfilerView.setScale(e)
    }
    onWindowChanged() {
        this.logTreeView.updateWindow(this.paintProfilerView.selectionWindow())
    }
}
var l, o = Object.freeze({
    __proto__: null,
    LayerPaintProfilerView: n
});
class d extends s.SDKModel.SDKModel {
    layerTreeAgent;
    paintProfilerModel;
    layerTreeInternal;
    throttler;
    enabled;
    lastPaintRectByLayerId;
    constructor(e) {
        super(e),
        this.layerTreeAgent = e.layerTreeAgent(),
        e.registerLayerTreeDispatcher(new c(this)),
        this.paintProfilerModel = e.model(s.PaintProfiler.PaintProfilerModel);
        const t = e.model(s.ResourceTreeModel.ResourceTreeModel);
        t && t.addEventListener(s.ResourceTreeModel.Events.PrimaryPageChanged, this.onPrimaryPageChanged, this),
        this.layerTreeInternal = null,
        this.throttler = new i.Throttler.Throttler(20)
    }
    async disable() {
        this.enabled && (this.enabled = !1,
        await this.layerTreeAgent.invoke_disable())
    }
    enable() {
        this.enabled || (this.enabled = !0,
        this.forceEnable())
    }
    async forceEnable() {
        this.lastPaintRectByLayerId = new Map,
        this.layerTreeInternal || (this.layerTreeInternal = new h(this)),
        await this.layerTreeAgent.invoke_enable()
    }
    layerTree() {
        return this.layerTreeInternal
    }
    async layerTreeChanged(e) {
        this.enabled && this.throttler.schedule(this.innerSetLayers.bind(this, e))
    }
    async innerSetLayers(e) {
        const t = this.layerTreeInternal;
        await t.setLayers(e),
        this.lastPaintRectByLayerId || (this.lastPaintRectByLayerId = new Map);
        for (const e of this.lastPaintRectByLayerId.keys()) {
            const r = this.lastPaintRectByLayerId.get(e)
              , i = t.layerById(e);
            i && i.setLastPaintRect(r)
        }
        this.lastPaintRectByLayerId = new Map,
        this.dispatchEventToListeners(l.LayerTreeChanged)
    }
    layerPainted(e, t) {
        if (!this.enabled)
            return;
        const r = this.layerTreeInternal.layerById(e);
        if (!r)
            return this.lastPaintRectByLayerId || (this.lastPaintRectByLayerId = new Map),
            void this.lastPaintRectByLayerId.set(e, t);
        r.didPaint(t),
        this.dispatchEventToListeners(l.LayerPainted, r)
    }
    onPrimaryPageChanged() {
        this.layerTreeInternal = null,
        this.enabled && this.forceEnable()
    }
}
s.SDKModel.SDKModel.register(d, {
    capabilities: 2,
    autostart: !1
}),
function(e) {
    e.LayerTreeChanged = "LayerTreeChanged",
    e.LayerPainted = "LayerPainted"
}(l || (l = {}));
class h extends s.LayerTreeBase.LayerTreeBase {
    layerTreeModel;
    constructor(e) {
        super(e.target()),
        this.layerTreeModel = e
    }
    async setLayers(e) {
        if (!e)
            return void this.innerSetLayers(e);
        const t = new Set;
        for (let r = 0; r < e.length; ++r) {
            const i = e[r].backendNodeId;
            i && !this.backendNodeIdToNode().has(i) && t.add(i)
        }
        await this.resolveBackendNodeIds(t),
        this.innerSetLayers(e)
    }
    innerSetLayers(e) {
        if (this.setRoot(null),
        this.setContentRoot(null),
        !e)
            return;
        let t;
        const r = this.layersById;
        this.layersById = new Map;
        for (let i = 0; i < e.length; ++i) {
            const a = e[i].layerId;
            let s = r.get(a);
            s ? s.reset(e[i]) : s = new y(this.layerTreeModel,e[i]),
            this.layersById.set(a, s);
            const n = e[i].backendNodeId;
            n && s.setNode(this.backendNodeIdToNode().get(n) || null),
            !this.contentRoot() && s.drawsContent() && this.setContentRoot(s);
            const l = s.parentId();
            if (l) {
                const e = this.layersById.get(l);
                if (!e)
                    throw new Error(`Missing parent ${l} for layer ${a}`);
                e.addChild(s)
            } else
                t && console.assert(!1, "Multiple root layers"),
                t = s
        }
        t && (this.setRoot(t),
        t.calculateQuad(new WebKitCSSMatrix))
    }
}
class y {
    scrollRectsInternal;
    quadInternal;
    childrenInternal;
    image;
    parentInternal;
    layerPayload;
    layerTreeModel;
    nodeInternal;
    lastPaintRectInternal;
    paintCountInternal;
    stickyPositionConstraintInternal;
    constructor(e, t) {
        this.layerTreeModel = e,
        this.reset(t)
    }
    id() {
        return this.layerPayload.layerId
    }
    parentId() {
        return this.layerPayload.parentLayerId || null
    }
    parent() {
        return this.parentInternal
    }
    isRoot() {
        return !this.parentId()
    }
    children() {
        return this.childrenInternal
    }
    addChild(e) {
        const t = e;
        t.parentInternal && console.assert(!1, "Child already has a parent"),
        this.childrenInternal.push(t),
        t.parentInternal = this
    }
    setNode(e) {
        this.nodeInternal = e
    }
    node() {
        return this.nodeInternal || null
    }
    nodeForSelfOrAncestor() {
        let e = this;
        for (; e; e = e.parentInternal)
            if (e.nodeInternal)
                return e.nodeInternal;
        return null
    }
    offsetX() {
        return this.layerPayload.offsetX
    }
    offsetY() {
        return this.layerPayload.offsetY
    }
    width() {
        return this.layerPayload.width
    }
    height() {
        return this.layerPayload.height
    }
    transform() {
        return this.layerPayload.transform || null
    }
    quad() {
        return this.quadInternal
    }
    anchorPoint() {
        return [this.layerPayload.anchorX || 0, this.layerPayload.anchorY || 0, this.layerPayload.anchorZ || 0]
    }
    invisible() {
        return this.layerPayload.invisible || !1
    }
    paintCount() {
        return this.paintCountInternal || this.layerPayload.paintCount
    }
    lastPaintRect() {
        return this.lastPaintRectInternal || null
    }
    setLastPaintRect(e) {
        this.lastPaintRectInternal = e
    }
    scrollRects() {
        return this.scrollRectsInternal
    }
    stickyPositionConstraint() {
        return this.stickyPositionConstraintInternal || null
    }
    async requestCompositingReasons() {
        return (await this.layerTreeModel.layerTreeAgent.invoke_compositingReasons({
            layerId: this.id()
        })).compositingReasons || []
    }
    async requestCompositingReasonIds() {
        return (await this.layerTreeModel.layerTreeAgent.invoke_compositingReasons({
            layerId: this.id()
        })).compositingReasonIds || []
    }
    drawsContent() {
        return this.layerPayload.drawsContent
    }
    gpuMemoryUsage() {
        return this.drawsContent() ? this.width() * this.height() * 4 : 0
    }
    snapshots() {
        return [this.layerTreeModel.paintProfilerModel.makeSnapshot(this.id()).then((e => e ? {
            rect: {
                x: 0,
                y: 0,
                width: this.width(),
                height: this.height()
            },
            snapshot: e
        } : null))]
    }
    didPaint(e) {
        this.lastPaintRectInternal = e,
        this.paintCountInternal = this.paintCount() + 1,
        this.image = null
    }
    reset(e) {
        this.nodeInternal = null,
        this.childrenInternal = [],
        this.parentInternal = null,
        this.paintCountInternal = 0,
        this.layerPayload = e,
        this.image = null,
        this.scrollRectsInternal = this.layerPayload.scrollRects || [],
        this.stickyPositionConstraintInternal = this.layerPayload.stickyPositionConstraint ? new s.LayerTreeBase.StickyPositionConstraint(this.layerTreeModel.layerTree(),this.layerPayload.stickyPositionConstraint) : null
    }
    matrixFromArray(e) {
        return new WebKitCSSMatrix("matrix3d(" + e.map((function(e) {
            return e.toFixed(9)
        }
        )).join(",") + ")")
    }
    calculateTransformToViewport(t) {
        let r = (new WebKitCSSMatrix).translate(this.layerPayload.offsetX, this.layerPayload.offsetY);
        if (this.layerPayload.transform) {
            const t = this.matrixFromArray(this.layerPayload.transform)
              , i = new e.Geometry.Vector(this.layerPayload.width * this.anchorPoint()[0],this.layerPayload.height * this.anchorPoint()[1],this.anchorPoint()[2])
              , a = e.Geometry.multiplyVectorByMatrixAndNormalize(i, r)
              , s = (new WebKitCSSMatrix).translate(-a.x, -a.y, -a.z);
            r = s.inverse().multiply(t.multiply(s.multiply(r)))
        }
        return r = t.multiply(r),
        r
    }
    createVertexArrayForRect(e, t) {
        return [0, 0, 0, e, 0, 0, e, t, 0, 0, t, 0]
    }
    calculateQuad(t) {
        const r = this.calculateTransformToViewport(t);
        this.quadInternal = [];
        const i = this.createVertexArrayForRect(this.layerPayload.width, this.layerPayload.height);
        for (let t = 0; t < 4; ++t) {
            const a = e.Geometry.multiplyVectorByMatrixAndNormalize(new e.Geometry.Vector(i[3 * t],i[3 * t + 1],i[3 * t + 2]), r);
            this.quadInternal.push(a.x, a.y)
        }
        this.childrenInternal.forEach((function(e) {
            e.calculateQuad(r)
        }
        ))
    }
}
class c {
    layerTreeModel;
    constructor(e) {
        this.layerTreeModel = e
    }
    layerTreeDidChange({layers: e}) {
        this.layerTreeModel.layerTreeChanged(e || null)
    }
    layerPainted({layerId: e, clip: t}) {
        this.layerTreeModel.layerPainted(e, t)
    }
}
var u = Object.freeze({
    __proto__: null,
    AgentLayer: y,
    AgentLayerTree: h,
    get Events() {
        return l
    },
    LayerTreeModel: d
});
const P = {
    details: "Details",
    profiler: "Profiler"
}
  , p = a.i18n.registerUIStrings("panels/layers/LayersPanel.ts", P)
  , g = a.i18n.getLocalizedString.bind(void 0, p);
let w;
class f extends e.Panel.PanelWithSidebar {
    model;
    layerViewHost;
    layerTreeOutline;
    rightSplitWidget;
    layers3DView;
    tabbedPane;
    layerDetailsView;
    paintProfilerView;
    updateThrottler;
    layerBeingProfiled;
    constructor() {
        super("layers", 225),
        this.model = null,
        s.TargetManager.TargetManager.instance().observeTargets(this, {
            scoped: !0
        }),
        this.layerViewHost = new r.LayerViewHost.LayerViewHost,
        this.layerTreeOutline = new r.LayerTreeOutline.LayerTreeOutline(this.layerViewHost),
        this.layerTreeOutline.addEventListener("PaintProfilerRequested", this.onPaintProfileRequested, this),
        this.panelSidebarElement().appendChild(this.layerTreeOutline.element),
        this.setDefaultFocusedElement(this.layerTreeOutline.element),
        this.rightSplitWidget = new e.SplitWidget.SplitWidget(!1,!0,"layer-details-split-view-state"),
        this.splitWidget().setMainWidget(this.rightSplitWidget),
        this.layers3DView = new r.Layers3DView.Layers3DView(this.layerViewHost),
        this.rightSplitWidget.setMainWidget(this.layers3DView),
        this.layers3DView.addEventListener("PaintProfilerRequested", this.onPaintProfileRequested, this),
        this.layers3DView.addEventListener("ScaleChanged", this.onScaleChanged, this),
        this.tabbedPane = new e.TabbedPane.TabbedPane,
        this.rightSplitWidget.setSidebarWidget(this.tabbedPane),
        this.layerDetailsView = new r.LayerDetailsView.LayerDetailsView(this.layerViewHost),
        this.layerDetailsView.addEventListener("PaintProfilerRequested", this.onPaintProfileRequested, this),
        this.tabbedPane.appendTab(m.Details, g(P.details), this.layerDetailsView),
        this.paintProfilerView = new n(this.showImage.bind(this)),
        this.tabbedPane.addEventListener(e.TabbedPane.Events.TabClosed, this.onTabClosed, this),
        this.updateThrottler = new i.Throttler.Throttler(100)
    }
    static instance(e) {
        return w && !e?.forceNew || (w = new f),
        w
    }
    focus() {
        this.layerTreeOutline.focus()
    }
    wasShown() {
        super.wasShown(),
        this.model && this.model.enable()
    }
    willHide() {
        this.model && this.model.disable(),
        super.willHide()
    }
    targetAdded(e) {
        e === e.outermostTarget() && (this.model = e.model(d),
        this.model && (this.model.addEventListener(l.LayerTreeChanged, this.onLayerTreeUpdated, this),
        this.model.addEventListener(l.LayerPainted, this.onLayerPainted, this),
        this.isShowing() && (this.model.enable(),
        this.update())))
    }
    targetRemoved(e) {
        this.model && this.model.target() === e && (this.model.removeEventListener(l.LayerTreeChanged, this.onLayerTreeUpdated, this),
        this.model.removeEventListener(l.LayerPainted, this.onLayerPainted, this),
        this.model.disable(),
        this.model = null)
    }
    onLayerTreeUpdated() {
        this.updateThrottler.schedule(this.update.bind(this))
    }
    update() {
        if (this.model) {
            this.layerViewHost.setLayerTree(this.model.layerTree());
            const e = this.model.target().model(s.ResourceTreeModel.ResourceTreeModel);
            if (e) {
                const t = e.mainFrame;
                if (t) {
                    const e = t.url;
                    this.element.setAttribute("test-current-url", e)
                }
            }
        }
        return Promise.resolve()
    }
    onLayerPainted({data: e}) {
        if (!this.model)
            return;
        const t = this.layerViewHost.selection();
        t && t.layer() === e && this.layerDetailsView.update(),
        this.layers3DView.updateLayerSnapshot(e)
    }
    onPaintProfileRequested({data: e}) {
        this.layers3DView.snapshotForSelection(e).then((t => {
            t && (this.layerBeingProfiled = e.layer(),
            this.tabbedPane.hasTab(m.Profiler) || this.tabbedPane.appendTab(m.Profiler, g(P.profiler), this.paintProfilerView, void 0, !0, !0),
            this.tabbedPane.selectTab(m.Profiler),
            this.paintProfilerView.profile(t.snapshot))
        }
        ))
    }
    onTabClosed(e) {
        e.data.tabId === m.Profiler && this.layerBeingProfiled && (this.paintProfilerView.reset(),
        this.layers3DView.showImageForLayer(this.layerBeingProfiled, void 0),
        this.layerBeingProfiled = null)
    }
    showImage(e) {
        this.layerBeingProfiled && this.layers3DView.showImageForLayer(this.layerBeingProfiled, e)
    }
    onScaleChanged(e) {
        this.paintProfilerView.setScale(e.data)
    }
}
const m = {
    Details: "details",
    Profiler: "profiler"
};
var T = Object.freeze({
    __proto__: null,
    DetailsViewTabs: m,
    LayersPanel: f
});
export {o as LayerPaintProfilerView, u as LayerTreeModel, T as LayersPanel};

 

  1. Press Command+Option+i (Ctrl+Shift+i on Windows) to open DevTools.

  2. Make sure that the developer tools are undocked into a new window. You may have to undock from the menu: Undock from menu

  3. Press Command+Option+i again on this new window.

  4. That will open the DevTools on the DevTools.

  • You can redock the page's DevTools if you want.
  1. If it's not already, select Elements — it's the first icon at the top of the inspector.

打开devtools的devtools

标签:layers,layerPayload,return,js,&&,new,devtools,null,model
From: https://www.cnblogs.com/bigben0123/p/18568271

相关文章

  • Driver.js:轻量级用户引导插件,小而美的界面,让用户体验飞起来!
    大家好,欢迎来到程序视点!我是小二哥!每当我们的新产品上线或大版本迭代后,产品使用步骤或功能介绍是必不可少的。今天就给大家介绍一款可以快速实现新手引导和交互效果的工具库:Driver.js    关于Driver.jsDriver.js是一个可以轻松......
  • python怎么调用js中的函数
    Python调用JS文件中的函数方法如下:1、安装PyExecJS第三方库2、导入库:importexecjs3、调用JS文件中的方法Passwd = execjs.compile(open(r"web.js").read().decode("utf-8")).call('loginHandle','steam')语句解析,open后跟所执行的js文件位置,call后第一个单引号引......
  • HTML-CSS-JS-day01:html常见的标签
    前端--一、相关概念1、前后端--技术层面程序运行在客户端上,这样的程序称为前端程序运行在服务器端2、前后台--应用层面如果服务是面向所有用户,这样的服务称为前台服务如果服务是面向相关的管理或者维护人员,这样的服务称为后台服务二、web(网页)访问流程基于http/htt......
  • FastJson漏洞复现
    FastJson漏洞复现环境:vulhub/fastjson Fastjson是阿里巴巴公司开源的一个高性能的Java库,专门用于处理JSON数据格式。 它不仅能够将Java对象序列化为JSON格式的字符串,还能将JSON字符串反序列化为Java对象。漏洞发现出现json格式的地方,就可能使用FastJsson1.通过报错页面可......
  • js 根据传入数字,返回千、万、百万、千万、亿等单位
    使用while循环,更便捷简练,代码如下:constcountUnit=(value:number,section=10)=>{leti=0;letsum=value/section;while(sum>section){sum=sum/section;i++;}constdata=['十','百','千','万......
  • H5流媒体播放器EasyPlayer.js网页直播/点播播放器如果H.265视频在播放器上播放不流畅,
    随着流媒体技术的迅速发展,H5流媒体播放器已成为现代网络视频播放的重要工具。其中,EasyPlayer.js网页直播/点播播放器作为一款功能强大的H5播放器,凭借其全面的协议支持、多种解码方式以及跨平台兼容性,赢得了广泛的关注和应用。如果H.265视频在播放器上播放不流畅,可以考虑以下几种......
  • Vue Devtools的下载和安装
    1.下载下载地址:https://github.com/vuejs/vue-devtools/tree/v5.1.1 下载下来zip包。解压到指定文件夹 2.安装依赖在这个目录,执行npminstall命令进行依赖安装 3.修改配置打开解压目录vue-devtools-master下的shells/Chrome/manifest.json文件,将代码"persistent":fal......
  • 支持无限加载的js图片画廊插件
    在线演示  下载  natural-gallery-js是一款支持无限加载的js图片画廊插件。该js图片画廊支持图片的懒加载,可以对图片进行搜索,分类,还可以以轮播图的方式来展示和切换图片。  使用方法在页面中引入下面的CSS和js文件。<linkrel="stylesheet"href="../dist/t......
  • (免费送源码)计算机毕业设计原创定制:Java+ B/S+JSP+ springboot 基于SpringBoot的健康管
    摘 要随着我国经济迅速发展,人们对手机的需求越来越大,各种手机软件也都在被广泛应用,但是对于手机进行数据信息管理,对于手机的各种软件也是备受用户的喜爱,健康管理系统被用户普遍使用,为方便用户能够可以随时进行健康管理系统的数据信息管理,特开发了基于springboot的健康管理系......
  • vite.config.js配置入门详解
    一,搭建vite项目兼容性注意:Vite需要 Node.js 版本14.18+,16+。然而,有些模板需要依赖更高的Node版本才能正常运行,当你的包管理器发出警告时,请注意升级你的Node版本。通过下面的命令行可以创建指定项目名称和你想要使用的模板的vue项目#npm6.xnpmcreatevite@......