diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 40c35fc..d823d6a 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -38,6 +38,7 @@ jobs: cache: pnpm - run: pnpm install + - run: pnpm build:types - run: pnpm docs:build - name: Upload artifact diff --git a/package.json b/package.json index 8f20dc0..271592e 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "devDependencies": { "@antfu/eslint-config": "^2.16.1", "@tsconfig/node20": "^20.1.4", + "@types/fs-extra": "^11.0.4", "@types/node": "^20.12.8", "@unocss/reset": "^0.59.4", "@unocss/transformer-directives": "^0.59.4", @@ -71,9 +72,12 @@ "cesium": "^1.117.0", "consola": "^3.2.3", "eslint": "^8.57.0", + "fs-extra": "^11.2.0", "jsdom": "^24.0.0", "markdown-it-mathjax3": "^4.3.2", "npm-run-all2": "^6.1.2", + "pathe": "^1.1.2", + "prettier": "^3.2.5", "typescript": "^5.4.5", "unocss": "^0.59.4", "unplugin-auto-import": "^0.17.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c38edb..d2ebeb7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,6 +21,9 @@ importers: '@tsconfig/node20': specifier: ^20.1.4 version: 20.1.4 + '@types/fs-extra': + specifier: ^11.0.4 + version: 11.0.4 '@types/node': specifier: ^20.12.8 version: 20.12.8 @@ -51,6 +54,9 @@ importers: eslint: specifier: ^8.57.0 version: 8.57.0 + fs-extra: + specifier: ^11.2.0 + version: 11.2.0 jsdom: specifier: ^24.0.0 version: 24.0.0 @@ -60,6 +66,12 @@ importers: npm-run-all2: specifier: ^6.1.2 version: 6.1.2 + pathe: + specifier: ^1.1.2 + version: 1.1.2 + prettier: + specifier: ^3.2.5 + version: 3.2.5 typescript: specifier: ^5.4.5 version: 5.4.5 @@ -717,46 +729,55 @@ packages: resolution: {integrity: sha512-3reX2fUHqN7sffBNqmEyMQVj/CKhIHZd4y631duy0hZqI8Qoqf6lTtmAKvJFYa6bhU95B1D0WgzHkmTg33In0A==} cpu: [arm] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.17.2': resolution: {integrity: sha512-uSqpsp91mheRgw96xtyAGP9FW5ChctTFEoXP0r5FAzj/3ZRv3Uxjtc7taRQSaQM/q85KEKjKsZuiZM3GyUivRg==} cpu: [arm] os: [linux] + libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.17.2': resolution: {integrity: sha512-EMMPHkiCRtE8Wdk3Qhtciq6BndLtstqZIroHiiGzB3C5LDJmIZcSzVtLRbwuXuUft1Cnv+9fxuDtDxz3k3EW2A==} cpu: [arm64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.17.2': resolution: {integrity: sha512-NMPylUUZ1i0z/xJUIx6VUhISZDRT+uTWpBcjdv0/zkp7b/bQDF+NfnfdzuTiB1G6HTodgoFa93hp0O1xl+/UbA==} cpu: [arm64] os: [linux] + libc: [musl] '@rollup/rollup-linux-powerpc64le-gnu@4.17.2': resolution: {integrity: sha512-T19My13y8uYXPw/L/k0JYaX1fJKFT/PWdXiHr8mTbXWxjVF1t+8Xl31DgBBvEKclw+1b00Chg0hxE2O7bTG7GQ==} cpu: [ppc64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.17.2': resolution: {integrity: sha512-BOaNfthf3X3fOWAB+IJ9kxTgPmMqPPH5f5k2DcCsRrBIbWnaJCgX2ll77dV1TdSy9SaXTR5iDXRL8n7AnoP5cg==} cpu: [riscv64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.17.2': resolution: {integrity: sha512-W0UP/x7bnn3xN2eYMql2T/+wpASLE5SjObXILTMPUBDB/Fg/FxC+gX4nvCfPBCbNhz51C+HcqQp2qQ4u25ok6g==} cpu: [s390x] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.17.2': resolution: {integrity: sha512-Hy7pLwByUOuyaFC6mAr7m+oMC+V7qyifzs/nW2OJfC8H4hbCzOX07Ov0VFk/zP3kBsELWNFi7rJtgbKYsav9QQ==} cpu: [x64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-musl@4.17.2': resolution: {integrity: sha512-h1+yTWeYbRdAyJ/jMiVw0l6fOOm/0D1vNLui9iPuqgRGnXA0u21gAqOyB5iHjlM9MMfNOm9RHCQ7zLIzT0x11Q==} cpu: [x64] os: [linux] + libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.17.2': resolution: {integrity: sha512-tmdtXMfKAjy5+IQsVtDiCfqbynAQE/TQRpWdVataHmhMb9DCoJxp9vLcCBjEQWMiUYxO1QprH/HbY9ragCEFLA==} @@ -862,24 +883,28 @@ packages: engines: {node: '>=10'} cpu: [arm64] os: [linux] + libc: [glibc] '@swc/core-linux-arm64-musl@1.4.17': resolution: {integrity: sha512-qhH4gr9gAlVk8MBtzXbzTP3BJyqbAfUOATGkyUtohh85fPXQYuzVlbExix3FZXTwFHNidGHY8C+ocscI7uDaYw==} engines: {node: '>=10'} cpu: [arm64] os: [linux] + libc: [musl] '@swc/core-linux-x64-gnu@1.4.17': resolution: {integrity: sha512-vRDFATL1oN5oZMImkwbgSHEkp8xG1ofEASBypze01W1Tqto8t+yo6gsp69wzCZBlxldsvPpvFZW55Jq0Rn+UnA==} engines: {node: '>=10'} cpu: [x64] os: [linux] + libc: [glibc] '@swc/core-linux-x64-musl@1.4.17': resolution: {integrity: sha512-zQNPXAXn3nmPqv54JVEN8k2JMEcMTQ6veVuU0p5O+A7KscJq+AGle/7ZQXzpXSfUCXlLMX4wvd+rwfGhh3J4cw==} engines: {node: '>=10'} cpu: [x64] os: [linux] + libc: [musl] '@swc/core-win32-arm64-msvc@1.4.17': resolution: {integrity: sha512-z86n7EhOwyzxwm+DLE5NoLkxCTme2lq7QZlDjbQyfCxOt6isWz8rkW5QowTX8w9Rdmk34ncrjSLvnHOeLY17+w==} @@ -929,9 +954,15 @@ packages: '@types/estree@1.0.5': resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} + '@types/fs-extra@11.0.4': + resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==} + '@types/json-schema@7.0.15': resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} + '@types/jsonfile@6.1.4': + resolution: {integrity: sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==} + '@types/linkify-it@5.0.0': resolution: {integrity: sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==} @@ -2780,6 +2811,11 @@ packages: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} + prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} + hasBin: true + pretty-format@29.7.0: resolution: {integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -4412,8 +4448,17 @@ snapshots: '@types/estree@1.0.5': {} + '@types/fs-extra@11.0.4': + dependencies: + '@types/jsonfile': 6.1.4 + '@types/node': 20.12.8 + '@types/json-schema@7.0.15': {} + '@types/jsonfile@6.1.4': + dependencies: + '@types/node': 20.12.8 + '@types/linkify-it@5.0.0': {} '@types/markdown-it@14.1.1': @@ -6500,6 +6545,8 @@ snapshots: prelude-ls@1.2.1: {} + prettier@3.2.5: {} + pretty-format@29.7.0: dependencies: '@jest/schemas': 29.6.3 diff --git a/src/.vitepress/plugins/markdownTransform.ts b/src/.vitepress/plugins/markdownTransform.ts new file mode 100644 index 0000000..0700c5b --- /dev/null +++ b/src/.vitepress/plugins/markdownTransform.ts @@ -0,0 +1,66 @@ +import { fileURLToPath } from 'node:url' +import fs from 'fs-extra' +import { resolve } from 'pathe' +import type { Plugin } from 'vite' + +import { getTypeDeclaration } from '../utils' + +export function markdownTransform(): Plugin { + const DIR_CORE = resolve(fileURLToPath(import.meta.url), '../../../core') + const DIR_TYPES = resolve(fileURLToPath(import.meta.url), '../../../tsc-types/src/core') + const hasTypes = fs.existsSync(DIR_TYPES) + + if (!hasTypes) + console.warn('No types dist found, run `pnpm build:types` first.') + + return { + name: 'docs-md-transform', + enforce: 'pre', + async transform(code, id) { + if (!id.match(/\.md\b/)) + return + + const [pkg, name, i] = id.split('/').slice(-3) + const lang = langMap(i.split('-')[1].replace(/\.md$/, '') ?? 'en') + + const types = await getTypeDeclaration(pkg, name) + + const URL = 'https://github.com/s3xysteak/cesium-use/blob/main/src/core' + + const existDemo = fs.existsSync(`${DIR_CORE}/${pkg}/${name}/demo.vue`) + + const existsIndex = fs.existsSync(`${DIR_CORE}/${pkg}/${name}/index.ts`) + + return `${code} +${types +? ` +## ${lang?.type} + +::: details + +\`\`\`ts +${types} +\`\`\` + +::: +` +: ''} +## ${lang?.source} + +[source](${`${URL}/${pkg}/${name}/index.${existsIndex ? 'ts' : 'vue'}`})${existDemo ? ` • [demo](${`${URL}/core/${pkg}/${name}/demo.vue`})` : ''}` + }, + } +} + +function langMap(lang: string) { + return { + en: { + type: 'Type Declarations', + source: 'Source', + }, + zh: { + type: '类型声明', + source: '源码', + }, + }[lang] +} diff --git a/src/.vitepress/shared.ts b/src/.vitepress/shared.ts index 5c8b13a..464a57d 100644 --- a/src/.vitepress/shared.ts +++ b/src/.vitepress/shared.ts @@ -1,4 +1,5 @@ import { defineConfig } from 'vitepress' +import { markdownTransform } from './plugins/markdownTransform' export const shared = defineConfig({ title: 'Cesium Use', @@ -8,12 +9,15 @@ export const shared = defineConfig({ 'core/:part/:module/index.md': ':part/:module.md', 'core/:part/:module/index-zh.md': 'zh/:part/:module.md', }, - vite: { - publicDir: 'docs/public', - }, base: '/cesium-use/', head: [['link', { rel: 'icon', href: '/cesium-use/logo.webp' }]], markdown: { math: true, }, + vite: { + publicDir: 'docs/public', + plugins: [ + markdownTransform(), + ], + }, }) diff --git a/src/.vitepress/utils.ts b/src/.vitepress/utils.ts new file mode 100644 index 0000000..7ba9ff7 --- /dev/null +++ b/src/.vitepress/utils.ts @@ -0,0 +1,35 @@ +import { fileURLToPath } from 'node:url' +import fs from 'fs-extra' +import { join, resolve } from 'pathe' + +const DIR_TYPES = resolve(fileURLToPath(import.meta.url), '../../../tsc-types/src/core') + +export async function getTypeDeclaration(pkg: string, name: string): Promise { + const typingFilepath = join(DIR_TYPES, `${pkg}/${name}/index.d.ts`) + + if (!fs.existsSync(typingFilepath)) + return + + let types = await fs.readFile(typingFilepath, 'utf-8') + + if (!types) + return + + // clean up types + types = types + .replace('/// ', '') + .replace(/import\(.*?\)\./g, '') + .replace(/import[\s\S]+?from ?["'][\s\S]+?["']/g, '') + .replace(/export {}/g, '') + + const prettier = await import('prettier') + return (await prettier + .format( + types, + { + semi: false, + parser: 'typescript', + }, + )) + .trim() +} diff --git a/src/core/composables/useEntityCollection/index-zh.md b/src/core/composables/useEntityCollection/index-zh.md index db586f5..b91f8eb 100644 --- a/src/core/composables/useEntityCollection/index-zh.md +++ b/src/core/composables/useEntityCollection/index-zh.md @@ -15,21 +15,3 @@ collection.add({ ``` `useEntityCollection` 会在内部通过`getViewer`获取 viewer 实例。 - -## 类型声明 - -::: details - -```ts -// 与Cesium.EntityCollection的使用完全相同,只是重写了增删改查方法 - -export function useEntityCollection(...args: ConstructorParameters) { - return new EntityCollection(...args) -} - -class EntityCollection extends Cesium.EntityCollection { - // ... -} -``` - -::: diff --git a/src/core/composables/useEntityCollection/index.md b/src/core/composables/useEntityCollection/index.md index 5e021f6..4239d8c 100644 --- a/src/core/composables/useEntityCollection/index.md +++ b/src/core/composables/useEntityCollection/index.md @@ -15,21 +15,3 @@ collection.add({ ``` The `useEntityCollection` will internally retrieve the viewer instance through `getViewer`. - -## Usage Declaration - -::: details - -```ts -// It functions identically to Cesium's EntityCollection, with the exception of overridden methods for adding, removing, updating, and querying entities. - -export function useEntityCollection(...args: ConstructorParameters) { - return new EntityCollection(...args) -} - -class EntityCollection extends Cesium.EntityCollection { - // ... -} -``` - -::: diff --git a/src/core/composables/useEvent/index-zh.md b/src/core/composables/useEvent/index-zh.md index 9847309..510bd1d 100644 --- a/src/core/composables/useEvent/index-zh.md +++ b/src/core/composables/useEvent/index-zh.md @@ -21,31 +21,3 @@ const handler = useEvent((e) => { ``` 值得一提的是,建议在使用`useEvent`时先提供第二个参数,也就是`ScreenSpaceEventType`。这会触发`useEvent`的函数重载,以提供更好的类型提示。 - -## 类型声明 - -:::details - -```ts -export type SetInputActionArgs = Parameters< - InstanceType['setInputAction'] -> - -export function useEvent( - callback: Cesium.ScreenSpaceEventHandler.MotionEventCallback, - type: Cesium.ScreenSpaceEventType.MOUSE_MOVE -): Cesium.ScreenSpaceEventHandler - -export function useEvent( - callback: Cesium.ScreenSpaceEventHandler.PositionedEventCallback, - type: - | Cesium.ScreenSpaceEventType.LEFT_CLICK - | Cesium.ScreenSpaceEventType.RIGHT_CLICK -): Cesium.ScreenSpaceEventHandler - -export function useEvent( - ...args: SetInputActionArgs -): Cesium.ScreenSpaceEventHandler -``` - -::: diff --git a/src/core/composables/useEvent/index.md b/src/core/composables/useEvent/index.md index e0cbafc..372558a 100644 --- a/src/core/composables/useEvent/index.md +++ b/src/core/composables/useEvent/index.md @@ -21,31 +21,3 @@ const handler = useEvent((e) => { ``` It is worth noting that when using `useEvent`, it is recommended to first provide the second parameter, which is `ScreenSpaceEventType`. This triggers function overloading in `useEvent` to offer better type hints. - -## Type Declaration - -:::details - -```ts -export type SetInputActionArgs = Parameters< - InstanceType['setInputAction'] -> - -export function useEvent( - callback: Cesium.ScreenSpaceEventHandler.MotionEventCallback, - type: Cesium.ScreenSpaceEventType.MOUSE_MOVE -): Cesium.ScreenSpaceEventHandler - -export function useEvent( - callback: Cesium.ScreenSpaceEventHandler.PositionedEventCallback, - type: - | Cesium.ScreenSpaceEventType.LEFT_CLICK - | Cesium.ScreenSpaceEventType.RIGHT_CLICK -): Cesium.ScreenSpaceEventHandler - -export function useEvent( - ...args: SetInputActionArgs -): Cesium.ScreenSpaceEventHandler -``` - -::: diff --git a/src/core/composables/useFlyToArea/index-zh.md b/src/core/composables/useFlyToArea/index-zh.md index 0602153..4c9b137 100644 --- a/src/core/composables/useFlyToArea/index-zh.md +++ b/src/core/composables/useFlyToArea/index-zh.md @@ -16,21 +16,3 @@ flyToArea([[100, 20], [120, 40], [110, 30]], { - 数组中无数据时,不进行任何操作 - 数组中只有 1 个数据时,视角会飞行到俯视角位置。 - -## 类型声明 - -::: details - -```ts -export interface UseFlyToAreaOptions { - onSingle: () => void - onEmpty: () => void -} - -function useFlyToArea( - posList: MaybeCartesian3OrLonLat[], - options?: Partial -): void -``` - -::: diff --git a/src/core/composables/useFlyToArea/index.md b/src/core/composables/useFlyToArea/index.md index 2928ff3..77a3673 100644 --- a/src/core/composables/useFlyToArea/index.md +++ b/src/core/composables/useFlyToArea/index.md @@ -16,21 +16,3 @@ By default: - When there is nothing in the array, no action will be taken. - When there is only 1 element in the array, the viewpoint will fly to an overhead position on the coordinate. - -## Type Declarations - -::: details - -```ts -export interface UseFlyToAreaOptions { - onSingle: () => void - onEmpty: () => void -} - -function useFlyToArea( - posList: MaybeCartesian3OrLonLat[], - options?: Partial -): void -``` - -::: diff --git a/src/core/composables/useGlobePick/index-zh.md b/src/core/composables/useGlobePick/index-zh.md index 88dbeb4..a7045ef 100644 --- a/src/core/composables/useGlobePick/index-zh.md +++ b/src/core/composables/useGlobePick/index-zh.md @@ -15,13 +15,3 @@ useEvent(({ position }) => { ``` 这种方式只会获取 `椭球体 + 地形`上的坐标,而会忽略tileset和模型等。 - -## 类型声明 - -::: details - -```ts -function useGlobePick(): (position: Cartesian2) => Cartesian3 | undefined -``` - -::: diff --git a/src/core/composables/useGlobePick/index.md b/src/core/composables/useGlobePick/index.md index 6388dd4..1350292 100644 --- a/src/core/composables/useGlobePick/index.md +++ b/src/core/composables/useGlobePick/index.md @@ -15,13 +15,3 @@ useEvent(({ position }) => { ``` This method will only obtain the coordinates on the `ellipsoid + terrain`, and will ignore the tileset and model. - -## Type Declaration - -::: details - -```ts -function useGlobePick(): (position: Cartesian2) => Cartesian3 | undefined -``` - -::: diff --git a/src/core/composables/useMeasure/index-zh.md b/src/core/composables/useMeasure/index-zh.md index 62a1fdf..89a00fe 100644 --- a/src/core/composables/useMeasure/index-zh.md +++ b/src/core/composables/useMeasure/index-zh.md @@ -42,22 +42,3 @@ const { state, clearAll } = useMeasure('height') `state` 为 `true` 时开始测高,左键选择起点,双击左键选择终点。内部通过 `editEntity` 合并各个点的构造参数。 通过计算投影坐标来获得高度。 - -## 类型声明 - -更多类型细节请见类型声明文件。 - -::: details - -```ts -type UseMeasureType = 'area' | 'distance' | 'height' -type UseMeasureOptions = AreaOptions | DistanceOptions | HeightOptions -type UseMeasureReturns = AreaReturn | DistanceReturn | HeightReturn - -export function useMeasure(type: 'area', options: AreaOptions): AreaReturn -export function useMeasure(type: 'distance', options: DistanceOptions): DistanceReturn -export function useMeasure(type: 'height', options: HeightOptions): HeightReturn -export function useMeasure(type: UseMeasureType, options: UseMeasureOptions): UseMeasureReturns -``` - -::: diff --git a/src/core/composables/useMeasure/index.md b/src/core/composables/useMeasure/index.md index 1e24160..694ac8b 100644 --- a/src/core/composables/useMeasure/index.md +++ b/src/core/composables/useMeasure/index.md @@ -42,22 +42,3 @@ const { state, clearAll } = useMeasure('height') Start measuring when `state` is `true`. Left click to pick the start point, double left click to pick the end point. It use `editEntity` to merge constructor options of all entities. Obtain the height by calculating the projected coordinates. - -## Type Declaration - -For more detailed types, please refer to the type declaration file. - -::: details - -```ts -type UseMeasureType = 'area' | 'distance' | 'height' -type UseMeasureOptions = AreaOptions | DistanceOptions | HeightOptions -type UseMeasureReturns = AreaReturn | DistanceReturn | HeightReturn - -export function useMeasure(type: 'area', options: AreaOptions): AreaReturn -export function useMeasure(type: 'distance', options: DistanceOptions): DistanceReturn -export function useMeasure(type: 'height', options: HeightOptions): HeightReturn -export function useMeasure(type: UseMeasureType, options: UseMeasureOptions): UseMeasureReturns -``` - -::: diff --git a/src/core/composables/useMoveByKeyboard/index-zh.md b/src/core/composables/useMoveByKeyboard/index-zh.md index 2618e0f..4ee2cbd 100644 --- a/src/core/composables/useMoveByKeyboard/index-zh.md +++ b/src/core/composables/useMoveByKeyboard/index-zh.md @@ -23,25 +23,3 @@ useMoveByKeyboard({ ### 可选的按键 按键绑定基于`vueuse`的`useMagicKeys`实现,更多可选的按键见[mozilla](https://developer.mozilla.org/zh-CN/docs/Web/API/KeyboardEvent/key) - -## 类型声明 - -::: details - -```ts -export type UseMoveByKeyboardKeybindingList = - | 'forward' - | 'backward' - | 'left' - | 'right' - | 'down' - | 'up' -export interface UseMoveByKeyboardOptions { - distancePerFrame?: MaybeRefOrGetter - keybinding?: Partial> -} - -export function useMoveByKeyboard(options: UseMoveByKeyboardOptions = {}): void -``` - -::: diff --git a/src/core/composables/useMoveByKeyboard/index.md b/src/core/composables/useMoveByKeyboard/index.md index 2a7f8f4..a8c6098 100644 --- a/src/core/composables/useMoveByKeyboard/index.md +++ b/src/core/composables/useMoveByKeyboard/index.md @@ -23,25 +23,3 @@ You can modify key bindings through the keybinding option. ### Optional Keys Key bindings are based on `useMagicKeys` implementation from `vueuse`. For more optional keys, see [mozilla](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key). - -## Usage Declaration - -::: details - -```ts -export type UseMoveByKeyboardKeybindingList = - | 'forward' - | 'backward' - | 'left' - | 'right' - | 'down' - | 'up' -export interface UseMoveByKeyboardOptions { - distancePerFrame?: MaybeRefOrGetter - keybinding?: Partial> -} - -export function useMoveByKeyboard(options: UseMoveByKeyboardOptions = {}): void -``` - -::: diff --git a/src/core/composables/usePointerPosition/index-zh.md b/src/core/composables/usePointerPosition/index-zh.md index ffc5abe..1043943 100644 --- a/src/core/composables/usePointerPosition/index-zh.md +++ b/src/core/composables/usePointerPosition/index-zh.md @@ -23,24 +23,3 @@ const [lon, lat, alt] = usePointerPosition({ ``` - -## 类型声明 - -::: details - -```ts -export interface UsePointerPositionOptions { - throttle?: Parameters[1] - longitudeToFixed?: number - latitudeToFixed?: number - heightToFixed?: number -} - -export function usePointerPosition(options: UsePointerPositionOptions = {}): { - longitude: Ref - latitude: Ref - altitude: Ref -} & Ref[] -``` - -::: diff --git a/src/core/composables/usePointerPosition/index.md b/src/core/composables/usePointerPosition/index.md index 4e028f6..21d455c 100644 --- a/src/core/composables/usePointerPosition/index.md +++ b/src/core/composables/usePointerPosition/index.md @@ -23,24 +23,3 @@ const [lon, lat, alt] = usePointerPosition({ ``` - -## Type Declaration - -::: details - -```ts -export interface UsePointerPositionOptions { - throttle?: Parameters[1] - longitudeToFixed?: number - latitudeToFixed?: number - heightToFixed?: number -} - -export function usePointerPosition(options: UsePointerPositionOptions = {}): { - longitude: Ref - latitude: Ref - altitude: Ref -} & Ref[] -``` - -::: diff --git a/src/core/composables/usePoints/index-zh.md b/src/core/composables/usePoints/index-zh.md index 7f5e725..0789c16 100644 --- a/src/core/composables/usePoints/index-zh.md +++ b/src/core/composables/usePoints/index-zh.md @@ -57,46 +57,3 @@ data.value = [] // 相当于清除所有定位 在使用`points`进行增删改时候,不要忘记手动同步到`billboardCollection`和`labelCollection`。 因为`usePoints`被认为是用于根据一段数据生成点位的函数,因此手动修改其中的点位被认为是少见的边缘情况,目前没有计划为了方便手动修改而添加新的 API。 ::: - -## 类型声明 - -:::details - -```ts -export type UsePointsBillboardOptions = - Cesium.BillboardGraphics.ConstructorOptions & { - position?: Cesium.Cartesian3 - } - -export type UsePointsLabelOptions = Cesium.LabelGraphics.ConstructorOptions & { - position?: Cesium.Cartesian3 -} -export interface UsePointsOptions { - id: any - longitude: number | string - latitude: number | string - height?: number | string - billboardOptions: UsePointsBillboardOptions - labelOptions: UsePointsLabelOptions - onEach?: ( - item: { label: Cesium.Label, billboard: Cesium.Billboard }, - index: number - ) => void -} - -export function usePoints( - data: MaybeRefOrGetter, - options: (item: UsePointsItem) => UsePointsOptions -): { - billboardCollection: Cesium.BillboardCollection - labelCollection: Cesium.LabelCollection - points: Map - toggleShow: (state?: boolean) => void - flyTo: ( - id: UsePointsOptions['id'], - fn?: (billboard: Cesium.Billboard, coordinate: Cesium.Cartesian3) => void - ) => Promise -} -``` - -::: diff --git a/src/core/composables/usePoints/index.md b/src/core/composables/usePoints/index.md index e143ea6..1b2c856 100644 --- a/src/core/composables/usePoints/index.md +++ b/src/core/composables/usePoints/index.md @@ -57,46 +57,3 @@ data.value = [] // Equal to clear all points When adding, removing, or updating points using `points`, remember to manually synchronize with `billboardCollection` and `labelCollection`. Since `usePoints` is intended to be a function for generating data points based on a dataset, manually modifying the points within it is considered a rare edge case. There are currently no plans to introduce new APIs for easier manual modifications. ::: - -## Type Declaration - -:::details - -```ts -export type UsePointsBillboardOptions = - Cesium.BillboardGraphics.ConstructorOptions & { - position?: Cesium.Cartesian3 - } - -export type UsePointsLabelOptions = Cesium.LabelGraphics.ConstructorOptions & { - position?: Cesium.Cartesian3 -} -export interface UsePointsOptions { - id: any - longitude: number | string - latitude: number | string - height?: number | string - billboardOptions: UsePointsBillboardOptions - labelOptions: UsePointsLabelOptions - onEach?: ( - item: { label: Cesium.Label, billboard: Cesium.Billboard }, - index: number - ) => void -} - -export function usePoints( - data: MaybeRefOrGetter, - options: (item: UsePointsItem) => UsePointsOptions -): { - billboardCollection: Cesium.BillboardCollection - labelCollection: Cesium.LabelCollection - points: Map - toggleShow: (state?: boolean) => void - flyTo: ( - id: UsePointsOptions['id'], - fn?: (billboard: Cesium.Billboard, coordinate: Cesium.Cartesian3) => void - ) => Promise -} -``` - -::: diff --git a/src/core/composables/useUnderground/index-zh.md b/src/core/composables/useUnderground/index-zh.md index 511b0bd..337bfac 100644 --- a/src/core/composables/useUnderground/index-zh.md +++ b/src/core/composables/useUnderground/index-zh.md @@ -19,20 +19,3 @@ watchEffect(() => { state.value ? doWhenOn() : doWhenOff() }) ``` - -## 类型声明 - -:::details - -```ts -export interface UseUndergroundOptions { - frontFaceAlphaByDistance: ConstructorParameters -} - -export function useUnderground( - initialState = false, - options?: MaybeRefOrGetter> -): { state: Ref } -``` - -::: diff --git a/src/core/composables/useUnderground/index.md b/src/core/composables/useUnderground/index.md index 24ec324..4f0955c 100644 --- a/src/core/composables/useUnderground/index.md +++ b/src/core/composables/useUnderground/index.md @@ -19,20 +19,3 @@ watchEffect(() => { state.value ? doWhenOn() : doWhenOff() }) ``` - -## Type Declaration - -:::details - -```ts -export interface UseUndergroundOptions { - frontFaceAlphaByDistance: ConstructorParameters -} - -export function useUnderground( - initialState = false, - options?: MaybeRefOrGetter> -): { state: Ref } -``` - -::: diff --git a/src/core/composables/viewerStore/index-zh.md b/src/core/composables/viewerStore/index-zh.md index 1249014..76796a4 100644 --- a/src/core/composables/viewerStore/index-zh.md +++ b/src/core/composables/viewerStore/index-zh.md @@ -97,20 +97,6 @@ doSomething() 事实上,绝大部分 CesiumUse 的函数都是这么做的。 -## 类型声明 - -:::details - -```ts -export const getViewer: () => Viewer - -export const setViewer: (v: Viewer) => void - -export const useViewerProvider: (v: ShallowRef) => void -``` - -::: - ## 查错指南 错误通常是由`getViewer`引起的,在`getViewer`尝试获取 viewer 实例失败后,会抛出错误。 diff --git a/src/core/composables/viewerStore/index.md b/src/core/composables/viewerStore/index.md index 62843d9..953a649 100644 --- a/src/core/composables/viewerStore/index.md +++ b/src/core/composables/viewerStore/index.md @@ -97,21 +97,7 @@ doSomething() In fact, this is how the majority of functions in Cesium Use are implemented. -## Type Declaration - -:::details - -```ts -export const getViewer: () => Viewer - -export const setViewer: (v: Viewer) => void - -export const useViewerProvider: (v: ShallowRef) => void -``` - -::: - -### Corrections Guide +## Corrections Guide Errors are typically caused by `getViewer`, which throws an error when attempting to retrieve the viewer instance. diff --git a/src/core/utils/defineColor/index-zh.md b/src/core/utils/defineColor/index-zh.md index 846307c..31e8727 100644 --- a/src/core/utils/defineColor/index-zh.md +++ b/src/core/utils/defineColor/index-zh.md @@ -35,13 +35,3 @@ defineColor('#f00') // Cesium.Color.fromCssColorString('#f00').withAlpha(0.8) defineColor('#f00/80') ``` - -## 类型声明 - -::: details - -```ts -export const defineColor = (str: string) => Cesium.Color -``` - -::: diff --git a/src/core/utils/defineColor/index.md b/src/core/utils/defineColor/index.md index fb4cecc..ffe10dc 100644 --- a/src/core/utils/defineColor/index.md +++ b/src/core/utils/defineColor/index.md @@ -35,13 +35,3 @@ defineColor('#f00') // Cesium.Color.fromCssColorString('#f00').withAlpha(0.8) defineColor('#f00/80') ``` - -## Type Declaration - -::: details - -```ts -export const defineColor = (str: string) => Cesium.Color -``` - -::: diff --git a/src/core/utils/editEntity/index-zh.md b/src/core/utils/editEntity/index-zh.md index ee0800e..ebdd0a9 100644 --- a/src/core/utils/editEntity/index-zh.md +++ b/src/core/utils/editEntity/index-zh.md @@ -26,13 +26,3 @@ editEntity( ) // 这会将entity的材质改为红色 ``` - -## 类型声明 - -::: details - -```ts -function editEntity(entity: Entity, ...args: Entity.ConstructorOptions[]): Entity -``` - -::: diff --git a/src/core/utils/editEntity/index.md b/src/core/utils/editEntity/index.md index 36b97d8..55bfd6f 100644 --- a/src/core/utils/editEntity/index.md +++ b/src/core/utils/editEntity/index.md @@ -26,13 +26,3 @@ editEntity( ) // This will change the material of the entity to red ``` - -## Type Declarations - -::: details - -```ts -function editEntity(entity: Entity, ...args: Entity.ConstructorOptions[]): Entity -``` - -::: diff --git a/src/core/utils/loadGeojson/index-zh.md b/src/core/utils/loadGeojson/index-zh.md index 5610d31..e37031f 100644 --- a/src/core/utils/loadGeojson/index-zh.md +++ b/src/core/utils/loadGeojson/index-zh.md @@ -53,24 +53,3 @@ const primitive = await loadGeojson({ ``` 这在你需要访问自身作用域时是有用的。 - -## 类型声明 - -::: details - -```ts -export interface LoadGeojsonConfig { - url: Parameters[0] - dataSourceOptions?: Parameters[1] - onEntity?: (entity: Cesium.Entity) => void - custom?: (dataSource: Cesium.GeoJsonDataSource) => CustomReturns -} - -function loadGeojson>( - config: T -): Promise< - T['custom'] extends (...args: any[]) => infer R ? R : Cesium.GeoJsonDataSource -> -``` - -::: diff --git a/src/core/utils/loadGeojson/index.md b/src/core/utils/loadGeojson/index.md index 74d8231..d4a91c4 100644 --- a/src/core/utils/loadGeojson/index.md +++ b/src/core/utils/loadGeojson/index.md @@ -53,24 +53,3 @@ const primitive = await loadGeojson({ ``` This is useful when you need to access the local scope. - -## Type Declarations - -::: details - -```ts -export interface LoadGeojsonConfig { - url: Parameters[0] - dataSourceOptions?: Parameters[1] - onEntity?: (entity: Cesium.Entity) => void - custom?: (dataSource: Cesium.GeoJsonDataSource) => CustomReturns -} - -function loadGeojson>( - config: T -): Promise< - T['custom'] extends (...args: any[]) => infer R ? R : Cesium.GeoJsonDataSource -> -``` - -::: diff --git a/src/core/utils/projectionPosition/index-zh.md b/src/core/utils/projectionPosition/index-zh.md index a7011e3..5f3d7d8 100644 --- a/src/core/utils/projectionPosition/index-zh.md +++ b/src/core/utils/projectionPosition/index-zh.md @@ -13,13 +13,3 @@ const projection = projectionPosition(p0, p1) 1. $\text{projection} = k \cdot p_0$ 2. $(k \cdot p_0 - p_1) \cdot p_0 = 0$ 3. $k = \frac{{p_0 \cdot p_1}}{{p_0 \cdot p_0}}$ - -## 类型声明 - -::: details - -```ts -function projectionPosition(p0: Cesium.Cartesian3, p1: Cesium.Cartesian3): Cesium.Cartesian3 -``` - -::: diff --git a/src/core/utils/projectionPosition/index.md b/src/core/utils/projectionPosition/index.md index 995c300..c216046 100644 --- a/src/core/utils/projectionPosition/index.md +++ b/src/core/utils/projectionPosition/index.md @@ -13,13 +13,3 @@ Give two vector $p_0 = (x_0, y_0, z_0)$ and $p_1 = (x_1, y_1, z_1)$, The derivat 1. $\text{projection} = k \cdot p_0$ 2. $(k \cdot p_0 - p_1) \cdot p_0 = 0$ 3. $k = \frac{{p_0 \cdot p_1}}{{p_0 \cdot p_0}}$ - -## Type Declaration - -::: details - -```ts -function projectionPosition(p0: Cesium.Cartesian3, p1: Cesium.Cartesian3): Cesium.Cartesian3 -``` - -::: diff --git a/src/core/utils/toCartesian3/index-zh.md b/src/core/utils/toCartesian3/index-zh.md index 84e4097..d84e9c2 100644 --- a/src/core/utils/toCartesian3/index-zh.md +++ b/src/core/utils/toCartesian3/index-zh.md @@ -18,13 +18,3 @@ const pos5 = toCartesian3({ height: 10 }) ``` - -## 类型声明 - -::: details - -```ts -function toCartesian3(source: Cesium.Cartesian3 | MaybeCoordinates): Cesium.Cartesian3 -``` - -::: diff --git a/src/core/utils/toCartesian3/index.md b/src/core/utils/toCartesian3/index.md index 127a224..8e1da7a 100644 --- a/src/core/utils/toCartesian3/index.md +++ b/src/core/utils/toCartesian3/index.md @@ -18,13 +18,3 @@ const pos5 = toCartesian3({ height: 10 }) ``` - -## Type Declaration - -::: details - -```ts -function toCartesian3(source: Cesium.Cartesian3 | MaybeCoordinates): Cesium.Cartesian3 -``` - -::: diff --git a/src/core/utils/toCoordinates/index-zh.md b/src/core/utils/toCoordinates/index-zh.md index 04fd979..7106ed2 100644 --- a/src/core/utils/toCoordinates/index-zh.md +++ b/src/core/utils/toCoordinates/index-zh.md @@ -21,17 +21,3 @@ const pos5 = toCoordinates({ height: 10 }) ``` - -## 类型声明 - -::: details - -```ts -function toCoordinates(source: Cesium.Cartesian3 | MaybeCoordinates): { - longitude: number - latitude: number - height: number | undefined -} & (number | undefined)[] -``` - -::: diff --git a/src/core/utils/toCoordinates/index.md b/src/core/utils/toCoordinates/index.md index bd4a72f..7e1f28e 100644 --- a/src/core/utils/toCoordinates/index.md +++ b/src/core/utils/toCoordinates/index.md @@ -21,17 +21,3 @@ const pos5 = toCoordinates({ height: 10 }) ``` - -## Type Declaration - -::: details - -```ts -function toCoordinates(source: Cesium.Cartesian3 | MaybeCoordinates): { - longitude: number - latitude: number - height: number | undefined -} & (number | undefined)[] -``` - -:::