q5 2.13.2 → 2.13.9
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/README.md +3 -27
- package/defaultFont-msdf.json +1 -0
- package/defaultFont.png +0 -0
- package/package.json +1 -1
- package/q5.d.ts +32 -5
- package/q5.js +74 -74
- package/q5.min.js +1 -1
- package/src/q5-2d-drawing.js +7 -7
- package/src/q5-2d-text.js +1 -1
- package/src/q5-core.js +8 -7
- package/src/q5-input.js +2 -2
- package/src/q5-math.js +2 -1
- package/src/q5-webgpu-canvas.js +13 -20
- package/src/q5-webgpu-drawing.js +9 -6
- package/src/q5-webgpu-image.js +4 -7
- package/src/q5-webgpu-text.js +28 -23
package/README.md
CHANGED
|
@@ -65,35 +65,11 @@ q5 is open source and anyone can use it for free under the terms of the LGPL (ju
|
|
|
65
65
|
|
|
66
66
|
We need your support though! If you enjoy using q5.js, please donate via [GitHub Sponsors](https://github.com/sponsors/quinton-ashley) or [Patreon](https://www.patreon.com/p5play).
|
|
67
67
|
|
|
68
|
-
## Size Comparison
|
|
69
|
-
|
|
70
|
-
q5 is 98% smaller than p5.
|
|
71
|
-
|
|
72
|
-
p5.js is nearly 5MB in size due to lengthy JSDoc comments, [the WebGL render, and the dependencies corejs and opentype](https://github.com/processing/p5.js/issues/6776#issuecomment-1918238317).
|
|
73
|
-
|
|
74
|
-
q5's JSDoc comments are stored separately in the q5.d.ts file, which includes type definitions for Visual Studio Code autocompletion. q5 also has no dependencies.
|
|
75
|
-
|
|
76
|
-
npm packages:
|
|
77
|
-
|
|
78
|
-
- p5 **7800kb** ⚠️
|
|
79
|
-
- @types/p5 1070kb
|
|
80
|
-
- q5 415kb
|
|
81
|
-
|
|
82
|
-
Unminified:
|
|
83
|
-
|
|
84
|
-
- p5.js **5112kb** ⚠️
|
|
85
|
-
- p5.sound.js 488kb
|
|
86
|
-
- q5.js 117kb
|
|
87
|
-
|
|
88
|
-
Minified:
|
|
89
|
-
|
|
90
|
-
- p5.min.js 1034kb ⚠️
|
|
91
|
-
- p5.sound.min.js 200kb
|
|
92
|
-
- q5.min.js **73kb** 🎉
|
|
93
|
-
|
|
94
68
|
## Modular Use
|
|
95
69
|
|
|
96
|
-
|
|
70
|
+
q5 has no dependencies and the default bundle is just 126kb unminified.
|
|
71
|
+
|
|
72
|
+
But for extremely lightweight use, you can load a subset of scripts from the `src` folder. See the [src/readme.md](src/readme.md) for more info on modular use.
|
|
97
73
|
|
|
98
74
|
## Contributing
|
|
99
75
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"pages":["defaultFont.png"],"chars":"id index char width height xoffset yoffset xadvance chnl x y page\n124 98 \"|\" 8 49 2 1 11 15 0 0 0\n253 190 \"ý\" 26 49 -2 2 22 15 0 50 0\n106 80 \"j\" 16 48 -6 3 11 15 9 0 0\n254 191 \"þ\" 25 48 2 2 27 15 26 0 0\n87 61 \"W\" 46 36 -1 4 43 15 0 100 0\n192 129 \"À\" 33 46 -2 -6 30 15 27 49 0\n193 130 \"Á\" 33 46 -2 -6 30 15 52 0 0\n194 131 \"Â\" 33 46 -2 -6 30 15 0 137 0\n199 136 \"Ç\" 28 46 0 4 28 15 0 184 0\n200 137 \"È\" 21 46 2 -6 23 15 0 231 0\n201 138 \"É\" 21 46 2 -6 23 15 0 278 0\n202 139 \"Ê\" 21 46 2 -6 23 15 0 325 0\n204 141 \"Ì\" 15 46 -1 -6 12 15 0 372 0\n205 142 \"Í\" 15 46 -1 -6 12 15 0 419 0\n206 143 \"Î\" 17 46 -2 -6 12 15 0 466 0\n210 147 \"Ò\" 34 46 0 -6 34 15 16 372 0\n211 148 \"Ó\" 34 46 0 -6 34 15 16 419 0\n212 149 \"Ô\" 34 46 0 -6 34 15 18 466 0\n217 154 \"Ù\" 28 46 2 -6 31 15 22 231 0\n218 155 \"Ú\" 28 46 2 -6 31 15 29 184 0\n219 156 \"Û\" 28 46 2 -6 31 15 34 137 0\n221 158 \"Ý\" 29 46 -2 -6 25 15 61 47 0\n255 192 \"ÿ\" 26 46 -2 5 22 15 86 0 0\n81 55 \"Q\" 35 45 0 4 34 15 22 278 0\n213 150 \"Õ\" 34 45 0 -4 34 15 51 231 0\n36 10 \"$\" 22 44 1 0 25 15 58 184 0\n195 132 \"Ã\" 33 44 -2 -4 30 15 22 324 0\n209 146 \"Ñ\" 30 44 2 -4 34 15 63 94 0\n214 151 \"Ö\" 34 44 0 -3 34 15 63 139 0\n220 157 \"Ü\" 28 44 2 -3 31 15 91 47 0\n40 14 \"(\" 14 43 1 4 14 15 81 184 0\n41 15 \")\" 15 43 -2 4 14 15 113 0 0\n91 65 \"[\" 12 43 2 4 14 15 94 92 0\n93 67 \"]\" 12 43 -1 4 14 15 51 369 0\n123 97 \"{\" 15 43 0 4 14 15 56 324 0\n125 99 \"}\" 15 43 -1 4 14 15 58 277 0\n196 133 \"Ä\" 33 43 -2 -3 30 15 51 413 0\n197 134 \"Å\" 33 43 -2 -3 30 15 64 368 0\n203 140 \"Ë\" 21 43 2 -3 23 15 72 321 0\n207 144 \"Ï\" 17 43 -2 -3 12 15 74 277 0\n47 21 \"/\" 23 41 -3 4 18 15 86 228 0\n92 66 \"\\\\\" 23 41 -3 4 17 15 96 184 0\n198 135 \"Æ\" 41 36 -2 4 39 15 98 136 0\n64 38 \"@\" 40 40 2 4 43 15 107 92 0\n223 160 \"ß\" 24 39 2 2 25 15 120 44 0\n224 161 \"à\" 22 39 0 2 23 15 129 0 0\n225 162 \"á\" 22 39 0 2 23 15 92 270 0\n226 163 \"â\" 22 39 0 2 23 15 110 226 0\n229 166 \"å\" 22 39 0 1 23 15 145 40 0\n232 169 \"è\" 24 39 0 2 24 15 152 0 0\n233 170 \"é\" 24 39 0 2 24 15 120 173 0\n234 171 \"ê\" 24 39 0 2 24 15 140 133 0\n242 179 \"ò\" 27 39 0 2 27 15 148 80 0\n243 180 \"ó\" 27 39 0 2 27 15 168 40 0\n244 181 \"ô\" 27 39 0 2 27 15 177 0 0\n249 186 \"ù\" 23 39 1 2 26 15 53 457 0\n250 187 \"ú\" 23 39 1 2 26 15 77 457 0\n251 188 \"û\" 23 39 1 2 26 15 85 412 0\n37 11 \"%\" 38 37 0 4 37 15 94 310 0\n98 72 \"b\" 25 38 2 2 27 15 115 266 0\n100 74 \"d\" 25 38 0 2 27 15 133 213 0\n102 76 \"f\" 18 38 -1 2 15 15 145 173 0\n103 77 \"g\" 25 38 0 13 27 15 101 452 0\n104 78 \"h\" 23 38 2 2 26 15 98 348 0\n107 81 \"k\" 23 38 2 2 23 15 109 387 0\n108 82 \"l\" 8 38 2 2 11 15 122 348 0\n112 86 \"p\" 25 38 2 13 27 15 131 348 0\n113 87 \"q\" 25 38 0 13 27 15 133 305 0\n216 153 \"Ø\" 34 38 0 3 34 15 141 252 0\n230 167 \"æ\" 38 28 0 13 38 15 159 212 0\n236 173 \"ì\" 13 38 -2 2 11 15 164 173 0\n237 174 \"í\" 13 38 0 2 11 15 47 96 0\n238 175 \"î\" 17 38 -3 2 11 15 165 120 0\n240 177 \"ð\" 25 38 0 2 26 15 176 80 0\n38 12 \"&\" 37 37 1 4 37 15 196 40 0\n48 22 \"0\" 25 37 0 4 25 15 205 0 0\n51 25 \"3\" 23 37 1 4 25 15 231 0 0\n54 28 \"6\" 24 37 0 4 25 15 178 159 0\n56 30 \"8\" 24 37 0 4 25 15 183 119 0\n57 31 \"9\" 24 37 0 4 25 15 202 78 0\n63 37 \"?\" 19 37 1 4 20 15 127 426 0\n67 41 \"C\" 28 37 0 4 28 15 133 387 0\n71 45 \"G\" 30 37 0 4 31 15 157 344 0\n77 51 \"M\" 37 36 2 4 41 15 127 464 0\n79 53 \"O\" 34 37 0 4 34 15 147 425 0\n83 57 \"S\" 24 37 1 4 24 15 162 382 0\n105 79 \"i\" 9 37 1 3 11 15 165 463 0\n109 83 \"m\" 37 27 2 13 39 15 175 463 0\n121 95 \"y\" 26 37 -2 13 22 15 182 420 0\n169 106 \"©\" 37 37 2 4 40 15 187 382 0\n174 111 \"®\" 37 37 2 4 40 15 209 420 0\n191 128 \"¿\" 19 37 1 13 20 15 159 291 0\n227 164 \"ã\" 22 37 0 4 23 15 176 241 0\n231 168 \"ç\" 21 37 0 13 21 15 198 197 0\n245 182 \"õ\" 27 37 0 4 27 15 203 157 0\n33 7 \"!\" 9 36 2 4 13 15 208 116 0\n49 23 \"1\" 22 36 2 4 25 15 218 116 0\n50 24 \"2\" 24 36 0 4 25 15 227 78 0\n52 26 \"4\" 27 36 -2 4 25 15 234 38 0\n53 27 \"5\" 22 36 2 4 25 15 255 0 0\n55 29 \"7\" 25 36 0 4 25 15 213 458 0\n65 39 \"A\" 33 36 -2 4 30 15 239 458 0\n66 40 \"B\" 24 36 2 4 26 15 179 279 0\n68 42 \"D\" 30 36 2 4 32 15 199 235 0\n69 43 \"E\" 21 36 2 4 23 15 220 195 0\n70 44 \"F\" 20 36 2 4 22 15 231 153 0\n72 46 \"H\" 28 36 2 4 32 15 241 115 0\n73 47 \"I\" 14 36 -1 4 12 15 252 75 0\n74 48 \"J\" 16 36 -2 4 17 15 262 37 0\n75 49 \"K\" 27 36 2 4 27 15 278 0 0\n76 50 \"L\" 21 36 2 4 22 15 267 74 0\n78 52 \"N\" 30 36 2 4 34 15 279 37 0\n80 54 \"P\" 24 36 2 4 26 15 306 0 0\n82 56 \"R\" 27 36 2 4 27 15 188 316 0\n84 58 \"T\" 26 36 -1 4 24 15 204 272 0\n85 59 \"U\" 28 36 2 4 31 15 230 232 0\n86 60 \"V\" 32 36 -2 4 28 15 242 190 0\n88 62 \"X\" 30 36 -1 4 27 15 252 152 0\n89 63 \"Y\" 29 36 -2 4 25 15 270 111 0\n90 64 \"Z\" 28 36 -1 4 26 15 289 74 0\n119 93 \"w\" 36 27 -1 13 33 15 188 353 0\n161 4 \"¡\" 9 36 2 13 13 15 310 37 0\n162 5 \"¢\" 21 36 2 5 25 15 216 309 0\n163 6 \"£\" 24 36 0 4 25 15 231 269 0\n165 102 \"¥\" 26 36 -1 4 25 15 225 346 0\n208 145 \"Ð\" 33 36 -1 4 32 15 225 383 0\n222 159 \"Þ\" 24 36 2 4 26 15 247 420 0\n228 165 \"ä\" 22 36 0 5 23 15 238 306 0\n235 172 \"ë\" 24 36 0 5 24 15 256 269 0\n241 178 \"ñ\" 23 36 2 4 26 15 252 343 0\n246 183 \"ö\" 27 36 0 5 27 15 261 306 0\n252 189 \"ü\" 23 36 1 5 26 15 259 380 0\n128 0 \"\" 26 35 2 5 29 15 276 343 0\n239 176 \"ï\" 17 35 -3 5 11 15 272 417 0\n116 90 \"t\" 18 34 -1 7 16 15 283 379 0\n35 9 \"#\" 29 33 -1 4 27 15 259 227 0\n59 33 \";\" 11 33 -1 13 10 15 275 189 0\n248 185 \"ø\" 29 31 -1 11 27 15 283 148 0\n960 362 \"π\" 31 27 -2 13 29 15 300 111 0\n58 32 \":\" 9 28 0 13 10 15 318 74 0\n97 71 \"a\" 22 28 0 13 23 15 320 37 0\n99 73 \"c\" 21 28 0 13 21 15 331 0 0\n101 75 \"e\" 24 28 0 13 24 15 281 261 0\n111 85 \"o\" 27 28 0 13 27 15 328 66 0\n115 89 \"s\" 19 28 0 13 19 15 343 29 0\n110 84 \"n\" 23 27 2 13 26 15 353 0 0\n114 88 \"r\" 16 27 2 13 16 15 287 180 0\n117 91 \"u\" 23 27 1 13 26 15 289 290 0\n118 92 \"v\" 26 27 -2 13 22 15 289 208 0\n120 94 \"x\" 24 27 -1 13 21 15 304 180 0\n122 96 \"z\" 23 27 -1 13 21 15 313 139 0\n60 34 \"<\" 23 26 4 12 31 15 332 95 0\n62 36 \">\" 23 26 4 12 31 15 306 236 0\n126 100 \"~\" 26 11 3 19 31 15 53 501 0\n247 184 \"÷\" 25 26 3 12 31 15 306 263 0\n43 17 \"+\" 25 25 3 12 31 15 316 208 0\n61 35 \"=\" 25 17 3 17 31 15 101 491 0\n94 68 \"^\" 25 23 3 4 31 15 289 318 0\n179 116 \"³\" 16 24 1 4 17 15 289 236 0\n95 69 \"_\" 23 7 -2 40 19 15 120 84 0\n178 115 \"²\" 16 23 0 4 17 15 109 426 0\n185 122 \"¹\" 16 23 1 4 16 15 313 290 0\n215 152 \"×\" 23 23 4 13 31 15 330 234 0\n186 123 \"º\" 20 21 0 4 20 15 175 491 0\n42 16 \"*\" 20 20 0 4 19 15 329 167 0\n8220 532 \"“\" 17 14 25 4 42 15 178 197 0\n8221 533 \"”\" 17 14 0 4 42 15 159 329 0\n45 19 \"-\" 16 7 1 22 18 15 148 120 0\n176 113 \"°\" 16 16 0 4 17 15 332 122 0\n44 18 \",\" 10 15 -1 31 10 15 98 387 0\n34 8 \"\\\"\" 14 14 2 4 18 15 80 497 0\n39 13 \"'\" 8 14 1 4 11 15 179 316 0\n8216 528 \"‘\" 10 14 32 4 42 15 196 495 0\n8217 529 \"’\" 10 14 0 4 42 15 207 495 0\n96 70 \"`\" 13 11 0 2 12 15 127 501 0\n180 117 \"´\" 13 11 1 2 13 15 141 501 0\n46 20 \".\" 9 9 0 31 10 15 98 173 0\n183 120 \"·\" 9 9 0 20 10 15 159 241 0","info":{"face":"YaHei","size":42},"common":{"lineHeight":45,"base":36,"scaleW":512,"scaleH":512},"kernings":"first second amount\n34 114 -1\n34 115 -1\n39 114 -1\n39 115 -1\n40 106 5\n42 65 -4\n42 74 -3\n42 99 -2\n42 100 -2\n42 101 -2\n42 103 -2\n42 111 -2\n42 113 -2\n44 8216 -5\n44 8217 -5\n44 8220 -5\n44 8221 -5\n46 8216 -5\n46 8217 -4\n46 8220 -5\n46 8221 -4\n65 42 -3\n65 44 1\n65 59 1\n65 67 -1\n65 71 -1\n65 74 2\n65 79 -1\n65 84 -3\n65 85 -1\n65 86 -3\n65 87 -2\n65 89 -3\n65 90 1\n65 116 -1\n65 118 -1\n65 119 -1\n65 121 -1\n65 8216 -3\n65 8217 -4\n65 8220 -3\n65 8221 -4\n66 84 -2\n66 89 -1\n67 63 0\n67 67 -1\n67 71 -1\n67 79 -1\n67 81 -1\n68 44 -3\n68 46 -3\n68 65 -1\n68 84 -2\n68 88 -1\n68 90 -1\n69 65 0\n69 74 1\n69 84 0\n69 87 1\n69 88 0\n70 44 -3\n70 46 -3\n70 65 -3\n70 74 -1\n70 83 -1\n70 84 0\n70 97 -2\n70 102 0\n71 84 -1\n71 86 -1\n71 121 -1\n74 44 -2\n74 46 -2\n74 65 -1\n74 74 -1\n74 97 -1\n74 224 -1\n74 225 -1\n75 44 1\n75 59 1\n75 67 -2\n75 71 -2\n75 74 2\n75 79 -2\n75 81 -2\n75 88 1\n75 90 1\n75 99 -1\n75 100 -1\n75 101 -1\n75 103 -1\n75 111 -1\n75 113 -1\n75 116 -1\n75 118 -2\n75 119 -1\n75 121 -2\n75 232 -1\n75 233 -1\n75 234 -1\n75 237 -1\n75 242 -1\n75 243 -1\n76 42 -5\n76 63 -2\n76 65 1\n76 67 -1\n76 71 -1\n76 74 2\n76 79 -2\n76 81 -2\n76 84 -3\n76 85 -1\n76 86 -3\n76 87 -1\n76 89 -3\n76 90 1\n76 116 -1\n76 118 -2\n76 119 -1\n76 121 -2\n76 8216 -3\n76 8217 -3\n76 8220 -3\n76 8221 -3\n79 44 -2\n79 46 -2\n79 65 -1\n79 74 0\n79 84 -2\n79 88 -1\n79 89 -1\n79 90 -1\n80 44 -7\n80 46 -7\n80 65 -4\n80 71 0\n80 74 -3\n80 87 1\n80 88 -1\n80 97 -1\n80 99 -2\n80 100 -2\n80 101 -2\n80 103 -2\n80 111 -2\n80 113 -2\n80 224 -1\n80 225 -1\n80 232 -2\n80 233 -2\n80 234 -2\n80 242 -2\n80 243 -2\n81 44 -2\n81 46 -3\n81 65 -1\n81 84 -2\n81 88 -1\n81 89 0\n81 90 -1\n82 59 2\n82 67 -1\n82 71 -1\n82 74 1\n82 79 0\n82 81 0\n82 84 -1\n82 89 -1\n82 99 -1\n82 100 -1\n82 101 -1\n82 103 -1\n82 111 -1\n82 113 -1\n82 232 -1\n82 233 -1\n82 234 -1\n82 242 -1\n82 243 -1\n83 116 -1\n83 118 -1\n83 119 -1\n83 121 -1\n84 44 -3\n84 46 -4\n84 58 -1\n84 59 -1\n84 65 -3\n84 67 -2\n84 71 -2\n84 74 -3\n84 79 -2\n84 81 -2\n84 84 1\n84 86 1\n84 87 1\n84 88 0\n84 89 1\n84 97 -5\n84 99 -5\n84 100 -5\n84 101 -5\n84 102 -2\n84 103 -5\n84 109 -4\n84 110 -4\n84 111 -5\n84 112 -4\n84 113 -5\n84 114 -4\n84 115 -3\n84 117 -4\n84 118 -2\n84 119 -3\n84 120 -4\n84 121 -3\n84 122 -3\n84 224 -5\n84 225 -5\n84 232 -5\n84 233 -5\n84 234 -5\n84 237 -1\n84 242 -5\n84 243 -5\n84 249 -4\n84 250 -4\n84 252 -4\n84 8217 1\n84 8221 1\n85 65 -1\n86 44 -5\n86 46 -5\n86 65 -3\n86 67 -1\n86 71 -1\n86 74 -2\n86 79 0\n86 81 -1\n86 83 -1\n86 84 1\n86 97 -3\n86 99 -3\n86 100 -3\n86 101 -3\n86 103 -3\n86 109 -2\n86 110 -2\n86 111 -3\n86 112 -2\n86 113 -3\n86 114 -2\n86 115 -1\n86 117 -2\n86 224 -3\n86 225 -3\n86 232 -3\n86 233 -3\n86 234 -3\n86 242 -3\n86 243 -3\n86 249 -2\n86 250 -2\n86 252 -2\n87 44 -3\n87 46 -3\n87 65 -2\n87 84 1\n87 97 -2\n87 99 -1\n87 100 -1\n87 101 -1\n87 103 -1\n87 111 -1\n87 113 -1\n87 224 -2\n87 225 -2\n87 232 -1\n87 233 -1\n87 234 -1\n87 242 -1\n87 243 -1\n88 44 1\n88 46 1\n88 59 2\n88 67 -1\n88 71 -1\n88 74 2\n88 79 -1\n88 81 -1\n88 84 1\n89 44 -4\n89 46 -4\n89 65 -4\n89 67 -1\n89 71 -1\n89 74 -1\n89 79 -1\n89 81 -1\n89 83 -1\n89 84 1\n89 97 -4\n89 99 -4\n89 100 -4\n89 101 -4\n89 102 -1\n89 103 -4\n89 109 -3\n89 110 -3\n89 111 -4\n89 112 -3\n89 113 -4\n89 114 -3\n89 115 -3\n89 117 -3\n89 224 -4\n89 225 -4\n89 232 -4\n89 233 -4\n89 234 -4\n89 242 -4\n89 243 -4\n89 249 -3\n89 250 -3\n89 252 -3\n90 74 2\n90 84 1\n90 121 -1\n91 106 5\n98 97 -1\n98 102 0\n98 120 -1\n98 224 -1\n98 225 -1\n99 74 2\n99 84 -2\n99 89 -2\n101 34 -2\n101 39 -2\n102 41 3\n102 44 -3\n102 45 -2\n102 46 -3\n102 58 2\n102 59 2\n102 63 1\n102 93 3\n102 98 0\n102 104 0\n102 116 1\n102 118 1\n102 119 1\n102 120 0\n102 121 1\n102 125 2\n102 236 1\n102 8216 2\n102 8217 2\n102 8220 2\n102 8221 2\n103 106 1\n106 106 1\n107 44 2\n107 45 -3\n107 46 2\n107 58 2\n107 59 2\n107 99 -1\n107 100 -1\n107 101 -1\n107 103 -1\n107 111 -1\n107 113 -1\n107 116 0\n107 232 -1\n107 233 -1\n107 234 -1\n107 242 -1\n107 243 -1\n110 34 -2\n110 39 -2\n111 34 -3\n111 39 -3\n111 97 -1\n111 102 -1\n111 120 -1\n111 224 -1\n111 225 -1\n111 8216 -1\n111 8217 -3\n111 8220 -2\n111 8221 -3\n112 97 -1\n112 102 -1\n112 120 -1\n112 224 -1\n112 225 -1\n112 8216 -3\n112 8217 -3\n112 8220 -1\n112 8221 -3\n113 106 2\n114 44 -4\n114 45 -3\n114 46 -4\n114 58 2\n114 59 2\n114 99 -1\n114 100 -1\n114 101 -1\n114 102 1\n114 103 -1\n114 109 0\n114 110 0\n114 111 -1\n114 113 -1\n114 115 0\n114 116 1\n114 118 2\n114 119 2\n114 120 1\n114 121 2\n114 122 1\n114 232 -1\n114 233 -1\n114 234 -1\n114 242 -1\n114 243 -1\n114 8216 4\n114 8217 3\n114 8220 4\n114 8221 3\n116 45 -3\n116 63 -1\n116 99 -1\n116 100 -1\n116 101 0\n116 103 0\n116 111 0\n116 113 0\n116 120 1\n116 232 0\n116 233 0\n116 234 0\n116 242 0\n116 243 0\n117 34 -1\n117 39 -1\n118 44 -3\n118 46 -3\n118 97 -1\n118 99 0\n118 100 0\n118 101 0\n118 103 0\n118 111 0\n118 113 0\n118 224 -1\n118 225 -1\n118 232 0\n118 233 0\n118 234 0\n118 242 0\n118 243 0\n119 44 -2\n119 46 -2\n119 99 0\n119 100 0\n119 101 0\n119 103 0\n119 111 0\n119 113 0\n119 232 0\n119 233 0\n119 234 0\n119 242 0\n119 243 0\n120 99 0\n120 100 0\n120 101 0\n120 103 0\n120 111 0\n120 113 0\n120 232 0\n120 233 0\n120 234 0\n120 242 0\n120 243 0\n121 34 1\n121 39 1\n121 44 -2\n121 46 -3\n121 63 -2\n121 99 0\n121 100 0\n121 101 0\n121 102 0\n121 103 0\n121 111 0\n121 113 0\n121 116 0\n121 232 0\n121 233 0\n121 234 0\n121 242 0\n121 243 0\n123 106 4\n242 97 -1\n242 102 -1\n242 120 -1\n243 97 -1\n243 102 -1\n243 120 -1\n8216 65 -5\n8216 67 -1\n8216 74 -3\n8216 84 2\n8216 99 -3\n8216 100 -4\n8216 101 -3\n8216 103 -3\n8216 111 -3\n8216 115 -2\n8216 8216 -4\n8217 44 -2\n8217 46 -2\n8217 65 -4\n8217 74 -4\n8217 84 2\n8217 97 -2\n8217 99 -4\n8217 100 -4\n8217 101 -4\n8217 103 -4\n8217 111 -4\n8217 113 -3\n8217 115 -3\n8217 8217 -4\n8220 44 -2\n8220 46 -2\n8220 65 -5\n8220 74 -4\n8220 84 2\n8220 99 -3\n8220 100 -3\n8220 101 -3\n8220 103 -3\n8220 115 -2\n8221 44 -2\n8221 46 -2\n8221 65 -3\n8221 84 2\n8221 99 -1\n8221 100 -4\n8221 101 -4\n8221 103 -4\n8221 111 -4\n8221 115 -3"}
|
package/defaultFont.png
ADDED
|
Binary file
|
package/package.json
CHANGED
package/q5.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ function draw() {
|
|
|
18
18
|
function draw(): void;
|
|
19
19
|
|
|
20
20
|
/** ⭐️
|
|
21
|
-
* The setup function is
|
|
21
|
+
* The setup function is run once, when the program starts.
|
|
22
22
|
* @example
|
|
23
23
|
function setup() {
|
|
24
24
|
createCanvas(200, 100);
|
|
@@ -76,7 +76,7 @@ function draw() {
|
|
|
76
76
|
circle(frameCount * 5, 100, 80);
|
|
77
77
|
}
|
|
78
78
|
function mousePressed() {
|
|
79
|
-
redraw(
|
|
79
|
+
redraw(10);
|
|
80
80
|
}
|
|
81
81
|
*/
|
|
82
82
|
function redraw(n?: number): void;
|
|
@@ -97,7 +97,12 @@ function mousePressed() {
|
|
|
97
97
|
function loop(): void;
|
|
98
98
|
|
|
99
99
|
/** ⭐️
|
|
100
|
-
* Sets the target frame rate or gets
|
|
100
|
+
* Sets the target frame rate or gets an approximation of the
|
|
101
|
+
* sketch's current frame rate.
|
|
102
|
+
*
|
|
103
|
+
* Even when the sketch is running at a consistent frame rate,
|
|
104
|
+
* the current frame rate value will fluctuate. Use your web browser's
|
|
105
|
+
* developer tools for more accurate performance analysis.
|
|
101
106
|
* @param {number} [hertz] target frame rate, default is 60
|
|
102
107
|
* @returns {number} current frame rate
|
|
103
108
|
* @example
|
|
@@ -133,8 +138,10 @@ function draw() {
|
|
|
133
138
|
|
|
134
139
|
/** ⭐️
|
|
135
140
|
* Gets the current FPS, in terms of how many frames could be generated
|
|
136
|
-
* in one second, which can be higher than the target frame rate.
|
|
137
|
-
*
|
|
141
|
+
* in one second, which can be higher than the target frame rate.
|
|
142
|
+
*
|
|
143
|
+
* Use your web browser's developer tools for more in-depth
|
|
144
|
+
* performance analysis.
|
|
138
145
|
* @returns {number} frames per second
|
|
139
146
|
* @example
|
|
140
147
|
function draw() {
|
|
@@ -158,6 +165,24 @@ function draw() {
|
|
|
158
165
|
*/
|
|
159
166
|
function log(message: any): void;
|
|
160
167
|
|
|
168
|
+
/** ⭐️
|
|
169
|
+
* Runs after each `draw` function call and post draw hooks.
|
|
170
|
+
*
|
|
171
|
+
* Useful for adding post-processing effects when it's not possible
|
|
172
|
+
* to do so at the end of the `draw` function, such as when using
|
|
173
|
+
* libraries like p5play that draw to the canvas after the `draw`
|
|
174
|
+
* function is run.
|
|
175
|
+
* @example
|
|
176
|
+
function draw() {
|
|
177
|
+
background(200);
|
|
178
|
+
circle(frameCount % 200, 100, 80);
|
|
179
|
+
}
|
|
180
|
+
function postProcess() {
|
|
181
|
+
filter(INVERT);
|
|
182
|
+
}
|
|
183
|
+
*/
|
|
184
|
+
function postProcess(): void;
|
|
185
|
+
|
|
161
186
|
/** ⭐️
|
|
162
187
|
* The width of the window.
|
|
163
188
|
* @example
|
|
@@ -1871,6 +1896,8 @@ noCursor();
|
|
|
1871
1896
|
|
|
1872
1897
|
/** 🧮
|
|
1873
1898
|
* Calculates the distance between two points.
|
|
1899
|
+
*
|
|
1900
|
+
* This function also accepts two objects with `x` and `y` properties.
|
|
1874
1901
|
* @param {number} x1 x-coordinate of the first point
|
|
1875
1902
|
* @param {number} y1 y-coordinate of the first point
|
|
1876
1903
|
* @param {number} x2 x-coordinate of the second point
|
package/q5.js
CHANGED
|
@@ -20,14 +20,14 @@ function Q5(scope, parent, renderer) {
|
|
|
20
20
|
let autoLoaded = scope == 'auto';
|
|
21
21
|
scope ??= 'global';
|
|
22
22
|
if (scope == 'auto') {
|
|
23
|
-
if (!(window.setup || window.draw)) return;
|
|
23
|
+
if (!(window.setup || window.update || window.draw)) return;
|
|
24
24
|
scope = 'global';
|
|
25
25
|
}
|
|
26
26
|
$._scope = scope;
|
|
27
27
|
let globalScope;
|
|
28
28
|
if (scope == 'global') {
|
|
29
29
|
Q5._hasGlobal = $._isGlobal = true;
|
|
30
|
-
globalScope = !Q5._server ? window : global;
|
|
30
|
+
globalScope = Q5._esm ? globalThis : !Q5._server ? window : global;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
let q = new Proxy($, {
|
|
@@ -105,6 +105,7 @@ function Q5(scope, parent, renderer) {
|
|
|
105
105
|
for (let m of Q5.methods.post) m.call($);
|
|
106
106
|
if ($._render) $._render();
|
|
107
107
|
if ($._finishRender) $._finishRender();
|
|
108
|
+
$.postProcess();
|
|
108
109
|
q.pmouseX = $.mouseX;
|
|
109
110
|
q.pmouseY = $.mouseY;
|
|
110
111
|
q.moveX = q.moveY = 0;
|
|
@@ -178,10 +179,7 @@ function Q5(scope, parent, renderer) {
|
|
|
178
179
|
delete Q5.Q5;
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
if ($._webgpuFallback)
|
|
182
|
-
$.colorMode('rgb', 1);
|
|
183
|
-
$._beginRender = () => $.translate($.canvas.hw, $.canvas.hh);
|
|
184
|
-
}
|
|
182
|
+
if ($._webgpuFallback) $.colorMode('rgb', 1);
|
|
185
183
|
|
|
186
184
|
for (let m of Q5.methods.init) {
|
|
187
185
|
m.call($);
|
|
@@ -218,10 +216,12 @@ function Q5(scope, parent, renderer) {
|
|
|
218
216
|
$.preload = t.preload;
|
|
219
217
|
$.setup = t.setup;
|
|
220
218
|
$.draw = t.draw;
|
|
219
|
+
$.postProcess = t.postProcess;
|
|
221
220
|
}
|
|
222
221
|
$.preload ??= () => {};
|
|
223
222
|
$.setup ??= () => {};
|
|
224
223
|
$.draw ??= () => {};
|
|
224
|
+
$.postProcess ??= () => {};
|
|
225
225
|
|
|
226
226
|
let userFns = [
|
|
227
227
|
'mouseMoved',
|
|
@@ -284,6 +284,7 @@ Q5.renderers = {};
|
|
|
284
284
|
Q5.modules = {};
|
|
285
285
|
|
|
286
286
|
Q5._server = typeof process == 'object';
|
|
287
|
+
Q5._esm = this === undefined;
|
|
287
288
|
|
|
288
289
|
Q5._instanceCount = 0;
|
|
289
290
|
Q5._friendlyError = (msg, func) => {
|
|
@@ -312,7 +313,7 @@ function createCanvas(w, h, opt) {
|
|
|
312
313
|
}
|
|
313
314
|
}
|
|
314
315
|
|
|
315
|
-
Q5.version = Q5.VERSION = '2.
|
|
316
|
+
Q5.version = Q5.VERSION = '2.13';
|
|
316
317
|
|
|
317
318
|
if (typeof document == 'object') {
|
|
318
319
|
document.addEventListener('DOMContentLoaded', () => {
|
|
@@ -1104,19 +1105,19 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
1104
1105
|
};
|
|
1105
1106
|
|
|
1106
1107
|
$.beginShape = () => {
|
|
1107
|
-
curveBuff
|
|
1108
|
+
curveBuff = [];
|
|
1108
1109
|
$.ctx.beginPath();
|
|
1109
1110
|
firstVertex = true;
|
|
1110
1111
|
};
|
|
1111
1112
|
|
|
1112
1113
|
$.beginContour = () => {
|
|
1113
1114
|
$.ctx.closePath();
|
|
1114
|
-
curveBuff
|
|
1115
|
+
curveBuff = [];
|
|
1115
1116
|
firstVertex = true;
|
|
1116
1117
|
};
|
|
1117
1118
|
|
|
1118
1119
|
$.endContour = () => {
|
|
1119
|
-
curveBuff
|
|
1120
|
+
curveBuff = [];
|
|
1120
1121
|
firstVertex = true;
|
|
1121
1122
|
};
|
|
1122
1123
|
|
|
@@ -1125,7 +1126,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
1125
1126
|
x *= $._da;
|
|
1126
1127
|
y *= $._da;
|
|
1127
1128
|
}
|
|
1128
|
-
curveBuff
|
|
1129
|
+
curveBuff = [];
|
|
1129
1130
|
if (firstVertex) {
|
|
1130
1131
|
$.ctx.moveTo(x, y);
|
|
1131
1132
|
} else {
|
|
@@ -1143,7 +1144,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
1143
1144
|
x *= $._da;
|
|
1144
1145
|
y *= $._da;
|
|
1145
1146
|
}
|
|
1146
|
-
curveBuff
|
|
1147
|
+
curveBuff = [];
|
|
1147
1148
|
$.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
1148
1149
|
};
|
|
1149
1150
|
|
|
@@ -1154,7 +1155,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
1154
1155
|
x *= $._da;
|
|
1155
1156
|
y *= $._da;
|
|
1156
1157
|
}
|
|
1157
|
-
curveBuff
|
|
1158
|
+
curveBuff = [];
|
|
1158
1159
|
$.ctx.quadraticCurveTo(cp1x, cp1y, x, y);
|
|
1159
1160
|
};
|
|
1160
1161
|
|
|
@@ -1183,7 +1184,7 @@ Q5.renderers.q2d.drawing = ($) => {
|
|
|
1183
1184
|
};
|
|
1184
1185
|
|
|
1185
1186
|
$.endShape = (close) => {
|
|
1186
|
-
curveBuff
|
|
1187
|
+
curveBuff = [];
|
|
1187
1188
|
if (close) $.ctx.closePath();
|
|
1188
1189
|
ink();
|
|
1189
1190
|
};
|
|
@@ -1985,7 +1986,7 @@ Q5.renderers.q2d.text = ($, q) => {
|
|
|
1985
1986
|
lineAmount++;
|
|
1986
1987
|
if (lineAmount >= h) break;
|
|
1987
1988
|
}
|
|
1988
|
-
lines
|
|
1989
|
+
lines = [];
|
|
1989
1990
|
|
|
1990
1991
|
if (!$._fillSet) ctx.fillStyle = ogFill;
|
|
1991
1992
|
|
|
@@ -2642,8 +2643,8 @@ Q5.modules.input = ($, q) => {
|
|
|
2642
2643
|
};
|
|
2643
2644
|
|
|
2644
2645
|
if (window) {
|
|
2645
|
-
$.
|
|
2646
|
-
$.
|
|
2646
|
+
$.lockMouse = document.body?.requestPointerLock;
|
|
2647
|
+
$.unlockMouse = document.exitPointerLock;
|
|
2647
2648
|
}
|
|
2648
2649
|
|
|
2649
2650
|
$._onkeydown = (e) => {
|
|
@@ -2790,8 +2791,9 @@ Q5.modules.math = ($, q) => {
|
|
|
2790
2791
|
|
|
2791
2792
|
$.dist = function () {
|
|
2792
2793
|
let a = arguments;
|
|
2794
|
+
if (a.length == 2) return Math.hypot(a[0].x - a[1].x, a[0].y - a[1].y);
|
|
2793
2795
|
if (a.length == 4) return Math.hypot(a[0] - a[2], a[1] - a[3]);
|
|
2794
|
-
|
|
2796
|
+
return Math.hypot(a[0] - a[3], a[1] - a[4], a[2] - a[5]);
|
|
2795
2797
|
};
|
|
2796
2798
|
|
|
2797
2799
|
$.lerp = (a, b, t) => a * (1 - t) + b * t;
|
|
@@ -3743,12 +3745,12 @@ Q5.renderers.webgpu.canvas = ($, q) => {
|
|
|
3743
3745
|
|
|
3744
3746
|
const MAX_TRANSFORMS = 1e7, // or whatever maximum you need
|
|
3745
3747
|
MATRIX_SIZE = 16, // 4x4 matrix
|
|
3746
|
-
transforms = new Float32Array(MAX_TRANSFORMS * MATRIX_SIZE)
|
|
3748
|
+
transforms = new Float32Array(MAX_TRANSFORMS * MATRIX_SIZE);
|
|
3749
|
+
|
|
3750
|
+
let matrix,
|
|
3747
3751
|
matrices = [],
|
|
3748
3752
|
matricesIndexStack = [];
|
|
3749
3753
|
|
|
3750
|
-
let matrix;
|
|
3751
|
-
|
|
3752
3754
|
// tracks if the matrix has been modified
|
|
3753
3755
|
$._matrixDirty = false;
|
|
3754
3756
|
|
|
@@ -4043,7 +4045,7 @@ Q5.renderers.webgpu.canvas = ($, q) => {
|
|
|
4043
4045
|
new Float32Array(colorsBuffer.getMappedRange()).set(colorStack.slice(0, colorStackIndex));
|
|
4044
4046
|
colorsBuffer.unmap();
|
|
4045
4047
|
|
|
4046
|
-
mainBindGroup = Q5.device.createBindGroup({
|
|
4048
|
+
let mainBindGroup = Q5.device.createBindGroup({
|
|
4047
4049
|
layout: mainLayout,
|
|
4048
4050
|
entries: [
|
|
4049
4051
|
{ binding: 0, resource: { buffer: uniformBuffer } },
|
|
@@ -4059,8 +4061,7 @@ Q5.renderers.webgpu.canvas = ($, q) => {
|
|
|
4059
4061
|
let drawVertOffset = 0,
|
|
4060
4062
|
imageVertOffset = 0,
|
|
4061
4063
|
textCharOffset = 0,
|
|
4062
|
-
curPipelineIndex = -1
|
|
4063
|
-
curTextureIndex = -1;
|
|
4064
|
+
curPipelineIndex = -1;
|
|
4064
4065
|
|
|
4065
4066
|
for (let i = 0; i < drawStack.length; i += 2) {
|
|
4066
4067
|
let v = drawStack[i + 1];
|
|
@@ -4076,15 +4077,11 @@ Q5.renderers.webgpu.canvas = ($, q) => {
|
|
|
4076
4077
|
pass.draw(v, 1, drawVertOffset);
|
|
4077
4078
|
drawVertOffset += v;
|
|
4078
4079
|
} else if (curPipelineIndex == 1) {
|
|
4079
|
-
// let instanceCount = drawStack[i + 2];
|
|
4080
4080
|
// draw images
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
pass.setBindGroup(1, $._textureBindGroups[v]);
|
|
4084
|
-
}
|
|
4081
|
+
// v is the texture index
|
|
4082
|
+
pass.setBindGroup(1, $._textureBindGroups[v]);
|
|
4085
4083
|
pass.draw(4, 1, imageVertOffset);
|
|
4086
4084
|
imageVertOffset += 4;
|
|
4087
|
-
// i++;
|
|
4088
4085
|
} else if (curPipelineIndex == 2) {
|
|
4089
4086
|
// draw text
|
|
4090
4087
|
let o = drawStack[i + 2];
|
|
@@ -4097,8 +4094,6 @@ Q5.renderers.webgpu.canvas = ($, q) => {
|
|
|
4097
4094
|
i++;
|
|
4098
4095
|
}
|
|
4099
4096
|
}
|
|
4100
|
-
|
|
4101
|
-
for (let m of $._hooks.postRender) m();
|
|
4102
4097
|
};
|
|
4103
4098
|
|
|
4104
4099
|
$._finishRender = () => {
|
|
@@ -4109,19 +4104,19 @@ Q5.renderers.webgpu.canvas = ($, q) => {
|
|
|
4109
4104
|
q.pass = $.encoder = null;
|
|
4110
4105
|
|
|
4111
4106
|
// clear the stacks for the next frame
|
|
4112
|
-
$.drawStack
|
|
4107
|
+
$.drawStack = drawStack = [];
|
|
4113
4108
|
colorIndex = 1;
|
|
4114
4109
|
colorStackIndex = 8;
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4110
|
+
matrices = [matrices[0]];
|
|
4111
|
+
matricesIndexStack = [];
|
|
4112
|
+
|
|
4113
|
+
for (let m of $._hooks.postRender) m();
|
|
4119
4114
|
};
|
|
4120
4115
|
};
|
|
4121
4116
|
|
|
4122
4117
|
Q5.initWebGPU = async () => {
|
|
4123
4118
|
if (!navigator.gpu) {
|
|
4124
|
-
console.warn('q5 WebGPU not supported on this browser!');
|
|
4119
|
+
console.warn('q5 WebGPU not supported on this browser! Use Google Chrome or Edge.');
|
|
4125
4120
|
return false;
|
|
4126
4121
|
}
|
|
4127
4122
|
if (!Q5.device) {
|
|
@@ -4190,7 +4185,7 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
|
|
|
4190
4185
|
});
|
|
4191
4186
|
|
|
4192
4187
|
let vertexBufferLayout = {
|
|
4193
|
-
arrayStride: 16, //
|
|
4188
|
+
arrayStride: 16, // 4 floats * 4 bytes
|
|
4194
4189
|
attributes: [
|
|
4195
4190
|
{ format: 'float32x2', offset: 0, shaderLocation: 0 }, // position
|
|
4196
4191
|
{ format: 'float32', offset: 8, shaderLocation: 1 }, // colorIndex
|
|
@@ -4450,8 +4445,10 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
|
|
|
4450
4445
|
}
|
|
4451
4446
|
};
|
|
4452
4447
|
|
|
4453
|
-
$.
|
|
4454
|
-
|
|
4448
|
+
$._strokeJoin = 'round';
|
|
4449
|
+
|
|
4450
|
+
$.strokeJoin = (x) => {
|
|
4451
|
+
$._strokeJoin = x;
|
|
4455
4452
|
};
|
|
4456
4453
|
|
|
4457
4454
|
$.line = (x1, y1, x2, y2) => {
|
|
@@ -4472,7 +4469,7 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
|
|
|
4472
4469
|
|
|
4473
4470
|
addRect(x1 + px, -y1 - py, x1 - px, -y1 + py, x2 - px, -y2 + py, x2 + px, -y2 - py, ci, ti);
|
|
4474
4471
|
|
|
4475
|
-
if (sw > 2) {
|
|
4472
|
+
if (sw > 2 && $._strokeJoin != 'none') {
|
|
4476
4473
|
let n = getArcSegments(sw);
|
|
4477
4474
|
addEllipse(x1, y1, hsw, hsw, n, ci, ti);
|
|
4478
4475
|
addEllipse(x2, y2, hsw, hsw, n, ci, ti);
|
|
@@ -4614,7 +4611,7 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
|
|
|
4614
4611
|
};
|
|
4615
4612
|
|
|
4616
4613
|
$.background = (r, g, b, a) => {
|
|
4617
|
-
$.
|
|
4614
|
+
$.pushMatrix();
|
|
4618
4615
|
$.resetMatrix();
|
|
4619
4616
|
$._doStroke = false;
|
|
4620
4617
|
if (r.src) {
|
|
@@ -4629,7 +4626,7 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
|
|
|
4629
4626
|
$.rect(-c.hw, -c.hh, c.w, c.h);
|
|
4630
4627
|
$._rectMode = og;
|
|
4631
4628
|
}
|
|
4632
|
-
$.
|
|
4629
|
+
$.popMatrix();
|
|
4633
4630
|
if (!$._fillSet) $._fill = 1;
|
|
4634
4631
|
};
|
|
4635
4632
|
|
|
@@ -4649,6 +4646,7 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
|
|
|
4649
4646
|
});
|
|
4650
4647
|
|
|
4651
4648
|
$._hooks.postRender.push(() => {
|
|
4649
|
+
drawStack = $.drawStack;
|
|
4652
4650
|
vertIndex = 0;
|
|
4653
4651
|
});
|
|
4654
4652
|
};
|
|
@@ -4772,14 +4770,11 @@ fn fragmentMain(f: FragmentParams) -> @location(0) vec4f {
|
|
|
4772
4770
|
minFilter: filter
|
|
4773
4771
|
});
|
|
4774
4772
|
};
|
|
4775
|
-
makeSampler('linear');
|
|
4776
4773
|
|
|
4777
|
-
$.smooth = () =>
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
$.
|
|
4781
|
-
makeSampler('nearest');
|
|
4782
|
-
};
|
|
4774
|
+
$.smooth = () => makeSampler('linear');
|
|
4775
|
+
$.noSmooth = () => makeSampler('nearest');
|
|
4776
|
+
|
|
4777
|
+
$.smooth();
|
|
4783
4778
|
|
|
4784
4779
|
let MAX_TEXTURES = 12000;
|
|
4785
4780
|
|
|
@@ -5244,8 +5239,8 @@ fn fragmentMain(f : FragmentParams) -> @location(0) vec4f {
|
|
|
5244
5239
|
if (vert) $._textBaseline = vert;
|
|
5245
5240
|
};
|
|
5246
5241
|
|
|
5247
|
-
|
|
5248
|
-
|
|
5242
|
+
let charStack = [],
|
|
5243
|
+
textStack = [];
|
|
5249
5244
|
|
|
5250
5245
|
let measureText = (font, text, charCallback) => {
|
|
5251
5246
|
let maxWidth = 0,
|
|
@@ -5298,11 +5293,16 @@ fn fragmentMain(f : FragmentParams) -> @location(0) vec4f {
|
|
|
5298
5293
|
|
|
5299
5294
|
$.text = (str, x, y, w, h) => {
|
|
5300
5295
|
if (!$._font) {
|
|
5301
|
-
// check if
|
|
5302
|
-
|
|
5303
|
-
if (navigator.onLine && !initLoadDefaultFont) {
|
|
5296
|
+
// check if loading the default font hasn't been attempted
|
|
5297
|
+
if (!initLoadDefaultFont) {
|
|
5304
5298
|
initLoadDefaultFont = true;
|
|
5305
|
-
|
|
5299
|
+
|
|
5300
|
+
if (navigator.onLine) {
|
|
5301
|
+
$.loadFont('https://q5js.org/defaultFont-msdf.json');
|
|
5302
|
+
} else if (Q5._esm && import.meta?.url) {
|
|
5303
|
+
let path = new URL('defaultFont-msdf.json', import.meta.url);
|
|
5304
|
+
$.loadFont(path.href);
|
|
5305
|
+
}
|
|
5306
5306
|
}
|
|
5307
5307
|
return;
|
|
5308
5308
|
}
|
|
@@ -5342,7 +5342,7 @@ fn fragmentMain(f : FragmentParams) -> @location(0) vec4f {
|
|
|
5342
5342
|
|
|
5343
5343
|
let ta = $._textAlign,
|
|
5344
5344
|
tb = $._textBaseline,
|
|
5345
|
-
textIndex =
|
|
5345
|
+
textIndex = textStack.length,
|
|
5346
5346
|
o = 0, // offset
|
|
5347
5347
|
measurements;
|
|
5348
5348
|
|
|
@@ -5382,20 +5382,20 @@ fn fragmentMain(f : FragmentParams) -> @location(0) vec4f {
|
|
|
5382
5382
|
o += 4;
|
|
5383
5383
|
});
|
|
5384
5384
|
}
|
|
5385
|
-
|
|
5385
|
+
charStack.push(charsData);
|
|
5386
5386
|
|
|
5387
|
-
let
|
|
5387
|
+
let txt = [];
|
|
5388
5388
|
|
|
5389
5389
|
if ($._matrixDirty) $._saveMatrix();
|
|
5390
5390
|
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5391
|
+
txt[0] = x;
|
|
5392
|
+
txt[1] = -y;
|
|
5393
|
+
txt[2] = $._textSize / 44;
|
|
5394
|
+
txt[3] = $._matrixIndex;
|
|
5395
|
+
txt[4] = $._fillSet ? $._fill : 0;
|
|
5396
|
+
txt[5] = $._stroke;
|
|
5397
5397
|
|
|
5398
|
-
|
|
5398
|
+
textStack.push(txt);
|
|
5399
5399
|
$.drawStack.push(2, measurements.printedCharCount, $._font.index);
|
|
5400
5400
|
};
|
|
5401
5401
|
|
|
@@ -5456,11 +5456,11 @@ fn fragmentMain(f : FragmentParams) -> @location(0) vec4f {
|
|
|
5456
5456
|
};
|
|
5457
5457
|
|
|
5458
5458
|
$._hooks.preRender.push(() => {
|
|
5459
|
-
if (
|
|
5459
|
+
if (!charStack.length) return;
|
|
5460
5460
|
|
|
5461
5461
|
// calculate total buffer size for text data
|
|
5462
5462
|
let totalTextSize = 0;
|
|
5463
|
-
for (let charsData of
|
|
5463
|
+
for (let charsData of charStack) {
|
|
5464
5464
|
totalTextSize += charsData.length * 4;
|
|
5465
5465
|
}
|
|
5466
5466
|
|
|
@@ -5472,11 +5472,11 @@ fn fragmentMain(f : FragmentParams) -> @location(0) vec4f {
|
|
|
5472
5472
|
});
|
|
5473
5473
|
|
|
5474
5474
|
// copy all the text data into the buffer
|
|
5475
|
-
new Float32Array(charBuffer.getMappedRange()).set(
|
|
5475
|
+
new Float32Array(charBuffer.getMappedRange()).set(charStack.flat());
|
|
5476
5476
|
charBuffer.unmap();
|
|
5477
5477
|
|
|
5478
5478
|
// calculate total buffer size for metadata
|
|
5479
|
-
let totalMetadataSize =
|
|
5479
|
+
let totalMetadataSize = textStack.length * 6 * 4;
|
|
5480
5480
|
|
|
5481
5481
|
// create a single buffer for all metadata
|
|
5482
5482
|
let textBuffer = Q5.device.createBuffer({
|
|
@@ -5487,7 +5487,7 @@ fn fragmentMain(f : FragmentParams) -> @location(0) vec4f {
|
|
|
5487
5487
|
});
|
|
5488
5488
|
|
|
5489
5489
|
// copy all metadata into the buffer
|
|
5490
|
-
new Float32Array(textBuffer.getMappedRange()).set(
|
|
5490
|
+
new Float32Array(textBuffer.getMappedRange()).set(textStack.flat());
|
|
5491
5491
|
textBuffer.unmap();
|
|
5492
5492
|
|
|
5493
5493
|
// create a single bind group for the text buffer and metadata buffer
|
|
@@ -5502,7 +5502,7 @@ fn fragmentMain(f : FragmentParams) -> @location(0) vec4f {
|
|
|
5502
5502
|
});
|
|
5503
5503
|
|
|
5504
5504
|
$._hooks.postRender.push(() => {
|
|
5505
|
-
|
|
5506
|
-
|
|
5505
|
+
charStack = [];
|
|
5506
|
+
textStack = [];
|
|
5507
5507
|
});
|
|
5508
5508
|
};
|