hyperbook 0.84.5 → 0.86.0
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/dist/assets/directive-embed/client.js +112 -0
- package/dist/assets/directive-embed/style.css +70 -1
- package/dist/assets/directive-struktolab/client.js +54 -0
- package/dist/assets/directive-struktolab/struktolab-editor.umd.js +190 -0
- package/dist/assets/directive-struktolab/struktolab-renderer.umd.js +47 -0
- package/dist/assets/directive-struktolab/style.css +0 -0
- package/dist/assets/directive-youtube/client.js +99 -0
- package/dist/assets/directive-youtube/style.css +63 -0
- package/dist/assets/store.js +3 -1
- package/dist/index.js +661 -379
- package/dist/locales/de.json +9 -1
- package/dist/locales/en.json +9 -1
- package/package.json +3 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
(function(J,st){typeof exports=="object"&&typeof module<"u"?st(exports):typeof define=="function"&&define.amd?define(["exports"],st):(J=typeof globalThis<"u"?globalThis:J||self,st(J.StruktolabRenderer={}))})(this,(function(J){"use strict";const st="http://www.w3.org/2000/svg",bt={color:s=>({TaskNode:"rgb(253, 237, 206)",InputNode:"rgb(253, 237, 206)",OutputNode:"rgb(253, 237, 206)",HeadLoopNode:"rgb(220, 239, 231)",CountLoopNode:"rgb(220, 239, 231)",FootLoopNode:"rgb(220, 239, 231)",BranchNode:"rgb(250, 218, 209)",CaseNode:"rgb(250, 218, 209)",InsertCase:"rgb(250, 218, 209)",TryCatchNode:"rgb(250, 218, 209)",FunctionNode:"rgb(255, 255, 255)"})[s],bw:s=>({TaskNode:"rgb(255, 255, 255)",InputNode:"rgb(255, 255, 255)",OutputNode:"rgb(255, 255, 255)",HeadLoopNode:"rgb(255, 255, 255)",CountLoopNode:"rgb(255, 255, 255)",FootLoopNode:"rgb(255, 255, 255)",BranchNode:"rgb(255, 255, 255)",CaseNode:"rgb(255, 255, 255)",InsertCase:"rgb(255, 255, 255)",TryCatchNode:"rgb(255, 255, 255)",FunctionNode:"rgb(255, 255, 255)"})[s]||"rgb(255, 255, 255)",greyscale:s=>({TaskNode:"rgb(250, 250, 250)",InputNode:"rgb(250, 250, 250)",OutputNode:"rgb(250, 250, 250)",HeadLoopNode:"rgb(245, 245, 245)",CountLoopNode:"rgb(245, 245, 245)",FootLoopNode:"rgb(245, 245, 245)",BranchNode:"rgb(240, 240, 240)",CaseNode:"rgb(240, 240, 240)",InsertCase:"rgb(240, 240, 240)",TryCatchNode:"rgb(240, 240, 240)",FunctionNode:"rgb(255, 255, 255)"})[s]};let wt="color";function S(s){return bt[wt](s)}const pt=40,g=20,K=8,et=6,Pt="#333",kt=1.5;let Et=0,it=null;function xt(s){it||(it=document.createElement("canvas"));const e=it.getContext("2d");return e.font=`${s}px sans-serif`,e}function Ht(s,e,t){if(!s)return[""];const c=xt(t),o=s.split(`
|
|
2
|
+
`),r=[];for(const h of o){if(!h||c.measureText(h).width<=e){r.push(h||"");continue}const n=h.split(/\s+/);let a="";for(const l of n){const u=a?a+" "+l:l;c.measureText(u).width>e&&a?(r.push(a),a=l):a=u}a&&r.push(a)}return r.length?r:[""]}function B(s,e,t){const c=Ht(s,e,t),o=t*1.3;return Math.max(pt,c.length*o+et*2)}function ot(s,e={}){const t=document.createElementNS(st,s);for(const[c,o]of Object.entries(e))t.setAttribute(c,String(o));return t}function Y(s,e,t,c,o,r,h="start"){const n=r!=null?Ht(s,r,o):[s||""],a=o*1.3,l=n.length*a,u=t+(c-l)/2+a/2,b=ot("text",{x:e,"font-size":o,"font-family":"sans-serif",fill:"#333","text-anchor":h,"dominant-baseline":"central"});for(let p=0;p<n.length;p++){const i=ot("tspan",{x:e,dy:p===0?0:a});p===0&&i.setAttribute("y",u),i.textContent=n[p],b.appendChild(i)}return b}function F(s,e,t,c,o){return ot("rect",{x:s,y:e,width:t,height:c,fill:o,stroke:"none"})}function f(s,e,t,c){return ot("line",{x1:s,y1:e,x2:t,y2:c,stroke:Pt,"stroke-width":kt})}function rt(s,e,t){if(t&&t.length===e)return t.map(o=>s*o);const c=s/e;return Array(e).fill(c)}function C(s,e,t){if(!s)return 0;const c=t-K*2;switch(s.type){case"InsertNode":return Et+C(s.followElement,e,t);case"Placeholder":return 0;case"TaskNode":case"InputNode":case"OutputNode":{let o=s.text||"";return s.type==="InputNode"&&(o="▶ "+o),s.type==="OutputNode"&&(o="◀ "+o),B(o,c,e)+C(s.followElement,e,t)}case"InsertCase":return B(s.text||"",c,e)+C(s.followElement,e,t);case"BranchNode":{const o=B(s.text||"",c,e),r=e*1.3+et,h=e*1.3+et,n=o+r+h,a=rt(t,2,s.columnWidths),l=C(s.trueChild,e,a[0]),u=C(s.falseChild,e,a[1]);return n+Math.max(l,u)+C(s.followElement,e,t)}case"CaseNode":{const o=s.cases.length+(s.defaultOn?1:0),r=rt(t,o,s.columnWidths),h=B(s.text||"",c,e),n=e*1.3+et,a=h+n;let l=0;for(let u=0;u<s.cases.length;u++)l=Math.max(l,C(s.cases[u],e,r[u]));return s.defaultOn&&s.defaultNode&&(l=Math.max(l,C(s.defaultNode,e,r[o-1]))),a+l+C(s.followElement,e,t)}case"HeadLoopNode":case"CountLoopNode":{const o=t-g,r=B(s.text||"",c,e),h=C(s.child,e,o),n=Math.max(h,r*.5);return r+n+C(s.followElement,e,t)}case"FootLoopNode":{const o=t-g,r=B(s.text||"",c,e),h=C(s.child,e,o);return Math.max(h,r*.5)+r+C(s.followElement,e,t)}case"FunctionNode":{const o=t-g;let r=s.text||"";s.parameters&&s.parameters.length>0?r+="("+s.parameters.map(u=>u.parName||"").join(", ")+")":r+="()",r+=" {";const h=B(r,c,e),n=C(s.child,e,o),a=Math.max(n,h*.5),l=pt*.6;return h+a+l+C(s.followElement,e,t)}case"TryCatchNode":{const o=t-g,r=B("Try",c,e);let h="Catch";s.text&&(h+=" ("+s.text+")");const n=B(h,c,e),a=C(s.tryChild,e,o),l=Math.max(a,r*.5),u=C(s.catchChild,e,o),b=Math.max(u,n*.5);return r+l+n+b+C(s.followElement,e,t)}default:return 0}}function _(s,e,t,c,o,r){if(!s)return{elements:[],height:0};const h=c-K*2,n=[];switch(s.type){case"InsertNode":{const a=Et,l=_(s.followElement,e,t+a,c,o,r?r-a:void 0);return{elements:l.elements,height:a+l.height}}case"Placeholder":return{elements:[],height:0};case"TaskNode":case"InputNode":case"OutputNode":{const a=S(s.type);let l=s.text||"";s.type==="InputNode"&&(l="▶ "+l),s.type==="OutputNode"&&(l="◀ "+l);const u=B(l,h,o),b=C(s.followElement,o,c),p=u+b,i=r!=null&&r>p?u+(r-p):u;n.push(F(e,t,c,i,a)),n.push(f(e,t,e+c,t)),n.push(f(e,t,e,t+i)),n.push(Y(l,e+K,t,u,o,h));const d=r!=null?r-i:void 0,N=_(s.followElement,e,t+i,c,o,d);return{elements:n.concat(N.elements),height:i+N.height}}case"InsertCase":{const a=S(s.type),l=B(s.text||"",h,o),u=C(s.followElement,o,c),b=l+u,p=r!=null&&r>b?l+(r-b):l;n.push(F(e,t,c,p,a)),n.push(f(e,t,e,t+p)),n.push(Y(s.text||"",e+K,t,l,o,h));const i=r!=null?r-p:void 0,d=_(s.followElement,e,t+p,c,o,i);return{elements:n.concat(d.elements),height:p+d.height}}case"BranchNode":{const a=S(s.type),l=B(s.text||"",h,o),u=o*1.3+et,b=o*1.3+et,p=l+u+b,i=rt(c,2,s.columnWidths),d=e+i[0];n.push(F(e,t,c,p,a)),n.push(f(e,t,e+c,t)),n.push(f(e,t,e,t+p)),n.push(Y(s.text||"",e+c/2,t,l,o,h,"middle"));const N=t+l+u;n.push(f(e,t+l,d,N)),n.push(f(e+c,t+l,d,N));const w=o*.8;n.push(Y("Wahr",e+K,N,b,w,null)),n.push(Y("Falsch",e+c-K,N,b,w,null,"end")),n.push(f(d,N,d,t+p));const U=C(s.trueChild,o,i[0]),E=C(s.falseChild,o,i[1]),A=C(s.followElement,o,c),j=Math.max(U,E),Q=r!=null&&r>p+j+A?r-p-j-A:0,m=j+Q,D=_(s.trueChild,e,t+p,i[0],o,m);n.push(...D.elements);const v=_(s.falseChild,d,t+p,i[1],o,m);n.push(...v.elements),n.push(f(d,t+p,d,t+p+m));const y=p+m,nt=r!=null?r-y:void 0,at=_(s.followElement,e,t+y,c,o,nt);return{elements:n.concat(at.elements),height:y+at.height}}case"CaseNode":{const a=S(s.type),l=s.cases.length+(s.defaultOn?1:0),u=rt(c,l,s.columnWidths),b=B(s.text||"",h,o),p=o*1.3+et,i=b+p;n.push(F(e,t,c,i,a)),n.push(f(e,t,e+c,t)),n.push(f(e,t,e,t+i)),n.push(Y(s.text||"",e+c/2,t,b,o,h,"middle"));const d=[0];for(let m=0;m<l;m++)d.push(d[m]+u[m]);if(s.defaultOn){const m=e+d[l-1];n.push(f(e,t+b,m,t+i)),n.push(f(e+c,t+b,m,t+i));for(let D=1;D<l-1;D++){const v=e+d[D],y=d[D]/d[l-1],nt=t+b+p*y;n.push(f(v,nt,v,t+i))}}else{n.push(f(e,t+b,e+c,t+i));for(let m=1;m<l;m++){const D=e+d[m],v=d[m]/c,y=t+b+p*v;n.push(f(D,y,D,t+i))}}let N=0;for(let m=0;m<s.cases.length;m++){const D=C(s.cases[m],o,u[m]);N=Math.max(N,D)}if(s.defaultOn&&s.defaultNode){const m=C(s.defaultNode,o,u[l-1]);N=Math.max(N,m)}const w=C(s.followElement,o,c),U=r!=null&&r>i+N+w?r-i-N-w:0;N+=U;let E=e;for(let m=0;m<s.cases.length;m++){const D=_(s.cases[m],E,t+i,u[m],o,N);n.push(...D.elements),m>0&&n.push(f(E,t+i,E,t+i+N)),E+=u[m]}if(s.defaultOn&&s.defaultNode){const m=_(s.defaultNode,E,t+i,u[l-1],o,N);n.push(...m.elements),n.push(f(E,t+i,E,t+i+N))}const A=i+N,j=r!=null?r-A:void 0,Q=_(s.followElement,e,t+A,c,o,j);return{elements:n.concat(Q.elements),height:A+Q.height}}case"HeadLoopNode":case"CountLoopNode":{const a=S(s.type),l=B(s.text||"",h,o);n.push(F(e,t,c,l,a)),n.push(f(e,t,e+c,t)),n.push(f(e,t,e,t+l)),n.push(Y(s.text||"",e+K,t,l,o,h));const u=c-g,b=C(s.child,o,u),p=Math.max(b,l*.5);n.push(F(e,t+l,g,p,a)),n.push(f(e,t+l,e,t+l+p)),n.push(f(e+g,t+l,e+g,t+l+p));const i=_(s.child,e+g,t+l,u,o);n.push(...i.elements);const d=l+p,N=r!=null?r-d:void 0,w=_(s.followElement,e,t+d,c,o,N);return{elements:n.concat(w.elements),height:d+w.height}}case"FootLoopNode":{const a=S(s.type),l=c-g,u=B(s.text||"",h,o),b=C(s.child,o,l),p=Math.max(b,u*.5);n.push(F(e,t,g,p,a)),n.push(f(e,t,e+c,t)),n.push(f(e,t,e,t+p)),n.push(f(e+g,t,e+g,t+p));const i=_(s.child,e+g,t,l,o);n.push(...i.elements),n.push(F(e,t+p,c,u,a)),n.push(f(e+g,t+p,e+c,t+p)),n.push(f(e,t+p,e,t+p+u)),n.push(Y(s.text||"",e+K,t+p,u,o,h));const d=p+u,N=r!=null?r-d:void 0,w=_(s.followElement,e,t+d,c,o,N);return{elements:n.concat(w.elements),height:d+w.height}}case"FunctionNode":{const a=S(s.type);let l=s.text||"";if(s.parameters&&s.parameters.length>0){const A=s.parameters.map(j=>j.parName||"").join(", ");l+="("+A+")"}else l+="()";l+=" {";const u=B(l,h,o);n.push(F(e,t,c,u,a)),n.push(f(e,t,e+c,t)),n.push(f(e,t,e,t+u)),n.push(Y(l,e+K,t,u,o,h));const b=c-g,p=C(s.child,o,b),i=Math.max(p,u*.5);n.push(F(e,t+u,g,i,a)),n.push(f(e,t+u,e,t+u+i)),n.push(f(e+g,t+u,e+g,t+u+i));const d=_(s.child,e+g,t+u,b,o);n.push(...d.elements);const N=pt*.6;n.push(F(e,t+u+i,c,N,a)),n.push(f(e+g,t+u+i,e+c,t+u+i)),n.push(f(e,t+u+i,e,t+u+i+N)),n.push(Y("}",e+K,t+u+i,N,o,null));const w=u+i+N,U=r!=null?r-w:void 0,E=_(s.followElement,e,t+w,c,o,U);return{elements:n.concat(E.elements),height:w+E.height}}case"TryCatchNode":{const a=S(s.type),l=c-g,u=B("Try",h,o);n.push(F(e,t,c,u,a)),n.push(f(e,t,e+c,t)),n.push(f(e,t,e,t+u)),n.push(Y("Try",e+K,t,u,o,null));const b=C(s.tryChild,o,l),p=Math.max(b,u*.5);n.push(F(e,t+u,g,p,a)),n.push(f(e,t+u,e,t+u+p)),n.push(f(e+g,t+u,e+g,t+u+p));const i=_(s.tryChild,e+g,t+u,l,o);n.push(...i.elements);const d=t+u+p;let N="Catch";s.text&&(N+=" ("+s.text+")");const w=B(N,h,o);n.push(F(e,d,c,w,a)),n.push(f(e+g,d,e+c,d)),n.push(f(e,d,e,d+w)),n.push(Y(N,e+K,d,w,o,h));const U=C(s.catchChild,o,l),E=Math.max(U,w*.5);n.push(F(e,d+w,g,E,a)),n.push(f(e,d+w,e,d+w+E)),n.push(f(e+g,d+w,e+g,d+w+E)),n.push(f(e,d+w+E,e+g,d+w+E));const A=_(s.catchChild,e+g,d+w,l,o);n.push(...A.elements);const j=u+p+w+E,Q=r!=null?r-j:void 0,m=_(s.followElement,e,t+j,c,o,Q);return{elements:n.concat(m.elements),height:j+m.height}}default:return{elements:[],height:0}}}function _t(s,e={}){const t=e.width||600,c=e.fontSize||14;e.colorMode&&bt[e.colorMode]&&(wt=e.colorMode);const r=C(s,c,t)||40,h=kt,n=ot("svg",{xmlns:st,viewBox:`${-h} ${-h} ${t+h*2} ${r+h*2}`,preserveAspectRatio:"xMinYMin meet"});n.style.display="block",n.style.width="100%",n.style.height="auto";const a=_(s,0,0,t,c);for(const l of a.elements)n.appendChild(l);return n.appendChild(f(t,0,t,a.height)),n.appendChild(f(0,a.height,t,a.height)),n}const dt={if:"falls",else:"sonst",repeat:"wiederhole",while:"solange",for:"für",switch:"unterscheide",case:"fall",function:"funktion",try:"versuche",catch:"fange",input:"eingabe",output:"ausgabe",true:"Wahr",false:"Falsch",default:"Sonst"},Bt={if:"if",else:"else",repeat:"repeat",while:"while",for:"for",switch:"switch",case:"case",function:"function",try:"try",catch:"catch",input:"input",output:"output",true:"True",false:"False",default:"Default"};function X(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}let Tt=0;function $(){return"__pseudo_"+ ++Tt}function L(s){return{id:$(),type:"InsertNode",followElement:s}}function lt(){return{type:"Placeholder"}}function ft(s){const e=s.match(/^(.*?)\s*\[([0-9.,\s]+)\]\s*$/);if(e){const t=e[1].trim(),c=e[2].split(",").map(o=>parseFloat(o.trim())).filter(o=>!isNaN(o));return{text:t,columnWidths:c.length>0?c:null}}return{text:s,columnWidths:null}}function Kt(s){const e=s.split(`
|
|
3
|
+
`),t=[];for(const c of e){const o=c.trimEnd();if(o===""||o.startsWith("#"))continue;const r=c.replace(/\t/g," "),h=r.length-r.trimStart().length;t.push({text:o.trim(),indent:h})}return t}function Lt(s,e){const t=[];let c=0;for(;c<s.length;){const o=s[c];if(o.indent<e)break;if(o.indent>e){c++;continue}const r=[];for(c++;c<s.length&&s[c].indent>e;)r.push(s[c]),c++;t.push({text:o.text,indent:o.indent,children:r})}return t}function mt(s){return s.endsWith(":")?s.slice(0,-1).trimEnd():s}function G(s,e,t){const c=Lt(s,e);if(c.length===0)return L(lt());const o=X(t.try),r=X(t.catch),h=X(t.if),n=X(t.else),a=X(t.repeat),l=X(t.while),u=X(t.for),b=X(t.switch),p=X(t.case),i=X(t.function),d=X(t.input),N=X(t.output),w=new RegExp(`^${o}\\s*:$`,"i"),U=new RegExp(`^${r}\\s+`,"i"),E=new RegExp(`^${h}\\s+`,"i"),A=new RegExp(`^${n}\\s*:$`,"i"),j=new RegExp(`^${a}\\s*:$`,"i"),Q=new RegExp(`^${l}\\s+`,"i"),m=new RegExp(`^${a}\\s+${u}\\s+(.+)\\s*:$`,"i"),D=new RegExp(`^${a}\\s+${l}\\s+(.+)\\s*:$`,"i"),v=new RegExp(`^${i}\\s+(\\w+)\\s*\\(([^)]*)\\)\\s*:$`,"i"),y=new RegExp(`^${b}\\s+(.+)\\s*:$`,"i"),nt=new RegExp(`^${p}\\s+(.+)\\s*:$`,"i"),at=new RegExp(`^${d}\\s*\\(\\s*"?([^"]*)"?\\s*\\)$`,"i"),Yt=new RegExp(`^${N}\\s*\\(\\s*"?([^"]*)"?\\s*\\)$`,"i"),q=[];for(const I of c)q.push({block:I,_skip:!1});for(let I=0;I<q.length-1;I++){const P=q[I].block.text,T=q[I+1].block.text;(w.test(P)&&U.test(T)||E.test(P)&&A.test(T)||j.test(P)&&Q.test(T)&&!T.endsWith(":"))&&(q[I+1]._skip=!0)}let H=L(null);for(let I=q.length-1;I>=0;I--){const P=q[I].block,T=P.text;if(q[I]._skip)continue;const V=I+1<q.length?q[I+1].block:null;if(w.test(T)&&V&&U.test(V.text)){const O=e+4,R=G(P.children,O,t),W=mt(V.text.replace(U,"")),x=G(V.children,O,t);H=L({id:$(),type:"TryCatchNode",text:W,tryChild:R,catchChild:x,followElement:H});continue}if(E.test(T)&&V&&A.test(V.text)){const O=mt(T.replace(E,"")),{text:R,columnWidths:W}=ft(O),x=e+4,z=G(P.children,x,t),tt=G(V.children,x,t),Z={id:$(),type:"BranchNode",text:R,trueChild:z,falseChild:tt,followElement:H};W&&(Z.columnWidths=W),H=L(Z);continue}if(E.test(T)){const O=mt(T.replace(E,"")),{text:R,columnWidths:W}=ft(O),x=e+4,z=G(P.children,x,t),tt={id:$(),type:"BranchNode",text:R,trueChild:z,falseChild:L(lt()),followElement:H};W&&(tt.columnWidths=W),H=L(tt);continue}if(j.test(T)&&V&&Q.test(V.text)&&!V.text.endsWith(":")){const O=V.text.replace(Q,"").trim(),R=e+4,W=G(P.children,R,t);H=L({id:$(),type:"FootLoopNode",text:O,child:W,followElement:H});continue}const Wt=T.match(m);if(Wt){const O=e+4,R=G(P.children,O,t);H=L({id:$(),type:"CountLoopNode",text:Wt[1],child:R,followElement:H});continue}const Ft=T.match(D);if(Ft){const O=e+4,R=G(P.children,O,t);H=L({id:$(),type:"HeadLoopNode",text:Ft[1],child:R,followElement:H});continue}const Nt=T.match(v);if(Nt){const O=Nt[1],R=Nt[2].trim(),W=R?R.split(",").map((Z,ct)=>({pos:String(ct*3),parName:Z.trim()})):[],x=e+4,z=G(P.children,x,t);H=L({id:$(),type:"FunctionNode",text:O,parameters:W,child:z,followElement:H});continue}const $t=T.match(y);if($t){const O=$t[1],{text:R,columnWidths:W}=ft(O),x=e+4,z=Lt(P.children,x),tt=[];let Z=null,ct=!1;for(const ht of z){const jt=ht.text.match(nt);if(jt){const gt=x+4,Ct=G(ht.children,gt,t);tt.push({id:$(),type:"InsertCase",text:jt[1].replace(/^"(.*)"$/,"$1"),followElement:Ct})}else if(A.test(ht.text)){ct=!0;const gt=x+4,Ct=G(ht.children,gt,t);Z={id:$(),type:"InsertCase",text:t.default,followElement:Ct}}}Z||(Z={id:$(),type:"InsertCase",text:t.default,followElement:L(lt())});const At={id:$(),type:"CaseNode",text:R,defaultOn:ct,defaultNode:Z,cases:tt,followElement:H};W&&(At.columnWidths=W),H=L(At);continue}const Mt=T.match(at);if(Mt){H=L({id:$(),type:"InputNode",text:Mt[1],followElement:H});continue}const Dt=T.match(Yt);if(Dt){H=L({id:$(),type:"OutputNode",text:Dt[1],followElement:H});continue}H=L({id:$(),type:"TaskNode",text:T,followElement:H})}return H}function ut(s,e=dt){Tt=0;const t=Kt(s);if(t.length===0)return L(lt());const c=Math.min(...t.map(o=>o.indent));return G(t,c,e)}const It={python:{InputNode:{pre:"",post:` = input("Eingabe")
|
|
4
|
+
`},OutputNode:{pre:"print(",post:`)
|
|
5
|
+
`},TaskNode:{pre:"",post:`
|
|
6
|
+
`},BranchNode:{pre:"if ",post:`:
|
|
7
|
+
`,between:`else:
|
|
8
|
+
`},TryCatchNode:{pre:`try:
|
|
9
|
+
`,between:"except ",post:`:
|
|
10
|
+
`},CountLoopNode:{pre:"for ",post:`:
|
|
11
|
+
`},HeadLoopNode:{pre:"while ",post:`:
|
|
12
|
+
`},FootLoopNode:{prepre:`while True:
|
|
13
|
+
`,pre:" if not ",post:`:
|
|
14
|
+
break
|
|
15
|
+
`},FunctionNode:{pre:"def ",between:"(",post:`):
|
|
16
|
+
`},CaseNode:{pre:"if ",post:`:
|
|
17
|
+
`},InsertCase:{preNormal:"elif ",preDefault:"else",post:`:
|
|
18
|
+
`,postpost:`
|
|
19
|
+
`},leftBracket:"",rightBracket:"",pseudoSwitch:!0},java:{InputNode:{pre:"",post:` = System.console().readLine();
|
|
20
|
+
`},OutputNode:{pre:"System.out.println(",post:`);
|
|
21
|
+
`},TaskNode:{pre:"",post:`;
|
|
22
|
+
`},BranchNode:{pre:"if (",post:")",between:`} else {
|
|
23
|
+
`},TryCatchNode:{pre:"try",between:"catch (",post:")"},CountLoopNode:{pre:"for (",post:")"},HeadLoopNode:{pre:"while (",post:")"},FootLoopNode:{prepre:"do",pre:"while (",post:`);
|
|
24
|
+
`},FunctionNode:{pre:"public void ",between:"(",post:")"},CaseNode:{pre:"switch (",post:")"},InsertCase:{preNormal:"case ",preDefault:"default",post:`:
|
|
25
|
+
`,postpost:`break;
|
|
26
|
+
`},leftBracket:"{",rightBracket:"}",pseudoSwitch:!1},javascript:{InputNode:{pre:"",post:` = prompt("Eingabe");
|
|
27
|
+
`},OutputNode:{pre:"console.log(",post:`);
|
|
28
|
+
`},TaskNode:{pre:"",post:`;
|
|
29
|
+
`},BranchNode:{pre:"if (",post:")",between:`} else {
|
|
30
|
+
`},TryCatchNode:{pre:"try",between:"catch (",post:")"},CountLoopNode:{pre:"for (",post:")"},HeadLoopNode:{pre:"while (",post:")"},FootLoopNode:{prepre:"do",pre:"while (",post:`);
|
|
31
|
+
`},FunctionNode:{pre:"function ",between:"(",post:")"},CaseNode:{pre:"switch (",post:")"},InsertCase:{preNormal:"case ",preDefault:"default",post:`:
|
|
32
|
+
`,postpost:`break;
|
|
33
|
+
`},leftBracket:"{",rightBracket:"}",pseudoSwitch:!1}};function k(s){return" ".repeat(s)}function Ot(s,e="python"){const t=It[e.toLowerCase()];if(!t)throw new Error(`Unsupported language: ${e}. Supported: ${Object.keys(It).join(", ")}`);return M(s,0,t,e.toLowerCase()).join("")}function M(s,e,t,c){if(!s)return[];if(s.type==="InsertNode"||s.type==="Placeholder")return M(s.followElement,e,t,c);const o=s.text||"",r=[];switch(s.type){case"TaskNode":r.push(k(e)+t.TaskNode.pre+o+t.TaskNode.post);break;case"InputNode":r.push(k(e)+t.InputNode.pre+o+t.InputNode.post);break;case"OutputNode":r.push(k(e)+t.OutputNode.pre+o+t.OutputNode.post);break;case"BranchNode":{r.push(k(e)+t.BranchNode.pre+o+t.BranchNode.post+(t.leftBracket?" "+t.leftBracket+`
|
|
34
|
+
`:"")),r.push(...M(s.trueChild,e+1,t,c)),r.push(k(e)+t.BranchNode.between),r.push(...M(s.falseChild,e+1,t,c)),t.rightBracket&&r.push(k(e)+t.rightBracket+`
|
|
35
|
+
`);break}case"HeadLoopNode":r.push(k(e)+t.HeadLoopNode.pre+o+t.HeadLoopNode.post+(t.leftBracket?" "+t.leftBracket+`
|
|
36
|
+
`:"")),r.push(...M(s.child,e+1,t,c)),t.rightBracket&&r.push(k(e)+t.rightBracket+`
|
|
37
|
+
`);break;case"CountLoopNode":r.push(k(e)+t.CountLoopNode.pre+o+t.CountLoopNode.post+(t.leftBracket?" "+t.leftBracket+`
|
|
38
|
+
`:"")),r.push(...M(s.child,e+1,t,c)),t.rightBracket&&r.push(k(e)+t.rightBracket+`
|
|
39
|
+
`);break;case"FootLoopNode":{r.push(k(e)+t.FootLoopNode.prepre+(t.leftBracket?" "+t.leftBracket+`
|
|
40
|
+
`:"")),r.push(...M(s.child,e+1,t,c)),t.pseudoSwitch?r.push(k(e)+t.FootLoopNode.pre+o+t.FootLoopNode.post):(t.rightBracket&&r.push(k(e)+t.rightBracket+" "),r.push(t.FootLoopNode.pre+o+t.FootLoopNode.post));break}case"FunctionNode":{const h=(s.parameters||[]).map(n=>n.parName).join(", ");r.push(k(e)+t.FunctionNode.pre+o+t.FunctionNode.between+h+t.FunctionNode.post+(t.leftBracket?" "+t.leftBracket+`
|
|
41
|
+
`:"")),r.push(...M(s.child,e+1,t,c)),t.rightBracket&&r.push(k(e)+t.rightBracket+`
|
|
42
|
+
`);break}case"TryCatchNode":{r.push(k(e)+t.TryCatchNode.pre+(t.leftBracket?" "+t.leftBracket+`
|
|
43
|
+
`:"")),r.push(...M(s.tryChild,e+1,t,c)),r.push(k(e)+(t.rightBracket?t.rightBracket+" ":"")+t.TryCatchNode.between+o+t.TryCatchNode.post+(t.leftBracket?" "+t.leftBracket+`
|
|
44
|
+
`:"")),r.push(...M(s.catchChild,e+1,t,c)),t.rightBracket&&r.push(k(e)+t.rightBracket+`
|
|
45
|
+
`);break}case"CaseNode":{if(t.pseudoSwitch){let h=!0;for(const n of s.cases||[])if(n.type==="InsertCase"){const a=h?"if ":t.InsertCase.preNormal;r.push(k(e)+a+o+" == "+n.text+t.InsertCase.post),r.push(...M(n.followElement,e+1,t,c)),h=!1}s.defaultOn&&s.defaultNode&&(r.push(k(e)+t.InsertCase.preDefault+t.InsertCase.post),r.push(...M(s.defaultNode.followElement,e+1,t,c)))}else{r.push(k(e)+t.CaseNode.pre+o+t.CaseNode.post+(t.leftBracket?" "+t.leftBracket+`
|
|
46
|
+
`:""));for(const h of s.cases||[])h.type==="InsertCase"&&(r.push(k(e+1)+t.InsertCase.preNormal+h.text+t.InsertCase.post),r.push(...M(h.followElement,e+2,t,c)),t.InsertCase.postpost&&r.push(k(e+2)+t.InsertCase.postpost));s.defaultOn&&s.defaultNode&&(r.push(k(e+1)+t.InsertCase.preDefault+t.InsertCase.post),r.push(...M(s.defaultNode.followElement,e+2,t,c)),c==="java"&&r.push(k(e+2)+t.InsertCase.postpost)),t.rightBracket&&r.push(k(e)+t.rightBracket+`
|
|
47
|
+
`)}break}}return r.push(...M(s.followElement,e,t,c)),r}class Rt extends HTMLElement{static get observedAttributes(){return["width","font-size","src","lang","scale","color-mode"]}constructor(){super(),this._tree=null,this._keywords=null,this._shadow=this.attachShadow({mode:"open"});const e=document.createElement("style");e.textContent=":host { display: block; width: 100%; }",this._shadow.appendChild(e),this._container=document.createElement("div"),this._shadow.appendChild(this._container)}connectedCallback(){requestAnimationFrame(()=>this._initialize())}_getKeywords(){return this._keywords?this._keywords:(this.getAttribute("lang")||"de").toLowerCase()==="en"?Bt:dt}_initialize(){if(!this._tree){const e=this.querySelector('script[type="text/pseudocode"]');if(e)try{this._tree=ut(e.textContent,this._getKeywords())}catch(t){console.error("struktolab-renderer: failed to parse pseudocode",t)}}if(!this._tree){const e=this.querySelector('script[type="application/json"]');if(e)try{this._tree=JSON.parse(e.textContent)}catch(t){console.error("struktolab-renderer: invalid inline JSON",t)}}if(!this._tree&&this.hasAttribute("src")){this._fetchTree(this.getAttribute("src"));return}this._render()}attributeChangedCallback(e,t,c){if(e==="src"&&c&&c!==t)this._fetchTree(c);else if(e==="lang"){const o=this.querySelector('script[type="text/pseudocode"]');if(o)try{this._tree=ut(o.textContent,this._getKeywords())}catch{}this._render()}else this._render()}set tree(e){this._tree=e,this._render()}get tree(){return this._tree}set keywords(e){this._keywords=e}get keywords(){return this._getKeywords()}set pseudocode(e){this._tree=ut(e,this._getKeywords()),this._render()}toCode(e){return this._tree?Ot(this._tree,e):""}async _fetchTree(e){try{const t=await fetch(e);this._tree=await t.json(),this._render()}catch(t){console.error("struktolab-renderer: failed to fetch tree from",e,t)}}_resolveWidth(){const e=parseFloat(this.getAttribute("scale"))||1,t=this.clientWidth||this.getBoundingClientRect().width||600;return Math.round(t/e)}_render(){if(!this._tree)return;const e=parseInt(this.getAttribute("font-size"),10)||14;this.getAttribute("width"),parseFloat(this.getAttribute("scale"));const t=this.getAttribute("color-mode")||"color",c=this._resolveWidth();for(;this._container.firstChild;)this._container.removeChild(this._container.firstChild);const o=_t(this._tree,{width:c,fontSize:e,colorMode:t});this._container.appendChild(o)}}customElements.get("struktolab-renderer")||customElements.define("struktolab-renderer",Rt),J.KEYWORDS_DE=dt,J.KEYWORDS_EN=Bt,J.StruktolabRenderer=Rt,J.generateCode=Ot,J.parsePseudocode=ut,J.renderStructogramSVG=_t,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"})}));
|
|
File without changes
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/// <reference path="../hyperbook.types.js" />
|
|
2
|
+
window.hyperbook = window.hyperbook || {};
|
|
3
|
+
|
|
4
|
+
hyperbook.youtube = hyperbook.youtube || {};
|
|
5
|
+
|
|
6
|
+
hyperbook.youtube.consent = (function () {
|
|
7
|
+
var CONSENT_ID = "youtube";
|
|
8
|
+
|
|
9
|
+
async function isAllowed() {
|
|
10
|
+
try {
|
|
11
|
+
var entry = await hyperbook.store.consent.get(CONSENT_ID);
|
|
12
|
+
return entry?.allowed === true;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function allow() {
|
|
19
|
+
await hyperbook.store.consent.put({ id: CONSENT_ID, allowed: true });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function loadContent(wrapper) {
|
|
23
|
+
var banner = wrapper.querySelector(".directive-youtube-consent-banner");
|
|
24
|
+
if (banner) {
|
|
25
|
+
banner.remove();
|
|
26
|
+
}
|
|
27
|
+
var iframe = wrapper.querySelector("iframe");
|
|
28
|
+
if (iframe) {
|
|
29
|
+
var src = iframe.getAttribute("data-consent-src");
|
|
30
|
+
if (src) {
|
|
31
|
+
iframe.setAttribute("src", src);
|
|
32
|
+
iframe.removeAttribute("data-consent-src");
|
|
33
|
+
iframe.style.display = "";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function initWrapper(wrapper) {
|
|
39
|
+
if (wrapper.getAttribute("data-consent-initialized")) return;
|
|
40
|
+
wrapper.setAttribute("data-consent-initialized", "true");
|
|
41
|
+
|
|
42
|
+
var allowed = await isAllowed();
|
|
43
|
+
if (allowed) {
|
|
44
|
+
loadContent(wrapper);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var btn = wrapper.querySelector(".directive-youtube-consent-accept-btn");
|
|
49
|
+
var checkbox = wrapper.querySelector(
|
|
50
|
+
".directive-youtube-consent-always-checkbox"
|
|
51
|
+
);
|
|
52
|
+
if (btn) {
|
|
53
|
+
btn.addEventListener("click", async function () {
|
|
54
|
+
if (checkbox && checkbox.checked) {
|
|
55
|
+
await allow();
|
|
56
|
+
}
|
|
57
|
+
loadContent(wrapper);
|
|
58
|
+
if (checkbox && checkbox.checked) {
|
|
59
|
+
document
|
|
60
|
+
.querySelectorAll(".directive-youtube-consent")
|
|
61
|
+
.forEach(function (el) {
|
|
62
|
+
loadContent(el);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function init(root) {
|
|
70
|
+
var wrappers = root.querySelectorAll
|
|
71
|
+
? root.querySelectorAll(".directive-youtube-consent")
|
|
72
|
+
: [];
|
|
73
|
+
wrappers.forEach(function (w) {
|
|
74
|
+
initWrapper(w);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
79
|
+
init(document);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
var observer = new MutationObserver(function (mutations) {
|
|
83
|
+
mutations.forEach(function (mutation) {
|
|
84
|
+
mutation.addedNodes.forEach(function (node) {
|
|
85
|
+
if (node.nodeType === 1) {
|
|
86
|
+
init(node);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
isAllowed: isAllowed,
|
|
96
|
+
allow: allow,
|
|
97
|
+
init: init,
|
|
98
|
+
};
|
|
99
|
+
})();
|
|
@@ -14,3 +14,66 @@
|
|
|
14
14
|
height: 100%;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
.directive-youtube-consent {
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: 0;
|
|
20
|
+
left: 0;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.directive-youtube-consent iframe[data-consent-src] {
|
|
26
|
+
display: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.directive-youtube-consent-banner {
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
gap: 12px;
|
|
35
|
+
padding: 24px;
|
|
36
|
+
background-color: var(--color-background-tinted, #f5f5f5);
|
|
37
|
+
border: 2px solid var(--color-brand, #333);
|
|
38
|
+
border-radius: 8px;
|
|
39
|
+
text-align: center;
|
|
40
|
+
height: 100%;
|
|
41
|
+
box-sizing: border-box;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.directive-youtube-consent-banner-text {
|
|
45
|
+
font-size: 0.95em;
|
|
46
|
+
line-height: 1.5;
|
|
47
|
+
color: var(--color-text, #333);
|
|
48
|
+
max-width: 600px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.directive-youtube-consent-always-label {
|
|
52
|
+
display: flex;
|
|
53
|
+
align-items: center;
|
|
54
|
+
gap: 6px;
|
|
55
|
+
font-size: 0.85em;
|
|
56
|
+
color: var(--color-text, #333);
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.directive-youtube-consent-always-checkbox {
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
margin: 0!important;
|
|
63
|
+
vertical-align: middle;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.directive-youtube-consent-accept-btn {
|
|
67
|
+
padding: 8px 24px;
|
|
68
|
+
background-color: var(--color-brand, #333);
|
|
69
|
+
color: var(--color-brand-text, #fff);
|
|
70
|
+
border: none;
|
|
71
|
+
border-radius: 4px;
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
font-size: 0.95em;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.directive-youtube-consent-accept-btn:hover {
|
|
77
|
+
opacity: 0.9;
|
|
78
|
+
}
|
|
79
|
+
|
package/dist/assets/store.js
CHANGED
|
@@ -12,7 +12,8 @@ window.hyperbook = window.hyperbook || {};
|
|
|
12
12
|
hyperbook.store = (function () {
|
|
13
13
|
/** @type {import("dexie").Dexie} */
|
|
14
14
|
var db = new Dexie("Hyperbook");
|
|
15
|
-
db.version(
|
|
15
|
+
db.version(4).stores({
|
|
16
|
+
consent: `id`,
|
|
16
17
|
currentState: `
|
|
17
18
|
id,
|
|
18
19
|
path,
|
|
@@ -42,6 +43,7 @@ hyperbook.store = (function () {
|
|
|
42
43
|
onlineide: `scriptId,script`,
|
|
43
44
|
sqlideScripts: `scriptId,script`,
|
|
44
45
|
sqlideDatabases: `databaseId,database`,
|
|
46
|
+
struktolab: `id,tree`,
|
|
45
47
|
multievent: `id,state`,
|
|
46
48
|
typst: `id,code`,
|
|
47
49
|
});
|