Git Product home page Git Product logo

ngx-kjua's Introduction

NPM version Downloads PRs Welcome

If you find my work useful you can buy me a coffee, I am very thankful for your support.

Buy Me A Coffee

ngx-kjua

Angular QR-Code generator component.

This is basically an Angular-wrapper for kjua by Lars Jung.

Breaking changes v16.1.0

Fromm the v16.1.0 this library use the standalone component, and not the module anymore.
See how to implement it

Demo

Demo

StackBlitz

StackBlitz Example for encoding Contacts, Calendar entries, WiFi-settings and more. You can use iPhone's default Camera App, it will decode QR-Codes!

StackBlitz Example with 300 codes at once (async rendering)

StackBlitz Example for generating a PDF with jspdf

Installation

To install this package, run:

npm i ngx-kjua --save

Then import it into your Angular AppModule:

// Common imports
import { NgModule /* , ... */ } from '@angular/core';

// Import the package's module
import { NgxKjuaComponent } from 'ngx-kjua';

@NgModule({
    declarations: [ /* AppComponent ... */ ],
    imports: [
    
        // BrowserModule, 
        // ...
        
        NgxKjuaComponent,
        
        // other imports...
    ],
    // ...
})
export class AppModule { }

Usage

Once the package is imported, you can use it in your Angular application:

Basic

  <ngx-kjua
    [text]="'hello'"
  ></ngx-kjua>

Advanced

  <ngx-kjua
    [text]="'hello'"
    [renderAsync]="false"
    [render]="'svg'"
    [crisp]="true"
    [minVersion]="1"
    [ecLevel]="'H'"
    [size]="400"
    [ratio]="undefined"
    [fill]="'#333'"
    [back]="'#fff'"
    [rounded]="100"
    [quiet]="1"
    [mode]="'plain'"
    [mSize]="30"
    [mPosX]="50"
    [mPosY]="50"
    [label]="'label text'"
    [fontname]="'sans-serif'"
    [fontcolor]="'#ff9818'"
    [image]="undefined"
    [cssClass]="'image-auto'"
  ></ngx-kjua>

Options

Caution: When adding images, label or similar, this will reduce the readability of the QR-code. Consider using a higher error correction level (e.g. L) in those cases.

Crisp

As you can set the size of the image, the amount of 'modules' (black/white boxes that make up the QR-code) is calculated based on the size and the amount of quiet modules. The calculation can result in an odd number so that a module is e.g. 4.5 pixels big. The resulting image will be drawn fuzzy if crisp is set to false. Setting it to true will result in 'sharp' lines.

crisp false

crisp true

Label

Kjua lets you embed a text or image to the code. This can be set with the setting mode. This can reduce the readability of the code!

Image

Image as Code

Clear + Image

This mode let's you "cut out" parts of the QR-code and at the same time add an image.

labelimage, imagelabel and clearimage

Use this, if you want a label AND an image. In these modes mSize, mPosX and mPosY can be provided as an array. In mode labelimage, the first value (index 0) of the mSize, mPosX and mPosY arrays is used for the label, the second value (index 1) is used for image and vice versa. Also in labelimage mode, the label is drawn before the image is drawn and therefore kinda "in the background" if the two overlap.

