@g9tm/lynxcontrols-web 0.0.0-stage → 2.4.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.
- package/README.md +107 -2
- package/catalog/catalog.json +305 -0
- package/catalog/index.md +4 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/font.d.ts +7 -0
- package/dist/font.d.ts.map +1 -0
- package/dist/font.js +4 -0
- package/dist/font.js.map +1 -0
- package/dist/handler.d.ts +69 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +180 -0
- package/dist/handler.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/install.d.ts +96 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +310 -0
- package/dist/install.js.map +1 -0
- package/dist/module.d.ts +22 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +46 -0
- package/dist/module.js.map +1 -0
- package/dist/static.d.ts +57 -0
- package/dist/static.d.ts.map +1 -0
- package/dist/static.js +395 -0
- package/dist/static.js.map +1 -0
- package/package.json +44 -4
package/dist/handler.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
function ok(value) {
|
|
2
|
+
return {
|
|
3
|
+
ok: true,
|
|
4
|
+
value
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
const unsupported = (what)=>({
|
|
8
|
+
ok: false,
|
|
9
|
+
error: {
|
|
10
|
+
code: 'unsupported',
|
|
11
|
+
message: `${what} is not available in a browser.`
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const invalid = (message)=>({
|
|
15
|
+
ok: false,
|
|
16
|
+
error: {
|
|
17
|
+
code: 'invalid-argument',
|
|
18
|
+
message
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
function createMemoryWebStorage() {
|
|
22
|
+
const map = new Map();
|
|
23
|
+
return {
|
|
24
|
+
getItem: (key)=>{
|
|
25
|
+
var _map_get;
|
|
26
|
+
return null != (_map_get = map.get(key)) ? _map_get : null;
|
|
27
|
+
},
|
|
28
|
+
setItem: (key, value)=>void map.set(key, value),
|
|
29
|
+
removeItem: (key)=>void map.delete(key),
|
|
30
|
+
key: (index)=>{
|
|
31
|
+
var _index;
|
|
32
|
+
return null != (_index = [
|
|
33
|
+
...map.keys()
|
|
34
|
+
][index]) ? _index : null;
|
|
35
|
+
},
|
|
36
|
+
get length () {
|
|
37
|
+
return map.size;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function pageStorage() {
|
|
42
|
+
try {
|
|
43
|
+
return "u" < typeof localStorage ? null : localStorage;
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function createG9WebHostHandler(options = {}) {
|
|
49
|
+
var _pageStorage, _options_storage, _options_prefix, _options_insets;
|
|
50
|
+
const storage = void 0 === options.storage ? null != (_pageStorage = pageStorage()) ? _pageStorage : createMemoryWebStorage() : null != (_options_storage = options.storage) ? _options_storage : createMemoryWebStorage();
|
|
51
|
+
const prefix = null != (_options_prefix = options.prefix) ? _options_prefix : 'g9:';
|
|
52
|
+
const insets = null != (_options_insets = options.insets) ? _options_insets : ()=>({
|
|
53
|
+
top: 0,
|
|
54
|
+
end: 0,
|
|
55
|
+
bottom: 0,
|
|
56
|
+
start: 0
|
|
57
|
+
});
|
|
58
|
+
return (method, data)=>{
|
|
59
|
+
switch(method){
|
|
60
|
+
case 'capabilities':
|
|
61
|
+
return ok({
|
|
62
|
+
host: 'web',
|
|
63
|
+
preferences: true,
|
|
64
|
+
safeInsets: true,
|
|
65
|
+
haptics: void 0 !== options.vibrate,
|
|
66
|
+
hideKeyboard: void 0 !== options.blur,
|
|
67
|
+
exit: false,
|
|
68
|
+
softInputMode: false,
|
|
69
|
+
appDataDirectory: false,
|
|
70
|
+
sqlite: false
|
|
71
|
+
});
|
|
72
|
+
case 'getPreference':
|
|
73
|
+
{
|
|
74
|
+
const key = data.key;
|
|
75
|
+
if ('string' != typeof key) return invalid('getPreference needs a string key.');
|
|
76
|
+
const raw = storage.getItem(prefix + key);
|
|
77
|
+
if (null === raw) return ok(null);
|
|
78
|
+
try {
|
|
79
|
+
const stored = JSON.parse(raw);
|
|
80
|
+
if ('int' === stored.type && 'number' == typeof stored.value) return ok({
|
|
81
|
+
type: 'int',
|
|
82
|
+
value: stored.value
|
|
83
|
+
});
|
|
84
|
+
if ('string' === stored.type && 'string' == typeof stored.value) return ok({
|
|
85
|
+
type: 'string',
|
|
86
|
+
value: stored.value
|
|
87
|
+
});
|
|
88
|
+
} catch {}
|
|
89
|
+
return ok(null);
|
|
90
|
+
}
|
|
91
|
+
case 'setPreference':
|
|
92
|
+
{
|
|
93
|
+
const { key, kind, value } = data;
|
|
94
|
+
if ('string' != typeof key) return invalid('setPreference needs a string key.');
|
|
95
|
+
if ('remove' === kind) {
|
|
96
|
+
storage.removeItem(prefix + key);
|
|
97
|
+
return ok(null);
|
|
98
|
+
}
|
|
99
|
+
if ('int' === kind) {
|
|
100
|
+
const n = Number(value);
|
|
101
|
+
if (!Number.isInteger(n)) return invalid(`setPreference int needs a whole number, got ${String(value)}.`);
|
|
102
|
+
storage.setItem(prefix + key, JSON.stringify({
|
|
103
|
+
type: 'int',
|
|
104
|
+
value: n
|
|
105
|
+
}));
|
|
106
|
+
return ok(null);
|
|
107
|
+
}
|
|
108
|
+
if ('string' === kind && 'string' == typeof value) {
|
|
109
|
+
storage.setItem(prefix + key, JSON.stringify({
|
|
110
|
+
type: 'string',
|
|
111
|
+
value
|
|
112
|
+
}));
|
|
113
|
+
return ok(null);
|
|
114
|
+
}
|
|
115
|
+
return invalid(`setPreference kind ${String(kind)} is not int, string or remove.`);
|
|
116
|
+
}
|
|
117
|
+
case 'preferenceEntries':
|
|
118
|
+
{
|
|
119
|
+
const wanted = 'string' == typeof data.prefix ? data.prefix : '';
|
|
120
|
+
const out = [];
|
|
121
|
+
for(let i = 0; i < storage.length; i++){
|
|
122
|
+
const full = storage.key(i);
|
|
123
|
+
if (null == full ? void 0 : full.startsWith(prefix + wanted)) try {
|
|
124
|
+
var _storage_getItem;
|
|
125
|
+
const stored = JSON.parse(null != (_storage_getItem = storage.getItem(full)) ? _storage_getItem : 'null');
|
|
126
|
+
if (stored && ('int' === stored.type && 'number' == typeof stored.value || 'string' === stored.type && 'string' == typeof stored.value)) out.push([
|
|
127
|
+
full.slice(prefix.length),
|
|
128
|
+
stored.value
|
|
129
|
+
]);
|
|
130
|
+
} catch {}
|
|
131
|
+
}
|
|
132
|
+
return ok(out.sort((a, b)=>a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
133
|
+
}
|
|
134
|
+
case 'safeInsets':
|
|
135
|
+
return ok(insets());
|
|
136
|
+
case 'appDataDirectory':
|
|
137
|
+
return unsupported('An app data directory');
|
|
138
|
+
case 'assetUri':
|
|
139
|
+
{
|
|
140
|
+
const path = data.path;
|
|
141
|
+
if ('string' != typeof path) return invalid('assetUri needs a string path.');
|
|
142
|
+
return ok(options.assetUrl ? options.assetUrl(path) : path);
|
|
143
|
+
}
|
|
144
|
+
case 'hapticTick':
|
|
145
|
+
var _options_vibrate;
|
|
146
|
+
null == (_options_vibrate = options.vibrate) || _options_vibrate.call(options, 8);
|
|
147
|
+
return;
|
|
148
|
+
case 'hideKeyboard':
|
|
149
|
+
var _options_blur;
|
|
150
|
+
null == (_options_blur = options.blur) || _options_blur.call(options);
|
|
151
|
+
return;
|
|
152
|
+
case 'pilotFindings':
|
|
153
|
+
try {
|
|
154
|
+
var _data_payload;
|
|
155
|
+
var _options_onPilotFindings;
|
|
156
|
+
const parsed = JSON.parse(String(null != (_data_payload = data.payload) ? _data_payload : ''));
|
|
157
|
+
if (Array.isArray(parsed.findings)) null == (_options_onPilotFindings = options.onPilotFindings) || _options_onPilotFindings.call(options, {
|
|
158
|
+
findings: parsed.findings,
|
|
159
|
+
unsupported: Array.isArray(parsed.unsupported) ? parsed.unsupported : [],
|
|
160
|
+
checks: 'number' == typeof parsed.checks ? parsed.checks : 0
|
|
161
|
+
});
|
|
162
|
+
} catch {}
|
|
163
|
+
return;
|
|
164
|
+
case 'moveToBack':
|
|
165
|
+
case 'setSoftInputMode':
|
|
166
|
+
return;
|
|
167
|
+
default:
|
|
168
|
+
return {
|
|
169
|
+
ok: false,
|
|
170
|
+
error: {
|
|
171
|
+
code: 'not-found',
|
|
172
|
+
message: `G9HostModule has no ${method} on the web.`
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export { createG9WebHostHandler, createMemoryWebStorage, pageStorage };
|
|
179
|
+
|
|
180
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sources":["../src/handler.ts"],"sourcesContent":["// The page side of `G9HostModule` on the web: what a browser page answers when the page's code (in Lynx for Web's\n// worker) calls the host. The same contract as the Android and iOS hosts (@g9tm/lynxcontrols-native's\n// G9HostNativeModule): every reply an envelope `{ ok: true, value }` or `{ ok: false, error: { code, message } }`,\n// preferences typed (`int` / `string`), insets in dp. What a browser cannot do is said, never faked: `capabilities`\n// lists it, and a call that must answer (appDataDirectory) answers the typed error `unsupported`.\n\n/** A reply of the host, as the native modules send it. */\nexport type G9WebEnvelope<T> =\n | { readonly ok: true; readonly value: T }\n | { readonly ok: false; readonly error: { readonly code: string; readonly message: string } };\n\n/** The browser storage a host keeps preferences in (`localStorage` by default; tests pass a map). */\nexport interface G9WebStorage {\n getItem(key: string): string | null;\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n key(index: number): string | null;\n readonly length: number;\n}\n\n/** Safe-area insets in dp (the page's `env(safe-area-inset-*)`, start/end in the reading direction). */\nexport interface G9WebInsets {\n readonly top: number;\n readonly end: number;\n readonly bottom: number;\n readonly start: number;\n}\n\n/** Options of {@link createG9WebHostHandler}. */\nexport interface G9WebHostOptions {\n /** Where preferences live. Default: the page's `localStorage`; none (a private window that refuses it) = memory. */\n readonly storage?: G9WebStorage | null;\n /** Prefix of every preference key in the storage, so two apps on one origin stay apart. Default `'g9:'`. */\n readonly prefix?: string;\n /** The current safe-area insets. Default: none (0). */\n readonly insets?: () => G9WebInsets;\n /** A short vibration for `hapticTick` (`navigator.vibrate`); absent = haptics unsupported. */\n readonly vibrate?: (ms: number) => boolean;\n /** Blurs whatever has the focus (`hideKeyboard`); absent = a no-op the capabilities report. */\n readonly blur?: () => void;\n /** Resolves an asset path to a URL the page can load (`assetUri`). Default: the path as given. */\n readonly assetUrl?: (path: string) => string;\n /** G9AppPilot's findings as the page's watch sends them (profile `observe` and up; LC-08). */\n readonly onPilotFindings?: (findings: G9WebFindings) => void;\n}\n\n/** One finding of G9AppPilot's watch (`rule`, `severity`, `message`, …; @g9tm/lynxcontrols-pilot `G9PilotFinding`). */\nexport interface G9WebFinding {\n readonly rule: string;\n readonly message?: string;\n readonly severity?: string;\n readonly [field: string]: unknown;\n}\n\n/** What the page's watch sends: its findings, what this host cannot measure, and how many screen checks ran. */\nexport interface G9WebFindings {\n readonly findings: readonly G9WebFinding[];\n readonly unsupported: readonly { readonly rule: string; readonly reason: string }[];\n readonly checks: number;\n}\n\n// a function, not a generic arrow: the ReactLynx test transform reads `<T>(…) =>` in a .ts file as JSX\nfunction ok<T>(value: T): G9WebEnvelope<T> {\n return { ok: true, value };\n}\nconst unsupported = (what: string): G9WebEnvelope<never> => ({\n ok: false,\n error: { code: 'unsupported', message: `${what} is not available in a browser.` },\n});\nconst invalid = (message: string): G9WebEnvelope<never> => ({\n ok: false,\n error: { code: 'invalid-argument', message },\n});\n\n/** A storage kept in memory: where a browser gives none (a private window that throws on `localStorage`). */\nexport function createMemoryWebStorage(): G9WebStorage {\n const map = new Map<string, string>();\n return {\n getItem: (key) => map.get(key) ?? null,\n setItem: (key, value) => void map.set(key, value),\n removeItem: (key) => void map.delete(key),\n key: (index) => [...map.keys()][index] ?? null,\n get length() {\n return map.size;\n },\n };\n}\n\n/** The page's `localStorage`, or null where reading it throws (blocked storage, a sandboxed frame). */\nexport function pageStorage(): G9WebStorage | null {\n try {\n return typeof localStorage === 'undefined' ? null : (localStorage as G9WebStorage);\n } catch {\n return null;\n }\n}\n\n/**\n * The handler of `G9HostModule` calls on a web page: `(method, data) → envelope` for the calls that answer,\n * `undefined` for the fire-and-forget ones (moveToBack, hideKeyboard, setSoftInputMode, hapticTick, pilotFindings).\n */\nexport function createG9WebHostHandler(\n options: G9WebHostOptions = {},\n): (method: string, data: Readonly<Record<string, unknown>>) => G9WebEnvelope<unknown> | undefined {\n const storage =\n options.storage === undefined\n ? (pageStorage() ?? createMemoryWebStorage())\n : (options.storage ?? createMemoryWebStorage());\n const prefix = options.prefix ?? 'g9:';\n const insets = options.insets ?? (() => ({ top: 0, end: 0, bottom: 0, start: 0 }));\n return (method, data) => {\n switch (method) {\n case 'capabilities':\n return ok({\n host: 'web',\n preferences: true,\n safeInsets: true,\n haptics: options.vibrate !== undefined,\n hideKeyboard: options.blur !== undefined,\n exit: false,\n softInputMode: false,\n appDataDirectory: false,\n sqlite: false,\n });\n case 'getPreference': {\n const key = data.key;\n if (typeof key !== 'string') return invalid('getPreference needs a string key.');\n const raw = storage.getItem(prefix + key);\n if (raw === null) return ok(null);\n try {\n const stored = JSON.parse(raw) as { type?: unknown; value?: unknown };\n if (stored.type === 'int' && typeof stored.value === 'number')\n return ok({ type: 'int', value: stored.value });\n if (stored.type === 'string' && typeof stored.value === 'string')\n return ok({ type: 'string', value: stored.value });\n } catch {\n // written by something else: not ours\n }\n return ok(null);\n }\n case 'setPreference': {\n const { key, kind, value } = data as { key?: unknown; kind?: unknown; value?: unknown };\n if (typeof key !== 'string') return invalid('setPreference needs a string key.');\n if (kind === 'remove') {\n storage.removeItem(prefix + key);\n return ok(null);\n }\n if (kind === 'int') {\n const n = Number(value);\n if (!Number.isInteger(n)) return invalid(`setPreference int needs a whole number, got ${String(value)}.`);\n storage.setItem(prefix + key, JSON.stringify({ type: 'int', value: n }));\n return ok(null);\n }\n if (kind === 'string' && typeof value === 'string') {\n storage.setItem(prefix + key, JSON.stringify({ type: 'string', value }));\n return ok(null);\n }\n return invalid(`setPreference kind ${String(kind)} is not int, string or remove.`);\n }\n case 'preferenceEntries': {\n const wanted = typeof data.prefix === 'string' ? data.prefix : '';\n const out: Array<[string, number | string]> = [];\n for (let i = 0; i < storage.length; i++) {\n const full = storage.key(i);\n if (!full?.startsWith(prefix + wanted)) continue;\n try {\n const stored = JSON.parse(storage.getItem(full) ?? 'null') as { type?: unknown; value?: unknown } | null;\n // the same reading as getPreference: a type and a value that agree, or it is not ours\n if (\n stored &&\n ((stored.type === 'int' && typeof stored.value === 'number') ||\n (stored.type === 'string' && typeof stored.value === 'string'))\n )\n out.push([full.slice(prefix.length), stored.value]);\n } catch {\n // not ours\n }\n }\n // code-unit order (keys are the app's own names; no Intl in the library's tests)\n return ok(out.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)));\n }\n case 'safeInsets':\n return ok(insets());\n case 'appDataDirectory':\n return unsupported('An app data directory');\n case 'assetUri': {\n const path = data.path;\n if (typeof path !== 'string') return invalid('assetUri needs a string path.');\n return ok(options.assetUrl ? options.assetUrl(path) : path);\n }\n case 'hapticTick':\n options.vibrate?.(8);\n return undefined;\n case 'hideKeyboard':\n options.blur?.();\n return undefined;\n case 'pilotFindings': {\n try {\n const parsed = JSON.parse(String(data.payload ?? '')) as Partial<G9WebFindings>;\n if (Array.isArray(parsed.findings))\n options.onPilotFindings?.({\n findings: parsed.findings,\n unsupported: Array.isArray(parsed.unsupported) ? parsed.unsupported : [],\n checks: typeof parsed.checks === 'number' ? parsed.checks : 0,\n });\n } catch {\n // not the watch's payload: ignored\n }\n return undefined;\n }\n case 'moveToBack':\n case 'setSoftInputMode':\n // a page cannot send itself to the background or resize for a keyboard: the capabilities say so\n return undefined;\n default:\n return { ok: false, error: { code: 'not-found', message: `G9HostModule has no ${method} on the web.` } };\n }\n };\n}\n"],"names":["ok","value","unsupported","what","invalid","message","createMemoryWebStorage","map","Map","key","_map_get","index","_index","pageStorage","localStorage","createG9WebHostHandler","options","_pageStorage","_options_storage","_options_prefix","_options_insets","storage","undefined","prefix","insets","method","data","raw","stored","JSON","kind","n","Number","String","wanted","out","i","full","_storage_getItem","a","b","path","_data_payload","parsed","Array"],"mappings":"AA8DA,SAASA,GAAMC,KAAQ;IACrB,OAAO;QAAE,IAAI;QAAMA;IAAM;AAC3B;AACA,MAAMC,cAAc,CAACC,OAAwC;QAC3D,IAAI;QACJ,OAAO;YAAE,MAAM;YAAe,SAAS,GAAGA,KAAK,+BAA+B,CAAC;QAAC;IAClF;AACA,MAAMC,UAAU,CAACC,UAA2C;QAC1D,IAAI;QACJ,OAAO;YAAE,MAAM;YAAoBA;QAAQ;IAC7C;AAGO,SAASC;IACd,MAAMC,MAAM,IAAIC;IAChB,OAAO;QACL,SAAS,CAACC;gBAAQC;2BAAAA,CAAAA,WAAAA,IAAI,GAAG,CAACD,IAAG,IAAXC,WAAgB;;QAClC,SAAS,CAACD,KAAKR,QAAU,KAAKM,IAAI,GAAG,CAACE,KAAKR;QAC3C,YAAY,CAACQ,MAAQ,KAAKF,IAAI,MAAM,CAACE;QACrC,KAAK,CAACE;gBAAUC;2BAAAA,CAAAA,SAAAA;mBAAIL,IAAI,IAAI;aAAG,CAACI,MAAM,AAAD,IAArBC,SAA0B;;QAC1C,IAAI;YACF,OAAOL,IAAI,IAAI;QACjB;IACF;AACF;AAGO,SAASM;IACd,IAAI;QACF,OAAO,AAAwB,MAAxB,OAAOC,eAA+B,OAAQA;IACvD,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAMO,SAASC,uBACdC,UAA4B,CAAC,CAAC;QAIvBC,cACAC,kBACQC,iBACAC;IALf,MAAMC,UACJL,AAAoBM,WAApBN,QAAQ,OAAO,GAAKM,QACfL,CAAAA,eAAAA,aAAY,IAAZA,eAAiBX,2BAAA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,WAAW,GAAG,EAAE;wBACxE,QAAQ,AAAyB,YAAzB,OAAOA,OAAO,MAAM,GAAgBA,OAAO,MAAM,GAAG;oBAC9D;gBACJ,EAAE,OAAM,CAER;gBACA;YAEF,KAAK;YACL,KAAK;gBAEH;YACF;gBACE,OAAO;oBAAE,IAAI;oBAAO,OAAO;wBAAE,MAAM;wBAAa,SAAS,CAAC,oBAAoB,EAAElB,OAAO,YAAY,CAAC;oBAAC;gBAAE;QAC3G;IACF;AACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createG9WebHostHandler, createMemoryWebStorage, type G9WebEnvelope, type G9WebFinding, type G9WebFindings, type G9WebHostOptions, type G9WebInsets, type G9WebStorage, pageStorage, } from './handler.js';
|
|
2
|
+
export { bridgeStartText, bridgeViewportUnits, checkG9WebScreen, G9_WEB_STYLE_RULES, type G9LynxViewElement, type G9SizeWatcher, type G9WebInstallOptions, g9WebFindings, g9WebHostModuleUrl, installG9WebHost, pageSafeInsets, subscribeG9WebFindings, toContainerUnits, } from './install.js';
|
|
3
|
+
export type { G9WebHostModule } from './module.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { createG9WebHostHandler, createMemoryWebStorage, pageStorage } from "./handler.js";
|
|
2
|
+
export { G9_WEB_STYLE_RULES, bridgeStartText, bridgeViewportUnits, checkG9WebScreen, g9WebFindings, g9WebHostModuleUrl, installG9WebHost, pageSafeInsets, subscribeG9WebFindings, toContainerUnits } from "./install.js";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type G9WebFindings, type G9WebHostOptions, type G9WebInsets } from './handler.js';
|
|
2
|
+
/** The part of a `<lynx-view>` element (@lynx-js/web-core) the host uses. */
|
|
3
|
+
export interface G9LynxViewElement {
|
|
4
|
+
nativeModulesMap?: Record<string, string> | undefined;
|
|
5
|
+
onNativeModulesCall?: ((name: string, data: unknown, moduleName: string) => unknown) | undefined;
|
|
6
|
+
sendGlobalEvent?(eventName: string, params: unknown[]): void;
|
|
7
|
+
/** The view's own events (`error`: the runtime caught an error in the page's code). */
|
|
8
|
+
addEventListener?(type: string, listener: (event: {
|
|
9
|
+
readonly detail?: unknown;
|
|
10
|
+
}) => void): void;
|
|
11
|
+
removeEventListener?(type: string, listener: (event: {
|
|
12
|
+
readonly detail?: unknown;
|
|
13
|
+
}) => void): void;
|
|
14
|
+
/** CSS rules inserted into the view's shadow root, read when the card starts. */
|
|
15
|
+
injectStyleRules?: string[] | undefined;
|
|
16
|
+
/** The view's SystemInfo overrides (pixelWidth / pixelHeight / pixelRatio), read when the card starts. */
|
|
17
|
+
browserConfig?: Record<string, unknown> | string | undefined;
|
|
18
|
+
readonly clientWidth?: number;
|
|
19
|
+
readonly clientHeight?: number;
|
|
20
|
+
/** Where the card's elements live (an open shadow root, attached when the view first renders). */
|
|
21
|
+
readonly shadowRoot?: Node | null;
|
|
22
|
+
attachShadow?(init: {
|
|
23
|
+
mode: 'open' | 'closed';
|
|
24
|
+
}): Node;
|
|
25
|
+
}
|
|
26
|
+
/** Watches an element's size (`ResizeObserver`); tests pass a fake. Returns the stop function. */
|
|
27
|
+
export type G9SizeWatcher = (element: object, onResize: () => void) => () => void;
|
|
28
|
+
/**
|
|
29
|
+
* The rules the host adds to the view's shadow root so a browser draws text as the native engines do:
|
|
30
|
+
* - the system font: a browser's default is a serif, the native default the system's sans;
|
|
31
|
+
* - each text's direction from its first strong letter (`@g9tm/lynxcontrols` in a Persian page reads as written, as on
|
|
32
|
+
* Android and iOS), where the browser would take it from the CSS `direction` and move the `@` to the end;
|
|
33
|
+
* - the view as a size container, the box the viewport units measure against ({@link bridgeViewportUnits}).
|
|
34
|
+
*/
|
|
35
|
+
export declare const G9_WEB_STYLE_RULES: readonly string[];
|
|
36
|
+
/** `100vw` → `100cqw`, `calc(50vh - 8px)` → `calc(50cqh - 8px)`. */
|
|
37
|
+
export declare const toContainerUnits: (value: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Viewport units on the web: a native engine measures `vw` / `vh` against the LynxView, a browser against its window,
|
|
40
|
+
* so lynx-ui's sheet (`width: 100vw`) in a 390 px view inside a 1,600 px window was 1,600 px wide and its text ran out
|
|
41
|
+
* of the view. The view is a size container (`:host { container-type: size }`, {@link G9_WEB_STYLE_RULES}; it already
|
|
42
|
+
* has `contain: strict`), and every viewport unit under `root` becomes the container's own (`cqw`, `cqh`, `cqmin`,
|
|
43
|
+
* `cqmax`): in each style sheet once, and in each element's inline style as it is written. Returns the stop function.
|
|
44
|
+
*/
|
|
45
|
+
export declare function bridgeViewportUnits(root: Node & {
|
|
46
|
+
styleSheets?: StyleSheetList;
|
|
47
|
+
adoptedStyleSheets?: CSSStyleSheet[];
|
|
48
|
+
}): () => void;
|
|
49
|
+
/**
|
|
50
|
+
* Lynx's `<input default-value>` / `<textarea default-value>` (the start text, which G9's number, time and tag entries
|
|
51
|
+
* write) on the web: Lynx for Web's `x-input` and `x-textarea` know only `value`, so a time entry started at 08:30 drew
|
|
52
|
+
* an empty box. Every input that appears under `root` with a start text gets it as its `value`, once; later text comes
|
|
53
|
+
* from the control's own `setValue`, as on the native engines. Returns the stop function (nothing to stop without a
|
|
54
|
+
* `MutationObserver`).
|
|
55
|
+
*/
|
|
56
|
+
export declare function bridgeStartText(root: Node): () => void;
|
|
57
|
+
/** Options of {@link installG9WebHost}. */
|
|
58
|
+
export interface G9WebInstallOptions extends G9WebHostOptions {
|
|
59
|
+
/** The URL of this package's worker module (`@g9tm/lynxcontrols-web/module`), when a bundler moved it. */
|
|
60
|
+
readonly moduleUrl?: string;
|
|
61
|
+
/** Where resizes come from (default: the page's `window`); tests pass a fake. */
|
|
62
|
+
readonly resizeTarget?: {
|
|
63
|
+
addEventListener(type: 'resize', l: () => void): void;
|
|
64
|
+
removeEventListener(type: 'resize', l: () => void): void;
|
|
65
|
+
} | null;
|
|
66
|
+
/** How the view's own size is watched (default: a `ResizeObserver`; null: the layout keeps the start size). */
|
|
67
|
+
readonly sizeWatcher?: G9SizeWatcher | null;
|
|
68
|
+
/** The device pixel ratio (default: the page's `devicePixelRatio`). */
|
|
69
|
+
readonly pixelRatio?: number;
|
|
70
|
+
/** The rules added to the view's shadow root (default {@link G9_WEB_STYLE_RULES}; `[]` adds none). */
|
|
71
|
+
readonly styleRules?: readonly string[];
|
|
72
|
+
}
|
|
73
|
+
/** The page's safe-area insets in px (= dp on the web), start/end in the document's direction; 0 without `env()`. */
|
|
74
|
+
export declare function pageSafeInsets(): G9WebInsets;
|
|
75
|
+
/**
|
|
76
|
+
* The default URL of the worker module: `module.js` next to this file in the published package. Plain string work on
|
|
77
|
+
* `import.meta.url`, never `new URL('./module.js', import.meta.url)`: a bundler rewrites that pattern (rslib copied
|
|
78
|
+
* module.ts as an asset, and with a variable it emitted a `require` context that fails in a browser).
|
|
79
|
+
*/
|
|
80
|
+
export declare const g9WebHostModuleUrl: () => string;
|
|
81
|
+
/**
|
|
82
|
+
* The latest findings of G9AppPilot's watch in `view`'s page (LC-08: the bundle built with the `observe` profile or up,
|
|
83
|
+
* `@g9tm/lynxcontrols-pilot`): js errors, controls without a name, translation keys and controls off screen, and what
|
|
84
|
+
* a browser cannot measure (`unsupported`). Null before the watch has sent anything (or in a build without it).
|
|
85
|
+
*/
|
|
86
|
+
export declare function g9WebFindings(view: object): G9WebFindings | null;
|
|
87
|
+
/** Calls `listener` with every set of findings `view`'s watch sends; returns the unsubscribe. */
|
|
88
|
+
export declare function subscribeG9WebFindings(view: object, listener: (findings: G9WebFindings) => void): () => void;
|
|
89
|
+
/**
|
|
90
|
+
* Asks the watch to run its screen rules now (`oracle.check`) and resolves with the findings it sends after that
|
|
91
|
+
* check; null when nothing answers within `timeoutMs` (a build without the watch).
|
|
92
|
+
*/
|
|
93
|
+
export declare function checkG9WebScreen(view: G9LynxViewElement, timeoutMs?: number): Promise<G9WebFindings | null>;
|
|
94
|
+
/** Installs the host on `view`; returns the uninstaller (the previous handler and map come back). */
|
|
95
|
+
export declare function installG9WebHost(view: G9LynxViewElement, options?: G9WebInstallOptions): () => void;
|
|
96
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAWA,OAAO,EAA0B,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAEhH,6EAA6E;AAC7E,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACtD,mBAAmB,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;IACjG,eAAe,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC7D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gBAAgB,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,IAAI,CA0FvG"}
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { G9_WEB_FONT_STACK } from "./font.js";
|
|
2
|
+
import { createG9WebHostHandler } from "./handler.js";
|
|
3
|
+
function resizeObserverWatcher() {
|
|
4
|
+
if ("u" < typeof ResizeObserver) return null;
|
|
5
|
+
return (element, onResize)=>{
|
|
6
|
+
const observer = new ResizeObserver(()=>onResize());
|
|
7
|
+
observer.observe(element);
|
|
8
|
+
return ()=>observer.disconnect();
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const G9_WEB_STYLE_RULES = [
|
|
12
|
+
`:host { font-family: ${G9_WEB_FONT_STACK}; }`,
|
|
13
|
+
'x-text::part(inner-box) { unicode-bidi: plaintext; }',
|
|
14
|
+
':host { container-type: size; }'
|
|
15
|
+
];
|
|
16
|
+
const VIEWPORT_UNIT = /(\d)v(w|h|min|max)\b/g;
|
|
17
|
+
const HAS_VIEWPORT_UNIT = /\dv(w|h|min|max)\b/;
|
|
18
|
+
const toContainerUnits = (value)=>value.replace(VIEWPORT_UNIT, '$1cq$2');
|
|
19
|
+
function rewriteDeclaration(style) {
|
|
20
|
+
for(let i = 0; i < style.length; i++){
|
|
21
|
+
const name = style.item(i);
|
|
22
|
+
const value = style.getPropertyValue(name);
|
|
23
|
+
if (HAS_VIEWPORT_UNIT.test(value)) style.setProperty(name, toContainerUnits(value), style.getPropertyPriority(name));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function rewriteRules(rules) {
|
|
27
|
+
for(let i = 0; i < rules.length; i++){
|
|
28
|
+
const rule = rules[i];
|
|
29
|
+
if (rule.style) rewriteDeclaration(rule.style);
|
|
30
|
+
if (rule.cssRules) rewriteRules(rule.cssRules);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function bridgeViewportUnits(root) {
|
|
34
|
+
if ("u" < typeof MutationObserver) return ()=>void 0;
|
|
35
|
+
const seen = new WeakSet();
|
|
36
|
+
const sheets = ()=>{
|
|
37
|
+
var _root_styleSheets, _root_adoptedStyleSheets;
|
|
38
|
+
for (const sheet of [
|
|
39
|
+
...Array.from(null != (_root_styleSheets = root.styleSheets) ? _root_styleSheets : []),
|
|
40
|
+
...null != (_root_adoptedStyleSheets = root.adoptedStyleSheets) ? _root_adoptedStyleSheets : []
|
|
41
|
+
])if (!seen.has(sheet)) {
|
|
42
|
+
seen.add(sheet);
|
|
43
|
+
try {
|
|
44
|
+
rewriteRules(sheet.cssRules);
|
|
45
|
+
} catch {}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const inline = (element)=>{
|
|
49
|
+
const text = element.getAttribute('style');
|
|
50
|
+
if (text && HAS_VIEWPORT_UNIT.test(text)) rewriteDeclaration(element.style);
|
|
51
|
+
};
|
|
52
|
+
const scan = (node)=>{
|
|
53
|
+
if (!(node instanceof Element)) return;
|
|
54
|
+
inline(node);
|
|
55
|
+
for (const e of Array.from(node.querySelectorAll('[style]')))inline(e);
|
|
56
|
+
};
|
|
57
|
+
sheets();
|
|
58
|
+
for (const child of Array.from(root.childNodes))scan(child);
|
|
59
|
+
const observer = new MutationObserver((records)=>{
|
|
60
|
+
sheets();
|
|
61
|
+
for (const r of records)if ('childList' === r.type) for (const n of Array.from(r.addedNodes))scan(n);
|
|
62
|
+
else if (r.target instanceof Element) inline(r.target);
|
|
63
|
+
});
|
|
64
|
+
observer.observe(root, {
|
|
65
|
+
childList: true,
|
|
66
|
+
subtree: true,
|
|
67
|
+
attributes: true,
|
|
68
|
+
attributeFilter: [
|
|
69
|
+
'style'
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
return ()=>observer.disconnect();
|
|
73
|
+
}
|
|
74
|
+
const INPUTS = 'x-input[default-value], x-textarea[default-value]';
|
|
75
|
+
function startTextOf(element) {
|
|
76
|
+
const text = element.getAttribute('default-value');
|
|
77
|
+
if (null !== text && !element.hasAttribute('value')) element.setAttribute('value', text);
|
|
78
|
+
}
|
|
79
|
+
function bridgeStartText(root) {
|
|
80
|
+
if ("u" < typeof MutationObserver) return ()=>void 0;
|
|
81
|
+
const scan = (node)=>{
|
|
82
|
+
if (!(node instanceof Element)) return;
|
|
83
|
+
if (node.matches(INPUTS)) startTextOf(node);
|
|
84
|
+
for (const input of Array.from(node.querySelectorAll(INPUTS)))startTextOf(input);
|
|
85
|
+
};
|
|
86
|
+
for (const child of Array.from(root.childNodes))scan(child);
|
|
87
|
+
const observer = new MutationObserver((records)=>{
|
|
88
|
+
for (const r of records)if ('childList' === r.type) for (const n of Array.from(r.addedNodes))scan(n);
|
|
89
|
+
else if (null === r.oldValue && r.target instanceof Element && r.target.matches(INPUTS)) startTextOf(r.target);
|
|
90
|
+
});
|
|
91
|
+
observer.observe(root, {
|
|
92
|
+
childList: true,
|
|
93
|
+
subtree: true,
|
|
94
|
+
attributes: true,
|
|
95
|
+
attributeFilter: [
|
|
96
|
+
'default-value'
|
|
97
|
+
],
|
|
98
|
+
attributeOldValue: true
|
|
99
|
+
});
|
|
100
|
+
return ()=>observer.disconnect();
|
|
101
|
+
}
|
|
102
|
+
function pageSafeInsets() {
|
|
103
|
+
if ("u" < typeof document || !document.body) return {
|
|
104
|
+
top: 0,
|
|
105
|
+
end: 0,
|
|
106
|
+
bottom: 0,
|
|
107
|
+
start: 0
|
|
108
|
+
};
|
|
109
|
+
const probe = document.createElement('div');
|
|
110
|
+
probe.style.cssText = 'position:fixed;visibility:hidden;pointer-events:none;padding:env(safe-area-inset-top,0px) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px)';
|
|
111
|
+
document.body.appendChild(probe);
|
|
112
|
+
const style = getComputedStyle(probe);
|
|
113
|
+
const px = (v)=>Number.parseFloat(v) || 0;
|
|
114
|
+
const left = px(style.paddingLeft);
|
|
115
|
+
const right = px(style.paddingRight);
|
|
116
|
+
const insets = {
|
|
117
|
+
top: px(style.paddingTop),
|
|
118
|
+
bottom: px(style.paddingBottom)
|
|
119
|
+
};
|
|
120
|
+
probe.remove();
|
|
121
|
+
const rtl = 'rtl' === document.documentElement.dir;
|
|
122
|
+
return {
|
|
123
|
+
...insets,
|
|
124
|
+
start: rtl ? right : left,
|
|
125
|
+
end: rtl ? left : right
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const g9WebHostModuleUrl = ()=>{
|
|
129
|
+
const here = import.meta.url;
|
|
130
|
+
return `${here.slice(0, here.lastIndexOf('/') + 1)}module.js`;
|
|
131
|
+
};
|
|
132
|
+
const findingsOf = new WeakMap();
|
|
133
|
+
function stateOf(view) {
|
|
134
|
+
let state = findingsOf.get(view);
|
|
135
|
+
if (!state) {
|
|
136
|
+
state = {
|
|
137
|
+
latest: null,
|
|
138
|
+
listeners: new Set()
|
|
139
|
+
};
|
|
140
|
+
findingsOf.set(view, state);
|
|
141
|
+
}
|
|
142
|
+
return state;
|
|
143
|
+
}
|
|
144
|
+
function g9WebFindings(view) {
|
|
145
|
+
var _ref;
|
|
146
|
+
var _findingsOf_get;
|
|
147
|
+
return null != (_ref = null == (_findingsOf_get = findingsOf.get(view)) ? void 0 : _findingsOf_get.latest) ? _ref : null;
|
|
148
|
+
}
|
|
149
|
+
function subscribeG9WebFindings(view, listener) {
|
|
150
|
+
const state = stateOf(view);
|
|
151
|
+
state.listeners.add(listener);
|
|
152
|
+
return ()=>void state.listeners.delete(listener);
|
|
153
|
+
}
|
|
154
|
+
function checkG9WebScreen(view, timeoutMs = 5000) {
|
|
155
|
+
var _ref;
|
|
156
|
+
var _g9WebFindings;
|
|
157
|
+
const before = null != (_ref = null == (_g9WebFindings = g9WebFindings(view)) ? void 0 : _g9WebFindings.checks) ? _ref : 0;
|
|
158
|
+
return new Promise((resolve)=>{
|
|
159
|
+
var _view_sendGlobalEvent;
|
|
160
|
+
let done = false;
|
|
161
|
+
const finish = (value)=>{
|
|
162
|
+
if (done) return;
|
|
163
|
+
done = true;
|
|
164
|
+
stop();
|
|
165
|
+
clearTimeout(timer);
|
|
166
|
+
resolve(value);
|
|
167
|
+
};
|
|
168
|
+
const stop = subscribeG9WebFindings(view, (findings)=>{
|
|
169
|
+
if (findings.checks > before) finish(findings);
|
|
170
|
+
});
|
|
171
|
+
const timer = setTimeout(()=>finish(null), timeoutMs);
|
|
172
|
+
null == (_view_sendGlobalEvent = view.sendGlobalEvent) || _view_sendGlobalEvent.call(view, 'g9:pilot-check', []);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function errorText(detail) {
|
|
176
|
+
if ('string' == typeof detail) return detail;
|
|
177
|
+
const d = detail;
|
|
178
|
+
const inner = null == d ? void 0 : d.error;
|
|
179
|
+
if ('string' == typeof inner) return inner;
|
|
180
|
+
if ('string' == typeof (null == inner ? void 0 : inner.message)) return inner.message;
|
|
181
|
+
if ('string' == typeof (null == d ? void 0 : d.message)) return d.message;
|
|
182
|
+
try {
|
|
183
|
+
var _JSON_stringify;
|
|
184
|
+
return null != (_JSON_stringify = JSON.stringify(detail)) ? _JSON_stringify : '';
|
|
185
|
+
} catch {
|
|
186
|
+
return String(detail);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function installG9WebHost(view, options = {}) {
|
|
190
|
+
var _options_insets, _options_moduleUrl, _options_styleRules, _options_pixelRatio;
|
|
191
|
+
var _view_addEventListener;
|
|
192
|
+
const insets = null != (_options_insets = options.insets) ? _options_insets : pageSafeInsets;
|
|
193
|
+
const findings = stateOf(view);
|
|
194
|
+
const handle = createG9WebHostHandler({
|
|
195
|
+
...options,
|
|
196
|
+
insets,
|
|
197
|
+
onPilotFindings: (next)=>{
|
|
198
|
+
var _options_onPilotFindings;
|
|
199
|
+
findings.latest = next;
|
|
200
|
+
for (const listener of [
|
|
201
|
+
...findings.listeners
|
|
202
|
+
])listener(next);
|
|
203
|
+
null == (_options_onPilotFindings = options.onPilotFindings) || _options_onPilotFindings.call(options, next);
|
|
204
|
+
},
|
|
205
|
+
...void 0 === options.vibrate && "u" > typeof navigator && 'function' == typeof navigator.vibrate ? {
|
|
206
|
+
vibrate: (ms)=>navigator.vibrate(ms)
|
|
207
|
+
} : {},
|
|
208
|
+
...void 0 === options.blur && "u" > typeof document ? {
|
|
209
|
+
blur: ()=>{
|
|
210
|
+
var _document_activeElement_blur, _document_activeElement;
|
|
211
|
+
return null == (_document_activeElement = document.activeElement) ? void 0 : null == (_document_activeElement_blur = _document_activeElement.blur) ? void 0 : _document_activeElement_blur.call(_document_activeElement);
|
|
212
|
+
}
|
|
213
|
+
} : {}
|
|
214
|
+
});
|
|
215
|
+
const previousMap = view.nativeModulesMap;
|
|
216
|
+
const previousCall = view.onNativeModulesCall;
|
|
217
|
+
view.nativeModulesMap = {
|
|
218
|
+
...null != previousMap ? previousMap : {},
|
|
219
|
+
G9HostModule: null != (_options_moduleUrl = options.moduleUrl) ? _options_moduleUrl : g9WebHostModuleUrl()
|
|
220
|
+
};
|
|
221
|
+
view.onNativeModulesCall = (name, data, moduleName)=>'G9HostModule' === moduleName ? handle(name, null != data ? data : {}) : null == previousCall ? void 0 : previousCall(name, data, moduleName);
|
|
222
|
+
const previousRules = view.injectStyleRules;
|
|
223
|
+
const rules = null != (_options_styleRules = options.styleRules) ? _options_styleRules : G9_WEB_STYLE_RULES;
|
|
224
|
+
if (rules.length) view.injectStyleRules = [
|
|
225
|
+
...null != previousRules ? previousRules : [],
|
|
226
|
+
...rules
|
|
227
|
+
];
|
|
228
|
+
let stopBridges;
|
|
229
|
+
const ownAttach = Object.prototype.hasOwnProperty.call(view, 'attachShadow') ? view.attachShadow : void 0;
|
|
230
|
+
const bridge = (root)=>{
|
|
231
|
+
const stops = [
|
|
232
|
+
bridgeStartText(root),
|
|
233
|
+
bridgeViewportUnits(root)
|
|
234
|
+
];
|
|
235
|
+
stopBridges = ()=>{
|
|
236
|
+
for (const stop of stops)stop();
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
if (view.shadowRoot) bridge(view.shadowRoot);
|
|
240
|
+
else if ('function' == typeof view.attachShadow) {
|
|
241
|
+
const attach = view.attachShadow;
|
|
242
|
+
view.attachShadow = function(init) {
|
|
243
|
+
const root = attach.call(this, init);
|
|
244
|
+
bridge(root);
|
|
245
|
+
return root;
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const onError = (event)=>{
|
|
249
|
+
var _view_sendGlobalEvent;
|
|
250
|
+
return null == (_view_sendGlobalEvent = view.sendGlobalEvent) ? void 0 : _view_sendGlobalEvent.call(view, 'g9:lynx-error', [
|
|
251
|
+
errorText(event.detail)
|
|
252
|
+
]);
|
|
253
|
+
};
|
|
254
|
+
null == (_view_addEventListener = view.addEventListener) || _view_addEventListener.call(view, 'error', onError);
|
|
255
|
+
const resizes = void 0 === options.resizeTarget ? "u" < typeof window ? null : window : options.resizeTarget;
|
|
256
|
+
const onResize = ()=>{
|
|
257
|
+
var _view_sendGlobalEvent;
|
|
258
|
+
return null == (_view_sendGlobalEvent = view.sendGlobalEvent) ? void 0 : _view_sendGlobalEvent.call(view, 'g9:insets', [
|
|
259
|
+
insets()
|
|
260
|
+
]);
|
|
261
|
+
};
|
|
262
|
+
null == resizes || resizes.addEventListener('resize', onResize);
|
|
263
|
+
const ratio = null != (_options_pixelRatio = options.pixelRatio) ? _options_pixelRatio : 'number' == typeof devicePixelRatio && devicePixelRatio > 0 ? devicePixelRatio : 1;
|
|
264
|
+
const size = ()=>{
|
|
265
|
+
var _view_clientWidth, _view_clientHeight;
|
|
266
|
+
return {
|
|
267
|
+
width: null != (_view_clientWidth = view.clientWidth) ? _view_clientWidth : 0,
|
|
268
|
+
height: null != (_view_clientHeight = view.clientHeight) ? _view_clientHeight : 0
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
const previousConfig = view.browserConfig;
|
|
272
|
+
const start = size();
|
|
273
|
+
if (start.width > 0 && start.height > 0) {
|
|
274
|
+
const base = 'object' == typeof previousConfig && null !== previousConfig ? previousConfig : {};
|
|
275
|
+
view.browserConfig = {
|
|
276
|
+
...base,
|
|
277
|
+
pixelRatio: ratio,
|
|
278
|
+
pixelWidth: start.width * ratio,
|
|
279
|
+
pixelHeight: start.height * ratio
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
let last = start;
|
|
283
|
+
const watcher = void 0 === options.sizeWatcher ? resizeObserverWatcher() : options.sizeWatcher;
|
|
284
|
+
const stopWatching = null == watcher ? void 0 : watcher(view, ()=>{
|
|
285
|
+
var _view_sendGlobalEvent;
|
|
286
|
+
const next = size();
|
|
287
|
+
if (next.width === last.width && next.height === last.height) return;
|
|
288
|
+
last = next;
|
|
289
|
+
null == (_view_sendGlobalEvent = view.sendGlobalEvent) || _view_sendGlobalEvent.call(view, 'onWindowResize', [
|
|
290
|
+
next.width,
|
|
291
|
+
next.height
|
|
292
|
+
]);
|
|
293
|
+
});
|
|
294
|
+
return ()=>{
|
|
295
|
+
var _view_removeEventListener;
|
|
296
|
+
null == (_view_removeEventListener = view.removeEventListener) || _view_removeEventListener.call(view, 'error', onError);
|
|
297
|
+
null == stopBridges || stopBridges();
|
|
298
|
+
if (ownAttach) view.attachShadow = ownAttach;
|
|
299
|
+
else delete view.attachShadow;
|
|
300
|
+
null == stopWatching || stopWatching();
|
|
301
|
+
null == resizes || resizes.removeEventListener('resize', onResize);
|
|
302
|
+
view.nativeModulesMap = previousMap;
|
|
303
|
+
view.onNativeModulesCall = previousCall;
|
|
304
|
+
view.browserConfig = previousConfig;
|
|
305
|
+
view.injectStyleRules = previousRules;
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
export { G9_WEB_STYLE_RULES, bridgeStartText, bridgeViewportUnits, checkG9WebScreen, g9WebFindings, g9WebHostModuleUrl, installG9WebHost, pageSafeInsets, subscribeG9WebFindings, toContainerUnits };
|
|
309
|
+
|
|
310
|
+
//# sourceMappingURL=install.js.map
|