Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ition into main
  • Loading branch information
valentine195 committed May 23, 2024
2 parents 1bb3398 + 594790c commit 7105416
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "10.2.0"
".": "10.3.0"
}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
77 changes: 77 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

/**
Expand Down Expand Up @@ -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)];
}

0 comments on commit 7105416

Please sign in to comment.