@kirana-style/ember 0.0.0-stage → 0.1.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 +27 -2
- package/package.json +50 -4
- package/src/index.d.ts +5 -0
- package/src/index.js +18 -0
- package/src/vite.d.ts +9 -0
- package/src/vite.js +41 -0
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kirana-style/ember
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Kirana for Ember on Embroider and Vite (D-072): `css()` in `.gjs` and `.gts` files, and `sx` to merge
|
|
4
|
+
handles in templates.
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
// vite.config.mjs — Kirana last, after Embroider's plugins
|
|
8
|
+
plugins: [
|
|
9
|
+
classicEmberSupport(),
|
|
10
|
+
ember(),
|
|
11
|
+
babel({ babelHelpers: "runtime", extensions }),
|
|
12
|
+
kiranaEmber(),
|
|
13
|
+
]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
// app/components/card.gjs
|
|
18
|
+
import { css } from "@kirana-style/core"
|
|
19
|
+
import { sx } from "@kirana-style/ember"
|
|
20
|
+
|
|
21
|
+
const styles = { card: css({ padding: "1rem" }), active: css({ outline: "2px solid" }) }
|
|
22
|
+
|
|
23
|
+
<template><div class={{sx styles.card (if @active styles.active)}}>{{yield}}</div></template>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`kiranaEmber()` is the Vite adapter run after Embroider, taking template-tag modules, with Ember's
|
|
27
|
+
own modules (`@ember/`, `@glimmer/`, `@embroider/virtual/`) as `externals`. `createSx(prefix)` makes
|
|
28
|
+
the helper for another `names.prefix`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirana-style/ember",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Kirana for Ember on Embroider and Vite: css() in .gjs and .gts files, and the sx template helper.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "The Kirana authors",
|
|
7
|
+
"homepage": "https://kirana.style",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/kirana-style/kirana.git",
|
|
11
|
+
"directory": "packages/kirana/npm/ember"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/kirana-style/kirana/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./src/index.d.ts",
|
|
20
|
+
"default": "./src/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./vite": {
|
|
23
|
+
"types": "./src/vite.d.ts",
|
|
24
|
+
"default": "./src/vite.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@kirana-style/core": "0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@kirana-style/vite": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@kirana-style/vite": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"src",
|
|
41
|
+
"bin",
|
|
42
|
+
"*.d.ts",
|
|
43
|
+
"*.css",
|
|
44
|
+
"README.md",
|
|
45
|
+
"builders.json",
|
|
46
|
+
"schemas",
|
|
47
|
+
"gatsby-node.mjs",
|
|
48
|
+
"rules",
|
|
49
|
+
"recommended.json",
|
|
50
|
+
"strict.json"
|
|
51
|
+
]
|
|
52
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Handle } from "@kirana-style/core/internal";
|
|
2
|
+
/** A merge helper for another class-name prefix (`names.prefix`). */
|
|
3
|
+
export declare function createSx(prefix: string): (...handles: Handle[]) => string;
|
|
4
|
+
/** The merge helper for the default prefix, `k`. */
|
|
5
|
+
export declare const sx: (...handles: Handle[]) => string;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sx` for Ember templates (D-072). A template reaches the handles in its module's scope, but the
|
|
3
|
+
* merge `sx` does at build time elsewhere needs a function here: `class={{sx styles.card (if
|
|
4
|
+
* this.active styles.on)}}` merges the handles with Kirana's runtime, later ones winning, as an
|
|
5
|
+
* `sx` list does. Ember calls a plain function as a helper.
|
|
6
|
+
*
|
|
7
|
+
* A handle with values known only at runtime carries custom properties a class cannot hold; set
|
|
8
|
+
* those from the component's code, as the [Ember guide](https://kirana.style/docs/frameworks/ember)
|
|
9
|
+
* shows.
|
|
10
|
+
*/
|
|
11
|
+
import { runtime } from "@kirana-style/core/internal";
|
|
12
|
+
/** A merge helper for another class-name prefix (`names.prefix`). */
|
|
13
|
+
export function createSx(prefix) {
|
|
14
|
+
const kirana = runtime(prefix, "class");
|
|
15
|
+
return (...handles) => kirana.sx(handles, [], []).class ?? "";
|
|
16
|
+
}
|
|
17
|
+
/** The merge helper for the default prefix, `k`. */
|
|
18
|
+
export const sx = createSx("k");
|
package/src/vite.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { KiranaViteOptions } from "@kirana-style/vite";
|
|
2
|
+
import type { Plugin } from "vite";
|
|
3
|
+
export type { KiranaViteOptions as KiranaEmberOptions };
|
|
4
|
+
/** Ember's template-tag modules, as Vite names them. */
|
|
5
|
+
export declare const TEMPLATE_TAG: RegExp;
|
|
6
|
+
/** What Embroider resolves and Node.js cannot: Ember's own modules. */
|
|
7
|
+
export declare const EMBER_EXTERNALS: string[];
|
|
8
|
+
export declare function kiranaEmber(options?: KiranaViteOptions): Plugin[];
|
|
9
|
+
export default kiranaEmber;
|
package/src/vite.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kirana for Ember on Embroider and Vite (D-072). A `.gjs` or `.gts` file holds a `<template>`
|
|
3
|
+
* Kirana's parser does not read, so its Vite plugin runs after Embroider's instead and compiles the
|
|
4
|
+
* JavaScript Embroider emitted for each module, where `css()` calls and their imports are as written.
|
|
5
|
+
* Its transform takes those modules too, which a Vite plugin's filter would otherwise skip, and
|
|
6
|
+
* `@ember/`, `@glimmer/` and `@embroider/virtual/` — modules only Embroider resolves — are runtime values (`externals`).
|
|
7
|
+
*
|
|
8
|
+
* plugins: [classicEmberSupport(), ember(), babel({ … }), kiranaEmber()]
|
|
9
|
+
*/
|
|
10
|
+
import kirana from "@kirana-style/vite";
|
|
11
|
+
/** Ember's template-tag modules, as Vite names them. */
|
|
12
|
+
export const TEMPLATE_TAG = /\.g[jt]s(?:[?#]|$)/;
|
|
13
|
+
/** What Embroider resolves and Node.js cannot: Ember's own modules. */
|
|
14
|
+
export const EMBER_EXTERNALS = ["@ember/", "@glimmer/", "@embroider/virtual/"];
|
|
15
|
+
export function kiranaEmber(options = {}) {
|
|
16
|
+
// Inline options override `kirana.config` key by key, so a project's own `externals` go here.
|
|
17
|
+
const externals = [...(options.config?.externals ?? []), ...EMBER_EXTERNALS];
|
|
18
|
+
const [main, late] = kirana({
|
|
19
|
+
...options,
|
|
20
|
+
config: { ...options.config, externals },
|
|
21
|
+
});
|
|
22
|
+
const transform = main.transform;
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
...main,
|
|
26
|
+
enforce: "post",
|
|
27
|
+
transform: {
|
|
28
|
+
...transform,
|
|
29
|
+
filter: {
|
|
30
|
+
...transform.filter,
|
|
31
|
+
id: {
|
|
32
|
+
...transform.filter.id,
|
|
33
|
+
include: [transform.filter.id.include, TEMPLATE_TAG],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
late,
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
export default kiranaEmber;
|