@stanko/kaplay-inspector 0.0.1
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.
- package/README.md +71 -0
- package/dist/components/breadcrumbs.d.ts +7 -0
- package/dist/components/breadcrumbs.js +17 -0
- package/dist/components/game-object.d.ts +10 -0
- package/dist/components/game-object.js +42 -0
- package/dist/components/icons.d.ts +6 -0
- package/dist/components/icons.js +19 -0
- package/dist/components/inspector.d.ts +6 -0
- package/dist/components/inspector.js +19 -0
- package/dist/components/position-controls.d.ts +6 -0
- package/dist/components/position-controls.js +9 -0
- package/dist/components/text-controls.d.ts +6 -0
- package/dist/components/text-controls.js +9 -0
- package/dist/init.d.ts +5 -0
- package/dist/init.js +9 -0
- package/dist/lib/cx.d.ts +1 -0
- package/dist/lib/cx.js +12 -0
- package/dist/lib/draw-bbox.d.ts +2 -0
- package/dist/lib/draw-bbox.js +38 -0
- package/dist/lib/get-object-info.d.ts +9 -0
- package/dist/lib/get-object-info.js +11 -0
- package/dist/lib/inspect-comps.d.ts +6 -0
- package/dist/lib/inspect-comps.js +61 -0
- package/dist/lib/round-to-decimal.d.ts +1 -0
- package/dist/lib/round-to-decimal.js +4 -0
- package/dist/lib/stringify.d.ts +1 -0
- package/dist/lib/stringify.js +22 -0
- package/dist/styles.css +313 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Kaplay Inspector
|
|
2
|
+
|
|
3
|
+
A dev tool for [Kaplay](https://kaplayjs.com/) which allows you to explore and inspect the game object tree.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Navigate the game object tree
|
|
8
|
+
- Updates every 100ms (configurable)
|
|
9
|
+
- Hover an object to draw it's area, anchor and bounding box
|
|
10
|
+
- Inspect object's component and custom props
|
|
11
|
+
- Log an object to console
|
|
12
|
+
- Tweak position and text
|
|
13
|
+
- Pause an object
|
|
14
|
+
- Dark theme (is this a feature?)
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
This is a dev tool, so I strongly recommend you import it only in development mode. If you are using vite, it exposes the dev flag in `import.meta.env.DEV`. For other bundlers check their documentation.
|
|
19
|
+
|
|
20
|
+
You'll need to import the CSS and `init` method, here is an example using vite:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import kaplay from "kaplay";
|
|
24
|
+
|
|
25
|
+
// Init you kaplay game
|
|
26
|
+
const k = kaplay({})
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
// Make sure to load it only in development mode
|
|
30
|
+
import.meta.env.DEV &&
|
|
31
|
+
// I like to enable it only when ?inspector is available in the URL (this is optional)
|
|
32
|
+
// This gives you an easy way to enable or disable it
|
|
33
|
+
new URLSearchParams(window.location.search).get("inspector") !== null
|
|
34
|
+
) {
|
|
35
|
+
import("@stanko/kaplay-inspector/styles.css");
|
|
36
|
+
import("@stanko/kaplay-inspector").then(({ default: init }) => {
|
|
37
|
+
// Pass the "k" instance to the inspector
|
|
38
|
+
init(k);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Options
|
|
44
|
+
|
|
45
|
+
You can pass options object to the init method as a second parameter:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
init(k, {
|
|
49
|
+
updateTimeout: 250,
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
available options are:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
interface InspectorOptions {
|
|
57
|
+
updateTimeout?: number; // in milliseconds
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## TODO
|
|
63
|
+
|
|
64
|
+
* [ ] Show/Hide button
|
|
65
|
+
* [ ] Bounding box - handle a case when anchor is a `Vec2`
|
|
66
|
+
* [ ] Controllable theme - system/light/dark. At the moment it is always matching the system.
|
|
67
|
+
* [ ] Filter/search
|
|
68
|
+
* [ ] Persist search in URL or local storage
|
|
69
|
+
* [ ] Build and deploy simple demo
|
|
70
|
+
* [ ] Figure out why child bounding box are drawn in the wrong position
|
|
71
|
+
* [ ] Check if all of CSS is namespaced
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { getObjectInfo } from "../lib/get-object-info";
|
|
3
|
+
export const Breadcrumbs = ({ obj, setRenderRoot }) => {
|
|
4
|
+
const breadcrumbs = [];
|
|
5
|
+
let parent = obj.parent;
|
|
6
|
+
while (parent) {
|
|
7
|
+
const { tags, compsLabel } = getObjectInfo(parent);
|
|
8
|
+
breadcrumbs.unshift({
|
|
9
|
+
id: parent.id,
|
|
10
|
+
tags,
|
|
11
|
+
compsLabel,
|
|
12
|
+
object: parent,
|
|
13
|
+
});
|
|
14
|
+
parent = parent.parent;
|
|
15
|
+
}
|
|
16
|
+
return (_jsxs("div", { class: "breadcrumbs", children: ["Back to", breadcrumbs.map((breadcrumb) => (_jsxs("button", { class: "btn", onClick: () => setRenderRoot(breadcrumb.object), children: ["ID ", breadcrumb.id, ": ", breadcrumb.tags || breadcrumb.compsLabel] })))] }));
|
|
17
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GameObj, KAPLAYCtx } from "kaplay";
|
|
2
|
+
export interface GameObjectProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
obj: GameObj;
|
|
5
|
+
setRenderRoot: (obj: GameObj) => void;
|
|
6
|
+
isExpanded?: boolean;
|
|
7
|
+
isRenderRoot?: boolean;
|
|
8
|
+
k: KAPLAYCtx;
|
|
9
|
+
}
|
|
10
|
+
export declare const GameObject: ({ obj, className, isExpanded: isExpandedExternal, isRenderRoot, setRenderRoot, k, }: GameObjectProps) => import("preact").JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "preact/hooks";
|
|
3
|
+
import { MinusIcon, PlusIcon } from "../components/icons";
|
|
4
|
+
import { cx } from "../lib/cx";
|
|
5
|
+
import { drawBoundingBox } from "../lib/draw-bbox";
|
|
6
|
+
import { getObjectInfo } from "../lib/get-object-info";
|
|
7
|
+
import { Breadcrumbs } from "./breadcrumbs";
|
|
8
|
+
export const GameObject = ({ obj, className = "", isExpanded: isExpandedExternal = false, isRenderRoot, setRenderRoot, k, }) => {
|
|
9
|
+
const [isExpanded, setIsExpanded] = useState(isExpandedExternal);
|
|
10
|
+
const mouseHoverController = useRef(null);
|
|
11
|
+
const { compsData, tags, compsLabel } = getObjectInfo(obj);
|
|
12
|
+
const isRootObject = obj.id === 0;
|
|
13
|
+
const isObjectDestroyed = !obj.exists() && !isRootObject;
|
|
14
|
+
const showExpandTree = obj.children.length > 0;
|
|
15
|
+
const hasChildren = obj.children.length > 0;
|
|
16
|
+
const isInspecting = isRenderRoot && obj.id !== 0;
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
return () => {
|
|
19
|
+
mouseHoverController.current?.cancel();
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
const handleToggleClick = () => {
|
|
23
|
+
setIsExpanded(!isExpanded);
|
|
24
|
+
};
|
|
25
|
+
const handleMouseEnter = () => {
|
|
26
|
+
mouseHoverController.current?.cancel();
|
|
27
|
+
if (!obj.hidden) {
|
|
28
|
+
mouseHoverController.current = obj.onDraw(() => {
|
|
29
|
+
obj.drawInspect();
|
|
30
|
+
drawBoundingBox(obj, k);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const handleMouseLeave = () => {
|
|
35
|
+
mouseHoverController.current?.cancel();
|
|
36
|
+
};
|
|
37
|
+
return (_jsxs("div", { class: cx("obj", className, {
|
|
38
|
+
"obj--no-children": !hasChildren,
|
|
39
|
+
}), children: [isInspecting && _jsx(Breadcrumbs, { setRenderRoot: setRenderRoot, obj: obj }), _jsxs("div", { class: "obj__content", onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, children: [_jsxs("button", { class: cx("obj__header", {
|
|
40
|
+
"obj__header--expandable": showExpandTree,
|
|
41
|
+
}), onClick: handleToggleClick, children: [_jsx("span", { class: "obj__expand-icon", children: isExpanded ? _jsx(MinusIcon, {}) : _jsx(PlusIcon, {}) }), _jsxs("div", { class: "obj__id", children: ["ID ", obj.id, ":"] }), tags ? (_jsx("div", { class: "obj__tags", children: isRootObject ? "Root" : tags })) : (_jsx("div", { class: "obj__comp-names", children: compsLabel })), obj.children.length > 0 && _jsxs("div", { children: ["(", obj.children.length, ")"] }), isObjectDestroyed && _jsx("div", { class: "obj__destroyed", children: "DESTROYED" })] }), _jsxs("div", { class: "obj__buttons", children: [!isRenderRoot && (_jsx("button", { class: "btn", onClick: () => setRenderRoot(obj), children: "inspect" })), _jsx("button", { class: "btn ", onClick: () => console.log(obj), children: "log" })] }), isExpanded && (_jsx("div", { class: "obj__comps-wrapper", children: _jsxs("div", { class: "obj__comps", children: [_jsxs("div", { class: "obj__comps-row", children: [_jsx("label", { for: `paused-${obj.id}`, children: _jsx("b", { children: "paused" }) }), _jsx("div", { children: _jsx("input", { id: `paused-${obj.id}`, type: "checkbox", defaultChecked: obj.paused, onChange: () => (obj.paused = !obj.paused) }) })] }), compsData.map((comp) => (_jsxs("div", { class: "obj__comps-row", children: [_jsx("div", { children: _jsx("b", { children: comp.tag }) }), _jsx("div", { children: comp.value })] }, comp.tag)))] }) }))] }), isExpanded && hasChildren && (_jsx("div", { class: "obj__children", style: { display: isExpanded ? "block" : "none" }, children: obj.children.map((child) => (_jsx(GameObject, { k: k, obj: child, setRenderRoot: setRenderRoot }, child.id))) }))] }, obj.id));
|
|
42
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const PlusIcon: () => import("preact").JSX.Element;
|
|
2
|
+
export declare const MinusIcon: () => import("preact").JSX.Element;
|
|
3
|
+
export declare const ArrowUpIcon: () => import("preact").JSX.Element;
|
|
4
|
+
export declare const ArrowDownIcon: () => import("preact").JSX.Element;
|
|
5
|
+
export declare const ArrowLeftIcon: () => import("preact").JSX.Element;
|
|
6
|
+
export declare const ArrowRightIcon: () => import("preact").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
export const PlusIcon = () => {
|
|
3
|
+
return (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", xmlns: "http://www.w3.org/2000/svg", children: _jsxs("g", { fill: "none", "stroke-width": "1.25", stroke: "currentColor", "stroke-linejoin": "round", "stroke-linecap": "round", children: [_jsx("rect", { width: "14", height: "14", x: "1", y: "1", rx: "4" }), _jsx("path", { d: "M 8 4 V 12 M 4 8 H12" })] }) }));
|
|
4
|
+
};
|
|
5
|
+
export const MinusIcon = () => {
|
|
6
|
+
return (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsxs("g", { fill: "none", "stroke-width": "1.25", stroke: "currentColor", "stroke-linejoin": "round", "stroke-linecap": "round", children: [_jsx("rect", { width: "14", height: "14", x: "1", y: "1", rx: "4" }), _jsx("path", { d: "M 4 8 H 12" })] }) }));
|
|
7
|
+
};
|
|
8
|
+
export const ArrowUpIcon = () => {
|
|
9
|
+
return (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("g", { fill: "none", stroke: "currentColor", "stroke-linejoin": "round", "stroke-linecap": "round", children: _jsx("path", { d: "M 3 10 L 8 6 L 13 10" }) }) }));
|
|
10
|
+
};
|
|
11
|
+
export const ArrowDownIcon = () => {
|
|
12
|
+
return (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("g", { fill: "none", stroke: "currentColor", "stroke-linejoin": "round", "stroke-linecap": "round", children: _jsx("path", { d: "M 3 6 L 8 10 L 13 6" }) }) }));
|
|
13
|
+
};
|
|
14
|
+
export const ArrowLeftIcon = () => {
|
|
15
|
+
return (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("g", { fill: "none", stroke: "currentColor", "stroke-linejoin": "round", "stroke-linecap": "round", children: _jsx("path", { d: "M 10 3 L 6 8 L 10 13" }) }) }));
|
|
16
|
+
};
|
|
17
|
+
export const ArrowRightIcon = () => {
|
|
18
|
+
return (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("g", { fill: "none", stroke: "currentColor", "stroke-linejoin": "round", "stroke-linecap": "round", children: _jsx("path", { d: "M 6 3 L 10 8 L 6 13" }) }) }));
|
|
19
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { KAPLAYCtxT } from "kaplay";
|
|
2
|
+
import type { InspectorOptions } from "../init";
|
|
3
|
+
export interface InspectorProps extends InspectorOptions {
|
|
4
|
+
k: KAPLAYCtxT;
|
|
5
|
+
}
|
|
6
|
+
export declare const Inspector: ({ updateTimeout, k }: InspectorProps) => import("preact").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "preact/hooks";
|
|
3
|
+
import { GameObject } from "./game-object";
|
|
4
|
+
export const Inspector = ({ updateTimeout = 250, k }) => {
|
|
5
|
+
const [root, setRoot] = useState(k.getTreeRoot());
|
|
6
|
+
const [renderIndex, setRenderIndex] = useState(0);
|
|
7
|
+
// Force re-render every updateTimeout milliseconds
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const interval = setInterval(() => {
|
|
10
|
+
setRenderIndex(renderIndex + 1);
|
|
11
|
+
}, updateTimeout);
|
|
12
|
+
return () => clearInterval(interval);
|
|
13
|
+
}, [renderIndex, updateTimeout]);
|
|
14
|
+
const handlePauseClick = () => {
|
|
15
|
+
const root = k.getTreeRoot();
|
|
16
|
+
root.paused = !root.paused;
|
|
17
|
+
};
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { class: "exp__header", children: [_jsx("button", { class: "btn", onClick: handlePauseClick, children: "Pause/Resume" }), "\u2022", _jsxs("div", { children: [k.get("*", { recursive: true }).length, " objects"] }), "\u2022", _jsxs("div", { children: [Math.round(k.debug.fps()), " fps"] })] }), _jsx("div", { class: "exp__objects", children: _jsx(GameObject, { k: k, className: "obj--root", obj: root, setRenderRoot: setRoot, isExpanded: true, isRenderRoot: true }) })] }));
|
|
19
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { roundToDecimal } from "../lib/round-to-decimal";
|
|
3
|
+
import { ArrowDownIcon, ArrowLeftIcon, ArrowRightIcon, ArrowUpIcon, } from "./icons";
|
|
4
|
+
export const PositionControls = ({ obj }) => {
|
|
5
|
+
if (!obj.pos) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
return (_jsxs("div", { class: "pos-controls", children: [_jsx("button", { class: "btn", onClick: () => (obj.pos.x -= 1), children: _jsx(ArrowLeftIcon, {}) }), _jsx("button", { class: "btn", onClick: () => (obj.pos.x += 1), children: _jsx(ArrowRightIcon, {}) }), _jsxs("div", { class: "pos-controls__value", children: ["x: ", roundToDecimal(obj.pos.x, 2)] }), _jsxs("div", { class: "pos-controls__value", children: ["y: ", roundToDecimal(obj.pos.y, 2)] }), _jsx("button", { class: "btn", onClick: () => (obj.pos.y -= 1), children: _jsx(ArrowUpIcon, {}) }), _jsx("button", { class: "btn", onClick: () => (obj.pos.y += 1), children: _jsx(ArrowDownIcon, {}) })] }));
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
export const TextControls = ({ obj }) => {
|
|
3
|
+
if (typeof obj.text !== "string") {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
return (_jsx("div", { class: "text-controls", children: _jsx("input", { class: "text-controls__input", type: "text", placeholder: "Enter text", defaultValue: obj.text, onInput: (e) => {
|
|
7
|
+
obj.text = e.target.value;
|
|
8
|
+
} }) }));
|
|
9
|
+
};
|
package/dist/init.d.ts
ADDED
package/dist/init.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { render } from "preact";
|
|
3
|
+
import { Inspector } from "./components/inspector";
|
|
4
|
+
export default function init(k, props = {}) {
|
|
5
|
+
const appElement = document.createElement("div");
|
|
6
|
+
appElement.className = "exp";
|
|
7
|
+
document.body.appendChild(appElement);
|
|
8
|
+
render(_jsx(Inspector, { k: k, ...props }), appElement);
|
|
9
|
+
}
|
package/dist/lib/cx.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const cx: (...classes: (string | Record<string, any>)[]) => string;
|
package/dist/lib/cx.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const drawBoundingBox = (obj, k) => {
|
|
2
|
+
// TODO handle a case when anchor is a vec2
|
|
3
|
+
const anchor = obj.anchor || "topleft";
|
|
4
|
+
if (obj.renderArea && obj.has("anchor")) {
|
|
5
|
+
const offset = k.vec2(0);
|
|
6
|
+
const rect = obj.renderArea().bbox();
|
|
7
|
+
if (anchor.includes("left")) {
|
|
8
|
+
offset.x = 0;
|
|
9
|
+
}
|
|
10
|
+
else if (anchor.includes("right")) {
|
|
11
|
+
offset.x = rect.width;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
offset.x = rect.width / 2;
|
|
15
|
+
}
|
|
16
|
+
if (anchor.includes("top")) {
|
|
17
|
+
offset.y = 0;
|
|
18
|
+
}
|
|
19
|
+
else if (anchor.includes("bot")) {
|
|
20
|
+
offset.y = rect.height;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
offset.y = rect.height / 2;
|
|
24
|
+
}
|
|
25
|
+
rect.pos = rect.pos.sub(offset);
|
|
26
|
+
k.drawRect({
|
|
27
|
+
...rect,
|
|
28
|
+
fill: false,
|
|
29
|
+
outline: {
|
|
30
|
+
width: 1,
|
|
31
|
+
color: k.GREEN,
|
|
32
|
+
opacity: 0.75,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
// TODO figure out why these positions are wrong
|
|
36
|
+
// obj.children.forEach((child) => drawBoundingBox(child, k));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { inspectComps } from "./inspect-comps";
|
|
2
|
+
export const getObjectInfo = (obj) => {
|
|
3
|
+
const compsData = inspectComps(obj);
|
|
4
|
+
const tags = obj.id === 0 ? "Root" : obj.tags.slice(1).join(", ");
|
|
5
|
+
const compsLabel = compsData.map((comp) => comp.tag).join(", ");
|
|
6
|
+
return {
|
|
7
|
+
compsData,
|
|
8
|
+
tags,
|
|
9
|
+
compsLabel,
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { stringify } from "./stringify";
|
|
3
|
+
import { PositionControls } from "../components/position-controls";
|
|
4
|
+
import { TextControls } from "../components/text-controls";
|
|
5
|
+
export const inspectComps = (obj) => {
|
|
6
|
+
const info = {};
|
|
7
|
+
for (const [tag, comp] of obj._compStates) {
|
|
8
|
+
info[tag] = comp.inspect?.() ?? null;
|
|
9
|
+
}
|
|
10
|
+
for (const [i, comp] of obj._anonymousCompStates.entries()) {
|
|
11
|
+
if (comp.inspect) {
|
|
12
|
+
info[i] = comp.inspect();
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
for (const [key, value] of Object.entries(comp)) {
|
|
16
|
+
if (typeof value === "function") {
|
|
17
|
+
info[key] = `${key}: function`;
|
|
18
|
+
}
|
|
19
|
+
else if (typeof value === "object") {
|
|
20
|
+
info[key] = `${key}: ${stringify(value)}`;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
info[key] = `${key}: ${value}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const lines = [];
|
|
28
|
+
for (const tag in info) {
|
|
29
|
+
if (info[tag]) {
|
|
30
|
+
if (tag === "pos") {
|
|
31
|
+
// Custom component for position
|
|
32
|
+
lines.push({
|
|
33
|
+
tag,
|
|
34
|
+
value: _jsx(PositionControls, { obj: obj }),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
lines.push({
|
|
39
|
+
tag,
|
|
40
|
+
value: info[tag].replace(`${tag}: `, ""),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (tag === "text") {
|
|
46
|
+
// Custom component for text
|
|
47
|
+
lines.push({
|
|
48
|
+
tag,
|
|
49
|
+
value: _jsx(TextControls, { obj: obj }),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// pushes only the tag (name of the component)
|
|
54
|
+
lines.push({
|
|
55
|
+
tag,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return lines.sort((a, b) => a.tag.localeCompare(b.tag));
|
|
61
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const roundToDecimal: (value: number, decimalPlaces: number) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stringify: (obj: any, maxDepth?: number, currentDepth?: number) => string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const stringify = (obj, maxDepth = 1, currentDepth = 0) => {
|
|
2
|
+
if (typeof obj !== "object" || obj === null) {
|
|
3
|
+
return obj.toString();
|
|
4
|
+
}
|
|
5
|
+
const lines = Object.entries(obj).map(([key, value]) => {
|
|
6
|
+
if (typeof value === "function") {
|
|
7
|
+
return `${key}: function`;
|
|
8
|
+
}
|
|
9
|
+
else if (typeof value === "object") {
|
|
10
|
+
if (currentDepth < maxDepth) {
|
|
11
|
+
return `${key}: ${stringify(value, maxDepth, currentDepth + 1)}`;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return `${key}: [Object object]`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return `${key}: ${value}`;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return `{ ${lines.join(", ")} }`;
|
|
22
|
+
};
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
.exp {
|
|
2
|
+
--exp-bg: rgb(250 250 250);
|
|
3
|
+
--exp-fg: rgb(25 25 25);
|
|
4
|
+
--exp-red: #d9174b;
|
|
5
|
+
--exp-gray-light: rgb(238 238 238);
|
|
6
|
+
--exp-gray-bg: rgb(244 244 244);
|
|
7
|
+
--exp-border: rgb(170 170 170);
|
|
8
|
+
--exp-border-light: rgb(210 210 210);
|
|
9
|
+
|
|
10
|
+
--exp-l: 0.62;
|
|
11
|
+
--exp-c: 0.2;
|
|
12
|
+
--exp-h: 250;
|
|
13
|
+
--exp-lch: var(--exp-l) var(--exp-c) var(--exp-h);
|
|
14
|
+
--exp-h-secondary: 150;
|
|
15
|
+
--exp-secondary-lch: var(--exp-l) var(--exp-c) var(--exp-h-secondary);
|
|
16
|
+
|
|
17
|
+
--exp-primary: oklch(var(--exp-lch));
|
|
18
|
+
--exp-primary-light: oklch(var(--exp-lch) / 0.1);
|
|
19
|
+
--exp-secondary: oklch(var(--exp-secondary-lch));
|
|
20
|
+
|
|
21
|
+
@media (prefers-color-scheme: dark) {
|
|
22
|
+
--exp-bg: rgb(30 30 30);
|
|
23
|
+
--exp-fg: rgb(230 230 230);
|
|
24
|
+
--exp-red: #ff4073;
|
|
25
|
+
--exp-gray-light: rgb(50 50 50);
|
|
26
|
+
--exp-gray-bg: rgb(40 40 40);
|
|
27
|
+
--exp-border: rgb(80 80 80);
|
|
28
|
+
--exp-border-light: rgb(60 60 60);
|
|
29
|
+
|
|
30
|
+
--exp-l: 0.7;
|
|
31
|
+
--exp-c: 0.15;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
font-synthesis: none;
|
|
35
|
+
text-rendering: optimizeLegibility;
|
|
36
|
+
-webkit-font-smoothing: antialiased;
|
|
37
|
+
-moz-osx-font-smoothing: grayscale;
|
|
38
|
+
position: fixed;
|
|
39
|
+
bottom: 0;
|
|
40
|
+
left: 0;
|
|
41
|
+
width: 100%;
|
|
42
|
+
background-color: var(--exp-bg);
|
|
43
|
+
color: var(--exp-fg);
|
|
44
|
+
max-height: 45vh;
|
|
45
|
+
overflow: auto;
|
|
46
|
+
font-family:
|
|
47
|
+
ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
|
|
48
|
+
"DejaVu Sans Mono", monospace;
|
|
49
|
+
font-size: 0.875rem;
|
|
50
|
+
scrollbar-width: thin;
|
|
51
|
+
scrollbar-color: var(--exp-border) transparent;
|
|
52
|
+
box-sizing: border-box;
|
|
53
|
+
padding: 0;
|
|
54
|
+
margin: 0;
|
|
55
|
+
line-height: 1.2;
|
|
56
|
+
border-top: 1px solid var(--exp-gray-light);
|
|
57
|
+
|
|
58
|
+
* {
|
|
59
|
+
box-sizing: border-box;
|
|
60
|
+
padding: 0;
|
|
61
|
+
margin: 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
button,
|
|
65
|
+
input,
|
|
66
|
+
select,
|
|
67
|
+
textarea {
|
|
68
|
+
accent-color: var(--exp-primary);
|
|
69
|
+
font: inherit;
|
|
70
|
+
color: inherit;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
button {
|
|
74
|
+
border: none;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
background: none;
|
|
77
|
+
outline-offset: 2px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
button:focus-visible {
|
|
81
|
+
outline: 2px solid var(--exp-primary);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
button:active {
|
|
85
|
+
transform: translateY(1px);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.btn {
|
|
89
|
+
padding: 0.25rem 0.375rem;
|
|
90
|
+
font-size: 0.75rem;
|
|
91
|
+
border-radius: 4px;
|
|
92
|
+
background-color: var(--exp-gray-light);
|
|
93
|
+
border: 1px solid var(--exp-border-light);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.btn:hover {
|
|
97
|
+
border: 1px solid var(--exp-primary);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
svg {
|
|
101
|
+
display: block;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.exp__header {
|
|
105
|
+
position: sticky;
|
|
106
|
+
top: 0;
|
|
107
|
+
display: flex;
|
|
108
|
+
gap: 0.5rem;
|
|
109
|
+
padding: 0.5rem;
|
|
110
|
+
align-items: center;
|
|
111
|
+
z-index: 2;
|
|
112
|
+
background-color: var(--exp-bg);
|
|
113
|
+
border-bottom: 1px solid var(--exp-gray-light);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.exp__objects {
|
|
117
|
+
padding: 0.5rem;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Game object */
|
|
121
|
+
|
|
122
|
+
.obj {
|
|
123
|
+
transition: background 500ms;
|
|
124
|
+
position: relative;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.obj .obj {
|
|
128
|
+
padding-left: 1.5rem;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.obj .obj::before,
|
|
132
|
+
.obj .obj__comps-wrapper::before {
|
|
133
|
+
content: "";
|
|
134
|
+
height: 100%;
|
|
135
|
+
position: absolute;
|
|
136
|
+
left: 0.75rem;
|
|
137
|
+
top: 0;
|
|
138
|
+
border-left: 1px solid var(--exp-border);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.obj .obj__comps-wrapper::before {
|
|
142
|
+
left: -1rem;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.obj .obj:last-child:before {
|
|
146
|
+
height: 1rem;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.obj--no-children .obj__comps-wrapper:last-child::before {
|
|
150
|
+
display: none;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.obj--root > .obj__content .obj__header::before {
|
|
154
|
+
display: none;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.obj__content {
|
|
158
|
+
position: relative;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* Header */
|
|
162
|
+
|
|
163
|
+
.obj__header {
|
|
164
|
+
position: relative;
|
|
165
|
+
display: flex;
|
|
166
|
+
padding: 0.25rem 0.25rem;
|
|
167
|
+
margin-right: -0.25rem;
|
|
168
|
+
gap: 0.25rem;
|
|
169
|
+
align-items: center;
|
|
170
|
+
height: 2rem;
|
|
171
|
+
width: calc(100% + 0.25rem);
|
|
172
|
+
border-radius: 4px;
|
|
173
|
+
outline-offset: 0;
|
|
174
|
+
|
|
175
|
+
svg rect {
|
|
176
|
+
fill: var(--exp-bg);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.obj__header:hover {
|
|
181
|
+
background-color: var(--exp-primary-light);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.obj__header::before {
|
|
185
|
+
content: "";
|
|
186
|
+
position: absolute;
|
|
187
|
+
left: calc(-0.75rem);
|
|
188
|
+
width: 0.75rem;
|
|
189
|
+
top: 50%;
|
|
190
|
+
border-bottom: 1px solid var(--exp-border);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/* Header info and actions */
|
|
194
|
+
|
|
195
|
+
.obj__tags {
|
|
196
|
+
color: var(--exp-primary);
|
|
197
|
+
font-weight: bold;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.obj__comp-names {
|
|
201
|
+
color: var(--exp-secondary);
|
|
202
|
+
font-weight: bold;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.obj__buttons {
|
|
206
|
+
position: absolute;
|
|
207
|
+
top: 0;
|
|
208
|
+
right: 0;
|
|
209
|
+
display: flex;
|
|
210
|
+
gap: 0.25rem;
|
|
211
|
+
align-items: center;
|
|
212
|
+
height: 2rem;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.obj__destroyed {
|
|
216
|
+
color: var(--exp-red);
|
|
217
|
+
font-weight: bold;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* Expand tree button */
|
|
221
|
+
|
|
222
|
+
.obj__expand-icon {
|
|
223
|
+
margin-right: 0.25rem;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.obj__header:hover .obj__expand-icon {
|
|
227
|
+
color: var(--exp-primary);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/* Comps */
|
|
231
|
+
|
|
232
|
+
.obj__comps-wrapper {
|
|
233
|
+
position: relative;
|
|
234
|
+
padding: 0.5rem 0;
|
|
235
|
+
margin-left: 1.75rem;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.obj__comps {
|
|
239
|
+
border: 1px solid var(--exp-border-light);
|
|
240
|
+
border-radius: 4px;
|
|
241
|
+
overflow: hidden;
|
|
242
|
+
font-size: 0.75rem;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.obj__comps-row {
|
|
246
|
+
display: grid;
|
|
247
|
+
align-items: center;
|
|
248
|
+
padding: 0.375rem 0.5rem;
|
|
249
|
+
gap: 0.5rem;
|
|
250
|
+
grid-template-columns: 10rem 1fr;
|
|
251
|
+
|
|
252
|
+
input {
|
|
253
|
+
display: block;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.obj__comps-row:nth-child(even) {
|
|
258
|
+
background-color: var(--exp-gray-bg);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/* Children */
|
|
262
|
+
|
|
263
|
+
.obj__children {
|
|
264
|
+
padding-bottom: 1rem;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/* Position controls */
|
|
268
|
+
|
|
269
|
+
.pos-controls {
|
|
270
|
+
display: flex;
|
|
271
|
+
align-items: center;
|
|
272
|
+
gap: 0.25rem;
|
|
273
|
+
width: fit-content;
|
|
274
|
+
min-width: 12rem;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.pos-controls__.btn,
|
|
278
|
+
.pos-controls__value {
|
|
279
|
+
flex-shrink: 0;
|
|
280
|
+
text-align: center;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.pos-controls__value {
|
|
284
|
+
width: 5rem;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/* Text Controls */
|
|
288
|
+
|
|
289
|
+
.text-controls__input {
|
|
290
|
+
background-color: var(--exp-bg);
|
|
291
|
+
border: none;
|
|
292
|
+
padding: 0.25rem 0.375rem;
|
|
293
|
+
border: 1px solid var(--exp-border-light);
|
|
294
|
+
font-size: 0.75rem;
|
|
295
|
+
border-radius: 4px;
|
|
296
|
+
width: 100%;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.text-controls__input:focus-visible {
|
|
300
|
+
outline: none;
|
|
301
|
+
border-color: var(--exp-primary);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/* Breadcrumbs */
|
|
306
|
+
|
|
307
|
+
.breadcrumbs {
|
|
308
|
+
font-size: 0.75rem;
|
|
309
|
+
display: flex;
|
|
310
|
+
margin-bottom: 0.5rem;
|
|
311
|
+
gap: 0.25rem;
|
|
312
|
+
align-items: center;
|
|
313
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stanko/kaplay-inspector",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/init.js",
|
|
7
|
+
"types": "./dist/init.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"./dist",
|
|
10
|
+
"./public"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"start": "vite",
|
|
14
|
+
"dev": "vite",
|
|
15
|
+
"preview": "vite preview",
|
|
16
|
+
"copy-css": "cp ./src/styles/styles.css ./dist/",
|
|
17
|
+
"build": "tsc -b && rm -rf ./docs && vite build && touch ./docs/.nojekyll",
|
|
18
|
+
"build-lib": "rm -rf ./dist && tsc -p ./tsconfig-lib.json && npm run copy-css",
|
|
19
|
+
"prepare": "cp ./pre-commit ./.git/hooks/pre-commit && chmod +x ./.git/hooks/pre-commit",
|
|
20
|
+
"prepublish": "npm run build-lib"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"kaplay": "^4000.0.0-alpha.20"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"preact": "^10.27.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@preact/preset-vite": "^2.10.2",
|
|
30
|
+
"@types/node": "^24.10.1",
|
|
31
|
+
"typescript": "~5.9.3",
|
|
32
|
+
"vite": "^7.2.4"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+ssh://git@github.com/Stanko/kaplay-inspector.git"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"kaplay",
|
|
40
|
+
"inspector",
|
|
41
|
+
"dev tools"
|
|
42
|
+
],
|
|
43
|
+
"author": "Stanko",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/Stanko/kaplay-inspector/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/Stanko/kaplay-inspector"
|
|
48
|
+
}
|