dtwo 2.17.0 → 3.0.0-rc.14

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.
Files changed (118) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -41
  3. package/app.d.ts +1 -0
  4. package/bin/dtwo.mjs +2 -0
  5. package/config.cjs +7 -0
  6. package/config.d.ts +4 -0
  7. package/config.mjs +5 -0
  8. package/dist/app/compat/capi.d.ts +4 -0
  9. package/dist/app/compat/capi.mjs +19 -0
  10. package/dist/app/compat/kdu-demi.d.ts +4 -0
  11. package/dist/app/compat/kdu-demi.mjs +4 -0
  12. package/dist/app/components/client-only.d.mts +22 -0
  13. package/dist/app/components/client-only.mjs +75 -0
  14. package/dist/app/components/dev-only.d.mts +4 -0
  15. package/dist/app/components/dev-only.mjs +11 -0
  16. package/dist/app/components/dtwo-error-boundary.d.ts +8 -0
  17. package/dist/app/components/dtwo-error-boundary.mjs +21 -0
  18. package/dist/app/components/dtwo-error-page.kdu +46 -0
  19. package/dist/app/components/dtwo-link.d.ts +33 -0
  20. package/dist/app/components/dtwo-link.mjs +248 -0
  21. package/dist/app/components/dtwo-loading-indicator.d.ts +43 -0
  22. package/dist/app/components/dtwo-loading-indicator.mjs +107 -0
  23. package/dist/app/components/dtwo-root.kdu +35 -0
  24. package/dist/app/components/index.d.ts +2 -0
  25. package/dist/app/components/index.mjs +1 -0
  26. package/dist/app/components/layout.d.ts +17 -0
  27. package/dist/app/components/layout.mjs +66 -0
  28. package/dist/app/components/server-placeholder.d.ts +2 -0
  29. package/dist/app/components/server-placeholder.mjs +7 -0
  30. package/dist/app/components/utils.d.ts +11 -0
  31. package/dist/app/components/utils.mjs +9 -0
  32. package/dist/app/composables/asyncData.d.ts +40 -0
  33. package/dist/app/composables/asyncData.mjs +169 -0
  34. package/dist/app/composables/component.d.ts +3 -0
  35. package/dist/app/composables/component.mjs +46 -0
  36. package/dist/app/composables/cookie.d.ts +12 -0
  37. package/dist/app/composables/cookie.mjs +58 -0
  38. package/dist/app/composables/error.d.ts +17 -0
  39. package/dist/app/composables/error.mjs +31 -0
  40. package/dist/app/composables/fetch.d.ts +15 -0
  41. package/dist/app/composables/fetch.mjs +66 -0
  42. package/dist/app/composables/hydrate.d.ts +8 -0
  43. package/dist/app/composables/hydrate.mjs +14 -0
  44. package/dist/app/composables/index.d.ts +16 -0
  45. package/dist/app/composables/index.mjs +11 -0
  46. package/dist/app/composables/payload.d.ts +8 -0
  47. package/dist/app/composables/payload.mjs +58 -0
  48. package/dist/app/composables/preload.d.ts +17 -0
  49. package/dist/app/composables/preload.mjs +41 -0
  50. package/dist/app/composables/router.d.ts +28 -0
  51. package/dist/app/composables/router.mjs +111 -0
  52. package/dist/app/composables/ssr.d.ts +6 -0
  53. package/dist/app/composables/ssr.mjs +23 -0
  54. package/dist/app/composables/state.d.ts +9 -0
  55. package/dist/app/composables/state.mjs +27 -0
  56. package/dist/app/config.d.ts +13 -0
  57. package/dist/app/config.mjs +56 -0
  58. package/dist/app/dtwo.d.ts +122 -0
  59. package/dist/app/dtwo.mjs +168 -0
  60. package/dist/app/entry.async.d.ts +2 -0
  61. package/dist/app/entry.async.mjs +5 -0
  62. package/dist/app/entry.d.ts +3 -0
  63. package/dist/app/entry.mjs +59 -0
  64. package/dist/app/index.d.ts +10 -0
  65. package/dist/app/index.mjs +7 -0
  66. package/dist/app/plugins/cross-origin-prefetch.client.d.ts +2 -0
  67. package/dist/app/plugins/cross-origin-prefetch.client.mjs +28 -0
  68. package/dist/app/plugins/debug.d.ts +2 -0
  69. package/dist/app/plugins/debug.mjs +5 -0
  70. package/dist/app/plugins/payload.client.d.ts +2 -0
  71. package/dist/app/plugins/payload.client.mjs +22 -0
  72. package/dist/app/plugins/preload.server.d.ts +2 -0
  73. package/dist/app/plugins/preload.server.mjs +10 -0
  74. package/dist/app/plugins/router.d.ts +53 -0
  75. package/dist/app/plugins/router.mjs +176 -0
  76. package/dist/app/types/augments.d.ts +28 -0
  77. package/dist/core/runtime/hole/error.d.ts +3 -0
  78. package/dist/core/runtime/hole/error.mjs +58 -0
  79. package/dist/core/runtime/hole/paths.d.ts +4 -0
  80. package/dist/core/runtime/hole/paths.mjs +15 -0
  81. package/dist/core/runtime/hole/renderer.d.ts +16 -0
  82. package/dist/core/runtime/hole/renderer.mjs +219 -0
  83. package/dist/head/runtime/components.d.ts +796 -0
  84. package/dist/head/runtime/components.mjs +209 -0
  85. package/dist/head/runtime/composables.d.ts +10 -0
  86. package/dist/head/runtime/composables.mjs +4 -0
  87. package/dist/head/runtime/index.d.ts +4 -0
  88. package/dist/head/runtime/index.mjs +1 -0
  89. package/dist/head/runtime/lib/kdu-meta.plugin.d.ts +2 -0
  90. package/dist/head/runtime/lib/kdu-meta.plugin.mjs +31 -0
  91. package/dist/head/runtime/lib/kduse-head.plugin.d.ts +2 -0
  92. package/dist/head/runtime/lib/kduse-head.plugin.mjs +35 -0
  93. package/dist/head/runtime/types.d.ts +7 -0
  94. package/dist/head/runtime/types.mjs +0 -0
  95. package/dist/index.d.ts +9 -0
  96. package/dist/index.mjs +2274 -0
  97. package/dist/pages/runtime/app.kdu +5 -0
  98. package/dist/pages/runtime/composables.d.ts +42 -0
  99. package/dist/pages/runtime/composables.mjs +8 -0
  100. package/dist/pages/runtime/index.d.ts +1 -0
  101. package/dist/pages/runtime/index.mjs +1 -0
  102. package/dist/pages/runtime/page-placeholder.d.ts +4 -0
  103. package/dist/pages/runtime/page-placeholder.mjs +10 -0
  104. package/dist/pages/runtime/page.d.ts +15 -0
  105. package/dist/pages/runtime/page.mjs +107 -0
  106. package/dist/pages/runtime/router.d.ts +8 -0
  107. package/dist/pages/runtime/router.mjs +152 -0
  108. package/dist/pages/runtime/router.options.d.ts +2 -0
  109. package/dist/pages/runtime/router.options.mjs +51 -0
  110. package/dist/pages/runtime/utils.d.ts +9 -0
  111. package/dist/pages/runtime/utils.mjs +12 -0
  112. package/dist/pages/runtime/validate.d.ts +2 -0
  113. package/dist/pages/runtime/validate.mjs +11 -0
  114. package/package.json +79 -42
  115. package/types.d.ts +15 -0
  116. package/bin/dtwo.js +0 -10
  117. package/dist/dtwo.js +0 -37
  118. package/webpack.config.js +0 -4
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023-present Dtwo Team
3
+ Copyright (c) 2022 - Dtwo Project
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,42 +1,3 @@
1
- # Dtwo
1
+ # Dtwo 3
2
2
 
