@celljs/ta-web 4.39.0 → 4.41.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 (89) hide show
  1. package/esm/browser/chat/chat-shown.js +2 -2
  2. package/esm/browser/components/busy.d.ts +5 -0
  3. package/esm/browser/components/busy.js +17 -0
  4. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  5. package/esm/browser/components/host-view.d.ts +1 -1
  6. package/esm/browser/extension/icons.js +15 -1
  7. package/esm/browser/extension/web-api-hosts.d.ts +22 -0
  8. package/esm/browser/extension/web-api-hosts.js +2 -0
  9. package/esm/browser/extension/web-api-play.d.ts +9 -1
  10. package/esm/browser/extension/web-api-spec.js +3 -0
  11. package/esm/browser/extension/web-extension-api.d.ts +7 -0
  12. package/esm/browser/extension/web-extension-context.js +6 -3
  13. package/esm/browser/extension/web-file-drag.d.ts +3 -0
  14. package/esm/browser/extension/web-file-drag.js +4 -0
  15. package/esm/browser/extension/web-hosts.d.ts +7 -0
  16. package/esm/browser/extension/web-hosts.js +29 -0
  17. package/esm/browser/hosts.d.ts +2 -0
  18. package/esm/browser/hosts.js +9 -0
  19. package/esm/browser/i18n/en/chat.d.ts +1 -0
  20. package/esm/browser/i18n/en/chat.js +1 -0
  21. package/esm/browser/i18n/ja/chat.js +1 -0
  22. package/esm/browser/i18n/locales.d.ts +2 -1
  23. package/esm/browser/i18n/messages.d.ts +1 -0
  24. package/esm/browser/i18n/zh/chat.js +1 -0
  25. package/esm/browser/i18n/zh-tw/chat.js +1 -0
  26. package/esm/browser/sandbox/sandbox-runtime-code.js +1 -1
  27. package/esm/browser/sandbox/work/work-api.d.ts +9 -0
  28. package/esm/browser/sandbox/work/work-api.js +4 -8
  29. package/esm/browser/sandbox/work/work-docs.js +26 -2
  30. package/esm/browser/sandbox/work/work-frame.d.ts +22 -2
  31. package/esm/browser/sandbox/work/work-frame.js +60 -9
  32. package/esm/browser/sandbox/work/work-senses.d.ts +100 -0
  33. package/esm/browser/sandbox/work/work-senses.js +352 -0
  34. package/esm/browser/share/shared-extensions.js +13 -1
  35. package/esm/browser/share/shared-link.d.ts +3 -1
  36. package/esm/browser/share/shared-link.js +17 -1
  37. package/esm/browser/share/shared-page.js +27 -3
  38. package/esm/browser/style/conversation.d.ts +1 -1
  39. package/esm/browser/style/conversation.js +2 -2
  40. package/esm/browser/style/shared.d.ts +1 -1
  41. package/esm/browser/style/shared.js +3 -0
  42. package/esm/browser/workbench-hosts.d.ts +1 -0
  43. package/esm/browser/workbench-hosts.js +9 -0
  44. package/esm/browser/workbench-protocol.d.ts +5 -0
  45. package/lib/browser/chat/chat-shown.js +2 -2
  46. package/lib/browser/components/busy.d.ts +5 -0
  47. package/lib/browser/components/busy.js +17 -0
  48. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  49. package/lib/browser/components/host-view.d.ts +1 -1
  50. package/lib/browser/extension/icons.js +14 -0
  51. package/lib/browser/extension/web-api-hosts.d.ts +23 -0
  52. package/lib/browser/extension/web-api-hosts.js +3 -0
  53. package/lib/browser/extension/web-api-play.d.ts +9 -1
  54. package/lib/browser/extension/web-api-spec.js +3 -0
  55. package/lib/browser/extension/web-extension-api.d.ts +7 -0
  56. package/lib/browser/extension/web-extension-context.js +6 -3
  57. package/lib/browser/extension/web-file-drag.d.ts +4 -0
  58. package/lib/browser/extension/web-file-drag.js +7 -0
  59. package/lib/browser/extension/web-hosts.d.ts +8 -0
  60. package/lib/browser/extension/web-hosts.js +32 -0
  61. package/lib/browser/hosts.d.ts +2 -0
  62. package/lib/browser/hosts.js +9 -0
  63. package/lib/browser/i18n/en/chat.d.ts +1 -0
  64. package/lib/browser/i18n/en/chat.js +1 -0
  65. package/lib/browser/i18n/ja/chat.js +1 -0
  66. package/lib/browser/i18n/locales.d.ts +2 -1
  67. package/lib/browser/i18n/messages.d.ts +1 -0
  68. package/lib/browser/i18n/zh/chat.js +1 -0
  69. package/lib/browser/i18n/zh-tw/chat.js +1 -0
  70. package/lib/browser/sandbox/sandbox-runtime-code.js +1 -1
  71. package/lib/browser/sandbox/work/work-api.d.ts +9 -0
  72. package/lib/browser/sandbox/work/work-api.js +4 -8
  73. package/lib/browser/sandbox/work/work-docs.js +26 -2
  74. package/lib/browser/sandbox/work/work-frame.d.ts +22 -2
  75. package/lib/browser/sandbox/work/work-frame.js +60 -9
  76. package/lib/browser/sandbox/work/work-senses.d.ts +101 -0
  77. package/lib/browser/sandbox/work/work-senses.js +356 -0
  78. package/lib/browser/share/shared-extensions.js +13 -1
  79. package/lib/browser/share/shared-link.d.ts +3 -1
  80. package/lib/browser/share/shared-link.js +16 -0
  81. package/lib/browser/share/shared-page.js +27 -3
  82. package/lib/browser/style/conversation.d.ts +1 -1
  83. package/lib/browser/style/conversation.js +2 -2
  84. package/lib/browser/style/shared.d.ts +1 -1
  85. package/lib/browser/style/shared.js +3 -0
  86. package/lib/browser/workbench-hosts.d.ts +1 -0
  87. package/lib/browser/workbench-hosts.js +9 -0
  88. package/lib/browser/workbench-protocol.d.ts +5 -0
  89. package/package.json +7 -7
