[
  {
    "path": ".editorconfig",
    "content": "# EditorConfig helps developers define and maintain consistent\n# coding styles between different editors and IDEs\n# editorconfig.org\n\nroot = true\n\n[*]\n\n# Change these settings to your own preference\nindent_style = space\nindent_size = 2\n\n# We recommend you to keep these unchanged\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n\n[*.md]\ntrim_trailing_whitespace = false\n"
  },
  {
    "path": ".gitignore",
    "content": "# Node\nnode_modules\n\n## OS X\n.DS_Store\n.AppleDouble\n.LSOverride\nIcon\n._*\n.Spotlight-V100\n.Trashes\n\n## Windows\nThumbs.db\nehthumbs.db\nDesktop.ini\n$RECYCLE.BIN/\n"
  },
  {
    "path": ".jshintrc",
    "content": "{\n  \"node\": true,\n  \"browser\": true,\n  \"esnext\": true,\n  \"bitwise\": true,\n  \"camelcase\": true,\n  \"curly\": false,\n  \"eqeqeq\": true,\n  \"indent\": 2,\n  \"loopfunc\": true,\n  \"immed\": true,\n  \"latedef\": true,\n  \"newcap\": true,\n  \"noarg\": true,\n  \"quotmark\": \"single\",\n  \"regexp\": true,\n  \"undef\": true,\n  \"unused\": false,\n  \"trailing\": false,\n  \"sub\": true,\n  \"globals\": {\n    \"angular\": true\n  }\n}\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\nnode_js:\n  - \"0.10\"\n  - \"0.11\"\nbefore_script:\n  - npm install -g gulp\nscript: gulp\n"
  },
  {
    "path": "LICENSE",
    "content": "LICENSE\n\nThe MIT License\n\nCopyright (c) 2015 Todd Motto\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\nall copies 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\nTHE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# angular-component.js\n\nStart using `.component()` now!\n\n> [View live demo in v1.3.0](https://jsfiddle.net/vz53audf)\n\nangular-component.js is a `~1kb` script that adds `component()` support in Angular 1.5 to all Angular versions above `1.3`, so you can begin using the new method now.\n\n_Note_: you must include this script straight after `angular.js` and before your application code to ensure the `component()` method has been added to the `angular.module` global.\n\n> Read about the Angular 1.5 `component()` method [here](http://toddmotto.com/exploring-the-angular-1-5-component-method)\n\n### Polyfill support\n\nThis polyfill supports the following feature set of the `.component()` method:\n\n| Feature                                                        | Supports  |\n|----------------------------------------------------------------|-----------|\n| `angular.module.component()` method                            | Yes       |\n| `bindings` property                                            | Yes       |\n| `'E'` restrict default                                         | Yes       |\n| `$ctrl` controllerAs default                                   | Yes       |\n| `transclude` property                                          | Yes       |\n| `template` support                                             | Yes       |\n| `templateUrl` injectable for `$element` and `$attrs`           | Yes       |\n| One-way data-binding emulated                                  | Yes       |\n| Lifecycles: `$onInit`, `$onChanges`m `$postLink`, `$onDestroy` | Yes       |\n| `require` Object for parent Component inheritance              | Yes       |\n| `$` prefixed properties such as `$canActivate`                 | Yes       |\n\n### Component method usage\n\n```html\n<div ng-app=\"app\">\n  <div ng-controller=\"MainCtrl as vm\">\n    <counter count=\"vm.count\"></counter>\n  </div>\n</div>\n\n<script>\nangular\n\t.module('app', [])\n  .component('parentComponent', {\n    template: `\n      <div>\n        {{ $ctrl.user }}\n        <child-component user=\"$ctrl.user\" on-update=\"$ctrl.updateUser($event);\"></child-component>\n      </div>\n    `,\n    controller: function () {\n      this.user = {\n        name: 'Todd',\n        location: 'England, UK'\n      };\n      this.updateUser = function (event) {\n        this.user = event.user;\n      };\n    }\n  })\n\t.component('childComponent', {\n    bindings: {\n      user: '<',\n      onUpdate: '&'\n    },\n    controller: function () {\n    \tthis.$onInit = function () {\n        // component initialisation\n      };\n      this.$onChanges = function (changes) {\n        if (changes.user) {\n          this.user = angular.copy(this.user);\n        }\n      };\n      this.$postLink = function () {\n        // component post-link\n      };\n      this.$onDestroy = function () {\n        // component $destroy function\n      };\n    },\n    template: `\n      <div>\n        <input type=\"text\" ng-model=\"$ctrl.user.name\">\n        <a href=\"\" ng-click=\"$ctrl.onUpdate({$event: {user: $ctrl.user}});\">Update</a>\n      </div>\n    `\n  });\n</script>\n```\n\n## Installing with NPM\n\n```\nnpm install angular-component --save\n```\n\n## Installing with Bower\n\n```\nbower install angular-component.js --save\n```\n\n## Manual installation\nEnsure you're using the files from the `dist` directory (contains compiled production-ready code). Ensure you place the script before the closing `</body>` tag.\n\n```html\n<body>\n  <!-- html above -->\n  <script src=\"angular-1.x.js\"></script>\n  <script src=\"dist/angular-component.js\"></script>\n  <script src=\"app.js\"></script>\n</body>\n```\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Gulp.\n\n## Release history\n\n- 0.1.2\n  - Version fixes\n- 0.1.1\n  - Version fixes\n- 0.1.0\n  - Add one-way data-binding and $onChanges lifecycle, stable release\n- 0.0.8\n  - Add new lifecycle hooks ($onInit, $onDestroy, $postLink)\n- 0.0.7\n  - Add `require` property from 1.5 stable, `restrict: 'E'` as default\n- 0.0.6\n  - Add automated `$` prefixed properties to factory Object\n- 0.0.5\n  - Add automatic function annotations\n- 0.0.4\n  - Fix Array dependency annotations [#11](https://github.com/toddmotto/angular-component/issues/11)\n- 0.0.3\n  - Fix bug caused by bugfix (aligns with new 1.5 changes)\n- 0.0.2\n  - Bugfix isolate scope when `bindings` is omitted, short-circuit if .component() is already supported\n- 0.0.1\n  - Initial release\n"
  },
  {
    "path": "bower.json",
    "content": "{\n  \"name\": \"angular-component.js\",\n  \"version\": \"0.0.7\",\n  \"main\": \"./dist/angular-component.min.js\",\n  \"dependencies\": {\n    \"angular\": \">=1.3.0 <=1.5\"\n  },\n  \"homepage\": \"https://github.com/toddmotto/angular-component\",\n  \"authors\": [\n    \"Todd Motto <todd@toddmotto.com>\"\n  ],\n  \"description\": \"Angular component() polyfill for v1.3+\",\n  \"moduleType\": [],\n  \"keywords\": [\n    \"Angular\",\n    \"Component\",\n    \"Directives\"\n  ],\n  \"license\": \"MIT\",\n  \"ignore\": [\n    \"**/.*\",\n    \"node_modules\",\n    \"bower_components\",\n    \"test\",\n    \"tests\"\n  ]\n}\n"
  },
  {
    "path": "dist/angular-component.js",
    "content": "/*! angular-component v0.1.3 | (c) 2017 @toddmotto | https://github.com/toddmotto/angular-component */\n(function () {\n\n  var ng = angular.module;\n\n  function identifierForController(controller, ident) {\n    if (ident && typeof ident === 'string') return ident;\n    if (typeof controller === 'string') {\n      var match = /^(\\S+)(\\s+as\\s+(\\w+))?$/.exec(controller);\n      if (match) return match[3];\n    }\n  }\n\n  function module() {\n\n    var hijacked = ng.apply(this, arguments);\n\n    if (hijacked.component) {\n      return hijacked;\n    }\n\n    function component(name, options) {\n\n      function factory($injector) {\n\n        function makeInjectable(fn) {\n          var closure;\n          var isArray = angular.isArray(fn);\n          if (angular.isFunction(fn) || isArray) {\n            return function (tElement, tAttrs) {\n              return $injector.invoke((isArray ? fn : [\n                '$element',\n                '$attrs',\n                fn\n              ]), this, {\n                $element: tElement,\n                $attrs: tAttrs\n              });\n            };\n          } else {\n            return fn;\n          }\n        }\n\n        var oneWayQueue = [];\n\n        function parseBindings(bindings) {\n          var newBindings = {};\n          for (var prop in bindings) {\n            var binding = bindings[prop];\n            if (binding.charAt(0) === '<') {\n              var attr = binding.substring(1);\n              oneWayQueue.unshift({\n              \tlocal: prop,\n                attr: attr === '' ? prop : attr\n              });\n            } else {\n              newBindings[prop] = binding;\n            }\n          }\n          return newBindings;\n        }\n\n        var modifiedBindings = parseBindings(options.bindings);\n\n        var requires = [name];\n        var ctrlNames = [];\n        if (angular.isObject(options.require)) {\n          for (var prop in options.require) {\n            requires.push(options.require[prop]);\n            ctrlNames.push(prop);\n          }\n        }\n\n        return {\n          controller: options.controller || angular.noop,\n          controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',\n          template: makeInjectable(\n            !options.template && !options.templateUrl ? '' : options.template\n          ),\n          templateUrl: makeInjectable(options.templateUrl),\n          transclude: options.transclude,\n          scope: modifiedBindings || {},\n          bindToController: !!modifiedBindings,\n          restrict: 'E',\n          require: requires,\n          link: {\n            pre: function ($scope, $element, $attrs, $ctrls) {\n              var self = $ctrls[0];\n              for (var i = 0; i < ctrlNames.length; i++) {\n                self[ctrlNames[i]] = $ctrls[i + 1];\n              }\n              if (typeof self.$onDestroy === 'function') {\n                $scope.$on('$destroy', function () {\n                  self.$onDestroy.call(self);\n                });\n              }\n              var changes;\n              function triggerOnChanges() {\n                self.$onChanges(changes);\n                changes = undefined;\n              }\n              function updateChangeListener(key, newValue, oldValue, flush) {\n                if (typeof self.$onChanges === 'function') {\n                  if (!changes) {\n                    changes = {};\n                  }\n                  if (changes[key]) {\n                    oldValue = changes[key].currentValue;\n                  }\n                  changes[key] = {\n                    currentValue: newValue,\n                    previousValue: oldValue\n                  };\n                  if (flush) {\n                    triggerOnChanges();\n                  }\n                }\n              }\n              if (oneWayQueue.length) {\n                var destroyQueue = [];\n                for (var q = oneWayQueue.length; q--;) {\n                  (function(current){\n                    self[current.local] = $scope.$parent.$eval($attrs[current.attr]);\n                    var unbindParent = $scope.$parent.$watch($attrs[current.attr], function (newValue, oldValue) {\n                      self[current.local] = newValue;\n                      updateChangeListener(current.local, newValue, oldValue, true);\n                    });\n                    destroyQueue.unshift(unbindParent);\n                    var unbindLocal = $scope.$watch(function () {\n                      return self[current.local];\n                    }, function (newValue, oldValue) {\n                      updateChangeListener(current.local, newValue, oldValue, false);\n                    });\n                    destroyQueue.unshift(unbindLocal);\n                  })(oneWayQueue[q]);\n                }\n                $scope.$on('$destroy', function () {\n                  for (var i = destroyQueue.length; i--;) {\n                    destroyQueue[i]();\n                  }\n                });\n              }\n              if (typeof self.$onInit === 'function') {\n                self.$onInit();\n              }\n            },\n            post: function ($scope, $element, $attrs, $ctrls) {\n              var self = $ctrls[0];\n              if (typeof self.$postLink === 'function') {\n                self.$postLink();\n              }\n            }\n          }\n        };\n      }\n\n      for (var key in options) {\n        if (key.charAt(0) === '$') {\n          factory[key] = options[key];\n        }\n      }\n\n      factory.$inject = ['$injector'];\n\n      return hijacked.directive(name, factory);\n\n    }\n\n    hijacked.component = component;\n\n    return hijacked;\n\n  }\n\n  angular.module = module;\n\n})();\n"
  },
  {
    "path": "gulpfile.js",
    "content": "var gulp    = require('gulp'),\n    jshint  = require('gulp-jshint'),\n    stylish = require('jshint-stylish'),\n    header  = require('gulp-header'),\n    uglify  = require('gulp-uglify'),\n    plumber = require('gulp-plumber'),\n    clean   = require('gulp-clean'),\n    rename  = require('gulp-rename'),\n    package = require('./package.json');\n\nvar paths = {\n  output : 'dist/',\n  scripts : [\n    'src/angular-component.js'\n  ],\n  test: [\n    'test/spec/**/*.js'\n  ]\n};\n\nvar banner = [\n  '/*! ',\n    '<%= package.name %> ',\n    'v<%= package.version %> | ',\n    '(c) ' + new Date().getFullYear() + ' <%= package.author %> |',\n    ' <%= package.homepage %>',\n  ' */',\n  '\\n'\n].join('');\n\ngulp.task('scripts', ['clean'], function() {\n  return gulp.src(paths.scripts)\n    .pipe(plumber())\n    .pipe(header(banner, { package : package }))\n    .pipe(gulp.dest('dist/'))\n    .pipe(rename({ suffix: '.min' }))\n    .pipe(uglify())\n    .pipe(header(banner, { package : package }))\n    .pipe(gulp.dest('dist/'));\n});\n\ngulp.task('lint', function () {\n  return gulp.src(paths.scripts)\n    .pipe(plumber())\n    .pipe(jshint())\n    .pipe(jshint.reporter('jshint-stylish'));\n});\n\ngulp.task('clean', function () {\n  return gulp.src(paths.output, { read: false })\n    .pipe(plumber())\n    .pipe(clean());\n});\n\ngulp.task('default', [\n  'lint',\n  'clean',\n  'scripts'\n]);\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"angular-component\",\n  \"version\": \"0.1.3\",\n  \"main\": \"./dist/angular-component.min.js\",\n  \"description\": \"Angular component() polyfill\",\n  \"author\": \"@toddmotto\",\n  \"license\": \"MIT\",\n  \"homepage\": \"https://github.com/toddmotto/angular-component\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"https://github.com/toddmotto/angular-component.git\"\n  },\n  \"devDependencies\": {\n    \"gulp\": \"~3.9.0\",\n    \"gulp-uglify\": \"~0.3.0\",\n    \"gulp-rename\": \"~1.1.0\",\n    \"gulp-clean\": \"^0.2.4\",\n    \"gulp-plumber\": \"~0.6.2\",\n    \"gulp-header\": \"^1.0.2\",\n    \"gulp-jshint\": \"^1.6.1\",\n    \"jshint-stylish\": \"^0.2.0\"\n  }\n}\n"
  },
  {
    "path": "src/angular-component.js",
    "content": "(function () {\n\n  var ng = angular.module;\n\n  function identifierForController(controller, ident) {\n    if (ident && typeof ident === 'string') return ident;\n    if (typeof controller === 'string') {\n      var match = /^(\\S+)(\\s+as\\s+(\\w+))?$/.exec(controller);\n      if (match) return match[3];\n    }\n  }\n\n  function module() {\n\n    var hijacked = ng.apply(this, arguments);\n\n    if (hijacked.component) {\n      return hijacked;\n    }\n\n    function component(name, options) {\n\n      function factory($injector) {\n\n        function makeInjectable(fn) {\n          var closure;\n          var isArray = angular.isArray(fn);\n          if (angular.isFunction(fn) || isArray) {\n            return function (tElement, tAttrs) {\n              return $injector.invoke((isArray ? fn : [\n                '$element',\n                '$attrs',\n                fn\n              ]), this, {\n                $element: tElement,\n                $attrs: tAttrs\n              });\n            };\n          } else {\n            return fn;\n          }\n        }\n\n        var oneWayQueue = [];\n\n        function parseBindings(bindings) {\n          var newBindings = {};\n          for (var prop in bindings) {\n            var binding = bindings[prop];\n            if (binding.charAt(0) === '<') {\n              var attr = binding.substring(1);\n              oneWayQueue.unshift({\n              \tlocal: prop,\n                attr: attr === '' ? prop : attr\n              });\n            } else {\n              newBindings[prop] = binding;\n            }\n          }\n          return newBindings;\n        }\n\n        var modifiedBindings = parseBindings(options.bindings);\n\n        var requires = [name];\n        var ctrlNames = [];\n        if (angular.isObject(options.require)) {\n          for (var prop in options.require) {\n            requires.push(options.require[prop]);\n            ctrlNames.push(prop);\n          }\n        }\n\n        return {\n          controller: options.controller || angular.noop,\n          controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',\n          template: makeInjectable(\n            !options.template && !options.templateUrl ? '' : options.template\n          ),\n          templateUrl: makeInjectable(options.templateUrl),\n          transclude: options.transclude,\n          scope: modifiedBindings || {},\n          bindToController: !!modifiedBindings,\n          restrict: 'E',\n          require: requires,\n          link: {\n            pre: function ($scope, $element, $attrs, $ctrls) {\n              var self = $ctrls[0];\n              for (var i = 0; i < ctrlNames.length; i++) {\n                self[ctrlNames[i]] = $ctrls[i + 1];\n              }\n              if (typeof self.$onDestroy === 'function') {\n                $scope.$on('$destroy', function () {\n                  self.$onDestroy.call(self);\n                });\n              }\n              var changes;\n              function triggerOnChanges() {\n                self.$onChanges(changes);\n                changes = undefined;\n              }\n              function updateChangeListener(key, newValue, oldValue, flush) {\n                if (typeof self.$onChanges === 'function') {\n                  if (!changes) {\n                    changes = {};\n                  }\n                  if (changes[key]) {\n                    oldValue = changes[key].currentValue;\n                  }\n                  changes[key] = {\n                    currentValue: newValue,\n                    previousValue: oldValue\n                  };\n                  if (flush) {\n                    triggerOnChanges();\n                  }\n                }\n              }\n              if (oneWayQueue.length) {\n                var destroyQueue = [];\n                for (var q = oneWayQueue.length; q--;) {\n                  (function(current){\n                    self[current.local] = $scope.$parent.$eval($attrs[current.attr]);\n                    var unbindParent = $scope.$parent.$watch($attrs[current.attr], function (newValue, oldValue) {\n                      self[current.local] = newValue;\n                      updateChangeListener(current.local, newValue, oldValue, true);\n                    });\n                    destroyQueue.unshift(unbindParent);\n                    var unbindLocal = $scope.$watch(function () {\n                      return self[current.local];\n                    }, function (newValue, oldValue) {\n                      updateChangeListener(current.local, newValue, oldValue, false);\n                    });\n                    destroyQueue.unshift(unbindLocal);\n                  })(oneWayQueue[q]);\n                }\n                $scope.$on('$destroy', function () {\n                  for (var i = destroyQueue.length; i--;) {\n                    destroyQueue[i]();\n                  }\n                });\n              }\n              if (typeof self.$onInit === 'function') {\n                self.$onInit();\n              }\n            },\n            post: function ($scope, $element, $attrs, $ctrls) {\n              var self = $ctrls[0];\n              if (typeof self.$postLink === 'function') {\n                self.$postLink();\n              }\n            }\n          }\n        };\n      }\n\n      for (var key in options) {\n        if (key.charAt(0) === '$') {\n          factory[key] = options[key];\n        }\n      }\n\n      factory.$inject = ['$injector'];\n\n      return hijacked.directive(name, factory);\n\n    }\n\n    hijacked.component = component;\n\n    return hijacked;\n\n  }\n\n  angular.module = module;\n\n})();\n"
  }
]