Skip to content

Commit

Permalink
Merge branch 'main' into feat/palette-version
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoudham authored Sep 20, 2024
2 parents cede8df + cf765d2 commit e89f382
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 38 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
tag_name: ${{ steps.release.outputs.tag_name }}

release:
runs-on: ubuntu-latest
runs-on: macos-latest
needs: release-please
if: ${{ needs.release-please.outputs.release_created || github.event.inputs.force_release }}
steps:
Expand All @@ -43,8 +43,14 @@ jobs:
node-version: "lts/*"
registry-url: "https://registry.npmjs.org"

- uses: swift-actions/setup-swift@v2
with:
swift-version: "5"

- name: Build
run: deno task build
env:
COMPILE_APPLE_COLOR_LIST: 1

- name: Publish NPM package
working-directory: dist/npm
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ on:
jobs:
main:
name: Lint and test
runs-on: ubuntu-latest
runs-on: macos-latest

steps:
- uses: actions/checkout@v4

- uses: nekowinston/setup-deno@v1

- uses: swift-actions/setup-swift@v2
with:
swift-version: "5"

- uses: actions/setup-node@v4
with:
node-version: "lts/*"
Expand All @@ -28,5 +32,13 @@ jobs:
- name: Test
run: deno test --doc

- name: Test Deno dnt
run: deno task build:npm
- name: Build
run: deno task build
env:
COMPILE_APPLE_COLOR_LIST: 1

- name: Upload Built Palette Formats
uses: actions/upload-artifact@v4
with:
name: "Catppuccin Palette Formats"
path: dist/palettes
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.2.0"
".": "1.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.

## [1.3.0](https://github.com/catppuccin/palette/compare/v1.2.0...v1.3.0) (2024-09-08)


### Features

