fragment-tools 0.1.15 → 0.1.17
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/bin/index.js +3 -0
- package/package.json +1 -1
- package/src/cli/build.js +35 -22
- package/src/cli/createConfig.js +1 -0
- package/src/cli/plugins/save.js +12 -6
- package/src/cli/templates/p5-webgl/index.js +2 -2
- package/src/client/app/modules/Exports.svelte +0 -1
- package/src/client/app/renderers/P5GLRenderer.js +4 -2
- package/src/client/app/renderers/P5Renderer.js +11 -2
- package/src/client/app/ui/SketchRenderer.svelte +3 -1
- package/src/client/app/utils/canvas.utils.js +2 -1
- package/src/client/app/utils/fields.utils.js +2 -2
package/bin/index.js
CHANGED
|
@@ -28,6 +28,7 @@ prog.command('run [entry]', '', { default: true })
|
|
|
28
28
|
.option('--outDir', 'Build output directory')
|
|
29
29
|
.option('--emptyOutDir', 'Empty outDir before static build')
|
|
30
30
|
.option('--base', 'Base public path when served in production', undefined)
|
|
31
|
+
.option('--prompts', 'Enable interactive prompts', true)
|
|
31
32
|
.action((entry, options) => {
|
|
32
33
|
if (options.new) {
|
|
33
34
|
return create(entry, {
|
|
@@ -41,6 +42,7 @@ prog.command('run [entry]', '', { default: true })
|
|
|
41
42
|
outDir: options.outDir,
|
|
42
43
|
emptyOutDir: options.emptyOutDir,
|
|
43
44
|
base: options.base,
|
|
45
|
+
prompts: options.prompts,
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -66,6 +68,7 @@ prog.command('build [entry]')
|
|
|
66
68
|
.option('--emptyOutDir', 'Empty outDir before building for production')
|
|
67
69
|
.option('--base', 'Base public path', undefined)
|
|
68
70
|
.option('-dev, --development', 'Enable development mode', false)
|
|
71
|
+
.option('--prompts', 'Enable interactive prompts', true)
|
|
69
72
|
.action((entry, options) => {
|
|
70
73
|
build(entry, options);
|
|
71
74
|
});
|
package/package.json
CHANGED
package/src/cli/build.js
CHANGED
|
@@ -17,12 +17,15 @@ import hotShaderReplacement from './plugins/hot-shader-replacement.js';
|
|
|
17
17
|
* @param {string} options.outDir
|
|
18
18
|
* @param {boolean} options.emptyOutDir
|
|
19
19
|
* @param {boolean} options.development
|
|
20
|
+
* @param {boolean} [options.prompts=true]
|
|
20
21
|
*/
|
|
21
22
|
export async function build(entry, options) {
|
|
22
23
|
const cwd = process.cwd();
|
|
23
24
|
const command = 'build';
|
|
24
25
|
const prefix = log.prefix(command);
|
|
25
26
|
|
|
27
|
+
const { prompts = true } = options;
|
|
28
|
+
|
|
26
29
|
try {
|
|
27
30
|
const entries = await getEntries(entry, cwd, command, prefix);
|
|
28
31
|
|
|
@@ -30,15 +33,19 @@ export async function build(entry, options) {
|
|
|
30
33
|
|
|
31
34
|
log.message(`${magenta(entry)}\n`, prefix);
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
placeholder: '.',
|
|
36
|
-
hint: '(hit Enter to use current directory)',
|
|
37
|
-
initialValue:
|
|
38
|
-
options.outDir ?? entries[0].split(path.extname(entries[0]))[0],
|
|
39
|
-
});
|
|
36
|
+
let outDir =
|
|
37
|
+
options.outDir ?? entries[0].split(path.extname(entries[0]))[0];
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
if (prompts) {
|
|
40
|
+
outDir = await p.text({
|
|
41
|
+
message: 'Output directory:',
|
|
42
|
+
placeholder: '.',
|
|
43
|
+
hint: '(hit Enter to use current directory)',
|
|
44
|
+
initialValue: outDir,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
handleCancelledPrompt(outDir, prefix);
|
|
48
|
+
}
|
|
42
49
|
|
|
43
50
|
let outDirPath = path.join(cwd, outDir);
|
|
44
51
|
|
|
@@ -52,24 +59,30 @@ export async function build(entry, options) {
|
|
|
52
59
|
if (files.length > 0) {
|
|
53
60
|
log.warn(`${outDirPath} is not an empty folder.\n`);
|
|
54
61
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
if (prompts) {
|
|
63
|
+
emptyOutDir = await p.confirm({
|
|
64
|
+
message: 'Empty folder before building?',
|
|
65
|
+
active: 'Yes',
|
|
66
|
+
inactive: 'No',
|
|
67
|
+
initialValue: emptyOutDir,
|
|
68
|
+
});
|
|
61
69
|
|
|
62
|
-
|
|
70
|
+
handleCancelledPrompt(emptyOutDir, prefix);
|
|
71
|
+
}
|
|
63
72
|
}
|
|
64
73
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
let base = options.base;
|
|
75
|
+
|
|
76
|
+
if (prompts) {
|
|
77
|
+
base = await p.text({
|
|
78
|
+
message: 'Base public path:',
|
|
79
|
+
placeholder: `/`,
|
|
80
|
+
hint: '(Hit Enter to validate)',
|
|
81
|
+
initialValue: base,
|
|
82
|
+
});
|
|
71
83
|
|
|
72
|
-
|
|
84
|
+
handleCancelledPrompt(base, prefix);
|
|
85
|
+
}
|
|
73
86
|
|
|
74
87
|
if (entries.length > 0) {
|
|
75
88
|
log.message(
|
package/src/cli/createConfig.js
CHANGED
package/src/cli/plugins/save.js
CHANGED
|
@@ -15,13 +15,13 @@ export default function screenshot({
|
|
|
15
15
|
cwd = process.cwd(),
|
|
16
16
|
inlineExportDir,
|
|
17
17
|
} = {}) {
|
|
18
|
-
function resolveDirectory(directoryPath) {
|
|
18
|
+
function resolveDirectory(directoryPath, dirname) {
|
|
19
19
|
return path.isAbsolute(directoryPath)
|
|
20
20
|
? directoryPath
|
|
21
|
-
: path.join(cwd, directoryPath);
|
|
21
|
+
: path.join(path.join(cwd, dirname), directoryPath);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function resolveExportDirectory(exportDir) {
|
|
24
|
+
function resolveExportDirectory(exportDir, dirname) {
|
|
25
25
|
let directory;
|
|
26
26
|
|
|
27
27
|
if (inlineExportDir) {
|
|
@@ -37,7 +37,7 @@ export default function screenshot({
|
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
} else if (exportDir) {
|
|
40
|
-
directory = resolveDirectory(exportDir);
|
|
40
|
+
directory = resolveDirectory(exportDir, dirname);
|
|
41
41
|
} else {
|
|
42
42
|
directory = cwd;
|
|
43
43
|
}
|
|
@@ -62,10 +62,16 @@ export default function screenshot({
|
|
|
62
62
|
const { filename, data, encoding, exportDir } =
|
|
63
63
|
files[i];
|
|
64
64
|
|
|
65
|
-
let directory = resolveExportDirectory(
|
|
65
|
+
let directory = resolveExportDirectory(
|
|
66
|
+
exportDir,
|
|
67
|
+
path.dirname(filename),
|
|
68
|
+
);
|
|
66
69
|
mkdirp(directory);
|
|
67
70
|
|
|
68
|
-
let filepath = path.join(
|
|
71
|
+
let filepath = path.join(
|
|
72
|
+
directory,
|
|
73
|
+
path.basename(filename),
|
|
74
|
+
);
|
|
69
75
|
|
|
70
76
|
let buffer = Buffer.from(
|
|
71
77
|
encoding === 'base64'
|
|
@@ -17,7 +17,7 @@ let shader;
|
|
|
17
17
|
* @param {number} params.height
|
|
18
18
|
* @param {number} params.pixelRatio
|
|
19
19
|
*/
|
|
20
|
-
export
|
|
20
|
+
export function setup({ p, width, height }) {
|
|
21
21
|
shader = p.createShader(
|
|
22
22
|
/* glsl */ `
|
|
23
23
|
attribute vec3 aPosition;
|
|
@@ -39,7 +39,7 @@ void main() {
|
|
|
39
39
|
`,
|
|
40
40
|
fragmentShader,
|
|
41
41
|
);
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* @param {object} params
|
|
@@ -30,6 +30,7 @@ export let onBeforeUpdatePreview = ({ id }) => {
|
|
|
30
30
|
|
|
31
31
|
if (preview) {
|
|
32
32
|
preview.rendered = false;
|
|
33
|
+
preview.p.resetMatrix();
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
|
|
@@ -52,12 +53,13 @@ export let onResizePreview = ({ id, width, height, pixelRatio }) => {
|
|
|
52
53
|
const preview = previews.find((p) => p.id === id);
|
|
53
54
|
|
|
54
55
|
if (preview) {
|
|
55
|
-
preview.p.
|
|
56
|
+
preview.p.pixelDensity(pixelRatio);
|
|
57
|
+
preview.p.resizeCanvas(width, height, false);
|
|
56
58
|
}
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
export let onDestroyPreview = ({ id }) => {
|
|
60
|
-
const previewIndex = previews.
|
|
62
|
+
const previewIndex = previews.findIndex((preview) => preview.id === id);
|
|
61
63
|
const preview = previews[previewIndex];
|
|
62
64
|
|
|
63
65
|
if (preview) {
|
|
@@ -22,16 +22,25 @@ export let onMountPreview = ({ id, width, height }) => {
|
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
export let onBeforeUpdatePreview = ({ id }) => {
|
|
26
|
+
const preview = previews.find((p) => p.id === id);
|
|
27
|
+
|
|
28
|
+
if (preview) {
|
|
29
|
+
preview.p.resetMatrix();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
25
33
|
export let onResizePreview = ({ id, width, height, pixelRatio }) => {
|
|
26
34
|
const preview = previews.find((p) => p.id === id);
|
|
27
35
|
|
|
28
36
|
if (preview) {
|
|
29
|
-
preview.p.
|
|
37
|
+
preview.p.pixelDensity(pixelRatio);
|
|
38
|
+
preview.p.resizeCanvas(width, height, false);
|
|
30
39
|
}
|
|
31
40
|
};
|
|
32
41
|
|
|
33
42
|
export let onDestroyPreview = ({ id }) => {
|
|
34
|
-
const previewIndex = previews.
|
|
43
|
+
const previewIndex = previews.findIndex((p) => p.id === id);
|
|
35
44
|
const preview = previews[previewIndex];
|
|
36
45
|
|
|
37
46
|
if (preview) {
|
|
@@ -182,6 +182,8 @@
|
|
|
182
182
|
async function createSketch(key) {
|
|
183
183
|
_created = false;
|
|
184
184
|
|
|
185
|
+
sketch?.dispose?.();
|
|
186
|
+
|
|
185
187
|
sketch = $sketches[key];
|
|
186
188
|
|
|
187
189
|
if (!key || !sketch) {
|
|
@@ -458,7 +460,7 @@
|
|
|
458
460
|
elapsed += dt;
|
|
459
461
|
|
|
460
462
|
if (!$sync) {
|
|
461
|
-
if (elapsed >= (1 / framerate) * 1000) {
|
|
463
|
+
if (elapsed >= (1 / framerate) * 1000 && _created) {
|
|
462
464
|
elapsed = 0;
|
|
463
465
|
_renderSketch();
|
|
464
466
|
}
|
|
@@ -80,8 +80,8 @@ export function inferFieldType({ type, value, params, key }) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
export function hasChanged(initialValue, currentValue) {
|
|
83
|
-
const initialType = typeof initialValue;
|
|
84
|
-
const currentType = typeof currentValue;
|
|
83
|
+
const initialType = initialValue && typeof initialValue;
|
|
84
|
+
const currentType = currentValue && typeof currentValue;
|
|
85
85
|
|
|
86
86
|
if (initialType !== currentType) return true;
|
|
87
87
|
|