@virid/renderer 0.3.0 → 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 CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @virid/renderer v0.3.0
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 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 n=(e,r,i)=>V(e,typeof r!="symbol"?r+"":r,i);var W={};$(W,{FromMain:()=>h,FromMainMessage:()=>c,RenderPluginClass:()=>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);n(this,"__virid_source","unknown");n(this,"__virid_target","");n(this,"__virid_messageType","")}};_(f,"FromMainMessage");var c=f,w=class w extends v.EventMessage{};_(w,"ToMainMessage"),n(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:
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: ${o}.`));return}if(!m.has(o)){p.MessageWriter.error(new Error(`[Virid Render] Unregistered type: ${o} `));return}let M=m.get(o),s=new M;s.__virid_source=r,s.__virid_target=i,s.__virid_messageType=o,t&&Object.assign(s,t),p.MessageWriter.write(s)}_(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(){n(this,"name","@virid/render")}install(r,i){E(r,i)}};_(R,"RenderPluginClass");var u=R;0&&(module.exports={FromMain,FromMainMessage,RenderPluginClass,ToMainMessage,convertFromMainMessage,middleWare});
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
@@ -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\";\n\nexport class RenderPluginClass 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,sBAAAC,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,MACEJ,EAAAA,CAEJ,EAnBsC,cCFtC,IAAAW,EAAuC,uBAEvC,IAAMC,EAAc,IAAIC,IAEjB,SAASC,EAASC,EAAY,CACnC,OAAO,SAAUC,EAAgC,CAC3CJ,EAAYK,IAAIF,CAAAA,GAClBG,gBAAcC,MACZ,IAAIC,MACF,6DAA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MA,CAAAA,CAAN,cACLC,EAAAA,YAAO,iBACPC,QAAQC,EAAeC,EAAuB,CAC5CC,EAAYF,EAAKC,CAAAA,CACnB,CACF,EALaJ,EAAAA,EAAAA,qBAAN,IAAMA,EAANM","names":["index_exports","__export","FromMain","FromMainMessage","RenderPluginClass","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","RenderPluginClass","name","install","app","options","activateApp","_RenderPluginClass"]}
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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ASM,UACZH,gBAAcC,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,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
@@ -49,9 +49,9 @@ interface PluginOption {
49
49
  windowId: string;
50
50
  }
51
51
 
52
- declare class RenderPluginClass implements ViridPlugin<PluginOption> {
52
+ declare class RenderPlugin implements ViridPlugin<PluginOption> {
53
53
  name: string;
54
54
  install(app: ViridApp, options: PluginOption): void;
55
55
  }
56
56
 
57
- export { FromMain, FromMainMessage, type PluginOption, RenderPluginClass, ToMainMessage, convertFromMainMessage, middleWare };
57
+ export { FromMain, FromMainMessage, type PluginOption, RenderPlugin, ToMainMessage, convertFromMainMessage, middleWare };
package/dist/index.d.ts CHANGED
@@ -49,9 +49,9 @@ interface PluginOption {
49
49
  windowId: string;
50
50
  }
51
51
 
52
- declare class RenderPluginClass implements ViridPlugin<PluginOption> {
52
+ declare class RenderPlugin implements ViridPlugin<PluginOption> {
53
53
  name: string;
54
54
  install(app: ViridApp, options: PluginOption): void;
55
55
  }
56
56
 
57
- export { FromMain, FromMainMessage, type PluginOption, RenderPluginClass, ToMainMessage, convertFromMainMessage, middleWare };
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.3.0
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 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,...s}=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:s})}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:s}=e;if(!t||!r||!i){p.error(new Error(`[Virid Render] Incomplete Data:
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 E=c.get(t),n=new E;n.__virid_source=r,n.__virid_target=i,n.__virid_messageType=t,s&&Object.assign(n,s),p.write(n)}_(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,"RenderPluginClass");var x=v;export{B as FromMain,w as FromMainMessage,x as RenderPluginClass,o as ToMainMessage,l as convertFromMainMessage,I as middleWare};
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: 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 RenderPluginClass 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,cAItB,IAAeC,EAAf,MAAeA,UAAwBC,CAAAA,CAAvC,kCAGEC,EAAAA,sBAAyB,WAMzBC,EAAAA,sBAAyB,IAIzBC,EAAAA,2BAA8B,IACvC,EAd8CH,EAAAA,EAAAA,mBAAvC,IAAeD,EAA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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,qBAAN,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","RenderPluginClass","name","install","app","options","activateApp","_RenderPluginClass"]}
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,gBA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AAwCC,CAAAA,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.3.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.3.0"
37
+ "@virid/core": "0.3.1"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup --config tsup.config.ts",