@reidelsaltres/pureper 0.2.32 → 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.
Files changed (48) hide show
  1. package/out/foundation/CacheManager.d.ts +20 -0
  2. package/out/foundation/CacheManager.d.ts.map +1 -0
  3. package/out/foundation/CacheManager.js +129 -0
  4. package/out/foundation/CacheManager.js.map +1 -0
  5. package/out/foundation/Injection.d.ts +6 -0
  6. package/out/foundation/Injection.d.ts.map +1 -1
  7. package/out/foundation/Injection.js +23 -0
  8. package/out/foundation/Injection.js.map +1 -1
  9. package/out/foundation/Module.d.ts +47 -5
  10. package/out/foundation/Module.d.ts.map +1 -1
  11. package/out/foundation/Module.js +277 -26
  12. package/out/foundation/Module.js.map +1 -1
  13. package/out/foundation/Theme.d.ts +2 -0
  14. package/out/foundation/Theme.d.ts.map +1 -1
  15. package/out/foundation/Theme.js +9 -1
  16. package/out/foundation/Theme.js.map +1 -1
  17. package/out/foundation/Triplet.d.ts +10 -0
  18. package/out/foundation/Triplet.d.ts.map +1 -1
  19. package/out/foundation/Triplet.js +17 -0
  20. package/out/foundation/Triplet.js.map +1 -1
  21. package/out/foundation/TripletDecorator.d.ts.map +1 -1
  22. package/out/foundation/TripletDecorator.js +28 -1
  23. package/out/foundation/TripletDecorator.js.map +1 -1
  24. package/out/foundation/engine/Expression.d.ts.map +1 -1
  25. package/out/foundation/engine/Expression.js +11 -11
  26. package/out/foundation/engine/Expression.js.map +1 -1
  27. package/out/foundation/engine/TemplateEngine.d.ts.map +1 -1
  28. package/out/foundation/engine/TemplateEngine.js +6 -2
  29. package/out/foundation/engine/TemplateEngine.js.map +1 -1
  30. package/out/foundation/worker/ServiceWorker.d.ts +2 -25
  31. package/out/foundation/worker/ServiceWorker.d.ts.map +1 -1
  32. package/out/foundation/worker/ServiceWorker.js +2 -94
  33. package/out/foundation/worker/ServiceWorker.js.map +1 -1
  34. package/out/index.d.ts +4 -3
  35. package/out/index.d.ts.map +1 -1
  36. package/out/index.js +3 -2
  37. package/out/index.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/foundation/CacheManager.ts +151 -0
  40. package/src/foundation/Injection.ts +24 -0
  41. package/src/foundation/Module.ts +312 -27
  42. package/src/foundation/Theme.ts +10 -1
  43. package/src/foundation/Triplet.ts +21 -0
  44. package/src/foundation/TripletDecorator.ts +19 -1
  45. package/src/foundation/engine/Expression.ts +11 -12
  46. package/src/foundation/engine/TemplateEngine.ts +6 -3
  47. package/src/foundation/worker/ServiceWorker.ts +2 -101
  48. package/src/index.ts +4 -3
@@ -1,5 +1,5 @@
1
1
  import { AnyConstructor, UniHtml } from "../index.js";
2
- import Triplet, { TripletStruct } from "./Triplet.js"
2
+ import Triplet, { RegistryCapture, TripletStruct } from "./Triplet.js"
3
3
 
