@rulecad/variables 0.1.7 → 0.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/variables",
3
- "version": "0.1.7",
3
+ "version": "0.2.0",
4
4
  "description": "Design values you can trace: every number says where it comes from, and expressions are parsed, never run.",
5
5
  "type": "module",
6
6
  "exports": {
package/variables.d.mts CHANGED
@@ -60,7 +60,7 @@ export type Variable = {
60
60
  max: number;
61
61
  };
62
62
  choice?: string[];
63
- type?: "text" | "anchor" | "layout";
63
+ type?: "text" | "anchor" | "layout" | "problem";
64
64
  };
65
65
  export type RuleSet = {
66
66
  name?: string;
package/variables.mjs CHANGED
@@ -7,7 +7,7 @@
7
7
  // No imports and no file access: it runs in a browser as well. Rule sets are handed in (sets) or fetched by name
8
8
  // through load(name), such as one that reads rules/<name>.json.
9
9
 
10
- /** @typedef {{ value: number | string, unit?: string, rule?: string, kind?: 'spec' | 'community' | 'default' | 'estimate' | 'measured' | 'derived', source?: string, licence?: string, checked?: string, label?: string, show?: boolean, interface?: boolean, tweak?: { min: number, max: number }, choice?: string[], type?: 'text' | 'anchor' | 'layout' }} Variable */
10
+ /** @typedef {{ value: number | string, unit?: string, rule?: string, kind?: 'spec' | 'community' | 'default' | 'estimate' | 'measured' | 'derived', source?: string, licence?: string, checked?: string, label?: string, show?: boolean, interface?: boolean, tweak?: { min: number, max: number }, choice?: string[], type?: 'text' | 'anchor' | 'layout' | 'problem' }} Variable */
11
11
  /** @typedef {{ name?: string, rules: Record<string, Variable> }} RuleSet */
12
12
  /** @typedef {{ uses?: string[], variables?: Record<string, Variable>, [field: string]: any }} DesignObject */
13
13
  /** @typedef {{ name: string, value: number | string, used?: boolean, set?: boolean, [field: string]: any }} Entry */
@@ -17,7 +17,7 @@ const fail = (code, message, path) => Object.assign(new Error(message), { code,
17
17
 
18
18
  export const ANCHORS = ['tl', 'tc', 'tr', 'ml', 'mc', 'mr', 'bl', 'bc', 'br'];
19
19
  // A variable that holds a name or text, and the names it may hold (null: any text)
20
- export const isName = (d) => !!(d.choice || ['text', 'anchor', 'layout'].includes(d.type));
20
+ export const isName = (d) => !!(d.choice || ['text', 'anchor', 'layout', 'problem'].includes(d.type));
21
21
  export const options = (d) => (d.type === 'anchor' ? ANCHORS : d.type === 'text' ? null : d.choice);
22
22
  export function checkName(name, d, v) {
23
23
  const s = String(v), opts = options(d), match = opts?.find((o) => String(o) === s);
@@ -145,6 +145,7 @@ export function unitsOf(src, unitOf) {
145
145
  // { "type": "text", "value": "", "max": 8 } free text, e.g. a keycap's legend
146
146
  // { "type": "anchor", "value": "mc" } one of 9 places on a face: tl tc tr, ml mc mr, bl bc br
147
147
  // { "type": "layout", "value": "grid", "choice": [...] } a layout file in the project's layouts/ (or a built-in)
148
+ // { "type": "problem", "value": "lever" } an optimisation problem in the project's problems/
148
149
  /**
149
150
  * Every variable's value, and an entry for each variable and rule for checks and rule cards.
150
151
  * @param {DesignObject} object