All options

  • text encoded content (defaults to ``)
  • render render-mode: 'image', 'canvas', 'svg' (defaults to image)
  • crisp render pixel-perfect lines (defaults to true)
  • minVersion minimum version: 1..40 (defaults to 1)
  • ecLevel error correction level: 'L', 'M', 'Q' or 'H' (defaults to L)
  • size size in pixel (defaults to 200, min 24 or higher, depend on how much character you're using)
  • fill code color (defaults to #333)
  • back background color (defaults to #fff, for transparent use '' or null)
  • rounded roundend corners in pc: 0..100 (defaults to 0, not working if renderis set to svg)
  • quiet quiet zone in modules (defaults to 0)
  • mode modes: 'plain', 'label', 'image' or 'clear' (defaults to plain, set label or image property if you change this)
  • mSize label/image size in pc: 0..100 (defaults to 30)
  • mPosX label/image pos x in pc: 0..100 (defaults to 50)
  • mPosY label/image pos y in pc: 0..100 (defaults to 50)
  • label additional label text (defaults to ``)
  • fontname font for additional label text (defaults to sans-serif)
  • fontcolor font-color for additional label text (defaults to #333)
  • fontoutline draw an outline on the label text in the color of the back (defaults to true)
  • image additional image (defaults to undefined, use an HTMLImageElement or base64-string)
  • imageAsCode draw the image as part of the code (defaults to false)
  • renderAsync weather or not rendering is done inside "requestAnimationFrame"-call (defaults to false, use true if you want to generate more than one code (e.g. batch))
  • cssClass additional css-class that will be appended to the div-container that contains the qr-code (defaults to undefined)

More details can be found on larsjung.de/kjua

Async rendering

If you plan to render more than one barcode (e.g. batch-generation) I recommend using renderAsync-flag. It executes the rendering inside a "requestAnimationFrame"-call.

Encoding Contacts, Calendar entries, WiFi-settings, ...

The component comes with a helper-class (QrCodeHelper), that helps you with generating Codes that have information like a Contact encoded. Currently it supports the generation of:

  • SMS: number with optional pre-defined text
  • Call
  • Geo-Information: a point on the map with Latitude and Longitude
  • Events
  • Email: recipient with an optional subject and text
  • WiFi: SSID with optional password and a flag for hidden WiFis
  • Contact Information: name with optional address, telephone-number(s), email, url.

Contact Encoding is done with MECard-format and NOT VCard! VCard gives a longer string and therefore a bigger code which potentially has a negative impact on readability for scanners. You can, of course, create a VCard string as well but the format is more complex.

Generate PDF

See the example above. It works with pure kjua and has in fact nothing to do with ngx-kjua but I thought somebody might find it useful.

ngx-kjua's People

Contributors

delyethan avatar dependabot[bot] avatar hramberger avatar josineiaraujo avatar rbalet avatar werthdavid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-kjua's Issues

QR Code Image Style

Hello

Thanks for your professional package for generating QR code.
I'm using this image in a portlet and I like to have some options to style the QR code image e.g. I need variable size for being responsive or some CSS styles to place image in the middle of the portlet. I used ::ng-deep img {} in angular component styles to add style to below image tag, but it affects all image tags in all components we have.
I think it will be good if you add style options to ngx-kjua or at least add spcific class to below image tag for flexible usage of ng-deep to add style to that.

<ngx-kjua>
    <div>
        <img src="" width="400" height="400" style="width: 200px; height: 200px;">
    </div>
</ngx-kjua>

Thanks

feature request : output the newly created element

Description

I would find it useful that the component does emit his value when it did finish initializing it.

Objective

Being able to bind it with a button that let the user download the file.

Implementation

@Output() emitData = new EventEmitter<any>()

Result

<ngx-kjua
 (emoitData)="downloadFIle = $event"
></ngx-kjua>

Angular 6.0.2 cannot find module 'ngx-kjua' Vers. 1.4.0

Angular: 6.0.2
ngx-kjua: 1.4.0

Imported into the root level app.module.ts using ReadMe details.
import { NgxKjuaModule } from 'ngx-kjua';

ng serve throws the following error. VS-Code highlights and shows the same:

ERROR in src/app/app.module.ts(18,31): error TS2307: Cannot find module 'ngx-kjua'.

All dependencies are installed and visible in the node modules directory

PS: With [email protected] it works!

bug: ERROR ReferenceError: require is not defined

Description

After the update to 1.14.0 the NgxKjuaComponent throws the following error when it is been initialized / first called in our application (see Stacktrace for more details):

ERROR ReferenceError: require is not defined
The compilation on the other hand runs without any errors.
Moreover version 1.13.2 works fine in the exact same setting.
Do I need a special configuration (e.g special compiler options) to make version 1.14.0 work?

Stacktrace

main.js ERROR ReferenceError: require is not defined
    at new NgxKjuaComponent
    at NodeInjectorFactory.NgxKjuaComponent_Factory [as factory]
    at getNodeInjectable
    at instantiateAllDirectives
    at createDirectivesInstances
    at ɵɵelementStart
    at Module.ɵɵelement
    at MyComponent_Template
    at executeTemplate
    at renderView

The references in the stacktrace point to the following code in the transpiled main.js which is part of the class cunstructor of NgxKjuaComponent:

    if ((0,_angular_common__WEBPACK_IMPORTED_MODULE_1__.isPlatformServer)(this.platformId)) {
      return;
    } else if (!kjua) {
      kjua = require("kjua-svg");
    }

Used versions

  "dependencies": {
	...
    "@angular/common": "13.2.2",
    "@angular/compiler": "13.2.2",
    "@angular/core": "13.2.2",
	...
    "kjua-svg": "1.13.1", (as defined in the peerDependencies)
    "ngx-kjua": "1.14.0",
	...
  },
  "devDependencies": {
	...
    "@angular-devkit/build-angular": "13.2.3",
    "@angular/cli": "13.2.3",
    "@angular/compiler-cli": "13.2.2",
    "@types/node": "17.0.18",
    "typescript": "4.4.4",
	...
  }

ngx-kjua modes 'imagelabel' and 'labelimage' bug

Hello,

angular and pakage version:

"@angular/cli": "~12.0.0",
"ngx-kjua": "^1.13.0",

in mode 'imagelabel' or 'labelimage':
mSize, mPosX, mPosY must accept a number or an array of number,
i tray that but i get this message on the angular cli: Type 'number' is not assignable to type 'undefined'. mSize:[10, 2],

here i check the kjua interface i found this:

/**
* label/image size and pos in pc: 0..100
*/
mSize?: number | [number];
mPosX?: number | [number];
mPosY?: number | [number];

we can solve this issues by:

const mSize: [number] = [10, 5] as any;
const mPosX: [number] = [50, 10] as any;
const mPosY: [number] = [50, 2] as any;

or by updating the interface code: '[number]' by 'Array[number]' to accept the array values in 'imagelabel' or 'labelimage' mode.

/**
* label/image size and pos in pc: 0..100
*/
mSize?: number | Array<number>;
mPosX?: number | Array<number>;
mPosY?: number | Array<number>;

update - changelog : v2.1.0

Add the v2.1.0 to the changelog.

@werthdavid Thx for the update <3.

If you wish I can do such update on my own if you give me the access :)

Feature-request

I'm starting to do as follow we my libraries, but basically I update the library version accordingly to the angular one.
Meaning the version here would be v16.0.0.

Doing that way let people see better & directly which version to install.

What do you think ?

ReferenceError: window is not defined

was using this in angular 13 universal and this error occurred.

Setup:

<ngx-kjua [text]="settings.data" [renderAsync]="false" [render]="'svg'" [crisp]="true" [minVersion]="1" [ecLevel]="settings.errorCorrectionLevel" [size]="400" [ratio]="undefined" [fill]="settings.fgColor" [back]="settings.bgColor" [rounded]="100" [quiet]="1" [mode]="'plain'" [mSize]="30" [mPosX]="50" [mPosY]="50" [label]="'label text'" [fontname]="'sans-serif'" [fontcolor]="'#ff9818'" [image]="undefined" [cssClass]="'image-auto'"></ngx-kjua>

Error after upgrading to 18

Hi! First of all, thanks for this awesome package.

I'm having some issues after upgrading to Angular 18 and 18.1.1 version of this lib:

 [ERROR] Cannot assign to import "stringToBytes"

    node_modules/ngx-kjua/fesm2022/ngx-kjua.mjs:587:7:
      587 │ qr_gen.stringToBytes = qr_gen.stringToBytesFuncs["UTF-8"];
          ╵        ~~~~~~~~~~~~~

  Imports are immutable in JavaScript. To modify the value of this import, you must export a setter
  function in the imported file (e.g. "setStringToBytes") and then import and call that function
  here instead.

I didn't have any issue in NG17
Thanks

Edit: I think this is the problem?

(qr_gen as any).stringToBytes = qr_gen.stringToBytesFuncs["UTF-8"];

I'm using the application builder since it's recommended in v17 and higher

bug: container height

Description

The container height isn't the same as the svg one

image

Idea how to fix

I'd give the div that we have around the svg the same height & width

Why is it a problem.

As you can see in the picture, I would have loved to add a rounded border all around, but this isn't working properly.

feature request : add element id

Description

Being able to add an id to the image could be really useful.

Objective

Being able to get the element with its ID so we could download the image in the local machine.

Implementation

@input() id: string

Result

<svg id="myId" xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200" style="width: 200px; height: 200px;">

ERROR Error: code length overflow.

Hi,

First of all what a nice library you have here for angular.
Im creating a qr code with vcf contact details. My image is base64 and its too long im getting this error ERROR Error: code length overflow.

do we have any alternative?

and also when generating a qr code, it padding in the side depending on values. Notice the white background differs

Screenshot 2023-06-18 at 4 40 41 PM Screenshot 2023-06-18 at 4 41 37 PM

feat(image): avoid under image

Description

Would it be doable to avoid rendering the middle of the qr-code ?

This would enable having gradient under the qr-code

image

ReferenceError: window is not defined

When using ngx-kjua with Angular Universal (for SSR support), an error is thrown, when starting the node web server:

ReferenceError: window is not defined

Support angular 17

Would be nice if the library could support angular 17.

Would also be nice if the library also support future angular update, in a way that this does accept those version, since angular is now pretty stable I'm that regards

bug : quiet 0 not working

Description

even with quiet: 0 the QR-Code sometimes have a white border.

Expected behavior

Being able to set [quiet]="0" or simple not adding the variable at all and having a nice path that is merged with the border

add image on the qr-code

guys, can someone show me how to add an image on the qr code using base64? i am a little bit confused, i appreciate your attention.

Error importing NgxKjuaModule on Angular 7

Hi,
when I import NgxKjuaModule
import { NgxKjuaModule } from 'ngx-kjua';
I have this error:

ERROR in ./node_modules/ngx-kjua/esm5/ngx-kjua.js
Module not found: Error: Can't resolve 'kjua' in 'C:\....\node_modules\ngx-kjua\esm5'

How can add pasword in QR code

Hi,

I would like to add password in my QR code so if and when I scan my barcode, it will ask for password and if I entered correct password then only will able to read the content of barcode.

Is it possible in your QR code script?

Angular 7.2.11 cannot find module 'ngx-kjua'

Angular: 7.2.11
ngx-kjua: 1.3.1
kjua: 0.1.2

Imported into the root level app.module.ts using readme details.

import { NgxKjuaModule } from 'ngx-kjua';

ng serve throws the following error. Vs code highlights and shows the same:

ERROR in src/app/app.module.ts(24,31): error TS2307: Cannot find module 'ngx-kjua'

All dependencies are installed and visible in the node modules directory

iphone camera scanner

While Scanning QR Code With iphone Camera Scanner ,
If Number Of The Words while creating Contact more than three not read The name

Auto format text as string

Description

Somehow, I've added a number to the qr-code generator and it outputted me a qr-code.

Little did I know that it was just a default image with no value.

Idk why I was to lazy to test it, but I just shipped it.

It didn't work, obviously.

Feature request

Being able to pass a number and it being converted automatically to a string.

Code

From

  @Input()
  text = "";

To

  private _text = "";
  @Input() text(value: any) {
    if (String(value)) this._text = value;
    else if (Number(value)) this._text = value.toString();
    else this._text = "";
  }

add - CHANGELOG

I would find it very useful that have a small CHANGELOG.md file that list what does have the new release, so that we know why we are updating the library, and if it may break stuff.

feat(size): accept string

Description

Would be nice to accept string instead of only number, so we can write size="200" & [size]="200" at the same time

error NG8001: 'ngx-kjua' is not a known element:

Trying out v2.0 but getting error with Angular v13.0.0

Error: src/app/components/qr-code/qr-code.component.html:4:7 - error NG8001: 'ngx-kjua' is not a known element:

  1. If 'ngx-kjua' is an Angular component, then verify that it is part of this module.
  2. If 'ngx-kjua' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

4 <ngx-kjua
~~~~~~~~~
5 [renderAsync]="true"
~~~~~~~~~~~~~~~~~~~~~~~~~~
...
13 [size]="size"
~~~~~~~~~~~~~~~~~~~
14 >

Update to Angular 14

Hi.

Thank you for the great plugin.

When running on Angular 14 the following error is displayed.

ERROR TypeError: (kjua_svg__WEBPACK_IMPORTED_MODULE_0___namespace_cache || kjua_svg__WEBPACK_IMPORTED_MODULE_0___namespace_cache) is not a function
    at get template [as template] (http://localhost/src_app_pages_receive_receive_module_ts.js:2464:206)
    at NgxKjuaComponent.renderCode (http://localhost/src_app_pages_receive_receive_module_ts.js:2469:23)
    at NgxKjuaComponent.updateView (http://localhost/src_app_pages_receive_receive_module_ts.js:2495:14)
    at NgxKjuaComponent.ngAfterViewInit (http://localhost/src_app_pages_receive_receive_module_ts.js:2

Using

"kjua-svg": "^1.13.1",
"ngx-kjua": "^1.14.4",

Is there an easy workaround?

Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.