Catalog npm
Back to packageRELEASE DETAILS

0.1.1

npm

@0xllllh/react-krpano

React bindings for krpano.

krpanoreact
Published17 Dec 2020
Direct dependencies44
Transitive dependenciesNot calculated

README

Current package documentation

React Krpano

React bindings for krpano.

license Commitizen friendly NPM version

Demo

✨ Features

  • Dynamic rendering of scenes and hotspots without generating xml
  • Use Typescript to develop and provide a complete type definition file.

🖥 Dependencies

  • krpano.js >= 1.20.9
  • React >= 16.8

📦 Installation

  • With NPM
yarn add @0xllllh/react-krpano
  • Download the latest Krpano from Krpano official website and unzip it to get JS file, then import it through the script tag of your index.html to make the script available globally.
<script src="krpano.js"></script>

🔨 How to use

Loading XML file

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.

krpano.xml

<krpano onstart="loadscene(scene1);">
    <scene name="scene1">
        <image>
            <cube url="https://some.jpg_%s" />
        </image>
        <hotspot
            name="image_hotspot"
            type="image"
            url="https://0xllllh.github.io/krpano-examples/images/hotspot.png"
            ath="0"
            atv="0"
        />
    </scene>
    <view hlookat="0" vlookat="0" fovtype="VFOV" fov="90" fovmin="30" fovmax="150" />
</krpano>

App.css

.App {
    width: 600px;
    height: 400px;
}

App.tsx

ReactDOM.render(<Krpano className="App" xml="/krpano.xml" />, document.getElementById('app'));

Scene display and switching

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

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.

ReactDOM.render(
<Krpano currentScene="scene0">
    <Scene
        name="scene0"
        images={[{
            type: 'cube',
            url: 'https://qhyxpicoss.kujiale.com/r/2017/09/01/L3D221IS3QKUQUQBOGAPEK3P3XU888_7500x1250.jpg_%s',
        }]}
    />
    <Scene
        name="scene1"
        images={[{
            type: 'cube',
            url: 'https://qhyxpicoss.kujiale.com/r/2017/09/01/L3D221IS3QKUQUQBOGAPEK3P3XU888_7500x1250.jpg_%s',
        }]}
    />
    <View fov={90} fovmin={80} fovmax={120} />
</Krpano>,
document.getElementById('app'));

Hotspots

Currently support only image hotspots

Hotspots can be easily rendered using Hotspot component. It support a bunch of callback settings

const App = () => {
    const [currentScene, setCurrentScene] = React.useState('scene0');
    // Datas
    const scenes = [{
        name: 'scene0',
        previewUrl: '/preview.jpg',
        hotspots: [{
            name: 'hot',
            type: 'image',
            url: 'hotspot.png',
            ath: 0,
            atv: 20,
            onClick: () => setCurrentScene('scene1')
        }]
    },
        name: 'scene1',
        previewUrl: '/preview.jpg',
        hotspots: []
    }]

    return (
        <Krpano currentScene={currentScene}>
            <View fov={90} fovmin={80} fovmax={120} />
            {scenes.map(sc => (
                <Scene name={sc.name} previewUrl={sc.previewUrl}>
                    {sc.hotspots.map(pt => <Hotspot {...pt} />)}
                </Scene>
            ))}
        </Krpano>
    )
}

ReactDOM.render(<App />, document.getElementById('app'));

Access unsuported features

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.

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.

const App = () => {
    const [currentScene, setCurrentScene] = React.useState('scene0');
    const onHotspotClick = React.useCallback((renderer: KrpanoActionProxy) => {
        console.log(renderer.get('view.fov'));
        setCurrentScene('scene1');
    }, []);

    return (
        <Krpano
            className="App"
            currentScene={currentScene}
            onReady={renderer => {
                console.log('Ready message from App', renderer.krpanoRenderer);
            }}
        >
            <View fov={90} fovmin={80} fovmax={120} />
            <Scene name="scene0" previewUrl="/preview.jpg">
                <Hotspot
                    name="hot"
                    type="image"
                    url="https://0xllllh.github.io/krpano-examples/images/hotspot.png"
                    ath={0}
                    atv={20}
                    onClick={onHotspotClick}
                />
            </Scene>
            <Scene name="scene1" previewUrl="/preview.jpg" />
        </Krpano>
    );
};

In addition, tags such as style and action can be written in xml, then imported through xml prop of Krpano component.

pano.xml

<krpano>
    <style name="hotspot_style" url="hotspot.png" scale="0.5" edge="top" distorted="true" onover="tween(scale,0.55);" onout="tween(scale,0.5);" />
    ...
</krpano>

App.tsx

