@@ -12,7 +12,7 @@ import {
1212 type OoxmlResolverParams ,
1313} from './index.js' ;
1414
15- const emptyStyles = { docDefaults : { } , latentStyles : { } , styles : { } } ;
15+ const emptyStyles = { docDefaults : { } , latentStyles : { } , styles : [ ] } ;
1616const emptyNumbering = { abstracts : { } , definitions : { } } ;
1717
1818const buildParams = ( overrides ?: Partial < OoxmlResolverParams > ) : OoxmlResolverParams => ( {
@@ -32,9 +32,7 @@ describe('ooxml - resolveStyleChain', () => {
3232 const params = buildParams ( {
3333 translatedLinkedStyles : {
3434 ...emptyStyles ,
35- styles : {
36- Heading1 : { runProperties : { fontSize : 32 , bold : true } } ,
37- } ,
35+ styles : [ { styleId : 'Heading1' , runProperties : { fontSize : 32 , bold : true } } ] ,
3836 } ,
3937 } ) ;
4038 const result = resolveStyleChain ( 'runProperties' , params , 'Heading1' ) ;
@@ -45,16 +43,34 @@ describe('ooxml - resolveStyleChain', () => {
4543 const params = buildParams ( {
4644 translatedLinkedStyles : {
4745 ...emptyStyles ,
48- styles : {
49- BaseStyle : { runProperties : { fontSize : 22 , italic : true } } ,
50- DerivedStyle : { basedOn : 'BaseStyle' , runProperties : { fontSize : 24 , bold : true } } ,
51- } ,
46+ styles : [
47+ { styleId : 'BaseStyle' , runProperties : { fontSize : 22 , italic : true } } ,
48+ { styleId : 'DerivedStyle' , basedOn : 'BaseStyle' , runProperties : { fontSize : 24 , bold : true } } ,
49+ ] ,
5250 } ,
5351 } ) ;
5452 const result = resolveStyleChain ( 'runProperties' , params , 'DerivedStyle' ) ;
5553 expect ( result ) . toEqual ( { fontSize : 24 , bold : true , italic : true } ) ;
5654 } ) ;
5755
56+ it ( 'refreshes cached lookups after in-place styles mutations' , ( ) => {
57+ const styles = [ { styleId : 'Heading1' , runProperties : { fontSize : 32 , bold : true } } ] ;
58+ const params = buildParams ( {
59+ translatedLinkedStyles : {
60+ ...emptyStyles ,
61+ styles,
62+ } ,
63+ } ) ;
64+
65+ expect ( resolveStyleChain ( 'runProperties' , params , 'Heading1' ) ) . toEqual ( { fontSize : 32 , bold : true } ) ;
66+
67+ styles . push ( { styleId : 'Heading2' , runProperties : { italic : true } } ) ;
68+ expect ( resolveStyleChain ( 'runProperties' , params , 'Heading2' ) ) . toEqual ( { italic : true } ) ;
69+
70+ styles [ 0 ] . styleId = 'Heading1Renamed' ;
71+ expect ( resolveStyleChain ( 'runProperties' , params , 'Heading1Renamed' ) ) . toEqual ( { fontSize : 32 , bold : true } ) ;
72+ } ) ;
73+
5874 it ( 'returns empty object when styleId is missing from definitions' , ( ) => {
5975 const params = buildParams ( ) ;
6076 const result = resolveStyleChain ( 'runProperties' , params , 'MissingStyle' ) ;
@@ -152,9 +168,7 @@ describe('ooxml - resolveRunProperties', () => {
152168 translatedLinkedStyles : {
153169 ...emptyStyles ,
154170 docDefaults : { runProperties : { fontSize : 20 } } ,
155- styles : {
156- Normal : { default : true , runProperties : { fontSize : 22 } } ,
157- } ,
171+ styles : [ { styleId : 'Normal' , default : true , runProperties : { fontSize : 22 } } ] ,
158172 } ,
159173 } ) ;
160174 const result = resolveRunProperties ( params , null , null ) ;
@@ -166,9 +180,7 @@ describe('ooxml - resolveRunProperties', () => {
166180 translatedLinkedStyles : {
167181 ...emptyStyles ,
168182 docDefaults : { runProperties : { fontSize : 20 , color : { val : 'AAAAAA' } } } ,
169- styles : {
170- Normal : { default : false , runProperties : { fontSize : 22 , color : { val : 'BBBBBB' } } } ,
171- } ,
183+ styles : [ { styleId : 'Normal' , default : false , runProperties : { fontSize : 22 , color : { val : 'BBBBBB' } } } ] ,
172184 } ,
173185 } ) ;
174186 const result = resolveRunProperties ( params , null , null ) ;
@@ -179,10 +191,10 @@ describe('ooxml - resolveRunProperties', () => {
179191 const params = buildParams ( {
180192 translatedLinkedStyles : {
181193 ...emptyStyles ,
182- styles : {
183- TOC1 : { runProperties : { bold : true } } ,
184- Emphasis : { runProperties : { italic : true } } ,
185- } ,
194+ styles : [
195+ { styleId : 'TOC1' , runProperties : { bold : true } } ,
196+ { styleId : 'Emphasis' , runProperties : { italic : true } } ,
197+ ] ,
186198 } ,
187199 } ) ;
188200 const result = resolveRunProperties ( params , { styleId : 'Emphasis' , color : { val : 'FF0000' } } , { styleId : 'TOC1' } ) ;
@@ -221,8 +233,9 @@ describe('ooxml - resolveRunProperties', () => {
221233 const params = buildParams ( {
222234 translatedLinkedStyles : {
223235 ...emptyStyles ,
224- styles : {
225- TableStyle1 : {
236+ styles : [
237+ {
238+ styleId : 'TableStyle1' ,
226239 type : 'table' ,
227240 runProperties : { color : { val : 'AAAAAA' } } ,
228241 tableProperties : { tableStyleRowBandSize : 1 , tableStyleColBandSize : 1 } ,
@@ -235,7 +248,7 @@ describe('ooxml - resolveRunProperties', () => {
235248 nwCell : { runProperties : { fontSize : 15 } } ,
236249 } ,
237250 } ,
238- } ,
251+ ] ,
239252 } ,
240253 } ) ;
241254 const tableInfo = {
@@ -279,9 +292,7 @@ describe('ooxml - resolveParagraphProperties', () => {
279292 translatedLinkedStyles : {
280293 ...emptyStyles ,
281294 docDefaults : { paragraphProperties : { spacing : { before : 240 } } } ,
282- styles : {
283- Normal : { default : true , paragraphProperties : { spacing : { after : 120 } } } ,
284- } ,
295+ styles : [ { styleId : 'Normal' , default : true , paragraphProperties : { spacing : { after : 120 } } } ] ,
285296 } ,
286297 } ) ;
287298 const inlineProps = { spacing : { before : 480 } } ;
@@ -293,9 +304,7 @@ describe('ooxml - resolveParagraphProperties', () => {
293304 const params = buildParams ( {
294305 translatedLinkedStyles : {
295306 ...emptyStyles ,
296- styles : {
297- ListStyle : { paragraphProperties : { indent : { left : 1200 } } } ,
298- } ,
307+ styles : [ { styleId : 'ListStyle' , paragraphProperties : { indent : { left : 1200 } } } ] ,
299308 } ,
300309 translatedNumbering : {
301310 definitions : { '1' : { abstractNumId : 10 } } ,
@@ -319,13 +328,14 @@ describe('ooxml - resolveParagraphProperties', () => {
319328 const params = buildParams ( {
320329 translatedLinkedStyles : {
321330 ...emptyStyles ,
322- styles : {
323- BaseStyle : { paragraphProperties : { indent : { left : 2000 } } } ,
324- NumberedStyle : {
331+ styles : [
332+ { styleId : 'BaseStyle' , paragraphProperties : { indent : { left : 2000 } } } ,
333+ {
334+ styleId : 'NumberedStyle' ,
325335 basedOn : 'BaseStyle' ,
326336 paragraphProperties : { numberingProperties : { numId : 1 , ilvl : 0 } } ,
327337 } ,
328- } ,
338+ ] ,
329339 } ,
330340 translatedNumbering : {
331341 definitions : { '1' : { abstractNumId : 10 } } ,
@@ -348,9 +358,7 @@ describe('ooxml - resolveParagraphProperties', () => {
348358 translatedLinkedStyles : {
349359 ...emptyStyles ,
350360 docDefaults : { paragraphProperties : { tabStops : [ { pos : 720 } ] } } ,
351- styles : {
352- Normal : { default : true , paragraphProperties : { tabStops : [ { pos : 1440 } ] } } ,
353- } ,
361+ styles : [ { styleId : 'Normal' , default : true , paragraphProperties : { tabStops : [ { pos : 1440 } ] } } ] ,
354362 } ,
355363 } ) ;
356364 const result = resolveParagraphProperties ( params , { tabStops : [ { pos : 2160 } ] } ) ;
@@ -361,16 +369,17 @@ describe('ooxml - resolveParagraphProperties', () => {
361369 const params = buildParams ( {
362370 translatedLinkedStyles : {
363371 ...emptyStyles ,
364- styles : {
365- TableStyle1 : {
372+ styles : [
373+ {
374+ styleId : 'TableStyle1' ,
366375 type : 'table' ,
367376 paragraphProperties : { spacing : { before : 120 , after : 120 } , keepNext : true } ,
368377 tableProperties : { tableStyleRowBandSize : 1 , tableStyleColBandSize : 1 } ,
369378 tableStyleProperties : {
370379 firstRow : { paragraphProperties : { spacing : { after : 240 } } } ,
371380 } ,
372381 } ,
373- } ,
382+ ] ,
374383 } ,
375384 } ) ;
376385 const tableInfo = {
@@ -391,8 +400,9 @@ describe('ooxml - resolveCellStyles', () => {
391400 const params = buildParams ( {
392401 translatedLinkedStyles : {
393402 ...emptyStyles ,
394- styles : {
395- TableStyleBand : {
403+ styles : [
404+ {
405+ styleId : 'TableStyleBand' ,
396406 type : 'table' ,
397407 tableProperties : { tableStyleRowBandSize : 2 , tableStyleColBandSize : 3 } ,
398408 tableStyleProperties : {
@@ -403,7 +413,7 @@ describe('ooxml - resolveCellStyles', () => {
403413 band2Horz : { runProperties : { fontSize : 50 } } ,
404414 } ,
405415 } ,
406- } ,
416+ ] ,
407417 } ,
408418 } ) ;
409419 const tableInfo = {
@@ -421,9 +431,10 @@ describe('ooxml - resolveCellStyles', () => {
421431describe ( 'ooxml - resolveTableCellProperties' , ( ) => {
422432 const gridTable4Styles = {
423433 ...emptyStyles ,
424- styles : {
425- 'GridTable4-Accent1' : {
426- type : 'table' ,
434+ styles : [
435+ {
436+ styleId : 'GridTable4-Accent1' ,
437+ type : 'table' as const ,
427438 tableProperties : { tableStyleRowBandSize : 1 , tableStyleColBandSize : 1 } ,
428439 tableStyleProperties : {
429440 firstRow : {
@@ -444,7 +455,7 @@ describe('ooxml - resolveTableCellProperties', () => {
444455 } ,
445456 } ,
446457 } ,
447- } ,
458+ ] ,
448459 } ;
449460
450461 it ( 'resolves firstRow shading from table style' , ( ) => {
@@ -474,7 +485,6 @@ describe('ooxml - resolveTableCellProperties', () => {
474485 numCells : 4 ,
475486 } ;
476487 const result = resolveTableCellProperties ( null , tableInfo , gridTable4Styles ) ;
477- // band1Horz overrides wholeTable
478488 expect ( result . shading ) . toEqual ( { val : 'clear' , color : 'auto' , fill : 'C1E4F5' } ) ;
479489 } ) ;
480490
@@ -540,7 +550,6 @@ describe('ooxml - resolveTableCellProperties', () => {
540550 } ;
541551 const inlineProps = { borders : { bottom : { val : 'double' , color : '000000' , size : 8 } } } ;
542552 const result = resolveTableCellProperties ( inlineProps , tableInfo , gridTable4Styles ) ;
543- // firstRow style provides top border, inline provides bottom border - both should be present
544553 expect ( result . borders ?. top ) . toEqual ( { val : 'single' , color : '156082' , size : 4 } ) ;
545554 expect ( result . borders ?. bottom ) . toEqual ( { val : 'double' , color : '000000' , size : 8 } ) ;
546555 } ) ;
0 commit comments