@bigmistqke/view.gl 0.1.1 → 0.1.3

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 (52) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.github/ISSUE_TEMPLATE/bug-report.yml +31 -0
  3. package/.github/ISSUE_TEMPLATE/feature-request.yml +27 -0
  4. package/.github/workflows/codeql.yml +46 -0
  5. package/.github/workflows/deploy-page.yml +38 -0
  6. package/.github/workflows/format.yml +40 -0
  7. package/README.md +286 -84
  8. package/dev/404.html +19 -0
  9. package/dev/dist/404.html +19 -0
  10. package/dev/dist/assets/bezier-DuLTb2d1.js +294 -0
  11. package/dev/dist/assets/game_of_life-D7qHdFcv.js +202 -0
  12. package/dev/dist/assets/grid-Ie22U_9K.js +173 -0
  13. package/dev/dist/assets/index-0qrXMlfv.js +109 -0
  14. package/dev/dist/assets/index-C2N3u8wj.css +12 -0
  15. package/dev/dist/assets/main-BZ1N6pp6.js +32 -0
  16. package/dev/dist/assets/overview-DAxtMIw5.js +78 -0
  17. package/dev/dist/assets/pix_sim-DIhzM_vu.js +501 -0
  18. package/dev/dist/assets/symbol-BouRL-Ni.js +65 -0
  19. package/dev/dist/assets/tag-C_bg62fD.js +516 -0
  20. package/dev/dist/assets/tetris-IMnkSi9p.js +344 -0
  21. package/dev/dist/assets/utils-CvCgsM08.js +50 -0
  22. package/dev/dist/index.html +51 -0
  23. package/dev/index.html +39 -10
  24. package/dev/{bezier.ts → src/examples/bezier.ts} +1 -1
  25. package/dev/{grid.ts → src/examples/grid.ts} +1 -1
  26. package/dev/{pix_sim.ts → src/examples/pix_sim.ts} +112 -97
  27. package/dev/src/examples/symbol.ts +79 -0
  28. package/dev/{tetris.ts → src/examples/tetris.ts} +1 -0
  29. package/dev/src/index.css +12 -0
  30. package/dev/src/index.ts +69 -0
  31. package/dev/{utils.ts → src/utils.ts} +8 -2
  32. package/dev/vite.config.ts +9 -1
  33. package/dist/index.d.mts +3 -2
  34. package/dist/index.mjs +81 -27
  35. package/dist/index.mjs.map +1 -1
  36. package/dist/tag.d.mts +9 -9
  37. package/dist/tag.mjs +46 -17
  38. package/dist/tag.mjs.map +1 -1
  39. package/dist/{types-DxpS9Bae.d.mts → types-DoFAJoh-.d.mts} +18 -18
  40. package/package.json +20 -7
  41. package/src/index.ts +39 -17
  42. package/src/tag.ts +47 -39
  43. package/src/types.ts +24 -24
  44. package/src/{utils.ts → utils/index.ts} +39 -14
  45. package/src/utils/object.ts +27 -0
  46. package/test/index.test.ts +1017 -0
  47. package/test/mocks/webgl.ts +248 -0
  48. package/test/setup.ts +13 -0
  49. package/test/tag.test.ts +790 -0
  50. package/vitest.config.ts +15 -0
  51. /package/dev/{game_of_life.ts → src/examples/game_of_life.ts} +0 -0
  52. /package/dev/{index.ts → src/examples/overview.ts} +0 -0
