@virid/renderer 0.2.5 → 0.3.1
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/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -16
- package/dist/index.d.ts +19 -16
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @virid/renderer v0.
|
|
2
|
+
* @virid/renderer v0.3.1
|
|
3
3
|
* Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process
|
|
4
4
|
*/
|
|
5
|
-
var
|
|
5
|
+
var a=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var V=(e,r,i)=>r in e?a(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i;var _=(e,r)=>a(e,"name",{value:r,configurable:!0});var $=(e,r)=>{for(var i in r)a(e,i,{get:r[i],enumerable:!0})},A=(e,r,i,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of D(r))!T.call(e,t)&&t!==i&&a(e,t,{get:()=>r[t],enumerable:!(o=y(r,t))||o.enumerable});return e};var G=e=>A(a({},"__esModule",{value:!0}),e);var s=(e,r,i)=>V(e,typeof r!="symbol"?r+"":r,i);var W={};$(W,{FromMain:()=>h,FromMainMessage:()=>c,RenderPlugin:()=>u,ToMainMessage:()=>d,convertFromMainMessage:()=>I,middleWare:()=>g});module.exports=G(W);var v=require("@virid/core");var f=class f extends v.EventMessage{constructor(){super(...arguments);s(this,"__virid_source","unknown");s(this,"__virid_target","");s(this,"__virid_messageType","")}};_(f,"FromMainMessage");var c=f,w=class w extends v.EventMessage{};_(w,"ToMainMessage"),s(w,"__virid_source");var d=w;var x=require("@virid/core");var g=_((e,r)=>{if(e instanceof d){let{__virid_target:i,__virid_messageType:o,...t}=e;if(i==d.__virid_source){x.MessageWriter.warn(`[Virid Render] Prohibit Sending To Oneself: ${i} is not allowed in ToRenderMessage.`);return}window.__VIRID_BRIDGE__.post({__virid_source:d.__virid_source,__virid_target:i,__virid_messageType:o,payload:t})}else r()},"middleWare");var p=require("@virid/core");var m=new Map;function h(e){return function(r){m.has(e)&&p.MessageWriter.error(new Error(`[Virid Main] Duplicate IpcMessage: Registration for type: ${e}`)),m.set(e,r)}}_(h,"FromMain");function I(e){let{__virid_source:r,__virid_target:i,__virid_messageType:o,payload:t}=e;if(!o||!r||!i){p.MessageWriter.error(new Error(`[Virid Render] Incomplete Data:
|
|
6
6
|
__virid_source: ${r}
|
|
7
7
|
__virid_target:${i}
|
|
8
|
-
__virid_messageType: ${
|
|
9
|
-
Please provide the windowId:${r?.windowId}.`)),d.__virid_source=r.windowId,window.__VIRID_BRIDGE__.post({__virid_source:r.windowId,__virid_target:"main",__virid_messageType:"VIRID_INTERNAL_REGISTER",payload:{windowId:r.windowId}}),window.__VIRID_BRIDGE__.subscribe(
|
|
8
|
+
__virid_messageType: ${o}.`));return}if(!m.has(o)){p.MessageWriter.error(new Error(`[Virid Render] Unregistered type: ${o} `));return}let M=m.get(o),n=new M;n.__virid_source=r,n.__virid_target=i,n.__virid_messageType=o,t&&Object.assign(n,t),p.MessageWriter.write(n)}_(I,"convertFromMainMessage");var l=require("@virid/core");function E(e,r){window.__VIRID_BRIDGE__||l.MessageWriter.error(new Error("[Virid Render] Preloading Failed: Please initialize in the preloaded script first.")),r?.windowId||l.MessageWriter.error(new Error(`[Virid Render] Activate Failed:
|
|
9
|
+
Please provide the windowId:${r?.windowId}.`)),d.__virid_source=r.windowId,window.__VIRID_BRIDGE__.post({__virid_source:r.windowId,__virid_target:"main",__virid_messageType:"VIRID_INTERNAL_REGISTER",payload:{windowId:r.windowId}}),window.__VIRID_BRIDGE__.subscribe(I),e.useMiddleware(g)}_(E,"activateApp");var R=class R{constructor(){s(this,"name","@virid/render")}install(r,i){E(r,i)}};_(R,"RenderPlugin");var u=R;0&&(module.exports={FromMain,FromMainMessage,RenderPlugin,ToMainMessage,convertFromMainMessage,middleWare});
|
|
10
10
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/renderer/message.ts","../src/renderer/middleware.ts","../src/renderer/router.ts","../src/app.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process.\n */\nimport { ViridPlugin, type ViridApp } from \"@virid/core\";\nexport { ToMainMessage, FromMainMessage } from \"./renderer\";\nexport * from \"./interfaces\";\nexport * from \"./renderer\";\nimport { activateApp } from \"./app\";\nimport { type PluginOption } from \"./interfaces\";\nexport const RenderPlugin: ViridPlugin<PluginOption> = {\n name: \"@virid/render\",\n install(app: ViridApp, options) {\n activateApp(app, options);\n },\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { EventMessage } from \"@virid/core\";\n/**\n * RenderMessage: 由主进程发来的消息\n */\nexport abstract class FromMainMessage extends EventMessage {\n /** 我来自哪?\n */\n public __virid_source: string = \"unknown\";\n /** 我的目的地是哪儿?\n * 'main': 发给主进程处理\n * 'all': 广播给所有窗口(经过主进程中转)\n * string: 指定某个窗口的 ID (windowId)\n */\n public __virid_target: string = \"\";\n /**\n * 我应该在目的地转变成什么消息?\n */\n public __virid_messageType: string = \"\";\n}\n\n/**\n * RenderMessage: 由渲染进程发起,目标是主进程或其他窗口\n */\nexport abstract class ToMainMessage extends EventMessage {\n /** 我来自哪?\n */\n public static __virid_source: string;\n\n /** 我的目的地是哪儿?\n * 'main': 发给主进程处理\n * 'all': 广播给所有窗口(经过主进程中转)\n * string: 指定某个窗口的 ID (windowId)\n */\n public abstract __virid_target: string;\n\n /**\n * 我应该在目的地转变成什么消息?\n */\n public abstract __virid_messageType: string;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { type Middleware, MessageWriter } from \"@virid/core\";\nimport { ToMainMessage } from \"./message\";\nexport const middleWare: Middleware = (message, next) => {\n //如果消息继承自ToMainMessage,拦截并发往主进程\n if (message instanceof ToMainMessage) {\n const { __virid_target, __virid_messageType, ...payload } = message;\n //禁止发给自己\n if (__virid_target == ToMainMessage.__virid_source) {\n MessageWriter.warn(\n `[Virid Render] Prohibit Sending To Oneself: ${__virid_target} is not allowed in ToRenderMessage.`,\n );\n return;\n }\n window.__VIRID_BRIDGE__.post({\n __virid_source: ToMainMessage.__virid_source,\n __virid_target: __virid_target,\n __virid_messageType: __virid_messageType,\n payload: payload, // 展开实例上的所有属性\n });\n } else {\n next();\n }\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { MessageWriter, Newable } from \"@virid/core\";\nimport { type FromMainMessage } from \"./message\";\nconst MESSAGE_MAP = new Map<string, Newable<FromMainMessage>>();\n\nexport function FromMain(type: string) {\n return function (target: Newable<FromMainMessage>) {\n if (MESSAGE_MAP.has(type)) {\n MessageWriter.error(\n new Error(\n `[Virid Main] Duplicate IpcMessage: Registration for type: ${type}`,\n ),\n );\n }\n MESSAGE_MAP.set(type, target);\n };\n}\nexport function convertFromMainMessage(ipcMessage: any): void {\n // 解构\n const { __virid_source, __virid_target, __virid_messageType, payload } =\n ipcMessage;\n if (!__virid_messageType || !__virid_source || !__virid_target) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Incomplete Data:\\n__virid_source: ${__virid_source}\\n__virid_target:${__virid_target}\\n__virid_messageType: ${__virid_messageType}.`,\n ),\n );\n return;\n }\n if (!MESSAGE_MAP.has(__virid_messageType)) {\n MessageWriter.error(\n new Error(`[Virid Render] Unregistered type: ${__virid_messageType} `),\n );\n return;\n }\n // 找到对应的构造函数\n const MessageClass = MESSAGE_MAP.get(__virid_messageType)!;\n // 实例化并注入参数\n const instance = new MessageClass();\n\n // 显式赋值基类标识,确保实例的身份信息完整\n instance.__virid_source = __virid_source;\n instance.__virid_target = __virid_target;\n instance.__virid_messageType = __virid_messageType;\n\n // 还原数据\n if (payload) {\n Object.assign(instance, payload);\n }\n\n // 重新分发\n MessageWriter.write(instance);\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\n\nimport { MessageWriter, type ViridApp } from \"@virid/core\";\nimport { middleWare, convertFromMainMessage, ToMainMessage } from \"./renderer\";\nimport { type PluginOption } from \"./interfaces\";\nexport function activateApp(app: ViridApp, options: PluginOption) {\n // 先检查预加载脚本是否已经加载\n if (!window.__VIRID_BRIDGE__) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Preloading Failed: Please initialize in the preloaded script first.`,\n ),\n );\n }\n // 检查参数是否传递\n if (!options?.windowId) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Activate Failed:\\nPlease provide the windowId:${options?.windowId}.`,\n ),\n );\n }\n //注册自己的id,以后所有发往主进程的消息都会携带自己的id\n ToMainMessage.__virid_source = options.windowId;\n //主动向主进程发一个注册消息来注册自己\n window.__VIRID_BRIDGE__.post({\n __virid_source: options.windowId,\n __virid_target: \"main\",\n __virid_messageType: \"VIRID_INTERNAL_REGISTER\",\n payload: {\n windowId: options.windowId,\n },\n });\n // 订阅ipc通道,所有返回的消息,全部转换按照注册表转换成自己的消息类型\n window.__VIRID_BRIDGE__.subscribe(convertFromMainMessage);\n //注册自己的中间件函数,把ToMainMessage类型的消息拦截发往electron主进程\n app.useMiddleware(middleWare);\n}\n"],"mappings":";;;;ulBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,oBAAAC,EAAA,iBAAAC,EAAA,kBAAAC,EAAA,2BAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAR,GCKA,IAAAS,EAA6B,uBAItB,IAAeC,EAAf,MAAeA,UAAwBC,cAAAA,CAAvC,kCAGEC,EAAAA,sBAAyB,WAMzBC,EAAAA,sBAAyB,IAIzBC,EAAAA,2BAA8B,IACvC,EAd8CH,EAAAA,EAAAA,mBAAvC,IAAeD,EAAfK,EAmBeC,EAAf,MAAeA,UAAsBL,cAAAA,CAgB5C,EAhB4CA,EAAAA,EAAAA,iBAG1CM,EAHoBD,EAGNJ,kBAHT,IAAeI,EAAfE,ECvBP,IAAAC,EAA+C,uBAExC,IAAMC,EAAyBC,EAAA,CAACC,EAASC,IAAAA,CAE9C,GAAID,aAAmBE,EAAe,CACpC,GAAM,CAAEC,eAAAA,EAAgBC,oBAAAA,EAAqB,GAAGC,CAAAA,EAAYL,EAE5D,GAAIG,GAAkBD,EAAcI,eAAgB,CAClDC,gBAAcC,KACZ,+CAA+CL,CAAAA,qCAAmD,EAEpG,MACF,CACAM,OAAOC,iBAAiBC,KAAK,CAC3BL,eAAgBJ,EAAcI,eAC9BH,eAAgBA,EAChBC,oBAAqBA,EACrBC,QAASA,CACX,CAAA,CACF,MACEJ,EAAAA,CAEJ,EApBsC,cCFtC,IAAAW,EAAuC,uBAEvC,IAAMC,EAAc,IAAIC,IAEjB,SAASC,EAASC,EAAY,CACnC,OAAO,SAAUC,EAAgC,CAC3CJ,EAAYK,IAAIF,CAAAA,GAClBG,gBAAcC,MACZ,IAAIC,MACF,6DAA6DL,CAAAA,EAAM,CAAA,EAIzEH,EAAYS,IAAIN,EAAMC,CAAAA,CACxB,CACF,CAXgBF,EAAAA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exports","__export","FromMain","FromMainMessage","RenderPlugin","ToMainMessage","convertFromMainMessage","middleWare","__toCommonJS","import_core","FromMainMessage","EventMessage","__virid_source","__virid_target","__virid_messageType","_FromMainMessage","ToMainMessage","__publicField","_ToMainMessage","import_core","middleWare","__name","message","next","ToMainMessage","__virid_target","__virid_messageType","payload","__virid_source","MessageWriter","warn","window","__VIRID_BRIDGE__","post","import_core","MESSAGE_MAP","Map","FromMain","type","target","has","MessageWriter","error","Error","set","convertFromMainMessage","ipcMessage","__virid_source","__virid_target","__virid_messageType","payload","MessageClass","get","instance","Object","assign","write","import_core","activateApp","app","options","window","__VIRID_BRIDGE__","MessageWriter","error","Error","windowId","ToMainMessage","__virid_source","post","__virid_target","__virid_messageType","payload","subscribe","convertFromMainMessage","useMiddleware","middleWare","RenderPlugin","name","install","app","options","activateApp"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/renderer/message.ts","../src/renderer/middleware.ts","../src/renderer/router.ts","../src/app.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process.\n */\nimport { ViridPlugin, type ViridApp } from \"@virid/core\";\nexport { ToMainMessage, FromMainMessage } from \"./renderer\";\nexport * from \"./interfaces\";\nexport * from \"./renderer\";\nimport { activateApp } from \"./app\";\nimport { type PluginOption } from \"./interfaces\";\n\nexport class RenderPlugin implements ViridPlugin<PluginOption> {\n name = \"@virid/render\";\n install(app: ViridApp, options: PluginOption) {\n activateApp(app, options);\n }\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { EventMessage } from \"@virid/core\";\n/**\n * RenderMessage: Message sent by the main process\n */\nexport abstract class FromMainMessage extends EventMessage {\n /** Where am I from?\n */\n public __virid_source: string = \"unknown\";\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public __virid_target: string = \"\";\n /**\n *What message should I turn into at the destination?\n */\n public __virid_messageType: string = \"\";\n}\n\n/**\n *RenderMessage: Initiated by the rendering process, targeting the main process or other windows\n */\nexport abstract class ToMainMessage extends EventMessage {\n /**Where am I from?\n */\n public static __virid_source: string;\n\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public abstract __virid_target: string;\n\n /**\n *What message should I turn into at the destination?\n */\n public abstract __virid_messageType: string;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { type Middleware, MessageWriter } from \"@virid/core\";\nimport { ToMainMessage } from \"./message\";\nexport const middleWare: Middleware = (message, next) => {\n // If the message inherits from ToMainMessage, intercept concurrency to the main process\n if (message instanceof ToMainMessage) {\n const { __virid_target, __virid_messageType, ...payload } = message;\n if (__virid_target == ToMainMessage.__virid_source) {\n MessageWriter.warn(\n `[Virid Render] Prohibit Sending To Oneself: ${__virid_target} is not allowed in ToRenderMessage.`,\n );\n return;\n }\n window.__VIRID_BRIDGE__.post({\n __virid_source: ToMainMessage.__virid_source,\n __virid_target: __virid_target,\n __virid_messageType: __virid_messageType,\n payload: payload, // Expand all attributes on the instance\n });\n } else {\n next();\n }\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { MessageWriter, Newable } from \"@virid/core\";\nimport { type FromMainMessage } from \"./message\";\nconst MESSAGE_MAP = new Map<string, Newable<FromMainMessage>>();\n\nexport function FromMain(type: string) {\n return function (target: Newable<FromMainMessage>) {\n if (MESSAGE_MAP.has(type)) {\n MessageWriter.error(\n new Error(\n `[Virid Main] Duplicate IpcMessage: Registration for type: ${type}`,\n ),\n );\n }\n MESSAGE_MAP.set(type, target);\n };\n}\nexport function convertFromMainMessage(ipcMessage: any): void {\n const { __virid_source, __virid_target, __virid_messageType, payload } =\n ipcMessage;\n if (!__virid_messageType || !__virid_source || !__virid_target) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Incomplete Data:\\n__virid_source: ${__virid_source}\\n__virid_target:${__virid_target}\\n__virid_messageType: ${__virid_messageType}.`,\n ),\n );\n return;\n }\n if (!MESSAGE_MAP.has(__virid_messageType)) {\n MessageWriter.error(\n new Error(`[Virid Render] Unregistered type: ${__virid_messageType} `),\n );\n return;\n }\n // Find the corresponding constructor\n const MessageClass = MESSAGE_MAP.get(__virid_messageType)!;\n // Instantiate and inject parameters\n const instance = new MessageClass();\n\n // Explicitly assigning base class identifiers to ensure complete identity information of instances\n instance.__virid_source = __virid_source;\n instance.__virid_target = __virid_target;\n instance.__virid_messageType = __virid_messageType;\n\n // Restore data\n if (payload) {\n Object.assign(instance, payload);\n }\n\n // Redistribution\n MessageWriter.write(instance);\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\n\nimport { MessageWriter, type ViridApp } from \"@virid/core\";\nimport { middleWare, convertFromMainMessage, ToMainMessage } from \"./renderer\";\nimport { type PluginOption } from \"./interfaces\";\nexport function activateApp(app: ViridApp, options: PluginOption) {\n // first, check if the preload script has been loaded\n if (!window.__VIRID_BRIDGE__) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Preloading Failed: Please initialize in the preloaded script first.`,\n ),\n );\n }\n // check whether parameters are passed\n if (!options?.windowId) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Activate Failed:\\nPlease provide the windowId:${options?.windowId}.`,\n ),\n );\n }\n // register your own id, so that all messages sent to the main process will carry your own id in the future\n ToMainMessage.__virid_source = options.windowId;\n // actively send a registration message to the main process to register itself\n window.__VIRID_BRIDGE__.post({\n __virid_source: options.windowId,\n __virid_target: \"main\",\n __virid_messageType: \"VIRID_INTERNAL_REGISTER\",\n payload: {\n windowId: options.windowId,\n },\n });\n // Subscribe to the ipc channel, and convert all returned messages into our own message types according to the registry\n window.__VIRID_BRIDGE__.subscribe(convertFromMainMessage);\n // register your own middleware function to intercept messages of type ToMainMessage and forward them to the main process of electron\n app.useMiddleware(middleWare);\n}\n"],"mappings":";;;;ulBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,oBAAAC,EAAA,iBAAAC,EAAA,kBAAAC,EAAA,2BAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAR,GCKA,IAAAS,EAA6B,uBAItB,IAAeC,EAAf,MAAeA,UAAwBC,cAAAA,CAAvC,kCAGEC,EAAAA,sBAAyB,WAMzBC,EAAAA,sBAAyB,IAIzBC,EAAAA,2BAA8B,IACvC,EAd8CH,EAAAA,EAAAA,mBAAvC,IAAeD,EAAfK,EAmBeC,EAAf,MAAeA,UAAsBL,cAAAA,CAgB5C,EAhB4CA,EAAAA,EAAAA,iBAG1CM,EAHoBD,EAGNJ,kBAHT,IAAeI,EAAfE,ECvBP,IAAAC,EAA+C,uBAExC,IAAMC,EAAyBC,EAAA,CAACC,EAASC,IAAAA,CAE9C,GAAID,aAAmBE,EAAe,CACpC,GAAM,CAAEC,eAAAA,EAAgBC,oBAAAA,EAAqB,GAAGC,CAAAA,EAAYL,EAC5D,GAAIG,GAAkBD,EAAcI,eAAgB,CAClDC,gBAAcC,KACZ,+CAA+CL,CAAAA,qCAAmD,EAEpG,MACF,CACAM,OAAOC,iBAAiBC,KAAK,CAC3BL,eAAgBJ,EAAcI,eAC9BH,eAAgBA,EAChBC,oBAAqBA,EACrBC,QAASA,CACX,CAAA,CACF,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BI,eAAgB,OAChBC,oBAAqB,0BACrBC,QAAS,CACPN,SAAUN,EAAQM,QACpB,CACF,CAAA,EAEAL,OAAOC,iBAAiBW,UAAUC,CAAAA,EAElCf,EAAIgB,cAAcC,CAAAA,CACpB,CAhCgBlB,EAAAA,EAAAA,eJeT,IAAMmB,EAAN,MAAMA,CAAAA,CAAN,cACLC,EAAAA,YAAO,iBACPC,QAAQC,EAAeC,EAAuB,CAC5CC,EAAYF,EAAKC,CAAAA,CACnB,CACF,EALaJ,EAAAA,EAAAA,gBAAN,IAAMA,EAANM","names":["index_exports","__export","FromMain","FromMainMessage","RenderPlugin","ToMainMessage","convertFromMainMessage","middleWare","__toCommonJS","import_core","FromMainMessage","EventMessage","__virid_source","__virid_target","__virid_messageType","_FromMainMessage","ToMainMessage","__publicField","_ToMainMessage","import_core","middleWare","__name","message","next","ToMainMessage","__virid_target","__virid_messageType","payload","__virid_source","MessageWriter","warn","window","__VIRID_BRIDGE__","post","import_core","MESSAGE_MAP","Map","FromMain","type","target","has","MessageWriter","error","Error","set","convertFromMainMessage","ipcMessage","__virid_source","__virid_target","__virid_messageType","payload","MessageClass","get","instance","Object","assign","write","import_core","activateApp","app","options","window","__VIRID_BRIDGE__","MessageWriter","error","Error","windowId","ToMainMessage","__virid_source","post","__virid_target","__virid_messageType","payload","subscribe","convertFromMainMessage","useMiddleware","middleWare","RenderPlugin","name","install","app","options","activateApp","_RenderPlugin"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { EventMessage, Middleware, Newable, ViridPlugin } from '@virid/core';
|
|
1
|
+
import { EventMessage, Middleware, Newable, ViridPlugin, ViridApp } from '@virid/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* RenderMessage:
|
|
4
|
+
* RenderMessage: Message sent by the main process
|
|
5
5
|
*/
|
|
6
6
|
declare abstract class FromMainMessage extends EventMessage {
|
|
7
|
-
/**
|
|
7
|
+
/** Where am I from?
|
|
8
8
|
*/
|
|
9
9
|
__virid_source: string;
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
/**Where is my destination?
|
|
11
|
+
*'main ': Sent to the main process for processing
|
|
12
|
+
*'all': Broadcast to all windows (relayed through the main process)
|
|
13
|
+
*String: Specify the ID of a window (windowId)
|
|
14
14
|
*/
|
|
15
15
|
__virid_target: string;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
*What message should I turn into at the destination?
|
|
18
18
|
*/
|
|
19
19
|
__virid_messageType: string;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
*RenderMessage: Initiated by the rendering process, targeting the main process or other windows
|
|
23
23
|
*/
|
|
24
24
|
declare abstract class ToMainMessage extends EventMessage {
|
|
25
|
-
/**
|
|
25
|
+
/**Where am I from?
|
|
26
26
|
*/
|
|
27
27
|
static __virid_source: string;
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
28
|
+
/**Where is my destination?
|
|
29
|
+
*'main ': Sent to the main process for processing
|
|
30
|
+
*'all': Broadcast to all windows (relayed through the main process)
|
|
31
|
+
*String: Specify the ID of a window (windowId)
|
|
32
32
|
*/
|
|
33
33
|
abstract __virid_target: string;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
*What message should I turn into at the destination?
|
|
36
36
|
*/
|
|
37
37
|
abstract __virid_messageType: string;
|
|
38
38
|
}
|
|
@@ -49,6 +49,9 @@ interface PluginOption {
|
|
|
49
49
|
windowId: string;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
declare
|
|
52
|
+
declare class RenderPlugin implements ViridPlugin<PluginOption> {
|
|
53
|
+
name: string;
|
|
54
|
+
install(app: ViridApp, options: PluginOption): void;
|
|
55
|
+
}
|
|
53
56
|
|
|
54
57
|
export { FromMain, FromMainMessage, type PluginOption, RenderPlugin, ToMainMessage, convertFromMainMessage, middleWare };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { EventMessage, Middleware, Newable, ViridPlugin } from '@virid/core';
|
|
1
|
+
import { EventMessage, Middleware, Newable, ViridPlugin, ViridApp } from '@virid/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* RenderMessage:
|
|
4
|
+
* RenderMessage: Message sent by the main process
|
|
5
5
|
*/
|
|
6
6
|
declare abstract class FromMainMessage extends EventMessage {
|
|
7
|
-
/**
|
|
7
|
+
/** Where am I from?
|
|
8
8
|
*/
|
|
9
9
|
__virid_source: string;
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
/**Where is my destination?
|
|
11
|
+
*'main ': Sent to the main process for processing
|
|
12
|
+
*'all': Broadcast to all windows (relayed through the main process)
|
|
13
|
+
*String: Specify the ID of a window (windowId)
|
|
14
14
|
*/
|
|
15
15
|
__virid_target: string;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
*What message should I turn into at the destination?
|
|
18
18
|
*/
|
|
19
19
|
__virid_messageType: string;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
*RenderMessage: Initiated by the rendering process, targeting the main process or other windows
|
|
23
23
|
*/
|
|
24
24
|
declare abstract class ToMainMessage extends EventMessage {
|
|
25
|
-
/**
|
|
25
|
+
/**Where am I from?
|
|
26
26
|
*/
|
|
27
27
|
static __virid_source: string;
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
28
|
+
/**Where is my destination?
|
|
29
|
+
*'main ': Sent to the main process for processing
|
|
30
|
+
*'all': Broadcast to all windows (relayed through the main process)
|
|
31
|
+
*String: Specify the ID of a window (windowId)
|
|
32
32
|
*/
|
|
33
33
|
abstract __virid_target: string;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
*What message should I turn into at the destination?
|
|
36
36
|
*/
|
|
37
37
|
abstract __virid_messageType: string;
|
|
38
38
|
}
|
|
@@ -49,6 +49,9 @@ interface PluginOption {
|
|
|
49
49
|
windowId: string;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
declare
|
|
52
|
+
declare class RenderPlugin implements ViridPlugin<PluginOption> {
|
|
53
|
+
name: string;
|
|
54
|
+
install(app: ViridApp, options: PluginOption): void;
|
|
55
|
+
}
|
|
53
56
|
|
|
54
57
|
export { FromMain, FromMainMessage, type PluginOption, RenderPlugin, ToMainMessage, convertFromMainMessage, middleWare };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @virid/renderer v0.
|
|
2
|
+
* @virid/renderer v0.3.1
|
|
3
3
|
* Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process
|
|
4
4
|
*/
|
|
5
|
-
var
|
|
5
|
+
var f=Object.defineProperty;var M=(e,r,i)=>r in e?f(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i;var _=(e,r)=>f(e,"name",{value:r,configurable:!0});var d=(e,r,i)=>M(e,typeof r!="symbol"?r+"":r,i);import{EventMessage as g}from"@virid/core";var m=class m extends g{constructor(){super(...arguments);d(this,"__virid_source","unknown");d(this,"__virid_target","");d(this,"__virid_messageType","")}};_(m,"FromMainMessage");var w=m,a=class a extends g{};_(a,"ToMainMessage"),d(a,"__virid_source");var o=a;import{MessageWriter as y}from"@virid/core";var I=_((e,r)=>{if(e instanceof o){let{__virid_target:i,__virid_messageType:t,...n}=e;if(i==o.__virid_source){y.warn(`[Virid Render] Prohibit Sending To Oneself: ${i} is not allowed in ToRenderMessage.`);return}window.__VIRID_BRIDGE__.post({__virid_source:o.__virid_source,__virid_target:i,__virid_messageType:t,payload:n})}else r()},"middleWare");import{MessageWriter as p}from"@virid/core";var c=new Map;function B(e){return function(r){c.has(e)&&p.error(new Error(`[Virid Main] Duplicate IpcMessage: Registration for type: ${e}`)),c.set(e,r)}}_(B,"FromMain");function l(e){let{__virid_source:r,__virid_target:i,__virid_messageType:t,payload:n}=e;if(!t||!r||!i){p.error(new Error(`[Virid Render] Incomplete Data:
|
|
6
6
|
__virid_source: ${r}
|
|
7
7
|
__virid_target:${i}
|
|
8
|
-
__virid_messageType: ${t}.`));return}if(!c.has(t)){p.error(new Error(`[Virid Render] Unregistered type: ${t} `));return}let
|
|
9
|
-
Please provide the windowId:${r?.windowId}.`)),o.__virid_source=r.windowId,window.__VIRID_BRIDGE__.post({__virid_source:r.windowId,__virid_target:"main",__virid_messageType:"VIRID_INTERNAL_REGISTER",payload:{windowId:r.windowId}}),window.__VIRID_BRIDGE__.subscribe(l),e.useMiddleware(
|
|
8
|
+
__virid_messageType: ${t}.`));return}if(!c.has(t)){p.error(new Error(`[Virid Render] Unregistered type: ${t} `));return}let E=c.get(t),s=new E;s.__virid_source=r,s.__virid_target=i,s.__virid_messageType=t,n&&Object.assign(s,n),p.write(s)}_(l,"convertFromMainMessage");import{MessageWriter as u}from"@virid/core";function R(e,r){window.__VIRID_BRIDGE__||u.error(new Error("[Virid Render] Preloading Failed: Please initialize in the preloaded script first.")),r?.windowId||u.error(new Error(`[Virid Render] Activate Failed:
|
|
9
|
+
Please provide the windowId:${r?.windowId}.`)),o.__virid_source=r.windowId,window.__VIRID_BRIDGE__.post({__virid_source:r.windowId,__virid_target:"main",__virid_messageType:"VIRID_INTERNAL_REGISTER",payload:{windowId:r.windowId}}),window.__VIRID_BRIDGE__.subscribe(l),e.useMiddleware(I)}_(R,"activateApp");var v=class v{constructor(){d(this,"name","@virid/render")}install(r,i){R(r,i)}};_(v,"RenderPlugin");var x=v;export{B as FromMain,w as FromMainMessage,x as RenderPlugin,o as ToMainMessage,l as convertFromMainMessage,I as middleWare};
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/renderer/message.ts","../src/renderer/middleware.ts","../src/renderer/router.ts","../src/app.ts","../src/index.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { EventMessage } from \"@virid/core\";\n/**\n * RenderMessage: 由主进程发来的消息\n */\nexport abstract class FromMainMessage extends EventMessage {\n /** 我来自哪?\n */\n public __virid_source: string = \"unknown\";\n /** 我的目的地是哪儿?\n * 'main': 发给主进程处理\n * 'all': 广播给所有窗口(经过主进程中转)\n * string: 指定某个窗口的 ID (windowId)\n */\n public __virid_target: string = \"\";\n /**\n * 我应该在目的地转变成什么消息?\n */\n public __virid_messageType: string = \"\";\n}\n\n/**\n * RenderMessage: 由渲染进程发起,目标是主进程或其他窗口\n */\nexport abstract class ToMainMessage extends EventMessage {\n /** 我来自哪?\n */\n public static __virid_source: string;\n\n /** 我的目的地是哪儿?\n * 'main': 发给主进程处理\n * 'all': 广播给所有窗口(经过主进程中转)\n * string: 指定某个窗口的 ID (windowId)\n */\n public abstract __virid_target: string;\n\n /**\n * 我应该在目的地转变成什么消息?\n */\n public abstract __virid_messageType: string;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { type Middleware, MessageWriter } from \"@virid/core\";\nimport { ToMainMessage } from \"./message\";\nexport const middleWare: Middleware = (message, next) => {\n //如果消息继承自ToMainMessage,拦截并发往主进程\n if (message instanceof ToMainMessage) {\n const { __virid_target, __virid_messageType, ...payload } = message;\n //禁止发给自己\n if (__virid_target == ToMainMessage.__virid_source) {\n MessageWriter.warn(\n `[Virid Render] Prohibit Sending To Oneself: ${__virid_target} is not allowed in ToRenderMessage.`,\n );\n return;\n }\n window.__VIRID_BRIDGE__.post({\n __virid_source: ToMainMessage.__virid_source,\n __virid_target: __virid_target,\n __virid_messageType: __virid_messageType,\n payload: payload, // 展开实例上的所有属性\n });\n } else {\n next();\n }\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { MessageWriter, Newable } from \"@virid/core\";\nimport { type FromMainMessage } from \"./message\";\nconst MESSAGE_MAP = new Map<string, Newable<FromMainMessage>>();\n\nexport function FromMain(type: string) {\n return function (target: Newable<FromMainMessage>) {\n if (MESSAGE_MAP.has(type)) {\n MessageWriter.error(\n new Error(\n `[Virid Main] Duplicate IpcMessage: Registration for type: ${type}`,\n ),\n );\n }\n MESSAGE_MAP.set(type, target);\n };\n}\nexport function convertFromMainMessage(ipcMessage: any): void {\n // 解构\n const { __virid_source, __virid_target, __virid_messageType, payload } =\n ipcMessage;\n if (!__virid_messageType || !__virid_source || !__virid_target) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Incomplete Data:\\n__virid_source: ${__virid_source}\\n__virid_target:${__virid_target}\\n__virid_messageType: ${__virid_messageType}.`,\n ),\n );\n return;\n }\n if (!MESSAGE_MAP.has(__virid_messageType)) {\n MessageWriter.error(\n new Error(`[Virid Render] Unregistered type: ${__virid_messageType} `),\n );\n return;\n }\n // 找到对应的构造函数\n const MessageClass = MESSAGE_MAP.get(__virid_messageType)!;\n // 实例化并注入参数\n const instance = new MessageClass();\n\n // 显式赋值基类标识,确保实例的身份信息完整\n instance.__virid_source = __virid_source;\n instance.__virid_target = __virid_target;\n instance.__virid_messageType = __virid_messageType;\n\n // 还原数据\n if (payload) {\n Object.assign(instance, payload);\n }\n\n // 重新分发\n MessageWriter.write(instance);\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\n\nimport { MessageWriter, type ViridApp } from \"@virid/core\";\nimport { middleWare, convertFromMainMessage, ToMainMessage } from \"./renderer\";\nimport { type PluginOption } from \"./interfaces\";\nexport function activateApp(app: ViridApp, options: PluginOption) {\n // 先检查预加载脚本是否已经加载\n if (!window.__VIRID_BRIDGE__) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Preloading Failed: Please initialize in the preloaded script first.`,\n ),\n );\n }\n // 检查参数是否传递\n if (!options?.windowId) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Activate Failed:\\nPlease provide the windowId:${options?.windowId}.`,\n ),\n );\n }\n //注册自己的id,以后所有发往主进程的消息都会携带自己的id\n ToMainMessage.__virid_source = options.windowId;\n //主动向主进程发一个注册消息来注册自己\n window.__VIRID_BRIDGE__.post({\n __virid_source: options.windowId,\n __virid_target: \"main\",\n __virid_messageType: \"VIRID_INTERNAL_REGISTER\",\n payload: {\n windowId: options.windowId,\n },\n });\n // 订阅ipc通道,所有返回的消息,全部转换按照注册表转换成自己的消息类型\n window.__VIRID_BRIDGE__.subscribe(convertFromMainMessage);\n //注册自己的中间件函数,把ToMainMessage类型的消息拦截发往electron主进程\n app.useMiddleware(middleWare);\n}\n","/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process.\n */\nimport { ViridPlugin, type ViridApp } from \"@virid/core\";\nexport { ToMainMessage, FromMainMessage } from \"./renderer\";\nexport * from \"./interfaces\";\nexport * from \"./renderer\";\nimport { activateApp } from \"./app\";\nimport { type PluginOption } from \"./interfaces\";\nexport const RenderPlugin: ViridPlugin<PluginOption> = {\n name: \"@virid/render\",\n install(app: ViridApp, options) {\n activateApp(app, options);\n },\n};\n"],"mappings":";;;;uNAKA,OAASA,gBAAAA,MAAoB,cAItB,IAAeC,EAAf,MAAeA,UAAwBC,CAAAA,CAAvC,kCAGEC,EAAAA,sBAAyB,WAMzBC,EAAAA,sBAAyB,IAIzBC,EA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qCAAqCM,CAAAA,GAAsB,CAAA,EAEvE,MACF,CAEA,IAAME,EAAehB,EAAYiB,IAAIH,CAAAA,EAE/BI,EAAW,IAAIF,EAGrBE,EAASN,eAAiBA,EAC1BM,EAASL,eAAiBA,EAC1BK,EAASJ,oBAAsBA,EAG3BC,GACFI,OAAOC,OAAOF,EAAUH,CAAAA,EAI1BT,EAAce,MAAMH,CAAAA,CACtB,CAnCgBR,EAAAA,EAAAA,0BCfhB,OAASY,iBAAAA,MAAoC,cAGtC,SAASC,EAAYC,EAAeC,EAAqB,CAEzDC,OAAOC,kBACVC,EAAcC,MACZ,IAAIC,MACF,oFAAoF,CAAA,EAKrFL,GAASM,UACZH,EAAcC,MACZ,IAAIC,MACF;8BAAgEL,GAASM,QAAAA,GAAW,CAAA,EAK1FC,EAAcC,eAAiBR,EAAQM,SAEvCL,OAAOC,iBAAiBO,KAAK,CAC3BD,eAAgBR,EAAQM,SACxBI,eAAgB,OAChBC,oBAAqB,0BACrBC,QAAS,CACPN,SAAUN,EAAQM,QACpB,CACF,CAAA,EAEAL,OAAOC,iBAAiBW,UAAUC,CAAAA,EAElCf,EAAIgB,cAAcC,CAAAA,CACpB,CAhCgBlB,EAAAA,EAAAA,eCcT,IAAMmB,EAA0C,CACrDC,KAAM,gBACNC,QAAQC,EAAeC,EAAO,CAC5BC,EAAYF,EAAKC,CAAAA,CACnB,CACF","names":["EventMessage","FromMainMessage","EventMessage","__virid_source","__virid_target","__virid_messageType","_FromMainMessage","ToMainMessage","__publicField","_ToMainMessage","MessageWriter","middleWare","__name","message","next","ToMainMessage","__virid_target","__virid_messageType","payload","__virid_source","MessageWriter","warn","window","__VIRID_BRIDGE__","post","MessageWriter","MESSAGE_MAP","Map","FromMain","type","target","has","MessageWriter","error","Error","set","convertFromMainMessage","ipcMessage","__virid_source","__virid_target","__virid_messageType","payload","MessageClass","get","instance","Object","assign","write","MessageWriter","activateApp","app","options","window","__VIRID_BRIDGE__","MessageWriter","error","Error","windowId","ToMainMessage","__virid_source","post","__virid_target","__virid_messageType","payload","subscribe","convertFromMainMessage","useMiddleware","middleWare","RenderPlugin","name","install","app","options","activateApp"]}
|
|
1
|
+
{"version":3,"sources":["../src/renderer/message.ts","../src/renderer/middleware.ts","../src/renderer/router.ts","../src/app.ts","../src/index.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { EventMessage } from \"@virid/core\";\n/**\n * RenderMessage: Message sent by the main process\n */\nexport abstract class FromMainMessage extends EventMessage {\n /** Where am I from?\n */\n public __virid_source: string = \"unknown\";\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public __virid_target: string = \"\";\n /**\n *What message should I turn into at the destination?\n */\n public __virid_messageType: string = \"\";\n}\n\n/**\n *RenderMessage: Initiated by the rendering process, targeting the main process or other windows\n */\nexport abstract class ToMainMessage extends EventMessage {\n /**Where am I from?\n */\n public static __virid_source: string;\n\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public abstract __virid_target: string;\n\n /**\n *What message should I turn into at the destination?\n */\n public abstract __virid_messageType: string;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { type Middleware, MessageWriter } from \"@virid/core\";\nimport { ToMainMessage } from \"./message\";\nexport const middleWare: Middleware = (message, next) => {\n // If the message inherits from ToMainMessage, intercept concurrency to the main process\n if (message instanceof ToMainMessage) {\n const { __virid_target, __virid_messageType, ...payload } = message;\n if (__virid_target == ToMainMessage.__virid_source) {\n MessageWriter.warn(\n `[Virid Render] Prohibit Sending To Oneself: ${__virid_target} is not allowed in ToRenderMessage.`,\n );\n return;\n }\n window.__VIRID_BRIDGE__.post({\n __virid_source: ToMainMessage.__virid_source,\n __virid_target: __virid_target,\n __virid_messageType: __virid_messageType,\n payload: payload, // Expand all attributes on the instance\n });\n } else {\n next();\n }\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { MessageWriter, Newable } from \"@virid/core\";\nimport { type FromMainMessage } from \"./message\";\nconst MESSAGE_MAP = new Map<string, Newable<FromMainMessage>>();\n\nexport function FromMain(type: string) {\n return function (target: Newable<FromMainMessage>) {\n if (MESSAGE_MAP.has(type)) {\n MessageWriter.error(\n new Error(\n `[Virid Main] Duplicate IpcMessage: Registration for type: ${type}`,\n ),\n );\n }\n MESSAGE_MAP.set(type, target);\n };\n}\nexport function convertFromMainMessage(ipcMessage: any): void {\n const { __virid_source, __virid_target, __virid_messageType, payload } =\n ipcMessage;\n if (!__virid_messageType || !__virid_source || !__virid_target) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Incomplete Data:\\n__virid_source: ${__virid_source}\\n__virid_target:${__virid_target}\\n__virid_messageType: ${__virid_messageType}.`,\n ),\n );\n return;\n }\n if (!MESSAGE_MAP.has(__virid_messageType)) {\n MessageWriter.error(\n new Error(`[Virid Render] Unregistered type: ${__virid_messageType} `),\n );\n return;\n }\n // Find the corresponding constructor\n const MessageClass = MESSAGE_MAP.get(__virid_messageType)!;\n // Instantiate and inject parameters\n const instance = new MessageClass();\n\n // Explicitly assigning base class identifiers to ensure complete identity information of instances\n instance.__virid_source = __virid_source;\n instance.__virid_target = __virid_target;\n instance.__virid_messageType = __virid_messageType;\n\n // Restore data\n if (payload) {\n Object.assign(instance, payload);\n }\n\n // Redistribution\n MessageWriter.write(instance);\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\n\nimport { MessageWriter, type ViridApp } from \"@virid/core\";\nimport { middleWare, convertFromMainMessage, ToMainMessage } from \"./renderer\";\nimport { type PluginOption } from \"./interfaces\";\nexport function activateApp(app: ViridApp, options: PluginOption) {\n // first, check if the preload script has been loaded\n if (!window.__VIRID_BRIDGE__) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Preloading Failed: Please initialize in the preloaded script first.`,\n ),\n );\n }\n // check whether parameters are passed\n if (!options?.windowId) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Activate Failed:\\nPlease provide the windowId:${options?.windowId}.`,\n ),\n );\n }\n // register your own id, so that all messages sent to the main process will carry your own id in the future\n ToMainMessage.__virid_source = options.windowId;\n // actively send a registration message to the main process to register itself\n window.__VIRID_BRIDGE__.post({\n __virid_source: options.windowId,\n __virid_target: \"main\",\n __virid_messageType: \"VIRID_INTERNAL_REGISTER\",\n payload: {\n windowId: options.windowId,\n },\n });\n // Subscribe to the ipc channel, and convert all returned messages into our own message types according to the registry\n window.__VIRID_BRIDGE__.subscribe(convertFromMainMessage);\n // register your own middleware function to intercept messages of type ToMainMessage and forward them to the main process of electron\n app.useMiddleware(middleWare);\n}\n","/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process.\n */\nimport { ViridPlugin, type ViridApp } from \"@virid/core\";\nexport { ToMainMessage, FromMainMessage } from \"./renderer\";\nexport * from \"./interfaces\";\nexport * from \"./renderer\";\nimport { activateApp } from \"./app\";\nimport { type PluginOption } from \"./interfaces\";\n\nexport class RenderPlugin implements ViridPlugin<PluginOption> {\n name = \"@virid/render\";\n install(app: ViridApp, options: PluginOption) {\n activateApp(app, options);\n }\n}\n"],"mappings":";;;;uNAKA,OAASA,gBAAAA,MAAoB,c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,GAAsB,CAAA,EAGxJ,MACF,CACA,GAAI,CAACd,EAAYK,IAAIS,CAAAA,EAAsB,CACzCR,EAAcC,MACZ,IAAIC,MAAM,qCAAqCM,CAAAA,GAAsB,CAAA,EAEvE,MACF,CAEA,IAAME,EAAehB,EAAYiB,IAAIH,CAAAA,EAE/BI,EAAW,IAAIF,EAGrBE,EAASN,eAAiBA,EAC1BM,EAASL,eAAiBA,EAC1BK,EAASJ,oBAAsBA,EAG3BC,GACFI,OAAOC,OAAOF,EAAUH,CAAAA,EAI1BT,EAAce,MAAMH,CAAAA,CACtB,CAlCgBR,EAAAA,EAAAA,0BCfhB,OAASY,iBAAAA,MAAoC,cAGtC,SAASC,EAAYC,EAAeC,EAAqB,CAEzDC,OAAOC,kBACVC,EAAcC,MACZ,IAAIC,MACF,oFAAoF,CAAA,EAKrFL,GAASM,UACZH,EAAcC,MACZ,IAAIC,MACF;8BAAgEL,GAASM,QAAAA,GAAW,CAAA,EAK1FC,EAAcC,eAAiBR,EAAQM,SAEvCL,OAAOC,iBAAiBO,KAAK,CAC3BD,eAAgBR,EAAQM,SACxBI,eAAgB,OAChBC,oBAAqB,0BACrBC,QAAS,CACPN,SAAUN,EAAQM,QACpB,CACF,CAAA,EAEAL,OAAOC,iBAAiBW,UAAUC,CAAAA,EAElCf,EAAIgB,cAAcC,CAAAA,CACpB,CAhCgBlB,EAAAA,EAAAA,eCeT,IAAMmB,EAAN,MAAMA,CAAAA,CAAN,cACLC,EAAAA,YAAO,iBACPC,QAAQC,EAAeC,EAAuB,CAC5CC,EAAYF,EAAKC,CAAAA,CACnB,CACF,EALaJ,EAAAA,EAAAA,gBAAN,IAAMA,EAANM","names":["EventMessage","FromMainMessage","EventMessage","__virid_source","__virid_target","__virid_messageType","_FromMainMessage","ToMainMessage","__publicField","_ToMainMessage","MessageWriter","middleWare","__name","message","next","ToMainMessage","__virid_target","__virid_messageType","payload","__virid_source","MessageWriter","warn","window","__VIRID_BRIDGE__","post","MessageWriter","MESSAGE_MAP","Map","FromMain","type","target","has","MessageWriter","error","Error","set","convertFromMainMessage","ipcMessage","__virid_source","__virid_target","__virid_messageType","payload","MessageClass","get","instance","Object","assign","write","MessageWriter","activateApp","app","options","window","__VIRID_BRIDGE__","MessageWriter","error","Error","windowId","ToMainMessage","__virid_source","post","__virid_target","__virid_messageType","payload","subscribe","convertFromMainMessage","useMiddleware","middleWare","RenderPlugin","name","install","app","options","activateApp","_RenderPlugin"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@virid/renderer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"description": "Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process",
|
|
6
6
|
"author": "Ailrid",
|
|
7
7
|
"license": "Apache 2.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@virid/core": "0.
|
|
37
|
+
"@virid/core": "0.3.1"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup --config tsup.config.ts",
|