@reidelsaltres/pureper 0.2.15 → 0.2.18

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 (40) hide show
  1. package/out/foundation/Fetcher.d.ts.map +1 -1
  2. package/out/foundation/Fetcher.js +8 -13
  3. package/out/foundation/Fetcher.js.map +1 -1
  4. package/out/foundation/Injection.d.ts +87 -0
  5. package/out/foundation/Injection.d.ts.map +1 -0
  6. package/out/foundation/Injection.js +149 -0
  7. package/out/foundation/Injection.js.map +1 -0
  8. package/out/foundation/Triplet.d.ts +30 -25
  9. package/out/foundation/Triplet.d.ts.map +1 -1
  10. package/out/foundation/Triplet.js +96 -115
  11. package/out/foundation/Triplet.js.map +1 -1
  12. package/out/foundation/TripletDecorator.d.ts +11 -0
  13. package/out/foundation/TripletDecorator.d.ts.map +1 -1
  14. package/out/foundation/TripletDecorator.js +25 -8
  15. package/out/foundation/TripletDecorator.js.map +1 -1
  16. package/out/foundation/component_api/UniHtml.d.ts +5 -1
  17. package/out/foundation/component_api/UniHtml.d.ts.map +1 -1
  18. package/out/foundation/component_api/UniHtml.js +23 -5
  19. package/out/foundation/component_api/UniHtml.js.map +1 -1
  20. package/out/foundation/worker/ServiceWorker.d.ts +48 -17
  21. package/out/foundation/worker/ServiceWorker.d.ts.map +1 -1
  22. package/out/foundation/worker/ServiceWorker.js +186 -119
  23. package/out/foundation/worker/ServiceWorker.js.map +1 -1
  24. package/out/index.d.ts +4 -3
  25. package/out/index.d.ts.map +1 -1
  26. package/out/index.js +3 -2
  27. package/out/index.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/foundation/Fetcher.ts +9 -14
  30. package/src/foundation/Injection.ts +183 -0
  31. package/src/foundation/Triplet.ts +114 -141
  32. package/src/foundation/TripletDecorator.ts +32 -8
  33. package/src/foundation/component_api/UniHtml.ts +26 -5
  34. package/src/foundation/worker/ServiceWorker.ts +203 -129
  35. package/src/foundation/worker/serviceworker.js +191 -0
  36. package/src/index.ts +8 -5
  37. package/out/foundation/worker/serviceworker.d.ts +0 -1
  38. package/out/foundation/worker/serviceworker.d.ts.map +0 -1
  39. package/out/foundation/worker/serviceworker.js +0 -2
  40. package/out/foundation/worker/serviceworker.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceWorker.js","sourceRoot":"","sources":["../../../src/foundation/worker/ServiceWorker.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,GAAG,IAAI,CAAC;AAEpB,mDAAmD;AACnD,6CAA6C;AAC7C,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC,MAAM,aAAa,GAAa;IAC5B,aAAa;CAChB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;;;;;;;;;;;;;;;;;;KAkBK;AAEL,MAAM,CAAC,OAAO,OAAO,aAAa;IAC9B;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAW;QAC/B,IAAI,eAAe,IAAI,SAAS,IAAI,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;YACrE,SAAS,CAAC,aAAa,CAAC,UAAU,CAAC,WAAW,CAAC;gBAC3C,IAAI,EAAE,WAAW;gBACjB,GAAG,EAAE,GAAG;aACX,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,sDAAsD;YACtD,IAAI,CAAC;gBACD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBAC9C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACd,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;oBAC/B,OAAO,CAAC,GAAG,CAAC,4CAA4C,EAAE,GAAG,CAAC,CAAC;gBACnE,CAAC;YACL,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,OAAO,CAAC,IAAI,C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D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,IAAI,cAAc,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;gBAChG,MAAM,MAAM,GAAG,QAAQ,CAAC,EAAE,CAAC;gBAC3B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBAC9B,OAAO,MAAM,CAAC;YAClB,CAAC;YAAC,MAAM,CAAC;gBACL,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBAC7B,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;IACL,CAAC;IAED,oCAAoC;IACpC,MAAM,KAAK,YAAY;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC"}
