Skip to content

Commit

Permalink
feat: support 'pixels' in pointer-events #1373 (#1374)
Browse files Browse the repository at this point in the history
* feat: support 'pixels' in pointer-events #1373

* fix: add to image cache when it loaded #1325

* fix: rename to non-transparent-pixel #1373

* feat: use vertex compression to reduce GPU memory using #1375

* Publish

 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
  • Loading branch information
xiaoiver authored Jun 15, 2023
1 parent 79c6ee1 commit 3595884
Show file tree
Hide file tree
Showing 56 changed files with 333 additions and 226 deletions.
12 changes: 6 additions & 6 deletions packages/g-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvas",
"version": "1.9.47",
"version": "1.9.48",
"description": "A renderer implemented by Canvas 2D API",
"keywords": [
"antv",
Expand Down Expand Up @@ -33,11 +33,11 @@
},
"dependencies": {
"@antv/g-plugin-canvas-path-generator": "^1.1.51",
"@antv/g-plugin-canvas-picker": "^1.8.50",
"@antv/g-plugin-canvas-renderer": "^1.7.59",
"@antv/g-plugin-dom-interaction": "^1.7.51",
"@antv/g-plugin-html-renderer": "^1.7.55",
"@antv/g-plugin-image-loader": "^1.1.53",
"@antv/g-plugin-canvas-picker": "^1.8.51",
"@antv/g-plugin-canvas-renderer": "^1.7.60",
"@antv/g-plugin-dom-interaction": "^1.7.52",
"@antv/g-plugin-html-renderer": "^1.7.56",
"@antv/g-plugin-image-loader": "^1.1.54",
"@antv/util": "^3.3.1",
"@types/offscreencanvas": "^2019.6.4",
"tslib": "^2.3.1"
Expand Down
12 changes: 6 additions & 6 deletions packages/g-canvaskit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvaskit",
"version": "0.8.44",
"version": "0.8.45",
"description": "A renderer implemented by CanvasKit",
"keywords": [
"antv",
Expand Down Expand Up @@ -33,11 +33,11 @@
},
"dependencies": {
"@antv/g-plugin-canvas-path-generator": "^1.1.51",
"@antv/g-plugin-canvas-picker": "^1.8.50",
"@antv/g-plugin-canvaskit-renderer": "^1.1.53",
"@antv/g-plugin-dom-interaction": "^1.7.51",
"@antv/g-plugin-html-renderer": "^1.7.55",
"@antv/g-plugin-image-loader": "^1.1.53",
"@antv/g-plugin-canvas-picker": "^1.8.51",
"@antv/g-plugin-canvaskit-renderer": "^1.1.54",
"@antv/g-plugin-dom-interaction": "^1.7.52",
"@antv/g-plugin-html-renderer": "^1.7.56",
"@antv/g-plugin-image-loader": "^1.1.54",
"@antv/util": "^3.3.1",
"canvaskit-wasm": "^0.34.0",
"tslib": "^2.3.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/g-gesture/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-gesture",
"version": "0.0.82",
"version": "0.0.83",
"description": "G Gesture",
"keywords": [
"antv",
Expand Down Expand Up @@ -34,7 +34,7 @@
"eventemitter3": "^4.0.0"
},
"devDependencies": {
"@antv/g-mobile-canvas": "^0.8.55",
"@antv/g-mobile-canvas": "^0.8.56",
"@antv/g-mobile-canvas-element": "^0.6.49"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/g-lite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-lite",
"version": "1.0.69",
"version": "1.0.70",
"description": "A core module for rendering engine implements DOM API.",
"keywords": [
"antv",
Expand Down
1 change: 1 addition & 0 deletions packages/g-lite/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface BaseStyleProps {
| 'visiblepainted'
// | 'bounding-box'
| 'all'
| 'non-transparent-pixel' // valid only for Image
| CSSGlobalKeywords;

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/g-mobile-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-mobile-canvas",
"version": "0.8.55",
"version": "0.8.56",
"description": "A renderer implemented with Canvas2D API in mobile environment",
"keywords": [
"antv",
Expand Down Expand Up @@ -31,10 +31,10 @@
},
"dependencies": {
"@antv/g-plugin-canvas-path-generator": "^1.1.51",
"@antv/g-plugin-canvas-picker": "^1.8.50",
"@antv/g-plugin-canvas-renderer": "^1.7.59",
"@antv/g-plugin-image-loader": "^1.1.53",
"@antv/g-plugin-mobile-interaction": "^0.7.50",
"@antv/g-plugin-canvas-picker": "^1.8.51",
"@antv/g-plugin-canvas-renderer": "^1.7.60",
"@antv/g-plugin-image-loader": "^1.1.54",
"@antv/g-plugin-mobile-interaction": "^0.7.51",
"@antv/util": "^3.3.1",
"tslib": "^2.3.1"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/g-mobile-svg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-mobile-svg",
"version": "0.8.59",
"version": "0.8.60",
"description": "A renderer implemented by SVG in mobile environment",
"keywords": [
"antv",
Expand Down Expand Up @@ -30,9 +30,9 @@
"sync": "tnpm sync"
},
"dependencies": {
"@antv/g-plugin-mobile-interaction": "^0.7.50",
"@antv/g-plugin-mobile-interaction": "^0.7.51",
"@antv/g-plugin-svg-picker": "^1.7.51",
"@antv/g-plugin-svg-renderer": "^1.8.59",
"@antv/g-plugin-svg-renderer": "^1.8.60",
"@antv/util": "^3.3.1",
"tslib": "^2.3.1"
},
Expand Down
14 changes: 7 additions & 7 deletions packages/g-mobile-webgl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-mobile-webgl",
"version": "0.7.73",
"version": "0.7.74",
"description": "A renderer implemented by WebGL1/2 in mobile environment",
"keywords": [
"antv",
Expand Down Expand Up @@ -30,12 +30,12 @@
"sync": "tnpm sync"
},
"dependencies": {
"@antv/g-plugin-device-renderer": "^1.7.69",
"@antv/g-plugin-dragndrop": "^1.6.50",
"@antv/g-plugin-html-renderer": "^1.7.55",
"@antv/g-plugin-image-loader": "^1.1.53",
"@antv/g-plugin-mobile-interaction": "^0.7.50",
"@antv/g-plugin-webgl-device": "^1.7.53",
"@antv/g-plugin-device-renderer": "^1.7.70",
"@antv/g-plugin-dragndrop": "^1.6.51",
"@antv/g-plugin-html-renderer": "^1.7.56",
"@antv/g-plugin-image-loader": "^1.1.54",
"@antv/g-plugin-mobile-interaction": "^0.7.51",
"@antv/g-plugin-webgl-device": "^1.7.54",
"@antv/util": "^3.3.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/g-plugin-3d/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-3d",
"version": "1.7.56",
"version": "1.7.57",
"description": "Provide 3D extension for G",
"keywords": [
"antv",
Expand Down Expand Up @@ -30,7 +30,7 @@
"sync": "tnpm sync"
},
"dependencies": {
"@antv/g-shader-components": "^1.7.54",
"@antv/g-shader-components": "^1.7.55",
"gl-matrix": "^3.1.0",
"tslib": "^2.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-a11y/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-a11y",
"version": "0.4.51",
"version": "0.4.52",
"description": "A G plugin for accessibility",
"keywords": [
"antv",
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-annotation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-annotation",
"version": "0.2.68",
"version": "0.2.69",
"description": "A G plugin for annotation",
"keywords": [
"antv",
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-box2d/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-box2d",
"version": "1.7.52",
"version": "1.7.53",
"description": "A G plugin for Box2D",
"keywords": [
"antv",
Expand Down
3 changes: 2 additions & 1 deletion packages/g-plugin-canvas-picker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-canvas-picker",
"version": "1.8.50",
"version": "1.8.51",
"description": "A G plugin for picking in canvas",
"keywords": [
"antv",
Expand Down Expand Up @@ -31,6 +31,7 @@
},
"dependencies": {
"@antv/g-plugin-canvas-path-generator": "^1.1.51",
"@antv/g-plugin-canvas-renderer": "^1.7.60",
"@antv/util": "^3.3.1",
"gl-matrix": "^3.1.0",
"tslib": "^2.3.1"
Expand Down
69 changes: 26 additions & 43 deletions packages/g-plugin-canvas-picker/src/CanvasPickerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
Shape,
IDocument,
RenderingPluginContext,
CanvasConfig,
GlobalRuntime,
} from '@antv/g-lite';
import { findClosestClipPathTarget, Point } from '@antv/g-lite';
Expand All @@ -17,20 +16,22 @@ import { mat4, vec3 } from 'gl-matrix';
export type PointInPathPicker<T extends BaseStyleProps> = (
displayObject: DisplayObject<T>,
point: Point,
isClipPath?: boolean,
isPointInPath?: (
runtime: GlobalRuntime,
displayObject: DisplayObject<T>,
point: Point,
) => boolean,
runtime?: GlobalRuntime,
isClipPath: boolean,
isPointInPath: (displayObject: DisplayObject<T>, point: Point) => boolean,
context: RenderingPluginContext,
runtime: GlobalRuntime,
) => boolean;

const tmpVec3a = vec3.create();
const tmpVec3b = vec3.create();
const tmpVec3c = vec3.create();
const tmpMat4 = mat4.create();

interface Extended {
pathGeneratorFactory: Record<Shape, PathGenerator<any>>;
pointInPathPickerFactory: Record<Shape, PointInPathPicker<any>>;
}

/**
* pick shape(s) with Mouse/Touch event
*
Expand All @@ -40,46 +41,32 @@ const tmpMat4 = mat4.create();
export class CanvasPickerPlugin implements RenderingPlugin {
static tag = 'CanvasPicker';

private canvasConfig: Partial<CanvasConfig>;
private pathGeneratorFactory: Record<Shape, PathGenerator<any>>;
private pointInPathPickerFactory: Record<Shape, PointInPathPicker<any>>;
private context: RenderingPluginContext & Extended;
private runtime: GlobalRuntime;

apply(context: RenderingPluginContext, runtime: GlobalRuntime) {
const {
config,
renderingService,
renderingContext,
// @ts-ignore
pathGeneratorFactory,
// @ts-ignore
pointInPathPickerFactory,
} = context;
this.canvasConfig = config;
this.pathGeneratorFactory = pathGeneratorFactory;
this.pointInPathPickerFactory = pointInPathPickerFactory;
const { renderingService, renderingContext } = context;
this.context = context as RenderingPluginContext & Extended;
this.runtime = runtime;

const document = renderingContext.root?.ownerDocument;

renderingService.hooks.pick.tapPromise(
CanvasPickerPlugin.tag,
async (result: PickingResult) => {
return this.pick(document, result, runtime);
return this.pick(document, result);
},
);

renderingService.hooks.pickSync.tap(
CanvasPickerPlugin.tag,
(result: PickingResult) => {
return this.pick(document, result, runtime);
return this.pick(document, result);
},
);
}

private pick(
document: IDocument,
result: PickingResult,
runtime: GlobalRuntime,
) {
private pick(document: IDocument, result: PickingResult) {
const {
topmost,
position: { x, y },
Expand All @@ -106,7 +93,6 @@ export class CanvasPickerPlugin implements RenderingPlugin {
position,
worldTransform,
false,
runtime,
);
if (isHitOriginShape) {
// should look up in the ancestor node
Expand All @@ -118,7 +104,6 @@ export class CanvasPickerPlugin implements RenderingPlugin {
position,
clipPath.getWorldTransform(),
true,
runtime,
);
if (isHitClipPath) {
if (topmost) {
Expand Down Expand Up @@ -148,10 +133,10 @@ export class CanvasPickerPlugin implements RenderingPlugin {
position: vec3,
worldTransform: mat4,
isClipPath: boolean,
runtime: GlobalRuntime,
) => {
// use picker for current shape's type
const pick = this.pointInPathPickerFactory[displayObject.nodeName];
const pick =
this.context.pointInPathPickerFactory[displayObject.nodeName as Shape];
if (pick) {
// invert with world matrix
const invertWorldMat = mat4.invert(tmpMat4, worldTransform);
Expand All @@ -174,7 +159,8 @@ export class CanvasPickerPlugin implements RenderingPlugin {
new Point(localPosition[0], localPosition[1]),
isClipPath,
this.isPointInPath,
runtime,
this.context,
this.runtime,
)
) {
return true;
Expand All @@ -188,16 +174,13 @@ export class CanvasPickerPlugin implements RenderingPlugin {
* use native picking method
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/isPointInPath
*/
private isPointInPath = (
runtime: GlobalRuntime,
displayObject: DisplayObject,
position: Point,
) => {
const context = runtime.offscreenCanvas.getOrCreateContext(
this.canvasConfig.offscreenCanvas,
private isPointInPath = (displayObject: DisplayObject, position: Point) => {
const context = this.runtime.offscreenCanvas.getOrCreateContext(
this.context.config.offscreenCanvas,
) as CanvasRenderingContext2D;

const generatePath = this.pathGeneratorFactory[displayObject.nodeName];
const generatePath =
this.context.pathGeneratorFactory[displayObject.nodeName];
if (generatePath) {
context.beginPath();
generatePath(context, displayObject.parsedStyle);
Expand Down
Loading

0 comments on commit 3595884

Please sign in to comment.