piral-blazor 1.0.0-pre.2217 → 1.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.
Files changed (236) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +55 -12
  3. package/convert.d.ts +13 -10
  4. package/convert.js +17 -12
  5. package/esm/converter.d.ts +10 -6
  6. package/esm/converter.js +164 -48
  7. package/esm/converter.js.map +1 -1
  8. package/esm/create.d.ts +21 -1
  9. package/esm/create.js +29 -15
  10. package/esm/create.js.map +1 -1
  11. package/esm/dependencies.d.ts +6 -3
  12. package/esm/dependencies.js +104 -14
  13. package/esm/dependencies.js.map +1 -1
  14. package/esm/events.d.ts +6 -0
  15. package/esm/events.js +145 -0
  16. package/esm/events.js.map +1 -0
  17. package/esm/interop.d.ts +29 -0
  18. package/esm/interop.js +205 -0
  19. package/esm/interop.js.map +1 -0
  20. package/esm/navigation.d.ts +2 -0
  21. package/esm/navigation.js +30 -0
  22. package/esm/navigation.js.map +1 -0
  23. package/esm/types.d.ts +97 -4
  24. package/infra.codegen +53 -68
  25. package/lib/converter.d.ts +10 -6
  26. package/lib/converter.js +164 -48
  27. package/lib/converter.js.map +1 -1
  28. package/lib/create.d.ts +21 -1
  29. package/lib/create.js +31 -17
  30. package/lib/create.js.map +1 -1
  31. package/lib/dependencies.d.ts +6 -3
  32. package/lib/dependencies.js +104 -14
  33. package/lib/dependencies.js.map +1 -1
  34. package/lib/events.d.ts +6 -0
  35. package/lib/events.js +154 -0
  36. package/lib/events.js.map +1 -0
  37. package/lib/index.js +1 -1
  38. package/lib/interop.d.ts +29 -0
  39. package/lib/interop.js +226 -0
  40. package/lib/interop.js.map +1 -0
  41. package/lib/navigation.d.ts +2 -0
  42. package/lib/navigation.js +35 -0
  43. package/lib/navigation.js.map +1 -0
  44. package/lib/types.d.ts +97 -4
  45. package/package.json +26 -13
  46. package/src/converter.ts +237 -57
  47. package/src/create.ts +53 -9
  48. package/src/dependencies.ts +122 -14
  49. package/src/events.ts +174 -0
  50. package/src/interop.ts +273 -0
  51. package/src/navigation.ts +36 -0
  52. package/src/types.ts +115 -4
  53. package/convert.ts +0 -17
  54. package/esm/internal/Environment.d.ts +0 -3
  55. package/esm/internal/Environment.js +0 -6
  56. package/esm/internal/Environment.js.map +0 -1
  57. package/esm/internal/Platform/BootConfig.d.ts +0 -20
  58. package/esm/internal/Platform/BootConfig.js +0 -10
  59. package/esm/internal/Platform/BootConfig.js.map +0 -1
  60. package/esm/internal/Platform/Mono/MonoDebugger.d.ts +0 -3
  61. package/esm/internal/Platform/Mono/MonoDebugger.js +0 -43
  62. package/esm/internal/Platform/Mono/MonoDebugger.js.map +0 -1
  63. package/esm/internal/Platform/Mono/MonoPlatform.d.ts +0 -2
  64. package/esm/internal/Platform/Mono/MonoPlatform.js +0 -403
  65. package/esm/internal/Platform/Mono/MonoPlatform.js.map +0 -1
  66. package/esm/internal/Platform/Mono/TimezoneDataFile.d.ts +0 -1
  67. package/esm/internal/Platform/Mono/TimezoneDataFile.js +0 -51
  68. package/esm/internal/Platform/Mono/TimezoneDataFile.js.map +0 -1
  69. package/esm/internal/Platform/Platform.d.ts +0 -31
  70. package/esm/internal/Platform/Platform.js +0 -2
  71. package/esm/internal/Platform/Platform.js.map +0 -1
  72. package/esm/internal/Platform/Url.d.ts +0 -2
  73. package/esm/internal/Platform/Url.js +0 -11
  74. package/esm/internal/Platform/Url.js.map +0 -1
  75. package/esm/internal/Platform/WebAssemblyConfigLoader.d.ts +0 -4
  76. package/esm/internal/Platform/WebAssemblyConfigLoader.js +0 -64
  77. package/esm/internal/Platform/WebAssemblyConfigLoader.js.map +0 -1
  78. package/esm/internal/Platform/WebAssemblyResourceLoader.d.ts +0 -24
  79. package/esm/internal/Platform/WebAssemblyResourceLoader.js +0 -223
  80. package/esm/internal/Platform/WebAssemblyResourceLoader.js.map +0 -1
  81. package/esm/internal/Platform/WebAssemblyStartOptions.d.ts +0 -13
  82. package/esm/internal/Platform/WebAssemblyStartOptions.js +0 -2
  83. package/esm/internal/Platform/WebAssemblyStartOptions.js.map +0 -1
  84. package/esm/internal/Rendering/BrowserRenderer.d.ts +0 -38
  85. package/esm/internal/Rendering/BrowserRenderer.js +0 -458
  86. package/esm/internal/Rendering/BrowserRenderer.js.map +0 -1
  87. package/esm/internal/Rendering/ElementReferenceCapture.d.ts +0 -1
  88. package/esm/internal/Rendering/ElementReferenceCapture.js +0 -24
  89. package/esm/internal/Rendering/ElementReferenceCapture.js.map +0 -1
  90. package/esm/internal/Rendering/EventDelegator.d.ts +0 -20
  91. package/esm/internal/Rendering/EventDelegator.js +0 -236
  92. package/esm/internal/Rendering/EventDelegator.js.map +0 -1
  93. package/esm/internal/Rendering/EventFieldInfo.d.ts +0 -6
  94. package/esm/internal/Rendering/EventFieldInfo.js +0 -32
  95. package/esm/internal/Rendering/EventFieldInfo.js.map +0 -1
  96. package/esm/internal/Rendering/EventForDotNet.d.ts +0 -10
  97. package/esm/internal/Rendering/EventForDotNet.js +0 -194
  98. package/esm/internal/Rendering/EventForDotNet.js.map +0 -1
  99. package/esm/internal/Rendering/LogicalElements.d.ts +0 -19
  100. package/esm/internal/Rendering/LogicalElements.js +0 -250
  101. package/esm/internal/Rendering/LogicalElements.js.map +0 -1
  102. package/esm/internal/Rendering/RenderBatch/BinaryDecoder.d.ts +0 -5
  103. package/esm/internal/Rendering/RenderBatch/BinaryDecoder.js +0 -34
  104. package/esm/internal/Rendering/RenderBatch/BinaryDecoder.js.map +0 -1
  105. package/esm/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.d.ts +0 -18
  106. package/esm/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js +0 -190
  107. package/esm/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js.map +0 -1
  108. package/esm/internal/Rendering/RenderBatch/RenderBatch.d.ts +0 -87
  109. package/esm/internal/Rendering/RenderBatch/RenderBatch.js +0 -26
  110. package/esm/internal/Rendering/RenderBatch/RenderBatch.js.map +0 -1
  111. package/esm/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.d.ts +0 -52
  112. package/esm/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js +0 -103
  113. package/esm/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js.map +0 -1
  114. package/esm/internal/Rendering/RenderBatch/Utf8Decoder.d.ts +0 -1
  115. package/esm/internal/Rendering/RenderBatch/Utf8Decoder.js +0 -63
  116. package/esm/internal/Rendering/RenderBatch/Utf8Decoder.js.map +0 -1
  117. package/esm/internal/Rendering/Renderer.d.ts +0 -8
  118. package/esm/internal/Rendering/Renderer.js +0 -69
  119. package/esm/internal/Rendering/Renderer.js.map +0 -1
  120. package/esm/internal/Rendering/RendererEventDispatcher.d.ts +0 -4
  121. package/esm/internal/Rendering/RendererEventDispatcher.js +0 -11
  122. package/esm/internal/Rendering/RendererEventDispatcher.js.map +0 -1
  123. package/esm/internal/Services/NavigationManager.d.ts +0 -16
  124. package/esm/internal/Services/NavigationManager.js +0 -138
  125. package/esm/internal/Services/NavigationManager.js.map +0 -1
  126. package/esm/internal/globals.d.ts +0 -1
  127. package/esm/internal/globals.js +0 -5
  128. package/esm/internal/globals.js.map +0 -1
  129. package/esm/internal/index.d.ts +0 -15
  130. package/esm/internal/index.js +0 -152
  131. package/esm/internal/index.js.map +0 -1
  132. package/lib/internal/Environment.d.ts +0 -3
  133. package/lib/internal/Environment.js +0 -9
  134. package/lib/internal/Environment.js.map +0 -1
  135. package/lib/internal/Platform/BootConfig.d.ts +0 -20
  136. package/lib/internal/Platform/BootConfig.js +0 -13
  137. package/lib/internal/Platform/BootConfig.js.map +0 -1
  138. package/lib/internal/Platform/Mono/MonoDebugger.d.ts +0 -3
  139. package/lib/internal/Platform/Mono/MonoDebugger.js +0 -48
  140. package/lib/internal/Platform/Mono/MonoDebugger.js.map +0 -1
  141. package/lib/internal/Platform/Mono/MonoPlatform.d.ts +0 -2
  142. package/lib/internal/Platform/Mono/MonoPlatform.js +0 -406
  143. package/lib/internal/Platform/Mono/MonoPlatform.js.map +0 -1
  144. package/lib/internal/Platform/Mono/TimezoneDataFile.d.ts +0 -1
  145. package/lib/internal/Platform/Mono/TimezoneDataFile.js +0 -55
  146. package/lib/internal/Platform/Mono/TimezoneDataFile.js.map +0 -1
  147. package/lib/internal/Platform/Platform.d.ts +0 -31
  148. package/lib/internal/Platform/Platform.js +0 -3
  149. package/lib/internal/Platform/Platform.js.map +0 -1
  150. package/lib/internal/Platform/Url.d.ts +0 -2
  151. package/lib/internal/Platform/Url.js +0 -16
  152. package/lib/internal/Platform/Url.js.map +0 -1
  153. package/lib/internal/Platform/WebAssemblyConfigLoader.d.ts +0 -4
  154. package/lib/internal/Platform/WebAssemblyConfigLoader.js +0 -67
  155. package/lib/internal/Platform/WebAssemblyConfigLoader.js.map +0 -1
  156. package/lib/internal/Platform/WebAssemblyResourceLoader.d.ts +0 -24
  157. package/lib/internal/Platform/WebAssemblyResourceLoader.js +0 -226
  158. package/lib/internal/Platform/WebAssemblyResourceLoader.js.map +0 -1
  159. package/lib/internal/Platform/WebAssemblyStartOptions.d.ts +0 -13
  160. package/lib/internal/Platform/WebAssemblyStartOptions.js +0 -3
  161. package/lib/internal/Platform/WebAssemblyStartOptions.js.map +0 -1
  162. package/lib/internal/Rendering/BrowserRenderer.d.ts +0 -38
  163. package/lib/internal/Rendering/BrowserRenderer.js +0 -461
  164. package/lib/internal/Rendering/BrowserRenderer.js.map +0 -1
  165. package/lib/internal/Rendering/ElementReferenceCapture.d.ts +0 -1
  166. package/lib/internal/Rendering/ElementReferenceCapture.js +0 -28
  167. package/lib/internal/Rendering/ElementReferenceCapture.js.map +0 -1
  168. package/lib/internal/Rendering/EventDelegator.d.ts +0 -20
  169. package/lib/internal/Rendering/EventDelegator.js +0 -239
  170. package/lib/internal/Rendering/EventDelegator.js.map +0 -1
  171. package/lib/internal/Rendering/EventFieldInfo.d.ts +0 -6
  172. package/lib/internal/Rendering/EventFieldInfo.js +0 -35
  173. package/lib/internal/Rendering/EventFieldInfo.js.map +0 -1
  174. package/lib/internal/Rendering/EventForDotNet.d.ts +0 -10
  175. package/lib/internal/Rendering/EventForDotNet.js +0 -197
  176. package/lib/internal/Rendering/EventForDotNet.js.map +0 -1
  177. package/lib/internal/Rendering/LogicalElements.d.ts +0 -19
  178. package/lib/internal/Rendering/LogicalElements.js +0 -265
  179. package/lib/internal/Rendering/LogicalElements.js.map +0 -1
  180. package/lib/internal/Rendering/RenderBatch/BinaryDecoder.d.ts +0 -5
  181. package/lib/internal/Rendering/RenderBatch/BinaryDecoder.js +0 -42
  182. package/lib/internal/Rendering/RenderBatch/BinaryDecoder.js.map +0 -1
  183. package/lib/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.d.ts +0 -18
  184. package/lib/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js +0 -193
  185. package/lib/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js.map +0 -1
  186. package/lib/internal/Rendering/RenderBatch/RenderBatch.d.ts +0 -87
  187. package/lib/internal/Rendering/RenderBatch/RenderBatch.js +0 -29
  188. package/lib/internal/Rendering/RenderBatch/RenderBatch.js.map +0 -1
  189. package/lib/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.d.ts +0 -52
  190. package/lib/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js +0 -106
  191. package/lib/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js.map +0 -1
  192. package/lib/internal/Rendering/RenderBatch/Utf8Decoder.d.ts +0 -1
  193. package/lib/internal/Rendering/RenderBatch/Utf8Decoder.js +0 -66
  194. package/lib/internal/Rendering/RenderBatch/Utf8Decoder.js.map +0 -1
  195. package/lib/internal/Rendering/Renderer.d.ts +0 -8
  196. package/lib/internal/Rendering/Renderer.js +0 -76
  197. package/lib/internal/Rendering/Renderer.js.map +0 -1
  198. package/lib/internal/Rendering/RendererEventDispatcher.d.ts +0 -4
  199. package/lib/internal/Rendering/RendererEventDispatcher.js +0 -16
  200. package/lib/internal/Rendering/RendererEventDispatcher.js.map +0 -1
  201. package/lib/internal/Services/NavigationManager.d.ts +0 -16
  202. package/lib/internal/Services/NavigationManager.js +0 -144
  203. package/lib/internal/Services/NavigationManager.js.map +0 -1
  204. package/lib/internal/globals.d.ts +0 -1
  205. package/lib/internal/globals.js +0 -7
  206. package/lib/internal/globals.js.map +0 -1
  207. package/lib/internal/index.d.ts +0 -15
  208. package/lib/internal/index.js +0 -161
  209. package/lib/internal/index.js.map +0 -1
  210. package/src/internal/Environment.ts +0 -11
  211. package/src/internal/Platform/BootConfig.ts +0 -21
  212. package/src/internal/Platform/Mono/MonoDebugger.ts +0 -48
  213. package/src/internal/Platform/Mono/MonoPlatform.ts +0 -494
  214. package/src/internal/Platform/Mono/MonoTypes.d.ts +0 -27
  215. package/src/internal/Platform/Mono/TimezoneDataFile.ts +0 -46
  216. package/src/internal/Platform/Platform.ts +0 -40
  217. package/src/internal/Platform/Url.ts +0 -11
  218. package/src/internal/Platform/WebAssemblyConfigLoader.ts +0 -34
  219. package/src/internal/Platform/WebAssemblyResourceLoader.ts +0 -234
  220. package/src/internal/Platform/WebAssemblyStartOptions.ts +0 -22
  221. package/src/internal/Rendering/BrowserRenderer.ts +0 -616
  222. package/src/internal/Rendering/ElementReferenceCapture.ts +0 -27
  223. package/src/internal/Rendering/EventDelegator.ts +0 -293
  224. package/src/internal/Rendering/EventFieldInfo.ts +0 -31
  225. package/src/internal/Rendering/EventForDotNet.ts +0 -370
  226. package/src/internal/Rendering/LogicalElements.ts +0 -289
  227. package/src/internal/Rendering/RenderBatch/BinaryDecoder.ts +0 -43
  228. package/src/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.ts +0 -244
  229. package/src/internal/Rendering/RenderBatch/RenderBatch.ts +0 -100
  230. package/src/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.ts +0 -137
  231. package/src/internal/Rendering/RenderBatch/Utf8Decoder.ts +0 -66
  232. package/src/internal/Rendering/Renderer.ts +0 -98
  233. package/src/internal/Rendering/RendererEventDispatcher.ts +0 -20
  234. package/src/internal/Services/NavigationManager.ts +0 -157
  235. package/src/internal/globals.ts +0 -5
  236. package/src/internal/index.ts +0 -170