package/out/index.d.ts CHANGED
@@ -7,12 +7,13 @@ 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 } from './foundation/Triplet.js';
11
- export { ReComponent, RePage } from './foundation/TripletDecorator.js';
10
+ export { default as Triplet, TripletStruct, AccessType, REGISTRY } from './foundation/Triplet.js';
11
+ export { ReComponent, RePage, ReImplementation } from './foundation/TripletDecorator.js';
12
+ export { Implementation, ImplementationStruct, Placeholder } from './foundation/Injection.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';
15
- export { default as ServiceWorker } from './foundation/worker/ServiceWorker.js';
16
+ export { default as ServiceWorker, ServiceWorkerConfig } from './foundation/worker/ServiceWorker.js';
16
17
  export * from './foundation/Hosting.js';
17
18
  export * from './foundation/Theme.js';
18
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"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AAE,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;AAClG,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,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,MAAM,sCAAsC,CAAC;AAErG,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
package/out/index.js CHANGED
@@ -5,8 +5,9 @@ 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 } from './foundation/Triplet.js';
9
- export { ReComponent, RePage } from './foundation/TripletDecorator.js';
8
+ export { default as Triplet, AccessType, REGISTRY } from './foundation/Triplet.js';
9
+ export { ReComponent, RePage, ReImplementation } from './foundation/TripletDecorator.js';
10
+ export { Implementation, Placeholder } from './foundation/Injection.js';
10
11
  export { default as Fetcher } from './foundation/Fetcher.js';
11
12
  export * from './foundation/engine/TemplateEngine.js';
12
13
  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,EAAE,OAAO,IAAI,UAAU,EACuB,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAC3F,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAEnD,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,MAAM,yBAAyB,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAEvE,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,MAAM,sCAAsC,CAAC;AAEhF,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AAGtC,qEAAqE;AACrE;;WAEQ;AAER,yEAAyE"}
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;AAClG,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEzF,OAAO,EAAE,cAAc,EAAwB,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC9F,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,EAAuB,MAAM,sCAAsC,CAAC;AAErG,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AAGtC,qEAAqE;AACrE;;WAEQ;AAER,yEAAyE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reidelsaltres/pureper",
3
- "version": "0.2.15",
3
+ "version": "0.2.18",
4
4
  "description": "Minimal library extracted from the Pureper SPA foundation — utilities and base classes for components/pages.",
5
5
  "type": "module",
6
6
  "main": "out/src/index.js",
@@ -1,45 +1,34 @@
1
- import { HOSTING, HOSTING_ORIGIN } from "./Hosting.js";
1
+ import { HOSTING_ORIGIN } from "./Hosting.js";
2
2
 
3
- // cache stores response bodies (text) by resolved URL so we can reuse them safely
4
- const temporaryCache: Map<string, string> = new Map();
5
3
  // keep in-flight promises to deduplicate concurrent identical requests
6
4
  const inFlightText: Map<string, Promise<string>> = new Map();
7
5
  const inFlightJSON: Map<string, Promise<any>> = new Map();
