crelte 0.4.7 → 0.5.0-alpha.1

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.
Files changed (110) hide show
  1. package/dist/Crelte.d.ts +7 -6
  2. package/dist/Crelte.d.ts.map +1 -1
  3. package/dist/Crelte.js +5 -13
  4. package/dist/CrelteRequest.d.ts +9 -0
  5. package/dist/CrelteRequest.d.ts.map +1 -1
  6. package/dist/CrelteRequest.js +16 -2
  7. package/dist/blocks/Blocks.svelte +2 -2
  8. package/dist/blocks/Blocks.svelte.d.ts +3 -19
  9. package/dist/blocks/Blocks.svelte.d.ts.map +1 -1
  10. package/dist/cookies/ClientCookies.d.ts +0 -1
  11. package/dist/cookies/ClientCookies.d.ts.map +1 -1
  12. package/dist/cookies/ClientCookies.js +0 -1
  13. package/dist/cookies/ServerCookies.d.ts +1 -2
  14. package/dist/cookies/ServerCookies.d.ts.map +1 -1
  15. package/dist/cookies/ServerCookies.js +2 -6
  16. package/dist/cookies/index.d.ts +0 -2
  17. package/dist/cookies/index.d.ts.map +1 -1
  18. package/dist/graphql/GraphQl.d.ts +2 -2
  19. package/dist/graphql/GraphQl.d.ts.map +1 -1
  20. package/dist/index.d.ts +9 -3
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +14 -6
  23. package/dist/init/InternalApp.d.ts +30 -0
  24. package/dist/init/InternalApp.d.ts.map +1 -0
  25. package/dist/init/InternalApp.js +71 -0
  26. package/dist/init/client.d.ts +0 -5
  27. package/dist/init/client.d.ts.map +1 -1
  28. package/dist/init/client.js +88 -75
  29. package/dist/init/crelte-vite-plugin.d.ts +5 -0
  30. package/dist/init/server.d.ts +0 -5
  31. package/dist/init/server.d.ts.map +1 -1
  32. package/dist/init/server.js +50 -20
  33. package/dist/init/shared.d.ts +7 -18
  34. package/dist/init/shared.d.ts.map +1 -1
  35. package/dist/init/shared.js +97 -154
  36. package/dist/init/svelteComponents.d.ts +3 -0
  37. package/dist/init/svelteComponents.d.ts.map +1 -0
  38. package/dist/init/svelteComponents.js +7 -0
  39. package/dist/loadData/Globals.d.ts +40 -33
  40. package/dist/loadData/Globals.d.ts.map +1 -1
  41. package/dist/loadData/Globals.js +99 -88
  42. package/dist/loadData/index.d.ts +3 -2
  43. package/dist/loadData/index.d.ts.map +1 -1
  44. package/dist/loadData/index.js +2 -0
  45. package/dist/plugins/Events.d.ts +11 -13
  46. package/dist/plugins/Events.d.ts.map +1 -1
  47. package/dist/plugins/Events.js +10 -3
  48. package/dist/routing/BaseRoute.d.ts +255 -0
  49. package/dist/routing/BaseRoute.d.ts.map +1 -0
  50. package/dist/routing/BaseRoute.js +349 -0
  51. package/dist/routing/BaseRouter.d.ts +210 -0
  52. package/dist/routing/BaseRouter.d.ts.map +1 -0
  53. package/dist/routing/BaseRouter.js +444 -0
  54. package/dist/routing/ClientRouter.d.ts +32 -0
  55. package/dist/routing/ClientRouter.d.ts.map +1 -0
  56. package/dist/routing/ClientRouter.js +259 -0
  57. package/dist/routing/LoadRunner.d.ts +39 -0
  58. package/dist/routing/LoadRunner.d.ts.map +1 -0
  59. package/dist/routing/{PageLoader.js → LoadRunner.js} +32 -20
  60. package/dist/routing/Request.d.ts +35 -3
  61. package/dist/routing/Request.d.ts.map +1 -1
  62. package/dist/routing/Request.js +64 -5
  63. package/dist/routing/Route.d.ts +24 -223
  64. package/dist/routing/Route.d.ts.map +1 -1
  65. package/dist/routing/Route.js +26 -315
  66. package/dist/routing/Router.d.ts +49 -73
  67. package/dist/routing/Router.d.ts.map +1 -1
  68. package/dist/routing/Router.js +85 -251
  69. package/dist/routing/ServerRouter.d.ts +23 -0
  70. package/dist/routing/ServerRouter.d.ts.map +1 -0
  71. package/dist/routing/ServerRouter.js +57 -0
  72. package/dist/routing/utils.d.ts +5 -0
  73. package/dist/routing/utils.d.ts.map +1 -1
  74. package/dist/routing/utils.js +39 -0
  75. package/dist/utils.d.ts +1 -0
  76. package/dist/utils.d.ts.map +1 -1
  77. package/dist/utils.js +3 -0
  78. package/package.json +6 -5
  79. package/src/Crelte.ts +12 -18
  80. package/src/CrelteRequest.ts +21 -2
  81. package/src/cookies/ClientCookies.ts +0 -2
  82. package/src/cookies/ServerCookies.ts +2 -7
  83. package/src/cookies/index.ts +0 -3
  84. package/src/graphql/GraphQl.ts +2 -1
  85. package/src/index.ts +17 -9
  86. package/src/init/InternalApp.ts +134 -0
  87. package/src/init/client.ts +104 -93
  88. package/src/init/crelte-vite-plugin.d.ts +5 -0
  89. package/src/init/server.ts +70 -35
  90. package/src/init/shared.ts +107 -227
  91. package/src/init/svelteComponents.ts +12 -0
  92. package/src/loadData/Globals.ts +121 -102
  93. package/src/loadData/index.ts +3 -2
  94. package/src/plugins/Events.ts +40 -42
  95. package/src/routing/BaseRoute.ts +422 -0
  96. package/src/routing/BaseRouter.ts +528 -0
  97. package/src/routing/ClientRouter.ts +329 -0
  98. package/src/routing/{PageLoader.ts → LoadRunner.ts} +43 -30
  99. package/src/routing/Request.ts +97 -12
  100. package/src/routing/Route.ts +56 -376
  101. package/src/routing/Router.ts +100 -359
  102. package/src/routing/ServerRouter.ts +78 -0
  103. package/src/routing/utils.ts +53 -0
  104. package/src/utils.ts +4 -0
  105. package/dist/routing/InnerRouter.d.ts +0 -113
  106. package/dist/routing/InnerRouter.d.ts.map +0 -1
  107. package/dist/routing/InnerRouter.js +0 -417
  108. package/dist/routing/PageLoader.d.ts +0 -36
  109. package/dist/routing/PageLoader.d.ts.map +0 -1
  110. package/src/routing/InnerRouter.ts +0 -498
