{"id":15312721,"url":"https://github.com/everweij/solid-boundaries","last_synced_at":"2025-06-11T13:35:02.305Z","repository":{"id":57689343,"uuid":"476880149","full_name":"everweij/solid-boundaries","owner":"everweij","description":"Utility to track the boundaries of html-elements in SolidJS","archived":false,"fork":false,"pushed_at":"2022-05-04T09:53:37.000Z","size":99,"stargazers_count":18,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T03:50:06.137Z","etag":null,"topics":["bounds","measure","position","resize","size","solidjs"],"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/everweij.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.MD","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-01T22:02:49.000Z","updated_at":"2025-02-09T23:15:18.000Z","dependencies_parsed_at":"2022-09-26T20:53:31.137Z","dependency_job_id":null,"html_url":"https://github.com/everweij/solid-boundaries","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everweij%2Fsolid-boundaries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everweij%2Fsolid-boundaries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everweij%2Fsolid-boundaries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everweij%2Fsolid-boundaries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/everweij","download_url":"https://codeload.github.com/everweij/solid-boundaries/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everweij%2Fsolid-boundaries/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259274306,"owners_count":22832496,"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":["bounds","measure","position","resize","size","solidjs"],"created_at":"2024-10-01T08:38:21.165Z","updated_at":"2025-06-11T13:35:02.278Z","avatar_url":"https://github.com/everweij.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"100\" src=\"https://www.solidjs.com/img/logo/without-wordmark/logo.svg\"\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\" style=\"font-weight: 700;\"\u003esolid-boundaries\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  Helps you to track the size and position of html-elements in solid-js.\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\n## What does it do?\n\nSee it in action [here](https://7j26ix.sse.codesandbox.io/), or see it on [CodeSandbox](https://codesandbox.io/s/solid-boundaries-example-7j26ix?file=/src/main.tsx)!\n\nThis small library exposes a small reactive primitive which tracks the **size** and **position** (_bounds_) of a specific html-element (subject). _Bounds_, just like when you call `.getBoundingClientRect()`, have the following structure:\n\n```ts\ninterface Bounds {\n  top: number;\n  left: number;\n  right: number;\n  bottom: number;\n  width: number;\n  height: number;\n}\n```\n\nThis is useful for all kinds of things, like building tooltips, popovers, or other behavior and interactions related to changes regarding size and positions.\n\nBounds update in response to:\n\n- scrolling - the entire window as well as (nested-)scroll-containers\n- resizing - the entire window as well as the subject\n- mutations in the document - to be more specific:\n  - any changes that may affect styling (style/class attributes)\n  - adding or removal of other html-elements\n\n## Install\n\n```bash\nnpm install solid-boundaries\n```\n\n## Usage\n\n```tsx\nimport { trackBounds } from \"solid-boundaries\";\n\nfunction App() {\n  const { ref, bounds } = trackBounds();\n\n  // Make sure to pass the ref properly to the element you\n  // want to track, and do something with fun with the bounds!\n  // Note: the bounds are `null` when the element has not been\n  // connected to the DOM yet.\n  return (\n    \u003cdiv ref={ref}\u003e\n      {bounds() \u0026\u0026 JSON.stringify(bounds())}\n    \u003cdiv\u003e\n  )\n}\n```\n\n## API\n\n```tsx\ninterface Bounds {\n  top: number;\n  left: number;\n  right: number;\n  bottom: number;\n  width: number;\n  height: number;\n}\n\ninterface Config {\n  /**\n   * Whether to actively track the element's position.\n   * @default () =\u003e true\n   */\n  enabled?: Accessor\u003cboolean\u003e;\n  /**\n   * Whether to actively track mutations in the DOM.\n   * @default () =\u003e true\n   */\n  trackMutations?: boolean;\n  /**\n   * Whether to actively track resizes of the element you're\n   * tracking or of the entire window.\n   * @default () =\u003e true\n   */\n  trackResize?: boolean;\n  /**\n   * Whether to actively track scrolling.\n   * @default () =\u003e true\n   */\n  trackScroll?: boolean;\n  /**\n   * Defines specific keys of the boundary to track.\n   * By default all keys are tracked.\n   * @default [\"top\", \"right\", \"bottom\", \"left\", \"width\", \"height\"]\n   */\n  keys?: BoundsKeys;\n  /**\n   * Whether not to show warning messages in the console\n   */\n  suppressWarnings?: boolean;\n}\n\ntype TrackBoundsProps = {\n  /**\n   * Setter which should be passed to the `ref` prop of the\n   * element you want to track.\n   */\n  ref: Setter\u003cHTMLElement | null\u003e;\n  /**\n   * The bounds of the element you are tracking.\n   * Note: returns `null` if the element is not connected\n   * to the DOM.\n   */\n  bounds: Accessor\u003cBounds | null\u003e;\n  /**\n   * Provides a reference to the element.\n   */\n  element: Accessor\u003cHTMLElement | null\u003e;\n};\n\nfunction trackBounds(config?: Config): TrackBoundsProps;\n```\n\n## Browser compatibility\n\nThis library makes use of `ResizeObserver` and `MutationObserver`. If you need to support older browsers I recommend to use a polyfill, otherwise certain behavior will be skipped.\n\n## Contributing\n\nWant to contribute to solid-boundaries? Your help is very much appreciated!\nPlease consult the [contribution guide](./CONTRIBUTING.MD) on how to get started.\n\n## License\n\nMIT © [everweij](https://github.com/everweij)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverweij%2Fsolid-boundaries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feverweij%2Fsolid-boundaries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverweij%2Fsolid-boundaries/lists"}