AI-native design editor. Open-source Figma alternative.
refactor: name formula operators in OpenPencil's terms (#1331)
Danila Poyarkovdff6b0969ab5
diff --git a/packages/core/src/io/formats/fig/export/variables.ts b/packages/core/src/io/formats/fig/export/variables.tsindex d491f66d9..596af500c 100644--- a/packages/core/src/io/formats/fig/export/variables.ts+++ b/packages/core/src/io/formats/fig/export/variables.ts@@ -2,6 +2,7 @@ import * as v from 'valibot'import {collectionPluginDataNodeChange,+ figmaFormulaFunction,parseGuidOrNull,mapUnsupportedExpressionReferences,unsupportedExpressionData,@@ -222,7 +223,7 @@ function formulaToKiwi(resolvedDataType: known(inferFormulaType(operation, typeOf)),value: {expressionValue: {- expressionFunction: operation.operator,+ expressionFunction: figmaFormulaFunction(operation.operator),expressionArguments: operands}}diff --git a/packages/core/tests/io/formats/fig/export/formula.test.ts b/packages/core/tests/io/formats/fig/export/formula.test.tsindex b0f9f1cd2..7cee987f0 100644--- a/packages/core/tests/io/formats/fig/export/formula.test.ts+++ b/packages/core/tests/io/formats/fig/export/formula.test.ts@@ -57,9 +57,9 @@ test('numeric, Boolean and comparison formulas survive fresh and patched .fig satest.each([- { operator: 'ADDITION', operands: [true, 1] },- { operator: 'AND', operands: [1, false] },- { operator: 'NEGATE', operands: [1, 2] }+ { operator: 'add', operands: [true, 1] },+ { operator: 'and', operands: [1, false] },+ { operator: 'negate', operands: [1, 2] }] as const)('FIG export rejects invalid formula operands instead of coercing them: %j', async (value) => {await initCodec()const graph = new SceneGraph()diff --git a/packages/docs/development/architecture.md b/packages/docs/development/architecture.mdindex 918015fc9..075b70bb1 100644--- a/packages/docs/development/architecture.md+++ b/packages/docs/development/architecture.md@@ -56,7 +56,7 @@ See [Scene Graph Reference](/reference/scene-graph) for internals.Scene Graph owns the canonical variable definitions: literals, stable-ID aliases, bounded formula trees that give numbers, Booleans, text or colors, and composed colors. Shared Valibot schemas validate expression structure on FIG import, FIG export, and resolution. The resolver owns mode selection, dependency traversal, cycles, and evaluation; draft validation supplies an override without mutating the document. Canvas callers treat resolution failures as unresolved values, while the inspector retains diagnostics. Core applies edits, undo, binding reconciliation, and layout.-Formula trees use Figma's `ExpressionFunction` operators and its operand signatures, so `.fig` files carry them as they are: `+` joins text, `STRINGIFY`, `IS_TRUTHY` and `TERNARY` are written `text()`, `truthy()` and `if()`, and number text follows Figma's two-decimal format. An expression the reader cannot hold as a formula, such as one naming a variable the file lacks, is kept as the file wrote it. Scene Graph parses formula text into a tree, checking operand types as it goes, and prints a tree back with only the parentheses precedence needs; references are `{name}` in text and IDs in the tree. Editors show references as pills and never ask users to type braces.+Formula trees name operators in OpenPencil's own terms (`add`, `truthy`, `if`) with Figma's operand signatures and value rules: `+` joins text, `text()`, `truthy()` and `if()` convert and choose as Figma's `STRINGIFY`, `IS_TRUTHY` and `TERNARY` do, and number text follows Figma's two-decimal format. The FIG package alone maps each operator to Figma's `ExpressionFunction`, so other formats read and write the same tree. An expression the reader cannot hold as a formula, such as one naming a variable the file lacks, is kept as the file wrote it. Scene Graph parses formula text into a tree, checking operand types as it goes, and prints a tree back with only the parentheses precedence needs; references are `{name}` in text and IDs in the tree. Editors show references as pills and never ask users to type braces.A formula in `valuesByMode` is live document behavior. `expressions[modeId].css` is separate, target-specific CSS that replaces the value in CSS alone, edited in its own field. The token stylesheet writes number formulas as `calc()` over `var()` references, checking that units add and multiply as CSS allows, and declares a formula again in each mode scope that changes a variable it uses. Design-token files hold each mode's result with the formula in `$extensions`. Design JSX preserves node bindings through `designVar`, but does not yet bundle the referenced formula definitions; formulas that give Booleans, text or colors, or use `if()`, have no CSS form.diff --git a/packages/dom-css/src/tokens/formula.ts b/packages/dom-css/src/tokens/formula.tsindex 1307ced06..01d6b9c04 100644--- a/packages/dom-css/src/tokens/formula.ts+++ b/packages/dom-css/src/tokens/formula.ts@@ -12,10 +12,10 @@ type Term =| { kind: 'css'; text: string; precedence: number; dimension: boolean }const OPERATORS = {- ADDITION: { symbol: '+', precedence: 1 },- SUBTRACTION: { symbol: '-', precedence: 1 },- MULTIPLY: { symbol: '*', precedence: 2 },- DIVIDE: { symbol: '/', precedence: 2 }+ add: { symbol: '+', precedence: 1 },+ subtract: { symbol: '-', precedence: 1 },+ multiply: { symbol: '*', precedence: 2 },+ divide: { symbol: '/', precedence: 2 }} as consttype Arithmetic = keyof typeof OPERATORSconst ATOM = 3@@ -63,7 +63,7 @@ function convert(node: VariableFormulaNode, context: FormulaContext): Term {reference: (id) => reference(id, context),operation: ({ operator }, operands) => {const [a, b] = operands- if (operator === 'NEGATE' && operands.length === 1) return negate(a, context)+ if (operator === 'negate' && operands.length === 1) return negate(a, context)if (operands.length !== 2 || !isArithmetic(operator))throw new UnsupportedFormulaError('uses logic that CSS has no form for')if (a.kind === 'literal' && b.kind === 'literal')@@ -86,15 +86,14 @@ function reference(id: string, { variables, names }: FormulaContext): Term {function negate(term: Term, context: FormulaContext): Term {if (term.kind === 'literal') return { kind: 'literal', value: -term.value }- const text = `-1 * ${grouped(term, false, OPERATORS.MULTIPLY.precedence, context)}`- return { kind: 'css', text, precedence: OPERATORS.MULTIPLY.precedence, dimension: term.dimension }+ const text = `-1 * ${grouped(term, false, OPERATORS.multiply.precedence, context)}`+ return { kind: 'css', text, precedence: OPERATORS.multiply.precedence, dimension: term.dimension }}function binary(operator: Arithmetic, a: Term, b: Term, context: FormulaContext): Term {const { symbol, precedence } = OPERATORS[operator]// The right side of - and / keeps its parentheses even at equal precedence.- const rightBelow =- operator === 'SUBTRACTION' || operator === 'DIVIDE' ? precedence + 1 : precedence+ const rightBelow = operator === 'subtract' || operator === 'divide' ? precedence + 1 : precedenceconst aDimension = a.kind === 'css' && a.dimensionconst bDimension = b.kind === 'css' && b.dimensionif (precedence === 1) {@@ -105,7 +104,7 @@ function binary(operator: Arithmetic, a: Term, b: Term, context: FormulaContext)const right = grouped(b, dimension, rightBelow, context)return { kind: 'css', text: `${left} ${symbol} ${right}`, precedence, dimension }}- if (bDimension && operator === 'DIVIDE') throw new UnsupportedFormulaError('divides by a length')+ if (bDimension && operator === 'divide') throw new UnsupportedFormulaError('divides by a length')if (aDimension && bDimension) throw new UnsupportedFormulaError('multiplies two lengths')const left = grouped(a, false, precedence, context)const right = grouped(b, false, rightBelow, context)@@ -133,8 +132,8 @@ function isArithmetic(operator: string): operator is Arithmetic {}function fold(operator: Arithmetic, a: number, b: number) {- if (operator === 'ADDITION') return a + b- if (operator === 'SUBTRACTION') return a - b- if (operator === 'MULTIPLY') return a * b+ if (operator === 'add') return a + b+ if (operator === 'subtract') return a - b+ if (operator === 'multiply') return a * breturn a / b}diff --git a/packages/fig/src/document/variables.ts b/packages/fig/src/document/variables.tsindex 25037a16e..ed90936de 100644--- a/packages/fig/src/document/variables.ts+++ b/packages/fig/src/document/variables.ts@@ -3,7 +3,6 @@ import * as v from 'valibot'import type { NodeChange, VariableDataEntry } from '@open-pencil/kiwi/fig/codec'import { guidToString } from '@open-pencil/kiwi/fig/guid'import {- VARIABLE_FORMULA_OPERATORS,variableFormulaSchema,variableColorExpressionSchema,inferFormulaType,@@ -15,6 +14,7 @@ import {} from '@open-pencil/scene-graph'import { extractPluginData } from '../node-change/plugin-data'+import { formulaOperatorOfFigmaFunction } from '../node-change/variable/formula'import { readVariableMetadata } from '../node-change/variable/metadata'import {readModeAttribute,@@ -68,14 +68,13 @@ function expressionValue(if (value.expressionValue?.expressionFunction === 'COMPOSE_COLOR')return colorExpression(entry, resolve)const expression = value.expressionValue- const parsed = v.safeParse(v.picklist(VARIABLE_FORMULA_OPERATORS), expression?.expressionFunction)- if (!parsed.success) {+ const operator = formulaOperatorOfFigmaFunction(expression?.expressionFunction)+ if (!operator) {if (!expression?.expressionFunction) throw new Error('Missing variable expression function')throw new UnsupportedExpressionError(`Unsupported variable expression ${expression.expressionFunction}`)}- const operator = parsed.outputconst operands = (expression?.expressionArguments ?? []).map((arg) => {// A formula needs every variable it uses; one the document lacks keeps the file's tree.if ((arg.dataType ?? arg.resolvedDataType) === 'ALIAS' && !resolve(arg.value?.alias))diff --git a/packages/fig/src/node-change/index.ts b/packages/fig/src/node-change/index.tsindex 5a8a3f6ba..f84d2aa07 100644--- a/packages/fig/src/node-change/index.ts+++ b/packages/fig/src/node-change/index.ts@@ -22,6 +22,7 @@ export * from './style/runs'export * from './text/data-export'export * from './text/values'export * from './variable/bindings'+export * from './variable/formula'export * from './variable/metadata'export * from './variable/token'export * from './variable/unsupported'diff --git a/packages/fig/src/node-change/variable/formula.ts b/packages/fig/src/node-change/variable/formula.tsnew file mode 100644index 000000000..86344db01--- /dev/null+++ b/packages/fig/src/node-change/variable/formula.ts@@ -0,0 +1,38 @@+import { invert } from 'es-toolkit'++import type { VariableFormulaOperator } from '@open-pencil/scene-graph'++/** The `ExpressionFunction` Figma saves for each formula operator. */+const FIGMA_FORMULA_FUNCTIONS = {+ add: 'ADDITION',+ subtract: 'SUBTRACTION',+ multiply: 'MULTIPLY',+ divide: 'DIVIDE',+ negate: 'NEGATE',+ equal: 'EQUALS',+ notEqual: 'NOT_EQUAL',+ less: 'LESS_THAN',+ lessOrEqual: 'LESS_THAN_OR_EQUAL',+ greater: 'GREATER_THAN',+ greaterOrEqual: 'GREATER_THAN_OR_EQUAL',+ and: 'AND',+ or: 'OR',+ not: 'NOT',+ text: 'STRINGIFY',+ truthy: 'IS_TRUTHY',+ if: 'TERNARY'+} as const satisfies Record<VariableFormulaOperator, string>++const FORMULA_OPERATORS_BY_FUNCTION: Partial<Record<string, VariableFormulaOperator>> =+ invert(FIGMA_FORMULA_FUNCTIONS)++export function figmaFormulaFunction(operator: VariableFormulaOperator): string {+ return FIGMA_FORMULA_FUNCTIONS[operator]+}++/** The formula operator a saved `ExpressionFunction` is, when it is one. */+export function formulaOperatorOfFigmaFunction(+ name: string | undefined+): VariableFormulaOperator | undefined {+ return name === undefined ? undefined : FORMULA_OPERATORS_BY_FUNCTION[name]+}diff --git a/packages/fig/tests/node-change/variable-token.test.ts b/packages/fig/tests/node-change/variable-token.test.tsindex fab0d4803..b36c38436 100644--- a/packages/fig/tests/node-change/variable-token.test.ts+++ b/packages/fig/tests/node-change/variable-token.test.ts@@ -73,7 +73,7 @@ describe('token plugin data', () => {const formula = {expression: 'FORMULA' as const,type: 'FLOAT' as const,- value: { operator: 'MULTIPLY' as const, operands: [{ aliasId: '1:2' }, 2] }+ value: { operator: 'multiply' as const, operands: [{ aliasId: '1:2' }, 2] }}// A number now where no number was recorded was edited elsewhere: the expression goes.expect(diff --git a/packages/scene-graph/src/types.ts b/packages/scene-graph/src/types.tsindex 37c67f369..b5f31fc7a 100644--- a/packages/scene-graph/src/types.ts+++ b/packages/scene-graph/src/types.ts@@ -848,25 +848,25 @@ export interface VariableColorExpression {}export type VariableLiteral = Color | number | string | boolean-/** Figma's `ExpressionFunction` names for the arithmetic, comparison, logic and text a formula uses. */+/** The arithmetic, comparison, logic and conversions a formula combines values with. */export const VARIABLE_FORMULA_OPERATORS = [- 'ADDITION',- 'SUBTRACTION',- 'MULTIPLY',- 'DIVIDE',- 'NEGATE',- 'EQUALS',- 'NOT_EQUAL',- 'LESS_THAN',- 'LESS_THAN_OR_EQUAL',- 'GREATER_THAN',- 'GREATER_THAN_OR_EQUAL',- 'AND',- 'OR',- 'NOT',- 'STRINGIFY',- 'IS_TRUTHY',- 'TERNARY'+ 'add',+ 'subtract',+ 'multiply',+ 'divide',+ 'negate',+ 'equal',+ 'notEqual',+ 'less',+ 'lessOrEqual',+ 'greater',+ 'greaterOrEqual',+ 'and',+ 'or',+ 'not',+ 'text',+ 'truthy',+ 'if'] as constexport type VariableFormulaOperator = (typeof VARIABLE_FORMULA_OPERATORS)[number]export interface VariableFormulaOperation {@@ -887,7 +887,7 @@ export interface VariableFormula {*/export interface VariableUnsupportedExpression {expression: 'UNSUPPORTED'- /** The function name the file gives, such as `TERNARY`. */+ /** The function name the file gives, such as `VAR_MODE_LOOKUP`. */function: stringvalue: Record<string, unknown>references: (string | null)[]diff --git a/packages/scene-graph/src/variables/formula/parse.ts b/packages/scene-graph/src/variables/formula/parse.tsindex 4dbc3975a..1989407b7 100644--- a/packages/scene-graph/src/variables/formula/parse.ts+++ b/packages/scene-graph/src/variables/formula/parse.ts@@ -133,7 +133,7 @@ export function parseFormulaSyntax(if (!operator) throw new VariableFormulaError(`Unexpected ${token.text}`)const operand = expression(FORMULA_PREFIX_PRECEDENCE, depth + 1)// A negative number is a literal, not the negation of one.- if (operator === 'NEGATE' && typeof operand.node === 'number')+ if (operator === 'negate' && typeof operand.node === 'number')return { node: -operand.node, type: 'FLOAT' }return operation(operator, [operand])}diff --git a/packages/scene-graph/src/variables/formula/print.ts b/packages/scene-graph/src/variables/formula/print.tsindex c3c7a29a1..7d0d2c0ae 100644--- a/packages/scene-graph/src/variables/formula/print.ts+++ b/packages/scene-graph/src/variables/formula/print.ts@@ -21,7 +21,7 @@ import { isFormulaOperation, isFormulaReference, MAX_FORMULA_DEPTH } from './treconst ATOM = FORMULA_PREFIX_PRECEDENCE + 1/** A long formula breaks before these: `or`, `and`, and `+` and `-`. */const BREAKABLE = new Set(- (['OR', 'AND', 'ADDITION'] satisfies VariableFormulaOperator[]).map(formulaPrecedence)+ (['or', 'and', 'add'] satisfies VariableFormulaOperator[]).map(formulaPrecedence))const CONTINUATION = '\n '@@ -93,7 +93,7 @@ function printBinary(isFormulaAssociative(node.operator) &&isFormulaOperation(rightNode) &&rightNode.operator === node.operator &&- (node.operator !== 'ADDITION' || regroups(node))+ (node.operator !== 'add' || regroups(node))// The chain continues through a left operand and an unparenthesized right one of its level.const breaking = breakAt === precedenceconst left = print(leftNode, depth + 1, breaking ? breakAt : undefined)@@ -126,7 +126,7 @@ export function printFormula(// Text printed without parentheses reads left to right, so `"a" + (1 + 2)` would read as// `"a" + 1 + 2`: regroup only when every operand of the chain gives the sum's type.const chain = (of: VariableFormulaNode): VariableFormulaNode[] =>- isFormulaOperation(of) && of.operator === 'ADDITION'+ isFormulaOperation(of) && of.operator === 'add'? [...chain(of.operands[0]), of.operands[1]]: [of]const regroups: Regroups = (sum) => {diff --git a/packages/scene-graph/src/variables/formula/signatures.ts b/packages/scene-graph/src/variables/formula/signatures.tsindex d9c957166..42977ac7e 100644--- a/packages/scene-graph/src/variables/formula/signatures.ts+++ b/packages/scene-graph/src/variables/formula/signatures.ts@@ -46,7 +46,7 @@ const FLOAT_FLOAT = ['FLOAT', 'FLOAT'] as constconst TEXT_TYPES = ['FLOAT', 'BOOLEAN', 'STRING'] as constconst SIGNATURES: Record<VariableFormulaOperator, OperatorSignature> = {- ADDITION: {+ add: {spellings: ['+'],arity: 2,precedence: 5,@@ -65,13 +65,13 @@ const SIGNATURES: Record<VariableFormulaOperator, OperatorSignature> = {? a + b: `${variableText(a) ?? ''}${variableText(b) ?? ''}`},- SUBTRACTION: arithmetic('-', 5, (a, b) => a - b),- MULTIPLY: { ...arithmetic('*', 6, (a, b) => a * b), associative: true },- DIVIDE: arithmetic('/', 6, (a, b) => {+ subtract: arithmetic('-', 5, (a, b) => a - b),+ multiply: { ...arithmetic('*', 6, (a, b) => a * b), associative: true },+ divide: arithmetic('/', 6, (a, b) => {if (b === 0) throw new VariableFormulaError('Cannot divide by zero')return a / b}),- NEGATE: {+ negate: {spellings: ['-'],arity: 1,precedence: FORMULA_PREFIX_PRECEDENCE,@@ -79,15 +79,15 @@ const SIGNATURES: Record<VariableFormulaOperator, OperatorSignature> = {needs: 'needs numbers',apply: ([a]) => -Number(a)},- EQUALS: equality('==', (a, b) => a === b),- NOT_EQUAL: equality('!=', (a, b) => a !== b),- LESS_THAN: comparison('<', (a, b) => a < b),- LESS_THAN_OR_EQUAL: comparison('<=', (a, b) => a <= b),- GREATER_THAN: comparison('>', (a, b) => a > b),- GREATER_THAN_OR_EQUAL: comparison('>=', (a, b) => a >= b),- AND: logic(['and', '&&'], 2, (a, b) => a && b),- OR: logic(['or', '||'], 1, (a, b) => a || b),- NOT: {+ equal: equality('==', (a, b) => a === b),+ notEqual: equality('!=', (a, b) => a !== b),+ less: comparison('<', (a, b) => a < b),+ lessOrEqual: comparison('<=', (a, b) => a <= b),+ greater: comparison('>', (a, b) => a > b),+ greaterOrEqual: comparison('>=', (a, b) => a >= b),+ and: logic(['and', '&&'], 2, (a, b) => a && b),+ or: logic(['or', '||'], 1, (a, b) => a || b),+ not: {spellings: ['not', '!'],arity: 1,precedence: FORMULA_PREFIX_PRECEDENCE,@@ -95,7 +95,7 @@ const SIGNATURES: Record<VariableFormulaOperator, OperatorSignature> = {needs: 'needs true or false',apply: ([a]) => a !== true},- STRINGIFY: {+ text: {spellings: ['text'],call: true,arity: 1,@@ -103,7 +103,7 @@ const SIGNATURES: Record<VariableFormulaOperator, OperatorSignature> = {needs: 'needs a number, text, or true or false',apply: ([a]) => variableText(a) ?? ''},- IS_TRUTHY: {+ truthy: {spellings: ['truthy'],call: true,arity: 1,@@ -111,7 +111,7 @@ const SIGNATURES: Record<VariableFormulaOperator, OperatorSignature> = {needs: 'needs a number, text, or true or false',apply: ([a]) => variableTruthy(a) ?? false},- TERNARY: {+ if: {spellings: ['if'],call: true,arity: 3,diff --git a/packages/scene-graph/tests/variables/formula.test.ts b/packages/scene-graph/tests/variables/formula.test.tsindex 525e6c6d1..68c804205 100644--- a/packages/scene-graph/tests/variables/formula.test.ts+++ b/packages/scene-graph/tests/variables/formula.test.ts@@ -227,7 +227,7 @@ test('shared formula dependencies resolve once per evaluation and never cache acexpression: 'FORMULA',type: 'FLOAT',value: {- operator: 'ADDITION',+ operator: 'add',operands: [{ aliasId: previous.id }, { aliasId: previous.id }]}}@@ -263,11 +263,11 @@ test('100 consumers share one calculation per mode during a batch', () => {test('numeric schema and resolver reject invalid formula trees', () => {const values: VariableFormulaNode[] = [- { operator: 'ADDITION', operands: [true, 1] },- { operator: 'ADDITION', operands: [1] },- { operator: 'NOT', operands: [true] },- { operator: 'MULTIPLY', operands: [1, { operator: 'OR', operands: [false, true] }] },- { operator: 'DIVIDE', operands: [Infinity, 2] }+ { operator: 'add', operands: [true, 1] },+ { operator: 'add', operands: [1] },+ { operator: 'not', operands: [true] },+ { operator: 'multiply', operands: [1, { operator: 'or', operands: [false, true] }] },+ { operator: 'divide', operands: [Infinity, 2] }]const { graph, derived, mode } = setup()for (const value of values) {@@ -282,10 +282,10 @@ test('bounded schema rejects deeply nested and cyclic input', () => {const value: VariableValue = { expression: 'FORMULA', type: 'FLOAT', value: 1 }if (!('expression' in value) || value.expression !== 'FORMULA')throw new Error('Expected formula')- for (let i = 0; i < 65; i++) value.value = { operator: 'NEGATE', operands: [value.value] }+ for (let i = 0; i < 65; i++) value.value = { operator: 'negate', operands: [value.value] }expect(v.safeParse(variableFormulaSchema, value).success).toBe(false)const operands: VariableFormulaNode[] = [1]- const cyclic: VariableFormulaNode = { operator: 'NEGATE', operands }+ const cyclic: VariableFormulaNode = { operator: 'negate', operands }operands[0] = cyclicexpect(v.safeParse(variableFormulaSchema, { expression: 'FORMULA', type: 'FLOAT', value: cyclic })diff --git a/packages/scene-graph/tests/variables/functions.test.ts b/packages/scene-graph/tests/variables/functions.test.tsindex 4eae8f075..39e79d3ca 100644--- a/packages/scene-graph/tests/variables/functions.test.ts+++ b/packages/scene-graph/tests/variables/functions.test.ts@@ -130,15 +130,15 @@ test('literal text and colors print as the field reads them back', () => {test('the schema takes text and color formulas, and refuses operands that do not fit', () => {const formula = (type: VariableType, value: unknown) =>v.safeParse(variableFormulaSchema, { expression: 'FORMULA', type, value }).success- const ternary = (operands: unknown[]) => ({ operator: 'TERNARY', operands })+ const ternary = (operands: unknown[]) => ({ operator: 'if', operands })const red = { r: 1, g: 0, b: 0, a: 1 }- expect(formula('STRING', { operator: 'STRINGIFY', operands: [1.5] })).toBe(true)+ expect(formula('STRING', { operator: 'text', operands: [1.5] })).toBe(true)expect(formula('COLOR', ternary([{ aliasId: 'flag' }, red, { aliasId: 'ink' }]))).toBe(true)expect(formula('FLOAT', ternary([true, 1, 2]))).toBe(true)expect(formula('FLOAT', ternary([1, 1, 2]))).toBe(false)expect(formula('STRING', ternary([true, 1, 2]))).toBe(false)- expect(formula('FLOAT', { operator: 'STRINGIFY', operands: [1] })).toBe(false)- expect(formula('FLOAT', { operator: 'TERNARY', operands: [true, 1] })).toBe(false)+ expect(formula('FLOAT', { operator: 'text', operands: [1] })).toBe(false)+ expect(formula('FLOAT', { operator: 'if', operands: [true, 1] })).toBe(false)})test('the tokenizer reads text, colors, calls and commas, and text still being typed', () => {diff --git a/src/app/editor/tokens/model.ts b/src/app/editor/tokens/model.tsindex 29a48e63d..6ce234fa4 100644--- a/src/app/editor/tokens/model.ts+++ b/src/app/editor/tokens/model.ts@@ -38,7 +38,7 @@ export interface TokenModeValue {result?: string/** A CSS expression written instead of the stored number, such as `clamp(…)`. */expression?: string- /** A function from the file OpenPencil cannot evaluate, such as `TERNARY`. */+ /** A function from the file OpenPencil cannot evaluate, such as `VAR_MODE_LOOKUP`. */unsupported?: string}diff --git a/src/components/variables/TokenValueEditor.vue b/src/components/variables/TokenValueEditor.vueindex e9dede2b2..b40bf0807 100644--- a/src/components/variables/TokenValueEditor.vue+++ b/src/components/variables/TokenValueEditor.vue@@ -123,9 +123,9 @@ const referenceItems = computed(() => formula.candidates.map(withValue))const functionCompletions = computed(() =>([- ['TERNARY', variables.value.formulaIf],- ['STRINGIFY', variables.value.formulaText],- ['IS_TRUTHY', variables.value.formulaTruthy]+ ['if', variables.value.formulaIf],+ ['text', variables.value.formulaText],+ ['truthy', variables.value.formulaTruthy]] as const).map(([operator, detail]) => ({label: formulaSymbol(operator),