Skip to content

Commit

Permalink
fix: injectGlobal supports @media print
Browse files Browse the repository at this point in the history
closes #333
  • Loading branch information
sastan committed Oct 3, 2022
1 parent 0e2aa5c commit 9b5e329
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .changeset/good-shoes-grin.md
Expand Up @@ -2,4 +2,4 @@
'@twind/with-next': patch
---

update to @sveltejs/kit@1.0.0-next.507 (the new routing system)
update to @sveltejs/kit@1.0.0-next.507 (the new routing system) 🙏🏽 @SergeiZheleznov!
5 changes: 5 additions & 0 deletions .changeset/moody-bees-poke.md
@@ -0,0 +1,5 @@
---
'twind': patch
---

`injectGlobal` support for `@media print (#333, #334) 🙏 @javascriptjedi!
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -43,7 +43,7 @@
"name": "twind",
"path": "packages/twind/dist/twind.esnext.js",
"brotli": true,
"limit": "7.65kb"
"limit": "7.7kb"
},
{
"name": "twind (setup)",
Expand All @@ -63,7 +63,7 @@
"name": "@twind/cdn",
"path": "packages/cdn/dist/cdn.esnext.js",
"brotli": true,
"limit": "15.2kb"
"limit": "15.25kb"
},
{
"name": "@twind/preset-tailwind",
Expand Down
2 changes: 1 addition & 1 deletion packages/cdn/package.json
Expand Up @@ -32,7 +32,7 @@
"name": "@twind/cdn",
"path": "dist/cdn.esnext.js",
"brotli": true,
"limit": "15.2kb"
"limit": "15.25kb"
}
],
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/preset-tailwind/src/rules.test.json
Expand Up @@ -866,6 +866,7 @@
"-rotate-3 hover:rotate-6 md:rotate-3 md:hover:-rotate-6",
[
"*,::before,::after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-transform:translateX(var(--tw-translate-x)) translateY(var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}",
"@media (min-width:768px){*,::before,::after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-transform:translateX(var(--tw-translate-x)) translateY(var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}}",
".-rotate-3{--tw-rotate:calc(3deg * -1);transform:var(--tw-transform)}",
".hover\\:rotate-6:hover{--tw-rotate:6deg;transform:var(--tw-transform)}",
"@media (min-width:768px){.md\\:rotate-3{--tw-rotate:3deg;transform:var(--tw-transform)}}",
Expand Down
2 changes: 1 addition & 1 deletion packages/twind/package.json
Expand Up @@ -29,7 +29,7 @@
"name": "twind",
"path": "dist/twind.esnext.js",
"brotli": true,
"limit": "7.65kb"
"limit": "7.7kb"
},
{
"name": "twind (setup)",
Expand Down
4 changes: 3 additions & 1 deletion packages/twind/src/internal/serialize.ts
Expand Up @@ -173,7 +173,9 @@ function serialize$<Theme extends BaseTheme = BaseTheme>(
)
} else {
// global selector
rules.push(...serialize$(value as CSSObject, { p: precedence, r: [key] }, context))
rules.push(
...serialize$(value as CSSObject, { p: precedence, r: [...conditions, key] }, context),
)
}
} else if (key == 'label' && value) {
name = (value as string) + hash(JSON.stringify([precedence, important, style]))
Expand Down
12 changes: 12 additions & 0 deletions packages/twind/src/tests/inject-global.test.ts
Expand Up @@ -203,3 +203,15 @@ test('multiple @font-face and @import using object', () => {
"/*!0,0*/@font-face{font-family:'Roboto';font-style:normal;font-weight:400;src:local('Roboto'),local('Roboto-Regular'),url(fonts/roboto-v18-latin-regular.woff2) format('woff2'),url(fonts/roboto-v18-latin-regular.woff) format('woff')}",
])
})

test('@media print', () => {
injectGlobal(`
@media print {
main {
height: auto;
}
}
`)

assert.deepEqual(tw.target, ['/*!27wr28,v*/@media print{main{height:auto}}'])
})

0 comments on commit 9b5e329

Please sign in to comment.