glre 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/package.json +5 -3
  2. package/react.ts +40 -0
  3. package/solid.ts +25 -0
  4. package/README.md +0 -245
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "glre",
3
3
  "author": "tseijp",
4
4
  "license": "MIT",
5
- "version": "0.11.0",
5
+ "version": "0.12.0",
6
6
  "module": "index.js",
7
7
  "types": "index.ts",
8
8
  "main": "index.cjs.js",
@@ -35,7 +35,9 @@
35
35
  "index.ts",
36
36
  "events.ts",
37
37
  "helpers.ts",
38
- "utils.ts",
39
- "types.ts"
38
+ "react.ts",
39
+ "solid.ts",
40
+ "types.ts",
41
+ "utils.ts"
40
42
  ]
41
43
  }
package/react.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { gl } from './index'
2
+ import type { GL } from './types'
3
+ import { useRef, useMemo, useEffect, useCallback } from 'react'
4
+
5
+ export function useGL(config?: Partial<GL>, target?: GL) {
6
+ const self = useMemo(() => {
7
+ if (target) return target
8
+ return (gl.default = gl(target))
9
+ }, [target])
10
+ useEffect(() => void self.setConfig(config), [self, config])
11
+ useEffect(() => void self.event('mount'), [self])
12
+ useEffect(() => () => self.event('clean'), [self])
13
+ return self
14
+ }
15
+
16
+ export function useTexture(props, self?: GL) {
17
+ if (!self) self = gl.default
18
+ useEffect(() => self.setTexture(props), [props, self])
19
+ }
20
+
21
+ export function useAttribute(props, self?: GL) {
22
+ if (!self) self = gl.default
23
+ return self.setAttribute(props)
24
+ }
25
+
26
+ export function useUniform(props, self?: GL) {
27
+ if (!self) self = gl.default
28
+ return self.setUniform(props)
29
+ }
30
+
31
+ export function useFrame(fun, self?: GL) {
32
+ if (!self) self = gl.default
33
+ const ref = useMutable(fun)
34
+ useEffect(() => void self.setFrame(ref), [ref, self])
35
+ }
36
+
37
+ export function useMutable(fun) {
38
+ const ref = useRef(fun)
39
+ return useCallback(() => ref.current(), [])
40
+ }
package/solid.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { gl } from './index'
2
+ import type { GL } from './types'
3
+ import { onMount, onCleanup } from 'solid-js'
4
+
5
+ export function createGL(config: Partial<GL>, _gl?: GL) {
6
+ const self = _gl || (gl.default = gl(config))
7
+ onMount(() => self.event('mount'))
8
+ onCleanup(() => self.event('clean'))
9
+ return self
10
+ }
11
+
12
+ export function onFrame(fun: any, self: GL) {
13
+ if (!self) self = gl.default
14
+ onMount(() => self.setFrame(fun))
15
+ }
16
+
17
+ export function setTexture(props, self?: GL) {
18
+ if (!self) self = gl.default
19
+ return self.setTexture(props)
20
+ }
21
+
22
+ export function setAttribute(props, self?: GL) {
23
+ if (!self) self = gl.default
24
+ return self.setAttribute(props)
25
+ }
package/README.md DELETED
@@ -1,245 +0,0 @@
1
- # 🌇 glre
2
-
3
- <strong>
4
- <samp>
5
-
6
- <p align="center">
7
-
8
- [![ npm version ](
9
- https://img.shields.io/npm/v/glre?style=flat&colorA=000&colorB=000)](
10
- https://www.npmjs.com/package/glre)
11
- [![ downloads ](
12
- https://img.shields.io/npm/dm/glre.svg?style=flat&colorA=000&colorB=000)](
13
- https://www.npmtrends.com/glre)
14
- [![ license MIT ](
15
- https://img.shields.io/npm/l/glre?style=flat&colorA=000&colorB=000)](
16
- https://github.com/tseijp/glre)
17
- [![ docs available ](
18
- https://img.shields.io/badge/docs-available-000.svg?style=flat&colorA=000)](
19
- https://glre.tsei.jp/>)
20
- [![ bundle size ](
21
- https://img.shields.io/bundlephobia/minzip/glre?style=flat&colorA=000&colorB=000)](
22
- https://bundlephobia.com/package/glre@latest)
23
-
24
- glre is a simple glsl Reactive Engine on the web and native via TypeScript, React, Solid and more.
25
-
26
- </p>
27
- <p align="center" valign="top">
28
- <a href="https://codesandbox.io/s/glre-test1-skyl9p">
29
- <img alt="test1" width="256" src="https://user-images.githubusercontent.com/40712342/212297558-15a1e721-55d6-4b6f-aab4-9f5d7cede2cb.gif"></img>
30
- </a>
31
- <a href="https://codesandbox.io/s/glre-test2-c1syho">
32
- <img alt="test2" width="256" src="https://user-images.githubusercontent.com/40712342/212297576-e12cef1b-b0e0-40cb-ac0f-7fb387ae6da8.gif"></img>
33
- </a>
34
- <a href="https://codesandbox.io/s/glre-test3-ntlk3l">
35
- <img alt="test3" width="256" src="https://user-images.githubusercontent.com/40712342/212297587-0227d536-5cef-447a-be3e-4c93dad002a2.gif"></img>
36
- </a>
37
- <a href="https://codesandbox.io/s/glre-raymarch-test-q8pyxv" target="_blank" rel="noopener">
38
- <img alt="raymarch1" width="256" src="https://user-images.githubusercontent.com/40712342/215024903-90f25934-1018-4f2a-81e6-f16e5c64c378.gif">
39
- </a>
40
- <a href="https://codesandbox.io/s/glre-raymarch-test2-fcds29" target="_blank" rel="noopener">
41
- <img alt="raymarch2" width="256" src="https://user-images.githubusercontent.com/40712342/215024942-27766b2b-7b85-4725-bb3d-865bf137ea29.gif">
42
- </a>
43
- <a href="https://codesandbox.io/s/glre-raymarch-test3-nx6ggi" target="_blank" rel="noopener">
44
- <img alt="raymarch3" width="256" src="https://user-images.githubusercontent.com/40712342/215025052-c2fa46e5-5e0e-4de8-baee-869ca6135a61.gif">
45
- </a>
46
- <a href="https://codesandbox.io/s/glre-raymarch-test4-cy1wpp" target="_blank" rel="noopener">
47
- <img alt="raymarch4" width="256" src="https://user-images.githubusercontent.com/40712342/215025289-132b4213-aabc-48f2-bbe3-05764a8dae42.gif">
48
- </a>
49
- <a href="https://codesandbox.io/s/glre-raymarch-test5-19v0g7" target="_blank" rel="noopener">
50
- <img alt="raymarch5" width="256" src="https://user-images.githubusercontent.com/40712342/215025456-8ab75328-ca7a-41f6-b5fe-98dd58410b38.gif">
51
- </a>
52
- <a href="https://codesandbox.io/s/glre-raymarch-test6-jew0it" target="_blank" rel="noopener">
53
- <img alt="raymarch6" width="256" src="https://user-images.githubusercontent.com/40712342/215025517-343fdfbf-af54-497c-a759-267acc450366.gif">
54
- </a>
55
- </p>
56
-
57
- ## Installation
58
-
59
- ```ruby
60
- npm install glre
61
- ```
62
-
63
- <table>
64
- <td width="1000px" valign="top">
65
-
66
- ## Documentation
67
-
68
- ###### [Docs][docs] : glre Introduction
69
-
70
- ###### [API][api] : glre API and feature
71
-
72
- ###### [Guide][guide] : Creating a scene
73
-
74
- [docs]: https://glre.tsei.jp/docs
75
- [api]: https://glre.tsei.jp/api
76
- [guide]: https://glre.tsei.jp/guide
77
-
78
- </td>
79
- <td width="1000px" valign="top">
80
-
81
- ## Ecosystem
82
-
83
- ###### ⛪️ [reev][reev]: reactive event state manager
84
-
85
- ###### 🌃 [refr][refr]: request animation frame
86
-
87
- [reev]: https://github.com/tseijp/reev
88
- [refr]: https://github.com/tseijp/refr
89
-
90
- </td>
91
- <td width="1000px" valign="top">
92
-
93
- ## Staying informed
94
-
95
- ###### [github discussions][github] welcome✨
96
-
97
- ###### [@tseijp][twitter] twitter
98
-
99
- ###### [tsei.jp][articles] articles
100
-
101
- [github]: https://github.com/tseijp/glre/discussions
102
- [twitter]: https://twitter.com/tseijp
103
- [articles]: https://tsei.jp/articles
104
-
105
- </td>
106
- </table>
107
-
108
- ## PRs
109
-
110
- ###### welcome✨
111
-
112
- ## What does it look like?
113
-
114
- <table>
115
- <tr>
116
- <td width="7500px" align="center" valign="center">
117
- glre simplifies glsl programming via TypeScript, React, Solid and more (<a href="https://codesandbox.io/s/glre-basic-demo-ppzo3d">live demo</a>).
118
- </td>
119
- <td width="2500px" valign="top">
120
- <a href="https://codesandbox.io/s/glre-basic-demo-ppzo3d">
121
- <img alt="4" src="https://i.imgur.com/Lb3h9fs.jpg"></img>
122
- </a>
123
- </td>
124
- </tr>
125
- </table>
126
-
127
- ```ts
128
- import { createRoot } from "react-dom/client";
129
- import { useGL, useFrame } from "@glre/react";
130
-
131
- const App = (props) => {
132
- const gl = useGL()`
133
- precision highp float;
134
- uniform vec2 iResolution;
135
- void main() {
136
- gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
137
- }
138
- `;
139
- useFrame(() => {
140
- gl.clear();
141
- gl.viewport();
142
- gl.drawArrays();
143
- return true;
144
- });
145
- return <canvas id={gl.id} {...props} />;
146
- };
147
-
148
- const style = { top: 0, left: 0, position: "fixed" };
149
- createRoot(document.getElementById("root")).render(<App style={style} />);
150
- ```
151
-
152
- <details>
153
- <summary>
154
-
155
- solid js supported ([codesandbox demo](https://codesandbox.io/s/glre-basic-demo2-m1h6cr))
156
-
157
- </summary>
158
-
159
- ```html
160
- <html>
161
- <body>
162
- <script type="module">
163
- import html from "https://cdn.skypack.dev/solid-js/html";
164
- import { gl } from "https://cdn.skypack.dev/glre@latest";
165
- import { render } from "https://cdn.skypack.dev/solid-js/web";
166
- import { onCleanup, onMount } from "https://cdn.skypack.dev/solid-js";
167
-
168
- function createGL(config, _gl) {
169
- const self = _gl || (gl.default = gl(config));
170
- onMount(() => self.mount());
171
- onCleanup(() => self.clean());
172
- return self;
173
- }
174
-
175
- function onFrame(fun, self) {
176
- if (!self) self = gl.default;
177
- onMount(() => self.setFrame(fun));
178
- }
179
-
180
- const App = () => {
181
- const gl = createGL()`
182
- precision highp float;
183
- uniform vec2 iResolution;
184
- void main() {
185
- gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
186
- }
187
- `;
188
- onFrame(() => {
189
- gl.clear();
190
- gl.viewport();
191
- gl.drawArrays();
192
- return true;
193
- });
194
- return html`<canvas id=${gl.id} />`;
195
- };
196
-
197
- render(App, document.body);
198
- </script>
199
- </body>
200
- </html>
201
- ```
202
-
203
- </details>
204
- <details>
205
- <summary>
206
-
207
- pure js supported ([codesandbox demo](https://codesandbox.io/s/glre-basic-demo3-3bhr3y))
208
-
209
- </summary>
210
-
211
- ```html
212
- <!DOCTYPE html>
213
- <html>
214
- <body>
215
- <script type="module">
216
- import createGL from "https://cdn.skypack.dev/glre@latest"
217
- const gl = createGL`
218
- precision highp float;
219
- uniform vec2 iResolution;
220
- void main() {
221
- gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
222
- }
223
- `;
224
-
225
- gl.setFrame(() => {
226
- gl.clear();
227
- gl.viewport();
228
- gl.drawArrays();
229
- return true;
230
- });
231
-
232
- const style = { top: 0, left: 0, position: "fixed" };
233
- const canvas = document.createElement("canvas");
234
- Object.assign(canvas, { id: gl.id });
235
- Object.assign(canvas.style, style);
236
- document.body.append(canvas);
237
- window.addEventListener("DOMContentLoaded", gl.mount);
238
- </script>
239
- </body>
240
- </html>
241
- ```
242
-
243
- </details>
244
- </samp>
245
- </strong>