@styleframe/transpiler 1.0.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.
Files changed (57) hide show
  1. package/.tsbuildinfo +1 -0
  2. package/CHANGELOG.md +12 -0
  3. package/package.json +43 -0
  4. package/src/constants.ts +4 -0
  5. package/src/consume/at-rule.test.ts +339 -0
  6. package/src/consume/at-rule.ts +34 -0
  7. package/src/consume/consume.test.ts +259 -0
  8. package/src/consume/consume.ts +60 -0
  9. package/src/consume/container.test.ts +501 -0
  10. package/src/consume/container.ts +73 -0
  11. package/src/consume/css.test.ts +184 -0
  12. package/src/consume/css.ts +17 -0
  13. package/src/consume/declarations.test.ts +210 -0
  14. package/src/consume/declarations.ts +17 -0
  15. package/src/consume/index.ts +12 -0
  16. package/src/consume/primitive.test.ts +52 -0
  17. package/src/consume/primitive.ts +16 -0
  18. package/src/consume/ref.test.ts +84 -0
  19. package/src/consume/ref.ts +22 -0
  20. package/src/consume/root.test.ts +353 -0
  21. package/src/consume/root.ts +19 -0
  22. package/src/consume/selector.test.ts +441 -0
  23. package/src/consume/selector.ts +17 -0
  24. package/src/consume/theme.test.ts +215 -0
  25. package/src/consume/theme.ts +15 -0
  26. package/src/consume/utility.test.ts +696 -0
  27. package/src/consume/utility.ts +31 -0
  28. package/src/consume/variable.test.ts +197 -0
  29. package/src/consume/variable.ts +20 -0
  30. package/src/defaults.ts +21 -0
  31. package/src/generator/genAtRuleQuery.test.ts +148 -0
  32. package/src/generator/genAtRuleQuery.ts +3 -0
  33. package/src/generator/genDeclaration.test.ts +283 -0
  34. package/src/generator/genDeclaration.ts +9 -0
  35. package/src/generator/genDeclarationsBlock.test.ts +278 -0
  36. package/src/generator/genDeclarationsBlock.ts +7 -0
  37. package/src/generator/genDeclareVariable.test.ts +323 -0
  38. package/src/generator/genDeclareVariable.ts +6 -0
  39. package/src/generator/genInlineAtRule.test.ts +351 -0
  40. package/src/generator/genInlineAtRule.ts +5 -0
  41. package/src/generator/genReferenceVariable.test.ts +392 -0
  42. package/src/generator/genReferenceVariable.ts +5 -0
  43. package/src/generator/genSafePropertyName.test.ts +489 -0
  44. package/src/generator/genSafePropertyName.ts +5 -0
  45. package/src/generator/genSafeVariableName.test.ts +358 -0
  46. package/src/generator/genSafeVariableName.ts +21 -0
  47. package/src/generator/genSelector.test.ts +357 -0
  48. package/src/generator/genSelector.ts +5 -0
  49. package/src/generator/index.ts +9 -0
  50. package/src/index.ts +6 -0
  51. package/src/transpile.test.ts +825 -0
  52. package/src/transpile.ts +21 -0
  53. package/src/types.ts +15 -0
  54. package/src/utils.ts +18 -0
  55. package/src/vite-env.d.ts +1 -0
  56. package/tsconfig.json +7 -0
  57. package/vite.config.ts +5 -0
@@ -0,0 +1,21 @@
1
+ import type { Styleframe } from "@styleframe/core";
2
+ import { consume } from "./consume";
3
+ import type { Output, OutputFile } from "./types";
4
+
5
+ export function createFile(name: string, content: string = ""): OutputFile {
6
+ return {
7
+ name,
8
+ content,
9
+ };
10
+ }
11
+
12
+ export function transpile(instance: Styleframe): Output {
13
+ const output: Output = { files: [] };
14
+ const options = instance.options;
15
+
16
+ const indexFile = createFile("index.css", consume(instance.root, options));
17
+
18
+ output.files.push(indexFile);
19
+
20
+ return output;
21
+ }
package/src/types.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { StyleframeOptions } from "@styleframe/core";
2
+
3
+ export type OutputFile = {
4
+ name: string;
5
+ content: string;
6
+ };
7
+
8
+ export type Output = {
9
+ files: OutputFile[];
10
+ };
11
+
12
+ export type ConsumeFunction = (
13
+ instance: unknown,
14
+ options: StyleframeOptions,
15
+ ) => string;
package/src/utils.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { DEFAULT_INDENT } from "./constants";
2
+ import { kebabCase } from "scule";
3
+ import type { KebabCase } from "scule";
4
+
5
+ export function addIndentToLine(line: string): string {
6
+ return `${DEFAULT_INDENT}${line}`;
7
+ }
8
+
9
+ export function indentLines(lines: string): string {
10
+ return lines
11
+ .split("\n")
12
+ .map((line) => addIndentToLine(line))
13
+ .join("\n");
14
+ }
15
+
16
+ export function toKebabCase<S extends string>(str: S): KebabCase<S> {
17
+ return kebabCase(str);
18
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "@styleframe/config-typescript",
3
+ "compilerOptions": {
4
+ "tsBuildInfoFile": ".tsbuildinfo"
5
+ },
6
+ "include": ["src/**/*.ts", "tsup.config.ts", "vite.config.ts"]
7
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { createViteConfig } from "@styleframe/config-vite";
2
+
3
+ const __dirname = new URL(".", import.meta.url).pathname;
4
+
5
+ export default createViteConfig("transpiler", __dirname);