canvasengine 2.0.0-rc.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasengine",
3
- "version": "2.0.0-rc.4",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -240,7 +240,22 @@ export function Circle(props: CircleProps) {
240
240
  }
241
241
 
242
242
  export function Ellipse(props: EllipseProps) {
243
- return Circle(props as CircleProps);
243
+ const { color, border } = useProps(props, {
244
+ border: null
245
+ })
246
+
247
+ return Graphics({
248
+ draw: (g, width, height, anchor) => {
249
+ const { x, y } = graphicsAnchor(anchor, width, height);
250
+ g.ellipse(x + width / 2, y + height / 2, width / 2, height / 2);
251
+ const borderValue = propValue(border);
252
+ if (borderValue) {
253
+ g.stroke(borderValue);
254
+ }
255
+ g.fill(propValue(color));
256
+ },
257
+ ...props
258
+ })
244
259
  }
245
260
 
246
261
  export function Triangle(props: TriangleProps) {
@@ -753,7 +753,7 @@ export class CanvasSprite extends DisplayObject(PixiSprite) {
753
753
  spriteHeight: number,
754
754
  realSize?: TextureOptionsMerging["spriteRealSize"]
755
755
  ) {
756
- if (!this.hitbox || !spriteWidth || !spriteHeight) {
756
+ if (!this.hitbox || !spriteWidth || !spriteHeight || !this.anchor) {
757
757
  return;
758
758
  }
759
759
 
@@ -163,6 +163,49 @@ export const useDefineProps = (props: any) => {
163
163
  }
164
164
  }
165
165
 
166
+ const getRawProps = (props: any) => isSignal(props) ? props() : (props ?? {})
167
+
168
+ const getEmitHandler = (handler: any) => {
169
+ if (handler?.[DEFINE_PROPS_CALLABLE_SIGNAL_VALUE]) return handler
170
+ if (isSignal(handler)) return handler()
171
+ return handler
172
+ }
173
+
174
+ /**
175
+ * Defines event emitters from component props.
176
+ *
177
+ * @param {object} props - The raw component props containing event handlers.
178
+ * @returns {function} A function returning named emit callbacks.
179
+ *
180
+ * @example
181
+ * const { select } = useDefineEmits({ select: (item) => item.id })();
182
+ * select({ id: 1 });
183
+ */
184
+ export const useDefineEmits = (props: any) => {
185
+ return () => new Proxy({}, {
186
+ get(_target, key) {
187
+ if (typeof key !== 'string') {
188
+ return undefined
189
+ }
190
+
191
+ return (...args: any[]) => {
192
+ const rawProps = getRawProps(props)
193
+ const handler = getEmitHandler(rawProps[key])
194
+
195
+ if (handler === undefined || handler === null) {
196
+ return undefined
197
+ }
198
+
199
+ if (typeof handler !== 'function') {
200
+ throw new Error(`Invalid emit handler: "${key}" must be a function`)
201
+ }
202
+
203
+ return handler(...args)
204
+ }
205
+ }
206
+ })
207
+ }
208
+
166
209
  /**
167
210
  * Validates the type of a property.
168
211
  *
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ export * from './engine/trigger'
10
10
  export * from './engine/bootstrap'
11
11
  export * from './engine/animation'
12
12
  export { FocusManager, focusManager, type ScrollOptions } from './engine/FocusManager'
13
- export { useProps, useDefineProps } from './hooks/useProps'
13
+ export { useProps, useDefineProps, useDefineEmits } from './hooks/useProps'
14
14
  export { useFocusIndex, useFocusedElement, useFocusChange } from './hooks/useFocus'
15
15
  export * from './utils/Ease'
16
16
  export * from './utils/RadialGradient'