Skip to content

Commit 3477201

Browse files
committed
pixiv7
1 parent 1d65518 commit 3477201

File tree

18 files changed

+430
-348
lines changed

18 files changed

+430
-348
lines changed

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
},
5555
"homepage": "https://github.com/davidfig/pixi-viewport#readme",
5656
"peerDependencies": {
57-
"@pixi/display": "^6.5.8",
58-
"@pixi/interaction": "^6.5.8",
59-
"@pixi/math": "^6.5.8",
60-
"@pixi/ticker": "^6.5.8"
57+
"@pixi/display": "^7.0.4",
58+
"@pixi/events": "^7.0.4",
59+
"@pixi/math": "^7.0.4",
60+
"@pixi/ticker": "^7.0.4"
6161
},
6262
"dependencies": {},
6363
"devDependencies": {
@@ -66,12 +66,11 @@
6666
"@joseph184/rollup-plugin-node-builtins": "^2.1.4",
6767
"@microsoft/api-extractor": "^7.18.19",
6868
"@pixi-build-tools/rollup-configurator": "^1.0.14",
69-
"@pixi/display": "^6.5.8",
69+
"@pixi/display": "^7.0.4",
7070
"@pixi/eslint-config": "^4.0.1",
71-
"@pixi/events": "^6.5.8",
72-
"@pixi/interaction": "^6.5.8",
73-
"@pixi/math": "^6.5.8",
74-
"@pixi/ticker": "^6.5.8",
71+
"@pixi/events": "^7.0.4",
72+
"@pixi/math": "^7.0.4",
73+
"@pixi/ticker": "^7.0.4",
7574
"@rollup/plugin-babel": "^5.3.0",
7675
"@rollup/plugin-commonjs": "^22.0.2",
7776
"@rollup/plugin-node-resolve": "^13.0.6",
@@ -91,7 +90,7 @@
9190
"fs-extra": "^10.0.0",
9291
"jsdoc": "^3.6.3",
9392
"pixi-ease": "^3.0.7",
94-
"pixi.js": "^6.5.8",
93+
"pixi.js": "^7.0.4",
9594
"raf": "^3.4.1",
9695
"rollup": "^2.60.2",
9796
"rollup-plugin-node-globals": "^1.4.0",

src/InputManager.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Point, Rectangle } from '@pixi/math';
1+
import { Point, Rectangle } from '@pixi/core';
22

3-
import type { IPointData } from '@pixi/math';
4-
import type { InteractionEvent } from '@pixi/interaction';
3+
import type { IPointData } from '@pixi/core';
4+
import type { FederatedPointerEvent } from '@pixi/events';
55
import type { Viewport } from './Viewport';
66

