Copies stay where you paste them. Chat apps, email and browser history keep the full link.
Opens view-only: no Edit or Snapshot.
-
+
+
Embed on a website
+
+
+
+
@@ -2276,7 +2293,30 @@
Flow Explainer
const pageUrl=sub=>sub?tidyUrl(rootUrl()+sub):tidyUrl(rootUrl()+'/');
const linkOpts=()=>(DSK!=='original'?'&s='+DSK:'')+(ICONS_ON?'':'&i=0');
const clientLink=async()=>pageUrl(is3dView()?'/3d':'')+'#c='+await encode(/** @type {any} */(S).md)+linkOpts();
-const embedLink=async()=>pageUrl('/embed'+(is3dView()?'/3d':''))+'#c='+await encode(/** @type {any} */(S).md)+linkOpts();
+/**
+ * iframe HTML for pasting into a website, like YouTube's "Embed" code.
+ * @param {string} url the /embed link (with #c=…)
+ * @param {string} size 'r' for responsive (full width, 16:10), or 'WxH' in pixels
+ * @param {string} [title]
+ * @returns {string}
+ */
+function embedCode(url,size,title){
+ const a=(/** @type {string} */v)=>v.replace(/&/g,'&').replace(/"/g,'"').replace(/';
+ return '
\n \n
';
+}
+/**
+ * Embed-only options carried in the link: &t=0 hides the step text panel, &v=0 locks the view.
+ * @param {{text:boolean,switchView:boolean}} o
+ */
+const embedOpts=o=>(o.text?'':'&t=0')+(o.switchView?'':'&v=0');
+/** @param {string} k @returns {string|null} value of k in the URL hash (#c=…&k=v) */
+const hashParam=k=>{const m=location.hash.match(new RegExp('[#&]'+k+'=([^&]*)'));return m?m[1]:null};
+/** In the embed player, apply &t=0 / &v=0 from the link. */
+function applyEmbedOpts(){if(!isEmbed())return;document.body.classList.toggle('no-text',hashParam('t')==='0');document.body.classList.toggle('lock-view',hashParam('v')==='0')}
+const embedLink=async(/** @type {{text:boolean,switchView:boolean}} */o={text:true,switchView:true})=>pageUrl('/embed'+(is3dView()?'/3d':''))+'#c='+await encode(/** @type {any} */(S).md)+linkOpts()+embedOpts(o);
/** @param {'2d'|'3d'} dim */
function viewHref(dim){
const h=location.hash||'';
@@ -2304,6 +2344,7 @@
const url=await clientLink();let ok=true;
try{await navigator.clipboard.writeText(url)}catch(e){ok=false}
$('#shareUrl').value=url;$('#shareTitle span').textContent=ok?'Client link copied':'Copy this client link';openPop('share');
+ await fillEmbed();
if(!ok){$('#shareUrl').focus();$('#shareUrl').select()}
};
$('#shareCopy').onclick=async()=>{try{await navigator.clipboard.writeText($('#shareUrl').value);toast('Client link copied')}catch(e){$('#shareUrl').select()}};
+ /** Fill the embed box from the current diagram, view and size. */
+ const fillEmbed=async()=>{const doc=/** @type {{doc?:{docTitle?:string}|null}} */(/** @type {unknown} */(S)).doc;
+ $('#embedCode').value=embedCode(await embedLink(curOpts()),$('#embedSize').value,(doc&&doc.docTitle)||'Flow Explainer')};
+ const curOpts=()=>({text:$('#embedText').checked,switchView:$('#embedSwitch').checked});
+ $('#embedSize').onchange=$('#embedText').onchange=$('#embedSwitch').onchange=fillEmbed;
+ $('#embedCopy').onclick=async()=>{try{await navigator.clipboard.writeText($('#embedCode').value);toast('Embed code copied')}catch(e){$('#embedCode').select()}};
$('#shareEmbed').onclick=async()=>{
- const url=await embedLink();
+ const url=await embedLink(curOpts());
try{await navigator.clipboard.writeText(url);toast('Embed link copied')}catch(e){prompt('Copy this embed link',url)}
};
$('#panel').addEventListener('keydown',(/** @type {KeyboardEvent} */e)=>{const t=tgt(e),li=/** @type {HTMLElement|null} */(t.closest&&t.closest('.stepper li'));if(li&&(e.key==='Enter'||e.key===' ')){e.preventDefault();e.stopPropagation();go(+(li.dataset.s||0))}});
diff --git a/README.md b/README.md
index 4b4871c..585f93f 100644
--- a/README.md
+++ b/README.md
@@ -276,17 +276,24 @@ To host it, upload the folder to GitHub Pages, Cloudflare Pages, Netlify, S3 or
### Embed in another site
-Use the compact player at `/embed` (2D) or `/embed/3d` (3D) with the same `#c=…` client-link payload. In the app, **Copy client link** → **Copy embed link**, then iframe it:
+Use the compact player at `/embed` (2D) or `/embed/3d` (3D) with the same `#c=…` client-link payload.
+
+In the app, press **Copy client link**. The box that opens has an **Embed on a website** section, like YouTube's embed code:
+- **Size:** pick *Responsive* (full width, 16:10) or a fixed size: 960 × 600, 800 × 500 or 640 × 480.
+- **Show step text:** untick to hide the step list and show only the diagram and the stepper (adds `&t=0`).
+- **Allow 2D / 3D switch:** untick to lock the embed to the view you copied it from: only 2D or only 3D (adds `&v=0`).
+- **Copy embed code** copies the ready-to-paste `
@@ -2292,7 +2309,30 @@
Flow Explainer
const pageUrl=sub=>sub?tidyUrl(rootUrl()+sub):tidyUrl(rootUrl()+'/');
const linkOpts=()=>(DSK!=='original'?'&s='+DSK:'')+(ICONS_ON?'':'&i=0');
const clientLink=async()=>pageUrl(is3dView()?'/3d':'')+'#c='+await encode(/** @type {any} */(S).md)+linkOpts();
-const embedLink=async()=>pageUrl('/embed'+(is3dView()?'/3d':''))+'#c='+await encode(/** @type {any} */(S).md)+linkOpts();
+/**
+ * iframe HTML for pasting into a website, like YouTube's "Embed" code.
+ * @param {string} url the /embed link (with #c=…)
+ * @param {string} size 'r' for responsive (full width, 16:10), or 'WxH' in pixels
+ * @param {string} [title]
+ * @returns {string}
+ */
+function embedCode(url,size,title){
+ const a=(/** @type {string} */v)=>v.replace(/&/g,'&').replace(/"/g,'"').replace(/';
+ return '
\n \n
';
+}
+/**
+ * Embed-only options carried in the link: &t=0 hides the step text panel, &v=0 locks the view.
+ * @param {{text:boolean,switchView:boolean}} o
+ */
+const embedOpts=o=>(o.text?'':'&t=0')+(o.switchView?'':'&v=0');
+/** @param {string} k @returns {string|null} value of k in the URL hash (#c=…&k=v) */
+const hashParam=k=>{const m=location.hash.match(new RegExp('[#&]'+k+'=([^&]*)'));return m?m[1]:null};
+/** In the embed player, apply &t=0 / &v=0 from the link. */
+function applyEmbedOpts(){if(!isEmbed())return;document.body.classList.toggle('no-text',hashParam('t')==='0');document.body.classList.toggle('lock-view',hashParam('v')==='0')}
+const embedLink=async(/** @type {{text:boolean,switchView:boolean}} */o={text:true,switchView:true})=>pageUrl('/embed'+(is3dView()?'/3d':''))+'#c='+await encode(/** @type {any} */(S).md)+linkOpts()+embedOpts(o);
/** @param {'2d'|'3d'} dim */
function viewHref(dim){
const h=location.hash||'';
@@ -2320,6 +2360,7 @@