@tano.page/protocol 0.10.0 → 0.11.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/package.json +3 -3
- package/src/appearance.ts +44 -12
- package/src/entry-drag.ts +15 -15
- package/src/extensions.ts +1 -1
- package/src/plugins.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tano.page/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"url": "git+https://github.com/Dramwig/Tano.git"
|
|
25
25
|
},
|
|
26
26
|
"tanoCore": {
|
|
27
|
-
"sourceCommit": "
|
|
28
|
-
"version": "0.
|
|
27
|
+
"sourceCommit": "16145a8281f7572fce8dabf297e00129a5bd6813",
|
|
28
|
+
"version": "0.11.0",
|
|
29
29
|
"importName": "@tano/protocol"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/appearance.ts
CHANGED
|
@@ -35,10 +35,14 @@ export interface FileIconDefinition {
|
|
|
35
35
|
paths: readonly string[];
|
|
36
36
|
label?: string;
|
|
37
37
|
silhouette?: 'file' | 'folder' | 'folder-open' | 'none';
|
|
38
|
+
/** Embedded raster artwork; never a URL or executable SVG. */
|
|
39
|
+
image?: string;
|
|
40
|
+
lightImage?: string;
|
|
38
41
|
}
|
|
39
42
|
export interface FileIconTheme {
|
|
40
43
|
id: string;
|
|
41
44
|
label: string;
|
|
45
|
+
notice?: string;
|
|
42
46
|
icons: Readonly<Record<string, FileIconDefinition>>;
|
|
43
47
|
file?: string;
|
|
44
48
|
folder?: string;
|
|
@@ -71,14 +75,14 @@ export interface ThemePresetDefinition {
|
|
|
71
75
|
export interface LayoutThemeDefinition {
|
|
72
76
|
id: string;
|
|
73
77
|
label: string;
|
|
74
|
-
structure: 'continuous' | 'islands' | '
|
|
75
|
-
surface: 'flat' | 'paper'
|
|
78
|
+
structure: 'continuous' | 'islands' | 'document';
|
|
79
|
+
surface: 'flat' | 'paper';
|
|
76
80
|
gap?: number;
|
|
77
81
|
pageWidth?: number;
|
|
78
82
|
}
|
|
79
83
|
/** Only host-designed and verified structure/material pairs are supported. */
|
|
80
84
|
export const layoutSurfaceByStructure = {
|
|
81
|
-
continuous: 'flat', islands: 'flat',
|
|
85
|
+
continuous: 'flat', islands: 'flat', document: 'paper',
|
|
82
86
|
} as const satisfies Record<LayoutThemeDefinition['structure'], LayoutThemeDefinition['surface']>;
|
|
83
87
|
const color = /^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i;
|
|
84
88
|
export function isFileIconColor(value: unknown): value is FileIconColor {
|
|
@@ -87,6 +91,26 @@ export function isFileIconColor(value: unknown): value is FileIconColor {
|
|
|
87
91
|
export function fileIconCssColor(value: FileIconColor): string {
|
|
88
92
|
return (themeColorTokens as readonly string[]).includes(value) ? `var(--${value})` : value;
|
|
89
93
|
}
|
|
94
|
+
/** Bound decoded dimensions as well as encoded bytes before passing artwork to the image decoder. */
|
|
95
|
+
export function isFileIconImage(value: unknown): value is string {
|
|
96
|
+
if (typeof value !== 'string' || value.length > 44 * 1024 || !/^data:image\/png;base64,(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) return false;
|
|
97
|
+
try {
|
|
98
|
+
const bytes = Uint8Array.from(atob(value.slice(22)), char => char.charCodeAt(0));
|
|
99
|
+
const view = new DataView(bytes.buffer);
|
|
100
|
+
if (bytes.length < 45 || view.getUint32(0) !== 0x89504e47 || view.getUint32(4) !== 0x0d0a1a0a ||
|
|
101
|
+
view.getUint32(8) !== 13 || view.getUint32(12) !== 0x49484452 ||
|
|
102
|
+
![16, 20].every(offset => view.getUint32(offset) > 0 && view.getUint32(offset) <= 128)) return false;
|
|
103
|
+
let hasData = false;
|
|
104
|
+
for (let offset = 8; offset + 12 <= bytes.length;) {
|
|
105
|
+
const length = view.getUint32(offset), type = view.getUint32(offset + 4);
|
|
106
|
+
if (length > bytes.length - offset - 12) return false;
|
|
107
|
+
if (type === 0x49444154) hasData = true;
|
|
108
|
+
if (type === 0x49454e44) return hasData && length === 0 && offset + 12 === bytes.length;
|
|
109
|
+
offset += length + 12;
|
|
110
|
+
}
|
|
111
|
+
} catch { return false; }
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
90
114
|
const record = (value: unknown): value is Record<string, unknown> => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
91
115
|
function keys(value: unknown, allowed: readonly string[]): asserts value is Record<string, unknown> {
|
|
92
116
|
if (!record(value) || Object.keys(value).some(key => !allowed.includes(key))) throw new Error('主题包含不支持的字段');
|
|
@@ -121,21 +145,27 @@ export function parseThemeTokens(value: unknown): ThemeTokens {
|
|
|
121
145
|
export function parseFileIconTheme(value: unknown): FileIconTheme {
|
|
122
146
|
const defaults = ['file', 'folder', 'folderExpanded', 'folderHome', 'folderHomeExpanded'];
|
|
123
147
|
const maps = ['fileNames', 'fileExtensions', 'folderNames', 'folderNamesExpanded'];
|
|
124
|
-
keys(value, ['id', 'label', 'icons', ...defaults, ...maps]);
|
|
148
|
+
keys(value, ['id', 'label', 'notice', 'icons', ...defaults, ...maps]);
|
|
125
149
|
id(value.id); label(value.label);
|
|
126
|
-
if (
|
|
150
|
+
if (value.notice !== undefined && (typeof value.notice !== 'string' || value.notice.length > 4096 || /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(value.notice))) throw new Error('图标许可声明无效');
|
|
151
|
+
if (!record(value.icons) || !Object.keys(value.icons).length || Object.keys(value.icons).length > 2048) throw new Error('图标主题数量无效');
|
|
127
152
|
const icons: Record<string, FileIconDefinition> = {};
|
|
128
153
|
for (const [name, icon] of Object.entries(value.icons)) {
|
|
129
|
-
id(name); keys(icon, ['color', 'paths', 'label', 'silhouette']);
|
|
154
|
+
id(name); keys(icon, ['color', 'paths', 'label', 'silhouette', 'image', 'lightImage']);
|
|
130
155
|
if (!isFileIconColor(icon.color) ||
|
|
131
156
|
!Array.isArray(icon.paths) || icon.paths.length > 32 || icon.paths.some(path => typeof path !== 'string' || path.length > 4096 || !/^[MmZzLlHhVvCcSsQqTtAaEe\d\s.,+\-]*$/.test(path)) ||
|
|
132
157
|
(icon.label !== undefined && (typeof icon.label !== 'string' || icon.label.length > 4 || /[\u0000-\u001f]/.test(icon.label))) ||
|
|
133
|
-
(icon.silhouette !== undefined && !['file', 'folder', 'folder-open', 'none'].includes(String(icon.silhouette)))
|
|
158
|
+
(icon.silhouette !== undefined && !['file', 'folder', 'folder-open', 'none'].includes(String(icon.silhouette))) ||
|
|
159
|
+
(icon.image !== undefined && !isFileIconImage(icon.image)) ||
|
|
160
|
+
(icon.lightImage !== undefined && (icon.image === undefined || !isFileIconImage(icon.lightImage)))) throw new Error(`图标无效:${name}`);
|
|
134
161
|
icons[name] = { color: icon.color, paths: [...icon.paths],
|
|
135
162
|
...(icon.label === undefined ? {} : { label: icon.label as string }),
|
|
136
|
-
...(icon.silhouette === undefined ? {} : { silhouette: icon.silhouette as FileIconDefinition['silhouette'] })
|
|
163
|
+
...(icon.silhouette === undefined ? {} : { silhouette: icon.silhouette as FileIconDefinition['silhouette'] }),
|
|
164
|
+
...(icon.image === undefined ? {} : { image: icon.image as string }),
|
|
165
|
+
...(icon.lightImage === undefined ? {} : { lightImage: icon.lightImage as string }) };
|
|
137
166
|
}
|
|
138
|
-
const result: Record<string, unknown> = { id: value.id, label: value.label, icons
|
|
167
|
+
const result: Record<string, unknown> = { id: value.id, label: value.label, icons,
|
|
168
|
+
...(value.notice === undefined ? {} : { notice: value.notice }) };
|
|
139
169
|
const reference = (name: unknown) => {
|
|
140
170
|
if (typeof name !== 'string' || !Object.hasOwn(icons, name)) throw new Error('图标引用不存在');
|
|
141
171
|
return name;
|
|
@@ -143,7 +173,7 @@ export function parseFileIconTheme(value: unknown): FileIconTheme {
|
|
|
143
173
|
for (const name of defaults) if (value[name] !== undefined) result[name] = reference(value[name]);
|
|
144
174
|
for (const name of maps) if (value[name] !== undefined) {
|
|
145
175
|
const map = value[name];
|
|
146
|
-
if (!record(map) || Object.keys(map).length >
|
|
176
|
+
if (!record(map) || Object.keys(map).length > 8192) throw new Error('图标匹配表无效');
|
|
147
177
|
const normalized: Record<string, string> = Object.create(null);
|
|
148
178
|
for (const [key, target] of Object.entries(map)) {
|
|
149
179
|
if (!key.trim() || key.length > 255 || /[\u0000-\u001f/\\]/.test(key) || Object.hasOwn(normalized, key.toLowerCase())) throw new Error('图标匹配名称重复或无效');
|
|
@@ -183,8 +213,10 @@ export function parsePluginAppearance(value: unknown): PluginAppearance {
|
|
|
183
213
|
const icons = value.icons === undefined ? undefined : parseList(value.icons, parseFileIconTheme);
|
|
184
214
|
const layouts = value.layouts === undefined ? undefined : parseList(value.layouts, item => {
|
|
185
215
|
keys(item, ['id', 'label', 'structure', 'surface', 'gap', 'pageWidth']); id(item.id); label(item.label);
|
|
186
|
-
|
|
187
|
-
|
|
216
|
+
// The skeuomorphic notebook structure was retired in favour of the calmer paper document.
|
|
217
|
+
if (item.structure === 'notebook') throw new Error('笔记本布局已停止支持,请改用 document 结构');
|
|
218
|
+
if (typeof item.structure !== 'string' || !['continuous', 'islands', 'document'].includes(item.structure) ||
|
|
219
|
+
typeof item.surface !== 'string' || !['flat', 'paper'].includes(item.surface)) throw new Error('布局风格无效');
|
|
188
220
|
if (layoutSurfaceByStructure[item.structure as LayoutThemeDefinition['structure']] !== item.surface) throw new Error(`不支持此布局与材质组合:${item.structure} × ${item.surface}`);
|
|
189
221
|
for (const [key, min, max] of [['gap', 8, 32], ['pageWidth', 640, 1200]] as const) {
|
|
190
222
|
if (item[key] !== undefined && (typeof item[key] !== 'number' || !Number.isInteger(item[key]) || item[key] < min || item[key] > max)) throw new Error(`布局尺寸无效:${key}`);
|
package/src/entry-drag.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { ReferenceTarget } from './objects';
|
|
2
|
-
|
|
3
|
-
export const entryReferenceDragType = 'application/x-tano-entry-references';
|
|
4
|
-
|
|
5
|
-
/** Resolve drag identities against live targets, never trust dragged labels or paths. */
|
|
6
|
-
export function droppedEntryReferences(data: string, targets: readonly ReferenceTarget[]): ReferenceTarget[] {
|
|
7
|
-
try {
|
|
8
|
-
const payload = JSON.parse(data);
|
|
9
|
-
if (typeof payload.workspace !== 'string' || !Array.isArray(payload.ids)) return [];
|
|
10
|
-
const ids = new Set(payload.ids.filter((id: unknown) => typeof id === 'string'));
|
|
11
|
-
return targets.filter(target => target.workspace === payload.workspace && ids.has(target.id));
|
|
12
|
-
} catch {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
import type { ReferenceTarget } from './objects';
|
|
2
|
+
|
|
3
|
+
export const entryReferenceDragType = 'application/x-tano-entry-references';
|
|
4
|
+
|
|
5
|
+
/** Resolve drag identities against live targets, never trust dragged labels or paths. */
|
|
6
|
+
export function droppedEntryReferences(data: string, targets: readonly ReferenceTarget[]): ReferenceTarget[] {
|
|
7
|
+
try {
|
|
8
|
+
const payload = JSON.parse(data);
|
|
9
|
+
if (typeof payload.workspace !== 'string' || !Array.isArray(payload.ids)) return [];
|
|
10
|
+
const ids = new Set(payload.ids.filter((id: unknown) => typeof id === 'string'));
|
|
11
|
+
return targets.filter(target => target.workspace === payload.workspace && ids.has(target.id));
|
|
12
|
+
} catch {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/extensions.ts
CHANGED
|
@@ -175,7 +175,7 @@ export function parsePluginJson(value: unknown, limit = 128 * 1024): PluginJson
|
|
|
175
175
|
return JSON.parse(content);
|
|
176
176
|
}
|
|
177
177
|
export function parsePluginPolicy(content: string): WorkspacePluginPolicy {
|
|
178
|
-
if (content.length > 1024 * 1024) throw new Error('工作区插件规则不能超过
|
|
178
|
+
if (new TextEncoder().encode(content).length > 16 * 1024 * 1024) throw new Error('工作区插件规则不能超过 16 MiB');
|
|
179
179
|
const value = JSON.parse(content);
|
|
180
180
|
keys(value, ['version', 'plugins']);
|
|
181
181
|
if (value.version !== 1 || !Array.isArray(value.plugins) || value.plugins.length > 100) throw new Error('工作区插件规则无效');
|
package/src/plugins.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface ObjectPluginManifest {
|
|
|
15
15
|
}
|
|
16
16
|
/** Data-only manifests: no script, network, renderer, or filesystem execution. */
|
|
17
17
|
export function parseObjectPlugin(content: string): ObjectPluginManifest {
|
|
18
|
-
if (content.length >
|
|
18
|
+
if (new TextEncoder().encode(content).length > 4 * 1024 * 1024) throw new Error('插件清单不能超过 4 MiB');
|
|
19
19
|
const value = JSON.parse(content);
|
|
20
20
|
const keys = (object: unknown, allowed: string[]) => {
|
|
21
21
|
if (
|