@reidelsaltres/pureper 0.2.33 → 0.2.34
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/out/foundation/CacheManager.d.ts +20 -0
- package/out/foundation/CacheManager.d.ts.map +1 -0
- package/out/foundation/CacheManager.js +129 -0
- package/out/foundation/CacheManager.js.map +1 -0
- package/out/foundation/Injection.d.ts +6 -0
- package/out/foundation/Injection.d.ts.map +1 -1
- package/out/foundation/Injection.js +23 -0
- package/out/foundation/Injection.js.map +1 -1
- package/out/foundation/Module.d.ts +41 -24
- package/out/foundation/Module.d.ts.map +1 -1
- package/out/foundation/Module.js +253 -152
- package/out/foundation/Module.js.map +1 -1
- package/out/foundation/Theme.d.ts +2 -0
- package/out/foundation/Theme.d.ts.map +1 -1
- package/out/foundation/Theme.js +9 -1
- package/out/foundation/Theme.js.map +1 -1
- package/out/foundation/Triplet.d.ts +10 -0
- package/out/foundation/Triplet.d.ts.map +1 -1
- package/out/foundation/Triplet.js +17 -0
- package/out/foundation/Triplet.js.map +1 -1
- package/out/foundation/TripletDecorator.d.ts.map +1 -1
- package/out/foundation/TripletDecorator.js +28 -1
- package/out/foundation/TripletDecorator.js.map +1 -1
- package/out/foundation/engine/Expression.d.ts.map +1 -1
- package/out/foundation/engine/Expression.js +11 -11
- package/out/foundation/engine/Expression.js.map +1 -1
- package/out/foundation/engine/TemplateEngine.d.ts.map +1 -1
- package/out/foundation/engine/TemplateEngine.js +6 -2
- package/out/foundation/engine/TemplateEngine.js.map +1 -1
- package/out/foundation/worker/ServiceWorker.d.ts +2 -25
- package/out/foundation/worker/ServiceWorker.d.ts.map +1 -1
- package/out/foundation/worker/ServiceWorker.js +2 -94
- package/out/foundation/worker/ServiceWorker.js.map +1 -1
- package/out/index.d.ts +4 -3
- package/out/index.d.ts.map +1 -1
- package/out/index.js +3 -2
- package/out/index.js.map +1 -1
- package/package.json +1 -1
- package/src/foundation/CacheManager.ts +151 -0
- package/src/foundation/Injection.ts +24 -0
- package/src/foundation/Module.ts +282 -174
- package/src/foundation/Theme.ts +10 -1
- package/src/foundation/Triplet.ts +21 -0
- package/src/foundation/TripletDecorator.ts +19 -1
- package/src/foundation/engine/Expression.ts +11 -12
- package/src/foundation/engine/TemplateEngine.ts +6 -3
- package/src/foundation/worker/ServiceWorker.ts +2 -101
- package/src/index.ts +4 -3
package/out/index.d.ts
CHANGED
|
@@ -7,14 +7,15 @@ export { default as UniHtml } from './foundation/component_api/UniHtml.js';
|
|
|
7
7
|
export { default as Page } from './foundation/component_api/Page.js';
|
|
8
8
|
export { default as Component } from './foundation/component_api/Component.js';
|
|
9
9
|
export { default as Attribute } from './foundation/component_api/Attribute.js';
|
|
10
|
-
export { default as Triplet, TripletStruct, AccessType, REGISTRY } from './foundation/Triplet.js';
|
|
10
|
+
export { default as Triplet, TripletStruct, AccessType, REGISTRY, RegistryCapture } from './foundation/Triplet.js';
|
|
11
11
|
export { ReComponent, RePage, ReImplementation } from './foundation/TripletDecorator.js';
|
|
12
12
|
export { Implementation, ImplementationStruct, Placeholder } from './foundation/Injection.js';
|
|
13
|
-
export { default as Module, ModuleStruct, ModuleManager,
|
|
13
|
+
export { default as Module, ModuleStruct, ModuleManager, SubModule, SubModuleStruct } from './foundation/Module.js';
|
|
14
|
+
export { default as CacheManager, DownloadProgress } from './foundation/CacheManager.js';
|
|
14
15
|
export { default as Fetcher } from './foundation/Fetcher.js';
|
|
15
16
|
export * from './foundation/engine/TemplateEngine.js';
|
|
16
17
|
export { Router } from './foundation/worker/Router.js';
|
|
17
|
-
export { default as ServiceWorker, ServiceWorkerConfig, FetchActivityItem, PageSourceType
|
|
18
|
+
export { default as ServiceWorker, ServiceWorkerConfig, FetchActivityItem, PageSourceType } from './foundation/worker/ServiceWorker.js';
|
|
18
19
|
export * from './foundation/Hosting.js';
|
|
19
20
|
export * from './foundation/Theme.js';
|
|
20
21
|
//# sourceMappingURL=index.d.ts.map
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAE3D,cAAc,2CAA2C,CAAC;AAC1D,OAAO,EACN,OAAO,IAAI,UAAU,EACrB,SAAS,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAC3F,YAAY,EACZ,MAAM,8BAA8B,CAAA;AAErC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAE3D,cAAc,2CAA2C,CAAC;AAC1D,OAAO,EACN,OAAO,IAAI,UAAU,EACrB,SAAS,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAC3F,YAAY,EACZ,MAAM,8BAA8B,CAAA;AAErC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACnH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEzF,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC9F,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACpH,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAE7D,cAAc,uCAAuC,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAExI,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
|
package/out/index.js
CHANGED
|
@@ -5,10 +5,11 @@ export { default as UniHtml } from './foundation/component_api/UniHtml.js';
|
|
|
5
5
|
export { default as Page } from './foundation/component_api/Page.js';
|
|
6
6
|
export { default as Component } from './foundation/component_api/Component.js';
|
|
7
7
|
export { default as Attribute } from './foundation/component_api/Attribute.js';
|
|
8
|
-
export { default as Triplet, AccessType, REGISTRY } from './foundation/Triplet.js';
|
|
8
|
+
export { default as Triplet, AccessType, REGISTRY, RegistryCapture } from './foundation/Triplet.js';
|
|
9
9
|
export { ReComponent, RePage, ReImplementation } from './foundation/TripletDecorator.js';
|
|
10
10
|
export { Implementation, Placeholder } from './foundation/Injection.js';
|
|
11
|
-
export { default as Module, ModuleManager } from './foundation/Module.js';
|
|
11
|
+
export { default as Module, ModuleManager, SubModule } from './foundation/Module.js';
|
|
12
|
+
export { default as CacheManager } from './foundation/CacheManager.js';
|
|
12
13
|
export { default as Fetcher } from './foundation/Fetcher.js';
|
|
13
14
|
export * from './foundation/engine/TemplateEngine.js';
|
|
14
15
|
export { Router } from './foundation/worker/Router.js';
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAE3D,cAAc,2CAA2C,CAAC;AAC1D,OAAO,EACN,OAAO,IAAI,UAAU,EAC+B,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAC3F,YAAY,EACZ,MAAM,8BAA8B,CAAA;AAErC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAiB,UAAU,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO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"./Fetcher.js";
|
|
3
|
+
|
|
4
|
+
export type DownloadProgress = {
|
|
5
|
+
totalFiles: number;
|
|
6
|
+
completedFiles: number;
|
|
7
|
+
currentFile: string;
|
|
8
|
+
totalBytes: number;
|
|
9
|
+
downloadedBytes: number;
|
|
10
|
+
speed: number;
|
|
11
|
+
active: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default class CacheManager {
|
|
15
|
+
private static readonly CACHE_NAME = 'purper-modules';
|
|
16
|
+
|
|
17
|
+
static resolveUrl(url: string): string {
|
|
18
|
+
return Fetcher.resolveUrl(url);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static async download(urls: string[], progress?: Observable<DownloadProgress>): Promise<number> {
|
|
22
|
+
if (urls.length === 0) return 0;
|
|
23
|
+
|
|
24
|
+
const totalFiles = urls.length;
|
|
25
|
+
let completedFiles = 0;
|
|
26
|
+
let downloadedBytes = 0;
|
|
27
|
+
let totalBytes = 0;
|
|
28
|
+
let lastTime = performance.now();
|
|
29
|
+
let lastBytes = 0;
|
|
30
|
+
let speed = 0;
|
|
31
|
+
|
|
32
|
+
const update = (currentFile: string, active: boolean) => {
|
|
33
|
+
progress?.setObject({ totalFiles, completedFiles, currentFile, totalBytes, downloadedBytes, speed, active });
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Estimate total size via HEAD
|
|
37
|
+
const sizes = await Promise.all(urls.map(async (url) => {
|
|
38
|
+
try {
|
|
39
|
+
const resp = await fetch(this.resolveUrl(url), { method: 'HEAD' });
|
|
40
|
+
const cl = resp.headers.get('content-length');
|
|
41
|
+
return cl ? parseInt(cl, 10) : 0;
|
|
42
|
+
} catch { return 0; }
|
|
43
|
+
}));
|
|
44
|
+
totalBytes = sizes.reduce((a, b) => a + b, 0);
|
|
45
|
+
|
|
46
|
+
update('', true);
|
|
47
|
+
|
|
48
|
+
const failedFiles: string[] = [];
|
|
49
|
+
|
|
50
|
+
for (const url of urls) {
|
|
51
|
+
const resolved = this.resolveUrl(url);
|
|
52
|
+
const fileName = url.split('/').pop() || url;
|
|
53
|
+
update(fileName, true);
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const response = await fetch(resolved);
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
console.warn(`[CacheManager]: Failed to download ${url}: ${response.status}`);
|
|
59
|
+
failedFiles.push(url);
|
|
60
|
+
completedFiles++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const reader = response.body?.getReader();
|
|
65
|
+
const chunks: BlobPart[] = [];
|
|
66
|
+
|
|
67
|
+
if (reader) {
|
|
68
|
+
while (true) {
|
|
69
|
+
const { done, value } = await reader.read();
|
|
70
|
+
if (done) break;
|
|
71
|
+
chunks.push(value);
|
|
72
|
+
downloadedBytes += value.byteLength;
|
|
73
|
+
|
|
74
|
+
const now = performance.now();
|
|
75
|
+
const elapsed = (now - lastTime) / 1000;
|
|
76
|
+
if (elapsed >= 0.5) {
|
|
77
|
+
speed = (downloadedBytes - lastBytes) / elapsed;
|
|
78
|
+
lastTime = now;
|
|
79
|
+
lastBytes = downloadedBytes;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
update(fileName, true);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ('caches' in window) {
|
|
87
|
+
try {
|
|
88
|
+
const cache = await caches.open(this.CACHE_NAME);
|
|
89
|
+
const blob = new Blob(chunks);
|
|
90
|
+
const cacheResponse = new Response(blob, { headers: response.headers });
|
|
91
|
+
await cache.put(resolved, cacheResponse);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
console.warn(`[CacheManager]: Failed to cache ${url}`, e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
completedFiles++;
|
|
98
|
+
} catch (e) {
|
|
99
|
+
console.warn(`[CacheManager]: Error downloading ${url}`, e);
|
|
100
|
+
failedFiles.push(url);
|
|
101
|
+
completedFiles++;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
speed = 0;
|
|
106
|
+
update('', false);
|
|
107
|
+
|
|
108
|
+
if (failedFiles.length > 0) {
|
|
109
|
+
throw new Error(`[CacheManager]: ${failedFiles.length} file(s) failed to download: ${failedFiles.join(', ')}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return downloadedBytes;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static async delete(urls: string[]): Promise<void> {
|
|
116
|
+
if (!('caches' in window) || urls.length === 0) return;
|
|
117
|
+
const cache = await caches.open(this.CACHE_NAME);
|
|
118
|
+
for (const url of urls) {
|
|
119
|
+
await cache.delete(this.resolveUrl(url));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static async isCached(url: string): Promise<boolean> {
|
|
124
|
+
if (!('caches' in window)) return false;
|
|
125
|
+
const cache = await caches.open(this.CACHE_NAME);
|
|
126
|
+
const match = await cache.match(this.resolveUrl(url));
|
|
127
|
+
return match !== undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static async getCachedSize(urls: string[]): Promise<number> {
|
|
131
|
+
if (!('caches' in window) || urls.length === 0) return 0;
|
|
132
|
+
const cache = await caches.open(this.CACHE_NAME);
|
|
133
|
+
let total = 0;
|
|
134
|
+
for (const url of urls) {
|
|
135
|
+
const match = await cache.match(this.resolveUrl(url));
|
|
136
|
+
if (match) {
|
|
137
|
+
const blob = await match.blob();
|
|
138
|
+
total += blob.size;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return total;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static formatBytes(bytes: number): string {
|
|
145
|
+
if (bytes === 0) return '0 B';
|
|
146
|
+
const k = 1024;
|
|
147
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
148
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
149
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -165,6 +165,30 @@ export class Placeholder {
|
|
|
165
165
|
console.info(`[Placeholder:${placeholderName}]: Reloaded ${reloads.length} instance(s)`);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
/** Return all registered placeholder names. */
|
|
169
|
+
public static getAllNames(): string[] {
|
|
170
|
+
return Array.from(this._all.keys());
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Deactivate a placeholder — hides all instances. */
|
|
174
|
+
public static deactivate(name: string): void {
|
|
175
|
+
const p = this._all.get(name);
|
|
176
|
+
if (!p) return;
|
|
177
|
+
p.activeImpl.setObject(null);
|
|
178
|
+
console.info(`[Placeholder:${name}]: Deactivated`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Activate a placeholder — restores the default implementation. */
|
|
182
|
+
public static activate(name: string): void {
|
|
183
|
+
const p = this._all.get(name);
|
|
184
|
+
if (!p) return;
|
|
185
|
+
const first = p.implementations.values().next().value;
|
|
186
|
+
if (first && !p.activeImpl.getObject()) {
|
|
187
|
+
p.activeImpl.setObject(first);
|
|
188
|
+
console.info(`[Placeholder:${name}]: Activated with "${first.name}"`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
168
192
|
/**
|
|
169
193
|
* Switch a single instance to a different implementation and reload it.
|
|
170
194
|
* Does NOT change the global active implementation.
|