@treasure-ai/treasure-deck 2026.10.11 → 2026.10.13
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/dist/build.d.ts +53 -2
- package/dist/build.js +91 -9
- package/dist/build.js.map +1 -1
- package/dist/cli.js +40 -5
- package/dist/cli.js.map +1 -1
- package/dist/dev.js +1 -5
- package/dist/dev.js.map +1 -1
- package/dist/import.d.ts +36 -0
- package/dist/import.js +177 -0
- package/dist/import.js.map +1 -0
- package/dist/render.d.ts +4 -0
- package/dist/render.js +8 -0
- package/dist/render.js.map +1 -1
- package/docs/commands.md +21 -3
- package/package.json +1 -1
- package/runtime/runtime.js +108 -0
- package/skills/treasure-deck/SKILL.md +4 -0
package/runtime/runtime.js
CHANGED
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
// written from them where the page has no URL to reopen (Apps Script's sandboxed iframe).
|
|
22
22
|
var pristineDeck = deck.outerHTML;
|
|
23
23
|
var runtimeSource = document.currentScript ? document.currentScript.textContent : '';
|
|
24
|
+
// The deck's source, which `deck build` puts in the page (unless --no-source), for the share panel's download.
|
|
25
|
+
var deckSource = document.getElementById('deck-source');
|
|
24
26
|
|
|
25
27
|
// Host adapter: Apps Script web apps run in a sandboxed iframe, so the top-level URL
|
|
26
28
|
// hash is reachable only through google.script.history / google.script.url.
|
|
@@ -65,8 +67,16 @@
|
|
|
65
67
|
'<button data-act="embed">Copy embed snippet</button>' +
|
|
66
68
|
'<button data-act="print">Print / save as PDF</button>' +
|
|
67
69
|
'<button data-act="presenter">Open presenter window</button>' +
|
|
70
|
+
(deckSource ? '<button data-act="download">Download source (.zip)</button>' +
|
|
71
|
+
'<button data-act="open">Open in Treasure Work</button>' : '') +
|
|
68
72
|
'<div class="deck-status"></div>');
|
|
69
73
|
share.hidden = true;
|
|
74
|
+
// Treasure Work imports the deck from its published URL, so a page opened from a file can't offer it.
|
|
75
|
+
function offerOpen() {
|
|
76
|
+
var b = share.querySelector('[data-act="open"]');
|
|
77
|
+
if (b) b.hidden = !/^https?:/.test(host.baseUrl());
|
|
78
|
+
}
|
|
79
|
+
offerOpen();
|
|
70
80
|
var notesPanel = el('div', 'deck-panel deck-notes-panel');
|
|
71
81
|
notesPanel.hidden = true;
|
|
72
82
|
[progress, black, laser, gotoBox, help, share, notesPanel].forEach(function (e) { deck.appendChild(e); });
|
|
@@ -175,6 +185,7 @@
|
|
|
175
185
|
var open = panel.hidden;
|
|
176
186
|
[help, share].forEach(function (p) { if (p !== panel) p.hidden = true; });
|
|
177
187
|
panel.hidden = !open;
|
|
188
|
+
if (panel === share) offerOpen();
|
|
178
189
|
if (open) used(panel === share ? 'share' : panel === help ? 'help' : 'notes');
|
|
179
190
|
if (panel === notesPanel) renderNotes();
|
|
180
191
|
}
|
|
@@ -224,6 +235,101 @@
|
|
|
224
235
|
ta.remove();
|
|
225
236
|
}
|
|
226
237
|
|
|
238
|
+
// The deck folder as a .zip: the Markdown and theme files from the page's source, and its images and theme assets
|
|
239
|
+
// from the page's data: URIs, found by the hash the source lists them by. Under Apps Script, the one copy of a deck
|
|
240
|
+
// a viewer can reach.
|
|
241
|
+
function downloadDeck() {
|
|
242
|
+
var bundle = JSON.parse(deckSource.textContent);
|
|
243
|
+
var folder = bundle.deck.replace(/\.md$/, '');
|
|
244
|
+
var enc = new TextEncoder(), entries = [], missing = [];
|
|
245
|
+
function add(rel, data) {
|
|
246
|
+
if (/^\//.test(rel) || /(^|\/)\.\.(\/|$)/.test(rel)) { missing.push(rel); return; }
|
|
247
|
+
entries.push({ name: folder + '/' + rel, data: typeof data === 'string' ? enc.encode(data) : data });
|
|
248
|
+
}
|
|
249
|
+
function addInlined(media, base, found) {
|
|
250
|
+
Object.keys(media || {}).forEach(function (rel) {
|
|
251
|
+
var bytes = found[media[rel].sha256] || (media[rel].data && bytesOf(media[rel].data));
|
|
252
|
+
if (bytes) add(base + rel, bytes); else missing.push(base + rel);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
status('Preparing the download…');
|
|
256
|
+
// In the chain, so an error hashing (no crypto.subtle off https and localhost) reaches the catch below.
|
|
257
|
+
Promise.resolve().then(inlinedFiles).then(function (found) {
|
|
258
|
+
Object.keys(bundle.files).forEach(function (rel) { add(rel, bundle.files[rel]); });
|
|
259
|
+
addInlined(bundle.media, '', found);
|
|
260
|
+
if (bundle.themeFolder) {
|
|
261
|
+
var base = bundle.theme.replace(/^\.\//, '').replace(/\/?$/, '/');
|
|
262
|
+
Object.keys(bundle.themeFolder.files).forEach(function (rel) { add(base + rel, bundle.themeFolder.files[rel]); });
|
|
263
|
+
addInlined(bundle.themeFolder.media, base, found);
|
|
264
|
+
}
|
|
265
|
+
// Videos kept out of the page (--media-dir) aren't in it to save.
|
|
266
|
+
missing = missing.concat(Object.keys(bundle.linked || {}));
|
|
267
|
+
var name = folder + '.zip';
|
|
268
|
+
var url = URL.createObjectURL(zip(entries));
|
|
269
|
+
var a = el('a');
|
|
270
|
+
a.href = url;
|
|
271
|
+
a.download = name;
|
|
272
|
+
document.body.appendChild(a);
|
|
273
|
+
a.click();
|
|
274
|
+
a.remove();
|
|
275
|
+
setTimeout(function () { URL.revokeObjectURL(url); }, 60000);
|
|
276
|
+
status('Saved ' + name + (missing.length ? ', without ' + missing.join(', ') : '') + '. Unzip it and edit it with: deck editor ' + folder);
|
|
277
|
+
}).catch(function (e) { status('The download failed: ' + e.message); });
|
|
278
|
+
}
|
|
279
|
+
// Each data: URI's bytes in the page as built (the deck, and the stylesheets with the theme's assets), by SHA-256.
|
|
280
|
+
function inlinedFiles() {
|
|
281
|
+
var text = pristineDeck + Array.prototype.map.call(document.querySelectorAll('style'), function (e) { return e.textContent; }).join('\n');
|
|
282
|
+
var re = /data:[\w.+-]+\/[\w.+-]+;base64,([A-Za-z0-9+\/]+=*)/g, m, seen = {}, found = {}, work = [];
|
|
283
|
+
while ((m = re.exec(text))) {
|
|
284
|
+
if (seen[m[1]]) continue;
|
|
285
|
+
seen[m[1]] = true;
|
|
286
|
+
work.push(bytesOf(m[1]));
|
|
287
|
+
}
|
|
288
|
+
return Promise.all(work.map(function (bytes) {
|
|
289
|
+
return crypto.subtle.digest('SHA-256', bytes).then(function (h) {
|
|
290
|
+
found[Array.prototype.map.call(new Uint8Array(h), function (b) { return (b < 16 ? '0' : '') + b.toString(16); }).join('')] = bytes;
|
|
291
|
+
});
|
|
292
|
+
})).then(function () { return found; });
|
|
293
|
+
}
|
|
294
|
+
function bytesOf(base64) {
|
|
295
|
+
var bin = atob(base64), bytes = new Uint8Array(bin.length);
|
|
296
|
+
for (var i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
|
297
|
+
return bytes;
|
|
298
|
+
}
|
|
299
|
+
var CRC_TABLE = (function () {
|
|
300
|
+
var t = [];
|
|
301
|
+
for (var n = 0; n < 256; n++) {
|
|
302
|
+
var c = n;
|
|
303
|
+
for (var k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
304
|
+
t[n] = c >>> 0;
|
|
305
|
+
}
|
|
306
|
+
return t;
|
|
307
|
+
})();
|
|
308
|
+
function crc32(bytes) {
|
|
309
|
+
var c = -1;
|
|
310
|
+
for (var i = 0; i < bytes.length; i++) c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ (c >>> 8);
|
|
311
|
+
return (c ^ -1) >>> 0;
|
|
312
|
+
}
|
|
313
|
+
// A zip of stored (uncompressed) entries, {name, data}: a deck's images are compressed already and its text is small.
|
|
314
|
+
function zip(entries) {
|
|
315
|
+
var enc = new TextEncoder(), parts = [], central = [], offset = 0, size = 0;
|
|
316
|
+
function u16(v) { return [v & 255, (v >>> 8) & 255]; }
|
|
317
|
+
function u32(v) { return u16(v & 0xffff).concat(u16(v >>> 16)); }
|
|
318
|
+
entries.forEach(function (e) {
|
|
319
|
+
var name = enc.encode(e.name);
|
|
320
|
+
// Version 2.0, UTF-8 names, stored, dated 1980-01-01, the CRC and sizes, the name's length, no extra field.
|
|
321
|
+
var fields = [].concat(u16(20), u16(0x0800), u16(0), u16(0), u16(0x21), u32(crc32(e.data)), u32(e.data.length), u32(e.data.length), u16(name.length), u16(0));
|
|
322
|
+
var local = new Uint8Array(u32(0x04034b50).concat(fields));
|
|
323
|
+
var entry = new Uint8Array(u32(0x02014b50).concat(u16(20), fields, u16(0), u16(0), u16(0), u32(0), u32(offset)));
|
|
324
|
+
parts.push(local, name, e.data);
|
|
325
|
+
central.push(entry, name);
|
|
326
|
+
offset += local.length + name.length + e.data.length;
|
|
327
|
+
size += entry.length + name.length;
|
|
328
|
+
});
|
|
329
|
+
var end = new Uint8Array(u32(0x06054b50).concat(u16(0), u16(0), u16(entries.length), u16(entries.length), u32(size), u32(offset), u16(0)));
|
|
330
|
+
return new Blob(parts.concat(central, [end]), { type: 'application/zip' });
|
|
331
|
+
}
|
|
332
|
+
|
|
227
333
|
share.addEventListener('click', function (e) {
|
|
228
334
|
var act = e.target && e.target.getAttribute('data-act');
|
|
229
335
|
var base = host.baseUrl();
|
|
@@ -233,6 +339,8 @@
|
|
|
233
339
|
else if (act === 'embed') copy(base && '<iframe src="' + base + '" width="960" height="540" frameborder="0" allowfullscreen></iframe>', 'Embed snippet');
|
|
234
340
|
else if (act === 'print') { share.hidden = true; window.print(); }
|
|
235
341
|
else if (act === 'presenter') { share.hidden = true; openPresenter(); }
|
|
342
|
+
else if (act === 'download') { used('download'); downloadDeck(); }
|
|
343
|
+
else if (act === 'open') { used('open_treasure_work'); location.href = 'treasure-work://deck/import?url=' + encodeURIComponent(base); }
|
|
236
344
|
});
|
|
237
345
|
|
|
238
346
|
var typed = '';
|
|
@@ -319,6 +319,10 @@ Treasure Work publishes a built deck as an Apps Script web page through the `sha
|
|
|
319
319
|
4. Give the user the URL. Keep the artifact id from the result. To update the same page after edits, rebuild and pass that id as `artifact_id`; without it, the publish creates a second page.
|
|
320
320
|
5. Publishing needs the user's Google account connected in Settings ▸ Connectors. If the tool reports that it is missing, tell the user to connect it.
|
|
321
321
|
|
|
322
|
+
A built page carries the deck's source, so whoever can open it can get the deck folder back (share panel ▸ Download source, or `deck import`), hidden slides included. Build with `--no-source` when the user wants the page shared but not its source.
|
|
323
|
+
|
|
324
|
+
To start from a deck someone shared, run `deck import <page.html | url> [dir]` and edit the folder it writes. For an Apps Script deck that isn't public, it needs the user's Google sign-in (`gcloud auth login --enable-gdrive-access`); otherwise have the user download the `.zip` from the deck's share panel.
|
|
325
|
+
|
|
322
326
|
Don't publish the deck `.md` as a `note`: it would appear as a plain document, not slides. Don't use `mechanism: "drive"` for a deck either, since Drive doesn't serve the HTML as a page. A published page is a snapshot, so rebuild and republish after each edit.
|
|
323
327
|
|
|
324
328
|
## When the user wants a different look
|