@@ -11,8 +11,6 @@ const PROP_BORDER = 0x08;
1111const PROP_CLIP = 0x10 ;
1212const PROP_FLOATING = 0x20 ;
1313
14- /* ── Packing ──────────────────────────────────────────────────────── */
15-
1614const encoder = new TextEncoder ( ) ;
1715
1816function packAxis ( view : DataView , offset : number , axis : SizingAxis ) : number {
@@ -73,18 +71,18 @@ export function pack(
7371 let o = offset ;
7472
7573 for ( let op of ops ) {
76- switch ( op . id ) {
74+ switch ( op . directive ) {
7775 case OP_CLOSE_ELEMENT :
78- view . setUint32 ( o , op . id , true ) ;
76+ view . setUint32 ( o , op . directive , true ) ;
7977 o += 4 ;
8078 break ;
8179
8280 case OP_OPEN_ELEMENT : {
8381 view . setUint32 ( o , OP_OPEN_ELEMENT , true ) ;
8482 o += 4 ;
8583
86- let id = encoder . encode ( op . name ) ;
87- o = packString ( view , id , o ) ;
84+ let bytes = encoder . encode ( op . id ) ;
85+ o = packString ( view , bytes , o ) ;
8886
8987 let mask = 0 ;
9088 if ( op . layout ) mask |= PROP_LAYOUT ;
@@ -210,15 +208,11 @@ export function pack(
210208 return ( o - offset ) / 4 ;
211209}
212210
213- /* ── Color ────────────────────────────────────────────────────────── */
214-
215211export function rgba ( r : number , g : number , b : number , a = 255 ) : number {
216212 return ( ( a & 0xFF ) << 24 ) | ( ( r & 0xFF ) << 16 ) | ( ( g & 0xFF ) << 8 ) |
217213 ( b & 0xFF ) ;
218214}
219215
220- /* ── Sizing axis types ────────────────────────────────────────────── */
221-
222216export type SizingAxis =
223217 | { type : "fit" ; min ?: number ; max ?: number }
224218 | { type : "grow" ; min ?: number ; max ?: number }
@@ -241,15 +235,13 @@ export const percent = (value: number): SizingAxis => ({
241235} ) ;
242236export const fixed = ( value : number ) : SizingAxis => ( { type : "fixed" , value } ) ;
243237
244- /* ── Op descriptors ───────────────────────────────────────────────── */
245-
246238export interface CloseElement {
247- id : typeof OP_CLOSE_ELEMENT ;
239+ directive : typeof OP_CLOSE_ELEMENT ;
248240}
249241
250242export interface OpenElement {
251- id : typeof OP_OPEN_ELEMENT ;
252- name : string ;
243+ directive : typeof OP_OPEN_ELEMENT ;
244+ id : string ;
253245 layout ?: {
254246 width ?: SizingAxis ;
255247 height ?: SizingAxis ;
@@ -280,7 +272,7 @@ export interface OpenElement {
280272}
281273
282274export interface Text {
283- id : typeof OP_TEXT ;
275+ directive : typeof OP_TEXT ;
284276 content : string ;
285277 color ?: number ;
286278 fontSize ?: number ;
@@ -291,22 +283,20 @@ export interface Text {
291283
292284export type Op = OpenElement | Text | CloseElement ;
293285
294- /* ── Descriptor constructors ──────────────────────────────────────── */
295-
296286export function open (
297- name : string ,
298- props : Omit < OpenElement , "id " | "name " > = { } ,
287+ id : string ,
288+ props : Omit < OpenElement , "directive " | "id " > = { } ,
299289) : OpenElement {
300- return { id : OP_OPEN_ELEMENT , name , ...props } ;
290+ return { directive : OP_OPEN_ELEMENT , id , ...props } ;
301291}
302292
303293export function text (
304294 content : string ,
305- props : Omit < Text , "id " | "content" > = { } ,
295+ props : Omit < Text , "directive " | "content" > = { } ,
306296) : Text {
307- return { id : OP_TEXT , content, ...props } ;
297+ return { directive : OP_TEXT , content, ...props } ;
308298}
309299
310300export function close ( ) : CloseElement {
311- return { id : OP_CLOSE_ELEMENT } ;
301+ return { directive : OP_CLOSE_ELEMENT } ;
312302}
0 commit comments