From 8ebc56f9d127932020082de8f590b423d285cc45 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Sat, 23 Dec 2023 18:43:05 +0100 Subject: [PATCH] GitHub Pages --- .github/workflows/actions.yml | 52 +++++++++++++--- package.json | 3 +- packages/examples/package.json | 2 +- packages/wtd-core/src/index.ts | 59 +++++++++++++++++-- .../wtd-core/src/offscreen/MainEventProxy.ts | 37 ++++++------ packages/wtd-core/src/utilities.ts | 2 +- packages/wtd-three-ext/src/index.ts | 20 +++++-- 7 files changed, 137 insertions(+), 38 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 28d5350..b5ec27c 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -1,12 +1,29 @@ 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 @@ -14,23 +31,44 @@ jobs: 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 diff --git a/package.json b/package.json index 6ca2b48..1843bff 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/packages/examples/package.json b/packages/examples/package.json index c941c10..587fa35 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -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": { diff --git a/packages/wtd-core/src/index.ts b/packages/wtd-core/src/index.ts index 129cd25..dd2ddae 100644 --- a/packages/wtd-core/src/index.ts +++ b/packages/wtd-core/src/index.ts @@ -68,7 +68,12 @@ import { WorkerTaskMessage } from './WorkerTaskMessage.js'; -export * from './utilities.js'; +import { + applyProperties, + createWorkerBlob, + fillTransferables, + initChannel +} from './utilities.js'; import type { OffscreenPayloadAdditions, OffscreenPayloadMessage @@ -76,8 +81,30 @@ import type { 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, @@ -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 }; diff --git a/packages/wtd-core/src/offscreen/MainEventProxy.ts b/packages/wtd-core/src/offscreen/MainEventProxy.ts index 36fb307..7369b84 100644 --- a/packages/wtd-core/src/offscreen/MainEventProxy.ts +++ b/packages/wtd-core/src/offscreen/MainEventProxy.ts @@ -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', @@ -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', @@ -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); @@ -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; @@ -122,24 +123,24 @@ export type HandlingInstructions = { export const buildDefaultEventHandlingInstructions = (): Map => { const handlingInstructions: Map = 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 }; diff --git a/packages/wtd-core/src/utilities.ts b/packages/wtd-core/src/utilities.ts index 86a6c83..1f846bb 100644 --- a/packages/wtd-core/src/utilities.ts +++ b/packages/wtd-core/src/utilities.ts @@ -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, transferables: Transferable[], cloneBuffers: boolean) => { for (const buffer of buffers) { diff --git a/packages/wtd-three-ext/src/index.ts b/packages/wtd-three-ext/src/index.ts index 01786ae..6b47281 100644 --- a/packages/wtd-three-ext/src/index.ts +++ b/packages/wtd-three-ext/src/index.ts @@ -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 };