-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add rdom-reactive-svg example
- Loading branch information
1 parent
46ddf39
commit 8886cac
Showing
12 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# rdom-reactive-svg | ||
|
||
![screenshot](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-reactive-svg.jpg) | ||
|
||
[Live demo](http://demo.thi.ng/umbrella/rdom-reactive-svg/) | ||
|
||
## Developing & building | ||
|
||
Please refer to the instructions on the wiki: | ||
|
||
- [Development](https://github.com/thi-ng/umbrella/wiki/Development-mode-for-examples-using-thi.ng-meta%E2%80%90css) | ||
- [Production build](https://github.com/thi-ng/umbrella/wiki/Example-build-instructions) | ||
|
||
## Authors | ||
|
||
- Karsten Schmidt | ||
|
||
## License | ||
|
||
© 2024 Karsten Schmidt // Apache Software License 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"tables": {}, | ||
"vars": {}, | ||
"decls": [], | ||
"specs": [], | ||
"templates": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// list of CSS class names to force-include in generated CSS | ||
// (one class per line, basic wildcards supported) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// thi.ng/meta-css stylesheet | ||
// see package readme for more details/usage | ||
// use `yarn css:build` or `yarn css:watch` to transpile to CSS | ||
// also see component-specific *.mcss files in /src folder | ||
|
||
// (optional) variable declarations | ||
:root { | ||
// color1=#fff | ||
} | ||
|
||
body { system-sans-serif ma3 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<link | ||
rel="icon" | ||
href='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">⛱️</text></svg>' | ||
/> | ||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>rdom-reactive-svg · @thi.ng/umbrella</title> | ||
<link href="/css/style.css" rel="stylesheet"> | ||
<script>window.goatcounter = { path: (p) => location.host + p };</script> | ||
<script data-goatcounter="https://thing.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<div><a class="link" href="https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-reactive-svg">Source code</a></div> | ||
<script type="module" src="/src/index.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@example/rdom-reactive-svg", | ||
"version": "0.0.1", | ||
"private": true, | ||
"description": "Animated SVG elements with reactive attributes", | ||
"repository": "https://github.com/thi-ng/umbrella", | ||
"author": "Karsten Schmidt <k+npm@thi.ng>", | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"start": "yarn css:build && yarn start:only", | ||
"start:only": "vite --host --open", | ||
"css:watch": "../../node_modules/.bin/metacss develop --bundle --watch --pretty --out-specs css/framework.json --out-css css/style.css --force @css/includes.txt ../../packages/meta-css/specs/*.mcss.json css/*.mcss.json css/*.mcss", | ||
"css:build": "../../node_modules/.bin/metacss develop --bundle --out-specs css/framework.json --out-css css/style.css --force @css/includes.txt ../../packages/meta-css/specs/*.mcss.json css/*.mcss.json css/*.mcss", | ||
"build": "yarn css:build && tsc && vite build --base='./'", | ||
"preview": "vite preview --host --open" | ||
}, | ||
"devDependencies": { | ||
"@thi.ng/meta-css": "workspace:^", | ||
"typescript": "^5.4.3", | ||
"vite": "^5.2.6" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/color": "workspace:^", | ||
"@thi.ng/hiccup-svg": "workspace:^", | ||
"@thi.ng/random": "workspace:^", | ||
"@thi.ng/rdom": "workspace:^", | ||
"@thi.ng/rstream": "workspace:^", | ||
"@thi.ng/transducers": "workspace:^" | ||
}, | ||
"browser": { | ||
"process": false | ||
}, | ||
"thi.ng": { | ||
"readme": false, | ||
"screenshot": "examples/rdom-reactive-svg.jpg" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { css, lch } from "@thi.ng/color"; | ||
import { group, svg } from "@thi.ng/hiccup-svg"; | ||
import { SYSTEM } from "@thi.ng/random"; | ||
import { $compile } from "@thi.ng/rdom"; | ||
import { fromRAF } from "@thi.ng/rstream"; | ||
import { repeatedly } from "@thi.ng/transducers"; | ||
|
||
// time in seconds | ||
const time = fromRAF({ timestamp: true }).map((t) => t * 0.001); | ||
|
||
// create circle element w/ randomized reactive attribs | ||
const circle = () => { | ||
const fX = SYSTEM.minmax(0.5, 3); | ||
const fY = SYSTEM.minmax(0.5, 3); | ||
const fR = SYSTEM.minmax(0.5, 3); | ||
const fC = SYSTEM.minmax(0.1, 1); | ||
// use plain hiccup to define the SVG circle element | ||
return [ | ||
"circle", | ||
{ | ||
cx: time.map((t) => Math.cos(t * fX) * 200), | ||
cy: time.map((t) => Math.sin(t * fY) * 200), | ||
r: time.map((t) => Math.sin(t * fR) * 45 + 50), | ||
fill: time.map((t) => css(lch(0.8, 1, t * fC))), | ||
}, | ||
]; | ||
}; | ||
|
||
$compile( | ||
// for the non-reactive outer elements, we can use hiccup-svg | ||
// for convenience & syntax sugar... | ||
svg( | ||
{ width: 600, height: 600, style: { background: "#ccc" } }, | ||
group( | ||
{ translate: [300, 300] }, | ||
// create N random circles | ||
...repeatedly(circle, 10) | ||
) | ||
) | ||
).mount(document.body); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["src/**/*"], | ||
"compilerOptions": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
build: { target: "esnext" }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters