{"id":15501453,"url":"https://github.com/martynaskadisa/figma-comlink","last_synced_at":"2025-04-22T23:06:28.101Z","repository":{"id":83102273,"uuid":"461846274","full_name":"martynaskadisa/figma-comlink","owner":"martynaskadisa","description":"Comlink endpoint utilities for Figma plugins","archived":false,"fork":false,"pushed_at":"2022-02-21T13:41:59.000Z","size":20,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-22T23:06:27.400Z","etag":null,"topics":["comlink","figma"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martynaskadisa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-21T12:13:32.000Z","updated_at":"2025-03-03T01:36:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"90e87bfe-6188-4f0c-a286-a693627d8057","html_url":"https://github.com/martynaskadisa/figma-comlink","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martynaskadisa%2Ffigma-comlink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martynaskadisa%2Ffigma-comlink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martynaskadisa%2Ffigma-comlink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martynaskadisa%2Ffigma-comlink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martynaskadisa","download_url":"https://codeload.github.com/martynaskadisa/figma-comlink/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250337947,"owners_count":21414104,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["comlink","figma"],"created_at":"2024-10-02T09:04:24.560Z","updated_at":"2025-04-22T23:06:28.073Z","avatar_url":"https://github.com/martynaskadisa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# figma-comlink\n\nComlink endpoint utilities for Figma plugins\n\n## Install\n\n```\nnpm i figma-comlink\n```\n\nor\n\n```\nyarn add figma-comlink\n```\n\n## Usage\n\n### Exposing plugin methods to the UI\n\nDeclare your object you want to expose and call `Comlink`'s `expose` method with an endpoint from `figma-comlink`:\n\n```js\n// plugin.js\nimport * as Comlink from \"comlink\";\nimport { uiEndpoint } from \"figma-comlink\";\n\nconst api = {\n  foo() {\n    return 'bar';\n  }\n  // If you want to expose figma's built in methods, make sure to wrap it with a `proxy`\n  clientStorage: Comlink.proxy({\n    getAsync: figma.clientStorage.getAsync,\n    setAsync: figma.clientStorage.setAsync,\n  }),\n}\n\nComlink.expose(api, uiEndpoint());\n\n\n```\n\nand then use it from the UI thread like so:\n\n```js\n// ui.js\nimport * as Comlink from \"comlink\";\nimport { pluginEndpoint } from \"figma-comlink\";\n\nconst plugin = Comlink.wrap(pluginEndpoint());\n\nplugin.foo()\n  .then(console.log) //-\u003e \"bar\"\n\n```\n\n### Exposing UI methods to the plugin\n\nDefine your UI methods:\n```js\n// ui.js\nimport * as Comlink from \"comlink\";\nimport { pluginEndpoint } from \"figma-comlink\";\n\nconst api = {\n  notify(msg) {\n    // ... your notification implementation\n    window.alert(msg)\n  }\n};\n\nComlink.expose(api, pluginEndpoint);\n\n```\n\nadd UI endpoint and use your exposed method\n\n```js\n// plugin.js\nimport * as Comlink from \"comlink\";\nimport { uiEndpoint } from \"figma-comlink\";\n\nconst ui = Comlink.wrap(uiEndpoint());\n\nui.notify(\"Hey ma! I'm sending a notification from plugin thread!\")\n\n```\n\n## API\n\n### uiEndpoint \n`() =\u003e Comlink.Endpoint`\n\nCreates a UI endpoint. This should be used in your _plugin_ thread.\n  \n### pluginEndpoint \n`({ targetOrigin, pluginId }?: Options) =\u003e Comlink.Endpoint`\n\n`Options`:\n  - `targetOrigin?: string`\n    Origin on which we should listen and send messages to.\n    Defaults to `'*'`\n    \n  - `pluginId?: string`\n    Your plugin ID\n\nCreates a plugin endpoint. This should be used in your _UI_ thread\n\nIf your UI lives on a different origin or you have potentially sensitive data, you should pass `pluginId` and `targetOrigin`:\n\n```js\nconst plugin = Comlink.wrap(\n  pluginEndpoint({\n    pluginId: \"\u003c\u003cyour plugin id\u003e\u003e\",\n    targetOrigin: \"https://www.figma.com\",\n  })\n);\n```\n\nSee more at Figma's docs [here](https://www.figma.com/plugin-docs/creating-ui/#non-null-origin-iframes)\n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartynaskadisa%2Ffigma-comlink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartynaskadisa%2Ffigma-comlink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartynaskadisa%2Ffigma-comlink/lists"}