UNPKG

tldraw

Version:

A tiny little drawing editor.

87 lines (86 loc) 3.68 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var DefaultDebugPanel_exports = {}; __export(DefaultDebugPanel_exports, { DefaultDebugPanel: () => DefaultDebugPanel }); module.exports = __toCommonJS(DefaultDebugPanel_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_editor = require("@tldraw/editor"); var import_react = require("react"); var import_components = require("../context/components"); const DefaultDebugPanel = (0, import_react.memo)(function DefaultDebugPanel2() { const { DebugMenu } = (0, import_components.useTldrawUiComponents)(); const ref = (0, import_react.useRef)(null); (0, import_editor.usePassThroughWheelEvents)(ref); return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("footer", { ref, className: "tlui-debug-panel", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CurrentState, {}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FPS, {}), DebugMenu && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DebugMenu, {}) ] }); }); const CurrentState = (0, import_editor.track)(function CurrentState2() { const editor = (0, import_editor.useEditor)(); const path = editor.getPath(); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tlui-debug-panel__current-state", children: `${path}` }); }); function FPS() { const editor = (0, import_editor.useEditor)(); const showFps = (0, import_editor.useValue)("show_fps", () => import_editor.debugFlags.showFps.get(), [import_editor.debugFlags]); const fpsRef = (0, import_react.useRef)(null); (0, import_react.useEffect)(() => { if (!showFps) return; const TICK_LENGTH = 250; let maxKnownFps = 0; let raf = -1; let start = performance.now(); let currentTickLength = 0; let framesInCurrentTick = 0; let isSlow = false; function loop() { framesInCurrentTick++; currentTickLength = performance.now() - start; if (currentTickLength > TICK_LENGTH) { const fps = Math.round( framesInCurrentTick * (TICK_LENGTH / currentTickLength) * (1e3 / TICK_LENGTH) ); if (fps > maxKnownFps) { maxKnownFps = fps; } const slowFps = maxKnownFps * 0.75; if (fps < slowFps && !isSlow || fps >= slowFps && isSlow) { isSlow = !isSlow; } fpsRef.current.innerHTML = `FPS ${fps.toString()} (max: ${maxKnownFps})`; fpsRef.current.className = `tlui-debug-panel__fps` + (isSlow ? ` tlui-debug-panel__fps__slow` : ``); currentTickLength -= TICK_LENGTH; framesInCurrentTick = 0; start = performance.now(); } raf = editor.timers.requestAnimationFrame(loop); } loop(); return () => { cancelAnimationFrame(raf); }; }, [showFps, editor]); if (!showFps) return null; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: fpsRef }); } //# sourceMappingURL=DefaultDebugPanel.js.map