Skip to content

Commit

Permalink
Merge pull request #81 from fosslife/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparkenstein authored Jul 13, 2024
2 parents 7f91eec + 3e9539d commit 79bf016
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 13 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

## [devtoolsx-v2.10.0] - 2024-07-05
## [devtoolsx-v2.10.0] - 2024-07-12

### 🚀 Features

Expand All @@ -15,20 +15,33 @@ All notable changes to this project will be documented in this file.
- Support both grouped and ungrouped views, settings in sidebar
- Vertical layout
- Auto open accordion for path
- Changelog generator
- Css playground
- *(ci)* New bump version script
- Rewrote jwt
- Rest options for monaco
- Svg preview
- QR code reader
- Compress binaries with upx

### 🐛 Bug Fixes

- Hardcoded width
- Vertical image overflow
- Error handling
- *(ci)* Js heap out of mem
- *(ci)* Incorrect matrix platforms
- Autosizing text
- No sourcemaps
- Upx script

### 📚 Documentation

- Rest client
- Update FAQ
- Star history
- Reorder features
- New feature

### ⚙️ Miscellaneous Tasks

Expand All @@ -40,6 +53,9 @@ All notable changes to this project will be documented in this file.
- Cleanup
- Unused vars rule
- Deps upgrade
- *(doc)* Add download instructions
- *(ui)* Shortcut styling
- Rename file

### Deps

Expand All @@ -49,6 +65,8 @@ All notable changes to this project will be documented in this file.

- V2.10.0
- V2.11.0
- V2.11.1
- V2.12.0

