@homebound/truss 2.11.3 → 2.13.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 CHANGED
@@ -1138,6 +1138,11 @@ class CssBuilder<T extends Properties> {
1138
1138
  return this;
1139
1139
  }
1140
1140
 
1141
+ /** Tagged template literal for raw CSS in .css.ts files; passes through the string as-is. */
1142
+ raw(strings: TemplateStringsArray, ...values: unknown[]): string {
1143
+ return String.raw(strings, ...values);
1144
+ }
1145
+
1141
1146
  }
1142
1147
 
1143
1148
  /** Sort keys so equivalent rule objects have deterministic shape. */
@@ -1258,6 +1263,7 @@ function generateStylexCssBuilder(config, sections) {
1258
1263
  // Target: native (build-time plugin)
1259
1264
 
1260
1265
  import { trussProps } from "@homebound/truss/runtime";
1266
+ export { RuntimeStyle } from "@homebound/truss/runtime";
1261
1267
 
1262
1268
  /** Given a type X, and the user's proposed type T, only allow keys in X and nothing else. */
1263
1269
  export type Only<X, T> = X & Record<Exclude<keyof T, keyof X>, never>;
@@ -1291,6 +1297,7 @@ type Opts<T> = {
1291
1297
  enabled: boolean;
1292
1298
  selector: string | undefined;
1293
1299
  elseApplied: boolean;
1300
+ runtimeError: string | undefined;
1294
1301
  };
1295
1302
 
1296
1303
  class CssBuilder<T extends Properties> {
@@ -1299,6 +1306,12 @@ class CssBuilder<T extends Properties> {
1299
1306
  ${lines.join("\n ").replace(/ +\n/g, "\n")}
1300
1307
 
1301
1308
  get $(): T {
1309
+ if (this.opts.runtimeError) {
1310
+ throw new Error(this.opts.runtimeError);
1311
+ }
1312
+ if (this.selector !== undefined) {
1313
+ throw new Error("Selector-based Css helpers cannot be used in RuntimeStyle css expressions.");
1314
+ }
1302
1315
  return this.rules as any;
1303
1316
  }
1304
1317
 
@@ -1329,12 +1342,12 @@ class CssBuilder<T extends Properties> {
1329
1342
 
1330
1343
  /** Marks this element as a default hover marker (for ancestor pseudo selectors). */
1331
1344
  get marker(): CssBuilder<T> {
1332
- return this;
1345
+ return this.unsupportedRuntime("marker cannot be used in RuntimeStyle css expressions.");
1333
1346
  }
1334
1347
 
1335
1348
  /** Marks this element with a user-defined marker. */
1336
1349
  markerOf(_marker: Marker): CssBuilder<T> {
1337
- return this;
1350
+ return this.unsupportedRuntime("markerOf() cannot be used in RuntimeStyle css expressions.");
1338
1351
  }
1339
1352
 
1340
1353
  /** Creates a marker token for use with markerOf() and when(). */
@@ -1361,16 +1374,16 @@ class CssBuilder<T extends Properties> {
1361
1374
  */
1362
1375
  when(marker: Marker, relationship: "ancestor" | "descendant" | "anySibling" | "siblingBefore" | "siblingAfter", pseudo: string): CssBuilder<T>;
1363
1376
  when(_selectorOrMarker: string | Marker, _relationship?: string, _pseudo?: string): CssBuilder<T> {
1364
- return this;
1377
+ return this.unsupportedRuntime("when() cannot be used in RuntimeStyle css expressions.");
1365
1378
  }
1366
1379
 
1367
1380
  ifContainer(_props: { name?: string; lt?: number; gt?: number }) {
1368
- return this;
1381
+ return this.unsupportedRuntime("ifContainer() cannot be used in RuntimeStyle css expressions.");
1369
1382
  }
1370
1383
 
1371
1384
  /** Apply styles within a pseudo-element (e.g. \`"::placeholder"\`, \`"::selection"\`). */
1372
1385
  element(_pseudoElement: string): CssBuilder<T> {
1373
- return this;
1386
+ return this.unsupportedRuntime("element() cannot be used in RuntimeStyle css expressions.");
1374
1387
  }
1375
1388
 
1376
1389
  ${breakpointIfs}
@@ -1383,7 +1396,7 @@ class CssBuilder<T extends Properties> {
1383
1396
  if (typeof condOrMediaQuery === "boolean") {
1384
1397
  return new CssBuilder({ ...this.opts, enabled: condOrMediaQuery, elseApplied: false });
1385
1398
  }
1386
- return this.newCss({ selector: condOrMediaQuery, elseApplied: false });
1399
+ return this.unsupportedRuntime("if(mediaQuery) cannot be used in RuntimeStyle css expressions.");
1387
1400
  }
1388
1401
 
1389
1402
  get else(): CssBuilder<T> {
@@ -1419,7 +1432,7 @@ class CssBuilder<T extends Properties> {
1419
1432
  /** Marker for the build-time transform to append a raw className. */
1420
1433
  className(className: string): CssBuilder<T> {
1421
1434
  void className;
1422
- return this;
1435
+ return this.unsupportedRuntime("className() cannot be used in RuntimeStyle css expressions.");
1423
1436
  }
1424
1437
 
1425
1438
  /** Convert a style hash into \`{ className, style }\` props for manual spreading into non-\`css=\` contexts. */
@@ -1427,6 +1440,11 @@ class CssBuilder<T extends Properties> {
1427
1440
  return trussProps(styles as any);
1428
1441
  }
1429
1442
 
1443
+ /** Tagged template literal for raw CSS in .css.ts files; passes through the string as-is. */
1444
+ raw(strings: TemplateStringsArray, ...values: unknown[]): string {
1445
+ return String.raw(strings, ...values);
1446
+ }
1447
+
1430
1448
  private get rules(): T {
1431
1449
  return this.opts.rules;
1432
1450
  }
@@ -1436,6 +1454,9 @@ class CssBuilder<T extends Properties> {
1436
1454
  private get selector(): string | undefined {
1437
1455
  return this.opts.selector;
1438
1456
  }
1457
+ private unsupportedRuntime(message: string): CssBuilder<T> {
1458
+ return this.newCss({ runtimeError: message });
1459
+ }
1439
1460
  private newCss(opts: Partial<Opts<T>>): CssBuilder<T> {
1440
1461
  return new CssBuilder({ ...this.opts, ...opts });
1441
1462
  }
@@ -1476,7 +1497,13 @@ export type Xss<P extends keyof Properties> = Pick<Properties, P>;
1476
1497
  export const marker: Marker = Symbol.for("truss-default-marker");
1477
1498
 
1478
1499
  /** An entry point for Css expressions. CssBuilder is immutable so this is safe to share. */
1479
- export const Css = new CssBuilder({ rules: {}, enabled: true, selector: undefined, elseApplied: false });
1500
+ export const Css = new CssBuilder({
1501
+ rules: {},
1502
+ enabled: true,
1503
+ selector: undefined,
1504
+ elseApplied: false,
1505
+ runtimeError: undefined,
1506
+ });
1480
1507
 
1481
1508
  ${typeAliasCode}
1482
1509