Home / File/ attributes.js — svelte Source File

attributes.js — svelte Source File

Architecture documentation for attributes.js, a javascript file in the svelte codebase. 3 imports, 4 dependents.

File javascript SharedInternal BitFlags 3 imports 4 dependents 6 functions

Entity Profile

Dependency Diagram

graph LR
  22eadd41_615a_90cd_7963_26c9a3fc58cb["attributes.js"]
  cb064307_faf7_de99_b8a6_9523086a7c01["escaping.js"]
  22eadd41_615a_90cd_7963_26c9a3fc58cb --> cb064307_faf7_de99_b8a6_9523086a7c01
  d6dfd043_7103_f2c7_aab3_9660fb0a5f75["escape_html"]
  22eadd41_615a_90cd_7963_26c9a3fc58cb --> d6dfd043_7103_f2c7_aab3_9660fb0a5f75
  cf775a44_a27f_113d_604d_e7e0754bad98["clsx"]
  22eadd41_615a_90cd_7963_26c9a3fc58cb --> cf775a44_a27f_113d_604d_e7e0754bad98
  0acd2537_e1bf_d7ae_30d5_407378cfa4d3["attributes.js"]
  0acd2537_e1bf_d7ae_30d5_407378cfa4d3 --> 22eadd41_615a_90cd_7963_26c9a3fc58cb
  686ca949_4d11_24e5_89bf_2c8c02e51cde["class.js"]
  686ca949_4d11_24e5_89bf_2c8c02e51cde --> 22eadd41_615a_90cd_7963_26c9a3fc58cb
  e6776a33_ae8b_fb40_7de7_0a08f609b2db["style.js"]
  e6776a33_ae8b_fb40_7de7_0a08f609b2db --> 22eadd41_615a_90cd_7963_26c9a3fc58cb
  1c4bc493_24af_177e_7307_a999997aceac["index.js"]
  1c4bc493_24af_177e_7307_a999997aceac --> 22eadd41_615a_90cd_7963_26c9a3fc58cb
  style 22eadd41_615a_90cd_7963_26c9a3fc58cb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { escape_html } from '../../escaping.js';
import { clsx as _clsx } from 'clsx';

/**
 * `<div translate={false}>` should be rendered as `<div translate="no">` and _not_
 * `<div translate="false">`, which is equivalent to `<div translate="yes">`. There
 * may be other odd cases that need to be added to this list in future
 * @type {Record<string, Map<any, string>>}
 */
const replacements = {
	translate: new Map([
		[true, 'yes'],
		[false, 'no']
	])
};

/**
 * @template V
 * @param {string} name
 * @param {V} value
 * @param {boolean} [is_boolean]
 * @returns {string}
 */
export function attr(name, value, is_boolean = false) {
	// attribute hidden for values other than "until-found" behaves like a boolean attribute
	if (name === 'hidden' && value !== 'until-found') {
		is_boolean = true;
	}
	if (value == null || (!value && is_boolean)) return '';
	const normalized = (name in replacements && replacements[name].get(value)) || value;
	const assignment = is_boolean ? '' : `="${escape_html(normalized, true)}"`;
	return ` ${name}${assignment}`;
}

/**
 * Small wrapper around clsx to preserve Svelte's (weird) handling of falsy values.
 * TODO Svelte 6 revisit this, and likely turn all falsy values into the empty string (what clsx also does)
 * @param  {any} value
 */
export function clsx(value) {
	if (typeof value === 'object') {
		return _clsx(value);
	} else {
		return value ?? '';
	}
}

const whitespace = [...' \t\n\r\f\u00a0\u000b\ufeff'];

/**
 * @param {any} value
 * @param {string | null} [hash]
 * @param {Record<string, boolean>} [directives]
 * @returns {string | null}
 */
export function to_class(value, hash, directives) {
	var classname = value == null ? '' : '' + value;

	if (hash) {
		classname = classname ? classname + ' ' + hash : hash;
// ... (164 more lines)

Subdomains

Dependencies

Frequently Asked Questions

What does attributes.js do?
attributes.js is a source file in the svelte codebase, written in javascript. It belongs to the SharedInternal domain, BitFlags subdomain.
What functions are defined in attributes.js?
attributes.js defines 6 function(s): append_styles, attr, clsx, to_class, to_css_name, to_style.
What does attributes.js depend on?
attributes.js imports 3 module(s): clsx, escape_html, escaping.js.
What files import attributes.js?
attributes.js is imported by 4 file(s): attributes.js, class.js, index.js, style.js.
Where is attributes.js in the architecture?
attributes.js is located at packages/svelte/src/internal/shared/attributes.js (domain: SharedInternal, subdomain: BitFlags, directory: packages/svelte/src/internal/shared).

Analyze Your Own Codebase

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

Try Supermodel Free