Browse Source

add more events to sugar (fixes #1217)

master
Ulrich-Matthias Schäfer 8 months ago
parent
commit
2a8b5ea3fb
5 changed files with 93 additions and 58 deletions
  1. 4
    4
      package-lock.json
  2. 1
    1
      package.json
  3. 8
    1
      src/modules/optional/sugar.js
  4. 79
    52
      svg.js.d.ts
  5. 1
    0
      tsconfig.json

+ 4
- 4
package-lock.json View File

"rollup": "^3.25.1", "rollup": "^3.25.1",
"rollup-plugin-filesize": "^10.0.0", "rollup-plugin-filesize": "^10.0.0",
"svgdom": "^0.1.16", "svgdom": "^0.1.16",
"typescript": "^5.1.3",
"typescript": "^5.2.2",
"yargs": "^17.7.2" "yargs": "^17.7.2"
}, },
"funding": { "funding": {
} }
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "5.1.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz",
"integrity": "sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==",
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz",
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
"dev": true, "dev": true,
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",

+ 1
- 1
package.json View File

"rollup": "^3.25.1", "rollup": "^3.25.1",
"rollup-plugin-filesize": "^10.0.0", "rollup-plugin-filesize": "^10.0.0",
"svgdom": "^0.1.16", "svgdom": "^0.1.16",
"typescript": "^5.1.3",
"typescript": "^5.2.2",
"yargs": "^17.7.2" "yargs": "^17.7.2"
}, },
"browserslist": ">0.3%, last 2 version, not dead, not op_mini all" "browserslist": ">0.3%, last 2 version, not dead, not op_mini all"

+ 8
- 1
src/modules/optional/sugar.js View File

