@wcstack/router 1.5.2 → 1.6.3

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/dist/index.d.ts CHANGED
@@ -1,3 +1,12 @@
1
+ interface ITagNames {
2
+ readonly route: string;
3
+ readonly router: string;
4
+ readonly outlet: string;
5
+ readonly layout: string;
6
+ readonly layoutOutlet: string;
7
+ readonly link: string;
8
+ readonly head: string;
9
+ }
1
10
  interface IWritableTagNames {
2
11
  route?: string;
3
12
  router?: string;
@@ -7,6 +16,11 @@ interface IWritableTagNames {
7
16
  link?: string;
8
17
  head?: string;
9
18
  }
19
+ interface IConfig {
20
+ readonly tagNames: ITagNames;
21
+ readonly enableShadowRoot: boolean;
22
+ readonly basenameFileExtensions: ReadonlyArray<string>;
23
+ }
10
24
  interface IWritableConfig {
11
25
  tagNames?: IWritableTagNames;
12
26
  enableShadowRoot?: boolean;
@@ -31,6 +45,8 @@ interface IWcBindable {
31
45
  */
32
46
  declare function bootstrapRouter(config?: Partial<IWritableConfig>): void;
33
47
 
48
+ declare function getConfig(): IConfig;
49
+
34
50
  interface IRouteMatchResult {
35
51
  routes: IRoute[];
36
52
  params: Record<string, string>;
@@ -154,5 +170,5 @@ declare class RouteCore extends EventTarget {
154
170
  guardCheck(matchResult: IRouteMatchResult): Promise<void>;
155
171
  }
156
172
 
157
- export { RouteCore, bootstrapRouter };
173
+ export { RouteCore, bootstrapRouter, getConfig };
158
174
  export type { IWritableConfig, IWritableTagNames, RouteParseOptions };
package/dist/index.esm.js CHANGED
@@ -11,8 +11,33 @@ const _config = {
11
11
  enableShadowRoot: false,
12
12
  basenameFileExtensions: [".html"]
13
13
  };
14
+ function deepFreeze(obj) {
15
+ if (obj === null || typeof obj !== "object")
16
+ return obj;
17
+ Object.freeze(obj);
18
+ for (const key of Object.keys(obj)) {
19
+ deepFreeze(obj[key]);
20
+ }
21
+ return obj;
22
+ }
23
+ function deepClone(obj) {
24
+ if (obj === null || typeof obj !== "object")
25
+ return obj;
26
+ const clone = {};
27
+ for (const key of Object.keys(obj)) {
28
+ clone[key] = deepClone(obj[key]);
29
+ }
30
+ return clone;
31
+ }
32
+ let frozenConfig = null;
14
33
  // 後方互換のため config もエクスポート(読み取り専用として使用)
15
34
  const config = _config;
35
+ function getConfig() {
36
+ if (!frozenConfig) {
37
+ frozenConfig = deepFreeze(deepClone(_config));
38
+ }
39
+ return frozenConfig;
40
+ }
16
41
  function setConfig(partialConfig) {
17
42
  if (partialConfig.tagNames) {
18
43
  Object.assign(_config.tagNames, partialConfig.tagNames);
@@ -23,6 +48,7 @@ function setConfig(partialConfig) {
23
48
  if (Array.isArray(partialConfig.basenameFileExtensions)) {
24
49
  _config.basenameFileExtensions = partialConfig.basenameFileExtensions;
25
50
  }
51
+ frozenConfig = null;
26
52
  }
27
53
 
28
54
  function getUUID() {
@@ -1806,5 +1832,5 @@ function bootstrapRouter(config) {
1806
1832
  registerComponents();
1807
1833
  }
1808
1834
 
1809
- export { RouteCore, bootstrapRouter };
1835
+ export { RouteCore, bootstrapRouter, getConfig };
1810
1836
  //# sourceMappingURL=index.esm.js.map