Skip to content

Commit

Permalink
feat: shadow dom support
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Sep 27, 2024
1 parent 600ea62 commit ddac0c9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"autoprefixer": "^9.7.4",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.5",
"chobitsu": "^1.5.1",
"chobitsu": "^1.8.1",
"core-js": "^3.37.1",
"css-loader": "^3.4.2",
"es-check": "^6.2.1",
Expand All @@ -65,7 +65,7 @@
"luna-box-model": "^1.0.0",
"luna-console": "^1.3.4",
"luna-data-grid": "^0.6.0",
"luna-dom-viewer": "^1.3.0",
"luna-dom-viewer": "^1.4.0",
"luna-modal": "^1.2.3",
"luna-notification": "^0.3.2",
"luna-object-viewer": "^0.3.1",
Expand Down
7 changes: 5 additions & 2 deletions src/Elements/Detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ export default class Detail {
const events = el.erudaEvents
if (events && keys(events).length !== 0) ret.listeners = events

if (needNoStyle(tagName)) return ret
if (needNoStyle(tagName)) {
return ret
}

let computedStyle = cssStore.getComputedStyle()

Expand Down Expand Up @@ -472,8 +474,9 @@ function rmDefComputedStyle(computedStyle, styles) {

const NO_STYLE_TAG = ['script', 'style', 'meta', 'title', 'link', 'head']

const needNoStyle = (tagName) =>
const needNoStyle = (tagName) => {
NO_STYLE_TAG.indexOf(tagName.toLowerCase()) > -1
}

const wrapLink = (link) => `<a href="${link}" target="_blank">${link}</a>`

Expand Down
13 changes: 10 additions & 3 deletions src/Elements/Elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import evalCss from '../lib/evalCss'
import Detail from './Detail'
import chobitsu from '../lib/chobitsu'
import emitter from '../lib/emitter'
import { formatNodeName } from './util'
import { formatNodeName, isShadowRoot } from './util'

export default class Elements extends Tool {
constructor() {
Expand Down Expand Up @@ -118,7 +118,7 @@ export default class Elements extends Tool {
if (this._curNode.nodeType === Node.ELEMENT_NODE) {
this._detail.show(this._curNode)
} else {
this._detail.show(this._curNode.parentNode)
this._detail.show(this._curNode.parentNode || this._curNode.host)
}
}
_initTpl() {
Expand Down Expand Up @@ -309,7 +309,14 @@ function getCrumbs(el) {
idx: i++,
})

el = el.parentElement
if (isShadowRoot(el)) {
el = el.host
}
if (!el.parentElement && isShadowRoot(el.parentNode)) {
el = el.parentNode
} else {
el = el.parentElement
}
}

return ret.reverse()
Expand Down
10 changes: 10 additions & 0 deletions src/Elements/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export function formatNodeName(node, { noAttr = false } = {}) {
return `<span class="${c('tag-name-color')}">(text)</span>`
} else if (node.nodeType === Node.COMMENT_NODE) {
return `<span class="${c('tag-name-color')}"><!--></span>`
} else if (isShadowRoot(node)) {
return `<span class="${c('tag-name-color')}">#shadow-root</span>`
}

const { id, className, attributes } = node
Expand Down Expand Up @@ -34,3 +36,11 @@ export function formatNodeName(node, { noAttr = false } = {}) {

return ret
}

export function isShadowRoot(node) {
if (window.ShadowRoot) {
return node instanceof ShadowRoot
}

return false
}

0 comments on commit ddac0c9

Please sign in to comment.