swpp-backends 3.0.0-alpha.4 → 3.0.0-alpha.5

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RuntimeData = exports.SwCompiler = void 0;
4
4
  const CrossDepCode_1 = require("./database/CrossDepCode");
5
+ const DomCode_1 = require("./database/DomCode");
5
6
  const RuntimeCoreCode_1 = require("./database/RuntimeCoreCode");
6
7
  const RuntimeDepCode_1 = require("./database/RuntimeDepCode");
7
8
  const CrossEnv_1 = require("./database/CrossEnv");
@@ -44,6 +45,8 @@ class RuntimeData {
44
45
  this.runtimeEvent = new RuntimeEventCode_1.RuntimeEventCode();
45
46
  /** 运行时/编译时工具函数 */
46
47
  this.crossDep = new CrossDepCode_1.CrossDepCode();
48
+ /** DOM 相关设置 */
49
+ this.domConfig = new DomCode_1.DomCode();
47
50
  }
48
51
  getDatabase(key) {
49
52
  if (!(key in this))
@@ -67,7 +67,7 @@ class ConfigLoader {
67
67
  const config = this.config;
68
68
  // 写入运行时信息
69
69
  const writeRuntime = () => {
70
- const insertList = ['runtimeDep', 'runtimeCore', 'runtimeEvent'];
70
+ const insertList = ['runtimeDep', 'runtimeCore', 'runtimeEvent', 'domConfig'];
71
71
  for (let str of insertList) {
72
72
  const configValue = config[str];
73
73
  if (!configValue)
@@ -16,6 +16,7 @@ class DomCode extends RuntimeKeyValueDatabase_1.RuntimeKeyValueDatabase {
16
16
  }
17
17
  buildInnerSource() {
18
18
  const map = this.entries();
19
+ delete map['registry'];
19
20
  const inlineCode = Object.keys(map)
20
21
  .filter(it => it.startsWith('_inline'))
21
22
  .map(it => `${it}()`);
@@ -38,6 +39,19 @@ let pjaxUpdate;
38
39
  let postMessage2Sw;
39
40
  function buildCommon() {
40
41
  return {
42
+ registry: {
43
+ default: () => {
44
+ const sw = navigator.serviceWorker;
45
+ if (sw) {
46
+ sw.register('sw.js')
47
+ .then(() => console.log('SWPP 注册成功'))
48
+ .catch(err => console.error('SWPP 注册失败', err));
49
+ }
50
+ else {
51
+ console.warn('当前浏览器不支持 SW');
52
+ }
53
+ }
54
+ },
41
55
  postMessage2Sw: {
42
56
  default: (type) => controller.postMessage(type)
43
57
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.5",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",
@@ -1,5 +1,6 @@
1
1
  import { CompilationEnv } from './database/CompilationEnv';
2
2
  import { CrossDepCode } from './database/CrossDepCode';
3
+ import { DomCode } from './database/DomCode';
3
4
  import { RuntimeCoreCode } from './database/RuntimeCoreCode';
4
5
  import { RuntimeDepCode } from './database/RuntimeDepCode';
5
6
  import { CrossEnv } from './database/CrossEnv';
@@ -15,17 +16,19 @@ export declare class SwCompiler {
15
16
  /** 运行时数据 */
16
17
  export declare class RuntimeData {
17
18
  /** 控制插入顺序 */
18
- readonly insertOrder: (Exclude<keyof RuntimeData, 'insertOrder'> | string)[];
19
+ readonly insertOrder: (Exclude<keyof RuntimeData, 'insertOrder' | 'domConfig'> | string)[];
19
20
  /** 运行时环境变量 */
20
- readonly crossEnv: CrossEnv;
21
+ crossEnv: CrossEnv;
21
22
  /** 运行时工具函数 */
22
- readonly runtimeDep: RuntimeDepCode;
23
+ runtimeDep: RuntimeDepCode;
23
24
  /** 运行时核心功能函数 */
24
- readonly runtimeCore: RuntimeCoreCode;
25
+ runtimeCore: RuntimeCoreCode;
25
26
  /** 运行时事件注册 */
26
- readonly runtimeEvent: RuntimeEventCode;
27
+ runtimeEvent: RuntimeEventCode;
27
28
  /** 运行时/编译时工具函数 */
28
- readonly crossDep: CrossDepCode;
29
+ crossDep: CrossDepCode;
30
+ /** DOM 相关设置 */
31
+ domConfig: DomCode;
29
32
  getDatabase(key: string): RuntimeKeyValueDatabase<any, {}>;
30
33
  }
31
34
  /** 编译时数据 */
@@ -6,6 +6,9 @@ export declare class DomCode extends RuntimeKeyValueDatabase<any, COMMON_TYPE_DO
6
6
  buildInnerSource(): string;
7
7
  }
8
8
  declare function buildCommon(): {
9
+ readonly registry: {
10
+ readonly default: () => void;
11
+ };
9
12
  readonly postMessage2Sw: {
10
13
  readonly default: (type: string) => void;
11
14
  };