77
export interface IViewportTouch
@@ -70,25 +70,25 @@ export class InputManager
7070
/**
7171
* handle down events for viewport
7272
*
73-
* @param {PIXI.InteractionEvent} event
73+
* @param {PIXI.FederatedPointerEvent} event
7474
*/
75-
public down(event: InteractionEvent): void
75+
public down(event: FederatedPointerEvent): void
7676
{
7777
if (this.viewport.pause || !this.viewport.worldVisible)
7878
{
7979
return;
8080
}
81-
if (event.data.pointerType === 'mouse')
81+
if (event.pointerType === 'mouse')
8282
{
8383
this.isMouseDown = true;
8484
}
85-
else if (!this.get(event.data.pointerId))
85+
else if (!this.get(event.pointerId))
8686
{
87-
this.touches.push({ id: event.data.pointerId, last: null });
87+
this.touches.push({ id: event.pointerId, last: null });
8888
}
8989
if (this.count() === 1)
9090
{
91-
this.last = event.data.global.clone();
91+
this.last = event.global.clone();
9292

9393
// clicked event does not fire if viewport is decelerating or bouncing
9494
const decelerate = this.viewport.plugins.get('decelerate', true);
@@ -139,7 +139,7 @@ export class InputManager
139139
}
140140

141141
/** Handle move events for viewport */
142-
public move(event: InteractionEvent): void
142+
public move(event: FederatedPointerEvent): void
143143
{
144144
if (this.viewport.pause || !this.viewport.worldVisible)
145145
{
@@ -150,8 +150,8 @@ export class InputManager
150150

151151
if (this.clickedAvailable && this.last)
152152
{
153-
const distX = event.data.global.x - this.last.x;
154-
const distY = event.data.global.y - this.last.y;
153+
const distX = event.global.x - this.last.x;
154+
const distY = event.global.y - this.last.y;
155155

156156
if (this.checkThreshold(distX) || this.checkThreshold(distY))
157157
{
@@ -166,21 +166,21 @@ export class InputManager
166166
}
167167

168168
/** Handle up events for viewport */
169-
public up(event: InteractionEvent): void
169+
public up(event: FederatedPointerEvent): void
170170
{
171171
if (this.viewport.pause || !this.viewport.worldVisible)
172172
{
173173
return;
174174
}
175175

176-
if (event.data.pointerType === 'mouse')
176+
if (event.pointerType === 'mouse')
177177
{
178178
this.isMouseDown = false;
179179
}
180180

181-
if (event.data.pointerType !== 'mouse')
181+
if (event.pointerType !== 'mouse')
182182
{
183-
this.remove(event.data.pointerId);
183+
this.remove(event.pointerId);
184184
}
185185

186186
const stop = this.viewport.plugins.up(event);
@@ -191,7 +191,7 @@ export class InputManager
191191
event,
192192
screen: this.last,
193193
world: this.viewport.toWorld(this.last),
194-
viewport: this
194+
viewport: this.viewport
195195
});
196196
this.clickedAvailable = false;
197197
}

src/PluginManager.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
SnapZoom,
1414
Wheel,
1515
} from './plugins';
16-
import type { InteractionEvent } from '@pixi/interaction';
16+
import type { FederatedEvent } from '@pixi/events';
1717
import type { Viewport } from './Viewport';
1818

1919
const PLUGIN_ORDER = [
@@ -70,7 +70,6 @@ export class PluginManager
7070
*/
7171
public add(name: string, plugin: Plugin, index: number = PLUGIN_ORDER.length)
7272
{
73-
7473
const oldPlugin = this.plugins[name];
7574

7675
if (oldPlugin)
@@ -165,9 +164,10 @@ export class PluginManager
165164
/** removes all installed plugins */
166165
public removeAll(): void
167166
{
168-
this.list.forEach((plugin) => {
167+
this.list.forEach((plugin) =>
168+
{
169169
plugin.destroy();
170-
})
170+
});
171171
this.plugins = {};
172172
this.sort();
173173
}
@@ -183,7 +183,7 @@ export class PluginManager
183183
{
184184
this.plugins[name]?.destroy();
185185
delete this.plugins[name];
186-
this.viewport.emit(`${name}-remove`);
186+
this.viewport.emit('plugin-remove', name);
187187
this.sort();
188188
}
189189
}
@@ -233,7 +233,7 @@ export class PluginManager
233233
* @internal
234234
* @ignore
235235
*/
236-
public down(event: InteractionEvent): boolean
236+
public down(event: FederatedEvent): boolean
237237
{
238238
let stop = false;
239239

@@ -254,7 +254,7 @@ export class PluginManager
254254
* @internal
255255
* @ignore
256256
*/
257-
public move(event: InteractionEvent): boolean
257+
public move(event: FederatedEvent): boolean
258258
{
259259
let stop = false;
260260

@@ -275,7 +275,7 @@ export class PluginManager
275275
* @internal
276276
* @ignore
277277
*/
278-
public up(event: InteractionEvent): boolean
278+
public up(event: FederatedEvent): boolean
279279
{
280280
let stop = false;
281281

src/Viewport.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Container } from '@pixi/display';
2-
import { IPointData, Point, Rectangle } from '@pixi/math';
3-
import { Ticker } from '@pixi/ticker';
2+
import { IPointData, Point, Rectangle, Ticker } from '@pixi/core';
43

54
import { InputManager } from './InputManager';
65
import { PluginManager } from './PluginManager';
@@ -20,7 +19,7 @@ import {
2019
} from './plugins';
2120

2221
import type { DisplayObject, IDestroyOptions } from '@pixi/display';
23-
import type { IHitArea, InteractionManager } from '@pixi/interaction';
22+
import type { IHitArea, EventSystem } from '@pixi/events';
2423

2524
/** Options for {@link Viewport}. */
2625
export interface IViewportOptions
@@ -70,11 +69,11 @@ export interface IViewportOptions
7069
noTicker?: boolean;
7170

7271
/**
73-
* InteractionManager, available from instantiated `WebGLRenderer/CanvasRenderer.plugins.interaction`
72+
* EventSystem, available from instantiated `WebGLRenderer/CanvasRenderer.plugins.interaction`
7473
*
7574
* It's used to calculate pointer postion relative to canvas location on screen
7675
*/
77-
interaction?: InteractionManager | null;
76+
interaction?: EventSystem | null;
7877

7978
/**
8079
* Remove oncontextmenu=() => {} from the divWheel element
@@ -158,7 +157,7 @@ const DEFAULT_VIEWPORT_OPTIONS: ICompleteViewportOptions = {
158157
* @fires bounce-y-start
159158
* @fires bounce-y-end
160159
* @fires bounce-remove
161-
* @fires wheel
160+
* @fires wheel-start
162161
* @fires wheel-remove
163162
* @fires wheel-scroll
164163
* @fires wheel-scroll-remove
@@ -219,7 +218,7 @@ export class Viewport extends Container
219218
* @param {HitArea} [options.forceHitArea] change the default hitArea from world size to a new value
220219
* @param {boolean} [options.noTicker] set this if you want to manually call update() function on each frame
221220
* @param {PIXI.Ticker} [options.ticker=PIXI.Ticker.shared] use this PIXI.ticker for updates
222-
* @param {PIXI.InteractionManager} [options.interaction=null] InteractionManager, available from instantiated
221+
* @param {PIXI.EventSystem} [options.interaction=null] EventSystem, available from instantiated
223222
* WebGLRenderer/CanvasRenderer.plugins.interaction - used to calculate pointer position relative to canvas
224223
* location on screen
225224
* @param {HTMLElement} [options.divWheel=document.body] div to attach the wheel event
@@ -1431,12 +1430,9 @@ export class Viewport extends Container
14311430

14321431
/**
14331432
* Fires when for a mouse wheel event
1434-
* @event Viewport#wheel
1433+
* @event Viewport#wheel-start
14351434
* @type {object}
1436-
* @property {object} wheel
1437-
* @property {number} wheel.dx
1438-
* @property {number} wheel.dy
1439-
* @property {number} wheel.dz
1435+
* @property {WheelEvent} event
14401436
* @property {Viewport} viewport
14411437
*/
14421438

src/global.d.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// https://github.com/pixijs/pixijs/issues/8957
2+
3+
declare namespace GlobalMixins
4+
{
5+
type Viewport = import('./Viewport').Viewport;
6+
type PixiVieportClickedEvent = import('./types').ClickedEvent;
7+
type PixiVieportDragEvent = import('./types').DragEvent;
8+
type PixiVieportMovedEvent = import('./types').MovedEvent;
9+
type PixiVieportZoomedEvent = import('./types').ZoomedEvent;
10+
type PixiVieportWheelStartEvent = import('./types').WheelStartEvent;
11+
12+
interface DisplayObjectEvents
13+
{
14+
clicked: [PixiVieportClickedEvent]
15+
'drag-start': [PixiVieportDragEvent],
16+
'drag-end': [PixiVieportDragEvent],
17+
moved: [PixiVieportMovedEvent],
18+
zoomed: [PixiVieportZoomedEvent],
19+
'pinch-start': [Viewport],
20+
'pinch-end': [Viewport],
21+
'snap-start': [Viewport],
22+
'snap-end': [Viewport],
23+
'snap-zoom-start': [Viewport],
24+
'snap-zoom-end': [Viewport],
25+
'bounce-x-start': [Viewport],
26+
'bounce-x-end': [Viewport],
27+
'bounce-y-start': [Viewport],
28+
'bounce-y-end': [Viewport],
29+
'wheel-start': [PixiVieportWheelStartEvent],
30+
'wheel-scroll': [Viewport],
31+
'animate-end': [Viewport],
32+
'mouse-edge-start': [Viewport],
33+
'mouse-edge-end': [Viewport],
34+
'moved-end': [Viewport],
35+
'zoomed-end': [Viewport],
36+
'frame-end': [Viewport],
37+
'plugin-remove': [string],
38+
}
39+
}

src/plugins/Animate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IPointData, Point } from '@pixi/math';
1+
import { IPointData, Point } from '@pixi/core';
22
import { Plugin } from './Plugin';
33
import ease from '../ease';
44

src/plugins/Bounce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Point, Rectangle } from '@pixi/math';
1+
import { Point, Rectangle } from '@pixi/core';
22
import { Plugin } from './Plugin';
33
import ease from '../ease';
44

src/plugins/Clamp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Point } from '@pixi/core';
12
import { Plugin } from './Plugin';
23

34
import type { Viewport } from '../Viewport';
@@ -160,7 +161,7 @@ export class Clamp extends Plugin
160161
{
161162
return;
162163
}
163-
const original = { x: this.parent.x, y: this.parent.y };
164+
const original = new Point(this.parent.x, this.parent.y);
164165
// TODO: Fix
165166
const decelerate: any = (this.parent.plugins as any).decelerate || {};
166167

src/plugins/Decelerate.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Plugin } from './Plugin';
22

