From 93c91b15df0ad131aee238d1f0bf236c581dbc27 Mon Sep 17 00:00:00 2001 From: Acbox liu <850625057@qq.com> Date: Wed, 14 Aug 2024 22:04:02 +0800 Subject: [PATCH] release: v2.0.0-beta.10 --- examples/scene1.ts | 35 +++++----------------- mods/mod-geometry/package.json | 2 +- mods/mod-layout/package.json | 2 +- mods/mod-markdown/package.json | 2 +- mods/mod-math/package.json | 2 +- mods/mod-skottie/package.json | 2 +- packages/basic/package.json | 2 +- packages/core/package.json | 2 +- packages/json/package.json | 2 +- packages/json/src/import-widget.ts | 42 +++++++++------------------ packages/json/src/process-resource.ts | 16 ---------- packages/newcar/package.json | 2 +- packages/recorder/package.json | 2 +- packages/utils/package.json | 2 +- plugins/plugin-debug/package.json | 2 +- plugins/plugin-timeview/package.json | 2 +- 16 files changed, 34 insertions(+), 85 deletions(-) delete mode 100644 packages/json/src/process-resource.ts diff --git a/examples/scene1.ts b/examples/scene1.ts index d92cd95b6..61e325038 100644 --- a/examples/scene1.ts +++ b/examples/scene1.ts @@ -3,6 +3,7 @@ import TextEditor from "@newcar/mod-text-editor" import { Table } from "@newcar/mod-table"; import {importScene} from "newcar"; import * as nc from 'newcar' +import * as mt from '@newcar/mod-math' await useFont('./default.ttf') @@ -10,38 +11,16 @@ export default importScene( `{ "root": { - "type": "Circle", - "arguments": [150], + "type": "MathFunction", + "arguments": ["fn((x) => Math.sin(x))", [-2, 2]], "options": { - "style": { - "border": true, - "fill": false, - "borderColor": [144, 144, 144, 1] - }, - "x": 800, - "y": 450 - }, - "animations": [ - { - "type": "stroke", - "parameters": { - "duration": 4 - } - }, - { - "custom": "change-property", - "target": "radius", - "parameters": { - "from": 1, - "to": 100, - "duration": 2 - } - } - ] + "x": "calc(200)", + "y": 100 + } } } `, - nc as any, + {...(nc as any), ...mt}, nc as any, nc as any, ) diff --git a/mods/mod-geometry/package.json b/mods/mod-geometry/package.json index cea4ae422..cc54b4631 100644 --- a/mods/mod-geometry/package.json +++ b/mods/mod-geometry/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/mod-geometry", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/mods/mod-layout/package.json b/mods/mod-layout/package.json index dfcae45ba..adcc2b475 100644 --- a/mods/mod-layout/package.json +++ b/mods/mod-layout/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/mod-layout", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/mods/mod-markdown/package.json b/mods/mod-markdown/package.json index 4b2481298..29123aaef 100644 --- a/mods/mod-markdown/package.json +++ b/mods/mod-markdown/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/mod-markdown", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/mods/mod-math/package.json b/mods/mod-math/package.json index fe384030a..4bab1fa80 100644 --- a/mods/mod-math/package.json +++ b/mods/mod-math/package.json @@ -1,7 +1,7 @@ { "name": "@newcar/mod-math", "type": "module", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/mods/mod-skottie/package.json b/mods/mod-skottie/package.json index ab6d1829c..62c9b260e 100644 --- a/mods/mod-skottie/package.json +++ b/mods/mod-skottie/package.json @@ -1,7 +1,7 @@ { "name": "@newcar/mod-skottie", "type": "module", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/basic/package.json b/packages/basic/package.json index dfd2a5d75..268868c8d 100644 --- a/packages/basic/package.json +++ b/packages/basic/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/basic", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "The basic objects, animations and interpolators of newcar.", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/core/package.json b/packages/core/package.json index 6f6f1d460..1ecdd3527 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,7 +1,7 @@ { "name": "@newcar/core", "type": "module", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "The core of newcar.", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/json/package.json b/packages/json/package.json index df241fcd7..be7811d24 100644 --- a/packages/json/package.json +++ b/packages/json/package.json @@ -1,7 +1,7 @@ { "name": "@newcar/json", "type": "module", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "The core of newcar.", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/json/src/import-widget.ts b/packages/json/src/import-widget.ts index 133eb6dfe..3b05b2cd0 100644 --- a/packages/json/src/import-widget.ts +++ b/packages/json/src/import-widget.ts @@ -1,10 +1,9 @@ import type { Widget, WidgetOptions } from '@newcar/core' -import { changeProperty, parallel } from '@newcar/core' +import { changeProperty, parallel, useFont, useImage } from '@newcar/core' import { Color, Shader, isString } from '@newcar/utils' import { linear } from '@newcar/basic' import type { WidgetFormat } from './format' import { processAction } from './process-action' -import { processResource } from './process-resource' export function processItem(color: string | Array) { if (Array.isArray(color)) { @@ -20,6 +19,16 @@ export function processItem(color: string | Array) { // eslint-disable-next-line no-new-func return Function(`return ${color.replace(/fn\(/, '').replace(/\)$/, '')}`)() } + else if (isString(color) && /image\(.+\)/.test(color)) { + return useImage(color.replace(/image\(/, '').replace(/\)$/, '')) + } + else if (isString(color) && /font\(.+\)/.test(color)) { + return useFont(color.replace(/font\(/, '').replace(/\)$/, '')) + } + else if (isString(color) && /calc\(.+\)/.test(color)) { + // eslint-disable-next-line no-new-func + return Function(`return ${color.replace(/calc\(/, '').replace(/\)$/, '')}`)() + } else { return color } @@ -27,21 +36,10 @@ export function processItem(color: string | Array) { export function processOptions(options: WidgetOptions) { for (const key in options) { - if (typeof (options as Record)[key] === 'object') + if (typeof (options as Record)[key] === 'object') { (options as Record)[key] = processOptions((options as Record)[key]) - const result1 = processResource((options as Record)[key]) - const result2 = processItem((options as Record)[key]) - if (isString(result2)) { - if (isString(result1)) { - (options as Record)[key] = (options as Record)[key] - } - else { - (options as Record)[key] = result1 - } - } - else { - (options as Record)[key] = result2 } + (options as Record)[key] = processItem((options as Record)[key]) } return options } @@ -50,19 +48,7 @@ export function processArguments(args: unknown[]) { const result = [] for (const arg of args) { if (isString(arg)) { - const result1 = processResource(arg as string) - const result2 = processItem(arg as string) - if (isString(result1)) { - if (isString(result2)) { - result.push(arg) - } - else { - result.push(result2) - } - } - else { - result.push(result1) - } + result.push(processItem(arg as string)) } else { result.push(arg) diff --git a/packages/json/src/process-resource.ts b/packages/json/src/process-resource.ts deleted file mode 100644 index d5886ece4..000000000 --- a/packages/json/src/process-resource.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { useFont, useImage } from '@newcar/core' - -export function processResource(str: string) { - const rex = /(?:image|font)\(.+\)/ - if (rex.test(str)) { - if (/image\(.+\)/) { - return useImage(str.replace(/image\(/, '').replace(/\)$/, '')) - } - else if (/font\(.+\)/.test(str)) { - return useFont(str.replace(/font\(/, '').replace(/\)$/, '')) - } - } - else { - return str - } -} diff --git a/packages/newcar/package.json b/packages/newcar/package.json index 2a690ee17..7c67ec3be 100644 --- a/packages/newcar/package.json +++ b/packages/newcar/package.json @@ -1,7 +1,7 @@ { "name": "newcar", "type": "module", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "A Highly configurable universal advanced engine, Born for creating animation rapidly.", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/recorder/package.json b/packages/recorder/package.json index 097e6dbe5..d31e48790 100644 --- a/packages/recorder/package.json +++ b/packages/recorder/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/recorder", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "The utils of newcar", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/utils/package.json b/packages/utils/package.json index bfa0726cf..42358f795 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/utils", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "The utils of newcar", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/plugins/plugin-debug/package.json b/plugins/plugin-debug/package.json index 08ca647e1..62a0d5b87 100644 --- a/plugins/plugin-debug/package.json +++ b/plugins/plugin-debug/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/plugin-debug", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/plugins/plugin-timeview/package.json b/plugins/plugin-timeview/package.json index 918783146..a474c1ad3 100644 --- a/plugins/plugin-timeview/package.json +++ b/plugins/plugin-timeview/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/plugin-timeview", - "version": "2.0.0-beta.9", + "version": "2.0.0-beta.10", "description": "", "author": "BugDuck Team", "license": "Apache-2.0",