## [devtoolsx-v2.9.0] - 2024-03-31

Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dev-tools",
"version": "2.12.0",
"version": "2.13.0",
"license": "MIT",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -36,6 +36,7 @@
"@uiw/react-markdown-preview": "^5.1.1",
"angular-html-parser": "^5.2.0",
"axios": "^1.6.8",
"chroma-js": "^2.4.2",
"clsx": "^2.1.0",
"color-convert": "^2.0.1",
"convert-units": "^2.3.4",
Expand All @@ -61,6 +62,7 @@
"react": "^18.2.0",
"react-colorful": "^5.6.1",
"react-compare-slider": "^3.0.1",
"react-cropper": "^2.3.3",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
"react-live": "^4.1.5",
Expand All @@ -79,6 +81,7 @@
"@actions/github": "^6.0.0",
"@linaria/rollup": "^5.0.4",
"@tauri-apps/cli": "^1.6.0",
"@types/chroma-js": "^2.4.4",
"@types/color-convert": "^2.0.3",
"@types/convert-units": "^2.3.9",
"@types/crypto-js": "^4.2.2",
Expand Down Expand Up @@ -113,6 +116,5 @@
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.4.3",
"vite": "^5.2.7"
},
"packageManager": "yarn@1.22.22"
}
}
}
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

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

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "devtools-x"
version = "2.12.0"
version = "2.13.0"
description = "Developer tools desktop application"
authors = ["Sparkenstein"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "dev-tools",
"version": "2.12.0"
"version": "2.13.0"
},
"build": {
"distDir": "../dist",
Expand Down
12 changes: 11 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ const Compress = loadable(() => import("./Features/text/TextCompress"));
const Faker = loadable(() => import("./Features/faker/Faker"));
const CssPlayground = loadable(() => import("./Features/css/CssPlayground"));
const SvgPreview = loadable(() => import("./Features/svg/Svg"));

const ColorGenerator = loadable(
() => import("./Features/colors/ColorGenerator")
);
const QrReadcer = loadable(() => import("./Features/qrcode/QrCodeReader"));
const HmacGenerator = loadable(() => import("./Features/hash/HmacGenerator"));
const ImageCrop = loadable(() => import("./Features/image/ImageCrop"));

const shortCuts = [
{
Expand Down Expand Up @@ -249,6 +253,12 @@ function App() {
<Route path="/cssplayground" element={<CssPlayground />}></Route>
<Route path="/svg-preview" element={<SvgPreview />}></Route>
<Route path="/qrcode-reader" element={<QrReadcer />}></Route>
<Route path="/hmac-generator" element={<HmacGenerator />}></Route>
<Route path="/image-crop" element={<ImageCrop />}></Route>
<Route
path="/colorgenerator"
element={<ColorGenerator />}
></Route>
</Routes>
</Stack>
</Group>
Expand Down
60 changes: 60 additions & 0 deletions src/Features/colors/ColorGenerator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
ColorPicker,
ColorSwatch,
Group,
isLightColor,
Stack,
Text,
} from "@mantine/core";
import { generateColorsMap } from "./generator";
import { useState } from "react";
import classes from "./colorgenerator.module.css";

export default function ColorGenerator() {
const [selectedColor, setSelectedColor] = useState("#FF007F");

const { baseColorIndex, colors } = generateColorsMap(selectedColor);
return (
<Stack>
<ColorPicker
w="100%"
value={selectedColor}
style={{ border: "1px solid #ccc" }}
onChange={(e) => setSelectedColor(e)}
/>
<Text
w="fit-content"
p="5px"
c={selectedColor}
bg={isLightColor(selectedColor) ? "dark" : "white"}
>
{" "}
Selected color: {selectedColor}
</Text>
<Group grow gap={0}>
{colors?.map((color, index) => (
<div key={index} className={classes.item}>
<ColorSwatch
color={color.hex()}
radius={0}
className={classes.swatch}
withShadow={false}
data-base={index === baseColorIndex || undefined}
c={isLightColor(color.hex()) ? "black" : "white"}
>
{
<div className={classes.label}>
<span className={classes.index}>{index}</span>
<span className={classes.hex}>{color.hex()}</span>
</div>
}
</ColorSwatch>
</div>
))}
</Group>
<Text c="dimmed">
Inspired from: https://mantine.dev/colors-generator
</Text>
</Stack>
);
}
61 changes: 61 additions & 0 deletions src/Features/colors/colorgenerator.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
item {
flex: 1;

&:first-of-type > .swatch {
border-top-left-radius: var(--mantine-radius-md) !important;
border-bottom-left-radius: var(--mantine-radius-md) !important;
}

&:last-of-type > .swatch {
border-top-right-radius: var(--mantine-radius-md) !important;
border-bottom-right-radius: var(--mantine-radius-md) !important;
}
}

.swatch {
width: 100%;
height: 0;
padding-bottom: 100%;
overflow: hidden;
transition:
transform 100ms ease,
box-shadow 100ms ease,
border-radius 100ms ease;

&[data-base] {
transform: scale(1.2) translateY(-5px);
z-index: 1;
box-shadow: var(--mantine-shadow-md);
border-radius: var(--mantine-radius-md);

@media (max-width: em(600px)) {
transform: none;
box-shadow: none;
border-radius: 0;
}
}
}

.label {
display: flex;
flex-direction: column;
text-align: center;
gap: 5px;

@media (max-width: em(600px)) {
display: none;
}
}

.hex {
font-weight: 700;
text-transform: uppercase;
font-family: var(--mantine-font-family-monospace);
font-size: 10px;
}

.index {
font-size: var(--mantine-font-size-lg);
font-weight: 700;
font-family: var(--docs-font-primary);
}
53 changes: 53 additions & 0 deletions src/Features/colors/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import chroma from "chroma-js";

const LIGHTNESS_MAP = [
0.96, 0.907, 0.805, 0.697, 0.605, 0.547, 0.518, 0.445, 0.395, 0.34,
];
const SATURATION_MAP = [0.32, 0.16, 0.08, 0.04, 0, 0, 0.04, 0.08, 0.16, 0.32];

function getClosestLightness(colorObject: chroma.Color) {
const lightnessGoal = colorObject.get("hsl.l");
return LIGHTNESS_MAP.reduce((prev, curr) =>
Math.abs(curr - lightnessGoal) < Math.abs(prev - lightnessGoal)
? curr
: prev
);
}

export function generateColorsMap(color: string) {
const colorObject = chroma(color);
const closestLightness = getClosestLightness(colorObject);
const baseColorIndex = LIGHTNESS_MAP.findIndex((l) => l === closestLightness);

const colors = LIGHTNESS_MAP.map((l) => colorObject.set("hsl.l", l))
.map((c) => chroma(c))
.map((c, i) => {
const saturationDelta =
SATURATION_MAP[i] - SATURATION_MAP[baseColorIndex];
return saturationDelta >= 0
? c.saturate(saturationDelta)
: c.desaturate(saturationDelta * -1);
});

return { baseColorIndex, colors };
}

export type MantineColorsTuple = readonly [
string,
string,
string,
string,
string,
string,
string,
string,
string,
string,
...string[],
];

export function generateColors(color: string) {
return generateColorsMap(color).colors.map((c) =>
c.hex()
) as unknown as MantineColorsTuple;
}
53 changes: 53 additions & 0 deletions src/Features/hash/HmacGenerator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Divider, Stack, Textarea, TextInput } from "@mantine/core";
import { useInputState } from "@mantine/hooks";
import { useEffect, useState } from "react";

export default function HmacGenerator() {
const [hmac, setHmac] = useState("");
const [input, setInput] = useInputState("");
const [secret, setSecret] = useInputState("");

useEffect(() => {
if (input && secret) {
const encoder = new TextEncoder();
const data = encoder.encode(input);
const key = encoder.encode(secret);
crypto.subtle
.importKey("raw", key, { name: "HMAC", hash: "SHA-256" }, false, [
"sign",
])
.then((key) =>
crypto.subtle.sign("HMAC", key, data).then((signature) => {
const view = new DataView(signature);
let hex = "";
for (let i = 0; i < view.byteLength; i += 1) {
const byte = view.getUint8(i).toString(16);
hex += byte.length === 1 ? `0${byte}` : byte;
}
setHmac(hex);
})
);
} else {
setHmac("");
}
}, [input, secret]);

return (
<Stack>
<Textarea
minRows={5}
autosize
value={input}
onChange={setInput}
placeholder="Enter input data"
/>
<TextInput
placeholder="Enter secret key"
value={secret}
onChange={setSecret}
/>
<Divider label="HMAC" />
<Textarea placeholder="generated HMAC" value={hmac} readOnly />
</Stack>
);
}
Loading

0 comments on commit 79bf016

Please sign in to comment.