ranuts 0.4.1-alpha.1 → 0.5.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.
- package/CLAUDE.md +178 -26
- package/README.de.md +62 -0
- package/README.es.md +62 -0
- package/README.fa.md +62 -0
- package/README.ja.md +62 -0
- package/README.ko.md +62 -0
- package/README.md +35 -90
- package/README.pt.md +62 -0
- package/README.zh-CN.md +35 -89
- package/dist/iife/index.iife.js +4 -0
- package/dist/iife/utils.iife.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +306 -1
- package/dist/src/_virtual/_rolldown/runtime/index.js +12 -0
- package/dist/src/conversation/engine.d.ts +109 -0
- package/dist/src/conversation/engine.js +101 -0
- package/dist/src/conversation/index.d.ts +12 -0
- package/dist/src/conversation/index.js +4 -0
- package/dist/src/conversation/types.d.ts +99 -0
- package/dist/src/stream/accumulator.d.ts +51 -0
- package/dist/src/stream/accumulator.js +79 -0
- package/dist/src/stream/budget.d.ts +89 -0
- package/dist/src/stream/budget.js +45 -0
- package/dist/src/stream/index.d.ts +25 -0
- package/dist/src/stream/index.js +11 -0
- package/dist/src/stream/sse.d.ts +51 -0
- package/dist/src/stream/sse.js +61 -0
- package/dist/src/stream/types.d.ts +106 -0
- package/dist/src/sw/index.js +52 -1
- package/dist/src/utils/async.js +49 -0
- package/dist/src/utils/audioRecorder.js +1121 -0
- package/dist/src/utils/behavior.js +9 -0
- package/dist/src/utils/binary.js +89 -0
- package/dist/src/utils/bom.d.ts +31 -9
- package/dist/src/utils/bom.js +165 -0
- package/dist/src/utils/bridge.js +310 -0
- package/dist/src/utils/canvas.d.ts +1 -0
- package/dist/src/utils/canvas.js +103 -0
- package/dist/src/utils/chain.js +76 -0
- package/dist/src/utils/color.d.ts +0 -1
- package/dist/src/utils/color.js +312 -0
- package/dist/src/utils/compose.js +22 -0
- package/dist/src/utils/console.js +22 -0
- package/dist/src/utils/debounce.js +18 -0
- package/dist/src/utils/device.d.ts +0 -9
- package/dist/src/utils/device.js +31 -0
- package/dist/src/utils/diff.d.ts +51 -0
- package/dist/src/utils/diff.js +110 -0
- package/dist/src/utils/dom.d.ts +1 -1
- package/dist/src/utils/dom.js +89 -0
- package/dist/src/utils/error.js +11 -0
- package/dist/src/utils/event.d.ts +3 -3
- package/dist/src/utils/event.js +39 -0
- package/dist/src/utils/file.js +14 -0
- package/dist/src/utils/func.js +4 -0
- package/dist/src/utils/i18n/index.js +79 -1
- package/dist/src/utils/idb.js +177 -0
- package/dist/src/utils/img.d.ts +1 -1
- package/dist/src/utils/img.js +68 -0
- package/dist/src/utils/index.d.ts +81 -77
- package/dist/src/utils/index.js +306 -1
- package/dist/src/utils/lang.d.ts +23 -6
- package/dist/src/utils/lang.js +42 -0
- package/dist/src/utils/localePath.js +48 -0
- package/dist/src/utils/memoize.d.ts +1 -7
- package/dist/src/utils/memoize.js +16 -0
- package/dist/src/utils/mimeType.js +841 -0
- package/dist/src/utils/monitor.js +84 -0
- package/dist/src/utils/network.js +117 -0
- package/dist/src/utils/noop.js +5 -0
- package/dist/src/utils/number.d.ts +20 -0
- package/dist/src/utils/number.js +185 -0
- package/dist/src/utils/obj.d.ts +2 -2
- package/dist/src/utils/obj.js +140 -0
- package/dist/src/utils/paginate.js +93 -0
- package/dist/src/utils/performance.js +26 -0
- package/dist/src/utils/placement.d.ts +42 -5
- package/dist/src/utils/placement.js +37 -0
- package/dist/src/utils/prefetch.js +69 -0
- package/dist/src/utils/queue.js +46 -0
- package/dist/src/utils/report.js +44 -0
- package/dist/src/utils/request.js +35 -0
- package/dist/src/utils/script.d.ts +1 -1
- package/dist/src/utils/script.js +46 -0
- package/dist/src/utils/scroll.d.ts +93 -0
- package/dist/src/utils/scroll.js +62 -0
- package/dist/src/utils/secure.js +36 -0
- package/dist/src/utils/segment.js +43 -0
- package/dist/src/utils/signal.d.ts +1 -1
- package/dist/src/utils/signal.js +13 -0
- package/dist/src/utils/speech.js +59 -0
- package/dist/src/utils/storage.js +53 -0
- package/dist/src/utils/str.d.ts +0 -6
- package/dist/src/utils/str.js +395 -0
- package/dist/src/utils/style.js +29 -0
- package/dist/src/utils/subscribe.js +58 -0
- package/dist/src/utils/throttle.js +17 -0
- package/dist/src/utils/time.d.ts +0 -21
- package/dist/src/utils/time.js +97 -0
- package/dist/src/utils/totp/sha/common.d.ts +1 -1
- package/dist/src/utils/totp/sha/common.js +201 -0
- package/dist/src/utils/totp/sha/converters.d.ts +1 -1
- package/dist/src/utils/totp/sha/converters.js +188 -0
- package/dist/src/utils/totp/sha/primitives_32.js +55 -0
- package/dist/src/utils/totp/sha/primitives_64.js +85 -0
- package/dist/src/utils/totp/sha/sha.d.ts +1 -1
- package/dist/src/utils/totp/sha/sha.js +30 -0
- package/dist/src/utils/totp/sha/sha1.d.ts +2 -2
- package/dist/src/utils/totp/sha/sha1.js +51 -0
- package/dist/src/utils/totp/sha/sha256.d.ts +2 -2
- package/dist/src/utils/totp/sha/sha256.js +56 -0
- package/dist/src/utils/totp/sha/sha3.d.ts +3 -3
- package/dist/src/utils/totp/sha/sha3.js +253 -0
- package/dist/src/utils/totp/sha/sha512.d.ts +3 -3
- package/dist/src/utils/totp/sha/sha512.js +177 -0
- package/dist/src/utils/totp/totp.js +49 -0
- package/dist/src/utils/tween.js +59 -0
- package/dist/src/utils/visual/application.d.ts +4 -4
- package/dist/src/utils/visual/application.js +42 -0
- package/dist/src/utils/visual/enums.js +19 -0
- package/dist/src/utils/visual/event/boundary.d.ts +2 -2
- package/dist/src/utils/visual/event/boundary.js +93 -0
- package/dist/src/utils/visual/event/event.d.ts +1 -1
- package/dist/src/utils/visual/event/event.js +34 -0
- package/dist/src/utils/visual/event/index.d.ts +4 -4
- package/dist/src/utils/visual/event/types.d.ts +2 -2
- package/dist/src/utils/visual/event/types.js +23 -0
- package/dist/src/utils/visual/graphics/graphics.d.ts +8 -8
- package/dist/src/utils/visual/graphics/graphics.js +168 -0
- package/dist/src/utils/visual/graphics/graphicsData.d.ts +3 -3
- package/dist/src/utils/visual/graphics/graphicsData.js +12 -0
- package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +7 -7
- package/dist/src/utils/visual/graphics/graphicsGeometry.js +39 -0
- package/dist/src/utils/visual/graphics/index.d.ts +3 -3
- package/dist/src/utils/visual/index.d.ts +8 -8
- package/dist/src/utils/visual/index.js +20 -1
- package/dist/src/utils/visual/math/bezier.js +15 -0
- package/dist/src/utils/visual/math/enums.js +6 -0
- package/dist/src/utils/visual/math/index.d.ts +4 -4
- package/dist/src/utils/visual/math/matrix.d.ts +1 -1
- package/dist/src/utils/visual/math/matrix.js +59 -0
- package/dist/src/utils/visual/math/transform.d.ts +2 -2
- package/dist/src/utils/visual/math/transform.js +50 -0
- package/dist/src/utils/visual/render/batchRenderer.d.ts +4 -4
- package/dist/src/utils/visual/render/batchRenderer.js +59 -0
- package/dist/src/utils/visual/render/canvasRenderer.d.ts +3 -3
- package/dist/src/utils/visual/render/canvasRenderer.js +17 -0
- package/dist/src/utils/visual/render/filter.d.ts +1 -1
- package/dist/src/utils/visual/render/filter.js +92 -0
- package/dist/src/utils/visual/render/index.d.ts +2 -2
- package/dist/src/utils/visual/render/index.js +20 -0
- package/dist/src/utils/visual/render/render.d.ts +4 -4
- package/dist/src/utils/visual/render/render.js +19 -0
- package/dist/src/utils/visual/render/renderTarget.js +28 -0
- package/dist/src/utils/visual/render/utils/batch/index.d.ts +4 -4
- package/dist/src/utils/visual/render/utils/batch/index.js +88 -0
- package/dist/src/utils/visual/render/utils/earcut.js +328 -0
- package/dist/src/utils/visual/render/utils/float.js +65 -0
- package/dist/src/utils/visual/render/utils/index.js +50 -0
- package/dist/src/utils/visual/render/utils/verticy.d.ts +2 -2
- package/dist/src/utils/visual/render/utils/verticy.js +162 -0
- package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +1 -1
- package/dist/src/utils/visual/render/utils/webgl/initShader.js +31 -0
- package/dist/src/utils/visual/render/utils/webgl/shaders.js +22 -0
- package/dist/src/utils/visual/render/utils/webgpu/shaders.js +32 -0
- package/dist/src/utils/visual/render/webGPURenderer.d.ts +2 -2
- package/dist/src/utils/visual/render/webGPURenderer.js +185 -0
- package/dist/src/utils/visual/render/webGlRenderer.d.ts +2 -2
- package/dist/src/utils/visual/render/webGlRenderer.js +88 -0
- package/dist/src/utils/visual/shape/circle.d.ts +3 -3
- package/dist/src/utils/visual/shape/circle.js +17 -0
- package/dist/src/utils/visual/shape/ellipse.d.ts +3 -3
- package/dist/src/utils/visual/shape/ellipse.js +18 -0
- package/dist/src/utils/visual/shape/index.d.ts +6 -6
- package/dist/src/utils/visual/shape/polygon.d.ts +3 -3
- package/dist/src/utils/visual/shape/polygon.js +29 -0
- package/dist/src/utils/visual/shape/rectangle.d.ts +3 -3
- package/dist/src/utils/visual/shape/rectangle.js +18 -0
- package/dist/src/utils/visual/shape/roundedRectangle.d.ts +3 -3
- package/dist/src/utils/visual/shape/roundedRectangle.js +32 -0
- package/dist/src/utils/visual/shape/shape.d.ts +2 -2
- package/dist/src/utils/visual/shape/shape.js +5 -0
- package/dist/src/utils/visual/style/fill.js +18 -0
- package/dist/src/utils/visual/style/index.d.ts +2 -2
- package/dist/src/utils/visual/style/line.d.ts +2 -2
- package/dist/src/utils/visual/style/line.js +18 -0
- package/dist/src/utils/visual/types.d.ts +1 -1
- package/dist/src/utils/visual/vertex/container.d.ts +5 -5
- package/dist/src/utils/visual/vertex/container.js +54 -0
- package/dist/src/utils/visual/vertex/point.js +37 -0
- package/dist/src/utils/visual/vertex/vertex.d.ts +7 -7
- package/dist/src/utils/visual/vertex/vertex.js +76 -0
- package/dist/src/utils/worker.js +89 -0
- package/dist/src/utils/zip.js +161 -0
- package/dist/src/vnode/h.d.ts +1 -1
- package/dist/src/vnode/h.js +22 -0
- package/dist/src/vnode/hooks.d.ts +1 -1
- package/dist/src/vnode/htmlDomApi.js +94 -0
- package/dist/src/vnode/index.d.ts +16 -16
- package/dist/src/vnode/index.js +28 -1
- package/dist/src/vnode/init.d.ts +1 -1
- package/dist/src/vnode/init.js +104 -0
- package/dist/src/vnode/is.d.ts +1 -1
- package/dist/src/vnode/is.js +20 -0
- package/dist/src/vnode/modules/attributes.d.ts +1 -1
- package/dist/src/vnode/modules/attributes.js +21 -0
- package/dist/src/vnode/modules/class.d.ts +1 -1
- package/dist/src/vnode/modules/class.js +18 -0
- package/dist/src/vnode/modules/index.js +15 -0
- package/dist/src/vnode/modules/listeners.d.ts +1 -1
- package/dist/src/vnode/modules/listeners.js +36 -0
- package/dist/src/vnode/modules/props.d.ts +1 -1
- package/dist/src/vnode/modules/props.js +17 -0
- package/dist/src/vnode/modules/style.d.ts +1 -1
- package/dist/src/vnode/modules/style.js +52 -0
- package/dist/src/vnode/vnode.d.ts +6 -6
- package/dist/src/vnode/vnode.js +13 -0
- package/dist/third-party/jschardet/LICENSE.txt +504 -0
- package/dist/third-party/jschardet/NOTICE.txt +33 -0
- package/docs/API.md +86 -65
- package/package.json +20 -15
- package/dist/bin/generate-api-docs.d.ts +0 -1
- package/dist/build/build.es.d.ts +0 -2
- package/dist/build/build.umd.d.ts +0 -2
- package/dist/build/build.umd.node.d.ts +0 -2
- package/dist/build/build.umd.utils.d.ts +0 -2
- package/dist/chain-CTywmh_H.js +0 -1
- package/dist/color-B_KMM8UX.js +0 -1
- package/dist/enums-BAgbyGdH.js +0 -1
- package/dist/examples/clone-deep-example.d.ts +0 -1
- package/dist/examples/is-equal-example.d.ts +0 -1
- package/dist/i18n-BJIS1fR1.js +0 -1
- package/dist/plugins/vite-plugins-banner.d.ts +0 -2
- package/dist/rolldown-runtime-I3TIJKkN.js +0 -1
- package/dist/src/node/appendFile.d.ts +0 -7
- package/dist/src/node/body.d.ts +0 -9
- package/dist/src/node/color.d.ts +0 -7
- package/dist/src/node/command.d.ts +0 -8
- package/dist/src/node/ctx2req.d.ts +0 -5
- package/dist/src/node/fileInfo.d.ts +0 -7
- package/dist/src/node/fs.d.ts +0 -7
- package/dist/src/node/get.d.ts +0 -10
- package/dist/src/node/getIPAdress.d.ts +0 -1
- package/dist/src/node/index.d.ts +0 -25
- package/dist/src/node/index.js +0 -1
- package/dist/src/node/isColorSupported.d.ts +0 -2
- package/dist/src/node/paresUrl.d.ts +0 -19
- package/dist/src/node/readDir.d.ts +0 -6
- package/dist/src/node/readFile.d.ts +0 -9
- package/dist/src/node/router.d.ts +0 -42
- package/dist/src/node/send.d.ts +0 -7
- package/dist/src/node/server.d.ts +0 -18
- package/dist/src/node/startTask.d.ts +0 -2
- package/dist/src/node/stream.d.ts +0 -15
- package/dist/src/node/taskEnd.d.ts +0 -2
- package/dist/src/node/traverse.d.ts +0 -17
- package/dist/src/node/watchFile.d.ts +0 -8
- package/dist/src/node/writeFile.d.ts +0 -8
- package/dist/src/node/ws.d.ts +0 -8
- package/dist/src/utils/visual/render/utils/batch/index.test.d.ts +0 -1
- package/dist/src/utils/visual/render/utils/index.test.d.ts +0 -1
- package/dist/test/binary.test.d.ts +0 -1
- package/dist/test/bridge.test.d.ts +0 -1
- package/dist/test/canvas.test.d.ts +0 -1
- package/dist/test/clearBr.test.d.ts +0 -1
- package/dist/test/cloneDeep.test.d.ts +0 -1
- package/dist/test/color.test.d.ts +0 -1
- package/dist/test/command.test.d.ts +0 -1
- package/dist/test/encodeUrl.test.d.ts +0 -1
- package/dist/test/escapeHtml.test.d.ts +0 -1
- package/dist/test/is-equal.test.d.ts +0 -1
- package/dist/test/mimeType.test.d.ts +0 -1
- package/dist/test/package-exports.test.d.ts +0 -1
- package/dist/test/server.test.d.ts +0 -1
- package/dist/test/status.test.d.ts +0 -1
- package/dist/test/sw.test.d.ts +0 -1
- package/dist/test/totp.test.d.ts +0 -1
- package/dist/test/tween.test.d.ts +0 -1
- package/dist/test/utils/async.test.d.ts +0 -1
- package/dist/test/utils/autosize.test.d.ts +0 -1
- package/dist/test/utils/color-grade.test.d.ts +0 -1
- package/dist/test/utils/compose.test.d.ts +0 -1
- package/dist/test/utils/event.test.d.ts +0 -1
- package/dist/test/utils/file-read.test.d.ts +0 -1
- package/dist/test/utils/format.test.d.ts +0 -1
- package/dist/test/utils/i18n.test.d.ts +0 -1
- package/dist/test/utils/idb-collection.test.d.ts +0 -1
- package/dist/test/utils/idb.test.d.ts +0 -1
- package/dist/test/utils/instrumentation.test.d.ts +0 -1
- package/dist/test/utils/interp.test.d.ts +0 -1
- package/dist/test/utils/lang.test.d.ts +0 -1
- package/dist/test/utils/locale-path.test.d.ts +0 -1
- package/dist/test/utils/media-query.test.d.ts +0 -1
- package/dist/test/utils/mergeObj.test.d.ts +0 -1
- package/dist/test/utils/number-parse.test.d.ts +0 -1
- package/dist/test/utils/paginate.test.d.ts +0 -1
- package/dist/test/utils/placement.test.d.ts +0 -1
- package/dist/test/utils/prefetch.test.d.ts +0 -1
- package/dist/test/utils/query-storage.test.d.ts +0 -1
- package/dist/test/utils/queue.test.d.ts +0 -1
- package/dist/test/utils/report-config.test.d.ts +0 -1
- package/dist/test/utils/report-image.test.d.ts +0 -1
- package/dist/test/utils/secure.test.d.ts +0 -1
- package/dist/test/utils/segment.test.d.ts +0 -1
- package/dist/test/utils/signal-once.test.d.ts +0 -1
- package/dist/test/utils/single-flight.test.d.ts +0 -1
- package/dist/test/utils/speech.test.d.ts +0 -1
- package/dist/test/utils/text-boundary.test.d.ts +0 -1
- package/dist/test/utils/time.test.d.ts +0 -1
- package/dist/test/utils/timing.test.d.ts +0 -1
- package/dist/test/utils/truncate.test.d.ts +0 -1
- package/dist/test/utils/visual/filter.test.d.ts +0 -1
- package/dist/test/utils/worker-client.test.d.ts +0 -1
- package/dist/test/utils/worker-serve.test.d.ts +0 -1
- package/dist/test/utils/zip.test.d.ts +0 -1
- package/dist/test/visual/math.test.d.ts +0 -1
- package/dist/test/visual-application.test.d.ts +0 -1
- package/dist/test/visual-batch.test.d.ts +0 -1
- package/dist/test/visual-math.test.d.ts +0 -1
- package/dist/test/vnode/index.d.ts +0 -1
- package/dist/test/vnode/server.d.ts +0 -2
- package/dist/test/vnode/vnode.d.ts +0 -1
- package/dist/test/vnode.test.d.ts +0 -1
- package/dist/test/websocket.test.d.ts +0 -1
- package/dist/test/writeFile.test.d.ts +0 -1
- package/dist/umd/index.umd.cjs +0 -1
- package/dist/umd/node/node.umd.cjs +0 -1
- package/dist/umd/utils/utils.umd.cjs +0 -1
- package/dist/utils-BNwhohXq.js +0 -1
- package/dist/vite.config.d.ts +0 -8
- package/dist/vitest.config.d.ts +0 -2
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { LINE_CAP as k, LINE_JOIN as w } from "../../enums.js";
|
|
2
|
+
import { Rectangle as $ } from "../../shape/rectangle.js";
|
|
3
|
+
import { BatchPart as tt } from "./batch/index.js";
|
|
4
|
+
import { Polygon as z } from "../../shape/polygon.js";
|
|
5
|
+
import at from "./earcut.js";
|
|
6
|
+
import { Circle as st } from "../../shape/circle.js";
|
|
7
|
+
import { Ellipse as nt } from "../../shape/ellipse.js";
|
|
8
|
+
import { RoundedRectangle as et } from "../../shape/roundedRectangle.js";
|
|
9
|
+
var lt = (r, h) => {
|
|
10
|
+
const { x: n, y: o, radius: v } = r, p = 2 * Math.PI * v, i = Math.min(Math.ceil(p / 5), 2048);
|
|
11
|
+
for (let d = 0; d < i; d++) {
|
|
12
|
+
const l = d / i * Math.PI * 2, t = n + v * Math.cos(l), u = o + v * Math.sin(l);
|
|
13
|
+
h.vertices.push(t, u);
|
|
14
|
+
}
|
|
15
|
+
}, ut = (r, h) => {
|
|
16
|
+
const { x: n, y: o, width: v, height: p, radius: i } = r, d = 2 * Math.PI * i / 4, l = Math.min(Math.ceil(d / 4), 2048);
|
|
17
|
+
for (let t = 0; t < l; t++) {
|
|
18
|
+
const u = t / l * Math.PI * 0.5, g = i * Math.cos(u), s = i * Math.sin(u);
|
|
19
|
+
h.vertices.push(n + v - i + g, o + p - i + s);
|
|
20
|
+
}
|
|
21
|
+
for (let t = 0; t < l; t++) {
|
|
22
|
+
const u = t / l * Math.PI * 0.5 + Math.PI / 2, g = i * Math.cos(u), s = i * Math.sin(u);
|
|
23
|
+
h.vertices.push(n + i + g, o + p - i + s);
|
|
24
|
+
}
|
|
25
|
+
for (let t = 0; t < l; t++) {
|
|
26
|
+
const u = t / l * Math.PI * 0.5 + Math.PI, g = i * Math.cos(u), s = i * Math.sin(u);
|
|
27
|
+
h.vertices.push(n + i + g, o + i + s);
|
|
28
|
+
}
|
|
29
|
+
for (let t = 0; t < l; t++) {
|
|
30
|
+
const u = t / l * Math.PI * 0.5 + Math.PI * 1.5, g = i * Math.cos(u), s = i * Math.sin(u);
|
|
31
|
+
h.vertices.push(n + v - i + g, o + i + s);
|
|
32
|
+
}
|
|
33
|
+
}, ft = (r, h) => {
|
|
34
|
+
const { x: n, y: o, radiusX: v, radiusY: p } = r, i = Math.PI * Math.sqrt(2 * (v * v + p * p)), d = Math.min(Math.ceil(i / 5), 2048);
|
|
35
|
+
for (let l = 0; l < d; l++) {
|
|
36
|
+
const t = l / d * Math.PI * 2, u = n + v * Math.cos(t), g = o + p * Math.sin(t);
|
|
37
|
+
h.vertices.push(u, g);
|
|
38
|
+
}
|
|
39
|
+
}, bt = (r) => {
|
|
40
|
+
const { shape: h, vertices: n } = r;
|
|
41
|
+
if (h instanceof $) {
|
|
42
|
+
const { x: o, y: v, width: p, height: i } = h;
|
|
43
|
+
n.push(o, v, o + p, v, o + p, v + i, o, v + i);
|
|
44
|
+
}
|
|
45
|
+
h instanceof st && lt(h, r), h instanceof et && ut(h, r), h instanceof nt && ft(h, r), h instanceof z && (r.vertices = h.points);
|
|
46
|
+
}, y = (r) => {
|
|
47
|
+
const h = [], n = r.length / 2 + 1;
|
|
48
|
+
for (let o = 1; o < n - 1; o++) h.push(0, o, o + 1);
|
|
49
|
+
return h.push(0, n - 1, 1), h;
|
|
50
|
+
}, Et = (r, h) => {
|
|
51
|
+
const { shape: n, vertices: o, fillStyle: v } = r, p = new tt(v);
|
|
52
|
+
if (h.batchParts.push(p), p.start(h.vertices.length / 2, h.indices.length), n instanceof $ && (h.vertices.concat(o), h.indices.concat([
|
|
53
|
+
0,
|
|
54
|
+
1,
|
|
55
|
+
2,
|
|
56
|
+
0,
|
|
57
|
+
2,
|
|
58
|
+
3
|
|
59
|
+
]), p.end(4, 6)), n instanceof st) {
|
|
60
|
+
const { x: i, y: d } = n;
|
|
61
|
+
h.vertices.push(i), h.vertices.push(d), h.vertices.concat(o);
|
|
62
|
+
const l = y(o);
|
|
63
|
+
h.indices.concat(l), p.end(o.length / 2 + 1, l.length);
|
|
64
|
+
}
|
|
65
|
+
if (n instanceof et) {
|
|
66
|
+
const { x: i, y: d, width: l, height: t } = n;
|
|
67
|
+
h.vertices.push(i + l / 2), h.vertices.push(d + t / 2), h.vertices.concat(o);
|
|
68
|
+
const u = y(o);
|
|
69
|
+
h.indices.concat(u), p.end(o.length / 2 + 1, u.length);
|
|
70
|
+
}
|
|
71
|
+
if (n instanceof nt) {
|
|
72
|
+
const { x: i, y: d } = n;
|
|
73
|
+
h.vertices.push(i), h.vertices.push(d), h.vertices.concat(o);
|
|
74
|
+
const l = y(o);
|
|
75
|
+
h.indices.concat(l), p.end(o.length / 2 + 1, l.length);
|
|
76
|
+
}
|
|
77
|
+
if (n instanceof z) {
|
|
78
|
+
h.vertices.concat(o);
|
|
79
|
+
const i = at(o);
|
|
80
|
+
h.indices.concat(i), p.end(o.length / 2, i.length);
|
|
81
|
+
}
|
|
82
|
+
}, Z = (r, h, n, o, v, p, i, d) => {
|
|
83
|
+
let l = 0, t = 0, u = 0, g = 0, s = 0, a = 0;
|
|
84
|
+
if (Math.abs(n - r) <= Number.EPSILON)
|
|
85
|
+
l = 1, t = 0, s = n;
|
|
86
|
+
else {
|
|
87
|
+
const E = (o - h) / (n - r), N = o - E * n;
|
|
88
|
+
l = E, t = -1, s = -N;
|
|
89
|
+
}
|
|
90
|
+
if (Math.abs(i - v) <= Number.EPSILON)
|
|
91
|
+
u = 1, g = 0, a = i;
|
|
92
|
+
else {
|
|
93
|
+
const E = (d - p) / (i - v), N = d - E * i;
|
|
94
|
+
u = E, g = -1, a = -N;
|
|
95
|
+
}
|
|
96
|
+
return [(s * g - t * a) / (l * g - t * u), (l * a - s * u) / (l * g - t * u)];
|
|
97
|
+
}, J = (r, h, n) => {
|
|
98
|
+
const o = h, v = -r, p = Math.sqrt(r * r + h * h), i = n / 2 / p;
|
|
99
|
+
return [o * i, v * i];
|
|
100
|
+
}, V = (r, h, n, o, v, p, i, d) => {
|
|
101
|
+
const l = n - r, t = o - h, u = v - r, g = p - h;
|
|
102
|
+
let s = 0;
|
|
103
|
+
l === 0 ? t > 0 ? s = Math.PI * 0.5 : s = Math.PI * 1.5 : t === 0 ? l > 0 ? s = 0 : s = Math.PI : l >= 0 && t >= 0 ? s = Math.atan(t / l) : l <= 0 && t >= 0 ? s = Math.atan(-l / t) + Math.PI * 0.5 : l <= 0 && t <= 0 ? s = Math.atan(t / l) + Math.PI : s = Math.atan(l / -t) + Math.PI * 1.5;
|
|
104
|
+
let a = 0;
|
|
105
|
+
u === 0 ? g > 0 ? a = Math.PI * 0.5 : a = Math.PI * 1.5 : g === 0 ? u > 0 ? a = 0 : a = Math.PI : u >= 0 && g >= 0 ? a = Math.atan(g / u) : u <= 0 && g >= 0 ? a = Math.atan(-u / g) + Math.PI * 0.5 : u <= 0 && g <= 0 ? a = Math.atan(g / u) + Math.PI : a = Math.atan(u / -g) + Math.PI * 1.5, s > a && (s -= Math.PI * 2);
|
|
106
|
+
const E = Math.sqrt((n - r) * (n - r) + (o - h) * (o - h)), N = 2 * Math.PI * E / 3, q = i.length / 2;
|
|
107
|
+
i.push(r, h, n, o);
|
|
108
|
+
for (let O = 1; O < N; O++) {
|
|
109
|
+
const m = s + (a - s) * (O / N), C = r + E * Math.cos(m), D = h + E * Math.sin(m);
|
|
110
|
+
i.push(C, D);
|
|
111
|
+
}
|
|
112
|
+
i.push(v, p);
|
|
113
|
+
for (let O = 1; O < i.length / 2 - q - 1; O++) d.push(0 + q, O + q, O + 1 + q);
|
|
114
|
+
}, Rt = (r, h) => {
|
|
115
|
+
const { vertices: n, shape: o, lineStyle: v } = r, { width: p, cap: i, join: d, miterLimit: l } = v;
|
|
116
|
+
let t = 0, u = !1;
|
|
117
|
+
if (o instanceof z ? o.closeStroke && (u = !0) : u = !0, u) {
|
|
118
|
+
const I = n[0], R = n[1], B = n[n.length - 2], c = n[n.length - 1];
|
|
119
|
+
Math.abs(I - B) < 1e-4 && Math.abs(R - c) < 1e-4 && (n.pop(), n.pop());
|
|
120
|
+
const e = n[n.length - 2], x = n[n.length - 1], U = (I + e) / 2, f = (R + x) / 2;
|
|
121
|
+
n.unshift(U, f), n.push(U, f);
|
|
122
|
+
}
|
|
123
|
+
const g = new tt(v);
|
|
124
|
+
h.batchParts.push(g), g.start(h.vertices.length / 2, h.indices.length);
|
|
125
|
+
const s = [], a = [], E = n[0], N = n[1], q = n[2], O = n[3], [m, C] = J(q - E, O - N, p);
|
|
126
|
+
if (!u) {
|
|
127
|
+
if (i === k.SQUARE) {
|
|
128
|
+
const I = C, R = -m;
|
|
129
|
+
s.push(E + m, N + C, E + m + I, N + C + R, E - m + I, N - C + R, E - m, N - C), a.push(0, 1, 2, 0, 2, 3);
|
|
130
|
+
}
|
|
131
|
+
i === k.ROUND && V(E, N, E - m, N - C, E + m, N + C, s, a), k.BUTT;
|
|
132
|
+
}
|
|
133
|
+
t = s.length / 2, s.push(E - m, N - C, E + m, N + C);
|
|
134
|
+
for (let I = 2; I < n.length - 2; I += 2) {
|
|
135
|
+
const R = n[I - 2], B = n[I - 1], c = n[I], e = n[I + 1], x = n[I + 2], U = n[I + 3], [f, M] = J(c - R, e - B, p), [P, b] = J(x - c, U - e, p), F = c - R, Q = e - B, _ = x - c, j = U - e, A = _ * Q - F * j, K = F * _ + Q * j;
|
|
136
|
+
if (Math.abs(A) < 1e-3 * Math.abs(K)) {
|
|
137
|
+
s.push(c + f, e + M, c - f, e - M), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t), t = s.length / 2, K > 0 ? s.push(c - f, e - M, c + f, e + M) : (d === w.ROUND && (V(c, e, c + f, e + M, c - f, e - M, s, a), t = s.length / 2), d === w.BEVEL || w.MITER, s.push(c + f, e + M, c - f, e - M));
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const [X, Y] = Z(R + f, B + M, c + f, e + M, c + P, e + b, x + P, U + b), [L, S] = Z(R - f, B - M, c - f, e - M, c - P, e - b, x - P, U - b);
|
|
141
|
+
let T = d;
|
|
142
|
+
d === w.MITER && (((L - X) ** 2 + (S - Y) ** 2) / p ** 2 <= l ** 2 || (T = w.BEVEL));
|
|
143
|
+
const it = F * F + Q * Q + (p / 2) ** 2, ot = _ * _ + j * j + (p / 2) ** 2;
|
|
144
|
+
(L - c) ** 2 + (S - e) ** 2 < Math.min(it, ot) ? (T === w.BEVEL && (A > 0 ? (s.push(X, Y, c - f, e - M), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t), t = s.length / 2, s.push(X, Y, c - f, e - M, c - P, e - b), a.push(0 + t, 1 + t, 2 + t), t = s.length / 2, s.push(c - P, e - b, X, Y)) : (s.push(c + f, e + M, L, S), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t), t = s.length / 2, s.push(L, S, c + f, e + M, c + P, e + b), a.push(0 + t, 1 + t, 2 + t), t = s.length / 2, s.push(L, S, c + P, e + b))), T === w.MITER && (s.push(X, Y, L, S), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t), t = s.length / 2, s.push(L, S, X, Y)), T === w.ROUND && (A < 0 ? (s.push(c + f, e + M, L, S), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t), t = s.length / 2, s.push(L, S, c + f, e + M, c, e), a.push(0 + t, 1 + t, 2 + t), t = s.length / 2, s.push(L, S, c + P, e + b, c, e), a.push(0 + t, 1 + t, 2 + t), t = s.length / 2, V(c, e, c + f, e + M, c + P, e + b, s, a), t = s.length / 2, s.push(L, S, c + P, e + b)) : (s.push(X, Y, c - f, e - M), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t), t = s.length / 2, s.push(X, Y, c - f, e - M, c, e), a.push(0 + t, 1 + t, 2 + t), t = s.length / 2, s.push(X, Y, c - P, e - b, c, e), a.push(0 + t, 1 + t, 2 + t), t = s.length / 2, V(c, e, c - P, e - b, c - f, e - M, s, a), t = s.length / 2, s.push(c - P, e - b, X, Y)))) : (s.push(c + f, e + M, c - f, e - M), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t), t = s.length / 2, T === w.BEVEL && (A > 0 ? (s.push(c, e, c - f, e - M, c - P, e - b), a.push(0 + t, 1 + t, 2 + t)) : (s.push(c, e, c + f, e + M, c + P, e + b), a.push(0 + t, 1 + t, 2 + t))), T === w.MITER && (A > 0 ? (s.push(c, e, c - f, e - M, L, S, c - P, e - b), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t)) : (s.push(c, e, c + f, e + M, X, Y, c + P, e + b), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t))), T === w.ROUND && (A > 0 ? V(c, e, c - P, e - b, c - f, e - M, s, a) : V(c, e, c + f, e + M, c + P, e + b, s, a)), t = s.length / 2, s.push(c - P, e - b, c + P, e + b));
|
|
145
|
+
}
|
|
146
|
+
const D = n[n.length - 2], W = n[n.length - 1], ct = n[n.length - 4], ht = n[n.length - 3], [G, H] = J(D - ct, W - ht, p);
|
|
147
|
+
if (s.push(D + G, W + H, D - G, W - H), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t), t = s.length / 2, !u) {
|
|
148
|
+
const I = n[n.length - 2], R = n[n.length - 1], B = n[n.length - 4], c = n[n.length - 3], [e, x] = J(I - B, R - c, p);
|
|
149
|
+
if (i === k.SQUARE) {
|
|
150
|
+
const U = -x, f = e;
|
|
151
|
+
s.push(I + e, R + x, I + e + U, R + x + f, I - e + U, R - x + f, I - e, R - x), a.push(0 + t, 1 + t, 2 + t, 0 + t, 2 + t, 3 + t);
|
|
152
|
+
}
|
|
153
|
+
i === k.ROUND && V(I, R, I + e, R + x, I - e, R - x, s, a);
|
|
154
|
+
}
|
|
155
|
+
h.vertices.concat(s), h.indices.concat(a), g.end(s.length / 2, a.length);
|
|
156
|
+
};
|
|
157
|
+
export {
|
|
158
|
+
bt as buildVertices,
|
|
159
|
+
J as getNormalVector,
|
|
160
|
+
Et as triangulateFill,
|
|
161
|
+
Rt as triangulateStroke
|
|
162
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WebGLRenderer } from
|
|
1
|
+
import type { WebGLRenderer } from "../../webGlRenderer.js";
|
|
2
2
|
/**
|
|
3
3
|
* Set the vertex attribute layout. The target ARRAY_BUFFER must already be bound.
|
|
4
4
|
* The vertex format matches the shared batching pipeline (BatchRenderer):
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "../../../enums.js";
|
|
2
|
+
import { fragmentShaderSource as i, vertexShaderSource as c } from "./shaders.js";
|
|
3
|
+
var n = (r, t, o) => {
|
|
4
|
+
const e = r.createShader(t);
|
|
5
|
+
if (r.shaderSource(e, o), r.compileShader(e), r.getShaderParameter(e, r.COMPILE_STATUS)) return e;
|
|
6
|
+
{
|
|
7
|
+
const a = r.getShaderInfoLog(e);
|
|
8
|
+
throw r.deleteShader(e), console.error(`shader compilation failed: ${a}`), new Error(`shader compilation failed: ${a}`);
|
|
9
|
+
}
|
|
10
|
+
}, d = (r, t, o) => {
|
|
11
|
+
const e = r.createProgram();
|
|
12
|
+
if (!e)
|
|
13
|
+
throw console.error("failed to create the program"), new Error("failed to create the program");
|
|
14
|
+
if (r.attachShader(e, t), r.attachShader(e, o), r.linkProgram(e), !r.getProgramParameter(e, r.LINK_STATUS)) {
|
|
15
|
+
const a = r.getProgramInfoLog(e);
|
|
16
|
+
throw console.error(`link failed: ${a}`), r.deleteProgram(e), r.deleteShader(t), r.deleteShader(o), new Error(`link failed: ${a}`);
|
|
17
|
+
}
|
|
18
|
+
return r.useProgram(e), e;
|
|
19
|
+
}, m = (r, t) => {
|
|
20
|
+
const o = r.getAttribLocation(t, "a_position");
|
|
21
|
+
r.vertexAttribPointer(o, 2, r.FLOAT, !1, 12, 0), r.enableVertexAttribArray(o);
|
|
22
|
+
const e = r.getAttribLocation(t, "a_color");
|
|
23
|
+
r.vertexAttribPointer(e, 4, r.UNSIGNED_BYTE, !0, 12, 8), r.enableVertexAttribArray(e);
|
|
24
|
+
}, E = (r) => {
|
|
25
|
+
const t = r.gl, o = n(t, t.VERTEX_SHADER, c), e = n(t, t.FRAGMENT_SHADER, i), a = d(t, o, e);
|
|
26
|
+
return t.enable(t.BLEND), t.blendFunc(t.ONE, t.ONE_MINUS_SRC_ALPHA), a;
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
E as initShader,
|
|
30
|
+
m as setupVertexLayout
|
|
31
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var o = `
|
|
2
|
+
precision highp float;
|
|
3
|
+
attribute vec2 a_position;
|
|
4
|
+
attribute vec4 a_color;
|
|
5
|
+
varying vec4 v_color;
|
|
6
|
+
uniform mat3 u_root_transform;
|
|
7
|
+
uniform mat3 u_projection_matrix;
|
|
8
|
+
void main(){
|
|
9
|
+
v_color = a_color;
|
|
10
|
+
gl_Position = vec4((u_projection_matrix * u_root_transform * vec3(a_position, 1.0)).xy, 0.0, 1.0);
|
|
11
|
+
}
|
|
12
|
+
`.trim(), r = `
|
|
13
|
+
precision mediump float;
|
|
14
|
+
varying vec4 v_color;
|
|
15
|
+
void main(){
|
|
16
|
+
gl_FragColor = v_color;
|
|
17
|
+
}
|
|
18
|
+
`.trim();
|
|
19
|
+
export {
|
|
20
|
+
r as fragmentShaderSource,
|
|
21
|
+
o as vertexShaderSource
|
|
22
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var o = `
|
|
2
|
+
@group(0) @binding(0) var<uniform> u_root_transform: mat3x3<f32>;
|
|
3
|
+
@group(0) @binding(1) var<uniform> u_projection_matrix: mat3x3<f32>;
|
|
4
|
+
|
|
5
|
+
struct VertOutput {
|
|
6
|
+
@builtin(position) v_position: vec4<f32>,
|
|
7
|
+
@location(0) v_color : vec4<f32>,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
@vertex
|
|
11
|
+
fn main(
|
|
12
|
+
@location(0) a_position: vec2<f32>,
|
|
13
|
+
@location(1) a_color: vec4<f32>,
|
|
14
|
+
) -> VertOutput {
|
|
15
|
+
let v_position = vec4<f32>((u_projection_matrix * u_root_transform * vec3<f32>(a_position, 1.0)).xy, 0.0, 1.0);
|
|
16
|
+
|
|
17
|
+
let v_color = a_color;
|
|
18
|
+
|
|
19
|
+
return VertOutput(v_position, v_color);
|
|
20
|
+
}
|
|
21
|
+
`, r = `
|
|
22
|
+
@fragment
|
|
23
|
+
fn main(
|
|
24
|
+
@location(0) v_color : vec4<f32>,
|
|
25
|
+
) -> @location(0) vec4<f32> {
|
|
26
|
+
return v_color;
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
export {
|
|
30
|
+
r as fragmentShaderSource,
|
|
31
|
+
o as vertexShaderSource
|
|
32
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BatchRenderer } from
|
|
2
|
-
import type { IApplicationOptions } from
|
|
1
|
+
import { BatchRenderer } from "./batchRenderer.js";
|
|
2
|
+
import type { IApplicationOptions } from "../types.js";
|
|
3
3
|
export declare class WebGPURenderer extends BatchRenderer {
|
|
4
4
|
private gpu;
|
|
5
5
|
private device;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import "../enums.js";
|
|
2
|
+
import { BatchRenderer as h } from "./batchRenderer.js";
|
|
3
|
+
import { toRgbArray as p } from "./utils/index.js";
|
|
4
|
+
import { fragmentShaderSource as g, vertexShaderSource as l } from "./utils/webgpu/shaders.js";
|
|
5
|
+
var E = class extends h {
|
|
6
|
+
gpu;
|
|
7
|
+
device;
|
|
8
|
+
pipeline;
|
|
9
|
+
renderPassDescriptor;
|
|
10
|
+
options;
|
|
11
|
+
gpuVertexBuffer;
|
|
12
|
+
gpuIndexBuffer;
|
|
13
|
+
projectionMatBuffer;
|
|
14
|
+
stageMatBuffer;
|
|
15
|
+
uniformBindGroup;
|
|
16
|
+
constructor(e) {
|
|
17
|
+
super(e), e.debug, this.options = e, this.gpu = this.canvasEle.getContext("webgpu"), this.curVertBufferLength = 256, this.curIndexBufferLength = 256;
|
|
18
|
+
}
|
|
19
|
+
async init() {
|
|
20
|
+
await this.initDevice(), this.initGpuBuffer(), this.initRenderPassDescriptor(), this.createPipeline(), this.initUniformBindGroup(), this.setRootTransform(1, 0, 0, 1, 0, 0), this.setProjectionMatrix();
|
|
21
|
+
}
|
|
22
|
+
draw() {
|
|
23
|
+
const { device: e, renderPassDescriptor: r, gpuVertexBuffer: t, gpuIndexBuffer: i, gpu: a, uniformBindGroup: u, indexCount: f, pipeline: c } = this, n = e.createCommandEncoder(), o = [...r.colorAttachments];
|
|
24
|
+
o?.[0]?.view && (o[0].view = a.getCurrentTexture().createView());
|
|
25
|
+
const s = n.beginRenderPass(r);
|
|
26
|
+
s.setPipeline(c), s.setVertexBuffer(0, t), s.setIndexBuffer(i, "uint32"), s.setBindGroup(0, u), s.drawIndexed(f), s.end();
|
|
27
|
+
const d = n.finish();
|
|
28
|
+
e.queue.submit([d]);
|
|
29
|
+
}
|
|
30
|
+
initUniformBindGroup() {
|
|
31
|
+
const e = this.device;
|
|
32
|
+
this.stageMatBuffer = e.createBuffer({
|
|
33
|
+
label: "stage-matrix-uniform-buffer",
|
|
34
|
+
size: 12 * Float32Array.BYTES_PER_ELEMENT,
|
|
35
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
36
|
+
}), this.projectionMatBuffer = e.createBuffer({
|
|
37
|
+
label: "projection-matrix-uniform-buffer",
|
|
38
|
+
size: 12 * Float32Array.BYTES_PER_ELEMENT,
|
|
39
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
40
|
+
}), this.uniformBindGroup = this.device.createBindGroup({
|
|
41
|
+
label: "my-uniform-bind-group",
|
|
42
|
+
layout: this.pipeline.getBindGroupLayout(0),
|
|
43
|
+
entries: [{
|
|
44
|
+
binding: 0,
|
|
45
|
+
resource: { buffer: this.stageMatBuffer }
|
|
46
|
+
}, {
|
|
47
|
+
binding: 1,
|
|
48
|
+
resource: { buffer: this.projectionMatBuffer }
|
|
49
|
+
}]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
initGpuBuffer() {
|
|
53
|
+
const e = this.device;
|
|
54
|
+
this.gpuVertexBuffer = e.createBuffer({
|
|
55
|
+
label: "my-gpu-vertex-buffer",
|
|
56
|
+
size: this.curVertBufferLength * 12,
|
|
57
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
58
|
+
}), this.gpuIndexBuffer = e.createBuffer({
|
|
59
|
+
label: "my-gpu-index-buffer",
|
|
60
|
+
size: this.curIndexBufferLength * Uint32Array.BYTES_PER_ELEMENT,
|
|
61
|
+
usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
updateBuffer() {
|
|
65
|
+
const e = this.device;
|
|
66
|
+
this.vertexCount > this.curVertBufferLength && (this.gpuVertexBuffer.destroy(), this.gpuVertexBuffer = e.createBuffer({
|
|
67
|
+
label: "my-gpu-vertex-buffer",
|
|
68
|
+
size: this.vertexCount * 12,
|
|
69
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
70
|
+
}), this.curVertBufferLength = this.vertexCount), e.queue.writeBuffer(this.gpuVertexBuffer, 0, this.vertFloatView.buffer), this.indexCount > this.curIndexBufferLength && (this.gpuIndexBuffer.destroy(), this.gpuIndexBuffer = e.createBuffer({
|
|
71
|
+
label: "my-gpu-index-buffer",
|
|
72
|
+
size: this.indexCount * Uint32Array.BYTES_PER_ELEMENT,
|
|
73
|
+
usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST
|
|
74
|
+
}), this.curIndexBufferLength = this.indexCount), e.queue.writeBuffer(this.gpuIndexBuffer, 0, this.indexBuffer.buffer);
|
|
75
|
+
}
|
|
76
|
+
setRootTransform(e, r, t, i, a, u) {
|
|
77
|
+
this.device.queue.writeBuffer(this.stageMatBuffer, 0, new Float32Array([
|
|
78
|
+
e,
|
|
79
|
+
r,
|
|
80
|
+
0,
|
|
81
|
+
0,
|
|
82
|
+
t,
|
|
83
|
+
i,
|
|
84
|
+
0,
|
|
85
|
+
0,
|
|
86
|
+
a,
|
|
87
|
+
u,
|
|
88
|
+
1,
|
|
89
|
+
0
|
|
90
|
+
]));
|
|
91
|
+
}
|
|
92
|
+
setProjectionMatrix() {
|
|
93
|
+
const e = this.canvasEle.width, r = this.canvasEle.height, t = 1 / e * 2, i = 1 / r * 2;
|
|
94
|
+
this.device.queue.writeBuffer(this.projectionMatBuffer, 0, new Float32Array([
|
|
95
|
+
t,
|
|
96
|
+
0,
|
|
97
|
+
0,
|
|
98
|
+
0,
|
|
99
|
+
0,
|
|
100
|
+
-i,
|
|
101
|
+
0,
|
|
102
|
+
0,
|
|
103
|
+
-1,
|
|
104
|
+
1,
|
|
105
|
+
1,
|
|
106
|
+
0
|
|
107
|
+
]));
|
|
108
|
+
}
|
|
109
|
+
createPipeline() {
|
|
110
|
+
this.pipeline = this.device.createRenderPipeline({
|
|
111
|
+
layout: "auto",
|
|
112
|
+
label: "my-render-pipeline",
|
|
113
|
+
vertex: {
|
|
114
|
+
module: this.device.createShaderModule({
|
|
115
|
+
code: l,
|
|
116
|
+
label: "my-vert-shader-module"
|
|
117
|
+
}),
|
|
118
|
+
entryPoint: "main",
|
|
119
|
+
buffers: [{
|
|
120
|
+
arrayStride: 12,
|
|
121
|
+
attributes: [{
|
|
122
|
+
shaderLocation: 0,
|
|
123
|
+
format: "float32x2",
|
|
124
|
+
offset: 0
|
|
125
|
+
}, {
|
|
126
|
+
shaderLocation: 1,
|
|
127
|
+
format: "unorm8x4",
|
|
128
|
+
offset: 2 * Float32Array.BYTES_PER_ELEMENT
|
|
129
|
+
}]
|
|
130
|
+
}]
|
|
131
|
+
},
|
|
132
|
+
fragment: {
|
|
133
|
+
module: this.device.createShaderModule({
|
|
134
|
+
code: g,
|
|
135
|
+
label: "my-frag-shader-module"
|
|
136
|
+
}),
|
|
137
|
+
entryPoint: "main",
|
|
138
|
+
targets: [{
|
|
139
|
+
format: navigator.gpu.getPreferredCanvasFormat(),
|
|
140
|
+
blend: {
|
|
141
|
+
alpha: {
|
|
142
|
+
srcFactor: "one",
|
|
143
|
+
dstFactor: "one-minus-src-alpha",
|
|
144
|
+
operation: "add"
|
|
145
|
+
},
|
|
146
|
+
color: {
|
|
147
|
+
srcFactor: "one",
|
|
148
|
+
dstFactor: "one-minus-src-alpha",
|
|
149
|
+
operation: "add"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}]
|
|
153
|
+
},
|
|
154
|
+
primitive: { topology: "triangle-list" }
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
async initDevice() {
|
|
158
|
+
const e = await (await navigator.gpu.requestAdapter())?.requestDevice();
|
|
159
|
+
e && (this.gpu.configure({
|
|
160
|
+
device: e,
|
|
161
|
+
format: navigator.gpu.getPreferredCanvasFormat(),
|
|
162
|
+
alphaMode: "premultiplied"
|
|
163
|
+
}), this.device = e);
|
|
164
|
+
}
|
|
165
|
+
initRenderPassDescriptor() {
|
|
166
|
+
const { backgroundColor: e = "", backgroundAlpha: r = 1 } = this.options, t = r, [i, a, u] = p(e).map((f) => f * t);
|
|
167
|
+
this.renderPassDescriptor = {
|
|
168
|
+
label: "my-render-pass-descriptor",
|
|
169
|
+
colorAttachments: [{
|
|
170
|
+
view: this.gpu.getCurrentTexture().createView(),
|
|
171
|
+
storeOp: "store",
|
|
172
|
+
loadOp: "clear",
|
|
173
|
+
clearValue: [
|
|
174
|
+
i,
|
|
175
|
+
a,
|
|
176
|
+
u,
|
|
177
|
+
t
|
|
178
|
+
]
|
|
179
|
+
}]
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
export {
|
|
184
|
+
E as WebGPURenderer
|
|
185
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BatchRenderer } from
|
|
2
|
-
import type { IApplicationOptions } from
|
|
1
|
+
import { BatchRenderer } from "./batchRenderer.js";
|
|
2
|
+
import type { IApplicationOptions } from "../types.js";
|
|
3
3
|
export declare class WebGLRenderer extends BatchRenderer {
|
|
4
4
|
gl: WebGLRenderingContext;
|
|
5
5
|
private program;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { BatchRenderer as g } from "./batchRenderer.js";
|
|
2
|
+
import { initShader as R, setupVertexLayout as h } from "./utils/webgl/initShader.js";
|
|
3
|
+
import { toRgbArray as B } from "./utils/index.js";
|
|
4
|
+
import { WebGLRenderTarget as l } from "./renderTarget.js";
|
|
5
|
+
var _ = class extends g {
|
|
6
|
+
gl;
|
|
7
|
+
program;
|
|
8
|
+
glVertexBuffer;
|
|
9
|
+
glIndexBuffer;
|
|
10
|
+
unifLoc;
|
|
11
|
+
targetA;
|
|
12
|
+
targetB;
|
|
13
|
+
quadBuffer;
|
|
14
|
+
constructor(t) {
|
|
15
|
+
super(t), t.debug, this.gl = this.canvasEle.getContext("webgl", { antialias: !0 }), this.gl.getExtension("OES_element_index_uint"), this.program = R(this), this.glVertexBuffer = this.gl.createBuffer(), this.glIndexBuffer = this.gl.createBuffer(), this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.glVertexBuffer), this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.glIndexBuffer), h(this.gl, this.program), this.unifLoc = {
|
|
16
|
+
u_root_transform: this.gl.getUniformLocation(this.program, "u_root_transform"),
|
|
17
|
+
u_projection_matrix: this.gl.getUniformLocation(this.program, "u_projection_matrix")
|
|
18
|
+
};
|
|
19
|
+
const r = t.backgroundAlpha ?? 0, [e, i, s] = B(t.backgroundColor ?? "");
|
|
20
|
+
this.gl.clearColor(e * r, i * r, s * r, r), this.setRootTransform(1, 0, 0, 1, 0, 0), this.setProjectionMatrix();
|
|
21
|
+
}
|
|
22
|
+
setProjectionMatrix() {
|
|
23
|
+
const t = this.canvasEle.width, r = this.canvasEle.height, e = 1 / t * 2, i = 1 / r * 2;
|
|
24
|
+
this.gl.uniformMatrix3fv(this.unifLoc.u_projection_matrix, !1, new Float32Array([
|
|
25
|
+
e,
|
|
26
|
+
0,
|
|
27
|
+
0,
|
|
28
|
+
0,
|
|
29
|
+
-i,
|
|
30
|
+
0,
|
|
31
|
+
-1,
|
|
32
|
+
1,
|
|
33
|
+
1
|
|
34
|
+
]));
|
|
35
|
+
}
|
|
36
|
+
setRootTransform(t, r, e, i, s, a) {
|
|
37
|
+
this.gl.uniformMatrix3fv(this.unifLoc.u_root_transform, !1, new Float32Array([
|
|
38
|
+
t,
|
|
39
|
+
r,
|
|
40
|
+
0,
|
|
41
|
+
e,
|
|
42
|
+
i,
|
|
43
|
+
0,
|
|
44
|
+
s,
|
|
45
|
+
a,
|
|
46
|
+
1
|
|
47
|
+
]));
|
|
48
|
+
}
|
|
49
|
+
updateBuffer() {
|
|
50
|
+
const t = this.gl;
|
|
51
|
+
t.bindBuffer(t.ARRAY_BUFFER, this.glVertexBuffer), t.bufferData(t.ARRAY_BUFFER, this.vertFloatView, t.DYNAMIC_DRAW), t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, this.glIndexBuffer), t.bufferData(t.ELEMENT_ARRAY_BUFFER, this.indexBuffer, t.DYNAMIC_DRAW);
|
|
52
|
+
}
|
|
53
|
+
draw() {
|
|
54
|
+
const t = this.gl, r = this.canvasEle.width, e = this.canvasEle.height;
|
|
55
|
+
if (this.filters.length === 0) {
|
|
56
|
+
t.bindFramebuffer(t.FRAMEBUFFER, null), t.viewport(0, 0, r, e), t.clear(t.COLOR_BUFFER_BIT), t.drawElements(t.TRIANGLES, this.indexCount, t.UNSIGNED_INT, 0);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.ensurePostResources(r, e);
|
|
60
|
+
const i = this.targetA, s = this.targetB;
|
|
61
|
+
i.bind(), t.clear(t.COLOR_BUFFER_BIT), t.drawElements(t.TRIANGLES, this.indexCount, t.UNSIGNED_INT, 0);
|
|
62
|
+
let a = i, o = s;
|
|
63
|
+
for (let f = 0; f < this.filters.length; f++) {
|
|
64
|
+
const n = f === this.filters.length - 1;
|
|
65
|
+
if (this.filters[f].apply(t, this.quadBuffer, a.texture, n ? null : o, r, e), !n) {
|
|
66
|
+
const u = a;
|
|
67
|
+
a = o, o = u;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
t.useProgram(this.program), t.bindBuffer(t.ARRAY_BUFFER, this.glVertexBuffer), t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, this.glIndexBuffer), h(t, this.program);
|
|
71
|
+
}
|
|
72
|
+
ensurePostResources(t, r) {
|
|
73
|
+
const e = this.gl;
|
|
74
|
+
this.quadBuffer || (this.quadBuffer = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.quadBuffer), e.bufferData(e.ARRAY_BUFFER, new Float32Array([
|
|
75
|
+
-1,
|
|
76
|
+
-1,
|
|
77
|
+
1,
|
|
78
|
+
-1,
|
|
79
|
+
-1,
|
|
80
|
+
1,
|
|
81
|
+
1,
|
|
82
|
+
1
|
|
83
|
+
]), e.STATIC_DRAW), this.targetA = new l(e), this.targetB = new l(e)), this.targetA?.resize(t, r), this.targetB?.resize(t, r);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
export {
|
|
87
|
+
_ as WebGLRenderer
|
|
88
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Shape } from
|
|
2
|
-
import { SHAPE_TYPE } from
|
|
3
|
-
import type { Point } from
|
|
1
|
+
import { Shape } from "./shape.js";
|
|
2
|
+
import { SHAPE_TYPE } from "../enums.js";
|
|
3
|
+
import type { Point } from "../vertex/point.js";
|
|
4
4
|
export declare class Circle extends Shape {
|
|
5
5
|
x: number;
|
|
6
6
|
y: number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SHAPE_TYPE as i } from "../enums.js";
|
|
2
|
+
import { Shape as e } from "./shape.js";
|
|
3
|
+
var u = class extends e {
|
|
4
|
+
x;
|
|
5
|
+
y;
|
|
6
|
+
radius;
|
|
7
|
+
type = i.CIRCLE;
|
|
8
|
+
constructor(s = 0, t = 0, r = 0) {
|
|
9
|
+
super(), this.x = s, this.y = t, this.radius = r;
|
|
10
|
+
}
|
|
11
|
+
contains(s) {
|
|
12
|
+
return (s.x - this.x) * (s.x - this.x) + (s.y - this.y) * (s.y - this.y) < this.radius * this.radius;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
u as Circle
|
|
17
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Shape } from
|
|
2
|
-
import { SHAPE_TYPE } from
|
|
3
|
-
import type { Point } from
|
|
1
|
+
import { Shape } from "./shape.js";
|
|
2
|
+
import { SHAPE_TYPE } from "../enums.js";
|
|
3
|
+
import type { Point } from "../vertex/point.js";
|
|
4
4
|
export declare class Ellipse extends Shape {
|
|
5
5
|
x: number;
|
|
6
6
|
y: number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SHAPE_TYPE as a } from "../enums.js";
|
|
2
|
+
import { Shape as e } from "./shape.js";
|
|
3
|
+
var d = class extends e {
|
|
4
|
+
x;
|
|
5
|
+
y;
|
|
6
|
+
radiusX;
|
|
7
|
+
radiusY;
|
|
8
|
+
type = a.ELLIPSE;
|
|
9
|
+
constructor(s = 0, i = 0, t = 0, r = 0) {
|
|
10
|
+
super(), this.x = s, this.y = i, this.radiusX = t, this.radiusY = r;
|
|
11
|
+
}
|
|
12
|
+
contains(s) {
|
|
13
|
+
return (s.x - this.x) * (s.x - this.x) / (this.radiusX * this.radiusX) + (s.y - this.y) * (s.y - this.y) / (this.radiusY * this.radiusY) < 1;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
d as Ellipse
|
|
18
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Circle } from
|
|
2
|
-
import { Ellipse } from
|
|
3
|
-
import { Polygon } from
|
|
4
|
-
import { Rectangle } from
|
|
5
|
-
import { Shape } from
|
|
6
|
-
import { RoundedRectangle } from
|
|
1
|
+
import { Circle } from "./circle.js";
|
|
2
|
+
import { Ellipse } from "./ellipse.js";
|
|
3
|
+
import { Polygon } from "./polygon.js";
|
|
4
|
+
import { Rectangle } from "./rectangle.js";
|
|
5
|
+
import { Shape } from "./shape.js";
|
|
6
|
+
import { RoundedRectangle } from "./roundedRectangle.js";
|
|
7
7
|
export { Shape, Circle, Ellipse, Polygon, Rectangle, RoundedRectangle };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Shape } from
|
|
2
|
-
import { SHAPE_TYPE } from
|
|
3
|
-
import type { Point } from
|
|
1
|
+
import { Shape } from "./shape.js";
|
|
2
|
+
import { SHAPE_TYPE } from "../enums.js";
|
|
3
|
+
import type { Point } from "../vertex/point.js";
|
|
4
4
|
export declare class Polygon extends Shape {
|
|
5
5
|
points: number[];
|
|
6
6
|
closeStroke: boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SHAPE_TYPE as a } from "../enums.js";
|
|
2
|
+
import { Shape as p } from "./shape.js";
|
|
3
|
+
var I = class extends p {
|
|
4
|
+
points = [];
|
|
5
|
+
closeStroke = !1;
|
|
6
|
+
type = a.POLYGON;
|
|
7
|
+
constructor(t = []) {
|
|
8
|
+
super(), this.points = t;
|
|
9
|
+
}
|
|
10
|
+
isIntersect(t, s, e, r, o, i) {
|
|
11
|
+
if (r > s && i > s || r < s && i < s || e < t && o < t) return !1;
|
|
12
|
+
if (e > t && o > t) return !0;
|
|
13
|
+
const c = r - i, n = o - e, f = s - i;
|
|
14
|
+
return o - n / c * f > t;
|
|
15
|
+
}
|
|
16
|
+
contains(t) {
|
|
17
|
+
const s = this.points.length;
|
|
18
|
+
let e = 0;
|
|
19
|
+
for (let n = 2; n <= s - 2; n += 2) {
|
|
20
|
+
const f = this.points[n - 2], l = this.points[n - 1], h = this.points[n], u = this.points[n + 1];
|
|
21
|
+
this.isIntersect(t.x, t.y, f, l, h, u) && e++;
|
|
22
|
+
}
|
|
23
|
+
const r = this.points[0], o = this.points[1], i = this.points[s - 2], c = this.points[s - 1];
|
|
24
|
+
return this.isIntersect(t.x, t.y, r, o, i, c) && e++, e % 2 !== 0;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
I as Polygon
|
|
29
|
+
};
|