Zum Inhalt

src/share/embedCode.ts

// src/share/embedCode.ts
import type { Preset } from '~/engine/types';
import { PLAYER_BUNDLE_URL } from '~/player/constants';
import { encodePreset } from './encodePreset';

export interface EmbedOptions {
  bundleUrl?: string;
}

/** Builds a ready-to-paste embed snippet: a module script tag loading the
 *  player bundle plus a <physarum-player> carrying the preset as a
 *  self-contained share token. */
export function embedSnippet(preset: Preset, opts: EmbedOptions = {}): string {
  const token = encodePreset(preset);
  const src = opts.bundleUrl ?? PLAYER_BUNDLE_URL;
  return (
    `<script type="module" src="${src}"></script>\n` +
    `<physarum-player preset="token:${token}"></physarum-player>`
  );
}