\\n\"}"
+ },
+ {
+ "simStepId": "6abaf85a-bbba-43a6-8a7b-c137931d139a",
+ "diagramNodeId": "61f846e2-4e6a-425e-aff3-fe1f9bf7088d",
+ "simStepLabel": "Parse Source Code into AST",
+ "simStepDescription": "The parser processes the component source. It uses a state machine to parse the template markup (`element.js`, `tag.js`), Acorn for JavaScript in `\\n
Hello {name}!
\\n\"}",
+ "outputDataExample": "{\"type\":\"Root\",\"fragment\":{\"type\":\"Fragment\",\"nodes\":[{\"type\":\"RegularElement\",\"name\":\"h1\",\"fragment\":{\"nodes\":[{\"type\":\"Text\",\"data\":\"Hello \"},{\"type\":\"ExpressionTag\",\"expression\":{\"type\":\"Identifier\",\"name\":\"name\"}},{\"type\":\"Text\",\"data\":\"!\"}]}}]},\"css\":{\"type\":\"StyleSheet\",\"children\":[{\"type\":\"Rule\",\"prelude\":{\"children\":[{\"selectors\":[{\"type\":\"TypeSelector\",\"name\":\"h1\"}]}]},\"block\":{\"children\":[{\"type\":\"Declaration\",\"property\":\"color\",\"value\":\"red\"}]}},{\"type\":\"Rule\",\"prelude\":{\"children\":[{\"selectors\":[{\"type\":\"TypeSelector\",\"name\":\"p\"}]}]},\"block\":{\"children\":[{\"type\":\"Declaration\",\"property\":\"color\",\"value\":\"blue\"}]}}]},\"instance\":{\"type\":\"Script\",\"content\":{\"body\":[{\"type\":\"ExportNamedDeclaration\",\"declaration\":{\"declarations\":[{\"id\":{\"name\":\"name\"},\"init\":{\"value\":\"world\"}}]}}]}}}"
+ },
+ {
+ "simStepId": "6dcc1391-65e2-4e74-8119-b46aebe563a6",
+ "diagramNodeId": "9a648bc5-c023-4653-9e9b-151eb41704f3",
+ "simStepLabel": "AST to Analyzer",
+ "simStepDescription": "The generated AST is passed to the analysis phase. This AST contains the raw parsed structure of the component, which will be enriched with metadata about reactivity, scopes, and CSS usage.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/index.js",
+ "startLine": "65",
+ "endLine": "65",
+ "relevantVariables": [
+ "analyze_component",
+ "parsed"
+ ]
+ },
+ "inputDataExample": "{\"type\":\"Root\",\"fragment\":{\"type\":\"Fragment\",\"nodes\":[{\"type\":\"RegularElement\",\"name\":\"h1\",\"fragment\":{\"nodes\":[{\"type\":\"Text\",\"data\":\"Hello \"},{\"type\":\"ExpressionTag\",\"expression\":{\"type\":\"Identifier\",\"name\":\"name\"}},{\"type\":\"Text\",\"data\":\"!\"}]}}]},\"css\":{\"type\":\"StyleSheet\",\"children\":[{\"type\":\"Rule\",\"prelude\":{\"children\":[{\"selectors\":[{\"type\":\"TypeSelector\",\"name\":\"h1\"}]}]},\"block\":{\"children\":[{\"type\":\"Declaration\",\"property\":\"color\",\"value\":\"red\"}]}},{\"type\":\"Rule\",\"prelude\":{\"children\":[{\"selectors\":[{\"type\":\"TypeSelector\",\"name\":\"p\"}]}]},\"block\":{\"children\":[{\"type\":\"Declaration\",\"property\":\"color\",\"value\":\"blue\"}]}}]},\"instance\":{\"type\":\"Script\",\"content\":{\"body\":[{\"type\":\"ExportNamedDeclaration\",\"declaration\":{\"declarations\":[{\"id\":{\"name\":\"name\"},\"init\":{\"value\":\"world\"}}]}}]}}}",
+ "outputDataExample": "{\"type\":\"Root\",\"fragment\":{\"type\":\"Fragment\",\"nodes\":[{\"type\":\"RegularElement\",\"name\":\"h1\",\"fragment\":{\"nodes\":[{\"type\":\"Text\",\"data\":\"Hello \"},{\"type\":\"ExpressionTag\",\"expression\":{\"type\":\"Identifier\",\"name\":\"name\"}},{\"type\":\"Text\",\"data\":\"!\"}]}}]},\"css\":{\"type\":\"StyleSheet\",\"children\":[{\"type\":\"Rule\",\"prelude\":{\"children\":[{\"selectors\":[{\"type\":\"TypeSelector\",\"name\":\"h1\"}]}]},\"block\":{\"children\":[{\"type\":\"Declaration\",\"property\":\"color\",\"value\":\"red\"}]}},{\"type\":\"Rule\",\"prelude\":{\"children\":[{\"selectors\":[{\"type\":\"TypeSelector\",\"name\":\"p\"}]}]},\"block\":{\"children\":[{\"type\":\"Declaration\",\"property\":\"color\",\"value\":\"blue\"}]}}]},\"instance\":{\"type\":\"Script\",\"content\":{\"body\":[{\"type\":\"ExportNamedDeclaration\",\"declaration\":{\"declarations\":[{\"id\":{\"name\":\"name\"},\"init\":{\"value\":\"world\"}}]}}]}}}"
+ },
+ {
+ "simStepId": "e3549e74-8d2c-49f9-9d16-7573de53db6a",
+ "diagramNodeId": "ddfea10a-886f-4b9e-998a-8bc04e6471c8",
+ "simStepLabel": "Analyze Component AST",
+ "simStepDescription": "The analysis phase walks the AST to understand the component's behavior. It builds scopes, identifies reactive variables, and analyzes CSS to determine which styles are used and can be pruned. This phase enriches the AST with metadata for the final transformation phase.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/2-analyze/index.js",
+ "startLine": "325",
+ "endLine": "328",
+ "relevantVariables": [
+ "analyze_component",
+ "ScopeRoot",
+ "root",
+ "source",
+ "options"
+ ]
+ },
+ "inputDataExample": "{\"type\":\"Root\",\"fragment\":{\"nodes\":[{\"type\":\"RegularElement\",\"name\":\"h1\"}]},\"css\":{\"children\":[{\"type\":\"Rule\",\"prelude\":{\"children\":[{\"selectors\":[{\"type\":\"TypeSelector\",\"name\":\"h1\"}]}]},\"block\":{}},{\"type\":\"Rule\",\"prelude\":{\"children\":[{\"selectors\":[{\"type\":\"TypeSelector\",\"name\":\"p\"}]}]},\"block\":{}}]},\"instance\":{\"content\":{\"body\":[{\"type\":\"ExportNamedDeclaration\"}]}}}",
+ "outputDataExample": "{\"name\":\"App\",\"root\":{},\"module\":{},\"instance\":{\"scope\":{},\"ast\":{}},\"template\":{\"scope\":{}},\"css\":{\"ast\":{\"children\":[{\"type\":\"Rule\",\"metadata\":{\"has_local_selectors\":true}},{\"type\":\"Rule\",\"metadata\":{\"has_local_selectors\":false}}]}},\"reactive_statements\":{},\"component_references\":{},\"runes\":false}"
+ },
+ {
+ "simStepId": "ce2180fe-150c-49f1-a0ba-dc9219fbd8bb",
+ "diagramNodeId": "ee258f8d-6cfe-4b5c-89c5-ef1f58ac3527",
+ "simStepLabel": "Analysis to Transformer",
+ "simStepDescription": "The enriched `ComponentAnalysis` object, containing the AST and all collected metadata, is passed to the transformation phase to generate the final JavaScript code.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/index.js",
+ "startLine": "66",
+ "endLine": "66",
+ "relevantVariables": [
+ "transform_component",
+ "analysis"
+ ]
+ },
+ "inputDataExample": "{\"name\":\"App\",\"root\":{},\"module\":{},\"instance\":{\"scope\":{},\"ast\":{}},\"template\":{\"scope\":{}},\"css\":{\"ast\":{\"children\":[{\"type\":\"Rule\",\"metadata\":{\"has_local_selectors\":true}},{\"type\":\"Rule\",\"metadata\":{\"has_local_selectors\":false}}]}},\"reactive_statements\":{},\"component_references\":{},\"runes\":false}",
+ "outputDataExample": "{\"name\":\"App\",\"root\":{},\"module\":{},\"instance\":{\"scope\":{},\"ast\":{}},\"template\":{\"scope\":{}},\"css\":{\"ast\":{\"children\":[{\"type\":\"Rule\",\"metadata\":{\"has_local_selectors\":true}},{\"type\":\"Rule\",\"metadata\":{\"has_local_selectors\":false}}]}},\"reactive_statements\":{},\"component_references\":{},\"runes\":false}"
+ },
+ {
+ "simStepId": "f40522ec-9c92-4e66-8338-0d0a0b420f3b",
+ "diagramNodeId": "722de3d2-78b4-492f-be78-45b476cce49d",
+ "simStepLabel": "Transform AST to JavaScript",
+ "simStepDescription": "The transformation phase takes the analyzed component and generates the output JavaScript module. For client-side components, it creates the logic for building, hydrating, mounting, and updating the DOM, along with handling component state and props.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/3-transform/index.js",
+ "startLine": "21",
+ "endLine": "26",
+ "relevantVariables": [
+ "transform_component",
+ "analysis",
+ "source",
+ "options"
+ ]
+ },
+ "inputDataExample": "{\"name\":\"App\",\"root\":{},\"module\":{},\"instance\":{\"scope\":{}},\"template\":{\"scope\":{}},\"css\":{\"ast\":{}},\"reactive_statements\":{},\"component_references\":{},\"runes\":false}",
+ "outputDataExample": "{\"js\":{\"code\":\"import { SvelteComponent, init, safe_not_equal, element, text, insert, append, set_data, detach } from 'svelte/internal';\\n\\nfunction create_fragment(ctx) {\\n // ... fragment creation logic ... \\n}\\n\\nfunction instance($$self, $$props, $$invalidate) {\\n let { name = 'world' } = $$props;\\n // ... instance logic ... \\n}\\n\\nclass App extends SvelteComponent {\\n constructor(options) {\\n super();\\n init(this, options, instance, create_fragment, safe_not_equal, { name: 0 });\\n }\\n}\\n\\nexport default App;\",\"map\":{...}},\"css\":{\"code\":\"h1.svelte-xyz { color: red; }\",\"map\":{...}},\"warnings\":[],\"metadata\":{\"runes\":false}}"
+ },
+ {
+ "simStepId": "a56da5ef-b0a2-4f15-b652-0534802c24b4",
+ "diagramNodeId": "",
+ "simStepLabel": "Return Compiled Result",
+ "simStepDescription": "The final `CompileResult` object, containing the generated JavaScript and CSS code along with source maps and any warnings, is returned from the top-level `compile` function. This completes the compilation process.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/index.js",
+ "startLine": "67",
+ "endLine": "67",
+ "relevantVariables": [
+ "result"
+ ]
+ },
+ "inputDataExample": "{\"js\":{\"code\":\"import { SvelteComponent, ... } from 'svelte/internal';\\n// ... component code ...\\nexport default App;\",\"map\":{...}},\"css\":{\"code\":\"h1.svelte-xyz { color: red; }\",\"map\":{...}},\"warnings\":[],\"metadata\":{\"runes\":false}}",
+ "outputDataExample": "{\"js\":{\"code\":\"import { SvelteComponent, ... } from 'svelte/internal';\\n// ... component code ...\\nexport default App;\",\"map\":{...}},\"css\":{\"code\":\"h1.svelte-xyz { color: red; }\",\"map\":{...}},\"warnings\":[],\"metadata\":{\"runes\":false}}"
+ }
+ ],
+ "description": "
The core feature of Svelte is its component-centric architecture, where UI is built using self-contained and reusable
svelte files
These files encapsulate markup, logic, and styles
The Svelte compiler processes these files, converting them into highly optimized vanilla JavaScript that directly manipulates the DOM
",
+ "simulationNodesAndEdges": {
+ "f48bf76d-115e-4ebe-af39-11c4d3e00642": {
+ "simStepIds": [
+ "73988ccd-a18f-4141-9178-ce9152f835b6"
+ ]
+ },
+ "61f846e2-4e6a-425e-aff3-fe1f9bf7088d": {
+ "simStepIds": [
+ "6abaf85a-bbba-43a6-8a7b-c137931d139a"
+ ]
+ },
+ "ddfea10a-886f-4b9e-998a-8bc04e6471c8": {
+ "simStepIds": [
+ "e3549e74-8d2c-49f9-9d16-7573de53db6a"
+ ]
+ },
+ "722de3d2-78b4-492f-be78-45b476cce49d": {
+ "simStepIds": [
+ "f40522ec-9c92-4e66-8338-0d0a0b420f3b"
+ ]
+ },
+ "7eb8d72d-c4e3-42bc-ab82-f0c77f50b03e": {
+ "simStepIds": [
+ "36738ebf-0ae1-47f0-98fc-16b845647b81"
+ ]
+ },
+ "9a648bc5-c023-4653-9e9b-151eb41704f3": {
+ "simStepIds": [
+ "6dcc1391-65e2-4e74-8119-b46aebe563a6"
+ ]
+ },
+ "ee258f8d-6cfe-4b5c-89c5-ef1f58ac3527": {
+ "simStepIds": [
+ "ce2180fe-150c-49f1-a0ba-dc9219fbd8bb"
+ ]
+ }
+ },
+ "isAIGenerated": true,
+ "keywords": "compile, parse, ComponentAnalysis",
+ "generationPrompt": "Component-Based UI Development",
+ "generationKeywords": "compile, parse, ComponentAnalysis"
+ },
+ "Declarative & Fine-Grained Reactivity (Runes)": {
+ "name": "Declarative & Fine-Grained Reactivity (Runes)",
+ "simSteps": [
+ {
+ "simStepId": "41484434-76b1-4c57-8ea0-1bd25cd84ca1",
+ "diagramNodeId": "745e8e46-db2f-4dc8-a3ea-f9a2b3026552",
+ "simStepLabel": "1. Declare Reactive State with `$state`",
+ "simStepDescription": "A developer initializes a reactive variable `count` to `0` using the `$state` rune. This is a compiler instruction that, at runtime, creates a reactive 'source' signal to track the variable's value. Any part of the application that reads this value will automatically subscribe to its changes.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/ambient.d.ts",
+ "startLine": "12",
+ "endLine": "19",
+ "relevantVariables": [
+ "$state"
+ ]
+ },
+ "inputDataExample": "{\"initialValue\": 0}",
+ "outputDataExample": "{\"signal\": {\"value\": 0, \"subscribers\": []}}"
+ },
+ {
+ "simStepId": "4d02c778-1f6e-4425-9042-2d792034f805",
+ "diagramNodeId": "10d99855-477c-4f9c-bbc6-9dec6f928433",
+ "simStepLabel": "2. State Value Flow to Derived Calculation",
+ "simStepDescription": "The value of the `count` state (initially `0`) is read during the initialization of a `$derived` expression. This establishes `count` as a dependency for the derived state.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/ambient.d.ts",
+ "startLine": "164",
+ "endLine": "173",
+ "relevantVariables": [
+ "$derived"
+ ]
+ },
+ "inputDataExample": "{\"count\": 0}",
+ "outputDataExample": "{\"count\": 0}"
+ },
+ {
+ "simStepId": "a46f5d0f-f7f1-4dce-b7f6-f7a860b1f9b8",
+ "diagramNodeId": "17b7357f-5678-4337-802a-bdf19c9febdd",
+ "simStepLabel": "3. Declare Derived State with `$derived`",
+ "simStepDescription": "A new derived state variable `doubled` is declared. The Svelte compiler transforms the `$derived` rune into a function that creates a 'derived' signal. This signal automatically tracks `count` as a dependency and computes its value as `count * 2`. The value is lazily re-calculated only when `doubled` is read and its dependencies have changed.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/reactivity/deriveds.js",
+ "startLine": "66",
+ "endLine": "113",
+ "relevantVariables": [
+ "derived",
+ "derived_effect"
+ ]
+ },
+ "inputDataExample": "{\"expression\": \"count * 2\", \"dependencies\": {\"count\": 0}}",
+ "outputDataExample": "{\"derivedSignal\": {\"value\": 0, \"dependencies\": [\"count\"]}}"
+ },
+ {
+ "simStepId": "e1b10348-1d2f-42f7-b399-55672a30e36b",
+ "diagramNodeId": "9a28bb95-39a0-4fac-a561-fe7d4dcd6300",
+ "simStepLabel": "4. State Value Flow to Side Effect",
+ "simStepDescription": "The value of `count` is also read during the initialization of an `$effect`. This establishes `count` as a dependency for the effect, meaning the effect will re-run whenever `count` changes.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/reactivity/effects.js",
+ "startLine": "195",
+ "endLine": "224",
+ "relevantVariables": [
+ "user_effect"
+ ]
+ },
+ "inputDataExample": "{\"count\": 0}",
+ "outputDataExample": "{\"count\": 0}"
+ },
+ {
+ "simStepId": "269bbdfe-dca8-407f-a63b-0235d9c16e90",
+ "diagramNodeId": "b5cc8d6a-f7ac-40ed-926d-696ba7bcddf2",
+ "simStepLabel": "5. Register Side Effect with `$effect`",
+ "simStepDescription": "A side effect is registered using the `$effect` rune. The runtime creates an 'effect' that subscribes to its dependencies (in this case, `count`). The provided callback function is executed once after the component mounts, and then re-executed after any subsequent change to its dependencies.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/reactivity/effects.js",
+ "startLine": "195",
+ "endLine": "224",
+ "relevantVariables": [
+ "user_effect",
+ "validate_effect",
+ "create_effect"
+ ]
+ },
+ "inputDataExample": "{\"callback\": \"() => { console.log('Count is:', count) }\", \"dependencies\": {\"count\": 0}}",
+ "outputDataExample": "{\"effect\": {\"status\": \"scheduled\", \"dependencies\": [\"count\"]}}"
+ },
+ {
+ "simStepId": "fe988104-19fe-4e2c-928b-480e7f25d2f5",
+ "diagramNodeId": "c37c9b57-4d87-4b28-82b7-b88f15d5f1ef",
+ "simStepLabel": "6. User Interaction Triggers State Update",
+ "simStepDescription": "A user interaction, such as clicking a button, triggers an event handler that executes `count++`. This initiates the reactive update cycle.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/proxy.js",
+ "startLine": "105",
+ "endLine": "134",
+ "relevantVariables": [
+ "set"
+ ]
+ },
+ "inputDataExample": "{\"event\": \"click\", \"handler\": \"() => count++\"}",
+ "outputDataExample": "{\"operation\": \"set\", \"target\": \"count\", \"newValue\": 1}"
+ },
+ {
+ "simStepId": "b4f33a1a-fb27-4571-82eb-c4b4a9b31258",
+ "diagramNodeId": "52b3fbf0-a463-42d0-813d-35c6b2df5f5f",
+ "simStepLabel": "7. Runtime Detects State Change via Proxy",
+ "simStepDescription": "The assignment to `count` is intercepted by the `$state` proxy's `set` handler. This handler compares the new value with the old one. Since the value has changed, it calls `set_signal_value` to mark the `count` signal as 'dirty' and schedules an update.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/reactivity/sources.js",
+ "startLine": "204",
+ "endLine": "236",
+ "relevantVariables": [
+ "set_signal_value",
+ "is_runes",
+ "current_component_context",
+ "mark_reactions"
+ ]
+ },
+ "inputDataExample": "{\"target\": {\"signal\": \"count\"}, \"property\": \"value\", \"newValue\": 1}",
+ "outputDataExample": "{\"dirtySignal\": \"count\", \"status\": \"update_scheduled\"}"
+ },
+ {
+ "simStepId": "e7c044f8-f77f-4f17-90f9-4c83b4f7e6ed",
+ "diagramNodeId": "9191c53a-2475-429e-b2f2-f538d670baa3",
+ "simStepLabel": "8. Propagate 'Dirty' Status to Dependents",
+ "simStepDescription": "The runtime traverses the dependency graph starting from the `count` signal. It marks all dependent signals and effects (`doubled` and the logging effect) as 'dirty', indicating they need to be updated or re-run.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/reactivity/sources.js",
+ "startLine": "238",
+ "endLine": "260",
+ "relevantVariables": [
+ "mark_reactions",
+ "mark_reaction"
+ ]
+ },
+ "inputDataExample": "{\"dirtySignal\": \"count\"}",
+ "outputDataExample": "{\"dirtyDependents\": [\"doubled_signal\", \"log_effect\"]}"
+ },
+ {
+ "simStepId": "7052b8a8-1b42-4298-baf4-07f931221a33",
+ "diagramNodeId": "91d3446d-904e-44b2-9b47-d82feb813f59",
+ "simStepLabel": "9. Re-compute Derived State",
+ "simStepDescription": "During the update cycle, the runtime processes all dirty signals. It re-evaluates the expression for the `doubled` signal (`count * 2`) using the new value of `count` (1). The result (2) is then compared to the old value, and if it has changed, `doubled` itself is marked as dirty to propagate the change further.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/reactivity/deriveds.js",
+ "startLine": "119",
+ "endLine": "147",
+ "relevantVariables": [
+ "update_derived",
+ "set_signal_value"
+ ]
+ },
+ "inputDataExample": "{\"dirtySignal\": \"doubled\", \"dependencies\": {\"count\": 1}}",
+ "outputDataExample": "{\"recomputedSignal\": \"doubled\", \"newValue\": 2}"
+ },
+ {
+ "simStepId": "b95bd6bd-1d99-4146-aeca-3fd11f3026e5",
+ "diagramNodeId": "c4ef69d1-0e78-4099-8cba-cdf590cdfff0",
+ "simStepLabel": "10. Updated Values Flow to Effect",
+ "simStepDescription": "The new value of `count` is now available for the scheduled side effect to consume during its execution.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/reactivity/batch.js",
+ "startLine": "321",
+ "endLine": "344",
+ "relevantVariables": [
+ "execute_effect"
+ ]
+ },
+ "inputDataExample": "{\"count\": 1}",
+ "outputDataExample": "{\"count\": 1}"
+ },
+ {
+ "simStepId": "d7ef3ce4-3728-4fc3-924a-2fdd2dd79b7c",
+ "diagramNodeId": "b08c5565-60eb-4e1c-af03-54ec0bd2b8cd",
+ "simStepLabel": "11. Re-run Side Effect",
+ "simStepDescription": "After DOM updates are flushed, the runtime executes all dirty effects. The callback for the logging `$effect` is re-run because its dependency `count` changed. It now reads the new value of `count` (1) and logs it to the console.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/reactivity/batch.js",
+ "startLine": "321",
+ "endLine": "344",
+ "relevantVariables": [
+ "flush_effects",
+ "execute_effect",
+ "update_effect"
+ ]
+ },
+ "inputDataExample": "{\"dirtyEffect\": \"log_effect\", \"dependencies\": {\"count\": 1}}",
+ "outputDataExample": "{\"sideEffectResult\": \"console.log('Count is: 1')\"}"
+ }
+ ],
+ "description": "
Svelte provides a powerful and simple reactivity model using 'runes'
State is created with $state(), derived computations with $derived(), and side effects with $effect()
The compiler analyzes these runes to generate code that automatically updates the UI and runs effects when underlying state changes, eliminating the need for manual DOM manipulation or complex lifecycle hooks
Svelte provides declarative, HTML-like syntax for control flow directly in the markup
This includes {#if
}, {#each
}, and {#await
} blocks
These constructs allow developers to conditionally render content, iterate over lists, and handle asynchronous data fetching in a clean and readable way
",
+ "simulationNodesAndEdges": {
+ "c9b60bf5-a13b-4c05-9b8a-68846136b1a8": {
+ "simStepIds": [
+ "dbce1619-de41-4a9b-b635-11f05daf28a1"
+ ]
+ },
+ "df29ced6-a767-4ab4-b1ec-223befc40079": {
+ "simStepIds": [
+ "6034fafc-8dbf-43b4-bb5e-3ce9cd58fc15"
+ ]
+ },
+ "d3e32856-76e7-443e-bf26-a9e29dce7674": {
+ "simStepIds": [
+ "ba4a8df7-43c2-4261-a212-c49bff26f59b"
+ ]
+ },
+ "faa3371b-e46a-4d3f-81a1-26b2e528d200": {
+ "simStepIds": [
+ "c9fbbdb3-acd4-428e-a025-4855edfd6511"
+ ]
+ },
+ "077a9c68-36c7-4e14-9f21-45bea946be72": {
+ "simStepIds": [
+ "7e6e69f3-d953-4548-9a52-f0e07cc36990"
+ ]
+ },
+ "7e0e1f17-748d-454a-8b2c-3fbb5470572d": {
+ "simStepIds": [
+ "2f8f0941-b0fb-43b9-a22a-fa9a84a41e7e"
+ ]
+ },
+ "f89f3e3d-6afa-41d1-98ed-f6e3f575aab0": {
+ "simStepIds": [
+ "fb60f504-256d-442e-8512-77a92eb41e02"
+ ]
+ },
+ "15dbc2da-73ae-4ced-9797-7db8ee24084b": {
+ "simStepIds": [
+ "82641ab4-a258-4844-b326-f94928e7ca98"
+ ]
+ },
+ "6fd30577-5f5e-4a2a-80ee-26dcff891603": {
+ "simStepIds": [
+ "04e91e0f-56f1-49ba-9a43-646169a3e02a"
+ ]
+ }
+ },
+ "isAIGenerated": true,
+ "keywords": "EachBlock, IfBlock, AwaitBlock",
+ "generationPrompt": "Template Control Flow Logic",
+ "generationKeywords": "EachBlock, IfBlock, AwaitBlock"
+ },
+ "Two-Way Data Binding": {
+ "name": "Two-Way Data Binding",
+ "simSteps": [
+ {
+ "simStepId": "b2adfb46-eaea-466a-b752-bdb0bb0a0d87",
+ "diagramNodeId": "4b6a3abf-e21a-4888-93b6-9fcb9bb3b316",
+ "simStepLabel": "Template Parsing",
+ "simStepDescription": "The Svelte compiler parses a `.svelte` file. When it encounters the `bind:value={message}` syntax on an `` element, it identifies it as a special directive and creates a `BindDirective` node in the Abstract Syntax Tree (AST).",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/1-parse/state/element.js",
+ "startLine": "696",
+ "endLine": "704",
+ "relevantVariables": [
+ "get_directive_type"
+ ]
+ },
+ "inputDataExample": "",
+ "outputDataExample": "{\"type\":\"BindDirective\",\"name\":\"value\",\"expression\":{\"type\":\"Identifier\",\"name\":\"message\"}}"
+ },
+ {
+ "simStepId": "e241bb4f-802b-4702-aa2c-d141fd12acd3",
+ "diagramNodeId": "30528d02-bd0d-495b-8c41-37176d9a7246",
+ "simStepLabel": "AST to Analyzer",
+ "simStepDescription": "The newly created `BindDirective` AST node is passed from the parser to the analysis phase for validation and enrichment.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "",
+ "startLine": "0",
+ "endLine": "0",
+ "relevantVariables": []
+ },
+ "inputDataExample": "{\"type\":\"BindDirective\",\"name\":\"value\",\"expression\":{\"type\":\"Identifier\",\"name\":\"message\"}}",
+ "outputDataExample": "{\"type\":\"BindDirective\",\"name\":\"value\",\"expression\":{\"type\":\"Identifier\",\"name\":\"message\"}}"
+ },
+ {
+ "simStepId": "56760edd-8197-436f-8793-d1036fac8776",
+ "diagramNodeId": "61bdcd0f-7ce8-47bd-97f2-6ce5d9c405db",
+ "simStepLabel": "Binding Analysis",
+ "simStepDescription": "The analyzer processes the `BindDirective` node. It validates that `bind:value` is a valid binding for an `` element. It looks up the `message` variable in the current scope and marks it as a mutable state that is bound to the DOM.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/2-analyze/visitors/BindDirective.js",
+ "startLine": "16",
+ "endLine": "233",
+ "relevantVariables": [
+ "BindDirective"
+ ]
+ },
+ "inputDataExample": "{\"type\":\"BindDirective\",\"name\":\"value\",\"expression\":{\"type\":\"Identifier\",\"name\":\"message\"}}",
+ "outputDataExample": "{\"type\":\"BindDirective\",\"name\":\"value\",\"expression\":{\"type\":\"Identifier\",\"name\":\"message\"},\"metadata\":{\"binding_group_name\":null,\"parent_is_runes\":true}}"
+ },
+ {
+ "simStepId": "ed132dc8-42da-4d0e-8fbf-a3ee605ac07b",
+ "diagramNodeId": "721eff03-3c68-43d9-bfd3-d0bd78cb016e",
+ "simStepLabel": "Analyzed AST to Transformer",
+ "simStepDescription": "The validated and enriched `BindDirective` AST node is passed to the transform phase, which is responsible for generating the final JavaScript code.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "",
+ "startLine": "0",
+ "endLine": "0",
+ "relevantVariables": []
+ },
+ "inputDataExample": "{\"type\":\"BindDirective\",\"name\":\"value\",\"expression\":{\"type\":\"Identifier\",\"name\":\"message\"},\"metadata\":{\"binding_group_name\":null,\"parent_is_runes\":true}}",
+ "outputDataExample": "{\"type\":\"BindDirective\",\"name\":\"value\",\"expression\":{\"type\":\"Identifier\",\"name\":\"message\"},\"metadata\":{\"binding_group_name\":null,\"parent_is_runes\":true}}"
+ },
+ {
+ "simStepId": "a0a75d39-c6f4-47cd-b653-0ca8cf5b3966",
+ "diagramNodeId": "094d4b5d-6294-4167-b442-bd893dc55897",
+ "simStepLabel": "Client-Side Code Generation",
+ "simStepDescription": "The transformer visits the `BindDirective` node and generates client-side JavaScript code. For an `` with `bind:value`, it generates a call to the `$.bind_value` runtime helper function. This function receives the DOM element, a getter for the state variable, and a setter to update it.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/3-transform/client/visitors/BindDirective.js",
+ "startLine": "160",
+ "endLine": "168",
+ "relevantVariables": [
+ "BindDirective",
+ "b.call",
+ "$.bind_value",
+ "$.bind_select_value"
+ ]
+ },
+ "inputDataExample": "{\"type\":\"BindDirective\",\"name\":\"value\",\"expression\":{\"type\":\"Identifier\",\"name\":\"message\"},\"metadata\":{\"binding_group_name\":null,\"parent_is_runes\":true}}",
+ "outputDataExample": "$.bind_value(input_element, () => message, ($$value) => message = $$value);"
+ },
+ {
+ "simStepId": "cfc0d01f-8eff-4901-9074-d72ae31be9b7",
+ "diagramNodeId": "0c410183-3dc5-4f18-8af0-5429289e87b3",
+ "simStepLabel": "Code Execution in Browser",
+ "simStepDescription": "The generated JavaScript, including the call to `$.bind_value`, is executed in the browser when the component is mounted.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "",
+ "startLine": "0",
+ "endLine": "0",
+ "relevantVariables": []
+ },
+ "inputDataExample": "{\"function_call\":\"$.bind_value\",\"arguments\":[\"HTMLInputElement\",\"() => 'initial value'\",\"($$value) => { /* state update logic */ }\"]}",
+ "outputDataExample": "{\"function_call\":\"$.bind_value\",\"arguments\":[\"HTMLInputElement\",\"() => 'initial value'\",\"($$value) => { /* state update logic */ }\"]}"
+ },
+ {
+ "simStepId": "f033033f-bb40-49b6-b42c-9ee69d0e2cc6",
+ "diagramNodeId": "02866d1c-9e07-4059-9152-4474f6e2c447",
+ "simStepLabel": "Runtime Binding Initialization",
+ "simStepDescription": "The `bind_value` runtime helper function is executed. It attaches an 'input' event listener to the element and sets up a reactive effect to update the element's `.value` property whenever the bound state variable changes.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/dom/elements/bindings/input.js",
+ "startLine": "15",
+ "endLine": "92",
+ "relevantVariables": [
+ "bind_value",
+ "listen_to_event_and_reset_event",
+ "effect"
+ ]
+ },
+ "inputDataExample": "{\"function_call\":\"$.bind_value\",\"arguments\":[\"HTMLInputElement\",\"() => 'initial value'\",\"($$value) => { /* state update logic */ }\"]}",
+ "outputDataExample": "null"
+ },
+ {
+ "simStepId": "fe033411-37a8-4180-88ae-ca0f6b004d08",
+ "diagramNodeId": "948295ec-2f58-4fc8-b58d-f866f457288e",
+ "simStepLabel": "Data Flow: User Input",
+ "simStepDescription": "The user types into the `` field in the browser. This action triggers an `input` event on the DOM element.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "",
+ "startLine": "0",
+ "endLine": "0",
+ "relevantVariables": []
+ },
+ "inputDataExample": "{\"event\":\"InputEvent\",\"target\":{\"value\":\"new user text\"}}",
+ "outputDataExample": "{\"event\":\"InputEvent\",\"target\":{\"value\":\"new user text\"}}"
+ },
+ {
+ "simStepId": "0b96b271-3a64-4f76-911a-937547e9f13b",
+ "diagramNodeId": "5b62a59c-d046-466d-bee7-609ef25e71cf",
+ "simStepLabel": "Update State from DOM",
+ "simStepDescription": "The `input` event listener, set up by `bind_value`, executes. It reads the new value from the input element and calls the 'set' function to update the corresponding Svelte state variable (`message`).",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/dom/elements/bindings/input.js",
+ "startLine": "23",
+ "endLine": "33",
+ "relevantVariables": [
+ "set",
+ "get_value",
+ "is_reset"
+ ]
+ },
+ "inputDataExample": "{\"event\":\"InputEvent\",\"target\":{\"value\":\"new user text\"}}",
+ "outputDataExample": "{\"updatedState\":{\"message\":\"new user text\"}}"
+ },
+ {
+ "simStepId": "99a1cef4-3ca9-4c6c-a44e-082b96db5ad8",
+ "diagramNodeId": "04d26407-9072-426d-88ff-7354fdc3d4e3",
+ "simStepLabel": "Data Flow: Programmatic State Change",
+ "simStepDescription": "In the other direction, the `message` state variable is updated programmatically somewhere in the application code. Svelte's reactivity system detects this change and schedules an update.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "",
+ "startLine": "0",
+ "endLine": "0",
+ "relevantVariables": []
+ },
+ "inputDataExample": "{\"newState\":{\"message\":\"programmatic update\"}}",
+ "outputDataExample": "{\"newState\":{\"message\":\"programmatic update\"}}"
+ },
+ {
+ "simStepId": "820fc63a-1b56-4fae-bee8-e71aba1dc25d",
+ "diagramNodeId": "4af2d2fa-fe5d-481f-bfcd-a3ce99430c35",
+ "simStepLabel": "Update DOM from State",
+ "simStepDescription": "The reactive effect created during initialization is triggered by the state change. It reads the new value ('programmatic update') and updates the `.value` property of the `` element in the DOM, but only if the input is not currently focused to avoid disrupting user input.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/dom/elements/bindings/input.js",
+ "startLine": "84",
+ "endLine": "91",
+ "relevantVariables": [
+ "effect",
+ "get",
+ "is_flushing",
+ "document.activeElement"
+ ]
+ },
+ "inputDataExample": "{\"newState\":{\"message\":\"programmatic update\"}}",
+ "outputDataExample": "null"
+ }
+ ],
+ "description": "
Svelte simplifies form handling and component communication with the bind: directive
It creates a two-way binding between a variable and an element's property (like an input's value)
This means that when the user types in the input, the variable updates, and when the variable changes, the input's value updates automatically
",
+ "simulationNodesAndEdges": {
+ "4b6a3abf-e21a-4888-93b6-9fcb9bb3b316": {
+ "simStepIds": [
+ "b2adfb46-eaea-466a-b752-bdb0bb0a0d87"
+ ]
+ },
+ "61bdcd0f-7ce8-47bd-97f2-6ce5d9c405db": {
+ "simStepIds": [
+ "56760edd-8197-436f-8793-d1036fac8776"
+ ]
+ },
+ "094d4b5d-6294-4167-b442-bd893dc55897": {
+ "simStepIds": [
+ "a0a75d39-c6f4-47cd-b653-0ca8cf5b3966"
+ ]
+ },
+ "02866d1c-9e07-4059-9152-4474f6e2c447": {
+ "simStepIds": [
+ "f033033f-bb40-49b6-b42c-9ee69d0e2cc6"
+ ]
+ },
+ "5b62a59c-d046-466d-bee7-609ef25e71cf": {
+ "simStepIds": [
+ "0b96b271-3a64-4f76-911a-937547e9f13b"
+ ]
+ },
+ "4af2d2fa-fe5d-481f-bfcd-a3ce99430c35": {
+ "simStepIds": [
+ "820fc63a-1b56-4fae-bee8-e71aba1dc25d"
+ ]
+ },
+ "30528d02-bd0d-495b-8c41-37176d9a7246": {
+ "simStepIds": [
+ "e241bb4f-802b-4702-aa2c-d141fd12acd3"
+ ]
+ },
+ "721eff03-3c68-43d9-bfd3-d0bd78cb016e": {
+ "simStepIds": [
+ "ed132dc8-42da-4d0e-8fbf-a3ee605ac07b"
+ ]
+ },
+ "0c410183-3dc5-4f18-8af0-5429289e87b3": {
+ "simStepIds": [
+ "cfc0d01f-8eff-4901-9074-d72ae31be9b7"
+ ]
+ },
+ "948295ec-2f58-4fc8-b58d-f866f457288e": {
+ "simStepIds": [
+ "fe033411-37a8-4180-88ae-ca0f6b004d08"
+ ]
+ },
+ "04d26407-9072-426d-88ff-7354fdc3d4e3": {
+ "simStepIds": [
+ "99a1cef4-3ca9-4c6c-a44e-082b96db5ad8"
+ ]
+ }
+ },
+ "isAIGenerated": true,
+ "keywords": "bind:, BindDirective, bind_value",
+ "generationPrompt": "Two-Way Data Binding",
+ "generationKeywords": "bind:, BindDirective, bind_value"
+ },
+ "Cross-Component State Management with Stores": {
+ "name": "Cross-Component State Management with Stores",
+ "simSteps": [
+ {
+ "simStepId": "0c2654b1-8c26-4a45-8f27-5a22365296ca",
+ "diagramNodeId": "89b020ee-1209-4c9b-924a-8b58eee91ab5",
+ "simStepLabel": "Store Creation: writable()",
+ "simStepDescription": "A writable store is created by calling the `writable` function from `svelte/store`. This function initializes the store with a starting value, sets up an empty collection for subscribers, and defines the `set`, `update`, and `subscribe` methods. It returns a store object that conforms to the Svelte store contract.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/store/shared/index.js",
+ "startLine": "36",
+ "endLine": "97",
+ "relevantVariables": [
+ "writable",
+ "value",
+ "start",
+ "subscribers",
+ "set",
+ "update",
+ "subscribe"
+ ]
+ },
+ "inputDataExample": "{\n \"initialValue\": 0,\n \"startStopNotifier\": null\n}",
+ "outputDataExample": "{\n \"set\": \"function(value)\",\n \"update\": \"function(updater)\",\n \"subscribe\": \"function(callback)\"\n}"
+ },
+ {
+ "simStepId": "d56ebc63-8373-43d7-a0cb-0320f64a0cf4",
+ "diagramNodeId": "511657b1-f003-4450-ad13-2bab56c28062",
+ "simStepLabel": "Data Transmission: Store Object Returned",
+ "simStepDescription": "The newly created store object, containing `set`, `update`, and `subscribe` methods, is returned to the calling code. This object can now be shared across different parts of the application.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/store/shared/index.js",
+ "startLine": "96",
+ "endLine": "96",
+ "relevantVariables": [
+ "set",
+ "update",
+ "subscribe"
+ ]
+ },
+ "inputDataExample": "{\n \"set\": \"function(value)\",\n \"update\": \"function(updater)\",\n \"subscribe\": \"function(callback)\"\n}",
+ "outputDataExample": "{\n \"set\": \"function(value)\",\n \"update\": \"function(updater)\",\n \"subscribe\": \"function(callback)\"\n}"
+ },
+ {
+ "simStepId": "9e720ebf-613f-453a-849a-ccc835189361",
+ "diagramNodeId": "eead44fb-0270-4324-acf1-a27efa869a56",
+ "simStepLabel": "Store Subscription",
+ "simStepDescription": "A component or module subscribes to the store by calling its `subscribe` method with a callback function. The store adds this callback to its set of subscribers. If this is the first subscription, it calls the `start` function (if one was provided during creation).",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/store/shared/index.js",
+ "startLine": "78",
+ "endLine": "95",
+ "relevantVariables": [
+ "subscribe",
+ "run",
+ "invalidate",
+ "subscriber",
+ "subscribers",
+ "start",
+ "stop"
+ ]
+ },
+ "inputDataExample": "{\n \"run\": \"(value) => { console.log('New value:', value) }\",\n \"invalidate\": \"() => {}\"\n}",
+ "outputDataExample": "{\n \"unsubscribe\": \"function()\"\n}"
+ },
+ {
+ "simStepId": "df8c734d-66a7-43a2-b64a-d8d701dfd6e5",
+ "diagramNodeId": "3b6bcdfc-8d22-4485-96d2-bcbef2f092fe",
+ "simStepLabel": "Data Transmission: Initial Value Pushed to Subscriber",
+ "simStepDescription": "As per the store contract, immediately after subscribing, the store synchronously calls the provided callback with its current value. This ensures the subscriber has the most up-to-date state right away.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/store/shared/index.js",
+ "startLine": "88",
+ "endLine": "88",
+ "relevantVariables": [
+ "run",
+ "value"
+ ]
+ },
+ "inputDataExample": "{\n \"currentValue\": 0\n}",
+ "outputDataExample": "{\n \"currentValue\": 0\n}"
+ },
+ {
+ "simStepId": "5eccfae7-3e3c-4aec-bdb6-5d58467296e2",
+ "diagramNodeId": "f6ea321b-e44a-4ef8-ae2e-39dd015b6d96",
+ "simStepLabel": "Update Store Value",
+ "simStepDescription": "The store's value is updated by calling the `set` method with a new value. The `set` function first checks if the new value is different from the current one using `safe_not_equal` to avoid unnecessary updates. If the value has changed, it updates the internal state.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/store/shared/index.js",
+ "startLine": "45",
+ "endLine": "63",
+ "relevantVariables": [
+ "set",
+ "new_value",
+ "safe_not_equal",
+ "value",
+ "subscriber_queue"
+ ]
+ },
+ "inputDataExample": "{\n \"newValue\": 1\n}",
+ "outputDataExample": "{\n \"valueUpdated\": true,\n \"oldValue\": 0,\n \"newValue\": 1\n}"
+ },
+ {
+ "simStepId": "fb76da55-3b5e-40cf-af9a-69d273511a05",
+ "diagramNodeId": "48f9a9e2-4223-4d0e-88c2-275a34b2a172",
+ "simStepLabel": "Data Transmission: Queuing Subscriber Notifications",
+ "simStepDescription": "After the internal value is updated, the `set` function iterates through all active subscribers. Each subscriber callback and the new value are added to a global `subscriber_queue`. This batching mechanism ensures that all subscribers are notified in a predictable and efficient manner.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/store/shared/index.js",
+ "startLine": "51",
+ "endLine": "54",
+ "relevantVariables": [
+ "subscribers",
+ "subscriber_queue"
+ ]
+ },
+ "inputDataExample": "{\n \"subscribers\": [\n [\n \"(value) => { console.log('New value:', value) }\",\n \"() => {}\"\n ]\n ],\n \"newValue\": 1\n}",
+ "outputDataExample": "{\n \"subscribers\": [\n [\n \"(value) => { console.log('New value:', value) }\",\n \"() => {}\"\n ]\n ],\n \"newValue\": 1\n}"
+ },
+ {
+ "simStepId": "1b59caea-f549-403a-aa9c-170aec5c0769",
+ "diagramNodeId": "b93a9117-644b-472d-b396-9b7ca12e4f42",
+ "simStepLabel": "Executing Subscriber Callbacks",
+ "simStepDescription": "The runtime processes the `subscriber_queue`. It iterates through the queue, calling each subscriber's callback function with the new value. This is the step where components and other parts of the application react to the state change.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/store/shared/index.js",
+ "startLine": "56",
+ "endLine": "58",
+ "relevantVariables": [
+ "subscriber_queue"
+ ]
+ },
+ "inputDataExample": "{\n \"subscriber_queue\": [\n [\n \"(value) => { console.log('New value:', value) }\",\n \"() => {}\"\n ],\n 1\n ]\n}",
+ "outputDataExample": "{\n \"subscriber_queue_after_processing\": []\n}"
+ },
+ {
+ "simStepId": "06382bf8-72b6-4d62-ae5f-99c34bef8828",
+ "diagramNodeId": "dc833ff0-fc6a-4abc-bfe9-f5134325eddd",
+ "simStepLabel": "Data Transmission: Unsubscribe Function Returned",
+ "simStepDescription": "The original call to `store.subscribe()` returned an `unsubscribe` function. This function is a closure that holds a reference to the specific subscriber instance.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/store/shared/index.js",
+ "startLine": "89",
+ "endLine": "95",
+ "relevantVariables": [
+ "subscriber",
+ "subscribers"
+ ]
+ },
+ "inputDataExample": "{\n \"unsubscribe\": \"function()\"\n}",
+ "outputDataExample": "{\n \"unsubscribe\": \"function()\"\n}"
+ },
+ {
+ "simStepId": "e91fbf1c-7489-4884-a78c-f62f98f4c1a0",
+ "diagramNodeId": "23394fba-4c2a-4f1d-bd28-bb0ff176a6e7",
+ "simStepLabel": "Unsubscribe from Store",
+ "simStepDescription": "When a component is destroyed or the subscription is no longer needed, the returned `unsubscribe` function is called. This removes the subscriber's callback from the store's internal set, preventing memory leaks and stopping future notifications. If the number of subscribers drops to zero, the `stop` function (if provided) is called for cleanup.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/store/shared/index.js",
+ "startLine": "90",
+ "endLine": "94",
+ "relevantVariables": [
+ "subscribers",
+ "subscriber",
+ "stop"
+ ]
+ },
+ "inputDataExample": "{}",
+ "outputDataExample": "{}"
+ }
+ ],
+ "description": "
For state that needs to be shared across different parts of an application, Svelte provides a built-in store system
Stores are simple objects with a subscribe method that components can use to get notified of value changes
Svelte offers writable, readable, and derived stores to cover various state management scenarios
` that is conditionally rendered using an `{#if}` block. This tells Svelte to apply the 'fade' transition when the element enters or leaves the DOM.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "documentation/docs/03-template-syntax/14-transition.md",
+ "startLine": "17",
+ "endLine": "25",
+ "relevantVariables": [
+ "transition:fade"
+ ]
+ },
+ "inputDataExample": "null",
+ "outputDataExample": "{\n \"file\": \"App.svelte\",\n \"content\": \"{#if visible}
{/if}\"\n}"
+ },
+ {
+ "simStepId": "63a8c2b5-f6ce-4d09-aa94-73a18d25b1af",
+ "diagramNodeId": "65e30850-8aac-4bdf-b9d0-034bf3f84636",
+ "simStepLabel": "Flow: Transition - Parsing and AST Generation",
+ "simStepDescription": "The Svelte compiler parses the template. When it encounters `transition:fade`, it creates a `TransitionDirective` node in the Abstract Syntax Tree (AST). This structured representation captures the directive's name ('fade'), type, and modifiers.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/1-parse/state/element.js",
+ "startLine": "706",
+ "endLine": "708",
+ "relevantVariables": [
+ "directive_type"
+ ]
+ },
+ "inputDataExample": "\"transition:fade\"",
+ "outputDataExample": "{\n \"type\": \"TransitionDirective\",\n \"name\": \"fade\",\n \"expression\": null,\n \"modifiers\": [],\n \"intro\": true,\n \"outro\": true\n}"
+ },
+ {
+ "simStepId": "e54b258e-8590-4e93-a58e-cace014e0fb5",
+ "diagramNodeId": "e35cbd61-dc10-492d-87d9-29743f968d37",
+ "simStepLabel": "Flow: Transition - AST to Transformer",
+ "simStepDescription": "The generated AST, now containing the `TransitionDirective` node, is passed to the transform phase of the compiler, which will convert it into executable JavaScript code.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/2-analyze/index.js",
+ "startLine": "237",
+ "endLine": "237",
+ "relevantVariables": [
+ "walk"
+ ]
+ },
+ "inputDataExample": "{\n \"type\": \"TransitionDirective\",\n \"name\": \"fade\",\n \"expression\": null,\n \"modifiers\": [],\n \"intro\": true,\n \"outro\": true\n}",
+ "outputDataExample": "{\n \"type\": \"TransitionDirective\",\n \"name\": \"fade\",\n \"expression\": null,\n \"modifiers\": [],\n \"intro\": true,\n \"outro\": true\n}"
+ },
+ {
+ "simStepId": "7183b52a-d894-4c9b-938d-debc842f8b01",
+ "diagramNodeId": "16e4305d-7296-436b-bb55-8ef01da75426",
+ "simStepLabel": "Flow: Transition - Code Generation",
+ "simStepDescription": "The transformer processes the `TransitionDirective` AST node and generates a call to the internal Svelte runtime function `$.transition`. This function call includes the transition function itself (`fade`), any parameters, and flags indicating it's a bidirectional transition (`TRANSITION_IN | TRANSITION_OUT`).",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/3-transform/client/visitors/TransitionDirective.js",
+ "startLine": "11",
+ "endLine": "25",
+ "relevantVariables": [
+ "TransitionDirective"
+ ]
+ },
+ "inputDataExample": "{\n \"type\": \"TransitionDirective\",\n \"name\": \"fade\",\n \"expression\": null\n}",
+ "outputDataExample": "{\n \"type\": \"CallExpression\",\n \"callee\": {\n \"type\": \"MemberExpression\",\n \"object\": {\"name\": \"$\"},\n \"property\": {\"name\": \"transition\"}\n },\n \"arguments\": [\n {\n \"type\": \"Literal\",\n \"value\": 3\n },\n {\n \"type\": \"Identifier\",\n \"name\": \"div\"\n },\n {\n \"type\": \"Identifier\",\n \"name\": \"fade\"\n }\n ]\n}"
+ },
+ {
+ "simStepId": "f5e14852-5d4b-4796-b8cb-293081dff907",
+ "diagramNodeId": "3a5cf991-17f0-4700-bab0-b1f90f1db13c",
+ "simStepLabel": "Flow: Transition - Runtime Trigger",
+ "simStepDescription": "The compiled JavaScript is executed in the browser. When the state controlling the `{#if}` block changes (e.g., `visible` becomes `false`), the generated code calls the `$.transition` function to handle the element's removal from the DOM.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/index.js",
+ "startLine": "46",
+ "endLine": "46",
+ "relevantVariables": [
+ "transition"
+ ]
+ },
+ "inputDataExample": "{\n \"event\": \"click\",\n \"newState\": {\n \"visible\": false\n }\n}",
+ "outputDataExample": "{\n \"event\": \"click\",\n \"newState\": {\n \"visible\": false\n }\n}"
+ },
+ {
+ "simStepId": "7e7ca1f9-5ca4-41da-8f7a-79b432d1c717",
+ "diagramNodeId": "3b9120dd-0925-4f08-a380-131a6e86ddef",
+ "simStepLabel": "Flow: Transition - Animation Execution",
+ "simStepDescription": "The `transition` runtime function calls the internal `animate` helper. This helper function uses the browser's native Web Animations API (`element.animate`) with the configuration provided by the `fade` function (CSS keyframes, duration, easing) to perform the visual transition. After the animation completes, the element is removed from the DOM.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/dom/elements/transitions.js",
+ "startLine": "316",
+ "endLine": "461",
+ "relevantVariables": [
+ "animate",
+ "element.animate"
+ ]
+ },
+ "inputDataExample": "{\n \"element\": \"HTMLDivElement\",\n \"options\": {\n \"delay\": 0,\n \"duration\": 400,\n \"easing\": \"cubicOut\",\n \"css\": \"(t, u) => `opacity: ${t}`\"\n },\n \"target_t\": 0\n}",
+ "outputDataExample": "{\n \"animation\": \"Animation\",\n \"playState\": \"running\"\n}"
+ },
+ {
+ "simStepId": "2749951d-3951-40a5-bf47-8dfe061e72bb",
+ "diagramNodeId": "27e39b58-82f8-4932-9307-5d881cdd9dc6",
+ "simStepLabel": "Flow: Animation - Define Animation Directive",
+ "simStepDescription": "A developer adds an `animate:flip` directive to an element that is an immediate child of a keyed `{#each}` block. This instructs Svelte to apply the 'flip' animation whenever the list of items is reordered.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "documentation/docs/03-template-syntax/16-animate.md",
+ "startLine": "9",
+ "endLine": "13",
+ "relevantVariables": [
+ "animate:flip"
+ ]
+ },
+ "inputDataExample": "null",
+ "outputDataExample": "{\n \"file\": \"App.svelte\",\n \"content\": \"{#each list as item (item.id)}
{item.name}
{/each}\"\n}"
+ },
+ {
+ "simStepId": "2e952827-bf14-484b-9fc6-ede0b3c1dedc",
+ "diagramNodeId": "4b5ee5bc-6f4f-4563-911c-16f7483ca9ae",
+ "simStepLabel": "Flow: Animation - Code Compilation",
+ "simStepDescription": "The Svelte component code containing the `animate:` directive is passed to the Svelte compiler.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/index.js",
+ "startLine": "301",
+ "endLine": "301",
+ "relevantVariables": [
+ "compile"
+ ]
+ },
+ "inputDataExample": "{\n \"file\": \"App.svelte\",\n \"content\": \"{#each list as item (item.id)}
{item.name}
{/each}\"\n}",
+ "outputDataExample": "{\n \"file\": \"App.svelte\",\n \"content\": \"{#each list as item (item.id)}
{item.name}
{/each}\"\n}"
+ },
+ {
+ "simStepId": "32ac57eb-f41c-4d55-997a-2f8fb41f5d54",
+ "diagramNodeId": "eba902bd-338b-4c7a-b0fd-65e5d2bdf713",
+ "simStepLabel": "Flow: Animation - Validation and Analysis",
+ "simStepDescription": "During the analysis phase, the compiler validates the `AnimateDirective`. It checks that the element is the direct and only child of a keyed `{#each}` block and that there isn't more than one `animate` directive on the element. If the validation fails, it throws a specific error.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/2-analyze/visitors/shared/element.js",
+ "startLine": "92",
+ "endLine": "108",
+ "relevantVariables": [
+ "AnimateDirective",
+ "e.animation_invalid_placement",
+ "e.animation_missing_key"
+ ]
+ },
+ "inputDataExample": "{\n \"type\": \"AnimateDirective\",\n \"name\": \"flip\"\n}",
+ "outputDataExample": "{\n \"type\": \"AnimateDirective\",\n \"name\": \"flip\",\n \"isValid\": true\n}"
+ },
+ {
+ "simStepId": "3faa89ae-38d1-4873-a171-ee200778898b",
+ "diagramNodeId": "bcc95282-0c08-4527-9b9d-0b1f3ba0cb67",
+ "simStepLabel": "Flow: Animation - AST to Transformer",
+ "simStepDescription": "The validated AST, which includes the `AnimateDirective` node, is sent to the code transformation phase to be converted into JavaScript.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/2-analyze/index.js",
+ "startLine": "237",
+ "endLine": "237",
+ "relevantVariables": [
+ "walk"
+ ]
+ },
+ "inputDataExample": "{\n \"type\": \"AnimateDirective\",\n \"name\": \"flip\",\n \"isValid\": true\n}",
+ "outputDataExample": "{\n \"type\": \"AnimateDirective\",\n \"name\": \"flip\",\n \"isValid\": true\n}"
+ },
+ {
+ "simStepId": "454afc3a-c047-4cee-a583-bc7245205fec",
+ "diagramNodeId": "521c5e61-52fd-4648-8786-6232a89eb9f3",
+ "simStepLabel": "Flow: Animation - Code Generation",
+ "simStepDescription": "The transformer converts the `AnimateDirective` AST node into a call to the Svelte runtime function `$.animation`. This function is responsible for creating and attaching an animation manager to the element at runtime.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/phases/3-transform/client/visitors/AnimateDirective.js",
+ "startLine": "11",
+ "endLine": "29",
+ "relevantVariables": [
+ "AnimateDirective",
+ "$.animation"
+ ]
+ },
+ "inputDataExample": "{\n \"type\": \"AnimateDirective\",\n \"name\": \"flip\"\n}",
+ "outputDataExample": "{\n \"type\": \"CallExpression\",\n \"callee\": {\n \"type\": \"MemberExpression\",\n \"object\": {\"name\": \"$\"},\n \"property\": {\"name\": \"animation\"}\n },\n \"arguments\": [\n {\n \"type\": \"Identifier\",\n \"name\": \"li\"\n },\n {\n \"type\": \"Identifier\",\n \"name\": \"flip\"\n }\n ]\n}"
+ },
+ {
+ "simStepId": "b9ece232-92b4-4a0d-a2a9-ff913bd05c91",
+ "diagramNodeId": "8f088cde-2ffe-4321-94fb-f666e1c65ebd",
+ "simStepLabel": "Flow: Animation - List Reordering",
+ "simStepDescription": "In the browser, an action occurs that reorders the list associated with the `{#each}` block. Svelte's reactivity system detects this change and begins the DOM reconciliation process.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/dom/blocks/each.js",
+ "startLine": "278",
+ "endLine": "301",
+ "relevantVariables": [
+ "update_keyed_each"
+ ]
+ },
+ "inputDataExample": "{\n \"oldList\": [{\"id\": 1, \"name\": \"A\"}, {\"id\": 2, \"name\": \"B\"}],\n \"newList\": [{\"id\": 2, \"name\": \"B\"}, {\"id\": 1, \"name\": \"A\"}]\n}",
+ "outputDataExample": "{\n \"oldList\": [{\"id\": 1, \"name\": \"A\"}, {\"id\": 2, \"name\": \"B\"}],\n \"newList\": [{\"id\": 2, \"name\": \"B\"}, {\"id\": 1, \"name\": \"A\"}]\n}"
+ },
+ {
+ "simStepId": "2f683b42-3a9d-42cd-b039-f5711579fb69",
+ "diagramNodeId": "3c807307-0cfd-4376-9df8-8ec7d14df8da",
+ "simStepLabel": "Flow: Animation - Measure and Apply",
+ "simStepDescription": "Before updating the DOM, the `each` block's reconciliation logic calls the `measure()` method on the animation manager for each moving item to record its starting `DOMRect`. After the DOM is updated, the `apply()` method is called. This method records the ending `DOMRect` and calculates the required transformation.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/dom/elements/transitions.js",
+ "startLine": "100",
+ "endLine": "128",
+ "relevantVariables": [
+ "measure",
+ "apply",
+ "getBoundingClientRect"
+ ]
+ },
+ "inputDataExample": "{\n \"element\": \"HTMLLIElement\"\n}",
+ "outputDataExample": "{\n \"from\": {\"x\": 10, \"y\": 50, \"width\": 100, \"height\": 20},\n \"to\": {\"x\": 10, \"y\": 10, \"width\": 100, \"height\": 20}\n}"
+ },
+ {
+ "simStepId": "60d8531d-56a1-47c8-bf12-4953eb22de64",
+ "diagramNodeId": "ce4687e3-0741-49e7-bee1-7a97a4f901c5",
+ "simStepLabel": "Flow: Animation - Animation Config Generation",
+ "simStepDescription": "The `apply` method calls the `flip` function (from `svelte/animate`), passing it the `from` and `to` rectangles. The `flip` function computes the necessary CSS transform to animate the element from its start to end position and returns an `AnimationConfig` object.",
+ "isEdge": 1,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/animate/index.js",
+ "startLine": "14",
+ "endLine": "57",
+ "relevantVariables": [
+ "flip"
+ ]
+ },
+ "inputDataExample": "{\n \"from\": {\"x\": 10, \"y\": 50, \"width\": 100, \"height\": 20},\n \"to\": {\"x\": 10, \"y\": 10, \"width\": 100, \"height\": 20}\n}",
+ "outputDataExample": "{\n \"delay\": 0,\n \"duration\": 146.9,\n \"easing\": \"cubicOut\",\n \"css\": \"(t, u) => `transform: translate(${u * 0}px, ${u * 40}px) scale(${t + u * 1}, ${t + u * 1});`\"\n}"
+ },
+ {
+ "simStepId": "5d81373e-8cab-4bf7-8e52-0989dd63129b",
+ "diagramNodeId": "85647cef-0ab8-4bec-b047-ec2147a833db",
+ "simStepLabel": "Flow: Animation - Web Animation Execution",
+ "simStepDescription": "The `AnimationConfig` is passed to the internal `animate` helper, which uses the Web Animations API (`element.animate`) to apply the calculated transform, creating a smooth FLIP (First, Last, Invert, Play) animation for the reordered element.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/internal/client/dom/elements/transitions.js",
+ "startLine": "316",
+ "endLine": "461",
+ "relevantVariables": [
+ "animate",
+ "element.animate"
+ ]
+ },
+ "inputDataExample": "{\n \"element\": \"HTMLLIElement\",\n \"options\": {\n \"delay\": 0,\n \"duration\": 146.9,\n \"easing\": \"cubicOut\",\n \"css\": \"(t, u) => `transform: translate(${u * 0}px, ${u * 40}px) scale(1, 1);`\"\n }\n}",
+ "outputDataExample": "{\n \"animation\": \"Animation\",\n \"playState\": \"running\"\n}"
+ }
+ ],
+ "description": "
Svelte makes it easy to add motion to a UI with built-in transition and animation directives
Using directives like transition:fade or in:fly, developers can declaratively apply animations to elements as they enter or leave the DOM, improving the user experience with minimal code
\",\n \"filename\": \"src/App.svelte\",\n \"sourcemap_list\": [ { ... }, { ... } ]\n }\n}"
+ },
+ {
+ "simStepId": "8d4cb3f3-f71c-438b-b1b1-1bd5a5f5f0dc",
+ "diagramNodeId": "571ae89d-0779-4872-aa50-d6ceebc82800",
+ "simStepLabel": "Finalize Result",
+ "simStepDescription": "The `to_processed` method is called on the `PreprocessResult` instance. It combines all the individual sourcemaps generated during each step into a single, final sourcemap that correctly maps the output code all the way back to the original source.",
+ "isEdge": 0,
+ "sourceCodeMapping": {
+ "filePath": "packages/svelte/src/compiler/preprocess/index.js",
+ "startLine": "83",
+ "endLine": "97",
+ "relevantVariables": [
+ "to_processed",
+ "combine_sourcemaps",
+ "this.sourcemap_list",
+ "this.dependencies"
+ ]
+ },
+ "inputDataExample": "{\n \"source\": \"
Svelte includes a preprocessing system that allows developers to use other languages like TypeScript, SCSS, or Pug within their
svelte files
The preprocessor runs before the Svelte compiler, transforming the code into standard JavaScript and CSS, enabling seamless integration with popular development tools and workflows