4
4
  export function ReComponent(settings: TripletStruct, tag: string) {
5
5
  return (ctor: Function) => {
@@ -12,6 +12,12 @@ export function ReComponent(settings: TripletStruct, tag: string) {
12
12
  const triplet: Triplet = new Triplet(settings);
13
13
 
14
14
  triplet.register("markup", tag);
15
+
16
+ const paths: string[] = [];
17
+ if (settings.markupURL) paths.push(settings.markupURL);
18
+ if (settings.cssURL) paths.push(settings.cssURL);
19
+ if (settings.ltCssURL) paths.push(settings.ltCssURL);
20
+ if (paths.length > 0) RegistryCapture.capture(ctor, paths);
15
21
  }
16
22
  }
17
23
  export function RePage(settings: TripletStruct, route: string) {
@@ -25,6 +31,12 @@ export function RePage(settings: TripletStruct, route: string) {
25
31
  const triplet: Triplet = new Triplet(settings);
26
32
 
27
33
  triplet.register("router", route);
34
+
35
+ const paths: string[] = [];
36
+ if (settings.markupURL) paths.push(settings.markupURL);
37
+ if (settings.cssURL) paths.push(settings.cssURL);
38
+ if (settings.ltCssURL) paths.push(settings.ltCssURL);
39
+ if (paths.length > 0) RegistryCapture.capture(ctor, paths);
28
40
  }
29
41
  }
30
42
 
@@ -53,6 +65,12 @@ export function ReImplementation(settings: TripletStruct, target: string) {
53
65
  // Register adds the implementation to the existing placeholder (or creates one)
54
66
  triplet.register(target.includes("-") ? "markup" : "router", target);
55
67
 
68
+ const paths: string[] = [];
69
+ if (settings.markupURL) paths.push(settings.markupURL);
70
+ if (settings.cssURL) paths.push(settings.cssURL);
71
+ if (settings.ltCssURL) paths.push(settings.ltCssURL);
72
+ if (paths.length > 0) RegistryCapture.capture(ctor, paths);
73
+
56
74
  console.info(`[ReImplementation:${target}] registered implementation "${implName}"`);
57
75
  }
58
76
  }
