{"id":26601217,"url":"https://github.com/thisloke/ng2-fittext","last_synced_at":"2025-04-09T16:34:06.816Z","repository":{"id":19503817,"uuid":"84933613","full_name":"thisloke/ng2-fittext","owner":"thisloke","description":"An Angular2+ directive that autoscale the font size of an element until it fit the upper level container dimension.","archived":false,"fork":false,"pushed_at":"2024-07-10T12:10:50.000Z","size":12498,"stargazers_count":32,"open_issues_count":4,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-23T18:50:27.121Z","etag":null,"topics":["angular","angular2-directive","font-automatic-resizing","font-size","ng2-fittext","responsive","text-automatic-resizing","text-resize"],"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/thisloke.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":"2017-03-14T10:00:38.000Z","updated_at":"2024-09-27T07:09:21.000Z","dependencies_parsed_at":"2024-06-18T17:00:37.974Z","dependency_job_id":"a77c6201-d728-4069-945d-e837b54c7677","html_url":"https://github.com/thisloke/ng2-fittext","commit_stats":null,"previous_names":["thisloke/ng2-fittext"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisloke%2Fng2-fittext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisloke%2Fng2-fittext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisloke%2Fng2-fittext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisloke%2Fng2-fittext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thisloke","download_url":"https://codeload.github.com/thisloke/ng2-fittext/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248067756,"owners_count":21042348,"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":["angular","angular2-directive","font-automatic-resizing","font-size","ng2-fittext","responsive","text-automatic-resizing","text-resize"],"created_at":"2025-03-23T18:38:01.286Z","updated_at":"2025-04-09T16:34:06.778Z","avatar_url":"https://github.com/thisloke.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  ng2-fittext\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003eAn Angular 2+ directive, written in pure TypeScript (without jQuery!), to automatically scale the font size of an element so that it fits within its parent container.\u003c/p\u003e\n\n[![Download via NPM](https://img.shields.io/npm/v/ng2-fittext.svg)](https://www.npmjs.com/package/ng2-fittext)\n![Angular](https://img.shields.io/badge/Angular-18-green.svg)\n![Build Status](https://github.com/thisloke/ng2-fittext/actions/workflows/tests.yml/badge.svg)\n![Contributions welcome](https://img.shields.io/badge/contributions-welcome-green.svg)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n## Demo\nCheck out the live demo: [ng2-fittext Demo](https://stackblitz.com/edit/stackblitz-starters-7ghzat?file=src%2Fmain.ts)\n\u003cdiv\u003e\n  \u003cimg src=\"ng2-fittext-example.gif\" alt=\"ng2 fittext example\" border=\"0\" style=\"width: 70%\" align=\"center\"/\u003e\n\u003c/div\u003e\n\n## Installation\n\nInstall the library using npm according to your angular version (see table below):\n\n| Angular | ng2-fittext | command                       |\n|---------|-------------|-------------------------------|\n| \u003c= v17  | 1.4.3       | ```npm i ng2-fittext@1.4.3``` |\n| \u003e= v18  | 2.0.0       | ```npm i ng2-fittext@2.0.0``` |\n\n\n### Usage\n\n1. Import the module in your Angular application:\n```ts\nimport { Ng2FittextModule } from \"ng2-fittext\";\n\n@NgModule({\n  imports: [Ng2FittextModule]\n})\n```\n\n2. Use the directive in your components:\n```ts\nimport { Component } from '@angular/core';\n\n@Component({\n  selector: 'label',\n  template: `\n    \u003cdiv #container\u003e\n      \u003cdiv [fittext]=\"true\" [activateOnResize]=\"true\" [container]=\"container\"\u003eBla bla bla...\u003c/div\u003e\n    \u003c/div\u003e\n  `\n})\nexport class LabelComponent {}\n```\n\n### Examples\n\nFit to the parent element (works if you have a variable number of elements between your element and its parent):\n\n```ts\nimport { Component } from '@angular/core';\n\n@Component({\n  selector: 'label',\n  template: `\n    \u003cdiv\u003e\n      \u003cdiv [fittext]=\"true\" [activateOnResize]=\"true\"\u003eBla bla bla...\u003c/div\u003e\n    \u003c/div\u003e\n  `\n})\nexport class LabelComponent {}\n```\n\n**NEW! Support for auto-resize input box:**\n\n```ts\nimport { Component } from '@angular/core';\n\n@Component({\n  selector: 'inputbox',\n  template: `\n    \u003cdiv #container\u003e\n      \u003cinput [fittext]=\"true\" [activateOnResize]=\"true\" [container]=\"container\" [activateOnInputEvents]=\"true\"\u003e\n    \u003c/div\u003e\n  `\n})\nexport class InputBoxComponent {}\n```\n\n**NEW! Support for maxFontSize:**\n\n```ts\nimport { Component } from '@angular/core';\n\n@Component({\n  selector: 'inputbox',\n  template: `\n    \u003cdiv\u003e\n      \u003cinput [fittext]=\"true\" [activateOnResize]=\"true\" [activateOnInputEvents]=\"true\" [minFontSize]=\"40\" [maxFontSize]=\"100\"\u003e\n    \u003c/div\u003e\n  `\n})\nexport class InputBoxComponent {}\n```\n\nInput Parameters:\n\n| Parameter                       | Description                                                                             | Values                        |\n| ------------------------------- | --------------------------------------------------------------------------------------- | ----------------------------- |\n| fittext                         | Directive selector                                                                      | true/false                    |\n| container                       | The container to fit (if not present it fits to the parent container by default)        | ElementRef                    |\n| activateOnResize                | Enable/disable the autofit on window resize                                             | true or false (default false) |\n| activateOnInputEvents           | Enable/disable the auto-fit in case of input box events (keydown, keyup etc..)          | true or false (default false) |\n| maxFontSize                     | Maximum font size                                                                       | Number (default is 1000)      |\n| **!deprecated!** useMaxFontSize | Use max font size if is true                                                            | Deprecated!                   |\n| minFontSize                     | Minimum font size                                                                       | Number (default is 7)         |\n| modelToWatch                    | Pass model to watch; when this model changes, font size is automatically recalculated   | Any type of model             |\n\nOutput Parameters:\n\n| Parameter       | Description       | Values |\n| --------------- | ----------------- | ------ |\n| fontSizeChanged | Current font size | string |\n\n### Development\n\nWant to contribute? Great!\nSimply, clone the repository!\n\nI created this library because I always spent too much time solving this problem and didn't find anything on the web (as of 13/03/2017) that does this without jQuery and is easily integrable in Angular 2+.\nWhile it might not be the best implementation, it gets the job done.\n\n### Todos\n\n- Write tests\n- Find a performant algorithm to find the font size that fits the container better\n\n## License\n\nMIT\n\n**Lorenzo I.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisloke%2Fng2-fittext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthisloke%2Fng2-fittext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisloke%2Fng2-fittext/lists"}