@cadence-app/compiler 0.5.0 → 0.7.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.
@@ -5,7 +5,7 @@ import * as router from '@cadence-app/router';
5
5
  import { JavaScriptChannelTransport, containerBridgeObject, NativeBridge, TransportUnavailableError, createNativeApi, setActiveNativeApi, } from '@cadence-app/bridge';
6
6
  import { APP_ICON_STYLE_ID, BASE_STYLESHEET, BASE_STYLE_ID, BUILTIN_COMPONENTS, BUILTIN_COMPONENT_STYLESHEET, BUILTIN_COMPONENT_STYLE_ID, BUILTIN_ICONS, ComponentRegistry, ICON_BASE_STYLESHEET, ICON_STYLE_ID, appendStyle, iconRulesFor, applyTextScale, applyViewportGeometry, injectStyleOnce, installErrorBoundary, instructions, textScaleOf, toEngineError, } from '@cadence-app/runtime';
7
7
  import { BridgeEvents } from '@cadence-app/bridge';
8
- import { PageRegistry, ROUTER_STYLESHEET, ROUTER_STYLE_ID, Router, resolvePageChrome, setActiveRouter, } from '@cadence-app/router';
8
+ import { PageRegistry, ROUTER_COMPONENTS, ROUTER_COMPONENT_STYLESHEET, ROUTER_COMPONENT_STYLE_ID, ROUTER_STYLESHEET, ROUTER_STYLE_ID, Router, resolvePageChrome, setActiveRouter, } from '@cadence-app/router';
9
9
  import { COLOR_SCHEME_ATTRIBUTE, PLATFORM_ATTRIBUTE, THEME_STYLE_ID } from '@cadence-app/theme';
10
10
  import { allManifestPages } from "../manifest.js";
11
11
  const ENGINE_VERSION = '0.1.0';
@@ -27,7 +27,7 @@ const errorBoundary = installErrorBoundary({
27
27
  });
28
28
  const componentRegistry = new ComponentRegistry();
29
29
  const pageRegistry = new PageRegistry();
30
- for (const definition of BUILTIN_COMPONENTS) {
30
+ for (const definition of [...BUILTIN_COMPONENTS, ...ROUTER_COMPONENTS]) {
31
31
  componentRegistry.register(definition);
32
32
  }
33
33
  function registerPage(route, definition) {
@@ -79,10 +79,10 @@ function loadSubPackageChunk(chunkRoot) {
79
79
  * La WebView occupe tout l'écran, barre de statut comprise : sans ces valeurs
80
80
  * le mini-programme dessinerait son en-tête sous l'heure et la batterie.
81
81
  */
82
- async function applyInitialEnvironment(nativeApi) {
82
+ async function applyInitialEnvironment(nativeApi, tone) {
83
83
  const info = await nativeApi.system.getSystemInfo();
84
84
  applyViewportGeometry(document, { safeAreaInsets: info.safeAreaInsets, capsule: info.capsule });
85
- applyColorScheme(nativeApi, info.colorScheme);
85
+ applyColorScheme(tone, info.colorScheme);
86
86
  applyTextScale(document, textScaleOf(info));
87
87
  /* La plateforme ne change pas en cours de route : elle se pose une fois, et
88
88
  un nom que le preset ignore ne matche simplement aucun bloc. */
@@ -91,14 +91,48 @@ async function applyInitialEnvironment(nativeApi) {
91
91
  /**
92
92
  * Le schéma va sur la racine, comme le style de navigation (ADR-006) : les
93
93
  * feuilles réagissent, rien n'est reconstruit. Les icônes de la barre de statut
94
- * suivent par défaut — un en-tête sombre demande des icônes claires — et un
95
- * mini-programme qui en décide autrement appelle `ui.setStatusBarIcons` après.
94
+ * suivent par défaut — un en-tête sombre demande des icônes claires.
95
+ *
96
+ * **Ce défaut cède dès qu'une page a choisi.** Il était inconditionnel, et
97
+ * effaçait à la bascule suivante la teinte qu'un mini-programme avait posée —
98
+ * y compris par la recette que ce commentaire recommandait. Un en-tête de
99
+ * marque garde donc la sienne (ADR-040).
96
100
  */
97
- function applyColorScheme(nativeApi, colorScheme) {
101
+ function applyColorScheme(tone, colorScheme) {
98
102
  document.documentElement.setAttribute(COLOR_SCHEME_ATTRIBUTE, colorScheme);
99
- void nativeApi.ui
100
- .setStatusBarIcons(colorScheme === 'dark' ? 'light' : 'dark')
101
- .catch(() => undefined);
103
+ tone.applyFor(colorScheme);
104
+ }
105
+ /**
106
+ * Le défaut de teinte, et la façade qui lui dit de se taire.
107
+ *
108
+ * Le moteur et la page passent par la même méthode du pont : sans ce détour, le
109
+ * moteur ne pourrait pas distinguer son propre défaut d'un choix explicite, et
110
+ * il continuerait à l'écraser à chaque bascule de thème. Le prototype de `ui`
111
+ * est conservé — seule cette méthode est reposée dessus.
112
+ *
113
+ * L'état vit dans cet amorçage, pas dans le module : un moteur par chargement
114
+ * de page, et deux amorçages ne se transmettent rien.
115
+ */
116
+ function statusBarIconsDefault(nativeApi) {
117
+ let pageChose = false;
118
+ const ui = Object.create(nativeApi.ui);
119
+ ui.setStatusBarIcons = (icons) => {
120
+ pageChose = true;
121
+ return nativeApi.ui.setStatusBarIcons(icons);
122
+ };
123
+ return {
124
+ api: { ...nativeApi, ui },
125
+ applyFor: (colorScheme) => {
126
+ if (pageChose) {
127
+ return;
128
+ }
129
+ void nativeApi.ui
130
+ .setStatusBarIcons(colorScheme === 'dark' ? 'light' : 'dark')
131
+ .catch((error) => {
132
+ console.error('[cadence/engine] status bar icons refused', error);
133
+ });
134
+ },
135
+ };
102
136
  }
103
137
  /**
104
138
  * Le conteneur répond sous le dernier chrome qu'on lui a annoncé : sans cette
@@ -167,7 +201,8 @@ async function startEngine(manifest, app) {
167
201
  const transport = selectTransport();
168
202
  const nativeBridge = new NativeBridge(transport);
169
203
  const nativeApi = createNativeApi(nativeBridge);
170
- setActiveNativeApi(nativeApi);
204
+ const tone = statusBarIconsDefault(nativeApi);
205
+ setActiveNativeApi(tone.api);
171
206
  reportToContainer = (error) => {
172
207
  // Un rejet ici relancerait le gestionnaire de rejets non interceptés.
173
208
  void nativeApi.app.reportError(error).catch(() => undefined);
@@ -176,6 +211,7 @@ async function startEngine(manifest, app) {
176
211
  injectStyleOnce(document, ICON_STYLE_ID, ICON_BASE_STYLESHEET + iconRulesFor(BUILTIN_ICONS));
177
212
  injectStyleOnce(document, BUILTIN_COMPONENT_STYLE_ID, BUILTIN_COMPONENT_STYLESHEET);
178
213
  injectStyleOnce(document, ROUTER_STYLE_ID, ROUTER_STYLESHEET);
214
+ injectStyleOnce(document, ROUTER_COMPONENT_STYLE_ID, ROUTER_COMPONENT_STYLESHEET);
179
215
  const routerManifest = {
180
216
  entry: manifest.entry,
181
217
  pages: allManifestPages(manifest),
@@ -186,9 +222,9 @@ async function startEngine(manifest, app) {
186
222
  : { navigationStyle: manifest.navigationStyle }),
187
223
  };
188
224
  announceEntryChrome(nativeApi, routerManifest);
189
- await applyInitialEnvironment(nativeApi);
225
+ await applyInitialEnvironment(nativeApi, tone);
190
226
  nativeBridge.on(BridgeEvents.colorSchemeChanged, (payload) => {
191
- applyColorScheme(nativeApi, payload.colorScheme);
227
+ applyColorScheme(tone, payload.colorScheme);
192
228
  });
193
229
  nativeBridge.on(BridgeEvents.textScaleChanged, (payload) => {
194
230
  applyTextScale(document, textScaleOf(payload));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cadence-app/compiler",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Compilation des templates en instructions, SCSS scopé, bundling",
5
5
  "keywords": [
6
6
  "compiler",
@@ -47,9 +47,9 @@
47
47
  "dependencies": {
48
48
  "@cadence-app/bridge": "0.2.0",
49
49
  "@cadence-app/core": "0.1.0",
50
- "@cadence-app/router": "0.2.0",
51
- "@cadence-app/runtime": "0.2.0",
52
- "@cadence-app/theme": "0.2.0",
50
+ "@cadence-app/router": "0.4.0",
51
+ "@cadence-app/runtime": "0.3.0",
52
+ "@cadence-app/theme": "0.3.0",
53
53
  "esbuild": "^0.25.0",
54
54
  "jszip": "^3.10.1",
55
55
  "postcss": "^8.5.1",