1(function (window, document) { 2 'use strict'; 3 4 var script = document.currentScript; 5 var defaultBase = '/lucide/icons/'; 6 var baseUrl = window.RB_LUCIDE_ICON_BASE || defaultBase; 7 8 if (!window.RB_LUCIDE_ICON_BASE && script && script.src) { 9 baseUrl = script.src.replace(/\/rb-lucide-loader\.js(?:[?#].*)?$/, '/icons/'); 10 } 11 12 var iconCache = Object.create(null); 13 var iconPending = Object.create(null); 14 var svgNs = 'http://www.w3.org/2000/svg'; 15 var iconAliases = { 16 'help-circle': 'circle-question-mark', 17 'home': 'house', 18 'minus-circle': 'circle-minus' 19 }; 20 21 function normalizeName(name) { 22 name = String(name || '').toLowerCase(); 23 return /^[a-z0-9-]+$/.test(name) ? name : ''; 24 } 25 26 function iconUrl(name) { 27 var fileName = iconAliases[name] || name; 28 return new URL(encodeURIComponent(fileName) + '.svg', baseUrl).toString(); 29 } 30 31 function loadIcon(name) { 32 if (iconCache[name]) return Promise.resolve(iconCache[name]); 33 if (iconPending[name]) return iconPending[name]; 34 35 iconPending[name] = fetch(iconUrl(name), { 36 credentials: 'same-origin', 37 cache: 'force-cache' 38 }).then(function (response) { 39 if (!response.ok) throw new Error('Lucide icon not found: ' + name); 40 return response.text(); 41 }).then(function (text) { 42 iconCache[name] = text; 43 delete iconPending[name]; 44 return text; 45 }).catch(function (error) { 46 delete iconPending[name]; 47 throw error; 48 }); 49 50 return iconPending[name]; 51 } 52 53 function addClasses(svg, source, name) { 54 var sourceClass = source.getAttribute('class') || ''; 55 var classes = ('lucide lucide-' + name + ' ' + sourceClass).replace(/\s+/g, ' ').trim(); 56 svg.setAttribute('class', classes); 57 } 58 59 function copySourceAttributes(svg, source) { 60 for (var i = 0; i < source.attributes.length; i++) { 61 var attr = source.attributes[i]; 62 if (attr.name === 'data-lucide' || attr.name === 'class') continue; 63 svg.setAttribute(attr.name, attr.value); 64 } 65 } 66 67 function buildSvg(name, source, text) { 68 var parsed = new DOMParser().parseFromString(text, 'image/svg+xml'); 69 var rawSvg = parsed.documentElement; 70 71 if (!rawSvg || rawSvg.nodeName.toLowerCase() !== 'svg') { 72 return null; 73 } 74 75 var svg = document.createElementNS(svgNs, 'svg'); 76 for (var i = 0; i < rawSvg.attributes.length; i++) { 77 var attr = rawSvg.attributes[i]; 78 svg.setAttribute(attr.name, attr.value); 79 } 80 81 copySourceAttributes(svg, source); 82 addClasses(svg, source, name); 83 svg.innerHTML = rawSvg.innerHTML; 84 return svg; 85 } 86 87 function replaceIcon(source, name, text) { 88 if (!source || !source.parentNode) return; 89 90 var svg = buildSvg(name, source, text); 91 if (!svg) { 92 source.setAttribute('data-lucide-error', '1'); 93 return; 94 } 95 96 source.parentNode.replaceChild(svg, source); 97 } 98 99 function createIcons(options) { 100 options = options || {}; 101 var attrName = options.nameAttr || 'data-lucide'; 102 var selector = '[' + attrName + ']:not([data-lucide-error])'; 103 var nodes = options.nodes || document.querySelectorAll(selector); 104 var tasks = []; 105 106 for (var i = 0; i < nodes.length; i++) { 107 (function (node) { 108 var name = normalizeName(node.getAttribute(attrName)); 109 if (!name) { 110 node.setAttribute('data-lucide-error', '1'); 111 return; 112 } 113 114 tasks.push(loadIcon(name).then(function (text) { 115 replaceIcon(node, name, text); 116 }).catch(function () { 117 node.setAttribute('data-lucide-error', '1'); 118 })); 119 })(nodes[i]); 120 } 121 122 return Promise.all(tasks); 123 } 124 125 window.lucide = window.lucide || {}; 126 window.lucide.createIcons = createIcons; 127 128 if (document.readyState === 'loading') { 129 document.addEventListener('DOMContentLoaded', function () { 130 createIcons(); 131 }, { once: true }); 132 } else { 133 window.setTimeout(createIcons, 0); 134 } 135})(window, document);
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.