@webgamekit/recording 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export { recordCreate } from './recorder';
2
+ export type { RecorderConfig, RecorderState, RecorderFormat, StateChangeCallback, Recorder } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ const y = (c) => c === "mp4" ? "video/mp4" : "video/webm", D = (c) => {
2
+ const { canvas: S, duration: p, format: b = "webm", frameRate: w = 30 } = c;
3
+ let o = {
4
+ isRecording: !1,
5
+ elapsed: 0,
6
+ blob: null
7
+ }, t = null, d = [];
8
+ const n = /* @__PURE__ */ new Set();
9
+ let a = null, s = null, m = 0, l = null;
10
+ const R = () => {
11
+ n.forEach((e) => e({ ...o }));
12
+ }, u = (e) => {
13
+ o = { ...o, ...e }, R();
14
+ }, f = () => {
15
+ a && (clearInterval(a), a = null), s && (clearTimeout(s), s = null);
16
+ }, v = () => {
17
+ if (o.isRecording) return;
18
+ const e = S.captureStream(w), i = y(b);
19
+ t = new MediaRecorder(e, { mimeType: i }), d = [], t.ondataavailable = (r) => {
20
+ r.data.size > 0 && d.push(r.data);
21
+ }, t.onstop = () => {
22
+ const r = new Blob(d, { type: i });
23
+ u({ isRecording: !1, blob: r }), f(), l && (l(r), l = null);
24
+ }, t.start(), m = Date.now(), u({ isRecording: !0, elapsed: 0, blob: null }), a = setInterval(() => {
25
+ const r = Date.now() - m;
26
+ u({ elapsed: r });
27
+ }, 100), p && (s = setTimeout(() => {
28
+ g();
29
+ }, p));
30
+ }, g = () => new Promise((e, i) => {
31
+ if (!o.isRecording || !t) {
32
+ i(new Error("Not recording"));
33
+ return;
34
+ }
35
+ l = e, t.stop();
36
+ });
37
+ return {
38
+ recordStart: v,
39
+ recordStop: g,
40
+ recordGetState: () => ({ ...o }),
41
+ recordOnStateChange: (e) => (n.add(e), () => {
42
+ n.delete(e);
43
+ }),
44
+ recordDestroy: () => {
45
+ o.isRecording && t && t.stop(), f(), n.clear(), t = null;
46
+ }
47
+ };
48
+ };
49
+ export {
50
+ D as recordCreate
51
+ };
@@ -0,0 +1 @@
1
+ (function(r,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(r=typeof globalThis<"u"?globalThis:r||self,s(r.WebGameToolkitRecording={}))})(this,function(r){"use strict";const s=u=>u==="mp4"?"video/mp4":"video/webm",y=u=>{const{canvas:T,duration:m,format:R="webm",frameRate:h=30}=u;let o={isRecording:!1,elapsed:0,blob:null},t=null,f=[];const a=new Set;let i=null,l=null,g=0,d=null;const w=()=>{a.forEach(e=>e({...o}))},p=e=>{o={...o,...e},w()},S=()=>{i&&(clearInterval(i),i=null),l&&(clearTimeout(l),l=null)},v=()=>{if(o.isRecording)return;const e=T.captureStream(h),c=s(R);t=new MediaRecorder(e,{mimeType:c}),f=[],t.ondataavailable=n=>{n.data.size>0&&f.push(n.data)},t.onstop=()=>{const n=new Blob(f,{type:c});p({isRecording:!1,blob:n}),S(),d&&(d(n),d=null)},t.start(),g=Date.now(),p({isRecording:!0,elapsed:0,blob:null}),i=setInterval(()=>{const n=Date.now()-g;p({elapsed:n})},100),m&&(l=setTimeout(()=>{b()},m))},b=()=>new Promise((e,c)=>{if(!o.isRecording||!t){c(new Error("Not recording"));return}d=e,t.stop()});return{recordStart:v,recordStop:b,recordGetState:()=>({...o}),recordOnStateChange:e=>(a.add(e),()=>{a.delete(e)}),recordDestroy:()=>{o.isRecording&&t&&t.stop(),S(),a.clear(),t=null}}};r.recordCreate=y,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,7 @@
1
+ import type { RecorderConfig, Recorder } from './types';
2
+ /**
3
+ * Creates a recorder that captures a canvas to a video blob for a fixed duration.
4
+ * @param config The canvas, duration, format and frame rate.
5
+ * @returns The recorder, to start, stop and read the result from.
6
+ */
7
+ export declare const recordCreate: (config: RecorderConfig) => Recorder;
@@ -0,0 +1,20 @@
1
+ export type RecorderFormat = 'webm' | 'mp4';
2
+ export type RecorderConfig = {
3
+ canvas: HTMLCanvasElement;
4
+ duration?: number;
5
+ format?: RecorderFormat;
6
+ frameRate?: number;
7
+ };
8
+ export type RecorderState = {
9
+ isRecording: boolean;
10
+ elapsed: number;
11
+ blob: Blob | null;
12
+ };
13
+ export type StateChangeCallback = (state: RecorderState) => void;
14
+ export type Recorder = {
15
+ recordStart: () => void;
16
+ recordStop: () => Promise<Blob>;
17
+ recordGetState: () => RecorderState;
18
+ recordOnStateChange: (callback: StateChangeCallback) => () => void;
19
+ recordDestroy: () => void;
20
+ };
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "@webgamekit/recording",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/cnotv/generative-art.git",
7
+ "directory": "packages/recording"
8
+ },
9
+ "type": "module",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "main": "./dist/index.umd.cjs",
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "require": "./dist/index.umd.cjs",
20
+ "types": "./dist/index.d.ts"
21
+ }
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "devDependencies": {
27
+ "typescript": "^5.0.0",
28
+ "vite": "^5.0.0"
29
+ },
30
+ "scripts": {
31
+ "build": "vite build && tsc"
32
+ }
6
33
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.