* add support for apple color list / .clr files ([#87](https://github.com/catppuccin/palette/issues/87)) ([88e2795](https://github.com/catppuccin/palette/commit/88e2795c5dc74371141018044706868f2aa04005))


### Documentation

* **CSS.md:** Add `/` to `rgba`/`hsla` usage ([#90](https://github.com/catppuccin/palette/issues/90)) ([628a04a](https://github.com/catppuccin/palette/commit/628a04a0ee16cf9727ee9dc53e3efa425dd57e20))
* **README:** add catppuccin/elixir ([7f17f46](https://github.com/catppuccin/palette/commit/7f17f46c5d3d86f4c8d17fef07d97459744e1157))
* **README:** add catppuccin/gleam ([#84](https://github.com/catppuccin/palette/issues/84)) ([f36dfe2](https://github.com/catppuccin/palette/commit/f36dfe2d92fd51f685117a684250405ca1c2a899))
* **README:** mention JSR ([#88](https://github.com/catppuccin/palette/issues/88)) ([1bfde0a](https://github.com/catppuccin/palette/commit/1bfde0ad8b41fd95d1d22b275ed1dc4ea0def1cb))

## [1.2.0](https://github.com/catppuccin/palette/compare/v1.1.1...v1.2.0) (2024-05-17)


Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

### Node

Get the [NPM package](https://www.npmjs.org/package/@catppuccin/palette):
The library is available on [npm](https://www.npmjs.org/package/@catppuccin/palette):

```console
npm install @catppuccin/palette
Expand Down Expand Up @@ -46,7 +46,7 @@ flavorEntries.map(([_, flavor]) => {

### Deno

The library gets published to [`deno.land/x/catppuccin`](https://deno.land/x/catppuccin).
The library is available through [JSR](https://jsr.io/@catppuccin/palette) and [`deno.land/x/catppuccin`](https://deno.land/x/catppuccin):

```ts
import { flavors, flavorEntries } from "https://deno.land/x/catppuccin/mod.ts";
Expand Down Expand Up @@ -74,7 +74,9 @@ flavorEntries.map(([_, flavor]) => {
- [CSS](docs/css.md)
- [Sass](docs/sass.md)
- Ports of this library
- [Elixir](https://github.com/catppuccin/elixir)
- [Flutter](https://github.com/catppuccin/flutter)
- [Gleam](https://github.com/catppuccin/gleam)
- [Go](https://github.com/catppuccin/go)
- [Java](https://github.com/catppuccin/java)
- [Lua](https://github.com/catppuccin/lua)
Expand All @@ -93,6 +95,7 @@ Please use the respective files in [the latest GitHub Release](https://github.co
| Adobe Suite, Affinity Suite, Sip | `ase/` |
| Aseprite, Gimp, Inkscape, Krita | `gimp/` |
| Procreate | `procreate/` |
| Apple Color List (.clr) | `clr/` |

 

Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@catppuccin/palette",
"version": "1.2.0",
"version": "1.3.0",
"exports": "./mod.ts",
"importMap": "./import_map.json",
"exclude": [
Expand Down
5 changes: 5 additions & 0 deletions deno.lock

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

4 changes: 2 additions & 2 deletions docs/css.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Then use them:
```css
.my-div {
color: var(--ctp-mocha-text);
background: rgba(var(--ctp-macchiato-base-rgb) 0.9);
border-color: hsla(var(--ctp-frappe-red-hsl) 0.75);
background: rgba(var(--ctp-macchiato-base-rgb) / 0.9);
border-color: hsla(var(--ctp-frappe-red-hsl) / 0.75);
}
```

Expand Down
79 changes: 54 additions & 25 deletions scripts/build_palettes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { join } from "std/path/mod.ts";
import { flavors } from "@catppuccin/palette";
import {
generateAse,
generateClrJson,
generateGimp,
generatePng,
generateProcreate,
Expand All @@ -14,34 +15,62 @@ const ROOT = new URL("../dist/palettes", import.meta.url).pathname;
await emptyDir(ROOT);

await Promise.all(
["ase", "gimp", "procreate", "png", "sip"].map((folder) =>
["ase", "gimp", "procreate", "png", "sip", "clr"].map((folder) =>
ensureDir(join(ROOT, folder))
),
);

Promise.all(
Object.entries(flavors).flatMap(async ([name, { colors }]) => {
const fname = name.charAt(0).toUpperCase() + name.slice(1);

await Deno.writeFile(
join(ROOT, `ase/${fname}.ase`),
generateAse(fname, colors),
);
await Deno.writeFile(
join(ROOT, `png/${fname}.png`),
generatePng(fname, colors),
);
await Deno.writeFile(
join(ROOT, `procreate/${fname}.swatches`),
await generateProcreate(fname, colors),
);
await Deno.writeTextFile(
join(ROOT, `gimp/${fname}.gpl`),
generateGimp(fname, colors),
);
await Deno.writeTextFile(
join(ROOT, `sip/${fname}.palette`),
generateSip(fname, colors),
);
}),
Object.entries(flavors).flatMap(
async ([identifier, { name: nameWithAccent, colors }]) => {
const nameWithoutAccent = identifier.charAt(0).toUpperCase() +
identifier.slice(1);

await Deno.writeFile(
join(ROOT, `ase/Catppuccin ${nameWithoutAccent}.ase`),
generateAse(nameWithoutAccent, colors),
);
await Deno.writeFile(
join(ROOT, `png/Catppuccin ${nameWithoutAccent}.png`),
generatePng(nameWithoutAccent, colors),
);
await Deno.writeFile(
join(ROOT, `procreate/Catppuccin ${nameWithoutAccent}.swatches`),
await generateProcreate(nameWithoutAccent, colors),
);
await Deno.writeTextFile(
join(ROOT, `gimp/Catppuccin ${nameWithoutAccent}.gpl`),
generateGimp(nameWithoutAccent, colors),
);
await Deno.writeTextFile(
join(ROOT, `sip/Catppuccin ${nameWithoutAccent}.palette`),
generateSip(nameWithoutAccent, colors),
);

if (Deno.env.get("COMPILE_APPLE_COLOR_LIST") === "1") {
const clrJson = join(ROOT, `clr/${nameWithoutAccent}.json`);
await Deno.writeTextFile(
clrJson,
generateClrJson(nameWithoutAccent, colors),
);

const cmd = new Deno.Command("swift", {
args: [
join(import.meta.dirname!, "./builders/palettes/json-to-clr.swift"),
clrJson,
join(ROOT, `clr/Catppuccin ${nameWithAccent}.clr`),
],
});
const { code, stderr, stdout } = await cmd.output();
const td = new TextDecoder();
if (code === 0) {
console.log(td.decode(stdout).trim());
} else {
throw new Error(td.decode(stderr));
}

await Deno.remove(clrJson);
}
},
),
).then(() => Deno.exit(0));
1 change: 1 addition & 0 deletions scripts/builders/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { generateGimp } from "./palettes/gimp.ts";
export { generatePng } from "./palettes/png.ts";
export { generateProcreate } from "./palettes/procreate.ts";
export { generateSip } from "./palettes/sip.ts";
export { generateClrJson } from "./palettes/clr.ts";
15 changes: 15 additions & 0 deletions scripts/builders/palettes/clr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { CatppuccinColors } from "@catppuccin/palette";

export const generateClrJson = (
_name: string,
palette: CatppuccinColors,
): string => {
const data: Record<string, { hex: string; order: number }> = Object
.fromEntries(
Object.entries(palette).map(([_, { name, hex, order }]) => {
return [name, { hex, order }];
}),
);

return JSON.stringify(data);
};
57 changes: 57 additions & 0 deletions scripts/builders/palettes/json-to-clr.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import AppKit
import Foundation

struct ColorProperties: Decodable {
let hex: String
let order: Int
}

typealias ColorList = [String: ColorProperties]

func hexToRGBA(_ color: String) -> (r: CGFloat, g: CGFloat, b: CGFloat) {
var hexColor = String(color.dropFirst())

let r = CGFloat(Int(hexColor.prefix(2), radix: 16) ?? 0) / 255
let g = CGFloat(Int(hexColor.dropFirst(2).prefix(2), radix: 16) ?? 0) / 255
let b = CGFloat(Int(hexColor.dropFirst(4).prefix(2), radix: 16) ?? 0) / 255
return (r, g, b)
}

func convertJSONToCLR(inputFilePath: String, outputFilePath: String) {
let url = URL(fileURLWithPath: inputFilePath)
guard let data = try? Data(contentsOf: url),
let colorList = try? JSONDecoder().decode(ColorList.self, from: data)
else {
print("Failed to read or parse JSON file.")
return
}

let sortedColors = colorList.sorted { (lhs, rhs) -> Bool in
return lhs.value.order < rhs.value.order
}

let paletteName = url.deletingPathExtension().lastPathComponent
let nsColorList = NSColorList(name: paletteName)

for (name, properties) in sortedColors {
let hex = properties.hex
let color = hexToRGBA(hex)
nsColorList.setColor(
NSColor(red: color.r, green: color.g, blue: color.b, alpha: 1), forKey: name)
}

let clrFilePath = URL(fileURLWithPath: outputFilePath)
do {
try nsColorList.write(to: clrFilePath)
print("Successfully saved palette to \(outputFilePath).")
} catch {
print("Failed to save color palette: \(error)")
}
}

if CommandLine.argc != 3 {
print("\(CommandLine.arguments[0]): Not enough arguments provided (expected input and output filenames)")
exit(1)
}

convertJSONToCLR(inputFilePath: CommandLine.arguments[1], outputFilePath: CommandLine.arguments[2])
8 changes: 5 additions & 3 deletions types/procreate-swatches.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { Buffer } from "node:buffer";

type ColorSpace = "rgb" | "hsl" | "hsv" | "hwb" | "xyz" | "lab" | "lch";
type Colors = [number[], ColorSpace][];

export function readSwatchesFile(
data: string | Uint8Array | ArrayBuffer | Blob,
colorSpace?: ColorSpace
colorSpace?: ColorSpace,
): Promise<{
name: string;
colors: Colors;
Expand All @@ -21,11 +23,11 @@ type SwatchReturnType = {
};

export function createSwatchesFile<
F extends keyof SwatchReturnType | undefined = undefined
F extends keyof SwatchReturnType | undefined = undefined,
>(
name: string,
colors: Colors,
format?: F
format?: F,
): Promise<F extends keyof SwatchReturnType ? SwatchReturnType[F] : Uint8Array>;

interface ProcreateSwatchesError extends Error {
Expand Down

0 comments on commit e89f382

Please sign in to comment.