{"id":15685551,"url":"https://github.com/neg4n/d3-no-dom","last_synced_at":"2025-05-05T20:55:32.336Z","repository":{"id":246571129,"uuid":"816189173","full_name":"neg4n/d3-no-dom","owner":"neg4n","description":" 📊 Fully use D3.js (Data Driven Documents) in environments without DOM. Perfect for serverless e.g. Vercel Functions","archived":false,"fork":false,"pushed_at":"2024-07-16T06:27:03.000Z","size":274,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-03T06:57:48.057Z","etag":null,"topics":["cloudflare-workers","d3","d3-js","d3-visualization","d3js","dom","jsdom","lambda","lambda-functions","no-dom","server-side","server-side-rendering","ssr","svg","svg-images","vercel","vercel-serverless","virtual-dom","virtualdom","workers"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/d3-no-dom","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/neg4n.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2024-06-17T08:12:18.000Z","updated_at":"2024-12-08T17:35:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"bf197732-1a0b-4f95-ad9c-fba279c520a4","html_url":"https://github.com/neg4n/d3-no-dom","commit_stats":null,"previous_names":["neg4n/d3-no-dom"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neg4n%2Fd3-no-dom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neg4n%2Fd3-no-dom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neg4n%2Fd3-no-dom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neg4n%2Fd3-no-dom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neg4n","download_url":"https://codeload.github.com/neg4n/d3-no-dom/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252576882,"owners_count":21770720,"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":["cloudflare-workers","d3","d3-js","d3-visualization","d3js","dom","jsdom","lambda","lambda-functions","no-dom","server-side","server-side-rendering","ssr","svg","svg-images","vercel","vercel-serverless","virtual-dom","virtualdom","workers"],"created_at":"2024-10-03T17:26:34.204Z","updated_at":"2025-05-05T20:55:32.312Z","avatar_url":"https://github.com/neg4n.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# d3-no-dom\n\nFully use [`d3.js`][d3] in environments without DOM, such as [Cloudflare Workers][cfworkers] or [Vercel Functions][vercel-functions]\n\n## Features\n\n- Simple API with maximum extensibility. \n- Support for asynchronous operations and API calls in render function\n- Utilities like sanitizing the HTML or outputting the base64 from generated svg\n- Tests covering most of the functionality ensuring robustness\n\n## Installation\n\n```sh\nnpm i d3-no-dom d3 \n# or\nyarn add d3-no-dom d3 \n# or\npnpm add d3-no-dom d3 \n```\n\nThe `d3-no-dom` library does not provide any underlying DOM implementation, giving users the flexibility to choose their preferred DOM library. Some options are:\n\n-  [`linkedom`][linkedom]: A lightweight and fast DOM implementation ideal for serverless environments such as [Cloudflare Workers][cfworkers] or [Vercel Functions][vercel-functions] (recommended).\n  ```sh\n  npm i linkedom \n  # or\n  yarn add linkedom \n  # or\n  pnpm add linkedom \n  ```\n  \n-  [`jsdom`][jsdom]: A more comprehensive and heavier DOM implementation, suitable for traditional backend environments like monolithic applications hosted on dedicated servers.\n  ```sh\n  npm i jsdom \n  # or\n  yarn add jsdom \n  # or\n  pnpm add jsdom \n  ```\n\n\u003e [!WARNING]  \n\u003e [`jsdom`][jsdom] may not work on the [Cloudflare Workers][cfworkers]\n\u003e without specifying `nodejs_compat` flag due to use of the Node native modules\n\n\n## How to use\n\n1. At first, you must supply your own d3 instance and dom provider to the `d3-no-dom`'s `prepreSvgServerSideRenderer`\n\n  - using [linkedom][linkedom] **(recommended)**\n    ```ts\n    import * as d3 from \"d3\"\n    import { parseHTML } from \"linkedom\"\n\n    // ...\n\n    class Linkedom {\n      window: { document: Document };\n      constructor(html: string) {\n        const { document, window } = parseHTML(html);\n        this.window = { document };\n        Object.assign(this.window, window);\n      }\n    }\n\n    const { render } = prepareSvgServerSideRenderer({\n      domProvider: Linkedom,\n      d3Instance: d3\n    });\n    ```\n\n  - using [jsdom][jsdom]\n    ```ts\n    import * as d3 from \"d3\"\n    import { JSDOM } from \"jsdom\"\n\n    // ...\n\n    const { render } = prepareSvgServerSideRenderer({\n      domProvider: JSDOM,\n      d3Instance: d3\n    });\n    ```\n\n2. Next, use the `render` function. It provides everything you need in order to fully use d3.js on the server side (the underlying mechanism is integration with Virtual DOM)\n\n  ```ts\n  //               you can make e.g. API calls here   \n  //           it can also be synchronous if not needed!\n  //              ╭────────────┤\n  //              │            │    \n  //              ↓            ↓ \n  const result = await render(async ({ d3Selection, svgNode, currentDom }) =\u003e {\n  //      ↑                                  ↑        ↑          ↑            \n  //      │                d3 selected       │        │          │\n  //      │                object to work on ╯        │          ╰ whole DOM  \n  //      │                                      underlying\n  //      ╰ rendered svg's                 svg DOM node to work on\n  //   source, as HTML or base64   \n  })\n  ```\n\n3. (Optionally) adjust your configuration or the [render function's options](\nhttps://github.com/neg4n/d3-no-dom/blob/main/src/index.ts#L32-L39) directly in order to e.g. disable sanitizing\nthe HTML or control the return value _(whether it should be HTML or base64 - where second is specifically useful with usage with [satori][satori])_\n\n### License \u0026 contributing\n\nThe MIT License. All contributions are welcome!\n\n[linkedom]: https://github.com/WebReflection/linkedom\n[vercel-functions]: https://vercel.com/docs/functions#vercel-functions\n[cfworkers]: https://workers.cloudflare.com/\n[jsdom]: https://github.com/jsdom/jsdom\n[d3]: https://d3js.org/\n[satori]: https://github.com/vercel/satori\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneg4n%2Fd3-no-dom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneg4n%2Fd3-no-dom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneg4n%2Fd3-no-dom/lists"}