mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-17 16:46:04 +00:00
* Split demo site into its own package Move the demo site from packages/webamp/demo/ into packages/webamp-demo/ as a standalone workspace package. This cleanly separates the library (published to npm) from the demo site (deployed to webamp.org). Key changes: - Demo imports webamp source via relative paths (no aliases needed) - Demo has its own package.json with demo-specific deps - Simplified vite config (just nodePolyfills plugin) - Removed vite branching from rollupPlugins.mjs (library-only now) - Renamed build-library -> build in webamp package - Updated turbo.json, CI, netlify config, and code-size workflow - Removed demo-only deps from webamp package (sentry, butterchurn stays for the butterchurn bundle) - Zero bundle size change for the library Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix: add type-check dependency to webamp#build task The webamp-docs package needs type declarations from webamp to type-check. These are generated by tsc (type-check), which must run before the build task. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add updated readme to webamp-demo package Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Document the live reloading dev flow in both readmes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix code-size CI: use deploy script that exists on both branches The compressed-size-action checks out master and runs the build script. Master doesn't have a root "build" script, so revert to using "deploy" which exists on both branches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
104 lines
3.4 KiB
TypeScript
104 lines
3.4 KiB
TypeScript
import { ButterchurnOptions } from "../../webamp/js/types";
|
|
|
|
const KNOWN_PRESET_URLS_REGEXES = [
|
|
/^https:\/\/unpkg\.com\/butterchurn-presets\/.*\.json$/,
|
|
/^https:\/\/unpkg\.com\/butterchurn-presets-weekly\/.*\.json$/,
|
|
/^https:\/\/archive\.org\/cors\/md_.*\.json$/,
|
|
/^https:\/\/s3-us-east-2\.amazonaws\.com\/butterchurn-presets\/.*\.json$/,
|
|
];
|
|
|
|
function presetNameFromURL(url: string) {
|
|
try {
|
|
const urlParts = url.split("/");
|
|
const lastPart = urlParts[urlParts.length - 1];
|
|
const presetName = lastPart.substring(0, lastPart.length - 5); // remove .milk or .json
|
|
return decodeURIComponent(presetName);
|
|
} catch (e) {
|
|
// if something goes wrong parsing url, just use url as the preset name
|
|
console.error(e);
|
|
return url;
|
|
}
|
|
}
|
|
|
|
async function loadButterchurnPresetMapURL(url: string) {
|
|
const resp = await fetch(url);
|
|
const namesToPresetUrls = await resp.json();
|
|
return Object.keys(namesToPresetUrls).map((name: string) => {
|
|
return { name, butterchurnPresetUrl: namesToPresetUrls[name] };
|
|
});
|
|
}
|
|
|
|
export function getButterchurnOptions(
|
|
startWithMilkdropHidden: boolean
|
|
): ButterchurnOptions {
|
|
return {
|
|
importButterchurn: () => {
|
|
return import(
|
|
/* webpackChunkName: "butterchurn" */
|
|
// @ts-ignore
|
|
"butterchurn"
|
|
);
|
|
},
|
|
importConvertPreset: () => {
|
|
return import(
|
|
/* webpackChunkName: "milkdrop-preset-converter" */
|
|
// @ts-ignore
|
|
"milkdrop-preset-converter-aws"
|
|
);
|
|
},
|
|
presetConverterEndpoint:
|
|
"https://p2tpeb5v8b.execute-api.us-east-2.amazonaws.com/default/milkdropShaderConverter",
|
|
getPresets: async () => {
|
|
if ("URLSearchParams" in window) {
|
|
const params = new URLSearchParams(location.search);
|
|
const butterchurnPresetUrlParam = params.get("butterchurnPresetUrl");
|
|
const butterchurnPresetMapUrlParam = params.get(
|
|
"butterchurnPresetMapUrl"
|
|
);
|
|
const milkdropPresetUrl = params.get("milkdropPresetUrl");
|
|
if (butterchurnPresetMapUrlParam) {
|
|
if (
|
|
!KNOWN_PRESET_URLS_REGEXES.some((pattern) =>
|
|
pattern.test(butterchurnPresetMapUrlParam)
|
|
)
|
|
) {
|
|
console.error(
|
|
"Unsupported URL passed as butterchurnPresetMapUrl query param."
|
|
);
|
|
} else {
|
|
return loadButterchurnPresetMapURL(butterchurnPresetMapUrlParam);
|
|
}
|
|
} else if (butterchurnPresetUrlParam) {
|
|
if (
|
|
!KNOWN_PRESET_URLS_REGEXES.some((pattern) =>
|
|
pattern.test(butterchurnPresetUrlParam)
|
|
)
|
|
) {
|
|
console.error(
|
|
"Unsupported URL passed as butterchurnPresetUrl query param."
|
|
);
|
|
} else {
|
|
return [
|
|
{
|
|
name: presetNameFromURL(butterchurnPresetUrlParam),
|
|
butterchurnPresetUrl: butterchurnPresetUrlParam,
|
|
},
|
|
];
|
|
}
|
|
} else if (milkdropPresetUrl) {
|
|
throw new Error("We still need to implement this");
|
|
}
|
|
}
|
|
|
|
const presets = await import(
|
|
/* webpackChunkName: "butterchurn-presets" */
|
|
// @ts-ignore
|
|
"butterchurn-presets"
|
|
);
|
|
return Object.entries(presets.default).map(([name, preset]) => {
|
|
return { name, butterchurnPresetObject: preset as Object };
|
|
});
|
|
},
|
|
butterchurnOpen: !startWithMilkdropHidden,
|
|
};
|
|
}
|