@homebound/truss 2.12.0 → 2.14.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
@@ -1263,6 +1263,7 @@ function generateStylexCssBuilder(config, sections) {
1263
1263
  // Target: native (build-time plugin)
1264
1264
 
1265
1265
  import { trussProps } from "@homebound/truss/runtime";
1266
+ export { RuntimeStyle, useRuntimeStyle } from "@homebound/truss/runtime";
1266
1267
 
1267
1268
  /** Given a type X, and the user's proposed type T, only allow keys in X and nothing else. */
1268
1269
  export type Only<X, T> = X & Record<Exclude<keyof T, keyof X>, never>;
@@ -1296,6 +1297,7 @@ type Opts<T> = {
1296
1297
  enabled: boolean;
1297
1298
  selector: string | undefined;
1298
1299
  elseApplied: boolean;
1300
+ runtimeError: string | undefined;
1299
1301
  };
1300
1302
 
1301
1303
  class CssBuilder<T extends Properties> {
@@ -1304,6 +1306,12 @@ class CssBuilder<T extends Properties> {
1304
1306
  ${lines.join("\n ").replace(/ +\n/g, "\n")}
1305
1307
 
1306
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
+ }
1307
1315
  return this.rules as any;
1308
1316
  }
1309
1317
 
@@ -1334,12 +1342,12 @@ class CssBuilder<T extends Properties> {
1334
1342
 
1335
1343
  /** Marks this element as a default hover marker (for ancestor pseudo selectors). */
1336
1344
  get marker(): CssBuilder<T> {
1337
- return this;
1345
+ return this.unsupportedRuntime("marker cannot be used in RuntimeStyle css expressions.");
1338
1346
  }
1339
1347
 
1340
1348
  /** Marks this element with a user-defined marker. */
1341
1349
  markerOf(_marker: Marker): CssBuilder<T> {
1342
- return this;
1350
+ return this.unsupportedRuntime("markerOf() cannot be used in RuntimeStyle css expressions.");
1343
1351
  }
1344
1352
 
1345
1353
  /** Creates a marker token for use with markerOf() and when(). */
@@ -1366,16 +1374,16 @@ class CssBuilder<T extends Properties> {
1366
1374
  */
1367
1375
  when(marker: Marker, relationship: "ancestor" | "descendant" | "anySibling" | "siblingBefore" | "siblingAfter", pseudo: string): CssBuilder<T>;
1368
1376
  when(_selectorOrMarker: string | Marker, _relationship?: string, _pseudo?: string): CssBuilder<T> {
1369
- return this;
1377
+ return this.unsupportedRuntime("when() cannot be used in RuntimeStyle css expressions.");
1370
1378
  }
1371
1379
 
1372
1380
  ifContainer(_props: { name?: string; lt?: number; gt?: number }) {
1373
- return this;
1381
+ return this.unsupportedRuntime("ifContainer() cannot be used in RuntimeStyle css expressions.");
1374
1382
  }
1375
1383
 
1376
1384
  /** Apply styles within a pseudo-element (e.g. \`"::placeholder"\`, \`"::selection"\`). */
1377
1385
  element(_pseudoElement: string): CssBuilder<T> {
1378
- return this;
1386
+ return this.unsupportedRuntime("element() cannot be used in RuntimeStyle css expressions.");
1379
1387
  }
1380
1388
 
1381
1389
  ${breakpointIfs}
@@ -1388,7 +1396,7 @@ class CssBuilder<T extends Properties> {
1388
1396
  if (typeof condOrMediaQuery === "boolean") {
1389
1397
  return new CssBuilder({ ...this.opts, enabled: condOrMediaQuery, elseApplied: false });
1390
1398
  }
1391
- return this.newCss({ selector: condOrMediaQuery, elseApplied: false });
1399
+ return this.unsupportedRuntime("if(mediaQuery) cannot be used in RuntimeStyle css expressions.");
1392
1400
  }
1393
1401
 
1394
1402
  get else(): CssBuilder<T> {
@@ -1424,7 +1432,7 @@ class CssBuilder<T extends Properties> {
1424
1432
  /** Marker for the build-time transform to append a raw className. */
1425
1433
  className(className: string): CssBuilder<T> {
1426
1434
  void className;
1427
- return this;
1435
+ return this.unsupportedRuntime("className() cannot be used in RuntimeStyle css expressions.");
1428
1436
  }
1429
1437
 
1430
1438
  /** Convert a style hash into \`{ className, style }\` props for manual spreading into non-\`css=\` contexts. */
@@ -1446,6 +1454,9 @@ class CssBuilder<T extends Properties> {
1446
1454
  private get selector(): string | undefined {
1447
1455
  return this.opts.selector;
1448
1456
  }
1457
+ private unsupportedRuntime(message: string): CssBuilder<T> {
1458
+ return this.newCss({ runtimeError: message });
1459
+ }
1449
1460
  private newCss(opts: Partial<Opts<T>>): CssBuilder<T> {
1450
1461
  return new CssBuilder({ ...this.opts, ...opts });
1451
1462
  }
@@ -1486,7 +1497,13 @@ export type Xss<P extends keyof Properties> = Pick<Properties, P>;
1486
1497
  export const marker: Marker = Symbol.for("truss-default-marker");
1487
1498
 
1488
1499
  /** An entry point for Css expressions. CssBuilder is immutable so this is safe to share. */
1489
- 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
+ });
1490
1507
 
1491
1508
  ${typeAliasCode}
1492
1509