• Stars
    star
    418
  • Rank 100,305 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 1 year ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A no-framework, no-dependencies, customizable, animate-able, SVG-based <qr-code> HTML element.

npm npm downloads Follow Bitjson on Twitter GitHub stars

<qr-code>

A no-framework, no-dependencies, customizable, animate-able, SVG-based <qr-code> HTML element. It's just a single, self-contained Web Component.

bitjson-qr-code-demo.mp4

Usage

Import <qr-code> using your build system or framework (e.g. npm install @bitjson/qr-code), or use the standalone script in your HTML <head> element:

<script src="https://unpkg.com/@bitjson/[email protected]/dist/qr-code.js"></script>

Then use the component anywhere in your HTML <body> element:

<qr-code contents="https://bitjson.com"></qr-code>

Full Example

Here's an example in pure HTML using most features:

<qr-code
  id="qr1"
  contents="https://bitjson.com/"
  module-color="#1c7d43"
  position-ring-color="#13532d"
  position-center-color="#70c559"
  mask-x-to-y-ratio="1.2"
  style="
    width: 200px;
    height: 200px;
    margin: 2em auto;
    background-color: #fff;
  "
>
  <img src="assets/1.2-x-to-y-ratio-icon.svg" slot="icon" />
</qr-code>

<script>
  document.getElementById('qr1').addEventListener('codeRendered', () => {
    document.getElementById('qr1').animateQRCode('MaterializeIn');
  });
</script>

Animations

Animate in, animate on user interactions like URL hits or detected payments, and/or animate out when the QR code interaction is complete.

Several preset animations are available, simply run them with the element's animateQRCode method:

document.getElementById('qr1').animateQRCode('RadialRipple');

Available built-in presets:

  • FadeInTopDown
  • FadeInCenterOut
  • MaterializeIn
  • RadialRipple
  • RadialRippleIn

You can also design your own custom animations! Just pass a function to the qr-code's animateQRCode method, e.g.:

document
  .getElementById('qr1')
  .animateQRCode((targets, _x, _y, _count, entity) => ({
    targets,
    from: entity === 'module' ? Math.random() * 200 : 200,
    duration: 500,
    easing: 'cubic-bezier(.5,0,1,1)',
    web: { opacity: [1, 0], scale: [1, 1.1, 0.5] },
  }));

The built-in presets use this API internally, so review those for guidance and inspiration. Pull request for new presets are welcome!

Animation Previewer

The animation previewer makes fine-tuning animations much easier: try it by cloning this repo and running the live-reloading package script:

git clone https://github.com/bitjson/qr-code.git
cd qr-code
npm ci
npm start

Then work on your animation in src/index.html using the animation previewer (at the bottom right of the window) to test the last-run animation at various speeds, scrub through it manually, or play it in reverse.

Production build

Disable the just-animate player in src/components/qr-code/qr-code.tsx, then build:

npm run build

You can test the built component by pointing the script in index.html to dist/qr-code.js and opening the page via the local filesystem.

More Repositories

1

typescript-starter

Quickly create and configure a new library or Node.js project
TypeScript
3,385
star
2

wip

WIP & naenae: CLI utilities to easily manage Work In Progress with Git
JavaScript
47
star
3

cashtokens

A proposal to enable two new primitives on Bitcoin Cash: fungible tokens and non-fungible tokens.
29
star
4

s18n

Semantic localization for html.
JavaScript
23
star
5

gulp-l10n

A gulp plugin for localizing html.
JavaScript
14
star
6

pmv3

(Withdrawn) A version 3 transaction format proposal for Bitcoin Cash. Maintainer recommends CashTokens:
13
star
7

jedex

Joint-Execution Decentralized Exchange – is a technical demonstration of a decentralized exchange built on Bitcoin Cash using CashTokens.
11
star
8

couple-api

Unofficial Couple CLI and node library (incomplete)
JavaScript
10
star
9

chip-bcmr

CHIP: Bitcoin Cash Metadata Registries
TypeScript
9
star
10

webshotgun

Webshotgun uses slimerjs to screenshot a list of urls.
JavaScript
9
star
11

bch-zce

CHIP-2021-08-ZCE: Zero-Confirmation Escrows – instant, incentive-secure payments on Bitcoin Cash.
8
star
12

TSA-logo

Vectored emblems (logos) for the national and state delegations of the Technology Student Association.
8
star
13

bch-loops

A proposal to enable loops in BCH contracts without increasing processing or memory requirements.
3
star
14

bch-vm-limits

By fixing poorly-targeted limits, we can make Bitcoin Cash contracts more powerful (without increasing validation costs).
3
star
15

bootstrap-breakpointify

Fight class creep with breakpoint suffixes for Bootstrap v4's utilities.
CSS
2
star
16

next-api-routes-bug

bug with query params: https://api-routes-app.bitjson.now.sh/api/people/1?q=a&q=b
JavaScript
2
star
17

create-bitauth-id

Create a BitAuth identifier (mostly) following the cash account spec
JavaScript
2
star
18

bitcoin-cpp-script

Work in Progress (status: nothing yet...)
C++
2
star
19

bitauth-slides

Original Bitauth presentation (Jan 2017):
JavaScript
2
star
20

libauth-signing-test

TypeScript
2
star
21

TSAPress

A WordPress theme for Technology Student Association state delegations. Currently in use at http://VirginiaTSA.org/
PHP
2
star
22

bitauth-npm-review

Not currently under development, check out
TypeScript
2
star
23

bitcoin-ts-example

A simple playground project for bitcoin-ts. You can also try it (without Typescript and the helpful autocompletion) on RunKit:
TypeScript
2
star
24

op-pushstate

(Withdrawn) A proposal for an OP_PUSHSTATE BCH VM operation. Replaced by CHIP-2021-02: Native Introspection Opcodes.
2
star
25

bitcoind.rs

Rust
1
star
26

bitcoin-hivemind-slack-irc-bridge

JavaScript
1
star
27

cashchannels-presentation

A quick reveal.js presentation for 2019-12-4 talk at BitPay
JavaScript
1
star
28

npm-archiver

...download the whole thing.
JavaScript
1
star
29

typescript-bug

example of a bug in TypeScript's forceConsistentCasingInFileNames
TypeScript
1
star
30

now-dev-custom-errors-bug

Reproduce bug in `now dev` error handling
TypeScript
1
star
31

qrscanner-test

Simple test project for cordova-plugin-qrscanner
CSS
1
star
32

cashtokens.org

A community-maintained website about the CashTokens technology, including technical specifications, documentation, guides, and other resources.
1
star
33

dc-pool

wip
TypeScript
1
star
34

gulp-s18n

This project has moved to:
JavaScript
1
star
35

geyser

(abandoned)
TypeScript
1
star
36

now-dev-async-bug

Reproduce an inconsistency in async task handling by `now dev`/`now` production
TypeScript
1
star
37

bitcoin-dev-discord

just bots
1
star
38

bitauth-ide-slides

TABConf demo
JavaScript
1
star