@@ -0,0 +1,109 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/bezier-DuLTb2d1.js","assets/tag-C_bg62fD.js","assets/utils-CvCgsM08.js","assets/game_of_life-D7qHdFcv.js","assets/grid-Ie22U_9K.js","assets/overview-DAxtMIw5.js","assets/pix_sim-DIhzM_vu.js","assets/symbol-BouRL-Ni.js","assets/tetris-IMnkSi9p.js"])))=>i.map(i=>d[i]);
2
+ import { c as createElement } from './utils-CvCgsM08.js';
3
+
4
+ const scriptRel = 'modulepreload';const assetsURL = function(dep) { return "/"+dep };const seen = {};const __vitePreload = function preload(baseModule, deps, importerUrl) {
5
+ let promise = Promise.resolve();
6
+ if (true && deps && deps.length > 0) {
7
+ document.getElementsByTagName("link");
8
+ const cspNonceMeta = document.querySelector("meta[property=csp-nonce]");
9
+ const cspNonce = cspNonceMeta?.nonce || cspNonceMeta?.getAttribute("nonce");
10
+ function allSettled(promises$2) {
11
+ return Promise.all(promises$2.map((p$1) => Promise.resolve(p$1).then((value$1) => ({
12
+ status: "fulfilled",
13
+ value: value$1
14
+ }), (reason) => ({
15
+ status: "rejected",
16
+ reason
17
+ }))));
18
+ }
19
+ promise = allSettled(deps.map((dep) => {
20
+ dep = assetsURL(dep);
21
+ if (dep in seen) return;
22
+ seen[dep] = true;
23
+ const isCss = dep.endsWith(".css");
24
+ const cssSelector = isCss ? "[rel=\"stylesheet\"]" : "";
25
+ if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) return;
26
+ const link = document.createElement("link");
27
+ link.rel = isCss ? "stylesheet" : scriptRel;
28
+ if (!isCss) link.as = "script";
29
+ link.crossOrigin = "";
30
+ link.href = dep;
31
+ if (cspNonce) link.setAttribute("nonce", cspNonce);
32
+ document.head.appendChild(link);
33
+ if (isCss) return new Promise((res, rej) => {
34
+ link.addEventListener("load", res);
35
+ link.addEventListener("error", () => rej(/* @__PURE__ */ new Error(`Unable to preload CSS for ${dep}`)));
36
+ });
37
+ }));
38
+ }
39
+ function handlePreloadError(err$2) {
40
+ const e$1 = new Event("vite:preloadError", { cancelable: true });
41
+ e$1.payload = err$2;
42
+ window.dispatchEvent(e$1);
43
+ if (!e$1.defaultPrevented) throw err$2;
44
+ }
45
+ return promise.then((res) => {
46
+ for (const item of res || []) {
47
+ if (item.status !== "rejected") continue;
48
+ handlePreloadError(item.reason);
49
+ }
50
+ return baseModule().catch(handlePreloadError);
51
+ });
52
+ };
53
+
54
+ const css = "/assets/index-C2N3u8wj.css";
55
+
56
+ const iframe = document.querySelector("iframe");
57
+ const nav = document.querySelector("nav");
58
+ createElement("h3", { innerText: "Examples", parentElement: nav });
59
+ const urls = Object.fromEntries(
60
+ Object.entries(/* #__PURE__ */ Object.assign({"./examples/bezier.ts": () => __vitePreload(() => import('./bezier-DuLTb2d1.js'),true ?__vite__mapDeps([0,1,2]):void 0),"./examples/game_of_life.ts": () => __vitePreload(() => import('./game_of_life-D7qHdFcv.js'),true ?__vite__mapDeps([3,1]):void 0),"./examples/grid.ts": () => __vitePreload(() => import('./grid-Ie22U_9K.js'),true ?__vite__mapDeps([4,1,2]):void 0),"./examples/overview.ts": () => __vitePreload(() => import('./overview-DAxtMIw5.js'),true ?__vite__mapDeps([5,1]):void 0),"./examples/pix_sim.ts": () => __vitePreload(() => import('./pix_sim-DIhzM_vu.js'),true ?__vite__mapDeps([6,1,2]):void 0),"./examples/symbol.ts": () => __vitePreload(() => import('./symbol-BouRL-Ni.js'),true ?__vite__mapDeps([7,1,2]):void 0),"./examples/tetris.ts": () => __vitePreload(() => import('./tetris-IMnkSi9p.js'),true ?__vite__mapDeps([8,1]):void 0)})).map(([key, entry]) => {
61
+ const name = key.split("/").pop().replace(".ts", "");
62
+ const chunk = entry.toString().match(/import\(['"]([^'"]+)['"]/)[1];
63
+ return [name, chunk];
64
+ })
65
+ );
66
+ Object.entries(urls).forEach(([name, localUrl]) => {
67
+ createElement("button", {
68
+ onclick(event) {
69
+ event.preventDefault();
70
+ load(name, localUrl);
71
+ },
72
+ innerHTML: name,
73
+ parentElement: nav,
74
+ "data-route": name
75
+ });
76
+ });
77
+ function load(name, url) {
78
+ window.location.hash = name;
79
+ URL.revokeObjectURL(iframe.src);
80
+ nav.querySelectorAll("button").forEach((button) => {
81
+ if (button.getAttribute("data-route") === name) {
82
+ button.classList.add("active");
83
+ } else {
84
+ button.classList.remove("active");
85
+ }
86
+ });
87
+ iframe.src = URL.createObjectURL(
88
+ new Blob(
89
+ [
90
+ `<head>
91
+ <link rel="stylesheet" href="${new URL(css, import.meta.url).href}"></link>
92
+ <script type="module" src="${new URL(url, import.meta.url).href}"><\/script></head>`
93
+ ],
94
+ {
95
+ type: "text/html"
96
+ }
97
+ )
98
+ );
99
+ }
100
+ const hash = window.location.hash.slice(1);
101
+ if (hash && hash in urls) {
102
+ load(hash, urls[hash]);
103
+ }
104
+ window.addEventListener("hashchange", () => {
105
+ const hash2 = window.location.hash.slice(1);
106
+ if (hash2 && hash2 in urls) {
107
+ load(hash2, urls[hash2]);
108
+ }
109
+ });
@@ -0,0 +1,12 @@
1
+ body {
2
+ display: flex;
3
+ justify-content: center;
4
+ align-items: center;
5
+ margin: 0px;
6
+ height: 100%;
7
+ overscroll-behavior-y: none;
8
+ }
9
+ canvas {
10
+ margin: auto;
11
+ image-rendering: pixelated;
12
+ }
@@ -0,0 +1,32 @@
1
+ import './index-0qrXMlfv.js';
2
+ import './utils-CvCgsM08.js';
3
+
4
+ true &&(function polyfill() {
5
+ const relList = document.createElement("link").relList;
6
+ if (relList && relList.supports && relList.supports("modulepreload")) return;
7
+ for (const link of document.querySelectorAll("link[rel=\"modulepreload\"]")) processPreload(link);
8
+ new MutationObserver((mutations) => {
9
+ for (const mutation of mutations) {
10
+ if (mutation.type !== "childList") continue;
11
+ for (const node of mutation.addedNodes) if (node.tagName === "LINK" && node.rel === "modulepreload") processPreload(node);
12
+ }
13
+ }).observe(document, {
14
+ childList: true,
15
+ subtree: true
16
+ });
17
+ function getFetchOpts(link) {
18
+ const fetchOpts = {};
19
+ if (link.integrity) fetchOpts.integrity = link.integrity;
20
+ if (link.referrerPolicy) fetchOpts.referrerPolicy = link.referrerPolicy;
21
+ if (link.crossOrigin === "use-credentials") fetchOpts.credentials = "include";
22
+ else if (link.crossOrigin === "anonymous") fetchOpts.credentials = "omit";
23
+ else fetchOpts.credentials = "same-origin";
24
+ return fetchOpts;
25
+ }
26
+ function processPreload(link) {
27
+ if (link.ep) return;
28
+ link.ep = true;
29
+ const fetchOpts = getFetchOpts(link);
30
+ fetch(link.href, fetchOpts);
31
+ }
32
+ }());
@@ -0,0 +1,78 @@
1
+ import { i as interleave, a as attribute, u as uniform, g as glsl, c as compile, v as view } from './tag-C_bg62fD.js';
2
+
3
+ const canvas = document.createElement("canvas");
4
+ canvas.width = 800;
5
+ canvas.height = 600;
6
+ document.body.append(canvas);
7
+ const gl = canvas.getContext("webgl2");
8
+ gl.viewport(0, 0, canvas.width, canvas.height);
9
+ const vertex = glsl`
10
+ precision mediump float;
11
+
12
+ ${interleave("instancedData", [attribute.vec2("a_pos"), attribute.vec3("a_color")], {
13
+ instanced: true
14
+ })}
15
+ ${attribute.vec2("a_vertex")}
16
+ ${uniform.float("u_time")}
17
+
18
+ varying vec3 v_color;
19
+
20
+ void main() {
21
+ float s = sin(u_time);
22
+ float c = cos(u_time);
23
+ mat2 rotation = mat2(
24
+ c, -s,
25
+ s, c
26
+ );
27
+ vec2 position = a_pos + a_vertex * rotation;
28
+ gl_Position = vec4(position, 0.0, 1.0);
29
+
30
+ v_color = a_color;
31
+ }`;
32
+ const fragment = glsl`
33
+ precision mediump float;
34
+
35
+ varying vec3 v_color;
36
+
37
+ void main() {
38
+ gl_FragColor = vec4(v_color, 1.0);
39
+ }`;
40
+ const { program, schema } = compile(gl, vertex, fragment);
41
+ const {
42
+ attributes: { a_vertex },
43
+ uniforms: { u_time },
44
+ interleavedAttributes: { instancedData }
45
+ } = view(gl, program, schema);
46
+ instancedData.set(
47
+ new Float32Array(
48
+ function* () {
49
+ for (let i = 0; i < 100; i++) {
50
+ yield (Math.random() - 0.5) * 2;
51
+ yield (Math.random() - 0.5) * 2;
52
+ yield Math.random();
53
+ yield Math.random();
54
+ yield Math.random();
55
+ }
56
+ }()
57
+ )
58
+ );
59
+ instancedData.bind();
60
+ a_vertex.set(
61
+ new Float32Array([
62
+ // top
63
+ 0,
64
+ 1,
65
+ // bottom left
66
+ -1,
67
+ -1,
68
+ // bottom right
69
+ 1,
70
+ -1
71
+ ])
72
+ ).bind();
73
+ gl.useProgram(program);
74
+ requestAnimationFrame(function draw(delta) {
75
+ requestAnimationFrame(draw);
76
+ u_time.set(delta / 1e3);
77
+ gl.drawArraysInstanced(gl.TRIANGLES, 0, 3, 100);
78
+ });