8
6
  export default class Fetcher {
9
7
  static async fetchText(url: string): Promise<string> {
10
8
  const resolved = this.resolveUrl(url);
11
- if (temporaryCache.has(resolved))
12
- return temporaryCache.get(resolved)!;
13
9
 
14
10
  // If a request for the same URL is already in-flight, reuse its promise
15
11
  if (inFlightText.has(resolved)) return inFlightText.get(resolved)!;
16
12
 
17
13
  const p = (async () => {
18
14
  const response = await this.internalFetch(resolved);
19
- const text = await response.text();
20
- temporaryCache.set(resolved, text);
21
- return text;
15
+ return response.text();
22
16
  })();
23
17
 
24
18
  inFlightText.set(resolved, p);
25
- // cleanup entry when finished
26
19
  p.finally(() => inFlightText.delete(resolved));
27
20
 
28
21
  return p;
29
22
  }
30
23
  static async fetchJSON(url: string): Promise<any> {
31
24
  const resolved = this.resolveUrl(url);
32
- if (temporaryCache.has(resolved))
33
- return JSON.parse(temporaryCache.get(resolved)!);
34
25
 
35
26
  // If a request for the same URL is already in-flight, reuse its promise
36
27
  if (inFlightJSON.has(resolved)) return inFlightJSON.get(resolved)!;
37
28
 
38
29
  const p = (async () => {
39
30
  const response = await this.internalFetch(resolved);
40
- const json = await response.json();
41
- temporaryCache.set(resolved, JSON.stringify(json));
42
- return json;
31
+ return response.json();
43
32
  })();
44
33
 
45
34
  inFlightJSON.set(resolved, p);
@@ -65,6 +54,12 @@ export default class Fetcher {
65
54
  }
66
55
 
67
56
  private static async internalFetch(resolvedUrl: string): Promise<Response> {
57
+ // L2: check ServiceWorker CacheStorage before hitting the network
58
+ if ('caches' in window) {
59
+ const cached = await caches.match(resolvedUrl);
60
+ if (cached) return cached;
61
+ }
62
+
68
63
  const response = await fetch(resolvedUrl, { cache: 'default' });
69
64
  if (!response.ok) {
70
65
  throw new Error(`HTTP error! ${resolvedUrl} status: ${response.status}`);
@@ -0,0 +1,183 @@
1
+ import Observable from "./api/Observer.js";
2
+ import Fetcher from "./Fetcher.js";
3
+ import { AnyConstructor } from "./component_api/mixin/Proto.js";
4
+ import UniHtml from "./component_api/UniHtml.js";
5
+
6
+ export type ImplementationStruct = {
7
+ markupURL?: string;
8
+ markup?: string;
9
+
10
+ cssURL?: string;
11
+ css?: string;
12
+
13
+ ltCssURL?: string;
14
+ ltCss?: string;
15
+
16
+ class?: AnyConstructor<UniHtml>;
17
+ }
18
+
19
+ /**
20
+ * Implementation — a swappable variant for a Triplet placeholder.
21
+ *
22
+ * Each placeholder (component tag or page route) can have multiple registered
23
+ * implementations. One is active at a time; switching triggers a reload on
24
+ * all live instances.
25
+ *
26
+ * ```ts
27
+ * // Register the default implementation
28
+ * @ReComponent({ markupURL: './Button.hmle', cssURL: './Button.css' }, "re-button")
29
+ * class ReButton extends Component { ... }
30
+ *
31
+ * // Register an alternative implementation
32
+ * @ReImplementation({ markupURL: './FancyButton.hmle', cssURL: './FancyButton.css' }, "re-button")
33
+ * class FancyButton extends Component { ... }
34
+ *
35
+ * // Switch all re-button instances to FancyButton
36
+ * Placeholder.switchTo("re-button", "FancyButton");
37
+ *
38
+ * // Switch a single instance manually
39
+ * const btn = document.querySelector("re-button");
40
+ * Placeholder.switchInstance(btn, "FancyButton");
41
+ * ```
42
+ */
43
+ export class Implementation {
44
+ public readonly name: string;
45
+ public readonly markup?: Promise<string>;
46
+ public readonly style?: Promise<string>;
47
+ public readonly globalStyle?: Promise<string>;
48
+ public readonly uniClass?: AnyConstructor<UniHtml>;
49
+
50
+ public constructor(name: string, struct: ImplementationStruct) {
51
+ this.name = name;
52
+
53
+ if (struct.markup && struct.markupURL)
54
+ throw new Error(`[Implementation:${name}]: Both markup and markupURL provided.`);
55
+ this.markup = struct.markupURL ? Fetcher.fetchText(struct.markupURL) : Promise.resolve(struct.markup);
56
+
57
+ if (struct.css && struct.cssURL)
58
+ throw new Error(`[Implementation:${name}]: Both css and cssURL provided.`);
59
+ this.style = struct.cssURL ? Fetcher.fetchText(struct.cssURL) : Promise.resolve(struct.css);
60
+
61
+ if (struct.ltCss && struct.ltCssURL)
62
+ throw new Error(`[Implementation:${name}]: Both ltCss and ltCssURL provided.`);
63
+ this.globalStyle = struct.ltCssURL ? Fetcher.fetchText(struct.ltCssURL) : Promise.resolve(struct.ltCss);
64
+
65
+ this.uniClass = struct.class;
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Placeholder — manages a named slot (tag or route) with swappable implementations.
71
+ *
72
+ * - `Placeholder.get(name)` — get or create a placeholder
73
+ * - `placeholder.addImplementation(impl)` — register an implementation
74
+ * - `Placeholder.switchTo(name, implName)` — globally switch + reload all instances
75
+ * - `Placeholder.switchInstance(instance, implName)` — switch one instance
76
+ */
77
+ export class Placeholder {
78
+ /** Все зарегистрированные placeholders по имени (tag / route). */
79
+ private static readonly _all: Map<string, Placeholder> = new Map();
80
+
81
+ public readonly name: string;
82
+ public readonly implementations: Map<string, Implementation> = new Map();
83
+ public readonly activeImpl: Observable<Implementation | null> = new Observable(null);
84
+
85
+ /** Все живые экземпляры этого placeholder для reload при смене implementation. */
86
+ private readonly _instances: Set<UniHtml> = new Set();
87
+
88
+ private constructor(name: string) {
89
+ this.name = name;
90
+ }
91
+
92
+ /** Get or create a placeholder by name. */
93
+ public static get(name: string): Placeholder {
94
+ let p = this._all.get(name);
95
+ if (!p) {
96
+ p = new Placeholder(name);
97
+ this._all.set(name, p);
98
+ }
99
+ return p;
100
+ }
101
+
102
+ /** Check if a placeholder exists. */
103
+ public static has(name: string): boolean {
104
+ return this._all.has(name);
105
+ }
106
+
107
+ /** Add an implementation. The first one added becomes active by default. */
108
+ public addImplementation(impl: Implementation): void {
109
+ if (this.implementations.has(impl.name)) {
110
+ console.warn(`[Placeholder:${this.name}]: Implementation "${impl.name}" already registered, overwriting.`);
111
+ }
112
+ this.implementations.set(impl.name, impl);
113
+
114
+ if (!this.activeImpl.getObject()) {
115
+ this.activeImpl.setObject(impl);
116
+ console.info(`[Placeholder:${this.name}]: Default implementation set to "${impl.name}"`);
117
+ } else {
118
+ console.info(`[Placeholder:${this.name}]: Implementation "${impl.name}" registered`);
119
+ }
120
+ }
121
+
122
+ /** Get the currently active implementation. */
123
+ public getActive(): Implementation | null {
124
+ return this.activeImpl.getObject();
125
+ }
126
+
127
+ /** Track a live instance for reload. */
128
+ public trackInstance(instance: UniHtml): void {
129
+ this._instances.add(instance);
130
+ }
131
+
132
+ /** Untrack a disposed instance. */
133
+ public untrackInstance(instance: UniHtml): void {
134
+ this._instances.delete(instance);
135
+ }
136
+
137
+ /** Get all tracked live instances. */
138
+ public getInstances(): Set<UniHtml> {
139
+ return this._instances;
140
+ }
141
+
142
+ /**
143
+ * Switch the active implementation globally.
144
+ * All live instances of this placeholder will reload.
145
+ */
146
+ public static async switchTo(placeholderName: string, implName: string): Promise<void> {
147
+ const p = this._all.get(placeholderName);
148
+ if (!p) throw new Error(`[Placeholder]: "${placeholderName}" not found.`);
149
+
150
+ const impl = p.implementations.get(implName);
151
+ if (!impl) throw new Error(`[Placeholder:${placeholderName}]: Implementation "${implName}" not found.`);
152
+
153
+ const prev = p.activeImpl.getObject();
154
+ if (prev === impl) return;
155
+
156
+ p.activeImpl.setObject(impl);
157
+ console.info(`[Placeholder:${placeholderName}]: Switched to "${implName}"`);
158
+
159
+ // Reload all live instances
160
+ const reloads: Promise<void>[] = [];
161
+ for (const instance of p._instances) {
162
+ reloads.push(instance.reload());
163
+ }
164
+ await Promise.all(reloads);
165
+ console.info(`[Placeholder:${placeholderName}]: Reloaded ${reloads.length} instance(s)`);
166
+ }
167
+
168
+ /**
169
+ * Switch a single instance to a different implementation and reload it.
170
+ * Does NOT change the global active implementation.
171
+ */
172
+ public static async switchInstance(placeholderName: string, instance: UniHtml, implName: string): Promise<void> {
173
+ const p = this._all.get(placeholderName);
174
+ if (!p) throw new Error(`[Placeholder]: "${placeholderName}" not found.`);
175
+
176
+ const impl = p.implementations.get(implName);
177
+ if (!impl) throw new Error(`[Placeholder:${placeholderName}]: Implementation "${implName}" not found.`);
178
+
179
+ (instance as any)._activeImplementation = impl;
180
+ await instance.reload();
181
+ console.info(`[Placeholder:${placeholderName}]: Instance switched to "${implName}"`);
182
+ }
183
+ }
@@ -1,13 +1,14 @@
1
1
  import Fetcher from "./Fetcher.js";
2
2
  import UniHtml from "./component_api/UniHtml.js";
3
3
  import { Router } from "./worker/Router.js";
4
- import ServiceWorker from "./worker/ServiceWorker.js";
5
4
  import Page from "./component_api/Page.js";
6
5
  import Component from "./component_api/Component.js";
7
6
  import { AnyConstructor, Constructor } from "./component_api/mixin/Proto.js";
8
7
  import TemplateEngine, { TemplateHolder } from "./engine/TemplateEngine.js";
9
8
  import Scope from "./engine/Scope.js";
9
+ import { Implementation, ImplementationStruct, Placeholder } from "./Injection.js";
10
10
 
11
+ export const REGISTRY: (() => void)[] = [];
11
12
 
12
13
  export enum AccessType {
13
14
  NONE = 0,
@@ -15,164 +16,136 @@ export enum AccessType {
15
16
  ONLINE = 1 << 1,
16
17
  BOTH = OFFLINE | ONLINE
17
18
  }
18
- export type TripletStruct = {
19
- markupURL?: string;
20
- markup?: string;
21
-
22
- cssURL?: string;
23
- css?: string;
24
-
25
- ltCssURL?: string;
26
- ltCss?: string;
27
-
28
- jsURL?: string;
29
19
 
20
+ export type TripletStruct = ImplementationStruct & {
30
21
  access?: AccessType;
31
- class?: AnyConstructor<UniHtml>;
32
22
  }
33
- export default class Triplet {
34
- public readonly markup?: Promise<string>;
35
- public readonly css?: Promise<string>;
36
- public readonly lightCss?: Promise<string>;
37
- public readonly js?: Promise<string>;
38
-
39
- private readonly markupURL?: string;
40
- private readonly cssURL?: string;
41
- private readonly ltCssURL?: string;
42
- private readonly jsURL?: string;
43
23
 
24
+ /**
25
+ * Triplet — registers a placeholder with a default implementation.
26
+ *
27
+ * The placeholder is what gets registered in `customElements.define()` or `Router`.
28
+ * At runtime, the placeholder resolves the currently active {@link Implementation}
29
+ * and uses its markup, style, and class for the lifecycle.
30
+ *
31
+ * ```ts
32
+ * // Default implementation registered via @ReComponent
33
+ * @ReComponent({ markupURL: './Button.hmle', cssURL: './Button.css' }, "re-button")
34
+ * class ReButton extends Component { ... }
35
+ *
36
+ * // Alternative implementation registered via @ReImplementation
37
+ * @ReImplementation({ markupURL: './FancyButton.hmle', cssURL: './Fancy.css' }, "re-button")
38
+ * class FancyButton extends Component { ... }
39
+ *
40
+ * // Switch globally — all re-button instances reload
41
+ * Placeholder.switchTo("re-button", "FancyButton");
42
+ *
43
+ * // Switch one instance only
44
+ * Placeholder.switchInstance("re-button", myBtnInstance, "FancyButton");
45
+ * ```
46
+ */
47
+ export default class Triplet {
44
48
  private readonly access: AccessType;
49
+ private readonly placeholderName?: string;
50
+ private readonly implementation: Implementation;
45
51
 
46
- private uni?: AnyConstructor<UniHtml>;
47
-
48
- public constructor(struct: TripletStruct) {
49
- this.markupURL = struct.markupURL;
50
- this.cssURL = struct.cssURL;
51
- this.ltCssURL = struct.ltCssURL;
52
- this.jsURL = struct.jsURL;
53
-
54
- let markup = Promise.resolve(struct.markup);
55
- if (struct.markupURL)
56
- markup = Fetcher.fetchText(struct.markupURL);
57
- let css = Promise.resolve(struct.css);
58
- if (struct.cssURL)
59
- css = Fetcher.fetchText(struct.cssURL);
60
- let ltCss = Promise.resolve(struct.ltCss);
61
- if (struct.ltCssURL)
62
- ltCss = Fetcher.fetchText(struct.ltCssURL);
63
- /*let js = Promise.resolve(undefined);
64
- if (struct.jsURL)
65
- js = Fetcher.fetchText(struct.jsURL);*/
66
-
67
- this.markup = markup;
68
- this.css = css;
69
- this.lightCss = ltCss;
70
- //this.js = js;
71
-
52
+ public constructor(struct: TripletStruct, implName?: string) {
72
53
  this.access = struct.access ?? AccessType.BOTH;
73
54
 
74
- this.uni = struct.class;
55
+ const name = implName ?? struct.class?.name ?? "default";
56
+ this.implementation = new Implementation(name, struct);
75
57
  }
76
58
 
77
- public async init(): Promise<boolean> {
78
- const isOnline: boolean = await ServiceWorker.isOnline();
59
+ public async register(type: "router" | "markup", name: string): Promise<void> {
60
+ const placeholder = Placeholder.get(name);
61
+ placeholder.addImplementation(this.implementation);
79
62
 
80
- if (this.access === AccessType.NONE) return false;
81
- if (this.access === AccessType.BOTH) {
82
- await this.cache();
83
- return true
84
- };
85
- if (this.access === AccessType.OFFLINE && isOnline) return false;
86
- if (this.access === AccessType.ONLINE && !isOnline) return false;
87
-
88
- return true;
89
- }
90
-
91
- public async cache(): Promise<void> {
92
- //
93
- }
94
-
95
- public async register(type: "router" | "markup", name: string): Promise<boolean> {
96
- if (!this.uni) {
97
- switch (type) {
98
- case "router":
99
- this.uni = Page;
100
- break;
101
- case "markup":
102
- this.uni = Component;
103
- break;
104
- }
105
- }
106
- if (this.lightCss) {
107
- var style = await new CSSStyleSheet().replace(await this.lightCss);
108
- document.adoptedStyleSheets = [
109
- ...document.adoptedStyleSheets,
110
- style
111
- ];
63
+ // If the placeholder already has a registered element/route, skip re-registration
64
+ if (placeholder.implementations.size > 1) {
65
+ console.info(`[Triplet]: Implementation "${this.implementation.name}" added to existing placeholder "${name}"`);
66
+ return;
112
67
  }
113
68
 
114
- let ori = this.createInjectedClass(this.uni, type);
115
-
69
+ // First implementation register the placeholder shell
116
70
  if (type === "router") {
117
- const routePath = this.markupURL ?? "";
118
- var reg = Router.registerRoute(routePath, name, (search) => {
119
- const paramNames = (() => {
120
- const ctor = this.uni.prototype.constructor;
121
- const fnStr = ctor.toString();
122
- const argsMatch = fnStr.match(/constructor\s*\(([^)]*)\)/);
123
- if (!argsMatch) return [];
124
- return argsMatch[1].split(',').map(s => s.trim()).filter(Boolean);
125
- })();
126
-
127
- const args = paramNames.map(name => {
128
- return search?.get(name)
71
+ REGISTRY.push(() => {
72
+ const routePath = name;
73
+ Router.registerRoute("", routePath, (search) => {
74
+ const impl = placeholder.getActive()!;
75
+ const cls = impl.uniClass ?? Page;
76
+
77
+ const paramNames = (() => {
78
+ const ctor = cls.prototype.constructor;
79
+ const fnStr = ctor.toString();
80
+ const argsMatch = fnStr.match(/constructor\s*\(([^)]*)\)/);
81
+ if (!argsMatch) return [];
82
+ return argsMatch[1].split(',').map(s => s.trim()).filter(Boolean);
83
+ })();
84
+
85
+ const args = paramNames.map(n => search?.get(n));
86
+ const instance = new cls(...args);
87
+
88
+ // Attach placeholder context to instance for _init resolution
89
+ (instance as any)._placeholderName = name;
90
+ (instance as any)._activeImplementation = impl;
91
+ placeholder.trackInstance(instance);
92
+
93
+ return instance;
129
94
  });
130
95
 
131
- return new ori(...args);
96
+ console.info(`[Triplet]: Router route "${name}" registered as placeholder`);
132
97
  });
133
-
134
- console.info(`[Triplet]` + `: Router route '${name}' registered for path '${routePath}' by class ${ori}.`);
135
- return reg.then(() => true).catch(() => false);
136
98
  } else if (type === "markup") {
137
- if (customElements.get(name)) throw new Error(`Custom element '${name}' is already defined.`);
138
- customElements.define(name, ori.prototype.constructor as CustomElementConstructor);
139
-
140
- console.info(`[Triplet]: Custom element '${name}' defined.`);
141
- return Promise.resolve(true);
142
- }
143
- return Promise.resolve(false);
144
- }
145
-
146
- private createInjectedClass(c: AnyConstructor<UniHtml>, type: "router" | "markup"): any {
147
- let that = this;
148
- let ori = class extends c {
149
- constructor(...args: any[]) {
150
- super(...args);
151
- }
152
- };
153
- let proto = ori.prototype as any;
154
- const parser = new TemplateEngine();
155
-
156
- proto._init = async function (): Promise<TemplateHolder> {
157
- const markupText = await that.markup;
158
- return TemplateEngine.createHolder(markupText, Scope.from(this));
159
- }
160
-
161
- proto._postInit = async function (preHtml: TemplateHolder): Promise<TemplateHolder> {
162
- const dmc: Document | ShadowRoot = this.shadowRoot ?? document;
163
- const css = await that.css;
164
-
165
- var style = await new CSSStyleSheet().replace(css);
166
- dmc.adoptedStyleSheets = [
167
- ...dmc.adoptedStyleSheets,
168
- style
169
- ];
170
-
171
- //parser.hydrate(preHtml, this);
172
- return preHtml;
99
+ REGISTRY.push(() => {
100
+ if (customElements.get(name))
101
+ throw new Error(`Custom element '${name}' is already defined.`);
102
+
103
+ const cls = this.implementation.uniClass ?? Component;
104
+ const placeholderRef = placeholder;
105
+ const placeholderName = name;
106
+
107
+ // Create the placeholder class that delegates to the active implementation
108
+ let proto = cls.prototype as any;
109
+
110
+ proto._init = async function (): Promise<TemplateHolder> {
111
+ // Resolve which implementation to use (per-instance override or global)
112
+ const impl: Implementation = (this as any)._activeImplementation
113
+ ?? placeholderRef.getActive();
114
+
115
+ if (!impl) throw new Error(`[Placeholder:${placeholderName}]: No active implementation.`);
116
+
117
+ // Store for reload
118
+ (this as any)._placeholderName = placeholderName;
119
+ if (!(this as any)._activeImplementation)
120
+ (this as any)._activeImplementation = impl;
121
+
122
+ placeholderRef.trackInstance(this);
123
+
124
+ // Load markup
125
+ const markupText = await impl.markup;
126
+ const holder = TemplateEngine.createHolder(markupText, Scope.from(this));
127
+
128
+ // Apply scoped CSS
129
+ const dmc: Document | ShadowRoot = this.shadowRoot ?? document;
130
+ const cssText = await impl.style;
131
+ if (cssText) {
132
+ dmc.adoptedStyleSheets.push(
133
+ await new CSSStyleSheet().replace(cssText));
134
+ }
135
+
136
+ // Apply global CSS
137
+ const globalCss = await impl.globalStyle;
138
+ if (globalCss) {
139
+ document.adoptedStyleSheets.push(
140
+ await new CSSStyleSheet().replace(globalCss));
141
+ }
142
+
143
+ return holder;
144
+ };
145
+
146
+ customElements.define(name, cls.prototype.constructor as CustomElementConstructor);
147
+ console.info(`[Triplet]: Custom element "${name}" registered as placeholder`);
148
+ });
173
149
  }
174
-
175
- return ori;
176
150
  }
177
-
178
151
  }