q5 2.14.3 → 2.14.5
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 +1 -1
- package/package.json +1 -1
- package/q5.js +190 -75
- package/q5.min.js +1 -1
- package/q5js_brand.webp +0 -0
- package/q5js_icon.png +0 -0
- package/src/q5-2d-canvas.js +0 -202
- package/src/q5-2d-drawing.js +0 -398
- package/src/q5-2d-image.js +0 -330
- package/src/q5-2d-soft-filters.js +0 -145
- package/src/q5-2d-text.js +0 -279
- package/src/q5-ai.js +0 -65
- package/src/q5-canvas.js +0 -367
- package/src/q5-color.js +0 -322
- package/src/q5-core.js +0 -321
- package/src/q5-display.js +0 -101
- package/src/q5-dom.js +0 -2
- package/src/q5-input.js +0 -215
- package/src/q5-math.js +0 -423
- package/src/q5-noisier.js +0 -264
- package/src/q5-record.js +0 -366
- package/src/q5-sensors.js +0 -98
- package/src/q5-sound.js +0 -64
- package/src/q5-util.js +0 -50
- package/src/q5-vector.js +0 -305
- package/src/q5-webgpu-canvas.js +0 -556
- package/src/q5-webgpu-drawing.js +0 -525
- package/src/q5-webgpu-image.js +0 -268
- package/src/q5-webgpu-text.js +0 -594
- package/src/readme.md +0 -248
package/src/q5-display.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
Q5.modules.display = ($) => {
|
|
2
|
-
if (!$.canvas || $._scope == 'graphics') return;
|
|
3
|
-
|
|
4
|
-
let c = $.canvas;
|
|
5
|
-
|
|
6
|
-
$.CENTERED = 'centered';
|
|
7
|
-
$.FULLSCREEN = 'fullscreen';
|
|
8
|
-
$.MAXED = 'maxed';
|
|
9
|
-
|
|
10
|
-
$.PIXELATED = 'pixelated';
|
|
11
|
-
|
|
12
|
-
if (Q5._instanceCount == 0 && !Q5._server) {
|
|
13
|
-
document.head.insertAdjacentHTML(
|
|
14
|
-
'beforeend',
|
|
15
|
-
`<style>
|
|
16
|
-
html, body {
|
|
17
|
-
margin: 0;
|
|
18
|
-
padding: 0;
|
|
19
|
-
}
|
|
20
|
-
.q5Canvas {
|
|
21
|
-
outline: none;
|
|
22
|
-
-webkit-touch-callout: none;
|
|
23
|
-
-webkit-text-size-adjust: none;
|
|
24
|
-
-webkit-user-select: none;
|
|
25
|
-
overscroll-behavior: none;
|
|
26
|
-
}
|
|
27
|
-
.q5-pixelated {
|
|
28
|
-
image-rendering: pixelated;
|
|
29
|
-
font-smooth: never;
|
|
30
|
-
-webkit-font-smoothing: none;
|
|
31
|
-
}
|
|
32
|
-
.q5-centered,
|
|
33
|
-
.q5-maxed,
|
|
34
|
-
.q5-fullscreen {
|
|
35
|
-
display: flex;
|
|
36
|
-
align-items: center;
|
|
37
|
-
justify-content: center;
|
|
38
|
-
}
|
|
39
|
-
main.q5-centered,
|
|
40
|
-
main.q5-maxed,
|
|
41
|
-
.q5-fullscreen {
|
|
42
|
-
height: 100vh;
|
|
43
|
-
}
|
|
44
|
-
main {
|
|
45
|
-
overscroll-behavior: none;
|
|
46
|
-
}
|
|
47
|
-
</style>`
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
$._adjustDisplay = () => {
|
|
52
|
-
let s = c.style;
|
|
53
|
-
let p = c.parentElement;
|
|
54
|
-
if (!s || !p || !c.displayMode) return;
|
|
55
|
-
if (c.renderQuality == 'pixelated') {
|
|
56
|
-
c.classList.add('q5-pixelated');
|
|
57
|
-
$.pixelDensity(1);
|
|
58
|
-
$.defaultImageScale(1);
|
|
59
|
-
if ($.noSmooth) $.noSmooth();
|
|
60
|
-
if ($.textFont) $.textFont('monospace');
|
|
61
|
-
}
|
|
62
|
-
if (c.displayMode == 'default' || c.displayMode == 'normal') {
|
|
63
|
-
p.classList.remove('q5-centered', 'q5-maxed', 'q5-fullscreen');
|
|
64
|
-
s.width = c.w * c.displayScale + 'px';
|
|
65
|
-
s.height = c.h * c.displayScale + 'px';
|
|
66
|
-
} else {
|
|
67
|
-
p.classList.add('q5-' + c.displayMode);
|
|
68
|
-
p = p.getBoundingClientRect();
|
|
69
|
-
if (c.w / c.h > p.width / p.height) {
|
|
70
|
-
if (c.displayMode == 'centered') {
|
|
71
|
-
s.width = c.w * c.displayScale + 'px';
|
|
72
|
-
s.maxWidth = '100%';
|
|
73
|
-
} else s.width = '100%';
|
|
74
|
-
s.height = 'auto';
|
|
75
|
-
s.maxHeight = '';
|
|
76
|
-
} else {
|
|
77
|
-
s.width = 'auto';
|
|
78
|
-
s.maxWidth = '';
|
|
79
|
-
if (c.displayMode == 'centered') {
|
|
80
|
-
s.height = c.h * c.displayScale + 'px';
|
|
81
|
-
s.maxHeight = '100%';
|
|
82
|
-
} else s.height = '100%';
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
$.displayMode = (displayMode = 'normal', renderQuality = 'smooth', displayScale = 1) => {
|
|
88
|
-
if (typeof displayScale == 'string') {
|
|
89
|
-
displayScale = parseFloat(displayScale.slice(1));
|
|
90
|
-
}
|
|
91
|
-
if (displayMode == 'center') displayMode = 'centered';
|
|
92
|
-
Object.assign(c, { displayMode, renderQuality, displayScale });
|
|
93
|
-
$._adjustDisplay();
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
$.fullscreen = (v) => {
|
|
97
|
-
if (v === undefined) return document.fullscreenElement;
|
|
98
|
-
if (v) document.body.requestFullscreen();
|
|
99
|
-
else document.body.exitFullscreen();
|
|
100
|
-
};
|
|
101
|
-
};
|
package/src/q5-dom.js
DELETED
package/src/q5-input.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
Q5.modules.input = ($, q) => {
|
|
2
|
-
if ($._scope == 'graphics') return;
|
|
3
|
-
|
|
4
|
-
$.mouseX = 0;
|
|
5
|
-
$.mouseY = 0;
|
|
6
|
-
$.pmouseX = 0;
|
|
7
|
-
$.pmouseY = 0;
|
|
8
|
-
$.touches = [];
|
|
9
|
-
$.mouseButton = '';
|
|
10
|
-
$.keyIsPressed = false;
|
|
11
|
-
$.mouseIsPressed = false;
|
|
12
|
-
$.key = '';
|
|
13
|
-
$.keyCode = 0;
|
|
14
|
-
|
|
15
|
-
$.UP_ARROW = 38;
|
|
16
|
-
$.DOWN_ARROW = 40;
|
|
17
|
-
$.LEFT_ARROW = 37;
|
|
18
|
-
$.RIGHT_ARROW = 39;
|
|
19
|
-
$.SHIFT = 16;
|
|
20
|
-
$.TAB = 9;
|
|
21
|
-
$.BACKSPACE = 8;
|
|
22
|
-
$.ENTER = $.RETURN = 13;
|
|
23
|
-
$.ALT = $.OPTION = 18;
|
|
24
|
-
$.CONTROL = 17;
|
|
25
|
-
$.DELETE = 46;
|
|
26
|
-
$.ESCAPE = 27;
|
|
27
|
-
|
|
28
|
-
$.ARROW = 'default';
|
|
29
|
-
$.CROSS = 'crosshair';
|
|
30
|
-
$.HAND = 'pointer';
|
|
31
|
-
$.MOVE = 'move';
|
|
32
|
-
$.TEXT = 'text';
|
|
33
|
-
|
|
34
|
-
let keysHeld = {};
|
|
35
|
-
let mouseBtns = [Q5.LEFT, Q5.CENTER, Q5.RIGHT];
|
|
36
|
-
|
|
37
|
-
let c = $.canvas;
|
|
38
|
-
|
|
39
|
-
$._startAudio = () => {
|
|
40
|
-
if (!Q5.aud || Q5.aud?.state == 'suspended') $.userStartAudio();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
$._updateMouse = (e) => {
|
|
44
|
-
if (e.changedTouches) return;
|
|
45
|
-
if (c) {
|
|
46
|
-
let rect = c.getBoundingClientRect();
|
|
47
|
-
let sx = c.scrollWidth / $.width || 1;
|
|
48
|
-
let sy = c.scrollHeight / $.height || 1;
|
|
49
|
-
q.mouseX = (e.clientX - rect.left) / sx;
|
|
50
|
-
q.mouseY = (e.clientY - rect.top) / sy;
|
|
51
|
-
if (c.renderer == 'webgpu') {
|
|
52
|
-
q.mouseX -= c.hw;
|
|
53
|
-
q.mouseY -= c.hh;
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
q.mouseX = e.clientX;
|
|
57
|
-
q.mouseY = e.clientY;
|
|
58
|
-
}
|
|
59
|
-
q.moveX = e.movementX;
|
|
60
|
-
q.moveY = e.movementY;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
let pressedInCanvas = 0;
|
|
64
|
-
|
|
65
|
-
$._onmousedown = (e) => {
|
|
66
|
-
pressedInCanvas++;
|
|
67
|
-
$._startAudio();
|
|
68
|
-
$._updateMouse(e);
|
|
69
|
-
q.mouseIsPressed = true;
|
|
70
|
-
q.mouseButton = mouseBtns[e.button];
|
|
71
|
-
$.mousePressed(e);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
$._onmousemove = (e) => {
|
|
75
|
-
$._updateMouse(e);
|
|
76
|
-
if ($.mouseIsPressed) $.mouseDragged(e);
|
|
77
|
-
else $.mouseMoved(e);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
$._onmouseup = (e) => {
|
|
81
|
-
$._updateMouse(e);
|
|
82
|
-
q.mouseIsPressed = false;
|
|
83
|
-
$.mouseReleased(e);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
$._onclick = (e) => {
|
|
87
|
-
$._updateMouse(e);
|
|
88
|
-
q.mouseIsPressed = true;
|
|
89
|
-
$.mouseClicked(e);
|
|
90
|
-
q.mouseIsPressed = false;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
$._onwheel = (e) => {
|
|
94
|
-
$._updateMouse(e);
|
|
95
|
-
e.delta = e.deltaY;
|
|
96
|
-
if ($.mouseWheel(e) == false) e.preventDefault();
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
$.cursor = (name, x, y) => {
|
|
100
|
-
let pfx = '';
|
|
101
|
-
if (name.includes('.')) {
|
|
102
|
-
name = `url("${name}")`;
|
|
103
|
-
pfx = ', auto';
|
|
104
|
-
}
|
|
105
|
-
if (x !== undefined) {
|
|
106
|
-
name += ' ' + x + ' ' + y;
|
|
107
|
-
}
|
|
108
|
-
$.canvas.style.cursor = name + pfx;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
$.noCursor = () => {
|
|
112
|
-
$.canvas.style.cursor = 'none';
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
if (window) {
|
|
116
|
-
$.lockMouse = document.body?.requestPointerLock;
|
|
117
|
-
$.unlockMouse = document.exitPointerLock;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
$._onkeydown = (e) => {
|
|
121
|
-
if (e.repeat) return;
|
|
122
|
-
$._startAudio();
|
|
123
|
-
q.keyIsPressed = true;
|
|
124
|
-
q.key = e.key;
|
|
125
|
-
q.keyCode = e.keyCode;
|
|
126
|
-
keysHeld[$.keyCode] = keysHeld[$.key.toLowerCase()] = true;
|
|
127
|
-
$.keyPressed(e);
|
|
128
|
-
if (e.key.length == 1) $.keyTyped(e);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
$._onkeyup = (e) => {
|
|
132
|
-
q.keyIsPressed = false;
|
|
133
|
-
q.key = e.key;
|
|
134
|
-
q.keyCode = e.keyCode;
|
|
135
|
-
keysHeld[$.keyCode] = keysHeld[$.key.toLowerCase()] = false;
|
|
136
|
-
$.keyReleased(e);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
$.keyIsDown = (v) => !!keysHeld[typeof v == 'string' ? v.toLowerCase() : v];
|
|
140
|
-
|
|
141
|
-
function getTouchInfo(touch) {
|
|
142
|
-
const rect = $.canvas.getBoundingClientRect();
|
|
143
|
-
const sx = $.canvas.scrollWidth / $.width || 1;
|
|
144
|
-
const sy = $.canvas.scrollHeight / $.height || 1;
|
|
145
|
-
return {
|
|
146
|
-
x: (touch.clientX - rect.left) / sx,
|
|
147
|
-
y: (touch.clientY - rect.top) / sy,
|
|
148
|
-
id: touch.identifier
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
$._ontouchstart = (e) => {
|
|
153
|
-
$._startAudio();
|
|
154
|
-
q.touches = [...e.touches].map(getTouchInfo);
|
|
155
|
-
if (!$._isTouchAware) {
|
|
156
|
-
q.mouseX = $.touches[0].x;
|
|
157
|
-
q.mouseY = $.touches[0].y;
|
|
158
|
-
q.mouseIsPressed = true;
|
|
159
|
-
q.mouseButton = $.LEFT;
|
|
160
|
-
$.mousePressed(e);
|
|
161
|
-
}
|
|
162
|
-
$.touchStarted(e);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
$._ontouchmove = (e) => {
|
|
166
|
-
q.touches = [...e.touches].map(getTouchInfo);
|
|
167
|
-
if (!$._isTouchAware) {
|
|
168
|
-
q.mouseX = $.touches[0].x;
|
|
169
|
-
q.mouseY = $.touches[0].y;
|
|
170
|
-
if (!$.mouseDragged(e)) e.preventDefault();
|
|
171
|
-
}
|
|
172
|
-
if (!$.touchMoved(e)) e.preventDefault();
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
$._ontouchend = (e) => {
|
|
176
|
-
q.touches = [...e.touches].map(getTouchInfo);
|
|
177
|
-
if (!$._isTouchAware && !$.touches.length) {
|
|
178
|
-
q.mouseIsPressed = false;
|
|
179
|
-
if (!$.mouseReleased(e)) e.preventDefault();
|
|
180
|
-
}
|
|
181
|
-
if (!$.touchEnded(e)) e.preventDefault();
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
if (c) {
|
|
185
|
-
let l = c.addEventListener.bind(c);
|
|
186
|
-
l('mousedown', (e) => $._onmousedown(e));
|
|
187
|
-
l('wheel', (e) => $._onwheel(e));
|
|
188
|
-
l('click', (e) => $._onclick(e));
|
|
189
|
-
|
|
190
|
-
l('touchstart', (e) => $._ontouchstart(e));
|
|
191
|
-
l('touchmove', (e) => $._ontouchmove(e));
|
|
192
|
-
l('touchend', (e) => $._ontouchend(e));
|
|
193
|
-
l('touchcancel', (e) => $._ontouchend(e));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (window) {
|
|
197
|
-
let l = window.addEventListener;
|
|
198
|
-
l('keydown', (e) => $._onkeydown(e), false);
|
|
199
|
-
l('keyup', (e) => $._onkeyup(e), false);
|
|
200
|
-
|
|
201
|
-
if (!c) {
|
|
202
|
-
l('mousedown', (e) => $._onmousedown(e));
|
|
203
|
-
l('wheel', (e) => $._onwheel(e));
|
|
204
|
-
l('click', (e) => $._onclick(e));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
l('mousemove', (e) => $._onmousemove(e), false);
|
|
208
|
-
l('mouseup', (e) => {
|
|
209
|
-
if (pressedInCanvas > 0) {
|
|
210
|
-
pressedInCanvas--;
|
|
211
|
-
$._onmouseup(e);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
};
|