diff --git a/pr-preview/pr-14/.vscode/settings.json b/pr-preview/pr-14/.vscode/settings.json new file mode 100644 index 0000000..0f9429a --- /dev/null +++ b/pr-preview/pr-14/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5503 +} \ No newline at end of file diff --git a/pr-preview/pr-14/README.md b/pr-preview/pr-14/README.md new file mode 100644 index 0000000..7491c7b --- /dev/null +++ b/pr-preview/pr-14/README.md @@ -0,0 +1,105 @@ +# Dynamsoft MRZ Scanner for Web + +The [Dynamsoft MRZ Scanner](https://www.dynamsoft.com/use-cases/mrz-scanner/?utm_source=mrzdemo&package=js) enables camera to scan the MRZ code of ID-cards and passports. It will extract all data like first name, last name, document number, nationality, date of birth, expiration date and more from the MRZ string, and converts the encoded string into human-readable fields. + +## Web demo + +You can scan the QR code below with your phone to visit our online demo, or use a desktop browser to access [https://demo.dynamsoft.com/solutions/mrz-scanner/index.html](https://demo.dynamsoft.com/solutions/mrz-scanner/index.html) (no personal data will be uploaded). + +mrz-scanner-demo-qr-code + +## Run this Solution + +1. Clone the repository to a working directory or download the code as a ZIP file: + +```sh +git clone https://github.com/Dynamsoft/mrz-scanner-javascript +``` + +2. Deploy the files to a directory hosted on an HTTPS server. + +3. Open the "index.html" file in your browser. + +> Basic Requirements +> +> * Internet connection +> * [A supported browser](#system-requirements) +> * An accessible Camera + +----- + +## Request a Trial License + +The key "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" used in this solution (found in the js/init.js file) is a test license valid for 24 hours for any newly authorized browser. If you wish to test the SDK further, you can request a 30-day free trial license through the Request a Trial License link. + +## Project Structure + +```text +MRZ Scanner +├── assets +│ ├── ... +│ ├── ... +│ └── ... +├── css +│ └── index.css +├── font +│ ├── ... +│ ├── ... +│ └── ... +├── js +│ ├── const.js +│ ├── index.js +│ ├── init.js +│ └── util.js +├── index.html +└── template.json +``` + + * `/assets` : This directory contains all the static files such as images, icons, etc. that are used in the project. + * `/css` : This directory contains the CSS file(s) used for styling the project. + * `/font` : This directory contains the font files used in the project. + * `/js` : This directory contains all the JavaScript files used in the project. + * `const.js` : This file contains definitions of certain constants or variables used across the project. + * `index.js`: This is the main JavaScript file where the core logic of the project is implemented. + * `init.js` : This file is used for initialization purposes, such as initializing license, load resources, etc. + * `util.js` : This file contains utility functions that are used across the project. + * `index.html` : This is the main HTML file that represents the homepage of the project. + * `template.json` : This file contains predefined templates used in the project. + +## System Requirements + +This project requires the following features to work: + +- Secure context (HTTPS deployment) + + When deploying your application / website for production, make sure to serve it via a secure HTTPS connection. This is required for two reasons + + - Access to the camera video stream is only granted in a security context. Most browsers impose this restriction. + > Some browsers like Chrome may grant the access for `http://127.0.0.1` and `http://localhost` or even for pages opened directly from the local disk (`file:///...`). This can be helpful for temporary development and test. + + - Dynamsoft License requires a secure context to work. + +- `WebAssembly`, `Blob`, `URL`/`createObjectURL`, `Web Workers` + + The above four features are required for the SDK to work. + +- `MediaDevices`/`getUserMedia` + + This API is required for in-browser video streaming. + +- `getSettings` + + This API inspects the video input which is a `MediaStreamTrack` object about its constrainable properties. + +The following table is a list of supported browsers based on the above requirements: + + | Browser Name | Version | + | :----------: | :--------------: | + | Chrome | v78+1 | + | Firefox | v68+1 | + | Edge | v79+ | + | Safari | v14+ | + + 1 devices running iOS needs to be on iOS 14.3+ for camera video streaming to work in Chrome, Firefox or other Apps using webviews. + +Apart from the browsers, the operating systems may impose some limitations of their own that could restrict the use of the SDK. Browser compatibility ultimately depends on whether the browser on that particular operating system supports the features listed above. diff --git a/pr-preview/pr-14/assets/Music-selected.svg b/pr-preview/pr-14/assets/Music-selected.svg new file mode 100644 index 0000000..f440979 --- /dev/null +++ b/pr-preview/pr-14/assets/Music-selected.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pr-preview/pr-14/assets/arrow-down 1.svg b/pr-preview/pr-14/assets/arrow-down 1.svg new file mode 100644 index 0000000..15adf7a --- /dev/null +++ b/pr-preview/pr-14/assets/arrow-down 1.svg @@ -0,0 +1,3 @@ + + + diff --git a/pr-preview/pr-14/assets/arrow-up 1.svg b/pr-preview/pr-14/assets/arrow-up 1.svg new file mode 100644 index 0000000..5c1e308 --- /dev/null +++ b/pr-preview/pr-14/assets/arrow-up 1.svg @@ -0,0 +1,3 @@ + + + diff --git a/pr-preview/pr-14/assets/logo-dynamsoft-blackBg-190x47.png b/pr-preview/pr-14/assets/logo-dynamsoft-blackBg-190x47.png new file mode 100644 index 0000000..7967e8e Binary files /dev/null and b/pr-preview/pr-14/assets/logo-dynamsoft-blackBg-190x47.png differ diff --git a/pr-preview/pr-14/assets/mrz-guide-box.svg b/pr-preview/pr-14/assets/mrz-guide-box.svg new file mode 100644 index 0000000..c5702ef --- /dev/null +++ b/pr-preview/pr-14/assets/mrz-guide-box.svg @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pr-preview/pr-14/assets/music-unselected.svg b/pr-preview/pr-14/assets/music-unselected.svg new file mode 100644 index 0000000..0edab1f --- /dev/null +++ b/pr-preview/pr-14/assets/music-unselected.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/pr-preview/pr-14/assets/qr-code.svg b/pr-preview/pr-14/assets/qr-code.svg new file mode 100644 index 0000000..4bdc98f --- /dev/null +++ b/pr-preview/pr-14/assets/qr-code.svg @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pr-preview/pr-14/assets/torch-icon-close.svg b/pr-preview/pr-14/assets/torch-icon-close.svg new file mode 100644 index 0000000..6b47cce --- /dev/null +++ b/pr-preview/pr-14/assets/torch-icon-close.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pr-preview/pr-14/assets/torch-icon-open.svg b/pr-preview/pr-14/assets/torch-icon-open.svg new file mode 100644 index 0000000..e8c0013 --- /dev/null +++ b/pr-preview/pr-14/assets/torch-icon-open.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pr-preview/pr-14/assets/upload-image.svg b/pr-preview/pr-14/assets/upload-image.svg new file mode 100644 index 0000000..fbb3d38 --- /dev/null +++ b/pr-preview/pr-14/assets/upload-image.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/pr-preview/pr-14/bare_pr_preview/HEAD b/pr-preview/pr-14/bare_pr_preview/HEAD new file mode 100644 index 0000000..747abf4 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/HEAD @@ -0,0 +1 @@ +b3a95bc3cdbc27d8941e9b74c5c294c9c9fcb12b diff --git a/pr-preview/pr-14/bare_pr_preview/config b/pr-preview/pr-14/bare_pr_preview/config new file mode 100644 index 0000000..d14c137 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true +[remote "origin"] + url = https://github.com/rossjrw/pr-preview-action diff --git a/pr-preview/pr-14/bare_pr_preview/description b/pr-preview/pr-14/bare_pr_preview/description new file mode 100755 index 0000000..498b267 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/applypatch-msg.sample b/pr-preview/pr-14/bare_pr_preview/hooks/applypatch-msg.sample new file mode 100755 index 0000000..a5d7b84 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/applypatch-msg.sample @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, rename this file to "applypatch-msg". + +. git-sh-setup +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/commit-msg.sample b/pr-preview/pr-14/bare_pr_preview/hooks/commit-msg.sample new file mode 100755 index 0000000..b58d118 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/fsmonitor-watchman.sample b/pr-preview/pr-14/bare_pr_preview/hooks/fsmonitor-watchman.sample new file mode 100755 index 0000000..23e856f --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/fsmonitor-watchman.sample @@ -0,0 +1,174 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 2) and last update token +# formatted as a string and outputs to stdout a new update token and +# all files that have been modified since the update token. Paths must +# be relative to the root of the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $last_update_token) = @ARGV; + +# Uncomment for debugging +# print STDERR "$0 $version $last_update_token\n"; + +# Check the hook interface version +if ($version ne 2) { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree = get_working_dir(); + +my $retry = 1; + +my $json_pkg; +eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; +} or do { + require JSON::PP; + $json_pkg = "JSON::PP"; +}; + +launch_watchman(); + +sub launch_watchman { + my $o = watchman_query(); + if (is_work_tree_watched($o)) { + output_result($o->{clock}, @{$o->{files}}); + } +} + +sub output_result { + my ($clockid, @files) = @_; + + # Uncomment for debugging watchman output + # open (my $fh, ">", ".git/watchman-output.out"); + # binmode $fh, ":utf8"; + # print $fh "$clockid\n@files\n"; + # close $fh; + + binmode STDOUT, ":utf8"; + print $clockid; + print "\0"; + local $, = "\0"; + print @files; +} + +sub watchman_clock { + my $response = qx/watchman clock "$git_work_tree"/; + die "Failed to get clock id on '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + return $json_pkg->new->utf8->decode($response); +} + +sub watchman_query { + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $last_update_token but not from the .git folder. + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. Then we're using the "expression" term to + # further constrain the results. + my $last_update_line = ""; + if (substr($last_update_token, 0, 1) eq "c") { + $last_update_token = "\"$last_update_token\""; + $last_update_line = qq[\n"since": $last_update_token,]; + } + my $query = <<" END"; + ["query", "$git_work_tree", {$last_update_line + "fields": ["name"], + "expression": ["not", ["dirname", ".git"]] + }] + END + + # Uncomment for debugging the watchman query + # open (my $fh, ">", ".git/watchman-query.json"); + # print $fh $query; + # close $fh; + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; }; + + # Uncomment for debugging the watch response + # open ($fh, ">", ".git/watchman-response.json"); + # print $fh $response; + # close $fh; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + return $json_pkg->new->utf8->decode($response); +} + +sub is_work_tree_watched { + my ($output) = @_; + my $error = $output->{error}; + if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) { + $retry--; + my $response = qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + $output = $json_pkg->new->utf8->decode($response); + $error = $output->{error}; + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + # Uncomment for debugging watchman output + # open (my $fh, ">", ".git/watchman-output.out"); + # close $fh; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + my $o = watchman_clock(); + $error = $output->{error}; + + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + output_result($o->{clock}, ("/")); + $last_update_token = $o->{clock}; + + eval { launch_watchman() }; + return 0; + } + + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + return 1; +} + +sub get_working_dir { + my $working_dir; + if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $working_dir = Win32::GetCwd(); + $working_dir =~ tr/\\/\//; + } else { + require Cwd; + $working_dir = Cwd::cwd(); + } + + return $working_dir; +} diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/post-update.sample b/pr-preview/pr-14/bare_pr_preview/hooks/post-update.sample new file mode 100755 index 0000000..ec17ec1 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/pre-applypatch.sample b/pr-preview/pr-14/bare_pr_preview/hooks/pre-applypatch.sample new file mode 100755 index 0000000..4142082 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/pre-commit.sample b/pr-preview/pr-14/bare_pr_preview/hooks/pre-commit.sample new file mode 100755 index 0000000..29ed5ee --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/pre-commit.sample @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --type=bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff-index --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/pre-merge-commit.sample b/pr-preview/pr-14/bare_pr_preview/hooks/pre-merge-commit.sample new file mode 100755 index 0000000..399eab1 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/pre-merge-commit.sample @@ -0,0 +1,13 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git merge" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message to +# stderr if it wants to stop the merge commit. +# +# To enable this hook, rename this file to "pre-merge-commit". + +. git-sh-setup +test -x "$GIT_DIR/hooks/pre-commit" && + exec "$GIT_DIR/hooks/pre-commit" +: diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/pre-push.sample b/pr-preview/pr-14/bare_pr_preview/hooks/pre-push.sample new file mode 100755 index 0000000..4ce688d --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/pre-push.sample @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +zero=$(git hash-object --stdin &2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/pre-rebase.sample b/pr-preview/pr-14/bare_pr_preview/hooks/pre-rebase.sample new file mode 100755 index 0000000..6cbef5c --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/pre-receive.sample b/pr-preview/pr-14/bare_pr_preview/hooks/pre-receive.sample new file mode 100755 index 0000000..a1fd29e --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/pre-receive.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/prepare-commit-msg.sample b/pr-preview/pr-14/bare_pr_preview/hooks/prepare-commit-msg.sample new file mode 100755 index 0000000..10fa14c --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/prepare-commit-msg.sample @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/push-to-checkout.sample b/pr-preview/pr-14/bare_pr_preview/hooks/push-to-checkout.sample new file mode 100755 index 0000000..af5a0c0 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/push-to-checkout.sample @@ -0,0 +1,78 @@ +#!/bin/sh + +# An example hook script to update a checked-out tree on a git push. +# +# This hook is invoked by git-receive-pack(1) when it reacts to git +# push and updates reference(s) in its repository, and when the push +# tries to update the branch that is currently checked out and the +# receive.denyCurrentBranch configuration variable is set to +# updateInstead. +# +# By default, such a push is refused if the working tree and the index +# of the remote repository has any difference from the currently +# checked out commit; when both the working tree and the index match +# the current commit, they are updated to match the newly pushed tip +# of the branch. This hook is to be used to override the default +# behaviour; however the code below reimplements the default behaviour +# as a starting point for convenient modification. +# +# The hook receives the commit with which the tip of the current +# branch is going to be updated: +commit=$1 + +# It can exit with a non-zero status to refuse the push (when it does +# so, it must not modify the index or the working tree). +die () { + echo >&2 "$*" + exit 1 +} + +# Or it can make any necessary changes to the working tree and to the +# index to bring them to the desired state when the tip of the current +# branch is updated to the new commit, and exit with a zero status. +# +# For example, the hook can simply run git read-tree -u -m HEAD "$1" +# in order to emulate git fetch that is run in the reverse direction +# with git push, as the two-tree form of git read-tree -u -m is +# essentially the same as git switch or git checkout that switches +# branches while keeping the local changes in the working tree that do +# not interfere with the difference between the branches. + +# The below is a more-or-less exact translation to shell of the C code +# for the default behaviour for git's push-to-checkout hook defined in +# the push_to_deploy() function in builtin/receive-pack.c. +# +# Note that the hook will be executed from the repository directory, +# not from the working tree, so if you want to perform operations on +# the working tree, you will have to adapt your code accordingly, e.g. +# by adding "cd .." or using relative paths. + +if ! git update-index -q --ignore-submodules --refresh +then + die "Up-to-date check failed" +fi + +if ! git diff-files --quiet --ignore-submodules -- +then + die "Working directory has unstaged changes" +fi + +# This is a rough translation of: +# +# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX +if git cat-file -e HEAD 2>/dev/null +then + head=HEAD +else + head=$(git hash-object -t tree --stdin &2 + exit 1 +} + +unset GIT_DIR GIT_WORK_TREE +cd "$worktree" && + +if grep -q "^diff --git " "$1" +then + validate_patch "$1" +else + validate_cover_letter "$1" +fi && + +if test "$GIT_SENDEMAIL_FILE_COUNTER" = "$GIT_SENDEMAIL_FILE_TOTAL" +then + git config --unset-all sendemail.validateWorktree && + trap 'git worktree remove -ff "$worktree"' EXIT && + validate_series +fi diff --git a/pr-preview/pr-14/bare_pr_preview/hooks/update.sample b/pr-preview/pr-14/bare_pr_preview/hooks/update.sample new file mode 100755 index 0000000..c4d426b --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/hooks/update.sample @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block unannotated tags from entering. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +# +# To enable this hook, rename this file to "update". +# +# Config +# ------ +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. +# hooks.denycreatebranch +# This boolean sets whether remotely creating branches will be denied +# in the repository. By default this is allowed. +# + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --type=bool hooks.allowunannotated) +allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch) +denycreatebranch=$(git config --type=bool hooks.denycreatebranch) +allowdeletetag=$(git config --type=bool hooks.allowdeletetag) +allowmodifytag=$(git config --type=bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero=$(git hash-object --stdin &2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 diff --git a/pr-preview/pr-14/bare_pr_preview/info/exclude b/pr-preview/pr-14/bare_pr_preview/info/exclude new file mode 100755 index 0000000..a5196d1 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/pr-preview/pr-14/bare_pr_preview/objects/pack/pack-f5043bd2e7bb236c48717782ed0d5d532770bc9d.idx b/pr-preview/pr-14/bare_pr_preview/objects/pack/pack-f5043bd2e7bb236c48717782ed0d5d532770bc9d.idx new file mode 100644 index 0000000..2382da1 Binary files /dev/null and b/pr-preview/pr-14/bare_pr_preview/objects/pack/pack-f5043bd2e7bb236c48717782ed0d5d532770bc9d.idx differ diff --git a/pr-preview/pr-14/bare_pr_preview/objects/pack/pack-f5043bd2e7bb236c48717782ed0d5d532770bc9d.pack b/pr-preview/pr-14/bare_pr_preview/objects/pack/pack-f5043bd2e7bb236c48717782ed0d5d532770bc9d.pack new file mode 100644 index 0000000..ba9c151 Binary files /dev/null and b/pr-preview/pr-14/bare_pr_preview/objects/pack/pack-f5043bd2e7bb236c48717782ed0d5d532770bc9d.pack differ diff --git a/pr-preview/pr-14/bare_pr_preview/objects/pack/pack-f5043bd2e7bb236c48717782ed0d5d532770bc9d.rev b/pr-preview/pr-14/bare_pr_preview/objects/pack/pack-f5043bd2e7bb236c48717782ed0d5d532770bc9d.rev new file mode 100644 index 0000000..9700a77 Binary files /dev/null and b/pr-preview/pr-14/bare_pr_preview/objects/pack/pack-f5043bd2e7bb236c48717782ed0d5d532770bc9d.rev differ diff --git a/pr-preview/pr-14/bare_pr_preview/packed-refs b/pr-preview/pr-14/bare_pr_preview/packed-refs new file mode 100644 index 0000000..eaafb17 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/packed-refs @@ -0,0 +1,2 @@ +# pack-refs with: peeled fully-peeled sorted +b3a95bc3cdbc27d8941e9b74c5c294c9c9fcb12b refs/tags/v1.4.3 diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v0.0.0 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v0.0.0 new file mode 100644 index 0000000..3479f93 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v0.0.0 @@ -0,0 +1 @@ +f5db5c92badaca355476a4831dd122195ab29956 diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v0.0.1 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v0.0.1 new file mode 100644 index 0000000..a32cc9f --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v0.0.1 @@ -0,0 +1 @@ +55df7d7c97c37ddfcad91d8da3700c1c80913ead diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v0.0.2 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v0.0.2 new file mode 100644 index 0000000..aa1f3b6 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v0.0.2 @@ -0,0 +1 @@ +30a02270046756a3e8bcad2923fddbfab73783be diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.0 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.0 new file mode 100644 index 0000000..fe87285 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.0 @@ -0,0 +1 @@ +fca13e940d9437bb975801f2c4005734ce2eefcb diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.0.0 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.0.0 new file mode 100644 index 0000000..fe87285 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.0.0 @@ -0,0 +1 @@ +fca13e940d9437bb975801f2c4005734ce2eefcb diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.1 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.1 new file mode 100644 index 0000000..9c4a279 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.1 @@ -0,0 +1 @@ +98706dff8eaffcef39fbd5c5cadd2c6339bbd60b diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.1.0 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.1.0 new file mode 100644 index 0000000..150c80b --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.1.0 @@ -0,0 +1 @@ +591779e70aba2ce461521af517b269dac0221c77 diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.1.1 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.1.1 new file mode 100644 index 0000000..9c4a279 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.1.1 @@ -0,0 +1 @@ +98706dff8eaffcef39fbd5c5cadd2c6339bbd60b diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.2 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.2 new file mode 100644 index 0000000..df966de --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.2 @@ -0,0 +1 @@ +eac2838daf487e8f054a4bc10dc957431cd6270b diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.2.0 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.2.0 new file mode 100644 index 0000000..df966de --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.2.0 @@ -0,0 +1 @@ +eac2838daf487e8f054a4bc10dc957431cd6270b diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3 new file mode 100644 index 0000000..6df7ed9 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3 @@ -0,0 +1 @@ +699c12bae12472ca7f43d0654858b16c3e60dab9 diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3.0 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3.0 new file mode 100644 index 0000000..0c5e425 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3.0 @@ -0,0 +1 @@ +9dac5c4777c535516ebf819f93aeadac70f66488 diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3.1 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3.1 new file mode 100644 index 0000000..4586fb1 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3.1 @@ -0,0 +1 @@ +2a652922e9b9c53e7e5ea62fa38da744de09043c diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3.2 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3.2 new file mode 100644 index 0000000..6df7ed9 --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.3.2 @@ -0,0 +1 @@ +699c12bae12472ca7f43d0654858b16c3e60dab9 diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.4.0 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.4.0 new file mode 100644 index 0000000..4d22dfe --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.4.0 @@ -0,0 +1 @@ +022361539c71c58a7141d4fe8c3e0e4a1c34f9c5 diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.4.1 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.4.1 new file mode 100644 index 0000000..90243ba --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.4.1 @@ -0,0 +1 @@ +60ad6fc41be190767f6c3cc5d87c0a4dc03e3022 diff --git a/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.4.2 b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.4.2 new file mode 100644 index 0000000..6c54f3c --- /dev/null +++ b/pr-preview/pr-14/bare_pr_preview/refs/tags/v1.4.2 @@ -0,0 +1 @@ +70d0e7a39b1712a874aeba33b936c6fdf795617a diff --git a/pr-preview/pr-14/css/index.css b/pr-preview/pr-14/css/index.css new file mode 100644 index 0000000..070ae9b --- /dev/null +++ b/pr-preview/pr-14/css/index.css @@ -0,0 +1,543 @@ +@font-face { + font-family: "Oswald-Regular"; + src: url("../font/Oswald-Regular.ttf"); +} + +@font-face { + font-family: "Oswald-Light"; + src: url("../font/Oswald-Light.ttf"); +} + +@font-face { + font-family: "OpenSans-Regular"; + src: url("../font/OpenSans-Regular.ttf"); +} + +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +html, +body { + width: 100%; + height: 100%; + -webkit-text-size-adjust: 100%; + /* Prevent font scaling in landscape while allowing user zoom */ + background-color: #2b2b2b; +} + +button { + border: none; + cursor: pointer; + color: #ffffff; + border: 0; +} + +img { + user-select: none; +} + +.home-page { + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + z-index: 1; + display: flex; + flex-direction: column; + justify-content: space-between; + align-items: center; + color: #ffffff; + background-color: #2b2b2b; + padding: 30px 0; + gap: 20px; +} + +.home-page .logo { + width: 112.5px; + height: 27px; +} + +.home-page .description { + width: 85%; + text-align: center; + background-color: #323234; + margin: 0 auto; + padding: 1rem 2rem 2rem; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); +} + +.home-page .description .title { + font-size: 26px; + font-family: Oswald-Regular; +} + +.home-page .description .content { + font-family: OpenSans-Regular; + font-size: 16px; + line-height: 26px; + margin: 1rem 0 1rem; +} + +.home-page .description .desktop-qr-container { + font-family: OpenSans-Regular; + background-color: #2b2b2b; + padding: 2rem; + border-radius: 8px; + display: flex; + flex-direction: column; + gap: 0.5rem; + justify-content: center; + align-items: center; +} + +.home-page .description .desktop-start-btn { + font-family: OpenSans-Regular; + background-color: #2b2b2b; + margin-top: 1rem; + padding: 2rem; + border-radius: 8px; + display: flex; + flex-direction: column; + align-items: start; + gap: 1rem; + text-align: start; +} + +.home-page .description .desktop-start-btn .start-btn { + display: flex; + width: 100%; +} + +.home-page .description .start-btn { + height: 6vh; + min-height: 40px; + max-height: 60px; + background-color: #fe8e14; + font-family: Oswald-Regular; + font-size: 16px; + margin: 0 auto; + display: none; + justify-content: center; + align-items: center; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + padding: 2rem; +} + +.home-page .description .start-btn:hover { + background-color: #fea543; +} + +.home-page .powered-by-msg { + font-size: 16px; + font-family: Oswald-Light; +} + +.scanner-container { + position: absolute; + width: 100%; + height: 100%; + display: none; +} + +.scanner-container .header { + width: 100%; + height: 46px; + background-color: rgb(55, 55, 55); + display: flex; + align-items: center; + gap: 15px; + position: relative; +} + +.scanner-container .header .camera-selector { + width: 70px; + height: 100%; + background-color: #000000; + display: flex; + justify-content: space-around; + align-items: center; + padding: 0 10px; + cursor: pointer; +} + +.scanner-container .header .camera-selector:hover { + opacity: 0.8; +} + +.scanner-container .header .camera-selector .camera-svg { + width: 28px; + height: 16px; +} + +.scanner-container .header .camera-selector .up { + display: none; +} + +.scanner-container .header .camera-list { + position: absolute; + top: 46px; + left: 0; + background-color: #000000; + z-index: 3; + display: none; + border-right: #aaaaaa; +} + +.scanner-container .header .camera-list .camera-item { + width: 100%; + height: 40px; + color: #aaaaaa; + border-bottom: 1px solid rgb(50, 50, 52); + font-size: 12px; + font-family: OpenSans-Regular; + line-height: 40px; + padding: 0 10px; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + user-select: none; + cursor: pointer; +} +.scanner-container .header .camera-list .camera-item:hover { + opacity: 0.8; +} + +.scanner-container .header .camera-list .camera-selected { + color: #fe8e14; +} + +.scanner-container .header .camera-list .camera-item:last-child { + border: unset; +} + +.scanner-container .header .music-container { + width: 30px; + height: 30px; + cursor: pointer; + display: flex; + align-items: center; + cursor: pointer; +} + +.scanner-container .header .music-container:hover { + opacity: 0.8; +} + +.scanner-container .header .music { + width: 24px; + height: 24px; +} + +.scanner-container .header .no-music { + width: 24px; + height: 24px; + display: none; +} + +.scanner-container .header .upload-image-btn { + width: 30px; + height: 30px; + cursor: pointer; + display: flex; + align-items: center; + cursor: pointer; +} + +.scanner-container .header .upload-image-icon { + width: 24px; + height: 24px; +} + +.scanner-container .header .upload-image-icon:hover { + opacity: 0.8; +} + +.result-container { + position: absolute; + width: 100%; + height: 100%; + display: none; + flex-direction: column; + justify-content: space-between; + background-color: #323234; + color: #ffffff; + font-family: "OpenSans-Regular"; + font-size: 16px; + z-index: 2; +} + +.result-container .result-header { + width: 100%; + height: 46px; + align-items: center; + position: relative; + background-color: #2b2b2b; + display: flex; + justify-content: space-between; + align-items: center; + gap: 15px; + padding-left: 30px; +} + +.result-container .result-header .result-title { + color: #aaaaaa; +} + +.result-container .scanned-image { + max-height: 200px; +} + +.result-container .scanned-image img, +.result-container .scanned-image canvas { + object-fit: contain; + width: 100%; + height: 100%; +} + +.result-container .parsed-result-area { + width: 100%; + height: 84%; + padding: 15px 15px 5px 30px; + overflow: auto; +} + +.result-container .parsed-result-area .parsed-filed { + display: flex; + flex-direction: column; + margin-bottom: 25px; +} + +.result-container .parsed-result-area .parsed-filed .field-name { + color: #aaaaaa; +} +.result-container .parsed-result-area .parsed-filed .field-value { + word-wrap: break-word; +} +.result-container .parsed-result-area .code .field-value { + font-family: monospace; +} + +.result-container .scan-again { + width: 100%; + height: 10%; + min-height: 60px; + max-height: 100px; + background-color: #2b2b2b; + display: flex; + justify-content: center; + align-items: center; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); +} + +.result-container .scan-again .btn-scan-again { + width: 160px; + height: 60%; + border: 0; + background-color: #fe8e14; + font-size: 20px; + color: #ffffff; + font-family: "Oswald-Regular"; +} + +.scan-mode-container { + display: none; + justify-content: center; + align-items: center; + position: fixed; + bottom: 15%; + left: 5%; + right: 5%; + z-index: 2; +} + +.scan-mode-container .scan-mode-content { + position: relative; + display: flex; + justify-content: center; + align-items: center; + background-color: rgb(34, 34, 34); + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + border-radius: 8px; + padding: 0.5rem; + width: max-content; + opacity: 0.8; +} + +.scan-option-btn { + background-color: transparent; + padding: 0.5rem; + font-family: OpenSans-Regular; + color: white; + flex: 1; + width: 5rem; +} + +.selected { + background-color: #fe8e14; + color: white; + border-radius: 8px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); +} + +#notification { + text-align: center; + text-align: center; + padding: 0.5rem; + width: -moz-fit-content; + width: fit-content; + position: absolute; + z-index: 3; + bottom: -200%; + left: 0; + right: 0; + margin-left: auto; + margin-right: auto; + font-family: Oswald-Light; + color: #fff; + + /* Fade in animation */ + opacity: 0; + display: none; + transition: opacity 300ms; +} + +.banner-default { + background-color: rgb(254, 142, 20, 0.4); + border: 1px solid #fe8e14; +} +.banner-error { + background-color: rgb(252, 2, 0, 0.4); + border: 1px solid #fc0200; +} +.banner-success { + background-color: rgb(124, 252, 0, 0.4); + border: 1px solid #00fc15; +} + +.information-btn { + display: flex; + justify-content: center; + align-items: center; + margin-left: auto; + margin-right: 1rem; + font-family: Oswald-Regular; + text-decoration: none; + cursor: pointer; +} + +.information-btn:hover { + opacity: 0.8; +} + +.scanner-container .header .information-list { + position: absolute; + top: 54px; /* Header height 46px + triangle 8px*/ + right: 0; + background-color: #000000; + z-index: 3; + display: none; + border-right: #aaaaaa; +} + +/* Tooltip Triangle */ +.scanner-container .header .information-list::after { + content: ""; + position: absolute; + top: -16px; /* At the top of the information list */ + right: calc(1rem + 8px); /* 1rem margin + center of icon 8px */ + /* margin-left: -5px; */ + border-width: 8px; + border-style: solid; + border-color: transparent transparent #2b2b2b transparent; /* triangle */ +} + +.scanner-container .header .information-list .information-item { + width: 100%; + border-bottom: 1px solid rgb(55, 55, 55); + padding: 10px; + cursor: pointer; + background-color: #2b2b2b; + display: flex; + align-items: center; + gap: 5px; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + user-select: none; + color: #aaaaaa; + font-size: 12px; + font-family: OpenSans-Regular; + text-decoration: none; +} + +.scanner-container .header .information-list .information-item:hover { + opacity: 0.8; +} + +.scanner-container .header .information-list .information-item:last-child { + border: unset; +} + +.dbr-download-code-icon { + width: 16px; + height: 16px; + stroke: #ffae38; + margin-left: 5px; +} + +@keyframes dce-rotate { + from { + transform: rotate(0turn); + } + + to { + transform: rotate(1turn); + } +} + +@keyframes dce-scanlight { + from { + top: 0; + } + + to { + top: 97%; + } +} + +@media screen and (max-width: 800px) { + html, + body, + .home-page { + background-color: #323234; + } + + .home-page .description { + width: 80%; + box-shadow: none; + } + + .home-page .description .desktop-qr-container { + display: none; + } + + .home-page .description .desktop-start-btn { + display: none; + } + + .home-page .description .start-btn { + display: flex; + font-size: 20px; + padding: 1.5rem; + } +} + +@media screen and (max-width: 800px) and (orientation: landscape) { + .result-container .parsed-result-area .parsed-filed { + font-size: 14px; + } +} diff --git a/pr-preview/pr-14/font/OpenSans-Regular.ttf b/pr-preview/pr-14/font/OpenSans-Regular.ttf new file mode 100644 index 0000000..4288698 Binary files /dev/null and b/pr-preview/pr-14/font/OpenSans-Regular.ttf differ diff --git a/pr-preview/pr-14/font/Oswald-Light.ttf b/pr-preview/pr-14/font/Oswald-Light.ttf new file mode 100644 index 0000000..dcfaa60 Binary files /dev/null and b/pr-preview/pr-14/font/Oswald-Light.ttf differ diff --git a/pr-preview/pr-14/font/Oswald-Regular.ttf b/pr-preview/pr-14/font/Oswald-Regular.ttf new file mode 100644 index 0000000..2492c44 Binary files /dev/null and b/pr-preview/pr-14/font/Oswald-Regular.ttf differ diff --git a/pr-preview/pr-14/index.html b/pr-preview/pr-14/index.html new file mode 100644 index 0000000..0d300df --- /dev/null +++ b/pr-preview/pr-14/index.html @@ -0,0 +1,413 @@ + + + + + + Dynamsoft MRZ Scanner for Web + + + + + + +
+ +
+
Dynamsoft MRZ Scanner
+
+ Dynamsoft MRZ Scanner recognizes the Machine-Readable Zone (MRZ) on a passport or ID card and converts the + encoded strings into human-readable fields +
+
+ https://demo.dynamsoft.com/solutions/mrz-scanner/ +

