@stingjs/stylex 1.0.0-bootstrap.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/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@stingjs/stylex",
3
+ "version": "1.0.0-bootstrap.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./src/index.ts"
7
+ },
8
+ "scripts": {
9
+ "test": "vitest run src/*.test.ts",
10
+ "typecheck": "tsc -p tsconfig.json --noEmit"
11
+ },
12
+ "dependencies": {
13
+ "@stingjs/native": "1.0.0-bootstrap.0"
14
+ },
15
+ "devDependencies": {
16
+ "@babel/core": "7.29.7",
17
+ "@stylexjs/babel-plugin": "0.19.0"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/chrisbirster/stingjs.git",
22
+ "directory": "packages/stylex"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "license": "MIT"
28
+ }
@@ -0,0 +1,119 @@
1
+ import { transformSync } from '@babel/core';
2
+ import stylexPlugin from '@stylexjs/babel-plugin';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { create, props } from './index';
5
+
6
+ const compilerOptions = {
7
+ dev: false,
8
+ runtimeInjection: false,
9
+ importSources: ['@stingjs/stylex'],
10
+ } as const;
11
+
12
+ describe('@stingjs/stylex', () => {
13
+ it('keeps StyleX create definitions reusable as Sting native sx input', () => {
14
+ const styles = create({
15
+ screen: { backgroundColor: '#09090b', padding: 16 },
16
+ selected: { opacity: 0.8 },
17
+ });
18
+
19
+ expect(styles.screen.backgroundColor).toBe('#09090b');
20
+ expect(styles.selected.opacity).toBe(0.8);
21
+ });
22
+
23
+ it('maps StyleX composition into Sting sx props on native builds', () => {
24
+ const styles = create({
25
+ card: { borderRadius: 12 },
26
+ selected: { opacity: 0.8 },
27
+ });
28
+
29
+ expect(props(styles.card, false, styles.selected)).toEqual({
30
+ sx: [styles.card, false, styles.selected],
31
+ });
32
+ });
33
+
34
+ it('compiles the complete portable Style IR through the official StyleX compiler', () => {
35
+ const result = transformSync(
36
+ `
37
+ import * as stylex from '@stingjs/stylex';
38
+ const styles = stylex.create({
39
+ layout: {
40
+ flexDirection: 'row',
41
+ alignItems: 'center',
42
+ justifyContent: 'center',
43
+ gap: 12,
44
+ padding: 16,
45
+ width: 320,
46
+ height: 48,
47
+ backgroundColor: '#09090b',
48
+ color: '#ffffff',
49
+ fontSize: 16,
50
+ fontWeight: 600,
51
+ borderRadius: 12,
52
+ opacity: 0.9,
53
+ },
54
+ edges: {
55
+ paddingTop: 8,
56
+ paddingRight: 12,
57
+ paddingBottom: 8,
58
+ paddingLeft: 12,
59
+ },
60
+ });
61
+ export const layout = styles.layout;
62
+ export const edges = styles.edges;
63
+ `,
64
+ {
65
+ filename: '/virtual/sting-stylex-web.js',
66
+ babelrc: false,
67
+ configFile: false,
68
+ plugins: [[stylexPlugin, compilerOptions]],
69
+ },
70
+ );
71
+
72
+ const metadata = result?.metadata as { stylex?: readonly unknown[] } | undefined;
73
+ expect(result?.code).not.toContain('stylex.create');
74
+ expect(metadata?.stylex?.length).toBeGreaterThan(0);
75
+ });
76
+
77
+ it('lets the official compiler lower the sx JSX bridge for web builds', () => {
78
+ const result = transformSync(
79
+ `
80
+ import * as stylex from '@stingjs/stylex';
81
+ const styles = stylex.create({ root: { color: '#18181b' } });
82
+ export const node = <div sx={styles.root}>Hello</div>;
83
+ `,
84
+ {
85
+ filename: '/virtual/sting-stylex-web.jsx',
86
+ babelrc: false,
87
+ configFile: false,
88
+ parserOpts: { plugins: ['jsx'] },
89
+ plugins: [[stylexPlugin, compilerOptions]],
90
+ },
91
+ );
92
+
93
+ const metadata = result?.metadata as { stylex?: readonly unknown[] } | undefined;
94
+ expect(result?.code).not.toContain(' sx=');
95
+ expect(result?.code).toContain('className');
96
+ expect(metadata?.stylex?.length).toBeGreaterThan(0);
97
+ });
98
+
99
+ it('lets the official compiler lower stylex.props for web component authors', () => {
100
+ const result = transformSync(
101
+ `
102
+ import * as stylex from '@stingjs/stylex';
103
+ const styles = stylex.create({ root: { color: '#18181b', opacity: 0.9 } });
104
+ export const attrs = stylex.props(styles.root);
105
+ `,
106
+ {
107
+ filename: '/virtual/sting-stylex-props-web.js',
108
+ babelrc: false,
109
+ configFile: false,
110
+ plugins: [[stylexPlugin, compilerOptions]],
111
+ },
112
+ );
113
+
114
+ const metadata = result?.metadata as { stylex?: readonly unknown[] } | undefined;
115
+ expect(result?.code).not.toContain('stylex.props');
116
+ expect(result?.code).toContain('className');
117
+ expect(metadata?.stylex?.length).toBeGreaterThan(0);
118
+ });
119
+ });
package/src/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { Style, SxInput } from '@stingjs/native';
2
+
3
+ export type StyleXDefinition = Readonly<Record<string, Style>>;
4
+ export type StyleXStyles<T extends Style = Style> =
5
+ | T
6
+ | readonly StyleXStyles<T>[]
7
+ | false
8
+ | null
9
+ | undefined;
10
+
11
+ /**
12
+ * Native half of Sting's StyleX integration.
13
+ *
14
+ * Application code uses StyleX's `create` + composition model. On Sting native
15
+ * builds these static definitions remain typed style values that feed `sx` and
16
+ * lower into the Sting Style IR. A web build can configure the official StyleX
17
+ * compiler to recognize this package as an import source and emit atomic CSS.
18
+ * CSS classes are never interpreted by the native runtime.
19
+ */
20
+ export function create<const T extends StyleXDefinition>(styles: T): T {
21
+ return styles;
22
+ }
23
+
24
+ /** Compose StyleX definitions into the `sx` prop consumed by @stingjs/native. */
25
+ export function props(...styles: readonly SxInput[]): { readonly sx: readonly SxInput[] } {
26
+ return { sx: styles };
27
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src"
5
+ },
6
+ "include": ["src"]
7
+ }