auto-register elements

This commit is contained in:
Orion Reed 2024-12-03 03:46:46 -05:00
parent 23d3d54e33
commit 3a6ade2e36
45 changed files with 72 additions and 158 deletions

View File

@ -31,8 +31,6 @@
import { DistanceField } from '../src/distance-field.ts'; import { DistanceField } from '../src/distance-field.ts';
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
FolkShape.define();
const d = document.querySelector('distance-field'); const d = document.querySelector('distance-field');
const geometries = []; const geometries = [];

View File

@ -24,8 +24,6 @@
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
FolkShape.define();
const geometries = []; const geometries = [];
const now = performance.now(); const now = performance.now();

View File

@ -66,8 +66,6 @@
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
FolkShape.define();
const geos = document.querySelectorAll('folk-shape'); const geos = document.querySelectorAll('folk-shape');
geos.forEach((el, i) => (el.style.viewTransitionName = `g${i}`)); geos.forEach((el, i) => (el.style.viewTransitionName = `g${i}`));

View File

@ -64,11 +64,6 @@
import { FolkLLM } from '../src/folk-llm.ts'; import { FolkLLM } from '../src/folk-llm.ts';
import { FolkMetronome } from '../src/folk-metronome.ts'; import { FolkMetronome } from '../src/folk-metronome.ts';
import { FolkEventPropagator } from '../src/folk-event-propagator.ts'; import { FolkEventPropagator } from '../src/folk-event-propagator.ts';
FolkShape.define();
FolkLLM.define();
FolkMetronome.define();
FolkEventPropagator.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -102,8 +102,6 @@
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
FolkShape.define();
function copyStyles(from, to) { function copyStyles(from, to) {
const styles = getComputedStyle(from); const styles = getComputedStyle(from);
for (const name of styles) { for (const name of styles) {

View File

@ -64,8 +64,6 @@
<script type="module"> <script type="module">
import { FolkXanadu } from '../src/folk-xanadu.ts'; import { FolkXanadu } from '../src/folk-xanadu.ts';
FolkXanadu.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -44,9 +44,6 @@
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { DistanceField } from '../src/distance-field.ts'; import { DistanceField } from '../src/distance-field.ts';
FolkShape.define();
DistanceField.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -121,11 +121,6 @@
import { FolkLLM } from '../src/folk-llm.ts'; import { FolkLLM } from '../src/folk-llm.ts';
import { FolkTimer } from '../src/folk-timer.ts'; import { FolkTimer } from '../src/folk-timer.ts';
import { FolkEventPropagator } from '../src/folk-event-propagator.ts'; import { FolkEventPropagator } from '../src/folk-event-propagator.ts';
FolkShape.define();
FolkLLM.define();
FolkTimer.define();
FolkEventPropagator.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -54,9 +54,6 @@ rotation: from.x"
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { FolkEventPropagator } from '../src/folk-event-propagator.ts'; import { FolkEventPropagator } from '../src/folk-event-propagator.ts';
FolkShape.define();
FolkEventPropagator.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -82,9 +82,6 @@
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { FolkEventPropagator } from '../src/folk-event-propagator.ts'; import { FolkEventPropagator } from '../src/folk-event-propagator.ts';
FolkShape.define();
FolkEventPropagator.define();
const ropeMode = document.querySelector('input[type="checkbox"]'); const ropeMode = document.querySelector('input[type="checkbox"]');
ropeMode.addEventListener('input', () => { ropeMode.addEventListener('input', () => {

View File

@ -24,9 +24,6 @@
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { FolkInk } from '../src/folk-ink.ts'; import { FolkInk } from '../src/folk-ink.ts';
FolkShape.define();
FolkInk.define();
const drawButton = document.querySelector('button'); const drawButton = document.querySelector('button');
async function draw(e) { async function draw(e) {

View File

@ -125,9 +125,6 @@
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { FolkSpreadsheet } from '../src/folk-spreadsheet.ts'; import { FolkSpreadsheet } from '../src/folk-spreadsheet.ts';
FolkShape.define();
FolkSpreadsheet.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -55,10 +55,6 @@
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { DistanceField } from '../src/distance-field.ts'; import { DistanceField } from '../src/distance-field.ts';
import { FolkToolbar } from '../src/folk-toolbar.ts'; import { FolkToolbar } from '../src/folk-toolbar.ts';
FolkShape.define();
DistanceField.define();
FolkToolbar.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -134,14 +134,6 @@
} }
}, },
}); });
FolkShape.define();
FolkMap.define();
FolkCluster.define();
FolkProximity.define();
FolkWeather.define();
GeoWiki.define();
FolkEventPropagator.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -119,13 +119,6 @@
} }
}, },
}); });
FolkShape.define();
FolkMap.define();
FolkCluster.define();
FolkProximity.define();
FolkWeather.define();
GeoWiki.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -64,15 +64,6 @@
import { RecordPlayer } from './src/record-player.ts'; import { RecordPlayer } from './src/record-player.ts';
import { collisionDetection } from '../src/common/collision.ts'; import { collisionDetection } from '../src/common/collision.ts';
FolkShape.define();
RecordPlayer.define();
/**
sips -c 326 276 --cropOffset 1 1 *.png --out pngs/
ffmpeg -framerate 25 -pattern_type glob -i '*.png' -c:v prores -pix_fmt yuva444p10le dancing-flower.mov
ffmpeg -framerate 25 -f image2 -pattern_type glob -i '*.png' -c:v libvpx-vp9 -pix_fmt yuva420p dancing-flowers.webm
*/
let proximityDistance = 150; let proximityDistance = 150;
const proximitySet = new Set(); const proximitySet = new Set();
const recordPlayerGeometry = document.querySelector('folk-shape:has(record-player)'); const recordPlayerGeometry = document.querySelector('folk-shape:has(record-player)');

