diff --git a/packages/math/src/angle/index.ts b/packages/math/src/angle/index.ts index c7e2065..b8a21f4 100644 --- a/packages/math/src/angle/index.ts +++ b/packages/math/src/angle/index.ts @@ -36,6 +36,8 @@ export const angle = defineComponent<'angle', typeof T.infer>((attrs) => { endSide: 10, startSideType: 'solid', endSideType: 'solid', + x: 0, + y: 0, }, setup(children) { const container = document.createElementNS('http://www.w3.org/2000/svg', 'g') diff --git a/packages/math/src/angle/points.ts b/packages/math/src/angle/points.ts index b8911d1..71e8158 100644 --- a/packages/math/src/angle/points.ts +++ b/packages/math/src/angle/points.ts @@ -15,9 +15,13 @@ export const angleStartPoint = defineComponent<'start-point', typeof InfoPointTy return { name: 'start-point', attrs: InfoPointType, - globals: { - [attrs.as.value]: position, - }, + globals: (() => { + if ('as' in attrs) { + return { + [attrs.as.value]: position, + } + } + })(), defaults: { value: '', }, @@ -44,9 +48,13 @@ export const angleEndPoint = defineComponent<'end-point', typeof InfoPointType.i return { name: 'end-point', attrs: InfoPointType, - globals: { - [attrs.as.value]: position, - }, + globals: (() => { + if ('as' in attrs) { + return { + [attrs.as.value]: position, + } + } + })(), defaults: { value: '', }, @@ -67,8 +75,21 @@ export const origin = defineComponent<'origin', typeof InfoPointType.infer, { return { name: 'origin', attrs: InfoPointType, - globals: { - [attrs.as.value]: [context.x, context.y], + globals: (() => { + if ('as' in attrs) { + return { + [attrs.as.value]: [context.x, context.y], + } + } + })(), + defaults: { + value: '', + }, + setup() { + const container = document.createElementNS('http://www.w3.org/2000/svg', 'g') + const texElement = generateTexNode(attrs.value.value) + container.append(texElement) + return container }, defaults: { value: '', diff --git a/packages/math/src/axis/index.ts b/packages/math/src/axis/index.ts index fc26c8d..691ee91 100644 --- a/packages/math/src/axis/index.ts +++ b/packages/math/src/axis/index.ts @@ -27,6 +27,9 @@ export const axis = defineComponent<'axis', typeof T.infer>((attrs) => { // division: 20, label: (count: number) => count.toString(), direction: 'right', + x: 0, + y: 0, + range: [-5, 5], }, setup(children) { const root = document.createElementNS('http://www.w3.org/2000/svg', 'g') diff --git a/packages/math/src/circle/points.ts b/packages/math/src/circle/points.ts index a41cf19..bb75d5c 100644 --- a/packages/math/src/circle/points.ts +++ b/packages/math/src/circle/points.ts @@ -16,7 +16,7 @@ export const edgePoint = defineComponent< } >((attrs, context) => { const { x, y, radius } = context - const { value, as } = attrs + const { value } = attrs const point = [ x + radius * Math.cos(value.value), y + radius * Math.sin(value.value), @@ -24,9 +24,13 @@ export const edgePoint = defineComponent< return { name: 'edge-points', attrs: EdgePointType, - globals: { - [as.value]: point, - }, + globals: (() => { + if ('as' in attrs) { + return { + [attrs.as.value]: point, + } + } + })(), } }) @@ -42,12 +46,15 @@ export const origin = defineComponent< y: number } >((attrs, context) => { - const { as } = attrs return { name: 'origin', attrs: OriginType, - globals: { - [as.value]: [context.x, context.y], - }, + globals: (() => { + if ('as' in attrs) { + return { + [attrs.as.value]: [context.x, context.y], + } + } + })(), } }) diff --git a/packages/math/src/dot/index.ts b/packages/math/src/dot/index.ts new file mode 100644 index 0000000..c865493 --- /dev/null +++ b/packages/math/src/dot/index.ts @@ -0,0 +1,49 @@ +import { theme } from '@sciux/utils-theme' +import { type } from 'arktype' +import { defineComponent } from 'sciux-laplace' +import { generateTexNode } from '../utils/tex' + +const T = type({ + x: type.number, + y: type.number, + value: type.string, + as: type.string, +}) + +export const dot = defineComponent<'dot', typeof T.infer, { division: number | undefined }>((attrs, context) => { + return { + name: 'dot', + attrs: T, + defaults: { + x: 0, + y: 0, + value: '', + }, + provides: (() => { + if ('as' in attrs) { + return { + [attrs.as.value]: [attrs.x.value * (context.division ?? 1), attrs.y.value * (context.division ?? 1)], + } + } + })(), + setup() { + const container = document.createElementNS('http://www.w3.org/2000/svg', 'g') + container.setAttribute('transform', `translate(${attrs.x.value * (context.division ?? 1)}, ${attrs.y.value * (context.division ?? 1)})`) + + const dotSvg = document.createElementNS('http://www.w3.org/2000/svg', 'circle') + dotSvg.id = 'dot-circle' + container.id = 'canvas-dot' + dotSvg.setAttribute('stroke', 'none') + dotSvg.setAttribute('fill', theme.pallete('primary')) + dotSvg.setAttribute('r', '2') + + if (attrs.value.value) { + const label = generateTexNode(attrs.value.value) + container.append(label) + } + + container.appendChild(dotSvg) + return container + }, + } +}) diff --git a/packages/math/src/index.ts b/packages/math/src/index.ts index 09621eb..67d9fe6 100644 --- a/packages/math/src/index.ts +++ b/packages/math/src/index.ts @@ -1,6 +1,7 @@ export * from './angle' export * from './axis' export * from './circle' +export * from './dot' export * from './figure' export * from './function' export * from './line' diff --git a/packages/math/src/line/points.ts b/packages/math/src/line/points.ts index e98f6dd..3cd3cf6 100644 --- a/packages/math/src/line/points.ts +++ b/packages/math/src/line/points.ts @@ -18,9 +18,13 @@ export const lineStartPoint = defineComponent<'start-point', typeof InfoPointTyp container.append(texElement) return container }, - globals: { - [attrs.as.value]: context.from, - }, + globals: (() => { + if ('as' in attrs) { + return { + [attrs.as.value]: context.from, + } + } + })(), } }) @@ -40,8 +44,12 @@ export const lineEndPoint = defineComponent<'end-point', typeof InfoPointType.in container.append(texElement) return container }, - globals: { - [attrs.as.value]: context.to, - }, + globals: (() => { + if ('as' in attrs) { + return { + [attrs.as.value]: context.to, + } + } + })(), } }) diff --git a/packages/math/src/plane/index.ts b/packages/math/src/plane/index.ts index cb43295..e1179ff 100644 --- a/packages/math/src/plane/index.ts +++ b/packages/math/src/plane/index.ts @@ -36,6 +36,10 @@ export const plane = defineComponent<'plane', typeof T.infer>((attrs) => { yLabel: (count: number) => count.toString(), xDirection: 'right', yDirection: 'top', + x: 0, + y: 0, + domain: [-5, 5], + range: [-5, 5], }, setup(children) { const root = document.createElementNS('http://www.w3.org/2000/svg', 'g') diff --git a/packages/math/src/plane/projection.ts b/packages/math/src/plane/projection.ts index df0342f..e6223bc 100644 --- a/packages/math/src/plane/projection.ts +++ b/packages/math/src/plane/projection.ts @@ -20,6 +20,8 @@ export const projection = defineComponent<'projection', typeof T.infer, { defaults: { type: 'both', value: '', + x: 0, + y: 0, }, setup() { const container = document.createElementNS('http://www.w3.org/2000/svg', 'g') diff --git a/packages/model/src/checkbox.ts b/packages/model/src/checkbox.ts index d31b34d..7e562d9 100644 --- a/packages/model/src/checkbox.ts +++ b/packages/model/src/checkbox.ts @@ -13,6 +13,9 @@ export default defineComponent<'checkbox', typeof T.infer, Context>((attrs, cont return { name: 'checkbox', attrs: T, + defaults: { + disabled: false, + }, setup: () => { const input = document.createElement('input') input.type = 'checkbox' diff --git a/packages/model/src/radio.ts b/packages/model/src/radio.ts index ec99267..34f6824 100644 --- a/packages/model/src/radio.ts +++ b/packages/model/src/radio.ts @@ -8,12 +8,18 @@ const T = type({ model: 'string', group: 'string', value: 'string', + disabled: 'boolean', }) export default defineComponent<'radio', typeof T.infer, Context>((attrs, context) => { return { name: 'radio', attrs: T, + defaults: { + value: '', + group: '__default_radio_group', + disabled: false, + }, setup: () => { const input = document.createElement('input') input.type = 'radio' diff --git a/packages/model/src/select.ts b/packages/model/src/select.ts index fe2ad2c..01cfa0b 100644 --- a/packages/model/src/select.ts +++ b/packages/model/src/select.ts @@ -18,6 +18,9 @@ export const select = defineComponent<'select', typeof SelectType.infer, Context return { name: 'select', attrs: SelectType, + defaults: { + disabled: false, + }, setup: (children) => { const select = document.createElement('select') if (attrs.model) { @@ -40,6 +43,10 @@ export const selectOption = defineComponent<'option', typeof SelectOptionType.in return { name: 'option', attrs: SelectOptionType, + defaults: { + disabled: false, + value: '__efault_select_option_value', + }, setup: (children) => { option.value = toValue(attrs.value) option.selected = toValue(attrs.selected) diff --git a/packages/model/src/slider.ts b/packages/model/src/slider.ts index fdfd1b5..6c8070c 100644 --- a/packages/model/src/slider.ts +++ b/packages/model/src/slider.ts @@ -14,6 +14,10 @@ export default defineComponent<'slider', typeof T.infer, Context>((attrs, contex return { name: 'slider', attrs: T, + defaults: { + value: 0, + disabled: false, + }, setup: () => { const input = document.createElement('input') input.type = 'range' diff --git a/packages/sciux/src/math.ts b/packages/sciux/src/math.ts index 97929f5..7fe108f 100644 --- a/packages/sciux/src/math.ts +++ b/packages/sciux/src/math.ts @@ -1,6 +1,6 @@ import type { Animation, Component } from 'sciux-laplace' import type { RegisterContext } from './types' -import { angle, angleArcCreation, angleCreation, axis, axisCreation, circle, circleCreation, figure, func, funcCreation, line, lineCreation, parametric, parametricCreation, plane, planeCreation, projectionCreation, tools, vector, vectorCreation } from '@sciux/math' +import { angle, angleArcCreation, angleCreation, axis, axisCreation, circle, circleCreation, dot, figure, func, funcCreation, line, lineCreation, parametric, parametricCreation, plane, planeCreation, projectionCreation, tools, vector, vectorCreation } from '@sciux/math' import { withSpace } from 'sciux-laplace' import { canvasSpace } from './widget' @@ -14,6 +14,7 @@ export default function ({ animations, context }: RegisterContext): void { canvasSpace.set('axis', axis) canvasSpace.set('plane', withSpace(plane as Component<'plane', any, any>, canvasSpace)) canvasSpace.set('parametric', parametric) + canvasSpace.set('dot', dot) const creation = []> animations.get('creation') creation.push(angleCreation, angleArcCreation, circleCreation, lineCreation, funcCreation, parametricCreation, axisCreation, planeCreation, projectionCreation, vectorCreation) Object.assign(context, tools) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2c8df32..7ccd03b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,8 +49,8 @@ catalogs: specifier: ^10.4.0 version: 10.4.0 sciux-laplace: - specifier: v0.0.1-beta.12 - version: 0.0.1-beta.12 + specifier: v0.0.1-beta.13 + version: 0.0.1-beta.13 simple-git-hooks: specifier: ^2.11.1 version: 2.11.1 @@ -194,7 +194,7 @@ importers: version: 2.1.20 sciux-laplace: specifier: 'catalog:' - version: 0.0.1-beta.12 + version: 0.0.1-beta.13 packages/math: dependencies: @@ -212,7 +212,7 @@ importers: version: 2.1.20 sciux-laplace: specifier: 'catalog:' - version: 0.0.1-beta.12 + version: 0.0.1-beta.13 packages/model: dependencies: @@ -224,7 +224,7 @@ importers: version: 2.1.20 sciux-laplace: specifier: 'catalog:' - version: 0.0.1-beta.12 + version: 0.0.1-beta.13 packages/sciux: dependencies: @@ -245,7 +245,7 @@ importers: version: link:../widget sciux-laplace: specifier: 'catalog:' - version: 0.0.1-beta.12 + version: 0.0.1-beta.13 packages/theme-default: dependencies: @@ -263,7 +263,7 @@ importers: version: 0.16.22 sciux-laplace: specifier: 'catalog:' - version: 0.0.1-beta.12 + version: 0.0.1-beta.13 shiki: specifier: ^3.4.2 version: 3.4.2 @@ -278,7 +278,7 @@ importers: version: 2.1.20 sciux-laplace: specifier: 'catalog:' - version: 0.0.1-beta.12 + version: 0.0.1-beta.13 packages/widget: dependencies: @@ -299,7 +299,7 @@ importers: version: 0.16.22 sciux-laplace: specifier: 'catalog:' - version: 0.0.1-beta.12 + version: 0.0.1-beta.13 shiki: specifier: ^3.4.2 version: 3.4.2 @@ -326,7 +326,7 @@ importers: version: link:../packages/sciux sciux-laplace: specifier: 'catalog:' - version: 0.0.1-beta.12 + version: 0.0.1-beta.13 devDependencies: typescript: specifier: ~5.8.3 @@ -4082,8 +4082,8 @@ packages: safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} - sciux-laplace@0.0.1-beta.12: - resolution: {integrity: sha512-mMj6cINCotgTS/IPwitfh6RRA3fujk+n0rDRIpag4FAGcYel8eFNhIYuCGn6QfBtQgVtmpCcXS+d7ec23rnvog==} + sciux-laplace@0.0.1-beta.13: + resolution: {integrity: sha512-816T+z5L+X2T/nXgsbjz98Ot7fWmDosQ/C0RQ6tSgE0671cIchFuAf8SxmmF/EM7Xf5IGA4mt0/egAQY0HCQxg==} scslre@0.3.0: resolution: {integrity: sha512-3A6sD0WYP7+QrjbfNA2FN3FsOaGGFoekCVgTyypy53gPxhbkCIjtO6YWgdrfM+n/8sI8JeXZOIxsHjMTNxQ4nQ==} @@ -8837,7 +8837,7 @@ snapshots: safer-buffer@2.1.2: {} - sciux-laplace@0.0.1-beta.12: + sciux-laplace@0.0.1-beta.13: dependencies: '@vue/reactivity': 3.5.14 '@vue/shared': 3.5.14 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 2a67f94..5b3b158 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -31,4 +31,4 @@ catalog: vitepress-plugin-group-icons: ^1.3.5 vitest: ^3.0.5 vue: ^3.5.13 - sciux-laplace: v0.0.1-beta.12 + sciux-laplace: v0.0.1-beta.13 diff --git a/test/src/examples.ts b/test/src/examples.ts index a5a018f..0986d95 100644 --- a/test/src/examples.ts +++ b/test/src/examples.ts @@ -4,6 +4,7 @@ import ins02 from './template/instance/ins02.sciux?raw' import angle from './template/math/angle.sciux?raw' import axis from './template/math/axis.sciux?raw' import circle from './template/math/circle.sciux?raw' +import dot from './template/math/dot.sciux?raw' import figure from './template/math/figure.sciux?raw' import parametric from './template/math/parametric.sciux?raw' import plane from './template/math/plane.sciux?raw' @@ -22,6 +23,7 @@ export default { plane, parametric, axis, + dot, }, 'INSTANCE': { ins01, diff --git a/test/src/template/math/dot.sciux b/test/src/template/math/dot.sciux new file mode 100644 index 0000000..4dcd3eb --- /dev/null +++ b/test/src/template/math/dot.sciux @@ -0,0 +1,5 @@ + + + + +