@@ -0,0 +1,356 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkSenses = exports.BROWSER_SENSE_DEVICES = exports.SenseMath = void 0;
4
+ const ta_protocol_1 = require("@celljs/ta-protocol");
5
+ /**
6
+ * The signals of the devices (docs/design/ta-works.md 7.9), worked out from what they read: an angle, an acceleration,
7
+ * the spectrum of a sound, two small grey frames. What the microphone heard and the camera saw stays here.
8
+ */
9
+ var SenseMath;
10
+ (function (SenseMath) {
11
+ const clamp = (value, low = -1, high = 1) => Math.min(high, Math.max(low, Number.isFinite(value) ? value : 0));
12
+ const round = (value) => Math.round(value * 100) / 100;
13
+ /** Degrees of tilt that read as all the way. */
14
+ SenseMath.TILT_RANGE = 35;
15
+ /**
16
+ * Tilt of `deviceorientation`, {x, y} each -1 to 1: x to the right, y toward the user, from `neutral` (the beta it
17
+ * was held at as it started); the axes turned with the screen (`angle`, 0, 90, 180, 270).
18
+ */
19
+ function tilt(beta, gamma, neutral, angle = 0) {
20
+ const forward = (beta - neutral) / SenseMath.TILT_RANGE;
21
+ const side = gamma / SenseMath.TILT_RANGE;
22
+ const turned = ((angle % 360) + 360) % 360;
23
+ const [x, y] = turned === 90 ? [forward, -side] : turned === 180 ? [-side, -forward] : turned === 270 ? [-forward, side] : [side, forward];
24
+ return { x: round(clamp(x)), y: round(clamp(y)) };
25
+ }
26
+ SenseMath.tilt = tilt;
27
+ /** The beta a phone is held at as it starts, taken as level: 0 (flat) to 70 (upright). */
28
+ function neutral(beta) {
29
+ return clamp(beta, 0, 70);
30
+ }
31
+ SenseMath.neutral = neutral;
32
+ /** m/s² of acceleration (gravity left out) that is a shake. */
33
+ SenseMath.SHAKE = 14;
34
+ /** How hard a shake was, 0 to 1 (0: none), of `devicemotion`'s acceleration. */
35
+ function shake(x, y, z) {
36
+ const force = Math.hypot(x || 0, y || 0, z || 0);
37
+ return force < SenseMath.SHAKE ? 0 : round(clamp((force - SenseMath.SHAKE) / 16 + 0.3, 0, 1));
38
+ }
39
+ SenseMath.shake = shake;
40
+ /**
41
+ * How loud a sound is and how hard it is blown, each 0 to 1, of the bytes of an AnalyserNode's
42
+ * `getByteFrequencyData` (`binHz` apart). A blow is wind on the microphone: loud below 400 Hz, much more than above.
43
+ */
44
+ function sound(bins, binHz) {
45
+ let low = 0;
46
+ let lows = 0;
47
+ let mid = 0;
48
+ let mids = 0;
49
+ for (let index = 1; index < bins.length && index * binHz <= 4000; index++) {
50
+ if (index * binHz < 400) {
51
+ low += bins[index];
52
+ lows++;
53
+ }
54
+ else {
55
+ mid += bins[index];
56
+ mids++;
57
+ }
58
+ }
59
+ const lowMean = lows ? low / lows : 0;
60
+ const midMean = mids ? mid / mids : 0;
61
+ const all = lows + mids ? (low + mid) / (lows + mids) : 0;
62
+ const loud = clamp((all - 40) / 110, 0, 1);
63
+ const blow = lowMean > 120 && lowMean > midMean * 1.4 ? clamp((lowMean - 110) / 100, 0, 1) : 0;
64
+ return { loud: round(loud), blow: round(blow) };
65
+ }
66
+ SenseMath.sound = sound;
67
+ /** How far apart two grey pixels must be to be something that moved. */
68
+ SenseMath.MOVED = 32;
69
+ /**
70
+ * What moved between two grey frames of the front camera (`width` by `height`, a byte a pixel): where, mirrored as a
71
+ * selfie is, {x, y} -1 to 1, and how much of the frame, 0 to 1.
72
+ */
73
+ function move(before, now, width, height) {
74
+ let count = 0;
75
+ let sumX = 0;
76
+ let sumY = 0;
77
+ for (let y = 0; y < height; y++) {
78
+ for (let x = 0; x < width; x++) {
79
+ const index = y * width + x;
80
+ if (Math.abs(now[index] - before[index]) > SenseMath.MOVED) {
81
+ count++;
82
+ sumX += x;
83
+ sumY += y;
84
+ }
85
+ }
86
+ }
87
+ const amount = count / (width * height || 1);
88
+ if (amount < 0.01) {
89
+ return { x: 0, y: 0, amount: 0 };
90
+ }
91
+ const cx = sumX / count / Math.max(1, width - 1);
92
+ const cy = sumY / count / Math.max(1, height - 1);
93
+ return { x: round(clamp(1 - 2 * cx)), y: round(clamp(2 * cy - 1)), amount: round(clamp(amount * 3, 0, 1)) };
94
+ }
95
+ SenseMath.move = move;
96
+ })(SenseMath || (exports.SenseMath = SenseMath = {}));
97
+ /** How many a second of a sense, the rest dropped; a value much the same as the last one waits for a while. */
98
+ class SenseGate {
99
+ constructor(perSecond) {
100
+ this.perSecond = perSecond;
101
+ this.last = 0;
102
+ }
103
+ allow(value, now) {
104
+ const text = JSON.stringify(value);
105
+ if (now - this.last < 1000 / this.perSecond || (text === this.sent && now - this.last < 500)) {
106
+ return false;
107
+ }
108
+ this.last = now;
109
+ this.sent = text;
110
+ return true;
111
+ }
112
+ }
113
+ /** The devices of the browser the page runs in. */
114
+ exports.BROWSER_SENSE_DEVICES = {
115
+ async motion() {
116
+ var _a;
117
+ if (typeof window === 'undefined' || !('DeviceOrientationEvent' in window)) {
118
+ return false;
119
+ }
120
+ // A computer has the events and never fires them: only where fingers touch.
121
+ if (!((_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, '(pointer: coarse)').matches)) {
122
+ return false;
123
+ }
124
+ const asks = [window.DeviceOrientationEvent, window.DeviceMotionEvent];
125
+ for (const ask of asks) {
126
+ if (typeof (ask === null || ask === void 0 ? void 0 : ask.requestPermission) === 'function' && (await ask.requestPermission().catch(() => 'denied')) !== 'granted') {
127
+ return false;
128
+ }
129
+ }
130
+ return true;
131
+ },
132
+ media(device) {
133
+ const media = typeof navigator === 'undefined' ? undefined : navigator.mediaDevices;
134
+ if (!(media === null || media === void 0 ? void 0 : media.getUserMedia)) {
135
+ return Promise.reject(new Error('No microphone or camera here.'));
136
+ }
137
+ return media.getUserMedia(device === 'mic'
138
+ ? { audio: { echoCancellation: false, noiseSuppression: false, autoGainControl: false } }
139
+ : { video: { facingMode: 'user', width: { ideal: 160 }, height: { ideal: 120 } } });
140
+ },
141
+ };
142
+ /**
143
+ * What a work senses where the page shows it (docs/design/ta-works.md 7.9): the page reads the devices and gives the
144
+ * work's frame signals alone (SenseMath), each as often as TA_WORK_SENSES says, none while the page is hidden.
145
+ * `request` asks the devices in a tap of the user (iOS lets motion be asked nowhere else), at once, before anything
146
+ * it waits for; asked again it adds. `stop` lets the microphone and the camera go. A sense whose device is not here,
147
+ * or not allowed, is not one of `names`: the frame draws a stand-in to touch in its place.
148
+ */
149
+ class WorkSenses {
150
+ constructor(devices = exports.BROWSER_SENSE_DEVICES) {
151
+ this.devices = devices;
152
+ this.wanted = new Set();
153
+ this.asked = new Map();
154
+ this.ready = new Set();
155
+ this.streams = new Map();
156
+ this.stopped = false;
157
+ }
158
+ /** Asks the devices of these senses; resolves with the senses that work here. Call it in a tap of the user. */
159
+ request(names) {
160
+ const senses = ta_protocol_1.TaWorkSense.of(names);
161
+ for (const name of senses) {
162
+ this.wanted.add(name);
163
+ }
164
+ const waits = ta_protocol_1.TaWorkSense.devices(senses).map(device => {
165
+ let asking = this.asked.get(device);
166
+ if (!asking) {
167
+ asking = this.ask(device);
168
+ this.asked.set(device, asking);
169
+ }
170
+ return asking;
171
+ });
172
+ return Promise.all(waits).then(() => this.names);
173
+ }
174
+ /** The senses asked for whose device works here. */
175
+ get names() {
176
+ return ta_protocol_1.TaWorkSense.NAMES.filter(name => this.wanted.has(name) && this.ready.has(ta_protocol_1.TA_WORK_SENSES[name].device));
177
+ }
178
+ async ask(device) {
179
+ try {
180
+ if (device === 'motion') {
181
+ if (await this.devices.motion()) {
182
+ this.ready.add(device);
183
+ }
184
+ return;
185
+ }
186
+ const stream = await this.devices.media(device);
187
+ if (this.stopped) {
188
+ WorkSenses.release(stream);
189
+ return;
190
+ }
191
+ this.streams.set(device, stream);
192
+ this.ready.add(device);
193
+ }
194
+ catch (_a) {
195
+ // Not here, or not allowed: a stand-in instead.
196
+ }
197
+ }
198
+ /**
199
+ * Reads the devices of the senses that work here, telling each signal; `missing` once a device said it was here and
200
+ * then gave nothing (its senses are no longer of `names`: stand-ins instead). Returns how to stop reading.
201
+ */
202
+ listen(emit, missing, now = Date.now) {
203
+ const names = this.names;
204
+ const gates = new Map(names.map(name => [name, new SenseGate(ta_protocol_1.TA_WORK_SENSES[name].perSecond)]));
205
+ const tell = (name, value) => {
206
+ var _a;
207
+ if ((_a = gates.get(name)) === null || _a === void 0 ? void 0 : _a.allow(value, now())) {
208
+ emit(name, value);
209
+ }
210
+ };
211
+ const stops = [];
212
+ if (this.ready.has('motion') && (gates.has('tilt') || gates.has('shake'))) {
213
+ stops.push(this.readMotion(tell, gates, () => {
214
+ this.ready.delete('motion');
215
+ missing === null || missing === void 0 ? void 0 : missing();
216
+ }));
217
+ }
218
+ const mic = this.streams.get('mic');
219
+ if (mic && (gates.has('blow') || gates.has('loud'))) {
220
+ stops.push(this.readSound(mic, tell, gates));
221
+ }
222
+ const camera = this.streams.get('camera');
223
+ if (camera && gates.has('move')) {
224
+ stops.push(this.readCamera(camera, tell));
225
+ }
226
+ return () => {
227
+ for (const stop of stops) {
228
+ stop();
229
+ }
230
+ };
231
+ }
232
+ stop() {
233
+ this.stopped = true;
234
+ for (const stream of this.streams.values()) {
235
+ WorkSenses.release(stream);
236
+ }
237
+ this.streams.clear();
238
+ this.ready.delete('mic');
239
+ this.ready.delete('camera');
240
+ }
241
+ static release(stream) {
242
+ for (const track of stream.getTracks()) {
243
+ track.stop();
244
+ }
245
+ }
246
+ static hidden() {
247
+ return typeof document !== 'undefined' && document.visibilityState === 'hidden';
248
+ }
249
+ readMotion(tell, gates, silent) {
250
+ let neutral;
251
+ let heard = false;
252
+ const quiet = setTimeout(() => !heard && !WorkSenses.hidden() && silent(), this.constructor.SILENT_MS);
253
+ const oriented = (event) => {
254
+ var _a;
255
+ var _b;
256
+ if (event.beta === null || event.gamma === null) {
257
+ return;
258
+ }
259
+ heard = true;
260
+ if (WorkSenses.hidden()) {
261
+ return;
262
+ }
263
+ neutral !== null && neutral !== void 0 ? neutral : (neutral = SenseMath.neutral(event.beta));
264
+ tell('tilt', SenseMath.tilt(event.beta, event.gamma, neutral, (_b = (_a = screen.orientation) === null || _a === void 0 ? void 0 : _a.angle) !== null && _b !== void 0 ? _b : 0));
265
+ };
266
+ const moved = (event) => {
267
+ var _a, _b, _c;
268
+ const acceleration = event.acceleration;
269
+ heard || (heard = !gates.has('tilt') && !!acceleration);
270
+ const power = acceleration ? SenseMath.shake((_a = acceleration.x) !== null && _a !== void 0 ? _a : 0, (_b = acceleration.y) !== null && _b !== void 0 ? _b : 0, (_c = acceleration.z) !== null && _c !== void 0 ? _c : 0) : 0;
271
+ if (power > 0 && !WorkSenses.hidden()) {
272
+ tell('shake', { power });
273
+ }
274
+ };
275
+ if (gates.has('tilt')) {
276
+ window.addEventListener('deviceorientation', oriented);
277
+ }
278
+ if (gates.has('shake')) {
279
+ window.addEventListener('devicemotion', moved);
280
+ }
281
+ return () => {
282
+ clearTimeout(quiet);
283
+ window.removeEventListener('deviceorientation', oriented);
284
+ window.removeEventListener('devicemotion', moved);
285
+ };
286
+ }
287
+ readSound(stream, tell, gates) {
288
+ var _a;
289
+ const Context = (_a = window.AudioContext) !== null && _a !== void 0 ? _a : window.webkitAudioContext;
290
+ if (!Context) {
291
+ return () => undefined;
292
+ }
293
+ const context = new Context();
294
+ const analyser = context.createAnalyser();
295
+ analyser.fftSize = 1024;
296
+ analyser.smoothingTimeConstant = 0.5;
297
+ context.createMediaStreamSource(stream).connect(analyser);
298
+ void context.resume().catch(() => undefined);
299
+ const bins = new Uint8Array(analyser.frequencyBinCount);
300
+ const binHz = context.sampleRate / analyser.fftSize;
301
+ const timer = setInterval(() => {
302
+ if (WorkSenses.hidden()) {
303
+ return;
304
+ }
305
+ analyser.getByteFrequencyData(bins);
306
+ const { loud, blow } = SenseMath.sound(bins, binHz);
307
+ if (gates.has('loud')) {
308
+ tell('loud', loud);
309
+ }
310
+ if (gates.has('blow')) {
311
+ tell('blow', blow);
312
+ }
313
+ }, 50);
314
+ return () => {
315
+ clearInterval(timer);
316
+ void context.close().catch(() => undefined);
317
+ };
318
+ }
319
+ readCamera(stream, tell) {
320
+ const width = 32;
321
+ const height = 24;
322
+ const video = document.createElement('video');
323
+ video.muted = true;
324
+ video.playsInline = true;
325
+ video.srcObject = stream;
326
+ void video.play().catch(() => undefined);
327
+ const canvas = document.createElement('canvas');
328
+ canvas.width = width;
329
+ canvas.height = height;
330
+ const context = canvas.getContext('2d', { willReadFrequently: true });
331
+ let before;
332
+ const timer = setInterval(() => {
333
+ if (!context || WorkSenses.hidden() || video.readyState < 2) {
334
+ return;
335
+ }
336
+ context.drawImage(video, 0, 0, width, height);
337
+ const rgba = context.getImageData(0, 0, width, height).data;
338
+ const grey = new Uint8Array(width * height);
339
+ for (let index = 0; index < grey.length; index++) {
340
+ grey[index] = (rgba[index * 4] * 3 + rgba[index * 4 + 1] * 6 + rgba[index * 4 + 2]) / 10;
341
+ }
342
+ if (before) {
343
+ tell('move', SenseMath.move(before, grey, width, height));
344
+ }
345
+ before = grey;
346
+ }, 66);
347
+ return () => {
348
+ clearInterval(timer);
349
+ video.srcObject = null;
350
+ };
351
+ }
352
+ }
353
+ exports.WorkSenses = WorkSenses;
354
+ /** How long the motion sensors may stay silent before they are taken as not here (a computer that says it is touched). */
355
+ WorkSenses.SILENT_MS = 1500;
356
+ //# sourceMappingURL=work-senses.js.map
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.SharedExtensions = void 0;
37
+ const ta_protocol_1 = require("@celljs/ta-protocol");
37
38
  const React = __importStar(require("react"));