View File

@ -153,9 +153,6 @@
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { FolkConnection } from '../src/folk-connection.ts'; import { FolkConnection } from '../src/folk-connection.ts';
FolkShape.define();
FolkConnection.define();
document.body.querySelectorAll('folk-shape').forEach((el, i) => (el.style.viewTransitionName = `g${i}`)); document.body.querySelectorAll('folk-shape').forEach((el, i) => (el.style.viewTransitionName = `g${i}`));
document.body.querySelectorAll('folk-connection').forEach((el, i) => (el.style.viewTransitionName = `c${i}`)); document.body.querySelectorAll('folk-connection').forEach((el, i) => (el.style.viewTransitionName = `c${i}`));
document.body.querySelectorAll('h2').forEach((el, i) => (el.style.viewTransitionName = `h${i}`)); document.body.querySelectorAll('h2').forEach((el, i) => (el.style.viewTransitionName = `h${i}`));

View File

@ -32,8 +32,6 @@
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { collisionDetection } from '../src/common/collision.ts'; import { collisionDetection } from '../src/common/collision.ts';
FolkShape.define();
const geometryElements = document.querySelectorAll('folk-shape'); const geometryElements = document.querySelectorAll('folk-shape');
function handleCollision(e) { function handleCollision(e) {

View File

@ -27,8 +27,6 @@
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
FolkShape.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -46,9 +46,6 @@
import { FolkSpace } from '../src/folk-space.ts'; import { FolkSpace } from '../src/folk-space.ts';
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
FolkSpace.define();
FolkShape.define();
const space = document.getElementById('space'); const space = document.getElementById('space');
document.addEventListener('keydown', (event) => { document.addEventListener('keydown', (event) => {
if (event.key === 'Enter') { if (event.key === 'Enter') {

View File

@ -170,10 +170,6 @@
import { FolkConnection } from '../src/folk-connection.ts'; import { FolkConnection } from '../src/folk-connection.ts';
import { FolkSpreadsheet } from '../src/folk-spreadsheet.ts'; import { FolkSpreadsheet } from '../src/folk-spreadsheet.ts';
FolkShape.define();
FolkConnection.define();
FolkSpreadsheet.define();
let isProjected = false; let isProjected = false;
const button = document.querySelector('button'); const button = document.querySelector('button');

View File

@ -171,11 +171,6 @@
import { FolkEventPropagator } from '../src/folk-event-propagator.ts'; import { FolkEventPropagator } from '../src/folk-event-propagator.ts';
import { FolkSpreadsheet } from '../src/folk-spreadsheet.ts'; import { FolkSpreadsheet } from '../src/folk-spreadsheet.ts';
FolkMap.define();
FolkShape.define();
FolkSpreadsheet.define();
FolkEventPropagator.define();
window.round = (number, digits = 0) => { window.round = (number, digits = 0) => {
const base = Number('1'.padEnd(digits + 1, '0')); const base = Number('1'.padEnd(digits + 1, '0'));
return Math.round(number * base) / base; return Math.round(number * base) / base;

View File

@ -46,9 +46,6 @@
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { FolkRope } from '../src/folk-rope.ts'; import { FolkRope } from '../src/folk-rope.ts';
FolkShape.define();
FolkRope.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -37,9 +37,6 @@
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { FolkConnection } from '../src/folk-connection.ts'; import { FolkConnection } from '../src/folk-connection.ts';
import '../src/common/iframe-script.ts'; import '../src/common/iframe-script.ts';
FolkShape.define();
FolkConnection.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -40,9 +40,6 @@
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { FolkRope } from '../src/folk-rope.ts'; import { FolkRope } from '../src/folk-rope.ts';
FolkShape.define();
FolkRope.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -38,9 +38,6 @@
<script type="module"> <script type="module">
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
import { FolkHull } from '../src/folk-hull.ts'; import { FolkHull } from '../src/folk-hull.ts';
FolkShape.define();
FolkHull.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -203,70 +203,6 @@
<script type="module"> <script type="module">
import { FolkXanadu } from '../src/folk-xanadu.ts'; import { FolkXanadu } from '../src/folk-xanadu.ts';
import { FolkShape } from '../src/folk-shape.ts'; import { FolkShape } from '../src/folk-shape.ts';
FolkShape.define();
FolkXanadu.define();
// class AnimatedXanaduLink extends FolkXanadu {
// sourceAnimation = null;
// targetAnimation = null;
// observeSource() {
// super.observeSource();
// this.sourceAnimation = this.animate(
// [
// { opacity: 0.3, offset: 0 },
// { opacity: 1, offset: 0.1 },
// { opacity: 1, offset: 0.9 },
// { opacity: 0.3, offset: 1 },
// ],
// {
// timeline: new ViewTimeline({
// subject: this.sourceElement,
// }),
// rangeStart: 'entry 0%',
// rangeEnd: 'exit 100%',
// }
// );
// }
// unobserveSource() {
// super.unobserveSource();
// this.sourceAnimation?.cancel();
// this.sourceAnimation = null;
// }
// observeTarget() {
// super.observeTarget();
// this.targetAnimation = this.animate(
// [
// { opacity: 0.3, offset: 0 },
// { opacity: 1, offset: 0.1 },
// { opacity: 1, offset: 0.9 },
// { opacity: 0.3, offset: 1 },
// ],
// {
// timeline: new ViewTimeline({
// subject: this.targetElement,
// }),
// rangeStart: 'entry 0%',
// rangeEnd: 'exit 100%',
// }
// );
// }
// unobserveTarget() {
// super.unobserveTarget();
// this.targetAnimation?.cancel();
// this.targetAnimation = null;
// }
// }
// AnimatedXanaduLink.define();
</script> </script>
</body> </body>
</html> </html>

View File

@ -568,3 +568,7 @@ void main() {
vec2 seedCoord = gl_FragCoord.xy / u_canvasSize; vec2 seedCoord = gl_FragCoord.xy / u_canvasSize;
outColor = vec4(seedCoord, v_shapeID, 0.0); // Seed coords (x, y), shape ID (z), initial distance (a) outColor = vec4(seedCoord, v_shapeID, 0.0); // Seed coords (x, y), shape ID (z), initial distance (a)
}`; }`;
if (!customElements.get('distance-field')) {
DistanceField.define();
}

View File

@ -85,3 +85,7 @@ export class FolkConnection extends AbstractArrow {
this.style.backgroundColor = 'black'; this.style.backgroundColor = 'black';
} }
} }
if (!customElements.get('folk-connection')) {
FolkConnection.define();
}

View File

@ -237,3 +237,7 @@ function parseAst(functionBody: string) {
console.log('Properties accessed on to:', Array.from(toProps)); console.log('Properties accessed on to:', Array.from(toProps));
console.log('Properties accessed on from:', Array.from(fromProps)); console.log('Properties accessed on from:', Array.from(fromProps));
} }
if (!customElements.get('folk-event-propagator')) {
FolkEventPropagator.define();
}

View File

@ -110,3 +110,7 @@ export function makeHull(rects: DOMRectReadOnly[]): Point[] {
return upperHull.concat(lowerHull); return upperHull.concat(lowerHull);
} }
if (!customElements.get('folk-hull')) {
FolkHull.define();
}

View File

@ -211,3 +211,7 @@ export class FolkInk extends HTMLElement {
return d.join(' '); return d.join(' ');
} }
} }
if (!customElements.get('folk-ink')) {
FolkInk.define();
}

View File

@ -102,3 +102,7 @@ declare global {
ai: any; ai: any;
} }
} }
if (!customElements.get('folk-llm')) {
FolkLLM.define();
}

