-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: add support for resize observer bindings #8022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3805838
⚡️ Use RO singleton instead of iframe if supported
TheCymaera 25dd06e
✨ Added support for resize observer bindings
TheCymaera 2c5c7a1
🐛 Fixed null bug
TheCymaera c0572ba
🎨 Simplified resize observer singleton
TheCymaera f3d2dd0
🎨 Simplified RO even more
TheCymaera c46eb62
🎨 Cleaned up binding group events
TheCymaera bb31fa6
🐛 Fixed import extension
TheCymaera 8a1e0a2
🐛 Fixed import extension
TheCymaera 1e295ea
🎨 Optimized runtime
TheCymaera 524b74a
🎨 Clean up
TheCymaera 8a85b43
🐛 Fix ResizeObserverSingleton.entries
TheCymaera fbd02ba
🔥 Removed resize_observer_content_rect
TheCymaera c215195
💩 Added ResizeObserver types
TheCymaera a3f8507
🎨 Copied ResizeObserver types from lib.dom.d.ts
TheCymaera 4d265be
Merge branch 'master' into master
dummdidumm 2c5b113
typings
dummdidumm 86470b0
Merge branch 'master' into master
TheCymaera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,67 @@ | ||
/** | ||
* Resize observer singleton. | ||
* One listener per element only! | ||
* https://groups.google.com/a/chromium.org/g/blink-dev/c/z6ienONUb5A/m/F5-VcUZtBAAJ | ||
*/ | ||
export class ResizeObserverSingleton { | ||
constructor(readonly options?: ResizeObserverOptions) {} | ||
|
||
observe(element: Element, listener: Listener) { | ||
this._listeners.set(element, listener); | ||
this._getObserver().observe(element, this.options); | ||
return () => { | ||
this._listeners.delete(element); | ||
this._observer.unobserve(element); // this line can probably be removed | ||
}; | ||
} | ||
|
||
static readonly entries: WeakMap<Element, ResizeObserverEntry> = 'WeakMap' in globalThis ? new WeakMap() : undefined; | ||
|
||
private readonly _listeners: WeakMap<Element, Listener> = 'WeakMap' in globalThis ? new WeakMap() : undefined; | ||
private _observer?: ResizeObserver; | ||
private _getObserver() { | ||
return this._observer ?? (this._observer = new ResizeObserver((entries) => { | ||
for (const entry of entries) { | ||
ResizeObserverSingleton.entries.set(entry.target, entry); | ||
this._listeners.get(entry.target)?.(entry); | ||
} | ||
})); | ||
} | ||
} | ||
|
||
type Listener = (entry: ResizeObserverEntry)=>any; | ||
|
||
// TODO: Remove this | ||
interface ResizeObserverSize { | ||
readonly blockSize: number; | ||
readonly inlineSize: number; | ||
} | ||
|
||
interface ResizeObserverEntry { | ||
readonly borderBoxSize: readonly ResizeObserverSize[]; | ||
readonly contentBoxSize: readonly ResizeObserverSize[]; | ||
readonly contentRect: DOMRectReadOnly; | ||
readonly devicePixelContentBoxSize: readonly ResizeObserverSize[]; | ||
readonly target: Element; | ||
} | ||
|
||
type ResizeObserverBoxOptions = 'border-box' | 'content-box' | 'device-pixel-content-box'; | ||
|
||
interface ResizeObserverOptions { | ||
box?: ResizeObserverBoxOptions; | ||
} | ||
|
||
interface ResizeObserver { | ||
disconnect(): void; | ||
observe(target: Element, options?: ResizeObserverOptions): void; | ||
unobserve(target: Element): void; | ||
} | ||
|
||
interface ResizeObserverCallback { | ||
(entries: ResizeObserverEntry[], observer: ResizeObserver): void; | ||
} | ||
|
||
declare let ResizeObserver: { | ||
prototype: ResizeObserver; | ||
new(callback: ResizeObserverCallback): ResizeObserver; | ||
}; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.