Scan to Open on Mobile

+

+ For optimal performance, scan this QR code to open the scanner on your mobile device +

+
+
+

Quick Start Options

+ +

+ Note: Desktop cameras may have limited performance. Mobile scanning is recommended for best results. +

+
+ +
+
Powered by Dynamsoft
+
+
+
+
+ + + + + + + + + + + down + up +
+
+ +
+ upload-image +
+
+ music + no-music +
+
+ + + + + + +
+ + +
+
+ + + + + + +
+
+ mrz-guide +
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
Scan Results
+ +
+ + + + + + +
+
+
+
+
+ +
+
+
+
+ + + +
+
+ + + + + diff --git a/pr-preview/pr-14/js/const.js b/pr-preview/pr-14/js/const.js new file mode 100644 index 0000000..bf96991 --- /dev/null +++ b/pr-preview/pr-14/js/const.js @@ -0,0 +1,59 @@ +// Define some global variables that will be used +let cameraList = []; +let cameraView = null; +let cameraEnhancer = null; +let cvRouter = null; +let pInit = null; // Promise of init +let isSoundOn = true; +let timer = null; + +const SCAN_MODES = ["id", "passport", "both"]; +const SCAN_TEMPLATES = { + id: "ReadId", + passport: "ReadPassport", + both: "ReadPassportAndId", +}; +let currentMode = SCAN_MODES[2]; // Set scan mode as "Scan Both" by default + +const resolutions = { + "Full HD": [1920, 1080], // Full HD + HD: [1280, 720], // HD +}; + +// Aspect Ratio of MRZ Guide Box +const MRZ_GUIDEBOX_ASPECT_RATIO = 6.73; + +// Get the UI element +const homePage = document.querySelector(".home-page"); + +const cameraViewContainer = document.querySelector(".camera-view-container"); + +const uploadImageInput = document.querySelector(".upload-image-input"); + +const cameraListContainer = document.querySelector(".camera-list"); +const cameraSelector = document.querySelector(".camera-selector"); + +const informationBtn = document.querySelectorAll(".information-btn"); +const informationListContainer = document.querySelector(".information-list"); + +const scannerContainer = document.querySelector(".scanner-container"); + +const mrzGuideFrame = document.querySelector(".mrz-frame"); + +const resultContainer = document.querySelector(".result-container"); +const scannedImage = document.querySelector(".scanned-image"); +const parsedResultArea = document.querySelector(".parsed-result-area"); + +const startScaningBtn = document.querySelectorAll(".start-btn"); + +const scanModeContainer = document.querySelector(".scan-mode-container"); +const scanBothBtn = document.querySelector("#scan-both-btn"); + +const scanAgainBtn = document.querySelector(".btn-scan-again"); + +const playSoundBtn = document.querySelector(".music"); +const closeSoundBtn = document.querySelector(".no-music"); +const down = document.querySelector(".down"); +const up = document.querySelector(".up"); + +const notification = document.querySelector("#notification"); diff --git a/pr-preview/pr-14/js/index.js b/pr-preview/pr-14/js/index.js new file mode 100644 index 0000000..ad166f0 --- /dev/null +++ b/pr-preview/pr-14/js/index.js @@ -0,0 +1,194 @@ +import { handleCapturedResult, init, pDataLoad } from "./init.js"; +import { judgeCurResolution, shouldShowScanModeContainer, showNotification } from "./util.js"; +import { checkOrientation, getVisibleRegionOfVideo } from "./util.js"; + +async function startCapturing(mode) { + try { + homePage.style.display = "none"; + scannerContainer.style.display = "block"; + + // Open the camera after the model and .wasm files have loaded + pInit = pInit || (await init); + await pDataLoad.promise; + + // Starts streaming the video + if (cameraEnhancer.isOpen()) { + await cvRouter.stopCapturing(); + await cameraView.clearAllInnerDrawingItems(); + } else { + await cameraEnhancer.open(); + } + + // Highlight the selected camera in the camera list container + const currentCamera = cameraEnhancer.getSelectedCamera(); + const currentResolution = judgeCurResolution(cameraEnhancer.getResolution()); + cameraListContainer.childNodes.forEach((child) => { + if (currentCamera.deviceId === child.deviceId && currentResolution === child.resolution) { + child.className = "camera-item camera-selected"; + } + }); + cameraEnhancer.setScanRegion(region()); + cameraView.setScanRegionMaskVisible(false); + + await cvRouter.startCapturing(SCAN_TEMPLATES[mode]); + + // Show MRZ guide frame + mrzGuideFrame.style.display = "inline-block"; + + // Update button styles to show selected scan mode + document.querySelectorAll(".scan-option-btn").forEach((button) => { + button.classList.remove("selected"); + }); + document.querySelector(`#scan-${mode}-btn`).classList.add("selected"); + showNotification(`Scan mode switched successfully`, "banner-success"); + + currentMode = mode; + scanModeContainer.style.display = "flex"; + } catch (ex) { + let errMsg = ex.message || ex; + console.error(`An error occurred: ${errMsg}`); + alert(`An error occurred: ${errMsg}`); + } +} + +SCAN_MODES.forEach((mode) => + document.querySelector(`#scan-${mode}-btn`).addEventListener("click", () => startCapturing(mode)) +); + +// -----------Logic for calculating scan region ↓------------ +const regionLeft = () => { + if (!cameraEnhancer || !cameraEnhancer.isOpen()) return 0; + const visibleRegionInPixels = getVisibleRegionOfVideo(); + const currentResolution = cameraEnhancer.getResolution(); + + const vw = + checkOrientation() === "portrait" + ? Math.min(currentResolution.width, currentResolution.height) + : Math.max(currentResolution.width, currentResolution.height); + const visibleRegionWidth = visibleRegionInPixels.width; + + let regionCssW; + if (document.body.clientWidth > document.body.clientHeight * MRZ_GUIDEBOX_ASPECT_RATIO) { + let regionCssH = document.body.clientHeight * 0.75; + regionCssW = regionCssH * MRZ_GUIDEBOX_ASPECT_RATIO; + } else { + regionCssW = document.body.clientWidth * 0.9; + } + regionCssW = Math.min(regionCssW, 600); + + const regionWidthInPixel = (visibleRegionWidth / document.body.clientWidth) * regionCssW; + const left = ((vw - regionWidthInPixel) / 2 / vw) * 100; + + return Math.round(left); +}; + +const regionTop = () => { + if (!cameraEnhancer || !cameraEnhancer.isOpen()) return 0; + + const currentResolution = cameraEnhancer.getResolution(); + + const vw = + checkOrientation() === "portrait" + ? Math.min(currentResolution.width, currentResolution.height) + : Math.max(currentResolution.width, currentResolution.height); + const vh = + checkOrientation() === "portrait" + ? Math.max(currentResolution.width, currentResolution.height) + : Math.min(currentResolution.width, currentResolution.height); + + const regionWidthInPixel = vw - (regionLeft() * 2 * vw) / 100; + const regionHeightInPixel = regionWidthInPixel / 4; + const top = ((vh - regionHeightInPixel) / 2 / vh) * 100; + return Math.round(top); +}; + +const region = () => { + let region = { + left: regionLeft(), + right: 100 - regionLeft(), + top: regionTop(), + bottom: 100 - regionTop(), + isMeasuredInPercentage: true, + }; + return region; +}; +// -----------Logic for calculating scan region ↑------------ + +window.addEventListener("click", () => { + cameraListContainer.style.display = "none"; + up.style.display = "none"; + down.style.display = "inline-block"; + informationListContainer.style.display = "none"; +}); + +// Recalculate the scan region when the window size changes +window.addEventListener("resize", () => { + mrzGuideFrame.style.display = "none"; + timer && clearTimeout(timer); + timer = setTimeout(() => { + shouldShowScanModeContainer(); + mrzGuideFrame.style.display = "inline-block"; + cameraEnhancer?.setScanRegion(region()); + cameraView?.setScanRegionMaskVisible(false); + }, 500); +}); + +// Add click events to buttons +startScaningBtn.forEach((btn) => btn.addEventListener("click", () => scanBothBtn.click())); +const restartVideo = async () => { + resultContainer.style.display = "none"; + document.querySelector(`#scan-${currentMode}-btn`).click(); +}; +scanAgainBtn.addEventListener("click", restartVideo); + +uploadImageInput.addEventListener("change", async (event) => { + try { + const file = event.target.files[0]; + + if (file) { + // Open the camera after the model and .wasm files have loaded + pInit = pInit || (await init); + await pDataLoad.promise; + + event.target.value = ""; + + // Decode selected image with 'both' template. + const result = await cvRouter.capture(file, SCAN_TEMPLATES.both); + handleCapturedResult(result, file); + } + } catch (ex) { + let errMsg = ex.message || ex; + alert(errMsg); + console.error(errMsg); + } +}); + +cameraSelector.addEventListener("click", (e) => { + e.stopPropagation(); + const isShow = cameraListContainer.style.display === "block"; + cameraListContainer.style.display = isShow ? "none" : "block"; + up.style.display = !isShow ? "inline-block" : "none"; + down.style.display = isShow ? "inline-block" : "none"; +}); + +playSoundBtn.addEventListener("click", () => { + playSoundBtn.style.display = "none"; + closeSoundBtn.style.display = "block"; + showNotification("Sound feedback off", "banner-default"); + isSoundOn = false; +}); + +closeSoundBtn.addEventListener("click", () => { + playSoundBtn.style.display = "block"; + closeSoundBtn.style.display = "none"; + showNotification("Sound feedback on", "banner-default"); + isSoundOn = true; +}); + +informationBtn.forEach((infoBtn) => + infoBtn.addEventListener("click", (e) => { + e.stopPropagation(); + const isShow = informationListContainer.style.display === "block"; + informationListContainer.style.display = isShow ? "none" : "block"; + }) +); diff --git a/pr-preview/pr-14/js/init.js b/pr-preview/pr-14/js/init.js new file mode 100644 index 0000000..d80f545 --- /dev/null +++ b/pr-preview/pr-14/js/init.js @@ -0,0 +1,167 @@ +import { judgeCurResolution, showNotification } from "./util.js"; +import { createPendingPromise, extractDocumentFields, resultToHTMLElement, formatMRZ } from "./util.js"; + +// Promise variable used to control model loading state +const pDataLoad = createPendingPromise(); + +/** LICENSE ALERT - README + * To use the library, you need to first specify a license key using the API "initLicense" as shown below. + */ +Dynamsoft.License.LicenseManager.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); +/** + * You can visit https://www.dynamsoft.com/customer/license/trialLicense/?product=mrz&utm_source=docs&package=js to get your own trial license good for 30 days. + * Note that if you downloaded this sample from Dynamsoft while logged in, the above license key may already be your own 30-day trial license. + * For more information, see https://www.dynamsoft.com/label-recognition/programming/javascript/user-guide.html?ver=latest#specify-the-license or contact support@dynamsoft.com. + * LICENSE ALERT - THE END + */ + +Dynamsoft.DLR.LabelRecognizerModule.onDataLoadProgressChanged = (modelPath, tag, progress) => { + if (tag === "completed") { + pDataLoad.resolve(); + } +}; + +/** + * Preloads the resources + */ +Dynamsoft.Core.CoreModule.loadWasm(["DLR", "DCP"]); +Dynamsoft.DCP.CodeParserModule.loadSpec("MRTD_TD3_PASSPORT"); +Dynamsoft.DCP.CodeParserModule.loadSpec("MRTD_TD1_ID"); +Dynamsoft.DCP.CodeParserModule.loadSpec("MRTD_TD2_ID"); +Dynamsoft.DLR.LabelRecognizerModule.loadRecognitionData("MRZ"); + +/** + * Creates a CameraEnhancer instance as the image source + */ +async function initDCE() { + cameraView = await Dynamsoft.DCE.CameraView.createInstance(cameraViewContainer); + cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView); + + // Get the camera information of the device and render the camera list + cameraList = await cameraEnhancer.getAllCameras(); + for (let camera of cameraList) { + for (let res of Object.keys(resolutions)) { + const cameraItem = document.createElement("div"); + cameraItem.className = "camera-item"; + cameraItem.innerText = `${camera.label} (${res})`; + cameraItem.deviceId = camera.deviceId; + cameraItem.resolution = res; + + cameraItem.addEventListener("click", async (e) => { + e.stopPropagation(); + for (let child of cameraListContainer.childNodes) { + child.className = "camera-item"; + } + cameraItem.className = "camera-item camera-selected"; + await cameraEnhancer.selectCamera(camera); + await cameraEnhancer.setResolution({ + width: resolutions[res][0], + height: resolutions[res][1], + }); + + const currentCamera = await cameraEnhancer.getSelectedCamera(); + const currentResolution = judgeCurResolution(await cameraEnhancer.getResolution()); + if (currentCamera.deviceId === camera.deviceId && currentResolution === res) { + showNotification("Camera and resolution switched successfully!", "banner-success"); + } else if (judgeCurResolution(currentResolution) !== res) { + showNotification(`Resolution switch failed! ${res} is not supported.`, "banner-default"); + + // Update resolution to the current resolution that is supported + for (let child of cameraListContainer.childNodes) { + child.className = "camera-item"; + if (currentCamera.deviceId === child.deviceId && currentResolution === child.resolution) { + child.className = "camera-item camera-selected"; + } + } + } else { + showNotification(`Camera switch failed!`, "banner-error"); + } + + // Hide options after user clicks an option + cameraSelector.click(); + }); + cameraListContainer.appendChild(cameraItem); + } + } + cameraView.setVideoFit("cover"); + await cameraEnhancer.setResolution({ width: 1920, height: 1080 }); +} + +/** + * Initialize CaptureVisionRouter, CameraEnhancer, and CameraView instance + */ +let init = (async () => { + await initDCE(); + cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance(); + await cvRouter.initSettings("./template.json"); + cvRouter.setInput(cameraEnhancer); + + /* Defines the result receiver for the solution.*/ + const resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver(); + resultReceiver.onCapturedResultReceived = handleCapturedResult; + + await cvRouter.addResultReceiver(resultReceiver); +})(); + +export const handleCapturedResult = (result, uploadedImage = null) => { + const recognizedResults = result.textLineResultItems; + const parsedResults = result.parsedResultItems; + const originalImage = result.items?.[0]?.imageData; + + if (recognizedResults?.length) { + // Play sound feedback if enabled + isSoundOn ? Dynamsoft.DCE.Feedback.beep() : null; + + parsedResultArea.innerText = ""; + + // Add MRZ Text to Result + const mrzElement = resultToHTMLElement("MRZ String", formatMRZ(recognizedResults[0]?.text)); + mrzElement.classList.add("code"); + parsedResultArea.appendChild(mrzElement); + + // If a parsed result is obtained, use it to render the result page + if (parsedResults) { + const parseResultInfo = extractDocumentFields(parsedResults[0]); + Object.entries(parseResultInfo).map(([field, value]) => { + const resultElement = resultToHTMLElement(field, value); + parsedResultArea.appendChild(resultElement); + }); + + if (uploadedImage && uploadedImage.type.startsWith("image/")) { + handleUploadedImage(uploadedImage); + } else if (originalImage) { + scannedImage.innerHTML = ""; + scannedImage.append(originalImage.toCanvas()); + } + } else { + alert(`Failed to parse the content.`); + parsedResultArea.style.justifyContent = "flex-start"; + } + resultContainer.style.display = "flex"; + cameraListContainer.style.display = "none"; + informationListContainer.style.display = "none"; + scanModeContainer.style.display = "none"; + + cameraEnhancer.close(); + cvRouter.stopCapturing(); + cameraView.clearAllInnerDrawingItems(); + } +}; + +function handleUploadedImage(file) { + const img = document.createElement("img"); + const imageUrl = URL.createObjectURL(file); + + img.src = imageUrl; + img.className = "uploaded-image"; + + // Append the image to the div + scannedImage.innerHTMl = ""; + scannedImage.append(img); + + img.onload = () => { + URL.revokeObjectURL(imageUrl); + }; +} + +export { pDataLoad, init }; diff --git a/pr-preview/pr-14/js/util.js b/pr-preview/pr-14/js/util.js new file mode 100644 index 0000000..403fe2d --- /dev/null +++ b/pr-preview/pr-14/js/util.js @@ -0,0 +1,201 @@ +/** + * Creates a pending promise. Used to keep track of library loading progress + * + * @returns {Object} An object containing the promise, resolve, and reject functions. + */ +export function createPendingPromise() { + let resolve, reject; + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); + + return { promise, resolve, reject }; +} + +/** + * Extracts and returns document fields from the parsed MRZ result + * + * @param {Object} result - The parsed result object containing document fields. + * @returns {Object} An object with key-value pairs of the extracted fields. + */ +export function extractDocumentFields(result) { + const parseResultInfo = {}; + if (!result.exception) { + const type = result.getFieldValue("documentCode"); + const documentType = JSON.parse(result.jsonString).CodeType; + const birthYear = result.getFieldValue("birthYear"); + const birthYearBase = parseInt(birthYear) > new Date().getFullYear() % 100 ? "19" : "20"; + const fullBirthYear = `${birthYearBase}${birthYear}`; + + const expiryYear = result.getFieldValue("expiryYear"); + const expiryYearBase = parseInt(expiryYear) >= 60 ? "19" : "20"; + const fullExpiryYear = `${expiryYearBase}${expiryYear}`; + + parseResultInfo["Document Type"] = documentType; + parseResultInfo["Surname"] = result.getFieldValue("primaryIdentifier"); + parseResultInfo["Given Name"] = result.getFieldValue("secondaryIdentifier"); + parseResultInfo["Nationality"] = result.getFieldValue("nationality"); + parseResultInfo["Document Number"] = + type === "P" ? result.getFieldValue("passportNumber") : result.getFieldValue("documentNumber"); + parseResultInfo["Issuing State"] = result.getFieldValue("issuingState"); + parseResultInfo["Sex"] = result.getFieldValue("sex"); + parseResultInfo["Date of Birth (YYYY-MM-DD)"] = + fullBirthYear + "-" + result.getFieldValue("birthMonth") + "-" + result.getFieldValue("birthDay"); + parseResultInfo["Date of Expiry (YYYY-MM-DD)"] = + fullExpiryYear + "-" + result.getFieldValue("expiryMonth") + "-" + result.getFieldValue("expiryDay"); + } + return parseResultInfo; +} + +/** + * Checks and returns the current screen orientation. + * + * @returns {string} The current screen orientation ('portrait' or 'landscape'). + */ +export function checkOrientation() { + if (window.matchMedia("(orientation: portrait)").matches) { + return "portrait"; + } else if (window.matchMedia("(orientation: landscape)").matches) { + return "landscape"; + } +} + +export function getVisibleRegionOfVideo() { + if (!cameraView || !cameraView.getVideoElement()) return; + const video = cameraView.getVideoElement(); + const { videoWidth, videoHeight } = video; + const objectFit = cameraView.getVideoFit(); + + // Adjust dimensions based on orientation + const isPortrait = checkOrientation() === "portrait"; + const width = isPortrait ? Math.min(videoWidth, videoHeight) : Math.max(videoWidth, videoHeight); + const height = isPortrait ? Math.max(videoWidth, videoHeight) : Math.min(videoWidth, videoHeight); + + // Get the CSS dimensions of the video element + const { width: videoCSSWidth, height: videoCSSHeight } = cameraView._innerComponent.getBoundingClientRect(); + if (videoCSSWidth <= 0 || videoCSSHeight <= 0) { + throw new Error(`Unable to get video dimensions. Video may not be rendered on the page.`); + } + + const videoCSSWHRatio = videoCSSWidth / videoCSSHeight, + videoWHRatio = width / height; + let cssScaleRatio; + + // Set visible region in pixels + const regionInPixels = { + x: 0, + y: 0, + width: width, + height: height, + isMeasuredInPercentage: false, + }; + + if (objectFit === "cover") { + if (videoCSSWHRatio < videoWHRatio) { + // a part of length is invisible + cssScaleRatio = videoCSSHeight / height; + regionInPixels.x = Math.floor((width - videoCSSWidth / cssScaleRatio) / 2); + regionInPixels.y = 0; + regionInPixels.width = Math.ceil(videoCSSWidth / cssScaleRatio); + regionInPixels.height = height; + } else { + // a part of height is invisible + cssScaleRatio = videoCSSWidth / width; + regionInPixels.x = 0; + regionInPixels.y = Math.floor((height - videoCSSHeight / cssScaleRatio) / 2); + regionInPixels.width = width; + regionInPixels.height = Math.ceil(videoCSSHeight / cssScaleRatio); + } + } + return regionInPixels; +} + +/** + * Create an HTML paragraph element containing the document field name and value. + * + * @param {string} field - The document field name. + * @param {string} value - The document field value. + * @returns {HTMLElement} The paragraph element containing the formatted document field name and value. + */ +export function resultToHTMLElement(field, value) { + const p = document.createElement("p"); + p.className = "parsed-filed"; + const spanFieldName = document.createElement("span"); + spanFieldName.className = "field-name"; + const spanValue = document.createElement("span"); + spanValue.className = "field-value"; + + spanFieldName.innerText = `${field} : `; + spanValue.innerText = `${value || "Not detected"}`; + + p.appendChild(spanFieldName); + p.appendChild(spanValue); + + return p; +} + +/** + * Formats a Machine Readable Zone (MRZ) string by adding line breaks based on its length. + * + * @param {string} [mrzString=""] - The MRZ string to format. + * @returns {string} The formatted MRZ string with appropriate line breaks or the original string + */ +export function formatMRZ(mrzString = "") { + let formattedMRZ = mrzString; + + // Check if the length matches any known MRZ format + if (mrzString.length === 88) { + // Passport (TD3 format) + formattedMRZ = mrzString.slice(0, 44) + "\n" + mrzString.slice(44); + } else if (mrzString.length === 90) { + // ID card (TD1 format) + formattedMRZ = mrzString.slice(0, 30) + "\n" + mrzString.slice(30, 60) + "\n" + mrzString.slice(60); + } else if (mrzString.length === 72) { + // Visa (TD2 format) + formattedMRZ = mrzString.slice(0, 36) + "\n" + mrzString.slice(36); + } + + return formattedMRZ; +} + +/** Check if current resolution is Full HD or HD + * @params {Object} currentResolution - an object with `width` and `height` to represent the current resolution of the camera + * @returns {string} Either "HD" or "Full HD" depending of the resolution of the screen + */ +export const judgeCurResolution = (currentResolution) => { + const width = currentResolution?.width ?? 0; + const height = currentResolution?.height ?? 0; + const minValue = Math.min(width, height); + const maxValue = Math.max(width, height); + if (minValue >= 480 && minValue <= 960 && maxValue >= 960 && maxValue <= 1440) { + return "HD"; + } else if (minValue >= 900 && minValue <= 1440 && maxValue >= 1400 && maxValue <= 2160) { + return "Full HD"; + } +}; + +/** + * Checks if we should show the switch scan mode buttons + * @returns true if cameraEnhancer is open, false otherwise + */ +export function shouldShowScanModeContainer() { + const isHomepageClosed = homePage.style.display === "none"; + const isResultClosed = resultContainer.style.display === "none" || resultContainer.style.display === ""; + scanModeContainer.style.display = isHomepageClosed && isResultClosed ? "flex" : "none"; +} + +/** Show notification banner to users + * @params {string} message - noficiation message + * @params {string} className - CSS class name to show notification status + */ +export function showNotification(message, className) { + notification.className = className; + notification.innerText = message; + notification.style.display = "block"; + notification.style.opacity = 1; + setTimeout(() => { + notification.style.opacity = 0; + notification.style.display = "none"; + }, 2000); +} diff --git a/pr-preview/pr-14/template.json b/pr-preview/pr-14/template.json new file mode 100644 index 0000000..b2ac8fb --- /dev/null +++ b/pr-preview/pr-14/template.json @@ -0,0 +1,257 @@ +{ + "CaptureVisionTemplates": [ + { + "Name": "ReadPassportAndId", + "OutputOriginalImage": 1, + "ImageROIProcessingNameArray": ["roi-passport-and-id"], + "SemanticProcessingNameArray": ["sp-passport-and-id"], + "Timeout": 2000 + }, + { + "Name": "ReadPassport", + "OutputOriginalImage": 1, + "ImageROIProcessingNameArray": ["roi-passport"], + "SemanticProcessingNameArray": ["sp-passport"], + "Timeout": 2000 + }, + { + "Name": "ReadId", + "OutputOriginalImage": 1, + "ImageROIProcessingNameArray": ["roi-id"], + "SemanticProcessingNameArray": ["sp-id"], + "Timeout": 2000 + } + ], + "TargetROIDefOptions": [ + { + "Name": "roi-passport-and-id", + "TaskSettingNameArray": ["task-passport-and-id"] + }, + { + "Name": "roi-passport", + "TaskSettingNameArray": ["task-passport"] + }, + { + "Name": "roi-id", + "TaskSettingNameArray": ["task-id"] + } + ], + "TextLineSpecificationOptions": [ + { + "Name": "tls_mrz_passport", + "BaseTextLineSpecificationName": "tls_base", + "StringLengthRange": [44, 44], + "OutputResults": 1, + "ExpectedGroupsCount": 1, + "ConcatResults": 1, + "ConcatSeparator": "\n", + "SubGroups": [ + { + "StringRegExPattern": "(P[A-Z<][A-Z<]{3}[A-Z<]{39}){(44)}", + "StringLengthRange": [44, 44], + "BaseTextLineSpecificationName": "tls_base" + }, + { + "StringRegExPattern": "([A-Z0-9<]{9}[0-9][A-Z<]{3}[0-9]{2}[0-9<]{4}[0-9][MF<][0-9]{2}[(01-12)][(01-31)][0-9][A-Z0-9<]{14}[0-9<][0-9]){(44)}", + "StringLengthRange": [44, 44], + "BaseTextLineSpecificationName": "tls_base" + } + ] + }, + { + "Name": "tls_mrz_id_td2", + "BaseTextLineSpecificationName": "tls_base", + "StringLengthRange": [36, 36], + "OutputResults": 1, + "ExpectedGroupsCount": 1, + "ConcatResults": 1, + "ConcatSeparator": "\n", + "SubGroups": [ + { + "StringRegExPattern": "([ACI][A-Z<][A-Z<]{3}[A-Z<]{31}){(36)}", + "StringLengthRange": [36, 36], + "BaseTextLineSpecificationName": "tls_base" + }, + { + "StringRegExPattern": "([A-Z0-9<]{9}[0-9][A-Z<]{3}[0-9]{2}[0-9<]{4}[0-9][MF<][0-9]{2}[(01-12)][(01-31)][0-9][A-Z0-9<]{8}){(36)}", + "StringLengthRange": [36, 36], + "BaseTextLineSpecificationName": "tls_base" + } + ] + }, + { + "Name": "tls_mrz_id_td1", + "BaseTextLineSpecificationName": "tls_base", + "StringLengthRange": [30, 30], + "OutputResults": 1, + "ExpectedGroupsCount": 1, + "ConcatResults": 1, + "ConcatSeparator": "\n", + "SubGroups": [ + { + "StringRegExPattern": "([ACI][A-Z<][A-Z<]{3}[A-Z0-9<]{9}[0-9<][A-Z0-9<]{15}){(30)}", + "StringLengthRange": [30, 30], + "BaseTextLineSpecificationName": "tls_base" + }, + { + "StringRegExPattern": "([0-9]{2}[(01-12)][(01-31)][0-9][MF<][0-9]{2}[0-9<]{4}[0-9][A-Z<]{3}[A-Z0-9<]{11}[0-9]){(30)}", + "StringLengthRange": [30, 30], + "BaseTextLineSpecificationName": "tls_base" + }, + { + "StringRegExPattern": "([A-Z<]{30}){(30)}", + "StringLengthRange": [30, 30], + "BaseTextLineSpecificationName": "tls_base" + } + ] + }, + { + "Name": "tls_base", + "CharacterModelName": "MRZ", + "CharHeightRange": [5, 1000, 1], + "BinarizationModes": [ + { + "BlockSizeX": 30, + "BlockSizeY": 30, + "Mode": "BM_LOCAL_BLOCK", + "EnableFillBinaryVacancy": 0, + "ThresholdCompensation": 15 + } + ], + "ConfusableCharactersCorrection": { + "ConfusableCharacters": [ + ["0", "O"], + ["1", "I"], + ["5", "S"] + ], + "FontNameArray": ["OCR_B"] + } + } + ], + "LabelRecognizerTaskSettingOptions": [ + { + "Name": "task-passport", + "ConfusableCharactersPath": "ConfusableChars.data", + "TextLineSpecificationNameArray": ["tls_mrz_passport"], + "SectionImageParameterArray": [ + { + "Section": "ST_REGION_PREDETECTION", + "ImageParameterName": "ip-mrz" + }, + { + "Section": "ST_TEXT_LINE_LOCALIZATION", + "ImageParameterName": "ip-mrz" + }, + { + "Section": "ST_TEXT_LINE_RECOGNITION", + "ImageParameterName": "ip-mrz" + } + ] + }, + { + "Name": "task-id", + "ConfusableCharactersPath": "ConfusableChars.data", + "TextLineSpecificationNameArray": ["tls_mrz_id_td1", "tls_mrz_id_td2"], + "SectionImageParameterArray": [ + { + "Section": "ST_REGION_PREDETECTION", + "ImageParameterName": "ip-mrz" + }, + { + "Section": "ST_TEXT_LINE_LOCALIZATION", + "ImageParameterName": "ip-mrz" + }, + { + "Section": "ST_TEXT_LINE_RECOGNITION", + "ImageParameterName": "ip-mrz" + } + ] + }, + { + "Name": "task-passport-and-id", + "ConfusableCharactersPath": "ConfusableChars.data", + "TextLineSpecificationNameArray": ["tls_mrz_passport", "tls_mrz_id_td1", "tls_mrz_id_td2"], + "SectionImageParameterArray": [ + { + "Section": "ST_REGION_PREDETECTION", + "ImageParameterName": "ip-mrz" + }, + { + "Section": "ST_TEXT_LINE_LOCALIZATION", + "ImageParameterName": "ip-mrz" + }, + { + "Section": "ST_TEXT_LINE_RECOGNITION", + "ImageParameterName": "ip-mrz" + } + ] + } + ], + "CharacterModelOptions": [ + { + "DirectoryPath": "", + "Name": "MRZ" + } + ], + "ImageParameterOptions": [ + { + "Name": "ip-mrz", + "TextureDetectionModes": [ + { + "Mode": "TDM_GENERAL_WIDTH_CONCENTRATION", + "Sensitivity": 8 + } + ], + "BinarizationModes": [ + { + "EnableFillBinaryVacancy": 0, + "ThresholdCompensation": 21, + "Mode": "BM_LOCAL_BLOCK" + } + ], + "TextDetectionMode": { + "Mode": "TTDM_LINE", + "CharHeightRange": [5, 1000, 1], + "Direction": "HORIZONTAL", + "Sensitivity": 7 + } + } + ], + "SemanticProcessingOptions": [ + { + "Name": "sp-passport-and-id", + "ReferenceObjectFilter": { + "ReferenceTargetROIDefNameArray": ["roi-passport-and-id"] + }, + "TaskSettingNameArray": ["dcp-passport-and-id"] + }, + { + "Name": "sp-passport", + "ReferenceObjectFilter": { + "ReferenceTargetROIDefNameArray": ["roi-passport"] + }, + "TaskSettingNameArray": ["dcp-passport"] + }, + { + "Name": "sp-id", + "ReferenceObjectFilter": { + "ReferenceTargetROIDefNameArray": ["roi-id"] + }, + "TaskSettingNameArray": ["dcp-id"] + } + ], + "CodeParserTaskSettingOptions": [ + { + "Name": "dcp-passport", + "CodeSpecifications": ["MRTD_TD3_PASSPORT"] + }, + { + "Name": "dcp-id", + "CodeSpecifications": ["MRTD_TD1_ID", "MRTD_TD2_ID"] + }, + { + "Name": "dcp-passport-and-id", + "CodeSpecifications": ["MRTD_TD3_PASSPORT", "MRTD_TD1_ID", "MRTD_TD2_ID"] + } + ] +}