Skip to content

Commit

Permalink
GitHub Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Dec 23, 2023
1 parent cf89b03 commit 8ebc56f
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 38 deletions.
52 changes: 45 additions & 7 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,74 @@
name: Build

on: push
on:
push:
branches:
- "**"
tags-ignore:
- "v*.*.*"
workflow_dispatch:
inputs:
ghp:
description: 'Deploy to GitHub Page'
required: true
type: boolean
default: false

permissions:
pages: write
id-token: write

jobs:
build:
name: wtd
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 15

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Setup
env:
DEPLOY_GHP: ${{ false || github.event.inputs.ghp == 'true' }}
run: |
echo "DEPLOY_GHP: ${DEPLOY_GHP}"
- name: Install
shell: bash
run: |
npm ci
- name: Lint
shell: bash
run: |
npm run lint
- name: Build
shell: bash
run: |
npm run build
- name: Test
shell: bash
run: |
npm run test
- name: Build Production
shell: bash
run: |
npm --prefix packages/examples run build:production
- name: SetupPages
if: ${{ github.event.inputs.ghp == 'true' }}
uses: actions/configure-pages@v3
- name: Upload examples preview build
if: ${{ github.event.inputs.ghp == 'true' }}
uses: actions/upload-pages-artifact@v1
with:
path: ./packages/examples/preview/
retention-days: 7

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
if: ${{ github.event.inputs.ghp == 'true' }}
id: deployment
uses: actions/deploy-pages@v1
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
"compile": "tsc --build tsconfig.build.json",
"watch": "tsc --build tsconfig.build.json --watch",
"build": "npm run build --workspaces",
"build:production": "npm run build:production --workspace packages/examples",
"dev": "vite",
"dev:debug": "vite --debug --force",
"release:prepare": "npm run reset:repo && npm ci && npm run lint && npm run build && npm run doc",
"release:prepare": "npm run reset:repo && npm ci && npm run lint && npm run build && npm run doc && npm run build:production",
"test": "vitest",
"reset:repo:dry": "git clean -f -d -x --dry-run",
"reset:repo": "git clean -f -d -x"
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"clean:production": "shx rm -fr preview",
"copy:assets:production": "shx mkdir -p ./preview/worker/generated && shx cp -f ./src/worker/generated/*.js ./preview/worker/generated && shx cp -f ./models/obj/female02/*.jpg ./preview/assets",
"build:production": "npm run build && npm run build:worker && npm run build:production:vite",
"build:production:vite": "npm run clean:production && vite --config vite.config.production.ts build --debug && npm run copy:assets:production",
"build:production:vite": "npm run clean:production && vite --config vite.config.production.ts build && npm run copy:assets:production",
"preview": "http-server ./preview"
},
"dependencies": {
Expand Down
59 changes: 55 additions & 4 deletions packages/wtd-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,43 @@ import {
WorkerTaskMessage
} from './WorkerTaskMessage.js';

export * from './utilities.js';
import {
applyProperties,
createWorkerBlob,
fillTransferables,
initChannel
} from './utilities.js';
import type {
OffscreenPayloadAdditions,
OffscreenPayloadMessage
} from './offscreen/OffscreenPayload.js';
import {
OffscreenPayload
} from './offscreen/OffscreenPayload.js';
export * from './offscreen/MainEventProxy.js';
export * from './offscreen/helper.js';
import type {
HandlingInstructions
} from './offscreen/MainEventProxy.js';
import {
AllowedKeyProperties,
KeydownEventProperties,
MouseEventProperties,
WheelEventProperties,
buildDefaultEventHandlingInstructions,
extractProperties,
handlePreventDefault,
handleFilteredKeydownEvent,
handleMouseEvent,
handleTouchEvent,
handleWheelEvent,
registerCanvas,
registerResizeHandler,
sentResize
} from './offscreen/MainEventProxy.js';
import {
getOffscreenCanvas,
initOffscreenCanvas,
recalcAspectRatio
} from './offscreen/helper.js';

export {
WorkerConfig,
Expand Down Expand Up @@ -112,5 +139,29 @@ export {
OffscreenPayload,
OffscreenWorker,
OffscreenWorkerCommandRequest,
OffscreenWorkerCommandResponse
OffscreenWorkerCommandResponse,
AllowedKeyProperties,
HandlingInstructions,
KeydownEventProperties,
MouseEventProperties,
WheelEventProperties,
buildDefaultEventHandlingInstructions,
extractProperties,
handleFilteredKeydownEvent,
handleMouseEvent,
handlePreventDefault,
handleTouchEvent,
handleWheelEvent,
registerCanvas,
registerResizeHandler,
sentResize,
// helper.ts
getOffscreenCanvas,
initOffscreenCanvas,
recalcAspectRatio,
// utilities.ts
applyProperties,
createWorkerBlob,
fillTransferables,
initChannel
};
37 changes: 19 additions & 18 deletions packages/wtd-core/src/offscreen/MainEventProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { WorkerTaskMessage } from '../WorkerTaskMessage.js';
import { OffscreenPayload } from './OffscreenPayload.js';
import { OffscreenWorkerCommandRequest, OffscreenWorkerCommandResponse } from './OffscreenWorker.js';

export const preventDefaultHandler = (event: Event) => {
export const handlePreventDefault = (event: Event) => {
event.preventDefault();
};

export const mouseEventProperties = [
export const MouseEventProperties = [
'ctrlKey',
'metaKey',
'shiftKey',
Expand All @@ -27,26 +27,26 @@ export const mouseEventProperties = [
'pageY',
];

export const mouseEventHandler = (event: Event, workerTask: WorkerTask, properties?: string[]) => {
export const handleMouseEvent = (event: Event, workerTask: WorkerTask, properties?: string[]) => {
const offscreenPayload = extractProperties(event, properties);
workerTask.sentMessage({
message: WorkerTaskMessage.fromPayload(offscreenPayload, 'proxyEvent')
});
};

export const wheelEventProperties = [
export const WheelEventProperties = [
'deltaX',
'deltaY',
];

export const wheelEventHandler = (event: Event, workerTask: WorkerTask, properties?: string[]) => {
export const handleWheelEvent = (event: Event, workerTask: WorkerTask, properties?: string[]) => {
const offscreenPayload = extractProperties(event, properties);
workerTask.sentMessage({
message: WorkerTaskMessage.fromPayload(offscreenPayload, 'proxyEvent')
});
};

export const keydownEventProperties = [
export const KeydownEventProperties = [
'ctrlKey',
'altKey',
'metaKey',
Expand All @@ -55,17 +55,18 @@ export const keydownEventProperties = [
];

// The four arrow keys
export const allowedKeys = [
export const AllowedKeyProperties = [
'ArrowLeft',
'ArrowUp',
'ArrowRight',
'ArrowDown',
'KeyW',
'KeyA',
'KeyS',
'KeyD'
];

export const filteredKeydownEventHandler = (event: Event, workerTask: WorkerTask, properties?: string[], positiveList?: string[]) => {
export const handleFilteredKeydownEvent = (event: Event, workerTask: WorkerTask, properties?: string[], positiveList?: string[]) => {
const { code } = event as KeyboardEvent;
if (positiveList?.includes(code)) {
const offscreenPayload = extractProperties(event, properties);
Expand All @@ -89,7 +90,7 @@ export const extractProperties = (event: Event, properties?: string[]) => {
});
};

export const touchEventHandler = (event: Event, workerTask: WorkerTask) => {
export const handleTouchEvent = (event: Event, workerTask: WorkerTask) => {
const touches = [];
const touchEvent = event as TouchEvent;

Expand Down Expand Up @@ -122,24 +123,24 @@ export type HandlingInstructions = {
export const buildDefaultEventHandlingInstructions = (): Map<string, HandlingInstructions> => {
const handlingInstructions: Map<string, HandlingInstructions> = new Map();
const contextMenuInstruction: HandlingInstructions = {
handler: preventDefaultHandler
handler: handlePreventDefault
};
const mouseInstruction: HandlingInstructions = {
handler: mouseEventHandler,
properties: mouseEventProperties
handler: handleMouseEvent,
properties: MouseEventProperties
};
const wheelInstruction: HandlingInstructions = {
handler: wheelEventHandler,
properties: wheelEventProperties,
handler: handleWheelEvent,
properties: WheelEventProperties,
passive: true
};
const keyboardInstruction: HandlingInstructions = {
handler: filteredKeydownEventHandler,
properties: keydownEventProperties,
positiveList: allowedKeys
handler: handleFilteredKeydownEvent,
properties: KeydownEventProperties,
positiveList: AllowedKeyProperties
};
const touchInstruction: HandlingInstructions = {
handler: touchEventHandler,
handler: handleTouchEvent,
passive: true
};

Expand Down
2 changes: 1 addition & 1 deletion packages/wtd-core/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AssociatedArrayType } from './Payload.js';
import { RawPayload } from './RawPayload.js';
import { WorkerTask } from './WorkerTask.js';
import { WorkerTaskMessage } from './WorkerTaskMessage.js';
import { WorkerTaskCommandRequest, WorkerTaskCommandResponse } from './index.js';
import { WorkerTaskCommandRequest, WorkerTaskCommandResponse } from './WorkerTaskWorker.js';

export const fillTransferables = (buffers: IterableIterator<ArrayBufferLike>, transferables: Transferable[], cloneBuffers: boolean) => {
for (const buffer of buffers) {
Expand Down
20 changes: 14 additions & 6 deletions packages/wtd-three-ext/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,30 @@ import {
packGeometryBuffers,
reconstructBuffer
} from './MeshPayload.js';
export * from './offscreen/WorkerEventProxy.js';
import {
ElementProxyReceiver,
noop,
proxyStart
} from './offscreen/WorkerEventProxy.js';

export {
MaterialUtils,
MaterialCloneInstructionsType,
AssociatedBufferAttributeArrayType,
AssociatedMaterialArrayType,
MaterialStore,
ElementProxyReceiver,
MaterialCloneInstructionsType,
MaterialsPayload,
MaterialsPayloadAdditions,
MaterialsPayloadMessageAdditions,
AssociatedBufferAttributeArrayType,
MaterialStore,
MaterialUtils,
MeshPayload,
MeshPayloadAdditions,
MeshPayloadMessageAdditions,
MeshPayload,
MeshPayloadHandler,
addAttributeToBuffers,
assignAttributeFromTransfered,
noop,
packGeometryBuffers,
proxyStart,
reconstructBuffer
};

0 comments on commit 8ebc56f

Please sign in to comment.