enya-agent 0.1.0
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/.env.example +20 -0
- package/.github/workflows/ci.yml +70 -0
- package/.github/workflows/publish.yml +250 -0
- package/.gitmodules +3 -0
- package/Cargo.lock +3584 -0
- package/Cargo.toml +97 -0
- package/crates/enact/Cargo.toml +27 -0
- package/crates/enact/src/lib.rs +60 -0
- package/crates/enact-a2a/Cargo.toml +25 -0
- package/crates/enact-a2a/src/lib.rs +411 -0
- package/crates/enact-channels/Cargo.toml +64 -0
- package/crates/enact-channels/examples/README.md +80 -0
- package/crates/enact-channels/examples/channel_bot.rs +169 -0
- package/crates/enact-channels/examples/telegram-echo.rs +34 -0
- package/crates/enact-channels/examples/whatsapp-echo.rs +142 -0
- package/crates/enact-channels/src/config.rs +213 -0
- package/crates/enact-channels/src/lib.rs +25 -0
- package/crates/enact-channels/src/runtime.rs +237 -0
- package/crates/enact-channels/src/security/mod.rs +5 -0
- package/crates/enact-channels/src/security/pairing.rs +205 -0
- package/crates/enact-channels/src/teams.rs +601 -0
- package/crates/enact-channels/src/telegram.rs +2833 -0
- package/crates/enact-channels/src/traits.rs +200 -0
- package/crates/enact-channels/src/webhook.rs +262 -0
- package/crates/enact-channels/src/whatsapp.rs +310 -0
- package/crates/enact-cli/Cargo.toml +40 -0
- package/crates/enact-cli/src/commands/doctor.rs +62 -0
- package/crates/enact-cli/src/commands/mod.rs +3 -0
- package/crates/enact-cli/src/commands/run.rs +69 -0
- package/crates/enact-cli/src/commands/serve.rs +81 -0
- package/crates/enact-cli/src/config.rs +2 -0
- package/crates/enact-cli/src/main.rs +79 -0
- package/crates/enact-config/Cargo.toml +36 -0
- package/crates/enact-config/ENV_VAR_MAPPING.md +135 -0
- package/crates/enact-config/QUICK_REFERENCE.md +92 -0
- package/crates/enact-config/README.md +107 -0
- package/crates/enact-config/TESTING.md +161 -0
- package/crates/enact-config/examples/test-env-vars.rs +100 -0
- package/crates/enact-config/src/config.rs +399 -0
- package/crates/enact-config/src/encrypted_store.rs +211 -0
- package/crates/enact-config/src/lib.rs +298 -0
- package/crates/enact-config/src/secrets.rs +149 -0
- package/crates/enact-config/src/sync.rs +260 -0
- package/crates/enact-config/test-env-vars.sh +34 -0
- package/crates/enact-config/tests/README.md +99 -0
- package/crates/enact-config/tests/config_integration_test.rs +202 -0
- package/crates/enact-config/tests/security_test.rs +140 -0
- package/crates/enact-context/Cargo.toml +41 -0
- package/crates/enact-context/src/budget.rs +314 -0
- package/crates/enact-context/src/calibrator.rs +535 -0
- package/crates/enact-context/src/compactor.rs +392 -0
- package/crates/enact-context/src/condenser.rs +826 -0
- package/crates/enact-context/src/lib.rs +94 -0
- package/crates/enact-context/src/segment.rs +238 -0
- package/crates/enact-context/src/step_context.rs +645 -0
- package/crates/enact-context/src/token_counter.rs +148 -0
- package/crates/enact-context/src/window.rs +372 -0
- package/crates/enact-core/Cargo.toml +42 -0
- package/crates/enact-core/README.md +98 -0
- package/crates/enact-core/src/background/executor.rs +524 -0
- package/crates/enact-core/src/background/mod.rs +48 -0
- package/crates/enact-core/src/background/target_binding.rs +390 -0
- package/crates/enact-core/src/background/trigger.rs +511 -0
- package/crates/enact-core/src/callable/callable.rs +152 -0
- package/crates/enact-core/src/callable/composite.rs +817 -0
- package/crates/enact-core/src/callable/graph.rs +104 -0
- package/crates/enact-core/src/callable/llm.rs +211 -0
- package/crates/enact-core/src/callable/mod.rs +64 -0
- package/crates/enact-core/src/callable/registry.rs +206 -0
- package/crates/enact-core/src/context/execution_context.rs +757 -0
- package/crates/enact-core/src/context/invocation.rs +99 -0
- package/crates/enact-core/src/context/mod.rs +50 -0
- package/crates/enact-core/src/context/tenant.rs +175 -0
- package/crates/enact-core/src/context/trace.rs +127 -0
- package/crates/enact-core/src/flow/conditional.rs +293 -0
- package/crates/enact-core/src/flow/mod.rs +43 -0
- package/crates/enact-core/src/flow/parallel.rs +437 -0
- package/crates/enact-core/src/flow/repeat.rs +534 -0
- package/crates/enact-core/src/flow/sequential.rs +248 -0
- package/crates/enact-core/src/graph/checkpoint.rs +79 -0
- package/crates/enact-core/src/graph/checkpoint_store.rs +76 -0
- package/crates/enact-core/src/graph/compiled.rs +189 -0
- package/crates/enact-core/src/graph/edge.rs +59 -0
- package/crates/enact-core/src/graph/graph_schema.rs +218 -0
- package/crates/enact-core/src/graph/loader.rs +155 -0
- package/crates/enact-core/src/graph/mod.rs +18 -0
- package/crates/enact-core/src/graph/node/function.rs +49 -0
- package/crates/enact-core/src/graph/node/mod.rs +48 -0
- package/crates/enact-core/src/graph/schema.rs +62 -0
- package/crates/enact-core/src/inbox/message.rs +405 -0
- package/crates/enact-core/src/inbox/mod.rs +31 -0
- package/crates/enact-core/src/inbox/store.rs +355 -0
- package/crates/enact-core/src/kernel/artifact/filesystem.rs +546 -0
- package/crates/enact-core/src/kernel/artifact/metadata.rs +283 -0
- package/crates/enact-core/src/kernel/artifact/mod.rs +27 -0
- package/crates/enact-core/src/kernel/artifact/store.rs +427 -0
- package/crates/enact-core/src/kernel/enforcement.rs +1315 -0
- package/crates/enact-core/src/kernel/error.rs +1200 -0
- package/crates/enact-core/src/kernel/event.rs +1394 -0
- package/crates/enact-core/src/kernel/execution_model.rs +831 -0
- package/crates/enact-core/src/kernel/execution_state.rs +189 -0
- package/crates/enact-core/src/kernel/execution_strategy.rs +117 -0
- package/crates/enact-core/src/kernel/ids.rs +2086 -0
- package/crates/enact-core/src/kernel/interrupt.rs +125 -0
- package/crates/enact-core/src/kernel/kernel.rs +1283 -0
- package/crates/enact-core/src/kernel/mod.rs +205 -0
- package/crates/enact-core/src/kernel/persistence/event_store.rs +270 -0
- package/crates/enact-core/src/kernel/persistence/message_store.rs +908 -0
- package/crates/enact-core/src/kernel/persistence/mod.rs +102 -0
- package/crates/enact-core/src/kernel/persistence/state_store.rs +228 -0
- package/crates/enact-core/src/kernel/persistence/vector_store.rs +299 -0
- package/crates/enact-core/src/kernel/reducer.rs +808 -0
- package/crates/enact-core/src/kernel/replay.rs +153 -0
- package/crates/enact-core/src/lib.rs +413 -0
- package/crates/enact-core/src/memory/episodic.rs +0 -0
- package/crates/enact-core/src/memory/mod.rs +6 -0
- package/crates/enact-core/src/memory/semantic.rs +0 -0
- package/crates/enact-core/src/memory/trait.rs +0 -0
- package/crates/enact-core/src/memory/vector_db.rs +0 -0
- package/crates/enact-core/src/memory/working.rs +0 -0
- package/crates/enact-core/src/policy/execution_policy.rs +292 -0
- package/crates/enact-core/src/policy/filters.rs +458 -0
- package/crates/enact-core/src/policy/input_processor.rs +407 -0
- package/crates/enact-core/src/policy/long_running.rs +134 -0
- package/crates/enact-core/src/policy/mod.rs +193 -0
- package/crates/enact-core/src/policy/pii_input.rs +274 -0
- package/crates/enact-core/src/policy/tenant_policy.rs +453 -0
- package/crates/enact-core/src/policy/tool_policy.rs +407 -0
- package/crates/enact-core/src/providers/mod.rs +63 -0
- package/crates/enact-core/src/providers/trait.rs +292 -0
- package/crates/enact-core/src/runner/callbacks.rs +6 -0
- package/crates/enact-core/src/runner/execution_runner.rs +476 -0
- package/crates/enact-core/src/runner/loop.rs +117 -0
- package/crates/enact-core/src/runner/mod.rs +58 -0
- package/crates/enact-core/src/runner/protected_runner.rs +280 -0
- package/crates/enact-core/src/signal/inmemory.rs +231 -0
- package/crates/enact-core/src/signal/mod.rs +108 -0
- package/crates/enact-core/src/streaming/event_logger.rs +195 -0
- package/crates/enact-core/src/streaming/event_stream.rs +1423 -0
- package/crates/enact-core/src/streaming/mod.rs +108 -0
- package/crates/enact-core/src/streaming/pause_cancel.rs +0 -0
- package/crates/enact-core/src/streaming/protected_emitter.rs +173 -0
- package/crates/enact-core/src/streaming/protection/context.rs +136 -0
- package/crates/enact-core/src/streaming/protection/encryption.rs +289 -0
- package/crates/enact-core/src/streaming/protection/mod.rs +43 -0
- package/crates/enact-core/src/streaming/protection/pii_protection.rs +243 -0
- package/crates/enact-core/src/streaming/protection/processor.rs +166 -0
- package/crates/enact-core/src/streaming/sse.rs +0 -0
- package/crates/enact-core/src/telemetry/exporter.rs +0 -0
- package/crates/enact-core/src/telemetry/init.rs +0 -0
- package/crates/enact-core/src/telemetry/mod.rs +49 -0
- package/crates/enact-core/src/telemetry/spans.rs +245 -0
- package/crates/enact-core/src/tool/agent_tool.rs +177 -0
- package/crates/enact-core/src/tool/browser/mod.rs +0 -0
- package/crates/enact-core/src/tool/browser/webdriver.rs +0 -0
- package/crates/enact-core/src/tool/cost.rs +247 -0
- package/crates/enact-core/src/tool/discovery.rs +0 -0
- package/crates/enact-core/src/tool/dispatcher.rs +347 -0
- package/crates/enact-core/src/tool/filesystem.rs +231 -0
- package/crates/enact-core/src/tool/function.rs +99 -0
- package/crates/enact-core/src/tool/git.rs +162 -0
- package/crates/enact-core/src/tool/http.rs +214 -0
- package/crates/enact-core/src/tool/mcp/client.rs +0 -0
- package/crates/enact-core/src/tool/mcp/mod.rs +0 -0
- package/crates/enact-core/src/tool/mod.rs +51 -0
- package/crates/enact-core/src/tool/reasoning/debugging.rs +0 -0
- package/crates/enact-core/src/tool/reasoning/mcts.rs +0 -0
- package/crates/enact-core/src/tool/reasoning/mod.rs +0 -0
- package/crates/enact-core/src/tool/reasoning/sequential.rs +0 -0
- package/crates/enact-core/src/tool/sandbox/dagger.rs +0 -0
- package/crates/enact-core/src/tool/sandbox/mod.rs +0 -0
- package/crates/enact-core/src/tool/shell.rs +147 -0
- package/crates/enact-core/src/tool/trait.rs +33 -0
- package/crates/enact-core/src/tool/web_search.rs +277 -0
- package/crates/enact-core/src/util/config.rs +0 -0
- package/crates/enact-core/src/util/errors.rs +0 -0
- package/crates/enact-core/src/util/mod.rs +6 -0
- package/crates/enact-core/tests/airgapped_e2e_test.rs +291 -0
- package/crates/enact-core/tests/e2e_agentic_loop.rs +119 -0
- package/crates/enact-core/tests/e2e_test.rs +259 -0
- package/crates/enact-core/tests/graph_test.rs +130 -0
- package/crates/enact-core/tests/stream_event_id_validation.rs +435 -0
- package/crates/enact-cron/Cargo.toml +28 -0
- package/crates/enact-cron/src/lib.rs +44 -0
- package/crates/enact-cron/src/schedule.rs +156 -0
- package/crates/enact-cron/src/store.rs +589 -0
- package/crates/enact-cron/src/types.rs +148 -0
- package/crates/enact-gateway/Cargo.toml +31 -0
- package/crates/enact-gateway/README.md +30 -0
- package/crates/enact-gateway/examples/whatsapp-gateway-runner-mock.rs +59 -0
- package/crates/enact-gateway/examples/whatsapp-gateway.rs +42 -0
- package/crates/enact-gateway/src/lib.rs +582 -0
- package/crates/enact-mcp/Cargo.toml +24 -0
- package/crates/enact-mcp/src/lib.rs +178 -0
- package/crates/enact-memory/Cargo.toml +25 -0
- package/crates/enact-memory/src/backend.rs +20 -0
- package/crates/enact-memory/src/chunker.rs +230 -0
- package/crates/enact-memory/src/embeddings.rs +221 -0
- package/crates/enact-memory/src/lib.rs +67 -0
- package/crates/enact-memory/src/markdown.rs +127 -0
- package/crates/enact-memory/src/none.rs +61 -0
- package/crates/enact-memory/src/sqlite.rs +276 -0
- package/crates/enact-memory/src/traits.rs +65 -0
- package/crates/enact-memory/src/vector.rs +198 -0
- package/crates/enact-oauth/Cargo.toml +27 -0
- package/crates/enact-oauth/src/lib.rs +584 -0
- package/crates/enact-observability/Cargo.toml +22 -0
- package/crates/enact-observability/src/lib.rs +197 -0
- package/crates/enact-providers/Cargo.toml +33 -0
- package/crates/enact-providers/examples/hello-agent.rs +33 -0
- package/crates/enact-providers/src/anthropic.rs +182 -0
- package/crates/enact-providers/src/azure.rs +96 -0
- package/crates/enact-providers/src/bridge.rs +221 -0
- package/crates/enact-providers/src/gemini.rs +227 -0
- package/crates/enact-providers/src/http.rs +78 -0
- package/crates/enact-providers/src/lib.rs +53 -0
- package/crates/enact-providers/src/openai_compatible.rs +167 -0
- package/crates/enact-providers/src/openrouter.rs +33 -0
- package/crates/enact-runner/Cargo.toml +24 -0
- package/crates/enact-runner/README.md +76 -0
- package/crates/enact-runner/src/compaction.rs +225 -0
- package/crates/enact-runner/src/config.rs +118 -0
- package/crates/enact-runner/src/lib.rs +63 -0
- package/crates/enact-runner/src/loop_driver.rs +414 -0
- package/crates/enact-runner/src/parser.rs +421 -0
- package/crates/enact-runner/src/retry.rs +262 -0
- package/crates/enact-runner/tests/integration.rs +278 -0
- package/crates/enact-security/Cargo.toml +22 -0
- package/crates/enact-security/src/audit.rs +375 -0
- package/crates/enact-security/src/lib.rs +37 -0
- package/crates/enact-security/src/policy.rs +406 -0
- package/crates/enact-skills/Cargo.toml +25 -0
- package/crates/enact-skills/src/lib.rs +506 -0
- package/crates/enact-tools/Cargo.toml +22 -0
- package/crates/enact-tools/src/file_read.rs +166 -0
- package/crates/enact-tools/src/file_write.rs +216 -0
- package/crates/enact-tools/src/git_operations.rs +513 -0
- package/crates/enact-tools/src/http_request.rs +417 -0
- package/crates/enact-tools/src/lib.rs +104 -0
- package/crates/enact-tools/src/security.rs +227 -0
- package/crates/enact-tools/src/shell.rs +191 -0
- package/crates/enact-tools/src/traits.rs +159 -0
- package/docs/Makefile +74 -0
- package/docs/config.toml +62 -0
- package/docs/content/_index.md +174 -0
- package/docs/content/a2a/_index.md +431 -0
- package/docs/content/api/_index.md +323 -0
- package/docs/content/channels/_index.md +160 -0
- package/docs/content/channels/teams.md +205 -0
- package/docs/content/channels/telegram.md +182 -0
- package/docs/content/channels/webhook.md +423 -0
- package/docs/content/channels/whatsapp.md +240 -0
- package/docs/content/cli/_index.md +261 -0
- package/docs/content/concepts/_index.md +273 -0
- package/docs/content/configuration/_index.md +241 -0
- package/docs/content/cron/_index.md +248 -0
- package/docs/content/developers/_index.md +278 -0
- package/docs/content/getting-started/_index.md +180 -0
- package/docs/content/installation/_index.md +186 -0
- package/docs/content/installation/uninstall.md +101 -0
- package/docs/content/installation/updating.md +120 -0
- package/docs/content/mcp/_index.md +215 -0
- package/docs/content/memory/_index.md +163 -0
- package/docs/content/oauth/_index.md +515 -0
- package/docs/content/providers/_index.md +206 -0
- package/docs/content/roadmap/_index.md +199 -0
- package/docs/content/security/_index.md +219 -0
- package/docs/content/skills/_index.md +228 -0
- package/docs/content/tools/_index.md +485 -0
- package/docs/content/troubleshooting/_index.md +259 -0
- package/docs/content/yaml-schema/_index.md +294 -0
- package/docs/static/giallo-dark.css +91 -0
- package/docs/static/giallo-light.css +91 -0
- package/docs/themes/tanuki/.github/workflows/deploy.yml +44 -0
- package/docs/themes/tanuki/LICENSE +21 -0
- package/docs/themes/tanuki/README.md +166 -0
- package/docs/themes/tanuki/examples/blog/config.toml +58 -0
- package/docs/themes/tanuki/examples/blog/content/_index.md +4 -0
- package/docs/themes/tanuki/examples/blog/content/about.md +33 -0
- package/docs/themes/tanuki/examples/blog/content/blog/_index.md +7 -0
- package/docs/themes/tanuki/examples/blog/content/blog/api-design-best-practices.md +245 -0
- package/docs/themes/tanuki/examples/blog/content/blog/building-accessible-websites.md +147 -0
- package/docs/themes/tanuki/examples/blog/content/blog/css-grid-vs-flexbox.md +165 -0
- package/docs/themes/tanuki/examples/blog/content/blog/customizing-catppuccin-colors.md +137 -0
- package/docs/themes/tanuki/examples/blog/content/blog/dark-mode-best-practices.md +82 -0
- package/docs/themes/tanuki/examples/blog/content/blog/docker-essentials.md +301 -0
- package/docs/themes/tanuki/examples/blog/content/blog/getting-started-with-zola.md +129 -0
- package/docs/themes/tanuki/examples/blog/content/blog/git-workflow-for-content.md +112 -0
- package/docs/themes/tanuki/examples/blog/content/blog/introduction-to-webassembly.md +183 -0
- package/docs/themes/tanuki/examples/blog/content/blog/modern-javascript-features.md +234 -0
- package/docs/themes/tanuki/examples/blog/content/blog/testing-strategies.md +311 -0
- package/docs/themes/tanuki/examples/blog/content/blog/typography-for-developers.md +104 -0
- package/docs/themes/tanuki/examples/blog/content/blog/welcome-to-tanuki.md +67 -0
- package/docs/themes/tanuki/examples/blog/content/blog/why-static-sites.md +85 -0
- package/docs/themes/tanuki/examples/blog/content/projects.md +64 -0
- package/docs/themes/tanuki/examples/book/config.toml +17 -0
- package/docs/themes/tanuki/examples/book/content/_index.md +12 -0
- package/docs/themes/tanuki/examples/book/content/chapter-1.md +90 -0
- package/docs/themes/tanuki/examples/book/content/chapter-2.md +143 -0
- package/docs/themes/tanuki/examples/book/content/chapter-3.md +217 -0
- package/docs/themes/tanuki/examples/book/content/chapter-4.md +224 -0
- package/docs/themes/tanuki/examples/book/content/chapter-5.md +297 -0
- package/docs/themes/tanuki/examples/book/content/print.md +6 -0
- package/docs/themes/tanuki/examples/docs/config.toml +28 -0
- package/docs/themes/tanuki/examples/docs/content/_index.md +20 -0
- package/docs/themes/tanuki/examples/docs/content/components.md +156 -0
- package/docs/themes/tanuki/examples/docs/content/configuration.md +94 -0
- package/docs/themes/tanuki/examples/docs/content/customization.md +202 -0
- package/docs/themes/tanuki/examples/docs/content/deployment.md +204 -0
- package/docs/themes/tanuki/examples/docs/content/installation.md +59 -0
- package/docs/themes/tanuki/examples/docs/content/print.md +6 -0
- package/docs/themes/tanuki/examples/docs/static/img/tanuki-icon.avif +0 -0
- package/docs/themes/tanuki/examples/index.html +2104 -0
- package/docs/themes/tanuki/mise.toml +108 -0
- package/docs/themes/tanuki/sass/base/_catppuccin.scss +164 -0
- package/docs/themes/tanuki/sass/base/_fonts.scss +64 -0
- package/docs/themes/tanuki/sass/base/_reset.scss +152 -0
- package/docs/themes/tanuki/sass/base/_typography.scss +523 -0
- package/docs/themes/tanuki/sass/components/_buttons.scss +209 -0
- package/docs/themes/tanuki/sass/components/_code.scss +457 -0
- package/docs/themes/tanuki/sass/components/_landing.scss +633 -0
- package/docs/themes/tanuki/sass/components/_layout.scss +294 -0
- package/docs/themes/tanuki/sass/components/_navigation.scss +1200 -0
- package/docs/themes/tanuki/sass/components/_print.scss +237 -0
- package/docs/themes/tanuki/sass/components/_search.scss +224 -0
- package/docs/themes/tanuki/sass/components/_sidebar.scss +473 -0
- package/docs/themes/tanuki/sass/components/_theme-toggle.scss +186 -0
- package/docs/themes/tanuki/sass/modes/_blog.scss +366 -0
- package/docs/themes/tanuki/sass/modes/_product.scss +875 -0
- package/docs/themes/tanuki/sass/modes/_raskell.scss +1696 -0
- package/docs/themes/tanuki/sass/patterns/_buttons.scss +183 -0
- package/docs/themes/tanuki/sass/patterns/_cards.scss +144 -0
- package/docs/themes/tanuki/sass/patterns/_index.scss +9 -0
- package/docs/themes/tanuki/sass/patterns/_lists.scss +259 -0
- package/docs/themes/tanuki/sass/patterns/_sections.scss +243 -0
- package/docs/themes/tanuki/sass/style.scss +47 -0
- package/docs/themes/tanuki/sass/tokens/_colors.scss +139 -0
- package/docs/themes/tanuki/sass/tokens/_spacing.scss +100 -0
- package/docs/themes/tanuki/sass/tokens/_typography.scss +186 -0
- package/docs/themes/tanuki/screenshot.png +0 -0
- package/docs/themes/tanuki/sentinel.kdl +59 -0
- package/docs/themes/tanuki/static/elasticlunr.min.js +10 -0
- package/docs/themes/tanuki/static/fonts/GEIST-LICENSE.txt +92 -0
- package/docs/themes/tanuki/static/fonts/Geist-Variable.woff2 +0 -0
- package/docs/themes/tanuki/static/fonts/GeistMono-Variable.woff2 +0 -0
- package/docs/themes/tanuki/static/img/tanuki-icon.avif +0 -0
- package/docs/themes/tanuki/static/img/tanuki-icon.png +0 -0
- package/docs/themes/tanuki/static/js/anchors.js +18 -0
- package/docs/themes/tanuki/static/js/app.js +274 -0
- package/docs/themes/tanuki/static/js/code.js +394 -0
- package/docs/themes/tanuki/static/js/navigation.js +778 -0
- package/docs/themes/tanuki/static/js/scroll-to-top.js +33 -0
- package/docs/themes/tanuki/static/js/search-raskell.js +240 -0
- package/docs/themes/tanuki/static/js/search.js +215 -0
- package/docs/themes/tanuki/static/js/theme.js +169 -0
- package/docs/themes/tanuki/static/syntax-dark.css +151 -0
- package/docs/themes/tanuki/static/syntax-light.css +151 -0
- package/docs/themes/tanuki/static/wasm/sentinel_playground_wasm.js +486 -0
- package/docs/themes/tanuki/static/wasm/sentinel_playground_wasm_bg.wasm +0 -0
- package/docs/themes/tanuki/templates/404.html +52 -0
- package/docs/themes/tanuki/templates/base.html +428 -0
- package/docs/themes/tanuki/templates/blog.html +66 -0
- package/docs/themes/tanuki/templates/home.html +108 -0
- package/docs/themes/tanuki/templates/index.html +178 -0
- package/docs/themes/tanuki/templates/landing.html +168 -0
- package/docs/themes/tanuki/templates/macros/nav.html +128 -0
- package/docs/themes/tanuki/templates/macros/posts.html +101 -0
- package/docs/themes/tanuki/templates/macros/ui.html +159 -0
- package/docs/themes/tanuki/templates/page.html +135 -0
- package/docs/themes/tanuki/templates/partials/footer.html +38 -0
- package/docs/themes/tanuki/templates/partials/header.html +366 -0
- package/docs/themes/tanuki/templates/partials/nav-buttons.html +55 -0
- package/docs/themes/tanuki/templates/partials/nav-overlay.html +81 -0
- package/docs/themes/tanuki/templates/partials/page-toc-panel.html +43 -0
- package/docs/themes/tanuki/templates/partials/search.html +52 -0
- package/docs/themes/tanuki/templates/partials/sidebar.html +107 -0
- package/docs/themes/tanuki/templates/partials/theme-toggle.html +35 -0
- package/docs/themes/tanuki/templates/partials/toc-overlay.html +146 -0
- package/docs/themes/tanuki/templates/partials/version-picker.html +38 -0
- package/docs/themes/tanuki/templates/print.html +244 -0
- package/docs/themes/tanuki/templates/section.html +186 -0
- package/docs/themes/tanuki/templates/taxonomy_list.html +18 -0
- package/docs/themes/tanuki/templates/taxonomy_single.html +31 -0
- package/docs/themes/tanuki/theme.toml +58 -0
- package/examples/hello-agent.rs +55 -0
- package/package.json +36 -0
- package/proto/config.proto +60 -0
- package/proto/events.proto +0 -0
- package/proto/runtime.proto +215 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
+++
|
|
2
|
+
title = "Why Static Sites Are Making a Comeback"
|
|
3
|
+
description = "Static site generators are more popular than ever. Here's why developers are choosing them over traditional CMS platforms."
|
|
4
|
+
date = 2024-12-18
|
|
5
|
+
[taxonomies]
|
|
6
|
+
tags = ["static-sites", "performance", "security"]
|
|
7
|
+
+++
|
|
8
|
+
|
|
9
|
+
# Why Static Sites Are Making a Comeback
|
|
10
|
+
|
|
11
|
+
In an era of complex web applications, static sites are experiencing a renaissance. Here's why.
|
|
12
|
+
|
|
13
|
+
## Performance
|
|
14
|
+
|
|
15
|
+
Static sites are *fast*. There's no database to query, no server-side rendering to wait for. Your HTML, CSS, and JavaScript are served directly from a CDN, often in under 100ms.
|
|
16
|
+
|
|
17
|
+
Compare this to a typical WordPress site that might take 2-3 seconds to generate a page.
|
|
18
|
+
|
|
19
|
+
## Security
|
|
20
|
+
|
|
21
|
+
With no database and no server-side code, the attack surface shrinks dramatically:
|
|
22
|
+
|
|
23
|
+
- No SQL injection
|
|
24
|
+
- No server-side vulnerabilities
|
|
25
|
+
- No CMS to keep patched
|
|
26
|
+
|
|
27
|
+
Your site is essentially a folder of files. There's nothing to hack.
|
|
28
|
+
|
|
29
|
+
## Cost
|
|
30
|
+
|
|
31
|
+
Static hosting is cheap—often free:
|
|
32
|
+
|
|
33
|
+
- **GitHub Pages**: Free
|
|
34
|
+
- **Cloudflare Pages**: Free
|
|
35
|
+
- **Netlify**: Free tier available
|
|
36
|
+
- **Vercel**: Free tier available
|
|
37
|
+
|
|
38
|
+
No server to maintain. No database to pay for. No DevOps headaches.
|
|
39
|
+
|
|
40
|
+
## Developer Experience
|
|
41
|
+
|
|
42
|
+
Modern static site generators like Zola, Hugo, and Eleventy offer:
|
|
43
|
+
|
|
44
|
+
- **Hot reload** during development
|
|
45
|
+
- **Markdown** for content
|
|
46
|
+
- **Git-based workflows** for versioning
|
|
47
|
+
- **Build previews** for pull requests
|
|
48
|
+
|
|
49
|
+
## When Static Doesn't Work
|
|
50
|
+
|
|
51
|
+
Static sites aren't for everything. You'll still need a server for:
|
|
52
|
+
|
|
53
|
+
- User authentication
|
|
54
|
+
- Real-time features
|
|
55
|
+
- Dynamic content that changes per-user
|
|
56
|
+
|
|
57
|
+
But for blogs, documentation, marketing sites, and portfolios? Static is hard to beat.
|
|
58
|
+
|
|
59
|
+
## The JAMstack Approach
|
|
60
|
+
|
|
61
|
+
The JAMstack (JavaScript, APIs, Markup) architecture extends static sites with:
|
|
62
|
+
|
|
63
|
+
- Client-side JavaScript for interactivity
|
|
64
|
+
- Third-party APIs for dynamic features
|
|
65
|
+
- Pre-rendered markup for speed
|
|
66
|
+
|
|
67
|
+
This gives you the best of both worlds: static performance with dynamic capabilities.
|
|
68
|
+
|
|
69
|
+
## Getting Started
|
|
70
|
+
|
|
71
|
+
Ready to try static? Zola is a great starting point:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Install Zola
|
|
75
|
+
brew install zola
|
|
76
|
+
|
|
77
|
+
# Create a new site
|
|
78
|
+
zola init my-site
|
|
79
|
+
cd my-site
|
|
80
|
+
|
|
81
|
+
# Start the dev server
|
|
82
|
+
zola serve
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The future is static—and it's faster than ever.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
+++
|
|
2
|
+
title = "Projects"
|
|
3
|
+
description = "Things I've built and contributed to."
|
|
4
|
+
template = "page.html"
|
|
5
|
+
path = "projects"
|
|
6
|
+
+++
|
|
7
|
+
|
|
8
|
+
# Projects
|
|
9
|
+
|
|
10
|
+
A selection of projects I've worked on—both personal experiments and contributions to open source.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Tanuki Theme
|
|
15
|
+
|
|
16
|
+
A modern, flexible theme for Zola with support for documentation, e-books, and blogs.
|
|
17
|
+
|
|
18
|
+
- **Stack**: Zola, Sass, JavaScript
|
|
19
|
+
- **Features**: Dark/light themes, search, responsive design
|
|
20
|
+
- [View on GitHub](https://github.com/raskell-io/tanuki)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## CLI Task Runner
|
|
25
|
+
|
|
26
|
+
A fast, parallel task runner written in Rust for managing development workflows.
|
|
27
|
+
|
|
28
|
+
- **Stack**: Rust, TOML
|
|
29
|
+
- **Features**: Parallel execution, file watching, task dependencies
|
|
30
|
+
- [View on GitHub](https://github.com/example/taskrunner)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## React Component Library
|
|
35
|
+
|
|
36
|
+
A collection of accessible, themeable React components for building consistent UIs.
|
|
37
|
+
|
|
38
|
+
- **Stack**: React, TypeScript, Storybook
|
|
39
|
+
- **Features**: WAI-ARIA compliant, customizable themes, tree-shakeable
|
|
40
|
+
- [View on GitHub](https://github.com/example/components)
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Markdown Note App
|
|
45
|
+
|
|
46
|
+
A minimalist note-taking app with Markdown support and local-first storage.
|
|
47
|
+
|
|
48
|
+
- **Stack**: Electron, React, SQLite
|
|
49
|
+
- **Features**: Offline-first, full-text search, sync optional
|
|
50
|
+
- [View on GitHub](https://github.com/example/notes)
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Open Source Contributions
|
|
55
|
+
|
|
56
|
+
I also contribute to projects I use and care about:
|
|
57
|
+
|
|
58
|
+
- **Zola** - Static site generator (documentation, bug fixes)
|
|
59
|
+
- **Catppuccin** - Color palette (theme ports)
|
|
60
|
+
- **Various Rust crates** - Bug fixes and features
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
*Interested in collaborating? [Get in touch](/about).*
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Tanuki Theme - Book Mode Example
|
|
2
|
+
base_url = "/tanuki/book"
|
|
3
|
+
title = "The Tanuki Guide"
|
|
4
|
+
description = "E-book example for the Tanuki theme"
|
|
5
|
+
theme = "tanuki"
|
|
6
|
+
compile_sass = true
|
|
7
|
+
build_search_index = true
|
|
8
|
+
generate_feeds = false
|
|
9
|
+
|
|
10
|
+
[markdown]
|
|
11
|
+
highlight_code = true
|
|
12
|
+
highlight_theme = "base16-ocean-dark"
|
|
13
|
+
|
|
14
|
+
[extra]
|
|
15
|
+
mode = "book"
|
|
16
|
+
github = "https://github.com/raskell-io/tanuki"
|
|
17
|
+
show_theme_toggle = true
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
+++
|
|
2
|
+
title = "The Art of Web Development"
|
|
3
|
+
description = "A comprehensive guide to building modern web applications."
|
|
4
|
+
sort_by = "weight"
|
|
5
|
+
template = "section.html"
|
|
6
|
+
+++
|
|
7
|
+
|
|
8
|
+
# The Art of Web Development
|
|
9
|
+
|
|
10
|
+
A comprehensive guide to building modern, accessible, and performant web applications.
|
|
11
|
+
|
|
12
|
+
This book takes you from the fundamentals of HTML, CSS, and JavaScript through to advanced topics like performance optimization, accessibility, and deployment strategies.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
+++
|
|
2
|
+
title = "Chapter 1: The Foundation"
|
|
3
|
+
description = "Understanding the core technologies of the web."
|
|
4
|
+
weight = 1
|
|
5
|
+
+++
|
|
6
|
+
|
|
7
|
+
# Chapter 1: The Foundation
|
|
8
|
+
|
|
9
|
+
Before we build castles in the sky, we must first understand the ground beneath our feet. The web is built on three fundamental technologies: HTML, CSS, and JavaScript. Each plays a crucial role in creating the experiences we use every day.
|
|
10
|
+
|
|
11
|
+
## The Triad of Web Technologies
|
|
12
|
+
|
|
13
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.
|
|
14
|
+
|
|
15
|
+
### HTML: The Structure
|
|
16
|
+
|
|
17
|
+
HTML (HyperText Markup Language) provides the semantic structure of web pages. Think of it as the skeleton of your website—the bones that give it shape and meaning.
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<!DOCTYPE html>
|
|
21
|
+
<html lang="en">
|
|
22
|
+
<head>
|
|
23
|
+
<meta charset="UTF-8">
|
|
24
|
+
<title>My First Page</title>
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
<header>
|
|
28
|
+
<h1>Welcome</h1>
|
|
29
|
+
</header>
|
|
30
|
+
<main>
|
|
31
|
+
<p>Hello, World!</p>
|
|
32
|
+
</main>
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.
|
|
38
|
+
|
|
39
|
+
### CSS: The Style
|
|
40
|
+
|
|
41
|
+
CSS (Cascading Style Sheets) controls the visual presentation. It's the skin, the clothes, the paint on the walls—everything that makes your site visually appealing.
|
|
42
|
+
|
|
43
|
+
```css
|
|
44
|
+
body {
|
|
45
|
+
font-family: system-ui, sans-serif;
|
|
46
|
+
line-height: 1.6;
|
|
47
|
+
color: #333;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
h1 {
|
|
51
|
+
color: #1e40af;
|
|
52
|
+
font-size: 2.5rem;
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.
|
|
57
|
+
|
|
58
|
+
### JavaScript: The Behavior
|
|
59
|
+
|
|
60
|
+
JavaScript brings interactivity to the web. It's the muscles and nervous system—the parts that let your site respond and react.
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
document.querySelector('button').addEventListener('click', () => {
|
|
64
|
+
console.log('Button clicked!');
|
|
65
|
+
alert('Hello, interactive web!');
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## The Document Object Model
|
|
70
|
+
|
|
71
|
+
The DOM is the bridge between your HTML and JavaScript. It represents your page as a tree of objects that can be manipulated programmatically.
|
|
72
|
+
|
|
73
|
+
| Concept | Description |
|
|
74
|
+
|---------|-------------|
|
|
75
|
+
| Node | Any point in the DOM tree |
|
|
76
|
+
| Element | An HTML element node |
|
|
77
|
+
| Attribute | Properties of elements |
|
|
78
|
+
| Text | Text content within elements |
|
|
79
|
+
|
|
80
|
+
## Summary
|
|
81
|
+
|
|
82
|
+
In this chapter, we explored:
|
|
83
|
+
|
|
84
|
+
- The three core technologies: HTML, CSS, and JavaScript
|
|
85
|
+
- How each technology contributes to the web experience
|
|
86
|
+
- The basics of the Document Object Model
|
|
87
|
+
|
|
88
|
+
> **Key Insight**: Understanding these fundamentals deeply will make you a better developer. Don't rush past the basics—they're the foundation everything else is built upon.
|
|
89
|
+
|
|
90
|
+
In the next chapter, we'll dive deeper into modern CSS and explore the powerful layout systems available to us today.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
+++
|
|
2
|
+
title = "Chapter 2: Modern CSS"
|
|
3
|
+
description = "Exploring Flexbox, Grid, and modern CSS features."
|
|
4
|
+
weight = 2
|
|
5
|
+
+++
|
|
6
|
+
|
|
7
|
+
# Chapter 2: Modern CSS
|
|
8
|
+
|
|
9
|
+
CSS has evolved dramatically over the past decade. Gone are the days of float-based layouts and clearfix hacks. Today, we have powerful tools like Flexbox and Grid that make complex layouts straightforward.
|
|
10
|
+
|
|
11
|
+
## The Flexbox Revolution
|
|
12
|
+
|
|
13
|
+
Flexbox (Flexible Box Layout) is designed for one-dimensional layouts—either rows or columns. It excels at distributing space and aligning items.
|
|
14
|
+
|
|
15
|
+
```css
|
|
16
|
+
.container {
|
|
17
|
+
display: flex;
|
|
18
|
+
justify-content: space-between;
|
|
19
|
+
align-items: center;
|
|
20
|
+
gap: 1rem;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.item {
|
|
24
|
+
flex: 1;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Flex Direction and Wrapping
|
|
29
|
+
|
|
30
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. The `flex-direction` property controls the main axis:
|
|
31
|
+
|
|
32
|
+
```css
|
|
33
|
+
.row { flex-direction: row; } /* Default: left to right */
|
|
34
|
+
.column { flex-direction: column; } /* Top to bottom */
|
|
35
|
+
.row-reverse { flex-direction: row-reverse; }
|
|
36
|
+
.column-reverse { flex-direction: column-reverse; }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Nulla facilisi. Sed euismod, nisl nec ultricies lacinia, nisl nisl aliquam nisl, eget aliquam nisl nisl sit amet nisl.
|
|
40
|
+
|
|
41
|
+
## CSS Grid: Two-Dimensional Layouts
|
|
42
|
+
|
|
43
|
+
Grid Layout is the answer to two-dimensional layouts. It handles both rows and columns simultaneously.
|
|
44
|
+
|
|
45
|
+
```css
|
|
46
|
+
.grid-container {
|
|
47
|
+
display: grid;
|
|
48
|
+
grid-template-columns: repeat(3, 1fr);
|
|
49
|
+
grid-template-rows: auto 1fr auto;
|
|
50
|
+
gap: 2rem;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.header { grid-column: 1 / -1; }
|
|
54
|
+
.sidebar { grid-row: 2 / 3; }
|
|
55
|
+
.main { grid-column: 2 / 4; }
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Grid Template Areas
|
|
59
|
+
|
|
60
|
+
For complex layouts, named grid areas provide clarity:
|
|
61
|
+
|
|
62
|
+
```css
|
|
63
|
+
.layout {
|
|
64
|
+
display: grid;
|
|
65
|
+
grid-template-areas:
|
|
66
|
+
"header header header"
|
|
67
|
+
"sidebar main main"
|
|
68
|
+
"footer footer footer";
|
|
69
|
+
grid-template-columns: 200px 1fr 1fr;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.header { grid-area: header; }
|
|
73
|
+
.sidebar { grid-area: sidebar; }
|
|
74
|
+
.main { grid-area: main; }
|
|
75
|
+
.footer { grid-area: footer; }
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Custom Properties (CSS Variables)
|
|
79
|
+
|
|
80
|
+
CSS Custom Properties bring the power of variables to stylesheets:
|
|
81
|
+
|
|
82
|
+
```css
|
|
83
|
+
:root {
|
|
84
|
+
--color-primary: #3b82f6;
|
|
85
|
+
--color-secondary: #10b981;
|
|
86
|
+
--spacing-unit: 8px;
|
|
87
|
+
--border-radius: 4px;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.button {
|
|
91
|
+
background: var(--color-primary);
|
|
92
|
+
padding: calc(var(--spacing-unit) * 2);
|
|
93
|
+
border-radius: var(--border-radius);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Dynamic Theming
|
|
98
|
+
|
|
99
|
+
Variables can be changed at runtime with JavaScript:
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
document.documentElement.style.setProperty('--color-primary', '#8b5cf6');
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Or scoped to specific elements:
|
|
106
|
+
|
|
107
|
+
```css
|
|
108
|
+
.dark-theme {
|
|
109
|
+
--color-background: #1a1a2e;
|
|
110
|
+
--color-text: #eaeaea;
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Container Queries
|
|
115
|
+
|
|
116
|
+
The newest addition to responsive design—container queries let you style based on parent size, not viewport:
|
|
117
|
+
|
|
118
|
+
```css
|
|
119
|
+
.card-container {
|
|
120
|
+
container-type: inline-size;
|
|
121
|
+
container-name: card;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@container card (min-width: 400px) {
|
|
125
|
+
.card {
|
|
126
|
+
display: flex;
|
|
127
|
+
flex-direction: row;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Summary
|
|
133
|
+
|
|
134
|
+
Modern CSS provides powerful tools for layout and styling:
|
|
135
|
+
|
|
136
|
+
- **Flexbox** for one-dimensional layouts
|
|
137
|
+
- **Grid** for two-dimensional layouts
|
|
138
|
+
- **Custom Properties** for maintainable, themeable CSS
|
|
139
|
+
- **Container Queries** for component-based responsive design
|
|
140
|
+
|
|
141
|
+
> **Pro Tip**: Don't choose between Flexbox and Grid—use both! Grid for page layouts, Flexbox for component internals.
|
|
142
|
+
|
|
143
|
+
Next, we'll explore JavaScript in depth and learn how to make our pages interactive.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
+++
|
|
2
|
+
title = "Chapter 3: JavaScript Essentials"
|
|
3
|
+
description = "Core JavaScript concepts every developer should know."
|
|
4
|
+
weight = 3
|
|
5
|
+
+++
|
|
6
|
+
|
|
7
|
+
# Chapter 3: JavaScript Essentials
|
|
8
|
+
|
|
9
|
+
JavaScript is the programming language of the web. From simple interactions to complex single-page applications, JavaScript powers the dynamic experiences users expect.
|
|
10
|
+
|
|
11
|
+
## Variables and Data Types
|
|
12
|
+
|
|
13
|
+
JavaScript has three ways to declare variables:
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
var legacy = "Avoid this in modern code";
|
|
17
|
+
let mutable = "Can be reassigned";
|
|
18
|
+
const immutable = "Cannot be reassigned";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Primitive Types
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// String
|
|
25
|
+
const name = "Tanuki";
|
|
26
|
+
|
|
27
|
+
// Number (integers and floats)
|
|
28
|
+
const count = 42;
|
|
29
|
+
const price = 19.99;
|
|
30
|
+
|
|
31
|
+
// Boolean
|
|
32
|
+
const isActive = true;
|
|
33
|
+
|
|
34
|
+
// Null and Undefined
|
|
35
|
+
const empty = null;
|
|
36
|
+
let notAssigned; // undefined
|
|
37
|
+
|
|
38
|
+
// Symbol (unique identifiers)
|
|
39
|
+
const id = Symbol('id');
|
|
40
|
+
|
|
41
|
+
// BigInt (large integers)
|
|
42
|
+
const huge = 9007199254740991n;
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Functions
|
|
46
|
+
|
|
47
|
+
Functions are first-class citizens in JavaScript:
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
// Function declaration
|
|
51
|
+
function greet(name) {
|
|
52
|
+
return `Hello, ${name}!`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Function expression
|
|
56
|
+
const greet = function(name) {
|
|
57
|
+
return `Hello, ${name}!`;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Arrow function
|
|
61
|
+
const greet = (name) => `Hello, ${name}!`;
|
|
62
|
+
|
|
63
|
+
// Arrow function with body
|
|
64
|
+
const greet = (name) => {
|
|
65
|
+
const greeting = `Hello, ${name}!`;
|
|
66
|
+
console.log(greeting);
|
|
67
|
+
return greeting;
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Higher-Order Functions
|
|
72
|
+
|
|
73
|
+
Functions that take or return other functions:
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
const numbers = [1, 2, 3, 4, 5];
|
|
77
|
+
|
|
78
|
+
// map: transform each element
|
|
79
|
+
const doubled = numbers.map(n => n * 2);
|
|
80
|
+
// [2, 4, 6, 8, 10]
|
|
81
|
+
|
|
82
|
+
// filter: keep elements that pass a test
|
|
83
|
+
const evens = numbers.filter(n => n % 2 === 0);
|
|
84
|
+
// [2, 4]
|
|
85
|
+
|
|
86
|
+
// reduce: combine elements into a single value
|
|
87
|
+
const sum = numbers.reduce((acc, n) => acc + n, 0);
|
|
88
|
+
// 15
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Asynchronous JavaScript
|
|
92
|
+
|
|
93
|
+
The web is inherently asynchronous. JavaScript provides several patterns for handling async operations.
|
|
94
|
+
|
|
95
|
+
### Promises
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
function fetchUser(id) {
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
if (id > 0) {
|
|
102
|
+
resolve({ id, name: 'Tanuki' });
|
|
103
|
+
} else {
|
|
104
|
+
reject(new Error('Invalid ID'));
|
|
105
|
+
}
|
|
106
|
+
}, 1000);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
fetchUser(1)
|
|
111
|
+
.then(user => console.log(user.name))
|
|
112
|
+
.catch(error => console.error(error));
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Async/Await
|
|
116
|
+
|
|
117
|
+
A cleaner syntax for working with Promises:
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
async function displayUser(id) {
|
|
121
|
+
try {
|
|
122
|
+
const user = await fetchUser(id);
|
|
123
|
+
console.log(user.name);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('Failed to fetch user:', error);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Modules
|
|
131
|
+
|
|
132
|
+
Modern JavaScript uses ES Modules for code organization:
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
// math.js
|
|
136
|
+
export const PI = 3.14159;
|
|
137
|
+
|
|
138
|
+
export function add(a, b) {
|
|
139
|
+
return a + b;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export default function multiply(a, b) {
|
|
143
|
+
return a * b;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
// main.js
|
|
149
|
+
import multiply, { PI, add } from './math.js';
|
|
150
|
+
|
|
151
|
+
console.log(PI); // 3.14159
|
|
152
|
+
console.log(add(2, 3)); // 5
|
|
153
|
+
console.log(multiply(4, 5)); // 20
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## The DOM API
|
|
157
|
+
|
|
158
|
+
Interacting with the Document Object Model:
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
// Selecting elements
|
|
162
|
+
const button = document.querySelector('.submit-btn');
|
|
163
|
+
const items = document.querySelectorAll('.item');
|
|
164
|
+
|
|
165
|
+
// Creating elements
|
|
166
|
+
const div = document.createElement('div');
|
|
167
|
+
div.className = 'card';
|
|
168
|
+
div.textContent = 'Hello!';
|
|
169
|
+
|
|
170
|
+
// Modifying elements
|
|
171
|
+
button.classList.add('active');
|
|
172
|
+
button.setAttribute('disabled', true);
|
|
173
|
+
button.style.backgroundColor = 'blue';
|
|
174
|
+
|
|
175
|
+
// Event handling
|
|
176
|
+
button.addEventListener('click', (event) => {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
console.log('Clicked!');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Appending to DOM
|
|
182
|
+
document.body.appendChild(div);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Error Handling
|
|
186
|
+
|
|
187
|
+
Robust error handling is crucial:
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
try {
|
|
191
|
+
const data = JSON.parse(invalidJson);
|
|
192
|
+
processData(data);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (error instanceof SyntaxError) {
|
|
195
|
+
console.error('Invalid JSON:', error.message);
|
|
196
|
+
} else {
|
|
197
|
+
throw error; // Re-throw unexpected errors
|
|
198
|
+
}
|
|
199
|
+
} finally {
|
|
200
|
+
cleanup();
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Summary
|
|
205
|
+
|
|
206
|
+
This chapter covered JavaScript fundamentals:
|
|
207
|
+
|
|
208
|
+
- Variables and data types
|
|
209
|
+
- Functions and higher-order functions
|
|
210
|
+
- Asynchronous programming with Promises and async/await
|
|
211
|
+
- ES Modules for code organization
|
|
212
|
+
- DOM manipulation
|
|
213
|
+
- Error handling
|
|
214
|
+
|
|
215
|
+
> **Remember**: JavaScript is a multi-paradigm language. You can write imperative, functional, or object-oriented code. Choose the style that best fits your problem.
|
|
216
|
+
|
|
217
|
+
In the next chapter, we'll explore performance optimization techniques.
|