@celljs/ta-web 4.34.0 → 4.35.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.
Files changed (221) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/esm/browser/apps/app-icon.d.ts +23 -0
  4. package/esm/browser/apps/app-icon.js +98 -0
  5. package/esm/browser/apps/app-settings.d.ts +6 -0
  6. package/esm/browser/apps/app-settings.js +67 -0
  7. package/esm/browser/apps/app-window-util.d.ts +23 -0
  8. package/esm/browser/apps/app-window-util.js +27 -0
  9. package/esm/browser/apps/app-window.d.ts +9 -0
  10. package/esm/browser/apps/app-window.js +90 -0
  11. package/esm/browser/apps/web-apps.d.ts +29 -0
  12. package/esm/browser/apps/web-apps.js +57 -0
  13. package/esm/browser/assistant/call-keeper.d.ts +2 -5
  14. package/esm/browser/assistant/call-keeper.js +7 -11
  15. package/esm/browser/components/access-settings.d.ts +6 -0
  16. package/esm/browser/components/access-settings.js +52 -0
  17. package/esm/browser/components/app-root.d.ts +6 -0
  18. package/esm/browser/components/app-root.js +34 -0
  19. package/esm/browser/components/app-view.d.ts +8 -2
  20. package/esm/browser/components/app-view.js +1 -25
  21. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  22. package/esm/browser/components/host-view.d.ts +1 -1
  23. package/esm/browser/components/settings-more.js +6 -0
  24. package/esm/browser/device/screen-awake.d.ts +16 -0
  25. package/esm/browser/device/screen-awake.js +37 -0
  26. package/esm/browser/device/sheet-swipe.js +4 -0
  27. package/esm/browser/extension/icons.js +2 -1
  28. package/esm/browser/extension/web-access.d.ts +16 -0
  29. package/esm/browser/extension/web-access.js +75 -0
  30. package/esm/browser/extension/web-api-desktop.d.ts +23 -0
  31. package/esm/browser/extension/web-api-spec.d.ts +70 -0
  32. package/esm/browser/extension/web-api-spec.js +223 -0
  33. package/esm/browser/extension/web-extension-api.d.ts +6 -0
  34. package/esm/browser/extension/web-extension-context.js +11 -2
  35. package/esm/browser/extension/web-extension-run.d.ts +6 -1
  36. package/esm/browser/extension/web-extension-run.js +25 -0
  37. package/esm/browser/extension/web-extensions-running.d.ts +18 -1
  38. package/esm/browser/extension/web-extensions-running.js +102 -9
  39. package/esm/browser/extension/web-pages.d.ts +5 -0
  40. package/esm/browser/extension/web-pages.js +3 -0
  41. package/esm/browser/i18n/en/common.d.ts +1 -0
  42. package/esm/browser/i18n/en/common.js +1 -0
  43. package/esm/browser/i18n/en/discover.d.ts +11 -0
  44. package/esm/browser/i18n/en/discover.js +11 -0
  45. package/esm/browser/i18n/en/settings.d.ts +28 -0
  46. package/esm/browser/i18n/en/settings.js +28 -0
  47. package/esm/browser/i18n/ja/common.js +1 -0
  48. package/esm/browser/i18n/ja/discover.js +11 -0
  49. package/esm/browser/i18n/ja/settings.js +28 -0
  50. package/esm/browser/i18n/locales.d.ts +41 -3
  51. package/esm/browser/i18n/messages.d.ts +40 -2
  52. package/esm/browser/i18n/zh/common.js +1 -0
  53. package/esm/browser/i18n/zh/discover.js +11 -0
  54. package/esm/browser/i18n/zh/settings.js +28 -0
  55. package/esm/browser/i18n/zh-tw/common.js +1 -0
  56. package/esm/browser/i18n/zh-tw/discover.js +11 -0
  57. package/esm/browser/i18n/zh-tw/settings.js +28 -0
  58. package/esm/browser/index.d.ts +1 -0
  59. package/esm/browser/index.js +1 -0
  60. package/esm/browser/notices/notices.js +1 -0
  61. package/esm/browser/sandbox/channel/channel.d.ts +56 -0
  62. package/esm/browser/sandbox/channel/channel.js +124 -0
  63. package/esm/browser/sandbox/channel/codec.d.ts +80 -0
  64. package/esm/browser/sandbox/channel/codec.js +251 -0
  65. package/esm/browser/sandbox/hook-host.d.ts +23 -0
  66. package/esm/browser/sandbox/hook-host.js +61 -0
  67. package/esm/browser/sandbox/isolated-host.d.ts +105 -0
  68. package/esm/browser/sandbox/isolated-host.js +395 -0
  69. package/esm/browser/sandbox/remote/remote-copy.d.ts +56 -0
  70. package/esm/browser/sandbox/remote/remote-copy.js +302 -0
  71. package/esm/browser/sandbox/remote/remote-mirror.d.ts +61 -0
  72. package/esm/browser/sandbox/remote/remote-mirror.js +341 -0
  73. package/esm/browser/sandbox/remote/remote-protocol.d.ts +79 -0
  74. package/esm/browser/sandbox/remote/remote-protocol.js +54 -0
  75. package/esm/browser/sandbox/remote/remote-styles.d.ts +10 -0
  76. package/esm/browser/sandbox/remote/remote-styles.js +113 -0
  77. package/esm/browser/sandbox/remote-root.d.ts +11 -0
  78. package/esm/browser/sandbox/remote-root.js +81 -0
  79. package/esm/browser/sandbox/runtime/frame-api.d.ts +28 -0
  80. package/esm/browser/sandbox/runtime/frame-api.js +147 -0
  81. package/esm/browser/sandbox/runtime/frame-features.d.ts +6 -0
  82. package/esm/browser/sandbox/runtime/frame-features.js +50 -0
  83. package/esm/browser/sandbox/runtime/frame-parts.d.ts +36 -0
  84. package/esm/browser/sandbox/runtime/frame-parts.js +69 -0
  85. package/esm/browser/sandbox/runtime/frame-roots.d.ts +26 -0
  86. package/esm/browser/sandbox/runtime/frame-roots.js +76 -0
  87. package/esm/browser/sandbox/runtime/frame-store.d.ts +9 -0
  88. package/esm/browser/sandbox/runtime/frame-store.js +18 -0
  89. package/esm/browser/sandbox/runtime/sandbox-runtime.d.ts +11 -0
  90. package/esm/browser/sandbox/runtime/sandbox-runtime.js +45 -0
  91. package/esm/browser/sandbox/sandbox-features.d.ts +25 -0
  92. package/esm/browser/sandbox/sandbox-features.js +32 -0
  93. package/esm/browser/sandbox/sandbox-frame.d.ts +21 -0
  94. package/esm/browser/sandbox/sandbox-frame.js +75 -0
  95. package/esm/browser/sandbox/sandbox-guards.d.ts +19 -0
  96. package/esm/browser/sandbox/sandbox-guards.js +74 -0
  97. package/esm/browser/sandbox/sandbox-protocol.d.ts +57 -0
  98. package/esm/browser/sandbox/sandbox-protocol.js +49 -0
  99. package/esm/browser/sandbox/sandbox-runtime-code.d.ts +1 -0
  100. package/esm/browser/sandbox/sandbox-runtime-code.js +3 -0
  101. package/esm/browser/sandbox/web-sandbox.d.ts +28 -0
  102. package/esm/browser/sandbox/web-sandbox.js +44 -0
  103. package/esm/browser/settings/settings-protocol.d.ts +2 -0
  104. package/esm/browser/settings/settings-protocol.js +2 -0
  105. package/esm/browser/style/surfaces.d.ts +1 -1
  106. package/esm/browser/style/surfaces.js +5 -0
  107. package/esm/browser/style/tints.d.ts +2 -0
  108. package/esm/browser/style/tints.js +10 -0
  109. package/esm/browser/util/desktop.d.ts +31 -1
  110. package/esm/browser/util/desktop.js +20 -0
  111. package/esm/browser/view.js +1 -1
  112. package/lib/browser/apps/app-icon.d.ts +24 -0
  113. package/lib/browser/apps/app-icon.js +134 -0
  114. package/lib/browser/apps/app-settings.d.ts +7 -0
  115. package/lib/browser/apps/app-settings.js +103 -0
  116. package/lib/browser/apps/app-window-util.d.ts +24 -0
  117. package/lib/browser/apps/app-window-util.js +30 -0
  118. package/lib/browser/apps/app-window.d.ts +10 -0
  119. package/lib/browser/apps/app-window.js +126 -0
  120. package/lib/browser/apps/web-apps.d.ts +30 -0
  121. package/lib/browser/apps/web-apps.js +61 -0
  122. package/lib/browser/assistant/call-keeper.d.ts +2 -5
  123. package/lib/browser/assistant/call-keeper.js +6 -10
  124. package/lib/browser/components/access-settings.d.ts +7 -0
  125. package/lib/browser/components/access-settings.js +88 -0
  126. package/lib/browser/components/app-root.d.ts +7 -0
  127. package/lib/browser/components/app-root.js +70 -0
  128. package/lib/browser/components/app-view.d.ts +8 -2
  129. package/lib/browser/components/app-view.js +1 -25
  130. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  131. package/lib/browser/components/host-view.d.ts +1 -1
  132. package/lib/browser/components/settings-more.js +6 -0
  133. package/lib/browser/device/screen-awake.d.ts +16 -0
  134. package/lib/browser/device/screen-awake.js +39 -1
  135. package/lib/browser/device/sheet-swipe.js +4 -0
  136. package/lib/browser/extension/icons.js +1 -0
  137. package/lib/browser/extension/web-access.d.ts +17 -0
  138. package/lib/browser/extension/web-access.js +78 -0
  139. package/lib/browser/extension/web-api-desktop.d.ts +23 -0
  140. package/lib/browser/extension/web-api-spec.d.ts +71 -0
  141. package/lib/browser/extension/web-api-spec.js +226 -0
  142. package/lib/browser/extension/web-extension-api.d.ts +6 -0
  143. package/lib/browser/extension/web-extension-context.js +11 -2
  144. package/lib/browser/extension/web-extension-run.d.ts +6 -1
  145. package/lib/browser/extension/web-extension-run.js +25 -0
  146. package/lib/browser/extension/web-extensions-running.d.ts +18 -1
  147. package/lib/browser/extension/web-extensions-running.js +102 -9
  148. package/lib/browser/extension/web-pages.d.ts +5 -0
  149. package/lib/browser/extension/web-pages.js +3 -0
  150. package/lib/browser/i18n/en/common.d.ts +1 -0
  151. package/lib/browser/i18n/en/common.js +1 -0
  152. package/lib/browser/i18n/en/discover.d.ts +11 -0
  153. package/lib/browser/i18n/en/discover.js +11 -0
  154. package/lib/browser/i18n/en/settings.d.ts +28 -0
  155. package/lib/browser/i18n/en/settings.js +28 -0
  156. package/lib/browser/i18n/ja/common.js +1 -0
  157. package/lib/browser/i18n/ja/discover.js +11 -0
  158. package/lib/browser/i18n/ja/settings.js +28 -0
  159. package/lib/browser/i18n/locales.d.ts +41 -3
  160. package/lib/browser/i18n/messages.d.ts +40 -2
  161. package/lib/browser/i18n/zh/common.js +1 -0
  162. package/lib/browser/i18n/zh/discover.js +11 -0
  163. package/lib/browser/i18n/zh/settings.js +28 -0
  164. package/lib/browser/i18n/zh-tw/common.js +1 -0
  165. package/lib/browser/i18n/zh-tw/discover.js +11 -0
  166. package/lib/browser/i18n/zh-tw/settings.js +28 -0
  167. package/lib/browser/index.d.ts +1 -0
  168. package/lib/browser/index.js +1 -0
  169. package/lib/browser/notices/notices.js +1 -0
  170. package/lib/browser/sandbox/channel/channel.d.ts +57 -0
  171. package/lib/browser/sandbox/channel/channel.js +128 -0
  172. package/lib/browser/sandbox/channel/codec.d.ts +81 -0
  173. package/lib/browser/sandbox/channel/codec.js +256 -0
  174. package/lib/browser/sandbox/hook-host.d.ts +24 -0
  175. package/lib/browser/sandbox/hook-host.js +98 -0
  176. package/lib/browser/sandbox/isolated-host.d.ts +106 -0
  177. package/lib/browser/sandbox/isolated-host.js +432 -0
  178. package/lib/browser/sandbox/remote/remote-copy.d.ts +57 -0
  179. package/lib/browser/sandbox/remote/remote-copy.js +306 -0
  180. package/lib/browser/sandbox/remote/remote-mirror.d.ts +62 -0
  181. package/lib/browser/sandbox/remote/remote-mirror.js +345 -0
  182. package/lib/browser/sandbox/remote/remote-protocol.d.ts +80 -0
  183. package/lib/browser/sandbox/remote/remote-protocol.js +57 -0
  184. package/lib/browser/sandbox/remote/remote-styles.d.ts +11 -0
  185. package/lib/browser/sandbox/remote/remote-styles.js +116 -0
  186. package/lib/browser/sandbox/remote-root.d.ts +12 -0
  187. package/lib/browser/sandbox/remote-root.js +117 -0
  188. package/lib/browser/sandbox/runtime/frame-api.d.ts +29 -0
  189. package/lib/browser/sandbox/runtime/frame-api.js +183 -0
  190. package/lib/browser/sandbox/runtime/frame-features.d.ts +7 -0
  191. package/lib/browser/sandbox/runtime/frame-features.js +53 -0
  192. package/lib/browser/sandbox/runtime/frame-parts.d.ts +37 -0
  193. package/lib/browser/sandbox/runtime/frame-parts.js +106 -0
  194. package/lib/browser/sandbox/runtime/frame-roots.d.ts +27 -0
  195. package/lib/browser/sandbox/runtime/frame-roots.js +113 -0
  196. package/lib/browser/sandbox/runtime/frame-store.d.ts +10 -0
  197. package/lib/browser/sandbox/runtime/frame-store.js +22 -0
  198. package/lib/browser/sandbox/runtime/sandbox-runtime.d.ts +12 -0
  199. package/lib/browser/sandbox/runtime/sandbox-runtime.js +47 -0
  200. package/lib/browser/sandbox/sandbox-features.d.ts +26 -0
  201. package/lib/browser/sandbox/sandbox-features.js +35 -0
  202. package/lib/browser/sandbox/sandbox-frame.d.ts +22 -0
  203. package/lib/browser/sandbox/sandbox-frame.js +79 -0
  204. package/lib/browser/sandbox/sandbox-guards.d.ts +20 -0
  205. package/lib/browser/sandbox/sandbox-guards.js +77 -0
  206. package/lib/browser/sandbox/sandbox-protocol.d.ts +58 -0
  207. package/lib/browser/sandbox/sandbox-protocol.js +52 -0
  208. package/lib/browser/sandbox/sandbox-runtime-code.d.ts +2 -0
  209. package/lib/browser/sandbox/sandbox-runtime-code.js +6 -0
  210. package/lib/browser/sandbox/web-sandbox.d.ts +29 -0
  211. package/lib/browser/sandbox/web-sandbox.js +47 -0
  212. package/lib/browser/settings/settings-protocol.d.ts +2 -0
  213. package/lib/browser/settings/settings-protocol.js +2 -0
  214. package/lib/browser/style/surfaces.d.ts +1 -1
  215. package/lib/browser/style/surfaces.js +5 -0
  216. package/lib/browser/style/tints.d.ts +2 -0
  217. package/lib/browser/style/tints.js +10 -0
  218. package/lib/browser/util/desktop.d.ts +31 -1
  219. package/lib/browser/util/desktop.js +20 -0
  220. package/lib/browser/view.js +2 -2
  221. package/package.json +8 -8
