Skip to content

Commit

Permalink
fix(*): 将 first-child 替换为 first-of-type,last-child 替换为 last-of-type,以…
Browse files Browse the repository at this point in the history
…此避免 feedback-sys 插入 div 后样式出错 OI-wiki/feedback-sys#71 (comment)
  • Loading branch information
ZnPdCo authored Sep 7, 2024
1 parent 5debe5a commit 06abc52
Show file tree
Hide file tree
Showing 22 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export function mountIconSearchResult(
)

/* Update search result metadata */
const meta = getElement(":scope > :first-child", el)
const meta = getElement(":scope > :first-of-type", el)
push$
.pipe(
withLatestFrom(query$)
Expand Down Expand Up @@ -208,7 +208,7 @@ export function mountIconSearchResult(

/* Update icon search result list */
const file = el.getAttribute("data-mdx-mode") === "file"
const list = getElement(":scope > :last-child", el)
const list = getElement(":scope > :last-of-type", el)
push$
.pipe(
tap(() => list.innerHTML = ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function mountSponsorship(
el.removeAttribute("hidden")

/* Render public sponsors with avatar and links */
const list = getElement(":scope > :first-child", el)
const list = getElement(":scope > :first-of-type", el)
for (const sponsor of sponsorship.sponsors)
if (sponsor.type === "public")
list.appendChild(renderPublicSponsor(sponsor.user))
Expand Down
2 changes: 1 addition & 1 deletion src/overrides/assets/stylesheets/custom/_typeset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
border-end-start-radius: px2rem(2px);

// If icon is alone, round corners
&:last-child {
&:last-of-type {
border-radius: px2rem(2px);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
border-bottom: px2rem(1px) solid var(--md-default-fg-color--lightest);

// Omit border on last child
&:last-child {
&:last-of-type {
border-bottom: none;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}

// Premium sponsor list
p:last-child {
p:last-of-type {
display: flex;
flex-wrap: wrap;
justify-content: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface Announce {
export function watchAnnounce(
el: HTMLElement
): Observable<Announce> {
const button = getElement(".md-typeset > :first-child", el)
const button = getElement(".md-typeset > :first-of-type", el)
return fromEvent(button, "click", { once: true })
.pipe(
map(() => getElement(".md-typeset", el)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function mountSearch(
if (active === query) {
const anchors = new Map<HTMLAnchorElement, number>()
for (const anchor of getElements<HTMLAnchorElement>(
":first-child [href]", result
":first-of-type [href]", result
)) {
const article = anchor.firstElementChild!
anchors.set(anchor, parseFloat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export function mountSearchResult(
const container = el.parentElement!

/* Retrieve nested components */
const meta = getElement(":scope > :first-child", el)
const list = getElement(":scope > :last-child", el)
const meta = getElement(":scope > :first-of-type", el)
const list = getElement(":scope > :last-of-type", el)

/* Reveal to accessibility tree – see https://bit.ly/3iAA7t8 */
watchToggle("search")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function watchSource(
export function mountSource(
el: HTMLAnchorElement
): Observable<Component<Source>> {
const inner = getElement(":scope > :last-child", el)
const inner = getElement(":scope > :last-of-type", el)
return defer(() => {
const push$ = new Subject<Source>()
push$.subscribe(({ facts }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/assets/javascripts/components/toc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function watchTableOfContents(
distinctUntilKeyChanged("height"),
map(({ height }) => {
const main = getComponentElement("main")
const grid = getElement(":scope > :first-child", main)
const grid = getElement(":scope > :first-of-type", main)
return height + 0.8 * (
grid.offsetTop -
main.offsetTop
Expand Down
6 changes: 3 additions & 3 deletions src/templates/assets/stylesheets/main/_typeset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ kbd {
}

// Adjust spacing on last child
&:last-child {
&:last-of-type {
margin-bottom: 0;
}

Expand Down Expand Up @@ -468,12 +468,12 @@ kbd {
:is(th, td) > * {

// Adjust spacing on first child
&:first-child {
&:first-of-type {
margin-top: 0;
}

// Adjust spacing on last child
&:last-child {
&:last-of-type {
margin-bottom: 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
}

// Adjust spacing on last child
> :last-child {
> :last-of-type {
margin-bottom: 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
}

// Adjust font weight of site title
&:first-child {
&:first-of-type {
font-weight: 700;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}

// Metadata item separator
&__item:not(:last-child)::after {
&__item:not(:last-of-type)::after {
margin-inline: px2rem(4px);
content: "·";
}
Expand Down
8 changes: 4 additions & 4 deletions src/templates/assets/stylesheets/main/components/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
}

// Always align navigation icons to the end
.md-icon:last-child {
.md-icon:last-of-type {
margin-inline-start: auto;
}

Expand Down Expand Up @@ -162,7 +162,7 @@
margin-top: 0;

// Stretch first child
&:first-child {
&:first-of-type {
flex-grow: 1;
// Hack: if a very long word is used, it can push the arrow out of sight.
// Setting this property contains the text - see https://t.ly/E02vp
Expand Down Expand Up @@ -250,7 +250,7 @@
scroll-snap-type: y mandatory;

// Omit border on first child
> :first-child {
> :first-of-type {
border-top: 0;
}
}
Expand Down Expand Up @@ -589,7 +589,7 @@
margin: 1.25em 0;

// Adjust spacing on last child
&:last-child {
&:last-of-type {
margin-bottom: 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
}

// Post excerpt content
.md-post__content > :first-child {
.md-post__content > :first-of-type {
--md-scroll-margin: #{px2rem(120px)};

margin-top: 0;
Expand Down
8 changes: 4 additions & 4 deletions src/templates/assets/stylesheets/main/components/_search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
inset-inline-start: px2rem(16px);

// Hide the magnifying glass
svg:first-child {
svg:first-of-type {
display: none;
}
}
Expand All @@ -332,7 +332,7 @@
pointer-events: none;

// Hide the back arrow
svg:last-child {
svg:last-of-type {
display: none;
}
}
Expand Down Expand Up @@ -537,7 +537,7 @@
box-shadow: 0 px2rem(-1px) var(--md-default-fg-color--lightest);

// Omit border on first child
&:first-child {
&:first-of-type {
box-shadow: none;
}
}
Expand All @@ -555,7 +555,7 @@
}

// Adjust spacing on last child of last link
&:last-child p:last-child {
&:last-of-type p:last-of-type {
margin-bottom: px2rem(12px);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@
font-size: px2rem(12.8px);

// Adjust spacing on first child
&.md-typeset > :first-child {
&.md-typeset > :first-of-type {
margin-top: 0;
}

// Adjust spacing on last child
&.md-typeset > :last-child {
&.md-typeset > :last-of-type {
margin-bottom: 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ $admonitions: (
}

// Adjust spacing on last child
html & > :last-child {
html & > :last-of-type {
margin-bottom: px2rem(12px);
}
}
Expand All @@ -133,7 +133,7 @@ $admonitions: (
border-start-end-radius: px2rem(2px);

// Adjust spacing for title-only admonitions
html &:last-child {
html &:last-of-type {
margin-bottom: 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
}

// Adjust spacing on first child
> :first-child {
> :first-of-type {
margin-top: 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@
box-shadow: none;

// Adjust spacing on first child
> :first-child {
> :first-of-type {
margin-top: 0.5em;
}

// Adjust spacing on last child
> :last-child {
> :last-of-type {
margin-bottom: 0.5em;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@

// Code block is the first child of a tab - remove margin and mirror
// previous (now deprecated) SuperFences code block grouping behavior
> pre:first-child,
> .highlight:first-child > pre {
> pre:first-of-type,
> .highlight:first-of-type > pre {
margin: 0;

// Remove rounded borders on code block
Expand All @@ -212,7 +212,7 @@

// Code block is the first child of a tab - remove margin and mirror
// previous (now deprecated) SuperFences code block grouping behavior
> .highlight:first-child {
> .highlight:first-of-type {

// Code block title - remove spacing and rounded borders
> .filename {
Expand Down

0 comments on commit 06abc52

Please sign in to comment.