{"id":20129354,"url":"https://github.com/ryanmorr/elemental","last_synced_at":"2026-05-08T09:31:10.252Z","repository":{"id":211773396,"uuid":"729937953","full_name":"ryanmorr/elemental","owner":"ryanmorr","description":"A functional approach to creating autonomous custom elements","archived":false,"fork":false,"pushed_at":"2023-12-10T20:07:38.000Z","size":89,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-06T21:50:03.637Z","etag":null,"topics":["custom-elements","dom","functional","javascript","ui","web-components"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryanmorr.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}},"created_at":"2023-12-10T20:04:18.000Z","updated_at":"2023-12-10T20:14:45.000Z","dependencies_parsed_at":"2023-12-10T20:11:13.780Z","dependency_job_id":"f910aa9e-95f8-4f21-88cd-34ea1ab71d61","html_url":"https://github.com/ryanmorr/elemental","commit_stats":null,"previous_names":["ryanmorr/elemental"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ryanmorr/elemental","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmorr%2Felemental","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmorr%2Felemental/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmorr%2Felemental/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmorr%2Felemental/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanmorr","download_url":"https://codeload.github.com/ryanmorr/elemental/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmorr%2Felemental/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32774677,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"ssl_error","status_checked_at":"2026-05-08T08:22:45.650Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["custom-elements","dom","functional","javascript","ui","web-components"],"created_at":"2024-11-13T20:33:48.165Z","updated_at":"2026-05-08T09:31:10.230Z","avatar_url":"https://github.com/ryanmorr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elemental\n\n[![Version Badge][version-image]][project-url]\n[![License][license-image]][license-url]\n[![Build Status][build-image]][build-url]\n\n\u003e A functional approach to creating autonomous custom elements\n\n## Install\n\nDownload the [CJS](https://github.com/ryanmorr/elemental/raw/master/dist/cjs/elemental.js), [ESM](https://github.com/ryanmorr/elemental/raw/master/dist/esm/elemental.js), [UMD](https://github.com/ryanmorr/elemental/raw/master/dist/umd/elemental.js) versions or install via NPM:\n\n```sh\nnpm install @ryanmorr/elemental\n```\n\n## Usage\n\nDefine an autonomous custom element by providing the tag name and an initialization function:\n\n```javascript\nimport elemental from '@ryanmorr/elemental';\n\n// Define a custom element and return the class\nconst CustomElement = elemental('custom-element', (element) =\u003e {\n    // Return an HTML string or DOM node to set the shadow root content\n    return '\u003cdiv\u003eHello World\u003c/div\u003e';\n});\n\n// Create an element instance\nconst element = document.createElement('custom-element');\n\n// Initialization function is called when the element is mounted to the DOM\ndocument.body.appendChild(element);\n```\n\nOptionally define default properties:\n\n```javascript\nelemental('custom-element', {msg: 'World'}, (element) =\u003e {\n    // Default properties are added to the element instance on initialization\n    return `Hello ${element.msg}`;\n});\n```\n\nDefault properties with a primitive value (string/number/boolean/null) are automatically reflected into attributes on initialization and observed for changes. After initialization, attribute changes are reflected into properties, but property changes are not reflected into attributes:\n\n```javascript\nelemental('custom-element', {foo: 'abc', bar: 123, baz: {}}, (element) =\u003e {\n    // Primitive default properties are reflected to attributes on initialization\n    element.getAttribute('foo'); //=\u003e \"abc\"\n    element.getAttribute('bar'); //=\u003e \"123\"\n    element.getAttribute('baz'); //=\u003e null\n\n    // A property assignment is not reflected into an attribute\n    element.foo = 'xyz';\n    element.getAttribute('foo'); //=\u003e \"abc\"\n\n    // Setting an attribute will be reflected into a property \n    // and convert the value to its natural type\n    element.setAttribute('bar', '789');\n    element.bar; //=\u003e 789 (number not string)\n});\n```\n\nSubscribe to DOM state changes via the `observe` method:\n\n```javascript\nelemental('custom-element', {foo: 'abc', bar: 123}, (element) =\u003e {\n    // Returns a function to stop future calls\n    const stop = element.observe('mount', (parentElement) =\u003e {\n        // Called everytime the element is mounted to the DOM\n    });\n\n    element.observe('unmount', () =\u003e {\n        // Called everytime the element is unmounted from the DOM\n    });\n\n    element.observe('prop', (name, newVal, oldVal) =\u003e {\n        // Called everytime a default property changes\n    });\n\n    element.observe('prop:foo', (newVal, oldVal) =\u003e {\n        // Called everytime the \"foo\" property changes\n    });\n\n    element.observe('attr', (name, newVal, oldVal) =\u003e {\n        // Called everytime a reflected attribute changes\n    });\n\n    element.observe('attr:bar', (newVal, oldVal) =\u003e {\n        // Called everytime the \"bar\" attribute changes\n    });\n});\n```\n\nUse the `html` property to get and set the shadow root:\n\n```javascript\nelemental('custom-element', (element) =\u003e {\n    // Supports HTML strings\n    element.html = '\u003cdiv\u003e\u003c/div\u003e';\n    element.html.innerHTML; //=\u003e \"\u003cdiv\u003e\u003c/div\u003e\"\n\n    // Supports DOM nodes\n    element.html = document.createElement('span');\n    element.html.innerHTML; //=\u003e \"\u003cspan\u003e\u003c/span\u003e\"\n});\n```\n\nAdd scoped CSS to the custom element via the `css` property. It supports CSS strings, `\u003cstyle\u003e` elements, `CSSStyleSheet` instances, or an array of any of those types. Each assignment to the `css` property appends to the CSS and does not replace it:\n\n```javascript\nelemental('custom-element', (element) =\u003e {\n    // Add CSS via string\n    element.css = `\n        .foo {\n            color: red;\n        }\n    `;\n\n    // Appends \u003cstyle\u003e element to CSS\n    const style = document.createElement('style');\n    style.textContent = `\n        .bar {\n            color: blue;\n        }\n    `;\n    element.css = style;\n\n    // Optionally define CSS within the shadow root using \u003cstyle\u003e and/or \u003clink\u003e elements\n    return `\n        \u003clink rel=\"stylesheet\" href=\"custom-element.css\"\u003e\n        \u003cstyle\u003e\n        .baz {\n            color: green;\n        }\n        \u003c/style\u003e\n        \u003cdiv class=\"foo\"\u003e\u003c/div\u003e\n        \u003cdiv class=\"bar\"\u003e\u003c/div\u003e\n        \u003cdiv class=\"baz\"\u003e\u003c/div\u003e\n    `;\n});\n```\n\n## License\n\nThis project is dedicated to the public domain as described by the [Unlicense](http://unlicense.org/).\n\n[project-url]: https://github.com/ryanmorr/elemental\n[version-image]: https://img.shields.io/github/package-json/v/ryanmorr/elemental?color=blue\u0026style=flat-square\n[build-url]: https://github.com/ryanmorr/elemental/actions\n[build-image]: https://img.shields.io/github/actions/workflow/status/ryanmorr/elemental/node.js.yml?style=flat-square\n[license-image]: https://img.shields.io/github/license/ryanmorr/elemental?color=blue\u0026style=flat-square\n[license-url]: UNLICENSE","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanmorr%2Felemental","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanmorr%2Felemental","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanmorr%2Felemental/lists"}