{"id":22729803,"url":"https://github.com/gc-victor/p","last_synced_at":"2025-08-04T06:39:57.241Z","repository":{"id":147530119,"uuid":"415790900","full_name":"gc-victor/p","owner":"gc-victor","description":"P is a micro-library (1 KB) to patch DOM Trees","archived":false,"fork":false,"pushed_at":"2021-11-01T16:22:48.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T01:13:49.781Z","etag":null,"topics":["dom","dom-diff","patch","vdom"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/gc-victor.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-10-11T05:33:18.000Z","updated_at":"2022-08-22T13:12:28.000Z","dependencies_parsed_at":"2023-07-24T19:15:37.408Z","dependency_job_id":null,"html_url":"https://github.com/gc-victor/p","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gc-victor/p","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gc-victor","download_url":"https://codeload.github.com/gc-victor/p/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gc-victor%2Fp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268658658,"owners_count":24285734,"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","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["dom","dom-diff","patch","vdom"],"created_at":"2024-12-10T18:11:49.930Z","updated_at":"2025-08-04T06:39:57.212Z","avatar_url":"https://github.com/gc-victor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# P\n\nP is a micro-library (1 KB) to patch DOM Trees. Instead of using a Virtual DOM, it uses dom-diff to update the DOM if there is a child active element. Otherwise, it will take one tree by the other.\n\n## Key Features\n\n- Micro-library 1 KB\n- Without dependencies\n- No compilation needed\n- No Virtual DOM, uses dom-diff to update the DOM\n- Zero Dependencies\n- Small API, not much to learn\n\n## Let's Play\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n    \u003chead\u003e\n        \u003cscript type=\"module\"\u003e\n            import p from 'https://cdn.jsdelivr.net/gh/gc-victor/p/dist/esm/index.js';\n            // Use any template engine of your choice that creates DOM trees\n            import { t } from 'https://cdn.jsdelivr.net/gh/gc-victor/t/dist/esm/index.js';\n\n            let count = 0;\n\n            const increment = () =\u003e {\n                count = count + 1;\n                // Updates the DOM\n                p(document.getElementById('app'), counter());\n            };\n            const decrement = () =\u003e {\n                count = count - 1;\n                // Updates the DOM\n                p(document.getElementById('app'), counter());\n            };\n            const add = (ev) =\u003e {\n                count = Number(ev.target.value);\n                // Updates the DOM\n                p(document.getElementById('app'), counter());\n            };\n\n            const counter = () =\u003e {\n                return t`\n                    \u003cdiv id=\"app\"\u003e\n                        \u003ch1\u003eCounter\u003c/h1\u003e\n                        \u003cbutton onclick=\"${increment}\"\u003e+\u003c/button\u003e\n                        \u003cinput oninput=\"${add}\" name=\"input\" type=\"number\" value=\"${count}\" /\u003e\n                        \u003cbutton onclick=\"${decrement}\"\u003e-\u003c/button\u003e\n                    \u003c/div\u003e\n                `;\n            };\n\n            // Updates the DOM\n            p(document.getElementById('app'), counter());\n        \u003c/script\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003cmain id=\"app\"\u003e\n            \u003ch1\u003eCounter\u003c/h1\u003e\n            \u003cbutton\u003e+\u003c/button\u003e\u003cinput name=\"c\" type=\"number\" value=\"0\"\u003e\u003cbutton\u003e-\u003c/button\u003e\n        \u003c/main\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Install\n\nYou can use pnpm, npm or yarn to install it.\n\n```console\nnpm install git+https://github.com/gc-victor/p.git#main\n```\n\nImport it in your framework.\n\n```js\nimport p from 'p';\n```\n\nOr import it in a `\u003cscript\u003e` as a module.\n\n```html\n\u003cscript type=\"module\"\u003e\n    import p from 'https://cdn.jsdelivr.net/gh/gc-victor/p/dist/esm/index.js';\n\u003c/script\u003e\n```\n\n## How to use it\n\nYou can create as many patches as you need. The first parameter is where you want to make the change, and the second specifies what you wish to change.\n\n```javascript\n// p(where, what)\np(document.getElementById('app'), count());\n```\n\nA key or name attribute is required to keep the focus of an active element when its content change.\n\nUsing the T library:\n```javascript\nt`\u003cinput name=\"input\" value=\"${variable}\" /\u003e`\n```\n\nOr\n\n```javascript\nt`\u003cbutton key=\"count\"\u003eCount - ${variable}\u003c/button\u003e`\n```\n\nUsing plain JS:\n\n```javascript\nbuttonElement.__key__ = 'count';\n```\n\n## Acknowledgments\n\n### Inspiration\n\n-   [udomdiff](https://github.com/WebReflection/udomdiff)\n-   [dom-expressions](https://github.com/ryansolid/dom-expressions)\n-   [h-h](https://github.com/gc-victor/h-h)\n\n### Tools\n\n-   [esbuild](https://esbuild.github.io/)\n-   [gzip-size](https://esbuild.github.io/)\n-   [d-d](https://github.com/gc-victor/d-d)\n-   [esm](https://github.com/standard-things/esm)\n-   [es-module-shims](https://github.com/guybedford/es-module-shims)\n-   [jsdom](https://github.com/jsdom/jsdom)\n-   [t-t](https://github.com/gc-victor/t-t)\n-   [chokidar-cli](https://github.com/kimmobrunfeldt/chokidar-cli)\n\n## Compatible Versioning\n\n### Summary\n\nGiven a version number MAJOR.MINOR, increment the:\n\n- MAJOR version when you make backwards-incompatible updates of any kind\n- MINOR version when you make 100% backwards-compatible updates\n\nAdditional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR format.\n\n[![ComVer](https://img.shields.io/badge/ComVer-compliant-brightgreen.svg)](https://github.com/staltz/comver)\n\n## Contribute\n\nFirst off, thanks for taking the time to contribute!\nNow, take a moment to be sure your contributions make sense to everyone else.\n\n### Reporting Issues\n\nFound a problem? Want a new feature? First of all, see if your issue or idea has [already been reported](../../issues).\nIf it hasn't, just open a [new clear and descriptive issue](../../issues/new).\n\n### Commit message conventions\n\nA specification for adding human and machine readable meaning to commit messages.\n\n- [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)\n\n### Submitting pull requests\n\nPull requests are the greatest contributions, so be sure they are focused in scope and do avoid unrelated commits.\n\n-   Fork it!\n-   Clone your fork: `git clone http://github.com/\u003cyour-username\u003e/p`\n-   Navigate to the newly cloned directory: `cd p`\n-   Create a new branch for the new feature: `git checkout -b my-new-feature`\n-   Install the tools necessary for development: `npm install`\n-   Make your changes.\n-   `npm run build` to verify your change doesn't increase output size.\n-   `npm test` to make sure your change doesn't break anything.\n-   Commit your changes: `git commit -am 'Add some feature'`\n-   Push to the branch: `git push origin my-new-feature`\n-   Submit a pull request with full remarks documenting your changes.\n\n## License\n\n[MIT License](https://github.com/gc-victor/p/blob/master/LICENSE)\n\nCopyright (c) 2021 Víctor García\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgc-victor%2Fp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgc-victor%2Fp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgc-victor%2Fp/lists"}