3
- > Build your next Kdu(2) application with confidence using Dtwo: a framework making web development simple and powerful.
4
-
5
- ## Features
6
-
7
- - Automatic transpilation and bundling (with webpack and babel)
8
- - Hot code reloading
9
- - Server-side rendering OR Single Page App OR Static Generated, you choose :fire:
10
- - Static file serving. `./static/` is mapped to `/`
11
- - Configurable with a `dtwo.config.js` file
12
- - Custom layouts with the `layouts/` directory
13
- - Middleware
14
- - Code splitting for every `pages/`
15
- - Loading just the critical CSS (page-level)
16
-
17
- Learn more at <https://dtwojs-v2.web.app>.
18
-
19
- ## Getting started
20
-
21
- ```sh
22
- $ npx create-dtwo-app <project-name>
23
- ```
24
-
25
- It's as simple as that!
26
-
27
- Learn more at https://dtwojs-2.web.app/guide/installation
28
-
29
- ## Production deployment
30
-
31
- To deploy, instead of running dtwo, you probably want to build ahead of time. Therefore, building and starting are separate commands:
32
-
33
- ```bash
34
- dtwo build
35
- dtwo start
36
- ```
37
-
38
- Learn more at https://dtwojs-v2.web.app/guide/commands#production-deployment
39
-
40
- ## License
41
-
42
- [MIT](./LICENSE)
3
+ > The core of Dtwo 3
package/app.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/app'
package/bin/dtwo.mjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '@dtwo/cli/cli'
package/config.cjs ADDED
@@ -0,0 +1,7 @@
1
+ function defineDtwoConfig (config) {
2
+ return config
3
+ }
4
+
5
+ module.exports = {
6
+ defineDtwoConfig
7
+ }
package/config.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { DtwoConfig } from '@dtwo/schema'
2
+ export { DtwoConfig } from '@dtwo/schema'
3
+
4
+ export declare function defineDtwoConfig(config: DtwoConfig): DtwoConfig
package/config.mjs ADDED
@@ -0,0 +1,5 @@
1
+ function defineDtwoConfig (config) {
2
+ return config
3
+ }
4
+
5
+ export { defineDtwoConfig }
@@ -0,0 +1,4 @@
1
+ export * from 'kdu';
2
+ export declare const install: () => void;
3
+ export declare function set(target: any, key: string | number | symbol, val: any): any;
4
+ export declare function del(target: any, key: string | number | symbol): void;
@@ -0,0 +1,19 @@
1
+ export * from "kdu";
2
+ export const install = () => {
3
+ };
4
+ export function set(target, key, val) {
5
+ if (Array.isArray(target)) {
6
+ target.length = Math.max(target.length, key);
7
+ target.splice(key, 1, val);
8
+ return val;
9
+ }
10
+ target[key] = val;
11
+ return val;
12
+ }
13
+ export function del(target, key) {
14
+ if (Array.isArray(target)) {
15
+ target.splice(key, 1);
16
+ return;
17
+ }
18
+ delete target[key];
19
+ }
@@ -0,0 +1,4 @@
1
+ export * from './capi';
2
+ export declare const Kdu2: undefined;
3
+ export declare const isKdu2 = false;
4
+ export declare const isKdu3 = true;
@@ -0,0 +1,4 @@
1
+ export * from "./capi.mjs";
2
+ export const Kdu2 = void 0;
3
+ export const isKdu2 = false;
4
+ export const isKdu3 = true;
@@ -0,0 +1,22 @@
1
+ export function createClientOnly(component: any): any;
2
+ declare const _default: import("kdu").DefineComponent<Readonly<{
3
+ fallback?: any;
4
+ placeholder?: any;
5
+ placeholderTag?: any;
6
+ fallbackTag?: any;
7
+ }>, (props: any) => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
8
+ [key: string]: any;
9
+ }>[] | import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
10
+ [key: string]: any;
11
+ }> | undefined, any, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<Readonly<{
12
+ fallback?: any;
13
+ placeholder?: any;
14
+ placeholderTag?: any;
15
+ fallbackTag?: any;
16
+ }>>>, {
17
+ readonly fallback?: any;
18
+ readonly placeholder?: any;
19
+ readonly placeholderTag?: any;
20
+ readonly fallbackTag?: any;
21
+ }>;
22
+ export default _default;
@@ -0,0 +1,75 @@
1
+ import { ref, onMounted, defineComponent, createElementBlock, h, createElementKNode } from 'kdu'
2
+
3
+ export default defineComponent({
4
+ name: 'ClientOnly',
5
+ inheritAttrs: false,
6
+ // eslint-disable-next-line kdu/require-prop-types
7
+ props: ['fallback', 'placeholder', 'placeholderTag', 'fallbackTag'],
8
+ setup (_, { slots, attrs }) {
9
+ const mounted = ref(false)
10
+ onMounted(() => { mounted.value = true })
11
+ return (props) => {
12
+ if (mounted.value) { return slots.default?.() }
13
+ const slot = slots.fallback || slots.placeholder
14
+ if (slot) { return slot() }
15
+ const fallbackStr = props.fallback || props.placeholder || ''
16
+ const fallbackTag = props.fallbackTag || props.placeholderTag || 'span'
17
+ return createElementBlock(fallbackTag, attrs, fallbackStr)
18
+ }
19
+ }
20
+ })
21
+
22
+ const cache = new WeakMap()
23
+
24
+ export function createClientOnly (component) {
25
+ if (cache.has(component)) {
26
+ return cache.get(component)
27
+ }
28
+
29
+ const clone = { ...component }
30
+
31
+ if (clone.render) {
32
+ // override the component render (non script setup component)
33
+ clone.render = (ctx, ...args) => {
34
+ if (ctx.mounted$) {
35
+ const res = component.render(ctx, ...args)
36
+ return (res.children === null || typeof res.children === 'string')
37
+ ? createElementKNode(res.type, res.props, res.children, res.patchFlag, res.dynamicProps, res.shapeFlag)
38
+ : h(res)
39
+ } else {
40
+ return h('div', ctx.$attrs ?? ctx._.attrs)
41
+ }
42
+ }
43
+ } else if (clone.template) {
44
+ // handle runtime-compiler template
45
+ clone.template = `
46
+ <template k-if="mounted$">${component.template}</template>
47
+ <template k-else><div></div></template>
48
+ `
49
+ }
50
+
51
+ clone.setup = (props, ctx) => {
52
+ const mounted$ = ref(false)
53
+ onMounted(() => { mounted$.value = true })
54
+
55
+ return Promise.resolve(component.setup?.(props, ctx) || {})
56
+ .then((setupState) => {
57
+ return typeof setupState !== 'function'
58
+ ? { ...setupState, mounted$ }
59
+ : (...args) => {
60
+ if (mounted$.value) {
61
+ const res = setupState(...args)
62
+ return (res.children === null || typeof res.children === 'string')
63
+ ? createElementKNode(res.type, res.props, res.children, res.patchFlag, res.dynamicProps, res.shapeFlag)
64
+ : h(res)
65
+ } else {
66
+ return h('div', ctx.attrs)
67
+ }
68
+ }
69
+ })
70
+ }
71
+
72
+ cache.set(component, clone)
73
+
74
+ return clone
75
+ }
@@ -0,0 +1,4 @@
1
+ declare const _default: import("kdu").DefineComponent<{}, (() => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
2
+ [key: string]: any;
3
+ }>[] | undefined) | (() => null), {}, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{}>>, {}>;
4
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { defineComponent } from 'kdu'
2
+
3
+ export default defineComponent({
4
+ name: 'DevOnly',
5
+ setup (_, props) {
6
+ if (process.dev) {
7
+ return () => props.slots.default?.()
8
+ }
9
+ return () => null
10
+ }
11
+ })
@@ -0,0 +1,8 @@
1
+ declare const _default: import("kdu").DefineComponent<{}, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
2
+ [key: string]: any;
3
+ }>[] | undefined, {}, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {
4
+ error(_error: unknown): boolean;
5
+ }, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{}>> & {
6
+ onError?: ((_error: unknown) => any) | undefined;
7
+ }, {}>;
8
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { defineComponent, ref, onErrorCaptured } from "kdu";
2
+ import { useDtwoApp } from "#app";
3
+ export default defineComponent({
4
+ emits: {
5
+ error(_error) {
6
+ return true;
7
+ }
8
+ },
9
+ setup(_props, { slots, emit }) {
10
+ const error = ref(null);
11
+ const dtwoApp = useDtwoApp();
12
+ onErrorCaptured((err) => {
13
+ if (process.client && !dtwoApp.isHydrating) {
14
+ emit("error", err);
15
+ error.value = err;
16
+ return false;
17
+ }
18
+ });
19
+ return () => error.value ? slots.error?.({ error }) : slots.default?.();
20
+ }
21
+ });
@@ -0,0 +1,46 @@
1
+ <template>
2
+ <ErrorTemplate k-bind="{ statusCode, statusMessage, description, stack }" />
3
+ </template>
4
+
5
+ <script setup>
6
+ import { defineAsyncComponent } from 'kdu'
7
+
8
+ // Deliberately prevent reactive update when error is cleared
9
+ // eslint-disable-next-line kdu/no-setup-props-destructure
10
+ const { error } = defineProps({
11
+ error: Object
12
+ })
13
+
14
+ // TODO: extract to a separate utility
15
+ const stacktrace = (error.stack || '')
16
+ .split('\n')
17
+ .splice(1)
18
+ .map((line) => {
19
+ const text = line
20
+ .replace('webpack:/', '')
21
+ .replace('.kdu', '.js') // TODO: Support sourcemap
22
+ .trim()
23
+ return {
24
+ text,
25
+ internal: (line.includes('node_modules') && !line.includes('.cache')) ||
26
+ line.includes('internal') ||
27
+ line.includes('new Promise')
28
+ }
29
+ }).map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')
30
+
31
+ // Error page props
32
+ const statusCode = Number(error.statusCode || 500)
33
+ const is404 = statusCode === 404
34
+
35
+ const statusMessage = error.statusMessage ?? (is404 ? 'Page Not Found' : 'Internal Server Error')
36
+ const description = error.message || error.toString()
37
+ const stack = process.dev && !is404 ? error.description || `<pre>${stacktrace}</pre>` : undefined
38
+
39
+ // TODO: Investigate side-effect issue with imports
40
+ const _Error404 = defineAsyncComponent(() => import('@dtwo/ui-templates/templates/error-404.kdu').then(r => r.default || r))
41
+ const _Error = process.dev
42
+ ? defineAsyncComponent(() => import('@dtwo/ui-templates/templates/error-dev.kdu').then(r => r.default || r))
43
+ : defineAsyncComponent(() => import('@dtwo/ui-templates/templates/error-500.kdu').then(r => r.default || r))
44
+
45
+ const ErrorTemplate = is404 ? _Error404 : _Error
46
+ </script>
@@ -0,0 +1,33 @@
1
+ import { DefineComponent } from 'kdu';
2
+ import type { RouteLocationRaw } from 'kdu-router';
3
+ export type DtwoLinkOptions = {
4
+ componentName?: string;
5
+ externalRelAttribute?: string | null;
6
+ activeClass?: string;
7
+ exactActiveClass?: string;
8
+ prefetchedClass?: string;
9
+ };
10
+ export type DtwoLinkProps = {
11
+ to?: string | RouteLocationRaw;
12
+ href?: string | RouteLocationRaw;
13
+ external?: boolean;
14
+ replace?: boolean;
15
+ custom?: boolean;
16
+ target?: '_blank' | '_parent' | '_self' | '_top' | (string & {}) | null;
17
+ rel?: string | null;
18
+ noRel?: boolean;
19
+ prefetch?: boolean;
20
+ noPrefetch?: boolean;
21
+ activeClass?: string;
22
+ exactActiveClass?: string;
23
+ ariaCurrentValue?: string;
24
+ };
25
+ export declare function defineDtwoLink(options: DtwoLinkOptions): DefineComponent<DtwoLinkProps, {}, {}, import("kdu").ComputedOptions, import("kdu").MethodOptions, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<DtwoLinkProps>, {
26
+ to?: any;
27
+ href?: any;
28
+ }>;
29
+ declare const _default: DefineComponent<DtwoLinkProps, {}, {}, import("kdu").ComputedOptions, import("kdu").MethodOptions, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<DtwoLinkProps>, {
30
+ to?: any;
31
+ href?: any;
32
+ }>;
33
+ export default _default;
@@ -0,0 +1,248 @@
1
+ import { defineComponent, h, ref, resolveComponent, computed, onMounted, onBeforeUnmount } from "kdu";
2
+ import { hasProtocol } from "ufo";
3
+ import { preloadRouteComponents } from "../composables/preload.mjs";
4
+ import { navigateTo, useRouter } from "../composables/router.mjs";
5
+ import { useDtwoApp } from "../dtwo.mjs";
6
+ const firstNonUndefined = (...args) => args.find((arg) => arg !== void 0);
7
+ const DEFAULT_EXTERNAL_REL_ATTRIBUTE = "noopener noreferrer";
8
+ const requestIdleCallback = process.server ? void 0 : globalThis.requestIdleCallback || ((cb) => {
9
+ const start = Date.now();
10
+ const idleDeadline = {
11
+ didTimeout: false,
12
+ timeRemaining: () => Math.max(0, 50 - (Date.now() - start))
13
+ };
14
+ return setTimeout(() => {
15
+ cb(idleDeadline);
16
+ }, 1);
17
+ });
18
+ const cancelIdleCallback = process.server ? null : globalThis.cancelIdleCallback || ((id) => {
19
+ clearTimeout(id);
20
+ });
21
+ export function defineDtwoLink(options) {
22
+ const componentName = options.componentName || "DtwoLink";
23
+ const checkPropConflicts = (props, main, sub) => {
24
+ if (process.dev && props[main] !== void 0 && props[sub] !== void 0) {
25
+ console.warn(`[${componentName}] \`${main}\` and \`${sub}\` cannot be used together. \`${sub}\` will be ignored.`);
26
+ }
27
+ };
28
+ return defineComponent({
29
+ name: componentName,
30
+ props: {
31
+ to: {
32
+ type: [String, Object],
33
+ default: void 0,
34
+ required: false
35
+ },
36
+ href: {
37
+ type: [String, Object],
38
+ default: void 0,
39
+ required: false
40
+ },
41
+ target: {
42
+ type: String,
43
+ default: void 0,
44
+ required: false
45
+ },
46
+ rel: {
47
+ type: String,
48
+ default: void 0,
49
+ required: false
50
+ },
51
+ noRel: {
52
+ type: Boolean,
53
+ default: void 0,
54
+ required: false
55
+ },
56
+ prefetch: {
57
+ type: Boolean,
58
+ default: void 0,
59
+ required: false
60
+ },
61
+ noPrefetch: {
62
+ type: Boolean,
63
+ default: void 0,
64
+ required: false
65
+ },
66
+ activeClass: {
67
+ type: String,
68
+ default: void 0,
69
+ required: false
70
+ },
71
+ exactActiveClass: {
72
+ type: String,
73
+ default: void 0,
74
+ required: false
75
+ },
76
+ prefetchedClass: {
77
+ type: String,
78
+ default: void 0,
79
+ required: false
80
+ },
81
+ replace: {
82
+ type: Boolean,
83
+ default: void 0,
84
+ required: false
85
+ },
86
+ ariaCurrentValue: {
87
+ type: String,
88
+ default: void 0,
89
+ required: false
90
+ },
91
+ external: {
92
+ type: Boolean,
93
+ default: void 0,
94
+ required: false
95
+ },
96
+ custom: {
97
+ type: Boolean,
98
+ default: void 0,
99
+ required: false
100
+ }
101
+ },
102
+ setup(props, { slots }) {
103
+ const router = useRouter();
104
+ const to = computed(() => {
105
+ checkPropConflicts(props, "to", "href");
106
+ return props.to || props.href || "";
107
+ });
108
+ const isExternal = computed(() => {
109
+ if (props.external) {
110
+ return true;
111
+ }
112
+ if (props.target && props.target !== "_self") {
113
+ return true;
114
+ }
115
+ if (typeof to.value === "object") {
116
+ return false;
117
+ }
118
+ return to.value === "" || hasProtocol(to.value, true);
119
+ });
120
+ const prefetched = ref(false);
121
+ const el = process.server ? void 0 : ref(null);
122
+ if (process.client) {
123
+ checkPropConflicts(props, "prefetch", "noPrefetch");
124
+ const shouldPrefetch = props.prefetch !== false && props.noPrefetch !== true && typeof to.value === "string" && props.target !== "_blank" && !isSlowConnection();
125
+ if (shouldPrefetch) {
126
+ const dtwoApp = useDtwoApp();
127
+ const observer = useObserver();
128
+ let idleId;
129
+ let unobserve = null;
130
+ onMounted(() => {
131
+ idleId = requestIdleCallback(() => {
132
+ if (el?.value?.tagName) {
133
+ unobserve = observer.observe(el.value, async () => {
134
+ unobserve?.();
135
+ unobserve = null;
136
+ await Promise.all([
137
+ dtwoApp.hooks.callHook("link:prefetch", to.value).catch(() => {
138
+ }),
139
+ !isExternal.value && preloadRouteComponents(to.value, router).catch(() => {
140
+ })
141
+ ]);
142
+ prefetched.value = true;
143
+ });
144
+ }
145
+ });
146
+ });
147
+ onBeforeUnmount(() => {
148
+ if (idleId) {
149
+ cancelIdleCallback(idleId);
150
+ }
151
+ unobserve?.();
152
+ unobserve = null;
153
+ });
154
+ }
155
+ }
156
+ return () => {
157
+ if (!isExternal.value) {
158
+ return h(
159
+ resolveComponent("RouterLink"),
160
+ {
161
+ ref: process.server ? void 0 : (ref2) => {
162
+ el.value = ref2?.$el;
163
+ },
164
+ to: to.value,
165
+ ...prefetched.value && !props.custom ? { class: props.prefetchedClass || options.prefetchedClass } : {},
166
+ activeClass: props.activeClass || options.activeClass,
167
+ exactActiveClass: props.exactActiveClass || options.exactActiveClass,
168
+ replace: props.replace,
169
+ ariaCurrentValue: props.ariaCurrentValue,
170
+ custom: props.custom
171
+ },
172
+ slots.default
173
+ );
174
+ }
175
+ const href = typeof to.value === "object" ? router.resolve(to.value)?.href ?? null : to.value || null;
176
+ const target = props.target || null;
177
+ checkPropConflicts(props, "noRel", "rel");
178
+ const rel = props.noRel ? null : firstNonUndefined(props.rel, options.externalRelAttribute, href ? DEFAULT_EXTERNAL_REL_ATTRIBUTE : "") || null;
179
+ const navigate = () => navigateTo(href, { replace: props.replace });
180
+ if (props.custom) {
181
+ if (!slots.default) {
182
+ return null;
183
+ }
184
+ return slots.default({
185
+ href,
186
+ navigate,
187
+ route: router.resolve(href),
188
+ rel,
189
+ target,
190
+ isExternal: isExternal.value,
191
+ isActive: false,
192
+ isExactActive: false
193
+ });
194
+ }
195
+ return h("a", { ref: el, href, rel, target }, slots.default?.());
196
+ };
197
+ }
198
+ });
199
+ }
200
+ export default defineDtwoLink({ componentName: "DtwoLink" });
201
+ function useObserver() {
202
+ if (process.server) {
203
+ return;
204
+ }
205
+ const dtwoApp = useDtwoApp();
206
+ if (dtwoApp._observer) {
207
+ return dtwoApp._observer;
208
+ }
209
+ let observer = null;
210
+ const callbacks = /* @__PURE__ */ new Map();
211
+ const observe = (element, callback) => {
212
+ if (!observer) {
213
+ observer = new IntersectionObserver((entries) => {
214
+ for (const entry of entries) {
215
+ const callback2 = callbacks.get(entry.target);
216
+ const isVisible = entry.isIntersecting || entry.intersectionRatio > 0;
217
+ if (isVisible && callback2) {
218
+ callback2();
219
+ }
220
+ }
221
+ });
222
+ }
223
+ callbacks.set(element, callback);
224
+ observer.observe(element);
225
+ return () => {
226
+ callbacks.delete(element);
227
+ observer.unobserve(element);
228
+ if (callbacks.size === 0) {
229
+ observer.disconnect();
230
+ observer = null;
231
+ }
232
+ };
233
+ };
234
+ const _observer = dtwoApp._observer = {
235
+ observe
236
+ };
237
+ return _observer;
238
+ }
239
+ function isSlowConnection() {
240
+ if (process.server) {
241
+ return;
242
+ }
243
+ const cn = navigator.connection;
244
+ if (cn && (cn.saveData || /2g/.test(cn.effectiveType))) {
245
+ return true;
246
+ }
247
+ return false;
248
+ }
@@ -0,0 +1,43 @@
1
+ declare const _default: import("kdu").DefineComponent<{
2
+ throttle: {
3
+ type: NumberConstructor;
4
+ default: number;
5
+ };
6
+ duration: {
7
+ type: NumberConstructor;
8
+ default: number;
9
+ };
10
+ height: {
11
+ type: NumberConstructor;
12
+ default: number;
13
+ };
14
+ color: {
15
+ type: StringConstructor;
16
+ default: string;
17
+ };
18
+ }, () => import("kdu").KNode<import("kdu").RendererNode, import("kdu").RendererElement, {
19
+ [key: string]: any;
20
+ }>, unknown, {}, {}, import("kdu").ComponentOptionsMixin, import("kdu").ComponentOptionsMixin, {}, string, import("kdu").KNodeProps & import("kdu").AllowedComponentProps & import("kdu").ComponentCustomProps, Readonly<import("kdu").ExtractPropTypes<{
21
+ throttle: {
22
+ type: NumberConstructor;
23
+ default: number;
24
+ };
25
+ duration: {
26
+ type: NumberConstructor;
27
+ default: number;
28
+ };
29
+ height: {
30
+ type: NumberConstructor;
31
+ default: number;
32
+ };
33
+ color: {
34
+ type: StringConstructor;
35
+ default: string;
36
+ };
37
+ }>>, {
38
+ duration: number;
39
+ throttle: number;
40
+ height: number;
41
+ color: string;
42
+ }>;
43
+ export default _default;