@homebound/truss 2.0.0-next.7 → 2.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.
- package/build/index.js +15 -2
- package/build/index.js.map +1 -1
- package/build/plugin/index.d.ts +2 -0
- package/build/plugin/index.js +450 -77
- package/build/plugin/index.js.map +1 -1
- package/build/runtime.d.ts +18 -0
- package/build/runtime.js +56 -0
- package/build/runtime.js.map +1 -0
- package/package.json +7 -3
- package/tsup.config.ts +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as stylex from '@stylexjs/stylex';
|
|
2
|
+
|
|
3
|
+
declare class TrussDebugInfo {
|
|
4
|
+
/** A compact `FileName.tsx:line` source label for a Truss CSS expression. */
|
|
5
|
+
readonly src: string;
|
|
6
|
+
constructor(src: string);
|
|
7
|
+
}
|
|
8
|
+
/** Call StyleX while stripping Truss debug sentinels from the style list. */
|
|
9
|
+
declare function trussProps(stylexNs: typeof stylex, ...styles: unknown[]): Record<string, unknown>;
|
|
10
|
+
declare function mergeProps(stylexNs: typeof stylex, explicitClassName: string, ...styles: unknown[]): Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Coerce maybe-array StyleX inputs into arrays, guarding against nullish/false and plain object values.
|
|
13
|
+
*
|
|
14
|
+
* I.e. `...asStyleArray(xss)` stays safe when destructured `xss` is `undefined`.
|
|
15
|
+
*/
|
|
16
|
+
declare function asStyleArray(styles: unknown): ReadonlyArray<unknown>;
|
|
17
|
+
|
|
18
|
+
export { TrussDebugInfo, asStyleArray, mergeProps, trussProps };
|
package/build/runtime.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/runtime.ts
|
|
2
|
+
var TrussDebugInfo = class {
|
|
3
|
+
/** A compact `FileName.tsx:line` source label for a Truss CSS expression. */
|
|
4
|
+
src;
|
|
5
|
+
constructor(src) {
|
|
6
|
+
this.src = src;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
function trussProps(stylexNs, ...styles) {
|
|
10
|
+
const { debugSources, styleArgs } = splitDebugInfo(styles);
|
|
11
|
+
const sx = stylexNs.props(...styleArgs);
|
|
12
|
+
return applyDebugSources(sx, debugSources);
|
|
13
|
+
}
|
|
14
|
+
function mergeProps(stylexNs, explicitClassName, ...styles) {
|
|
15
|
+
const { debugSources, styleArgs } = splitDebugInfo(styles);
|
|
16
|
+
const sx = stylexNs.props(...styleArgs);
|
|
17
|
+
return {
|
|
18
|
+
...applyDebugSources(sx, debugSources),
|
|
19
|
+
className: `${explicitClassName} ${sx.className ?? ""}`.trim()
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function asStyleArray(styles) {
|
|
23
|
+
if (Array.isArray(styles)) {
|
|
24
|
+
return styles;
|
|
25
|
+
}
|
|
26
|
+
return styles ? [styles] : [];
|
|
27
|
+
}
|
|
28
|
+
function splitDebugInfo(styles) {
|
|
29
|
+
const debugSources = [];
|
|
30
|
+
const styleArgs = [];
|
|
31
|
+
for (const style of styles) {
|
|
32
|
+
if (style instanceof TrussDebugInfo) {
|
|
33
|
+
debugSources.push(style.src);
|
|
34
|
+
} else {
|
|
35
|
+
styleArgs.push(style);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { debugSources, styleArgs };
|
|
39
|
+
}
|
|
40
|
+
function applyDebugSources(props, debugSources) {
|
|
41
|
+
if (debugSources.length === 0) {
|
|
42
|
+
return props;
|
|
43
|
+
}
|
|
44
|
+
const uniqueSources = Array.from(new Set(debugSources));
|
|
45
|
+
return {
|
|
46
|
+
...props,
|
|
47
|
+
"data-truss-src": uniqueSources.join("; ")
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
TrussDebugInfo,
|
|
52
|
+
asStyleArray,
|
|
53
|
+
mergeProps,
|
|
54
|
+
trussProps
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime.ts"],"sourcesContent":["import type * as stylex from \"@stylexjs/stylex\";\n\nexport class TrussDebugInfo {\n /** A compact `FileName.tsx:line` source label for a Truss CSS expression. */\n readonly src: string;\n\n constructor(src: string) {\n this.src = src;\n }\n}\n\ntype StylexPropArg = Parameters<typeof stylex.props>[number];\n\n/** Call StyleX while stripping Truss debug sentinels from the style list. */\nexport function trussProps(stylexNs: typeof stylex, ...styles: unknown[]): Record<string, unknown> {\n const { debugSources, styleArgs } = splitDebugInfo(styles);\n const sx = stylexNs.props(...styleArgs);\n return applyDebugSources(sx, debugSources);\n}\n\nexport function mergeProps(\n stylexNs: typeof stylex,\n explicitClassName: string,\n ...styles: unknown[]\n): Record<string, unknown> {\n const { debugSources, styleArgs } = splitDebugInfo(styles);\n const sx = stylexNs.props(...styleArgs);\n return {\n ...applyDebugSources(sx, debugSources),\n className: `${explicitClassName} ${sx.className ?? \"\"}`.trim(),\n };\n}\n\n/**\n * Coerce maybe-array StyleX inputs into arrays, guarding against nullish/false and plain object values.\n *\n * I.e. `...asStyleArray(xss)` stays safe when destructured `xss` is `undefined`.\n */\nexport function asStyleArray(styles: unknown): ReadonlyArray<unknown> {\n if (Array.isArray(styles)) {\n return styles;\n }\n // I.e. a single style object/ref like `xss={{ ...Css.blue.$ }}` becomes `[xss]`\n return styles ? [styles] : [];\n}\n\n/** Collect Truss debug info while preserving the original StyleX argument order. */\nfunction splitDebugInfo(styles: ReadonlyArray<unknown>): {\n debugSources: string[];\n styleArgs: StylexPropArg[];\n} {\n const debugSources: string[] = [];\n const styleArgs: StylexPropArg[] = [];\n\n for (const style of styles) {\n if (style instanceof TrussDebugInfo) {\n debugSources.push(style.src);\n } else {\n styleArgs.push(style as StylexPropArg);\n }\n }\n\n return { debugSources, styleArgs };\n}\n\n/** Deduplicate and attach compact Truss source labels to emitted props. */\nfunction applyDebugSources(\n props: Record<string, unknown>,\n debugSources: ReadonlyArray<string>,\n): Record<string, unknown> {\n if (debugSources.length === 0) {\n return props;\n }\n\n const uniqueSources = Array.from(new Set(debugSources));\n return {\n ...props,\n \"data-truss-src\": uniqueSources.join(\"; \"),\n };\n}\n"],"mappings":";AAEO,IAAM,iBAAN,MAAqB;AAAA;AAAA,EAEjB;AAAA,EAET,YAAY,KAAa;AACvB,SAAK,MAAM;AAAA,EACb;AACF;AAKO,SAAS,WAAW,aAA4B,QAA4C;AACjG,QAAM,EAAE,cAAc,UAAU,IAAI,eAAe,MAAM;AACzD,QAAM,KAAK,SAAS,MAAM,GAAG,SAAS;AACtC,SAAO,kBAAkB,IAAI,YAAY;AAC3C;AAEO,SAAS,WACd,UACA,sBACG,QACsB;AACzB,QAAM,EAAE,cAAc,UAAU,IAAI,eAAe,MAAM;AACzD,QAAM,KAAK,SAAS,MAAM,GAAG,SAAS;AACtC,SAAO;AAAA,IACL,GAAG,kBAAkB,IAAI,YAAY;AAAA,IACrC,WAAW,GAAG,iBAAiB,IAAI,GAAG,aAAa,EAAE,GAAG,KAAK;AAAA,EAC/D;AACF;AAOO,SAAS,aAAa,QAAyC;AACpE,MAAI,MAAM,QAAQ,MAAM,GAAG;AACzB,WAAO;AAAA,EACT;AAEA,SAAO,SAAS,CAAC,MAAM,IAAI,CAAC;AAC9B;AAGA,SAAS,eAAe,QAGtB;AACA,QAAM,eAAyB,CAAC;AAChC,QAAM,YAA6B,CAAC;AAEpC,aAAW,SAAS,QAAQ;AAC1B,QAAI,iBAAiB,gBAAgB;AACnC,mBAAa,KAAK,MAAM,GAAG;AAAA,IAC7B,OAAO;AACL,gBAAU,KAAK,KAAsB;AAAA,IACvC;AAAA,EACF;AAEA,SAAO,EAAE,cAAc,UAAU;AACnC;AAGA,SAAS,kBACP,OACA,cACyB;AACzB,MAAI,aAAa,WAAW,GAAG;AAC7B,WAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,MAAM,KAAK,IAAI,IAAI,YAAY,CAAC;AACtD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,kBAAkB,cAAc,KAAK,IAAI;AAAA,EAC3C;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homebound/truss",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"bin": "cli.js",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"types": "./build/plugin/index.d.ts",
|
|
15
15
|
"import": "./build/plugin/index.js",
|
|
16
16
|
"default": "./build/plugin/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./runtime": {
|
|
19
|
+
"types": "./build/runtime.d.ts",
|
|
20
|
+
"import": "./build/runtime.js",
|
|
21
|
+
"default": "./build/runtime.js"
|
|
17
22
|
}
|
|
18
23
|
},
|
|
19
24
|
"scripts": {
|
|
@@ -35,6 +40,5 @@
|
|
|
35
40
|
"tsup": "^8.5.1",
|
|
36
41
|
"typescript": "^5.9.3",
|
|
37
42
|
"vitest": "^4.1.0"
|
|
38
|
-
}
|
|
39
|
-
"stableVersion": "1.137.5"
|
|
43
|
+
}
|
|
40
44
|
}
|