add jsdoc comments

This commit is contained in:
lchen committed 2026-11-18 10:14:21 +08:00
1 parent 6de354ad47
commit 8c1205bc13
24 files changed
+1228 -425

No files matched your search

+44 -6
View File
@@ -1,13 +1,22 @@
import { global } from "../utility";
const svgns = 'http://www.w3.org/2000/svg';
/** @type {Object.<string, string>} */
const dict = {
"\uf000": "glass-martini", "\uf001": "music", "\uf002": "search", "\uf004": "heart", "\uf005": "star", "\uf007": "user", "\uf008": "film", "\uf009": "th-large", "\uf00a": "th", "\uf00b": "th-list", "\uf00c": "check", "\uf00d": "times", "\uf00e": "search-plus", "\uf010": "search-minus", "\uf011": "power-off", "\uf012": "signal", "\uf013": "cog", "\uf015": "home", "\uf017": "clock", "\uf018": "road", "\uf019": "download", "\uf01c": "inbox", "\uf01e": "redo", "\uf021": "sync", "\uf022": "list-alt", "\uf023": "lock", "\uf024": "flag", "\uf025": "headphones", "\uf026": "volume-off", "\uf027": "volume-down", "\uf028": "volume-up", "\uf029": "qrcode", "\uf02a": "barcode", "\uf02b": "tag", "\uf02c": "tags", "\uf02d": "book", "\uf02e": "bookmark", "\uf02f": "print", "\uf030": "camera", "\uf031": "font", "\uf032": "bold", "\uf033": "italic", "\uf034": "text-height", "\uf035": "text-width", "\uf036": "align-left", "\uf037": "align-center", "\uf038": "align-right", "\uf039": "align-justify", "\uf03a": "list", "\uf03b": "outdent", "\uf03c": "indent", "\uf03d": "video", "\uf03e": "image", "\uf040": "pencil", "\uf041": "map-marker", "\uf042": "adjust", "\uf043": "tint", "\uf044": "edit", "\uf047": "arrows", "\uf048": "step-backward", "\uf049": "fast-backward", "\uf04a": "backward", "\uf04b": "play", "\uf04c": "pause", "\uf04d": "stop", "\uf04e": "forward", "\uf050": "fast-forward", "\uf051": "step-forward", "\uf052": "eject", "\uf053": "chevron-left", "\uf054": "chevron-right", "\uf055": "plus-circle", "\uf056": "minus-circle", "\uf057": "times-circle", "\uf058": "check-circle", "\uf059": "question-circle", "\uf05a": "info-circle", "\uf05b": "crosshairs", "\uf05e": "ban", "\uf060": "arrow-left", "\uf061": "arrow-right", "\uf062": "arrow-up", "\uf063": "arrow-down", "\uf064": "share", "\uf065": "expand", "\uf066": "compress", "\uf067": "plus", "\uf068": "minus", "\uf069": "asterisk", "\uf06a": "exclamation-circle", "\uf06b": "gift", "\uf06c": "leaf", "\uf06d": "fire", "\uf06e": "eye", "\uf070": "eye-slash", "\uf071": "exclamation-triangle", "\uf072": "plane", "\uf073": "calendar-alt", "\uf074": "random", "\uf075": "comment", "\uf076": "magnet", "\uf077": "chevron-up", "\uf078": "chevron-down", "\uf079": "retweet", "\uf07a": "shopping-cart", "\uf07b": "folder", "\uf07c": "folder-open", "\uf07d": "arrows-v", "\uf07e": "arrows-h", "\uf080": "chart-bar", "\uf083": "camera-retro", "\uf084": "key", "\uf085": "cogs", "\uf086": "comments", "\uf089": "star-half", "\uf08b": "sign-out", "\uf08d": "thumbtack", "\uf08e": "external-link", "\uf090": "sign-in", "\uf091": "trophy", "\uf093": "upload", "\uf094": "lemon", "\uf095": "phone", "\uf098": "phone-square", "\uf09c": "unlock", "\uf09d": "credit-card", "\uf09e": "rss", "\uf0a0": "hdd", "\uf0a1": "bullhorn", "\uf0a3": "certificate", "\uf0a4": "hand-point-right", "\uf0a5": "hand-point-left", "\uf0a6": "hand-point-up", "\uf0a7": "hand-point-down", "\uf0a8": "arrow-circle-left", "\uf0a9": "arrow-circle-right", "\uf0aa": "arrow-circle-up", "\uf0ab": "arrow-circle-down", "\uf0ac": "globe", "\uf0ad": "wrench", "\uf0ae": "tasks", "\uf0b0": "filter", "\uf0b1": "briefcase", "\uf0b2": "arrows-alt", "\uf0c0": "users", "\uf0c1": "link", "\uf0c2": "cloud", "\uf0c3": "flask", "\uf0c4": "cut", "\uf0c5": "copy", "\uf0c6": "paperclip", "\uf0c7": "save", "\uf0c8": "square", "\uf0c9": "bars", "\uf0ca": "list-ul", "\uf0cb": "list-ol", "\uf0cc": "strikethrough", "\uf0cd": "underline", "\uf0ce": "table", "\uf0d0": "magic", "\uf0d1": "truck", "\uf0d6": "money-bill", "\uf0d7": "caret-down", "\uf0d8": "caret-up", "\uf0d9": "caret-left", "\uf0da": "caret-right", "\uf0db": "columns", "\uf0dc": "sort", "\uf0dd": "sort-down", "\uf0de": "sort-up", "\uf0e0": "envelope", "\uf0e2": "undo", "\uf0e3": "gavel", "\uf0e4": "tachometer", "\uf0e7": "bolt", "\uf0e8": "sitemap", "\uf0e9": "umbrella", "\uf0ea": "paste", "\uf0eb": "lightbulb", "\uf0ec": "exchange", "\uf0ed": "cloud-download", "\uf0ee": "cloud-upload", "\uf0f0": "user-md", "\uf0f1": "stethoscope", "\uf0f2": "suitcase", "\uf0f3": "bell", "\uf0f4": "coffee", "\uf0f8": "hospital", "\uf0f9": "ambulance", "\uf0fa": "medkit", "\uf0fb": "fighter-jet", "\uf0fc": "beer", "\uf0fd": "h-square", "\uf0fe": "plus-square", "\uf100": "angle-double-left", "\uf101": "angle-double-right", "\uf102": "angle-double-up", "\uf103": "angle-double-down", "\uf104": "angle-left", "\uf105": "angle-right", "\uf106": "angle-up", "\uf107": "angle-down", "\uf108": "desktop", "\uf109": "laptop", "\uf10a": "tablet", "\uf10b": "mobile", "\uf10d": "quote-left", "\uf10e": "quote-right", "\uf110": "spinner", "\uf111": "circle", "\uf118": "smile", "\uf119": "frown", "\uf11a": "meh", "\uf11b": "gamepad", "\uf11c": "keyboard", "\uf11e": "flag-checkered", "\uf120": "terminal", "\uf121": "code", "\uf122": "reply-all", "\uf124": "location-arrow", "\uf125": "crop", "\uf126": "code-branch", "\uf127": "unlink", "\uf128": "question", "\uf129": "info", "\uf12a": "exclamation", "\uf12b": "superscript", "\ufLine truncated
};
/**
* @private
* @param {string} type
* @param {string} id
* @returns {SVGUseElement}
*/
function createUse(type, id) {
const c = typeof consts !== 'undefined' ? consts : {};
const c = typeof global.consts !== 'undefined' ? global.consts : { resver: null, path: null };
const path = c.path ||
(typeof _network !== 'undefined' ? _network.root :
(typeof _net !== 'undefined' ? _net.root : ''));
(typeof global._network !== 'undefined' ? global._network.root :
(typeof global._net !== 'undefined' ? global._net.root : ''));
const ver = c.resver == null ? '' : `?${c.resver}`;
const use = document.createElementNS(svgns, 'use');
if (id?.length === 1 && id.charCodeAt(0) > 0xf000) {
@@ -17,6 +26,13 @@ function createUse(type, id) {
return use;
}
/**
* @template {typeof SVGElement} K
* @param {K} svg
* @param {string} type
* @param {string} id
* @returns {K}
*/
export function changeIcon(svg, type, id) {
if (svg instanceof SVGElement) {
svg.replaceChildren(createUse(type, id));
@@ -24,10 +40,23 @@ export function changeIcon(svg, type, id) {
return svg;
}
/**
* @param {string} type
* @param {string} id
* @param {{[key: string]: string} | ((icon: SVGSVGElement) => {[key: string]: string})} [style]
* @param {(this: SVGSVGElement, ev: PointerEvent) => any} [action]
* @returns {SVGSVGElement}
*/
export function createIcon(type, id, style, action) {
const svg = document.createElementNS(svgns, 'svg');
svg.classList.add('ui-icon');
svg.appendChild(createUse(type, id));
const css = typeof style === 'function' ? style(svg) : style;
if (css != null) {
for (let [key, value] of Object.entries(css)) {
svg.style.setProperty(key, value);
}
}
if (typeof style === 'function') {
style(svg);
} else if (style != null) {
@@ -41,15 +70,24 @@ export function createIcon(type, id, style, action) {
return svg;
}
/**
* @param {HTMLElement} container
* @returns {HTMLElement}
*/
export function resolveIcon(container) {
const svgs = container.querySelectorAll('svg[data-id]');
for (let icon of svgs) {
if (!(icon instanceof SVGElement)) {
continue;
}
icon.classList.add('ui-icon');
const type = icon.dataset.type;
const id = icon.dataset.id;
icon.replaceChildren(createUse(type, id));
icon.removeAttribute('data-type');
icon.removeAttribute('data-id');
if (type != null && id != null) {
icon.replaceChildren(createUse(type, id));
icon.removeAttribute('data-type');
icon.removeAttribute('data-id');
}
}
return container;
}