-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55b3c0b
commit c93f03b
Showing
30 changed files
with
781 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {define} from "./client/define.ts" | ||
export * from "./client/element.ts" | ||
|
||
define() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {ChapterContainer} from "./element.ts" | ||
|
||
declare global { | ||
interface Window { | ||
ChapterContainer: typeof ChapterContainer | ||
} | ||
|
||
interface HTMLElementTagNameMap { | ||
"chapter-container": ChapterContainer | ||
} | ||
|
||
namespace preact { | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
"chapter-container": HTMLAttributes<ChapterContainer> | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function define(): void { | ||
if (window.customElements.get(ChapterContainer.tagName)) { | ||
return | ||
} | ||
window.ChapterContainer = ChapterContainer | ||
window.customElements.define(ChapterContainer.tagName, ChapterContainer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
export class ChapterContainer extends HTMLElement { | ||
static get tagName(): string { | ||
return "chapter-container" | ||
} | ||
|
||
get navigationHidden(): boolean { | ||
return this.#hasState("navigation-hidden") | ||
} | ||
|
||
set navigationHidden(s: boolean) { | ||
this.#changeState("navigation-hidden", s) | ||
} | ||
|
||
connectedCallback(): void { | ||
this.#attach() | ||
this.#setup() | ||
} | ||
|
||
#internals: ElementInternals | null = null | ||
|
||
#attach(): void { | ||
if (this.attachInternals) { | ||
this.#internals = this.attachInternals() | ||
} | ||
} | ||
|
||
#setup(): void { | ||
this.#setupState() | ||
} | ||
|
||
#setupState(): void { | ||
if (this.#internals && CSS.supports("selector(:state(_))")) { | ||
this.#hasState = this.#hasModernState | ||
this.#changeState = this.#changeModernState | ||
return | ||
} | ||
this.#hasState = this.#hasFallbackState | ||
this.#changeState = this.#changeFallbackState | ||
} | ||
|
||
toggleNavigationHidden(): void { | ||
this.navigationHidden = !this.navigationHidden | ||
} | ||
|
||
#hasState: (k: string) => boolean = () => false | ||
|
||
#hasFallbackState(k: string): boolean { | ||
const s = this.getAttribute(`state-${k}`) | ||
if (s === null) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
#hasModernState(k: string): boolean { | ||
const t = this.#internals | ||
if (!t) { | ||
return false | ||
} | ||
return t.states.has(k) | ||
} | ||
|
||
#changeState: (k: string, v: boolean) => void = () => void 0 | ||
|
||
#changeFallbackState(k: string, v: boolean): void { | ||
if (!v) { | ||
this.removeAttribute(`state-${k}`) | ||
return | ||
} | ||
this.setAttribute(`state-${k}`, "") | ||
} | ||
|
||
#changeModernState(k: string, v: boolean): void { | ||
const t = this.#internals | ||
if (!t) { | ||
return | ||
} | ||
if (!v) { | ||
t.states.delete(k) | ||
return | ||
} | ||
t.states.add(k) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.