diff --git a/src/App.tsx b/src/App.tsx index cff4c4f..c625515 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,10 +1,12 @@ -import { atom, createShapeId, createTLUser, setUserPreferences, StoreSnapshot, Tldraw, TLGeoShape, TLInstance, TLRecord, TLShape, TLUiComponents, TLUnknownShape, TLUserPreferences, track, useEditor } from "@tldraw/tldraw"; +import { createShapeId, Tldraw, TLGeoShape, TLShape, TLUiComponents } from "@tldraw/tldraw"; import "@tldraw/tldraw/tldraw.css"; +import "./css/style.css" import { SimControls } from "./physics/ui/PhysicsControls"; import { uiOverrides } from "./physics/ui/overrides"; import { Helmet, HelmetProvider } from "react-helmet-async"; -import React, { Suspense, useEffect, useState } from "react"; +import React, { useEffect, useState } from "react"; import ReactDOM from "react-dom/client"; +import { HTMLShapeUtil, HTMLShape } from "./HTMLShapeUtil"; ReactDOM.createRoot(document.getElementById("root")!).render(); @@ -53,58 +55,51 @@ function App() { // Function to gather elements info asynchronously async function gatherElementsInfo() { - const rootElement = document.getElementById('root'); + const rootElement = document.getElementsByTagName('main')[0]; const info: any[] = []; if (rootElement) { for (const child of rootElement.children) { + if (['BUTTON'].includes(child.tagName)) continue const rect = child.getBoundingClientRect(); let w = rect.width - if (!['P', 'UL'].includes(child.tagName)) { - w = measureElementTextWidth(child); - } - console.log(w) + // if (!['P', 'UL'].includes(child.tagName)) { + // w = measureElementTextWidth(child); + // } + // console.log(w) info.push({ tagName: child.tagName, - position: { x: rect.left, y: rect.top }, - dimensions: { width: w, height: rect.height }, + x: rect.left, + y: rect.top, + w: w, + h: rect.height, + html: child.outerHTML }); }; } - // Example usage - // const element = document.getElementById('yourElementId'); // Replace 'yourElementId' with the actual ID - // if (element) { - // console.log(`Text width: ${textWidth}px`); - // } - // console.log(info.length); - // console.log(info); - return info; } - const shapes: TLGeoShape[] = elementsInfo.map((element, index) => ({ + const shapes: HTMLShape[] = elementsInfo.map((element) => ({ id: createShapeId(), - type: 'geo', - x: element.position.x, - y: element.position.y, + type: 'html', + x: element.x, + y: element.y, props: { - geo: "rectangle", - w: element.dimensions.width, - h: element.dimensions.height, - fill: 'solid', - color: 'green' + w: element.w, + h: element.h, + html: element.html, } })) shapes.push({ id: createShapeId(), - type: 'geo', + type: 'html', x: 0, y: window.innerHeight, props: { - geo: "rectangle", w: window.innerWidth, h: 20, - fill: 'solid' + html: "FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO" } }) @@ -120,10 +115,10 @@ function App() { function Default() { return ( - <> - +
+ {/* - + */}
Orion Reed
@@ -175,7 +170,7 @@ function Default() { href="https://blog.block.science/objects-as-reference-toward-robust-first-principles-of-digital-organization/">Objects as Reference: Toward Robust First Principles of Digital Organization - +
); } @@ -183,12 +178,13 @@ function Canvas({ shapes }: { shapes: TLShape[] }) { return (
- + {/* - + */} @@ -199,9 +195,9 @@ function Canvas({ shapes }: { shapes: TLShape[] }) { function Toggle() { return ( <> - + {/* - + */} diff --git a/src/HTMLShapeUtil.tsx b/src/HTMLShapeUtil.tsx new file mode 100644 index 0000000..7503eb3 --- /dev/null +++ b/src/HTMLShapeUtil.tsx @@ -0,0 +1,32 @@ +import { Rectangle2d, TLBaseShape } from '@tldraw/tldraw'; +import { HTMLContainer, ShapeUtil } from 'tldraw' + +export type HTMLShape = TLBaseShape<'html', { w: number; h: number, html: string }> + +export class HTMLShapeUtil extends ShapeUtil { + static override type = 'html' as const + + getDefaultProps(): HTMLShape['props'] { + return { + w: 100, + h: 100, + html: "
" + } + } + + getGeometry(shape: IHTMLShape) { + return new Rectangle2d({ + width: shape.props.w, + height: shape.props.h, + isFilled: true, + }) + } + + component(shape: HTMLShape) { + return
+ } + + indicator(shape: HTMLShape) { + return + } +} \ No newline at end of file diff --git a/src/css/default.css b/src/css/default.css deleted file mode 100644 index 7a6da37..0000000 --- a/src/css/default.css +++ /dev/null @@ -1,65 +0,0 @@ -@import url("reset.css"); - -body { - max-width: 60em; - margin: 0 auto; - padding-left: 4em; - padding-right: 4em; - padding-top: 3em; - padding-bottom: 3em; - font-family: "Recursive"; - font-variation-settings: "MONO" 1; - font-variation-settings: "CASL" 1; - color: #24292e; -} - -h1 { - font-size: 1.5rem; - margin-top: 1em; -} - -header { - margin-bottom: 2em; - font-size: 1.5em; - font-variation-settings: "MONO" 1; - font-variation-settings: "CASL" 1; -} - -i { - font-variation-settings: "slnt" -15; -} - -p { - font-family: Recursive; - margin-top: 0; - margin-bottom: 0.6em; - font-size: 1.1em; - font-variation-settings: "wght" 350; -} -.dinkus { - display: block; - text-align: center; - font-size: 1em; - margin-top: 2em; - margin-bottom: 0em; -} - -ul { - padding-left: 0; - list-style: decimal-leading-zero; - & li::marker { - color: rgba(0, 0, 0, 0.322); - } -} - -@media (max-width: 600px) { - body { - padding: 2em; - } - header { - margin-bottom: 1em; - } - ul { - list-style-position: inside; - } -} diff --git a/src/css/style.css b/src/css/style.css new file mode 100644 index 0000000..392858f --- /dev/null +++ b/src/css/style.css @@ -0,0 +1,133 @@ +@import url("reset.css"); + +html, +body { + padding: 0; + margin: 0; + overscroll-behavior: none; + touch-action: none; + min-height: 100vh; + min-height: -webkit-fill-available; + height: 100%; + /* font-family: "Inter", sans-serif; */ +} + +.tldraw__editor { + position: fixed; + inset: 0px; + overflow: hidden; +} + +.tl-background { + background-color: transparent; +} + +.tlui-debug-panel { + display: none; +} + +/* Non-tldraw stuff */ + +main { + max-width: 60em; + margin: 0 auto; + padding-left: 4em; + padding-right: 4em; + padding-top: 3em; + padding-bottom: 3em; + font-family: "Recursive"; + font-variation-settings: "MONO" 1; + font-variation-settings: "CASL" 1; + color: #24292e; +} + +h1 { + font-size: 1.5rem; + margin-top: 1em; +} + +header { + margin-bottom: 2em; + font-size: 1.5rem; + font-variation-settings: "MONO" 1; + font-variation-settings: "CASL" 1; +} + +i { + font-variation-settings: "slnt" -15; +} + +p { + font-family: Recursive; + margin-top: 0; + margin-bottom: 0.6em; + font-size: 1.1em; + font-variation-settings: "wght" 350; +} +.dinkus { + display: block; + text-align: center; + font-size: 1.1rem; + margin-top: 2em; + margin-bottom: 0em; +} + +ul { + padding-left: 0; + font-size: 1rem; + list-style: decimal-leading-zero; + & li::marker { + color: rgba(0, 0, 0, 0.322); + } +} + +#toggle-physics { + position: absolute; + z-index: 99999; + top: 10px; + right: 10px; + width: 50px; + height: 50px; + background: none; + border: none; + cursor: pointer; + opacity: 0.25; + &:hover { + opacity: 1; + } + & img { + width: 100%; + height: 100%; + } +} + +@media (max-width: 600px) { + body { + padding: 2em; + } + header { + margin-bottom: 1em; + } + ul { + list-style-position: inside; + } +} + +.tl-html-layer { + font-family: "Recursive"; + font-variation-settings: "MONO" 1; + font-variation-settings: "CASL" 1; + & h1, + p, + span, + header, + ul { + margin: 0; + } + & header { + font-size: 1.5rem; + } + & p { + font-size: 1.1rem; + } +} diff --git a/src/css/tldraw.css b/src/css/tldraw.css deleted file mode 100644 index b938a37..0000000 --- a/src/css/tldraw.css +++ /dev/null @@ -1,34 +0,0 @@ -@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap"); - -html, -body { - padding: 0; - margin: 0; - font-family: "Inter", sans-serif; - overscroll-behavior: none; - touch-action: none; - min-height: 100vh; - /* font-size: 16px; */ - /* mobile viewport bug fix */ - min-height: -webkit-fill-available; - height: 100%; -} - -html, -* { - box-sizing: border-box; -} - -.tldraw__editor { - position: fixed; - inset: 0px; - overflow: hidden; -} - -.tl-background { - background-color: transparent; -} - -.tlui-debug-panel { - display: none; -} diff --git a/src/css/toggle.css b/src/css/toggle.css deleted file mode 100644 index 94f0ab1..0000000 --- a/src/css/toggle.css +++ /dev/null @@ -1,19 +0,0 @@ -#toggle-physics { - position: absolute; - z-index: 99999; - top: 10px; - right: 10px; - width: 50px; - height: 50px; - background: none; - border: none; - cursor: pointer; - opacity: 0.25; - &:hover { - opacity: 1; - } - & img { - width: 100%; - height: 100%; - } -}