@1337exp/taoux 0.7.1 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+
5
+ Nothing to migrate: one new function; `downloadText` keeps its signature and result.
6
+
7
+ - **`file`: `downloadBlob(filename, data, mime?)`.** `downloadText` could only save a string, so an app that makes bytes (a ZIP, a PNG) wrote its own copy of the temporary-link dance. `downloadBlob` takes any `BlobPart` (`Uint8Array`, `Blob`, string); without `mime` a `Blob` keeps its own type and anything else is `application/octet-stream`. `downloadText` is now a thin call to it.
8
+ - **`file`: the download link is in the document while it is clicked.** Some browsers follow a link only if it is attached; the link is added to the body for the click and removed right after (`downloadText` gets this too).
9
+
3
10
  ## 0.7.1
4
11
 
5
12
  Nothing to migrate: three options, all off by default; an app that does not pass them works as before.
package/README.md CHANGED
@@ -86,7 +86,7 @@ import { History } from '@1337exp/taoux/history';
86
86
  | `undo` | undo/redo by records, not snapshots: a step keeps only the records it touched, so it is small and an undo after a sync does not roll back another device's edits; quick edits merge (`UndoStack`, `diffRecords`) | nothing |
87
87
  | `hotkeys` | shortcuts: `parseHotkey('Mod+Shift+Z')`, `matchHotkey` (Mod = ⌘ / Ctrl, non-Latin layouts by the physical key), `formatHotkey` (`Ctrl+Shift+Z` / `⇧⌘Z`), `isReservedHotkey` (⌘W, ⌘T, ⌘Q…), `bindHotkeys` on an element | DOM (for `bindHotkeys`) |
88
88
  | `storage` | autosave to localStorage without exceptions; `tryWrite` (why it failed: quota / denied), `remove`, `subscribe` (another tab changed the key) | nothing |
89
- | `file` | download text as a file (any `mime`), read a picked file as text with a size limit | DOM |
89
+ | `file` | download bytes or text as a file (`downloadBlob`, `downloadText`, any `mime`), read a picked file as text with a size limit | DOM |
90
90
  | `snap` | soft snapping to a grid with a threshold that follows the camera zoom | nothing |
91
91
  | `wheel` | wheel/trackpad → pan or zoom (like Figma) | nothing |
92
92
  | `edgescroll` | auto-scroll speed near an edge and a ready loop, `createEdgeScroller` (canvas, curve editors, any drag) | nothing |
package/README.ru.md CHANGED
@@ -86,7 +86,7 @@ import { History } from '@1337exp/taoux/history';
86
86
  | `undo` | undo/redo по записям, а не по снимкам: шаг хранит только затронутые записи, поэтому он мал, а отмена после синхронизации не откатывает правки другого устройства; частые правки склеиваются (`UndoStack`, `diffRecords`) | нет |
87
87
  | `hotkeys` | сочетания клавиш: `parseHotkey('Mod+Shift+Z')`, `matchHotkey` (Mod = ⌘ / Ctrl, нелатинские раскладки по физической клавише), `formatHotkey` (`Ctrl+Shift+Z` / `⇧⌘Z`), `isReservedHotkey` (⌘W, ⌘T, ⌘Q…), `bindHotkeys` на элементе | DOM (для `bindHotkeys`) |
88
88
  | `storage` | автосохранение в localStorage без исключений; `tryWrite` (почему не вышло: квота / запрет), `remove`, `subscribe` (ключ изменила другая вкладка) | нет |
89
- | `file` | скачивание текста как файла (любой `mime`), чтение выбранного файла как текста с лимитом размера | DOM |
89
+ | `file` | скачивание байтов или текста как файла (`downloadBlob`, `downloadText`, любой `mime`), чтение выбранного файла как текста с лимитом размера | DOM |
90
90
  | `snap` | мягкая привязка к сетке с порогом по масштабу камеры | нет |
91
91
  | `wheel` | колесо/тачпад → pan или zoom (как в Figma) | нет |
92
92
  | `edgescroll` | скорость автопрокрутки у края и готовый цикл `createEdgeScroller` (холст, редакторы кривых и любое перетаскивание) | нет |
