shaders 2.0.645 → 2.0.646

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.
Files changed (32) hide show
  1. package/dist/react/index.cjs +43 -43
  2. package/dist/react/index.cjs.map +1 -1
  3. package/dist/react/index.js +12262 -11719
  4. package/dist/react/index.js.map +1 -1
  5. package/dist/svelte/components/Checkerboard.svelte +202 -0
  6. package/dist/svelte/components/Checkerboard.svelte.d.ts +39 -0
  7. package/dist/svelte/components/Grid.svelte +202 -0
  8. package/dist/svelte/components/Grid.svelte.d.ts +39 -0
  9. package/dist/svelte/components/ImageTexture.svelte +202 -0
  10. package/dist/svelte/components/ImageTexture.svelte.d.ts +39 -0
  11. package/dist/svelte/components/Pixelate.svelte +202 -0
  12. package/dist/svelte/components/Pixelate.svelte.d.ts +39 -0
  13. package/dist/svelte/components/RadialGradient.svelte +202 -0
  14. package/dist/svelte/components/RadialGradient.svelte.d.ts +39 -0
  15. package/dist/svelte/index.d.ts +5 -0
  16. package/dist/svelte/index.js +5 -0
  17. package/dist/svelte/utils/generatePresetCode.js +5 -0
  18. package/dist/vue/components/Checkerboard.vue.d.ts +48 -0
  19. package/dist/vue/components/Checkerboard.vue.d.ts.map +1 -0
  20. package/dist/vue/components/Grid.vue.d.ts +48 -0
  21. package/dist/vue/components/Grid.vue.d.ts.map +1 -0
  22. package/dist/vue/components/ImageTexture.vue.d.ts +48 -0
  23. package/dist/vue/components/ImageTexture.vue.d.ts.map +1 -0
  24. package/dist/vue/components/Pixelate.vue.d.ts +48 -0
  25. package/dist/vue/components/Pixelate.vue.d.ts.map +1 -0
  26. package/dist/vue/components/RadialGradient.vue.d.ts +48 -0
  27. package/dist/vue/components/RadialGradient.vue.d.ts.map +1 -0
  28. package/dist/vue/index.d.ts +5 -0
  29. package/dist/vue/index.d.ts.map +1 -1
  30. package/dist/vue/index.js +38 -38
  31. package/dist/vue/utils/generatePresetCode.d.ts.map +1 -1
  32. package/package.json +1 -1
@@ -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/checkerboard';
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/checkerboard';
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 Checkerboard: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<ExtendedComponentProps, {
32
+ default: {};
33
+ }>, {
34
+ [evt: string]: CustomEvent<any>;
35
+ }, {
36
+ default: {};
37
+ }, {}, "">;
38
+ type Checkerboard = InstanceType<typeof Checkerboard>;
39
+ export default Checkerboard;
@@ -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/grid';
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/grid';
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 Grid: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<ExtendedComponentProps, {
32
+ default: {};
33
+ }>, {
34
+ [evt: string]: CustomEvent<any>;
35
+ }, {
36
+ default: {};
37
+ }, {}, "">;
38
+ type Grid = InstanceType<typeof Grid>;
39
+ export default Grid;
@@ -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/imageTexture';
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>