Compare commits
1 Commits
feat/shape
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9271d3a7e4
|
@@ -47,13 +47,13 @@
|
|||||||
"**/target",
|
"**/target",
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"https://plugins.dprint.dev/typescript-0.95.15.wasm",
|
"https://plugins.dprint.dev/typescript-0.95.13.wasm",
|
||||||
"https://plugins.dprint.dev/json-0.21.1.wasm",
|
"https://plugins.dprint.dev/json-0.21.1.wasm",
|
||||||
"https://plugins.dprint.dev/markdown-0.21.1.wasm",
|
"https://plugins.dprint.dev/markdown-0.20.0.wasm",
|
||||||
"https://plugins.dprint.dev/toml-0.7.0.wasm",
|
"https://plugins.dprint.dev/toml-0.7.0.wasm",
|
||||||
"https://plugins.dprint.dev/dockerfile-0.3.3.wasm",
|
"https://plugins.dprint.dev/dockerfile-0.3.3.wasm",
|
||||||
"https://plugins.dprint.dev/g-plane/markup_fmt-v0.25.3.wasm",
|
"https://plugins.dprint.dev/g-plane/markup_fmt-v0.25.3.wasm",
|
||||||
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.6.0.wasm",
|
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm",
|
||||||
"https://plugins.dprint.dev/exec-0.6.0.json@a054130d458f124f9b5c91484833828950723a5af3f8ff2bd1523bd47b83b364",
|
"https://plugins.dprint.dev/exec-0.6.0.json@a054130d458f124f9b5c91484833828950723a5af3f8ff2bd1523bd47b83b364",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ else
|
|||||||
COMMITS_SINCE_LAST_RELEASE="0"
|
COMMITS_SINCE_LAST_RELEASE="0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
commit_message=$(git log -1 --pretty=%B | tr -d '\n' | sed 's/"/\\"/g')
|
|
||||||
|
|
||||||
cat >app/static/git.json <<EOF
|
cat >app/static/git.json <<EOF
|
||||||
{
|
{
|
||||||
"ref": "${GITHUB_REF:-}",
|
"ref": "${GITHUB_REF:-}",
|
||||||
@@ -33,7 +31,7 @@ cat >app/static/git.json <<EOF
|
|||||||
"event_name": "${GITHUB_EVENT_NAME:-}",
|
"event_name": "${GITHUB_EVENT_NAME:-}",
|
||||||
"workflow": "${GITHUB_WORKFLOW:-}",
|
"workflow": "${GITHUB_WORKFLOW:-}",
|
||||||
"job": "${GITHUB_JOB:-}",
|
"job": "${GITHUB_JOB:-}",
|
||||||
"commit_message": "${commit_message}",
|
"commit_message": "$(git log -1 --pretty=%B)",
|
||||||
"commit_timestamp": "$(git log -1 --pretty=%cI)",
|
"commit_timestamp": "$(git log -1 --pretty=%cI)",
|
||||||
"branch": "${BRANCH}",
|
"branch": "${BRANCH}",
|
||||||
"commits_since_last_release": "${COMMITS_SINCE_LAST_RELEASE}"
|
"commits_since_last_release": "${COMMITS_SINCE_LAST_RELEASE}"
|
||||||
|
|||||||
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -245,14 +245,6 @@ dependencies = [
|
|||||||
"zmij",
|
"zmij",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shape"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"nodarium_macros",
|
|
||||||
"nodarium_utils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stem"
|
name = "stem"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
@@ -2,19 +2,19 @@
|
|||||||
import { colors } from '../graph/colors.svelte';
|
import { colors } from '../graph/colors.svelte';
|
||||||
|
|
||||||
const circleMaterial = new MeshBasicMaterial({
|
const circleMaterial = new MeshBasicMaterial({
|
||||||
color: colors.connection.clone(),
|
color: colors.edge.clone(),
|
||||||
toneMapped: false
|
toneMapped: false
|
||||||
});
|
});
|
||||||
|
|
||||||
let lineColor = $state(colors.connection.clone().convertSRGBToLinear());
|
let lineColor = $state(colors.edge.clone().convertSRGBToLinear());
|
||||||
|
|
||||||
$effect.root(() => {
|
$effect.root(() => {
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (appSettings.value.theme === undefined) {
|
if (appSettings.value.theme === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
circleMaterial.color = colors.connection.clone().convertSRGBToLinear();
|
circleMaterial.color = colors.edge.clone().convertSRGBToLinear();
|
||||||
lineColor = colors.connection.clone().convertSRGBToLinear();
|
lineColor = colors.edge.clone().convertSRGBToLinear();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -186,21 +186,15 @@ export class GraphState {
|
|||||||
if (!node?.inputs) {
|
if (!node?.inputs) {
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
let height = 5;
|
const height = 5
|
||||||
|
+ 10
|
||||||
for (const key of Object.keys(node.inputs)) {
|
* Object.keys(node.inputs).filter(
|
||||||
if (key === 'seed') continue;
|
(p) =>
|
||||||
if (!node.inputs) continue;
|
p !== 'seed'
|
||||||
if (node?.inputs?.[key] === undefined) continue;
|
&& node?.inputs
|
||||||
if ('setting' in node.inputs[key]) continue;
|
&& !(node?.inputs?.[p] !== undefined && 'setting' in node.inputs[p])
|
||||||
if (node.inputs[key].hidden) continue;
|
&& node.inputs[p].hidden !== true
|
||||||
if (node.inputs[key].type === 'shape') {
|
).length;
|
||||||
height += 20;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
height += 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.nodeHeightCache[nodeTypeId] = height;
|
this.nodeHeightCache[nodeTypeId] = height;
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const variables = [
|
|||||||
'outline',
|
'outline',
|
||||||
'active',
|
'active',
|
||||||
'selected',
|
'selected',
|
||||||
'connection'
|
'edge'
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
function getColor(variable: (typeof variables)[number]) {
|
function getColor(variable: (typeof variables)[number]) {
|
||||||
|
|||||||
@@ -166,14 +166,15 @@ export class MouseEventManager {
|
|||||||
|
|
||||||
if (this.state.mouseDown) return;
|
if (this.state.mouseDown) return;
|
||||||
this.state.edgeEndPosition = null;
|
this.state.edgeEndPosition = null;
|
||||||
const target = event.target as HTMLElement;
|
|
||||||
|
|
||||||
if (
|
if (event.target instanceof HTMLElement) {
|
||||||
target.nodeName !== 'CANVAS'
|
if (
|
||||||
&& !target.classList.contains('node')
|
event.target.nodeName !== 'CANVAS'
|
||||||
&& !target.classList.contains('content')
|
&& !event.target.classList.contains('node')
|
||||||
) {
|
&& !event.target.classList.contains('content')
|
||||||
return;
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mx = event.clientX - this.state.rect.x;
|
const mx = event.clientX - this.state.rect.x;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
const inputType = $derived(node?.state?.type?.inputs?.[id]);
|
const inputType = $derived(node?.state?.type?.inputs?.[id]);
|
||||||
|
|
||||||
const socketId = $derived(`${node.id}-${id}`);
|
const socketId = $derived(`${node.id}-${id}`);
|
||||||
const height = $derived(input.type === 'shape' ? 200 : 100);
|
|
||||||
|
|
||||||
const graphState = getGraphState();
|
const graphState = getGraphState();
|
||||||
const graphId = graph?.id;
|
const graphId = graph?.id;
|
||||||
@@ -65,7 +64,6 @@
|
|||||||
class="wrapper"
|
class="wrapper"
|
||||||
data-node-type={node.type}
|
data-node-type={node.type}
|
||||||
data-node-input={id}
|
data-node-input={id}
|
||||||
style:height="{height}px"
|
|
||||||
class:possible-socket={graphState?.possibleSocketIds.has(socketId)}
|
class:possible-socket={graphState?.possibleSocketIds.has(socketId)}
|
||||||
>
|
>
|
||||||
{#key id && graphId}
|
{#key id && graphId}
|
||||||
@@ -97,6 +95,8 @@
|
|||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 100 100"
|
viewBox="0 0 100 100"
|
||||||
|
width="100"
|
||||||
|
height="100"
|
||||||
preserveAspectRatio="none"
|
preserveAspectRatio="none"
|
||||||
style={`
|
style={`
|
||||||
--path: path("${path}");
|
--path: path("${path}");
|
||||||
@@ -111,6 +111,7 @@
|
|||||||
.wrapper {
|
.wrapper {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
transform: translateY(-0.5px);
|
transform: translateY(-0.5px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
svg {
|
svg {
|
||||||
height: 126px;
|
height: 124px;
|
||||||
margin: 24px 0px;
|
margin: 24px 0px;
|
||||||
border-top: solid thin var(--color-outline);
|
border-top: solid thin var(--color-outline);
|
||||||
border-bottom: solid thin var(--color-outline);
|
border-bottom: solid thin var(--color-outline);
|
||||||
|
|||||||
@@ -211,7 +211,7 @@
|
|||||||
.first-level.input {
|
.first-level.input {
|
||||||
padding-left: 1em;
|
padding-left: 1em;
|
||||||
padding-right: 1em;
|
padding-right: 1em;
|
||||||
padding-bottom: 0.5px;
|
padding-bottom: 1px;
|
||||||
gap: 3px;
|
gap: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,25 @@
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
function detectCommitType(commit: string) {
|
function detectCommitType(commit: string) {
|
||||||
for (const key of typeMap.keys()) {
|
if (commit.startsWith('fix:') || commit.startsWith('fix(')) {
|
||||||
if (commit.startsWith(key)) {
|
return 'fix';
|
||||||
return key;
|
}
|
||||||
}
|
|
||||||
|
if (commit.startsWith('feat:') || commit.startsWith('feat(')) {
|
||||||
|
return 'feat';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commit.startsWith('chore:') || commit.startsWith('chore(')) {
|
||||||
|
return 'chore';
|
||||||
|
}
|
||||||
|
if (commit.startsWith('docs:') || commit.startsWith('docs(')) {
|
||||||
|
return 'docs';
|
||||||
|
}
|
||||||
|
if (commit.startsWith('refactor:') || commit.startsWith('refactor(')) {
|
||||||
|
return 'refactor';
|
||||||
|
}
|
||||||
|
if (commit.startsWith('ci:') || commit.startsWith('ci(')) {
|
||||||
|
return 'ci';
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@@ -37,7 +52,7 @@
|
|||||||
|
|
||||||
const match = line.match(regex);
|
const match = line.match(regex);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [, sha, link, description] = match;
|
const [, sha, link, description] = match;
|
||||||
|
|||||||
6
nodes/max/plantarium/shape/.gitignore
vendored
6
nodes/max/plantarium/shape/.gitignore
vendored
@@ -1,6 +0,0 @@
|
|||||||
/target
|
|
||||||
**/*.rs.bk
|
|
||||||
Cargo.lock
|
|
||||||
bin/
|
|
||||||
pkg/
|
|
||||||
wasm-pack.log
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "shape"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Max Richter <jim-x@web.de>"]
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
crate-type = ["cdylib", "rlib"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" }
|
|
||||||
nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" }
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "max/plantarium/shape",
|
|
||||||
"outputs": [
|
|
||||||
"shape"
|
|
||||||
],
|
|
||||||
"inputs": {
|
|
||||||
"shape": {
|
|
||||||
"type": "shape",
|
|
||||||
"internal": true,
|
|
||||||
"value": [
|
|
||||||
47.8,
|
|
||||||
100,
|
|
||||||
47.8,
|
|
||||||
82.8,
|
|
||||||
30.9,
|
|
||||||
69.1,
|
|
||||||
23.2,
|
|
||||||
40.7,
|
|
||||||
27.1,
|
|
||||||
14.5,
|
|
||||||
42.5,
|
|
||||||
0
|
|
||||||
],
|
|
||||||
"label": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
use nodarium_macros::nodarium_definition_file;
|
|
||||||
use nodarium_macros::nodarium_execute;
|
|
||||||
use nodarium_utils::{concat_args, log, split_args};
|
|
||||||
|
|
||||||
nodarium_definition_file!("src/input.json");
|
|
||||||
|
|
||||||
#[nodarium_execute]
|
|
||||||
pub fn execute(input: &[i32]) -> Vec<i32> {
|
|
||||||
let args = split_args(input);
|
|
||||||
log!("vec3 input: {:?}", input);
|
|
||||||
log!("vec3 args: {:?}", args);
|
|
||||||
concat_args(args)
|
|
||||||
}
|
|
||||||
@@ -26,6 +26,7 @@ const DefaultOptionsSchema = z.object({
|
|||||||
export const NodeInputFloatSchema = z.object({
|
export const NodeInputFloatSchema = z.object({
|
||||||
...DefaultOptionsSchema.shape,
|
...DefaultOptionsSchema.shape,
|
||||||
type: z.literal('float'),
|
type: z.literal('float'),
|
||||||
|
element: z.literal('slider').optional(),
|
||||||
value: z.number().optional(),
|
value: z.number().optional(),
|
||||||
min: z.number().optional(),
|
min: z.number().optional(),
|
||||||
max: z.number().optional(),
|
max: z.number().optional(),
|
||||||
@@ -35,17 +36,12 @@ export const NodeInputFloatSchema = z.object({
|
|||||||
export const NodeInputIntegerSchema = z.object({
|
export const NodeInputIntegerSchema = z.object({
|
||||||
...DefaultOptionsSchema.shape,
|
...DefaultOptionsSchema.shape,
|
||||||
type: z.literal('integer'),
|
type: z.literal('integer'),
|
||||||
|
element: z.literal('slider').optional(),
|
||||||
value: z.number().optional(),
|
value: z.number().optional(),
|
||||||
min: z.number().optional(),
|
min: z.number().optional(),
|
||||||
max: z.number().optional()
|
max: z.number().optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
export const NodeInputShapeSchema = z.object({
|
|
||||||
...DefaultOptionsSchema.shape,
|
|
||||||
type: z.literal('shape'),
|
|
||||||
value: z.array(z.number()).optional()
|
|
||||||
});
|
|
||||||
|
|
||||||
export const NodeInputBooleanSchema = z.object({
|
export const NodeInputBooleanSchema = z.object({
|
||||||
...DefaultOptionsSchema.shape,
|
...DefaultOptionsSchema.shape,
|
||||||
type: z.literal('boolean'),
|
type: z.literal('boolean'),
|
||||||
@@ -88,7 +84,6 @@ export const NodeInputSchema = z.union([
|
|||||||
NodeInputBooleanSchema,
|
NodeInputBooleanSchema,
|
||||||
NodeInputFloatSchema,
|
NodeInputFloatSchema,
|
||||||
NodeInputIntegerSchema,
|
NodeInputIntegerSchema,
|
||||||
NodeInputShapeSchema,
|
|
||||||
NodeInputSelectSchema,
|
NodeInputSelectSchema,
|
||||||
NodeInputSeedSchema,
|
NodeInputSeedSchema,
|
||||||
NodeInputVec3Schema,
|
NodeInputVec3Schema,
|
||||||
|
|||||||
@@ -103,15 +103,6 @@ pub struct NodeInputVec3 {
|
|||||||
pub value: Option<Vec<f64>>,
|
pub value: Option<Vec<f64>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct NodeInputShape {
|
|
||||||
#[serde(flatten)]
|
|
||||||
pub default_options: DefaultOptions,
|
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub value: Option<Vec<f64>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct NodeInputGeometry {
|
pub struct NodeInputGeometry {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
@@ -134,7 +125,6 @@ pub enum NodeInput {
|
|||||||
select(NodeInputSelect),
|
select(NodeInputSelect),
|
||||||
seed(NodeInputSeed),
|
seed(NodeInputSeed),
|
||||||
vec3(NodeInputVec3),
|
vec3(NodeInputVec3),
|
||||||
shape(NodeInputShape),
|
|
||||||
geometry(NodeInputGeometry),
|
geometry(NodeInputGeometry),
|
||||||
path(NodeInputPath),
|
path(NodeInputPath),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { NodeInput } from '@nodarium/types';
|
import type { NodeInput } from '@nodarium/types';
|
||||||
|
|
||||||
import { InputCheckbox, InputNumber, InputSelect, InputShape, InputVec3 } from './index';
|
import { InputCheckbox, InputNumber, InputSelect, InputVec3 } from './index';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
input: NodeInput;
|
input: NodeInput;
|
||||||
@@ -19,8 +19,6 @@
|
|||||||
max={input?.max}
|
max={input?.max}
|
||||||
step={input?.step}
|
step={input?.step}
|
||||||
/>
|
/>
|
||||||
{:else if input.type === 'shape'}
|
|
||||||
<InputShape bind:value={value as number[]} />
|
|
||||||
{:else if input.type === 'integer'}
|
{:else if input.type === 'integer'}
|
||||||
<InputNumber bind:value={value as number} min={input?.min} max={input?.max} step={1} />
|
<InputNumber bind:value={value as number} min={input?.min} max={input?.max} step={1} />
|
||||||
{:else if input.type === 'boolean'}
|
{:else if input.type === 'boolean'}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
@source inline("{hover:,}{bg-,outline-,text-,}selected");
|
@source inline("{hover:,}{bg-,outline-,text-,}selected");
|
||||||
@source inline("{hover:,}{bg-,outline-,text-,}outline{!,}");
|
@source inline("{hover:,}{bg-,outline-,text-,}outline{!,}");
|
||||||
@source inline("{hover:,}{bg-,outline-,text-,}connection");
|
@source inline("{hover:,}{bg-,outline-,text-,}connection");
|
||||||
|
@source inline("{hover:,}{bg-,outline-,text-,}edge");
|
||||||
@source inline("{hover:,}{bg-,outline-,text-,}text");
|
@source inline("{hover:,}{bg-,outline-,text-,}text");
|
||||||
|
|
||||||
/* fira-code-300 - latin */
|
/* fira-code-300 - latin */
|
||||||
@@ -71,12 +72,12 @@
|
|||||||
|
|
||||||
--color-outline: var(--neutral-400);
|
--color-outline: var(--neutral-400);
|
||||||
--color-connection: #333333;
|
--color-connection: #333333;
|
||||||
|
--color-edge: var(--connection, var(--color-outline));
|
||||||
|
|
||||||
--color-text: var(--neutral-200);
|
--color-text: var(--neutral-200);
|
||||||
}
|
}
|
||||||
|
|
||||||
html {
|
html {
|
||||||
--neutral-050: #f0f0f0;
|
|
||||||
--neutral-100: #e7e7e7;
|
--neutral-100: #e7e7e7;
|
||||||
--neutral-200: #cecece;
|
--neutral-200: #cecece;
|
||||||
--neutral-300: #7c7c7c;
|
--neutral-300: #7c7c7c;
|
||||||
@@ -88,13 +89,14 @@ html {
|
|||||||
--color-layer-0: var(--neutral-900);
|
--color-layer-0: var(--neutral-900);
|
||||||
--color-layer-1: var(--neutral-500);
|
--color-layer-1: var(--neutral-500);
|
||||||
--color-layer-2: var(--neutral-400);
|
--color-layer-2: var(--neutral-400);
|
||||||
--color-layer-3: var(--neutral-300);
|
--color-layer-3: var(--neutral-200);
|
||||||
|
|
||||||
--color-active: #ffffff;
|
--color-active: #ffffff;
|
||||||
--color-selected: #c65a19;
|
--color-selected: #c65a19;
|
||||||
|
|
||||||
--color-outline: #3e3e3e;
|
--color-outline: var(--neutral-400);
|
||||||
--color-connection: #333333;
|
--color-connection: #333333;
|
||||||
|
--color-edge: var(--connection, var(--color-outline));
|
||||||
|
|
||||||
--color-text-color: var(--neutral-200);
|
--color-text-color: var(--neutral-200);
|
||||||
}
|
}
|
||||||
@@ -108,10 +110,10 @@ body {
|
|||||||
html.theme-light {
|
html.theme-light {
|
||||||
--color-text: var(--neutral-800);
|
--color-text: var(--neutral-800);
|
||||||
--color-outline: var(--neutral-300);
|
--color-outline: var(--neutral-300);
|
||||||
--color-layer-0: var(--neutral-050);
|
--color-layer-0: var(--neutral-100);
|
||||||
--color-layer-1: var(--neutral-100);
|
--color-layer-1: var(--neutral-100);
|
||||||
--color-layer-2: var(--neutral-200);
|
--color-layer-2: var(--neutral-200);
|
||||||
--color-layer-3: var(--neutral-300);
|
--color-layer-3: var(--neutral-500);
|
||||||
--color-active: #000000;
|
--color-active: #000000;
|
||||||
--color-selected: #c65a19;
|
--color-selected: #c65a19;
|
||||||
--color-connection: #888;
|
--color-connection: #888;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ export { default as Input } from './Input.svelte';
|
|||||||
export { default as InputCheckbox } from './inputs/InputCheckbox.svelte';
|
export { default as InputCheckbox } from './inputs/InputCheckbox.svelte';
|
||||||
export { default as InputNumber } from './inputs/InputNumber.svelte';
|
export { default as InputNumber } from './inputs/InputNumber.svelte';
|
||||||
export { default as InputSelect } from './inputs/InputSelect.svelte';
|
export { default as InputSelect } from './inputs/InputSelect.svelte';
|
||||||
export { default as InputShape } from './inputs/InputShape.svelte';
|
|
||||||
export { default as InputVec3 } from './inputs/InputVec3.svelte';
|
export { default as InputVec3 } from './inputs/InputVec3.svelte';
|
||||||
|
|
||||||
export { default as Details } from './Details.svelte';
|
export { default as Details } from './Details.svelte';
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
{id}
|
{id}
|
||||||
/>
|
/>
|
||||||
<span
|
<span
|
||||||
class="absolute opacity-0 peer-checked:opacity-100 transition-opacity duration-50 flex w-full h-full items-center justify-center"
|
class="absolute opacity-0 peer-checked:opacity-100 transition-opacity duration-100 flex w-full h-full items-center justify-center"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
viewBox="0 0 19 14"
|
viewBox="0 0 19 14"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
select {
|
select {
|
||||||
font-family: var(--font-family);
|
font-family: var(--font-family);
|
||||||
outline: solid 1px var(--color-outline);
|
outline: solid 1px var(--color-outline);
|
||||||
padding: 0.5em 0.8em;
|
padding: 0.8em 1em;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,265 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
type Props = {
|
|
||||||
value: number[];
|
|
||||||
mirror?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
let { value: points = $bindable(), mirror = true }: Props = $props();
|
|
||||||
|
|
||||||
let mouseDown = $state<number[]>();
|
|
||||||
let draggingIndex = $state<number>();
|
|
||||||
let downCirclePosition = $state<number[]>();
|
|
||||||
let svgElement = $state<SVGElement>(null!);
|
|
||||||
let svgRect = $state<DOMRect>(null!);
|
|
||||||
let isMirroredEvent = $state(false);
|
|
||||||
|
|
||||||
const pathD = $derived(calculatePath(points, mirror));
|
|
||||||
const groupedPoints = $derived(group(points));
|
|
||||||
|
|
||||||
function group<T>(arr: T[], size = 2): T[][] {
|
|
||||||
const result = [];
|
|
||||||
for (let i = 0; i < arr.length; i += size) {
|
|
||||||
result.push(arr.slice(i, i + size));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
const dist = (a: [number, number], b: [number, number]) => Math.hypot(a[0] - b[0], a[1] - b[1]);
|
|
||||||
const clamp = (v: number, min: number, max: number) => Math.min(Math.max(v, min), max);
|
|
||||||
const round = (v: number) => Math.floor(v * 10) / 10;
|
|
||||||
const getPt = (i: number) => [points[i * 2], points[i * 2 + 1]] as [number, number];
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if (!points.length) {
|
|
||||||
points = [47.8, 100, 47.8, 82.8, 30.9, 69.1, 23.2, 40.7, 27.1, 14.5, 42.5, 0];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if (mirror) {
|
|
||||||
const _points: [number, number, number][] = [];
|
|
||||||
for (let i = 0; i < points.length / 2; i++) {
|
|
||||||
_points.push([...getPt(i), i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortedPoints = _points
|
|
||||||
.sort((a, b) => {
|
|
||||||
if (a[1] !== b[1]) return b[1] - a[1];
|
|
||||||
return a[0] - b[0];
|
|
||||||
});
|
|
||||||
|
|
||||||
const newIndices = new Map(sortedPoints.map((p, i) => [p[2], i]));
|
|
||||||
|
|
||||||
const sorted = sortedPoints
|
|
||||||
.map(p => [p[0], p[1]])
|
|
||||||
.flat();
|
|
||||||
|
|
||||||
let sortChanged = false;
|
|
||||||
|
|
||||||
for (let i = 0; i < sorted.length; i++) {
|
|
||||||
if (sorted[i] !== points[i]) {
|
|
||||||
sortChanged = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sortChanged) {
|
|
||||||
points = sorted;
|
|
||||||
draggingIndex = newIndices.get(draggingIndex || 0) || 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function insertBetween(newPt: [number, number]): number {
|
|
||||||
const count = points.length / 2;
|
|
||||||
|
|
||||||
if (count < 2) {
|
|
||||||
points = [...points, ...newPt];
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
let minDist = Infinity;
|
|
||||||
let insertIdx = 0;
|
|
||||||
|
|
||||||
for (let i = 0; i < count - 1; i++) {
|
|
||||||
const a = getPt(i);
|
|
||||||
const b = getPt(i + 1);
|
|
||||||
const d = dist(newPt, a) + dist(newPt, b) - dist(a, b);
|
|
||||||
if (d < minDist) {
|
|
||||||
minDist = d;
|
|
||||||
insertIdx = i + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
points.splice(insertIdx * 2, 0, newPt[0], newPt[1]);
|
|
||||||
return insertIdx;
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculatePath(pts: number[], mirror = false): string {
|
|
||||||
if (pts.length === 0) return '';
|
|
||||||
|
|
||||||
const arr = [...pts];
|
|
||||||
|
|
||||||
let d = `M ${arr[0]} ${arr[1]}`;
|
|
||||||
for (let i = 2; i < arr.length; i += 2) {
|
|
||||||
d += ` L ${arr[i]} ${arr[i + 1]}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mirror) {
|
|
||||||
for (let i = arr.length - 2; i >= 0; i -= 2) {
|
|
||||||
const x = 100 - arr[i];
|
|
||||||
d += ` L ${x} ${arr[i + 1]}`;
|
|
||||||
}
|
|
||||||
d += ' Z';
|
|
||||||
}
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleMouseMove(ev: MouseEvent) {
|
|
||||||
if (mouseDown === undefined || draggingIndex === undefined || !downCirclePosition) return;
|
|
||||||
|
|
||||||
let vx = (mouseDown[0] - ev.clientX) * (100 / svgRect.width);
|
|
||||||
let vy = (mouseDown[1] - ev.clientY) * (100 / svgRect.height);
|
|
||||||
|
|
||||||
if (ev.shiftKey) {
|
|
||||||
vx /= 10;
|
|
||||||
vy /= 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
let x = downCirclePosition[0] + ((isMirroredEvent ? 1 : -1) * vx);
|
|
||||||
let y = downCirclePosition[1] - vy;
|
|
||||||
|
|
||||||
x = clamp(x, 0, mirror ? 50 : 100);
|
|
||||||
y = clamp(y, 0, 100);
|
|
||||||
|
|
||||||
points[draggingIndex * 2] = round(x);
|
|
||||||
points[draggingIndex * 2 + 1] = round(y);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleMouseDown(ev: MouseEvent) {
|
|
||||||
ev.preventDefault();
|
|
||||||
isMirroredEvent = false;
|
|
||||||
|
|
||||||
svgRect = svgElement.getBoundingClientRect();
|
|
||||||
mouseDown = [ev.clientX, ev.clientY];
|
|
||||||
|
|
||||||
const indexText = (ev.target as SVGCircleElement).dataset.index;
|
|
||||||
|
|
||||||
const x = ((ev.clientX - svgRect.left) / svgRect.width) * 100;
|
|
||||||
const y = ((ev.clientY - svgRect.top) / svgRect.height) * 100;
|
|
||||||
isMirroredEvent = x > 50;
|
|
||||||
|
|
||||||
if (indexText !== undefined) {
|
|
||||||
draggingIndex = parseInt(indexText);
|
|
||||||
downCirclePosition = getPt(draggingIndex);
|
|
||||||
} else {
|
|
||||||
draggingIndex = undefined;
|
|
||||||
|
|
||||||
const pt = [
|
|
||||||
round(clamp(x, 0, 100)),
|
|
||||||
round(clamp(y, 0, 100))
|
|
||||||
] as [
|
|
||||||
number,
|
|
||||||
number
|
|
||||||
];
|
|
||||||
if (isMirroredEvent) {
|
|
||||||
pt[0] = 100 - pt[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
draggingIndex = insertBetween(pt);
|
|
||||||
downCirclePosition = pt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleMouseUp() {
|
|
||||||
mouseDown = undefined;
|
|
||||||
draggingIndex = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleContextMenu(ev: MouseEvent) {
|
|
||||||
const indexText = (ev.target as HTMLElement).dataset?.index;
|
|
||||||
if (indexText !== undefined) {
|
|
||||||
ev.preventDefault();
|
|
||||||
ev.stopImmediatePropagation();
|
|
||||||
const index = parseInt(indexText);
|
|
||||||
draggingIndex = undefined;
|
|
||||||
points.splice(index * 2, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:window
|
|
||||||
onmousemove={handleMouseMove}
|
|
||||||
onmouseup={handleMouseUp}
|
|
||||||
oncontextmenu={handleContextMenu}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div class="wrapper" class:mirrored={mirror}>
|
|
||||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
||||||
<svg
|
|
||||||
width="100"
|
|
||||||
height="100"
|
|
||||||
viewBox="0 0 100 100"
|
|
||||||
bind:this={svgElement}
|
|
||||||
aria-label="Interactive 2D Shape Editor"
|
|
||||||
onmousedown={handleMouseDown}
|
|
||||||
>
|
|
||||||
<path d={pathD} style:fill="var(--color-layer-3)" style:opacity={0.3} />
|
|
||||||
<path d={pathD} fill="none" stroke="var(--color-layer-3)" />
|
|
||||||
{#if mirror}
|
|
||||||
{#each groupedPoints as p, i (i)}
|
|
||||||
{@const x = 100 - p[0]}
|
|
||||||
{@const y = p[1]}
|
|
||||||
<circle
|
|
||||||
class:active={isMirroredEvent && draggingIndex === i}
|
|
||||||
data-index={i}
|
|
||||||
cx={x}
|
|
||||||
cy={y}
|
|
||||||
r={3}
|
|
||||||
>
|
|
||||||
</circle>
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#each groupedPoints as p, i (i)}
|
|
||||||
<circle
|
|
||||||
class:active={!isMirroredEvent && draggingIndex === i}
|
|
||||||
data-index={i}
|
|
||||||
cx={p[0]}
|
|
||||||
cy={p[1]}
|
|
||||||
r={3}
|
|
||||||
>
|
|
||||||
</circle>
|
|
||||||
{/each}
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.wrapper {
|
|
||||||
width: 100%;
|
|
||||||
aspect-ratio: 1;
|
|
||||||
background-color: var(--color-layer-2);
|
|
||||||
padding: 7px;
|
|
||||||
border-radius: 5px;
|
|
||||||
outline: solid thin var(--color-outline);
|
|
||||||
}
|
|
||||||
|
|
||||||
svg {
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
overflow: visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
circle {
|
|
||||||
cursor: pointer;
|
|
||||||
stroke: transparent;
|
|
||||||
transition: fill 0.2s ease;
|
|
||||||
stroke-width: 1px;
|
|
||||||
stroke: var(--color-layer-3);
|
|
||||||
fill: var(--color-layer-2);
|
|
||||||
}
|
|
||||||
circle.active,
|
|
||||||
circle:hover {
|
|
||||||
fill: var(--color-layer-3);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,14 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$lib/app.css';
|
import '$lib/app.css';
|
||||||
import {
|
import { Details, InputCheckbox, InputNumber, InputSelect, InputVec3, ShortCut } from '$lib';
|
||||||
Details,
|
|
||||||
InputCheckbox,
|
|
||||||
InputNumber,
|
|
||||||
InputSelect,
|
|
||||||
InputShape,
|
|
||||||
InputVec3,
|
|
||||||
ShortCut
|
|
||||||
} from '$lib';
|
|
||||||
import Section from './Section.svelte';
|
import Section from './Section.svelte';
|
||||||
|
|
||||||
let intValue = $state(0);
|
let intValue = $state(0);
|
||||||
@@ -18,11 +10,9 @@
|
|||||||
const options = ['strawberry', 'raspberry', 'chickpeas'];
|
const options = ['strawberry', 'raspberry', 'chickpeas'];
|
||||||
let selectValue = $state(0);
|
let selectValue = $state(0);
|
||||||
const d = $derived(options[selectValue]);
|
const d = $derived(options[selectValue]);
|
||||||
let checked = $state(false);
|
|
||||||
let mirrorShape = $state(true);
|
|
||||||
let detailsOpen = $state(false);
|
|
||||||
|
|
||||||
let points = $state([]);
|
let checked = $state(false);
|
||||||
|
let detailsOpen = $state(false);
|
||||||
|
|
||||||
const themes = [
|
const themes = [
|
||||||
'dark',
|
'dark',
|
||||||
@@ -51,6 +41,7 @@
|
|||||||
'selected',
|
'selected',
|
||||||
'outline',
|
'outline',
|
||||||
'connection',
|
'connection',
|
||||||
|
'edge',
|
||||||
'text'
|
'text'
|
||||||
];
|
];
|
||||||
</script>
|
</script>
|
||||||
@@ -99,19 +90,6 @@
|
|||||||
<InputCheckbox bind:value={checked} />
|
<InputCheckbox bind:value={checked} />
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
<Section title="Shape">
|
|
||||||
{#snippet header()}
|
|
||||||
<label class="flex gap-2">
|
|
||||||
<InputCheckbox bind:value={mirrorShape} />
|
|
||||||
<p>mirror</p>
|
|
||||||
</label>
|
|
||||||
<p>{JSON.stringify(points)}</p>
|
|
||||||
{/snippet}
|
|
||||||
<div style:width="300px">
|
|
||||||
<InputShape bind:value={points} mirror={mirrorShape} />
|
|
||||||
</div>
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
<Section title="Details" value={detailsOpen}>
|
<Section title="Details" value={detailsOpen}>
|
||||||
<Details title="More Information" bind:open={detailsOpen}>
|
<Details title="More Information" bind:open={detailsOpen}>
|
||||||
<p>Here is some more information that was previously hidden.</p>
|
<p>Here is some more information that was previously hidden.</p>
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { type Snippet } from 'svelte';
|
import { type Snippet } from 'svelte';
|
||||||
let { title, value, header, children, class: _class } = $props<{
|
let { title, value, children, class: _class } = $props<{
|
||||||
title?: string;
|
title?: string;
|
||||||
value?: unknown;
|
value?: unknown;
|
||||||
header?: Snippet;
|
|
||||||
children?: Snippet;
|
children?: Snippet;
|
||||||
class?: string;
|
class?: string;
|
||||||
}>();
|
}>();
|
||||||
@@ -12,13 +11,7 @@
|
|||||||
<section class="border-outline border-1/2 bg-layer-1 rounded border mb-4 p-4 flex flex-col gap-4 {_class}">
|
<section class="border-outline border-1/2 bg-layer-1 rounded border mb-4 p-4 flex flex-col gap-4 {_class}">
|
||||||
<h3 class="flex gap-2 font-bold">
|
<h3 class="flex gap-2 font-bold">
|
||||||
{title}
|
{title}
|
||||||
<div class="flex gap-4 w-full font-normal opacity-50 max-w-[75%] whitespace-pre overflow-hidden text-clip">
|
<p class="font-normal! opacity-50!">{value}</p>
|
||||||
{#if header}
|
|
||||||
{@render header()}
|
|
||||||
{:else}
|
|
||||||
{value}
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</h3>
|
</h3>
|
||||||
<div>
|
<div>
|
||||||
{@render children()}
|
{@render children()}
|
||||||
|
|||||||
Reference in New Issue
Block a user