{ "version": 3, "sources": ["../src/kaboom.ts", "../src/utils.ts", "../src/math.ts", "../src/fps.ts", "../src/timer.ts"], "sourcesContent": ["import {\n\tvec2,\n\tvec3,\n\tVec3,\n\tRect,\n\tLine,\n\tCircle,\n\tColor,\n\tVec2,\n\tMat4,\n\tQuad,\n\tRNG,\n\tquad,\n\trgb,\n\thsl2rgb,\n\trng,\n\trand,\n\trandi,\n\trandSeed,\n\tchance,\n\tchoose,\n\tclamp,\n\tlerp,\n\tmap,\n\tmapc,\n\twave,\n\ttestAreaRect,\n\ttestAreaLine,\n\ttestAreaCircle,\n\ttestAreaPolygon,\n\ttestAreaPoint,\n\ttestAreaArea,\n\ttestLineLineT,\n\ttestRectRect2,\n\ttestLineLine,\n\ttestRectRect,\n\ttestRectLine,\n\ttestRectPoint,\n\ttestPolygonPoint,\n\ttestLinePolygon,\n\ttestPolygonPolygon,\n\ttestCircleCircle,\n\ttestCirclePoint,\n\ttestRectPolygon,\n\tminkDiff,\n\tdeg2rad,\n\trad2deg,\n} from \"./math\";\n\nimport {\n\tIDList,\n\tdownloadURL,\n\tdownloadBlob,\n\tuid,\n\tdeprecate,\n\tdeprecateMsg,\n\tisDataURL,\n\tdeepEq,\n} from \"./utils\";\n\nimport {\n\tGfxShader,\n\tGfxFont,\n\tTexFilter,\n\tRenderProps,\n\tCharTransform,\n\tCharTransformFunc,\n\tTexWrap,\n\tFormattedText,\n\tFormattedChar,\n\tDrawRectOpt,\n\tDrawLineOpt,\n\tDrawLinesOpt,\n\tDrawTriangleOpt,\n\tDrawPolygonOpt,\n\tDrawCircleOpt,\n\tDrawEllipseOpt,\n\tDrawUVQuadOpt,\n\tVertex,\n\tSpriteData,\n\tSoundData,\n\tFontData,\n\tShaderData,\n\tSpriteLoadSrc,\n\tSpriteLoadOpt,\n\tSpriteAtlasData,\n\tFontLoadOpt,\n\tGfxTexData,\n\tKaboomCtx,\n\tKaboomOpt,\n\tAudioPlay,\n\tAudioPlayOpt,\n\tDrawSpriteOpt,\n\tDrawTextOpt,\n\tGameObj,\n\tEventCanceller,\n\tSceneID,\n\tSceneDef,\n\tCompList,\n\tComp,\n\tTag,\n\tKey,\n\tMouseButton,\n\tTouchID,\n\tCollision,\n\tPosComp,\n\tScaleComp,\n\tRotateComp,\n\tColorComp,\n\tOpacityComp,\n\tOrigin,\n\tOriginComp,\n\tLayerComp,\n\tZComp,\n\tFollowComp,\n\tMoveComp,\n\tOutviewCompOpt,\n\tOutviewComp,\n\tCleanupCompOpt,\n\tCleanupComp,\n\tAreaCompOpt,\n\tAreaComp,\n\tArea,\n\tSpriteComp,\n\tSpriteCompOpt,\n\tGfxTexture,\n\tSpriteAnimPlayOpt,\n\tTextComp,\n\tTextCompOpt,\n\tRectComp,\n\tRectCompOpt,\n\tUVQuadComp,\n\tCircleComp,\n\tOutlineComp,\n\tTimerComp,\n\tBodyComp,\n\tBodyCompOpt,\n\tUniform,\n\tShaderComp,\n\tSolidComp,\n\tFixedComp,\n\tStayComp,\n\tHealthComp,\n\tLifespanComp,\n\tLifespanCompOpt,\n\tStateComp,\n\tDebug,\n\tKaboomPlugin,\n\tMergeObj,\n\tLevel,\n\tLevelOpt,\n\tCursor,\n\tRecording,\n\tKaboom,\n} from \"./types\";\n\nimport FPSCounter from \"./fps\";\nimport Timer from \"./timer\";\n\n// @ts-ignore\nimport apl386Src from \"./assets/apl386.png\";\n// @ts-ignore\nimport apl386oSrc from \"./assets/apl386o.png\";\n// @ts-ignore\nimport sinkSrc from \"./assets/sink.png\";\n// @ts-ignore\nimport sinkoSrc from \"./assets/sinko.png\";\n// @ts-ignore\nimport beanSrc from \"./assets/bean.png\";\n// @ts-ignore\nimport burpBytes from \"./assets/burp.mp3\";\n// @ts-ignore\nimport kaSrc from \"./assets/ka.png\";\n// @ts-ignore\nimport boomSrc from \"./assets/boom.png\";\n\ntype ButtonState =\n\t\"up\"\n\t| \"pressed\"\n\t| \"rpressed\"\n\t| \"down\"\n\t| \"released\"\n\t;\n\ntype DrawTextureOpt = RenderProps & {\n\ttex: GfxTexture,\n\twidth?: number,\n\theight?: number,\n\ttiled?: boolean,\n\tflipX?: boolean,\n\tflipY?: boolean,\n\tquad?: Quad,\n\torigin?: Origin | Vec2,\n}\n\ninterface GfxTexOpt {\n\tfilter?: TexFilter,\n\twrap?: TexWrap,\n}\n\n// translate these key names to a simpler version\nconst KEY_ALIAS = {\n\t\"ArrowLeft\": \"left\",\n\t\"ArrowRight\": \"right\",\n\t\"ArrowUp\": \"up\",\n\t\"ArrowDown\": \"down\",\n\t\" \": \"space\",\n};\n\n// according to https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button\nconst MOUSE_BUTTONS = [\n\t\"left\",\n\t\"middle\",\n\t\"right\",\n\t\"back\",\n\t\"forward\",\n];\n\n// don't trigger browser default event when these keys are pressed\nconst PREVENT_DEFAULT_KEYS = [\n\t\"space\",\n\t\"left\",\n\t\"right\",\n\t\"up\",\n\t\"down\",\n\t\"tab\",\n\t\"f1\",\n\t\"f2\",\n\t\"f3\",\n\t\"f4\",\n\t\"f5\",\n\t\"f6\",\n\t\"f7\",\n\t\"f8\",\n\t\"f9\",\n\t\"f10\",\n\t\"f11\",\n\t\"s\",\n];\n\n// some default charsets for loading bitmap fonts\nconst ASCII_CHARS = \" !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\";\nconst CP437_CHARS = \" \u263A\u263B\u2665\u2666\u2663\u2660\u2022\u25D8\u25CB\u25D9\u2642\u2640\u266A\u266B\u263C\u25BA\u25C4\u2195\u203C\u00B6\u00A7\u25AC\u21A8\u2191\u2193\u2192\u2190\u221F\u2194\u25B2\u25BC !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\u00C7\u00FC\u00E9\u00E2\u00E4\u00E0\u00E5\u00E7\u00EA\u00EB\u00E8\u00EF\u00EE\u00EC\u00C4\u00C5\u00C9\u00E6\u00C6\u00F4\u00F6\u00F2\u00FB\u00F9\u00FF\u00D6\u00DC\u00A2\u00A3\u00A5\u20A7\u0192\u00E1\u00ED\u00F3\u00FA\u00F1\u00D1\u00AA\u00BA\u00BF\u2310\u00AC\u00BD\u00BC\u00A1\u00AB\u00BB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\u00DF\u0393\u03C0\u03A3\u03C3\u00B5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\u00B1\u2265\u2264\u2320\u2321\u00F7\u2248\u00B0\u2219\u00B7\u221A\u207F\u00B2\u25A0\";\n\n// audio gain range\nconst MIN_GAIN = 0;\nconst MAX_GAIN = 3;\n\n// audio speed range\nconst MIN_SPEED = 0;\nconst MAX_SPEED = 3;\n\n// audio detune range\nconst MIN_DETUNE = -1200;\nconst MAX_DETUNE = 1200;\n\nconst DEF_ORIGIN = \"topleft\";\nconst DEF_GRAVITY = 1600;\nconst QUEUE_COUNT = 65536;\nconst BG_GRID_SIZE = 64;\n\nconst DEF_FONT = \"apl386o\";\nconst DBG_FONT = \"sink\";\n\n// vertex format stride (vec3 pos, vec2 uv, vec4 color)\nconst STRIDE = 9;\n\n// vertex shader template, replace {{user}} with user vertex shader code\nconst VERT_TEMPLATE = `\nattribute vec3 a_pos;\nattribute vec2 a_uv;\nattribute vec4 a_color;\n\nvarying vec3 v_pos;\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvec4 def_vert() {\n\treturn vec4(a_pos, 1.0);\n}\n\n{{user}}\n\nvoid main() {\n\tvec4 pos = vert(a_pos, a_uv, a_color);\n\tv_pos = a_pos;\n\tv_uv = a_uv;\n\tv_color = a_color;\n\tgl_Position = pos;\n}\n`;\n\n// fragment shader template, replace {{user}} with user fragment shader code\nconst FRAG_TEMPLATE = `\nprecision mediump float;\n\nvarying vec3 v_pos;\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nuniform sampler2D u_tex;\n\nvec4 def_frag() {\n\treturn v_color * texture2D(u_tex, v_uv);\n}\n\n{{user}}\n\nvoid main() {\n\tgl_FragColor = frag(v_pos, v_uv, v_color, u_tex);\n\tif (gl_FragColor.a == 0.0) {\n\t\tdiscard;\n\t}\n}\n`;\n\n// default {{user}} vertex shader code\nconst DEF_VERT = `\nvec4 vert(vec3 pos, vec2 uv, vec4 color) {\n\treturn def_vert();\n}\n`;\n\n// default {{user}} fragment shader code\nconst DEF_FRAG = `\nvec4 frag(vec3 pos, vec2 uv, vec4 color, sampler2D tex) {\n\treturn def_frag();\n}\n`;\n\nconst COMP_DESC = new Set([\n\t\"id\",\n\t\"require\",\n]);\n\nconst COMP_EVENTS = new Set([\n\t\"add\",\n\t\"load\",\n\t\"update\",\n\t\"draw\",\n\t\"destroy\",\n\t\"inspect\",\n]);\n\n// transform the button state to the next state\n// e.g. a button might become \"pressed\" one frame, and it should become \"down\" next frame\nfunction processButtonState(s: ButtonState): ButtonState {\n\tif (s === \"pressed\" || s === \"rpressed\") {\n\t\treturn \"down\";\n\t}\n\tif (s === \"released\") {\n\t\treturn \"up\";\n\t}\n\treturn s;\n}\n\n// wrappers around full screen functions to work across browsers\nfunction enterFullscreen(el: HTMLElement) {\n\tif (el.requestFullscreen) el.requestFullscreen();\n\t// @ts-ignore\n\telse if (el.webkitRequestFullscreen) el.webkitRequestFullscreen();\n};\n\nfunction exitFullscreen() {\n\tif (document.exitFullscreen) document.exitFullscreen();\n\t// @ts-ignore\n\telse if (document.webkitExitFullScreen) document.webkitExitFullScreen();\n};\n\nfunction getFullscreenElement(): Element | void {\n\treturn document.fullscreenElement\n\t\t// @ts-ignore\n\t\t|| document.webkitFullscreenElement\n\t\t;\n};\n\n// convert origin string to a vec2 offset\nfunction originPt(orig: Origin | Vec2): Vec2 {\n\tswitch (orig) {\n\t\tcase \"topleft\": return vec2(-1, -1);\n\t\tcase \"top\": return vec2(0, -1);\n\t\tcase \"topright\": return vec2(1, -1);\n\t\tcase \"left\": return vec2(-1, 0);\n\t\tcase \"center\": return vec2(0, 0);\n\t\tcase \"right\": return vec2(1, 0);\n\t\tcase \"botleft\": return vec2(-1, 1);\n\t\tcase \"bot\": return vec2(0, 1);\n\t\tcase \"botright\": return vec2(1, 1);\n\t\tdefault: return orig;\n\t}\n}\n\nfunction createEmptyAudioBuffer() {\n\treturn new AudioBuffer({\n\t\tlength: 1,\n\t\tnumberOfChannels: 1,\n\t\tsampleRate: 44100\n\t});\n}\n\n// only exports one kaboom() which contains all the state\nexport default (gopt: KaboomOpt = {}): KaboomCtx => {\n\nconst app = (() => {\n\n\tconst root = gopt.root ?? document.body;\n\n\t// if root is not defined (which falls back to
) we assume user is using kaboom on a clean page, and modify to better fit a full screen canvas\n\tif (root === document.body) {\n\t\tdocument.body.style[\"width\"] = \"100%\";\n\t\tdocument.body.style[\"height\"] = \"100%\";\n\t\tdocument.body.style[\"margin\"] = \"0px\";\n\t\tdocument.documentElement.style[\"width\"] = \"100%\";\n\t\tdocument.documentElement.style[\"height\"] = \"100%\";\n\t}\n\n\t// create a