shaders 2.0.646 → 2.0.647
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/dist/react/components/Checkerboard.d.ts +22 -0
- package/dist/react/components/Checkerboard.d.ts.map +1 -0
- package/dist/react/components/Grid.d.ts +22 -0
- package/dist/react/components/Grid.d.ts.map +1 -0
- package/dist/react/components/ImageTexture.d.ts +22 -0
- package/dist/react/components/ImageTexture.d.ts.map +1 -0
- package/dist/react/components/Pixelate.d.ts +22 -0
- package/dist/react/components/Pixelate.d.ts.map +1 -0
- package/dist/react/components/RadialGradient.d.ts +22 -0
- package/dist/react/components/RadialGradient.d.ts.map +1 -0
- package/dist/react/index.cjs +22 -22
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +4813 -4706
- package/dist/react/index.js.map +1 -1
- package/dist/react/utils/generatePresetCode.d.ts.map +1 -1
- package/dist/svelte/components/Spiral.svelte +202 -0
- package/dist/svelte/components/Spiral.svelte.d.ts +39 -0
- package/dist/svelte/index.d.ts +1 -0
- package/dist/svelte/index.js +1 -0
- package/dist/svelte/utils/generatePresetCode.js +1 -0
- package/dist/vue/index.js +38 -38
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generatePresetCode.d.ts","sourceRoot":"","sources":["../../src/utils/generatePresetCode.ts"],"names":[],"mappings":"AAAA,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAA;CAC7B;AAED,UAAU,YAAY;IACpB,UAAU,EAAE,eAAe,EAAE,CAAA;CAC9B;AAgBD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CA8B/D;AAGD,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"generatePresetCode.d.ts","sourceRoot":"","sources":["../../src/utils/generatePresetCode.ts"],"names":[],"mappings":"AAAA,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAA;CAC7B;AAED,UAAU,YAAY;IACpB,UAAU,EAAE,eAAe,EAAE,CAAA;CAC9B;AAgBD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CA8B/D;AAGD,eAAO,MAAM,mBAAmB,UAwB/B,CAAA"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, setContext, onMount, onDestroy } from 'svelte';
|
|
3
|
+
import {
|
|
4
|
+
createUniformsMap,
|
|
5
|
+
type UniformsMap,
|
|
6
|
+
type BlendMode,
|
|
7
|
+
type NodeMetadata,
|
|
8
|
+
type PropConfig,
|
|
9
|
+
type MaskConfig
|
|
10
|
+
} from 'shaders-core';
|
|
11
|
+
|
|
12
|
+
// @ts-ignore - this import is replaced at build time
|
|
13
|
+
import { componentDefinition, type ComponentProps } from 'shaders-core/spiral';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Define component props including blend mode, opacity, and masking
|
|
17
|
+
*/
|
|
18
|
+
interface ExtendedComponentProps extends Partial<ComponentProps> {
|
|
19
|
+
blendMode?: BlendMode;
|
|
20
|
+
opacity?: number;
|
|
21
|
+
id?: string;
|
|
22
|
+
maskSource?: string;
|
|
23
|
+
maskType?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Define the component props and their default values from the shader definition
|
|
27
|
+
const componentDefaults = {
|
|
28
|
+
blendMode: 'normal' as BlendMode,
|
|
29
|
+
// opacity intentionally has no default - handled by renderer
|
|
30
|
+
...Object.entries(componentDefinition.props).reduce(
|
|
31
|
+
(acc, [key, config]) => {
|
|
32
|
+
acc[key] = (config as unknown as PropConfig<typeof config>).default;
|
|
33
|
+
return acc;
|
|
34
|
+
},
|
|
35
|
+
{} as Record<string, any>
|
|
36
|
+
)
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Declare props using Svelte 5's syntax with defaults
|
|
40
|
+
const props = $props<ExtendedComponentProps>();
|
|
41
|
+
|
|
42
|
+
// Apply defaults manually since Svelte 5 doesn't have withDefaults equivalent
|
|
43
|
+
const blendMode = props.blendMode ?? componentDefaults.blendMode;
|
|
44
|
+
const opacity = props.opacity; // No default - handled by renderer
|
|
45
|
+
const id = props.id;
|
|
46
|
+
const maskSource = props.maskSource;
|
|
47
|
+
const maskType = props.maskType;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* FIRST: Get the parent ID from context BEFORE setting our own context
|
|
51
|
+
*/
|
|
52
|
+
const parentId = getContext<string>('ombreParentId');
|
|
53
|
+
if (parentId === undefined) {
|
|
54
|
+
throw new Error('Shader components must be used inside an <Shader> component or another shader component');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Use the provided ID or generate a unique identifier for this component instance
|
|
59
|
+
*/
|
|
60
|
+
const instanceId = id || `${componentDefinition.name.toLowerCase()}_${Math.random().toString(36).substring(7)}`;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* THEN: Provide our unique identifier to child components
|
|
64
|
+
*/
|
|
65
|
+
setContext('ombreParentId', instanceId);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Creates a non-reactive object containing only props that differ from defaults
|
|
69
|
+
* This optimization prevents unnecessary GPU uniform updates for unchanged values
|
|
70
|
+
* Special props like blendMode and opacity are handled separately
|
|
71
|
+
*/
|
|
72
|
+
const shaderReadyProps = $derived.by(() => {
|
|
73
|
+
let baseProps = { ...componentDefaults };
|
|
74
|
+
|
|
75
|
+
// Only include props that differ from defaults (excluding special props)
|
|
76
|
+
for (const key in props) {
|
|
77
|
+
if (key !== 'blendMode' && key !== 'opacity' && key !== 'id' && key !== 'maskSource' && key !== 'maskType') {
|
|
78
|
+
const propValue = (props as any)[key];
|
|
79
|
+
const defaultValue = (componentDefaults as any)[key];
|
|
80
|
+
if (propValue !== undefined && propValue !== defaultValue) {
|
|
81
|
+
(baseProps as any)[key] = propValue;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return baseProps;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Creates the GPU uniform values map using only the changed props
|
|
90
|
+
*/
|
|
91
|
+
const uniforms: UniformsMap = createUniformsMap(componentDefinition, shaderReadyProps, instanceId);
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the node registration function from parent context
|
|
95
|
+
*/
|
|
96
|
+
const parentRegister = getContext<(id: string, fragmentNodeFunc: any, parentId: string | null, metadata: NodeMetadata | null, uniforms: UniformsMap | null) => void>('ombreNodeRegister');
|
|
97
|
+
if (parentRegister === undefined) {
|
|
98
|
+
throw new Error('Shader components must be used inside an <Shader> component or another shader component');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Get the uniform update function from parent context
|
|
103
|
+
*/
|
|
104
|
+
const parentUniformUpdate = getContext<(nodeId: string, uniformName: string, value: any) => void>('ombreUniformUpdate');
|
|
105
|
+
if (parentUniformUpdate === undefined) {
|
|
106
|
+
throw new Error('Shader components require ombreUniformUpdate from parent');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get the metadata update function from parent context
|
|
111
|
+
*/
|
|
112
|
+
const parentMetadataUpdate = getContext<(nodeId: string, metadata: NodeMetadata) => void>('ombreMetadataUpdate');
|
|
113
|
+
if (parentMetadataUpdate === undefined) {
|
|
114
|
+
throw new Error('Shader components require ombreMetadataUpdate from parent');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Flag to track when component is registered
|
|
118
|
+
let isRegistered = $state(false);
|
|
119
|
+
|
|
120
|
+
// Setup uniform watchers with registration guard
|
|
121
|
+
Object.entries(uniforms).forEach(([propName, { uniform, transform }]) => {
|
|
122
|
+
$effect(() => {
|
|
123
|
+
// Only run after component is registered
|
|
124
|
+
if (!isRegistered) return;
|
|
125
|
+
|
|
126
|
+
if (uniform && uniform.value !== undefined) {
|
|
127
|
+
const newValue = (props as any)[propName];
|
|
128
|
+
if (newValue !== undefined) {
|
|
129
|
+
const transformedValue = transform ? transform(newValue) : newValue;
|
|
130
|
+
parentUniformUpdate(instanceId, propName, transformedValue);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Watch blend mode, opacity, and masking changes
|
|
137
|
+
$effect(() => {
|
|
138
|
+
// Only run after component is registered
|
|
139
|
+
if (!isRegistered) return;
|
|
140
|
+
|
|
141
|
+
const metadata: NodeMetadata = {
|
|
142
|
+
blendMode,
|
|
143
|
+
opacity,
|
|
144
|
+
id,
|
|
145
|
+
mask: maskSource ? {
|
|
146
|
+
source: maskSource,
|
|
147
|
+
type: maskType || 'alpha'
|
|
148
|
+
} : undefined,
|
|
149
|
+
renderOrder: 0
|
|
150
|
+
};
|
|
151
|
+
parentMetadataUpdate(instanceId, metadata);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Register this component after mount to ensure parent is ready
|
|
155
|
+
onMount(() => {
|
|
156
|
+
// Debug and safety check before registration
|
|
157
|
+
console.log('componentDefinition:', componentDefinition);
|
|
158
|
+
console.log('fragmentNode type:', typeof componentDefinition?.fragmentNode);
|
|
159
|
+
console.log('fragmentNode:', componentDefinition?.fragmentNode);
|
|
160
|
+
|
|
161
|
+
// Register this component with safety check
|
|
162
|
+
if (componentDefinition && typeof componentDefinition.fragmentNode === 'function') {
|
|
163
|
+
console.log(`Registering ${componentDefinition.name} with ID: ${instanceId}, parent: ${parentId}`);
|
|
164
|
+
|
|
165
|
+
parentRegister(
|
|
166
|
+
instanceId,
|
|
167
|
+
componentDefinition.fragmentNode,
|
|
168
|
+
parentId,
|
|
169
|
+
{
|
|
170
|
+
blendMode,
|
|
171
|
+
opacity,
|
|
172
|
+
id,
|
|
173
|
+
mask: maskSource ? {
|
|
174
|
+
source: maskSource,
|
|
175
|
+
type: maskType || 'alpha'
|
|
176
|
+
} as MaskConfig : undefined,
|
|
177
|
+
renderOrder: 0
|
|
178
|
+
},
|
|
179
|
+
uniforms
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
console.log(`${componentDefinition.name} registered successfully`);
|
|
183
|
+
|
|
184
|
+
// Set flag to enable effects after successful registration
|
|
185
|
+
isRegistered = true;
|
|
186
|
+
} else {
|
|
187
|
+
console.error('componentDefinition.fragmentNode is not a function:', {
|
|
188
|
+
componentDefinition,
|
|
189
|
+
fragmentNode: componentDefinition?.fragmentNode,
|
|
190
|
+
type: typeof componentDefinition?.fragmentNode
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Clean up node from registry when component is unmounted
|
|
196
|
+
onDestroy(() => {
|
|
197
|
+
isRegistered = false;
|
|
198
|
+
parentRegister(instanceId, null, null, null, null);
|
|
199
|
+
});
|
|
200
|
+
</script>
|
|
201
|
+
|
|
202
|
+
<slot></slot>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type BlendMode } from 'shaders-core';
|
|
2
|
+
import { type ComponentProps } from 'shaders-core/spiral';
|
|
3
|
+
/**
|
|
4
|
+
* Define component props including blend mode, opacity, and masking
|
|
5
|
+
*/
|
|
6
|
+
interface ExtendedComponentProps extends Partial<ComponentProps> {
|
|
7
|
+
blendMode?: BlendMode;
|
|
8
|
+
opacity?: number;
|
|
9
|
+
id?: string;
|
|
10
|
+
maskSource?: string;
|
|
11
|
+
maskType?: string;
|
|
12
|
+
}
|
|
13
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
14
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
15
|
+
$$bindings?: Bindings;
|
|
16
|
+
} & Exports;
|
|
17
|
+
(internal: unknown, props: Props & {
|
|
18
|
+
$$events?: Events;
|
|
19
|
+
$$slots?: Slots;
|
|
20
|
+
}): Exports & {
|
|
21
|
+
$set?: any;
|
|
22
|
+
$on?: any;
|
|
23
|
+
};
|
|
24
|
+
z_$$bindings?: Bindings;
|
|
25
|
+
}
|
|
26
|
+
type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
|
|
27
|
+
default: any;
|
|
28
|
+
} ? Props extends Record<string, never> ? any : {
|
|
29
|
+
children?: any;
|
|
30
|
+
} : {});
|
|
31
|
+
declare const Spiral: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<ExtendedComponentProps, {
|
|
32
|
+
default: {};
|
|
33
|
+
}>, {
|
|
34
|
+
[evt: string]: CustomEvent<any>;
|
|
35
|
+
}, {
|
|
36
|
+
default: {};
|
|
37
|
+
}, {}, "">;
|
|
38
|
+
type Spiral = InstanceType<typeof Spiral>;
|
|
39
|
+
export default Spiral;
|
package/dist/svelte/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { default as RadialGradient } from './components/RadialGradient.svelte';
|
|
|
18
18
|
export { default as Ripple } from './components/Ripple.svelte';
|
|
19
19
|
export { default as Saturation } from './components/Saturation.svelte';
|
|
20
20
|
export { default as SolidColor } from './components/SolidColor.svelte';
|
|
21
|
+
export { default as Spiral } from './components/Spiral.svelte';
|
|
21
22
|
export { default as Swirl } from './components/Swirl.svelte';
|
|
22
23
|
export { default as Twirl } from './components/Twirl.svelte';
|
|
23
24
|
export { default as Vibrance } from './components/Vibrance.svelte';
|
package/dist/svelte/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { default as RadialGradient } from './components/RadialGradient.svelte';
|
|
|
18
18
|
export { default as Ripple } from './components/Ripple.svelte';
|
|
19
19
|
export { default as Saturation } from './components/Saturation.svelte';
|
|
20
20
|
export { default as SolidColor } from './components/SolidColor.svelte';
|
|
21
|
+
export { default as Spiral } from './components/Spiral.svelte';
|
|
21
22
|
export { default as Swirl } from './components/Swirl.svelte';
|
|
22
23
|
export { default as Twirl } from './components/Twirl.svelte';
|
|
23
24
|
export { default as Vibrance } from './components/Vibrance.svelte';
|