Skip to content

Commit

Permalink
Breaking: Pixi v8 update (pixijs#142)
Browse files Browse the repository at this point in the history
* add initial files

* add initial files

* fix eslint roles

* abstract pixi & implement eresize

* fix button

* update to v8

* update pixi

* fix on update

* Merge remote-tracking branch 'origin/main' into pixi8

* test platform wip

* wip

* fix graphics

* wip

* wip

* wip

* wip

* add comment

* wip

* wip

* refactor

* update pixi

* wip

* update to v8 release

* more updates

* update stories

* fix masked frame

* update select

* test

* test

* remove vite

* add some tweeks

* disable input mask by default

* cleanup

* fix masked frame

* refactor

* cleanup docs

* update to 8.0.2

* add compatibility check

* fix lint

---------

Co-authored-by: Dmytro Soldatov <cyberdexx@gmail.com>
  • Loading branch information
Zyie and CyberDex authored Mar 21, 2024
1 parent 0733f9f commit 64ba782
Show file tree
Hide file tree
Showing 78 changed files with 7,333 additions and 16,314 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
}
},
"rules": {
"no-restricted-imports": ["error", { "paths": ["pixi.js"] }],
"@typescript-eslint/no-unused-expressions": [1, {"allowShortCircuit": true, "allowTernary": true}],
"no-mixed-operators": "off",
"no-mixed-operators/no-mixed-operators": 1,
"@typescript-eslint/no-parameter-properties": 1,
"@typescript-eslint/type-annotation-spacing": 1,
"jsdoc/multiline-blocks": [
1,
Expand All @@ -33,7 +31,6 @@
"jsdoc/check-values": 1,
"jsdoc/empty-tags": 1,
"jsdoc/implements-on-classes": 1,
"jsdoc/newline-after-description": [1, "never"],
"jsdoc/no-multi-asterisks": [1, { "allowWhitespace": true }],
"jsdoc/require-param": 1,
"jsdoc/require-param-description": 0,
Expand Down
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ Here are some useful resources:

**We are now a part of the [Open Collective](https://opencollective.com/pixijs) and with your support you can help us make PixiJS even better. To make a donation, simply click the button below and we'll love you forever!**

## Compatibility

Depending on your version of PixiJS, you'll need to figure out which major version of PixiJS UI to use.

| PixiJS | PixiJS UI |
|-------------|----------------|
| v7.x | v1.x |
| v8.x | v2.x |


## Install

```sh
Expand Down
18,392 changes: 4,708 additions & 13,684 deletions package-lock.json

Large diffs are not rendered by default.

59 changes: 22 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dist/"
],
"scripts": {
"start": "storybook dev -p 6006",
"start": "npm run storybook",
"build": "xs build",
"clean": "xs clean",
"deploy": "xs deploy",
Expand Down Expand Up @@ -60,53 +60,38 @@
"docsDescription": "API Documentation for UI components made with PixiJS",
"docsKeyword": "PixiJS, UI, components"
},
"peerDependencies": {
"pixi.js": "^8.0.2"
},
"dependencies": {
"tweedle.js": "^2.1.0",
"typed-signals": "^2.5.0"
},
"devDependencies": {
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@pixi/core": "^7.3.1",
"@pixi/display": "^7.3.1",
"@pixi/eslint-config": "^4.0.1",
"@pixi/events": "^7.3.1",
"@pixi/extension-scripts": "^1.3.0",
"@pixi/graphics": "^7.3.1",
"@pixi/mesh-extras": "^7.3.2",
"@pixi/sprite": "^7.3.1",
"@pixi/storybook-renderer": "^0.0.6",
"@pixi/storybook-webpack5": "^0.0.6",
"@pixi/text": "^7.3.1",
"@pixi/text-bitmap": "^7.3.1",
"@pixi/text-html": "^7.3.1",
"@storybook/addon-essentials": "7.5.2",
"@storybook/addon-interactions": "7.5.2",
"@storybook/addon-links": "7.5.2",
"@storybook/addon-storysource": "^7.5.2",
"@pixi/extension-scripts": "^2.4.1",
"@pixi/storybook-renderer": "^0.1.0",
"@pixi/storybook-webpack5": "^0.1.0",
"@storybook/addon-essentials": "7.6.17",
"@storybook/addon-interactions": "7.6.17",
"@storybook/addon-links": "7.6.17",
"@storybook/addon-storysource": "^7.6.17",
"@storybook/testing-library": "^0.2.2",
"@types/babel__core": "^7.1.20",
"@types/jest": "^29.2.4",
"@types/node": "^18.11.17",
"eslint": "^8.30.0",
"eslint-plugin-jsdoc": "^39.6.4",
"@storybook/types": "^7.6.17",
"@types/babel__core": "^7.20.5",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.22",
"eslint": "^8.57.0",
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-no-mixed-operators": "^1.1.1",
"husky": "^8.0.0",
"husky": "^8.0.3",
"jest": "^26.6.3",
"jest-raw-loader": "^1.0.1",
"lint-staged": "^13.1.0",
"storybook": "7.5.2",
"typescript": "^5.2.0"
},
"peerDependencies": {
"@pixi/core": "^7.3.1",
"@pixi/display": "^7.3.1",
"@pixi/events": "^7.3.1",
"@pixi/graphics": "^7.3.1",
"@pixi/sprite": "^7.3.1",
"@pixi/text": "^7.3.1",
"@pixi/text-bitmap": "^7.3.1",
"@pixi/text-html": "^7.3.1"
"lint-staged": "^13.3.0",
"storybook": "7.6.17",
"pixi.js": "^8.0.2",
"typescript": "^5.4.2"
},
"publishConfig": {
"access": "public"
Expand Down
14 changes: 6 additions & 8 deletions src/Button.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Container } from '@pixi/display';
import { ButtonEvents } from './ButtonEvents';
import { Container, FederatedPointerEvent } from 'pixi.js';
import { Signal } from 'typed-signals';
import { FederatedPointerEvent } from '@pixi/events';
import { ButtonEvents } from './ButtonEvents';

/**
* Adds button events to a given container-based view
Expand All @@ -11,14 +10,13 @@ import { FederatedPointerEvent } from '@pixi/events';
* const container = new Container();
* const button = new Button(
* new Graphics()
* .beginFill(0xFFFFFF)
* .drawRoundedRect(0, 0, 100, 50, 15)
* .rect(0, 0, 100, 50, 15)
* .fill(0xFFFFFF)
* );
*
* button.onPress.connect(() => console.log('onPress'));
*
* container.addChild(button.view);
* // or container.addChild(container); which is the same
*/
export class Button extends ButtonEvents
{
Expand Down Expand Up @@ -92,8 +90,8 @@ export class Button extends ButtonEvents
* @example
* const button = new ButtonContainer(
* new Graphics()
* .beginFill(0xFFFFFF)
* .drawRoundedRect(0, 0, 100, 50, 15)
* .fill(0xFFFFFF)
* .roundRect(0, 0, 100, 50, 15)
* );
*
* button.onPress.connect(() => console.log('onPress'));
Expand Down
8 changes: 3 additions & 5 deletions src/ButtonEvents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { FederatedPointerEvent } from '@pixi/events';
import { isMobile, utils } from '@pixi/core';
import { Container, FederatedPointerEvent, isMobile } from 'pixi.js';
import { Signal } from 'typed-signals';
import { Container } from '@pixi/display';

/** Events controller used for {@link Button}. */
export class ButtonEvents
Expand Down Expand Up @@ -40,7 +38,7 @@ export class ButtonEvents

protected connectEvents(view: Container)
{
if (utils.isMobile.any)
if (isMobile.any)
{
view.on('pointerdown', this.processDown, this);
view.on('pointerup', this.processUp, this);
Expand All @@ -62,7 +60,7 @@ export class ButtonEvents

protected disconnectEvents(view: Container)
{
if (utils.isMobile.any)
if (isMobile.any)
{
view.off('pointerdown', this.processDown, this);
view.off('pointerup', this.processUp, this);
Expand Down
45 changes: 23 additions & 22 deletions src/CheckBox.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Container } from '@pixi/display';
import { Text } from '@pixi/text';
import { Container, Text } from 'pixi.js';
import { Signal } from 'typed-signals';
import { Switcher } from './Switcher';
import { cleanup } from './utils/helpers/cleanup';
Expand Down Expand Up @@ -36,7 +35,7 @@ export type CheckBoxOptions = {
export class CheckBox extends Switcher
{
//* Text label */
label!: PixiText;
labelText!: PixiText;

/** Signal emitted when checkbox state changes. */
onCheck: Signal<(state: boolean) => void>;
Expand Down Expand Up @@ -68,31 +67,34 @@ export class CheckBox extends Switcher
{
if (!text) return;

this.label = new this._textClass(text ?? '', style ?? this._style?.text);
this.addChild(this.label);
this.labelText = new this._textClass({
text: text ?? '',
style: style ?? this._style?.text,
});
this.addChild(this.labelText);

this.label.cursor = 'pointer';
this.label.eventMode = 'static';
this.label.on('pointertap', () => (this.checked = !this.checked));
this.labelText.cursor = 'pointer';
this.labelText.eventMode = 'static';
this.labelText.on('pointertap', () => (this.checked = !this.checked));
}

/** Setter, which sets a checkbox text. */
set text(text: string)
{
if (!text)
{
cleanup(this.label);
cleanup(this.labelText);

return;
}

this.label ? (this.label.text = text) : this.addLabel(text);
this.labelText ? (this.labelText.text = text) : this.addLabel(text);
}

/** Getter, which returns a checkbox text. */
get text(): string | ''
{
return this.label?.text ?? '';
return this.labelText?.text ?? '';
}

/** Setter, which sets a checkbox style settings. */
Expand Down Expand Up @@ -120,22 +122,21 @@ export class CheckBox extends Switcher
uncheckedView.visible = true;
}

if (this.label)
if (this.labelText)
{
checkedView.visible = true;
this.active = 1;
if (style.text)
{
if ('style' in this.label)
{
this.label.style = style.text;
}
else
{
Object.assign(this.label, style.text);
}
this.labelText.style = style.text;
}

this.label.x = uncheckedView.width + 10 + (style.textOffset?.x ?? 0);
this.label.y = ((uncheckedView.height - this.label.height) / 2) + (style.textOffset?.y ?? 0);
this.labelText.x = uncheckedView.width + 10 + (style.textOffset?.x ?? 0);
this.labelText.y = ((uncheckedView.height - this.labelText.height) / 2) + (style.textOffset?.y ?? 0);
}
else
{
uncheckedView.visible = true;
}
}

Expand Down
34 changes: 17 additions & 17 deletions src/CircularProgressBar.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { DEG_TO_RAD } from '@pixi/core';
import { Container } from '@pixi/display';
import { Graphics, LINE_CAP } from '@pixi/graphics';
import { ColorSource, Container, DEG_TO_RAD, Graphics, LineCap } from 'pixi.js';

export type MaskedProgressBarOptions = {
backgroundColor?: number;
fillColor: number;
backgroundColor?: ColorSource;
fillColor: ColorSource;
lineWidth: number;
radius: number;
value?: number;
backgroundAlpha?: number;
fillAlpha?: number;
cap?: 'butt' | 'round' | 'square';
cap?: LineCap;
};

/**
Expand Down Expand Up @@ -42,8 +40,8 @@ export class CircularProgressBar extends Container
/**
* Creates a Circular ProgressBar.
* @param { number } options - Options object to use.
* @param { number } options.backgroundColor - Background color.
* @param { number } options.fillColor - Fill color.
* @param { ColorSource } options.backgroundColor - Background color.
* @param { ColorSource } options.fillColor - Fill color.
* @param { number } options.lineWidth - Line width.
* @param { number } options.radius - Radius.
* @param { number } options.value - Progress value.
Expand Down Expand Up @@ -90,11 +88,13 @@ export class CircularProgressBar extends Container
alpha = 0.000001;
}

this.bgCircle.lineStyle({
width: lineWidth,
color: backgroundColor,
alpha
}).drawCircle(0, 0, radius);
this.bgCircle
.circle(0, 0, radius)
.stroke({
width: lineWidth,
color: backgroundColor,
alpha
});
}

/**
Expand Down Expand Up @@ -135,13 +135,13 @@ export class CircularProgressBar extends Container

this.fillCircle
.clear()
.lineStyle({
.arc(0, 0, radius, (0 - 90 + startAngle) * DEG_TO_RAD, (0 - 90 + startAngle + endAngle) * DEG_TO_RAD)
.stroke({
width: lineWidth,
color: fillColor,
cap: cap as LINE_CAP,
cap,
alpha: fillAlpha
})
.arc(0, 0, radius, (0 - 90 + startAngle) * DEG_TO_RAD, (0 - 90 + startAngle + endAngle) * DEG_TO_RAD);
});
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/DoubleSlider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FederatedPointerEvent } from '@pixi/events';
import type { DragObject } from './utils/HelpTypes';
import { DoubleSliderOptions, SliderBase } from './SliderBase';
import { Container, FederatedPointerEvent } from 'pixi.js';
import { Signal } from 'typed-signals';
import { Container } from '@pixi/display';
import { DoubleSliderOptions, SliderBase } from './SliderBase';

import type { DragObject } from './utils/HelpTypes';

/**
* Creates a slider with range selection option.
Expand Down Expand Up @@ -270,8 +270,8 @@ export class DoubleSlider extends SliderBase

/**
* Sets width of a Sliders background and fill.
* If nineSlicePlane is set, then width will be set to nineSlicePlane.
* If nineSlicePlane is not set, then width will control components width as Container.
* If nineSliceSprite is set, then width will be set to nineSliceSprite.
* If nineSliceSprite is not set, then width will control components width as Container.
* @param value - Width value.
*/
override set width(value: number)
Expand All @@ -290,8 +290,8 @@ export class DoubleSlider extends SliderBase

/**
* Sets height of a Sliders background and fill.
* If nineSlicePlane is set, then height will be set to nineSlicePlane.
* If nineSlicePlane is not set, then height will control components height as Container.
* If nineSliceSprite is set, then height will be set to nineSliceSprite.
* If nineSliceSprite is not set, then height will control components height as Container.
* @param value - Height value.
*/
override set height(value: number)
Expand Down
Loading

0 comments on commit 64ba782

Please sign in to comment.