38
39
  const busy_1 = require("../components/busy");
39
40
  const conversation_view_1 = require("../components/conversation-view");
@@ -52,6 +53,8 @@ const web_dialog_1 = require("../components/web-dialog");
52
53
  const device_1 = require("../device/device");
53
54
  const icons_1 = require("../extension/icons");
54
55
  const game_view_1 = require("../game/game-view");
56
+ const work_frame_1 = require("../sandbox/work/work-frame");
57
+ const work_senses_1 = require("../sandbox/work/work-senses");
55
58
  /**
56
59
  * The web extensions that draw in conversations, for a conversation shared by a link (docs/design/ta-link.md 2.6):
57
60
  * the built-in packages that say so (`pi.shares`) lie next to the page, `ext/<name>.js`. They start with an API
@@ -116,6 +119,9 @@ var SharedExtensions;
116
119
  Avatar: ta_avatar_1.TaAvatar,
117
120
  Game: games.game,
118
121
  Game3D: games.game3d,
122
+ // A game of the conversation plays here, alone: its frame and senses are the page's, as in Ta.
123
+ WorkFrame: work_frame_1.WorkFrame,
124
+ WorkSenses: work_senses_1.WorkSenses,
119
125
  FullScreen: full_screen_1.FullScreen,
120
126
  Stack: phone_shell_1.PhoneStack,
121
127
  Face: face_1.Face,
@@ -138,7 +144,8 @@ var SharedExtensions;
138
144
  useAsks: () => [],
139
145
  useTasks: () => [],
140
146
  useHomeItems: () => [],
141
- confirm: () => Promise.resolve(false),
147
+ // What a game asks before it uses the microphone or the camera: the browser's own question.
148
+ confirm: (title, message) => Promise.resolve(typeof window !== 'undefined' && window.confirm([title, message].filter(Boolean).join('\n\n'))),
142
149
  input: () => Promise.resolve(undefined),
143
150
  editor: () => Promise.resolve(undefined),
144
151
  };
@@ -166,6 +173,11 @@ var SharedExtensions;
166
173
  fileUrl: refuse,
167
174
  reloadExtensions: () => Promise.resolve(),
168
175
  openTemporary: refuse,
176
+ // No Ta behind the page: no chats, no packages; what an extension keeps is kept in memory, gone with the page.
177
+ rooms: undefined,
178
+ onRoomEvent: undefined,
179
+ packages: undefined,
180
+ storage: new ta_protocol_1.TaMemoryStore(),
169
181
  };
170
182
  return orNothing(api);
171
183
  }
@@ -1,4 +1,4 @@
1
- import { type RelayContentItem, type RelayContentLink, type RelayConversation } from '@celljs/ta-relay';
1
+ import { type RelayContentItem, type RelayContentLink, type RelayConversation, type RelayWork } from '@celljs/ta-relay';
2
2
  /**
3
3
  * A conversation shared by a link, opened in a browser (docs/design/ta-link.md 2.6): the viewer of the relay
4
4
  * (`/s`) opens it and hands it to this page of the same relay, which draws it as Ta does, with the cards, plots
@@ -7,6 +7,8 @@ import { type RelayContentItem, type RelayContentLink, type RelayConversation }
7
7
  export declare namespace SharedPageUtil {
8
8
  /** The link the address of this page holds in its fragment (`#v=1&h=…&s=…`), as the viewer of the relay has it. */
