diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 895f651..6f9f10c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "10.2.0" + ".": "10.3.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 95ca6f0..4882ce9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [10.3.0](https://github.com/javalent/admonitions/compare/10.2.0...10.3.0) (2024-05-23) + + +### Features + +* Adds support for HSL, HSB, HSV, HEX and RGB colors in Admonition definitions (thanks [@x](https://github.com/x)Ryul ) ([a872858](https://github.com/javalent/admonitions/commit/a8728585e65e853d16eebebf52f33aa84755e9e4)) + + +### Bug Fixes + +* Improves appearance of Editor suggester ([7652ed0](https://github.com/javalent/admonitions/commit/7652ed08cc13cfea9f8fad0bae6473706991f286)) +* Improves appearance of suggesters (close [#338](https://github.com/javalent/admonitions/issues/338)) ([e36a4a8](https://github.com/javalent/admonitions/commit/e36a4a88fbb6590a4acbd78822ab5b6e7d203e36)) +* Improves behavior of Admonition edit modal ([72c2bc3](https://github.com/javalent/admonitions/commit/72c2bc3024957315e8b6c3e1693b59379962ad07)) +* Improves lifetime of Admonition rendered content ([a045776](https://github.com/javalent/admonitions/commit/a04577628731ced61b04e40d82afa86dd1c51c79)) + ## [10.2.0](https://github.com/javalent/admonitions/compare/10.1.2...10.2.0) (2024-02-13) diff --git a/manifest.json b/manifest.json index 730f0b3..820563a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-admonition", "name": "Admonition", - "version": "10.2.0", + "version": "10.3.0", "minAppVersion": "1.1.0", "description": "Enhanced callouts for Obsidian.md", "author": "Jeremy Valentine", diff --git a/package-lock.json b/package-lock.json index 46919ec..6a6f5de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-admonition", - "version": "10.2.0", + "version": "10.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-admonition", - "version": "10.2.0", + "version": "10.3.0", "license": "MIT", "dependencies": { "@fortawesome/free-brands-svg-icons": "^5.15.4", diff --git a/package.json b/package.json index 11ef6b0..25f4ebf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-admonition", - "version": "10.2.0", + "version": "10.3.0", "description": "Enhanced callouts for Obsidian.md", "main": "main.js", "scripts": { diff --git a/src/util/util.ts b/src/util/util.ts index c9c26e8..45f1ab4 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -49,6 +49,35 @@ export function getParametersFromSource( let { title, collapse, icon, color, metadata } = params; + // If color is in RGB format + if (color && color.startsWith('rgb')) { + color = color.slice(4, -1); + } + + // If color is in Hex format, convert it to RGB + if (color && color.startsWith('#')) { + const hex = color.slice(1); + const bigint = parseInt(hex, 16); + const r = (bigint >> 16) & 255; + const g = (bigint >> 8) & 255; + const b = bigint & 255; + color = `${r}, ${g}, ${b}`; + } + + // If color is in HSL format, convert it to RGB + if (color && color.startsWith('hsl')) { + const [h, s, l] = color.slice(4, -1).split(',').map(str => Number(str.replace('%', '').trim())); + const [r, g, b] = hslToRgb(h, s, l); + color = `${r}, ${g}, ${b}`; + } + + // If color is in HSB format, convert it to RGB + if (color && (color.startsWith('hsb') || color.startsWith('hsv'))) { + const [h, s, v] = color.slice(4, -1).split(',').map(str => Number(str.replace('%', '').trim())); + const [r, g, b] = hsbToRgb(h, s, v); + color = `${r}, ${g}, ${b}`; + } + let content = lines.slice(skipLines).join("\n"); /** @@ -83,3 +112,51 @@ export function getParametersFromSource( return { title, collapse, content, icon, color, metadata }; } + +function hslToRgb(h: number, s: number, l: number) { + h /= 360; + s /= 100; + l /= 100; + let r, g, b; + + if (s === 0) { + r = g = b = l; // achromatic + } else { + const hue2rgb = (p: number, q: number, t: number) => { + if (t < 0) t += 1; + if (t > 1) t -= 1; + if (t < 1 / 6) return p + (q - p) * 6 * t; + if (t < 1 / 2) return q; + if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; + return p; + }; + const q = l < 0.5 ? l * (1 + s) : l + s - l * s; + const p = 2 * l - q; + r = hue2rgb(p, q, h + 1 / 3); + g = hue2rgb(p, q, h); + b = hue2rgb(p, q, h - 1 / 3); + } + + return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]; +} + +function hsbToRgb(h: number, s: number, b: number) { + h /= 360; + s /= 100; + b /= 100; + let r, g, bb; + let i = Math.floor(h * 6); + let f = h * 6 - i; + let p = b * (1 - s); + let q = b * (1 - f * s); + let t = b * (1 - (1 - f) * s); + switch (i % 6) { + case 0: r = b, g = t, bb = p; break; + case 1: r = q, g = b, bb = p; break; + case 2: r = p, g = b, bb = t; break; + case 3: r = p, g = q, bb = b; break; + case 4: r = t, g = p, bb = b; break; + case 5: r = b, g = p, bb = q; break; + } + return [Math.round(r * 255), Math.round(g * 255), Math.round(bb * 255)]; +} \ No newline at end of file