package/dist/file.d.ts CHANGED
@@ -3,6 +3,13 @@
3
3
  * Размер файла, больше которого не открываем: проект на сотни нод весит десятки КБ.
4
4
  */
5
5
  export declare const MAX_FILE_BYTES = 5000000;
6
+ /**
7
+ * Downloads bytes (or any `BlobPart`: a `Blob`, a string) as a file through a temporary link. `mime` is the type
8
+ * of the file; without it a `Blob` keeps its own type and anything else is `application/octet-stream`.
9
+ * Скачивание байтов (или любого `BlobPart`: `Blob`, строки) как файла через временную ссылку. `mime` — тип файла;
10
+ * без него `Blob` сохраняет свой тип, а всё остальное идёт как `application/octet-stream`.
11
+ */
12
+ export declare function downloadBlob(filename: string, data: BlobPart, mime?: string): void;
6
13
  /**
7
14
  * Downloads text as a file through a temporary link. `mime` is the type of the file (JSON by default).
8
15
  * Скачивание текста как файла через временную ссылку. `mime` — тип файла (по умолчанию JSON).
package/dist/file.js CHANGED
@@ -5,18 +5,30 @@
5
5
  */
6
6
  var MAX_FILE_BYTES = 5e6;
7
7
  /**
8
- * Downloads text as a file through a temporary link. `mime` is the type of the file (JSON by default).
9
- * Скачивание текста как файла через временную ссылку. `mime` — тип файла (по умолчанию JSON).
8
+ * Downloads bytes (or any `BlobPart`: a `Blob`, a string) as a file through a temporary link. `mime` is the type
9
+ * of the file; without it a `Blob` keeps its own type and anything else is `application/octet-stream`.
10
+ * Скачивание байтов (или любого `BlobPart`: `Blob`, строки) как файла через временную ссылку. `mime` — тип файла;
11
+ * без него `Blob` сохраняет свой тип, а всё остальное идёт как `application/octet-stream`.
10
12
  */