const App = () => (
    <Krpano
        className="App"
        xml="/pano.xml"
        currentScene="scene0"
    >
        <Scene name="scene0" previewUrl="/preview.jpg">
            <Hotspot
                name="hot"
                type="image"
                style="hotspot_style"
                ath={0}
                atv={20}
            />
        </Scene>
    </Krpano>
);

❗️ Restrictions

  • Only one krpano panorama is displayed on a page at a time. If you need to display multiple panoramas at the same time, a lighter solution will be more appropriate.
  • React components only implement part of their functions for the time being.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 44

Native requirements
44 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@babel/runtime
Environment
{
  "local_name": "@babel/runtime",
  "alias": false,
  "peer_metadata": null
}
^7.12.5runtime
escape-html
Environment
{
  "local_name": "escape-html",
  "alias": false,
  "peer_metadata": null
}
^1.0.3runtime
tslib
Environment
{
  "local_name": "tslib",
  "alias": false,
  "peer_metadata": null
}
^2.0.3runtime
uuid
Environment
{
  "local_name": "uuid",
  "alias": false,
  "peer_metadata": null
}
^8.3.1runtime
@babel/plugin-proposal-class-properties
Environment
{
  "local_name": "@babel/plugin-proposal-class-properties",
  "alias": false,
  "peer_metadata": null
}
^7.12.1development
@babel/plugin-proposal-decorators
Environment
{
  "local_name": "@babel/plugin-proposal-decorators",
  "alias": false,
  "peer_metadata": null
}
^7.12.1development
@babel/plugin-proposal-object-rest-spread
Environment
{
  "local_name": "@babel/plugin-proposal-object-rest-spread",
  "alias": false,
  "peer_metadata": null
}
^7.12.1development
@babel/plugin-proposal-optional-chaining
Environment
{
  "local_name": "@babel/plugin-proposal-optional-chaining",
  "alias": false,
  "peer_metadata": null
}
^7.12.7development
@babel/plugin-transform-runtime
Environment
{
  "local_name": "@babel/plugin-transform-runtime",
  "alias": false,
  "peer_metadata": null
}
^7.12.10development
@babel/preset-env
Environment
{
  "local_name": "@babel/preset-env",
  "alias": false,
  "peer_metadata": null
}
^7.12.10development
@babel/preset-react
Environment
{
  "local_name": "@babel/preset-react",
  "alias": false,
  "peer_metadata": null
}
^7.12.10development
@babel/preset-typescript
Environment
{
  "local_name": "@babel/preset-typescript",
  "alias": false,
  "peer_metadata": null
}
^7.12.7development
@commitlint/cli
Environment
{
  "local_name": "@commitlint/cli",
  "alias": false,
  "peer_metadata": null
}
^11.0.0development
@commitlint/config-conventional
Environment
{
  "local_name": "@commitlint/config-conventional",
  "alias": false,
  "peer_metadata": null
}
^11.0.0development
@rollup/plugin-babel
Environment
{
  "local_name": "@rollup/plugin-babel",
  "alias": false,
  "peer_metadata": null
}
^5.2.2development
@rollup/plugin-commonjs
Environment
{
  "local_name": "@rollup/plugin-commonjs",
  "alias": false,
  "peer_metadata": null
}
^17.0.0development
@rollup/plugin-node-resolve
Environment
{
  "local_name": "@rollup/plugin-node-resolve",
  "alias": false,
  "peer_metadata": null
}
^11.0.0development
@rollup/plugin-url
Environment
{
  "local_name": "@rollup/plugin-url",
  "alias": false,
  "peer_metadata": null
}
^6.0.0development
@types/escape-html
Environment
{
  "local_name": "@types/escape-html",
  "alias": false,
  "peer_metadata": null
}
^1.0.0development
@types/eslint
Environment
{
  "local_name": "@types/eslint",
  "alias": false,
  "peer_metadata": null
}
^7.2.5development
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
^26.0.16development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^14.14.10development
@types/react
Environment
{
  "local_name": "@types/react",
  "alias": false,
  "peer_metadata": null
}
^17.0.0development
@types/react-dom
Environment
{
  "local_name": "@types/react-dom",
  "alias": false,
  "peer_metadata": null
}
^17.0.0development
@typescript-eslint/eslint-plugin
Environment
{
  "local_name": "@typescript-eslint/eslint-plugin",
  "alias": false,
  "peer_metadata": null
}
^4.9.0development
@typescript-eslint/parser
Environment
{
  "local_name": "@typescript-eslint/parser",
  "alias": false,
  "peer_metadata": null
}
^4.9.0development
babel-plugin-jsx-control-statements
Environment
{
  "local_name": "babel-plugin-jsx-control-statements",
  "alias": false,
  "peer_metadata": null
}
^4.1.0development
commitizen
Environment
{
  "local_name": "commitizen",
  "alias": false,
  "peer_metadata": null
}
^4.2.2development
commitlint-config-cz
Environment
{
  "local_name": "commitlint-config-cz",
  "alias": false,
  "peer_metadata": null
}
^0.13.2development
concurrently
Environment
{
  "local_name": "concurrently",
  "alias": false,
  "peer_metadata": null
}
^5.3.0development
cz-customizable
Environment
{
  "local_name": "cz-customizable",
  "alias": false,
  "peer_metadata": null
}
^6.3.0development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^7.14.0development
eslint-config-prettier
Environment
{
  "local_name": "eslint-config-prettier",
  "alias": false,
  "peer_metadata": null
}
^6.15.0development
eslint-plugin-prettier
Environment
{
  "local_name": "eslint-plugin-prettier",
  "alias": false,
  "peer_metadata": null
}
^3.1.4development
eslint-plugin-react-hooks
Environment
{
  "local_name": "eslint-plugin-react-hooks",
  "alias": false,
  "peer_metadata": null
}
^4.2.0development
husky
Environment
{
  "local_name": "husky",
  "alias": false,
  "peer_metadata": null
}
^4.3.6development
lint-staged
Environment
{
  "local_name": "lint-staged",
  "alias": false,
  "peer_metadata": null
}
^10.5.3development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
^2.2.1development
rollup
Environment
{
  "local_name": "rollup",
  "alias": false,
  "peer_metadata": null
}
^2.34.2development
rollup-plugin-peer-deps-external
Environment
{
  "local_name": "rollup-plugin-peer-deps-external",
  "alias": false,
  "peer_metadata": null
}
^2.2.4development
standard-version
Environment
{
  "local_name": "standard-version",
  "alias": false,
  "peer_metadata": null
}
^9.0.0development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^4.1.2development
react
Environment
{
  "local_name": "react",
  "alias": false,
  "peer_metadata": null
}
^17.0.1peer
react-dom
Environment
{
  "local_name": "react-dom",
  "alias": false,
  "peer_metadata": null
}
^17.0.1peer

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-DFnWSuxv2WP/l/1P6d7vULH6ROg5BTTdbElERoq88eZtnJhMZh2kXUZW4VPTITxgICwxH6R60BA5DL8cG4PXtQ==",
  "shasum": "b15bd0c790fa95c58307aadd5fcd563e849067e7",
  "tarball": "https://registry.npmjs.org/@0xllllh/react-krpano/-/react-krpano-0.1.1.tgz",
  "fileCount": 32,
  "unpackedSize": 147391,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf23EaCRA9TVsSAnZWagAA4ScP/A1F+51P5aNoNwF2UMmC\n3YjwYrjmlZ7Sz5L8LZfV6IjCE5+n93siWBiWjwbCdlBWcYuW34s04eR/dLZ6\n2ywz8Qjn6TUrq1pQ4nyDylFWTGfQDk/gYff0snlUgXqAMwUij1B+CECpoGY1\nktD0q4JtpGL1mShJ5mlJmkmJwHk0GxLlfLwcTIlpruTFcaTeciId7pkvoV/5\n7QqfYAGZMbFoA1tnl2IilaKxUIW8p3zUKVZ9b9nqhH8A0rHoqNibUfrQx3b2\nM06cnH3r8SQQTjjo644wxs6u8iIWYUseI3kPLfsDgNoREbv2hoB8PU/Gm3YW\nIxrJR7IcDlgS2nRu8HzA78CnJcRcuClr5AVQtmSFcw1AqX7WygyOukSu6ixX\nn4GycR/OtSrM/77qDUSSnoWL+NCSpoo03UPMAIxm+xQ+rNO8QBRsYL59i12o\noDj7bP4SjcwE8TZNFrsR9M37GIufwq8+jQllbhXI4MT+Xv2kG8yEFRfLFckO\nOFzzBek0h9EgCs+Cn8SjmsspFxdhrE1usZGG27oES4e99xWv66RCTRCZhUnY\nxu14vqkQqfX7r55sdXKx4kkjr4kw5EroFzePWXepauTP0mBysVI8YMvNn0F2\nKH8L/AjjATGPK5Xy8IAh1RtMTT6R3kKoesb8W9w/T29tth/OKD4mG1rrrJxy\nsmVa\r\n=WkX4\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQCJbcF1GCgp5vNaPsHpRWEVQ+ck7EyVwPj2zT3GCbcUkAIgCOnlQ6JYveqzspVCpQbsf8H9ZCJDzAD8HthYDzyt06U="
    }
  ]
}

Repository

PENDING
0xllllh/react-krpano

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 09:04 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:8dbefd0b5a9ba88e20de030dee8601e1258e71850199954cc998448579387648

Other collected versions

0.1.522 Feb0.1.43 Mar0.1.33 Jan0.1.219 Dec0.1.017 Dec0.0.216 DecView all collected versions →