{"bugs":{"url":"https://github.com/material-components/material-components-web/issues"},"dist":{"shasum":"e8b0ada89b697bec675d73b76c04fb4634b13ddf","tarball":"https://registry.npmjs.org/@material/auto-init/-/auto-init-15.0.0-canary.95ef196bc.0.tgz","fileCount":13,"integrity":"sha512-8Wio0/re7ywgFl5+jTOMKjOPSe6yuc8/y58XkyH1hi9fTMYsVDiOelAOKD+P1fCRhuVXgdVLRzf2Xz1HpS2KGg==","signatures":[{"sig":"MEYCIQDgIH0TeWNZhcHR7h0Cf9E/hG8zDx41F847ISwCjlzGTgIhAMe7Add6leUsx1Hy8VWXK+1HAcEO7d9Gtby/mg2GwNwu","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":49694,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjSe0GACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrjARAAj73KQjJo7soHQQ1Ry0JPkUJ0vxLjIGanUawf5h1I4CKDVPM2\r\nxS4vRd1h+h/ao/jS9LEp7OsoDLmOxKqWTGGczRzbx241OldaTq2CzFmO1T99\r\nA5gN08loHGSgyBU6Xcf8lra3yPlrscBVjt2gSP7Go8CdPlqeDBoHAkUMPBar\r\nivELC0/JtY5vZBzUDln49Lvgo/GicZReSa3Wo3VIo38s7QyRmcU5HTNxlHJU\r\ny+eZGPAl4r8v3gGCbAK2+FTTX+iaYlqFwGcD3sXNQ3gS5CbNNbRBtlI9JT5t\r\n82wdwT3v1BzJ06YdfI2SIRCC6IbgPm7gYTi9YbyI6FA0Pz4lfElOR3/OuIo7\r\nZXQfY0urETOP+A3Awx4n3YkQXytiUm3YEaiuL1fEK/01MuON3jXQ8pxj98KZ\r\nRVIFGe+flPPYZzBUjwrmH4hGFbq6rI1E8bufFQ0w4/rskVzlcpm+FdSNCiD4\r\nuPbdOq6oLdFWE4mt37LklDkY6gXIV7FQC2rPu53BT1SAThlryZBXOqumYCY1\r\nHgcVcMO0UfyeQE8+NvFlfAOw49HtKiFOF0oZhrtJQNDdqSUSTjiOUUhQgx0x\r\nr6/fxPuJJLPTJJc+xtmJ8KK6qrvotvTTdTXPZBKJdWPA1l41imm6CHACTPG5\r\nLu9R/Z86dyTCssxKLFdvgLjRUSx07/jcp3Y=\r\n=VLNW\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/mdc.autoInit.js","name":"@material/auto-init","module":"index.js","readme":"<!--docs:\ntitle: \"Auto Init\"\nlayout: detail\nsection: components\nexcerpt: \"Utilities for declarative, DOM-based initialization of components on simple web sites.\"\npath: /catalog/auto-init/\n-->\n\n# Auto Init\n\n`mdc-auto-init` is a utility package that provides declarative, DOM-based method of initialization\nfor MDC Web components on simple web sites. Note that for more advanced use-cases and complex sites,\nmanual instantiation of components will give you more flexibility. However, `mdc-auto-init` is great\nfor static websites, prototypes, and other use-cases where simplicity and convenience is most\nappropriate.\n\n## Installation\n\n```\nnpm install @material/auto-init\n```\n\n## Usage\n\n### Using as part of `material-components-web`\n\nIf you are using mdc-auto-init as part of the [material-components-web](../material-components-web)\npackage, simply write the necessary DOM needed for a component, and attach a `data-mdc-auto-init`\nattribute to the root element with its value set to the component's JavaScript class name (e.g.,\n`MDCTextField`). Then, after writing the markup, simply insert a script tag that calls\n`mdc.autoInit()`. Make sure you call `mdc.autoInit()` after all scripts are loaded so it works\nproperly.\n\n```html\n<label class=\"mdc-text-field mdc-text-field--filled\" data-mdc-auto-init=\"MDCTextField\">\n  <span class=\"mdc-text-field__ripple\"></span>\n  <input class=\"mdc-text-field__input\" type=\"text\" aria-labelledby=\"label\">\n  <span id=\"label\" class=\"mdc-floating-label\">Input Label</span>\n  <span class=\"mdc-line-ripple\"></span>\n</label>\n\n<!-- at the bottom of the page -->\n<script type=\"text/javascript\">\n  window.mdc.autoInit();\n</script>\n```\n\nThis will attach an [MDCTextField](../mdc-textfield) instance to the root `<div>` element.\n\n#### Accessing the component instance\n\nWhen `mdc-auto-init` attaches a component to an element, it assign that instance to the element\nusing a property whose name is the value of `data-mdc-auto-init`. For example, given\n\n```html\n<label class=\"mdc-text-field mdc-text-field--filled\" data-mdc-auto-init=\"MDCTextField\">\n  <span class=\"mdc-text-field__ripple\"></span>\n  <input class=\"mdc-text-field__input\" type=\"text\" aria-labelledby=\"label\">\n  <span id=\"label\" class=\"mdc-floating-label\">Input Label</span>\n  <span class=\"mdc-line-ripple\"></span>\n</label>\n```\n\nOnce `mdc.autoInit()` is called, you can access the component instance via an `MDCTextField`\nproperty on that element.\n\n```js\ndocument.querySelector('.mdc-text-field').MDCTextField.disabled = true;\n```\n\n#### Calling subsequent `mdc.autoInit()`\n\nIf you decide to add new components into the DOM after the initial `mdc.autoInit()`, you can make subsequent calls to `mdc.autoInit()`. This will not reinitialize existing components. This works since mdc-auto-init will add the `data-mdc-auto-init-state=\"initialized\"` attribute, which tracks if the component has already been initialized. After calling `mdc.autoInit()` your component will then look like:\n\n```html\n<label class=\"mdc-text-field mdc-text-field--filled\" data-mdc-auto-init=\"MDCTextField\" data-mdc-auto-init-state=\"initialized\">\n  ...\n</label>\n```\n\n### Using as a standalone module\n\n#### Registering Components\n\nIf you are using `mdc-auto-init` outside of `material-components-web`, you must manually provide a\nmapping between `data-mdc-auto-init` attribute values and the components which they map to. This can\nbe achieved via `mdcAutoInit.register`.\n\n```js\nimport mdcAutoInit from '@material/auto-init';\nimport {MDCTextField} from '@material/textfield';\n\nmdcAutoInit.register('MDCTextField', MDCTextField);\n```\n\n`mdcAutoInit.register()` tells `mdc-auto-init` that when it comes across an element with a\n`data-mdc-auto-init` attribute set to `\"MDCTextField\"`, it should initialize an `MDCTextField`\ninstance on that element. The `material-components-web` package does this for all components for\nconvenience.\n\nAlso note that a component can be mapped to any string, not necessarily the name of its constructor.\n\n```js\nimport mdcAutoInit from '@material/auto-init';\nimport {MDCTextField} from '@material/textfield';\n\nmdcAutoInit.register('My amazing text field!!!', MDCTextField);\n```\n\n```html\n<label class=\"mdc-text-field mdc-text-field--filled\" data-mdc-auto-init=\"My amazing text field!!!\">\n  <!-- ... -->\n</label>\n<script>window.mdc.autoInit();</script>\n```\n\n### De-registering components\n\nAny component can be deregistered by calling `mdcAutoInit.deregister` with the name used to register\nthe component.\n\n```js\nmdcAutoInit.deregister('MDCTextField');\n```\n\nThis will simply remove the name -> component mapping. It will _not_ affect any already-instantiated\ncomponents on the page.\n\nTo unregister all name -> component mappings, you can use `mdcAutoInit.deregisterAll()`.\n\n## How `mdc-auto-init` works\n\n`mdc-auto-init` maintains a registry object which maps string identifiers, or **names**, to\ncomponent constructors. When the default exported function - `mdcAutoInit()` - is called,\n`mdc-auto-init` queries the DOM for all elements with a `data-mdc-auto-init` attribute. For each\nelement returned, the following steps are taken:\n\n1. If the `data-mdc-auto-init` attribute does not have a value associated with it, throw an error\n2. If the value of `data-mdc-auto-init` cannot be found in the registry, throw an error\n3. If the element has an existing property whose name is the value of `data-mdc-auto-init`, it is\n   assumed to have already been initialized. Therefore it is skipped, and a warning will be logged\n   to the console (this behavior can be overridden).\n4. Let `Ctor` be the component constructor associated with the given name in the register\n5. Let `instance` be the result of calling `Ctor.attachTo()` and passing in the element as an\n   argument.\n6. Create a non-writable, non-enumerable property on the node whose name is the value of\n   `data-mdc-auto-init` and whose value is `instance`.\n\n### Initializing only a certain part of the page\n\nBy default, `mdc-auto-init` will query the entire document to figure out which components to\ninitialize. To override this behavior, you can pass in an optional `root` first argument specifying\nthe root node whose children will be queried for instantiation.\n\n```html\n<div id=\"mdc-section\">\n  <!-- MDC Web Components, etc. -->\n</div>\n<script>window.mdc.autoInit(document.getElementById('mdc-section'));</script>\n```\n\nIn the above example, only elements within `<div id=\"mdc-section\">` will be queried.\n\n### Calling autoInit() multiple times\n\nBy default, `mdc-auto-init` only expects to be called once, at page-load time. However, there may be\ncertain scenarios where one may want to use `mdc-auto-init` and may still need to call it multiple\ntimes, such as on a Wordpress site that contains an infinitely-scrolling list of new blog post\nelements containing MDC Web components. `mdcAutoInit()` takes an optional second argument which is the\nfunction used to warn users when a component is initialized multiple times. By default, this is just\n`console.warn()`. However, to skip over already-initialized components without logging a\nwarning, you could simply pass in a nop.\n\n```html\n<script>window.mdc.autoInit(/* root */ document, () => {});</script>\n```\n\nThis will suppress any warnings about already initialized elements.\n\n### Events\n\n#### MDCAutoInit:End\nTriggered when initialization of all components is complete.\n\n`document.addEventListener(\"MDCAutoInit:End\", () => {...});`\n","gitHead":"c133997c8c45e50d9ebfe12fabab75ec90d244e7","license":"MIT","_npmUser":{"name":"abhiomkar","email":"abhiomkar@gmail.com"},"homepage":"https://github.com/material-components/material-components-web#readme","repository":{"url":"git+https://github.com/material-components/material-components-web.git","type":"git","directory":"packages/mdc-auto-init"},"_npmVersion":"lerna/3.20.2/node@v14.20.1+x64 (linux)","description":"Declarative, easy-to-use auto-initialization for Material Components for the web","directories":{},"maintainers":[{"name":"material-admin","email":"aprigogin+npm@google.com"},{"name":"yefim","email":"hi@yef.im"},{"name":"abhiomkar","email":"abhiomkar@gmail.com"},{"name":"azakus","email":"dfreedm2@gmail.com"},{"name":"bicknellr","email":"bicknellr@gmail.com"},{"name":"aprigogin","email":"andrey.prigogin@gmail.com"},{"name":"patrickrodee","email":"prodee@google.com"},{"name":"aomarks","email":"aomarks@gmail.com"},{"name":"emarquez","email":"emarquez@google.com"},{"name":"allanchen","email":"allanchen@google.com"},{"name":"esgonzalez","email":"esgonzalez@google.com"},{"name":"asyncliz","email":"asyncliz@gmail.com"},{"name":"candysonya","email":"wangchan518@gmail.com"},{"name":"ssuarez","email":"sayrisuarez@google.com"},{"name":"taylorv","email":"brian.t.vann@gmail.com"}],"sideEffects":false,"_nodeVersion":"14.20.1","dependencies":{"tslib":"^2.1.0","@material/base":"15.0.0-canary.95ef196bc.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","_npmOperationalInternal":{"tmp":"tmp/auto-init_15.0.0-canary.95ef196bc.0_1665789190400_0.1643191392028689","host":"s3://npm-registry-packages"},"_id":"@material/auto-init@15.0.0-canary.95ef196bc.0","version":"15.0.0-canary.95ef196bc.0"}