feat: convert editor package to TypeScript
Verify editor package / test (push) Successful in 2m50s

This commit is contained in:
2026-09-20 14:22:47 +08:00
parent b385500108
commit 76f03eb046
14 changed files with 2192 additions and 236 deletions
-26
View File
@@ -1,26 +0,0 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { applyLayout, createDocument, createLayer, deterministicGlyphAngle, layoutDecoratedText, resolveToolTargets, selectCatalogItems, validateDocument } from '../src/index.js';
test('document and layers validate', () => {
const doc=createDocument({layers:[createLayer('text',{text:'hello'})]});
assert.equal(validateDocument(doc).valid,true);
});
test('glyph rotations are deterministic and bounded', () => {
const input={documentSeed:'a',layerId:'b',index:3,glyph:'花',maxAngle:8};
assert.equal(deterministicGlyphAngle(input),deterministicGlyphAngle(input));
assert.ok(Math.abs(deterministicGlyphAngle(input))<=8);
});
test('decorated background grows with text', () => {
const short=layoutDecoratedText('花',()=>20,{fontSize:40,background:{paddingX:10}});
const long=layoutDecoratedText('花花花',()=>20,{fontSize:40,background:{paddingX:10}});
assert.ok(long.background.width>short.background.width);
});
test('tag rules and layouts are deterministic', () => {
assert.deepEqual(selectCatalogItems([{id:1,tags:['a','b']},{id:2,tags:['a','c']}],{all:['a'],none:['c']}).map(x=>x.id),[1]);
assert.equal(applyLayout('two-top-large').length,2);
});
test('tool bindings target layers by id and dynamic tag', () => {
const doc=createDocument({layers:[createLayer('background',{id:'base',tags:['base-user-42']}),createLayer('image',{id:'photo',tags:['photo']})],bindings:{tools:{adjust:{layerIds:['base'],tags:['base-{user.id}']}}}});
assert.deepEqual(resolveToolTargets(doc,'adjust',{user:{id:42}}).map(item=>item.id),['base']);
});
+9
View File
@@ -0,0 +1,9 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { applyLayout, createDocument, createLayer, deterministicGlyphAngle, layoutDecoratedText, resolveToolTargets, selectCatalogItems, validateDocument } from '../dist/index.js';
test('document and layers validate',()=>{const doc=createDocument({layers:[createLayer('text',{text:'hello'})]});assert.equal(validateDocument(doc).valid,true);});
test('glyph rotations are deterministic and bounded',()=>{const input={documentSeed:'a',layerId:'b',index:3,glyph:'花',maxAngle:8};assert.equal(deterministicGlyphAngle(input),deterministicGlyphAngle(input));assert.ok(Math.abs(deterministicGlyphAngle(input))<=8);});
test('decorated background grows with text',()=>{const short=layoutDecoratedText('花',()=>20,{fontSize:40,background:{paddingX:10}}),long=layoutDecoratedText('花花花',()=>20,{fontSize:40,background:{paddingX:10}});assert.ok(long.background&&short.background&&long.background.width>short.background.width);});
test('tag rules and layouts are deterministic',()=>{assert.deepEqual(selectCatalogItems([{id:1,tags:['a','b']},{id:2,tags:['a','c']}],{all:['a'],none:['c']}).map(item=>item.id),[1]);assert.equal(applyLayout('two-top-large').length,2);});
test('tool bindings target layers by id and dynamic tag',()=>{const doc=createDocument({layers:[createLayer('background',{id:'base',tags:['base-user-42']}),createLayer('image',{id:'photo',tags:['photo']})],bindings:{tools:{adjust:{layerIds:['base'],tags:['base-{user.id}']}}}});assert.deepEqual(resolveToolTargets(doc,'adjust',{user:{id:42}}).map(item=>item.id),['base']);});