3-
import type { Point } from '@pixi/math';
43
import type { Viewport } from '../Viewport';
4+
import { MovedEvent } from '../types';
55

66
export interface IDecelerateOptions
77
{
@@ -110,7 +110,7 @@ export class Decelerate extends Plugin
110110
this.timeSinceRelease = 0;
111111

112112
this.reset();
113-
this.parent.on('moved', (data) => this.moved(data));
113+
this.parent.on('moved', (data) => this.handleMoved(data));
114114
}
115115

116116
public down(): boolean
@@ -150,22 +150,22 @@ export class Decelerate extends Plugin
150150
}
151151

152152
/** Listener to viewport's "moved" event. */
153-
protected moved(data: { type: 'clamp-x' | 'clamp-y'; original: Point }): void
153+
protected handleMoved(e: MovedEvent): void
154154
{
155155
if (this.saved.length)
156156
{
157157
const last = this.saved[this.saved.length - 1];
158158

159-
if (data.type === 'clamp-x')
159+
if (e.type === 'clamp-x' && e.original)
160160
{
161-
if (last.x === data.original.x)
161+
if (last.x === e.original.x)
162162
{
163163
last.x = this.parent.x;
164164
}
165165
}
166-
else if (data.type === 'clamp-y')
166+
else if (e.type === 'clamp-y' && e.original)
167167
{
168-
if (last.y === data.original.y)
168+
if (last.y === e.original.y)
169169
{
170170
last.y = this.parent.y;
171171
}

0 commit comments

Comments
 (0)