PageSourceSearch

https://vestnikkui.ru/bundles/journals/js/ds-icons.js?v=20260315-icon-alias

js vestnikkui.ru collected 2026-10-02 20:03:50 UTC 3,195 bytes, 90 lines download raw bytes

1/**
2 * Editorum Design System — Icon Helper
3 *
4 * Creates SVG icon elements referencing the inline sprite.
5 * Replaces string-concatenated Font Awesome markup in JS files.
6 *
7 * Usage:
8 *   var svg = EditoriumIcons.create('chevron-down');
9 *   var svg = EditoriumIcons.create('trash-2', { size: 'md', class: 'text-danger' });
10 *   container.appendChild(svg);
11 *
12 *   // Or get an HTML string (for innerHTML / insertAdjacentHTML):
13 *   var html = EditoriumIcons.html('arrow-up', { size: 'lg' });
14 */
15(function (root) {
16    'use strict';
17
18    var SVG_NS = 'http://www.w3.org/2000/svg';
19    var XLINK_NS = 'http://www.w3.org/1999/xlink';
20
21    var EditoriumIcons = {
22        /**
23         * Create an SVG DOM element for the named icon.
24         * @param {string} name  - Icon name (e.g. 'arrow-up', 'check')
25         * @param {Object} [opts]
26         * @param {string} [opts.size='sm']   - Size variant: sm | md | lg | xl
27         * @param {string} [opts.class='']    - Extra CSS classes
28         * @param {Object} [opts.attrs={}]    - Extra DOM attributes
29         * @returns {SVGSVGElement}
30         */
31        create: function (name, opts) {
32            opts = opts || {};
33            var size = opts.size || 'sm';
34            var extraClass = opts['class'] || '';
35
36            var svg = document.createElementNS(SVG_NS, 'svg');
37            var cls = 'ds-icon';
38            if (size !== 'sm') cls += ' ds-icon--' + size;
39            if (extraClass) cls += ' ' + extraClass;
40            svg.setAttribute('class', cls);
41            svg.setAttribute('aria-hidden', 'true');
42
43            if (opts.attrs) {
44                for (var key in opts.attrs) {
45                    if (opts.attrs.hasOwnProperty(key)) {
46                        svg.setAttribute(key, opts.attrs[key]);
47                    }
48                }
49            }
50
51            var use = document.createElementNS(SVG_NS, 'use');
52            use.setAttributeNS(XLINK_NS, 'xlink:href', '#icon-' + name);
53            use.setAttribute('href', '#icon-' + name);
54            svg.appendChild(use);
55
56            return svg;
57        },
58
59        /**
60         * Return an HTML string for the named icon.
61         * Useful for innerHTML and string concatenation contexts.
62         * @param {string} name
63         * @param {Object} [opts]  - Same options as create()
64         * @returns {string}
65         */
66        html: function (name, opts) {
67            opts = opts || {};
68            var size = opts.size || 'sm';
69            var extraClass = opts['class'] || '';
70
71            var cls = 'ds-icon';
72            if (size !== 'sm') cls += ' ds-icon--' + size;
73            if (extraClass) cls += ' ' + extraClass;
74
75            var attrsStr = '';
76            if (opts.attrs) {
77                for (var key in opts.attrs) {
78                    if (opts.attrs.hasOwnProperty(key)) {
79                        attrsStr += ' ' + key + '="' + opts.attrs[key] + '"';
80                    }
81                }
82            }
83
84            return '<svg class="' + cls + '" aria-hidden="true"' + attrsStr + '><use href="#icon-' + name + '"/></svg>';
85        }
86    };
87
88    root.EditoriumIcons = EditoriumIcons;
89    root.EditorumIcons = EditoriumIcons;
90})(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.