@@ -1,234 +0,0 @@
1
- import { toAbsoluteUri } from '../Services/NavigationManager';
2
- import { BootJsonData, ResourceList } from './BootConfig';
3
- import { WebAssemblyStartOptions, WebAssemblyBootResourceType } from './WebAssemblyStartOptions';
4
-
5
- const networkFetchCacheMode = 'no-cache';
6
-
7
- export class WebAssemblyResourceLoader {
8
- private usedCacheKeys: { [key: string]: boolean } = {};
9
- private networkLoads: { [name: string]: LoadLogEntry } = {};
10
- private cacheLoads: { [name: string]: LoadLogEntry } = {};
11
-
12
- static async initAsync(
13
- bootConfig: BootJsonData,
14
- startOptions: Partial<WebAssemblyStartOptions>,
15
- ): Promise<WebAssemblyResourceLoader> {
16
- const cache = await getCacheToUseIfEnabled(bootConfig);
17
- return new WebAssemblyResourceLoader(bootConfig, cache, startOptions);
18
- }
19
-
20
- constructor(
21
- readonly bootConfig: BootJsonData,
22
- readonly cacheIfUsed: Cache | null,
23
- readonly startOptions: Partial<WebAssemblyStartOptions>,
24
- ) {}
25
-
26
- loadResources(
27
- resources: ResourceList,
28
- url: (name: string) => string,
29
- resourceType: WebAssemblyBootResourceType,
30
- ): LoadingResource[] {
31
- return Object.keys(resources).map((name) => this.loadResource(name, url(name), resources[name], resourceType));
32
- }
33
-
34
- loadResource(
35
- name: string,
36
- url: string,
37
- contentHash: string,
38
- resourceType: WebAssemblyBootResourceType,
39
- ): LoadingResource {
40
- const response = this.cacheIfUsed
41
- ? this.loadResourceWithCaching(this.cacheIfUsed, name, url, contentHash, resourceType)
42
- : this.loadResourceWithoutCaching(name, url, contentHash, resourceType);
43
-
44
- return { name, url, response };
45
- }
46
-
47
- logToConsole() {
48
- const cacheLoadsEntries = Object.values(this.cacheLoads);
49
- const networkLoadsEntries = Object.values(this.networkLoads);
50
- const cacheResponseBytes = countTotalBytes(cacheLoadsEntries);
51
- const networkResponseBytes = countTotalBytes(networkLoadsEntries);
52
- const totalResponseBytes = cacheResponseBytes + networkResponseBytes;
53
- if (totalResponseBytes === 0) {
54
- // We have no perf stats to display, likely because caching is not in use.
55
- return;
56
- }
57
-
58
- const linkerDisabledWarning = this.bootConfig.linkerEnabled
59
- ? '%c'
60
- : '\n%cThis application was built with linking (tree shaking) disabled. Published applications will be significantly smaller.';
61
- console.groupCollapsed(
62
- `%cblazor%c Loaded ${toDataSizeString(totalResponseBytes)} resources${linkerDisabledWarning}`,
63
- 'background: purple; color: white; padding: 1px 3px; border-radius: 3px;',
64
- 'font-weight: bold;',
65
- 'font-weight: normal;',
66
- );
67
-
68
- if (cacheLoadsEntries.length) {
69
- console.groupCollapsed(`Loaded ${toDataSizeString(cacheResponseBytes)} resources from cache`);
70
- console.table(this.cacheLoads);
71
- console.groupEnd();
72
- }
73
-
74
- if (networkLoadsEntries.length) {
75
- console.groupCollapsed(`Loaded ${toDataSizeString(networkResponseBytes)} resources from network`);
76
- console.table(this.networkLoads);
77
- console.groupEnd();
78
- }
79
-
80
- console.groupEnd();
81
- }
82
-
83
- async purgeUnusedCacheEntriesAsync() {
84
- // We want to keep the cache small because, even though the browser will evict entries if it
85
- // gets too big, we don't want to be considered problematic by the end user viewing storage stats
86
- const cache = this.cacheIfUsed;
87
- if (cache) {
88
- const cachedRequests = await cache.keys();
89
- const deletionPromises = cachedRequests.map(async (cachedRequest) => {
90
- if (!(cachedRequest.url in this.usedCacheKeys)) {
91
- await cache.delete(cachedRequest);
92
- }
93
- });
94
-
95
- await Promise.all(deletionPromises);
96
- }
97
- }
98
-
99
- private async loadResourceWithCaching(
100
- cache: Cache,
101
- name: string,
102
- url: string,
103
- contentHash: string,
104
- resourceType: WebAssemblyBootResourceType,
105
- ) {
106
- // Since we are going to cache the response, we require there to be a content hash for integrity
107
- // checking. We don't want to cache bad responses. There should always be a hash, because the build
108
- // process generates this data.
109
- if (!contentHash || contentHash.length === 0) {
110
- throw new Error('Content hash is required');
111
- }
112
-
113
- const cacheKey = toAbsoluteUri(`${url}.${contentHash}`);
114
- this.usedCacheKeys[cacheKey] = true;
115
-
116
- const cachedResponse = await cache.match(cacheKey);
117
- if (cachedResponse) {
118
- // It's in the cache.
119
- const responseBytes = parseInt(cachedResponse.headers.get('content-length') || '0');
120
- this.cacheLoads[name] = { responseBytes };
121
- return cachedResponse;
122
- } else {
123
- // It's not in the cache. Fetch from network.
124
- const networkResponse = await this.loadResourceWithoutCaching(name, url, contentHash, resourceType);
125
- this.addToCacheAsync(cache, name, cacheKey, networkResponse); // Don't await - add to cache in background
126
- return networkResponse;
127
- }
128
- }
129
-
130
- private loadResourceWithoutCaching(
131
- name: string,
132
- url: string,
133
- contentHash: string,
134
- resourceType: WebAssemblyBootResourceType,
135
- ): Promise<Response> {
136
- // Allow developers to override how the resource is loaded
137
- if (this.startOptions.loadBootResource) {
138
- const customLoadResult = this.startOptions.loadBootResource(resourceType, name, url, contentHash);
139
- if (customLoadResult instanceof Promise) {
140
- // They are supplying an entire custom response, so just use that
141
- return customLoadResult;
142
- } else if (typeof customLoadResult === 'string') {
143
- // They are supplying a custom URL, so use that with the default fetch behavior
144
- url = customLoadResult;
145
- }
146
- }
147
-
148
- // Note that if cacheBootResources was explicitly disabled, we also bypass hash checking
149
- // This is to give developers an easy opt-out from the entire caching/validation flow if
150
- // there's anything they don't like about it.
151
- return fetch(url, {
152
- cache: networkFetchCacheMode,
153
- integrity: this.bootConfig.cacheBootResources ? contentHash : undefined,
154
- });
155
- }
156
-
157
- private async addToCacheAsync(cache: Cache, name: string, cacheKey: string, response: Response) {
158
- // We have to clone in order to put this in the cache *and* not prevent other code from
159
- // reading the original response stream.
160
- const responseData = await response.clone().arrayBuffer();
161
-
162
- // Now is an ideal moment to capture the performance stats for the request, since it
163
- // only just completed and is most likely to still be in the buffer. However this is
164
- // only done on a 'best effort' basis. Even if we do receive an entry, some of its
165
- // properties may be blanked out if it was a CORS request.
166
- const performanceEntry = getPerformanceEntry(response.url);
167
- const responseBytes = (performanceEntry && performanceEntry.encodedBodySize) || undefined;
168
- this.networkLoads[name] = { responseBytes };
169
-
170
- // Add to cache as a custom response object so we can track extra data such as responseBytes
171
- // We can't rely on the server sending content-length (ASP.NET Core doesn't by default)
172
- await cache.put(
173
- cacheKey,
174
- new Response(responseData, {
175
- headers: {
176
- 'content-type': response.headers.get('content-type') || '',
177
- 'content-length': (responseBytes || response.headers.get('content-length') || '').toString(),
178
- },
179
- }),
180
- );
181
- }
182
- }
183
-
184
- async function getCacheToUseIfEnabled(bootConfig: BootJsonData): Promise<Cache | null> {
185
- // caches will be undefined if we're running on an insecure origin (secure means https or localhost)
186
- if (!bootConfig.cacheBootResources || typeof caches === 'undefined') {
187
- return null;
188
- }
189
-
190
- // Define a separate cache for each base href, so we're isolated from any other
191
- // Blazor application running on the same origin. We need this so that we're free
192
- // to purge from the cache anything we're not using and don't let it keep growing,
193
- // since we don't want to be worst offenders for space usage.
194
- const relativeBaseHref = document.baseURI.substring(document.location.origin.length);
195
- const cacheName = `blazor-resources-${relativeBaseHref}`;
196
-
197
- try {
198
- // There's a Chromium bug we need to be aware of here: the CacheStorage APIs say that when
199
- // caches.open(name) returns a promise that succeeds, the value is meant to be a Cache instance.
200
- // However, if the browser was launched with a --user-data-dir param that's "too long" in some sense,
201
- // then even through the promise resolves as success, the value given is `undefined`.
202
- // See https://stackoverflow.com/a/46626574 and https://bugs.chromium.org/p/chromium/issues/detail?id=1054541
203
- // If we see this happening, return "null" to mean "proceed without caching".
204
- return (await caches.open(cacheName)) || null;
205
- } catch {
206
- // There's no known scenario where we should get an exception here, but considering the
207
- // Chromium bug above, let's tolerate it and treat as "proceed without caching".
208
- return null;
209
- }
210
- }
211
-
212
- function countTotalBytes(loads: LoadLogEntry[]) {
213
- return loads.reduce((prev, item) => prev + (item.responseBytes || 0), 0);
214
- }
215
-
216
- function toDataSizeString(byteCount: number) {
217
- return `${(byteCount / (1024 * 1024)).toFixed(2)} MB`;
218
- }
219
-
220
- function getPerformanceEntry(url: string): PerformanceResourceTiming | undefined {
221
- if (typeof performance !== 'undefined') {
222
- return performance.getEntriesByName(url)[0] as PerformanceResourceTiming;
223
- }
224
- }
225
-
226
- interface LoadLogEntry {
227
- responseBytes: number | undefined;
228
- }
229
-
230
- export interface LoadingResource {
231
- name: string;
232
- url: string;
233
- response: Promise<Response>;
234
- }
@@ -1,22 +0,0 @@
1
- export interface WebAssemblyStartOptions {
2
- /**
3
- * Overrides the built-in boot resource loading mechanism so that boot resources can be fetched
4
- * from a custom source, such as an external CDN.
5
- * @param type The type of the resource to be loaded.
6
- * @param name The name of the resource to be loaded.
7
- * @param defaultUri The URI from which the framework would fetch the resource by default. The URI may be relative or absolute.
8
- * @param integrity The integrity string representing the expected content in the response.
9
- * @returns A URI string or a Response promise to override the loading process, or null/undefined to allow the default loading behavior.
10
- */
11
- loadBootResource(
12
- type: WebAssemblyBootResourceType,
13
- name: string,
14
- defaultUri: string,
15
- integrity: string,
16
- ): string | Promise<Response> | null | undefined;
17
- }
18
-
19
- // This type doesn't have to align with anything in BootConfig.
20
- // Instead, this represents the public API through which certain aspects
21
- // of boot resource loading can be customized.
22
- export type WebAssemblyBootResourceType = 'assembly' | 'pdb' | 'dotnetjs' | 'dotnetwasm' | 'timezonedata';