11
- function downloadText(filename, text, mime = "application/json") {
12
- const url = URL.createObjectURL(new Blob([text], { type: mime }));
13
+ function downloadBlob(filename, data, mime) {
14
+ const type = mime ?? (data instanceof Blob && data.type ? data.type : "application/octet-stream");
15
+ const url = URL.createObjectURL(new Blob([data], { type }));
13
16
  const link = document.createElement("a");
14
17
  link.href = url;
15
18
  link.download = filename;
19
+ document.body.append(link);
16
20
  link.click();
21
+ link.remove();
17
22
  setTimeout(() => URL.revokeObjectURL(url), 1e3);
18
23
  }
19
24
  /**
25
+ * Downloads text as a file through a temporary link. `mime` is the type of the file (JSON by default).
26
+ * Скачивание текста как файла через временную ссылку. `mime` — тип файла (по умолчанию JSON).
27
+ */
28
+ function downloadText(filename, text, mime = "application/json") {
29
+ downloadBlob(filename, text, mime);
30
+ }
31
+ /**
20
32
  * Reads a picked file as text. A file above `limit` bytes is refused before it is read; a failed read is a result,
21
33
  * not an exception.
22
34
  * Читает выбранный файл как текст. Файл больше `limit` байт отклоняется до чтения; сбой чтения — результат, а не исключение.
@@ -39,6 +51,6 @@ async function readTextFile(file, limit = MAX_FILE_BYTES) {
39
51
  }
40
52
  }
41
53
  //#endregion
42
- export { MAX_FILE_BYTES, downloadText, readTextFile };
54
+ export { MAX_FILE_BYTES, downloadBlob, downloadText, readTextFile };
43
55
 
44
56
  //# sourceMappingURL=file.js.map
package/dist/file.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"file.js","names":[],"sources":["../src/file.ts"],"sourcesContent":["/**\n * Size above which a file is not opened: a project of hundreds of nodes weighs tens of KB.\n * Размер файла, больше которого не открываем: проект на сотни нод весит десятки КБ.\n */\nexport const MAX_FILE_BYTES = 5_000_000;\n\n/**\n * Downloads text as a file through a temporary link. `mime` is the type of the file (JSON by default).\n * Скачивание текста как файла через временную ссылку. `mime` — тип файла (по умолчанию JSON).\n */\nexport function downloadText(filename: string, text: string, mime = 'application/json'): void {\n const url = URL.createObjectURL(new Blob([text], { type: mime }));\n const link = document.createElement('a');\n link.href = url;\n link.download = filename;\n link.click();\n // The browser must get time to start the download, so the link is not released at once.\n // Браузер должен успеть начать скачивание, поэтому освобождаем ссылку не сразу.\n setTimeout(() => URL.revokeObjectURL(url), 1000);\n}\n\nexport type ReadTextResult = { ok: true; text: string } | { ok: false; error: 'tooLarge' | 'unreadable' };\n\n/**\n * Reads a picked file as text. A file above `limit` bytes is refused before it is read; a failed read is a result,\n * not an exception.\n * Читает выбранный файл как текст. Файл больше `limit` байт отклоняется до чтения; сбой чтения — результат, а не исключение.\n */\nexport async function readTextFile(file: Blob, limit = MAX_FILE_BYTES): Promise<ReadTextResult> {\n if (file.size > limit) return { ok: false, error: 'tooLarge' };\n try {\n return { ok: true, text: await file.text() };\n } catch {\n return { ok: false, error: 'unreadable' };\n }\n}\n"],"mappings":";;;;;AAIA,IAAa,iBAAiB;;;;;AAM9B,SAAgB,aAAa,UAAkB,MAAc,OAAO,oBAA0B;CAC1F,MAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAM,KAAK,CAAC,CAAC;CAChE,MAAM,OAAO,SAAS,cAAc,GAAG;CACvC,KAAK,OAAO;CACZ,KAAK,WAAW;CAChB,KAAK,MAAM;CAGX,iBAAiB,IAAI,gBAAgB,GAAG,GAAG,GAAI;AACnD;;;;;;AASA,eAAsB,aAAa,MAAY,QAAQ,gBAAyC;CAC5F,IAAI,KAAK,OAAO,OAAO,OAAO;EAAE,IAAI;EAAO,OAAO;CAAW;CAC7D,IAAI;EACA,OAAO;GAAE,IAAI;GAAM,MAAM,MAAM,KAAK,KAAK;EAAE;CAC/C,QAAQ;EACJ,OAAO;GAAE,IAAI;GAAO,OAAO;EAAa;CAC5C;AACJ"}
1
+ {"version":3,"file":"file.js","names":[],"sources":["../src/file.ts"],"sourcesContent":["/**\n * Size above which a file is not opened: a project of hundreds of nodes weighs tens of KB.\n * Размер файла, больше которого не открываем: проект на сотни нод весит десятки КБ.\n */\nexport const MAX_FILE_BYTES = 5_000_000;\n\n/**\n * Downloads bytes (or any `BlobPart`: a `Blob`, a string) as a file through a temporary link. `mime` is the type\n * of the file; without it a `Blob` keeps its own type and anything else is `application/octet-stream`.\n * Скачивание байтов (или любого `BlobPart`: `Blob`, строки) как файла через временную ссылку. `mime` — тип файла;\n * без него `Blob` сохраняет свой тип, а всё остальное идёт как `application/octet-stream`.\n */\nexport function downloadBlob(filename: string, data: BlobPart, mime?: string): void {\n const type = mime ?? (data instanceof Blob && data.type ? data.type : 'application/octet-stream');\n const url = URL.createObjectURL(new Blob([data], { type }));\n const link = document.createElement('a');\n link.href = url;\n link.download = filename;\n // Some browsers only follow a link that is in the document.\n // Часть браузеров идёт только по ссылке, которая есть в документе.\n document.body.append(link);\n link.click();\n link.remove();\n // The browser must get time to start the download, so the link is not released at once.\n // Браузер должен успеть начать скачивание, поэтому освобождаем ссылку не сразу.\n setTimeout(() => URL.revokeObjectURL(url), 1000);\n}\n\n/**\n * Downloads text as a file through a temporary link. `mime` is the type of the file (JSON by default).\n * Скачивание текста как файла через временную ссылку. `mime` — тип файла (по умолчанию JSON).\n */\nexport function downloadText(filename: string, text: string, mime = 'application/json'): void {\n downloadBlob(filename, text, mime);\n}\n\nexport type ReadTextResult = { ok: true; text: string } | { ok: false; error: 'tooLarge' | 'unreadable' };\n\n/**\n * Reads a picked file as text. A file above `limit` bytes is refused before it is read; a failed read is a result,\n * not an exception.\n * Читает выбранный файл как текст. Файл больше `limit` байт отклоняется до чтения; сбой чтения — результат, а не исключение.\n */\nexport async function readTextFile(file: Blob, limit = MAX_FILE_BYTES): Promise<ReadTextResult> {\n if (file.size > limit) return { ok: false, error: 'tooLarge' };\n try {\n return { ok: true, text: await file.text() };\n } catch {\n return { ok: false, error: 'unreadable' };\n }\n}\n"],"mappings":";;;;;AAIA,IAAa,iBAAiB;;;;;;;AAQ9B,SAAgB,aAAa,UAAkB,MAAgB,MAAqB;CAChF,MAAM,OAAO,SAAS,gBAAgB,QAAQ,KAAK,OAAO,KAAK,OAAO;CACtE,MAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;CAC1D,MAAM,OAAO,SAAS,cAAc,GAAG;CACvC,KAAK,OAAO;CACZ,KAAK,WAAW;CAGhB,SAAS,KAAK,OAAO,IAAI;CACzB,KAAK,MAAM;CACX,KAAK,OAAO;CAGZ,iBAAiB,IAAI,gBAAgB,GAAG,GAAG,GAAI;AACnD;;;;;AAMA,SAAgB,aAAa,UAAkB,MAAc,OAAO,oBAA0B;CAC1F,aAAa,UAAU,MAAM,IAAI;AACrC;;;;;;AASA,eAAsB,aAAa,MAAY,QAAQ,gBAAyC;CAC5F,IAAI,KAAK,OAAO,OAAO,OAAO;EAAE,IAAI;EAAO,OAAO;CAAW;CAC7D,IAAI;EACA,OAAO;GAAE,IAAI;GAAM,MAAM,MAAM,KAAK,KAAK;EAAE;CAC/C,QAAQ;EACJ,OAAO;GAAE,IAAI;GAAO,OAAO;EAAa;CAC5C;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1337exp/taoux",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Interaction and behavior building blocks for Vue apps: curve and gradient editors, canvas, undo/redo, playback. Import only what you need, bring your own design.",
5
5
  "keywords": [
6
6
  "vue",
@@ -33,7 +33,7 @@ controls, or with your own design.
33
33
  | `commands` | `createCommands([...])`: one registry for menus, shortcuts and palettes (see below) |
34
34
  | `hotkeys` | `parseHotkey('Mod+Shift+Z')`, `matchHotkey`, `formatHotkey` (`Ctrl+Shift+Z` / `⇧⌘Z`), `isReservedHotkey`, `bindHotkeys(element, map)` |
35
35
  | `storage` | autosave to localStorage that never throws; `tryWrite` gives the reason (`quota` / `denied`), `remove`, `subscribe` for changes from other tabs |
36
- | `file` | `downloadText(name, text, mime?)`; `readTextFile(file, limit?)` reads a picked file, refusing a big one |
36
+ | `file` | `downloadBlob(name, data, mime?)` saves bytes or a `Blob`; `downloadText(name, text, mime?)`; `readTextFile(file, limit?)` reads a picked file, refusing a big one |
37
37
  | `snap` | soft snapping to a grid, threshold follows the zoom |
38
38
  | `wheel` | wheel / trackpad → pan or zoom, like Figma (zoom only with Ctrl / ⌘ or a pinch) |
39
39
  | `edgescroll` | auto-scroll near an edge while dragging (`createEdgeScroller`) |