resuxjs 0.3.11 → 0.4.0-beta.3
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/README.md +23 -1
- package/dist/bin.d.ts +1 -2
- package/dist/bin.js +5 -0
- package/dist/bin.js.map +1 -1
- package/dist/build/index.d.ts +29 -0
- package/dist/build/index.js +51 -0
- package/dist/build/index.js.map +1 -0
- package/dist/cli.d.ts +19 -8
- package/dist/cli.js +2653 -3688
- package/dist/cli.js.map +1 -1
- package/dist/compiler/adapter.d.ts +19 -15
- package/dist/compiler/adapter.js +69 -93
- package/dist/compiler/adapter.js.map +1 -1
- package/dist/compiler/dev-warnings.d.ts +14 -10
- package/dist/compiler/dev-warnings.js +247 -319
- package/dist/compiler/dev-warnings.js.map +1 -1
- package/dist/compiler/directives.d.ts +7 -3
- package/dist/compiler/directives.js +125 -150
- package/dist/compiler/directives.js.map +1 -1
- package/dist/compiler/implementation.d.ts +117 -112
- package/dist/compiler/implementation.js +2954 -3426
- package/dist/compiler/index.d.ts +19 -15
- package/dist/compiler/index.js +69 -93
- package/dist/compiler/index.js.map +1 -1
- package/dist/core/config.d.ts +19 -10
- package/dist/core/config.js +42 -25
- package/dist/core/config.js.map +1 -1
- package/dist/core/hooks.d.ts +133 -131
- package/dist/core/hooks.js +45 -55
- package/dist/core/hooks.js.map +1 -1
- package/dist/core/index.d.ts +5 -4
- package/dist/core/index.js +6 -5
- package/dist/core/module-container.d.ts +97 -93
- package/dist/core/module-container.js +180 -185
- package/dist/core/module-container.js.map +1 -1
- package/dist/core/resux.d.ts +20 -15
- package/dist/core/resux.js +18 -13
- package/dist/core/resux.js.map +1 -1
- package/dist/create-bin.d.ts +1 -2
- package/dist/create-bin.js +5 -0
- package/dist/create-bin.js.map +1 -1
- package/dist/create.d.ts +6 -2
- package/dist/create.js +496 -638
- package/dist/create.js.map +1 -1
- package/dist/deploy/cloudflare.d.ts +7 -2
- package/dist/deploy/cloudflare.js +31 -34
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/deploy/common.d.ts +19 -15
- package/dist/deploy/common.js +119 -188
- package/dist/deploy/common.js.map +1 -1
- package/dist/deploy/framework-runtime.d.ts +5 -1
- package/dist/deploy/framework-runtime.js +44 -48
- package/dist/deploy/framework-runtime.js.map +1 -1
- package/dist/deploy/index.d.ts +8 -3
- package/dist/deploy/index.js +56 -80
- package/dist/deploy/index.js.map +1 -1
- package/dist/deploy/netlify.d.ts +7 -2
- package/dist/deploy/netlify.js +41 -41
- package/dist/deploy/netlify.js.map +1 -1
- package/dist/deploy/node.d.ts +7 -2
- package/dist/deploy/node.js +24 -19
- package/dist/deploy/node.js.map +1 -1
- package/dist/deploy/production-report.d.ts +5 -1
- package/dist/deploy/production-report.js +15 -14
- package/dist/deploy/production-report.js.map +1 -1
- package/dist/deploy/runtime-dependencies.d.ts +8 -4
- package/dist/deploy/runtime-dependencies.js +158 -220
- package/dist/deploy/runtime-dependencies.js.map +1 -1
- package/dist/deploy/static.d.ts +7 -2
- package/dist/deploy/static.js +17 -14
- package/dist/deploy/static.js.map +1 -1
- package/dist/deploy/types.d.ts +33 -29
- package/dist/deploy/types.js +1 -2
- package/dist/deploy/vercel.d.ts +8 -3
- package/dist/deploy/vercel.js +138 -188
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/fonts/index.d.ts +19 -14
- package/dist/fonts/index.js +115 -134
- package/dist/fonts/index.js.map +1 -1
- package/dist/globals.d.ts +79 -78
- package/dist/globals.js +1 -2
- package/dist/halal-core/ai/classifyProject.d.ts +9 -4
- package/dist/halal-core/ai/classifyProject.js +82 -95
- package/dist/halal-core/ai/classifyProject.js.map +1 -1
- package/dist/halal-core/ai/classifyRuntimeContent.d.ts +8 -3
- package/dist/halal-core/ai/classifyRuntimeContent.js +78 -95
- package/dist/halal-core/ai/classifyRuntimeContent.js.map +1 -1
- package/dist/halal-core/ai/createProjectSummary.d.ts +40 -36
- package/dist/halal-core/ai/createProjectSummary.js +39 -39
- package/dist/halal-core/ai/createProjectSummary.js.map +1 -1
- package/dist/halal-core/ai/halalClassifierPrompt.d.ts +5 -1
- package/dist/halal-core/ai/halalClassifierPrompt.js +5 -1
- package/dist/halal-core/ai/halalClassifierPrompt.js.map +1 -1
- package/dist/halal-core/ai/redactSensitiveData.d.ts +5 -1
- package/dist/halal-core/ai/redactSensitiveData.js +82 -110
- package/dist/halal-core/ai/redactSensitiveData.js.map +1 -1
- package/dist/halal-core/ai/validateAiResponse.d.ts +7 -2
- package/dist/halal-core/ai/validateAiResponse.js +56 -83
- package/dist/halal-core/ai/validateAiResponse.js.map +1 -1
- package/dist/halal-core/cli/check.d.ts +5 -1
- package/dist/halal-core/cli/check.js +28 -30
- package/dist/halal-core/cli/check.js.map +1 -1
- package/dist/halal-core/cli/explain.d.ts +5 -1
- package/dist/halal-core/cli/explain.js +27 -31
- package/dist/halal-core/cli/explain.js.map +1 -1
- package/dist/halal-core/cli/report.d.ts +5 -1
- package/dist/halal-core/cli/report.js +14 -10
- package/dist/halal-core/cli/report.js.map +1 -1
- package/dist/halal-core/cli/submitReview.d.ts +5 -1
- package/dist/halal-core/cli/submitReview.js +13 -9
- package/dist/halal-core/cli/submitReview.js.map +1 -1
- package/dist/halal-core/cli/verifyReview.d.ts +5 -1
- package/dist/halal-core/cli/verifyReview.js +17 -15
- package/dist/halal-core/cli/verifyReview.js.map +1 -1
- package/dist/halal-core/config.d.ts +39 -35
- package/dist/halal-core/config.js +77 -118
- package/dist/halal-core/config.js.map +1 -1
- package/dist/halal-core/crypto/integrity.d.ts +12 -8
- package/dist/halal-core/crypto/integrity.js +65 -87
- package/dist/halal-core/crypto/integrity.js.map +1 -1
- package/dist/halal-core/enforce.d.ts +9 -5
- package/dist/halal-core/enforce.js +90 -105
- package/dist/halal-core/enforce.js.map +1 -1
- package/dist/halal-core/index.d.ts +20 -16
- package/dist/halal-core/index.js +19 -19
- package/dist/halal-core/lifecycle.d.ts +5 -1
- package/dist/halal-core/lifecycle.js +16 -13
- package/dist/halal-core/lifecycle.js.map +1 -1
- package/dist/halal-core/policy.d.ts +7 -2
- package/dist/halal-core/policy.js +7 -2
- package/dist/halal-core/policy.js.map +1 -1
- package/dist/halal-core/report/formatBrowserOverlay.d.ts +7 -2
- package/dist/halal-core/report/formatBrowserOverlay.js +10 -8
- package/dist/halal-core/report/formatBrowserOverlay.js.map +1 -1
- package/dist/halal-core/report/formatTerminalReport.d.ts +7 -2
- package/dist/halal-core/report/formatTerminalReport.js +27 -37
- package/dist/halal-core/report/formatTerminalReport.js.map +1 -1
- package/dist/halal-core/report/generateHalalReport.d.ts +11 -6
- package/dist/halal-core/report/generateHalalReport.js +25 -27
- package/dist/halal-core/report/generateHalalReport.js.map +1 -1
- package/dist/halal-core/report/signReport.d.ts +8 -3
- package/dist/halal-core/report/signReport.js +17 -12
- package/dist/halal-core/report/signReport.js.map +1 -1
- package/dist/halal-core/report/verifyReport.d.ts +14 -9
- package/dist/halal-core/report/verifyReport.js +52 -41
- package/dist/halal-core/report/verifyReport.js.map +1 -1
- package/dist/halal-core/review/createReviewRequest.d.ts +7 -2
- package/dist/halal-core/review/createReviewRequest.js +21 -17
- package/dist/halal-core/review/createReviewRequest.js.map +1 -1
- package/dist/halal-core/review/reviewPolicy.d.ts +7 -3
- package/dist/halal-core/review/reviewPolicy.js +19 -17
- package/dist/halal-core/review/reviewPolicy.js.map +1 -1
- package/dist/halal-core/review/signedReviewFile.d.ts +17 -12
- package/dist/halal-core/review/signedReviewFile.js +25 -22
- package/dist/halal-core/review/signedReviewFile.js.map +1 -1
- package/dist/halal-core/review/verifyReviewApproval.d.ts +12 -8
- package/dist/halal-core/review/verifyReviewApproval.js +69 -62
- package/dist/halal-core/review/verifyReviewApproval.js.map +1 -1
- package/dist/halal-core/rules/adultContentRules.d.ts +6 -2
- package/dist/halal-core/rules/adultContentRules.js +23 -23
- package/dist/halal-core/rules/adultContentRules.js.map +1 -1
- package/dist/halal-core/rules/alcoholDrugVapeRules.d.ts +6 -2
- package/dist/halal-core/rules/alcoholDrugVapeRules.js +22 -22
- package/dist/halal-core/rules/alcoholDrugVapeRules.js.map +1 -1
- package/dist/halal-core/rules/childSafetyRules.d.ts +6 -2
- package/dist/halal-core/rules/childSafetyRules.js +19 -19
- package/dist/halal-core/rules/childSafetyRules.js.map +1 -1
- package/dist/halal-core/rules/coreCategories.d.ts +10 -6
- package/dist/halal-core/rules/coreCategories.js +237 -110
- package/dist/halal-core/rules/coreCategories.js.map +1 -1
- package/dist/halal-core/rules/cyberAbuseRules.d.ts +6 -2
- package/dist/halal-core/rules/cyberAbuseRules.js +27 -27
- package/dist/halal-core/rules/cyberAbuseRules.js.map +1 -1
- package/dist/halal-core/rules/defaultBlockedRules.d.ts +24 -19
- package/dist/halal-core/rules/defaultBlockedRules.js +156 -199
- package/dist/halal-core/rules/defaultBlockedRules.js.map +1 -1
- package/dist/halal-core/rules/dependencyRules.d.ts +11 -7
- package/dist/halal-core/rules/dependencyRules.js +50 -56
- package/dist/halal-core/rules/dependencyRules.js.map +1 -1
- package/dist/halal-core/rules/endpointRules.d.ts +9 -5
- package/dist/halal-core/rules/endpointRules.js +21 -23
- package/dist/halal-core/rules/endpointRules.js.map +1 -1
- package/dist/halal-core/rules/environmentalHarmRules.d.ts +6 -2
- package/dist/halal-core/rules/environmentalHarmRules.js +17 -17
- package/dist/halal-core/rules/environmentalHarmRules.js.map +1 -1
- package/dist/halal-core/rules/financeRibaRules.d.ts +6 -2
- package/dist/halal-core/rules/financeRibaRules.js +20 -20
- package/dist/halal-core/rules/financeRibaRules.js.map +1 -1
- package/dist/halal-core/rules/gamblingRules.d.ts +6 -2
- package/dist/halal-core/rules/gamblingRules.js +22 -22
- package/dist/halal-core/rules/gamblingRules.js.map +1 -1
- package/dist/halal-core/rules/generalHarmRules.d.ts +6 -2
- package/dist/halal-core/rules/generalHarmRules.js +15 -15
- package/dist/halal-core/rules/generalHarmRules.js.map +1 -1
- package/dist/halal-core/rules/healthHarmRules.d.ts +6 -2
- package/dist/halal-core/rules/healthHarmRules.js +19 -19
- package/dist/halal-core/rules/healthHarmRules.js.map +1 -1
- package/dist/halal-core/rules/keywordRules.d.ts +13 -9
- package/dist/halal-core/rules/keywordRules.js +90 -39
- package/dist/halal-core/rules/keywordRules.js.map +1 -1
- package/dist/halal-core/rules/privacyAbuseRules.d.ts +6 -2
- package/dist/halal-core/rules/privacyAbuseRules.js +21 -21
- package/dist/halal-core/rules/privacyAbuseRules.js.map +1 -1
- package/dist/halal-core/rules/scamFraudRules.d.ts +6 -2
- package/dist/halal-core/rules/scamFraudRules.js +29 -29
- package/dist/halal-core/rules/scamFraudRules.js.map +1 -1
- package/dist/halal-core/rules/selfHarmRules.d.ts +6 -2
- package/dist/halal-core/rules/selfHarmRules.js +17 -17
- package/dist/halal-core/rules/selfHarmRules.js.map +1 -1
- package/dist/halal-core/rules/violenceExtremismRules.d.ts +6 -2
- package/dist/halal-core/rules/violenceExtremismRules.js +30 -30
- package/dist/halal-core/rules/violenceExtremismRules.js.map +1 -1
- package/dist/halal-core/runtime/guard.d.ts +22 -17
- package/dist/halal-core/runtime/guard.js +163 -183
- package/dist/halal-core/runtime/guard.js.map +1 -1
- package/dist/halal-core/runtime/index.d.ts +5 -4
- package/dist/halal-core/runtime/index.js +5 -5
- package/dist/halal-core/runtime/reviewedMemory.d.ts +10 -5
- package/dist/halal-core/runtime/reviewedMemory.js +75 -110
- package/dist/halal-core/runtime/reviewedMemory.js.map +1 -1
- package/dist/halal-core/runtime/serializeRuntimeContent.d.ts +17 -12
- package/dist/halal-core/runtime/serializeRuntimeContent.js +133 -156
- package/dist/halal-core/runtime/serializeRuntimeContent.js.map +1 -1
- package/dist/halal-core/runtime/types.d.ts +55 -50
- package/dist/halal-core/runtime/types.js +1 -2
- package/dist/halal-core/scanner/scanApiRoutes.d.ts +5 -1
- package/dist/halal-core/scanner/scanApiRoutes.js +33 -36
- package/dist/halal-core/scanner/scanApiRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanComponents.d.ts +5 -1
- package/dist/halal-core/scanner/scanComponents.js +13 -13
- package/dist/halal-core/scanner/scanComponents.js.map +1 -1
- package/dist/halal-core/scanner/scanContent.d.ts +8 -4
- package/dist/halal-core/scanner/scanContent.js +192 -261
- package/dist/halal-core/scanner/scanContent.js.map +1 -1
- package/dist/halal-core/scanner/scanDependencies.d.ts +5 -1
- package/dist/halal-core/scanner/scanDependencies.js +17 -15
- package/dist/halal-core/scanner/scanDependencies.js.map +1 -1
- package/dist/halal-core/scanner/scanDomains.d.ts +7 -3
- package/dist/halal-core/scanner/scanDomains.js +12 -12
- package/dist/halal-core/scanner/scanDomains.js.map +1 -1
- package/dist/halal-core/scanner/scanEnvNames.d.ts +5 -1
- package/dist/halal-core/scanner/scanEnvNames.js +24 -26
- package/dist/halal-core/scanner/scanEnvNames.js.map +1 -1
- package/dist/halal-core/scanner/scanMetadata.d.ts +9 -5
- package/dist/halal-core/scanner/scanMetadata.js +21 -29
- package/dist/halal-core/scanner/scanMetadata.js.map +1 -1
- package/dist/halal-core/scanner/scanPages.d.ts +5 -1
- package/dist/halal-core/scanner/scanPages.js +13 -15
- package/dist/halal-core/scanner/scanPages.js.map +1 -1
- package/dist/halal-core/scanner/scanProject.d.ts +19 -12
- package/dist/halal-core/scanner/scanProject.js +44 -49
- package/dist/halal-core/scanner/scanProject.js.map +1 -1
- package/dist/halal-core/scanner/scanRoutes.d.ts +5 -1
- package/dist/halal-core/scanner/scanRoutes.js +33 -39
- package/dist/halal-core/scanner/scanRoutes.js.map +1 -1
- package/dist/halal-core/scanner/scanTranslations.d.ts +5 -1
- package/dist/halal-core/scanner/scanTranslations.js +22 -29
- package/dist/halal-core/scanner/scanTranslations.js.map +1 -1
- package/dist/halal-core/status.d.ts +17 -13
- package/dist/halal-core/status.js +1 -2
- package/dist/halal-core/tamper/verifyCoreIntegrity.d.ts +5 -1
- package/dist/halal-core/tamper/verifyCoreIntegrity.js +27 -24
- package/dist/halal-core/tamper/verifyCoreIntegrity.js.map +1 -1
- package/dist/halal-core/tamper/verifyLifecycleHooks.d.ts +5 -1
- package/dist/halal-core/tamper/verifyLifecycleHooks.js +13 -12
- package/dist/halal-core/tamper/verifyLifecycleHooks.js.map +1 -1
- package/dist/halal-core/tamper/verifyReportSignature.d.ts +9 -4
- package/dist/halal-core/tamper/verifyReportSignature.js +20 -14
- package/dist/halal-core/tamper/verifyReportSignature.js.map +1 -1
- package/dist/halal.d.ts +20 -1
- package/dist/halal.js +19 -2
- package/dist/i18n/index.d.ts +44 -40
- package/dist/i18n/index.js +218 -288
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/shared.d.ts +33 -29
- package/dist/i18n/shared.js +204 -266
- package/dist/i18n/shared.js.map +1 -1
- package/dist/icons/index.d.ts +160 -154
- package/dist/icons/index.js +323 -273
- package/dist/icons/index.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +8 -2
- package/dist/kit/index.d.ts +32 -27
- package/dist/kit/index.js +46 -43
- package/dist/kit/index.js.map +1 -1
- package/dist/nitro-server/index.d.ts +10 -6
- package/dist/nitro-server/index.js +6 -2
- package/dist/nitro-server/index.js.map +1 -1
- package/dist/node.d.ts +9 -4
- package/dist/node.js +89 -116
- package/dist/node.js.map +1 -1
- package/dist/reactivity/computed.d.ts +11 -6
- package/dist/reactivity/computed.js +46 -53
- package/dist/reactivity/computed.js.map +1 -1
- package/dist/reactivity/effect.d.ts +23 -18
- package/dist/reactivity/effect.js +105 -147
- package/dist/reactivity/effect.js.map +1 -1
- package/dist/reactivity/index.d.ts +8 -8
- package/dist/reactivity/index.js +8 -8
- package/dist/reactivity/reactive.d.ts +9 -5
- package/dist/reactivity/reactive.js +95 -134
- package/dist/reactivity/reactive.js.map +1 -1
- package/dist/reactivity/readonly.d.ts +2 -1
- package/dist/reactivity/readonly.js +3 -2
- package/dist/reactivity/ref.d.ts +23 -21
- package/dist/reactivity/ref.js +71 -81
- package/dist/reactivity/ref.js.map +1 -1
- package/dist/reactivity/scheduler.d.ts +8 -5
- package/dist/reactivity/scheduler.js +67 -69
- package/dist/reactivity/scheduler.js.map +1 -1
- package/dist/reactivity/types.d.ts +29 -25
- package/dist/reactivity/types.js +1 -2
- package/dist/reactivity/utils.d.ts +17 -13
- package/dist/reactivity/utils.js +25 -24
- package/dist/reactivity/utils.js.map +1 -1
- package/dist/reactivity/watch.d.ts +8 -4
- package/dist/reactivity/watch.js +74 -103
- package/dist/reactivity/watch.js.map +1 -1
- package/dist/runtime/core.d.ts +32 -0
- package/dist/runtime/core.js +155 -0
- package/dist/runtime/core.js.map +1 -0
- package/dist/runtime/index.d.ts +649 -622
- package/dist/runtime/index.js +4105 -5243
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/reactivity.d.ts +7 -0
- package/dist/runtime/reactivity.js +7 -0
- package/dist/runtime/resume.d.ts +80 -0
- package/dist/runtime/resume.js +482 -0
- package/dist/runtime/resume.js.map +1 -0
- package/dist/runtime/router.d.ts +21 -0
- package/dist/runtime/router.js +60 -0
- package/dist/runtime/router.js.map +1 -0
- package/dist/runtime/streaming.d.ts +25 -0
- package/dist/runtime/streaming.js +200 -0
- package/dist/runtime/streaming.js.map +1 -0
- package/dist/security/media-fetch.d.ts +33 -0
- package/dist/security/media-fetch.js +302 -0
- package/dist/security/media-fetch.js.map +1 -0
- package/dist/security/path-boundary.d.ts +8 -0
- package/dist/security/path-boundary.js +71 -0
- package/dist/security/path-boundary.js.map +1 -0
- package/dist/ui/index.d.ts +1774 -1768
- package/dist/ui/index.js +974 -674
- package/dist/ui/index.js.map +1 -1
- package/dist/vite-builder/index.d.ts +9 -5
- package/dist/vite-builder/index.js +6 -2
- package/dist/vite-builder/index.js.map +1 -1
- package/package.json +46 -86
- package/dist/compiler/implementation.js.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/deploy/types.js.map +0 -1
- package/dist/globals.js.map +0 -1
- package/dist/halal-core/index.js.map +0 -1
- package/dist/halal-core/runtime/index.js.map +0 -1
- package/dist/halal-core/runtime/types.js.map +0 -1
- package/dist/halal-core/status.js.map +0 -1
- package/dist/halal.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/reactivity/index.js.map +0 -1
- package/dist/reactivity/readonly.js.map +0 -1
- package/dist/reactivity/types.js.map +0 -1
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","
|
|
1
|
+
{"version":3,"file":"node.js","names":["createCliResuxNodeHandler"],"sources":["../src/node.ts"],"sourcesContent":["import type { OutgoingHttpHeaders, ServerResponse } from \"node:http\";\nimport {\n createResuxNodeHandler as createCliResuxNodeHandler,\n type ResuxNodeHandlerOptions,\n} from \"./cli.js\";\n\nexport type { ResuxNodeHandlerOptions } from \"./cli.js\";\n\nconst GENERATED_IMAGE_PREFIX = \"/_resux/generated/images/\";\nconst GENERATED_VIDEO_PREFIX = \"/_resux/generated/videos/\";\nconst STATELESS_IMAGE_PATH = \"/__resux/image\";\nconst STATELESS_VIDEO_PATH = \"/__resux/video\";\nconst CACHE_BOOLEAN_TRUE = new Set([\"true\", \"1\", \"yes\", \"on\"]);\nconst CACHE_BOOLEAN_FALSE = new Set([\"false\", \"0\", \"off\", \"no\"]);\nconst CACHE_UNIT_SECONDS: Record<string, number> = {\n s: 1,\n m: 60,\n h: 60 * 60,\n d: 24 * 60 * 60,\n w: 7 * 24 * 60 * 60,\n};\n\nfunction positiveRoundedSeconds(value: number): number | undefined {\n return Number.isFinite(value) && value > 0\n ? Math.max(1, Math.round(value))\n : undefined;\n}\n\nfunction parseCacheMaxAgeSeconds(value: string | null): number | undefined {\n const normalized = value?.trim().toLowerCase();\n if (!normalized || CACHE_BOOLEAN_FALSE.has(normalized)) {\n return undefined;\n }\n if (CACHE_BOOLEAN_TRUE.has(normalized)) {\n return 24 * 60 * 60;\n }\n\n const numericSeconds = positiveRoundedSeconds(Number(normalized));\n if (numericSeconds) {\n return numericSeconds;\n }\n\n const duration = /^(\\d+)\\s*([smhdw])$/.exec(normalized);\n if (!duration) {\n return undefined;\n }\n\n const amount = Number(duration[1]);\n const unitSeconds = CACHE_UNIT_SECONDS[duration[2] ?? \"\"];\n return unitSeconds ? positiveRoundedSeconds(amount * unitSeconds) : undefined;\n}\n\nfunction isStatelessDeploymentRuntime(): boolean {\n return Boolean(\n process.env.VERCEL\n || process.env.VERCEL_ENV\n || process.env.AWS_LAMBDA_FUNCTION_NAME\n || process.env.LAMBDA_TASK_ROOT\n || process.env.NETLIFY,\n );\n}\n\nfunction resolveStatelessGeneratedMediaRequest(rawUrl: string | undefined): {\n url: string;\n maxAgeSeconds: number;\n} | null {\n if (!rawUrl) {\n return null;\n }\n\n let requestUrl: URL;\n try {\n requestUrl = new URL(rawUrl, \"https://resux.invalid\");\n } catch {\n return null;\n }\n\n const cacheValue = requestUrl.searchParams.get(\"cache\") ?? requestUrl.searchParams.get(\"c\");\n const maxAgeSeconds = parseCacheMaxAgeSeconds(cacheValue);\n if (!maxAgeSeconds) {\n return null;\n }\n\n const hasSource = Boolean(\n requestUrl.searchParams.get(\"src\")\n || requestUrl.searchParams.get(\"url\")\n || requestUrl.searchParams.get(\"original\"),\n );\n if (!hasSource) {\n return null;\n }\n\n if (requestUrl.pathname.startsWith(GENERATED_IMAGE_PREFIX)) {\n requestUrl.pathname = STATELESS_IMAGE_PATH;\n } else if (requestUrl.pathname.startsWith(GENERATED_VIDEO_PREFIX)) {\n requestUrl.pathname = STATELESS_VIDEO_PATH;\n } else {\n return null;\n }\n\n return {\n url: `${requestUrl.pathname}${requestUrl.search}`,\n maxAgeSeconds,\n };\n}\n\nfunction withGeneratedMediaCacheHeaders(\n response: ServerResponse,\n maxAgeSeconds: number,\n): void {\n const originalWriteHead = response.writeHead.bind(response) as (...args: any[]) => ServerResponse;\n const cacheControl = `public, max-age=${maxAgeSeconds}, s-maxage=${maxAgeSeconds}`;\n const cdnCacheControl = `public, max-age=${maxAgeSeconds}`;\n const overrides: OutgoingHttpHeaders = {\n \"cache-control\": cacheControl,\n \"cdn-cache-control\": cdnCacheControl,\n \"vercel-cdn-cache-control\": cdnCacheControl,\n \"x-resux-cache\": \"stateless\",\n };\n\n response.writeHead = ((statusCode: number, ...args: any[]) => {\n if (statusCode >= 200 && statusCode < 300) {\n if (typeof args[0] === \"string\") {\n if (args[1] && typeof args[1] === \"object\" && !Array.isArray(args[1])) {\n args[1] = { ...args[1], ...overrides };\n } else if (!args[1]) {\n args[1] = { ...overrides };\n }\n } else if (args[0] && typeof args[0] === \"object\" && !Array.isArray(args[0])) {\n args[0] = { ...args[0], ...overrides };\n } else if (!args[0]) {\n args[0] = { ...overrides };\n } else {\n for (const [name, value] of Object.entries(overrides)) {\n if (value !== undefined) {\n response.setHeader(name, value as string | number | readonly string[]);\n }\n }\n }\n }\n\n return originalWriteHead(statusCode, ...args);\n }) as ServerResponse[\"writeHead\"];\n}\n\nexport function createResuxNodeHandler(options: ResuxNodeHandlerOptions = {}) {\n const handler = createCliResuxNodeHandler(options);\n\n if (!isStatelessDeploymentRuntime()) {\n return handler;\n }\n\n return (request: Parameters<typeof handler>[0], response: Parameters<typeof handler>[1]): void => {\n const rewritten = resolveStatelessGeneratedMediaRequest(request.url);\n if (rewritten) {\n request.url = rewritten.url;\n withGeneratedMediaCacheHeaders(response, rewritten.maxAgeSeconds);\n }\n handler(request, response);\n };\n}\n"],"mappings":";;;AAQA,MAAM,yBAAyB;AAC/B,MAAM,yBAAyB;AAC/B,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,qBAAqB,IAAI,IAAI;CAAC;CAAQ;CAAK;CAAO;CAAK,CAAC;AAC9D,MAAM,sBAAsB,IAAI,IAAI;CAAC;CAAS;CAAK;CAAO;CAAK,CAAC;AAChE,MAAM,qBAA6C;CACjD,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG,OAAU;CACb,GAAG,QAAc;CAClB;AAED,SAAS,uBAAuB,OAAmC;AACjE,QAAO,OAAO,SAAS,MAAM,IAAI,QAAQ,IACrC,KAAK,IAAI,GAAG,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|
+
declare function computed<T>(getter: () => T): ComputedRef<T>;
|
|
5
|
+
declare function computed<T>(options: {
|
|
6
|
+
get: () => T;
|
|
7
|
+
set?: (value: T) => void;
|
|
6
8
|
}): ComputedRef<T>;
|
|
7
|
-
|
|
9
|
+
declare function isComputed(value: unknown): boolean;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { computed, isComputed };
|
|
12
|
+
//# sourceMappingURL=computed.d.ts.map
|
|
@@ -1,58 +1,51 @@
|
|
|
1
1
|
import { effect, isTracking, trackEffects, triggerEffects } from "./effect.js";
|
|
2
2
|
import { ReactiveFlags } from "./utils.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
3
|
+
|
|
4
|
+
//#region src/reactivity/computed.ts
|
|
5
|
+
var ComputedRefImpl = class {
|
|
6
|
+
__v_isRef = true;
|
|
7
|
+
__v_isReadonly = true;
|
|
8
|
+
setter;
|
|
9
|
+
runner;
|
|
10
|
+
dep;
|
|
11
|
+
dirty = true;
|
|
12
|
+
_value;
|
|
13
|
+
constructor(getter, setter) {
|
|
14
|
+
this.setter = setter;
|
|
15
|
+
this.runner = effect(getter, {
|
|
16
|
+
lazy: true,
|
|
17
|
+
scheduler: () => {
|
|
18
|
+
if (!this.dirty) {
|
|
19
|
+
this.dirty = true;
|
|
20
|
+
if (this.dep) triggerEffects(this.dep);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
get value() {
|
|
26
|
+
if (isTracking()) trackEffects(this._dep());
|
|
27
|
+
if (this.dirty) {
|
|
28
|
+
this._value = this.runner();
|
|
29
|
+
this.dirty = false;
|
|
30
|
+
}
|
|
31
|
+
return this._value;
|
|
32
|
+
}
|
|
33
|
+
set value(newValue) {
|
|
34
|
+
this.setter?.(newValue);
|
|
35
|
+
}
|
|
36
|
+
_dep() {
|
|
37
|
+
if (!this.dep) this.dep = /* @__PURE__ */ new Set();
|
|
38
|
+
return this.dep;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function computed(getterOrOptions) {
|
|
42
|
+
if (typeof getterOrOptions === "function") return new ComputedRefImpl(getterOrOptions);
|
|
43
|
+
return new ComputedRefImpl(getterOrOptions.get, getterOrOptions.set);
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return new ComputedRefImpl(getterOrOptions);
|
|
49
|
-
}
|
|
50
|
-
return new ComputedRefImpl(getterOrOptions.get, getterOrOptions.set);
|
|
51
|
-
}
|
|
52
|
-
export function isComputed(value) {
|
|
53
|
-
return Boolean(value
|
|
54
|
-
&& typeof value === "object"
|
|
55
|
-
&& value[ReactiveFlags.IS_REF] === true
|
|
56
|
-
&& value[ReactiveFlags.IS_READONLY] === true);
|
|
45
|
+
function isComputed(value) {
|
|
46
|
+
return Boolean(value && typeof value === "object" && value[ReactiveFlags.IS_REF] === true && value[ReactiveFlags.IS_READONLY] === true);
|
|
57
47
|
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { computed, isComputed };
|
|
58
51
|
//# sourceMappingURL=computed.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed.js","
|
|
1
|
+
{"version":3,"file":"computed.js","names":[],"sources":["../../src/reactivity/computed.ts"],"sourcesContent":["import { effect, isTracking, trackEffects, triggerEffects, type Dep } from \"./effect.js\";\nimport type { ComputedRef } from \"./types.js\";\nimport { ReactiveFlags } from \"./utils.js\";\n\nclass ComputedRefImpl<T> implements ComputedRef<T> {\n readonly __v_isRef = true as const;\n readonly __v_isReadonly = true as const;\n\n private readonly setter?: (value: T) => void;\n private readonly runner;\n private dep?: Dep;\n private dirty = true;\n private _value!: T;\n\n constructor(getter: () => T, setter?: (value: T) => void) {\n this.setter = setter;\n this.runner = effect(getter, {\n lazy: true,\n scheduler: () => {\n if (!this.dirty) {\n this.dirty = true;\n if (this.dep) {\n triggerEffects(this.dep);\n }\n }\n }\n });\n }\n\n get value(): T {\n if (isTracking()) {\n trackEffects(this._dep());\n }\n if (this.dirty) {\n const value = this.runner();\n this._value = value;\n this.dirty = false;\n }\n return this._value;\n }\n\n set value(newValue: T) {\n this.setter?.(newValue);\n }\n\n private _dep(): Dep {\n if (!this.dep) {\n this.dep = new Set();\n }\n return this.dep;\n }\n}\n\nexport function computed<T>(getter: () => T): ComputedRef<T>;\nexport function computed<T>(options: { get: () => T; set?: (value: T) => void }): ComputedRef<T>;\nexport function computed<T>(\n getterOrOptions: (() => T) | { get: () => T; set?: (value: T) => void }\n): ComputedRef<T> {\n if (typeof getterOrOptions === \"function\") {\n return new ComputedRefImpl(getterOrOptions);\n }\n return new ComputedRefImpl(getterOrOptions.get, getterOrOptions.set);\n}\n\nexport function isComputed(value: unknown): boolean {\n return Boolean(\n value\n && typeof value === \"object\"\n && (value as Record<string, unknown>)[ReactiveFlags.IS_REF] === true\n && (value as Record<string, unknown>)[ReactiveFlags.IS_READONLY] === true\n );\n}\n"],"mappings":";;;;AAIA,IAAM,kBAAN,MAAmD;CACjD,AAAS,YAAY;CACrB,AAAS,iBAAiB;CAE1B,AAAiB;CACjB,AAAiB;CACjB,AAAQ;CACR,AAAQ,QAAQ;CAChB,AAAQ;CAER,YAAY,QAAiB,QAA6B;AACxD,OAAK,SAAS;AACd,OAAK,SAAS,OAAO,QAAQ;GAC3B,MAAM;GACN,iBAAiB;AACf,QAAI,CAAC,KAAK,OAAO;AACf,UAAK,QAAQ;AACb,SAAI,KAAK,IACP,gBAAe,KAAK,IAAI;;;GAI/B,CAAC;;CAGJ,IAAI,QAAW;AACb,MAAI,YAAY,CACd,cAAa,KAAK,MAAM,CAAC;AAE3B,MAAI,KAAK,OAAO;AAEd,QAAK,SADS,KAAK,QAAQ;AAE3B,QAAK,QAAQ;;AAEf,SAAO,KAAK;;CAGd,IAAI,MAAM,UAAa;AACrB,OAAK,SAAS,SAAS;;CAGzB,AAAQ,OAAY;AAClB,MAAI,CAAC,KAAK,IACR,MAAK,sBAAM,IAAI,KAAK;AAEtB,SAAO,KAAK;;;AAMhB,SAAgB,SACd,iBACgB;AAChB,KAAI,OAAO,oBAAoB,WAC7B,QAAO,IAAI,gBAAgB,gBAAgB;AAE7C,QAAO,IAAI,gBAAgB,gBAAgB,KAAK,gBAAgB,IAAI;;AAGtE,SAAgB,WAAW,OAAyB;AAClD,QAAO,QACL,SACK,OAAO,UAAU,YAChB,MAAkC,cAAc,YAAY,QAC5D,MAAkC,cAAc,iBAAiB,KACxE"}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ReactiveEffectOptions, ReactiveEffectRunner } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/reactivity/effect.d.ts
|
|
4
|
+
interface ReactiveEffectLike {
|
|
5
|
+
active: boolean;
|
|
6
|
+
run(): unknown;
|
|
7
|
+
scheduler?: () => void;
|
|
8
|
+
deps: Dep[];
|
|
7
9
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
type Dep = Set<ReactiveEffectLike>;
|
|
11
|
+
type TriggerOperation = "set" | "add" | "delete";
|
|
12
|
+
declare const ITERATE_KEY: unique symbol;
|
|
13
|
+
declare function effect<T = unknown>(fn: () => T, options?: ReactiveEffectOptions): ReactiveEffectRunner<T>;
|
|
14
|
+
declare function stop(runner: ReactiveEffectRunner): void;
|
|
15
|
+
declare function track(target: object, key: PropertyKey): void;
|
|
16
|
+
declare function trackEffects(dep: Dep): void;
|
|
17
|
+
declare function trigger(target: object, key: PropertyKey, operation?: TriggerOperation, newValue?: unknown, oldLength?: number): void;
|
|
18
|
+
declare function triggerEffects(dep: Dep): void;
|
|
19
|
+
declare function isTracking(): boolean;
|
|
20
|
+
declare function pauseTracking(): void;
|
|
21
|
+
declare function resetTracking(): void;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { Dep, ITERATE_KEY, ReactiveEffectLike, TriggerOperation, effect, isTracking, pauseTracking, resetTracking, stop, track, trackEffects, trigger, triggerEffects };
|
|
24
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -1,163 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
//#region src/reactivity/effect.ts
|
|
2
|
+
const ITERATE_KEY = Symbol("resux-iterate");
|
|
3
|
+
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
3
4
|
let activeEffect;
|
|
4
5
|
let shouldTrack = true;
|
|
5
6
|
const trackStack = [];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
cleanupEffect(this);
|
|
48
|
-
this.onStop?.();
|
|
49
|
-
this.active = false;
|
|
50
|
-
}
|
|
7
|
+
var ReactiveEffectImpl = class {
|
|
8
|
+
active = true;
|
|
9
|
+
deps = [];
|
|
10
|
+
scheduler;
|
|
11
|
+
onStop;
|
|
12
|
+
parent;
|
|
13
|
+
constructor(fn, options = {}) {
|
|
14
|
+
this.fn = fn;
|
|
15
|
+
this.scheduler = options.scheduler;
|
|
16
|
+
this.onStop = options.onStop;
|
|
17
|
+
}
|
|
18
|
+
run() {
|
|
19
|
+
if (!this.active) return this.fn();
|
|
20
|
+
let parent = activeEffect;
|
|
21
|
+
while (parent) {
|
|
22
|
+
if (parent === this) return;
|
|
23
|
+
parent = parent.parent;
|
|
24
|
+
}
|
|
25
|
+
cleanupEffect(this);
|
|
26
|
+
this.parent = activeEffect;
|
|
27
|
+
activeEffect = this;
|
|
28
|
+
trackStack.push(shouldTrack);
|
|
29
|
+
shouldTrack = true;
|
|
30
|
+
try {
|
|
31
|
+
return this.fn();
|
|
32
|
+
} finally {
|
|
33
|
+
shouldTrack = trackStack.pop() ?? true;
|
|
34
|
+
activeEffect = this.parent;
|
|
35
|
+
this.parent = void 0;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
stop() {
|
|
39
|
+
if (!this.active) return;
|
|
40
|
+
cleanupEffect(this);
|
|
41
|
+
this.onStop?.();
|
|
42
|
+
this.active = false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
function cleanupEffect(effect$1) {
|
|
46
|
+
for (const dep of effect$1.deps) dep.delete(effect$1);
|
|
47
|
+
effect$1.deps.length = 0;
|
|
51
48
|
}
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
function effect(fn, options = {}) {
|
|
50
|
+
const _effect = new ReactiveEffectImpl(fn, options);
|
|
51
|
+
if (!options.lazy) _effect.run();
|
|
52
|
+
const runner = _effect.run.bind(_effect);
|
|
53
|
+
runner.effect = _effect;
|
|
54
|
+
return runner;
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (!options.lazy) {
|
|
61
|
-
_effect.run();
|
|
62
|
-
}
|
|
63
|
-
const runner = _effect.run.bind(_effect);
|
|
64
|
-
runner.effect = _effect;
|
|
65
|
-
return runner;
|
|
56
|
+
function stop(runner) {
|
|
57
|
+
runner.effect.stop();
|
|
66
58
|
}
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
function track(target, key) {
|
|
60
|
+
if (!isTracking()) return;
|
|
61
|
+
let depsMap = targetMap.get(target);
|
|
62
|
+
if (!depsMap) {
|
|
63
|
+
depsMap = /* @__PURE__ */ new Map();
|
|
64
|
+
targetMap.set(target, depsMap);
|
|
65
|
+
}
|
|
66
|
+
let dep = depsMap.get(key);
|
|
67
|
+
if (!dep) {
|
|
68
|
+
dep = /* @__PURE__ */ new Set();
|
|
69
|
+
depsMap.set(key, dep);
|
|
70
|
+
}
|
|
71
|
+
trackEffects(dep);
|
|
69
72
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
let depsMap = targetMap.get(target);
|
|
75
|
-
if (!depsMap) {
|
|
76
|
-
depsMap = new Map();
|
|
77
|
-
targetMap.set(target, depsMap);
|
|
78
|
-
}
|
|
79
|
-
let dep = depsMap.get(key);
|
|
80
|
-
if (!dep) {
|
|
81
|
-
dep = new Set();
|
|
82
|
-
depsMap.set(key, dep);
|
|
83
|
-
}
|
|
84
|
-
trackEffects(dep);
|
|
73
|
+
function trackEffects(dep) {
|
|
74
|
+
if (!activeEffect || dep.has(activeEffect)) return;
|
|
75
|
+
dep.add(activeEffect);
|
|
76
|
+
activeEffect.deps.push(dep);
|
|
85
77
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
function trigger(target, key, operation = "set", newValue, oldLength) {
|
|
79
|
+
const depsMap = targetMap.get(target);
|
|
80
|
+
if (!depsMap) return;
|
|
81
|
+
const effects = /* @__PURE__ */ new Set();
|
|
82
|
+
const addEffects = (dep) => {
|
|
83
|
+
if (!dep) return;
|
|
84
|
+
for (const effect$1 of dep) effects.add(effect$1);
|
|
85
|
+
};
|
|
86
|
+
if (Array.isArray(target) && key === "length") {
|
|
87
|
+
const nextLength = Number(newValue);
|
|
88
|
+
for (const [depKey, dep] of depsMap) if (depKey === "length" || depKey === ITERATE_KEY || isArrayIndex(depKey) && Number(depKey) >= nextLength) addEffects(dep);
|
|
89
|
+
} else {
|
|
90
|
+
addEffects(depsMap.get(key));
|
|
91
|
+
if (operation === "add" || operation === "delete") addEffects(depsMap.get(ITERATE_KEY));
|
|
92
|
+
if (operation === "add" && Array.isArray(target) && isArrayIndex(key) && typeof oldLength === "number" && Number(key) >= oldLength) addEffects(depsMap.get("length"));
|
|
93
|
+
}
|
|
94
|
+
triggerEffects(effects);
|
|
92
95
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const addEffects = (dep) => {
|
|
100
|
-
if (!dep) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
for (const effect of dep) {
|
|
104
|
-
effects.add(effect);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
if (Array.isArray(target) && key === "length") {
|
|
108
|
-
const nextLength = Number(newValue);
|
|
109
|
-
for (const [depKey, dep] of depsMap) {
|
|
110
|
-
if (depKey === "length"
|
|
111
|
-
|| depKey === ITERATE_KEY
|
|
112
|
-
|| (isArrayIndex(depKey) && Number(depKey) >= nextLength)) {
|
|
113
|
-
addEffects(dep);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
addEffects(depsMap.get(key));
|
|
119
|
-
if (operation === "add" || operation === "delete") {
|
|
120
|
-
addEffects(depsMap.get(ITERATE_KEY));
|
|
121
|
-
}
|
|
122
|
-
if (operation === "add"
|
|
123
|
-
&& Array.isArray(target)
|
|
124
|
-
&& isArrayIndex(key)
|
|
125
|
-
&& typeof oldLength === "number"
|
|
126
|
-
&& Number(key) >= oldLength) {
|
|
127
|
-
addEffects(depsMap.get("length"));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
triggerEffects(effects);
|
|
96
|
+
function triggerEffects(dep) {
|
|
97
|
+
for (const effect$1 of [...dep]) {
|
|
98
|
+
if (effect$1 === activeEffect) continue;
|
|
99
|
+
if (effect$1.scheduler) effect$1.scheduler();
|
|
100
|
+
else effect$1.run();
|
|
101
|
+
}
|
|
131
102
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (effect === activeEffect) {
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
if (effect.scheduler) {
|
|
138
|
-
effect.scheduler();
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
effect.run();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
103
|
+
function isTracking() {
|
|
104
|
+
return shouldTrack && activeEffect !== void 0;
|
|
144
105
|
}
|
|
145
|
-
|
|
146
|
-
|
|
106
|
+
function pauseTracking() {
|
|
107
|
+
trackStack.push(shouldTrack);
|
|
108
|
+
shouldTrack = false;
|
|
147
109
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
shouldTrack = false;
|
|
151
|
-
}
|
|
152
|
-
export function resetTracking() {
|
|
153
|
-
shouldTrack = trackStack.pop() ?? true;
|
|
110
|
+
function resetTracking() {
|
|
111
|
+
shouldTrack = trackStack.pop() ?? true;
|
|
154
112
|
}
|
|
155
113
|
function isArrayIndex(key) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const value = String(key);
|
|
160
|
-
return /^(?:0|[1-9]\d*)$/.test(value)
|
|
161
|
-
&& Number(value) < 4_294_967_295;
|
|
114
|
+
if (typeof key === "symbol" || key === "length") return false;
|
|
115
|
+
const value = String(key);
|
|
116
|
+
return /^(?:0|[1-9]\d*)$/.test(value) && Number(value) < 4294967295;
|
|
162
117
|
}
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
export { ITERATE_KEY, effect, isTracking, pauseTracking, resetTracking, stop, track, trackEffects, trigger, triggerEffects };
|
|
163
121
|
//# sourceMappingURL=effect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect.js","
|
|
1
|
+
{"version":3,"file":"effect.js","names":["effect"],"sources":["../../src/reactivity/effect.ts"],"sourcesContent":["import type { ReactiveEffectOptions, ReactiveEffectRunner } from \"./types.js\";\n\nexport interface ReactiveEffectLike {\n active: boolean;\n run(): unknown;\n scheduler?: () => void;\n deps: Dep[];\n}\n\nexport type Dep = Set<ReactiveEffectLike>;\ntype KeyToDepMap = Map<PropertyKey, Dep>;\nexport type TriggerOperation = \"set\" | \"add\" | \"delete\";\n\nexport const ITERATE_KEY = Symbol(\"resux-iterate\");\n\nconst targetMap = new WeakMap<object, KeyToDepMap>();\n\nlet activeEffect: ReactiveEffectImpl | undefined;\nlet shouldTrack = true;\n\nconst trackStack: boolean[] = [];\n\nclass ReactiveEffectImpl implements ReactiveEffectLike {\n active = true;\n deps: Dep[] = [];\n readonly scheduler?: () => void;\n readonly onStop?: () => void;\n private parent?: ReactiveEffectImpl;\n\n constructor(\n private readonly fn: () => unknown,\n options: ReactiveEffectOptions = {}\n ) {\n this.scheduler = options.scheduler;\n this.onStop = options.onStop;\n }\n\n run(): unknown {\n if (!this.active) {\n return this.fn();\n }\n\n let parent = activeEffect;\n while (parent) {\n if (parent === this) {\n return undefined;\n }\n parent = parent.parent;\n }\n\n cleanupEffect(this);\n this.parent = activeEffect;\n activeEffect = this;\n trackStack.push(shouldTrack);\n shouldTrack = true;\n\n try {\n return this.fn();\n } finally {\n shouldTrack = trackStack.pop() ?? true;\n activeEffect = this.parent;\n this.parent = undefined;\n }\n }\n\n stop(): void {\n if (!this.active) {\n return;\n }\n cleanupEffect(this);\n this.onStop?.();\n this.active = false;\n }\n}\n\nfunction cleanupEffect(effect: ReactiveEffectImpl): void {\n for (const dep of effect.deps) {\n dep.delete(effect);\n }\n effect.deps.length = 0;\n}\n\nexport function effect<T = unknown>(\n fn: () => T,\n options: ReactiveEffectOptions = {}\n): ReactiveEffectRunner<T> {\n const _effect = new ReactiveEffectImpl(fn as () => unknown, options);\n if (!options.lazy) {\n _effect.run();\n }\n\n const runner = _effect.run.bind(_effect) as ReactiveEffectRunner<T>;\n runner.effect = _effect;\n return runner;\n}\n\nexport function stop(runner: ReactiveEffectRunner): void {\n runner.effect.stop();\n}\n\nexport function track(target: object, key: PropertyKey): void {\n if (!isTracking()) {\n return;\n }\n\n let depsMap = targetMap.get(target);\n if (!depsMap) {\n depsMap = new Map();\n targetMap.set(target, depsMap);\n }\n\n let dep = depsMap.get(key);\n if (!dep) {\n dep = new Set();\n depsMap.set(key, dep);\n }\n\n trackEffects(dep);\n}\n\nexport function trackEffects(dep: Dep): void {\n if (!activeEffect || dep.has(activeEffect)) {\n return;\n }\n dep.add(activeEffect);\n activeEffect.deps.push(dep);\n}\n\nexport function trigger(\n target: object,\n key: PropertyKey,\n operation: TriggerOperation = \"set\",\n newValue?: unknown,\n oldLength?: number\n): void {\n const depsMap = targetMap.get(target);\n if (!depsMap) {\n return;\n }\n\n const effects: Dep = new Set();\n const addEffects = (dep?: Dep) => {\n if (!dep) {\n return;\n }\n for (const effect of dep) {\n effects.add(effect);\n }\n };\n\n if (Array.isArray(target) && key === \"length\") {\n const nextLength = Number(newValue);\n for (const [depKey, dep] of depsMap) {\n if (\n depKey === \"length\"\n || depKey === ITERATE_KEY\n || (isArrayIndex(depKey) && Number(depKey) >= nextLength)\n ) {\n addEffects(dep);\n }\n }\n } else {\n addEffects(depsMap.get(key));\n\n if (operation === \"add\" || operation === \"delete\") {\n addEffects(depsMap.get(ITERATE_KEY));\n }\n\n if (\n operation === \"add\"\n && Array.isArray(target)\n && isArrayIndex(key)\n && typeof oldLength === \"number\"\n && Number(key) >= oldLength\n ) {\n addEffects(depsMap.get(\"length\"));\n }\n }\n\n triggerEffects(effects);\n}\n\nexport function triggerEffects(dep: Dep): void {\n for (const effect of [...dep]) {\n if (effect === activeEffect) {\n continue;\n }\n if (effect.scheduler) {\n effect.scheduler();\n } else {\n effect.run();\n }\n }\n}\n\nexport function isTracking(): boolean {\n return shouldTrack && activeEffect !== undefined;\n}\n\nexport function pauseTracking(): void {\n trackStack.push(shouldTrack);\n shouldTrack = false;\n}\n\nexport function resetTracking(): void {\n shouldTrack = trackStack.pop() ?? true;\n}\n\nfunction isArrayIndex(key: PropertyKey): boolean {\n if (typeof key === \"symbol\" || key === \"length\") {\n return false;\n }\n const value = String(key);\n return /^(?:0|[1-9]\\d*)$/.test(value)\n && Number(value) < 4_294_967_295;\n}\n"],"mappings":";AAaA,MAAa,cAAc,OAAO,gBAAgB;AAElD,MAAM,4BAAY,IAAI,SAA8B;AAEpD,IAAI;AACJ,IAAI,cAAc;AAElB,MAAM,aAAwB,EAAE;AAEhC,IAAM,qBAAN,MAAuD;CACrD,SAAS;CACT,OAAc,EAAE;CAChB,AAAS;CACT,AAAS;CACT,AAAQ;CAER,YACE,AAAiB,IACjB,UAAiC,EAAE,EACnC;EAFiB;AAGjB,OAAK,YAAY,QAAQ;AACzB,OAAK,SAAS,QAAQ;;CAGxB,MAAe;AACb,MAAI,CAAC,KAAK,OACR,QAAO,KAAK,IAAI;EAGlB,IAAI,SAAS;AACb,SAAO,QAAQ;AACb,OAAI,WAAW,KACb;AAEF,YAAS,OAAO;;AAGlB,gBAAc,KAAK;AACnB,OAAK,SAAS;AACd,iBAAe;AACf,aAAW,KAAK,YAAY;AAC5B,gBAAc;A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back, WatchCleanup, WatchOptions, WatchSource, WatchStopHandle } from "./types.js";
|
|
2
|
+
import { effect, stop } from "./effect.js";
|
|
3
|
+
import { isRef, ref, toRef, toRefs, unref } from "./ref.js";
|
|
4
|
+
import { isReactive, isReadonly, reactive, readonly, toRaw } from "./reactive.js";
|
|
5
|
+
import { computed, isComputed } from "./computed.js";
|
|
6
|
+
import { watch, watchEffect } from "./watch.js";
|
|
7
|
+
import { nextTick } from "./scheduler.js";
|
|
8
|
+
export { type ComputedRef, type MaybeRef, type MaybeRefOrGetter, type ReactiveEffectOptions, type ReactiveEffectRunner, type Ref, type WatchCallback, type WatchCleanup, type WatchOptions, type WatchSource, type WatchStopHandle, computed, effect, isComputed, isReactive, isReadonly, isRef, nextTick, reactive, readonly, ref, stop, toRaw, toRef, toRefs, unref, watch, watchEffect };
|
package/dist/reactivity/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { effect, stop } from "./effect.js";
|
|
2
|
+
import { isReactive, isReadonly, reactive, readonly, toRaw } from "./reactive.js";
|
|
3
|
+
import { isRef, ref, toRef, toRefs, unref } from "./ref.js";
|
|
4
|
+
import { computed, isComputed } from "./computed.js";
|
|
5
|
+
import { nextTick } from "./scheduler.js";
|
|
6
|
+
import { watch, watchEffect } from "./watch.js";
|
|
7
|
+
|
|
8
|
+
export { computed, effect, isComputed, isReactive, isReadonly, isRef, nextTick, reactive, readonly, ref, stop, toRaw, toRef, toRefs, unref, watch, watchEffect };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region src/reactivity/reactive.d.ts
|
|
2
|
+
declare function reactive<T extends object>(target: T): T;
|
|
3
|
+
declare function readonly<T>(target: T): Readonly<T>;
|
|
4
|
+
declare function isReactive(value: unknown): boolean;
|
|
5
|
+
declare function isReadonly(value: unknown): boolean;
|
|
6
|
+
declare function toRaw<T>(value: T): T;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isReactive, isReadonly, reactive, readonly, toRaw };
|
|
9
|
+
//# sourceMappingURL=reactive.d.ts.map
|