@cssints/css-grammar 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.
@@ -0,0 +1,12 @@
1
+ import { ParseError, TwinError } from "./errors.mjs";
2
+ import { Node, nullable } from "./twin-core.mjs";
3
+ import { Effect } from "effect";
4
+ //#region src/twin.d.ts
5
+ /** The grammar as a tree, memoized by its text. */
6
+ export declare const parse: (grammar: string) => Effect.Effect<Node, ParseError, never>;
7
+ /** Whether `s` is a complete value of the grammar `syntax`; `pending`: a var(), env() or if() in it stands for any value. */
8
+ export declare const matches: (syntax: string, s: string, pending?: boolean | undefined) => Effect.Effect<boolean, TwinError, never>;
9
+ /** Twin of Valid<P, S>: the value, or the furthest point it reached and what the grammar expected there. */
10
+ export declare const valid: (p: string, s: string) => Effect.Effect<string, TwinError, never>;
11
+ //#endregion
12
+ export { type Node, nullable };
package/dist/twin.mjs ADDED
@@ -0,0 +1,38 @@
1
+ import { ParseError, isTwinError } from "./errors.mjs";
2
+ import { matches as matches$1, nullable, parseGrammar, valid as valid$1 } from "./twin-core.mjs";
3
+ import { Effect } from "effect";
4
+ //#region src/twin.ts
5
+ const grammarError = (grammar, e) => isTwinError(e) ? e : new ParseError({
6
+ message: `grammar: ${String(e)}`,
7
+ grammar,
8
+ position: 0,
9
+ expected: []
10
+ });
11
+ /** The grammar as a tree, memoized by its text. */
12
+ const parse = Effect.fn("twin.parse")(function* (grammar) {
13
+ return yield* Effect.try({
14
+ try: () => parseGrammar(grammar),
15
+ catch: (e) => e instanceof ParseError ? e : new ParseError({
16
+ message: `grammar: ${String(e)}`,
17
+ grammar,
18
+ position: 0,
19
+ expected: []
20
+ })
21
+ });
22
+ });
23
+ /** Whether `s` is a complete value of the grammar `syntax`; `pending`: a var(), env() or if() in it stands for any value. */
24
+ const matches = Effect.fnUntraced(function* (syntax, s, pending) {
25
+ return yield* Effect.try({
26
+ try: () => matches$1(syntax, s, pending),
27
+ catch: (e) => grammarError(syntax, e)
28
+ });
29
+ });
30
+ /** Twin of Valid<P, S>: the value, or the furthest point it reached and what the grammar expected there. */
31
+ const valid = Effect.fnUntraced(function* (p, s) {
32
+ return yield* Effect.try({
33
+ try: () => valid$1(p, s),
34
+ catch: (e) => grammarError(p, e)
35
+ });
36
+ });
37
+ //#endregion
38
+ export { matches, nullable, parse, valid };
@@ -0,0 +1,28 @@
1
+ //#region src/values.d.ts
2
+ export declare class CSSStyleValue<T extends string = string> {
3
+ readonly "~type": T;
4
+ }
5
+ export declare class CSSUnitValue<T extends string = string> extends CSSStyleValue<T> {
6
+ readonly value: number;
7
+ readonly unit: string;
8
+ constructor(value: number, unit: string);
9
+ toString(): string;
10
+ }
11
+ export declare class CSSColorValue extends CSSStyleValue<"color"> {
12
+ readonly value: string;
13
+ constructor(value: string);
14
+ toString(): string;
15
+ }
16
+ export declare class CSSImageValue extends CSSStyleValue<"image"> {
17
+ readonly value: string;
18
+ constructor(value: string);
19
+ toString(): string;
20
+ }
21
+ export declare const CSS: {
22
+ px: (v: number) => CSSUnitValue<"length">;
23
+ rem: (v: number) => CSSUnitValue<"length">;
24
+ em: (v: number) => CSSUnitValue<"length">;
25
+ percent: (v: number) => CSSUnitValue<"percentage">;
26
+ number: (v: number) => CSSUnitValue<"number">;
27
+ };
28
+ //#endregion
@@ -0,0 +1,44 @@
1
+ //#region src/values.ts
2
+ var CSSStyleValue = class {};
3
+ var CSSUnitValue = class extends CSSStyleValue {
4
+ value;
5
+ unit;
6
+ constructor(value, unit) {
7
+ super();
8
+ this.value = value;
9
+ this.unit = unit;
10
+ }
11
+ toString() {
12
+ return `${this.value}${this.unit === "percent" ? "%" : this.unit === "number" ? "" : this.unit}`;
13
+ }
14
+ };
15
+ var CSSColorValue = class extends CSSStyleValue {
16
+ value;
17
+ constructor(value) {
18
+ super();
19
+ this.value = value;
20
+ }
21
+ toString() {
22
+ return this.value;
23
+ }
24
+ };
25
+ var CSSImageValue = class extends CSSStyleValue {
26
+ value;
27
+ constructor(value) {
28
+ super();
29
+ this.value = value;
30
+ }
31
+ toString() {
32
+ return this.value;
33
+ }
34
+ };
35
+ const unit = (u) => (v) => new CSSUnitValue(v, u);
36
+ const CSS = {
37
+ px: unit("px"),
38
+ rem: unit("rem"),
39
+ em: unit("em"),
40
+ percent: unit("percent"),
41
+ number: unit("number")
42
+ };
43
+ //#endregion
44
+ export { CSS, CSSColorValue, CSSImageValue, CSSStyleValue, CSSUnitValue };
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@cssints/css-grammar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Type-level and runtime recognizer of CSS values over mdn-data grammars (the engine of cssints)",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/alexeiaccio/css-in-ts-compiler.git",
9
+ "directory": "packages/css-grammar"
10
+ },
11
+ "homepage": "https://cssints.dev",
12
+ "files": [
13
+ "dist",
14
+ "THIRD_PARTY_NOTICES.md"
15
+ ],
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "exports": {
19
+ "./*": {
20
+ "types": "./dist/*.d.mts",
21
+ "default": "./dist/*.mjs"
22
+ }
23
+ },
24
+ "dependencies": {
25
+ "@mdn/browser-compat-data": "8.1.3",
26
+ "browserslist": "4.29.1",
27
+ "effect": "4.0.0"
28
+ },
29
+ "engines": {
30
+ "node": ">=22"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }