@serwist/window 8.0.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/.turbo/turbo-build.log +10 -0
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/Serwist.d.ts +271 -0
- package/dist/Serwist.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +689 -0
- package/dist/index.old.cjs +693 -0
- package/dist/messageSW.d.ts +16 -0
- package/dist/messageSW.d.ts.map +1 -0
- package/dist/utils/SerwistEvent.d.ts +39 -0
- package/dist/utils/SerwistEvent.d.ts.map +1 -0
- package/dist/utils/SerwistEventTarget.d.ts +38 -0
- package/dist/utils/SerwistEventTarget.d.ts.map +1 -0
- package/dist/utils/urlsMatch.d.ts +11 -0
- package/dist/utils/urlsMatch.d.ts.map +1 -0
- package/package.json +44 -0
- package/rollup.config.js +27 -0
- package/src/Serwist.ts +686 -0
- package/src/index.ts +15 -0
- package/src/messageSW.ts +34 -0
- package/src/utils/SerwistEvent.ts +57 -0
- package/src/utils/SerwistEventTarget.ts +68 -0
- package/src/utils/urlsMatch.ts +21 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sends a data object to a service worker via `postMessage` and resolves with
|
|
3
|
+
* a response (if any).
|
|
4
|
+
*
|
|
5
|
+
* A response can be set in a message handler in the service worker by
|
|
6
|
+
* calling `event.ports[0].postMessage(...)`, which will resolve the promise
|
|
7
|
+
* returned by `messageSW()`. If no response is set, the promise will not
|
|
8
|
+
* resolve.
|
|
9
|
+
*
|
|
10
|
+
* @param sw The service worker to send the message to.
|
|
11
|
+
* @param data An object to send to the service worker.
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
declare function messageSW(sw: ServiceWorker, data: {}): Promise<any>;
|
|
15
|
+
export { messageSW };
|
|
16
|
+
//# sourceMappingURL=messageSW.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageSW.d.ts","sourceRoot":"","sources":["../src/messageSW.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;GAYG;AAGH,iBAAS,SAAS,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAQ5D;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SerwistEventTarget } from "./SerwistEventTarget.js";
|
|
2
|
+
/**
|
|
3
|
+
* A minimal `Event` subclass shim.
|
|
4
|
+
* This doesn't *actually* subclass `Event` because not all browsers support
|
|
5
|
+
* constructable `EventTarget`, and using a real `Event` will error.
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export declare class SerwistEvent<K extends keyof SerwistEventMap> {
|
|
9
|
+
type: K;
|
|
10
|
+
target?: SerwistEventTarget;
|
|
11
|
+
sw?: ServiceWorker;
|
|
12
|
+
originalEvent?: Event;
|
|
13
|
+
isExternal?: boolean;
|
|
14
|
+
constructor(type: K, props: Omit<SerwistEventMap[K], "target" | "type">);
|
|
15
|
+
}
|
|
16
|
+
export interface SerwistMessageEvent extends SerwistEvent<"message"> {
|
|
17
|
+
data: any;
|
|
18
|
+
originalEvent: Event;
|
|
19
|
+
ports: readonly MessagePort[];
|
|
20
|
+
}
|
|
21
|
+
export interface SerwistLifecycleEvent extends SerwistEvent<keyof SerwistLifecycleEventMap> {
|
|
22
|
+
isUpdate?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface SerwistLifecycleWaitingEvent extends SerwistLifecycleEvent {
|
|
25
|
+
wasWaitingBeforeRegister?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface SerwistLifecycleEventMap {
|
|
28
|
+
installing: SerwistLifecycleEvent;
|
|
29
|
+
installed: SerwistLifecycleEvent;
|
|
30
|
+
waiting: SerwistLifecycleWaitingEvent;
|
|
31
|
+
activating: SerwistLifecycleEvent;
|
|
32
|
+
activated: SerwistLifecycleEvent;
|
|
33
|
+
controlling: SerwistLifecycleEvent;
|
|
34
|
+
redundant: SerwistLifecycleEvent;
|
|
35
|
+
}
|
|
36
|
+
export interface SerwistEventMap extends SerwistLifecycleEventMap {
|
|
37
|
+
message: SerwistMessageEvent;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=SerwistEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SerwistEvent.d.ts","sourceRoot":"","sources":["../../src/utils/SerwistEvent.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;;;GAKG;AACH,qBAAa,YAAY,CAAC,CAAC,SAAS,MAAM,eAAe;IAO9C,IAAI,EAAE,CAAC;IANhB,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,EAAE,CAAC,EAAE,aAAa,CAAC;IACnB,aAAa,CAAC,EAAE,KAAK,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;gBAGZ,IAAI,EAAE,CAAC,EACd,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAIrD;AAED,MAAM,WAAW,mBAAoB,SAAQ,YAAY,CAAC,SAAS,CAAC;IAClE,IAAI,EAAE,GAAG,CAAC;IACV,aAAa,EAAE,KAAK,CAAC;IACrB,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,qBAAsB,SAAQ,YAAY,CAAC,MAAM,wBAAwB,CAAC;IACzF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,4BAA6B,SAAQ,qBAAqB;IACzE,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,qBAAqB,CAAC;IAClC,SAAS,EAAE,qBAAqB,CAAC;IACjC,OAAO,EAAE,4BAA4B,CAAC;IACtC,UAAU,EAAE,qBAAqB,CAAC;IAClC,SAAS,EAAE,qBAAqB,CAAC;IACjC,WAAW,EAAE,qBAAqB,CAAC;IACnC,SAAS,EAAE,qBAAqB,CAAC;CAClC;AAED,MAAM,WAAW,eAAgB,SAAQ,wBAAwB;IAC/D,OAAO,EAAE,mBAAmB,CAAC;CAC9B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { SerwistEvent, SerwistEventMap } from "./SerwistEvent.js";
|
|
2
|
+
export type ListenerCallback = (event: SerwistEvent<any>) => any;
|
|
3
|
+
/**
|
|
4
|
+
* A minimal `EventTarget` shim.
|
|
5
|
+
* This is necessary because not all browsers support constructable
|
|
6
|
+
* `EventTarget`, so using a real `EventTarget` will error.
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export declare class SerwistEventTarget {
|
|
10
|
+
private readonly _eventListenerRegistry;
|
|
11
|
+
/**
|
|
12
|
+
* @param type
|
|
13
|
+
* @param listener
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
addEventListener<K extends keyof SerwistEventMap>(type: K, listener: (event: SerwistEventMap[K]) => any): void;
|
|
17
|
+
/**
|
|
18
|
+
* @param type
|
|
19
|
+
* @param listener
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
removeEventListener<K extends keyof SerwistEventMap>(type: K, listener: (event: SerwistEventMap[K]) => any): void;
|
|
23
|
+
/**
|
|
24
|
+
* @param event
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
dispatchEvent(event: SerwistEvent<any>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a Set of listeners associated with the passed event type.
|
|
30
|
+
* If no handlers have been registered, an empty Set is returned.
|
|
31
|
+
*
|
|
32
|
+
* @param type The event type.
|
|
33
|
+
* @returns An array of handler functions.
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
private _getEventListenersByType;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=SerwistEventTarget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SerwistEventTarget.d.ts","sourceRoot":"","sources":["../../src/utils/SerwistEventTarget.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEvE,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;AAEjE;;;;;GAKG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAgE;IAEvG;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,SAAS,MAAM,eAAe,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,IAAI;IAK9G;;;;OAIG;IACH,mBAAmB,CAAC,CAAC,SAAS,MAAM,eAAe,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,IAAI;IAIjH;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,IAAI;IAS7C;;;;;;;OAOG;IACH,OAAO,CAAC,wBAAwB;CAMjC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if two URLs have the same `.href` property. The URLS can be
|
|
3
|
+
* relative, and if they are the current location href is used to resolve URLs.
|
|
4
|
+
*
|
|
5
|
+
* @private
|
|
6
|
+
* @param url1
|
|
7
|
+
* @param url2
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function urlsMatch(url1: string, url2: string): boolean;
|
|
11
|
+
//# sourceMappingURL=urlsMatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlsMatch.d.ts","sourceRoot":"","sources":["../../src/utils/urlsMatch.ts"],"names":[],"mappings":"AAQA;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAG7D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@serwist/window",
|
|
3
|
+
"version": "8.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Simplifies communications with Serwist packages running in the service worker",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"serwist",
|
|
8
|
+
"serwistjs",
|
|
9
|
+
"service worker",
|
|
10
|
+
"sw",
|
|
11
|
+
"window",
|
|
12
|
+
"message",
|
|
13
|
+
"postMessage"
|
|
14
|
+
],
|
|
15
|
+
"author": "Google's Web DevRel Team, Serwist's Team",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": "serwist/serwist",
|
|
18
|
+
"bugs": "https://github.com/serwist/serwist/issues",
|
|
19
|
+
"homepage": "https://ducanh-next-pwa.vercel.app",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"main": "./dist/index.old.cjs",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.old.cjs",
|
|
27
|
+
"types": "./dist/index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@types/trusted-types": "2.0.4",
|
|
33
|
+
"@serwist/core": "8.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"rollup": "3.28.1",
|
|
37
|
+
"@serwist/constants": "8.0.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
|
|
41
|
+
"lint": "eslint src --ext ts,tsx,js,jsx,cjs,mjs",
|
|
42
|
+
"typecheck": "tsc"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { getRollupOptions } from "@serwist/constants/rollup";
|
|
3
|
+
|
|
4
|
+
import packageJson from "./package.json" assert { type: "json" };
|
|
5
|
+
|
|
6
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
7
|
+
|
|
8
|
+
export default getRollupOptions({
|
|
9
|
+
packageJson,
|
|
10
|
+
jsFiles: [
|
|
11
|
+
{
|
|
12
|
+
input: "src/index.ts",
|
|
13
|
+
output: [
|
|
14
|
+
{
|
|
15
|
+
file: "dist/index.old.cjs",
|
|
16
|
+
format: "cjs",
|
|
17
|
+
exports: "named",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
file: "dist/index.js",
|
|
21
|
+
format: "esm",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
shouldEmitDeclaration: !isDev,
|
|
27
|
+
});
|