@@ -0,0 +1,306 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RemoteCopy = void 0;
4
+ const remote_protocol_1 = require("./remote-protocol");
5
+ const remote_styles_1 = require("./remote-styles");
6
+ const SVG_NS = 'http://www.w3.org/2000/svg';
7
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
8
+ /**
9
+ * The copy of one root of a sandbox in the page (docs/design/ta-extension-access.md 3.4): the operations of the sandbox
10
+ * applied to real DOM under `container`, through the rules of RemoteRules, and what the user does to it sent back. It
11
+ * knows nothing of the API nor of React.
12
+ */
13
+ class RemoteCopy {
14
+ constructor(root, container, host,
15
+ /** What its styles are scoped to (RemoteStyles), and what renames its keyframes. */
16
+ styles) {
17
+ this.root = root;
18
+ this.container = container;
19
+ this.host = host;
20
+ this.styles = styles;
21
+ this.nodes = new Map();
22
+ this.ids = new WeakMap();
23
+ this.urls = new Map();
24
+ this.seq = 0;
25
+ this.typed = new Map();
26
+ this.stops = [];
27
+ this.nodes.set(0, container);
28
+ this.ids.set(container, 0);
29
+ // On the document: what the extension gave a part of Ta to draw may be drawn elsewhere (a dialog over the page).
30
+ for (const type of remote_protocol_1.REMOTE_EVENTS) {
31
+ const heard = (event) => this.heard(type, event);
32
+ document.addEventListener(type, heard, true);
33
+ this.stops.push(() => document.removeEventListener(type, heard, true));
34
+ }
35
+ }
36
+ apply(ops) {
37
+ for (const op of ops) {
38
+ try {
39
+ this.one(op);
40
+ }
41
+ catch (error) {
42
+ console.error('A change of a sandbox was left out:', error);
43
+ }
44
+ }
45
+ }
46
+ dispose() {
47
+ for (const stop of this.stops.splice(0))
48
+ stop();
49
+ if (this.moved) {
50
+ cancelAnimationFrame(this.moved.frame);
51
+ }
52
+ for (const [id, node] of this.nodes) {
53
+ if (id !== 0) {
54
+ this.gone(node);
55
+ }
56
+ }
57
+ for (const url of this.urls.values())
58
+ URL.revokeObjectURL(url);
59
+ this.urls.clear();
60
+ this.container.replaceChildren();
61
+ this.nodes.clear();
62
+ }
63
+ one(op) {
64
+ var _a;
65
+ var _b, _c, _d, _e;
66
+ switch (op.o) {
67
+ case 'ins': {
68
+ const parent = this.nodes.get(op.p);
69
+ if (!parent) {
70
+ return;
71
+ }
72
+ const node = this.make(op.node, parent instanceof SVGElement || op.node.s === 1);
73
+ if (!node) {
74
+ return;
75
+ }
76
+ const before = op.b ? this.nodes.get(op.b) : undefined;
77
+ parent.insertBefore(node, before && before.parentNode === parent ? before : null);
78
+ if (parent instanceof HTMLElement && parent.localName === remote_protocol_1.PART_TAG) {
79
+ this.host.part(parent);
80
+ }
81
+ return;
82
+ }
83
+ case 'rm': {
84
+ const node = this.nodes.get(op.i);
85
+ if (node && op.i !== 0) {
86
+ this.forget(node);
87
+ (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(node);
88
+ }
89
+ return;
90
+ }
91
+ case 'attr': {
92
+ const node = this.nodes.get(op.i);
93
+ if (node instanceof Element) {
94
+ this.attribute(node, op.k, op.v);
95
+ }
96
+ return;
97
+ }
98
+ case 'blob': {
99
+ const node = this.nodes.get(op.i);
100
+ if (node instanceof Element && op.v instanceof Blob) {
101
+ const url = URL.createObjectURL(op.v);
102
+ const key = `${op.i}:${op.k}`;
103
+ const before = this.urls.get(key);
104
+ if (before) {
105
+ URL.revokeObjectURL(before);
106
+ }
107
+ this.urls.set(key, url);
108
+ node.setAttribute(op.k, url);
109
+ }
110
+ return;
111
+ }
112
+ case 'text': {
113
+ const node = this.nodes.get(op.i);
114
+ if (node instanceof HTMLStyleElement) {
115
+ node.textContent = this.scoped(op.t);
116
+ }
117
+ else if (node instanceof Text) {
118
+ node.data = op.t;
119
+ }
120
+ return;
121
+ }
122
+ case 'prop': {
123
+ const node = this.nodes.get(op.i);
124
+ if (((_b = op.q) !== null && _b !== void 0 ? _b : 0) < ((_c = this.typed.get(op.i)) !== null && _c !== void 0 ? _c : 0) && op.k === 'value') {
125
+ // Set before what the user typed since reached the sandbox: what they typed stays.
126
+ return;
127
+ }
128
+ if (op.k === 'value' && (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement || node instanceof HTMLSelectElement)) {
129
+ if (node.value !== op.v) {
130
+ node.value = String(op.v);
131
+ }
132
+ }
133
+ else if (op.k === 'checked' && node instanceof HTMLInputElement && ((_d = op.q) !== null && _d !== void 0 ? _d : 0) >= ((_e = this.typed.get(op.i)) !== null && _e !== void 0 ? _e : 0)) {
134
+ node.checked = op.v === true;
135
+ }
136
+ return;
137
+ }
138
+ }
139
+ }
140
+ make(remote, svg) {
141
+ var _a, _b, _c, _d;
142
+ if (remote.n === '#text') {
143
+ const text = document.createTextNode((_a = remote.t) !== null && _a !== void 0 ? _a : '');
144
+ this.keep(remote.i, text);
145
+ return text;
146
+ }
147
+ const inSvg = svg || remote.n === 'svg';
148
+ if (inSvg ? !remote_protocol_1.RemoteRules.SVG.has(remote.n) : !remote_protocol_1.RemoteRules.HTML.has(remote.n)) {
149
+ console.warn(`A sandbox drew <${remote.n}>, which Ta leaves out.`);
150
+ return undefined;
151
+ }
152
+ const element = inSvg ? document.createElementNS(SVG_NS, remote.n) : document.createElement(remote.n);
153
+ this.keep(remote.i, element);
154
+ if (remote.n === 'style') {
155
+ element.textContent = this.scoped((_b = remote.t) !== null && _b !== void 0 ? _b : '');
156
+ return element;
157
+ }
158
+ for (const [name, value] of Object.entries((_c = remote.a) !== null && _c !== void 0 ? _c : {})) {
159
+ this.attribute(element, name, value);
160
+ }
161
+ for (const child of (_d = remote.c) !== null && _d !== void 0 ? _d : []) {
162
+ const made = this.make(child, inSvg && remote.n !== 'foreignObject');
163
+ if (made) {
164
+ element.appendChild(made);
165
+ }
166
+ }
167
+ if (remote.n === remote_protocol_1.PART_TAG) {
168
+ this.host.part(element);
169
+ }
170
+ return element;
171
+ }
172
+ scoped(css) {
173
+ return remote_styles_1.RemoteStyles.scope(css, this.styles.scope, this.styles.suffix);
174
+ }
175
+ attribute(element, name, value) {
176
+ const tag = element.localName;
177
+ if (value === null) {
178
+ element.removeAttribute(name);
179
+ }
180
+ else if (remote_protocol_1.RemoteRules.attribute(tag, name, value)) {
181
+ if (name === 'xlink:href') {
182
+ element.setAttributeNS(XLINK_NS, name, value);
183
+ }
184
+ else {
185
+ element.setAttribute(name, value);
186
+ }
187
+ }
188
+ if (tag === remote_protocol_1.PART_TAG || tag === remote_protocol_1.SLOT_TAG) {
189
+ const part = tag === remote_protocol_1.PART_TAG ? element : element.parentElement;
190
+ if ((part === null || part === void 0 ? void 0 : part.localName) === remote_protocol_1.PART_TAG) {
191
+ this.host.part(part);
192
+ }
193
+ }
194
+ }
195
+ keep(id, node) {
196
+ this.nodes.set(id, node);
197
+ this.ids.set(node, id);
198
+ }
199
+ forget(node) {
200
+ const id = this.ids.get(node);
201
+ if (id !== undefined) {
202
+ this.nodes.delete(id);
203
+ for (const key of [...this.urls.keys()]) {
204
+ if (key.startsWith(`${id}:`)) {
205
+ URL.revokeObjectURL(this.urls.get(key));
206
+ this.urls.delete(key);
207
+ }
208
+ }
209
+ }
210
+ this.gone(node);
211
+ for (const child of Array.from(node.childNodes))
212
+ this.forget(child);
213
+ }
214
+ gone(node) {
215
+ if (node instanceof HTMLElement && node.localName === remote_protocol_1.PART_TAG) {
216
+ this.host.partGone(node);
217
+ }
218
+ }
219
+ /**
220
+ * The node of the sandbox an event is for: the nearest of this copy; none when that is a part of Ta, whose own
221
+ * elements are the page's (its callbacks reach the sandbox themselves).
222
+ */
223
+ idOf(target) {
224
+ let node = target instanceof Node ? target : null;
225
+ while (node) {
226
+ const id = this.ids.get(node);
227
+ if (id !== undefined) {
228
+ return id === 0 || (node instanceof Element && node.localName === remote_protocol_1.PART_TAG) ? undefined : id;
229
+ }
230
+ node = node.parentNode;
231
+ }
232
+ return undefined;
233
+ }
234
+ heard(type, event) {
235
+ const id = this.idOf(event.target);
236
+ if (id === undefined) {
237
+ return;
238
+ }
239
+ const target = event.target;
240
+ if (type === 'submit') {
241
+ event.preventDefault();
242
+ }
243
+ if (type === 'click' && event.target instanceof Element && event.target.closest('a[href]')) {
244
+ // A link opens as the extension says (openLink), never by itself.
245
+ event.preventDefault();
246
+ }
247
+ if (type === 'pointermove') {
248
+ const moving = event;
249
+ if (this.moved) {
250
+ this.moved.event = moving;
251
+ }
252
+ else {
253
+ this.moved = {
254
+ event: moving,
255
+ frame: requestAnimationFrame(() => {
256
+ var _a;
257
+ var _b;
258
+ const last = (_a = this.moved) === null || _a === void 0 ? void 0 : _a.event;
259
+ this.moved = undefined;
260
+ if (last) {
261
+ this.send(type, last, (_b = this.idOf(last.target)) !== null && _b !== void 0 ? _b : id);
262
+ }
263
+ }),
264
+ };
265
+ }
266
+ return;
267
+ }
268
+ this.send(type, event, id, target);
269
+ }
270
+ send(type, event, id, target = event.target) {
271
+ var _a, _b;
272
+ const remote = { root: this.root, i: id, type };
273
+ // The value of a field of the copy, not of a part of Ta in it.
274
+ const own = target instanceof Node && this.ids.get(target) === id;
275
+ if ((own && target instanceof HTMLInputElement) || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) {
276
+ if (type === 'input' || type === 'change') {
277
+ if (target instanceof HTMLInputElement && (target.type === 'checkbox' || target.type === 'radio')) {
278
+ // The click toggles it there as here, and tells of its input and change itself.
279
+ return;
280
+ }
281
+ remote.seq = ++this.seq;
282
+ this.typed.set(id, remote.seq);
283
+ }
284
+ remote.value = target.value;
285
+ if (target instanceof HTMLInputElement) {
286
+ remote.checked = target.checked;
287
+ if (target.type === 'file' && target.files) {
288
+ remote.files = Array.from(target.files);
289
+ }
290
+ }
291
+ }
292
+ if (event instanceof KeyboardEvent) {
293
+ Object.assign(remote, { key: event.key, code: event.code });
294
+ }
295
+ if (event instanceof MouseEvent) {
296
+ const box = own && target instanceof Element ? target.getBoundingClientRect() : undefined;
297
+ Object.assign(remote, { button: event.button, x: event.clientX - ((_a = box === null || box === void 0 ? void 0 : box.left) !== null && _a !== void 0 ? _a : 0), y: event.clientY - ((_b = box === null || box === void 0 ? void 0 : box.top) !== null && _b !== void 0 ? _b : 0) });
298
+ }
299
+ if (event instanceof KeyboardEvent || event instanceof MouseEvent) {
300
+ Object.assign(remote, { alt: event.altKey, ctrl: event.ctrlKey, meta: event.metaKey, shift: event.shiftKey });
301
+ }
302
+ this.host.event(remote);
303
+ }
304
+ }
305
+ exports.RemoteCopy = RemoteCopy;
306
+ //# sourceMappingURL=remote-copy.js.map
@@ -0,0 +1,62 @@
1
+ import type { RemoteEvent, RemoteNode, RemoteOp } from './remote-protocol';
2
+ /** Where what a mirror sees goes: the operations of a root, a link the extension did not handle. */
3
+ export interface RemoteMirrorSink {
4
+ ops(root: number, ops: RemoteOp[]): void;
5
+ link(href: string): void;
6
+ /** The styles the extension put in the head of its document, whenever they change; the page scopes them. */
7
+ styles(css: string): void;
8
+ }
9
+ type Field = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
10
+ /**
11
+ * The sandbox's side of the copies (docs/design/ta-extension-access.md 3.4): the DOM under each root watched and sent
12
+ * as operations in batches, a frame at a time; the values of fields, which no mutation tells of, compared as it sends;
13
+ * `<style>` sent as written (the page scopes it); what the user did to a copy done again here, so that the extension's own React
14
+ * hears it as it would in the page. It knows nothing of the API.
15
+ */
16
+ export declare class RemoteMirror {
17
+ protected readonly sink: RemoteMirrorSink;
18
+ protected nextId: number;
19
+ protected readonly ids: WeakMap<Node, number>;
20
+ protected readonly nodes: Map<number, Node>;
21
+ protected readonly roots: Map<number, {
22
+ container: HTMLElement;
23
+ observer: MutationObserver;
24
+ pending: RemoteOp[];
25
+ }>;
26
+ protected readonly fields: Map<Field, {
27
+ root: number;
28
+ value: string;
29
+ checked: boolean;
30
+ seq: number;
31
+ }>;
32
+ protected readonly blobs: Map<string, Promise<Blob | undefined>>;
33
+ protected scheduled: boolean;
34
+ protected submitting: boolean;
35
+ protected poll?: ReturnType<typeof setInterval>;
36
+ constructor(sink: RemoteMirrorSink);
37
+ /** The styles of the head (an extension that adds its own `<style>`, as in the page), sent whole as they change. */
38
+ observeHead(): void;
39
+ /** Watches `container` as the root `root`: what is in it now is sent at once. */
40
+ observe(root: number, container: HTMLElement): void;
41
+ stop(root: number): void;
42
+ /** Does again what the user did to the copy of a node. */
43
+ dispatch(event: RemoteEvent): void;
44
+ protected setValue(field: Field, value: string, checked?: boolean): void;
45
+ protected changed(root: number, records: MutationRecord[]): void;
46
+ protected inserted(root: number, node: Node, parent: number, before?: number): RemoteOp[];
47
+ protected describe(root: number, node: Node, blobs: RemoteOp[]): RemoteNode | undefined;
48
+ protected attribute(element: Element, name: string): RemoteOp[];
49
+ /** A `blob:` address of the sandbox, which the page cannot load: its Blob, sent when read. */
50
+ protected blob(i: number, name: string, url: string): void;
51
+ protected rootOf(node: Node | undefined): number | undefined;
52
+ protected styleText(root: number, style: HTMLStyleElement): void;
53
+ protected keep(node: Node): number;
54
+ protected forget(node: Node): void;
55
+ protected queue(root: number, ops: RemoteOp[]): void;
56
+ protected schedule(): void;
57
+ /** Fields whose value the extension set (React clears a box after it sent) tell no mutation: compared as it sends. */
58
+ protected watchFields(): void;
59
+ protected flush(): void;
60
+ }
61
+ export {};
62
+ //# sourceMappingURL=remote-mirror.d.ts.map