@blackglory/observe 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -4
- package/lib/index.d.ts +3 -2
- package/lib/index.js +3 -2
- package/lib/index.js.map +1 -1
- package/lib/observe-addtions-of-descendant-nodes.d.ts +2 -0
- package/lib/observe-addtions-of-descendant-nodes.js +7 -0
- package/lib/observe-addtions-of-descendant-nodes.js.map +1 -0
- package/lib/observe-mutations.d.ts +2 -0
- package/lib/{utils/from-mutation-observer.js → observe-mutations.js} +2 -2
- package/lib/observe-mutations.js.map +1 -0
- package/lib/observe-removals-of-descendant-nodes.d.ts +2 -0
- package/lib/observe-removals-of-descendant-nodes.js +7 -0
- package/lib/observe-removals-of-descendant-nodes.js.map +1 -0
- package/lib/observe-state-changes.js.map +1 -1
- package/package.json +22 -21
- package/src/index.ts +5 -0
- package/src/observe-addtions-of-descendant-nodes.ts +14 -0
- package/src/observe-mutations.ts +13 -0
- package/src/observe-removals-of-descendant-nodes.ts +14 -0
- package/src/observe-state-changes.ts +55 -0
- package/src/observe-url-changes.ts +11 -0
- package/lib/observe-addtion-of-descendant-nodes.d.ts +0 -2
- package/lib/observe-addtion-of-descendant-nodes.js +0 -7
- package/lib/observe-addtion-of-descendant-nodes.js.map +0 -1
- package/lib/observe-removal-of-descendant-nodes.d.ts +0 -2
- package/lib/observe-removal-of-descendant-nodes.js +0 -7
- package/lib/observe-removal-of-descendant-nodes.js.map +0 -1
- package/lib/utils/from-mutation-observer.d.ts +0 -2
- package/lib/utils/from-mutation-observer.js.map +0 -1
package/README.md
CHANGED
|
@@ -19,12 +19,19 @@ function observeURLChanges(): Observable<void>
|
|
|
19
19
|
function observeStateChanges(): Observable<void>
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
###
|
|
22
|
+
### observeAdditionsOfDescendantNodes
|
|
23
23
|
```ts
|
|
24
|
-
function
|
|
24
|
+
function observeAdditionsOfDescendantNodes(node: Node): Observable<Node[]>
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
###
|
|
27
|
+
### observeRemovalsOfDescendantNodes
|
|
28
28
|
```ts
|
|
29
|
-
function
|
|
29
|
+
function observeRemovalsOfDescendantNodes(node: Node): Observable<Node[]>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### observeMutations
|
|
33
|
+
```ts
|
|
34
|
+
function observeMutations(
|
|
35
|
+
...args: Parameters<MutationObserver['observe']>
|
|
36
|
+
): Observable<MutationRecord[]>
|
|
30
37
|
```
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export * from './observe-addtion-of-descendant-nodes.js';
|
|
2
|
-
export * from './observe-removal-of-descendant-nodes.js';
|
|
3
1
|
export * from './observe-state-changes.js';
|
|
4
2
|
export * from './observe-url-changes.js';
|
|
3
|
+
export * from './observe-addtions-of-descendant-nodes.js';
|
|
4
|
+
export * from './observe-removals-of-descendant-nodes.js';
|
|
5
|
+
export * from './observe-mutations.js';
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export * from './observe-addtion-of-descendant-nodes.js';
|
|
2
|
-
export * from './observe-removal-of-descendant-nodes.js';
|
|
3
1
|
export * from './observe-state-changes.js';
|
|
4
2
|
export * from './observe-url-changes.js';
|
|
3
|
+
export * from './observe-addtions-of-descendant-nodes.js';
|
|
4
|
+
export * from './observe-removals-of-descendant-nodes.js';
|
|
5
|
+
export * from './observe-mutations.js';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AACxC,cAAc,2CAA2C,CAAA;AACzD,cAAc,2CAA2C,CAAA;AACzD,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { observeMutations } from './observe-mutations.js';
|
|
2
|
+
import { filter, map } from 'rxjs/operators';
|
|
3
|
+
import * as Iter from 'iterable-operator';
|
|
4
|
+
export function observeAdditionsOfDescendantNodes(node) {
|
|
5
|
+
return observeMutations(node, { childList: true, subtree: true }).pipe(map(records => Iter.toArray(Iter.flatMap(records, x => x.addedNodes))), filter(addedNodes => addedNodes.length > 0));
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=observe-addtions-of-descendant-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-addtions-of-descendant-nodes.js","sourceRoot":"","sources":["../src/observe-addtions-of-descendant-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AAEzC,MAAM,UAAU,iCAAiC,CAAC,IAAU;IAC1D,OAAO,gBAAgB,CACrB,IAAI,EACJ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CACnC,CAAC,IAAI,CACJ,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EACtE,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAC5C,CAAA;AACH,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
export function
|
|
2
|
+
export function observeMutations(...args) {
|
|
3
3
|
return new Observable(subscriber => {
|
|
4
4
|
const observer = new MutationObserver(mutationList => subscriber.next(mutationList));
|
|
5
5
|
observer.observe(...args);
|
|
6
6
|
return () => observer.disconnect();
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
|
-
//# sourceMappingURL=
|
|
9
|
+
//# sourceMappingURL=observe-mutations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-mutations.js","sourceRoot":"","sources":["../src/observe-mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEjC,MAAM,UAAU,gBAAgB,CAC9B,GAAG,IAA6C;IAEhD,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE;QACjC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CACnC,YAAY,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAC9C,CAAA;QACD,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;QACzB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { observeMutations } from './observe-mutations.js';
|
|
2
|
+
import { filter, map } from 'rxjs/operators';
|
|
3
|
+
import * as Iter from 'iterable-operator';
|
|
4
|
+
export function observeRemovalsOfDescendantNodes(node) {
|
|
5
|
+
return observeMutations(node, { childList: true, subtree: true }).pipe(map(records => Iter.toArray(Iter.flatMap(records, x => x.removedNodes))), filter(removedNodes => removedNodes.length > 0));
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=observe-removals-of-descendant-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe-removals-of-descendant-nodes.js","sourceRoot":"","sources":["../src/observe-removals-of-descendant-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE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CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,qBAAqB;IAC5B,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IACnC,OAAO,CAAC,SAAS,GAAG,UAAU,GAAG,IAAI;QACnC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QACpC,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACrD,CAAC,CAAA;IACD,uBAAuB,GAAG,IAAI,CAAA;AAChC,CAAC;AAED,SAAS,wBAAwB;IAC/B,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;IACzC,OAAO,CAAC,YAAY,GAAG,UAAU,GAAG,IAAI;QACtC,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QACvC,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC,CAAA;IACD,0BAA0B,GAAG,IAAI,CAAA;AACnC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackglory/observe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A module for observing things happening.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"DOM"
|
|
7
7
|
],
|
|
8
8
|
"files": [
|
|
9
|
-
"lib"
|
|
9
|
+
"lib",
|
|
10
|
+
"src"
|
|
10
11
|
],
|
|
11
12
|
"type": "module",
|
|
12
13
|
"main": "lib/index.js",
|
|
13
14
|
"types": "lib/index.d.ts",
|
|
14
15
|
"sideEffects": false,
|
|
15
16
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
17
|
+
"node": ">=22"
|
|
17
18
|
},
|
|
18
19
|
"repository": "git@github.com:BlackGlory/observe.git",
|
|
19
20
|
"author": "BlackGlory <woshenmedoubuzhidao@blackglory.me>",
|
|
20
21
|
"license": "MIT",
|
|
21
22
|
"scripts": {
|
|
22
23
|
"prepare": "ts-patch install -s",
|
|
23
|
-
"lint": "eslint --
|
|
24
|
+
"lint": "eslint --quiet src __tests__",
|
|
24
25
|
"test": "vitest --run",
|
|
25
26
|
"prepublishOnly": "run-s prepare clean build",
|
|
26
27
|
"clean": "rimraf lib",
|
|
@@ -34,28 +35,28 @@
|
|
|
34
35
|
}
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@blackglory/wait-for": "^0.
|
|
38
|
-
"@commitlint/cli": "^
|
|
39
|
-
"@commitlint/config-conventional": "^
|
|
40
|
-
"@
|
|
41
|
-
"@typescript-eslint/parser": "^5.55.0",
|
|
38
|
+
"@blackglory/wait-for": "^0.8.1",
|
|
39
|
+
"@commitlint/cli": "^19.8.1",
|
|
40
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
41
|
+
"@eslint/js": "^9.30.1",
|
|
42
42
|
"cross-env": "^7.0.3",
|
|
43
|
-
"eslint": "^
|
|
43
|
+
"eslint": "^9.30.1",
|
|
44
44
|
"husky": "^4.3.6",
|
|
45
|
-
"jsdom": "^
|
|
45
|
+
"jsdom": "^26.1.0",
|
|
46
46
|
"npm-run-all": "^4.1.5",
|
|
47
|
-
"rimraf": "^
|
|
47
|
+
"rimraf": "^6.0.1",
|
|
48
48
|
"standard-version": "^9.5.0",
|
|
49
|
-
"ts-patch": "^
|
|
50
|
-
"tslib": "^2.
|
|
51
|
-
"typescript": "
|
|
52
|
-
"typescript-
|
|
53
|
-
"
|
|
54
|
-
"vite
|
|
55
|
-
"
|
|
49
|
+
"ts-patch": "^3.3.0",
|
|
50
|
+
"tslib": "^2.8.1",
|
|
51
|
+
"typescript": "5.8.3",
|
|
52
|
+
"typescript-eslint": "^8.36.0",
|
|
53
|
+
"typescript-transform-paths": "^3.5.5",
|
|
54
|
+
"vite": "^7.0.4",
|
|
55
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
56
|
+
"vitest": "^3.2.4"
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
|
-
"iterable-operator": "^
|
|
59
|
-
"rxjs": "^7.8.
|
|
59
|
+
"iterable-operator": "^5.1.0",
|
|
60
|
+
"rxjs": "^7.8.2"
|
|
60
61
|
}
|
|
61
62
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { observeMutations } from './observe-mutations.js'
|
|
2
|
+
import { filter, map } from 'rxjs/operators'
|
|
3
|
+
import { Observable } from 'rxjs'
|
|
4
|
+
import * as Iter from 'iterable-operator'
|
|
5
|
+
|
|
6
|
+
export function observeAdditionsOfDescendantNodes(node: Node): Observable<Node[]> {
|
|
7
|
+
return observeMutations(
|
|
8
|
+
node
|
|
9
|
+
, { childList: true, subtree: true }
|
|
10
|
+
).pipe(
|
|
11
|
+
map(records => Iter.toArray(Iter.flatMap(records, x => x.addedNodes)))
|
|
12
|
+
, filter(addedNodes => addedNodes.length > 0)
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Observable } from 'rxjs'
|
|
2
|
+
|
|
3
|
+
export function observeMutations(
|
|
4
|
+
...args: Parameters<MutationObserver['observe']>
|
|
5
|
+
): Observable<MutationRecord[]> {
|
|
6
|
+
return new Observable(subscriber => {
|
|
7
|
+
const observer = new MutationObserver(
|
|
8
|
+
mutationList => subscriber.next(mutationList)
|
|
9
|
+
)
|
|
10
|
+
observer.observe(...args)
|
|
11
|
+
return () => observer.disconnect()
|
|
12
|
+
})
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { observeMutations } from './observe-mutations.js'
|
|
2
|
+
import { filter, map } from 'rxjs/operators'
|
|
3
|
+
import { Observable } from 'rxjs'
|
|
4
|
+
import * as Iter from 'iterable-operator'
|
|
5
|
+
|
|
6
|
+
export function observeRemovalsOfDescendantNodes(node: Node): Observable<Node[]> {
|
|
7
|
+
return observeMutations(
|
|
8
|
+
node
|
|
9
|
+
, { childList: true, subtree: true }
|
|
10
|
+
).pipe(
|
|
11
|
+
map(records => Iter.toArray(Iter.flatMap(records, x => x.removedNodes)))
|
|
12
|
+
, filter(removedNodes => removedNodes.length > 0)
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Observable, Subscriber, fromEvent, merge } from 'rxjs'
|
|
2
|
+
import { map } from 'rxjs/operators'
|
|
3
|
+
|
|
4
|
+
const pushStateHooks = new Set<Subscriber<void>>()
|
|
5
|
+
const replaceStateHooks = new Set<Subscriber<void>>()
|
|
6
|
+
let pushStateHookRegistered = false
|
|
7
|
+
let replaceStateHookRegistered = false
|
|
8
|
+
|
|
9
|
+
export function observeStateChanges(): Observable<void> {
|
|
10
|
+
return merge(
|
|
11
|
+
observePushState()
|
|
12
|
+
, observeReplaceState()
|
|
13
|
+
, fromEvent(window, 'popstate')
|
|
14
|
+
).pipe(
|
|
15
|
+
map(_ => undefined)
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function observePushState(): Observable<void> {
|
|
20
|
+
return new Observable(observer => {
|
|
21
|
+
if (!pushStateHookRegistered) {
|
|
22
|
+
registerPushStateHook()
|
|
23
|
+
}
|
|
24
|
+
pushStateHooks.add(observer)
|
|
25
|
+
return () => pushStateHooks.delete(observer)
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function observeReplaceState(): Observable<void> {
|
|
30
|
+
return new Observable(observer => {
|
|
31
|
+
if (!replaceStateHookRegistered) {
|
|
32
|
+
registerReplaceStateHook()
|
|
33
|
+
}
|
|
34
|
+
replaceStateHooks.add(observer)
|
|
35
|
+
return () => replaceStateHooks.delete(observer)
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function registerPushStateHook() {
|
|
40
|
+
const pushState = history.pushState
|
|
41
|
+
history.pushState = function (...args) {
|
|
42
|
+
Reflect.apply(pushState, this, args)
|
|
43
|
+
pushStateHooks.forEach(observer => observer.next())
|
|
44
|
+
}
|
|
45
|
+
pushStateHookRegistered = true
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function registerReplaceStateHook() {
|
|
49
|
+
const replaceState = history.replaceState
|
|
50
|
+
history.replaceState = function (...args) {
|
|
51
|
+
Reflect.apply(replaceState, this, args)
|
|
52
|
+
replaceStateHooks.forEach(observer => observer.next())
|
|
53
|
+
}
|
|
54
|
+
replaceStateHookRegistered = true
|
|
55
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Observable, animationFrames } from 'rxjs'
|
|
2
|
+
import { filter, tap, map } from 'rxjs/operators'
|
|
3
|
+
|
|
4
|
+
export function observeURLChanges(): Observable<void> {
|
|
5
|
+
let url = document.URL
|
|
6
|
+
return animationFrames().pipe(
|
|
7
|
+
filter(() => url !== document.URL)
|
|
8
|
+
, tap(() => url = document.URL)
|
|
9
|
+
, map(() => undefined)
|
|
10
|
+
)
|
|
11
|
+
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { fromMutationObserver } from "./utils/from-mutation-observer.js";
|
|
2
|
-
import { filter, map } from 'rxjs/operators';
|
|
3
|
-
import * as Iter from 'iterable-operator';
|
|
4
|
-
export function observeAdditionOfDescendantNodes(node) {
|
|
5
|
-
return fromMutationObserver(node, { childList: true, subtree: true }).pipe(map(records => Iter.toArray(Iter.flatten(Iter.map(records, x => x.addedNodes)))), filter(addedNodes => addedNodes.length > 0));
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=observe-addtion-of-descendant-nodes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observe-addtion-of-descendant-nodes.js","sourceRoot":"","sources":["../src/observe-addtion-of-descendant-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,0CAAwC;AACvE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AAEzC,MAAM,UAAU,gCAAgC,CAAC,IAAU;IACzD,OAAO,oBAAoB,CACzB,IAAI,EACJ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CACnC,CAAC,IAAI,CACJ,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CACzB,IAAI,CAAC,OAAO,CACV,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CACrC,CACF,CAAC,EACF,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAC5C,CAAA;AACH,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { fromMutationObserver } from "./utils/from-mutation-observer.js";
|
|
2
|
-
import { filter, map } from 'rxjs/operators';
|
|
3
|
-
import * as Iter from 'iterable-operator';
|
|
4
|
-
export function observeRemovalOfDescendantNodes(node) {
|
|
5
|
-
return fromMutationObserver(node, { childList: true, subtree: true }).pipe(map(records => Iter.toArray(Iter.flatten(Iter.map(records, x => x.removedNodes)))), filter(removedNodes => removedNodes.length > 0));
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=observe-removal-of-descendant-nodes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observe-removal-of-descendant-nodes.js","sourceRoot":"","sources":["../src/observe-removal-of-descendant-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,0CAAwC;AACvE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AAEzC,MAAM,UAAU,+BAA+B,CAAC,IAAU;IACxD,OAAO,oBAAoB,CACzB,IAAI,EACJ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CACnC,CAAC,IAAI,CACJ,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CACzB,IAAI,CAAC,OAAO,CACV,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CACvC,CACF,CAAC,EACF,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAChD,CAAA;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"from-mutation-observer.js","sourceRoot":"","sources":["../../src/utils/from-mutation-observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEjC,MAAM,UAAU,oBAAoB,CAClC,GAAG,IAA6C;IAEhD,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE;QACjC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CACnC,YAAY,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAC9C,CAAA;QACD,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;QACzB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC"}
|