@@ -27,7 +27,7 @@ if (hstr) {
2727 }
2828 }
2929 if ( category === "themes" && ids . length ) {
30- let themeInput = document . querySelector ( `#theme input[value="${ ids [ 0 ] } "]` ) ;
30+ let themeInput = document . querySelector ( `#theme input[value="${ ids [ 0 ] } "]` ) ;
3131 if ( themeInput ) {
3232 themeInput . checked = true ;
3333 themeInput . dispatchEvent ( new Event ( "change" ) ) ;
@@ -60,7 +60,9 @@ for (let category in components) {
6060 let all = components [ category ] ;
6161
6262 all . meta . section = form . querySelector ( `#category-${ category } ` ) ;
63- all . meta . section . querySelector ( `[name="check-all-${ category } "]` ) ?. addEventListener ( "change" , ( { target } ) => {
63+ all . meta . section . querySelector ( `[name="check-all-${ category } "]` ) ?. addEventListener ( "change" , ( {
64+ target,
65+ } ) => {
6466 all . meta . section . querySelectorAll ( `input[name="download-${ category } "]` ) . forEach ( input => {
6567 all [ input . value ] . enabled = input . checked = target . checked ;
6668 } ) ;
@@ -80,8 +82,10 @@ for (let category in components) {
8082 let option = all [ id ] . option || all . meta . option ;
8183
8284 switch ( option ) {
83- case "mandatory" : disabled = true ; // fallthrough
84- case "default" : checked = true ;
85+ case "mandatory" :
86+ disabled = true ; // fallthrough
87+ case "default" :
88+ checked = true ;
8589 }
8690
8791 if ( category === "themes" && storedTheme ) {
@@ -99,7 +103,7 @@ for (let category in components) {
99103
100104 filepath = filepath . replace ( / \{ i d \} / g, id ) ;
101105
102- let info = all [ id ] = {
106+ let info = ( all [ id ] = {
103107 noCSS : all [ id ] . noCSS || all . meta . noCSS ,
104108 noJS : all [ id ] . noJS || all . meta . noJS ,
105109 enabled : checked ,
@@ -110,7 +114,7 @@ for (let category in components) {
110114 paths : [ ] ,
111115 size : 0 ,
112116 } ,
113- } ;
117+ } ) ;
114118
115119 info . require . forEach ( v => {
116120 dependencies [ v ] = ( dependencies [ v ] || [ ] ) . concat ( id ) ;
@@ -137,7 +141,8 @@ for (let category in components) {
137141 } ) ;
138142 }
139143
140- if ( dependencies [ id ] && ! target . checked ) { // It’s required by others
144+ if ( dependencies [ id ] && ! target . checked ) {
145+ // It’s required by others
141146 dependencies [ id ] . forEach ( dependent => {
142147 let input = form . querySelector ( `label[data-id="${ dependent } "] > input` ) ;
143148 input . checked = false ;
@@ -174,7 +179,7 @@ function getFileSize (category, id, filepath) {
174179 }
175180}
176181
177- function getFilesSizes ( ) {
182+ function getFilesSizes ( ) {
178183 for ( let category in components ) {
179184 let all = components [ category ] ;
180185
@@ -187,7 +192,7 @@ function getFilesSizes() {
187192 let files = distro . paths ;
188193
189194 files . forEach ( filepath => {
190- let file = cache [ filepath ] = cache [ filepath ] || { } ;
195+ let file = ( cache [ filepath ] = cache [ filepath ] || { } ) ;
191196
192197 if ( ! file . size ) {
193198 let size = getFileSize ( category , id , filepath ) ;
@@ -206,13 +211,14 @@ function getFilesSizes() {
206211 }
207212}
208213
209- function prettySize ( size ) {
210- return Math . round ( 100 * size / 1024 ) / 100 + "KB" ;
214+ function prettySize ( size ) {
215+ return Math . round ( ( 100 * size ) / 1024 ) / 100 + "KB" ;
211216}
212217
213- function update ( updatedCategory , updatedId ) {
218+ function update ( updatedCategory , updatedId ) {
214219 // Update total size
215- let total = { js : 0 , css : 0 } ; let updated = { js : 0 , css : 0 } ;
220+ let total = { js : 0 , css : 0 } ;
221+ let updated = { js : 0 , css : 0 } ;
216222
217223 for ( let category in components ) {
218224 let all = components [ category ] ;
@@ -232,10 +238,11 @@ function update(updatedCategory, updatedId) {
232238 let size = file . size || 0 ;
233239
234240 if ( info . enabled ) {
235-
236241 if ( ! file . contentsPromise ) {
237242 // FIXME: Remove “v2” when Prism v2 is released
238- file . contentsPromise = getFileContents ( "https://v2.dev.prismjs.com/dist/" + path ) ;
243+ file . contentsPromise = getFileContents (
244+ "https://v2.dev.prismjs.com/dist/" + path ,
245+ ) ;
239246 }
240247
241248 total [ type ] += size ;
@@ -273,36 +280,37 @@ function update(updatedCategory, updatedId) {
273280
274281 Object . assign ( form . querySelector ( `label[data-id="${ updatedId } "] .filesize` ) , {
275282 textContent : prettySize ( updated . all ) ,
276- title : ( updated . js ? Math . round ( 100 * updated . js / updated . all ) + "% JavaScript" : "" ) +
283+ title :
284+ ( updated . js ? Math . round ( ( 100 * updated . js ) / updated . all ) + "% JavaScript" : "" ) +
277285 ( updated . js && updated . css ? " + " : "" ) +
278- ( updated . css ? Math . round ( 100 * updated . css / updated . all ) + "% CSS" : "" )
286+ ( updated . css ? Math . round ( ( 100 * updated . css ) / updated . all ) + "% CSS" : "" ) ,
279287 } ) ;
280288 }
281289
282290 form . querySelector ( "#filesize" ) . textContent = prettySize ( total . all ) ;
283291
284292 Object . assign ( form . querySelector ( "#percent-js" ) , {
285- textContent : Math . round ( 100 * total . js / total . all ) + "%" ,
286- title : prettySize ( total . js )
293+ textContent : Math . round ( ( 100 * total . js ) / total . all ) + "%" ,
294+ title : prettySize ( total . js ) ,
287295 } ) ;
288296
289297 Object . assign ( form . querySelector ( "#percent-css" ) , {
290- textContent : Math . round ( 100 * total . css / total . all ) + "%" ,
291- title : prettySize ( total . css )
298+ textContent : Math . round ( ( 100 * total . css ) / total . all ) + "%" ,
299+ title : prettySize ( total . css ) ,
292300 } ) ;
293301
294302 delayedGenerateCode ( ) ;
295303}
296304
297305// "debounce" multiple rapid requests to generate and highlight code
298- function delayedGenerateCode ( ) {
306+ function delayedGenerateCode ( ) {
299307 if ( timerId !== 0 ) {
300308 clearTimeout ( timerId ) ;
301309 }
302310 timerId = setTimeout ( generateCode , 500 ) ;
303311}
304312
305- async function generateCode ( ) {
313+ async function generateCode ( ) {
306314 /** @type {CodePromiseInfo[] } */
307315 let promises = [ ] ;
308316 let redownload = { } ;
@@ -328,7 +336,7 @@ async function generateCode() {
328336 id : id ,
329337 category : category ,
330338 path : path ,
331- type : type
339+ type : type ,
332340 } ) ;
333341 }
334342 } ) ;
@@ -369,11 +377,14 @@ async function generateCode() {
369377
370378 let newCode = Object . assign ( document . createElement ( "code" ) , {
371379 className : codeElement . className ,
372- textContent : text
380+ textContent : text ,
373381 } ) ;
374382
375- Prism . highlightElement ( newCode , false , ( ) => {
376- codeElement . replaceWith ( newCode ) ;
383+ Prism . highlightElement ( newCode , {
384+ async : false ,
385+ callback : ( ) => {
386+ codeElement . replaceWith ( newCode ) ;
387+ } ,
377388 } ) ;
378389
379390 form . querySelector ( `#download-${ type } .download-button` ) . onclick = ( ) => {
@@ -395,7 +406,7 @@ async function generateCode() {
395406 * @property {string } path
396407 * @property {string } type
397408 */
398- function buildCode ( promises ) {
409+ function buildCode ( promises ) {
399410 // sort the promises
400411
401412 /** @type {CodePromiseInfo[] } */
@@ -406,7 +417,8 @@ function buildCode(promises) {
406417 promises . forEach ( p => {
407418 if ( p . category === "core" || p . category === "themes" ) {
408419 finalPromises . push ( p ) ;
409- } else {
420+ }
421+ else {
410422 let infos = toSortMap [ p . id ] ;
411423 if ( ! infos ) {
412424 toSortMap [ p . id ] = infos = [ ] ;
@@ -416,12 +428,14 @@ function buildCode(promises) {
416428 } ) ;
417429
418430 // this assumes that the ids in `toSortMap` are complete under transitive requirements
419- getLoader ( components , Object . keys ( toSortMap ) ) . getIds ( ) . forEach ( id => {
420- if ( ! toSortMap [ id ] ) {
421- console . error ( `${ id } not found.` ) ;
422- }
423- finalPromises . push . apply ( finalPromises , toSortMap [ id ] ) ;
424- } ) ;
431+ getLoader ( components , Object . keys ( toSortMap ) )
432+ . getIds ( )
433+ . forEach ( id => {
434+ if ( ! toSortMap [ id ] ) {
435+ console . error ( `${ id } not found.` ) ;
436+ }
437+ finalPromises . push . apply ( finalPromises , toSortMap [ id ] ) ;
438+ } ) ;
425439 promises = finalPromises ;
426440
427441 // build
@@ -434,18 +448,22 @@ function buildCode(promises) {
434448 if ( i < l ) {
435449 let p = promises [ i ] ;
436450 p . contentsPromise . then ( function ( contents ) {
437- code [ p . type ] += contents + ( p . type === "js" && ! / ; \s * $ / . test ( contents ) ? ";" : "" ) + "\n" ;
451+ code [ p . type ] +=
452+ contents + ( p . type === "js" && ! / ; \s * $ / . test ( contents ) ? ";" : "" ) + "\n" ;
438453 i ++ ;
439454 f ( resolve ) ;
440455 } ) ;
441456 p . contentsPromise [ "catch" ] ( function ( ) {
442- errors . push ( Object . assign ( document . createElement ( "p" ) , {
443- textContent : `An error occurred while fetching the file "${ p . path } ".`
444- } ) ) ;
457+ errors . push (
458+ Object . assign ( document . createElement ( "p" ) , {
459+ textContent : `An error occurred while fetching the file "${ p . path } ".` ,
460+ } ) ,
461+ ) ;
445462 i ++ ;
446463 f ( resolve ) ;
447464 } ) ;
448- } else {
465+ }
466+ else {
449467 resolve ( { code : code , errors : errors } ) ;
450468 }
451469 } ;
@@ -456,7 +474,7 @@ function buildCode(promises) {
456474/**
457475 * @returns {Promise<string> }
458476 */
459- async function getVersion ( ) {
460- let packageJSON = await getFileContents ( "https://dev.prismjs.com/package.json" ) ;
477+ async function getVersion ( ) {
478+ let packageJSON = await getFileContents ( "https://v2. dev.prismjs.com/package.json" ) ;
461479 return JSON . parse ( packageJSON ) . version ;
462480}
0 commit comments