first commit

This commit is contained in:
what 2024-08-07 10:38:59 +08:00
commit 981469f5df
5 changed files with 8 additions and 0 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
### ff-worker
Copy this project to web /ff-worker.

3
index.js Normal file
View File

@ -0,0 +1,3 @@
"use strict";importScripts("./lib/moment@2_29_4.min.js","./lib/moment.locale.zh-cn.js"),moment.locale("zh-cn");const Util=(e,s)=>{const t=Util.msg_id++;return new Proxy(()=>{},{get({root:o},a){const r=o?`${o}/${a}`:a;return function(...i){return new Promise((n,l)=>{Util.mQueue.set(t,[n,l]),self.postMessage({id:t,task_id:e,session:s,category:"util",method:r,args:i})})}},apply(o,a,r){return new Proxy(Object.create({root:r[0]||null}),{get:this.get})}})};Util.msg_id=0,Util.mQueue=new Map,Util.mMethodWorkspace=new Map,self.addEventListener("message",function({data:{id:e,data:s,error:t,category:o}}){o==="util"&&(t!==null?Util.mQueue.get(e)[1](t):Util.mQueue.get(e)[0](s),Util.mQueue.get(e),Util.mQueue.delete(e))},!1),self.addEventListener("message",({data:{id,method,args,category,session,sourceURL}})=>{if(category!=="eval")return;session&&!Util.mMethodWorkspace.has(session)&&Util.mMethodWorkspace.set(session,{});const evalDataSourceURL=sourceURL?`
//# sourceURL=ff:///./${sourceURL}`:"",evalData=eval(`(async function({${Object.keys(args).join(", ")}}, Util){${method}
})${evalDataSourceURL}`).call(session?Util.mMethodWorkspace.get(session):{},args,Util(id,session));return Promise.resolve(evalData).then(e=>{self.postMessage({id,session,category,data:e,error:null})}).catch(e=>{self.postMessage({id,session,category,data:null,error:e instanceof DOMException&&e.name==="DataCloneError"?"DataCloneError 返回结果只能为简单数据格式":e})})}),self.addEventListener("message",({data:{category:e,session:s}})=>{e==="clear"&&Util.mMethodWorkspace.delete(s)},!1);

View File

@ -0,0 +1 @@
!function(e,d){"object"==typeof exports&&"undefined"!=typeof module&&"function"==typeof require?d(require("../moment")):"function"==typeof define&&define.amd?define(["../moment"],d):d(e.moment)}(this,function(e){"use strict";return e.defineLocale("zh-cn",{months:"一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),monthsShort:"1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),weekdays:"星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),weekdaysShort:"周日_周一_周二_周三_周四_周五_周六".split("_"),weekdaysMin:"日_一_二_三_四_五_六".split("_"),longDateFormat:{LT:"HH:mm",LTS:"HH:mm:ss",L:"YYYY/MM/DD",LL:"YYYY年M月D日",LLL:"YYYY年M月D日Ah点mm分",LLLL:"YYYY年M月D日ddddAh点mm分",l:"YYYY/M/D",ll:"YYYY年M月D日",lll:"YYYY年M月D日 HH:mm",llll:"YYYY年M月D日dddd HH:mm"},meridiemParse:/凌晨|早上|上午|中午|下午|晚上/,meridiemHour:function(e,d){return 12===e&&(e=0),"凌晨"===d||"早上"===d||"上午"===d||"下午"!==d&&" 晚上"!==d&&11<=e?e:e+12},meridiem:function(e,d,t){e=100*e+d;return e<600?"凌晨":e<900?"早上":e<1130?"上午":e<1230?"中午":e<1800?"下午":"晚上"},calendar:{sameDay:"[今天]LT",nextDay:"[明天]LT",nextWeek:function(e){return e.week()!==this.week()?"[下]dddLT":"[本]dddLT"},lastDay:"[昨天]LT",lastWeek:function(e){return this.week()!==e.week()?"[上]dddLT":"[本]dddLT"},sameElse:"L"},dayOfMonthOrdinalParse:/\d{1,2}(日|月|周)/,ordinal:function(e,d){switch(d){case"d":case"D":case"DDD":return e+"日";case"M":return e+"月";case"w":case"W":return e+"周";default:return e}},relativeTime:{future:"%s后",past:"%s前",s:"几秒",ss:"%d 秒",m:"1 分钟",mm:"%d 分钟",h:"1 小时",hh:"%d 小时",d:"1 天",dd:"%d 天",w:"1 周",ww:"%d 周",M:"1 个月",MM:"%d 个月",y:"1 年",yy:"%d 年"},week:{dow:1,doy:4}})});

1
lib/moment@2_29_4.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
res-ws.js Normal file
View File

@ -0,0 +1 @@
"use strict";const a=[];let t=null;function n(o){t=new WebSocket(o),t.onclose=e=>console.log("ws closed",e),t.onerror=e=>console.log("ws error",e),t.onmessage=({data:e})=>{const c=JSON.parse(e);a.forEach(s=>s.postMessage(c))}}function r(){t&&t.readyState!=WebSocket.OPEN||t.close()}function l(){this.postMessage({readyState:t?t.readyState:WebSocket.CLOSED})}self.onconnect=o=>{const e=o.ports[0];e.onmessage=({data:{command:c,data:s}})=>{switch(c){case"initWs":return Reflect.apply(n,e,s||[]);case"closeWs":return Reflect.apply(r,e,s||[]);case"status":return Reflect.apply(l,e,s||[])}},a.push(e)};