├── .editorconfig ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .npmignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE ├── bug_report.md └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── angular.json ├── browserslist ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── projects └── angular-inport │ ├── README.md │ ├── karma.conf.js │ ├── ng-package.json │ ├── package.json │ ├── src │ ├── lib │ │ ├── index.ts │ │ ├── inview-container.directive.ts │ │ ├── inview-item.directive.ts │ │ ├── inview.directive.ts │ │ ├── inview.module.ts │ │ └── utils │ │ │ ├── models.ts │ │ │ ├── offset-resolver.ts │ │ │ ├── position-resolver.ts │ │ │ ├── scroll-observable.ts │ │ │ └── viewport-ruler.ts │ ├── public-api.ts │ └── test.ts │ ├── tsconfig.lib.json │ ├── tsconfig.lib.prod.json │ ├── tsconfig.spec.json │ └── tslint.json ├── src ├── app │ ├── app.component.css │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ └── app.pipes.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.css └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | make.js 2 | # compiled output 3 | /.tmp 4 | /src 5 | 6 | /Architecture.md 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # IDEs and editors 12 | /.idea 13 | /.vscode 14 | .project 15 | .classpath 16 | .c9/ 17 | *.launch 18 | .settings/ 19 | tslint.json 20 | .editorconfig 21 | 22 | 23 | # misc 24 | /.sass-cache 25 | /connect.lock 26 | /coverage/* 27 | /libpeerconnection.log 28 | npm-debug.log 29 | testem.log 30 | /typings 31 | 32 | # e2e 33 | /e2e/*.js 34 | /e2e/*.map 35 | 36 | #System Files 37 | .DS_Store 38 | Thumbs.db 39 | 40 | 41 | # angular-cli 42 | .angular-cli.json 43 | .gitignore 44 | karma.conf.js 45 | protractor.conf.js 46 | tsconfig-lib.json 47 | tsconfig.json 48 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at meajaysingh@hotmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Atom 2 | 3 | :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: 4 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ⚛👋 Hello there! Welcome. Please follow the steps below to tell us about your contribution. 2 | 3 | 1. Use the correct words for your contribution 4 | - 🐛 Are you fixing a bug? 5 | - 📈 Are you improving performance? 6 | - 📝 Are you updating documentation? 7 | - 💻 Are you changing functionality? 8 | 2. create the branch based on above mention things as `bug-fix-`,`perf-fix-` etc 9 | 3. please provide descriptions. 10 | 4. please use words like resolve, resolves, close closes with issues id in commits. ex- resolves #30 11 | 4. Click "Create pull request" 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular In Port / Angular In View Port 2 | 3 | ## Installation 4 | 5 | - `npm i -S angular-inport` 6 | 7 | - `yarn add angular-inport` 8 | 9 | ## Importing module 10 | 11 | ```js 12 | import { NgInviewModule } from 'angular-inport'; 13 | 14 | @NgModule({ 15 | imports: [ 16 | // ... 17 | NgInviewModule 18 | ], 19 | declarations: [YourAppComponent], 20 | exports: [YourAppComponent], 21 | bootstrap: [YourAppComponent], 22 | }) 23 | ``` 24 | 25 | #### Basic Usages 26 | 27 | ```html 28 |
29 | ``` 30 | 31 | #### Advanced Usages 32 | 33 | ```html 34 | 35 |
43 | ....... 44 |
45 | 46 | ``` 47 | 48 | ## InviewContainer and InviewItem Directive 49 | 50 | #### Basic Usages 51 | 52 | ```html 53 | 54 |
55 |
56 | ....... 57 |
58 |
59 | 60 | ``` 61 | 62 | 63 | #### Advanced Usages 64 | 65 | ```html 66 | 67 |
75 |
76 | ....... 77 |
78 |
79 | 80 | ``` 81 | 82 | #### InView Props 83 | 84 | * `(inview)`: inview event, it will keep to emitting the event on scroll. 85 | * `[offset]`: offset value can be provided as [top, right, bottom, left] or [top/bottom, left/right] or [top/bottom/left/right] 86 | * `[viewPortOffset]` : offset value from an element or window port. 87 | * `[trigger]`: An Observable ex. BehaviorSubject can be passed to trigger (inview) event. 88 | * `[scrollELement]`: element to check if the content is available in view port with in the element 's view port. default value is window. 89 | * `[data]`: data property can be used to identify the in-view event source, when you have multiple in-view directives in a page attached to same in-view handler. 90 | 91 | * `[lazy]`: default false, set true when you want in-view event to trigger only on visibility of that content. will not trigger when content goes out of view port. 92 | * `[tooLazy]`: default false, set true when you want in-view event to trigger only when visibility state changes. 93 | * `[triggerOnInit]`: default false, set true when you want in-view event to get triggered on element load otherwise it will trigger only on scroll event. 94 | 95 | #### InViewContainer Props 96 | * `(inview)`: inview event, it will keep to emitting the event on scroll. 97 | * `[offset]`: offset value can be provided as [top, right, bottom, left] or [top/bottom, left/right] or [top/bottom/left/right] 98 | * `[viewPortOffset]` : offset value from an element or window port. 99 | * `[scrollWindow]`: default true uses window scroll to check inview status, set false to check from container's scroll. 100 | * `[bestMatch]` : will return only the centered element from other element. Please check example. 101 | * `[triggerOnInit]`: default false, set true when you want in-view event to get triggered on element load otherwise it will trigger only on scroll event. 102 | 103 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-inport-example": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/angular-inport-example", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": true, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "src/styles.css" 28 | ], 29 | "scripts": [] 30 | }, 31 | "configurations": { 32 | "production": { 33 | "fileReplacements": [ 34 | { 35 | "replace": "src/environments/environment.ts", 36 | "with": "src/environments/environment.prod.ts" 37 | } 38 | ], 39 | "optimization": true, 40 | "outputHashing": "all", 41 | "sourceMap": false, 42 | "extractCss": true, 43 | "namedChunks": false, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | }, 53 | { 54 | "type": "anyComponentStyle", 55 | "maximumWarning": "6kb", 56 | "maximumError": "10kb" 57 | } 58 | ] 59 | } 60 | } 61 | }, 62 | "serve": { 63 | "builder": "@angular-devkit/build-angular:dev-server", 64 | "options": { 65 | "browserTarget": "angular-inport-example:build" 66 | }, 67 | "configurations": { 68 | "production": { 69 | "browserTarget": "angular-inport-example:build:production" 70 | } 71 | } 72 | }, 73 | "extract-i18n": { 74 | "builder": "@angular-devkit/build-angular:extract-i18n", 75 | "options": { 76 | "browserTarget": "angular-inport-example:build" 77 | } 78 | }, 79 | "test": { 80 | "builder": "@angular-devkit/build-angular:karma", 81 | "options": { 82 | "main": "src/test.ts", 83 | "polyfills": "src/polyfills.ts", 84 | "tsConfig": "tsconfig.spec.json", 85 | "karmaConfig": "karma.conf.js", 86 | "assets": [ 87 | "src/favicon.ico", 88 | "src/assets" 89 | ], 90 | "styles": [ 91 | "src/styles.css" 92 | ], 93 | "scripts": [] 94 | } 95 | }, 96 | "lint": { 97 | "builder": "@angular-devkit/build-angular:tslint", 98 | "options": { 99 | "tsConfig": [ 100 | "tsconfig.app.json", 101 | "tsconfig.spec.json", 102 | "e2e/tsconfig.json" 103 | ], 104 | "exclude": [ 105 | "**/node_modules/**" 106 | ] 107 | } 108 | }, 109 | "e2e": { 110 | "builder": "@angular-devkit/build-angular:protractor", 111 | "options": { 112 | "protractorConfig": "e2e/protractor.conf.js", 113 | "devServerTarget": "angular-inport-example:serve" 114 | }, 115 | "configurations": { 116 | "production": { 117 | "devServerTarget": "angular-inport-example:serve:production" 118 | } 119 | } 120 | } 121 | } 122 | }, 123 | "angular-inport": { 124 | "projectType": "library", 125 | "root": "projects/angular-inport", 126 | "sourceRoot": "projects/angular-inport/src", 127 | "prefix": "lib", 128 | "architect": { 129 | "build": { 130 | "builder": "@angular-devkit/build-ng-packagr:build", 131 | "options": { 132 | "tsConfig": "projects/angular-inport/tsconfig.lib.json", 133 | "project": "projects/angular-inport/ng-package.json" 134 | }, 135 | "configurations": { 136 | "production": { 137 | "tsConfig": "projects/angular-inport/tsconfig.lib.prod.json" 138 | } 139 | } 140 | }, 141 | "test": { 142 | "builder": "@angular-devkit/build-angular:karma", 143 | "options": { 144 | "main": "projects/angular-inport/src/test.ts", 145 | "tsConfig": "projects/angular-inport/tsconfig.spec.json", 146 | "karmaConfig": "projects/angular-inport/karma.conf.js" 147 | } 148 | }, 149 | "lint": { 150 | "builder": "@angular-devkit/build-angular:tslint", 151 | "options": { 152 | "tsConfig": [ 153 | "projects/angular-inport/tsconfig.lib.json", 154 | "projects/angular-inport/tsconfig.spec.json" 155 | ], 156 | "exclude": [ 157 | "**/node_modules/**" 158 | ] 159 | } 160 | } 161 | } 162 | } 163 | }, 164 | "defaultProject": "angular-inport-example", 165 | "cli": { 166 | "analytics": false 167 | } 168 | } -------------------------------------------------------------------------------- /browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('angular-inport-example app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/angular-inport-example'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-inport", 3 | "version": "3.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~9.0.0-rc.7", 15 | "@angular/common": "~9.0.0-rc.7", 16 | "@angular/compiler": "~9.0.0-rc.7", 17 | "@angular/core": "~9.0.0-rc.7", 18 | "@angular/forms": "~9.0.0-rc.7", 19 | "@angular/platform-browser": "~9.0.0-rc.7", 20 | "@angular/platform-browser-dynamic": "~9.0.0-rc.7", 21 | "@angular/router": "~9.0.0-rc.7", 22 | "rxjs": "~6.5.3", 23 | "tslib": "^1.10.0", 24 | "zone.js": "~0.10.2" 25 | }, 26 | "devDependencies": { 27 | "@angular-devkit/build-angular": "~0.900.0-rc.7", 28 | "@angular-devkit/build-ng-packagr": "~0.900.0-rc.7", 29 | "@angular/cli": "~9.0.0-rc.7", 30 | "@angular/compiler-cli": "~9.0.0-rc.7", 31 | "@angular/language-service": "~9.0.0-rc.7", 32 | "@types/jasmine": "~3.5.0", 33 | "@types/jasminewd2": "~2.0.3", 34 | "@types/node": "^12.11.1", 35 | "codelyzer": "^5.1.2", 36 | "jasmine-core": "~3.5.0", 37 | "jasmine-spec-reporter": "~4.2.1", 38 | "karma": "~4.3.0", 39 | "karma-chrome-launcher": "~3.1.0", 40 | "karma-coverage-istanbul-reporter": "~2.1.0", 41 | "karma-jasmine": "~2.0.1", 42 | "karma-jasmine-html-reporter": "^1.4.2", 43 | "ng-packagr": "^9.0.0-rc.3", 44 | "prettier": "^1.19.1", 45 | "protractor": "~5.4.2", 46 | "ts-node": "~8.3.0", 47 | "tslint": "~5.18.0", 48 | "typescript": "~3.6.4" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /projects/angular-inport/README.md: -------------------------------------------------------------------------------- 1 | # AngularInport 2 | 3 | This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.0.0-rc.7. 4 | 5 | ## Code scaffolding 6 | 7 | Run `ng generate component component-name --project angular-inport` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project angular-inport`. 8 | 9 | > Note: Don't forget to add `--project angular-inport` or else it will be added to the default project in your `angular.json` file. 10 | 11 | ## Build 12 | 13 | Run `ng build angular-inport` to build the project. The build artifacts will be stored in the `dist/` directory. 14 | 15 | ## Publishing 16 | 17 | After building your library with `ng build angular-inport`, go to the dist folder `cd dist/angular-inport` and run `npm publish`. 18 | 19 | ## Running unit tests 20 | 21 | Run `ng test angular-inport` to execute the unit tests via [Karma](https://karma-runner.github.io). 22 | 23 | ## Further help 24 | 25 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 26 | -------------------------------------------------------------------------------- /projects/angular-inport/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function(config) { 5 | config.set({ 6 | basePath: "", 7 | frameworks: ["jasmine", "@angular-devkit/build-angular"], 8 | plugins: [ 9 | require("karma-jasmine"), 10 | require("karma-chrome-launcher"), 11 | require("karma-jasmine-html-reporter"), 12 | require("karma-coverage-istanbul-reporter"), 13 | require("@angular-devkit/build-angular/plugins/karma") 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require("path").join(__dirname, "../../coverage/angular-inport"), 20 | reports: ["html", "lcovonly", "text-summary"], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ["progress", "kjhtml"], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ["Chrome"], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /projects/angular-inport/ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", 3 | "dest": "../../dist/angular-inport", 4 | "lib": { 5 | "entryFile": "src/public-api.ts" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /projects/angular-inport/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-inport", 3 | "version": "0.0.1", 4 | "peerDependencies": { 5 | "@angular/common": "^9.0.0-rc.7", 6 | "@angular/core": "^9.0.0-rc.7", 7 | "tslib": "^1.10.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./inview.module"; 2 | export * from "./inview.directive"; 3 | export * from "./inview-container.directive"; 4 | export * from "./inview-item.directive"; 5 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/inview-container.directive.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Directive, 3 | ContentChildren, 4 | QueryList, 5 | OnInit, 6 | OnDestroy, 7 | AfterViewInit, 8 | Input, 9 | Output, 10 | EventEmitter, 11 | ElementRef, 12 | NgZone 13 | } from "@angular/core"; 14 | import { 15 | Observable, 16 | Subject, 17 | Subscription, 18 | merge, 19 | timer, 20 | of as _of 21 | } from "rxjs"; 22 | 23 | import { InviewItemDirective } from "./inview-item.directive"; 24 | import { ScrollObservable } from "./utils/scroll-observable"; 25 | import { WindowRuler } from "./utils/viewport-ruler"; 26 | import { OffsetResolverFactory } from "./utils/offset-resolver"; 27 | import { PositionResolver } from "./utils/position-resolver"; 28 | import { ElementBoundingPositions } from "./utils/models"; 29 | import { filter, mergeMap, tap, debounce } from "rxjs/operators"; 30 | 31 | // allmost same configuration as child 32 | // child will not have inview property? to trigger changes 33 | // will use scroll on this or window 34 | // will check wheather the child is in view port 35 | // will start checking from last inview child and with direction of scroll until a child is not visible 36 | // can return all inview children 37 | // or best match case 38 | // if container is used then first check if container itself is in the viewport of the window. 39 | // then only the futher calculation should take place 40 | 41 | @Directive({ 42 | selector: "[in-view-container]" 43 | }) 44 | export class InviewContainerDirective 45 | implements OnInit, OnDestroy, AfterViewInit { 46 | private _scrollSuscription: Subscription; 47 | private _throttleType: string = "debounce"; 48 | private _offset: Array = [0, 0, 0, 0]; 49 | private _viewPortOffset: Array = [0, 0, 0, 0]; 50 | private _throttle: number = 0; 51 | private _scrollWindow: boolean = true; 52 | private _data: any; 53 | private _bestMatch: boolean; 54 | private _lastScrollY: number = 0; 55 | private _scrollDirection: string = "down"; 56 | private _triggerOnInit: boolean; 57 | 58 | @Input() trigger: Subject; 59 | @Input() 60 | set offset(offset: Array | number | string) { 61 | this._offset = OffsetResolverFactory.create(offset).normalizeOffset(); 62 | } 63 | @Input() 64 | set triggerOnInit(triggerOnInit: boolean) { 65 | this._triggerOnInit = !!triggerOnInit; 66 | } 67 | @Input() 68 | set viewPortOffset(offset: Array | number | string) { 69 | this._viewPortOffset = OffsetResolverFactory.create( 70 | offset 71 | ).normalizeOffset(); 72 | } 73 | @Input() 74 | set throttle(throttle: number) { 75 | this._throttle = throttle; 76 | } 77 | @Input() 78 | set scrollWindow(sw: boolean) { 79 | this._scrollWindow = !!sw; 80 | } 81 | @Input() 82 | set data(_d: any) { 83 | this._data = _d; 84 | } 85 | @Input() 86 | set bestMatch(bm: any) { 87 | this._bestMatch = !!bm; 88 | } 89 | 90 | @Output() inview: EventEmitter = new EventEmitter(); 91 | @ContentChildren(InviewItemDirective) 92 | private _inviewChildren: QueryList; 93 | 94 | constructor( 95 | private _element: ElementRef, 96 | private _scrollObservable: ScrollObservable, 97 | private _windowRuler: WindowRuler, 98 | private _zone: NgZone 99 | ) {} 100 | 101 | ngOnInit() {} 102 | ngAfterViewInit() { 103 | this._scrollSuscription = this._scrollObservable 104 | .scrollObservableFor( 105 | this._scrollWindow ? window : this._element.nativeElement 106 | ) 107 | .pipe( 108 | debounce(() => timer(this._throttle)), 109 | filter(() => true), 110 | mergeMap((event: any) => _of(this._getViewPortRuler())), 111 | tap(() => this._checkScrollDirection()) 112 | ) 113 | .subscribe((containersBounds: ElementBoundingPositions) => 114 | this.handleOnScroll(containersBounds) 115 | ); 116 | if (this._triggerOnInit) 117 | return this.handleOnScroll(this._getViewPortRuler()); 118 | } 119 | 120 | private _checkScrollDirection() { 121 | if (this._scrollWindow) { 122 | this._scrollDirection = 123 | window.scrollY > this._lastScrollY ? "down" : "up"; 124 | this._lastScrollY = window.scrollY; 125 | } else { 126 | this._scrollDirection = 127 | this._element.nativeElement.scrollTop > this._lastScrollY 128 | ? "down" 129 | : "up"; 130 | this._lastScrollY = this._element.nativeElement.scrollTop; 131 | } 132 | } 133 | 134 | private _getViewPortRuler() { 135 | return this._scrollWindow 136 | ? this._windowRuler.getWindowViewPortRuler() 137 | : PositionResolver.getBoundingClientRect(this._element.nativeElement); 138 | } 139 | ngOnDestroy() { 140 | if (this._scrollSuscription) { 141 | this._scrollSuscription.unsubscribe(); 142 | } 143 | } 144 | 145 | handleOnScroll(containersBounds: ElementBoundingPositions) { 146 | // check of scroll up or down 147 | // Note:: check all children from parent if it is in view or not 148 | // for cache of less iterations start from the last visible item then based on scroll up and down check list futher 149 | const viewPortOffsetRect = PositionResolver.offsetRect( 150 | containersBounds, 151 | this._viewPortOffset 152 | ); 153 | let visibleChildren: Array = []; 154 | if (this._inviewChildren) { 155 | visibleChildren = this._inviewChildren 156 | .toArray() 157 | .filter((child: InviewItemDirective) => { 158 | const elementOffsetRect = PositionResolver.offsetRect( 159 | child.getELementRect(), 160 | this._offset 161 | ); 162 | return ( 163 | child.isVisible() && 164 | PositionResolver.intersectRect( 165 | elementOffsetRect, 166 | viewPortOffsetRect 167 | ) 168 | ); 169 | }); 170 | if (this._bestMatch) { 171 | let bestMatchChild: InviewItemDirective | any = 0; 172 | if (visibleChildren.length) { 173 | visibleChildren.reduce( 174 | (distance: number, currChild: InviewItemDirective) => { 175 | const _distance = PositionResolver.distance( 176 | viewPortOffsetRect, 177 | PositionResolver.offsetRect( 178 | currChild.getELementRect(), 179 | this._offset 180 | ) 181 | ); 182 | if (distance > _distance) { 183 | bestMatchChild = currChild; 184 | return _distance; 185 | } 186 | return distance; 187 | }, 188 | Infinity 189 | ); 190 | } 191 | const data: any = bestMatchChild ? bestMatchChild.getData() : {}; 192 | data.direction = this._scrollDirection; 193 | this._zone.run(() => this.inview.emit(data)); 194 | } else { 195 | const data: any = {}; 196 | data.inview = visibleChildren.map((vc: InviewItemDirective) => 197 | vc.getData() 198 | ); 199 | data.direction = this._scrollDirection; 200 | this._zone.run(() => this.inview.emit(data)); 201 | } 202 | } 203 | } 204 | } 205 | 206 | // inview-container -> inview-item -> 207 | 208 | // scrollWindow = true -> will test it against the window scroll event with container. 209 | // scrollWindow = false -> means we need to attach scroll event on this container. 210 | 211 | // inview -> directly used against the window. 212 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/inview-item.directive.ts: -------------------------------------------------------------------------------- 1 | import { Directive, OnInit, ElementRef, Input } from "@angular/core"; 2 | import { PositionResolver } from "./utils/position-resolver"; 3 | @Directive({ 4 | selector: "[in-view-item]" 5 | }) 6 | export class InviewItemDirective implements OnInit { 7 | private _data: any; 8 | private _id: any; 9 | @Input() 10 | set data(d: any) { 11 | this._data = d; 12 | } 13 | @Input() 14 | set id(_id: any) { 15 | this._id = _id; 16 | } 17 | constructor(private _element: ElementRef) {} 18 | ngOnInit() {} 19 | 20 | // expose a function returning rect of this _element 21 | getELementRect(): ClientRect { 22 | return PositionResolver.getBoundingClientRect(this._element.nativeElement); 23 | } 24 | isVisible(): boolean { 25 | return PositionResolver.isVisible(this._element.nativeElement); 26 | } 27 | getData(): any { 28 | return { id: this._id, data: this._data }; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/inview.directive.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Directive, 3 | Input, 4 | Output, 5 | OnInit, 6 | OnDestroy, 7 | EventEmitter, 8 | ElementRef, 9 | NgZone, 10 | AfterViewInit 11 | } from "@angular/core"; 12 | import { 13 | Observable, 14 | Subject, 15 | Subscription, 16 | merge, 17 | timer, 18 | of as _of 19 | } from "rxjs"; 20 | import { ScrollObservable } from "./utils/scroll-observable"; 21 | import { OffsetResolverFactory } from "./utils/offset-resolver"; 22 | import { PositionResolver } from "./utils/position-resolver"; 23 | import { ElementBoundingPositions } from "./utils/models"; 24 | import { WindowRuler } from "./utils/viewport-ruler"; 25 | import { debounce, filter, mergeMap } from "rxjs/operators"; 26 | @Directive({ 27 | selector: "[in-view]" 28 | }) 29 | export class InviewDirective implements OnInit, OnDestroy, AfterViewInit { 30 | private _throttleType: string = "debounce"; 31 | private _offset: Array = [0, 0, 0, 0]; 32 | private _viewPortOffset: Array = [0, 0, 0, 0]; 33 | private _throttle: number = 0; 34 | private _scrollElement: HTMLElement; 35 | private _lazy: boolean = false; // when visible only then. 36 | private _tooLazy: boolean = false; // when state changes only then. 37 | private _previous_state: boolean; 38 | private _data: any; 39 | private _triggerOnInit: boolean = false; 40 | 41 | @Input() trigger: Subject; 42 | 43 | @Input() 44 | set triggerOnInit(triggerOnInit: boolean) { 45 | this._triggerOnInit = !!triggerOnInit; 46 | } 47 | @Input() 48 | set offset(offset: Array | number | string) { 49 | this._offset = OffsetResolverFactory.create(offset).normalizeOffset(); 50 | } 51 | @Input() 52 | set viewPortOffset(offset: Array | number | string) { 53 | this._viewPortOffset = OffsetResolverFactory.create( 54 | offset 55 | ).normalizeOffset(); 56 | } 57 | @Input() 58 | set throttle(throttle: number) { 59 | this._throttle = throttle; 60 | } 61 | @Input() 62 | set scrollELement(sw: HTMLElement) { 63 | this._scrollElement = sw; 64 | } 65 | @Input() 66 | set lazy(lzy: boolean) { 67 | this._lazy = lzy; 68 | } 69 | @Input() 70 | set tooLazy(lzy: boolean) { 71 | this._tooLazy = lzy; 72 | } 73 | @Input() 74 | set data(_d: any) { 75 | this._data = _d; 76 | } 77 | @Output() private inview: EventEmitter = new EventEmitter(); 78 | private _scrollerSubscription: Subscription; 79 | 80 | constructor( 81 | private _scrollObservable: ScrollObservable, 82 | private _element: ElementRef, 83 | private _zone: NgZone, 84 | private _windowRuler: WindowRuler 85 | ) {} 86 | 87 | ngAfterViewInit() { 88 | this._scrollerSubscription = this._scrollObservable 89 | .scrollObservableFor(this._scrollElement || window) 90 | .pipe( 91 | debounce(() => timer(this._throttle)), 92 | filter(() => true), 93 | mergeMap((event: any) => _of(this._getViewPortRuler())) 94 | ) 95 | .subscribe((containersBounds: ElementBoundingPositions) => 96 | this.handleOnScroll(containersBounds) 97 | ); 98 | if (this._triggerOnInit) 99 | return this.handleOnScroll(this._getViewPortRuler()); 100 | } 101 | 102 | private _getViewPortRuler() { 103 | return this._scrollElement 104 | ? PositionResolver.getBoundingClientRect(this._scrollElement) 105 | : this._windowRuler.getWindowViewPortRuler(); 106 | } 107 | 108 | ngOnInit() {} 109 | 110 | ngOnDestroy() { 111 | if (this._scrollerSubscription) { 112 | this._scrollerSubscription.unsubscribe(); 113 | } 114 | } 115 | 116 | handleOnScroll(containersBounds: ElementBoundingPositions) { 117 | const viewPortOffsetRect = PositionResolver.offsetRect( 118 | containersBounds, 119 | this._viewPortOffset 120 | ); 121 | const elementOffsetRect = PositionResolver.offsetRect( 122 | PositionResolver.getBoundingClientRect(this._element.nativeElement), 123 | this._offset 124 | ); 125 | const isVisible = 126 | PositionResolver.isVisible(this._element.nativeElement) && 127 | PositionResolver.intersectRect(elementOffsetRect, viewPortOffsetRect); 128 | 129 | if ( 130 | this._tooLazy && 131 | this._previous_state !== undefined && 132 | this._previous_state === isVisible 133 | ) { 134 | return; 135 | } 136 | 137 | const output: any = { status: isVisible }; 138 | 139 | if (this._data !== undefined) { 140 | output.data = this._data; 141 | } 142 | 143 | if (!this._lazy && !isVisible) { 144 | output.isClipped = false; 145 | output.isOutsideView = true; 146 | output.parts = { top: false, right: false, left: false, bottom: false }; 147 | output.inViewPercentage = { vertical: 0, horizontal: 0 }; 148 | this._zone.run(() => this.inview.emit(output)); 149 | } 150 | 151 | if (!isVisible) { 152 | this._previous_state = isVisible; 153 | return; 154 | } 155 | 156 | const { isClipped, isOutsideView } = PositionResolver.clippedStatus( 157 | elementOffsetRect, 158 | viewPortOffsetRect 159 | ); 160 | output.isClipped = isClipped; 161 | output.isOutsideView = isOutsideView; 162 | output.parts = PositionResolver.inViewParts( 163 | viewPortOffsetRect, 164 | elementOffsetRect 165 | ); 166 | output.inViewPercentage = PositionResolver.inViewPercentage( 167 | viewPortOffsetRect, 168 | elementOffsetRect 169 | ); 170 | this._zone.run(() => this.inview.emit(output)); 171 | this._previous_state = isVisible; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/inview.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from "@angular/core"; 2 | import { InviewDirective } from "./inview.directive"; 3 | import { InviewContainerDirective } from "./inview-container.directive"; 4 | import { InviewItemDirective } from "./inview-item.directive"; 5 | import { ScrollObservable } from "./utils/scroll-observable"; 6 | import { WindowRuler } from "./utils/viewport-ruler"; 7 | @NgModule({ 8 | imports: [], 9 | declarations: [ 10 | InviewDirective, 11 | InviewContainerDirective, 12 | InviewItemDirective 13 | ], 14 | exports: [InviewDirective, InviewContainerDirective, InviewItemDirective], 15 | providers: [ScrollObservable, WindowRuler] 16 | }) 17 | export class NgInviewModule {} 18 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/utils/models.ts: -------------------------------------------------------------------------------- 1 | export interface ElementBoundingPositions { 2 | top: number; 3 | right: number; 4 | bottom: number; 5 | left: number; 6 | } 7 | 8 | export type WindowElement = HTMLElement | Window; 9 | 10 | export interface Point { 11 | x: number; 12 | y: number; 13 | } 14 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/utils/offset-resolver.ts: -------------------------------------------------------------------------------- 1 | export class OffsetResolver { 2 | constructor(private offset: Array | number | string) {} 3 | 4 | normalizeOffset() { 5 | if (!Array.isArray(this.offset)) { 6 | return [this.offset, this.offset, this.offset, this.offset]; 7 | } 8 | if (this.offset.length === 2) { 9 | return this.offset.concat(this.offset); 10 | } else if (this.offset.length === 3) { 11 | return this.offset.concat([this.offset[1]]); 12 | } 13 | return this.offset; 14 | } 15 | } 16 | 17 | export class OffsetResolverFactory { 18 | static create(offset: Array | number | string) { 19 | return new OffsetResolver(offset); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/utils/position-resolver.ts: -------------------------------------------------------------------------------- 1 | import { ElementBoundingPositions, Point } from "./models"; 2 | function isPercent(value: any): boolean { 3 | return typeof value === "string" && value.indexOf("%") > -1; 4 | } 5 | function distance(p1: Point, p2: Point) { 6 | return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); 7 | } 8 | export class PositionResolver { 9 | static getBoundingClientRect(element: HTMLElement): ClientRect { 10 | return element.getBoundingClientRect(); 11 | } 12 | 13 | static isVisible(element: HTMLElement): boolean { 14 | return !!( 15 | element.offsetWidth || 16 | element.offsetHeight || 17 | element.getClientRects().length 18 | ); 19 | } 20 | 21 | static intersectRect(r1: any, r2: any): boolean { 22 | return !( 23 | r2.left > r1.right || 24 | r2.right < r1.left || 25 | r2.top > r1.bottom || 26 | r2.bottom < r1.top 27 | ); 28 | } 29 | 30 | static offsetRect(rect: any, offset: Array): ClientRect { 31 | if (!offset) { 32 | return rect; 33 | } 34 | const offsetObject: any = { 35 | top: isPercent(offset[0]) 36 | ? (parseFloat(offset[0]) * rect.height) / 100 37 | : +offset[0], 38 | right: isPercent(offset[1]) 39 | ? (parseFloat(offset[1]) * rect.width) / 100 40 | : +offset[1], 41 | bottom: isPercent(offset[2]) 42 | ? (parseFloat(offset[2]) * rect.height) / 100 43 | : +offset[2], 44 | left: isPercent(offset[3]) 45 | ? (parseFloat(offset[3]) * rect.width) / 100 46 | : +offset[3] 47 | }; 48 | return { 49 | top: rect.top - offsetObject.top, 50 | left: rect.left - offsetObject.left, 51 | bottom: rect.bottom + offsetObject.bottom, 52 | right: rect.right + offsetObject.right, 53 | height: rect.height + offsetObject.top + offsetObject.bottom, 54 | width: rect.width + offsetObject.left + offsetObject.right 55 | }; 56 | } 57 | 58 | static distance(containerRect: any, elementRect: any) { 59 | const middlePointOfContainer: Point = { 60 | x: containerRect.height / 2, 61 | y: containerRect.width / 2 62 | }; 63 | const middlePointOfElement: Point = { 64 | x: elementRect.top + elementRect.height / 2, 65 | y: elementRect.left + elementRect.width / 2 66 | }; 67 | return distance(middlePointOfContainer, middlePointOfElement); 68 | } 69 | 70 | static inviewPercentage(containerRect: any, elementRect: any) { 71 | return { 72 | top: (100 * elementRect.top) / containerRect.top, 73 | left: (100 * elementRect.left) / containerRect.left, 74 | bottom: (100 * elementRect.bottom) / containerRect.bottom, 75 | right: (100 * elementRect.right) / containerRect.right 76 | }; 77 | } 78 | 79 | static inViewParts(containerRect: any, elementRect: any) { 80 | return { 81 | top: elementRect.top >= containerRect.top, 82 | left: elementRect.left >= containerRect.left, 83 | bottom: elementRect.bottom <= containerRect.bottom, 84 | right: elementRect.right <= containerRect.right 85 | }; 86 | } 87 | 88 | static inViewPercentage(containerRect: any, elementRect: any) { 89 | const elementHeight = elementRect.bottom - elementRect.top; 90 | const containerHeight = containerRect.bottom - containerRect.top; 91 | 92 | const elementWidth = elementRect.right - elementRect.left; 93 | const containerWidth = containerRect.right - containerRect.left; 94 | 95 | const diffAbove = containerHeight - (elementRect.top - containerRect.top); 96 | const diffBelow = 97 | containerHeight - (containerRect.bottom - elementRect.bottom); 98 | const diffLeft = containerWidth - (elementRect.left - containerRect.left); 99 | const diffRight = 100 | containerWidth - (containerRect.right - elementRect.right); 101 | 102 | const verticalAbove = (diffAbove * 100) / elementHeight; 103 | const verticalBelow = (diffBelow * 100) / elementHeight; 104 | 105 | const horizontalLeft = (diffLeft * 100) / elementWidth; 106 | const horizontalRight = (diffRight * 100) / elementWidth; 107 | 108 | return { 109 | vertical: Math.min(100, verticalAbove, verticalBelow), 110 | horizontal: Math.min(100, horizontalLeft, horizontalRight) 111 | }; 112 | } 113 | 114 | static isElementOutsideView( 115 | elementBounds: ElementBoundingPositions, 116 | containersBounds: ElementBoundingPositions 117 | ): boolean { 118 | const outsideAbove = elementBounds.bottom < containersBounds.top; 119 | const outsideBelow = elementBounds.top > containersBounds.bottom; 120 | const outsideLeft = elementBounds.right < containersBounds.left; 121 | const outsideRight = elementBounds.left > containersBounds.right; 122 | return outsideAbove || outsideBelow || outsideLeft || outsideRight; 123 | } 124 | 125 | static isElementClipped( 126 | elementBounds: ElementBoundingPositions, 127 | containersBounds: ElementBoundingPositions 128 | ): boolean { 129 | const clippedAbove = elementBounds.top < containersBounds.top; 130 | const clippedBelow = elementBounds.bottom > containersBounds.bottom; 131 | const clippedLeft = elementBounds.left < containersBounds.left; 132 | const clippedRight = elementBounds.right > containersBounds.right; 133 | 134 | return clippedAbove || clippedBelow || clippedLeft || clippedRight; 135 | } 136 | static clippedStatus( 137 | elementBounds: ElementBoundingPositions, 138 | containersBounds: ElementBoundingPositions 139 | ) { 140 | return { 141 | isClipped: this.isElementClipped(elementBounds, containersBounds), 142 | isOutsideView: this.isElementOutsideView(elementBounds, containersBounds) 143 | }; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/utils/scroll-observable.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | import { Observable, merge, fromEvent } from "rxjs"; 3 | import { map, share, tap } from "rxjs/operators"; 4 | import { WindowRuler } from "./viewport-ruler"; 5 | import { WindowElement } from "./models"; 6 | 7 | @Injectable() 8 | export class ScrollObservable { 9 | static _globalObservable: Observable; 10 | static _elementObservableReferences: Map< 11 | WindowElement, 12 | Observable 13 | > = new Map(); 14 | static isWindow(windowElement: WindowElement) { 15 | return Object.prototype.toString.call(windowElement).includes("Window"); 16 | } 17 | constructor(private _windowRuler: WindowRuler) { 18 | if (!ScrollObservable._globalObservable) { 19 | ScrollObservable._globalObservable = this._getGlobalObservable(); 20 | } 21 | } 22 | private _getGlobalObservable(): Observable { 23 | return merge( 24 | fromEvent(window.document, "scroll"), 25 | fromEvent(window, "resize") 26 | ).pipe( 27 | tap((event: any) => this._windowRuler.onChange()), 28 | share() 29 | ); 30 | 31 | /* 32 | return Observable.merge( 33 | Observable.fromEvent(window.document, 'scroll'), 34 | Observable.fromEvent(window, 'resize') 35 | .map((event: any) => { 36 | this._windowRuler.onChange(); 37 | return event; 38 | }) 39 | ).share(); 40 | */ 41 | } 42 | scrollObservableFor(windowElement: WindowElement): Observable { 43 | if (ScrollObservable.isWindow(windowElement)) { 44 | return ScrollObservable._globalObservable; 45 | } 46 | if (ScrollObservable._elementObservableReferences.has(windowElement)) { 47 | return >( 48 | ScrollObservable._elementObservableReferences.get(windowElement) 49 | ); 50 | } 51 | const ref = this._createElementObservable(windowElement); 52 | ScrollObservable._elementObservableReferences.set(windowElement, ref); 53 | return ref; 54 | } 55 | private _createElementObservable( 56 | windowElement: WindowElement 57 | ): Observable { 58 | return fromEvent(windowElement, "scroll").pipe(share()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /projects/angular-inport/src/lib/utils/viewport-ruler.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | 3 | export class WindowRulerStatic { 4 | private static _windowRect: ClientRect; 5 | private static _createWindowRect() { 6 | const height = window.innerHeight; 7 | const width = window.innerWidth; 8 | return { 9 | top: 0, 10 | left: 0, 11 | bottom: height, 12 | right: width, 13 | height, 14 | width 15 | }; 16 | } 17 | static onChange() { 18 | this._windowRect = this._createWindowRect(); 19 | } 20 | static getWindowViewPortRuler() { 21 | return this._windowRect; 22 | } 23 | } 24 | 25 | @Injectable() 26 | export class WindowRuler { 27 | constructor() { 28 | WindowRulerStatic.onChange(); 29 | } 30 | onChange() { 31 | WindowRulerStatic.onChange(); 32 | } 33 | getWindowViewPortRuler() { 34 | return WindowRulerStatic.getWindowViewPortRuler(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /projects/angular-inport/src/public-api.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Public API Surface of angular-inport 3 | */ 4 | 5 | export * from "./lib"; 6 | -------------------------------------------------------------------------------- /projects/angular-inport/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import "zone.js/dist/zone"; 4 | import "zone.js/dist/zone-testing"; 5 | import { getTestBed } from "@angular/core/testing"; 6 | import { 7 | BrowserDynamicTestingModule, 8 | platformBrowserDynamicTesting 9 | } from "@angular/platform-browser-dynamic/testing"; 10 | 11 | declare const require: any; 12 | 13 | // First, initialize the Angular testing environment. 14 | getTestBed().initTestEnvironment( 15 | BrowserDynamicTestingModule, 16 | platformBrowserDynamicTesting() 17 | ); 18 | // Then we find all the tests. 19 | const context = require.context("./", true, /\.spec\.ts$/); 20 | // And load the modules. 21 | context.keys().map(context); 22 | -------------------------------------------------------------------------------- /projects/angular-inport/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/lib", 5 | "target": "es2015", 6 | "declaration": true, 7 | "inlineSources": true, 8 | "types": [], 9 | "lib": ["dom", "es2018"] 10 | }, 11 | "angularCompilerOptions": { 12 | "skipTemplateCodegen": true, 13 | "strictMetadataEmit": true, 14 | "enableResourceInlining": true 15 | }, 16 | "exclude": ["src/test.ts", "**/*.spec.ts"] 17 | } 18 | -------------------------------------------------------------------------------- /projects/angular-inport/tsconfig.lib.prod.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.lib.json", 3 | "angularCompilerOptions": { 4 | "enableIvy": false 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /projects/angular-inport/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/spec", 5 | "types": ["jasmine", "node"] 6 | }, 7 | "files": ["src/test.ts"], 8 | "include": ["**/*.spec.ts", "**/*.d.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /projects/angular-inport/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tslint.json", 3 | "rules": { 4 | "directive-selector": [true, "attribute", "lib", "camelCase"], 5 | "component-selector": [true, "element", "lib", "kebab-case"] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | #menu { 2 | position: fixed; 3 | left: 0px; 4 | top: 0px; 5 | z-index: 1; 6 | background: #ccc; 7 | width: 25%; 8 | height: 100%; 9 | opacity: 0.7; 10 | box-shadow: 5px 0px 10px 0px rgba(0, 0, 0, 1); 11 | overflow-y: auto; 12 | } 13 | 14 | #menu-content { 15 | padding: 10px; 16 | } 17 | 18 | #container { 19 | position: relative; 20 | left: 25%; 21 | width: 100%; 22 | margin: 0px; 23 | } 24 | 25 | #container-content { 26 | padding-top: 110%; 27 | padding-bottom: 110%; 28 | padding-left: 110%; 29 | padding-right: 110%; 30 | width: 100%; 31 | } 32 | 33 | .box { 34 | height: 150px; 35 | width: 70%; 36 | margin-left: 15%; 37 | border: 5px solid; 38 | position: relative; 39 | text-align: center; 40 | font-size: 50px; 41 | line-height: 150px; 42 | margin-bottom: 10px; 43 | } 44 | 45 | .separator { 46 | height: 300px; 47 | } 48 | 49 | .boxes { 50 | width: 70%; 51 | margin-left: 15%; 52 | border: 5px solid red; 53 | height: 500px; 54 | overflow: auto; 55 | } 56 | 57 | .boxes-content { 58 | padding-top: 110%; 59 | padding-bottom: 110%; 60 | padding-left: 110%; 61 | padding-right: 110%; 62 | width: 100%; 63 | } 64 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 25 | 26 |
27 |
28 |
35 | Individual 36 |
37 | 38 |
39 | 40 |
46 |
53 | {{ item.name }} 54 |
55 |
56 | 57 |
58 | 59 |
60 |
61 |
68 | Individual Wrapped 69 |
70 |
71 |
72 | 73 |
74 | 75 |
82 |
83 |
90 | {{ item.name }} 91 |
92 |
93 |
94 | 95 |
96 | 97 |
105 |
106 |
113 | {{ item.name }} 114 |
115 |
116 |
117 |
118 |
119 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from "@angular/core/testing"; 2 | 3 | import { AppComponent } from "./app.component"; 4 | 5 | describe("AppComponent", () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | declarations: [AppComponent] 9 | }).compileComponents(); 10 | })); 11 | 12 | it("should create the app", async(() => { 13 | const fixture = TestBed.createComponent(AppComponent); 14 | const app = fixture.debugElement.componentInstance; 15 | expect(app).toBeTruthy(); 16 | })); 17 | 18 | it(`should have as title 'app'`, async(() => { 19 | const fixture = TestBed.createComponent(AppComponent); 20 | const app = fixture.debugElement.componentInstance; 21 | expect(app.title).toEqual("app"); 22 | })); 23 | 24 | it("should render title in a h1 tag", async(() => { 25 | const fixture = TestBed.createComponent(AppComponent); 26 | fixture.detectChanges(); 27 | const compiled = fixture.debugElement.nativeElement; 28 | expect(compiled.querySelector("h1").textContent).toContain( 29 | "Welcome to app!" 30 | ); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, ViewChild, OnInit } from "@angular/core"; 2 | import { BehaviorSubject } from "rxjs"; 3 | 4 | @Component({ 5 | selector: "app-root", 6 | templateUrl: "./app.component.html", 7 | styleUrls: ["./app.component.css"] 8 | }) 9 | export class AppComponent implements OnInit { 10 | @ViewChild("individualwrapped", { static: true }) individualwrapped: any; 11 | 12 | trigger: any = new BehaviorSubject(0); 13 | stateIndividual: any = {}; 14 | stateContainer: any = {}; 15 | stateIndividualWrapped: any = {}; 16 | elementIndividualWrapped = ""; 17 | stateContainerWrapped: any = {}; 18 | stateContainerBestWrapped: any = {}; 19 | items = []; 20 | ready = false; 21 | 22 | constructor() { 23 | for (let i = 0; i < 10; i++) { 24 | this.items.push({ 25 | name: "Item " + i 26 | }); 27 | } 28 | } 29 | 30 | ngOnInit() { 31 | this.elementIndividualWrapped = this.individualwrapped.nativeElement; 32 | setTimeout(() => (this.ready = true)); 33 | } 34 | 35 | inViewIndividualWrapped($event) { 36 | this.stateIndividualWrapped = $event; 37 | } 38 | 39 | inViewIndividual($event) { 40 | this.stateIndividual = $event; 41 | } 42 | 43 | inViewContainer($event) { 44 | this.stateContainer = $event; 45 | } 46 | 47 | inViewContainerWrapped($event) { 48 | this.stateContainerWrapped = $event; 49 | } 50 | 51 | inViewContainerBestWrapped($event) { 52 | this.stateContainerBestWrapped = $event; 53 | } 54 | 55 | triggerCustom() { 56 | this.trigger.next(0); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from "@angular/platform-browser"; 2 | import { NgModule } from "@angular/core"; 3 | import { NgInviewModule } from "angular-inport"; 4 | import { AppComponent } from "./app.component"; 5 | import { JsonBeautyPipe } from "./app.pipes"; 6 | 7 | @NgModule({ 8 | declarations: [AppComponent, JsonBeautyPipe], 9 | imports: [BrowserModule, NgInviewModule], 10 | providers: [], 11 | bootstrap: [AppComponent] 12 | }) 13 | export class AppModule {} 14 | -------------------------------------------------------------------------------- /src/app/app.pipes.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from "@angular/core"; 2 | 3 | @Pipe({ 4 | name: "jsonbeauty" 5 | }) 6 | export class JsonBeautyPipe implements PipeTransform { 7 | transform(json: string): string { 8 | json = JSON.stringify(json, undefined, 4); 9 | json = json 10 | .replace(/&/g, "&") 11 | .replace(//g, ">"); 13 | return json.replace( 14 | /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, 15 | function(match) { 16 | let cls = "number"; 17 | if (/^"/.test(match)) { 18 | if (/:$/.test(match)) { 19 | cls = "key"; 20 | } else { 21 | cls = "string"; 22 | } 23 | } else if (/true|false/.test(match)) { 24 | cls = "boolean"; 25 | } else if (/null/.test(match)) { 26 | cls = "null"; 27 | } 28 | return '' + match + ""; 29 | } 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ajaysinghj8/angular-inport/60eb58ed7bf7a71180809409fab06cb7213f457e/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ajaysinghj8/angular-inport/60eb58ed7bf7a71180809409fab06cb7213f457e/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularInportExample 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from "@angular/core"; 2 | import { platformBrowserDynamic } from "@angular/platform-browser-dynamic"; 3 | 4 | import { AppModule } from "./app/app.module"; 5 | import { environment } from "./environments/environment"; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic() 12 | .bootstrapModule(AppModule) 13 | .catch(err => console.error(err)); 14 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import "zone.js/dist/zone"; // Included with Angular CLI. 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import "zone.js/dist/zone-testing"; 4 | import { getTestBed } from "@angular/core/testing"; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from "@angular/platform-browser-dynamic/testing"; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context("./", true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [], 6 | "paths": { 7 | "angular-inport/*": ["projects/angular-inport/src/lib/*"], 8 | "angular-inport": ["projects/angular-inport/src/lib"] 9 | } 10 | }, 11 | "files": [ 12 | "src/main.ts", 13 | "src/polyfills.ts" 14 | ], 15 | "include": [ 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ], 21 | "paths": { 22 | "angular-inport": [ 23 | "dist/angular-inport" 24 | ] 25 | } 26 | }, 27 | "angularCompilerOptions": { 28 | "fullTemplateTypeCheck": true, 29 | "strictInjectionParameters": true 30 | } 31 | } -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warning" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "app", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "app", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-var-requires": false, 64 | "object-literal-key-quotes": [ 65 | true, 66 | "as-needed" 67 | ], 68 | "object-literal-sort-keys": false, 69 | "ordered-imports": false, 70 | "quotemark": [ 71 | true, 72 | "single" 73 | ], 74 | "trailing-comma": false, 75 | "no-conflicting-lifecycle": true, 76 | "no-host-metadata-property": true, 77 | "no-input-rename": true, 78 | "no-inputs-metadata-property": true, 79 | "no-output-native": true, 80 | "no-output-on-prefix": true, 81 | "no-output-rename": true, 82 | "no-outputs-metadata-property": true, 83 | "template-banana-in-box": true, 84 | "template-no-negated-async": true, 85 | "use-lifecycle-interface": true, 86 | "use-pipe-transform-interface": true 87 | }, 88 | "rulesDirectory": [ 89 | "codelyzer" 90 | ] 91 | } --------------------------------------------------------------------------------