@salty-css/vite 0.1.0-feat-define-font.0 → 0.1.0-feat-define-import.0
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 +33 -72
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ To get help with problems, [Join Salty CSS Discord server](https://discord.gg/R6
|
|
|
57
57
|
- [defineVariables](#variables) - create CSS variables (tokens) that can be used in any styling function
|
|
58
58
|
- [defineMediaQuery](#media-queries) - create CSS media queries and use them in any styling function
|
|
59
59
|
- [defineTemplates](#templates) - create reusable templates that can be applied when same styles are used over and over again
|
|
60
|
-
- [
|
|
60
|
+
- [defineImport](#importing-additional-css) - pull in external CSS files (relative, public, node_modules, or URL)
|
|
61
61
|
- [keyframes](#keyframes-animations) - create CSS keyframes animation that can be used and imported in any styling function
|
|
62
62
|
|
|
63
63
|
### Styling helpers & utility
|
|
@@ -320,86 +320,47 @@ Example usage:
|
|
|
320
320
|
styled('div', { base: { textStyle: 'headline.large', card: '20px' } });
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
-
##
|
|
323
|
+
## Importing additional CSS
|
|
324
324
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
The returned object stringifies to its `font-family` value and exposes helpers for explicit usage:
|
|
328
|
-
|
|
329
|
-
- `Font.variable` → CSS variable name (e.g. `--font-inter`)
|
|
330
|
-
- `Font.fontFamily` → final `font-family` string with fallbacks
|
|
331
|
-
- `Font.className` → class that sets the variable + applies the font on a subtree
|
|
332
|
-
- `Font.style` → object you can spread on a React `style` prop
|
|
325
|
+
Use `defineImport` to pull in CSS that lives outside of Salty's authoring API — a reset stylesheet from npm, a Google Fonts URL, an asset in your app's `public/` folder, or a sibling `.css` file. The compiler turns each spec into an `@import` rule in the generated `saltygen/index.css`, so the imported stylesheets travel with the rest of your build.
|
|
333
326
|
|
|
334
327
|
```ts
|
|
335
|
-
// /styles/
|
|
336
|
-
import {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
//
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
{
|
|
354
|
-
weight: 700,
|
|
355
|
-
style: 'normal',
|
|
356
|
-
// Multiple sources can be a string array — first entry is preferred;
|
|
357
|
-
// the browser picks the first format it supports.
|
|
358
|
-
src: ['/fonts/inter-700.woff2', '/fonts/inter-700.ttf'],
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
weight: 400,
|
|
362
|
-
style: 'italic',
|
|
363
|
-
// Use the `{ url, format }` object form when the URL has no recognisable
|
|
364
|
-
// extension (signed CDN URLs, query-only endpoints, etc.). You can also
|
|
365
|
-
// mix strings and objects in the same array.
|
|
366
|
-
src: ['/fonts/inter-400-italic.woff2', { url: 'https://cdn.example.com/inter-italic', format: 'woff' }],
|
|
367
|
-
},
|
|
368
|
-
],
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
// 2. Remote stylesheet (Google Fonts, etc.). Emits `@import url(...)` and still
|
|
372
|
-
// registers the CSS variable so usage stays the same as the @font-face flow.
|
|
373
|
-
export const InterCdn = defineFont({
|
|
374
|
-
name: 'Inter',
|
|
375
|
-
variable: '--font-inter',
|
|
376
|
-
import: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap',
|
|
377
|
-
});
|
|
328
|
+
// /styles/imports.css.ts
|
|
329
|
+
import { defineImport } from '@salty-css/core/factories';
|
|
330
|
+
|
|
331
|
+
export default defineImport(
|
|
332
|
+
// Relative to this file
|
|
333
|
+
'./reset.css',
|
|
334
|
+
// From node_modules (bare specifier — same as Vite / native CSS @import)
|
|
335
|
+
'modern-normalize/modern-normalize.css',
|
|
336
|
+
// From node_modules (~ prefix — same resolver, webpack-style)
|
|
337
|
+
'~normalize.css/normalize.css',
|
|
338
|
+
// From your app's public/ folder (served at the host root)
|
|
339
|
+
'/fonts/inter.css',
|
|
340
|
+
// External URL
|
|
341
|
+
'https://fonts.googleapis.com/css2?family=Inter&display=swap',
|
|
342
|
+
// Object form — attach media or supports() conditions
|
|
343
|
+
{ url: './print.css', media: 'print' },
|
|
344
|
+
{ url: './p3.css', supports: 'color(display-p3 1 1 1)' }
|
|
345
|
+
);
|
|
378
346
|
```
|
|
379
347
|
|
|
380
|
-
|
|
348
|
+
Path resolution:
|
|
381
349
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
350
|
+
| Pattern | Behaviour |
|
|
351
|
+
| --------------------------- | ---------------------------------------------------------------------------------------- |
|
|
352
|
+
| `http://`, `https://`, `//` | Emitted verbatim |
|
|
353
|
+
| Starts with `/` | Public-folder URL — emitted verbatim, the browser resolves it against your host |
|
|
354
|
+
| Starts with `./` or `../` | Resolved at build time relative to the file that called `defineImport` |
|
|
355
|
+
| `~package/file.css` | Stripped of the leading `~`, then resolved from `node_modules` and copied into the build |
|
|
356
|
+
| `package/file.css` (bare) | Same `node_modules` resolution as the `~` form |
|
|
385
357
|
|
|
386
|
-
|
|
387
|
-
// This sets `--font-inter` on the subtree and applies `font-family: var(--font-inter)`.
|
|
388
|
-
export const App = ({ children }) => <div className={Inter.className}>{children}</div>;
|
|
358
|
+
All imports are placed inside a new `imports` cascade layer that sits **before** `reset`, `global`, `templates`, and your component styles. This means your own styles always win over third-party CSS you pull in — which is what most teams expect when they drop in something like `modern-normalize`.
|
|
389
359
|
|
|
390
|
-
|
|
391
|
-
export const Heading = styled('h1', {
|
|
392
|
-
base: {
|
|
393
|
-
fontFamily: `${Inter}`,
|
|
394
|
-
},
|
|
395
|
-
});
|
|
360
|
+
The full layer order in the generated `index.css` is:
|
|
396
361
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
base: {
|
|
400
|
-
fontFamily: `var(${Inter.variable})`,
|
|
401
|
-
},
|
|
402
|
-
});
|
|
362
|
+
```css
|
|
363
|
+
@layer imports, reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
|
403
364
|
```
|
|
404
365
|
|
|
405
366
|
## Keyframes animations
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salty-css/vite",
|
|
3
|
-
"version": "0.1.0-feat-define-
|
|
3
|
+
"version": "0.1.0-feat-define-import.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@salty-css/core": "^0.1.0-feat-define-
|
|
37
|
+
"@salty-css/core": "^0.1.0-feat-define-import.0",
|
|
38
38
|
"vite": "^6.4.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|