9
9
  function link(href?: string): RelayContentLink | undefined;
10
+ /** A work shared (RELAY_WORK_KIND): one block, drawn as a reply draws it. */
11
+ function work(item: RelayContentItem): RelayWork | undefined;
10
12
  function conversation(item: RelayContentItem): RelayConversation | undefined;
11
13
  }
12
14
  //# sourceMappingURL=shared-link.d.ts.map
@@ -25,6 +25,22 @@ var SharedPageUtil;
25
25
  }
26
26
  }
27
27
  SharedPageUtil.link = link;
28
+ /** A work shared (RELAY_WORK_KIND): one block, drawn as a reply draws it. */
29
+ function work(item) {
30
+ if (item.kind !== ta_relay_1.RELAY_WORK_KIND) {
31
+ return undefined;
32
+ }
33
+ try {
34
+ const work = JSON.parse(new TextDecoder().decode(item.data));
35
+ return work && typeof work.language === 'string' && typeof work.code === 'string'
36
+ ? { v: 1, language: work.language, code: work.code, title: typeof work.title === 'string' ? work.title : item.title }
37
+ : undefined;
38
+ }
39
+ catch (_a) {
40
+ return undefined;
41
+ }
42
+ }
43
+ SharedPageUtil.work = work;
28
44
  function conversation(item) {
29
45
  if (item.kind !== ta_relay_1.RELAY_CONVERSATION_KIND) {
30
46
  return undefined;
@@ -34,14 +34,17 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.SharedPage = SharedPage;
37
+ const ta_protocol_1 = require("@celljs/ta-protocol");
37
38
  const ta_relay_1 = require("@celljs/ta-relay");
38
39
  const relay_content_1 = require("@celljs/ta-relay/lib/common/relay-content");
40
+ const relay_open_in_ta_1 = require("@celljs/ta-relay/lib/common/relay-open-in-ta");
39
41
  const lucide_react_1 = require("lucide-react");
40
42
  const React = __importStar(require("react"));
41
43
  const conversation_view_1 = require("../components/conversation-view");
42
44
  const dino_1 = require("../components/dino");
43
45
  const icon_1 = require("../components/icon");
44
46
  const loading_1 = require("../components/loading");
47
+ const markdown_1 = require("../components/markdown");
45
48
  const device_1 = require("../device/device");
46
49
  const extension_view_1 = require("../extension/extension-view");
47
50
  const hooks_1 = require("../hooks");
@@ -57,6 +60,11 @@ function useShared(link) {
57
60
  let live = true;
58
61
  const kept = relay_content_1.RelayContentHandoff.take(link.share);
59
62
  const show = (item) => {
63
+ const work = shared_link_1.SharedPageUtil.work(item);
64
+ if (work) {
65
+ setShown({ step: 'work', item, work });
66
+ return;
67
+ }
60
68
  const conversation = shared_link_1.SharedPageUtil.conversation(item);
61
69
  if (!conversation) {
62
70
  // Not a conversation: the viewer shows it.
@@ -145,9 +153,12 @@ function SharedPage({ link }) {
145
153
  const shown = useShared(link);
146
154
  const drawn = useRenderers();
147
155
  const conversation = shown.step === 'shown' ? shown.conversation : undefined;
148
- const title = (conversation === null || conversation === void 0 ? void 0 : conversation.title) || (shown.step === 'shown' ? shown.item.title : '');
156
+ const work = shown.step === 'work' ? shown.work : undefined;
157
+ const title = (conversation === null || conversation === void 0 ? void 0 : conversation.title) || (work === null || work === void 0 ? void 0 : work.title) || (shown.step === 'shown' ? shown.item.title : '');
149
158
  useSharedDocument(title);
150
- const date = shown.step === 'shown' ? new Intl.DateTimeFormat(language, { dateStyle: 'medium', timeStyle: 'short' }).format(shown.item.createdAt) : '';
159
+ const date = shown.step === 'shown' || shown.step === 'work'
160
+ ? new Intl.DateTimeFormat(language, { dateStyle: 'medium', timeStyle: 'short' }).format(shown.item.createdAt)
161
+ : '';
151
162
  const count = (_a = conversation === null || conversation === void 0 ? void 0 : conversation.messages.filter(message => message.role === 'user' || message.role === 'assistant').length) !== null && _a !== void 0 ? _a : 0;
152
163
  return (React.createElement("div", { className: "ta-shared" },
153
164
  React.createElement("header", { className: "ta-shared-top" },
@@ -156,7 +167,20 @@ function SharedPage({ link }) {
156
167
  React.createElement(CopyLink, null)),
157
168
  React.createElement("main", { className: "ta-scroll ta-conversation ta-shared-main" },
158
169
  shown.step === 'failed' && React.createElement("div", { className: "ta-shared-center ta-muted" }, t('ta.shared.failed')),
159
- (shown.step === 'loading' || (conversation && !drawn)) && React.createElement(loading_1.Loading, null),
170
+ (shown.step === 'loading' || ((conversation || work) && !drawn)) && React.createElement(loading_1.Loading, null),
171
+ work && drawn && (React.createElement(React.Fragment, null,
172
+ React.createElement("div", { className: "ta-shared-head" },
173
+ React.createElement("h1", null, title),
174
+ React.createElement("p", { className: "ta-shared-meta" },
175
+ React.createElement("span", null, t('ta.shared.sharedAt', { date })))),
176
+ React.createElement(code_renderers_1.CodeRenderers.Provider, { value: drawn.codeRenderers },
177
+ React.createElement("div", { className: "ta-shared-work" },
178
+ React.createElement(markdown_1.Markdown, { text: ta_protocol_1.TaWorkBlock.fenced(work.language, work.code) }))),
179
+ React.createElement("footer", { className: "ta-shared-foot" },
180
+ React.createElement("a", { className: "ta-button ta-primary ta-shared-mine", href: relay_open_in_ta_1.RelayOpenInTa.link(`${location.origin}${ta_relay_1.RELAY_CONTENT_PATH}${location.hash}`) }, t('ta.shared.makeMine')),
181
+ React.createElement("span", null, t('ta.shared.footer')),
182
+ React.createElement("span", null, t('ta.shared.secure')),
183
+ React.createElement("a", { className: "ta-shared-report", href: `${ta_relay_1.RELAY_CONTENT_PATH}?report${location.hash}` }, t('ta.shared.report'))))),
160
184
  conversation && drawn && (React.createElement(React.Fragment, null,
161
185
  React.createElement("div", { className: "ta-shared-head" },
162
186
  React.createElement("h1", null, title),