Skip to content

Commit

Permalink
v1.1.2 - ready to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
patelka2211 committed Jun 29, 2023
1 parent f448515 commit c43915d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 26 deletions.
4 changes: 2 additions & 2 deletions DynamicColors.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
## Installation

[![npm (scoped)](https://img.shields.io/npm/v/dynamic-colors)](https://www.npmjs.com/package/dynamic-colors)
[![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/dynamic-colors)](https://bundlephobia.com/package/[email protected].1)
[![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/dynamic-colors)](https://bundlephobia.com/package/[email protected].2)
[![npm](https://img.shields.io/npm/dy/dynamic-colors)](https://www.npmjs.com/package/dynamic-colors)
[![jsDelivr hits (npm scoped)](https://img.shields.io/jsdelivr/gh/hy/patelka2211/dynamic-colors)](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].1/)
[![jsDelivr hits (npm scoped)](https://img.shields.io/jsdelivr/gh/hy/patelka2211/dynamic-colors)](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].2/)

To install Dynamic Colors using npm, run the following command:

```sh
npm i dynamic-colors
```

Alternatively, you can include [Dynnamic Colors's IIFE file](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].1/DynamicColors.js) in your website using a `<script>` tag:
Alternatively, you can include [Dynnamic Colors's IIFE file](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].2/DynamicColors.js) in your website using a `<script>` tag:

```html
<script src="https://cdn.jsdelivr.net/gh/patelka2211/[email protected].1/DynamicColors.js"></script>
<script src="https://cdn.jsdelivr.net/gh/patelka2211/[email protected].2/DynamicColors.js"></script>
```

## Available APIs
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": "dynamic-colors",
"version": "1.1.1",
"version": "1.1.2",
"description": "Dynamic Colors is a JavaScript library that can dynamically generate color theme from a single HEX color and it provides a range of useful APIs for creating, managing, and manipulating color themes.",
"main": "index.js",
"module": "index.js",
Expand Down
4 changes: 2 additions & 2 deletions src/dynamicColors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { theme2x } from "./OSTheme";
import { getThemeCSSFromColor } from "./getColor";
import { addInstance, dcIDList, instances, removeInstance } from "./instances";
import { addLock, isLocked, removeLock } from "./lockMechanism";
Expand Down Expand Up @@ -51,8 +52,7 @@ export class DynamicColors {

if (this.id === undefined) return;

const { css, theme2x } = getThemeCSSFromColor(this.id, color);
this.styleTag.innerHTML = css;
this.styleTag.innerHTML = getThemeCSSFromColor(this.id, color);
this.styleTag.setAttribute("dc-color", color);
this.styleTag.setAttribute("dc-theme", theme2x);
}
Expand Down
19 changes: 6 additions & 13 deletions src/getColor.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import materialDynamicColors from "./helper/mdc";
import { fromHEX } from "./helper/mdc";
import { hex2rgb } from "./hex2rgb";
import { LightOrDark, theme2x } from "./OSTheme";
import { theme2x } from "./OSTheme";

/**
* Retrieves the theme CSS string for a given color.
* @param {string} id The ID associated with the DynamicColors.
* @param {string} color The color value.
* @returns {Object} An object containing the CSS string and theme value.
* @returns {string} CSS string.
*/
export function getThemeCSSFromColor(
id: string,
color: string
): {
css: string;
theme2x: LightOrDark;
} {
let themeObj = materialDynamicColors(color)[theme2x] as {
export function getThemeCSSFromColor(id: string, color: string): string {
let themeObj = fromHEX(color)[theme2x] as {
[_: string]: string;
},
css = "*{";
Expand All @@ -28,6 +22,5 @@ export function getThemeCSSFromColor(
css += `--${id}-${colorName}-rgb:${rgb.r},${rgb.g},${rgb.b};`;
}
css += "}";

return { css, theme2x };
return css;
}
3 changes: 1 addition & 2 deletions src/helper/mdc.js

Large diffs are not rendered by default.

0 comments on commit c43915d

Please sign in to comment.