From a11169e2f1b51165c012fb0429beda20ac8b93f9 Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov <186095128+alexandr-garbuzov@users.noreply.github.com> Date: Fri, 17 Oct 2025 22:57:15 +0300 Subject: [PATCH] refactor: move create progress node function into render module (#4594) Co-authored-by: Alexandr --- src/cards/top-languages.js | 7 +++-- src/cards/wakatime.js | 3 +-- src/common/createProgressNode.js | 46 -------------------------------- src/common/index.js | 1 - src/common/render.js | 42 +++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 51 deletions(-) delete mode 100644 src/common/createProgressNode.js diff --git a/src/cards/top-languages.js b/src/cards/top-languages.js index 4493835f..6a36bfc6 100644 --- a/src/cards/top-languages.js +++ b/src/cards/top-languages.js @@ -2,11 +2,14 @@ import { Card } from "../common/Card.js"; import { getCardColors } from "../common/color.js"; -import { createProgressNode } from "../common/createProgressNode.js"; import { formatBytes } from "../common/fmt.js"; import { I18n } from "../common/I18n.js"; import { chunkArray, clampValue, lowercaseTrim } from "../common/ops.js"; -import { flexLayout, measureText } from "../common/render.js"; +import { + createProgressNode, + flexLayout, + measureText, +} from "../common/render.js"; import { langCardLocales } from "../translations.js"; const DEFAULT_CARD_WIDTH = 300; diff --git a/src/cards/wakatime.js b/src/cards/wakatime.js index 811fb243..9107e82d 100644 --- a/src/cards/wakatime.js +++ b/src/cards/wakatime.js @@ -2,10 +2,9 @@ import { Card } from "../common/Card.js"; import { getCardColors } from "../common/color.js"; -import { createProgressNode } from "../common/createProgressNode.js"; import { I18n } from "../common/I18n.js"; import { clampValue, lowercaseTrim } from "../common/ops.js"; -import { flexLayout } from "../common/render.js"; +import { createProgressNode, flexLayout } from "../common/render.js"; import { wakatimeCardLocales } from "../translations.js"; /** Import language colors. diff --git a/src/common/createProgressNode.js b/src/common/createProgressNode.js deleted file mode 100644 index e63944e7..00000000 --- a/src/common/createProgressNode.js +++ /dev/null @@ -1,46 +0,0 @@ -// @ts-check - -import { clampValue } from "./ops.js"; - -/** - * Create a node to indicate progress in percentage along a horizontal line. - * - * @param {Object} params Object that contains the createProgressNode parameters. - * @param {number} params.x X-axis position. - * @param {number} params.y Y-axis position. - * @param {number} params.width Width of progress bar. - * @param {string} params.color Progress color. - * @param {number} params.progress Progress value. - * @param {string} params.progressBarBackgroundColor Progress bar bg color. - * @param {number} params.delay Delay before animation starts. - * @returns {string} Progress node. - */ -const createProgressNode = ({ - x, - y, - width, - color, - progress, - progressBarBackgroundColor, - delay, -}) => { - const progressPercentage = clampValue(progress, 2, 100); - - return ` - - - - - - - `; -}; - -export { createProgressNode }; -export default createProgressNode; diff --git a/src/common/index.js b/src/common/index.js index ccedfa9a..db914b86 100644 --- a/src/common/index.js +++ b/src/common/index.js @@ -2,7 +2,6 @@ export { blacklist } from "./blacklist.js"; export { Card } from "./Card.js"; -export { createProgressNode } from "./createProgressNode.js"; export { I18n } from "./I18n.js"; export { icons } from "./icons.js"; export { retryer } from "./retryer.js"; diff --git a/src/common/render.js b/src/common/render.js index 32ecc8eb..594abaa5 100644 --- a/src/common/render.js +++ b/src/common/render.js @@ -3,6 +3,7 @@ import { SECONDARY_ERROR_MESSAGES, TRY_AGAIN_LATER } from "./error.js"; import { getCardColors } from "./color.js"; import { encodeHTML } from "./html.js"; +import { clampValue } from "./ops.js"; /** * Auto layout utility, allows us to layout things vertically or horizontally with @@ -45,6 +46,46 @@ const createLanguageNode = (langName, langColor) => { `; }; +/** + * Create a node to indicate progress in percentage along a horizontal line. + * + * @param {Object} params Object that contains the createProgressNode parameters. + * @param {number} params.x X-axis position. + * @param {number} params.y Y-axis position. + * @param {number} params.width Width of progress bar. + * @param {string} params.color Progress color. + * @param {number} params.progress Progress value. + * @param {string} params.progressBarBackgroundColor Progress bar bg color. + * @param {number} params.delay Delay before animation starts. + * @returns {string} Progress node. + */ +const createProgressNode = ({ + x, + y, + width, + color, + progress, + progressBarBackgroundColor, + delay, +}) => { + const progressPercentage = clampValue(progress, 2, 100); + + return ` + + + + + + + `; +}; + /** * Creates an icon with label to display repository/gist stats like forks, stars, etc. * @@ -191,6 +232,7 @@ export { ERROR_CARD_LENGTH, renderError, createLanguageNode, + createProgressNode, iconWithLabel, flexLayout, measureText,