Skip to content

Commit

Permalink
release: v1.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Oct 18, 2024
1 parent 097457c commit 84a1ddb
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.8.4 (18 Oct 2024)

* fix: css priority [#16](https://github.com/liriliri/chobitsu/issues/16)

## 1.8.3 (17 Oct 2024)

* fix: ignore special ws connection
Expand Down
52 changes: 52 additions & 0 deletions devtools/target.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.motto {
display: inline-block;
}

.scroll {
margin-top: 15px;
border: 1px solid black;
width: 400px;
height: 200px;
overflow: auto;
}

.big {
width: 300px;
height: 300px;
margin-top: 15px;
background-color: red;
}

.small {
width: 100px;
height: 100px;
margin-top: 15px;
background-color: blue;
}

.image {
margin-top: 15px;
}

#priority.priority {
background: orange;
}

#priority.priority {
background: silver;
}

#priority.priority, .priority {
background: tomato;
}

.priority {
background: purple;
}

#priority {
margin-top: 15px;
width: 50px;
height: 50px;
background: green;
}
26 changes: 2 additions & 24 deletions devtools/target.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="modulepreload" href="/db.js" />
<title>Target</title>
<style>
.motto {
display: inline-block;
}
.scroll {
margin-top: 15px;
border: 1px solid black;
width: 400px;
height: 200px;
overflow: auto;
}
.big {
width: 300px;
height: 300px;
margin-top: 15px;
background-color: red;
}
.small {
width: 100px;
height: 100px;
margin-top: 15px;
background-color: blue;
}
</style>
<link rel="stylesheet" href="target.css" />
<script src="chobitsu.js"></script>
</head>
<body>
Expand Down Expand Up @@ -79,6 +56,7 @@
</div>
<div class="big"></div>
<div class="small"></div>
<div id="priority" class="priority"></div>
<div class="image">
<img src="https://chii.liriliri.io/logo.png" alt="placeholder" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chobitsu",
"version": "1.8.3",
"version": "1.8.4",
"description": "Chrome devtools protocol JavaScript implementation",
"main": "dist/chobitsu.js",
"exports": {
Expand Down
16 changes: 13 additions & 3 deletions src/lib/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Emitter from 'licia/Emitter'
import strHash from 'licia/strHash'
import toStr from 'licia/toStr'
import trim from 'licia/trim'
import cssPriority from 'licia/cssPriority'
import map from 'licia/map'
import { createId, getTextContent } from './util'

const elProto: any = Element.prototype
Expand Down Expand Up @@ -37,7 +39,7 @@ export function getStyleSheets() {
}

export function getMatchedCssRules(node: any) {
const ret: any[] = []
const unsorted: any[] = []

each(document.styleSheets, (styleSheet: any) => {
let styleSheetId = styleSheet.styleSheetId
Expand Down Expand Up @@ -65,15 +67,23 @@ export function getMatchedCssRules(node: any) {

if (!matchesEl) return

ret.push({
unsorted.push({
selectorText: cssRule.selectorText,
style: cssRule.style,
styleSheetId,
})
})
})

return ret
const sorted: any[] = []
const priorities = map(unsorted, ({ selectorText }, i) => {
return cssPriority(selectorText, { position: i })
})
each(priorities.sort(cssPriority.compare), property => {
sorted.push(unsorted[property[5]])
})

return sorted
}

export function formatStyle(style: any) {
Expand Down

0 comments on commit 84a1ddb

Please sign in to comment.