This commit is contained in:
Asaki Yuki 2026-01-17 02:31:37 +07:00
parent df7c642077
commit 80df04d3f6
3 changed files with 37 additions and 12 deletions

View file

@ -17,12 +17,13 @@ export function FormatProperties(properties: any) {
delete properties.anchor
}
if (Object.keys(property_bags))
if (Object.keys(property_bags).length) {
if (properties.property_bags) {
properties.property_bags = { ...property_bags, ...properties.property_bags }
} else {
properties.property_bags = property_bags
}
}
return properties
}

View file

@ -1,13 +1,16 @@
import { RandomBindingString } from "../../components/Utils.js"
import { Expression, GenBinding } from "./types.js"
export const FuntionMap = new Map<
string,
(...args: Expression[]) => {
type Callback = (...args: Expression[]) => {
genBindings?: GenBinding[]
value: Expression
}
>()
export const FuntionMap = new Map<string, Callback>()
function callFn(name: string, ...args: Expression[]) {
return FuntionMap.get(name)!(...args)
}
// Default Functions
FuntionMap.set("abs", number => {
@ -26,8 +29,29 @@ FuntionMap.set("new", expression => {
}
})
FuntionMap.set("max", (...args) => {
FuntionMap.set("sqrt", number => {
const rtn = RandomBindingString(16),
$1 = RandomBindingString(16),
$2 = RandomBindingString(16)
const { genBindings: absValue, value: absRtn } = callFn("abs")
return {
value: "#a",
genBindings: [
{
source: `${number} * 100 / 2`,
target: $1,
},
...absValue!,
{
source: `${absRtn} > 1`,
target: $2,
},
{
source: `(${number} < 0) * -1 + (${number} > -1) * (${$2} * ((${rtn} + ${number} / ${rtn}) / 2) + (not ${$2}) * ${rtn})`,
target: rtn,
},
],
value: rtn,
}
})

View file

@ -1,5 +1,5 @@
import { Parser } from ".."
import { Parser, Panel } from ".."
const { gen, out } = new Parser("new(#a + #b) >= #b").out()
const { gen, out } = new Parser("abs(#a)").out()
console.log(gen, out)