@reidelsaltres/pureper 0.2.14 → 0.2.17
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/Fetcher.d.ts.map +1 -1
- package/out/foundation/Fetcher.js +8 -13
- package/out/foundation/Fetcher.js.map +1 -1
- package/out/foundation/Injection.d.ts +87 -0
- package/out/foundation/Injection.d.ts.map +1 -0
- package/out/foundation/Injection.js +149 -0
- package/out/foundation/Injection.js.map +1 -0
- package/out/foundation/Theme.d.ts.map +1 -1
- package/out/foundation/Theme.js +16 -1
- package/out/foundation/Theme.js.map +1 -1
- package/out/foundation/Triplet.d.ts +30 -25
- package/out/foundation/Triplet.d.ts.map +1 -1
- package/out/foundation/Triplet.js +96 -115
- package/out/foundation/Triplet.js.map +1 -1
- package/out/foundation/TripletDecorator.d.ts +11 -0
- package/out/foundation/TripletDecorator.d.ts.map +1 -1
- package/out/foundation/TripletDecorator.js +25 -8
- package/out/foundation/TripletDecorator.js.map +1 -1
- package/out/foundation/component_api/Component.d.ts.map +1 -1
- package/out/foundation/component_api/Component.js +1 -0
- package/out/foundation/component_api/Component.js.map +1 -1
- package/out/foundation/component_api/UniHtml.d.ts +6 -1
- package/out/foundation/component_api/UniHtml.d.ts.map +1 -1
- package/out/foundation/component_api/UniHtml.js +32 -7
- package/out/foundation/component_api/UniHtml.js.map +1 -1
- package/out/foundation/engine/Expression.d.ts +2 -0
- package/out/foundation/engine/Expression.d.ts.map +1 -1
- package/out/foundation/engine/Expression.js +26 -11
- package/out/foundation/engine/Expression.js.map +1 -1
- package/out/foundation/engine/StylePreprocessor.js +2 -1
- package/out/foundation/engine/StylePreprocessor.js.map +1 -1
- package/out/foundation/engine/TemplateEngine.d.ts +3 -1
- package/out/foundation/engine/TemplateEngine.d.ts.map +1 -1
- package/out/foundation/engine/TemplateEngine.js +44 -15
- package/out/foundation/engine/TemplateEngine.js.map +1 -1
- package/out/foundation/worker/Router.d.ts.map +1 -1
- package/out/foundation/worker/Router.js +6 -0
- package/out/foundation/worker/Router.js.map +1 -1
- package/out/foundation/worker/ServiceWorker.d.ts +48 -17
- package/out/foundation/worker/ServiceWorker.d.ts.map +1 -1
- package/out/foundation/worker/ServiceWorker.js +186 -119
- package/out/foundation/worker/ServiceWorker.js.map +1 -1
- package/out/index.d.ts +3 -2
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/index.js.map +1 -1
- package/package.json +1 -1
- package/src/foundation/Fetcher.ts +9 -14
- package/src/foundation/Injection.ts +183 -0
- package/src/foundation/Theme.ts +17 -3
- package/src/foundation/Triplet.ts +114 -141
- package/src/foundation/TripletDecorator.ts +32 -8
- package/src/foundation/component_api/Component.ts +1 -0
- package/src/foundation/component_api/UniHtml.ts +35 -7
- package/src/foundation/engine/Expression.ts +34 -20
- package/src/foundation/engine/StylePreprocessor.ts +1 -1
- package/src/foundation/engine/TemplateEngine.ts +42 -15
- package/src/foundation/worker/Router.ts +10 -3
- package/src/foundation/worker/ServiceWorker.ts +203 -129
- package/src/foundation/worker/serviceworker.js +191 -0
- package/src/index.ts +7 -4
- package/out/foundation/worker/serviceworker.d.ts +0 -1
- package/out/foundation/worker/serviceworker.d.ts.map +0 -1
- package/out/foundation/worker/serviceworker.js +0 -2
- package/out/foundation/worker/serviceworker.js.map +0 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Purper Service Worker
|
|
3
|
+
* Handles caching, offline support, and connectivity detection.
|
|
4
|
+
*
|
|
5
|
+
* Message API (postMessage from client):
|
|
6
|
+
* CACHE_URL { url } — add a URL to cache
|
|
7
|
+
* CACHE_URLS { urls } — add multiple URLs to cache
|
|
8
|
+
* REMOVE_URL { url } — remove a URL from cache
|
|
9
|
+
* CLEAR_CACHE — — wipe entire cache
|
|
10
|
+
* GET_CACHE_KEYS — — list all cached URLs
|
|
11
|
+
* HAS_URL { url } — check if URL is cached
|
|
12
|
+
* SKIP_WAITING — — activate new SW immediately
|
|
13
|
+
* GET_VERSION — — return SW version string
|
|
14
|
+
* IS_ONLINE — — connectivity check from SW context
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const CACHE_VERSION = 'purper-v1';
|
|
18
|
+
const SW_VERSION = '1.0.0';
|
|
19
|
+
|
|
20
|
+
// ── Install ─────────────────────────────────────────────────────────
|
|
21
|
+
self.addEventListener('install', (event) => {
|
|
22
|
+
console.log(`[ServiceWorker ${SW_VERSION}]: Installing...`);
|
|
23
|
+
event.waitUntil(
|
|
24
|
+
caches.open(CACHE_VERSION)
|
|
25
|
+
.then(() => {
|
|
26
|
+
console.log(`[ServiceWorker ${SW_VERSION}]: Cache "${CACHE_VERSION}" opened`);
|
|
27
|
+
return self.skipWaiting();
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// ── Activate ────────────────────────────────────────────────────────
|
|
33
|
+
self.addEventListener('activate', (event) => {
|
|
34
|
+
console.log(`[ServiceWorker ${SW_VERSION}]: Activating...`);
|
|
35
|
+
event.waitUntil(
|
|
36
|
+
caches.keys()
|
|
37
|
+
.then((keys) => {
|
|
38
|
+
return Promise.all(
|
|
39
|
+
keys
|
|
40
|
+
.filter((key) => key !== CACHE_VERSION)
|
|
41
|
+
.map((key) => {
|
|
42
|
+
console.log(`[ServiceWorker ${SW_VERSION}]: Deleting old cache "${key}"`);
|
|
43
|
+
return caches.delete(key);
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
})
|
|
47
|
+
.then(() => {
|
|
48
|
+
console.log(`[ServiceWorker ${SW_VERSION}]: Claiming clients`);
|
|
49
|
+
return self.clients.claim();
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// ── Fetch ───────────────────────────────────────────────────────────
|
|
55
|
+
// Network-first for navigation, cache-first for assets.
|
|
56
|
+
self.addEventListener('fetch', (event) => {
|
|
57
|
+
const request = event.request;
|
|
58
|
+
|
|
59
|
+
// Only handle GET requests
|
|
60
|
+
if (request.method !== 'GET') return;
|
|
61
|
+
|
|
62
|
+
// Navigation requests (HTML pages) — network-first, fall back to cache
|
|
63
|
+
if (request.mode === 'navigate') {
|
|
64
|
+
event.respondWith(
|
|
65
|
+
fetch(request)
|
|
66
|
+
.then((response) => {
|
|
67
|
+
if (response.ok) {
|
|
68
|
+
const clone = response.clone();
|
|
69
|
+
caches.open(CACHE_VERSION).then((cache) => cache.put(request, clone));
|
|
70
|
+
}
|
|
71
|
+
return response;
|
|
72
|
+
})
|
|
73
|
+
.catch(() => {
|
|
74
|
+
return caches.match(request).then((cached) => {
|
|
75
|
+
return cached || caches.match('/index.html');
|
|
76
|
+
});
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Sub-resources (CSS, JS, images, fonts, JSON) — cache-first, fall back to network
|
|
83
|
+
event.respondWith(
|
|
84
|
+
caches.match(request).then((cached) => {
|
|
85
|
+
if (cached) return cached;
|
|
86
|
+
|
|
87
|
+
return fetch(request).then((response) => {
|
|
88
|
+
if (response.ok && response.type === 'basic') {
|
|
89
|
+
const clone = response.clone();
|
|
90
|
+
caches.open(CACHE_VERSION).then((cache) => cache.put(request, clone));
|
|
91
|
+
}
|
|
92
|
+
return response;
|
|
93
|
+
});
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// ── Message handling ────────────────────────────────────────────────
|
|
99
|
+
self.addEventListener('message', (event) => {
|
|
100
|
+
const { type, url, urls } = event.data || {};
|
|
101
|
+
const port = event.ports?.[0];
|
|
102
|
+
|
|
103
|
+
switch (type) {
|
|
104
|
+
case 'CACHE_URL':
|
|
105
|
+
caches.open(CACHE_VERSION)
|
|
106
|
+
.then((cache) => cache.add(url))
|
|
107
|
+
.then(() => console.log(`[ServiceWorker]: Cached "${url}"`))
|
|
108
|
+
.catch((err) => console.warn(`[ServiceWorker]: Failed to cache "${url}"`, err));
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
case 'CACHE_URLS':
|
|
112
|
+
if (Array.isArray(urls)) {
|
|
113
|
+
caches.open(CACHE_VERSION)
|
|
114
|
+
.then((cache) => cache.addAll(urls))
|
|
115
|
+
.then(() => console.log(`[ServiceWorker]: Cached ${urls.length} URLs`))
|
|
116
|
+
.catch((err) => console.warn('[ServiceWorker]: Failed to cache URLs', err));
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
case 'REMOVE_URL':
|
|
121
|
+
caches.open(CACHE_VERSION)
|
|
122
|
+
.then((cache) => cache.delete(url))
|
|
123
|
+
.then((deleted) => {
|
|
124
|
+
console.log(`[ServiceWorker]: ${deleted ? 'Removed' : 'Not found'} "${url}" from cache`);
|
|
125
|
+
if (port) port.postMessage({ deleted });
|
|
126
|
+
})
|
|
127
|
+
.catch((err) => {
|
|
128
|
+
console.warn(`[ServiceWorker]: Failed to remove "${url}"`, err);
|
|
129
|
+
if (port) port.postMessage({ deleted: false });
|
|
130
|
+
});
|
|
131
|
+
break;
|
|
132
|
+
|
|
133
|
+
case 'CLEAR_CACHE':
|
|
134
|
+
caches.delete(CACHE_VERSION)
|
|
135
|
+
.then(() => caches.open(CACHE_VERSION))
|
|
136
|
+
.then(() => {
|
|
137
|
+
console.log('[ServiceWorker]: Cache cleared');
|
|
138
|
+
if (port) port.postMessage({ cleared: true });
|
|
139
|
+
})
|
|
140
|
+
.catch((err) => {
|
|
141
|
+
console.warn('[ServiceWorker]: Failed to clear cache', err);
|
|
142
|
+
if (port) port.postMessage({ cleared: false });
|
|
143
|
+
});
|
|
144
|
+
break;
|
|
145
|
+
|
|
146
|
+
case 'GET_CACHE_KEYS':
|
|
147
|
+
caches.open(CACHE_VERSION)
|
|
148
|
+
.then((cache) => cache.keys())
|
|
149
|
+
.then((requests) => {
|
|
150
|
+
const keys = requests.map((r) => r.url);
|
|
151
|
+
if (port) port.postMessage({ keys });
|
|
152
|
+
})
|
|
153
|
+
.catch(() => {
|
|
154
|
+
if (port) port.postMessage({ keys: [] });
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
|
|
158
|
+
case 'HAS_URL':
|
|
159
|
+
caches.match(url)
|
|
160
|
+
.then((match) => {
|
|
161
|
+
if (port) port.postMessage({ cached: !!match });
|
|
162
|
+
})
|
|
163
|
+
.catch(() => {
|
|
164
|
+
if (port) port.postMessage({ cached: false });
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
|
|
168
|
+
case 'SKIP_WAITING':
|
|
169
|
+
console.log('[ServiceWorker]: Skip waiting requested');
|
|
170
|
+
self.skipWaiting();
|
|
171
|
+
break;
|
|
172
|
+
|
|
173
|
+
case 'GET_VERSION':
|
|
174
|
+
if (port) port.postMessage({ version: SW_VERSION });
|
|
175
|
+
break;
|
|
176
|
+
|
|
177
|
+
case 'IS_ONLINE': {
|
|
178
|
+
fetch(url || '/index.html', { cache: 'no-store', method: 'HEAD' })
|
|
179
|
+
.then((res) => {
|
|
180
|
+
if (port) port.postMessage({ online: res.ok });
|
|
181
|
+
})
|
|
182
|
+
.catch(() => {
|
|
183
|
+
if (port) port.postMessage({ online: false });
|
|
184
|
+
});
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
default:
|
|
189
|
+
console.warn(`[ServiceWorker]: Unknown message type "${type}"`);
|
|
190
|
+
}
|
|
191
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -4,9 +4,11 @@ export { default as EmptyConstructor } from './foundation/api/EmptyConstructor.j
|
|
|
4
4
|
export { default as Lazy } from './foundation/api/Lazy.js';
|
|
5
5
|
|
|
6
6
|
export * from './foundation/component_api/mixin/Proto.js';
|
|
7
|
-
export {
|
|
7
|
+
export {
|
|
8
|
+
default as Observable,
|
|
8
9
|
IObserver, IMutationObserver, IKeyMutationObserver, Observer, MutationObserver, Transaction,
|
|
9
|
-
isObservable
|
|
10
|
+
isObservable
|
|
11
|
+
} from './foundation/api/Observer.js'
|
|
10
12
|
|
|
11
13
|
export { default as UniHtml } from './foundation/component_api/UniHtml.js';
|
|
12
14
|
export { default as Page } from './foundation/component_api/Page.js';
|
|
@@ -14,14 +16,15 @@ export { default as Component } from './foundation/component_api/Component.js';
|
|
|
14
16
|
export { default as Attribute } from './foundation/component_api/Attribute.js';
|
|
15
17
|
|
|
16
18
|
export { default as Triplet, TripletStruct, AccessType } from './foundation/Triplet.js';
|
|
17
|
-
export { ReComponent, RePage } from './foundation/TripletDecorator.js';
|
|
19
|
+
export { ReComponent, RePage, ReImplementation } from './foundation/TripletDecorator.js';
|
|
18
20
|
|
|
21
|
+
export { Implementation, ImplementationStruct, Placeholder } from './foundation/Injection.js';
|
|
19
22
|
export { default as Fetcher } from './foundation/Fetcher.js';
|
|
20
23
|
|
|
21
24
|
export * from './foundation/engine/TemplateEngine.js';
|
|
22
25
|
|
|
23
26
|
export { Router } from './foundation/worker/Router.js';
|
|
24
|
-
export { default as ServiceWorker } from './foundation/worker/ServiceWorker.js';
|
|
27
|
+
export { default as ServiceWorker, ServiceWorkerConfig } from './foundation/worker/ServiceWorker.js';
|
|
25
28
|
|
|
26
29
|
export * from './foundation/Hosting.js';
|
|
27
30
|
export * from './foundation/Theme.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=serviceworker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serviceworker.d.ts","sourceRoot":"","sources":["../../../src/foundation/worker/serviceworker.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serviceworker.js","sourceRoot":"","sources":["../../../src/foundation/worker/serviceworker.js"],"names":[],"mappings":""}
|