From 80df04d3f6926f68c098c41c99af9564cbea9138 Mon Sep 17 00:00:00 2001 From: Asaki Yuki Date: Sat, 17 Jan 2026 02:31:37 +0700 Subject: [PATCH] he --- src/compilers/FormatProperties.ts | 3 ++- src/compilers/bindings/Funtion.ts | 42 ++++++++++++++++++++++++------- test/app.ts | 4 +-- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/compilers/FormatProperties.ts b/src/compilers/FormatProperties.ts index 3e8b547..3243e9a 100644 --- a/src/compilers/FormatProperties.ts +++ b/src/compilers/FormatProperties.ts @@ -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 } diff --git a/src/compilers/bindings/Funtion.ts b/src/compilers/bindings/Funtion.ts index c06db6a..8751990 100644 --- a/src/compilers/bindings/Funtion.ts +++ b/src/compilers/bindings/Funtion.ts @@ -1,13 +1,16 @@ import { RandomBindingString } from "../../components/Utils.js" import { Expression, GenBinding } from "./types.js" -export const FuntionMap = new Map< - string, - (...args: Expression[]) => { - genBindings?: GenBinding[] - value: Expression - } ->() +type Callback = (...args: Expression[]) => { + genBindings?: GenBinding[] + value: Expression +} + +export const FuntionMap = new Map() + +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, } }) diff --git a/test/app.ts b/test/app.ts index 26d63fa..ef2d080 100644 --- a/test/app.ts +++ b/test/app.ts @@ -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)