mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat(skin): broaden runtime UI output
This commit is contained in:
1 parent
b0b4a02a21
commit
8f097ec597
11 files changed
+96
-43
No files matched your search
@@ -28,6 +28,16 @@ const eventProps: Record<string, string> = {
|
||||
pointerenter: "onPointerenter", pointerleave: "onPointerleave", dragstart: "onDragstart", dragover: "onDragover", drop: "onDrop",
|
||||
};
|
||||
|
||||
const svgAttributeNames: Record<string, string> = {
|
||||
basefrequency: "baseFrequency", clippathunits: "clipPathUnits", diffuseconstant: "diffuseConstant", edgemode: "edgeMode",
|
||||
filterunits: "filterUnits", gradienttransform: "gradientTransform", gradientunits: "gradientUnits", kernelmatrix: "kernelMatrix",
|
||||
kernelunitlength: "kernelUnitLength", lengthadjust: "lengthAdjust", markerheight: "markerHeight", markerunits: "markerUnits",
|
||||
markerwidth: "markerWidth", numoctaves: "numOctaves", pathlength: "pathLength", pointsatx: "pointsAtX", pointsaty: "pointsAtY",
|
||||
pointsatz: "pointsAtZ", preserveaspectratio: "preserveAspectRatio", primitiveunits: "primitiveUnits", refx: "refX", refy: "refY",
|
||||
specularconstant: "specularConstant", specularexponent: "specularExponent", spreadmethod: "spreadMethod", startoffset: "startOffset",
|
||||
textlength: "textLength", viewbox: "viewBox",
|
||||
};
|
||||
|
||||
export default defineComponent({
|
||||
name: "SkinPluginOutlet",
|
||||
props: {
|
||||
@@ -251,7 +261,7 @@ export default defineComponent({
|
||||
}
|
||||
const attrs: Record<string, unknown> = {};
|
||||
for (const [key, value] of Object.entries(node.attributes ?? {})) {
|
||||
attrs[key === "viewbox" ? "viewBox" : key] = typeof value === "string" ? interpolate(value, context, state) : value;
|
||||
attrs[svgAttributeNames[key] ?? key] = typeof value === "string" ? interpolate(value, context, state) : value;
|
||||
}
|
||||
if (node.asset) {
|
||||
const url = assetUrl(node.asset);
|
||||
|
||||
@@ -81,6 +81,53 @@ test("generated UI supports broad safe markup, ARIA/data attributes, and inert c
|
||||
assert.equal(document.components[0].root.children?.[1].tag, "button");
|
||||
});
|
||||
|
||||
test("generated UI supports standard elements and attributes without a fixed presentation allowlist", () => {
|
||||
const document = parseSkinExtensionUiOutput(generatedOutput("custom-layout", {
|
||||
tag: "dialog",
|
||||
attributes: { open: true, inert: true, "aria-roledescription": "voice panel", "data-layout-state": "expanded" },
|
||||
children: [{ tag: "menu", attributes: { type: "toolbar", "aria-label": "Voice tools" }, children: [{ tag: "picture" }] }],
|
||||
}));
|
||||
assert.equal(document.components[0].root.tag, "dialog");
|
||||
assert.equal(document.components[0].root.attributes?.inert, true);
|
||||
assert.equal(document.components[0].root.children?.[0].tag, "menu");
|
||||
assert.equal(document.components[0].root.children?.[0].children?.[0].tag, "picture");
|
||||
});
|
||||
|
||||
test("generated SVG restores case-sensitive standard attribute names in host-rendered markup", async () => {
|
||||
const html = await renderToString(createSSRApp(SkinPluginOutlet, {
|
||||
skinId: "community.test",
|
||||
skinVersion: "1.0.0",
|
||||
document: { schemaVersion: 3, components: [] },
|
||||
extensionOutput: generatedOutput("svg-ui", {
|
||||
tag: "svg",
|
||||
attributes: { viewbox: "0 0 24 24", preserveaspectratio: "xMidYMid meet" },
|
||||
children: [{ tag: "linearGradient", attributes: { id: "paint", gradientunits: "userSpaceOnUse" } }],
|
||||
}),
|
||||
page: "voice",
|
||||
data: {},
|
||||
assets: {},
|
||||
actions: {},
|
||||
}));
|
||||
assert.match(html, /viewBox="0 0 24 24"/);
|
||||
assert.match(html, /preserveAspectRatio="xMidYMid meet"/);
|
||||
assert.match(html, /gradientUnits="userSpaceOnUse"/);
|
||||
});
|
||||
|
||||
test("generated UI can exceed the former 16 KiB output ceiling while staying within the new package-sized limit", () => {
|
||||
const source = JSON.stringify({
|
||||
schemaVersion: 4,
|
||||
components: [{
|
||||
id: "expanded-ui",
|
||||
name: "Expanded UI",
|
||||
page: "voice",
|
||||
accessibleName: "Expanded UI",
|
||||
root: { tag: "main", children: Array.from({ length: 4 }, () => ({ text: "x".repeat(7_000) })) },
|
||||
}],
|
||||
});
|
||||
assert.ok(new TextEncoder().encode(source).byteLength > 16 * 1024);
|
||||
assert.ok(parseSkinExtensionUiOutput(source).components.length === 1);
|
||||
});
|
||||
|
||||
test("generated screen-share host widget requires permission and renders as an interactive host control", async () => {
|
||||
const source = generatedOutput("share-control", {
|
||||
tag: "section",
|
||||
@@ -264,7 +311,8 @@ test("generated UI rejects executable elements, event handlers, and network/navi
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "img", attributes: { src: "https://example.invalid/a.png" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "a", attributes: { href: "https://example.invalid/" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { style: "display:none" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { mystery: "value" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { "bad name": "value" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { Onclick: "run" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { "data-ws-part": "spoofed" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
});
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@ export const SKIN_EXTENSION_WASM_MEMORY_LIMIT_PAGES = 64;
|
||||
export const SKIN_EXTENSION_WASM_PAGE_BYTES = 64 * 1024;
|
||||
export const SKIN_EXTENSION_WASM_STARTUP_TIMEOUT_MS = 3_000;
|
||||
export const SKIN_EXTENSION_WASM_EXECUTION_LIMIT_MS = 100;
|
||||
export const SKIN_EXTENSION_WASM_MESSAGE_LIMIT = 32 * 1024;
|
||||
export const SKIN_EXTENSION_WASM_UI_OUTPUT_LIMIT_BYTES = SKIN_EXTENSION_UI_OUTPUT_LIMIT_BYTES;
|
||||
// Worker messages serialize the bounded UI JSON as a string, escaping its quotes
|
||||
// and backslashes a second time. Allow that envelope plus bounded input metadata.
|
||||
export const SKIN_EXTENSION_WASM_MESSAGE_LIMIT = SKIN_EXTENSION_WASM_UI_OUTPUT_LIMIT_BYTES * 2 + 8 * 1024;
|
||||
export const SKIN_EXTENSION_WASM_STATUS_READ_LIMIT = 10;
|
||||
export const SKIN_EXTENSION_WASM_STATUS_BYTES_LIMIT = 512;
|
||||
export const SKIN_EXTENSION_WASM_UI_OUTPUT_LIMIT_BYTES = SKIN_EXTENSION_UI_OUTPUT_LIMIT_BYTES;
|
||||
export const SKIN_EXTENSION_WASM_FUEL_LIMIT = 10_000_000n;
|
||||
export const SKIN_EXTENSION_WASM_INTERPRETER_MEMORY_LIMIT_BYTES = 64 * 1024 * 1024;
|
||||
export const SKIN_EXTENSION_WASM_FUNCTION_LIMIT = 128;
|
||||
|
||||
@@ -84,8 +84,8 @@ test("the fixed Wasmi artifact caps its own memory and stops guest execution at
|
||||
});
|
||||
assert.equal(run(createSkinExtensionWasmUiInputProbe(true), uiInput).error, 13,
|
||||
"the host must reject a second UI input read in one guest invocation");
|
||||
assert.equal(run(createSkinExtensionWasmUiOutputProbe("x".repeat(16 * 1024 + 1))).error, 12,
|
||||
"the interpreter must reject a UI payload above its byte cap");
|
||||
assert.equal(run(createSkinExtensionWasmUiOutputProbe("x".repeat(16 * 1024 + 1))).uiOutput?.length, 16 * 1024 + 1,
|
||||
"the interpreter must accept payloads larger than the previous 16 KiB cap");
|
||||
assert.equal(run(createSkinExtensionWasmUiOutputProbe('{"type":"root"}', true)).error, 12,
|
||||
"the interpreter must reject more than one UI payload per execution");
|
||||
|
||||
|
||||
Reference in new issue
Block a user