Home / Function/ create_custom_element() — svelte Function Reference

create_custom_element() — svelte Function Reference

Architecture documentation for the create_custom_element() function in custom-element.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  0ce0b17f_0fc7_b361_b518_73a5de3f2e7a["create_custom_element()"]
  1a45e32c_24fc_a764_ca2d_b81df9bec325["custom-element.js"]
  0ce0b17f_0fc7_b361_b518_73a5de3f2e7a -->|defined in| 1a45e32c_24fc_a764_ca2d_b81df9bec325
  b72b8566_6fe5_6e9f_7848_f28f37253eff["constructor()"]
  0ce0b17f_0fc7_b361_b518_73a5de3f2e7a -->|calls| b72b8566_6fe5_6e9f_7848_f28f37253eff
  9c8487e2_66b5_01cd_e264_1fb1a356011d["get_custom_element_value()"]
  0ce0b17f_0fc7_b361_b518_73a5de3f2e7a -->|calls| 9c8487e2_66b5_01cd_e264_1fb1a356011d
  305392aa_5654_443f_1b37_389a8aee5428["$set()"]
  0ce0b17f_0fc7_b361_b518_73a5de3f2e7a -->|calls| 305392aa_5654_443f_1b37_389a8aee5428
  style 0ce0b17f_0fc7_b361_b518_73a5de3f2e7a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/dom/elements/custom-element.js lines 288–343

export function create_custom_element(
	Component,
	props_definition,
	slots,
	exports,
	shadow_root_init,
	extend
) {
	let Class = class extends SvelteElement {
		constructor() {
			super(Component, slots, shadow_root_init);
			this.$$p_d = props_definition;
		}
		static get observedAttributes() {
			return object_keys(props_definition).map((key) =>
				(props_definition[key].attribute || key).toLowerCase()
			);
		}
	};
	object_keys(props_definition).forEach((prop) => {
		define_property(Class.prototype, prop, {
			get() {
				return this.$$c && prop in this.$$c ? this.$$c[prop] : this.$$d[prop];
			},
			set(value) {
				value = get_custom_element_value(prop, value, props_definition);
				this.$$d[prop] = value;
				var component = this.$$c;

				if (component) {
					// // If the instance has an accessor, use that instead
					var setter = get_descriptor(component, prop)?.get;

					if (setter) {
						component[prop] = value;
					} else {
						component.$set({ [prop]: value });
					}
				}
			}
		});
	});
	exports.forEach((property) => {
		define_property(Class.prototype, property, {
			get() {
				return this.$$c?.[property];
			}
		});
	});
	if (extend) {
		// @ts-expect-error - assigning here is fine
		Class = extend(Class);
	}
	Component.element = /** @type {any} */ Class;
	return Class;
}

Domain

Subdomains

Frequently Asked Questions

What does create_custom_element() do?
create_custom_element() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/elements/custom-element.js.
Where is create_custom_element() defined?
create_custom_element() is defined in packages/svelte/src/internal/client/dom/elements/custom-element.js at line 288.
What does create_custom_element() call?
create_custom_element() calls 3 function(s): $set, constructor, get_custom_element_value.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free