@@ -27,6 +27,8 @@ export async function callLoadData(ld, cr, arg1, ...args) {
27
27
  /**
28
28
  * Spread the data of two loadData functions.
29
29
  *
30
+ * Prefer to use the array syntax.
31
+ *
30
32
  * ## Example
31
33
  * ```
32
34
  * export const loadData = mergeLoadData(
@@ -1,21 +1,23 @@
1
- import { EntryQueryVars } from '../entry/index.js';
2
1
  import { CrelteRequest, Entry } from '../index.js';
2
+ import { Route } from '../routing/index.js';
3
3
  export default class Events {
4
4
  inner: Map<string, Set<any>>;
5
5
  constructor();
6
6
  /**
7
7
  * Listens for an event.
8
8
  *
9
+ * ## beforeRequest
10
+ * Please prefer to return not return a promise only if you need to wait
11
+ * for something. This allows a push request to be done without a microtask.
12
+ * Allowing for a better DX.
13
+ *
9
14
  * @returns a function to remove the listener
10
15
  */
16
+ on(ev: 'beforeRequest', fn: (cr: CrelteRequest) => Promise<void> | void): () => void;
11
17
  on(ev: 'loadGlobalData', fn: (cr: CrelteRequest) => Promise<any>): () => void;
18
+ on(ev: 'afterLoadEntry', fn: (cr: CrelteRequest) => Promise<any>): () => void;
12
19
  on(ev: 'loadData', fn: (cr: CrelteRequest, entry: Entry) => Promise<any>): () => void;
13
20
  on(ev: 'beforeRender', fn: (cr: CrelteRequest) => void): () => void;
14
- on(ev: 'beforeQueryEntry', fn: (cr: CrelteRequest, vars: EntryQueryVars) => Promise<void> | void): () => void;
15
- on(ev: 'queryEntry', fn: (cr: CrelteRequest, vars: EntryQueryVars | null,
16
- /** this might contain other plugin calls */
17
- runQuery: (vars: EntryQueryVars | null) => Promise<Entry | null>) => Promise<Entry | null>): () => void;
18
- on(ev: 'afterQueryEntry', fn: (cr: CrelteRequest, entry: Entry) => Promise<void> | void): () => void;
19
21
  /**
20
22
  * Remove a listener
21
23
  */
@@ -27,14 +29,10 @@ export default class Events {
27
29
  /**
28
30
  * Trigger an event
29
31
  */
32
+ trigger(ev: 'beforeRequest', cr: CrelteRequest): (Promise<void> | void)[];
30
33
  trigger(ev: 'loadGlobalData', cr: CrelteRequest): Promise<any>[];
34
+ trigger(ev: 'afterLoadEntry', cr: CrelteRequest): Promise<any>[];
31
35
  trigger(ev: 'loadData', cr: CrelteRequest, entry: Entry): Promise<any>[];
32
- trigger(ev: 'beforeRender', cr: CrelteRequest): void[];
33
- trigger(ev: 'beforeQueryEntry', cr: CrelteRequest, vars: EntryQueryVars): void[];
34
- trigger(ev: 'afterQueryEntry', cr: CrelteRequest, entry: Entry): Promise<void>[];
35
- /**
36
- * Get all listeners for an event
37
- */
38
- getListeners(ev: 'queryEntry'): ((cr: CrelteRequest, vars: EntryQueryVars | null, runQuery: (vars: EntryQueryVars | null) => Promise<Entry | null>) => Promise<Entry | null>)[];
36
+ trigger(ev: 'beforeRender', cr: CrelteRequest, route: Route): void[];
39
37
  }
40
38
  //# sourceMappingURL=Events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Events.d.ts","sourceRoot":"","sources":["../../src/plugins/Events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,CAAC,OAAO,OAAO,MAAM;IAC1B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;;IAM7B;;;;OAIG;IAEH,EAAE,CACD,EAAE,EAAE,gBAAgB,EACpB,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,KAAK,OAAO,CAAC,GAAG,CAAC,GACrC,MAAM,IAAI;IACb,EAAE,CACD,EAAE,EAAE,UAAU,EACd,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,GAAG,CAAC,GACnD,MAAM,IAAI;IACb,EAAE,CAAC,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI;IACnE,EAAE,CACD,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GACnE,MAAM,IAAI;IACb,EAAE,CACD,EAAE,EAAE,YAAY,EAChB,EAAE,EAAE,CACH,EAAE,EAAE,aAAa,EACjB,IAAI,EAAE,cAAc,GAAG,IAAI;IAC3B,4CAA4C;I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O,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE;IACzE,OAAO,CAAC,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE;IAChE,OAAO,CAAC,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE;IAChE,OAAO,CAAC,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE;IACxE,OAAO,CAAC,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE;CAqBpE"}
@@ -3,6 +3,16 @@ export default class Events {
3
3
  constructor() {
4
4
  this.inner = new Map();
5
5
  }
6
+ // todo maybe add this
7
+ // on(
8
+ // ev: 'loadEntry',
9
+ // fn: (
10
+ // cr: CrelteRequest,
11
+ // vars: EntryQueryVars | null,
12
+ // /** this might contain other plugin calls */
13
+ // runQuery: (vars: EntryQueryVars | null) => Promise<Entry | null>,
14
+ // ) => Promise<Entry | null>,
15
+ // ): () => void;
6
16
  on(ev, fn) {
7
17
  let set = this.inner.get(ev);
8
18
  if (!set) {
@@ -36,7 +46,4 @@ export default class Events {
36
46
  return [];
37
47
  return Array.from(set).map(fn => fn(...args));
38
48
  }
39
- getListeners(ev) {
40
- return Array.from(this.inner.get(ev) ?? []);
41
- }
42
49
  }
@@ -0,0 +1,255 @@
1
+ import Site from './Site.js';
2
+ export type BaseRouteOptions = {
3
+ scrollY?: number;
4
+ index?: number;
5
+ origin?: RouteOrigin;
6
+ state?: Record<string, any>;
7
+ context?: Record<string, any>;
8
+ };
9
+ /**
10
+ * RouteOrigin represents the origin of a route.
11
+ * This type is non-exhaustive and might expand in the future.
12
+ *
13
+ * - `'init'`: is set on the first page load
14
+ * - `'manual'`: is set when a route is triggered manually via `Router.open`
15
+ * - `'click'`: is set when a route is triggered by a click event
16
+ * - `'pop'`: is set when a route is triggered by a popstate event (back/forward)
17
+ * - `'replace'`: is set when a route is replaced via `Router.replaceState`
18
+ * - `'push'`: is set when a route is pushed via `Router.pushState`
19
+ *
20
+ * ## Note
21
+ * `replace` and `push` will not call loadData
22
+ */
23
+ export type RouteOrigin = 'init' | 'manual' | 'click' | 'pop' | 'replace' | 'push';
24
+ /**
25
+ * A Route contains information about the current page for example the url and
26
+ * the site
27
+ */
28
+ export default class BaseRoute {
29
+ /**
30
+ * The url of the route
31
+ */
32
+ url: URL;
33
+ /**
34
+ * The site of the route
35
+ *
36
+ * ## Note
37
+ * The site might not always match with the current route
38
+ * but be the site default site or one that matches the
39
+ * users language.
40
+ *
41
+ * If that is important call `route.siteMatches()` to verify
42
+ */
43
+ site: Site;
44
+ /**
45
+ * The scroll position of the current route
46
+ *
47
+ * ## Note
48
+ * This does not have to represent the current scroll position
49
+ * should more be used internally.
50
+ *
51
+ * It might be useful for a new request to specify the wanted
52
+ * scroll position
53
+ */
54
+ scrollY: number | null;
55
+ /**
56
+ * the position in the browser history of this route
57
+ * this allows to find out if we can go back
58
+ */
59
+ index: number;
60
+ /**
61
+ * The origin of this route, See [[RouteOrigin]]
62
+ */
63
+ origin: RouteOrigin;
64
+ /**
65
+ * @hidden
66
+ * State data that can be used to store additional information
67
+ */
68
+ _state: Record<string, any>;
69
+ /**
70
+ * @hidden
71
+ * Any data that should be passed to onRoute and onRequest handlers
72
+ * or exchanged between loadData's
73
+ * This context is not persistant and should be considered "valid"
74
+ * only for the current request / route
75
+ *
76
+ * ## Note
77
+ * Consider using state instead. This will not be cloned in the clone
78
+ * call so will always be the same object
79
+ */
80
+ _context: Record<string, any>;
81
+ /**
82
+ * Creates a new Route
83
+ */
84
+ constructor(url: string | URL, site: Site, opts?: BaseRouteOptions);
85
+ /**
86
+ * Returns the uri of the route
87
+ *
88
+ * Never ends with a slash
89
+ *
90
+ * ## Example
91
+ * ```
92
+ * const site = _; // site with url https://example.com/fo
93
+ * const route = new Route('https://example.com/foo/bar/', site);
94
+ * console.log(route.uri); // '/bar'
95
+ *
96
+ * const site2 = _; // site with url https://example.com/other
97
+ * const route2 = new Route('https://example.com/foo/bar/?a=1', site2);
98
+ * console.log(route2.uri); // '/foo/bar'
99
+ * ```
100
+ */
101
+ get uri(): string;
102
+ /**
103
+ * Returns the base url of the route
104
+ *
105
+ * Never ends with a slash
106
+ *
107
+ * ## Example
108
+ * ```
109
+ * const site = _; // site with url https://example.com/foo
110
+ * const route = new Route('https://example.com/foo/bar/', null);
111
+ * console.log(route.baseUrl); // 'https://example.com/foo'
112
+ *
113
+ * const site2 = _; // site with url https://example.com/other
114
+ * const route2 = new Route('https://example.com/foo/bar/', site2);
115
+ * console.log(route2.baseUrl); // 'https://example.com'
116
+ * ```
117
+ */
118
+ get baseUrl(): string;
119
+ /**
120
+ * Returns the search params
121
+ *
122
+ * ## Note
123
+ * You might also have a look at `getSearchParam` and `setSearchParam`
124
+ *
125
+ * ## Example
126
+ * ```
127
+ * const route = new Route('https://example.com/foo/bar/?a=1&b=2', null);
128
+ * console.log(route.search.get('a')); // '1'
129
+ * ```
130
+ */
131
+ get search(): URLSearchParams;
132
+ /**
133
+ * Returns the hash of the route
134
+ *
135
+ * ## Example
136
+ * ```
137
+ * const route = new Route('https://example.com/foo/bar/#hash', null);
138
+ * console.log(route.hash); // '#hash'
139
+ * ```
140
+ */
141
+ get hash(): string;
142
+ /**
143
+ * Set the hash of the route
144
+ *
145
+ * ## Example
146
+ * ```
147
+ * const route = new Route('https://example.com/foo/bar/', null);
148
+ * route.hash = '#hash';
149
+ * console.log(route.url.href); // 'https://example.com/foo/bar/#hash'
150
+ * ```
151
+ */
152
+ set hash(hash: string);
153
+ /**
154
+ * Checks if there are previous routes which would allow it to go back
155
+ */
156
+ canGoBack(): boolean;
157
+ /**
158
+ * Gets the search param
159
+ *
160
+ * ## Example
161
+ * ```
162
+ * const route = new Route('https://example.com/foo/bar/?a=1&b=2', null);
163
+ * console.log(route.getSearchParam('a')); // '1'
164
+ * ```
165
+ */
166
+ getSearchParam(key: string): string | null;
167
+ /**
168
+ * Sets the search param or removes it if the value is null, undefined or an
169
+ * empty string
170
+ *
171
+ * ## Example
172
+ * ```
173
+ * const route = new Route('https://example.com/foo/bar/?a=1&b=2', null);
174
+ * route.setSearchParam('a', '3');
175
+ * console.log(route.url.href); // 'https://example.com/foo/bar/?a=3&b=2'
176
+ *
177
+ * route.setSearchParam('a', null);
178
+ * console.log(route.url.href); // 'https://example.com/foo/bar/?b=2'
179
+ * ```
180
+ */
181
+ setSearchParam(key: string, value?: string | number | null): void;
182
+ /**
183
+ * Returns a state value if it exists.
184
+ */
185
+ getState<T = any>(key: string): T | null;
186
+ /**
187
+ * Sets a state value.
188
+ * If the value is null or undefined, the key will be removed.
189
+ *
190
+ * ## When to use state
191
+ * State is used to store additional information that persists across route changes.
192
+ * The State is only available in the client code since it is stored using window.history.
193
+ *
194
+ * Consider using setSearchParam instead to enable server side rendering.
195
+ */
196
+ setState<T>(key: string, value: T | null | undefined): void;
197
+ /**
198
+ * Returns a context value if it exists.
199
+ */
200
+ getContext<T = any>(key: string): T | null;
201
+ /**
202
+ * Sets a context value.
203
+ * If the value is null or undefined, the key will be removed.
204
+ *
205
+ * ## When to use context
206
+ * Context is used to pass data to onRoute and onRequest handlers or exchange data between loadData calls.
207
+ * This context is not persistent and should be considered valid only for the current request/route.
208
+ * The context is not cloned in the clone call and will be the same object.
209
+ */
210
+ setContext<T>(key: string, value: T | null | undefined): void;
211
+ /**
212
+ * Returns true if the route is in live preview mode
213
+ */
214
+ inLivePreview(): boolean;
215
+ /**
216
+ * Returns if the site matches the url
217
+ */
218
+ siteMatches(): boolean;
219
+ /**
220
+ * Checks if the route is equal to another route
221
+ *
222
+ * This checks the url but search params do not have to be in the
223
+ * same order
224
+ *
225
+ * ## Note
226
+ * This only check the url, not site or anything else.
227
+ */
228
+ eq(route: BaseRoute | null): boolean | null;
229
+ /**
230
+ * Checks if the route is equal to another route
231
+ *
232
+ * This does not check the search params or hash
233
+ */
234
+ eqUrl(route: BaseRoute | null): boolean | null;
235
+ /**
236
+ * Checks if the search params are equal to another route
237
+ */
238
+ eqSearch(route: BaseRoute | null): boolean | null;
239
+ /**
240
+ * Checks if the hash is equal to another route
241
+ */
242
+ eqHash(route: BaseRoute | null): boolean | null;
243
+ /**
244
+ * Create a copy of the Route
245
+ *
246
+ * ## Note
247
+ * This does not make a copy of the template or context
248
+ */
249
+ clone(): BaseRoute;
250
+ /** @hidden */
251
+ _fillFromState(state: any): void;
252
+ /** @hidden */
253
+ _toState(): any;
254
+ }
255
+ //# sourceMappingURL=BaseRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseRoute.d.ts","sourceRoot":"","sources":["../../src/routing/BaseRoute.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,MAAM,gBAAgB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,WAAW,GACpB,MAAM,GACN,QAAQ,GACR,OAAO,GACP,KAAK,GACL,SAAS,GACT,MAAM,CAAC;AAEV;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC7B;;OAEG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;;;;;;;;OASG;IACH,IAAI,EAAE,IAAI,CAAC;IAEX;;;;;;;;;OASG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IA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