{"_id":"@apostrophecms/postcss-viewport-to-container-toggle-stable","name":"@apostrophecms/postcss-viewport-to-container-toggle-stable","dist-tags":{"latest":"2.3.0"},"versions":{"2.3.0":{"name":"@apostrophecms/postcss-viewport-to-container-toggle-stable","version":"2.3.0","description":"A plugin for [PostCSS](https://github.com/postcss/postcss) that allows to toggle between viewport and container units based on the presence of a container data attribute.","main":"index.js","scripts":{"test":"npm run lint && mocha","lint":"eslint --ext .js,.vue ."},"repository":{"type":"git","url":"git+https://github.com/apostrophecms/apostrophe.git","directory":"packages/postcss-viewport-to-container-toggle"},"homepage":"https://github.com/apostrophecms/apostrophe/tree/main/packages/postcss-viewport-to-container-toggle#readme","author":{"name":"Apostrophe Technologies, Inc."},"license":"MIT","devDependencies":{"cssnano":"^7.0.6","eslint":"^9.39.1","eslint-config-apostrophe":"workspace:^","mocha":"^11.7.5","postcss":"^8.4.47"},"apostropheTestConfig":{"requiresMongo":false},"gitHead":"b3e29f004f514041e1e389293ae67017c60d006e","_id":"@apostrophecms/postcss-viewport-to-container-toggle-stable@2.3.0","bugs":{"url":"https://github.com/apostrophecms/apostrophe/issues"},"_nodeVersion":"24.10.0","_npmVersion":"11.6.1","dist":{"integrity":"sha512-wftYNYuLAHs1MGDj1Ccsyi8H7ciUJx9mTepkNsthtGnb99QK99A1ix6ez7jwAURKxTiBcHUeJ0p48L724R+vOw==","shasum":"2fd0b12dc5dc0bf18050c55da4695a4263f832d4","tarball":"https://registry.npmjs.org/@apostrophecms/postcss-viewport-to-container-toggle-stable/-/postcss-viewport-to-container-toggle-stable-2.3.0.tgz","fileCount":23,"unpackedSize":123115,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICaxN8dLg5u5zzsEFfiMA6kcUmF6EzBnZ9gpFKfMy+siAiBjegTeEfwAL9m5EgaYd/Th2P1UGXDlIZ1cNygv29v2Dw=="}]},"_npmUser":{"name":"boutell","email":"tom@apostrophecms.com"},"directories":{},"maintainers":[{"name":"alexgilbert","email":"alex@apostrophecms.com"},{"name":"boutell","email":"tom@apostrophecms.com"},{"name":"romanek","email":"stuart+npm@apostrophecms.com"},{"name":"bodonkey","email":"robert.means1969+apostrophecms@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/postcss-viewport-to-container-toggle-stable_2.3.0_1781112740543_0.18662798262589897"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-10T17:32:20.404Z","2.3.0":"2026-06-10T17:32:20.707Z","modified":"2026-06-10T17:32:20.945Z"},"maintainers":[{"name":"alexgilbert","email":"alex@apostrophecms.com"},{"name":"boutell","email":"tom@apostrophecms.com"},{"name":"romanek","email":"stuart+npm@apostrophecms.com"},{"name":"bodonkey","email":"robert.means1969+apostrophecms@gmail.com"}],"description":"A plugin for [PostCSS](https://github.com/postcss/postcss) that allows to toggle between viewport and container units based on the presence of a container data attribute.","homepage":"https://github.com/apostrophecms/apostrophe/tree/main/packages/postcss-viewport-to-container-toggle#readme","repository":{"type":"git","url":"git+https://github.com/apostrophecms/apostrophe.git","directory":"packages/postcss-viewport-to-container-toggle"},"author":{"name":"Apostrophe Technologies, Inc."},"bugs":{"url":"https://github.com/apostrophecms/apostrophe/issues"},"license":"MIT","readme":"# postcss-viewport-to-container-toggle \n\nA plugin for [PostCSS](https://github.com/postcss/postcss) that allows to toggle between viewport and container units based on the presence of a container data attribute.\n\n## Why?\n\nThis plugin has been originally developed to allow mobile preview without using any `iframe` in order to be as close as possible to the real rendering.\n\nFor examples, let's say we have a block in our page that is taking `50vw`. \nWe want in the case of the mobile preview (where body is a container), this block to take `50cqw` instead of `50vw`.\n\nHere is what it looks like, in normal mode, our block takes `50vw` as it did before we the initial code:\n\n![image](./images/normal.png)\n\nIn mobile preview, body being a container, this block will take `50cqw` of the container:\n\n![image](./images/mobile.png)\n\n\n## Demo\n\nThis css:\n\n```css\n.hello {\n    width: 100vw;\n    height: 100vh;\n}\n```\n\nIf you set the `modifierAttr` to `data-breakpoint-preview-mode` and `containerEl` to `body` (default), it'll be converted this way:\n\n```css\n.hello {\n    width: 100vw;\n    height: 100vh;\n}\n\n:where(body[data-breakpoint-preview-mode]) .hello {\n    width: 100cqw;\n    height: 100cqh;\n}\n```\n\nThe purpose being here to keep the existing behavior but to make the code work compatible for containers when body is in container mode.\n\nHere is another examples with media queries:\n\n```css\n@media only screen and (width > 600px) and (max-width: 1000px) {\n  .hello {\n    top: 0;\n    width: 100vw;\n    height: calc(100vh - 50px);\n  }\n  .goodbye {\n    width: 100%;\n    color: #fff;\n    transform: translateX(20vw);\n  }\n}\n\n.toto {\n  width: 100vh;\n  color: white;\n}\n```\n\n\nwill become:\n\n```css\n@media only screen and (width > 600px) and (max-width: 1000px) {\n  :where(body:not([data-breakpoint-preview-mode])) .hello {\n    top: 0;\n    width: 100vw;\n    height: calc(100vh - 50px);\n  }\n  :where(body:not([data-breakpoint-preview-mode])) .goodbye {\n    width: 100%;\n    color: #fff;\n    transform: translateX(20vw);\n  }\n}\n\n@container (width > 600px) and (max-width: 1000px) {\n  .hello {\n    top: 0;\n    width: 100cqw;\n    height: calc(100cqh - 50px);\n  }\n  .goodbye {\n    width: 100%;\n    color: #fff;\n    transform: translateX(20cqw);\n  }\n}\n\n.toto {\n  width: 100vh;\n  color: white;\n}\n\n:where(body[data-breakpoint-preview-mode]) .toto {\n  width: 100cqh;\n}\n```\n\nAs you can see, if body has no specific attribute, the behavior stays the same. \nWhen adding `data-breakpoint-preview-mode`, data in media queries are converted to container units and moved to container queries.\n\n## Installation\n\n```bash\nnpm install postcss-viewport-to-container-toggle\n```\n\n## Getting started\n\n### Webpack\n\n```javascript\nconst postcssViewportToContainerToggle = require('postcss-viewport-to-container-toggle');\n\n{\n  loader: 'postcss-loader',\n  options: {\n    sourceMap: true,\n    postcssOptions: {\n      plugins: [\n        [\n          postcssViewportToContainerToggle({\n            modifierAttr: 'data-breakpoint-preview-mode',\n            containerEl: 'body',\n            debug: false\n          }),\n          'autoprefixer'\n        ]\n      ]\n    }\n  }\n}\n```\n\n### Vite\n\n```javascript\nconst postcssViewportToContainerToggle = require('postcss-viewport-to-container-toggle');\n\n{\n    css: {\n      postcss: {\n        plugins: [\n          postcssViewportToContainerToggle({\n            modifierAttr: 'data-breakpoint-preview-mode',\n            containerEl: 'body',\n            debug: false\n          })\n        ]\n      }\n    }\n}\n```\n\n### Options\n\n* `modifierAttr`: The attribute that will be used to toggle between viewport and container units.\n* `containerEl`: The element that will be used as container. Default: `body`\n* `debug`: If set to `true`, will output debug information. Default: `false`\n* `transform`: A function that will be called for each media query, allowing to modify its params when creating the `container`.\n","readmeFilename":"README.md","_rev":"1-90e328aa297bd27bf02e1ead58e0622a"}