@plotdb/lotion 0.1.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/audio/sfx.py ADDED
@@ -0,0 +1,93 @@
1
+ # UI 音效合成 ( 整理自 0926-motion ). 輸出 <outdir>/*.wav, 並量測每個檔的 transient peak 寫入 <outdir>/peaks.json
2
+ # python audio/sfx.py <outdir> [--list]
3
+ # peak 定義: 3ms RMS 包絡第一次達到全域最大 80% 的位置
4
+ # - 多音符音效 ( chime / toggle ) 取第一個音的擊點, 而非較晚但較響的音
5
+ # - 混音時以 peak 而非檔案開頭對齊 cue 時間 ( 見 mix.py )
6
+ import numpy as np, json, os, argparse
7
+ from common import SR, write
8
+
9
+ rng = np.random.default_rng(7)
10
+
11
+ def t_(dur): return np.arange(int(SR * dur)) / SR
12
+ def env(t, a, d): return (1 - np.exp(-t / max(a, 1e-4))) * np.exp(-t / d)
13
+ def bandnoise(n, lo, hi):
14
+ x = rng.standard_normal(n)
15
+ X = np.fft.rfft(x); f = np.fft.rfftfreq(n, 1 / SR)
16
+ X[(f < lo) | (f > hi)] = 0
17
+ y = np.fft.irfft(X, n); return y / (np.abs(y).max() + 1e-9)
18
+ def sine(t, f, ph=0): return np.sin(2 * np.pi * f * t + ph)
19
+ def pad(x, pre=0.0, post=0.0): return np.concatenate([np.zeros(int(SR * pre)), x, np.zeros(int(SR * post))])
20
+
21
+ def click():
22
+ t = t_(0.06)
23
+ body = sine(t, 1850) * env(t, 0.0004, 0.006) * 0.7 + sine(t, 520) * env(t, 0.0008, 0.012) * 0.5
24
+ return body + bandnoise(len(t), 2500, 9000) * env(t, 0.0002, 0.003) * 0.5
25
+
26
+ def tick():
27
+ t = t_(0.03)
28
+ return sine(t, 3400) * env(t, 0.0003, 0.004) * 0.6 + bandnoise(len(t), 4000, 12000) * env(t, 0.0002, 0.0015) * 0.3
29
+
30
+ def scrub():
31
+ t = t_(0.015)
32
+ return bandnoise(len(t), 5000, 12000) * env(t, 0.0002, 0.0012) * 0.5
33
+
34
+ def pop():
35
+ t = t_(0.14)
36
+ f = 380 + 520 * np.exp(-t / 0.018)
37
+ return np.sin(2 * np.pi * np.cumsum(f) / SR) * env(t, 0.001, 0.035) * 0.9
38
+
39
+ def toggle():
40
+ a = click() * 0.6
41
+ t = t_(0.05)
42
+ b = sine(t, 2600) * env(t, 0.0004, 0.005) * 0.6 + sine(t, 780) * env(t, 0.0006, 0.01) * 0.4
43
+ out = np.zeros(int(SR * 0.12)); out[:len(a)] += a
44
+ o = int(SR * 0.028); out[o:o + len(b)] += b
45
+ return out
46
+
47
+ def chime(notes, gap, dur=0.5):
48
+ out = np.zeros(int(SR * (gap * len(notes) + dur)))
49
+ for i, f in enumerate(notes):
50
+ t = t_(dur)
51
+ x = (sine(t, f) + 0.25 * sine(t, f * 2.01) + 0.08 * sine(t, f * 3.02)) * env(t, 0.002, 0.16)
52
+ o = int(SR * gap * i); out[o:o + len(x)] += x * (0.8 if i == 0 else 0.65)
53
+ return out * 0.45
54
+
55
+ def success(): return chime([1318.5, 1975.5], 0.07)
56
+ def notify(): return chime([1567.98, 2093.0, 2637.0], 0.06, 0.45)
57
+
58
+ def typing():
59
+ t = t_(0.05)
60
+ return bandnoise(len(t), 1200, 6000) * env(t, 0.0003, 0.005) * 0.55 + sine(t, 210) * env(t, 0.001, 0.01) * 0.35
61
+
62
+ def whoosh():
63
+ t = t_(0.32)
64
+ n = bandnoise(len(t), 300, 4000)
65
+ e = np.sin(np.pi * np.clip(t / 0.32, 0, 1)) ** 2.5
66
+ return n * e * 0.18
67
+
68
+ SFX = dict(click=click, tick=tick, scrub=scrub, pop=pop, toggle=toggle, success=success, notify=notify,
69
+ type=typing, whoosh=whoosh)
70
+
71
+ def peak(x):
72
+ win = int(SR * 0.003)
73
+ e = np.sqrt(np.convolve(x * x, np.ones(win) / win, 'same'))
74
+ i = int(np.argmax(e >= 0.8 * e.max()))
75
+ # 往後找到該段的局部最大
76
+ while i + 1 < len(e) and e[i + 1] >= e[i]: i += 1
77
+ return i
78
+
79
+ if __name__ == '__main__':
80
+ ap = argparse.ArgumentParser(description='synthesize ui sound effects')
81
+ ap.add_argument('outdir')
82
+ ap.add_argument('--list', action='store_true', help='only list available effects')
83
+ a = ap.parse_args()
84
+ if a.list:
85
+ print(' '.join(SFX)); raise SystemExit
86
+ os.makedirs(a.outdir, exist_ok=True)
87
+ peaks = {}
88
+ for name, fn in SFX.items():
89
+ x = pad(fn(), 0.005, 0.02)
90
+ write(os.path.join(a.outdir, name + '.wav'), x)
91
+ peaks[name] = round(peak(x) / SR, 5)
92
+ json.dump(peaks, open(os.path.join(a.outdir, 'peaks.json'), 'w'), indent=1)
93
+ print(json.dumps(peaks, indent=1))
@@ -0,0 +1,16 @@
1
+ /* @plotdb/semver/index.min.js */
2
+ !function(){var i=/(\D*)([^-+]+)(?:-([.0-9a-zA-Z]*))?(?:\+([.0-9a-zA-Z]*))?/,n=/^\d+(\.\d+){0,2}(-[.0-9a-zA-Z]+)?(\+[.0-9a-zA-Z]+)?$/,t=/^([~^]|>=?)?\d+(\.\d+){0,2}(-[.0-9a-zA-Z]+)?(\+[.0-9a-zA-Z]+)?$/,f=function(r){var n,t,e;return(r=i.exec(r))?(t=(n=[r[2].split("."),r[1]||""])[0],e=n[1]):(t=(n=[[],"",[]])[0],e=n[1],r=n[2]),[+(t[0]||0),+(t[1]||0),+(t[2]||0),r[3]||"",r[4]||"",e]},a=function(r,n){var t,e,i,a,u,f,o,s,l;if(r!==n){if(!r)return 1;if(!n)return-1;for(e=(t=[r.split("."),n.split(".")])[0],i=t[1],a=0,u=Math.max(e.length,i.length);a<u;++a){if(void 0===(f=(t=[e[f=a],i[f]])[0]))return-1;if(void 0===(o=t[1]))return 1;if(f!==o)return s=(t=[+f,+o])[0],l=t[1],isNaN(s)||isNaN(l)?!isNaN(s)||isNaN(l)&&f<o?-1:1:s<l?-1:1}}return 0},o=function(r,n){var t,e,i=[Array.isArray(r)?r:f(r||""),Array.isArray(n)?n:f(n||"")];for(r=i[0],n=i[1],t=0;t<3;++t)if(r[e=t]!==n[e])return r[e]<n[e]?-1:1;return a(r[3],n[3])},s=function(r,n){var t,e,i,a=[Array.isArray(r)?r:f(r||""),Array.isArray(n)?n:f(n||"")],u=o(r=a[0],n=a[1]);if(!n[5])return 0===u;if(r[3]&&(!n[3]||r[0]!==n[0]||r[1]!==n[1]||r[2]!==n[2]))return!1;switch(n[5]){case"^":for(t=0<n[0]?0:0<n[1]?1:2,e=0;e<=t;++e)if(r[i=e]!==n[i])return!1;return 0<=u;case"~":return r[0]===n[0]&&r[1]===n[1]&&0<=u;case">":return 0<u;case">=":return 0<=u;default:return 0===u}},r={parse:f,fit:s,compare:o,maxSatisfying:function(r,n){for(var t,e,i=null,a=0,u=(t=r||[]).length;a<u;++a)e=t[a],s(e,n)&&(null===i||0<o(e,i))&&(i=e);return i},valid:function(r){return"string"==typeof r&&n.test(r)},validRange:function(r){return"string"==typeof r&&t.test(r)}};"undefined"!=typeof module&&null!==module?module.exports=r:"undefined"!=typeof window&&null!==window&&(window.semver=r)}.call(this);;
3
+ /* proxise/index.min.js */
4
+ (function(){var n,e;n=function(n,e,t){return n.splice(0,n.length).map(function(n){if(n[t](e),n.timeout)return clearTimeout(n.timeout)})},(e=function(e,t){var i,r,o,u,l;return i=e instanceof Function?[e,t||0]:[t,e||0],r=i[0],o=i[1],u=[],l=function(){var n,e,t,i,l,f,c;for(e=[],t=0,i=arguments.length;t<i;++t)e.push(arguments[t]);return n=e,(l=r.apply(this,n))instanceof Promise?l:(f=null,c=o?setTimeout(function(){var n;if(f&&~(n=u.indexOf(f)))return u.splice(n,1),f.rej(new Error("timeout"))},o):null,new Promise(function(n,e){return u.push(f={res:n,rej:e,timeout:c})}))},l.resolve=function(e){return n(u,e,"res")},l.reject=function(e){return n(u,e,"rej")},l}).once=function(n,t){var i,r;return i={},r=e(function(){var e,o,u,l,f=this;for(o=[],u=0,l=arguments.length;u<l;++u)o.push(arguments[u]);return e=o,i.inited?Promise.resolve(null==t?i.val:"function"==typeof t?t():t):i.initing?void 0:(i.initing=!0,Promise.resolve().then(function(){return n.apply(f,e)}).finally(function(){return i.initing=!1}).then(function(n){return i.inited=!0,r.resolve(n=null==t?i.val=n:"function"==typeof t?t():t),n}).catch(function(n){return r.reject(n),Promise.reject(n)}))})},"undefined"!=typeof module&&null!==module?module.exports=e:"undefined"!=typeof window&&null!==window&&(window.proxise=e)}).call(this);
5
+ ;
6
+ /* @plotdb/csscope/index.min.js */
7
+ !function(){var t,g,o,f,x=[].slice;function s(e,t){var n,r={}.hasOwnProperty;for(n in t)r.call(t,n)&&(e[n]=t[n]);return e}g=function(e){return/^:scope[ .:\[#]|^:scope$/.exec(e)},o=function(e,t){return f.__node&&"undefined"!=typeof fs&&null!==fs&&!/^https?:/.exec(e)?new Promise(function(n,r){return fs.readFile(e,function(e,t){return e?r(e):n(t.toString())})}):fetch(e,t).then(function(i){var e;return i&&i.ok?i.text():i?i.clone().text().then(function(e){var t,n=i.status||404,r=new Error(n+" "+e);r.name="lderror",r.id=n,r.message=e,n=r;try{(t=JSON.parse(e))&&"lderror"===t.name&&(s(n,t).json=t)}catch(e){0}return Promise.reject(n)}):Promise.reject(((e=new Error("404")).name="lderror",e.id=404,e))})},(f=function(e,t,n,r){return f.default||(f.default=new f.converter),f.default.convert(e,t,n,r)}).env=function(e){e=[e,e.document];return t=e[1],e},f.id=function(e){var t=e.path||("js"===e.type?"index.min.js":"css"===e.type?"index.min.css":"index.html");return e.id||e.url||(e.ns?e.ns+":":"")+e.name+"@"+(e.version||"main")+":"+t},f.scope=function(e){return e.scope||"_"+btoa(f.id(e)).replace(/=/g,"_")},f._cache={},f._ver={map:{},list:{}},f.cache=function(e){var t,l,n,r,i,s,o,c,a,h,u;if((e="string"==typeof e?{url:e}:e).id||(e.id=f.id(e)),t=this._cache[e.id])return t;if(e.id&&!e.name?((i=e.id.split(":")).length<=2?(l=i[0],n=i[1],r=i[2]):(r=i[0],l=i[1],n=i[2]),s=(i=(i=/^(@?[^@]+)(?:@([^:]+))?$/.exec(l))?i:["",e.id,""])[1],o=i[2]):(r=(c=[e.ns,e.name,e.version||"",e.path||""])[0],s=c[1],o=c[2],n=c[3]),/^[0-9.]+$/.exec(o)){if((t=((c=this._ver.map)[s]||(c[s]={}))[o])&&(o=t),t=this._cache[f.id({name:s,version:o,path:n})])return t;for(a=0,h=((c=this._ver.list)[s]||(c[s]=[])).length;a<h;++a)if(u=a,u=this._ver.list[s][u],semver.fit(u,o)&&(this._ver.map[s][o]=u,e.id=f.id({ns:r,name:s,version:u,path:n}),t=this._cache[e.id]))return t}return function(e,t){var n=-1,r=t.length>>>0;for(;++n<r;)if(e===t[n])return!0;return!1}(o,(c=this._ver.list)[s]||(c[s]=[]))||this._ver.list[s].push(o),this._cache[e.id]=e},f.converter=function(e){return this.scopeTest=(e=null==e?{}:e).scopeTest,this.node=t.createElement("style"),this.iframe=e=t.createElement("iframe"),e.setAttribute("title","for csscope parsing"),e.style.display="none",e.src="about:blank",t.body.appendChild(e),this.iframe.contentDocument.body.appendChild(this.node),this._idx=0,this},f.converter.prototype=s(Object.create(Object.prototype),{getNames:function(e,t){var n,r,i;for(null==t&&(t={}),n=0,r=e.length;n<r;++n)(i=e[n]).name?t[i.name]=!0:i.cssRules&&this.getNames(i.cssRules,t);return t},_convert:function(e,i,t,s,n){var r,o,c,a,u,l;for(null==n&&(n={}),r="",o=0,c=e.length;o<c;++o)(a=e[o]).style&&(n[a.style.animationName]?a.style.animationName=t+"__"+a.style.animationName:a.style.animation&&(a.style.animation=a.style.animation.split(" ").map(h).join(" "))),a.selectorText?(r+=(u=(s?a.selectorText.split(",").map(d).map(m):a.selectorText.split(",").map(f).map(p)).join(","))+"{"+a.style.cssText+"}",a.selectorText=u):a.name?(u=a.name.split(",").map(y).map(v).join(","),r+="@keyframes "+(a.name=u)+" {\n "+Array.from(a.cssRules).map(_).join("\n")+"\n}"):a.cssRules&&(l=this._convert(a.cssRules,i,t,s,n),r+="@media "+a.conditionText+" {\n "+l+"\n}");return r;function h(e){return n[e]?t+"__"+e:e}function f(e){return e.trim()}function p(e){return g(e)?e.replace(/^:scope/,i):i+" "+e}function d(e){return e.trim()}function m(e){var t,n,r;return g(e)?e.replace(/^:scope/,i):(n=(r=e.split(" ").map(function(e){return e.trim()}).filter(function(e){return e}))[0],t=x.call(r,1),n=(r=/^[a-zA-Z]/.exec(n)?[n,""]:["",n])[0],r=r[1],/:[a-z-]+$/.exec(e)?i+" :not("+s+") "+e+","+i+" > "+n+r+" "+t.join(" "):i+" :not("+s+") "+e+","+i+" > "+n+":not("+s+")"+r+" "+t.join(" "))}function y(e){return e.trim()}function v(e){return t+"__"+e}function _(e){return e.cssText}},convert:function(e,t,n,r){var i,e="object"==typeof e?e:{name:e,css:t,rule:n,scopeTest:r},t=e.name,n=e.css,r=e.rule,e=e.scopeTest;return r=r||"."+t,t=t||r,e=e||this.scopeTest,n="object"==typeof n?n:(this.node.textContent=(n||"")+("/*"+this._idx++)+"*/",this.node.sheet.cssRules),i=this.getNames(n,{}),this._convert(n,r,t,e,i)||""}}),f.manager=function(e){return null==e&&(e={}),this.attrName="csscope",this._cache={},this.converter=new f.converter,this.counter=0,this.registry(e.registry||"/assets/lib/"),this.init(),this},f.manager.prototype=s(Object.create(Object.prototype),{cache:function(e){var t;return(e="string"==typeof e?{url:e}:e).id||(e.id=f.id(e)),(t=this._cache[e.id])?t:this._cache[e.id]=f.cache(e)},_ref:function(e){var t,n;return"string"==typeof e&&(e={url:e}),"function"==typeof(t=this._reg.url||this._reg)&&((n=s({},e)).url=t(e),e=n),this._reg.fetch?this._reg.fetch(e):e.url},registry:function(e){return"string"==typeof e?("/"===e[e.length-1]&&(e=e.substring(0,e.length-1)),this._reg=(t=e,function(e){return t+"/"+e.name+"/"+(e.version||"main")+"/"+(e.path||"index.min.css")})):this._reg=e;var t},init:function(){if(!this.inited)return this.inited=!0,this.styleNode=t.createElement("style"),this.styleNode.setAttribute("type","text/css"),this.styleNode.setAttribute("data-name","csscope.manager"),this.styleContent=[],t.body.appendChild(this.styleNode)},scope:function(e,t){t=this.get(t=null==t?[]:t);return e.classList.add.apply(e.classList,t.map(function(e){return e.scope})),t},get:function(e){var t=this;return null==e&&(e=[]),(Array.isArray(e)?e:[e]).map(function(e){return t.cache(e)}).filter(function(e){return e.scope})},load:function(t,r,n){var i,s=this;return t=(Array.isArray(t)?t:[t]).map(function(e){return s.cache(e)}),i=[],Promise.all(t.map(function(t,n){var e;return t.inited?Promise.resolve():t.scope&&t.code?(t.inited=!0,i.push([t.code,n]),Promise.resolve()):((e=s._ref(t)).then?e.then(function(e){return s.cache((t.id=void 0,t.version=e.version,t)),e}):o(e,{method:"GET"}).then(function(e){return{content:e}})).then(function(e){e=e.content;return t.inited=!0,t.scope=f.scope(t),t.code=s.converter.convert({css:e,name:t.scope,scopeTest:r}),i.push([t.code,n])})})).then(function(){var e;return n?t:(e=i.sort(function(e,t){return e[1]>t[1]?1:e[1]<t[1]?-1:0}).map(function(e){return e[0]}),s.styleContent.push.apply(s.styleContent,e),s.styleNode.textContent=s.styleContent.join("\n"),s.get(t))})}}),f.env("undefined"!=typeof self&&null!==self?self:globalThis),"undefined"!=typeof module&&null!==module?module.exports=f:"undefined"!=typeof window&&null!==window&&(window.csscope=f)}();
8
+ ;
9
+ /* @plotdb/rescope/index.min.js */
10
+ (()=>{var f,p,h,d,e,y,r=[].slice,v=Array.from||function(e){return r.call(e)};function m(e,r){var t,n={}.hasOwnProperty;for(t in r)n.call(r,t)&&(e[t]=r[t]);return e}function g(e,r){for(var t=-1,n=r.length>>>0;++t<n;)if(e===r[t])return 1}h=function(e,r){return y.__node&&"undefined"!=typeof fs&&null!==fs&&!/^https?:/.exec(e)?new Promise(function(t,n){return fs.readFile(e,function(e,r){return e?n(e):t(r.toString())})}):fetch(e,r).then(function(i){var e;return i&&i.ok?i.text():i?i.clone().text().then(function(e){var r,t=i.status||404,n=new Error(t+" "+e);n.name="lderror",n.id=t,n.message=e,t=n;try{(r=JSON.parse(e))&&"lderror"===r.name&&(m(t,r).json=r)}catch(e){0}return Promise.reject(t)}):Promise.reject(((e=new Error("404")).name="lderror",e.id=404,e))})},(d=function(e){var r,i,t,o,c,u,l,a,s,p=this;return this.lc=(e=null==e?{}:e).context||{},this.id=Math.random().toString(36).substring(2),this.mode=e.mode||"default",e.iframe&&(this.iframe=e.iframe),r=d.nativeKeys(e.iframe?e.iframe.contentWindow:e.target||f),i=r.attr,t=r.intrinsic,o={},c={},u={},l=new WeakMap,a=function(e){return new Proxy(e,{get:function(e,r){return"source"===r?p._proxy:"function"==typeof(r=e[r])?r.bind(e):r}})},this._proxy=new Proxy(e.target||f,{has:function(e,r){return"with"===p.mode||Reflect.has(e,r)},get:function(e,r,s){var n;if("with"===p.mode){if(r===Symbol.unscopables)return;if(d.selfKeys[r])return p._proxy}if(null!=p.lc[r])return p.lc[r];if(t[r])return e[r];if(null!=o[r])return o[r];if(null!=c[r])return c[r];if(null!=u[r])return u[r];if("addEventListener"===r)return u[r]=function(e,r){for(var t,n,i=[],o=2,c=arguments.length;o<c;++o)i.push(arguments[o]);return t=i,"message"!==e?(n=s.target||f).addEventListener.apply(n,[e,r].concat(v(t))):((n=s.target||f).addEventListener.apply(n,[e,n=function(e){return r.call(p._proxy,a(e))}].concat(v(t))),l.set(r,n))};if("removeEventListener"===r)return u[r]=function(e,r){for(var t,n,i=[],o=2,c=arguments.length;o<c;++o)i.push(arguments[o]);return t=i,"message"!==e?(n=s.target||f).removeEventListener.apply(n,[e,r].concat(v(t))):(n=s.target||f).removeEventListener.apply(n,[e,l.get(r)||r].concat(v(t)))};if("function"!=typeof e[r])return null!=i[r]?e[r]:void 0;try{n=Reflect.get(e,r,s)}catch(e){n=void 0}return"function"!=typeof n&&(n=e[r]),o[r]=new Proxy(n.bind(e),{get:function(e,r,t){return Reflect.get(g(r,e)?e:n,r,t)}})},set:function(e,r,t){var n;return"_rspvarsetcb_"===r?s.on(t.k,t.f):(s.fire(r,t),"onmessage"===r?(n=function(r){return function(e){if(r)return r.call(p._proxy,a(e))}},c[r]=t,queueMicrotask(function(){return e[r]=n(t)})):i[r]?e[r]=t:p.lc[r]=t),!0},defineProperty:function(e,r,t){return Object.defineProperty(p.lc,r,t),p._proxy}}),s={evthdr:{},on:function(e,t){var n=this;return(Array.isArray(e)?e:[e]).map(function(e){var r;return((r=n.evthdr)[e]||(r[e]=[])).push(t)})},fire:function(e){for(var r,t,n,i,o=[],c=[],s=1,u=arguments.length;s<u;++s)c.push(arguments[s]);for(r=c,s=0,n=(t=this.evthdr[e]||[]).length;s<n;++s)i=t[s],o.push(i.apply(this,r));return o}},this}).nativeRe=/\{\s*\[native code\]\s*\}/,d.nativeExtra=["chrome"],d.selfKeys={window:!0,self:!0,globalThis:!0,global:!0,top:!0,parent:!0,frames:!0},d.keysCache=new WeakMap,d.nativeKeys=function(e){var r,t,n,i,o,c,s,u,l;if(!(r=d.keysCache.get(e))){for(n=(t=[{},{}])[0],i=t[1],o=Object.getPrototypeOf(e);o;){for(c=0,s=(t=Reflect.ownKeys(o)).length;c<s;++c)n[u=t[c]]=!0;o=Object.getPrototypeOf(o)}for(c=0,s=(t=Reflect.ownKeys(e)).length;c<s;++c)u=t[c],(l=Object.getOwnPropertyDescriptor(e,u))&&(l.get||l.set?n[u]=!0:l.enumerable?"function"==typeof l.value&&d.nativeRe.exec(Function.prototype.toString.call(l.value))&&(n[u]=!0):(n[u]=!0,"function"==typeof l.value&&(i[u]=!0)));for(c=0,s=(t=d.nativeExtra).length;c<s;++c)n[u=t[c]]=!0;d.keysCache.set(e,r={attr:n,intrinsic:i})}return r},d.prototype=((e=Object.create(Object.prototype)).proxy=function(){return this._proxy},e.ctx=function(){return this.lc},e),(y=function(e){return null==e&&(e={}),this.id=Math.random().toString(36).substring(2),this._cache={},this._scope=e.scope||"default",this._delivery=e.delivery||"eval",this._scriptElement=null==e.scriptElement||!!e.scriptElement,this._preloads=e.preloads||[],this.proxy=new d,this.registry(e.registry||"/assets/lib/"),this}).env=function(e){e=[e,e.document];return f=e[0],p=e[1],e},y.sourceUrl=function(e){return e?"\n//# sourceURL="+e:""},y.compile=function(e,r){return f&&"function"==typeof f.eval?f.eval("(function(scope, ctx, win){"+e+"})"+y.sourceUrl(r)):new Function("scope","ctx","win",e)},y.markerType="application/rescope-marker",y.markers="function"==typeof WeakMap?new WeakMap:null,y.scriptNode=function(e,r){var t,n,i=r.url||r.resolvedUrl;return y.markers&&e&&e.createElement&&i?((t=y.markers.get(e))||y.markers.set(e,t={}),(n=t[i])||((n=t[i]=e.createElement("script")).setAttribute("type",y.markerType),n.setAttribute("src",i),n.setAttribute("data-rescope",r.id||i)),(e.body||e.documentElement).appendChild(n),n):null},y.pretendScript=function(e,r,t){var n=null;try{n=y.scriptNode(e,r)}catch(e){0}if(!n)return t();r=!1;try{Object.defineProperty(e,"currentScript",{configurable:!0,get:function(){return n}}),r=!0}catch(e){0}try{return t()}finally{if(r)try{delete e.currentScript}catch(e){}}},y.prop={legacy:{webkitStorageInfo:!0}},y.id=function(e){var r=e.path||("js"===e.type?"index.min.js":"css"===e.type?"index.min.css":"index.html");return e.id||e.url||(e.ns?e.ns+":":"")+e.name+"@"+(e.version||"main")+":"+r},y._cache={},y._ver={map:{},list:{}},y.genRegistry="__rescope_gen__",y.cache=function(i){var o,e,r,t,n,c,s,u,l,a,p;if("string"==typeof i&&(i={url:i}),Array.isArray(i.prop)&&m(i,{prop:Object.fromEntries((()=>{for(var e,r=[],t=0,n=(e=i.prop).length;t<n;++t)o=e[t],r.push([o,null]);return r})()),propCached:!0,propIniting:!0}),i.id||(i.id=y.id(i)),e=this._cache[i.id])return e;if(i.id&&!i.name?((o=i.id.split(":")).length<=2?(n=o[0],r=o[1],t=o[2]):(t=o[0],n=o[1],r=o[2]),c=(n=(n=/^(@?[^@]+)(?:@([^:]+))?$/.exec(n))||["",i.id,""])[1],s=n[2]):(t=(u=[i.ns,i.name,i.version||"",i.path||""])[0],c=u[1],s=u[2],r=u[3]),/^[0-9.]+$/.exec(s)){if((e=((u=this._ver.map)[c]||(u[c]={}))[s])&&(s=e),e=this._cache[y.id({ns:t,name:c,version:s,path:r})])return e;for(l=0,a=((u=this._ver.list)[c]||(u[c]=[])).length;l<a;++l)if(p=l,p=this._ver.list[c][p],semver.fit(p,s)&&(this._ver.map[c][s]=p,i.id=y.id({ns:t,name:c,version:p,path:r}),e=this._cache[i.id]))return e}return g(s,(u=this._ver.list)[c]||(u[c]=[]))||this._ver.list[c].push(s),this._cache[i.id]=i},y.prototype=((e=Object.create(Object.prototype)).peekScope=function(){return!1},e.init=function(){return Promise.resolve()},e._url=function(e){var r,t;if("function"!=typeof(r=this._reg.url||this._reg))return null;t=null;try{t=r(e)}catch(e){0}return"string"==typeof t?t:null},e._ref=function(e){var r,t,n="string"==typeof e?{url:e}:e;return"function"==typeof(r=this._reg.url||this._reg)&&((t=m({},n)).url=r(n),n=t,e)&&"object"==typeof e&&!e.url&&"string"==typeof n.url&&(e.resolvedUrl=n.url),this._reg.fetch?this._reg.fetch(n):n.url},e.registry=function(e){return"string"==typeof e?("/"===e[e.length-1]&&(e=e.substring(0,e.length-1)),this._reg=(r=e,function(e){return e.url||r+"/"+e.name+"/"+(e.version||"main")+"/"+(e.path||"index.min.js")})):this._reg=e;var r},e.cache=function(e){var r;return(e="string"==typeof e?{url:e}:e).id||(e.id=y.id(e)),(r=this._cache[e.id])||(this._cache[e.id]=y.cache(e))},e.ifr=function(){var e,r;return(e=this.iframe)||(this.iframe=e=p.createElement("iframe"),(r=e.style).position="absolute",r.top=0,r.left=0,r.width=0,r.height=0,r.pointerEvents="none",r.opacity=0,e.setAttribute("title","rescope script loader"),e.setAttribute("name","pdb-rescope-"+this.id),p.body.appendChild(e),e.contentWindow.document.body.innerHTML=this._preloads.map(function(e){return'<script type="text/javascript" src="'+e+'"><\/script>'}).join(""),e)},e.exports=function(e){var r,t,n,i,o=this,c=[],s=(e=null==e?{}:e).ctx||{};if(!(e="string"==typeof e.libs?[e.libs]:e.libs||[]).every(function(e){return o.cache(e).propCached})){for(i in t=(r=[{},this.ifr().contentWindow])[0],n=r[1],s)t[i]=n[i],n[i]=s[i];for(i in this._exports(e,0,s),t)c.push(n[i]=t[i]);return c}},e._exports=function(e,r,t){var n,i,o,c,s,u,l,a=[];if(null==t&&(t={}),n=e[r=null==r?0:r]){if((n=this.cache(n)).propCached)return this._exports(e,r+1,t);if(i=(l=[{},n.fprop,this.ifr().contentWindow])[0],o=l[1],c=l[2],o)for(s in o)i[s]=c[s],c[s]=o[s];else if(n.fprop=o={},n.prop={},n.propIniting=!0,n.gen)m(o,n.gen.apply(c,[c,c,c])),n.prop=Object.fromEntries((()=>{var e=[];for(s in o)e.push([s,null]);return e})());else{for(s in Object.fromEntries(Reflect.ownKeys(c).filter(function(e){return!y.prop.legacy[e]}).map(function(e){return[e,!0]})))i[s]=c[s];try{u=function(){return c.eval((n.code||"").replace('"use strict";',"")+y.sourceUrl(n.url||n.id))},this._scriptElement?y.pretendScript(c.document,n,u):u()}catch(e){throw l=e,console.error("[@plotdb/rescope] Parse failed",{url:n.url,ns:n.ns,name:n.name,version:n.version,path:n.path}),console.error("[@plotdb/rescope] with this error:",l),l}for(s in Object.fromEntries(Reflect.ownKeys(c).filter(function(e){return!y.prop.legacy[e]}).map(function(e){return[e,!0]})))c[s]!==i[s]&&"NaN"!==s&&(o[s]=c[s],n.prop[s]=null)}for(s in o)t[s]=o[s];for(s in this._exports(e,r+1,t),o)a.push(c[s]=i[s]);return a}},e._wrapWith=function(e,r,t){return null==r&&(r={}),r="with(scope){"+(e=null==e?{}:e).code+"\n}",(t=null==t?{}:t).codeOnly?"function(scope, ctx, win){"+r+"}":y.compile(r,e.url||e.id)},e._wrap=function(e,r,t){var n,i,o,c,s;if(null==e&&(e={}),null==r&&(r={}),"with"===((t=null==t?{}:t).scope||this._scope))return this._wrapWith(e,r,t);for(s in n=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,o="var window, global, globalThis, self, __ret = {}, __win = {}; window = global = globalThis = self = scope;",c=function(e){return"window['_rspvarsetcb_'] = {k:'"+e+"',f:function(v){"+e+"=v}};"},i=e.prop||{})n.exec(s)&&(o+="var "+s+";"+c(s)),o+="__win['"+s+"'] = win['"+s+"']; win['"+s+"'] = undefined;";for(s in r)o+="window['"+s+"'] = ctx['"+s+"'];",n.exec(s)&&(o+="var "+s+" = window['"+s+"'];"+c(s));for(s in o+="try {"+e.code+"\n;",i)n.exec(s)?o+="if(!("+s+")) { "+s+" = scope['"+s+"']; }\n__ret['"+s+"'] = "+s+" || window['"+s+"'] || win['"+s+"'] || this['"+s+"'];":o+="__ret['"+s+"'] = window['"+s+"'] || win['"+s+"'] || this['"+s+"'];";for(s in o+="} finally {",i)o+="win['"+s+"'] = __win['"+s+"'];";return o+="}return __ret;",t.codeOnly?"function(scope, ctx, win){"+o+"}":y.compile(o,e.url||e.id)},e._gen=function(o,e){var r,c,s,u;return(r=o.gen)?Promise.resolve(r):"script"!==this._delivery||y.__node||!p?Promise.resolve(o.gen=this._wrap(o,e)):(r=this._wrap(o,e,{codeOnly:!0}),c=this.id+"-"+Math.random().toString(36).substring(2),s=f[y.genRegistry]=f[y.genRegistry]||{},e="window['"+y.genRegistry+"']['"+c+"'] = "+r+";"+y.sourceUrl(o.url||o.id),u=URL.createObjectURL(new Blob([e],{type:"text/javascript"})),new Promise(function(t,n){var i=p.createElement("script"),e=function(e){var r;return i.remove(),URL.revokeObjectURL(u),(r=s[c])?(delete s[c],t(o.gen=r)):n(((r=new Error("[@plotdb/rescope] wrapper script blocked or failed for "+o.id+". with `delivery: 'script'` the page's CSP has to allow `blob:` in script-src, or use a nonce with 'strict-dynamic'.")).name="lderror",r.id=403,r))};return i.onload=e,i.onerror=e,i.src=u,p.body.appendChild(i)}))},e.load=function(e,o,t,c){var r,s,u,n,l,a=this;return null==o&&(o={}),null==t&&(t=!1),null==c&&(c=!1),r=(e=(Array.isArray(e)?e:[e]).map(function(e){return a.cache(e)})).px||(e.px=o&&o.p?o.p:new d({mode:this._scope})),s=r.ctx(),u=r.proxy(),n=[e],(l=function(e){var i,r;return(i=n[e=null==e?0:e])?(r=i.map(function(r){var e;return!r.code&&!r.gen||t?(e=a._ref(r)).then?e.then(function(e){return r.code=e.content,a.cache((r.id=void 0,r.version=e.version,r.code=e.content,r))}):h(e,{method:"GET"}).then(function(e){return r.code=e}):(r.url||r.resolvedUrl||(r.resolvedUrl=a._url(r)),Promise.resolve())}),Promise.all(r).then(function(){var e,r,t,n;if(!c){if("with"===a._scope)for(e=0,t=(r=i).length;e<t;++e)(n=r[e]).gen||n.prop||(n.prop={},n.propIniting=!0);else a.exports({libs:i,ctx:o.f});return i.reduce(function(e,n){return e.then(function(){return n.propIniting?a._gen(n,s).then(function(e){var r=function(){var r,t;return"with"!==a._scope?n.prop=e.apply(u,[u,s,f]):(r=Object.fromEntries((()=>{var e=[];for(t in s)e.push([t,!0]);return e})()),e.apply(u,[u,s,f]),n.prop=Object.fromEntries((()=>{var e=[];for(t in s)r[t]||e.push([t,s[t]]);return e})()))};return a._scriptElement?y.pretendScript(p,n,r):r(),n.propIniting=!1,m(s,n.prop)}):m(s,n.prop)})},Promise.resolve())}}).then(function(){return s}).then(function(){return l(e+1)})):Promise.resolve(s)})(0)},e.context=function(e,r,t){var n;return"function"!=typeof r&&(r=(n=[t,r])[0],t=n[1]),this.load(e,t).then(function(e){return r?r(e):e})},e),y.env("undefined"!=typeof self&&null!==self?self:globalThis),y.proxin=d,y.dualContext=function(){return{p:new d,f:{},ctx:function(){return this.p.ctx()}}},"undefined"!=typeof module&&null!==module?module.exports=y:"undefined"!=typeof window&&null!==window&&(window.rescope=y)})();
11
+ ;
12
+ /* @plotdb/block/index.min.js */
13
+ !function(){var win,doc,err,_fetch,rid,sanitize,pubsub,block,slice$=[].slice,arrayFrom$=Array.from||function(e){return slice$.call(e)};function import$(e,t){var n,r={}.hasOwnProperty;for(n in t)r.call(t,n)&&(e[n]=t[n]);return e}function in$(e,t){for(var n=-1,r=t.length>>>0;++n<r;)if(e===t[n])return 1}err=function(e,t){var n;return null==e&&(e=""),null==t&&(t=404),Promise.reject(((n=new Error(e)).name="lderror",n.id=t,n.message=e,n))},_fetch=function(i,e){return block.__node&&"undefined"!=typeof fs&&null!==fs&&!/^https?:/.exec(i)?new Promise(function(n,r){return fs.stat(i,function(e,t){return e?r(e):(e=t.isDirectory()?i+"/index.html":i,fs.readFile(e,function(e,t){return e?r(e):n(t.toString())}))})}):fetch(i,e).then(function(o){return o&&o.ok?o.text():o?o.clone().text().then(function(e){var t,n=o.status||404,r=n+" "+e,i=new Error(r);i.name="lderror",i.id=n,i.message=r,n=i;try{(t=JSON.parse(e))&&"lderror"===t.name&&(import$(n,t).json=t)}catch(e){0}return Promise.reject(n)}):err()})},rid=function(){for(var e;e="b-"+Math.random().toString(36).substring(2),rid.hash[e];);return rid.hash[e]=!0,e},rid.hash={},sanitize=function(e){return e||""},pubsub=function(){return this.subs={},this},pubsub.prototype=import$(Object.create(Object.prototype),{fire:function(e){for(var t,n,r=[],i=1,o=arguments.length;i<o;++i)r.push(arguments[i]);return t=r,Promise.all(((n=this.subs)[e]||(n[e]=[])).map(function(e){return e.apply(null,t)}))},on:function(e,n){var r=this;return(Array.isArray(e)?e:[e]).map(function(e){var t;return((t=r.subs)[e]||(t[e]=[])).push(n)})}}),block={id:function(e){var t;return"string"==typeof e?e:(t=e.path||("js"===e.type?"index.min.js":"css"===e.type?"index.min.css":"index.html"),e.id||e.url||(e.ns?e.ns+":":"")+e.name+"@"+(e.version||"main")+":"+t)},id2obj:function(e){var t,n,r;return(e=e.split(":")).length<=2?(t=e[0],n=e[1],r=e[2]):(r=e[0],t=e[1],n=e[2]),(e=/^(@?[^@]+)(?:@([^:]+))?$/.exec(t))?{ns:r,name:e[1],version:e[2],path:n}:null},env:function(e){e=[e,e.document];if(win=e[0],doc=e[1],rescope.env&&rescope.env(win),rescope.env)return csscope.env(win)},i18n:{module:{lng:"en",t:function(e,t){for(var n,r,i,o,s,c,a,l,u=Array.isArray(e)?e:[e],h=this.lng,f=0,p=u.length;f<p;++f)if(null!=(n=u[f])){for(r=n.indexOf(":"),i=n.substring(0,r),o=(n=n.substring(r+1)).split("."),s=(c=(c=this.res)[h]||(c[h]={}))[i]||(c[i]={}),a=0,l=o.length;a<l&&(r=a,s);++a)s=s[o[r]];if(s)return s}return n||e[e.length-1]},changeLanguage:function(e){return this._fire("languageChanged",this.lng=e)||"en"},addResourceBundle:function(e,t,n,r,i){var o;return((o=this.res)[e]||(o[e]={}))[t]=n},_evthdr:{},on:function(e,n){var r=this;return(Array.isArray(e)?e:[e]).map(function(e){var t;return((t=r._evthdr)[e]||(t[e]=[])).push(n)})},off:function(e,n){var r=this;return(Array.isArray(e)?e:[e]).map(function(e){var t;if(~(t=((t=r._evthdr)[e]||(t[e]=[])).indexOf(n)))return r._evthdr[e].splice(t,1)})},_fire:function(e){for(var t,n,r,i,o=[],s=[],c=1,a=arguments.length;c<a;++c)s.push(arguments[c]);for(t=s,c=0,r=(n=this._evthdr[e]||[]).length;c<r;++c)i=n[c],o.push(i.apply(this,t));return o},res:{}},use:function(e){return this.module=e},addResourceBundle:function(e,t,n,r,i){return block.i18n.module.addResourceBundle(e,t,n,r=null==r?!0:r,i=null==i?!0:i)},changeLanguage:function(e){return block.i18n.module.changeLanguage(e)}}},Object.defineProperty(block.i18n,"language",{get:function(){return block.i18n.module.lng||block.i18n.module.language}}),Object.defineProperty(block.i18n.module,"language",{get:function(){return block.i18n.module.lng}}),block.compatible=function(e){var e=null!=e?e:{},t=(e=[e.required||"",e.current||""])[1];return"string"==typeof(e=e[0])&&(e=block.id2obj(e)),"string"==typeof t&&(t=block.id2obj(t)),e.ns===t.ns&&e.name===t.name&&("main"===e.version||"main"===t.version||semver.fit(t.version,e.version))},block.global={csscope:{hash:{},apply:function(e){var t=this;if((e=e.filter(function(e){return!t.hash[e.id||e.url]}).map(function(e){return t.hash[e.id||e.url]=e.scope})).length)return doc.body.classList.add.apply(doc.body.classList,e)}}},block.init=proxise.once(function(){if(block._rescope)return block._rescope.init()}),block.rescope=function(){return block._rescope||(block._rescope=new rescope({global:null!=win?win:global})),block._rescope},block.csscope=function(){return block._csscope||(block._csscope=new csscope.manager),block._csscope},block.manager=function(e){var t=this;return null==e&&(e={}),this.hash={},this.proxy={},this.running={},this._ver={map:{}},this._chain=e.chain||null,this.init=proxise.once(function(){return t._init()}),this.rescope=e.rescope instanceof rescope?e.rescope:block.rescope(),this.csscope=e.csscope instanceof csscope?e.csscope:block.csscope(),e.registry&&this.registry(e.registry),this.init(),this},block.manager.prototype=import$(Object.create(Object.prototype),{_init:function(){return(this.rescope===block.rescope()?block:this.rescope).init()},id:block.id,id2obj:block.id2obj,chain:function(e,t){return!this._chain||t&&t.replace?this._chain=e:this._chain.chain(e)},registry:function(e){var t;if(null!=(e="string"==(t=typeof e)||"function"==t||e.url||e.fetch?{lib:e,block:e}:e).lib&&(this.rescope===block.rescope()&&(this.rescope=new rescope({global:win})),this.csscope===block.csscope()&&(this.csscope=new csscope.manager),this.rescope.registry(e.lib),this.csscope.registry(e.lib)),null!=e.block&&(this._reg=e.block||"","string"==typeof this._reg&&this._reg&&"/"!==(t=this._reg)[t.length-1]))return this._reg+="/"},set:function(e){var c=this;return null==e&&(e={}),e=Array.isArray(e)?e:"function"!=typeof e[Symbol.iterator]&&isNaN(e.length)?[e]:Array.from(e),Promise.all(e.map(function(e){var t,n,r,i,o,s;return e instanceof win.Element&&(t=e.dataset.bid||"",n=("template"===(e.nodeName||"").toLowerCase()&&e.content.childNodes[0]?e.content.childNodes[0]:e).cloneNode(!0),(t=block.id2obj(t)).block=new block.class({manager:c,root:n}),e=t),n=e.ns,r=e.name,i=e.version,o=e.path,n=n||"",e=e instanceof block.class?e:e.block,o=((o=o)||"index.html").replace(/\/(index\.html)?$/,""),((t=(s=(s=c.hash)[n]||(s[n]={}))[r]||(s[r]={}))[i]||(t[i]={}))[o]=e}))},_getUrl:function(e){var t=e.url,n=e.name,r=e.version,i=e.path,e=e.type;return t||(this._reg||"")+"/assets/block/"+n+"/"+(r||"main")+"/"+(i||("block"===e?"index.html":"js"===e?"index.min.js":"index.min.css"))},getUrl:function(e){var t;return e.type||(e.type="block"),"function"==typeof(t=this._reg.url||this._reg)?t(e):this._getUrl(e)},_ref:function(e){var t,n;return"function"==typeof(t=this._reg.url||this._reg)&&((n=import$({},e)).url=t(e),e=n),this._reg.fetch?this._reg.fetch(e):e.url},fetch:function(e){var t;return e.type="block",(t=this._ref(e))?t.then?t:_fetch(t,{method:"GET"}).then(function(e){return{content:e}}):err(e)},_get:function(t){var e,n,r,i,o=this,s=[t.ns||"",t.name,t.version||"main",t.path||"index.html"],c=s[0],a=s[1],l=s[2],u=s[3],h={ns:c,name:a,version:l,path:u,ctx:t.ctx};if(!a||!l)return err("",1015);if(u=u.replace(/\/(index\.html)?$/,""),(s=(e=this.hash)[c]||(e[c]={}))[a]||(s[a]={}),/[^0-9.]/.exec(l)&&!t.force){if(((s=this._ver.map)[c]||(s[c]={}))[a]&&this._ver.map[c][a][l]&&(i=((s=this.hash[c][a])[i=this._ver.map[c][a][l]]||(s[i]={}))[u]))return i;for(n in s=((e=this.hash)[c]||(e[c]={}))[a])if(r=s[n],semver.fit(n,l))return Promise.resolve(r[u])}return null==((s=this.hash[c][a])[l]||(s[l]={}))[u]||t.force?!0!==((s=(e=(i=this.running)[c]||(i[c]={}))[a]||(e[a]={}))[l]||(s[l]={}))[u]?(this.running[c][a][l][u]=!0,this.fetch({ns:t.ns,name:t.name,version:t.version,path:t.path}).then(function(e){var t;return e?(e.version&&(h.version!==e.version&&(((t=o._ver.map[c])[a]||(t[a]={}))[h.version]=e.version),h.version=e.version),e.content||e):e404(h)}).catch(function(e){return o._chain?o._chain.get(t):Promise.reject(e)}).then(function(e){e=new block.class((h.code=e=null==e?{}:e,h.manager=o,h));return o.set((h.block=e,h)),e}).then(function(e){return o.proxy[c][a][l][u].resolve(e),e}).finally(function(){return o.running[c][a][l][u]=!1}).catch(function(e){return o.proxy[c][a][l][u].reject(e),Promise.reject(e)})):void 0:Promise.resolve(this.hash[c][a][l][u])},from:function(e,n){return this.get(e).then(function(e){return e.create().then(function(t){return t.attach(n).then(function(){return t.interface()}).then(function(e){return{instance:t,interface:e}})})})},get:function(t){var e,c=this;return null==t&&(t={}),e=Array.isArray(t)?t:[t],Promise.all(e.map(function(e){var t,n,r=(t=[(e="string"==typeof(e=null==e?{}:e)?block.id2obj(e):e).ns||"",e.name,e.version||"main",e.path||"index.html"])[0],i=t[1],o=t[2],s=(s=t[3]).replace(/\/(index\.html)?$/,"");return((t=(n=(n=c.proxy)[r]||(n[r]={}))[i]||(n[i]={}))[o]||(t[o]={}))[s]||(c.proxy[r][i][o][s]=proxise(function(e){return c._get(e)})),c.proxy[r][i][o][s](e)})).then(function(e){return Array.isArray(t)?e:e[0]})},debundle:function(e){var n=this;return null==e&&(e={}),e=(e=Array.isArray(e)?e:[e]).map(function(t){return Promise.resolve().then(function(){var l=t.manager||n,u={},e=t.root?Promise.resolve("string"==typeof t.root?doc.querySelector(t.root):t.root):(e=t.url?_fetch(t.url,{method:"GET"}):Promise.resolve(t.code||"")).then(function(e){var t;return block.debundleNode||doc.body.appendChild(block.debundleNode=doc.createElement("div")),block.debundleNode.style.display="none",block.debundleNode.appendChild(t=doc.createElement("div")),t.innerHTML=e,t.querySelector("template")});return e.then(function(e){var n,t,r,i,o,s,c,a=[];if(e){for(t in e.content&&(e=e.content),n=[{},{}][0],Array.from(e.childNodes).map(function(e){var t;if(e.nodeType===doc.ELEMENT_NODE)return"SCRIPT"===e.nodeName?u.script=e.cloneNode(!0):"STYLE"===e.nodeName?u.style=e.cloneNode(!0):(t=e.getAttribute("block"))?n[t]=e:void 0}),u.script&&((e=doc.createElement("script")).textContent=u.script.textContent,u.script=e,u.script.import=function(e){return u.codes="function"==typeof e?e():e},u.script.setAttribute("type","text/javascript"),doc.body.appendChild(u.script)),u.style&&(u.style.setAttribute("type","text/css"),doc.body.appendChild(u.style)),n)r=n[t],c=(s=block.id2obj(t)).ns,i=s.name,o=s.version,s=s.path,c=new block.class({manager:l,ns:c,name:i,version:o,path:s,code:{script:u.codes[t],dom:r,style:""}}),a.push(l.set(c));return a}})})}),Promise.all(e)}}),block.class=function(e){var t,n,r,i,o,s,c=this;if(this.opt=e=null==e?{}:e,this.scope=e.scope||null,this._ctx={},this.csscopes={global:[],local:[]},this.ns=e.ns,this.name=e.name,this.version=e.version,this.path=e.path,this.manager=e.manager,e.ns||(e.ns=""),this.manager||console.warn("manager is mandatory when constructing block.class"),t=e.code,e.root?n="string"==typeof e.root?doc.querySelector(e.root):e.root:"string"==typeof(t="function"==typeof t?t():t)?(t=sanitize(t),(r=doc.createElement("div")).innerHTML=(t||"").trim(),this._templates=Array.from(r.querySelectorAll("template[rel=block]")).map(function(e){return e.parentNode.removeChild(e)}),1<r.childNodes.length&&console.warn("DOM definition of a block should contain only one root.")):"object"==typeof t&&(this.script=t.script,this.style=t.style,this.style=t.style,this.script=t.script,(e=t.dom instanceof Function?t.dom():t.dom)instanceof win.Element?n=e:(t=sanitize(e),(r=doc.createElement("div")).innerHTML=t,1<r.childNodes.length&&console.warn("DOM definition of a block should contain only one root."))),["script","style","link"].map(function(e){var t=Array.from((n||r).querySelectorAll(e)).map(function(e){return e.parentNode.removeChild(e),e.textContent}).join("\n");return c[e]=null!=t&&t?t:c[e]||""}),!n&&r)for(i=0,o=r.childNodes.length;i<o&&(s=i,(n=r.childNodes[s]).nodeType!==win.Element.ELEMENT_NODE);++i);return(n=n||doc.createElement("div")).nodeType!==win.Element.ELEMENT_NODE&&console.warn("root of DOM definition of a block should be an Element"),this.node=n,this.init=proxise.once(function(){return c._init()}),this},block.class.prototype=import$(Object.create(Object.prototype),{_init:function(){var this$=this;return block.init().then(function(){if(this$._templates)return Promise.all(this$._templates.map(function(e){return this$.manager.debundle({root:e})}))}).then(function(){var v,ref$,ret,getClient;return this$.interface=this$.script instanceof Function?this$.script():"object"==typeof this$.script?this$.script:(v=eval("(function(module){"+(this$.script||"")+";return module.exports;})({})"))instanceof Function?v():v||{},this$.interface||(this$.interface={}),(ref$=this$.interface).pkg||(ref$.pkg={}),this$.ns||(this$.ns=this$.interface.pkg.ns),this$.name||(this$.name=this$.interface.pkg.name),this$.version||(this$.version=this$.interface.pkg.version),this$.path||(this$.path=this$.interface.pkg.path),this$.id=block.id({ns:this$.ns,name:this$.name||rid(),version:this$.version||rid(),path:this$.path}),this$._id_t=this$.id.replace(/:/g,"="),this$.scope||(this$.scope=csscope.scope(this$)),this$.style&&(doc.body.appendChild(this$.styleNode=doc.createElement("style")),this$.styleNode.setAttribute("type","text/css"),ret=csscope({rule:"*[scope~="+this$.scope+"]",name:this$.scope,css:this$.style,scopeTest:"[scope]"}),ret=ret.replace(/url\("?(?!data:)([^()"]+)"?\)/g,"url("+this$._path("")+"$1)"),this$.styleNode.textContent=ret),this$.factory=function(e){return this._instance=e,this},getClient=function(e){return this.parent&&this.parent.client instanceof Function?this.parent.client(e):null},this$.factory.prototype=import$((ref$=Object.create(Object.prototype),ref$.init=function(){},ref$.destroy=function(){},ref$._class=this$,ref$.interface=function(){if(this.parent)return this.parent.interface instanceof Function?this.parent.interface():this.parent.interface},ref$.client=getClient,ref$.clients=function(e){return this.parent?this.parent.clients(e).concat(this.client===getClient?[null]:this.client(e)):[this.client(e)]},ref$),this$.interface)}).then(function(){var e,t;if(this$.acceptedHosts=this$.interface.pkg.host||[],this$.extends=[],e=this$.interface.pkg.extend)return this$.manager?(e.name||e.url||(e.ns=this$.ns,e.name=this$.name,e.version=this$.version),this$.opt.ctx&&((t=import$({},e)).ctx=this$.opt.ctx,e=t),this$.manager.get(e).then(function(t){this$.extend=t;try{this$.extend._usedby(this$)}catch(e){throw t=e,this$.extend=null,t}return this$.extendDom=!(null!=e.dom)||e.dom,this$.extendStyle=!(null!=e.style)||e.style,this$.extend.init()}).then(function(){return this$.extends=[this$.extend].concat(this$.extend.extends)})):new Error("no available manager to get extended block")}).then(function(){var e,t,n=[],r=this$.interface.pkg.i18n||{};for(e in r)t=r[e],n.push(block.i18n.module.addResourceBundle(e,this$._id_t,t,!0,!0));return n}).then(function(){var n,r;return this$.dependencies=Array.isArray(this$.interface.pkg.dependencies)?this$.interface.pkg.dependencies:function(){var e,t=[];for(n in e=this.interface.pkg.dependencies||{})r=e[n],t.push(r);return t}.call(this$),this$.dependencies.map(function(e){if(e.name||e.url||(e.ns=this$.ns,e.name=this$.name,e.version=this$.version),!e.type)return!/\.js$/.exec(e.url||e.path||e)&&/\.css$/.exec(e.url||e.path||e)?e.type="css":e.type="js"}),this$.extend?this$._ctx=this$.extend.context():this$.opt.ctx?this$._ctx=this$.opt.ctx:rescope.dualContext?this$._ctx=rescope.dualContext():rescope.proxin&&(this$._ctx=new rescope.proxin),this$.manager.rescope.load(this$.dependencies.filter(function(e){return!e.type||"js"===e.type}),this$._ctx)}).then(function(){return this$.manager.csscope.load(this$.dependencies.filter(function(e){return"css"===e.type&&!0===e.global}))}).then(function(e){return this$.csscopes.global=e||[],this$.manager.csscope.load(this$.dependencies.filter(function(e){return"css"===e.type&&!0!==e.global}))}).then(function(e){if(this$.csscopes.local=e||[],this$.extend)return(e=this$.csscopes).global=e.global.concat(this$.extend.csscopes.global||[]),!0===this$.extendStyle?(e=this$.csscopes).local=e.local.concat(this$.extend.csscopes.local||[]):"overwrite"===this$.extendDom?(e=this$.csscopes).local=e.local.concat(this$.extend.csscopes.local.slice(1)):void 0}).catch(function(e){return console.error("[@plotdb/block] init "+block.id(this$),e),this$.interface={},this$.styleNode={},this$.factory=function(){return this},this$.dependencies=[],this$})},_usedby:function(e){var o,s=this;if(this===e)throw new Error("circular extend");return(this._users||(this._users=[])).push(e),(o=function(e){var t,n,r,i=[];if(in$(s,e=null==e?[]:e))throw new Error("circular extend");for(t=0,n=e.length;t<n;++t)r=e[t],i.push(o(r._users));return i})(e._users)},context:function(){return this._ctx},dom:function(){return this.node},_path:function(e){return null==e&&(e=""),(this.manager.getUrl({ns:this.ns,name:this.name,version:this.version,path:this.path})||"").replace(/\/[^/]*$/,"/")+e},i18n:function(t,e){var n=this._id_t;return t=t.replace(/:/g,""),(block.i18n.module.t([n+":"+t].concat(this.extends.map(function(e){return e._id_t+":"+t}),[t+""]),e)||"").replace(/\uf8ff/g,":")},create:function(t){var n=this;return null==t&&(t={}),this.init().then(function(){var e=new block.instance({block:n,data:t.data,host:t.host,ns:n.ns,name:n.name,path:n.path,version:n.version});return e.init().then(function(){if(t.root)return e.attach({root:t.root,before:t.before,host:t.host,autoTransform:t.autoTransform||null})}).then(function(){return e})})},resolvePlugAndCloneNode:function(n,e){var t;return(e=null==e?!1:e)?t=n:(t=this.dom().cloneNode(!0),Array.from(t.querySelectorAll("plug")).forEach(function(e){var t=e.getAttribute("name");return n&&(t=n.querySelector(":scope :not([plug]) [plug="+t+"], :scope > [plug="+t+"]"))?e.replaceWith(t):void 0}),Array.from(t.querySelectorAll("plug")).forEach(function(e){var t,n,r,i,o,s=e.getAttribute("name");for(e.removeAttribute("name"),e.setAttribute("plug",s),t=doc.createElement("div"),n=0,i=(r=e.attributes).length;n<i;++n)o=r[n],t.setAttribute(o.name,o.value);for(;e.firstChild;)t.appendChild(e.firstChild);return e.replaceWith(t)})),this.extend&&!1!==this.extendDom?"overwrite"===this.extendDom?this.extend.resolvePlugAndCloneNode(t,!0):this.extend.resolvePlugAndCloneNode(t):t}}),block.instance=function(e){var t=this;return this.ns=(e=null==e?{}:e).ns,this.name=e.name,this.version=e.version,this.path=e.path,this.block=e.block,this.data=e.data,this._id=(null!=(e=e.block)?e._id_t:void 0)+"="+Date.now()+"-"+Math.random().toString(36).substring(2),this.init=proxise.once(function(){return t._init()}),this},block.instance.prototype=import$(Object.create(Object.prototype),{_init:function(){return this.block.init()},attach:function(e){var t,n,r,i,o,s,c,a,l,u,h,f,p,d=this;if(null==e&&(e={}),a=this._defered)return a.before?a.root.insertBefore(a.node,a.before):a.root.appendChild(a.node),Promise.resolve();if(e.data&&(this.data=e.data),this.host=(Array.isArray(e.host)?e.host:[e.host]).filter(function(e){return e}),e.i18n)for(this._i18nModule=e.i18n,n=(t=[this.block].concat(this.block.extends)).length-1;0<=n;--n)for(s in o=(i=t[r=n]).interface.pkg.i18n||{})c=o[s],this._i18nModule.addResourceBundle(s,i._id_t,c,!0,!0);else this._i18nModule=block.i18n.module;if(a=(a=e.root)?"string"==typeof a?doc.querySelector(a):a:null,block.global.csscope.apply(this.block.csscopes.global),a){for(l=this.dom(e.root),u=[this.block].concat(this.block.extends),h=[this.block.scope],n=0,f=u.length-1;n<f;++n)if("overwrite"!==(p=u[r=n].extendStyle)){if(!1===p)break;h.push(u[r+1].scope)}l.setAttribute("scope",h.join(" ")),l.classList.add.apply(l.classList,this.block.csscopes.local.map(function(e){return e.scope}).concat(this.block.csscopes.global.map(function(e){return e.scope}))),e.defer?this._defered={node:l,root:a,before:e.before}:e.before?a.insertBefore(l,e.before):a.appendChild(l)}else l=null;return"i18n"===e.autoTransform&&this._i18nModule.on("languageChanged",this._i18nTransform=function(){return d.transform("i18n")}),this.run({node:l,type:"init"})},detach:function(){var e=this.dom();return e.parentNode.removeChild(e),this._i18nTransform&&(this._i18nModule.off("languageChanged",this._i18nTransform),this._i18nTransform=null),this.run({node:e,type:"destroy"})},interface:function(){var e;return(e=this.obj)[e.length-1].interface()},client:function(e){var t;return(t=this.obj)[t.length-1].client(e)},clients:function(e){var t;return(t=this.obj)[t.length-1].clients(e)},_transform:function(e,a,l){var u=new RegExp("^"+a+"-(.+)$"),h=function(e){var t,n,r,i,o,s,c=[];if(e.nodeType===win.Element.TEXT_NODE)return e.parentNode.setAttribute(a,e.textContent),e.parentNode.replaceChild(doc.createTextNode(l(e.textContent)),e);for(t=0,n=e.attributes.length;t<n;++t)r=t,o=(i=e.attributes[r]).name,i=i.value,(o=u.exec(o))&&e.setAttribute(o[1],l(i||""));if(s=e.getAttribute(a))return e.textContent=l(s);for(t=0,n=e.childNodes.length;t<n;++t)r=t,c.push(h(e.childNodes[r]));return c},t=new WeakMap;return Array.from(e.querySelectorAll(":scope [scope] ["+a+"]")).map(function(e){return t.set(e,1)}),Array.from(e.querySelectorAll("["+a+"]")).filter(function(e){return!t.get(e)}).map(h),e},transform:function(e){var t=this;if("i18n"===e||"path"===e)return this._transform(this.node,"t",function(e){return t.i18n(e)}),this._transform(this.node,"path",function(e){return t._path(e)})},dom:function(e){var t;return(t=this.node)||(this.node=this.block.resolvePlugAndCloneNode(e),this.transform("i18n"),this.transform("path"))},_path:function(e){return this.block._path(e)},_gethost:function(e){var n=e.host,e=e.accept,t=(Array.isArray(e)?e:[e]).filter(function(e){return e});return t.length?(t=t.map(function(t){return(n||[]).filter(function(e){return(e.bid?block.id2obj(e.bid):e).name===t.name})[0]}),Array.isArray(e)?t:t[0]||null):n},i18n:function(e,t){var n,r;return this._i18nModule?(n=this.block._id_t,r=e.replace(/:/g,""),(this._i18nModule.t([n+":"+r].concat(this.block.extends.map(function(e){return e._id_t+":"+r}),[r+""]),t)||"").replace(/\uf8ff/g,":")):this.block.i18n(e,t)},run:function(e){var r,f,p=this,d=e.node,m=e.type,t=[],b=[],n=this.block;for(this.obj||(this.obj=[]),this.pubsub||(this.pubsub=new pubsub),r={t:function(e,t){return p.i18n(e,t)},getLanguage:function(){return this.language},addResourceBundles:function(e){var t,n,r=[];for(t in e=null==e?{}:e)n=e[t],r.push((p._i18nModule||p.block.i18n.module).addResourceBundle(t,p.block._id_t,n,!0,!0));return r}},f=new Proxy(this._i18nModule||this.block.i18n.module,{get:function(e,t,n){return r[t]||Reflect.get(e,t,n)},ownKeys:function(e){return arrayFrom$(Reflect.ownKeys(r)).concat(arrayFrom$(Reflect.ownKeys(e)))},getOwnPropertyDescriptor:function(e,t){return r[t]?{enumerable:!0,configurable:!0,value:r[t]}:Reflect.getOwnPropertyDescriptor(e,t)}});n;)t=[n].concat(t),n=n.extend;return new Promise(function(l,u){var h=function(e,t,n,r,i){var o,s,c,a;return null==t&&(t=0),null==n&&(n={}),(e=null==e?[]:e).length<=t?Promise.all(b).then(function(e){return l(e)}).catch(function(e){return u(e)}):(o=e[t],s=o._ctx.ctx?o._ctx.ctx():(s=o._ctx).local||(s.local={}),import$(n,s),s={root:d,parent:r,manager:p.block.manager,ctx:n,context:n,pubsub:p.pubsub,i18n:f,t:function(e,t){return p.i18n(e,t)},path:function(e){return p._path(e)},data:p.data,host:p._gethost({host:p.host,accept:o.acceptedHosts})},"init"===m&&(p.obj.push(c=new o.factory(p.block===o?p:null)),c.parent=p.obj[t-1]),(c=p.obj[t])&&b.push(a=c[m](s)),o.interface.pkg.syncInit&&a?Promise.resolve(a).then(function(){return h(e,t+1,n,c)}):h(e,t+1,n,c))};return h(t,0,{})})}}),block.env("undefined"!=typeof self&&null!==self?self:globalThis),"undefined"!=typeof module&&null!==module?module.exports=block:"undefined"!=typeof window&&null!==window&&(window.block=block)}();
14
+ ;
15
+ /* lotion block loader */
16
+ (()=>{var n,e=(i=document.currentScript)&&i.dataset||{},t=(i=function(n){return n.replace(/\/$/,"")})(null!=(n=e.blockRoot)?n:"/block"),r=i(null!=(n=e.libRoot)?n:"/assets/lib"),o=new block.manager({registry:{lib:function(n){var e=n.name;return r+"/"+e+"/"+(n.version||"main")+"/"+(n.path||"index.min.js")},block:function(n){var e=n.name;return t+"/"+e+"/"+(n.path||"index.html")}}}),a=function(t){return o.init().then(function(){return t.dataset.bundle?o.debundle({url:t.dataset.bundle}):Promise.resolve()}).then(function(){return o.from({name:t.dataset.block,version:t.dataset.version,path:t.dataset.path},{root:t})}).then(function(n){var e=n.interface;return(t.block=e)&&e.seek&&null!=e.duration&&/[?&]render\b/.test(location.search)?Promise.resolve(e.ready).then(function(){return window.seek=function(n){return e.seek(n)},window.DURATION=e.duration,e.cues&&(window.cues=e.cues),e}):e})},u=function(){return null!=e.manual?Promise.resolve([]):o.init().then(function(){return Promise.all(Array.from(document.querySelectorAll("[data-block]")).map(a))})},i=new Promise(function(n){return"loading"===document.readyState?document.addEventListener("DOMContentLoaded",function(){return n(u())}):n(u())});window.lotionBlock={manager:o,mount:a,ready:i}})();
package/cli.js ADDED
@@ -0,0 +1,390 @@
1
+ #!/usr/bin/env node
2
+ var fs, path, http, child_process, usage, parse, types, serve, open, shot, frames, sheet, video, cues, bundle, audioDir, audio, argv, ref$, pos, opt, cmd, src, out, rest, times, p, slice$ = [].slice;
3
+ fs = require('fs');
4
+ path = require('path');
5
+ http = require('http');
6
+ child_process = require('child_process');
7
+ usage = 'usage:\n lotion <frames|sheet|video|cues> <src> <out> [t...] [options]\n lotion bundle <base-url> <block-name> <out> [options]\n lotion <bgm|sfx|mix|beats> ... ( -h for help )\nsee README for options.';
8
+ parse = function(argv){
9
+ var ref$, pos, opt, i, a;
10
+ ref$ = [[], {}], pos = ref$[0], opt = ref$[1];
11
+ i = 0;
12
+ while (i < argv.length) {
13
+ a = argv[i];
14
+ if (/^--/.test(a)) {
15
+ opt[a.replace(/^--/, '')] = argv[i + 1];
16
+ i += 2;
17
+ } else {
18
+ pos.push(a);
19
+ i++;
20
+ }
21
+ }
22
+ return {
23
+ pos: pos,
24
+ opt: opt
25
+ };
26
+ };
27
+ types = {
28
+ '.html': 'text/html',
29
+ '.js': 'text/javascript',
30
+ '.css': 'text/css',
31
+ '.json': 'application/json',
32
+ '.svg': 'image/svg+xml',
33
+ '.png': 'image/png',
34
+ '.jpg': 'image/jpeg',
35
+ '.woff2': 'font/woff2',
36
+ '.woff': 'font/woff',
37
+ '.mp3': 'audio/mpeg',
38
+ '.wav': 'audio/wav'
39
+ };
40
+ serve = function(src){
41
+ return new Promise(function(res, rej){
42
+ var stat, root, page, server;
43
+ stat = fs.statSync(src);
44
+ root = stat.isDirectory()
45
+ ? src
46
+ : path.dirname(src);
47
+ page = stat.isDirectory()
48
+ ? ''
49
+ : path.basename(src);
50
+ server = http.createServer(function(req, rsp){
51
+ var f;
52
+ f = path.join(root, decodeURIComponent(req.url.split('?')[0]));
53
+ if (fs.existsSync(f) && fs.statSync(f).isDirectory()) {
54
+ f = path.join(f, 'index.html');
55
+ }
56
+ return fs.readFile(f, function(e, buf){
57
+ if (e) {
58
+ rsp.writeHead(404);
59
+ return rsp.end();
60
+ }
61
+ rsp.writeHead(200, {
62
+ 'Content-Type': types[path.extname(f)] || 'application/octet-stream'
63
+ });
64
+ return rsp.end(buf);
65
+ });
66
+ });
67
+ server.on('error', rej);
68
+ return server.listen(0, function(){
69
+ return res({
70
+ url: "http://localhost:" + server.address().port + "/" + page,
71
+ close: function(){
72
+ return server.close();
73
+ }
74
+ });
75
+ });
76
+ });
77
+ };
78
+ open = function(src, opt){
79
+ var chromium, p;
80
+ chromium = require('playwright').chromium;
81
+ p = /^https?:/.test(src)
82
+ ? Promise.resolve({
83
+ url: src,
84
+ close: function(){}
85
+ })
86
+ : serve(src);
87
+ return p.then(function(srv){
88
+ var ref$, u, h;
89
+ ref$ = srv.url.split('#'), u = ref$[0], h = ref$[1];
90
+ u += (/\?/.test(u) ? '&' : '?') + 'render' + (opt.query ? "&" + opt.query : '');
91
+ return chromium.launch().then(function(browser){
92
+ return browser.newPage({
93
+ viewport: {
94
+ width: +(opt.width || 1920),
95
+ height: +(opt.height || 1080)
96
+ },
97
+ deviceScaleFactor: 1
98
+ }).then(function(page){
99
+ page.on('pageerror', function(e){
100
+ return console.error("[page] " + e.message);
101
+ });
102
+ return page.goto(u, {
103
+ waitUntil: 'networkidle'
104
+ }).then(function(){
105
+ return page.waitForFunction(function(){
106
+ return typeof window.seek === 'function' && window.DURATION != null;
107
+ }, null, {
108
+ timeout: 30000
109
+ });
110
+ }).then(function(){
111
+ return page.evaluate(function(){
112
+ return document.fonts.ready.then(function(){
113
+ return true;
114
+ });
115
+ });
116
+ }).then(function(){
117
+ return page.evaluate(function(){
118
+ return window.DURATION;
119
+ });
120
+ }).then(function(duration){
121
+ return {
122
+ page: page,
123
+ duration: duration,
124
+ close: function(){
125
+ return browser.close().then(function(){
126
+ return srv.close();
127
+ });
128
+ }
129
+ };
130
+ });
131
+ });
132
+ });
133
+ });
134
+ };
135
+ shot = function(page, t, type){
136
+ type == null && (type = 'png');
137
+ return page.evaluate(function(t){
138
+ return window.seek(t);
139
+ }, t).then(function(){
140
+ return page.screenshot({
141
+ type: type
142
+ });
143
+ });
144
+ };
145
+ frames = function(src, out, times, opt){
146
+ fs.mkdirSync(out, {
147
+ recursive: true
148
+ });
149
+ return open(src, opt).then(function(arg$){
150
+ var page, close;
151
+ page = arg$.page, close = arg$.close;
152
+ return times.reduce(function(p, t, i){
153
+ return p.then(function(){
154
+ return shot(page, t).then(function(buf){
155
+ return fs.writeFileSync(path.join(out, "f" + (i + "").padStart(3, '0') + "-" + t + ".png"), buf);
156
+ });
157
+ });
158
+ }, Promise.resolve()).then(function(){
159
+ return close();
160
+ });
161
+ });
162
+ };
163
+ sheet = function(src, out, times, opt){
164
+ var tmp, cols, rows;
165
+ tmp = fs.mkdtempSync(path.join(require('os').tmpdir(), 'lotion-'));
166
+ cols = +(opt.cols || 3);
167
+ rows = Math.ceil(times.length / cols);
168
+ return frames(src, tmp, times, opt).then(function(){
169
+ return new Promise(function(res, rej){
170
+ var ff;
171
+ ff = child_process.spawn('ffmpeg', ['-v', 'error', '-y', '-pattern_type', 'glob', '-i', path.join(tmp, '*.png'), '-vf', "scale=" + (opt.tile || 640) + ":-1,tile=" + cols + "x" + rows, '-frames:v', '1', out], {
172
+ stdio: 'inherit'
173
+ });
174
+ return ff.on('close', function(c){
175
+ fs.rmSync(tmp, {
176
+ recursive: true,
177
+ force: true
178
+ });
179
+ if (c) {
180
+ return rej(new Error("ffmpeg exited with " + c));
181
+ } else {
182
+ return res();
183
+ }
184
+ });
185
+ });
186
+ });
187
+ };
188
+ video = function(src, out, opt){
189
+ var fps, sub, shutter;
190
+ fps = +(opt.fps || 60);
191
+ sub = +(opt.sub || 1);
192
+ shutter = +(opt.shutter || 0.5);
193
+ return open(src, opt).then(function(arg$){
194
+ var page, duration, close, from, to, n, d, vf, ff, t0, write, step;
195
+ page = arg$.page, duration = arg$.duration, close = arg$.close;
196
+ from = +(opt.from || 0);
197
+ to = +(opt.to || duration);
198
+ n = Math.round((to - from) * fps);
199
+ d = shutter / fps / sub;
200
+ vf = sub > 1
201
+ ? ['-vf', "tmix=frames=" + sub + ",select='eq(mod(n\\," + sub + ")\\," + (sub - 1) + ")',setpts=N/" + fps + "/TB"]
202
+ : [];
203
+ ff = child_process.spawn('ffmpeg', ['-y', '-v', 'error', '-f', 'image2pipe', '-framerate', fps * sub + "", '-i', '-'].concat(vf, ['-r', fps + "", '-c:v', 'libx264', '-preset', 'slow', '-crf', (opt.crf || 16) + "", '-pix_fmt', 'yuv420p', '-movflags', '+faststart', out]), {
204
+ stdio: ['pipe', 'inherit', 'inherit']
205
+ });
206
+ t0 = Date.now();
207
+ write = function(buf){
208
+ return new Promise(function(res){
209
+ if (ff.stdin.write(buf)) {
210
+ return res();
211
+ } else {
212
+ return ff.stdin.once('drain', res);
213
+ }
214
+ });
215
+ };
216
+ step = function(i, j){
217
+ var t;
218
+ if (i >= n) {
219
+ return Promise.resolve();
220
+ }
221
+ if (j >= sub) {
222
+ if (i % 300 === 0) {
223
+ console.log("frame " + i + "/" + n + " " + ((Date.now() - t0) / 1000).toFixed(0) + "s");
224
+ }
225
+ return step(i + 1, 0);
226
+ }
227
+ t = Math.max(0, from + i / fps + (sub > 1 ? (j - (sub - 1) / 2) * d : 0));
228
+ return shot(page, t).then(write).then(function(){
229
+ return step(i, j + 1);
230
+ });
231
+ };
232
+ return step(0, 0).then(function(){
233
+ return new Promise(function(res){
234
+ ff.on('close', res);
235
+ return ff.stdin.end();
236
+ });
237
+ }).then(function(){
238
+ return close();
239
+ }).then(function(){
240
+ return console.log(out + " ( " + n + " frames, " + ((Date.now() - t0) / 1000).toFixed(0) + "s )");
241
+ });
242
+ });
243
+ };
244
+ cues = function(src, out, opt){
245
+ return open(src, opt).then(function(arg$){
246
+ var page, close;
247
+ page = arg$.page, close = arg$.close;
248
+ return page.evaluate(function(){
249
+ if (window.cues) {
250
+ return window.cues();
251
+ } else {
252
+ return [];
253
+ }
254
+ }).then(function(c){
255
+ return fs.writeFileSync(out, JSON.stringify(c, null, 1));
256
+ }).then(function(){
257
+ return close();
258
+ });
259
+ });
260
+ };
261
+ bundle = function(base, name, out, opt){
262
+ var chromium, m;
263
+ chromium = require('playwright').chromium;
264
+ base = base.replace(/\/$/, '');
265
+ m = function(f){
266
+ return require.resolve(f);
267
+ };
268
+ return chromium.launch().then(function(browser){
269
+ return browser.newPage().then(function(page){
270
+ page.on('pageerror', function(e){
271
+ return console.error("[page] " + e.message);
272
+ });
273
+ return page.goto(base, {
274
+ waitUntil: 'load'
275
+ })['catch'](function(){}).then(function(){
276
+ var libs;
277
+ libs = ['@plotdb/semver/index.min.js', 'proxise/index.min.js', '@plotdb/csscope/bundle.js', '@plotdb/rescope/bundle.js', '@plotdb/block/bundle.js'];
278
+ return libs.reduce(function(p, f){
279
+ return p.then(function(){
280
+ return page.addScriptTag({
281
+ path: m(f)
282
+ });
283
+ });
284
+ }, Promise.resolve());
285
+ }).then(function(){
286
+ return page.evaluate(function(arg$){
287
+ var base, name, br, lr, mgr;
288
+ base = arg$.base, name = arg$.name, br = arg$.br, lr = arg$.lr;
289
+ mgr = new block.manager({
290
+ registry: {
291
+ lib: function(arg$){
292
+ var name, version, path;
293
+ name = arg$.name, version = arg$.version, path = arg$.path;
294
+ return base + "" + lr + "/" + name + "/" + (version || 'main') + "/" + (path || 'index.min.js');
295
+ },
296
+ block: function(arg$){
297
+ var name, path;
298
+ name = arg$.name, path = arg$.path;
299
+ return base + "" + br + "/" + name + "/" + (path || 'index.html');
300
+ }
301
+ }
302
+ });
303
+ return mgr.bundle({
304
+ blocks: [{
305
+ name: name
306
+ }]
307
+ }).then(function(r){
308
+ return r.code;
309
+ });
310
+ }, {
311
+ base: base,
312
+ name: name,
313
+ br: opt['block-root'] || '/block',
314
+ lr: opt['lib-root'] || '/assets/lib'
315
+ });
316
+ });
317
+ }).then(function(code){
318
+ fs.writeFileSync(out, code);
319
+ return console.log(out + " ( " + code.length + " bytes )");
320
+ })['finally'](function(){
321
+ return browser.close();
322
+ });
323
+ });
324
+ };
325
+ audioDir = function(){
326
+ return [path.join(__dirname, 'audio'), path.join(__dirname, '..', 'audio')].find(function(d){
327
+ return fs.existsSync(d);
328
+ });
329
+ };
330
+ audio = function(cmd, args){
331
+ return new Promise(function(res, rej){
332
+ var d, f, py;
333
+ if (!(d = audioDir())) {
334
+ return rej(new Error("audio scripts not found"));
335
+ }
336
+ f = path.join(d, cmd + ".py");
337
+ py = child_process.spawn(process.env.PYTHON || 'python3', [f].concat(args), {
338
+ stdio: 'inherit'
339
+ });
340
+ py.on('error', rej);
341
+ return py.on('close', function(c){
342
+ if (c) {
343
+ return rej(new Error(cmd + ".py exited with " + c));
344
+ } else {
345
+ return res();
346
+ }
347
+ });
348
+ });
349
+ };
350
+ argv = process.argv.slice(2);
351
+ if ((ref$ = argv[0]) === 'bgm' || ref$ === 'sfx' || ref$ === 'mix' || ref$ === 'beats') {
352
+ audio(argv[0], argv.slice(1))['catch'](function(e){
353
+ console.error(e.message);
354
+ return process.exit(1);
355
+ });
356
+ } else {
357
+ ref$ = parse(argv), pos = ref$.pos, opt = ref$.opt;
358
+ cmd = pos[0], src = pos[1], out = pos[2], rest = slice$.call(pos, 3);
359
+ times = rest.map(function(it){
360
+ return +it;
361
+ });
362
+ p = (function(){
363
+ switch (cmd) {
364
+ case 'frames':
365
+ return frames(src, out, times, opt);
366
+ case 'sheet':
367
+ return sheet(src, out, times, opt);
368
+ case 'video':
369
+ return video(src, out, opt);
370
+ case 'cues':
371
+ return cues(src, out, opt);
372
+ case 'bundle':
373
+ if (rest[0]) {
374
+ return bundle(src, out, rest[0], opt);
375
+ } else {
376
+ return null;
377
+ }
378
+ default:
379
+ return null;
380
+ }
381
+ }());
382
+ if (!p || !src || !out) {
383
+ console.log(usage);
384
+ process.exit(1);
385
+ }
386
+ p['catch'](function(e){
387
+ console.error(e.message) || e;
388
+ return process.exit(1);
389
+ });
390
+ }