{"id":19012604,"url":"https://github.com/zm-cttae/dom-inline-style-filter","last_synced_at":"2026-04-08T14:01:33.461Z","repository":{"id":172057479,"uuid":"638478691","full_name":"zm-cttae/dom-inline-style-filter","owner":"zm-cttae","description":"High-pass data compression filter for inline styling (embedded CSS).","archived":false,"fork":false,"pushed_at":"2025-10-30T20:39:47.000Z","size":6082,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-30T22:22:28.987Z","etag":null,"topics":["archiving","canvas","dataurl","dom","image","inkscape","javascript","screenshot","svg","web"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zm-cttae.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2023-05-09T12:58:18.000Z","updated_at":"2025-10-30T20:39:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"40e5d546-a3bf-43cf-9a81-30bd76985afa","html_url":"https://github.com/zm-cttae/dom-inline-style-filter","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"5bfe1fedf1ddb59b59cbc5c0b12879276b0355c1"},"previous_names":["zm-cttae/dom-inline-style-filter"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/zm-cttae/dom-inline-style-filter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zm-cttae%2Fdom-inline-style-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zm-cttae%2Fdom-inline-style-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zm-cttae%2Fdom-inline-style-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zm-cttae%2Fdom-inline-style-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zm-cttae","download_url":"https://codeload.github.com/zm-cttae/dom-inline-style-filter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zm-cttae%2Fdom-inline-style-filter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31558386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T10:21:54.569Z","status":"ssl_error","status_checked_at":"2026-04-08T10:21:38.171Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["archiving","canvas","dataurl","dom","image","inkscape","javascript","screenshot","svg","web"],"created_at":"2024-11-08T19:18:50.516Z","updated_at":"2026-04-08T14:01:33.428Z","avatar_url":"https://github.com/zm-cttae.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `dom-inline-style-filter`\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/zm-cttae/dom-inline-style-filter/raw/dddefaf96c39378bf00a335bac76fc3839fd0a4e/assets/icon.png\" height=\"128\" /\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://github.com/zm-cttae/dom-inline-style-filter\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/zm-cttae/dom-inline-style-filter.svg?style=flat-square\u0026label=Release\u0026logo=github\u0026logoColor=cacde2\u0026labelColor=2c2c32\u0026color=2196f3\" /\u003e\u003c/a\u003e \u003ca href=\"https://www.npmjs.com/package/dom-inline-style-filter\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/dom-inline-style-filter?style=flat-square\u0026label=Downloads\u0026logo=npm\u0026logoColor=cacde2\u0026labelColor=2c2c32\u0026color=2196f3\" /\u003e\u003c/a\u003e \u003ca href=\"https://github.com/vsce-toolroom/vscode-beautify/pipelines\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/zm-cttae/dom-inline-style-filter/CI.svg?style=flat-square\u0026label\t=CI\u0026logo=github\u0026logoColor=cacde2\u0026labelColor=2c2c32\u0026color=2196f3\" /\u003e\u003c/a\u003e\u003c/p\u003e\n\n`dom-inline-style-filter` library filters inline style declarations for a standalone DOM element tree by computed effect.\n\n- As web developers, we would like elements that ship only with inline styling to be light so that they can be included in NPM packages.\n- A main use case of this is SVG screenshots of HTML elements.\n- Even after a filter algorithm to [filter out user agent styling when inlining the style][css-author-style-filter], there is some way to go with data size.\n\n## Usage\n\n### `dominlinestylefilter(node)`\n\n**Parameter:** `node` - a `HTMLElement` with all style rules embedded as inline style attributes or `\u003cstyle\u003e` tags.\n\n**Returns:** a `Promise` that resolves to `node`. Within `node`, all inline styling has been filtered to the minimum declarations that produce the same computed style.\n\n### `dominlinestylefilter.sync(node)`\n\nSynchronous version. Returns `node` when the styling compression is completed.\n\n## Optimizations\n\n1.  **When traversing DOM tree of `node`, group nodes by descending node depth.**\n\n    CSS inheritance is computed on the DOM tree via preorder traversal and is additive-cumulative (increases styling data).\n\t\n\tFor the filter op which is subtractive, we want to traverse the tree in the opposite direction to avoid more recomputation.\n    \n    The algorithm sorts elements in the `node` tree by descending node depth. (This is known as reverse level order traversal.)\n\n    This gives us a 30% to 40% speed boost. This also ensures declarations are only removed when they really can be inherited.\n\n2.  **When filtering each inline style declaration by computed effect, go for the most hyphenated properties first.**\n\n    In CSS, shorthands consistently have less hyphens than their longhand.\n\n\tWe want to filter out scenarios where a CSS property matches their shorthand, e.g. `block-size` -\u003e `height` or `border-color` -\u003e `border`.\n\n    The algorithm does a radix sort with bitmasks for standard, custom and vendored proprties, then subsorts by descending hyphen count.\n\n    In tests this filtered another 50% of inline styling. We also get a 20-40% speed boost because we're not setting as many properties back.\n\n## Performance\n\n### `filterAuthorInlineStyles`\n\nThe [`filterAuthorInlineStyles` algorithm][css-author-style-filter] was proven to be a single-pass deterministic compression.\n\nData was collected from manual testing on the output of the `domtoimage.toSvg` function in the `dom-to-image` NPM package.\n\n### Large file inputs\n\n$O(N)$ growth for inputs at large filesizes $|F| \u003e\u003e 1e6 \\text{ bytes}$.\n\n| Wikipedia article demo    | Value                                  |\n| :------------------------ | :------------------------------------- |\n| Number of nodes           | 5558 nodes                             |\n| Initial declaration count | 2107482 (377.54 declarations / node)   |\n| Pre-compression bytes     | 33.79mb                                |\n| Reductions                | 27901890                               |\n| Processing time           | 7921.5ms (1.85 ms/node)                |\n| Total reduction           | 27.90mb                                |\n| Output declaration count  | 263099 (47.13 / node)                  |\n| Post-compression bytes    | 5.89mb                                 |\n| Compression ratio         | `5.74                                ` |\n\n### `filterWinningInlineStyles`\n\nThe `filterWinningInlineStyles` algorithm was proven to be a high-pass multi-pass - $N \\approx 4$ - deterministic compression in two modes.\n\nData was collected from manual testing on the output of the `domtoimage.toSvg` function in the `dom-to-image-more` NPM package.\n\n### Large file inputs\n\n$O(log(N))$ growth for inputs at large filesizes $|F| \u003e\u003e 1e6 \\text{ bytes}$.\n\n| Wikipedia article demo    | Value                                  |\n| :------------------------ | :------------------------------------- |\n| Number of nodes           | 5558 nodes                             |\n| Initial declaration count | 186985 (33.65 declarations / node)     |\n| Pre-compression bytes     | 3.88mb                                 |\n| Reductions                | [2970178, 95584, 16774, 0]             |\n| Processing time           | 7921.5ms (1.43 ms/node)                |\n| Total reduction           | 3.09mb                                 |\n| Output declaration count  | 83512 (15.03 / node)                   |\n| Post-compression bytes    | 793.7kb                                |\n| Compression quotients     | [0.5379, 0.8891, 0.9800, 1]            |\n| Compression ratio         | `4.88                                ` |\n| Decay formula             | $1-exp(-33 / 17 \\cdot N)$              |\n\n### Graph\n\n\u003cimg src=\"./assets/236925669-a3461c94-c1dd-4d42-9bd1-55484c084614.png\" width=\"539px\" /\u003e\n\n### Small file results\n\n$O(c \\cdot N), \\space c \\space \\approx \\space 4$ growth for inputs at small filesizes $|F| \u003c\u003c 1e6\\space\\text{ bytes}$.\n\n| Code screenshot demo      | Value                                  |\n| :------------------------ | :------------------------------------- |\n| Number of nodes           | 420 nodes                              |\n| Initial declaration count | 17551 (41.79 declarations / node)      |\n| Pre-compression bytes     | 429160b                                |\n| Reductions                | [298806, 40420, 0]                     |\n| Processing time           | 5445.2ms (12.96 ms / node)             |\n| Total reduction           | 339226b                                |\n| Post-compression bytes    | 89934b                                 |\n| Output declaration count  | 7637 (18.18 / node)                    |\n| Compression quotients     | [0.696, 0.931, 1]                      |\n| Total quotient (compound) | `4.77                                ` |\n| Decay formula             | $1-exp(-23 / 11 \\cdot N)$              |\n\n\u003cimg src=\"./assets/236925730-e880fabe-426f-491e-a95f-989536c9e3bc.png\" width=\"539px\" /\u003e\n\n\u003c!-- `dom-inline-style-filter` --\u003e\n[css-author-style-filter]: https://github.com/1904labs/dom-to-image-more/pull/71\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzm-cttae%2Fdom-inline-style-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzm-cttae%2Fdom-inline-style-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzm-cttae%2Fdom-inline-style-filter/lists"}