One self-contained stylesheet (.waves) with the wave PNG inlined and the gradient colours, angle and tile size as custom properties. Tags publish @mtps/waves to the Gitea npm registry. The README plans the move from the PNG to an SVG tile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f646b31c92
8 files changed
+180
No files matched your search
@@ -0,0 +1,36 @@
|
||||
name: Publish
|
||||
|
||||
# v1.2.3 -> publish @mtps/waves@1.2.3 to the Gitea npm registry
|
||||
on:
|
||||
push:
|
||||
tags: ['v*']
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: rocky-10
|
||||
steps:
|
||||
- name: Check out source
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24
|
||||
registry-url: ${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/npm/
|
||||
scope: '@mtps'
|
||||
|
||||
- name: Check tag matches package.json
|
||||
run: |
|
||||
VERSION="$(node -p 'require("./package.json").version')"
|
||||
if [ "v$VERSION" != "$GITHUB_REF_NAME" ]; then
|
||||
echo "tag $GITHUB_REF_NAME doesn't match package.json version $VERSION" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# prepack builds dist/waves.css
|
||||
- name: Publish
|
||||
env:
|
||||
# a token with package write access for mtps; the job token is
|
||||
# only a fallback in case Gitea grants it that
|
||||
NODE_AUTH_TOKEN: ${{ secrets.REGISTRY_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
run: npm publish
|
||||
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
dist/
|
||||
*.tgz
|
||||
@@ -0,0 +1,62 @@
|
||||
# @mtps/waves
|
||||
|
||||
The wave background from [mtps/auth](https://git.app.ygg/mtps/auth): a tiling wave texture under a colour gradient, blended with `difference`. It ships as one self-contained CSS file with the texture inlined, so it works the same in Astro, Vite or a plain `<link>`, with no asset paths to resolve.
|
||||
|
||||
Open `demo.html` after `pnpm build` to see it.
|
||||
|
||||
## Install
|
||||
|
||||
The package is on the Gitea npm registry. Tell npm/pnpm where `@mtps` lives with an `.npmrc` in the consuming project:
|
||||
|
||||
```ini
|
||||
@mtps:registry=https://git.app.ygg/api/packages/mtps/npm/
|
||||
```
|
||||
|
||||
```sh
|
||||
pnpm add @mtps/waves
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
import '@mtps/waves'; // or '@mtps/waves/waves.css'
|
||||
```
|
||||
|
||||
```html
|
||||
<body class="waves">
|
||||
```
|
||||
|
||||
The class works on any element, not just `body`. Set these variables on the element or any ancestor to change the look:
|
||||
|
||||
| variable | default | |
|
||||
|---|---|---|
|
||||
| `--waves-from` | `#f7b440` | gradient start |
|
||||
| `--waves-to` | `hsl(7 82% 63%)` | gradient end |
|
||||
| `--waves-angle` | `-45deg` | gradient direction |
|
||||
| `--waves-tile` | `400px` | texture tile size |
|
||||
|
||||
```css
|
||||
.night { --waves-from: #3a6073; --waves-to: #16222a; --waves-angle: 160deg; }
|
||||
```
|
||||
|
||||
## Develop and release
|
||||
|
||||
- `src/waves.css` is the source. It refers to `./waves.png`.
|
||||
- `pnpm build` writes `dist/waves.css` with the PNG inlined as a data URI. It also runs on `pnpm pack`/`publish` through `prepack`.
|
||||
- Bump `version` in `package.json`, commit, then `git tag vX.Y.Z && git push --follow-tags`. `.gitea/workflows/publish.yml` publishes the version to the registry. The tag has to match `package.json`.
|
||||
|
||||
## TODO: switch the texture to SVG
|
||||
|
||||
The texture is still the 400×400 PNG from mtps/auth (`src/waves.png`, ~10 KiB, ~14 KiB inlined as base64). An SVG version would be better:
|
||||
|
||||
- **Size:** a wave tile is a couple of `<path>`s, a few hundred bytes instead of ~14 KiB of base64.
|
||||
- **Sharpness:** it stays crisp on high-DPI screens and at any `--waves-tile`; the PNG blurs when scaled up.
|
||||
- **Styling:** line colour, stroke width and opacity could become variables too, instead of being baked into the pixels.
|
||||
- **Licensing:** the PNG's origin isn't recorded. Its old name, `papyrus-dark.png`, suggests it came from a pattern collection, possibly one that requires attribution. Redrawing it removes that question.
|
||||
|
||||
How to switch:
|
||||
|
||||
1. Draw one repeating tile (e.g. two offset sine-like `<path>`s with `stroke` and `fill="none"`) whose edges line up, and save it as `src/waves.svg`.
|
||||
2. Reference it as `url('./waves.svg')` in `src/waves.css`.
|
||||
3. Teach `scripts/build.mjs` to inline `.svg` as `data:image/svg+xml,…` (URL-encoded rather than base64, which is smaller).
|
||||
4. Compare it with `demo.html` against the current version and release it as a minor version. The look should stay the same, so it isn't a breaking change.
|
||||
@@ -0,0 +1,19 @@
|
||||
<!doctype html>
|
||||
<!-- open after `pnpm build` -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>waves</title>
|
||||
<link rel="stylesheet" href="dist/waves.css" />
|
||||
<style>
|
||||
body { margin: 0; min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
|
||||
.waves { display: grid; place-items: center; font: 600 20px system-ui; color: #fff; }
|
||||
.alt { --waves-from: #3a6073; --waves-to: #16222a; --waves-angle: 160deg; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="waves">default</div>
|
||||
<div class="waves alt">custom colours</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@mtps/waves",
|
||||
"version": "0.1.0",
|
||||
"description": "Wave texture under a colour gradient, as one self-contained CSS file",
|
||||
"license": "UNLICENSED",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist/waves.css"
|
||||
],
|
||||
"style": "./dist/waves.css",
|
||||
"exports": {
|
||||
".": "./dist/waves.css",
|
||||
"./waves.css": "./dist/waves.css"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.app.ygg/mtps/waves"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://git.app.ygg/api/packages/mtps/npm/"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node scripts/build.mjs",
|
||||
"prepack": "node scripts/build.mjs"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// src/waves.css -> dist/waves.css with the texture inlined as a data URI,
|
||||
// so consumers get one file and no asset paths for their bundler to resolve.
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
|
||||
const src = new URL('../src/', import.meta.url);
|
||||
const dist = new URL('../dist/', import.meta.url);
|
||||
|
||||
const css = readFileSync(new URL('waves.css', src), 'utf8').replace(
|
||||
/url\('\.\/([^']+)\.png'\)/g,
|
||||
(_, name) =>
|
||||
`url('data:image/png;base64,${readFileSync(new URL(`${name}.png`, src)).toString('base64')}')`,
|
||||
);
|
||||
if (css.includes("url('./")) throw new Error('src/waves.css references a file that was not inlined');
|
||||
|
||||
mkdirSync(dist, { recursive: true });
|
||||
writeFileSync(new URL('waves.css', dist), css);
|
||||
console.log(`dist/waves.css: ${(css.length / 1024).toFixed(1)} KiB`);
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* @mtps/waves: a tiling wave texture under a colour gradient, blended with
|
||||
* `difference`. Originally the page background of mtps/auth.
|
||||
*
|
||||
* Put class="waves" on any element (body included) and override the
|
||||
* variables on it or any ancestor.
|
||||
*/
|
||||
.waves {
|
||||
background:
|
||||
linear-gradient(
|
||||
var(--waves-angle, -45deg),
|
||||
var(--waves-from, #f7b440) 0%,
|
||||
var(--waves-to, hsl(7 82% 63%)) 100%
|
||||
),
|
||||
url('./waves.png') 0 0 / var(--waves-tile, 400px) repeat;
|
||||
background-blend-mode: difference;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Reference in new issue
Block a user