View File

@ -94,3 +94,7 @@ export class FolkMap extends HTMLElement {
} }
}; };
} }
if (!customElements.get('folk-map')) {
FolkMap.define();
}

View File

@ -69,3 +69,7 @@ export class FolkMetronome extends HTMLElement {
this.textContent = this.#beat.toString(); this.textContent = this.#beat.toString();
}; };
} }
if (!customElements.get('folk-metronome')) {
FolkMetronome.define();
}

View File

@ -192,3 +192,7 @@ export class FolkProximity extends HTMLElement {
return null; return null;
} }
} }
if (!customElements.get('folk-proximity')) {
FolkProximity.define();
}

View File

@ -257,3 +257,7 @@ function applyConstraint(p1: RopePoint, p2: RopePoint) {
p2.pos = Vector.sub(p2.pos, adjustment); p2.pos = Vector.sub(p2.pos, adjustment);
} }
} }
if (!customElements.get('folk-rope')) {
FolkRope.define();
}

View File

@ -78,3 +78,7 @@ export class FolkSet extends HTMLElement {
update() {} update() {}
} }
if (!customElements.get('folk-set')) {
FolkSet.define();
}

View File

@ -591,3 +591,7 @@ export class FolkShape extends HTMLElement {
this.#dispatchTransformEvent(new Set(['width', 'height'])); this.#dispatchTransformEvent(new Set(['width', 'height']));
}; };
} }
if (!customElements.get('folk-shape')) {
FolkShape.define();
}

