├── .commitlintrc.js ├── .cz-config.js ├── .eslintignore ├── .eslintrc.js ├── .github └── FUNDING.yml ├── .gitignore ├── .huskyrc.js ├── .prettierrc ├── CHANGELOG.md ├── CHANGELOG.zh-CN.md ├── LICENSE ├── README.md ├── README.zh-CN.md ├── babel.config.js ├── docs ├── .nojekyll ├── _navbar.md ├── en-us │ ├── _sidebar.md │ ├── components.md │ └── krpano-action-proxy.md ├── index.html └── zh-cn │ ├── _sidebar.md │ ├── components.md │ └── krpano-action-proxy.md ├── jest.config.js ├── krpano-lib ├── krpano.js └── krpano.swf ├── lint-staged.config.js ├── package-lock.json ├── package.json ├── rollup.config.js ├── scripts └── syncDoc.ts ├── src ├── KrpanoActionProxy.ts ├── __snapshots__ │ └── utils.test.ts.snap ├── components │ ├── Events.tsx │ ├── Hotspot.tsx │ ├── Krpano.tsx │ ├── Scene.tsx │ └── View.tsx ├── contexts │ ├── CurrentSceneContext.ts │ └── KrpanoRendererContext.ts ├── hooks │ ├── useEventCallback.ts │ └── useKrpano.ts ├── index.ts ├── types.ts ├── utils.test.ts └── utils.ts ├── tsconfig.json └── tsconfig.typing.json /.commitlintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['cz'], 3 | rules: {}, 4 | }; 5 | -------------------------------------------------------------------------------- /.cz-config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | types: [ 5 | { 6 | value: 'WIP', 7 | name: '💪 WIP: Work in progress', 8 | }, 9 | { 10 | value: 'feat', 11 | name: '✨ feat: A new feature', 12 | }, 13 | { 14 | value: 'fix', 15 | name: '🐞 fix: A bug fix', 16 | }, 17 | { 18 | value: 'refactor', 19 | name: '🛠 refactor: A code change that neither fixes a bug nor adds a feature', 20 | }, 21 | { 22 | value: 'docs', 23 | name: '📚 docs: Documentation only changes', 24 | }, 25 | { 26 | value: 'test', 27 | name: '🏁 test: Add missing tests or correcting existing tests', 28 | }, 29 | { 30 | value: 'chore', 31 | name: 32 | "🗯 chore: Changes that don't modify src or test files. Such as updating build tasks, package manager", 33 | }, 34 | { 35 | value: 'style', 36 | name: 37 | '💅 style: Code Style, Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)', 38 | }, 39 | { 40 | value: 'revert', 41 | name: '⏪ revert: Revert to a commit', 42 | }, 43 | ], 44 | 45 | scopes: [], 46 | 47 | allowCustomScopes: true, 48 | allowBreakingChanges: ['feat', 'fix'], 49 | }; 50 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build/ 2 | dist/ 3 | node_modules/ 4 | .snapshots/ 5 | *.min.js -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @type {import('@types/eslint').Linter.BaseConfig} 3 | */ 4 | module.exports = { 5 | parser: '@typescript-eslint/parser', // Specifies the ESLint parser 6 | extends: [ 7 | 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin 8 | 'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier 9 | 'plugin:prettier/recommended', 10 | ], 11 | parserOptions: { 12 | ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features 13 | sourceType: 'module', // Allows for the use of imports 14 | ecmaFeatures: { 15 | node: true, 16 | }, 17 | }, 18 | settings: { 19 | react: { 20 | version: 'detect', 21 | }, 22 | }, 23 | plugins: ['react-hooks'], 24 | rules: { 25 | // typescript 26 | '@typescript-eslint/no-parameter-properties': 'off', 27 | '@typescript-eslint/ban-ts-comment': 'off', 28 | // 不限制 29 | '@typescript-eslint/explicit-member-accessibility': 'off', 30 | '@typescript-eslint/no-empty-interface': 'off', 31 | '@typescript-eslint/no-non-null-assertion': 'warn', 32 | '@typescript-eslint/array-type': ['warn', { default: 'array-simple' }], 33 | '@typescript-eslint/interface-name-prefix': 'off', 34 | '@typescript-eslint/no-object-literal-type-assertion': 'off', 35 | '@typescript-eslint/explicit-function-return-type': [ 36 | 'off', 37 | { allowExpressions: true, allowTypedFunctionExpressions: true }, 38 | ], 39 | 40 | // hooks 41 | 'react-hooks/rules-of-hooks': 'error', 42 | 'react-hooks/exhaustive-deps': 'warn', 43 | 44 | // misc 45 | 'no-implicit-coercion': 'off', 46 | 'no-useless-escape': 'off', 47 | 'array-callback-return': 'off', 48 | 'no-useless-constructor': 'off', 49 | 'no-empty-function': ['error', { allow: ['constructors'] }], 50 | quotes: ['error', 'single', { allowTemplateLiterals: true }], 51 | 'no-undef': 'off', 52 | }, 53 | overrides: [ 54 | { 55 | files: ['**/*.js'], 56 | excludedFiles: ['node_modules', './dist/**/*'], 57 | rules: { 58 | '@typescript-eslint/no-unused-vars': 'warn', 59 | '@typescript-eslint/no-var-requires': 'off', 60 | '@typescript-eslint/camelcase': 'off', 61 | }, 62 | }, 63 | { 64 | files: ['**/*.test.tsx'], 65 | excludedFiles: ['node_modules', './dist/**/*'], 66 | env: { 67 | node: true, 68 | }, 69 | }, 70 | ], 71 | }; 72 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.buymeacoffee.com/reactkrpano']# Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | *.tsbuildinfo 107 | -------------------------------------------------------------------------------- /.huskyrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | hooks: { 3 | 'pre-commit': 'lint-staged', 4 | // 'prepare-commit-msg': 'exec < /dev/tty && git cz --hook || true', 5 | 'commit-msg': 'commitlint -e $GIT_PARAMS', 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "endOfLine": "lf", 3 | "semi": true, 4 | "trailingComma": "es5", 5 | "singleQuote": true, 6 | "printWidth": 120, 7 | "tabWidth": 4, 8 | "arrowParens": "avoid", 9 | "overrides": [ 10 | { 11 | "files": ["*.json"], 12 | "options": { 13 | "tabWidth": 2 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ### [0.1.5](https://github.com/0xLLLLH/react-krpano/compare/v0.1.3...v0.1.5) (2022-02-22) 6 | 7 | ### Bug Fixes 8 | 9 | - 🐞 fix CommonJS build dependency problem ([b90ba0b](https://github.com/0xLLLLH/react-krpano/commit/b90ba0bca9648b84b35b735c05f8303418b29364)) 10 | 11 | ## [0.1.4](https://github.com/0xLLLLH/react-krpano/compare/v0.1.3...v0.1.4) (2021-03-03) 12 | 13 | ### Features 14 | 15 | - ✨Krpano component supports enableLogger attribute ([158955f](https://github.com/0xLLLLH/react-krpano/commit/158955fbe77a045a85c9f3867742780d69759050)) 16 | 17 | ## [0.1.3](https://github.com/0xLLLLH/react-krpano/compare/v0.1.2...v0.1.3) (2021-01-03) 18 | 19 | ### Features 20 | 21 | - ✨Krpano component add default size ([fa8d678](https://github.com/0xLLLLH/react-krpano/commit/fa8d678228443b5f86a950d0d0548f5758904ab3)) 22 | 23 | ### Bug Fixes 24 | 25 | - 🐞Fix the problem that the related interface of each component is not exported ([604eb56](https://github.com/0xLLLLH/react-krpano/commit/604eb56a53389b4e05c5bb51b2d2ed1f4a63c006)) 26 | 27 | ## [0.1.2](https://github.com/0xLLLLH/react-krpano/compare/v0.1.1...v0.1.2) (2020-12-19) 28 | 29 | ### Features 30 | 31 | - ✨krpano component supports setting target and id ([cd396af](https://github.com/0xLLLLH/react-krpano/commit/cd396af5537b0f3918013a59d22c516d6f4d8097)) 32 | 33 | ## [0.1.1](https://github.com/0xLLLLH/react-krpano/compare/v0.1.0...v0.1.1) (2020-12-17) 34 | 35 | ### Bug Fixes 36 | 37 | - Fix the problem of View component children type ([966c13a](https://github.com/0xLLLLH/react-krpano/commit/966c13a026c3efc75bbde1bb65079c98a073698b)) 38 | 39 | ## [0.1.0](https://github.com/0xLLLLH/react-krpano/compare/v0.0.2...v0.1.0) (2020-12-17) 40 | 41 | ### ⚠ BREAKING CHANGES 42 | 43 | - Case adjustment of event name: oncontextmenu->onContextmenu, onAutorotateStart->onAutoRotateStart 44 | - Rename fovmin/fovmax to fovMin/fovMax 45 | 46 | ### Features 47 | 48 | - The view component supports all view tag attributes; fovmin->fovMin ([2b615e2](https://github.com/0xLLLLH/react-krpano/commit/2b615e2381eab8c7241eadffc6ff53619260f851)) 49 | 50 | - Events component event name adjustment ([25b0cfb](https://github.com/0xLLLLH/react-krpano/commit/25b0cfb7e4b092d0893ef7af1162e0cc2f8209ed)) 51 | 52 | ## 0.0.2 (2020-12-16) 53 | 54 | ### Bug Fixes 55 | 56 | - Fix the problem that KrpanoActionProxy and other content cannot be imported from the index ([11c6a7d](https://github.com/0xLLLLH/react-krpano/commit/11c6a7d3a02cd4631a67ef688e4aa8d76f7b90f8)) 57 | 58 | ## 0.0.1 (2020-12-16) 59 | -------------------------------------------------------------------------------- /CHANGELOG.zh-CN.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | 所有值得记录的修改会在这个文档中留档。查阅[standard-version](https://github.com/conventional-changelog/standard-version)来了解提交规范。 4 | 5 | ### [0.1.5](https://github.com/0xLLLLH/react-krpano/compare/v0.1.3...v0.1.5) (2022-02-22) 6 | 7 | ### Bug Fixes 8 | 9 | - 🐞 修复 CommonJS 构建产出的依赖问题 ([b90ba0b](https://github.com/0xLLLLH/react-krpano/commit/b90ba0bca9648b84b35b735c05f8303418b29364)) 10 | 11 | ## [0.1.4](https://github.com/0xLLLLH/react-krpano/compare/v0.1.3...v0.1.4) (2021-03-03) 12 | 13 | ### Features 14 | 15 | - ✨Krpano 组件支持 enableLogger 参数 ([158955f](https://github.com/0xLLLLH/react-krpano/commit/158955fbe77a045a85c9f3867742780d69759050)) 16 | 17 | ## [0.1.3](https://github.com/0xLLLLH/react-krpano/compare/v0.1.2...v0.1.3) (2021-01-03) 18 | 19 | ### Features 20 | 21 | - ✨Krpano 组件添加默认大小 ([fa8d678](https://github.com/0xLLLLH/react-krpano/commit/fa8d678228443b5f86a950d0d0548f5758904ab3)) 22 | 23 | ### Bug Fixes 24 | 25 | - 🐞 修复各个组件的相关 interface 未导出的问题 ([604eb56](https://github.com/0xLLLLH/react-krpano/commit/604eb56a53389b4e05c5bb51b2d2ed1f4a63c006)) 26 | 27 | ## [0.1.2](https://github.com/0xLLLLH/react-krpano/compare/v0.1.1...v0.1.2) (2020-12-19) 28 | 29 | ### Features 30 | 31 | - ✨krpano 组件支持设置 target 和 id ([cd396af](https://github.com/0xLLLLH/react-krpano/commit/cd396af5537b0f3918013a59d22c516d6f4d8097)) 32 | 33 | ## [0.1.1](https://github.com/0xLLLLH/react-krpano/compare/v0.1.0...v0.1.1) (2020-12-17) 34 | 35 | ### Bug Fixes 36 | 37 | - 修复 View 组件 children 类型的问题 ([966c13a](https://github.com/0xLLLLH/react-krpano/commit/966c13a026c3efc75bbde1bb65079c98a073698b)) 38 | 39 | ## [0.1.0](https://github.com/0xLLLLH/react-krpano/compare/v0.0.2...v0.1.0) (2020-12-17) 40 | 41 | ### ⚠ BREAKING CHANGES 42 | 43 | - 事件名称大小写调整:oncontextmenu->onContextmenu,onAutorotateStart->onAutoRotateStart 44 | - 将 fovmin/fovmax 重命名为 fovMin/fovMax 45 | 46 | ### Features 47 | 48 | - view 组件支持所有 view 标签属性;fovmin->fovMin ([2b615e2](https://github.com/0xLLLLH/react-krpano/commit/2b615e2381eab8c7241eadffc6ff53619260f851)) 49 | 50 | - events 组件事件名称调整 ([25b0cfb](https://github.com/0xLLLLH/react-krpano/commit/25b0cfb7e4b092d0893ef7af1162e0cc2f8209ed)) 51 | 52 | ## 0.0.2 (2020-12-16) 53 | 54 | ### Bug Fixes 55 | 56 | - 修复无法从 index 引入 KrpanoActionProxy 等内容的问题 ([11c6a7d](https://github.com/0xLLLLH/react-krpano/commit/11c6a7d3a02cd4631a67ef688e4aa8d76f7b90f8)) 57 | 58 | ## 0.0.1 (2020-12-16) 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 0xLLLLH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Krpano 2 | > React bindings for krpano. 3 | 4 | 5 | [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/0xLLLLH/react-krpano/blob/main/LICENSE) 6 | [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) 7 | [![NPM version][npm-image]][npm-url] 8 | 9 | [npm-image]: https://img.shields.io/npm/v/@0xllllh/react-krpano?style=flat-square 10 | [npm-url]: https://www.npmjs.com/package/@0xllllh/react-krpano 11 | 12 | [Demo](https://0xllllh.github.io/react-krpano-examples) 13 | ## ✨ Features 14 | * Dynamic rendering of scenes and hotspots without generating xml 15 | * Use Typescript to develop and provide a complete type definition file. 16 | 17 | ## 🖥 Dependencies 18 | 19 | * krpano.js >= 1.20.9 20 | * React >= 16.8 21 | 22 | ## 📦 Installation 23 | 24 | * With NPM 25 | ``` bash 26 | yarn add @0xllllh/react-krpano 27 | ``` 28 | * Download the latest Krpano from [Krpano official website](https://krpano.com/download/) and unzip it to get JS file, then import it through the script tag of your index.html to make the script available globally. 29 | ```html 30 | 31 | ``` 32 | 33 | ## 🔨 How to use 34 | ### Loading XML file 35 | The most basic usage is to directly load the krpano xml file through `Krpano` the `xml` parameters of the component . The Krpano component will faithfully render according to the xml configuration. 36 | 37 | **krpano.xml** 38 | ```xml 39 | 40 | 41 | 42 | 43 | 44 | 51 | 52 | 53 | 54 | ``` 55 | 56 | **App.css** 57 | ``` css 58 | .App { 59 | width: 600px; 60 | height: 400px; 61 | } 62 | ``` 63 | 64 | **App.tsx** 65 | ``` tsx 66 | ReactDOM.render(, document.getElementById('app')); 67 | ``` 68 | 69 | ### Scene display and switching 70 | > In order to simplify the implementation and use, the implementation of krpano's image tag has been merged into the Scene component. The images of the scene can be specified through the `images` props of Scene component 71 | 72 | To add a scene, you need to use the Scene component. Each one represents a scene, and active scene can be specified through the `currentScene` prop of Krpano component. 73 | 74 | ```tsx 75 | ReactDOM.render( 76 | 77 | 84 | 91 | 92 | , 93 | document.getElementById('app')); 94 | ``` 95 | 96 | ### Hotspots 97 | 98 | > Currently support only image hotspots 99 | 100 | Hotspots can be easily rendered using Hotspot component. It support a bunch of callback settings 101 | 102 | ```tsx 103 | const App = () => { 104 | const [currentScene, setCurrentScene] = React.useState('scene0'); 105 | // Datas 106 | const scenes = [{ 107 | name: 'scene0', 108 | previewUrl: '/preview.jpg', 109 | hotspots: [{ 110 | name: 'hot', 111 | type: 'image', 112 | url: 'hotspot.png', 113 | ath: 0, 114 | atv: 20, 115 | onClick: () => setCurrentScene('scene1') 116 | }] 117 | }, 118 | name: 'scene1', 119 | previewUrl: '/preview.jpg', 120 | hotspots: [] 121 | }] 122 | 123 | return ( 124 | 125 | 126 | {scenes.map(sc => ( 127 | 128 | {sc.hotspots.map(pt => )} 129 | 130 | ))} 131 | 132 | ) 133 | } 134 | 135 | ReactDOM.render(, document.getElementById('app')); 136 | ``` 137 | 138 | ### Access unsuported features 139 | Since this project has just started development, many components and functions are not yet completed. If there is a function that needs priority support, you can raise an issue on Github. If you want, you can use the `KrpanoActionProxy` to call the krpano functions by yourself after obtaining it. 140 | 141 | Various callback functions will get the KrpanoActionProxy instance as a parameter, and the encapsulated method can be used to control krpano. You can also use `renderer.KrpanoRenderer` to get a native instance of krpano. 142 | ```tsx 143 | const App = () => { 144 | const [currentScene, setCurrentScene] = React.useState('scene0'); 145 | const onHotspotClick = React.useCallback((renderer: KrpanoActionProxy) => { 146 | console.log(renderer.get('view.fov')); 147 | setCurrentScene('scene1'); 148 | }, []); 149 | 150 | return ( 151 | { 155 | console.log('Ready message from App', renderer.krpanoRenderer); 156 | }} 157 | > 158 | 159 | 160 | 168 | 169 | 170 | 171 | ); 172 | }; 173 | ``` 174 | 175 | In addition, tags such as style and action can be written in xml, then imported through `xml` prop of Krpano component. 176 | 177 | **pano.xml** 178 | ```xml 179 | 180 |