Add observers for stylesheet mutations (#177)

* hack together stylesheet observer

* Add test coverage for insertRule/deleteRule on stylesheets

* Add new observers

* update patch based on changes to master

* Functioning event recording

* Remove print statements

* Fix ID usage and mark add vs remove

* Correct type

Co-authored-by: Jon Perl <perl.jonathan@gmail.com>
This commit is contained in:
David Cramer
2026-04-01 12:00:00 +08:00
committed by GitHub
parent c7140ea8c6
commit 3a0e829884
10 changed files with 273 additions and 64 deletions

View File

@@ -52,6 +52,8 @@ export type customEvent<T = unknown> = {
};
};
export type styleSheetEvent = {};
export enum IncrementalSource {
Mutation,
MouseMove,
@@ -61,6 +63,7 @@ export enum IncrementalSource {
Input,
TouchMove,
MediaInteraction,
StyleSheetRule,
}
export type mutationData = {
@@ -93,6 +96,10 @@ export type mediaInteractionData = {
source: IncrementalSource.MediaInteraction;
} & mediaInteractionParam;
export type styleSheetRuleData = {
source: IncrementalSource.StyleSheetRule;
} & styleSheetRuleParam;
export type incrementalData =
| mutationData
| mousemoveData
@@ -100,7 +107,8 @@ export type incrementalData =
| scrollData
| viewportResizeData
| inputData
| mediaInteractionData;
| mediaInteractionData
| styleSheetRuleData;
export type event =
| domContentLoadedEvent
@@ -141,6 +149,7 @@ export type observerParam = {
ignoreClass: string;
maskAllInputs: boolean;
inlineStylesheet: boolean;
styleSheetRuleCb: styleSheetRuleCallback;
mousemoveWait: number;
};
@@ -152,6 +161,7 @@ export type hooksParam = {
viewportResize?: viewportResizeCallback;
input?: inputCallback;
mediaInteaction?: mediaInteractionCallback;
styleSheetRule?: styleSheetRuleCallback;
};
export type textCursor = {
@@ -239,6 +249,23 @@ export type scrollPosition = {
export type scrollCallback = (p: scrollPosition) => void;
export type styleSheetAddRule = {
rule: string;
index?: number;
};
export type styleSheetDeleteRule = {
index: number;
};
export type styleSheetRuleParam = {
id: number;
removes?: styleSheetDeleteRule[];
adds?: styleSheetAddRule[];
};
export type styleSheetRuleCallback = (s: styleSheetRuleParam) => void;
export type viewportResizeDimention = {
width: number;
height: number;