'touchmove', 'touchmove',
'touchleave', 'touchleave',
'touchend', 'touchend',
'touchcancel'
'touchcancel',
'contextmenu',
'wheel',
'pointerdown',
'pointermove',
'pointerup',
'pointerleave',
'pointercancel'
].reduce(function (last, event) { ].reduce(function (last, event) {
// add event to Element // add event to Element
const fn = function (f) { const fn = function (f) {

+ 79
- 52
svg.js.d.ts View File

isRoot(): boolean isRoot(): boolean
} }


type EventHandler<T extends Event> = (event: T) => void

interface Sugar { interface Sugar {
fill(): string fill(): string
fill(fill: FillData): this fill(fill: FillData): this
font(a: string): string font(a: string): string
font(a: string, v: string | number): this font(a: string, v: string | number): this
font(a: object): this font(a: object): this

click(cb: EventHandler<MouseEvent>): this
dblclick(cb: EventHandler<MouseEvent>): this
mousedown(cb: EventHandler<MouseEvent>): this
mouseup(cb: EventHandler<MouseEvent>): this
mouseover(cb: EventHandler<MouseEvent>): this
mouseout(cb: EventHandler<MouseEvent>): this
mousemove(cb: EventHandler<MouseEvent>): this
mouseenter(cb: EventHandler<MouseEvent>): this
mouseleave(cb: EventHandler<MouseEvent>): this
touchstart(cb: EventHandler<TouchEvent>): this
touchmove(cb: EventHandler<TouchEvent>): this
touchleave(cb: EventHandler<TouchEvent>): this
touchend(cb: EventHandler<TouchEvent>): this
touchcancel(cb: EventHandler<TouchEvent>): this
contextmenu(cb: EventHandler<MouseEvent>): this
wheel(cb: EventHandler<WheelEvent>): this
pointerdown(cb: EventHandler<PointerEvent>): this
pointermove(cb: EventHandler<PointerEvent>): this
pointerup(cb: EventHandler<PointerEvent>): this
pointerleave(cb: EventHandler<PointerEvent>): this
pointercancel(cb: EventHandler<PointerEvent>): this
} }


// Symbol.js // Symbol.js
before(element: Element): Element before(element: Element): Element
center(x: number, y: number): this center(x: number, y: number): this
classes(): string[] classes(): string[]
click(cb: Function | null): this
clipper(): ClipPath clipper(): ClipPath
clipWith(element: Element): this clipWith(element: Element): this
clone(deep?: boolean, assignNewIds?: boolean): this clone(deep?: boolean, assignNewIds?: boolean): this
data(name: string, value: any, sustain?: boolean): this data(name: string, value: any, sustain?: boolean): this
data(name: string): any data(name: string): any
data(val: object): this data(val: object): this
dblclick(cb: Function | null): this
defs(): Defs defs(): Defs
dmove(x: NumberAlias, y: NumberAlias): this dmove(x: NumberAlias, y: NumberAlias): this
dx(x: NumberAlias): this dx(x: NumberAlias): this
dy(y: NumberAlias): this dy(y: NumberAlias): this
event(): Event | CustomEvent event(): Event | CustomEvent
fill(): any
fill(color: string): this
fill(color: Color | ColorLike): this
fill(color: FillData): this
fill(pattern: Element): this

fire(event: Event): this fire(event: Event): this
fire(event: string, data?: any): this fire(event: string, data?: any): this
flip(a: string, offset?: number): this
flip(offset?: number): this
font(a: object): this
font(a: string, v: string | number): this
font(a: string): string
forget(...keys: string[]): this forget(...keys: string[]): this
forget(): this forget(): this
forward(): this forward(): this
maskWith(element: Element): this maskWith(element: Element): this
maskWith(mask: Mask): this maskWith(mask: Mask): this
matches(selector: string): boolean matches(selector: string): boolean
matrix(): Matrix
matrix(
a?: number,
b?: number,
c?: number,
d?: number,
e?: number,
f?: number
): this
matrix(
mat: MatrixAlias,
b?: number,
c?: number,
d?: number,
e?: number,
f?: number
): this
matrixify(): Matrix matrixify(): Matrix
memory(): object memory(): object
mousedown(cb: Function | null): this
mousemove(cb: Function | null): this
mouseout(cb: Function | null): this
mouseover(cb: Function | null): this
mouseup(cb: Function | null): this
mouseenter(cb: Function | null): this
mouseleave(cb: Function | null): this
move(x: NumberAlias, y: NumberAlias): this move(x: NumberAlias, y: NumberAlias): this
native(): LinkedHTMLElement native(): LinkedHTMLElement
next(): Element next(): Element
// off(events?: string | Event[], cb?: EventListener | number): this; // off(events?: string | Event[], cb?: EventListener | number): this;
// on(event: string, cb: Function, context?: object): this; // on(event: string, cb: Function, context?: object): this;
opacity(): number
opacity(o: number): this
relative(x: number, y: number): this
shear(lam: Matrix, cx: number, cy: number): this
toRoot(): Svg toRoot(): Svg
/** /**
* By default parents will return a list of elements up until the root svg. * By default parents will return a list of elements up until the root svg.
remove(): this remove(): this
removeClass(name: string): this removeClass(name: string): this
root(): Svg root(): Svg
rotate(d: number, cx?: number, cy?: number): this
scale(x?: number, y?: number, cx?: number, cy?: number): this
screenCTM(): Matrix screenCTM(): Matrix
setData(data: object): this setData(data: object): this
show(): this show(): this
show(): this show(): this
size(width?: NumberAlias, height?: NumberAlias): this size(width?: NumberAlias, height?: NumberAlias): this
skew(x?: number, y?: number, cx?: number, cy?: number): this
stop(jumpToEnd: boolean, clearQueue: boolean): Animation stop(jumpToEnd: boolean, clearQueue: boolean): Animation
stop( stop(
offset?: NumberAlias | string, offset?: NumberAlias | string,
color?: NumberAlias color?: NumberAlias
opacity?: NumberAlias opacity?: NumberAlias
}): Stop }): Stop
stroke(): any
stroke(color: string): this
stroke(stroke: StrokeData): this
timeline(): Timeline timeline(): Timeline
timeline(tl: Timeline): this timeline(tl: Timeline): this
toggleClass(name: string): this toggleClass(name: string): this
toParent(parent: Dom): this toParent(parent: Dom): this
toParent(parent: Dom, i: number): this toParent(parent: Dom, i: number): this
toSvg(): this toSvg(): this
touchcancel(cb: Function | null): this
touchend(cb: Function | null): this
touchleave(cb: Function | null): this
touchmove(cb: Function | null): this
touchstart(cb: Function | null): this
transform(): MatrixExtract transform(): MatrixExtract
transform(t: MatrixAlias, relative?: boolean): this transform(t: MatrixAlias, relative?: boolean): this
translate(x: number, y: number): this
unclip(): this unclip(): this
unmask(): this unmask(): this
untransform(): this untransform(): this
x(x: NumberAlias): this x(x: NumberAlias): this
y(): NumberAlias y(): NumberAlias
y(y: NumberAlias): this y(y: NumberAlias): this

fill(): string
fill(fill: FillData): this
fill(color: string): this
fill(pattern: Element): this
fill(image: Image): this
stroke(): string
stroke(stroke: StrokeData): this
stroke(color: string): this
matrix(): Matrix
matrix(
a: number,
b: number,
c: number,
d: number,
e: number,
f: number
): this
matrix(mat: MatrixAlias): this
rotate(degrees: number, cx?: number, cy?: number): this
skew(skewX?: number, skewY?: number, cx?: number, cy?: number): this
scale(scaleX?: number, scaleY?: number, cx?: number, cy?: number): this
translate(x: number, y: number): this
shear(lam: number, cx: number, cy: number): this
relative(x: number, y: number): this
flip(direction?: string, around?: number): this
flip(around: number): this
opacity(): number
opacity(value: number): this
font(a: string): string
font(a: string, v: string | number): this
font(a: object): this

click(cb: EventHandler<MouseEvent>): this
dblclick(cb: EventHandler<MouseEvent>): this
mousedown(cb: EventHandler<MouseEvent>): this
mouseup(cb: EventHandler<MouseEvent>): this
mouseover(cb: EventHandler<MouseEvent>): this
mouseout(cb: EventHandler<MouseEvent>): this
mousemove(cb: EventHandler<MouseEvent>): this
mouseenter(cb: EventHandler<MouseEvent>): this
mouseleave(cb: EventHandler<MouseEvent>): this
touchstart(cb: EventHandler<TouchEvent>): this
touchmove(cb: EventHandler<TouchEvent>): this
touchleave(cb: EventHandler<TouchEvent>): this
touchend(cb: EventHandler<TouchEvent>): this
touchcancel(cb: EventHandler<TouchEvent>): this
contextmenu(cb: EventHandler<MouseEvent>): this
wheel(cb: EventHandler<WheelEvent>): this
pointerdown(cb: EventHandler<PointerEvent>): this
pointermove(cb: EventHandler<PointerEvent>): this
pointerup(cb: EventHandler<PointerEvent>): this
pointerleave(cb: EventHandler<PointerEvent>): this
pointercancel(cb: EventHandler<PointerEvent>): this
} }


// ellipse.js // ellipse.js

+ 1
- 0
tsconfig.json View File

{}

Loading…
Cancel
Save