@@ -114,18 +114,17 @@ export default class Expression {
114
114
  const context = scope.getVariables();
115
115
  let transformedCode = this.code;
116
116
 
117
- // Находим Observable переменные
118
- const observableVars = new Set<string>();
119
- for (const [key, value] of Object.entries(context)) {
120
- if (isObservable(value)) {
121
- observableVars.add(key);
122
- }
123
- }
124
-
125
- // Трансформируем Observable: user.name -> user.getObject().name
126
- for (const varName of observableVars) {
127
- const propRegex = new RegExp(`\\b${varName}\\.(?!getObject|setObject|subscribe|unsubscribe|getObserver|getMutationObserver|subscribeMutation|unsubscribeMutation)`, 'g');
128
- transformedCode = transformedCode.replace(propRegex, `${varName}.getObject().`);
117
+ for (const [varName, value] of Object.entries(context)) {
118
+ if (!isObservable(value)) continue;
119
+
120
+ const propRegex = new RegExp(`\\b${varName}\\.(\\w+)`, 'g');
121
+ transformedCode = transformedCode.replace(propRegex, (match, propName) => {
122
+ // Не разворачиваем, если свойство/метод существует на самом экземпляре Observable
123
+ if (propName in value) {
124
+ return match;
125
+ }
126
+ return `${varName}.getObject().${propName}`;
127
+ });
129
128
  }
130
129
 
131
130
  return transformedCode;
@@ -57,11 +57,13 @@ export default class TemplateEngine {
57
57
  }
58
58
  return false;
59
59
  }
60
- doWork(context?: { element: Element, name: string, value: string }): void {
60
+ doWork(context?: { element: Element, name: string, value: string | boolean }): void {
61
61
  const { element, name, value } = context!;
62
- if (value === null || value === undefined) {
62
+ if (value === null || value === undefined || value === false) {
63
63
  if (element.hasAttribute(name))
64
64
  element.removeAttribute(name);
65
+ } else if (value === true) {
66
+ element.setAttribute(name, '');
65
67
  } else {
66
68
  element.setAttribute(name, value);
67
69
  }
@@ -256,7 +258,8 @@ export default class TemplateEngine {
256
258
  if (!point.nextSibling) break;
257
259
  point = point.nextSibling;
258
260
  if (!point || point.nodeType !== Node.ELEMENT_NODE) continue;
259
- if (!point || !this.acceptNode(point as Element)) break;
261
+ const tag = (point as Element).tagName;
262
+ if (tag !== "ELSEIF" && tag !== "ELSE") break;
260
263
  allParts.push({ element: point as Element, shadow: TemplateEngine.transContentToShadow(point as Element) });
261
264
  }
262
265
 
@@ -18,22 +18,18 @@ export interface FetchActivityItem {
18
18
 
19
19
  export type PageSourceType = 'cache' | 'network' | 'unknown';
20
20
 
21
- export type CacheStrategy = 'cache-first' | 'network-first';
22
- export type PrecacheMode = 'precache' | 'normal' | 'disabled';
23
-
24
21
  /**
25
22
  * Client-side Service Worker manager for Purper SPA.
26
23
  *
27
24
  * Provides:
28
25
  * - Registration with one call (`ServiceWorker.register()`)
29
- * - Cache management: add / remove / list / clear
30
26
  * - Connectivity detection with reactive `online` observable
27
+ * - Fetch tracking for debug NetworkStatus component
28
+ * - Version / lifecycle management
31
29
  *
32
30
  * Usage:
33
31
  * ```ts
34
32
  * await ServiceWorker.register(); // defaults to './serviceworker.js'
35
- * await ServiceWorker.addToCache('/data.json');
36
- * await ServiceWorker.removeFromCache('/old.css');
37
33
  * ServiceWorker.online.subscribe(v => console.log('online:', v));
38
34
  * ```
39
35
  */
@@ -45,8 +41,6 @@ export default class ServiceWorker {
45
41
 
46
42
  static readonly fetchActivities: Observable<FetchActivityItem[]> = new Observable([]);
47
43
  static readonly pageSource: Observable<PageSourceType> = new Observable<PageSourceType>('unknown');
48
- static readonly cacheStrategy: Observable<CacheStrategy> = new Observable<CacheStrategy>('cache-first');
49
- static readonly precacheMode: Observable<PrecacheMode> = new Observable<PrecacheMode>('normal');
50
44
  private static _fetchTrackingEnabled = false;
51
45
  private static _fetchListenerBound = false;
52
46
 
@@ -125,99 +119,6 @@ export default class ServiceWorker {
125
119
  });
126
120
  }
127
121
 
128
- // ── Cache Management ────────────────────────────────────────────
129
-
130
- /** Add a single URL to the SW cache. */
131
- static async addToCache(url: string): Promise<void> {
132
- if (navigator.serviceWorker?.controller) {
133
- this._postMessage({ type: 'CACHE_URL', url });
134
- return;
135
- }
136
- // Fallback: use Cache API directly
137
- try {
138
- const cache = await caches.open('purper-v1');
139
- const response = await fetch(url);
140
- if (response.ok) {
141
- await cache.put(url, response);
142
- console.log('[ServiceWorker]: Resource cached directly:', url);
143
- }
144
- } catch (e) {
145
- console.warn('[ServiceWorker]: Failed to cache resource:', url, e);
146
- }
147
- }
148
-
149
- /** Add multiple URLs to the SW cache in one batch. */
150
- static addAllToCache(urls: string[]): void {
151
- this._postMessage({ type: 'CACHE_URLS', urls });
152
- }
153
-
154
- /** Remove a URL from the SW cache. Returns true if it was found and deleted. */
155
- static async removeFromCache(url: string): Promise<boolean> {
156
- try {
157
- const data = await this._request<{ deleted: boolean }>({ type: 'REMOVE_URL', url });
158
- return data.deleted;
159
- } catch {
160
- // Fallback
161
- try {
162
- const cache = await caches.open('purper-v1');
163
- return await cache.delete(url);
164
- } catch {
165
- return false;
166
- }
167
- }
168
- }
169
-
170
- /** Return all URLs currently in the SW cache. */
171
- static async getCacheKeys(): Promise<string[]> {
172
- try {
173
- const data = await this._request<{ keys: string[] }>({ type: 'GET_CACHE_KEYS' });
174
- return data.keys;
175
- } catch {
176
- return [];
177
- }
178
- }
179
-
180
- /** Wipe the entire SW cache. */
181
- static async clearCache(): Promise<boolean> {
182
- try {
183
- const data = await this._request<{ cleared: boolean }>({ type: 'CLEAR_CACHE' });
184
- return data.cleared;
185
- } catch {
186
- return false;
187
- }
188
- }
189
-
190
- /** Check whether a URL exists in the SW cache. */
191
- static async isCached(url: string): Promise<boolean> {
192
- try {
193
- const data = await this._request<{ cached: boolean }>({ type: 'HAS_URL', url });
194
- return data.cached;
195
- } catch {
196
- // Fallback: CacheStorage directly
197
- try {
198
- return !!(await caches.match(url));
199
- } catch {
200
- return false;
201
- }
202
- }
203
- }
204
-
205
- // ── Cache Strategy & Precache Mode ────────────────────────────
206
-
207
- static setCacheStrategy(strategy: CacheStrategy): void {
208
- this.cacheStrategy.setObject(strategy);
209
- this._postMessage({ type: 'SET_CACHE_STRATEGY', strategy });
210
- }
211
-
212
- static setPrecacheMode(mode: PrecacheMode): void {
213
- this.precacheMode.setObject(mode);
214
- this._postMessage({ type: 'SET_PRECACHE_MODE', mode });
215
- }
216
-
217
- static async getConfig(): Promise<{ strategy: CacheStrategy; precacheMode: PrecacheMode }> {
218
- return this._request<{ strategy: CacheStrategy; precacheMode: PrecacheMode }>({ type: 'GET_CONFIG' });
219
- }
220
-
221
122
  // ── Version & lifecycle ─────────────────────────────────────────
222
123
 
223
124
  /** Ask the waiting SW to activate immediately. */
package/src/index.ts CHANGED
@@ -15,17 +15,18 @@ export { default as Page } from './foundation/component_api/Page.js';
15
15
  export { default as Component } from './foundation/component_api/Component.js';
16
16
  export { default as Attribute } from './foundation/component_api/Attribute.js';
17
17
 
18
- export { default as Triplet, TripletStruct, AccessType, REGISTRY } from './foundation/Triplet.js';
18
+ export { default as Triplet, TripletStruct, AccessType, REGISTRY, RegistryCapture } from './foundation/Triplet.js';
19
19
  export { ReComponent, RePage, ReImplementation } from './foundation/TripletDecorator.js';
20
20
 
21
21
  export { Implementation, ImplementationStruct, Placeholder } from './foundation/Injection.js';
22
- export { default as Module, ModuleStruct, ModuleManager } from './foundation/Module.js';
22
+ export { default as Module, ModuleStruct, ModuleManager, SubModule, SubModuleStruct } from './foundation/Module.js';
23
+ export { default as CacheManager, DownloadProgress } from './foundation/CacheManager.js';
23
24
  export { default as Fetcher } from './foundation/Fetcher.js';
24
25
 
25
26
  export * from './foundation/engine/TemplateEngine.js';
26
27
 
27
28
  export { Router } from './foundation/worker/Router.js';
28
- export { default as ServiceWorker, ServiceWorkerConfig, FetchActivityItem, PageSourceType, CacheStrategy, PrecacheMode } from './foundation/worker/ServiceWorker.js';
29
+ export { default as ServiceWorker, ServiceWorkerConfig, FetchActivityItem, PageSourceType } from './foundation/worker/ServiceWorker.js';
29
30
 
30
31
  export * from './foundation/Hosting.js';
31
32
  export * from './foundation/Theme.js';