code formatting
This commit is contained in:
parent
fd1e3d248a
commit
ba7721f53c
5 changed files with 30 additions and 30 deletions
|
|
@ -190,7 +190,6 @@ export class StrudelMirror {
|
||||||
this.onDraw(haps, time, painters);
|
this.onDraw(haps, time, painters);
|
||||||
}, drawTime);
|
}, drawTime);
|
||||||
|
|
||||||
|
|
||||||
this.prebaked = prebake();
|
this.prebaked = prebake();
|
||||||
autodraw && this.drawFirstFrame();
|
autodraw && this.drawFirstFrame();
|
||||||
this.repl = repl({
|
this.repl = repl({
|
||||||
|
|
|
||||||
|
|
@ -172,9 +172,9 @@ export function repl({
|
||||||
// These are Pattern.prototype methods that create persistent visualizations
|
// These are Pattern.prototype methods that create persistent visualizations
|
||||||
// I don't like this approach, feels hacky, but since these methods don't create ids that
|
// I don't like this approach, feels hacky, but since these methods don't create ids that
|
||||||
// can be read through the transpiler, I'm not sure how best to detect them.
|
// can be read through the transpiler, I'm not sure how best to detect them.
|
||||||
// Would probably be better to register these methods through some function that would
|
// Would probably be better to register these methods through some function that would
|
||||||
// tag them better
|
// tag them better
|
||||||
const nonInlineWidgets = ['punchcard', 'spiral', 'scope', 'pitchwheel', 'spectrum', 'pianoroll', 'wordfall',];
|
const nonInlineWidgets = ['punchcard', 'spiral', 'scope', 'pitchwheel', 'spectrum', 'pianoroll', 'wordfall'];
|
||||||
|
|
||||||
for (const widget of nonInlineWidgets) {
|
for (const widget of nonInlineWidgets) {
|
||||||
const widgetRegex = new RegExp(`\\.${widget}\\s*\\(`);
|
const widgetRegex = new RegExp(`\\.${widget}\\s*\\(`);
|
||||||
|
|
@ -187,17 +187,15 @@ export function repl({
|
||||||
|
|
||||||
// Helper function to handle single label code block storage
|
// Helper function to handle single label code block storage
|
||||||
function handleSingleLabelBlock(label, code, options, meta) {
|
function handleSingleLabelBlock(label, code, options, meta) {
|
||||||
|
|
||||||
// Detect if this block contains a non-inline widget
|
// Detect if this block contains a non-inline widget
|
||||||
// For 'all' label, widget info is already on the label object from extractLabelsFromCode
|
// For 'all' label, widget info is already on the label object from extractLabelsFromCode
|
||||||
|
|
||||||
// As mentioned in detectActiveVisualizer, this is a bad approach to
|
// As mentioned in detectActiveVisualizer, this is a bad approach to
|
||||||
// managing non-inline widgets (or widgets that don't have ids)
|
// managing non-inline widgets (or widgets that don't have ids)
|
||||||
// and a proper solution would give them widgets in the transpiler, or at least
|
// and a proper solution would give them widgets in the transpiler, or at least
|
||||||
// track where they are so we don't have to futz around with regexes
|
// track where they are so we don't have to futz around with regexes
|
||||||
const activeVisualizer = label.activeVisualizer !== undefined
|
const activeVisualizer =
|
||||||
? label.activeVisualizer
|
label.activeVisualizer !== undefined ? label.activeVisualizer : detectActiveVisualizer(code);
|
||||||
: detectActiveVisualizer(code);
|
|
||||||
|
|
||||||
if (activeVisualizer !== null) {
|
if (activeVisualizer !== null) {
|
||||||
lastActiveVisualizerLabel = label.name;
|
lastActiveVisualizerLabel = label.name;
|
||||||
|
|
@ -214,7 +212,6 @@ export function repl({
|
||||||
activeVisualizer: activeVisualizer, // Store the widget type if present, null otherwise
|
activeVisualizer: activeVisualizer, // Store the widget type if present, null otherwise
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Clean up any blocks with conflicting ranges
|
// Clean up any blocks with conflicting ranges
|
||||||
for (const [existingKey, existingBlock] of Object.entries(codeBlocks)) {
|
for (const [existingKey, existingBlock] of Object.entries(codeBlocks)) {
|
||||||
if (existingKey !== label.name && existingBlock.range && options.range) {
|
if (existingKey !== label.name && existingBlock.range && options.range) {
|
||||||
|
|
@ -412,7 +409,7 @@ export function repl({
|
||||||
if (labels.length > 0) {
|
if (labels.length > 0) {
|
||||||
for (let i = 0; i < labels.length; i++) {
|
for (let i = 0; i < labels.length; i++) {
|
||||||
// processLabeledBlock(labels, i, code, options, meta);
|
// processLabeledBlock(labels, i, code, options, meta);
|
||||||
// processing transpiler output instead of code is simply to avoid
|
// processing transpiler output instead of code is simply to avoid
|
||||||
// extra regex in detecting whether or not an inline widget has been commented out
|
// extra regex in detecting whether or not an inline widget has been commented out
|
||||||
processLabeledBlock(labels, i, meta.output, options, meta);
|
processLabeledBlock(labels, i, meta.output, options, meta);
|
||||||
}
|
}
|
||||||
|
|
@ -514,7 +511,6 @@ export function repl({
|
||||||
pending: false,
|
pending: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
afterEval?.({ code, pattern, meta, range: options.range, widgetRemoved });
|
afterEval?.({ code, pattern, meta, range: options.range, widgetRemoved });
|
||||||
return pattern;
|
return pattern;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -530,18 +526,18 @@ export function repl({
|
||||||
|
|
||||||
export const getTrigger =
|
export const getTrigger =
|
||||||
({ getTime, defaultOutput }) =>
|
({ getTime, defaultOutput }) =>
|
||||||
async (hap, deadline, duration, cps, t) => {
|
async (hap, deadline, duration, cps, t) => {
|
||||||
// ^ this signature is different from hap.context.onTrigger, as set by Pattern.onTrigger(onTrigger)
|
// ^ this signature is different from hap.context.onTrigger, as set by Pattern.onTrigger(onTrigger)
|
||||||
// TODO: get rid of deadline after https://codeberg.org/uzu/strudel/pulls/1004
|
// TODO: get rid of deadline after https://codeberg.org/uzu/strudel/pulls/1004
|
||||||
try {
|
try {
|
||||||
if (!hap.context.onTrigger || !hap.context.dominantTrigger) {
|
if (!hap.context.onTrigger || !hap.context.dominantTrigger) {
|
||||||
await defaultOutput(hap, deadline, duration, cps, t);
|
await defaultOutput(hap, deadline, duration, cps, t);
|
||||||
}
|
|
||||||
if (hap.context.onTrigger) {
|
|
||||||
// call signature of output / onTrigger is different...
|
|
||||||
await hap.context.onTrigger(hap, getTime(), cps, t);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
errorLogger(err, 'getTrigger');
|
|
||||||
}
|
}
|
||||||
};
|
if (hap.context.onTrigger) {
|
||||||
|
// call signature of output / onTrigger is different...
|
||||||
|
await hap.context.onTrigger(hap, getTime(), cps, t);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
errorLogger(err, 'getTrigger');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,8 @@ export const cleanupDrawContext = (replID) => {
|
||||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||||
|
|
||||||
// clear the big canvas context, ignore inline widgets
|
// clear the big canvas context, ignore inline widgets
|
||||||
Object.keys(animationFrames).forEach((id) =>
|
Object.keys(animationFrames).forEach(
|
||||||
(!replID || id.startsWith(replID)) && !id.startsWith('_') && stopAnimationFrame(id)
|
(id) => (!replID || id.startsWith(replID)) && !id.startsWith('_') && stopAnimationFrame(id),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ export function transpiler(input, options = {}) {
|
||||||
emitMiniLocations = true,
|
emitMiniLocations = true,
|
||||||
emitWidgets = true,
|
emitWidgets = true,
|
||||||
blockBased = false,
|
blockBased = false,
|
||||||
range = []
|
range = [],
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
let ast = parse(input, {
|
let ast = parse(input, {
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,13 @@ import bundleAudioWorkletPlugin from 'vite-plugin-bundle-audioworklet';
|
||||||
import tailwind from '@astrojs/tailwind';
|
import tailwind from '@astrojs/tailwind';
|
||||||
import AstroPWA from '@vite-pwa/astro';
|
import AstroPWA from '@vite-pwa/astro';
|
||||||
|
|
||||||
const site = `https://strudel.cc/`; // root url without a path
|
import process from 'node:process';
|
||||||
const base = '/'; // base path of the strudel site
|
|
||||||
|
const site = process.env.SITE_URL || `https://strudel.cc/`; // root url without a path
|
||||||
|
const base = process.env.BASE_PATH || ''; // base path of the strudel site
|
||||||
|
|
||||||
|
// const site = `https://strudel.cc/`; // root url without a path
|
||||||
|
// const base = '/'; // base path of the strudel site
|
||||||
const baseNoTrailing = base.endsWith('/') ? base.slice(0, -1) : base;
|
const baseNoTrailing = base.endsWith('/') ? base.slice(0, -1) : base;
|
||||||
|
|
||||||
// this rehype plugin fixes relative links
|
// this rehype plugin fixes relative links
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue