1/* Per-display random choices, shared by the article and preview. No persistent storage. */ 2(function(global){ 3 'use strict'; 4 function legacyBackground(key){return ['card','glass','ribbon'].includes(key)?'none':key;} 5 function draw(items,previous){ 6 var keys=Object.keys(items), candidates=keys.filter(function(key){return key!==previous;}); 7 if(!candidates.length)candidates=keys; 8 return candidates.length?candidates[Math.floor(Math.random()*candidates.length)]:'frame'; 9 } 10 function resolve(input,catalog,selection){ 11 catalog=catalog||{};selection=selection||{}; 12 var texts=catalog.texts||{}, backgrounds=catalog.backgrounds||{}; 13 var text=input.text_design||input.design||'frame'; 14 var background=input.background_design||legacyBackground(input.design||'frame'); 15 function pick(key,items,field){ 16 if(key==='random'){ 17 if(!Object.prototype.hasOwnProperty.call(items,selection[field]))selection[field]=draw(items); 18 return selection[field]; 19 } 20 return /^[a-z]+$/.test(key) && (!Object.keys(items).length||Object.prototype.hasOwnProperty.call(items,key))?key:'frame'; 21 } 22 var selectedText=pick(text,texts,'text'), selectedBackground=pick(background,backgrounds,'background'); 23 var settings=Object.assign({},input); 24 if(text==='random' && texts[selectedText])Object.assign(settings,texts[selectedText].defaults); 25 settings.design=selectedText;settings.text_design=selectedText;settings.background_design=selectedBackground; 26 return settings; 27 } 28 function shuffle(input,catalog,selection){ 29 catalog=catalog||{}; 30 if(input.text_design==='random')selection.text=draw(catalog.texts||{},selection.text); 31 if(input.background_design==='random')selection.background=draw(catalog.backgrounds||{},selection.background); 32 } 33 global.RHIECDesigns={resolve:resolve,shuffle:shuffle}; 34})(window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.