View File

@ -70,3 +70,7 @@ export class FolkSpace extends HTMLElement {
space?.classList.toggle('rotate'); space?.classList.toggle('rotate');
} }
} }
if (!customElements.get('folk-space')) {
FolkSpace.define();
}

View File

@ -513,3 +513,7 @@ export class FolkSpreadSheetCell extends HTMLElement {
} }
} }
} }
if (!customElements.get('folk-cell')) {
FolkSpreadSheetCell.define();
}

View File

@ -39,3 +39,7 @@ export class FolkTimer extends HTMLElement {
this.textContent = (time / 1000).toFixed(1); this.textContent = (time / 1000).toFixed(1);
}; };
} }
if (!customElements.get('folk-timer')) {
FolkTimer.define();
}

View File

@ -128,3 +128,7 @@ export class FolkToolbar extends HTMLElement {
return element.id; return element.id;
} }
} }
if (!customElements.get('folk-toolbar')) {
FolkToolbar.define();
}

View File

@ -68,3 +68,7 @@ export class FolkWeather extends HTMLElement {
`; `;
} }
} }
if (!customElements.get('folk-weather')) {
FolkWeather.define();
}

View File

@ -100,3 +100,7 @@ function computeInlineVertices(rects: DOMRect[]): Point[] {
return vertices; return vertices;
} }
if (!customElements.get('folk-xanadu')) {
FolkXanadu.define();
}