next-yak 0.0.25 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -27
- package/dist/static/index.cjs +2 -0
- package/dist/static/index.cjs.map +1 -0
- package/dist/static/index.d.cts +31 -0
- package/dist/static/index.d.ts +31 -0
- package/dist/static/index.js +2 -0
- package/dist/static/index.js.map +1 -0
- package/loaders/babel-yak-plugin.cjs +10 -6
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -172,33 +172,6 @@ module.exports = {
|
|
|
172
172
|
|
|
173
173
|
[Nesting Example (video)](https://github.com/jantimon/next-yak/assets/4113649/33eeeb13-b0cf-499f-a1d3-ba6f51cf4308)
|
|
174
174
|
|
|
175
|
-
## Build Time Constants
|
|
176
|
-
|
|
177
|
-
The downside of dynamic properties is that they require inline style attributes.
|
|
178
|
-
While this is not a problem for most cases, we can't use them for media queries.
|
|
179
|
-
|
|
180
|
-
`next-yak` allows you to define build time constants which can be used in your styles:
|
|
181
|
-
|
|
182
|
-
```jsx
|
|
183
|
-
import { styled } from 'next-yak';
|
|
184
|
-
import { breakpoints, spacings } from './constants.yak';
|
|
185
|
-
|
|
186
|
-
const Container = styled.div`
|
|
187
|
-
padding: ${spacings.md};
|
|
188
|
-
${breakpoints.md} {
|
|
189
|
-
padding: ${spacings.lg};
|
|
190
|
-
}
|
|
191
|
-
`;
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
| Feature | Code | Yak Constant files |
|
|
195
|
-
|---------------- |----------------------------------------------- |---------------------------------------------- |
|
|
196
|
-
| File Extension | `.js`, `.jsx`, `.tsx`, etc. | `.yak.js`, `.yak.jsx`, `.yak.tsx`, etc. |
|
|
197
|
-
| Runs at | Compile time (Bundler) | Runtime (Node or Browser) |
|
|
198
|
-
| Side effects | Allowed | Forbidden |
|
|
199
|
-
| Yak Features | All (`styled`, `css`, ...) | - |
|
|
200
|
-
|
|
201
|
-
|
|
202
175
|
## Motivation
|
|
203
176
|
|
|
204
177
|
Most of the existing CSS-in-JS libraries are either slow or have a complex api. This project tries to find a middle ground between speed and api complexity.
|
|
@@ -262,6 +235,36 @@ const Button = styled.button`
|
|
|
262
235
|
`;
|
|
263
236
|
```
|
|
264
237
|
|
|
238
|
+
|
|
239
|
+
## Build Time Constants
|
|
240
|
+
|
|
241
|
+
The downside of dynamic properties is that they require inline style attributes.
|
|
242
|
+
While this is not a problem for most cases, we can't use them for media queries.
|
|
243
|
+
|
|
244
|
+
`next-yak` allows you to define build time constants which can be used in your styles:
|
|
245
|
+
|
|
246
|
+
```jsx
|
|
247
|
+
import { styled } from 'next-yak';
|
|
248
|
+
import { breakpoints, spacings } from './constants.yak';
|
|
249
|
+
|
|
250
|
+
const Container = styled.div`
|
|
251
|
+
padding: ${spacings.md};
|
|
252
|
+
${breakpoints.md} {
|
|
253
|
+
padding: ${spacings.lg};
|
|
254
|
+
}
|
|
255
|
+
`;
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
| Feature | Code | Yak Constant files |
|
|
259
|
+
|:-----------------|:------------------------------------------------|:-----------------------------------------------|
|
|
260
|
+
| File Extension | `.js`, `.jsx`, `.tsx`, etc. | `.yak.js`, `.yak.jsx`, `.yak.tsx`, etc. |
|
|
261
|
+
| Runs at | Runtime (Node or Browser) | Compile time (Bundler) |
|
|
262
|
+
| Side effects | ✅ | 🚫 |
|
|
263
|
+
| Yak Features | All (`styled`, `css`, ...) | 🚫 |
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
[Build time constants (video)](https://github.com/jantimon/next-yak/assets/4113649/6bdc44df-2996-40a3-9255-4b9ed0df464a)
|
|
267
|
+
|
|
265
268
|
## Todos:
|
|
266
269
|
|
|
267
270
|
next-yak is currently in the development phase, with several todos that must be completed before it is ready for production:
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var m=(n,r)=>{for(var t in r)e(n,t,{get:r[t],enumerable:!0})},f=(n,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of a(r))!g.call(n,i)&&i!==t&&e(n,i,{get:()=>r[i],enumerable:!(s=p(r,i))||s.enumerable});return n};var y=n=>f(e({},"__esModule",{value:!0}),n);var c={};m(c,{mixin:()=>o});module.exports=y(c);var o={};m(o,{css:()=>b});var b=(n,...r)=>String.raw(n,...r.map(t=>typeof t=="number"||typeof t=="string"?t:"")).trim();0&&(module.exports={mixin});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../static/index.ts","../../static/staticCssLiteral.tsx"],"sourcesContent":["//\n// Utility function to be used inside .yak.ts or .yak.js\n// files to define static css mixings\n//\n//\nexport * as mixin from \"./staticCssLiteral.js\"","/**\n * A stub that allows us to use the `css()` (css literal function) inside of *.yak files.\n *\n * This is mainly used for tooling like stylelint and typechecking inside css of *.yak files.\n * It works similar to String.raw but filters out undefined, null and false values to allow for conditionals.\n *\n * @example\n * ```tsx\n * // inside of example.yak.ts\n * import { mixin } from \"next-yak/static\";\n *\n * const styles = mixin.css`\n * .foo {\n * color: red;\n * ${data.isBar && css`\n * background: blue;\n * `}\n * }\n * `\n * ```\n */\nexport const css = (\n strings: TemplateStringsArray,\n ...values: Array<string | number | boolean | null | undefined | Function>\n): string =>\n String.raw(\n strings,\n ...values.map((value) =>\n // filter out everything but strings and numbers\n typeof value === \"number\" || typeof value === \"string\" ? value : \"\"\n )\n ).trim();\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAA,GAAAC,EAAAD,EAAA,SAAAE,IAqBO,IAAMA,EAAM,CACjBC,KACGC,IAEH,OAAO,IACLD,EACA,GAAGC,EAAO,IAAKC,GAEb,OAAOA,GAAU,UAAY,OAAOA,GAAU,SAAWA,EAAQ,EACnE,CACF,EAAE,KAAK","names":["static_exports","__export","staticCssLiteral_exports","__toCommonJS","staticCssLiteral_exports","__export","css","strings","values","value"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stub that allows us to use the `css()` (css literal function) inside of *.yak files.
|
|
3
|
+
*
|
|
4
|
+
* This is mainly used for tooling like stylelint and typechecking inside css of *.yak files.
|
|
5
|
+
* It works similar to String.raw but filters out undefined, null and false values to allow for conditionals.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // inside of example.yak.ts
|
|
10
|
+
* import { mixin } from "next-yak/static";
|
|
11
|
+
*
|
|
12
|
+
* const styles = mixin.css`
|
|
13
|
+
* .foo {
|
|
14
|
+
* color: red;
|
|
15
|
+
* ${data.isBar && css`
|
|
16
|
+
* background: blue;
|
|
17
|
+
* `}
|
|
18
|
+
* }
|
|
19
|
+
* `
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare const css: (strings: TemplateStringsArray, ...values: Array<string | number | boolean | null | undefined | Function>) => string;
|
|
23
|
+
|
|
24
|
+
declare const staticCssLiteral_css: typeof css;
|
|
25
|
+
declare namespace staticCssLiteral {
|
|
26
|
+
export {
|
|
27
|
+
staticCssLiteral_css as css,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { staticCssLiteral as mixin };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stub that allows us to use the `css()` (css literal function) inside of *.yak files.
|
|
3
|
+
*
|
|
4
|
+
* This is mainly used for tooling like stylelint and typechecking inside css of *.yak files.
|
|
5
|
+
* It works similar to String.raw but filters out undefined, null and false values to allow for conditionals.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // inside of example.yak.ts
|
|
10
|
+
* import { mixin } from "next-yak/static";
|
|
11
|
+
*
|
|
12
|
+
* const styles = mixin.css`
|
|
13
|
+
* .foo {
|
|
14
|
+
* color: red;
|
|
15
|
+
* ${data.isBar && css`
|
|
16
|
+
* background: blue;
|
|
17
|
+
* `}
|
|
18
|
+
* }
|
|
19
|
+
* `
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare const css: (strings: TemplateStringsArray, ...values: Array<string | number | boolean | null | undefined | Function>) => string;
|
|
23
|
+
|
|
24
|
+
declare const staticCssLiteral_css: typeof css;
|
|
25
|
+
declare namespace staticCssLiteral {
|
|
26
|
+
export {
|
|
27
|
+
staticCssLiteral_css as css,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { staticCssLiteral as mixin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../static/staticCssLiteral.tsx"],"sourcesContent":["/**\n * A stub that allows us to use the `css()` (css literal function) inside of *.yak files.\n *\n * This is mainly used for tooling like stylelint and typechecking inside css of *.yak files.\n * It works similar to String.raw but filters out undefined, null and false values to allow for conditionals.\n *\n * @example\n * ```tsx\n * // inside of example.yak.ts\n * import { mixin } from \"next-yak/static\";\n *\n * const styles = mixin.css`\n * .foo {\n * color: red;\n * ${data.isBar && css`\n * background: blue;\n * `}\n * }\n * `\n * ```\n */\nexport const css = (\n strings: TemplateStringsArray,\n ...values: Array<string | number | boolean | null | undefined | Function>\n): string =>\n String.raw(\n strings,\n ...values.map((value) =>\n // filter out everything but strings and numbers\n typeof value === \"number\" || typeof value === \"string\" ? value : \"\"\n )\n ).trim();\n"],"mappings":"0FAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,IAqBO,IAAMA,EAAM,CACjBC,KACGC,IAEH,OAAO,IACLD,EACA,GAAGC,EAAO,IAAKC,GAEb,OAAOA,GAAU,UAAY,OAAOA,GAAU,SAAWA,EAAQ,EACnE,CACF,EAAE,KAAK","names":["staticCssLiteral_exports","__export","css","strings","values","value"]}
|
|
@@ -145,7 +145,7 @@ module.exports = function (babel, options) {
|
|
|
145
145
|
throw new Error("filePath is undefined");
|
|
146
146
|
}
|
|
147
147
|
const fileName = basename(filePath).replace(/\.tsx?/, "");
|
|
148
|
-
// Import '
|
|
148
|
+
// Import 'next-yak' styles and assign to '__styleYak'
|
|
149
149
|
// use webpacks !=! syntax to pretend that the typescript file is actually a css-module
|
|
150
150
|
path.insertAfter(
|
|
151
151
|
t.importDeclaration(
|
|
@@ -170,6 +170,7 @@ module.exports = function (babel, options) {
|
|
|
170
170
|
specifier.imported
|
|
171
171
|
);
|
|
172
172
|
const localSpecifier = specifier.local || importSpecifier;
|
|
173
|
+
|
|
173
174
|
if (
|
|
174
175
|
importSpecifier.name === "styled" ||
|
|
175
176
|
importSpecifier.name === "css" ||
|
|
@@ -211,7 +212,7 @@ module.exports = function (babel, options) {
|
|
|
211
212
|
replaceQuasiExpressionTokens(
|
|
212
213
|
path.node.quasi,
|
|
213
214
|
(name) => {
|
|
214
|
-
// Replace
|
|
215
|
+
// Replace constants from .yak files and
|
|
215
216
|
if (name in replaces) {
|
|
216
217
|
return replaces[name];
|
|
217
218
|
}
|
|
@@ -247,13 +248,15 @@ module.exports = function (babel, options) {
|
|
|
247
248
|
const variableName =
|
|
248
249
|
styledApi || expressionType === "keyframesLiteral"
|
|
249
250
|
? getStyledComponentName(path)
|
|
250
|
-
: expressionType === "cssLiteral"
|
|
251
|
-
|
|
251
|
+
: expressionType === "cssLiteral"
|
|
252
|
+
? getCssName(path)
|
|
252
253
|
: null;
|
|
253
254
|
|
|
254
255
|
const identifier = localIdent(
|
|
255
256
|
variableName || "_yak",
|
|
256
|
-
variableName && expressionType !== "cssLiteral"
|
|
257
|
+
variableName && expressionType !== "cssLiteral"
|
|
258
|
+
? null
|
|
259
|
+
: this.classNameCount++,
|
|
257
260
|
expressionType === "keyframesLiteral" ? "animation" : "className"
|
|
258
261
|
);
|
|
259
262
|
|
|
@@ -345,7 +348,8 @@ module.exports = function (babel, options) {
|
|
|
345
348
|
if (quasiTypes[i].currentNestingScopes.length > 0) {
|
|
346
349
|
// inside a nested scope a foreign css literal must not be used
|
|
347
350
|
// as we can not forward the scope
|
|
348
|
-
const isReferenceToMixin =
|
|
351
|
+
const isReferenceToMixin =
|
|
352
|
+
t.isIdentifier(expression) || t.isCallExpression(expression);
|
|
349
353
|
if (isReferenceToMixin) {
|
|
350
354
|
throw new InvalidPositionError(
|
|
351
355
|
`Mixins are not allowed inside nested selectors`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-yak",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/",
|
|
6
6
|
"exports": {
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"import": "./dist/index.js",
|
|
9
9
|
"require": "./dist/index.cjs"
|
|
10
10
|
},
|
|
11
|
+
"./static": {
|
|
12
|
+
"import": "./dist/static/index.js",
|
|
13
|
+
"require": "./dist/static/index.cjs"
|
|
14
|
+
},
|
|
11
15
|
"./withYak": {
|
|
12
16
|
"require": "./withYak/index.cjs"
|
|
13
17
|
},
|
|
@@ -27,15 +31,19 @@
|
|
|
27
31
|
}
|
|
28
32
|
},
|
|
29
33
|
"scripts": {
|
|
30
|
-
"prepublishOnly": "npm run build && npm run test",
|
|
34
|
+
"prepublishOnly": "npm run build && npm run test && npm run test:types:code && npm run test:types:test",
|
|
31
35
|
"build": "pnpm run --filter . \"/^build:/\"",
|
|
32
36
|
"build:runtime": "tsup runtime/index.ts --target es2022 --clean --external react --external next-yak/context --format cjs,esm --minify --sourcemap --out-dir dist",
|
|
33
37
|
"build:runtime:types": "tsup runtime/index.ts --target es2022 --clean --external react --dts-only --format cjs,esm --minify --sourcemap --out-dir dist",
|
|
38
|
+
"build:static": "tsup static/index.ts --target es2022 --clean --external react --external next-yak/context --format cjs,esm --minify --sourcemap --out-dir dist/static",
|
|
39
|
+
"build:static:types": "tsup static/index.ts --target es2022 --clean --external react --dts-only --format cjs,esm --minify --sourcemap --out-dir dist/static",
|
|
34
40
|
"build:baseContext": "tsup runtime/context/baseContext.tsx --target es2022 --external react --dts --format cjs,esm --sourcemap --out-dir dist/context/",
|
|
35
41
|
"build:context:client": "tsup runtime/context/index.tsx --target es2022 --external react --external next-yak/context/baseContext --dts --format cjs,esm --sourcemap --out-dir dist/context/",
|
|
36
42
|
"build:context:server": "tsup runtime/context/index.server.tsx --target es2022 --external react --external next-yak/context/baseContext --external ./index.js --format cjs,esm --sourcemap --out-dir dist/context/",
|
|
37
43
|
"build:withYak": "tsup withYak/index.ts --target es2022 --dts --format cjs --sourcemap --out-dir withYak --external ../loaders/tsloader.cjs --external ../loaders/cssloader.cjs",
|
|
38
|
-
"test": "vitest run
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:types:code": "tsc -p tsconfig.json",
|
|
46
|
+
"test:types:test": "tsc -p ./runtime/__tests__/tsconfig.json",
|
|
39
47
|
"test:watch": "vitest --watch"
|
|
40
48
|
},
|
|
41
49
|
"dependencies": {
|