index.d.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import type { ComponentValue } from '@csstools/css-parser-algorithms';
  2. import type { TokenDimension } from '@csstools/css-tokenizer';
  3. import type { TokenNumber } from '@csstools/css-tokenizer';
  4. import type { TokenPercentage } from '@csstools/css-tokenizer';
  5. export declare function calc(css: string, options?: conversionOptions): string;
  6. export declare function calcFromComponentValues(componentValuesList: Array<Array<ComponentValue>>, options?: conversionOptions): Array<Array<ComponentValue>>;
  7. export declare type conversionOptions = {
  8. /**
  9. * Pass global values as a map of key value pairs.
  10. */
  11. globals?: GlobalsWithStrings;
  12. /**
  13. * The default precision is fairly high.
  14. * It aims to be high enough to make rounding unnoticeable in the browser.
  15. * You can set it to a lower number to suite your needs.
  16. */
  17. precision?: number;
  18. /**
  19. * By default this package will try to preserve units.
  20. * The heuristic to do this is very simplistic.
  21. * We take the first unit we encounter and try to convert other dimensions to that unit.
  22. *
  23. * This better matches what users expect from a CSS dev tool.
  24. *
  25. * If you want to have outputs that are closes to CSS serialized values you can set `true`.
  26. */
  27. toCanonicalUnits?: boolean;
  28. /**
  29. * Convert NaN, Infinity, ... into standard representable values.
  30. */
  31. censorIntoStandardRepresentableValues?: boolean;
  32. /**
  33. * Some percentages resolve against other values and might be negative or positive depending on context.
  34. * Raw percentages are more likely to be safe to simplify outside of a browser context
  35. *
  36. * @see https://drafts.csswg.org/css-values-4/#calc-simplification
  37. */
  38. rawPercentages?: boolean;
  39. /**
  40. * The values used to generate random value cache keys.
  41. */
  42. randomCaching?: {
  43. /**
  44. * The name of the property the random function is used in.
  45. */
  46. propertyName: string;
  47. /**
  48. * N is the index of the random function among other random functions in the same property value.
  49. */
  50. propertyN: number;
  51. /**
  52. * An element ID identifying the element the style is being applied to.
  53. * When omitted any `random()` call will not be computed.
  54. */
  55. elementID: string;
  56. /**
  57. * A document ID identifying the Document the styles are from.
  58. * When omitted any `random()` call will not be computed.
  59. */
  60. documentID: string;
  61. };
  62. };
  63. export declare type GlobalsWithStrings = Map<string, TokenDimension | TokenNumber | TokenPercentage | string>;
  64. export declare const mathFunctionNames: Set<string>;
  65. export { }