]> BookStack Code Mirror - website/commitdiff
Started playing with webidx based search
authorDan Brown <redacted>
Wed, 24 Jan 2024 21:59:33 +0000 (21:59 +0000)
committerDan Brown <redacted>
Wed, 24 Jan 2024 21:59:33 +0000 (21:59 +0000)
.gitignore
LICENSE
package.json
search/webidx.pl [new file with mode: 0644]
themes/bookstack/layouts/about/single.html
themes/bookstack/layouts/hacks/single.html
themes/bookstack/layouts/partials/footer.html
themes/bookstack/layouts/partials/header.html
themes/bookstack/static/libs/photoswipe.min.js
themes/bookstack/static/libs/sql-wasm.js [new file with mode: 0644]
themes/bookstack/static/libs/webidx.js [new file with mode: 0644]

index 6ba3c98b65c5b2f666535667e4d2dbfa4d5a84f2..9b97e9691e1ab2c8a4b6594e3c0f2eba306b15f8 100644 (file)
@@ -3,4 +3,5 @@ node_modules
 /resources
 .hugo_build.lock
 .DS_Store
-/search/data
\ No newline at end of file
+/search/data
+/static/search.db
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 5d54591fe3ee244f48178e01c65e88c8473df3cf..23643c793547bdf9dcaadfc8b09686192553ea3c 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -7,11 +7,19 @@ from those in directories with their own license files. Specifically:
 - static/images/blog-cover-images/cc-by-sa-4
 - static/images/blog-cover-images/cc-by-4
 
+The following library files are also under a different license and copyright:
+(Full License and copyright stated within these files):
+
+- search/webidx.pl (BSD 3-Clause)
+- themes/bookstack/static/libs/webidx.js (BSD 3-Clause)
+- themes/bookstack/static/libs/sql-wasm.js (MIT)
+- themes/bookstack/static/libs/photoswipe.min.js (MIT)
+
 ---
 
 The MIT License (MIT)
 
-Copyright (c) 2023 Dan Brown
+Copyright (c) 2024 Dan Brown
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
index 9a63c2d44a700318e672be5e9c280eb52d6cca73..7238bd29b4726e26f1c90f7ceeca9df764b59c85 100644 (file)
@@ -9,11 +9,12 @@
     "build:css:watch": "sass ./themes/bookstack/sass:./themes/bookstack/static/css --watch",
     "build:hugo:prod": "hugo",
     "build:hugo:watch": "hugo serve -DF",
-    "build": "npm-run-all --sequential build:css:prod build:hugo:prod",
+    "build:search:prod": "./search/webidx.pl public ./static/search.db",
+    "build": "npm-run-all --sequential build:css:prod build:hugo:prod build:search:prod",
     "serve": "npm-run-all build:hugo:watch",
     "dev": "npm-run-all --parallel build:hugo:watch build:css:watch",
     "deploy:server": "rsync -avx --delete --exclude '.git/' --exclude 'node_modules/' --exclude 'search/data/' ./ bs-site:/var/www/bookstackapp.com/",
-    "deploy": "npm-run-all --sequential build:css:prod build:hugo:prod deploy:server",
+    "deploy": "npm-run-all --sequential build:css:prod build:hugo:prod build:search:prod deploy:server",
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "author": "Dan Brown",
diff --git a/search/webidx.pl b/search/webidx.pl
new file mode 100644 (file)
index 0000000..ae4c86e
--- /dev/null
@@ -0,0 +1,318 @@
+#!/usr/bin/perl
+
+# Taken from https://github.com/gbxyz/webidx/tree/main
+# BSD 3-Clause License
+# Copyright (c) 2024, Gavin Brown
+# Full license: https://github.com/gbxyz/webidx/blob/a28a984d38fd546d1bec4d6a4a5a47ab86cb08f8/LICENSE
+
+# Modifications have been made since taking a copy of the code
+# to suit this particular website and use-case
+
+# To use, needed to install the following packages (Tested on Fedora 39):
+# perl-open perl-HTML-Parser perl-DBD-SQLite
+
+use Cwd qw(abs_path);
+use Getopt::Long qw(:config bundling auto_version auto_help);
+use DBD::SQLite;
+use DBI;
+use File::Basename qw(basename);
+use File::Glob qw(:bsd_glob);
+use HTML::Parser;
+use IPC::Open2;
+use IO::File;
+use List::Util qw(uniq none any);
+use feature qw(say);
+use open qw(:encoding(utf8));
+use strict;
+use utf8;
+use vars qw($VERSION);
+
+$VERSION = 0.02;
+
+#
+# parse command line options
+#
+my (@exclude, @excludePattern, $compress, $origin);
+die() unless (GetOptions('exclude|x=s' => \@exclude, 'excludePattern|xP=s' => \@excludePattern, 'compress|z' => \$compress, 'origin|o=s' => \$origin));
+
+@exclude = map { abs_path($_) } @exclude;
+
+#
+# determine the source directory and the database filename
+#
+my $dir = abs_path(shift(@ARGV) || '.');
+my $dbfile = abs_path(shift(@ARGV) || $dir.'/webidx.db');
+
+#
+# initialise the database
+#
+unlink($dbfile) if (-e $dbfile);
+my $db = DBI->connect('dbi:SQLite:dbname='.$dbfile, '', '', {
+    'PrintError' => 1,
+    'RaiseError' => 1,
+    'AutoCommit' => 0,
+});
+
+#
+# a list of words we want to exclude
+#
+my @common = qw(be and of a in to it i for he on do at but from that not by or as can who get if my as up so me the are we was is);
+
+#
+# this is a map of filename => page title
+#
+my $titles = {};
+
+#
+# this is map of word => page
+#
+my $index = {};
+
+#
+# scan the source directory
+#
+
+say 'scanning ', $dir;
+
+scan_directory($dir);
+
+#
+# generate the database
+#
+
+say 'finished scan, generating index';
+
+$db->do(qq{BEGIN});
+
+$db->do(qq{CREATE TABLE `pages` (`id` INTEGER PRIMARY KEY, `url` TEXT, `title` TEXT)});
+$db->do(qq{CREATE TABLE `words` (`id` INTEGER PRIMARY KEY, `word` TEXT)});
+$db->do(qq{CREATE TABLE `index` (`id` INTEGER PRIMARY KEY, `word` INT, `page_id` INT)});
+
+my $word_sth    = $db->prepare(qq{INSERT INTO `words` (`word`) VALUES (?)});
+my $page_sth    = $db->prepare(qq{INSERT INTO `pages` (`url`, `title`) VALUES (?, ?)});
+my $index_sth   = $db->prepare(qq{INSERT INTO `index` (`word`, `page_id`) VALUES (?, ?)});
+
+my $word_ids = {};
+my $page_ids = {};
+
+#
+# for each word...
+#
+foreach my $word (keys(%{$index})) {
+
+    #
+    # insert an entry into the words table (if one doesn't already exist)
+    #
+    if (!defined($word_ids->{$word})) {
+        $word_sth->execute($word);
+        $word_ids->{$word} = $db->last_insert_id;
+    }
+
+    #
+    # for each page...
+    #
+    foreach my $page (keys(%{$index->{$word}})) {
+        #
+        # clean up the page title by removing leading and trailing whitespace
+        #
+        my $title = $titles->{$page};
+        $title =~ s/^[ \s\t\r\n]+//g;
+        $title =~ s/[ \s\t\r\n]+$//g;
+        #
+        # remove any trailing "· BookStack"
+        #
+        $title =~ s/· BookStack$//;
+
+        #
+        # remove the directory
+        #
+        $page =~ s/^$dir//;
+
+        #
+        # prepend the origin
+        #
+        $page = $origin.$page if ($origin);
+
+        #
+        # Trim off the /index.html
+        #
+        $page =~ s/\/index\.html$//;
+
+        #
+        # insert an entry into the pages table (if one doesn't already exist)
+        #
+        if (!defined($page_ids->{$page})) {
+            $page_sth->execute($page, $title);
+            $page_ids->{$page} = $db->last_insert_id;
+        }
+
+        #
+        # insert an index entry
+        #
+        $index_sth->execute($word_ids->{$word}, $page_ids->{$page}) || die();
+    }
+}
+
+$db->do(qq{COMMIT});
+
+$db->disconnect;
+
+if ($compress) {
+    say 'compressing database...';
+    open2(undef, undef, qw(gzip -f -9), $dbfile);
+}
+
+say 'done';
+
+exit;
+
+#
+# reads the contents of a directory: all HTML files are indexed, all directories
+# are scanned recursively. symlinks to directories are *not* followed
+#
+sub scan_directory {
+    my $dir = shift;
+
+    foreach my $file (map { abs_path($_) } bsd_glob(sprintf('%s/*', $dir))) {
+        if (-d $file) {
+
+            next if (any { $file =~ m/\Q$_/i } @excludePattern);
+
+            #
+            # directory, scan it
+            #
+            scan_directory($file);
+
+        } elsif ($file =~ /\.html?$/i) {
+            #
+            # HTML file, index it
+            #
+            index_html($file);
+
+        }
+    }
+}
+
+#
+# index an HTML file
+#
+sub index_html {
+    my $file = shift;
+
+    return if (any { $_ eq $file } @exclude) || (any { $file =~ m/\Q$_/i } @excludePattern);
+
+    my $currtag;
+    my $title;
+    my $text;
+    my $inmain = 0;
+    my $parser = HTML::Parser->new(
+        #
+        # text handler
+        #
+        'text_h' => [sub {
+            if ('title' eq $currtag) {
+                #
+                # <title> tag, which goes into the $titles hashref
+                #
+                $title = shift;
+
+            } elsif ($inmain) {
+                #
+                # everything else, which just gets appended to the $text string
+                #
+                $text .= " ".shift;
+
+            }
+        }, qq{dtext}],
+
+        #
+        # start tag handler
+        #
+        'start_h' => [sub {
+            #
+            # add the alt attributes of images, and any title attributes found
+            #
+            $text .= " ".$_[1]->{'alt'} if (lc('img') eq $_[0]);
+            $text .= " ".$_[1]->{'title'} if (defined($_[1]->{'title'}));
+
+            $currtag = $_[0];
+            if ('main' eq $currtag) {
+                $inmain = 1;
+            }
+        }, qq{tag,attr}],
+
+        #
+        # end tag handler
+        #
+        'end_h' => [sub {
+            undef($currtag);
+            if ('main' eq $_[0]) {
+                $inmain = 0;
+            }
+        }, qq{tag}],
+    );
+
+    $parser->unbroken_text(1);
+
+    #
+    # we expect these elements contain text we don't want to index
+    #
+    $parser->ignore_elements(qw(script style header nav footer svg));
+
+    #
+    # open the file, being careful to ensure it's treated as UTF-8
+    #
+    my $fh = IO::File->new($file);
+    $fh->binmode(qq{:utf8});
+
+    #
+    # parse
+    #
+    $parser->parse_file($fh);
+    $fh->close;
+
+    return if (!$text);
+
+    $titles->{$file} = $title;
+    my @words = grep { my $w = $_ ; none { $w eq $_ } @common } # filter out common words
+                grep { /\w/ }                                   # filter out strings that don't contain at least one word character
+                map {
+                    $_ =~ s/^[^\w]+//g;                         # remove leading non-word characters
+                    $_ =~ s/[^\w]+$//g;                         # remove trailing non-word characters
+                    $_;
+                }
+                split(/[\s\r\n]+/, lc($text));                  # split by whitespace
+
+    foreach my $word (@words) {
+        #
+        # increment the counter for this word/file
+        #
+        $index->{$word}->{$file}++;
+    }
+}
+
+=pod
+
+=head1 SYNOPSIS
+
+    webidx [-x FILE [-x FILE2 [...]]] [--xP PATTERN [--xP PATTERN2 [...]]] [-o ORIGIN] [-z] [DIRECTORY] [DBFILE]
+
+This will cause all HTML files in C<DIRECTORY> to be indexed, and the resulting database written to C<DBFILE>. The supported options are:
+
+=over
+
+=item * C<-x FILE> specifies a file to be excluded. May be specified multiple times.
+
+=item * C<--xP PATTERN> specifies a pattern of folders and files to be excluded. May be specified multiple times.
+
+=item * C<-o ORIGIN> specifies a base URL which will be prepended to the filenames (once C<DIRECTORY> has been removed).
+
+=item C<-z> specifies that the database file should be compressed once generated. If specified, the database will be at C<DBFILE.gz>.
+
+=item * C<DIRECTORY> is the directory to be indexed, defaults to the current working directory.
+
+=item * C<DBFILE> is the location where the database should be written. if not specified, defaults to C<DIRECTORY/index.db>.
+
+=back
+
+=cut
\ No newline at end of file
index 812fd37f729349d4e9b7b7e154bd1528c6537efa..770216d9c6d925c3630f3d11c9353e55dcd8ff41 100644 (file)
@@ -1,6 +1,6 @@
 {{ partial "header.html" . }}
 
-<div class="about-page">
+<main class="about-page">
   <div class="shaded primary">
     <div class="container small hero padded-vertical">
       <h1 class="text-center">{{.Title}}</h1>
@@ -14,6 +14,6 @@
   <div class="container small padded-vertical">
     {{.Content}}
   </div>
-</div>
+</main>
 
 {{ partial "footer.html" . }}
index fdc669e67e7c17798d9ec5f464194b6af363cdb5..02972828b6b364a1971c18783a200d36be2ed3c9 100644 (file)
       </div>
     </aside>
 
-    <main class="col-md-8 col-md-offset-1 hacks-content">
+    <div class="col-md-8 col-md-offset-1 hacks-content">
 
-      {{ if .Params.Date }}
-      <div class="hack-warning">
-        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M4.47 21h15.06c1.54 0 2.5-1.67 1.73-3L13.73 4.99c-.77-1.33-2.69-1.33-3.46 0L2.74 18c-.77 1.33.19 3 1.73 3zM12 14c-.55 0-1-.45-1-1v-2c0-.55.45-1 1-1s1 .45 1 1v2c0 .55-.45 1-1 1zm1 4h-2v-2h2v2z"/></svg>
-        <div>
-          These hacks are unsupported customizations meant as unofficial workarounds. <br>
-          They can cause instability, introduce issues and may conflict with future updates.
-          Apply at your own risk!
-        </div>
-      </div>
-      {{ end }}
+      <main>
 
-      <h1>{{.Title}}</h1>
-
-      {{ if .Params.Tested }}
-      <ul class="hack-meta">
-        {{ $authors := strings.Split .Params.Author " " }}
-        <li><strong>Author{{ if gt (len $authors) 1 }}s{{end}}:</strong> {{ range $authors }}<a href="https://github.com/{{ strings.TrimLeft "@" . }}" target="_blank">{{ . }}</a> {{ end }}</li>
-        <li><strong>Created:</strong> {{ .Date.Format "2" | humanize }} {{ .Date.Format "Jan 2006" }}</li>
-        <li><strong>Updated:</strong> {{ .Params.Updated.Format "2" | humanize }} {{ .Params.Updated.Format "Jan 2006" }}</li>
-        <li><strong>Last Tested On:</strong> {{ .Params.Tested }}</li>
-      </ul>
-      {{ end }}
+        {{ if .Params.Date }}
+        <div class="hack-warning">
+          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M4.47 21h15.06c1.54 0 2.5-1.67 1.73-3L13.73 4.99c-.77-1.33-2.69-1.33-3.46 0L2.74 18c-.77 1.33.19 3 1.73 3zM12 14c-.55 0-1-.45-1-1v-2c0-.55.45-1 1-1s1 .45 1 1v2c0 .55-.45 1-1 1zm1 4h-2v-2h2v2z"/></svg>
+          <div>
+            These hacks are unsupported customizations meant as unofficial workarounds. <br>
+            They can cause instability, introduce issues and may conflict with future updates.
+            Apply at your own risk!
+          </div>
+        </div>
+        {{ end }}
 
-      {{.Content}}
+        <h1>{{.Title}}</h1>
 
+        {{ if .Params.Tested }}
+        <ul class="hack-meta">
+          {{ $authors := strings.Split .Params.Author " " }}
+          <li><strong>Author{{ if gt (len $authors) 1 }}s{{end}}:</strong> {{ range $authors }}<a href="https://github.com/{{ strings.TrimLeft "@" . }}" target="_blank">{{ . }}</a> {{ end }}</li>
+          <li><strong>Created:</strong> {{ .Date.Format "2" | humanize }} {{ .Date.Format "Jan 2006" }}</li>
+          <li><strong>Updated:</strong> {{ .Params.Updated.Format "2" | humanize }} {{ .Params.Updated.Format "Jan 2006" }}</li>
+          <li><strong>Last Tested On:</strong> {{ .Params.Tested }}</li>
+        </ul>
+        {{ end }}
+  
+        {{.Content}}
+      </main>
 
       {{ if .Params.Tested }}
-      <hr>
-
-      <h4>Request an Update</h4>
-
-      <div class="row">
-        <div class="col col-md-8">
-          <p>
-            Hack not working on the latest version of BookStack? <br>
-            You can request this hack to be updated & tested for a small one-time fee. <br>
-            This helps keeps these hacks updated & maintained in a sustainable manner.
-          </p>
-        </div>
-        <div class="col col-md-4 text-center">
-          <a href="https://bookstack-hacks.httpfunctions.com?hack_id={{ .File.ContentBaseName }}&hack_name={{.Title}}" class="button" target="_blank">Request Update</a>
+        <hr>
+
+        <h4>Request an Update</h4>
+
+        <div class="row">
+          <div class="col col-md-8">
+            <p>
+              Hack not working on the latest version of BookStack? <br>
+              You can request this hack to be updated & tested for a small one-time fee. <br>
+              This helps keeps these hacks updated & maintained in a sustainable manner.
+            </p>
+          </div>
+          <div class="col col-md-4 text-center">
+            <a href="https://bookstack-hacks.httpfunctions.com?hack_id={{ .File.ContentBaseName }}&hack_name={{.Title}}" class="button" target="_blank">Request Update</a>
+          </div>
         </div>
-      </div>
 
-      <hr>
+        <hr>
 
-      <h4>Latest Hacks</h4>
+        <h4>Latest Hacks</h4>
 
-      <div class="hack-box-list">
-        {{ range first 4 ( where .Site.RegularPages "Section" "hacks") }}
-        {{ if .Params.Date }}
-          {{ partial "list-hack" .}}
+        <div class="hack-box-list">
+          {{ range first 4 ( where .Site.RegularPages "Section" "hacks") }}
+          {{ if .Params.Date }}
+            {{ partial "list-hack" .}}
+          {{ end }}
         {{ end }}
-      {{ end }}
-      </div>
-      {{ end }}
+        </div>
+      {{ end}}
 
-    </main>
+    </div>
   </div>
 
 </div>
index 52b1bfcc22eda2239b6345a2ed26b577d375b0d8..4068d393ecec0748f6748d3486a1ef65393de229 100644 (file)
         </div>
     </footer>
 
+    <form onsubmit="window.webidx.search({dbfile:'/search.db',query:document.getElementById('q').value});return false;">
+    <input id="q" type="search">
+    </form>
 
-    <script src="{{.Site.BaseURL}}libs/docs-searchbar.min.js"></script>
-    <script>
-        const searchInputSelector = '.doc-search-input,.blog-search-input';
-        if (document.querySelector(searchInputSelector) !== null) {
-            docsSearchBar({
-                hostUrl: 'https://search.bookstackapp.com',
-                apiKey: 'd36e621d5d924807a14c435b542aa98fd11d0c91df2526e128ecb19e617ba381',
-                indexUid: 'docs',
-                inputSelector: searchInputSelector,
-                debug: false, // Set debug to true if you want to inspect the dropdown
-            })
-        }
-    </script>
+    <script src="{{.Site.BaseURL}}libs/sql-wasm.js"></script>
+    <script src="{{.Site.BaseURL}}libs/webidx.js"></script>
 
     <script src="{{.Site.BaseURL}}js/script.js"></script>
 </body>
index f2ac34c4fea1279c0d86ced6050aa398c8c68b14..7d2189e89b4d39ac7d188444f62754803f1fa502 100644 (file)
@@ -33,7 +33,7 @@
     {{ end }}
 
     <title>
-      {{ if ne .RelPermalink "/" }} {{ .Title }} &middot; {{ end }} {{ .Site.Title }}
+      {{ if ne .RelPermalink "/" }} {{ .Title }} &middot; {{ end }}{{ .Site.Title }}
     </title>
 
     {{ $description := .Site.Params.Description }}
index 2546b5f9e34dd89edaea700bdf1ff6ba37b8b28e..8eb97e5905f3cebb6d40982c1d42ddca368b73a3 100644 (file)
@@ -1,5 +1,7 @@
 /*! PhotoSwipe - v4.1.1 - 2015-12-24
 * http://photoswipe.com
+* MIT License
+* https://github.com/dimsemenov/PhotoSwipe/blob/41ff96cb8e88ef6f884c388db9f2a6d5e9d3b77a/LICENSE
 * Copyright (c) 2015 Dmitry Semenov; */
 !function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.PhotoSwipe=b()}(this,function(){"use strict";var a=function(a,b,c,d){var e={features:null,bind:function(a,b,c,d){var e=(d?"remove":"add")+"EventListener";b=b.split(" ");for(var f=0;f<b.length;f++)b[f]&&a[e](b[f],c,!1)},isArray:function(a){return a instanceof Array},createEl:function(a,b){var c=document.createElement(b||"div");return a&&(c.className=a),c},getScrollY:function(){var a=window.pageYOffset;return void 0!==a?a:document.documentElement.scrollTop},unbind:function(a,b,c){e.bind(a,b,c,!0)},removeClass:function(a,b){var c=new RegExp("(\\s|^)"+b+"(\\s|$)");a.className=a.className.replace(c," ").replace(/^\s\s*/,"").replace(/\s\s*$/,"")},addClass:function(a,b){e.hasClass(a,b)||(a.className+=(a.className?" ":"")+b)},hasClass:function(a,b){return a.className&&new RegExp("(^|\\s)"+b+"(\\s|$)").test(a.className)},getChildByClass:function(a,b){for(var c=a.firstChild;c;){if(e.hasClass(c,b))return c;c=c.nextSibling}},arraySearch:function(a,b,c){for(var d=a.length;d--;)if(a[d][c]===b)return d;return-1},extend:function(a,b,c){for(var d in b)if(b.hasOwnProperty(d)){if(c&&a.hasOwnProperty(d))continue;a[d]=b[d]}},easing:{sine:{out:function(a){return Math.sin(a*(Math.PI/2))},inOut:function(a){return-(Math.cos(Math.PI*a)-1)/2}},cubic:{out:function(a){return--a*a*a+1}}},detectFeatures:function(){if(e.features)return e.features;var a=e.createEl(),b=a.style,c="",d={};if(d.oldIE=document.all&&!document.addEventListener,d.touch="ontouchstart"in window,window.requestAnimationFrame&&(d.raf=window.requestAnimationFrame,d.caf=window.cancelAnimationFrame),d.pointerEvent=navigator.pointerEnabled||navigator.msPointerEnabled,!d.pointerEvent){var f=navigator.userAgent;if(/iP(hone|od)/.test(navigator.platform)){var g=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);g&&g.length>0&&(g=parseInt(g[1],10),g>=1&&8>g&&(d.isOldIOSPhone=!0))}var h=f.match(/Android\s([0-9\.]*)/),i=h?h[1]:0;i=parseFloat(i),i>=1&&(4.4>i&&(d.isOldAndroid=!0),d.androidVersion=i),d.isMobileOpera=/opera mini|opera mobi/i.test(f)}for(var j,k,l=["transform","perspective","animationName"],m=["","webkit","Moz","ms","O"],n=0;4>n;n++){c=m[n];for(var o=0;3>o;o++)j=l[o],k=c+(c?j.charAt(0).toUpperCase()+j.slice(1):j),!d[j]&&k in b&&(d[j]=k);c&&!d.raf&&(c=c.toLowerCase(),d.raf=window[c+"RequestAnimationFrame"],d.raf&&(d.caf=window[c+"CancelAnimationFrame"]||window[c+"CancelRequestAnimationFrame"]))}if(!d.raf){var p=0;d.raf=function(a){var b=(new Date).getTime(),c=Math.max(0,16-(b-p)),d=window.setTimeout(function(){a(b+c)},c);return p=b+c,d},d.caf=function(a){clearTimeout(a)}}return d.svg=!!document.createElementNS&&!!document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect,e.features=d,d}};e.detectFeatures(),e.features.oldIE&&(e.bind=function(a,b,c,d){b=b.split(" ");for(var e,f=(d?"detach":"attach")+"Event",g=function(){c.handleEvent.call(c)},h=0;h<b.length;h++)if(e=b[h])if("object"==typeof c&&c.handleEvent){if(d){if(!c["oldIE"+e])return!1}else c["oldIE"+e]=g;a[f]("on"+e,c["oldIE"+e])}else a[f]("on"+e,c)});var f=this,g=25,h=3,i={allowPanToNext:!0,spacing:.12,bgOpacity:1,mouseUsed:!1,loop:!0,pinchToClose:!0,closeOnScroll:!0,closeOnVerticalDrag:!0,verticalDragRange:.75,hideAnimationDuration:333,showAnimationDuration:333,showHideOpacity:!1,focus:!0,escKey:!0,arrowKeys:!0,mainScrollEndFriction:.35,panEndFriction:.35,isClickableElement:function(a){return"A"===a.tagName},getDoubleTapZoom:function(a,b){return a?1:b.initialZoomLevel<.7?1:1.33},maxSpreadZoom:1.33,modal:!0,scaleMode:"fit"};e.extend(i,d);var j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,aa,ba,ca,da,ea,fa,ga,ha,ia,ja,ka,la=function(){return{x:0,y:0}},ma=la(),na=la(),oa=la(),pa={},qa=0,ra={},sa=la(),ta=0,ua=!0,va=[],wa={},xa=!1,ya=function(a,b){e.extend(f,b.publicMethods),va.push(a)},za=function(a){var b=_b();return a>b-1?a-b:0>a?b+a:a},Aa={},Ba=function(a,b){return Aa[a]||(Aa[a]=[]),Aa[a].push(b)},Ca=function(a){var b=Aa[a];if(b){var c=Array.prototype.slice.call(arguments);c.shift();for(var d=0;d<b.length;d++)b[d].apply(f,c)}},Da=function(){return(new Date).getTime()},Ea=function(a){ia=a,f.bg.style.opacity=a*i.bgOpacity},Fa=function(a,b,c,d,e){(!xa||e&&e!==f.currItem)&&(d/=e?e.fitRatio:f.currItem.fitRatio),a[E]=u+b+"px, "+c+"px"+v+" scale("+d+")"},Ga=function(a){da&&(a&&(s>f.currItem.fitRatio?xa||(lc(f.currItem,!1,!0),xa=!0):xa&&(lc(f.currItem),xa=!1)),Fa(da,oa.x,oa.y,s))},Ha=function(a){a.container&&Fa(a.container.style,a.initialPosition.x,a.initialPosition.y,a.initialZoomLevel,a)},Ia=function(a,b){b[E]=u+a+"px, 0px"+v},Ja=function(a,b){if(!i.loop&&b){var c=m+(sa.x*qa-a)/sa.x,d=Math.round(a-sb.x);(0>c&&d>0||c>=_b()-1&&0>d)&&(a=sb.x+d*i.mainScrollEndFriction)}sb.x=a,Ia(a,n)},Ka=function(a,b){var c=tb[a]-ra[a];return na[a]+ma[a]+c-c*(b/t)},La=function(a,b){a.x=b.x,a.y=b.y,b.id&&(a.id=b.id)},Ma=function(a){a.x=Math.round(a.x),a.y=Math.round(a.y)},Na=null,Oa=function(){Na&&(e.unbind(document,"mousemove",Oa),e.addClass(a,"pswp--has_mouse"),i.mouseUsed=!0,Ca("mouseUsed")),Na=setTimeout(function(){Na=null},100)},Pa=function(){e.bind(document,"keydown",f),N.transform&&e.bind(f.scrollWrap,"click",f),i.mouseUsed||e.bind(document,"mousemove",Oa),e.bind(window,"resize scroll",f),Ca("bindEvents")},Qa=function(){e.unbind(window,"resize",f),e.unbind(window,"scroll",r.scroll),e.unbind(document,"keydown",f),e.unbind(document,"mousemove",Oa),N.transform&&e.unbind(f.scrollWrap,"click",f),U&&e.unbind(window,p,f),Ca("unbindEvents")},Ra=function(a,b){var c=hc(f.currItem,pa,a);return b&&(ca=c),c},Sa=function(a){return a||(a=f.currItem),a.initialZoomLevel},Ta=function(a){return a||(a=f.currItem),a.w>0?i.maxSpreadZoom:1},Ua=function(a,b,c,d){return d===f.currItem.initialZoomLevel?(c[a]=f.currItem.initialPosition[a],!0):(c[a]=Ka(a,d),c[a]>b.min[a]?(c[a]=b.min[a],!0):c[a]<b.max[a]?(c[a]=b.max[a],!0):!1)},Va=function(){if(E){var b=N.perspective&&!G;return u="translate"+(b?"3d(":"("),void(v=N.perspective?", 0px)":")")}E="left",e.addClass(a,"pswp--ie"),Ia=function(a,b){b.left=a+"px"},Ha=function(a){var b=a.fitRatio>1?1:a.fitRatio,c=a.container.style,d=b*a.w,e=b*a.h;c.width=d+"px",c.height=e+"px",c.left=a.initialPosition.x+"px",c.top=a.initialPosition.y+"px"},Ga=function(){if(da){var a=da,b=f.currItem,c=b.fitRatio>1?1:b.fitRatio,d=c*b.w,e=c*b.h;a.width=d+"px",a.height=e+"px",a.left=oa.x+"px",a.top=oa.y+"px"}}},Wa=function(a){var b="";i.escKey&&27===a.keyCode?b="close":i.arrowKeys&&(37===a.keyCode?b="prev":39===a.keyCode&&(b="next")),b&&(a.ctrlKey||a.altKey||a.shiftKey||a.metaKey||(a.preventDefault?a.preventDefault():a.returnValue=!1,f[b]()))},Xa=function(a){a&&(X||W||ea||S)&&(a.preventDefault(),a.stopPropagation())},Ya=function(){f.setScrollOffset(0,e.getScrollY())},Za={},$a=0,_a=function(a){Za[a]&&(Za[a].raf&&I(Za[a].raf),$a--,delete Za[a])},ab=function(a){Za[a]&&_a(a),Za[a]||($a++,Za[a]={})},bb=function(){for(var a in Za)Za.hasOwnProperty(a)&&_a(a)},cb=function(a,b,c,d,e,f,g){var h,i=Da();ab(a);var j=function(){if(Za[a]){if(h=Da()-i,h>=d)return _a(a),f(c),void(g&&g());f((c-b)*e(h/d)+b),Za[a].raf=H(j)}};j()},db={shout:Ca,listen:Ba,viewportSize:pa,options:i,isMainScrollAnimating:function(){return ea},getZoomLevel:function(){return s},getCurrentIndex:function(){return m},isDragging:function(){return U},isZooming:function(){return _},setScrollOffset:function(a,b){ra.x=a,M=ra.y=b,Ca("updateScrollOffset",ra)},applyZoomPan:function(a,b,c,d){oa.x=b,oa.y=c,s=a,Ga(d)},init:function(){if(!j&&!k){var c;f.framework=e,f.template=a,f.bg=e.getChildByClass(a,"pswp__bg"),J=a.className,j=!0,N=e.detectFeatures(),H=N.raf,I=N.caf,E=N.transform,L=N.oldIE,f.scrollWrap=e.getChildByClass(a,"pswp__scroll-wrap"),f.container=e.getChildByClass(f.scrollWrap,"pswp__container"),n=f.container.style,f.itemHolders=y=[{el:f.container.children[0],wrap:0,index:-1},{el:f.container.children[1],wrap:0,index:-1},{el:f.container.children[2],wrap:0,index:-1}],y[0].el.style.display=y[2].el.style.display="none",Va(),r={resize:f.updateSize,scroll:Ya,keydown:Wa,click:Xa};var d=N.isOldIOSPhone||N.isOldAndroid||N.isMobileOpera;for(N.animationName&&N.transform&&!d||(i.showAnimationDuration=i.hideAnimationDuration=0),c=0;c<va.length;c++)f["init"+va[c]]();if(b){var g=f.ui=new b(f,e);g.init()}Ca("firstUpdate"),m=m||i.index||0,(isNaN(m)||0>m||m>=_b())&&(m=0),f.currItem=$b(m),(N.isOldIOSPhone||N.isOldAndroid)&&(ua=!1),a.setAttribute("aria-hidden","false"),i.modal&&(ua?a.style.position="fixed":(a.style.position="absolute",a.style.top=e.getScrollY()+"px")),void 0===M&&(Ca("initialLayout"),M=K=e.getScrollY());var l="pswp--open ";for(i.mainClass&&(l+=i.mainClass+" "),i.showHideOpacity&&(l+="pswp--animate_opacity "),l+=G?"pswp--touch":"pswp--notouch",l+=N.animationName?" pswp--css_animation":"",l+=N.svg?" pswp--svg":"",e.addClass(a,l),f.updateSize(),o=-1,ta=null,c=0;h>c;c++)Ia((c+o)*sa.x,y[c].el.style);L||e.bind(f.scrollWrap,q,f),Ba("initialZoomInEnd",function(){f.setContent(y[0],m-1),f.setContent(y[2],m+1),y[0].el.style.display=y[2].el.style.display="block",i.focus&&a.focus(),Pa()}),f.setContent(y[1],m),f.updateCurrItem(),Ca("afterInit"),ua||(w=setInterval(function(){$a||U||_||s!==f.currItem.initialZoomLevel||f.updateSize()},1e3)),e.addClass(a,"pswp--visible")}},close:function(){j&&(j=!1,k=!0,Ca("close"),Qa(),bc(f.currItem,null,!0,f.destroy))},destroy:function(){Ca("destroy"),Wb&&clearTimeout(Wb),a.setAttribute("aria-hidden","true"),a.className=J,w&&clearInterval(w),e.unbind(f.scrollWrap,q,f),e.unbind(window,"scroll",f),yb(),bb(),Aa=null},panTo:function(a,b,c){c||(a>ca.min.x?a=ca.min.x:a<ca.max.x&&(a=ca.max.x),b>ca.min.y?b=ca.min.y:b<ca.max.y&&(b=ca.max.y)),oa.x=a,oa.y=b,Ga()},handleEvent:function(a){a=a||window.event,r[a.type]&&r[a.type](a)},goTo:function(a){a=za(a);var b=a-m;ta=b,m=a,f.currItem=$b(m),qa-=b,Ja(sa.x*qa),bb(),ea=!1,f.updateCurrItem()},next:function(){f.goTo(m+1)},prev:function(){f.goTo(m-1)},updateCurrZoomItem:function(a){if(a&&Ca("beforeChange",0),y[1].el.children.length){var b=y[1].el.children[0];da=e.hasClass(b,"pswp__zoom-wrap")?b.style:null}else da=null;ca=f.currItem.bounds,t=s=f.currItem.initialZoomLevel,oa.x=ca.center.x,oa.y=ca.center.y,a&&Ca("afterChange")},invalidateCurrItems:function(){x=!0;for(var a=0;h>a;a++)y[a].item&&(y[a].item.needsUpdate=!0)},updateCurrItem:function(a){if(0!==ta){var b,c=Math.abs(ta);if(!(a&&2>c)){f.currItem=$b(m),xa=!1,Ca("beforeChange",ta),c>=h&&(o+=ta+(ta>0?-h:h),c=h);for(var d=0;c>d;d++)ta>0?(b=y.shift(),y[h-1]=b,o++,Ia((o+2)*sa.x,b.el.style),f.setContent(b,m-c+d+1+1)):(b=y.pop(),y.unshift(b),o--,Ia(o*sa.x,b.el.style),f.setContent(b,m+c-d-1-1));if(da&&1===Math.abs(ta)){var e=$b(z);e.initialZoomLevel!==s&&(hc(e,pa),lc(e),Ha(e))}ta=0,f.updateCurrZoomItem(),z=m,Ca("afterChange")}}},updateSize:function(b){if(!ua&&i.modal){var c=e.getScrollY();if(M!==c&&(a.style.top=c+"px",M=c),!b&&wa.x===window.innerWidth&&wa.y===window.innerHeight)return;wa.x=window.innerWidth,wa.y=window.innerHeight,a.style.height=wa.y+"px"}if(pa.x=f.scrollWrap.clientWidth,pa.y=f.scrollWrap.clientHeight,Ya(),sa.x=pa.x+Math.round(pa.x*i.spacing),sa.y=pa.y,Ja(sa.x*qa),Ca("beforeResize"),void 0!==o){for(var d,g,j,k=0;h>k;k++)d=y[k],Ia((k+o)*sa.x,d.el.style),j=m+k-1,i.loop&&_b()>2&&(j=za(j)),g=$b(j),g&&(x||g.needsUpdate||!g.bounds)?(f.cleanSlide(g),f.setContent(d,j),1===k&&(f.currItem=g,f.updateCurrZoomItem(!0)),g.needsUpdate=!1):-1===d.index&&j>=0&&f.setContent(d,j),g&&g.container&&(hc(g,pa),lc(g),Ha(g));x=!1}t=s=f.currItem.initialZoomLevel,ca=f.currItem.bounds,ca&&(oa.x=ca.center.x,oa.y=ca.center.y,Ga(!0)),Ca("resize")},zoomTo:function(a,b,c,d,f){b&&(t=s,tb.x=Math.abs(b.x)-oa.x,tb.y=Math.abs(b.y)-oa.y,La(na,oa));var g=Ra(a,!1),h={};Ua("x",g,h,a),Ua("y",g,h,a);var i=s,j={x:oa.x,y:oa.y};Ma(h);var k=function(b){1===b?(s=a,oa.x=h.x,oa.y=h.y):(s=(a-i)*b+i,oa.x=(h.x-j.x)*b+j.x,oa.y=(h.y-j.y)*b+j.y),f&&f(b),Ga(1===b)};c?cb("customZoomTo",0,1,c,d||e.easing.sine.inOut,k):k(1)}},eb=30,fb=10,gb={},hb={},ib={},jb={},kb={},lb=[],mb={},nb=[],ob={},pb=0,qb=la(),rb=0,sb=la(),tb=la(),ub=la(),vb=function(a,b){return a.x===b.x&&a.y===b.y},wb=function(a,b){return Math.abs(a.x-b.x)<g&&Math.abs(a.y-b.y)<g},xb=function(a,b){return ob.x=Math.abs(a.x-b.x),ob.y=Math.abs(a.y-b.y),Math.sqrt(ob.x*ob.x+ob.y*ob.y)},yb=function(){Y&&(I(Y),Y=null)},zb=function(){U&&(Y=H(zb),Pb())},Ab=function(){return!("fit"===i.scaleMode&&s===f.currItem.initialZoomLevel)},Bb=function(a,b){return a&&a!==document?a.getAttribute("class")&&a.getAttribute("class").indexOf("pswp__scroll-wrap")>-1?!1:b(a)?a:Bb(a.parentNode,b):!1},Cb={},Db=function(a,b){return Cb.prevent=!Bb(a.target,i.isClickableElement),Ca("preventDragEvent",a,b,Cb),Cb.prevent},Eb=function(a,b){return b.x=a.pageX,b.y=a.pageY,b.id=a.identifier,b},Fb=function(a,b,c){c.x=.5*(a.x+b.x),c.y=.5*(a.y+b.y)},Gb=function(a,b,c){if(a-P>50){var d=nb.length>2?nb.shift():{};d.x=b,d.y=c,nb.push(d),P=a}},Hb=function(){var a=oa.y-f.currItem.initialPosition.y;return 1-Math.abs(a/(pa.y/2))},Ib={},Jb={},Kb=[],Lb=function(a){for(;Kb.length>0;)Kb.pop();return F?(ka=0,lb.forEach(function(a){0===ka?Kb[0]=a:1===ka&&(Kb[1]=a),ka++})):a.type.indexOf("touch")>-1?a.touches&&a.touches.length>0&&(Kb[0]=Eb(a.touches[0],Ib),a.touches.length>1&&(Kb[1]=Eb(a.touches[1],Jb))):(Ib.x=a.pageX,Ib.y=a.pageY,Ib.id="",Kb[0]=Ib),Kb},Mb=function(a,b){var c,d,e,g,h=0,j=oa[a]+b[a],k=b[a]>0,l=sb.x+b.x,m=sb.x-mb.x;return c=j>ca.min[a]||j<ca.max[a]?i.panEndFriction:1,j=oa[a]+b[a]*c,!i.allowPanToNext&&s!==f.currItem.initialZoomLevel||(da?"h"!==fa||"x"!==a||W||(k?(j>ca.min[a]&&(c=i.panEndFriction,h=ca.min[a]-j,d=ca.min[a]-na[a]),(0>=d||0>m)&&_b()>1?(g=l,0>m&&l>mb.x&&(g=mb.x)):ca.min.x!==ca.max.x&&(e=j)):(j<ca.max[a]&&(c=i.panEndFriction,h=j-ca.max[a],d=na[a]-ca.max[a]),(0>=d||m>0)&&_b()>1?(g=l,m>0&&l<mb.x&&(g=mb.x)):ca.min.x!==ca.max.x&&(e=j))):g=l,"x"!==a)?void(ea||Z||s>f.currItem.fitRatio&&(oa[a]+=b[a]*c)):(void 0!==g&&(Ja(g,!0),Z=g===mb.x?!1:!0),ca.min.x!==ca.max.x&&(void 0!==e?oa.x=e:Z||(oa.x+=b.x*c)),void 0!==g)},Nb=function(a){if(!("mousedown"===a.type&&a.button>0)){if(Zb)return void a.preventDefault();if(!T||"mousedown"!==a.type){if(Db(a,!0)&&a.preventDefault(),Ca("pointerDown"),F){var b=e.arraySearch(lb,a.pointerId,"id");0>b&&(b=lb.length),lb[b]={x:a.pageX,y:a.pageY,id:a.pointerId}}var c=Lb(a),d=c.length;$=null,bb(),U&&1!==d||(U=ga=!0,e.bind(window,p,f),R=ja=ha=S=Z=X=V=W=!1,fa=null,Ca("firstTouchStart",c),La(na,oa),ma.x=ma.y=0,La(jb,c[0]),La(kb,jb),mb.x=sa.x*qa,nb=[{x:jb.x,y:jb.y}],P=O=Da(),Ra(s,!0),yb(),zb()),!_&&d>1&&!ea&&!Z&&(t=s,W=!1,_=V=!0,ma.y=ma.x=0,La(na,oa),La(gb,c[0]),La(hb,c[1]),Fb(gb,hb,ub),tb.x=Math.abs(ub.x)-oa.x,tb.y=Math.abs(ub.y)-oa.y,aa=ba=xb(gb,hb))}}},Ob=function(a){if(a.preventDefault(),F){var b=e.arraySearch(lb,a.pointerId,"id");if(b>-1){var c=lb[b];c.x=a.pageX,c.y=a.pageY}}if(U){var d=Lb(a);if(fa||X||_)$=d;else if(sb.x!==sa.x*qa)fa="h";else{var f=Math.abs(d[0].x-jb.x)-Math.abs(d[0].y-jb.y);Math.abs(f)>=fb&&(fa=f>0?"h":"v",$=d)}}},Pb=function(){if($){var a=$.length;if(0!==a)if(La(gb,$[0]),ib.x=gb.x-jb.x,ib.y=gb.y-jb.y,_&&a>1){if(jb.x=gb.x,jb.y=gb.y,!ib.x&&!ib.y&&vb($[1],hb))return;La(hb,$[1]),W||(W=!0,Ca("zoomGestureStarted"));var b=xb(gb,hb),c=Ub(b);c>f.currItem.initialZoomLevel+f.currItem.initialZoomLevel/15&&(ja=!0);var d=1,e=Sa(),g=Ta();if(e>c)if(i.pinchToClose&&!ja&&t<=f.currItem.initialZoomLevel){var h=e-c,j=1-h/(e/1.2);Ea(j),Ca("onPinchClose",j),ha=!0}else d=(e-c)/e,d>1&&(d=1),c=e-d*(e/3);else c>g&&(d=(c-g)/(6*e),d>1&&(d=1),c=g+d*e);0>d&&(d=0),aa=b,Fb(gb,hb,qb),ma.x+=qb.x-ub.x,ma.y+=qb.y-ub.y,La(ub,qb),oa.x=Ka("x",c),oa.y=Ka("y",c),R=c>s,s=c,Ga()}else{if(!fa)return;if(ga&&(ga=!1,Math.abs(ib.x)>=fb&&(ib.x-=$[0].x-kb.x),Math.abs(ib.y)>=fb&&(ib.y-=$[0].y-kb.y)),jb.x=gb.x,jb.y=gb.y,0===ib.x&&0===ib.y)return;if("v"===fa&&i.closeOnVerticalDrag&&!Ab()){ma.y+=ib.y,oa.y+=ib.y;var k=Hb();return S=!0,Ca("onVerticalDrag",k),Ea(k),void Ga()}Gb(Da(),gb.x,gb.y),X=!0,ca=f.currItem.bounds;var l=Mb("x",ib);l||(Mb("y",ib),Ma(oa),Ga())}}},Qb=function(a){if(N.isOldAndroid){if(T&&"mouseup"===a.type)return;a.type.indexOf("touch")>-1&&(clearTimeout(T),T=setTimeout(function(){T=0},600))}Ca("pointerUp"),Db(a,!1)&&a.preventDefault();var b;if(F){var c=e.arraySearch(lb,a.pointerId,"id");if(c>-1)if(b=lb.splice(c,1)[0],navigator.pointerEnabled)b.type=a.pointerType||"mouse";else{var d={4:"mouse",2:"touch",3:"pen"};b.type=d[a.pointerType],b.type||(b.type=a.pointerType||"mouse")}}var g,h=Lb(a),j=h.length;if("mouseup"===a.type&&(j=0),2===j)return $=null,!0;1===j&&La(kb,h[0]),0!==j||fa||ea||(b||("mouseup"===a.type?b={x:a.pageX,y:a.pageY,type:"mouse"}:a.changedTouches&&a.changedTouches[0]&&(b={x:a.changedTouches[0].pageX,y:a.changedTouches[0].pageY,type:"touch"})),Ca("touchRelease",a,b));var k=-1;if(0===j&&(U=!1,e.unbind(window,p,f),yb(),_?k=0:-1!==rb&&(k=Da()-rb)),rb=1===j?Da():-1,g=-1!==k&&150>k?"zoom":"swipe",_&&2>j&&(_=!1,1===j&&(g="zoomPointerUp"),Ca("zoomGestureEnded")),$=null,X||W||ea||S)if(bb(),Q||(Q=Rb()),Q.calculateSwipeSpeed("x"),S){var l=Hb();if(l<i.verticalDragRange)f.close();else{var m=oa.y,n=ia;cb("verticalDrag",0,1,300,e.easing.cubic.out,function(a){oa.y=(f.currItem.initialPosition.y-m)*a+m,Ea((1-n)*a+n),Ga()}),Ca("onVerticalDrag",1)}}else{if((Z||ea)&&0===j){var o=Tb(g,Q);if(o)return;g="zoomPointerUp"}if(!ea)return"swipe"!==g?void Vb():void(!Z&&s>f.currItem.fitRatio&&Sb(Q))}},Rb=function(){var a,b,c={lastFlickOffset:{},lastFlickDist:{},lastFlickSpeed:{},slowDownRatio:{},slowDownRatioReverse:{},speedDecelerationRatio:{},speedDecelerationRatioAbs:{},distanceOffset:{},backAnimDestination:{},backAnimStarted:{},calculateSwipeSpeed:function(d){nb.length>1?(a=Da()-P+50,b=nb[nb.length-2][d]):(a=Da()-O,b=kb[d]),c.lastFlickOffset[d]=jb[d]-b,c.lastFlickDist[d]=Math.abs(c.lastFlickOffset[d]),c.lastFlickDist[d]>20?c.lastFlickSpeed[d]=c.lastFlickOffset[d]/a:c.lastFlickSpeed[d]=0,Math.abs(c.lastFlickSpeed[d])<.1&&(c.lastFlickSpeed[d]=0),c.slowDownRatio[d]=.95,c.slowDownRatioReverse[d]=1-c.slowDownRatio[d],c.speedDecelerationRatio[d]=1},calculateOverBoundsAnimOffset:function(a,b){c.backAnimStarted[a]||(oa[a]>ca.min[a]?c.backAnimDestination[a]=ca.min[a]:oa[a]<ca.max[a]&&(c.backAnimDestination[a]=ca.max[a]),void 0!==c.backAnimDestination[a]&&(c.slowDownRatio[a]=.7,c.slowDownRatioReverse[a]=1-c.slowDownRatio[a],c.speedDecelerationRatioAbs[a]<.05&&(c.lastFlickSpeed[a]=0,c.backAnimStarted[a]=!0,cb("bounceZoomPan"+a,oa[a],c.backAnimDestination[a],b||300,e.easing.sine.out,function(b){oa[a]=b,Ga()}))))},calculateAnimOffset:function(a){c.backAnimStarted[a]||(c.speedDecelerationRatio[a]=c.speedDecelerationRatio[a]*(c.slowDownRatio[a]+c.slowDownRatioReverse[a]-c.slowDownRatioReverse[a]*c.timeDiff/10),c.speedDecelerationRatioAbs[a]=Math.abs(c.lastFlickSpeed[a]*c.speedDecelerationRatio[a]),c.distanceOffset[a]=c.lastFlickSpeed[a]*c.speedDecelerationRatio[a]*c.timeDiff,oa[a]+=c.distanceOffset[a])},panAnimLoop:function(){return Za.zoomPan&&(Za.zoomPan.raf=H(c.panAnimLoop),c.now=Da(),c.timeDiff=c.now-c.lastNow,c.lastNow=c.now,c.calculateAnimOffset("x"),c.calculateAnimOffset("y"),Ga(),c.calculateOverBoundsAnimOffset("x"),c.calculateOverBoundsAnimOffset("y"),c.speedDecelerationRatioAbs.x<.05&&c.speedDecelerationRatioAbs.y<.05)?(oa.x=Math.round(oa.x),oa.y=Math.round(oa.y),Ga(),void _a("zoomPan")):void 0}};return c},Sb=function(a){return a.calculateSwipeSpeed("y"),ca=f.currItem.bounds,a.backAnimDestination={},a.backAnimStarted={},Math.abs(a.lastFlickSpeed.x)<=.05&&Math.abs(a.lastFlickSpeed.y)<=.05?(a.speedDecelerationRatioAbs.x=a.speedDecelerationRatioAbs.y=0,a.calculateOverBoundsAnimOffset("x"),a.calculateOverBoundsAnimOffset("y"),!0):(ab("zoomPan"),a.lastNow=Da(),void a.panAnimLoop())},Tb=function(a,b){var c;ea||(pb=m);var d;if("swipe"===a){var g=jb.x-kb.x,h=b.lastFlickDist.x<10;g>eb&&(h||b.lastFlickOffset.x>20)?d=-1:-eb>g&&(h||b.lastFlickOffset.x<-20)&&(d=1)}var j;d&&(m+=d,0>m?(m=i.loop?_b()-1:0,j=!0):m>=_b()&&(m=i.loop?0:_b()-1,j=!0),(!j||i.loop)&&(ta+=d,qa-=d,c=!0));var k,l=sa.x*qa,n=Math.abs(l-sb.x);return c||l>sb.x==b.lastFlickSpeed.x>0?(k=Math.abs(b.lastFlickSpeed.x)>0?n/Math.abs(b.lastFlickSpeed.x):333,k=Math.min(k,400),k=Math.max(k,250)):k=333,pb===m&&(c=!1),ea=!0,Ca("mainScrollAnimStart"),cb("mainScroll",sb.x,l,k,e.easing.cubic.out,Ja,function(){bb(),ea=!1,pb=-1,(c||pb!==m)&&f.updateCurrItem(),Ca("mainScrollAnimComplete")}),c&&f.updateCurrItem(!0),c},Ub=function(a){return 1/ba*a*t},Vb=function(){var a=s,b=Sa(),c=Ta();b>s?a=b:s>c&&(a=c);var d,g=1,h=ia;return ha&&!R&&!ja&&b>s?(f.close(),!0):(ha&&(d=function(a){Ea((g-h)*a+h)}),f.zoomTo(a,0,200,e.easing.cubic.out,d),!0)};ya("Gestures",{publicMethods:{initGestures:function(){var a=function(a,b,c,d,e){A=a+b,B=a+c,C=a+d,D=e?a+e:""};F=N.pointerEvent,F&&N.touch&&(N.touch=!1),F?navigator.pointerEnabled?a("pointer","down","move","up","cancel"):a("MSPointer","Down","Move","Up","Cancel"):N.touch?(a("touch","start","move","end","cancel"),G=!0):a("mouse","down","move","up"),p=B+" "+C+" "+D,q=A,F&&!G&&(G=navigator.maxTouchPoints>1||navigator.msMaxTouchPoints>1),f.likelyTouchDevice=G,r[A]=Nb,r[B]=Ob,r[C]=Qb,D&&(r[D]=r[C]),N.touch&&(q+=" mousedown",p+=" mousemove mouseup",r.mousedown=r[A],r.mousemove=r[B],r.mouseup=r[C]),G||(i.allowPanToNext=!1)}}});var Wb,Xb,Yb,Zb,$b,_b,ac,bc=function(b,c,d,g){Wb&&clearTimeout(Wb),Zb=!0,Yb=!0;var h;b.initialLayout?(h=b.initialLayout,b.initialLayout=null):h=i.getThumbBoundsFn&&i.getThumbBoundsFn(m);var j=d?i.hideAnimationDuration:i.showAnimationDuration,k=function(){_a("initialZoom"),d?(f.template.removeAttribute("style"),f.bg.removeAttribute("style")):(Ea(1),c&&(c.style.display="block"),e.addClass(a,"pswp--animated-in"),Ca("initialZoom"+(d?"OutEnd":"InEnd"))),g&&g(),Zb=!1};if(!j||!h||void 0===h.x)return Ca("initialZoom"+(d?"Out":"In")),s=b.initialZoomLevel,La(oa,b.initialPosition),Ga(),a.style.opacity=d?0:1,Ea(1),void(j?setTimeout(function(){k()},j):k());var n=function(){var c=l,g=!f.currItem.src||f.currItem.loadError||i.showHideOpacity;b.miniImg&&(b.miniImg.style.webkitBackfaceVisibility="hidden"),d||(s=h.w/b.w,oa.x=h.x,oa.y=h.y-K,f[g?"template":"bg"].style.opacity=.001,Ga()),ab("initialZoom"),d&&!c&&e.removeClass(a,"pswp--animated-in"),g&&(d?e[(c?"remove":"add")+"Class"](a,"pswp--animate_opacity"):setTimeout(function(){e.addClass(a,"pswp--animate_opacity")},30)),Wb=setTimeout(function(){if(Ca("initialZoom"+(d?"Out":"In")),d){var f=h.w/b.w,i={x:oa.x,y:oa.y},l=s,m=ia,n=function(b){1===b?(s=f,oa.x=h.x,oa.y=h.y-M):(s=(f-l)*b+l,oa.x=(h.x-i.x)*b+i.x,oa.y=(h.y-M-i.y)*b+i.y),Ga(),g?a.style.opacity=1-b:Ea(m-b*m)};c?cb("initialZoom",0,1,j,e.easing.cubic.out,n,k):(n(1),Wb=setTimeout(k,j+20))}else s=b.initialZoomLevel,La(oa,b.initialPosition),Ga(),Ea(1),g?a.style.opacity=1:Ea(1),Wb=setTimeout(k,j+20)},d?25:90)};n()},cc={},dc=[],ec={index:0,errorMsg:'<div class="pswp__error-msg"><a href="%url%" target="_blank">The image</a> could not be loaded.</div>',forceProgressiveLoading:!1,preload:[1,1],getNumItemsFn:function(){return Xb.length}},fc=function(){return{center:{x:0,y:0},max:{x:0,y:0},min:{x:0,y:0}}},gc=function(a,b,c){var d=a.bounds;d.center.x=Math.round((cc.x-b)/2),d.center.y=Math.round((cc.y-c)/2)+a.vGap.top,d.max.x=b>cc.x?Math.round(cc.x-b):d.center.x,d.max.y=c>cc.y?Math.round(cc.y-c)+a.vGap.top:d.center.y,d.min.x=b>cc.x?0:d.center.x,d.min.y=c>cc.y?a.vGap.top:d.center.y},hc=function(a,b,c){if(a.src&&!a.loadError){var d=!c;if(d&&(a.vGap||(a.vGap={top:0,bottom:0}),Ca("parseVerticalMargin",a)),cc.x=b.x,cc.y=b.y-a.vGap.top-a.vGap.bottom,d){var e=cc.x/a.w,f=cc.y/a.h;a.fitRatio=f>e?e:f;var g=i.scaleMode;"orig"===g?c=1:"fit"===g&&(c=a.fitRatio),c>1&&(c=1),a.initialZoomLevel=c,a.bounds||(a.bounds=fc())}if(!c)return;return gc(a,a.w*c,a.h*c),d&&c===a.initialZoomLevel&&(a.initialPosition=a.bounds.center),a.bounds}return a.w=a.h=0,a.initialZoomLevel=a.fitRatio=1,a.bounds=fc(),a.initialPosition=a.bounds.center,a.bounds},ic=function(a,b,c,d,e,g){b.loadError||d&&(b.imageAppended=!0,lc(b,d,b===f.currItem&&xa),c.appendChild(d),g&&setTimeout(function(){b&&b.loaded&&b.placeholder&&(b.placeholder.style.display="none",b.placeholder=null)},500))},jc=function(a){a.loading=!0,a.loaded=!1;var b=a.img=e.createEl("pswp__img","img"),c=function(){a.loading=!1,a.loaded=!0,a.loadComplete?a.loadComplete(a):a.img=null,b.onload=b.onerror=null,b=null};return b.onload=c,b.onerror=function(){a.loadError=!0,c()},b.src=a.src,b},kc=function(a,b){return a.src&&a.loadError&&a.container?(b&&(a.container.innerHTML=""),a.container.innerHTML=i.errorMsg.replace("%url%",a.src),!0):void 0},lc=function(a,b,c){if(a.src){b||(b=a.container.lastChild);var d=c?a.w:Math.round(a.w*a.fitRatio),e=c?a.h:Math.round(a.h*a.fitRatio);a.placeholder&&!a.loaded&&(a.placeholder.style.width=d+"px",a.placeholder.style.height=e+"px"),b.style.width=d+"px",b.style.height=e+"px"}},mc=function(){if(dc.length){for(var a,b=0;b<dc.length;b++)a=dc[b],a.holder.index===a.index&&ic(a.index,a.item,a.baseDiv,a.img,!1,a.clearPlaceholder);dc=[]}};ya("Controller",{publicMethods:{lazyLoadItem:function(a){a=za(a);var b=$b(a);b&&(!b.loaded&&!b.loading||x)&&(Ca("gettingData",a,b),b.src&&jc(b))},initController:function(){e.extend(i,ec,!0),f.items=Xb=c,$b=f.getItemAt,_b=i.getNumItemsFn,ac=i.loop,_b()<3&&(i.loop=!1),Ba("beforeChange",function(a){var b,c=i.preload,d=null===a?!0:a>=0,e=Math.min(c[0],_b()),g=Math.min(c[1],_b());for(b=1;(d?g:e)>=b;b++)f.lazyLoadItem(m+b);for(b=1;(d?e:g)>=b;b++)f.lazyLoadItem(m-b)}),Ba("initialLayout",function(){f.currItem.initialLayout=i.getThumbBoundsFn&&i.getThumbBoundsFn(m)}),Ba("mainScrollAnimComplete",mc),Ba("initialZoomInEnd",mc),Ba("destroy",function(){for(var a,b=0;b<Xb.length;b++)a=Xb[b],a.container&&(a.container=null),a.placeholder&&(a.placeholder=null),a.img&&(a.img=null),a.preloader&&(a.preloader=null),a.loadError&&(a.loaded=a.loadError=!1);dc=null})},getItemAt:function(a){return a>=0&&void 0!==Xb[a]?Xb[a]:!1},allowProgressiveImg:function(){return i.forceProgressiveLoading||!G||i.mouseUsed||screen.width>1200},setContent:function(a,b){i.loop&&(b=za(b));var c=f.getItemAt(a.index);c&&(c.container=null);var d,g=f.getItemAt(b);if(!g)return void(a.el.innerHTML="");Ca("gettingData",b,g),a.index=b,a.item=g;var h=g.container=e.createEl("pswp__zoom-wrap");if(!g.src&&g.html&&(g.html.tagName?h.appendChild(g.html):h.innerHTML=g.html),kc(g),hc(g,pa),!g.src||g.loadError||g.loaded)g.src&&!g.loadError&&(d=e.createEl("pswp__img","img"),d.style.opacity=1,d.src=g.src,lc(g,d),ic(b,g,h,d,!0));else{if(g.loadComplete=function(c){if(j){if(a&&a.index===b){if(kc(c,!0))return c.loadComplete=c.img=null,hc(c,pa),Ha(c),void(a.index===m&&f.updateCurrZoomItem());c.imageAppended?!Zb&&c.placeholder&&(c.placeholder.style.display="none",c.placeholder=null):N.transform&&(ea||Zb)?dc.push({item:c,baseDiv:h,img:c.img,index:b,holder:a,clearPlaceholder:!0}):ic(b,c,h,c.img,ea||Zb,!0)}c.loadComplete=null,c.img=null,Ca("imageLoadComplete",b,c)}},e.features.transform){var k="pswp__img pswp__img--placeholder";k+=g.msrc?"":" pswp__img--placeholder--blank";var l=e.createEl(k,g.msrc?"img":"");g.msrc&&(l.src=g.msrc),lc(g,l),h.appendChild(l),g.placeholder=l}g.loading||jc(g),f.allowProgressiveImg()&&(!Yb&&N.transform?dc.push({item:g,baseDiv:h,img:g.img,index:b,holder:a}):ic(b,g,h,g.img,!0,!0))}Yb||b!==m?Ha(g):(da=h.style,bc(g,d||g.img)),a.el.innerHTML="",a.el.appendChild(h)},cleanSlide:function(a){a.img&&(a.img.onload=a.img.onerror=null),a.loaded=a.loading=a.img=a.imageAppended=!1}}});var nc,oc={},pc=function(a,b,c){var d=document.createEvent("CustomEvent"),e={origEvent:a,target:a.target,releasePoint:b,pointerType:c||"touch"};d.initCustomEvent("pswpTap",!0,!0,e),a.target.dispatchEvent(d)};ya("Tap",{publicMethods:{initTap:function(){Ba("firstTouchStart",f.onTapStart),Ba("touchRelease",f.onTapRelease),Ba("destroy",function(){oc={},nc=null})},onTapStart:function(a){a.length>1&&(clearTimeout(nc),nc=null)},onTapRelease:function(a,b){if(b&&!X&&!V&&!$a){var c=b;if(nc&&(clearTimeout(nc),nc=null,wb(c,oc)))return void Ca("doubleTap",c);if("mouse"===b.type)return void pc(a,b,"mouse");var d=a.target.tagName.toUpperCase();if("BUTTON"===d||e.hasClass(a.target,"pswp__single-tap"))return void pc(a,b);La(oc,c),nc=setTimeout(function(){pc(a,b),nc=null},300)}}}});var qc;ya("DesktopZoom",{publicMethods:{initDesktopZoom:function(){L||(G?Ba("mouseUsed",function(){f.setupDesktopZoom()}):f.setupDesktopZoom(!0))},setupDesktopZoom:function(b){qc={};var c="wheel mousewheel DOMMouseScroll";Ba("bindEvents",function(){e.bind(a,c,f.handleMouseWheel)}),Ba("unbindEvents",function(){qc&&e.unbind(a,c,f.handleMouseWheel)}),f.mouseZoomedIn=!1;var d,g=function(){f.mouseZoomedIn&&(e.removeClass(a,"pswp--zoomed-in"),f.mouseZoomedIn=!1),1>s?e.addClass(a,"pswp--zoom-allowed"):e.removeClass(a,"pswp--zoom-allowed"),h()},h=function(){d&&(e.removeClass(a,"pswp--dragging"),d=!1)};Ba("resize",g),Ba("afterChange",g),Ba("pointerDown",function(){f.mouseZoomedIn&&(d=!0,e.addClass(a,"pswp--dragging"))}),Ba("pointerUp",h),b||g()},handleMouseWheel:function(a){if(s<=f.currItem.fitRatio)return i.modal&&(!i.closeOnScroll||$a||U?a.preventDefault():E&&Math.abs(a.deltaY)>2&&(l=!0,f.close())),!0;if(a.stopPropagation(),qc.x=0,"deltaX"in a)1===a.deltaMode?(qc.x=18*a.deltaX,qc.y=18*a.deltaY):(qc.x=a.deltaX,qc.y=a.deltaY);else if("wheelDelta"in a)a.wheelDeltaX&&(qc.x=-.16*a.wheelDeltaX),a.wheelDeltaY?qc.y=-.16*a.wheelDeltaY:qc.y=-.16*a.wheelDelta;else{if(!("detail"in a))return;qc.y=a.detail}Ra(s,!0);var b=oa.x-qc.x,c=oa.y-qc.y;(i.modal||b<=ca.min.x&&b>=ca.max.x&&c<=ca.min.y&&c>=ca.max.y)&&a.preventDefault(),f.panTo(b,c)},toggleDesktopZoom:function(b){b=b||{x:pa.x/2+ra.x,y:pa.y/2+ra.y};var c=i.getDoubleTapZoom(!0,f.currItem),d=s===c;f.mouseZoomedIn=!d,f.zoomTo(d?f.currItem.initialZoomLevel:c,b,333),e[(d?"remove":"add")+"Class"](a,"pswp--zoomed-in")}}});var rc,sc,tc,uc,vc,wc,xc,yc,zc,Ac,Bc,Cc,Dc={history:!0,galleryUID:1},Ec=function(){return Bc.hash.substring(1)},Fc=function(){rc&&clearTimeout(rc),tc&&clearTimeout(tc)},Gc=function(){var a=Ec(),b={};if(a.length<5)return b;var c,d=a.split("&");for(c=0;c<d.length;c++)if(d[c]){var e=d[c].split("=");e.length<2||(b[e[0]]=e[1])}if(i.galleryPIDs){var f=b.pid;for(b.pid=0,c=0;c<Xb.length;c++)if(Xb[c].pid===f){b.pid=c;break}}else b.pid=parseInt(b.pid,10)-1;return b.pid<0&&(b.pid=0),b},Hc=function(){if(tc&&clearTimeout(tc),$a||U)return void(tc=setTimeout(Hc,500));uc?clearTimeout(sc):uc=!0;var a=m+1,b=$b(m);b.hasOwnProperty("pid")&&(a=b.pid);var c=xc+"&gid="+i.galleryUID+"&pid="+a;yc||-1===Bc.hash.indexOf(c)&&(Ac=!0);var d=Bc.href.split("#")[0]+"#"+c;Cc?"#"+c!==window.location.hash&&history[yc?"replaceState":"pushState"]("",document.title,d):yc?Bc.replace(d):Bc.hash=c,yc=!0,sc=setTimeout(function(){uc=!1},60)};ya("History",{publicMethods:{initHistory:function(){if(e.extend(i,Dc,!0),i.history){Bc=window.location,Ac=!1,zc=!1,yc=!1,xc=Ec(),Cc="pushState"in history,xc.indexOf("gid=")>-1&&(xc=xc.split("&gid=")[0],xc=xc.split("?gid=")[0]),Ba("afterChange",f.updateURL),Ba("unbindEvents",function(){e.unbind(window,"hashchange",f.onHashChange)});var a=function(){wc=!0,zc||(Ac?history.back():xc?Bc.hash=xc:Cc?history.pushState("",document.title,Bc.pathname+Bc.search):Bc.hash=""),Fc()};Ba("unbindEvents",function(){l&&a()}),Ba("destroy",function(){wc||a()}),Ba("firstUpdate",function(){m=Gc().pid});var b=xc.indexOf("pid=");b>-1&&(xc=xc.substring(0,b),"&"===xc.slice(-1)&&(xc=xc.slice(0,-1))),setTimeout(function(){j&&e.bind(window,"hashchange",f.onHashChange)},40)}},onHashChange:function(){return Ec()===xc?(zc=!0,void f.close()):void(uc||(vc=!0,f.goTo(Gc().pid),vc=!1))},updateURL:function(){Fc(),vc||(yc?rc=setTimeout(Hc,800):Hc())}}}),e.extend(f,db)};return a});
 
diff --git a/themes/bookstack/static/libs/sql-wasm.js b/themes/bookstack/static/libs/sql-wasm.js
new file mode 100644 (file)
index 0000000..b234f6b
--- /dev/null
@@ -0,0 +1,8 @@
+
+// sql.js 1.10.1
+// Copyright (c) 2017 sql.js authors (see AUTHORS)
+// https://github.com/sql-js/sql.js/blob/master/LICENSE
+// https://github.com/sql-js/sql.js/blob/master/AUTHORS
+// MIT license
+// Fetched via cdnjs: https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.10.1/sql-wasm.min.js
+var initSqlJsPromise=void 0,initSqlJs=function(Dt){return initSqlJsPromise=initSqlJsPromise||new Promise(function(A,I){var B,S,x,O,G,R,a,e=void 0!==Dt?Dt:{},H=e.onAbort,t=(e.onAbort=function(e){I(new Error(e)),H&&H(e)},e.postRun=e.postRun||[],e.postRun.push(function(){A(e)}),module=void 0,(B||=void 0!==e?e:{}).onRuntimeInitialized=function(){function u(e,t){switch(typeof t){case"boolean":C(e,t?1:0);break;case"number":W(e,t);break;case"string":J(e,t,-1,-1);break;case"object":var r;null===t?R(e):null!=t.length?(r=Mt(t,kt),K(e,r,t.length,-1),Ht(r)):H(e,"Wrong API use : tried to return a value of an unknown type ("+t+").",-1);break;default:R(e)}}function l(e,t){for(var r=[],n=0;n<e;n+=1){var i=Y(t+4*n,"i32");if(1===(a=D(i))||2===a)i=F(i);else if(3===a)i=U(i);else if(4===a){for(var i=P(a=i),a=z(a),o=new Uint8Array(i),s=0;s<i;s+=1)o[s]=Q[a+s];i=o}else i=null;r.push(i)}return r}function f(e,t){this.La=e,this.db=t,this.Ja=1,this.fb=[]}function t(e,t){if(this.db=t,t=$(e)+1,this.Ya=Rt(t),null===this.Ya)throw Error("Unable to allocate memory for the SQL string");Z(e,V,this.Ya,t),this.eb=this.Ya,this.Ua=this.ib=null}function e(e){if(this.filename="dbfile_"+(4294967295*Math.random()>>>0),null!=e){var t=this.filename,r=t;if((n="/")&&(n="string"==typeof n?n:He(n),r=t?X(n+"/"+t):n),r=Ke(r,4095&(void 0!==(t=Ae(!0,!0))?t:438)|32768,0),e){if("string"==typeof e){for(var n=Array(e.length),i=0,a=e.length;i<a;++i)n[i]=e.charCodeAt(i);e=n}Ze(r,146|t),it(n=ee(r,577),e,0,e.length,0),tt(n),Ze(r,t)}}this.handleError(o(this.filename,h)),this.db=Y(h,"i32"),N(this.db),this.Za={},this.Na={}}var h=re(4),r=B.cwrap,o=r("sqlite3_open","number",["string","number"]),n=r("sqlite3_close_v2","number",["number"]),i=r("sqlite3_exec","number",["number","string","number","number","number"]),a=r("sqlite3_changes","number",["number"]),s=r("sqlite3_prepare_v2","number",["number","string","number","number","number"]),c=r("sqlite3_sql","string",["number"]),d=r("sqlite3_normalized_sql","string",["number"]),b=r("sqlite3_prepare_v2","number",["number","number","number","number","number"]),m=r("sqlite3_bind_text","number",["number","number","number","number","number"]),p=r("sqlite3_bind_blob","number",["number","number","number","number","number"]),w=r("sqlite3_bind_double","number",["number","number","number"]),_=r("sqlite3_bind_int","number",["number","number","number"]),v=r("sqlite3_bind_parameter_index","number",["number","string"]),y=r("sqlite3_step","number",["number"]),g=r("sqlite3_errmsg","string",["number"]),q=r("sqlite3_column_count","number",["number"]),E=r("sqlite3_data_count","number",["number"]),k=r("sqlite3_column_double","number",["number","number"]),M=r("sqlite3_column_text","string",["number","number"]),A=r("sqlite3_column_blob","number",["number","number"]),I=r("sqlite3_column_bytes","number",["number","number"]),S=r("sqlite3_column_type","number",["number","number"]),x=r("sqlite3_column_name","string",["number","number"]),O=r("sqlite3_reset","number",["number"]),j=r("sqlite3_clear_bindings","number",["number"]),T=r("sqlite3_finalize","number",["number"]),G=r("sqlite3_create_function_v2","number","number string number number number number number number number".split(" ")),D=r("sqlite3_value_type","number",["number"]),P=r("sqlite3_value_bytes","number",["number"]),U=r("sqlite3_value_text","string",["number"]),z=r("sqlite3_value_blob","number",["number"]),F=r("sqlite3_value_double","number",["number"]),W=r("sqlite3_result_double","",["number","number"]),R=r("sqlite3_result_null","",["number"]),J=r("sqlite3_result_text","",["number","string","number","number"]),K=r("sqlite3_result_blob","",["number","number","number","number"]),C=r("sqlite3_result_int","",["number","number"]),H=r("sqlite3_result_error","",["number","string","number"]),L=r("sqlite3_aggregate_context","number",["number","number"]),N=r("RegisterExtensionFunctions","number",["number"]);f.prototype.bind=function(e){if(this.La)return this.reset(),Array.isArray(e)?this.wb(e):null==e||"object"!=typeof e||this.xb(e);throw"Statement closed"},f.prototype.step=function(){if(!this.La)throw"Statement closed";this.Ja=1;var e=y(this.La);switch(e){case 100:return!0;case 101:return!1;default:throw this.db.handleError(e)}},f.prototype.rb=function(e){return null==e&&(e=this.Ja,this.Ja+=1),k(this.La,e)},f.prototype.Ab=function(e){if(null==e&&(e=this.Ja,this.Ja+=1),e=M(this.La,e),"function"!=typeof BigInt)throw Error("BigInt is not supported");return BigInt(e)},f.prototype.Bb=function(e){return null==e&&(e=this.Ja,this.Ja+=1),M(this.La,e)},f.prototype.getBlob=function(e){null==e&&(e=this.Ja,this.Ja+=1);var t=I(this.La,e);e=A(this.La,e);for(var r=new Uint8Array(t),n=0;n<t;n+=1)r[n]=Q[e+n];return r},f.prototype.get=function(e,t){t=t||{},null!=e&&this.bind(e)&&this.step(),e=[];for(var r=E(this.La),n=0;n<r;n+=1)switch(S(this.La,n)){case 1:var i=t.useBigInt?this.Ab(n):this.rb(n);e.push(i);break;case 2:e.push(this.rb(n));break;case 3:e.push(this.Bb(n));break;case 4:e.push(this.getBlob(n));break;default:e.push(null)}return e},f.prototype.getColumnNames=function(){for(var e=[],t=q(this.La),r=0;r<t;r+=1)e.push(x(this.La,r));return e},f.prototype.getAsObject=function(e,t){e=this.get(e,t),t=this.getColumnNames();for(var r={},n=0;n<t.length;n+=1)r[t[n]]=e[n];return r},f.prototype.getSQL=function(){return c(this.La)},f.prototype.getNormalizedSQL=function(){return d(this.La)},f.prototype.run=function(e){return null!=e&&this.bind(e),this.step(),this.reset()},f.prototype.nb=function(e,t){null==t&&(t=this.Ja,this.Ja+=1),e=ge(e);var r=Mt(e,kt);this.fb.push(r),this.db.handleError(m(this.La,t,r,e.length-1,0))},f.prototype.vb=function(e,t){null==t&&(t=this.Ja,this.Ja+=1);var r=Mt(e,kt);this.fb.push(r),this.db.handleError(p(this.La,t,r,e.length,0))},f.prototype.mb=function(e,t){null==t&&(t=this.Ja,this.Ja+=1),this.db.handleError((e===(0|e)?_:w)(this.La,t,e))},f.prototype.yb=function(e){null==e&&(e=this.Ja,this.Ja+=1),p(this.La,e,0,0,0)},f.prototype.ob=function(e,t){switch(null==t&&(t=this.Ja,this.Ja+=1),typeof e){case"string":return void this.nb(e,t);case"number":return void this.mb(e,t);case"bigint":return void this.nb(e.toString(),t);case"boolean":return void this.mb(e+0,t);case"object":if(null===e)return void this.yb(t);if(null!=e.length)return void this.vb(e,t)}throw"Wrong API use : tried to bind a value of an unknown type ("+e+")."},f.prototype.xb=function(r){var n=this;return Object.keys(r).forEach(function(e){var t=v(n.La,e);0!==t&&n.ob(r[e],t)}),!0},f.prototype.wb=function(e){for(var t=0;t<e.length;t+=1)this.ob(e[t],t+1);return!0},f.prototype.reset=function(){return this.freemem(),0===j(this.La)&&0===O(this.La)},f.prototype.freemem=function(){for(var e;void 0!==(e=this.fb.pop());)Ht(e)},f.prototype.free=function(){this.freemem();var e=0===T(this.La);return delete this.db.Za[this.La],this.La=0,e},t.prototype.next=function(){if(null===this.Ya)return{done:!0};if(null!==this.Ua&&(this.Ua.free(),this.Ua=null),!this.db.db)throw this.gb(),Error("Database closed");var e=Nt(),t=re(4);ce(h),ce(t);try{this.db.handleError(b(this.db.db,this.eb,-1,h,t)),this.eb=Y(t,"i32");var r=Y(h,"i32");return 0===r?(this.gb(),{done:!0}):(this.Ua=new f(r,this.db),this.db.Za[r]=this.Ua,{value:this.Ua,done:!1})}catch(e){throw this.ib=be(this.eb),this.gb(),e}finally{jt(e)}},t.prototype.gb=function(){Ht(this.Ya),this.Ya=null},t.prototype.getRemainingSQL=function(){return null!==this.ib?this.ib:be(this.eb)},"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator&&(t.prototype[Symbol.iterator]=function(){return this}),e.prototype.run=function(e,t){if(!this.db)throw"Database closed";if(t){e=this.prepare(e,t);try{e.step()}finally{e.free()}}else this.handleError(i(this.db,e,0,0,h));return this},e.prototype.exec=function(e,t,r){if(!this.db)throw"Database closed";var n=Nt(),i=null;try{var a=Et(e),o=re(4);for(e=[];0!==Y(a,"i8");){ce(h),ce(o),this.handleError(b(this.db,a,-1,h,o));var s=Y(h,"i32"),a=Y(o,"i32");if(0!==s){var u=null,i=new f(s,this);for(null!=t&&i.bind(t);i.step();)null===u&&(u={columns:i.getColumnNames(),values:[]},e.push(u)),u.values.push(i.get(null,r));i.free()}}return e}catch(e){throw i&&i.free(),e}finally{jt(n)}},e.prototype.each=function(e,t,r,n,i){"function"==typeof t&&(n=r,r=t,t=void 0),e=this.prepare(e,t);try{for(;e.step();)r(e.getAsObject(null,i))}finally{e.free()}if("function"==typeof n)return n()},e.prototype.prepare=function(e,t){if(ce(h),this.handleError(s(this.db,e,-1,h,0)),0===(e=Y(h,"i32")))throw"Nothing to prepare";var r=new f(e,this);return null!=t&&r.bind(t),this.Za[e]=r},e.prototype.iterateStatements=function(e){return new t(e,this)},e.prototype.export=function(){Object.values(this.Za).forEach(function(e){e.free()}),Object.values(this.Na).forEach(te),this.Na={},this.handleError(n(this.db));e=this.filename,t=ee(e,0),e=Xe(e).size,r=new Uint8Array(e),nt(t,r,0,e,0),e=r,tt(t);var e,t,r=e;return this.handleError(o(this.filename,h)),this.db=Y(h,"i32"),N(this.db),r},e.prototype.close=function(){null!==this.db&&(Object.values(this.Za).forEach(function(e){e.free()}),Object.values(this.Na).forEach(te),this.Na={},this.handleError(n(this.db)),Ve("/"+this.filename),this.db=null)},e.prototype.handleError=function(e){if(0===e)return null;throw e=g(this.db),Error(e)},e.prototype.getRowsModified=function(){return a(this.db)},e.prototype.create_function=function(e,i){Object.prototype.hasOwnProperty.call(this.Na,e)&&(te(this.Na[e]),delete this.Na[e]);var t=It(function(t,e,r){e=l(e,r);try{var n=i.apply(null,e)}catch(e){return void H(t,e,-1)}u(t,n)},"viii");return this.Na[e]=t,this.handleError(G(this.db,e,i.length,1,0,t,0,0,0)),this},e.prototype.create_aggregate=function(e,t){var i=t.init||function(){return null},n=t.finalize||function(e){return e},a=t.step;if(!a)throw"An aggregate function must have a step function in "+e;var o={},r=(Object.hasOwnProperty.call(this.Na,e)&&(te(this.Na[e]),delete this.Na[e]),t=e+"__finalize",Object.hasOwnProperty.call(this.Na,t)&&(te(this.Na[t]),delete this.Na[t]),It(function(t,e,r){var n=L(t,1);Object.hasOwnProperty.call(o,n)||(o[n]=i()),e=l(e,r),e=[o[n]].concat(e);try{o[n]=a.apply(null,e)}catch(e){delete o[n],H(t,e,-1)}},"viii")),s=It(function(t){var r=L(t,1);try{var e=n(o[r])}catch(e){return delete o[r],void H(t,e,-1)}u(t,e),delete o[r]},"vi");return this.Na[e]=r,this.Na[t]=s,this.handleError(G(this.db,e,a.length-1,1,0,0,r,s,0)),this},B.Database=e},Object.assign({},B)),L="./this.program",N="object"==typeof window,j="function"==typeof importScripts,T="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,r="",D=(T?(S=require("fs"),x=require("path"),r=j?x.dirname(r)+"/":__dirname+"/",O=(e,t)=>(e=ue(e)?new URL(e):x.normalize(e),S.readFileSync(e,t?void 0:"utf8")),G=e=>e=(e=O(e,!0)).buffer?e:new Uint8Array(e),R=(e,r,n,i=!0)=>{e=ue(e)?new URL(e):x.normalize(e),S.readFile(e,i?void 0:"utf8",(e,t)=>{e?n(e):r(i?t.buffer:t)})},!B.thisProgram&&1<process.argv.length&&(L=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2),"undefined"!=typeof module&&(module.exports=B),B.inspect=()=>"[Emscripten Module object]"):(N||j)&&(j?r=self.location.href:"undefined"!=typeof document&&document.currentScript&&(r=document.currentScript.src),r=0!==r.indexOf("blob:")?r.substr(0,r.replace(/[?#].*/,"").lastIndexOf("/")+1):"",O=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),t.responseText},j&&(G=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),R=(e,t,r)=>{var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=()=>{200==n.status||0==n.status&&n.response?t(n.response):r()},n.onerror=r,n.send(null)}),B.print||console.log.bind(console)),o=B.printErr||console.error.bind(console);Object.assign(B,t),B.thisProgram&&(L=B.thisProgram),B.wasmBinary&&(a=B.wasmBinary),"object"!=typeof WebAssembly&&i("no native wasm support detected");var P,Q,V,U,h,c,z,F,W=!1;function J(){var e=P.buffer;B.HEAP8=Q=new Int8Array(e),B.HEAP16=U=new Int16Array(e),B.HEAPU8=V=new Uint8Array(e),B.HEAPU16=new Uint16Array(e),B.HEAP32=h=new Int32Array(e),B.HEAPU32=c=new Uint32Array(e),B.HEAPF32=z=new Float32Array(e),B.HEAPF64=F=new Float64Array(e)}var K=[],C=[],ne=[];var s=0,ie=null,ae=null;function i(e){throw B.onAbort?.(e),o(e="Aborted("+e+")"),W=!0,new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info.")}var oe,se=e=>e.startsWith("data:application/octet-stream;base64,"),ue=e=>e.startsWith("file://");function le(e){if(e==oe&&a)return new Uint8Array(a);if(G)return G(e);throw"both async and sync fetching of the wasm failed"}function fe(e,t,r){return function(r){if(!a&&(N||j)){if("function"==typeof fetch&&!ue(r))return fetch(r,{credentials:"same-origin"}).then(e=>{if(e.ok)return e.arrayBuffer();throw"failed to load wasm binary file at '"+r+"'"}).catch(()=>le(r));if(R)return new Promise((t,e)=>{R(r,e=>t(new Uint8Array(e)),e)})}return Promise.resolve().then(()=>le(r))}(e).then(e=>WebAssembly.instantiate(e,t)).then(e=>e).then(r,e=>{o("failed to asynchronously prepare wasm: "+e),i(e)})}se(oe="sql-wasm.wasm")||(t=oe,oe=B.locateFile?B.locateFile(t,r):r+t);var u,l,he=e=>{for(;0<e.length;)e.shift()(B)};function Y(e,t="i8"){switch(t=t.endsWith("*")?"*":t){case"i1":case"i8":return Q[e>>0];case"i16":return U[e>>1];case"i32":return h[e>>2];case"i64":i("to do getValue(i64) use WASM_BIGINT");case"float":return z[e>>2];case"double":return F[e>>3];case"*":return c[e>>2];default:i("invalid type for getValue: "+t)}}function ce(e){var t="i32";switch(t=t.endsWith("*")?"*":t){case"i1":case"i8":Q[e>>0]=0;break;case"i16":U[e>>1]=0;break;case"i32":h[e>>2]=0;break;case"i64":i("to do setValue(i64) use WASM_BIGINT");case"float":z[e>>2]=0;break;case"double":F[e>>3]=0;break;case"*":c[e>>2]=0;break;default:i("invalid type for setValue: "+t)}}var de="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0,d=(e,t,r)=>{var n=t+r;for(r=t;e[r]&&!(n<=r);)++r;if(16<r-t&&e.buffer&&de)return de.decode(e.subarray(t,r));for(n="";t<r;){var i,a,o=e[t++];128&o?(i=63&e[t++],192==(224&o)?n+=String.fromCharCode((31&o)<<6|i):(a=63&e[t++],(o=224==(240&o)?(15&o)<<12|i<<6|a:(7&o)<<18|i<<12|a<<6|63&e[t++])<65536?n+=String.fromCharCode(o):(o-=65536,n+=String.fromCharCode(55296|o>>10,56320|1023&o)))):n+=String.fromCharCode(o)}return n},be=(e,t)=>e?d(V,e,t):"",me=(e,t)=>{for(var r=0,n=e.length-1;0<=n;n--){var i=e[n];"."===i?e.splice(n,1):".."===i?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r;r--)e.unshift("..");return e},X=e=>{var t="/"===e.charAt(0),r="/"===e.substr(-1);return(e=(e=me(e.split("/").filter(e=>!!e),!t).join("/"))||t?e:".")&&r&&(e+="/"),(t?"/":"")+e},pe=e=>{var t=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(e).slice(1);return e=t[0],t=t[1],e||t?e+(t&&=t.substr(0,t.length-1)):"."},we=e=>{if("/"===e)return"/";var t=(e=(e=X(e)).replace(/\/$/,"")).lastIndexOf("/");return-1===t?e:e.substr(t+1)},_e=e=>(_e=(()=>{if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues)return e=>crypto.getRandomValues(e);if(T)try{var t=require("crypto");if(t.randomFillSync)return e=>t.randomFillSync(e);var r=t.randomBytes;return e=>(e.set(r(e.byteLength)),e)}catch(e){}i("initRandomDevice")})())(e);function ve(){for(var e="",t=!1,r=arguments.length-1;-1<=r&&!t;r--){if("string"!=typeof(t=0<=r?arguments[r]:"/"))throw new TypeError("Arguments to path.resolve must be strings");if(!t)return"";e=t+"/"+e,t="/"===t.charAt(0)}return(t?"/":"")+(e=me(e.split("/").filter(e=>!!e),!t).join("/"))||"."}var ye=[],$=e=>{for(var t=0,r=0;r<e.length;++r){var n=e.charCodeAt(r);n<=127?t++:n<=2047?t+=2:55296<=n&&n<=57343?(t+=4,++r):t+=3}return t},Z=(e,t,r,n)=>{if(!(0<n))return 0;var i=r;n=r+n-1;for(var a=0;a<e.length;++a){var o=e.charCodeAt(a);if((o=55296<=o&&o<=57343?65536+((1023&o)<<10)|1023&e.charCodeAt(++a):o)<=127){if(n<=r)break;t[r++]=o}else{if(o<=2047){if(n<=r+1)break;t[r++]=192|o>>6}else{if(o<=65535){if(n<=r+2)break;t[r++]=224|o>>12}else{if(n<=r+3)break;t[r++]=240|o>>18,t[r++]=128|o>>12&63}t[r++]=128|o>>6&63}t[r++]=128|63&o}}return t[r]=0,r-i};function ge(e,t){var r=Array($(e)+1);return e=Z(e,r,0,r.length),t&&(r.length=e),r}var qe=[];function Ee(e,t){qe[e]={input:[],output:[],Xa:t},We(e,ke)}var ke={open(e){var t=qe[e.node.rdev];if(!t)throw new m(43);e.tty=t,e.seekable=!1},close(e){e.tty.Xa.fsync(e.tty)},fsync(e){e.tty.Xa.fsync(e.tty)},read(e,t,r,n){if(!e.tty||!e.tty.Xa.sb)throw new m(60);for(var i=0,a=0;a<n;a++){try{var o=e.tty.Xa.sb(e.tty)}catch(e){throw new m(29)}if(void 0===o&&0===i)throw new m(6);if(null==o)break;i++,t[r+a]=o}return i&&(e.node.timestamp=Date.now()),i},write(e,t,r,n){if(!e.tty||!e.tty.Xa.jb)throw new m(60);try{for(var i=0;i<n;i++)e.tty.Xa.jb(e.tty,t[r+i])}catch(e){throw new m(29)}return n&&(e.node.timestamp=Date.now()),i}},r={sb(){e:{if(!ye.length){var e=null;if(T){var t=Buffer.alloc(256),r=0,n=process.stdin.fd;try{r=S.readSync(n,t)}catch(e){if(!e.toString().includes("EOF"))throw e;r=0}e=0<r?t.slice(0,r).toString("utf-8"):null}else"undefined"!=typeof window&&"function"==typeof window.prompt?null!==(e=window.prompt("Input: "))&&(e+="\n"):"function"==typeof readline&&(null!==(e=readline())&&(e+="\n"));if(!e){e=null;break e}ye=ge(e,!0)}e=ye.shift()}return e},jb(e,t){null===t||10===t?(D(d(e.output,0)),e.output=[]):0!=t&&e.output.push(t)},fsync(e){e.output&&0<e.output.length&&(D(d(e.output,0)),e.output=[])},Mb(){return{Ib:25856,Kb:5,Hb:191,Jb:35387,Gb:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},Nb(){return 0},Ob(){return[24,80]}},t={jb(e,t){null===t||10===t?(o(d(e.output,0)),e.output=[]):0!=t&&e.output.push(t)},fsync(e){e.output&&0<e.output.length&&(o(d(e.output,0)),e.output=[])}};function Me(e,t){var r=e.Ia?e.Ia.length:0;t<=r||(t=Math.max(t,r*(r<1048576?2:1.125)>>>0),0!=r&&(t=Math.max(t,256)),r=e.Ia,e.Ia=new Uint8Array(t),0<e.Ma&&e.Ia.set(r.subarray(0,e.Ma),0))}var f={Qa:null,Ra(){return f.createNode(null,"/",16895,0)},createNode(e,t,r,n){if(24576==(61440&r)||4096==(61440&r))throw new m(63);return f.Qa||(f.Qa={dir:{node:{Pa:f.Ga.Pa,Oa:f.Ga.Oa,lookup:f.Ga.lookup,ab:f.Ga.ab,rename:f.Ga.rename,unlink:f.Ga.unlink,rmdir:f.Ga.rmdir,readdir:f.Ga.readdir,symlink:f.Ga.symlink},stream:{Ta:f.Ha.Ta}},file:{node:{Pa:f.Ga.Pa,Oa:f.Ga.Oa},stream:{Ta:f.Ha.Ta,read:f.Ha.read,write:f.Ha.write,lb:f.Ha.lb,bb:f.Ha.bb,cb:f.Ha.cb}},link:{node:{Pa:f.Ga.Pa,Oa:f.Ga.Oa,readlink:f.Ga.readlink},stream:{}},pb:{node:{Pa:f.Ga.Pa,Oa:f.Ga.Oa},stream:Fe}}),_((r=je(e,t,r,n)).mode)?(r.Ga=f.Qa.dir.node,r.Ha=f.Qa.dir.stream,r.Ia={}):32768==(61440&r.mode)?(r.Ga=f.Qa.file.node,r.Ha=f.Qa.file.stream,r.Ma=0,r.Ia=null):40960==(61440&r.mode)?(r.Ga=f.Qa.link.node,r.Ha=f.Qa.link.stream):8192==(61440&r.mode)&&(r.Ga=f.Qa.pb.node,r.Ha=f.Qa.pb.stream),r.timestamp=Date.now(),e&&(e.Ia[t]=r,e.timestamp=r.timestamp),r},Lb(e){return e.Ia?e.Ia.subarray?e.Ia.subarray(0,e.Ma):new Uint8Array(e.Ia):new Uint8Array(0)},Ga:{Pa(e){var t={};return t.dev=8192==(61440&e.mode)?e.id:1,t.ino=e.id,t.mode=e.mode,t.nlink=1,t.uid=0,t.gid=0,t.rdev=e.rdev,_(e.mode)?t.size=4096:32768==(61440&e.mode)?t.size=e.Ma:40960==(61440&e.mode)?t.size=e.link.length:t.size=0,t.atime=new Date(e.timestamp),t.mtime=new Date(e.timestamp),t.ctime=new Date(e.timestamp),t.zb=4096,t.blocks=Math.ceil(t.size/t.zb),t},Oa(e,t){var r;void 0!==t.mode&&(e.mode=t.mode),void 0!==t.timestamp&&(e.timestamp=t.timestamp),void 0!==t.size&&(t=t.size,e.Ma!=t)&&(0==t?(e.Ia=null,e.Ma=0):(r=e.Ia,e.Ia=new Uint8Array(t),r&&e.Ia.set(r.subarray(0,Math.min(t,e.Ma))),e.Ma=t))},lookup(){throw Re[44]},ab(e,t,r,n){return f.createNode(e,t,r,n)},rename(e,t,r){if(_(e.mode)){try{var n=w(t,r)}catch(e){}if(n)for(var i in n.Ia)throw new m(55)}delete e.parent.Ia[e.name],e.parent.timestamp=Date.now(),e.name=r,t.Ia[r]=e,t.timestamp=e.parent.timestamp,e.parent=t},unlink(e,t){delete e.Ia[t],e.timestamp=Date.now()},rmdir(e,t){for(var r in w(e,t).Ia)throw new m(55);delete e.Ia[t],e.timestamp=Date.now()},readdir(e){var t,r=[".",".."];for(t of Object.keys(e.Ia))r.push(t);return r},symlink(e,t,r){return(e=f.createNode(e,t,41471,0)).link=r,e},readlink(e){if(40960!=(61440&e.mode))throw new m(28);return e.link}},Ha:{read(e,t,r,n,i){var a=e.node.Ia;if(i>=e.node.Ma)return 0;if(8<(e=Math.min(e.node.Ma-i,n))&&a.subarray)t.set(a.subarray(i,i+e),r);else for(n=0;n<e;n++)t[r+n]=a[i+n];return e},write(e,t,r,n,i,a){if(t.buffer===Q.buffer&&(a=!1),!n)return 0;if((e=e.node).timestamp=Date.now(),t.subarray&&(!e.Ia||e.Ia.subarray)){if(a)return e.Ia=t.subarray(r,r+n),e.Ma=n;if(0===e.Ma&&0===i)return e.Ia=t.slice(r,r+n),e.Ma=n;if(i+n<=e.Ma)return e.Ia.set(t.subarray(r,r+n),i),n}if(Me(e,i+n),e.Ia.subarray&&t.subarray)e.Ia.set(t.subarray(r,r+n),i);else for(a=0;a<n;a++)e.Ia[i+a]=t[r+a];return e.Ma=Math.max(e.Ma,i+n),n},Ta(e,t,r){if(1===r?t+=e.position:2===r&&32768==(61440&e.node.mode)&&(t+=e.node.Ma),t<0)throw new m(28);return t},lb(e,t,r){Me(e.node,t+r),e.node.Ma=Math.max(e.node.Ma,t+r)},bb(e,t,r,n,i){if(32768!=(61440&e.node.mode))throw new m(43);if(e=e.node.Ia,2&i||e.buffer!==Q.buffer){if((0<r||r+t<e.length)&&(e=e.subarray?e.subarray(r,r+t):Array.prototype.slice.call(e,r,r+t)),r=!0,t=65536*Math.ceil(t/65536),!(t=(i=Lt(65536,t))?(V.fill(0,i,i+t),i):0))throw new m(48);Q.set(e,t)}else r=!1,t=e.byteOffset;return{Db:t,ub:r}},cb(e,t,r,n){return f.Ha.write(e,t,0,n,r,!1),0}}},Ae=(e,t)=>{var r=0;return e&&(r|=365),t&&(r|=146),r},Ie=null,Se={},xe=[],Oe=1,b=null,Ge=!0,m=null,Re={};function p(e,t={}){if(!(e=ve(e)))return{path:"",node:null};if(8<(t=Object.assign({qb:!0,kb:0},t)).kb)throw new m(32);e=e.split("/").filter(e=>!!e);for(var r=Ie,n="/",i=0;i<e.length;i++){var a=i===e.length-1;if(a&&t.parent)break;if(r=w(r,e[i]),n=X(n+"/"+e[i]),!r.Va||a&&!t.qb||(r=r.Va.root),!a||t.Sa)for(a=0;40960==(61440&r.mode);)if(r=Ye(n),r=p(n=ve(pe(n),r),{kb:t.kb+1}).node,40<a++)throw new m(32)}return{path:n,node:r}}function He(e){for(var t;;){if(e===e.parent)return e=e.Ra.tb,t?"/"!==e[e.length-1]?e+"/"+t:e+t:e;t=t?e.name+"/"+t:e.name,e=e.parent}}function Le(e,t){for(var r=0,n=0;n<t.length;n++)r=(r<<5)-r+t.charCodeAt(n)|0;return(e+r>>>0)%b.length}function Ne(e){var t=Le(e.parent.id,e.name);if(b[t]===e)b[t]=e.Wa;else for(t=b[t];t;){if(t.Wa===e){t.Wa=e.Wa;break}t=t.Wa}}function w(e,t){var r;if(r=(r=v(e,"x"))?r:e.Ga.lookup?0:2)throw new m(r,e);for(r=b[Le(e.id,t)];r;r=r.Wa){var n=r.name;if(r.parent.id===e.id&&n===t)return r}return e.Ga.lookup(e,t)}function je(e,t,r,n){return t=Le((e=new St(e,t,r,n)).parent.id,e.name),e.Wa=b[t],b[t]=e}function _(e){return 16384==(61440&e)}function Te(e){var t=["r","w","rw"][3&e];return 512&e&&(t+="w"),t}function v(e,t){return!Ge&&(t.includes("r")&&!(292&e.mode)||t.includes("w")&&!(146&e.mode)||t.includes("x")&&!(73&e.mode))?2:0}function De(e,t){try{return w(e,t),20}catch(e){}return v(e,"wx")}function Pe(e,t,r){try{var n=w(e,t)}catch(e){return e.Ka}if(e=v(e,"wx"))return e;if(r){if(!_(n.mode))return 54;if(n===n.parent||"/"===He(n))return 10}else if(_(n.mode))return 31;return 0}function y(e){if(e=xe[e])return e;throw new m(8)}function Ue(e,t=-1){return ut||((ut=function(){this.$a={}}).prototype={},Object.defineProperties(ut.prototype,{object:{get(){return this.node},set(e){this.node=e}},flags:{get(){return this.$a.flags},set(e){this.$a.flags=e}},position:{get(){return this.$a.position},set(e){this.$a.position=e}}})),e=Object.assign(new ut,e),-1==t&&(t=function(){for(var e=0;e<=4096;e++)if(!xe[e])return e;throw new m(33)}()),e.fd=t,xe[t]=e}var ze,Fe={open(e){e.Ha=Se[e.node.rdev].Ha,e.Ha.open?.(e)},Ta(){throw new m(70)}};function We(e,t){Se[e]={Ha:t}}function Je(e,t){var r="/"===t,n=!t;if(r&&Ie)throw new m(10);if(!r&&!n){var i=p(t,{qb:!1});if(t=i.path,(i=i.node).Va)throw new m(10);if(!_(i.mode))throw new m(54)}((e=e.Ra(t={type:e,Pb:{},tb:t,Cb:[]})).Ra=t).root=e,r?Ie=e:i&&(i.Va=t,i.Ra&&i.Ra.Cb.push(t))}function Ke(e,t,r){var n=p(e,{parent:!0}).node;if(!(e=we(e))||"."===e||".."===e)throw new m(28);var i=De(n,e);if(i)throw new m(i);if(n.Ga.ab)return n.Ga.ab(n,e,t,r);throw new m(63)}function n(e,t){return Ke(e,1023&(void 0!==t?t:511)|16384,0)}function Ce(e,t,r){void 0===r&&(r=t,t=438),Ke(e,8192|t,r)}function Be(e,t){if(!ve(e))throw new m(44);var r=p(t,{parent:!0}).node;if(!r)throw new m(44);var n=De(r,t=we(t));if(n)throw new m(n);if(!r.Ga.symlink)throw new m(63);r.Ga.symlink(r,t,e)}function Qe(e){var t=p(e,{parent:!0}).node,r=w(t,e=we(e)),n=Pe(t,e,!0);if(n)throw new m(n);if(!t.Ga.rmdir)throw new m(63);if(r.Va)throw new m(10);t.Ga.rmdir(t,e),Ne(r)}function Ve(e){var t=p(e,{parent:!0}).node;if(!t)throw new m(44);var r=w(t,e=we(e)),n=Pe(t,e,!1);if(n)throw new m(n);if(!t.Ga.unlink)throw new m(63);if(r.Va)throw new m(10);t.Ga.unlink(t,e),Ne(r)}function Ye(e){if(!(e=p(e).node))throw new m(44);if(e.Ga.readlink)return ve(He(e.parent),e.Ga.readlink(e));throw new m(28)}function Xe(e,t){if(!(e=p(e,{Sa:!t}).node))throw new m(44);if(e.Ga.Pa)return e.Ga.Pa(e);throw new m(63)}function $e(e){return Xe(e,!0)}function Ze(e,t){if(!(e="string"==typeof e?p(e,{Sa:!0}).node:e).Ga.Oa)throw new m(63);e.Ga.Oa(e,{mode:4095&t|-4096&e.mode,timestamp:Date.now()})}function et(e,t){if(t<0)throw new m(28);if(!(e="string"==typeof e?p(e,{Sa:!0}).node:e).Ga.Oa)throw new m(63);if(_(e.mode))throw new m(31);if(32768!=(61440&e.mode))throw new m(28);var r=v(e,"w");if(r)throw new m(r);e.Ga.Oa(e,{size:t,timestamp:Date.now()})}function ee(e,t,r){if(""===e)throw new m(44);if("string"==typeof t){var n={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090}[t];if(void 0===n)throw Error("Unknown file open mode: "+t);t=n}if(r=64&t?4095&(void 0===r?438:r)|32768:0,"object"==typeof e)var i=e;else{e=X(e);try{i=p(e,{Sa:!(131072&t)}).node}catch(e){}}if(n=!1,64&t)if(i){if(128&t)throw new m(20)}else i=Ke(e,r,0),n=!0;if(!i)throw new m(44);if(8192==(61440&i.mode)&&(t&=-513),65536&t&&!_(i.mode))throw new m(54);if(!n&&(r=i?40960==(61440&i.mode)?32:_(i.mode)&&("r"!==Te(t)||512&t)?31:v(i,Te(t)):44))throw new m(r);return 512&t&&!n&&et(i,0),t&=-131713,(i=Ue({node:i,path:He(i),flags:t,seekable:!0,position:0,Ha:i.Ha,Fb:[],error:!1})).Ha.open&&i.Ha.open(i),!B.logReadFiles||1&t||(e in(lt||={})||(lt[e]=1)),i}function tt(e){if(null===e.fd)throw new m(8);e.hb&&(e.hb=null);try{e.Ha.close&&e.Ha.close(e)}catch(e){throw e}finally{xe[e.fd]=null}e.fd=null}function rt(e,t,r){if(null===e.fd)throw new m(8);if(!e.seekable||!e.Ha.Ta)throw new m(70);if(0!=r&&1!=r&&2!=r)throw new m(28);e.position=e.Ha.Ta(e,t,r),e.Fb=[]}function nt(e,t,r,n,i){if(n<0||i<0)throw new m(28);if(null===e.fd)throw new m(8);if(1==(2097155&e.flags))throw new m(8);if(_(e.node.mode))throw new m(31);if(!e.Ha.read)throw new m(28);var a=void 0!==i;if(a){if(!e.seekable)throw new m(70)}else i=e.position;return t=e.Ha.read(e,t,r,n,i),a||(e.position+=t),t}function it(e,t,r,n,i){if(n<0||i<0)throw new m(28);if(null===e.fd)throw new m(8);if(0==(2097155&e.flags))throw new m(8);if(_(e.node.mode))throw new m(31);if(!e.Ha.write)throw new m(28);e.seekable&&1024&e.flags&&rt(e,0,2);var a=void 0!==i;if(a){if(!e.seekable)throw new m(70)}else i=e.position;return t=e.Ha.write(e,t,r,n,i,void 0),a||(e.position+=t),t}function at(){m||((m=function(e,t){this.name="ErrnoError",this.node=t,this.Eb=function(e){this.Ka=e},this.Eb(e),this.message="FS error"}).prototype=Error(),m.prototype.constructor=m,[44].forEach(e=>{Re[e]=new m(e),Re[e].stack="<generic error, no stack>"}))}function ot(e,s,a){e=X("/dev/"+e);var t=Ae(!!s,!!a),r=(st||=64,st++<<8|0);We(r,{open(e){e.seekable=!1},close(){a?.buffer?.length&&a(10)},read(e,t,r,n){for(var i=0,a=0;a<n;a++){try{var o=s()}catch(e){throw new m(29)}if(void 0===o&&0===i)throw new m(6);if(null==o)break;i++,t[r+a]=o}return i&&(e.node.timestamp=Date.now()),i},write(e,t,r,n){for(var i=0;i<n;i++)try{a(t[r+i])}catch(e){throw new m(29)}return n&&(e.node.timestamp=Date.now()),i}}),Ce(e,t,r)}var st,ut,lt,g={};function q(e,t,r){if("/"===t.charAt(0))return t;if(e=-100===e?"/":y(e).path,0!=t.length)return X(e+"/"+t);if(r)return e;throw new m(44)}function ft(e,t,r){try{var n=e(t)}catch(e){if(e&&e.node&&X(t)!==X(He(e.node)))return-54;throw e}h[r>>2]=n.dev,h[r+4>>2]=n.mode,c[r+8>>2]=n.nlink,h[r+12>>2]=n.uid,h[r+16>>2]=n.gid,h[r+20>>2]=n.rdev,l=[n.size>>>0,(u=n.size,1<=+Math.abs(u)?0<u?+Math.floor(u/4294967296)>>>0:~~+Math.ceil((u-(~~u>>>0))/4294967296)>>>0:0)],h[r+24>>2]=l[0],h[r+28>>2]=l[1],h[r+32>>2]=4096,h[r+36>>2]=n.blocks,e=n.atime.getTime(),t=n.mtime.getTime();var i=n.ctime.getTime();return l=[Math.floor(e/1e3)>>>0,(u=Math.floor(e/1e3),1<=+Math.abs(u)?0<u?+Math.floor(u/4294967296)>>>0:~~+Math.ceil((u-(~~u>>>0))/4294967296)>>>0:0)],h[r+40>>2]=l[0],h[r+44>>2]=l[1],c[r+48>>2]=e%1e3*1e3,l=[Math.floor(t/1e3)>>>0,(u=Math.floor(t/1e3),1<=+Math.abs(u)?0<u?+Math.floor(u/4294967296)>>>0:~~+Math.ceil((u-(~~u>>>0))/4294967296)>>>0:0)],h[r+56>>2]=l[0],h[r+60>>2]=l[1],c[r+64>>2]=t%1e3*1e3,l=[Math.floor(i/1e3)>>>0,(u=Math.floor(i/1e3),1<=+Math.abs(u)?0<u?+Math.floor(u/4294967296)>>>0:~~+Math.ceil((u-(~~u>>>0))/4294967296)>>>0:0)],h[r+72>>2]=l[0],h[r+76>>2]=l[1],c[r+80>>2]=i%1e3*1e3,l=[n.ino>>>0,(u=n.ino,1<=+Math.abs(u)?0<u?+Math.floor(u/4294967296)>>>0:~~+Math.ceil((u-(~~u>>>0))/4294967296)>>>0:0)],h[r+88>>2]=l[0],h[r+92>>2]=l[1],0}var ht=void 0;function ct(){var e=h[+ht>>2];return ht+=4,e}var dt,E,k,bt,mt,pt,wt=(e,t)=>t+2097152>>>0<4194305-!!e?(e>>>0)+4294967296*t:NaN,_t=[0,31,60,91,121,152,182,213,244,274,305,335],vt=[0,31,59,90,120,151,181,212,243,273,304,334],yt=e=>{var t=$(e)+1,r=Rt(t);return r&&Z(e,V,r,t),r},gt={},qt=()=>{if(!dt){var e,t={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:L||"./this.program"};for(e in gt)void 0===gt[e]?delete t[e]:t[e]=gt[e];var r=[];for(e in t)r.push(e+"="+t[e]);dt=r}return dt},Et=e=>{var t=$(e)+1,r=re(t);return Z(e,V,r,t),r},kt=0,Mt=(e,t)=>(t=(1==t?re:Rt)(e.length),e.subarray||e.slice||(e=new Uint8Array(e)),V.set(e,t),t),At=[],te=e=>{E.delete(k.get(e)),k.set(e,null),At.push(e)},It=(t,r)=>{if(!E){E=new WeakMap;var n=k.length;if(E)for(var i=0;i<0+n;i++){var a=k.get(i);a&&E.set(a,i)}}if(n=E.get(t)||0)return n;if(At.length)n=At.pop();else{try{k.grow(1)}catch(e){if(e instanceof RangeError)throw"Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.";throw e}n=k.length-1}try{k.set(n,t)}catch(e){if(!(e instanceof TypeError))throw e;if("function"==typeof WebAssembly.Function){for(var i=WebAssembly.Function,a={i:"i32",j:"i64",f:"f32",d:"f64",e:"externref",p:"i32"},o={parameters:[],results:"v"==r[0]?[]:[a[r[0]]]},s=1;s<r.length;++s)o.parameters.push(a[r[s]]);r=new i(o,t)}else{for(i=[1],a=r.slice(0,1),r=r.slice(1),o={i:127,p:127,j:126,f:125,d:124,e:111},i.push(96),(s=r.length)<128?i.push(s):i.push(s%128|128,s>>7),s=0;s<r.length;++s)i.push(o[r[s]]);"v"==a?i.push(0):i.push(1,o[a]),r=[0,97,115,109,1,0,0,0,1],(a=i.length)<128?r.push(a):r.push(a%128|128,a>>7),r.push.apply(r,i),r.push(2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),r=new WebAssembly.Module(new Uint8Array(r)),r=new WebAssembly.Instance(r,{e:{f:t}}).exports.f}k.set(n,r)}return E.set(t,n),n};function St(e,t,r,n){this.parent=e||=this,this.Ra=e.Ra,this.Va=null,this.id=Oe++,this.name=t,this.mode=r,this.Ga={},this.Ha={},this.rdev=n}Object.defineProperties(St.prototype,{read:{get:function(){return 365==(365&this.mode)},set:function(e){e?this.mode|=365:this.mode&=-366}},write:{get:function(){return 146==(146&this.mode)},set:function(e){e?this.mode|=146:this.mode&=-147}}}),at(),b=Array(4096),Je(f,"/"),n("/tmp"),n("/home"),n("/home/web_user"),n("/dev"),We(259,{read:()=>0,write:(e,t,r,n)=>n}),Ce("/dev/null",259),Ee(1280,r),Ee(1536,t),Ce("/dev/tty",1280),Ce("/dev/tty1",1536),bt=new Uint8Array(1024),mt=0,ot("random",r=()=>(0===mt&&(mt=_e(bt).byteLength),bt[--mt])),ot("urandom",r),n("/dev/shm"),n("/dev/shm/tmp"),n("/proc"),pt=n("/proc/self"),n("/proc/self/fd"),Je({Ra(){var e=je(pt,"fd",16895,73);return e.Ga={lookup(e,t){var r=y(+t);return(e={parent:null,Ra:{tb:"fake"},Ga:{readlink:()=>r.path}}).parent=e}},e}},"/proc/self/fd");var xt,Ot={a:(e,t,r,n)=>{i(`Assertion failed: ${e?d(V,e):""}, at: `+[t?d(V,t):"unknown filename",r,n?d(V,n):"unknown function"])},h:function(e,t){try{return Ze(e=e?d(V,e):"",t),0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},H:function(e,t,r){try{if(t=q(e,t=t?d(V,t):""),-8&r)return-28;var n=p(t,{Sa:!0}).node;return n?(e="",4&r&&(e+="r"),2&r&&(e+="w"),1&r&&(e+="x"),e&&v(n,e)?-2:0):-44}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},i:function(e,t){try{return Ze(y(e).node,t),0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},g:function(e){try{var t=y(e).node,r="string"==typeof t?p(t,{Sa:!0}).node:t;if(r.Ga.Oa)return r.Ga.Oa(r,{timestamp:Date.now()}),0;throw new m(63)}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},b:function(e,t,r){ht=r;try{var n=y(e);switch(t){case 0:var i=ct();if(i<0)return-28;for(;xe[i];)i++;return Ue(n,i).fd;case 1:case 2:return 0;case 3:return n.flags;case 4:return i=ct(),n.flags|=i,0;case 5:return i=ct(),U[i+0>>1]=2,0;case 6:case 7:return 0;case 16:case 8:return-28;case 9:return h[Gt()>>2]=28,-1;default:return-28}}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},f:function(e,t){try{return ft(Xe,y(e).path,t)}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},n:function(e,t,r){t=wt(t,r);try{if(isNaN(t))return 61;var n=y(e);if(0==(2097155&n.flags))throw new m(28);return et(n.node,t),0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},C:function(e,t){try{if(0===t)return-28;var r=$("/")+1;return t<r?-68:(Z("/",V,e,t),r)}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},F:function(e,t){try{return ft($e,e=e?d(V,e):"",t)}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},z:function(e,t,r){try{return t=q(e,t=t?d(V,t):""),n(t="/"===(t=X(t))[t.length-1]?t.substr(0,t.length-1):t,r),0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},E:function(e,t,r,n){try{return ft(256&n?$e:Xe,t=q(e,t=t?d(V,t):"",4096&n),r)}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},y:function(e,t,r,n){ht=n;try{return ee(t=q(e,t=t?d(V,t):""),r,n?ct():0).fd}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},w:function(e,t,r,n){try{if(t=q(e,t=t?d(V,t):""),n<=0)return-28;var i=Ye(t),a=Math.min(n,$(i)),o=Q[r+a];return Z(i,V,r,n+1),Q[r+a]=o,a}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},v:function(e){try{return Qe(e=e?d(V,e):""),0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},G:function(e,t){try{return ft(Xe,e=e?d(V,e):"",t)}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},r:function(e,t,r){try{return t=q(e,t=t?d(V,t):""),0===r?Ve(t):512===r?Qe(t):i("Invalid flags passed to unlinkat"),0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},q:function(e,t,r){try{t=q(e,t=t?d(V,t):"",!0),i=r?(n=1e3*(c[r>>2]+4294967296*h[r+4>>2])+h[r+8>>2]/1e6,1e3*(c[(r+=16)>>2]+4294967296*h[r+4>>2])+h[r+8>>2]/1e6):n=Date.now(),e=n;var n,i,a=p(t,{Sa:!0}).node;return a.Ga.Oa(a,{timestamp:Math.max(e,i)}),0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},l:function(e,t,r){e=new Date(1e3*wt(e,t)),h[r>>2]=e.getSeconds(),h[r+4>>2]=e.getMinutes(),h[r+8>>2]=e.getHours(),h[r+12>>2]=e.getDate(),h[r+16>>2]=e.getMonth(),h[r+20>>2]=e.getFullYear()-1900,h[r+24>>2]=e.getDay(),t=e.getFullYear(),h[r+28>>2]=(0!=t%4||0==t%100&&0!=t%400?vt:_t)[e.getMonth()]+e.getDate()-1|0,h[r+36>>2]=-60*e.getTimezoneOffset(),t=new Date(e.getFullYear(),6,1).getTimezoneOffset();var n=new Date(e.getFullYear(),0,1).getTimezoneOffset();h[r+32>>2]=0|(t!=n&&e.getTimezoneOffset()==Math.min(n,t))},j:function(e,t,r,n,i,a,o,s){i=wt(i,a);try{if(isNaN(i))return 61;var u=y(n);if(0!=(2&t)&&0==(2&r)&&2!=(2097155&u.flags))throw new m(2);if(1==(2097155&u.flags))throw new m(2);if(!u.Ha.bb)throw new m(43);var l=u.Ha.bb(u,e,i,t,r),f=l.Db;return h[o>>2]=l.ub,c[s>>2]=f,0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},k:function(e,t,r,n,i,a,o){a=wt(a,o);try{if(isNaN(a))return 61;var s,u=y(i);if(2&r){if(32768!=(61440&u.node.mode))throw new m(43);2&n||(s=V.slice(e,e+t),u.Ha.cb&&u.Ha.cb(u,s,a,t,n))}}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return-e.Ka}},s:(e,t,r)=>{function n(e){return(e=e.toTimeString().match(/\(([A-Za-z ]+)\)$/))?e[1]:"GMT"}var i=(new Date).getFullYear(),a=new Date(i,0,1),o=new Date(i,6,1),i=a.getTimezoneOffset(),s=o.getTimezoneOffset();c[e>>2]=60*Math.max(i,s),h[t>>2]=Number(i!=s),e=n(a),t=n(o),e=yt(e),t=yt(t),s<i?(c[r>>2]=e,c[r+4>>2]=t):(c[r>>2]=t,c[r+4>>2]=e)},d:()=>Date.now(),t:()=>2147483648,c:()=>performance.now(),o:e=>{var t=V.length;if(2147483648<(e>>>=0))return!1;for(var r=1;r<=4;r*=2){var n=t*(1+.2/r),n=Math.min(n,e+100663296),i=Math;n=Math.max(e,n);e:{i=(i.min.call(i,2147483648,n+(65536-n%65536)%65536)-P.buffer.byteLength+65535)/65536;try{P.grow(i),J();var a=1;break e}catch(e){}a=void 0}if(a)return!0}return!1},A:(n,i)=>{var a=0;return qt().forEach((e,t)=>{var r=i+a;for(t=c[n+4*t>>2]=r,r=0;r<e.length;++r)Q[t++>>0]=e.charCodeAt(r);Q[t>>0]=0,a+=e.length+1}),0},B:(e,t)=>{var r=qt(),n=(c[e>>2]=r.length,0);return r.forEach(e=>n+=e.length+1),c[t>>2]=n,0},e:function(e){try{return tt(y(e)),0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return e.Ka}},p:function(e,t){try{var r=y(e);return Q[t>>0]=r.tty?2:_(r.mode)?3:40960==(61440&r.mode)?7:4,U[t+2>>1]=0,l=[0,(u=0,1<=+Math.abs(u)?0<u?+Math.floor(u/4294967296)>>>0:~~+Math.ceil((u-(~~u>>>0))/4294967296)>>>0:0)],h[t+8>>2]=l[0],h[t+12>>2]=l[1],l=[0,(u=0,1<=+Math.abs(u)?0<u?+Math.floor(u/4294967296)>>>0:~~+Math.ceil((u-(~~u>>>0))/4294967296)>>>0:0)],h[t+16>>2]=l[0],h[t+20>>2]=l[1],0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return e.Ka}},x:function(e,t,r,n){try{e:{var i=y(e);e=t;for(var a,o=t=0;o<r;o++){var s=c[e>>2],u=c[e+4>>2],l=(e+=8,nt(i,Q,s,u,a));if(l<0){var f=-1;break e}if(t+=l,l<u)break;void 0!==a&&(a+=l)}f=t}return c[n>>2]=f,0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return e.Ka}},m:function(e,t,r,n,i){t=wt(t,r);try{if(isNaN(t))return 61;var a=y(e);return rt(a,t,n),l=[a.position>>>0,(u=a.position,1<=+Math.abs(u)?0<u?+Math.floor(u/4294967296)>>>0:~~+Math.ceil((u-(~~u>>>0))/4294967296)>>>0:0)],h[i>>2]=l[0],h[i+4>>2]=l[1],a.hb&&0===t&&0===n&&(a.hb=null),0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return e.Ka}},D:function(e){try{var t=y(e);return t.Ha?.fsync?t.Ha.fsync(t):0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return e.Ka}},u:function(e,t,r,n){try{e:{var i=y(e);e=t;for(var a,o=t=0;o<r;o++){var s=c[e>>2],u=c[e+4>>2],l=(e+=8,it(i,Q,s,u,a));if(l<0){var f=-1;break e}t+=l,void 0!==a&&(a+=l)}f=t}return c[n>>2]=f,0}catch(e){if(void 0===g||"ErrnoError"!==e.name)throw e;return e.Ka}}},M=function(){function t(e){return M=e.exports,P=M.I,J(),k=M.Aa,C.unshift(M.J),s--,B.monitorRunDependencies?.(s),0==s&&(null!==ie&&(clearInterval(ie),ie=null),ae&&(e=ae,ae=null,e())),M}var r,n,i,e={a:Ot};if(s++,B.monitorRunDependencies?.(s),B.instantiateWasm)try{return B.instantiateWasm(e,t)}catch(e){return o("Module.instantiateWasm callback failed with error: "+e),!1}return r=e,n=function(e){t(e.instance)},i=oe,a||"function"!=typeof WebAssembly.instantiateStreaming||se(i)||ue(i)||T||"function"!=typeof fetch?fe(i,r,n):fetch(i,{credentials:"same-origin"}).then(e=>WebAssembly.instantiateStreaming(e,r).then(n,function(e){return o("wasm streaming compile failed: "+e),o("falling back to ArrayBuffer instantiation"),fe(i,r,n)})),{}}(),Gt=(B._sqlite3_free=e=>(B._sqlite3_free=M.K)(e),B._sqlite3_value_text=e=>(B._sqlite3_value_text=M.L)(e),()=>(Gt=M.M)()),Rt=(B._sqlite3_prepare_v2=(e,t,r,n,i)=>(B._sqlite3_prepare_v2=M.N)(e,t,r,n,i),B._sqlite3_step=e=>(B._sqlite3_step=M.O)(e),B._sqlite3_finalize=e=>(B._sqlite3_finalize=M.P)(e),B._sqlite3_reset=e=>(B._sqlite3_reset=M.Q)(e),B._sqlite3_clear_bindings=e=>(B._sqlite3_clear_bindings=M.R)(e),B._sqlite3_value_blob=e=>(B._sqlite3_value_blob=M.S)(e),B._sqlite3_value_bytes=e=>(B._sqlite3_value_bytes=M.T)(e),B._sqlite3_value_double=e=>(B._sqlite3_value_double=M.U)(e),B._sqlite3_value_int=e=>(B._sqlite3_value_int=M.V)(e),B._sqlite3_value_type=e=>(B._sqlite3_value_type=M.W)(e),B._sqlite3_result_blob=(e,t,r,n)=>(B._sqlite3_result_blob=M.X)(e,t,r,n),B._sqlite3_result_double=(e,t)=>(B._sqlite3_result_double=M.Y)(e,t),B._sqlite3_result_error=(e,t,r)=>(B._sqlite3_result_error=M.Z)(e,t,r),B._sqlite3_result_int=(e,t)=>(B._sqlite3_result_int=M._)(e,t),B._sqlite3_result_int64=(e,t,r)=>(B._sqlite3_result_int64=M.$)(e,t,r),B._sqlite3_result_null=e=>(B._sqlite3_result_null=M.aa)(e),B._sqlite3_result_text=(e,t,r,n)=>(B._sqlite3_result_text=M.ba)(e,t,r,n),B._sqlite3_aggregate_context=(e,t)=>(B._sqlite3_aggregate_context=M.ca)(e,t),B._sqlite3_column_count=e=>(B._sqlite3_column_count=M.da)(e),B._sqlite3_data_count=e=>(B._sqlite3_data_count=M.ea)(e),B._sqlite3_column_blob=(e,t)=>(B._sqlite3_column_blob=M.fa)(e,t),B._sqlite3_column_bytes=(e,t)=>(B._sqlite3_column_bytes=M.ga)(e,t),B._sqlite3_column_double=(e,t)=>(B._sqlite3_column_double=M.ha)(e,t),B._sqlite3_column_text=(e,t)=>(B._sqlite3_column_text=M.ia)(e,t),B._sqlite3_column_type=(e,t)=>(B._sqlite3_column_type=M.ja)(e,t),B._sqlite3_column_name=(e,t)=>(B._sqlite3_column_name=M.ka)(e,t),B._sqlite3_bind_blob=(e,t,r,n,i)=>(B._sqlite3_bind_blob=M.la)(e,t,r,n,i),B._sqlite3_bind_double=(e,t,r)=>(B._sqlite3_bind_double=M.ma)(e,t,r),B._sqlite3_bind_int=(e,t,r)=>(B._sqlite3_bind_int=M.na)(e,t,r),B._sqlite3_bind_text=(e,t,r,n,i)=>(B._sqlite3_bind_text=M.oa)(e,t,r,n,i),B._sqlite3_bind_parameter_index=(e,t)=>(B._sqlite3_bind_parameter_index=M.pa)(e,t),B._sqlite3_sql=e=>(B._sqlite3_sql=M.qa)(e),B._sqlite3_normalized_sql=e=>(B._sqlite3_normalized_sql=M.ra)(e),B._sqlite3_errmsg=e=>(B._sqlite3_errmsg=M.sa)(e),B._sqlite3_exec=(e,t,r,n,i)=>(B._sqlite3_exec=M.ta)(e,t,r,n,i),B._sqlite3_changes=e=>(B._sqlite3_changes=M.ua)(e),B._sqlite3_close_v2=e=>(B._sqlite3_close_v2=M.va)(e),B._sqlite3_create_function_v2=(e,t,r,n,i,a,o,s,u)=>(B._sqlite3_create_function_v2=M.wa)(e,t,r,n,i,a,o,s,u),B._sqlite3_open=(e,t)=>(B._sqlite3_open=M.xa)(e,t),B._malloc=e=>(Rt=B._malloc=M.ya)(e)),Ht=B._free=e=>(Ht=B._free=M.za)(e),Lt=(B._RegisterExtensionFunctions=e=>(B._RegisterExtensionFunctions=M.Ba)(e),(e,t)=>(Lt=M.Ca)(e,t)),Nt=()=>(Nt=M.Da)(),jt=e=>(jt=M.Ea)(e),re=e=>(re=M.Fa)(e);function Tt(){function e(){if(!xt&&(xt=!0,B.calledRun=!0,!W)){if(B.noFSInit||ze||(ze=!0,at(),B.stdin=B.stdin,B.stdout=B.stdout,B.stderr=B.stderr,B.stdin?ot("stdin",B.stdin):Be("/dev/tty","/dev/stdin"),B.stdout?ot("stdout",null,B.stdout):Be("/dev/tty","/dev/stdout"),B.stderr?ot("stderr",null,B.stderr):Be("/dev/tty1","/dev/stderr"),ee("/dev/stdin",0),ee("/dev/stdout",1),ee("/dev/stderr",1)),Ge=!1,he(C),B.onRuntimeInitialized&&B.onRuntimeInitialized(),B.postRun)for("function"==typeof B.postRun&&(B.postRun=[B.postRun]);B.postRun.length;){var e=B.postRun.shift();ne.unshift(e)}he(ne)}}if(!(0<s)){if(B.preRun)for("function"==typeof B.preRun&&(B.preRun=[B.preRun]);B.preRun.length;)t=void 0,t=B.preRun.shift(),K.unshift(t);he(K),0<s||(B.setStatus?(B.setStatus("Running..."),setTimeout(function(){setTimeout(function(){B.setStatus("")},1),e()},1)):e())}var t}if(B.stackAlloc=re,B.stackSave=Nt,B.stackRestore=jt,B.cwrap=(l,f,h,e)=>{var t=!h||h.every(e=>"number"===e||"boolean"===e);return"string"!==f&&t&&!e?B["_"+l]:function(){var e=l,t=f,r=h,n=arguments,i={string:e=>{var t=0;return t=null!=e&&0!==e?Et(e):t},array:e=>{var t=re(e.length);return Q.set(e,t),t}},a=(e=B["_"+e],[]),o=0;if(n)for(var s=0;s<n.length;s++){var u=i[r[s]];u?(0===o&&(o=Nt()),a[s]=u(n[s])):a[s]=n[s]}return e=r=e.apply(null,a),0!==o&&jt(o),"string"===t?e?d(V,e):"":"boolean"===t?!!e:e}},B.addFunction=It,B.removeFunction=te,B.UTF8ToString=be,B.ALLOC_NORMAL=kt,B.allocate=Mt,B.allocateUTF8OnStack=Et,ae=function e(){xt||Tt(),xt||(ae=e)},B.preInit)for("function"==typeof B.preInit&&(B.preInit=[B.preInit]);0<B.preInit.length;)B.preInit.pop()();return Tt(),e})};"object"==typeof exports&&"object"==typeof module?(module.exports=initSqlJs,module.exports.default=initSqlJs):"function"==typeof define&&define.amd?define([],function(){return initSqlJs}):"object"==typeof exports&&(exports.Module=initSqlJs);
diff --git a/themes/bookstack/static/libs/webidx.js b/themes/bookstack/static/libs/webidx.js
new file mode 100644 (file)
index 0000000..d261abb
--- /dev/null
@@ -0,0 +1,240 @@
+// Taken from https://github.com/gbxyz/webidx/tree/main
+// BSD 3-Clause License
+// Copyright (c) 2024, Gavin Brown
+// Full license: https://github.com/gbxyz/webidx/blob/a28a984d38fd546d1bec4d6a4a5a47ab86cb08f8/LICENSE
+
+window.webidx = {};
+webidx = window.webidx;
+
+webidx.search = async function (params) {
+  if (!webidx.sql) {
+    //
+    // initialise sql.js
+    //
+    webidx.sql = await window.initSqlJs({locateFile: file => `https://sql.js.org/dist/${file}`});
+  }
+
+  if (webidx.hasOwnProperty('db')) {
+    webidx.displayResults(webidx.query(params.query), params);
+
+  } else {
+    webidx.loadDB(params);
+
+  }
+};
+
+webidx.loadDB = function (params) {
+  var xhr = new XMLHttpRequest();
+
+  xhr.open('GET', params.dbfile);
+  xhr.timeout = params.timeout ?? 5000;
+  xhr.responseType = 'arraybuffer';
+
+  xhr.ontimeout = function() {
+    if (params.hasOwnProperty('errorCallback')) {
+      params.errorCallback('Unable to load index, please refresh the page.');
+    }
+  };
+
+  xhr.onload = function() {
+    webidx.initializeDB(this.response);
+    webidx.displayResults(webidx.query(params.query), params);
+  };
+
+  xhr.send();
+};
+
+webidx.initializeDB = function (arrayBuffer) {
+  webidx.db = new webidx.sql.Database(new Uint8Array(arrayBuffer));
+
+  //
+  // prepare statements
+  //
+  webidx.wordQuery  = webidx.db.prepare("SELECT `id` FROM `words` WHERE (`word`=:word)");
+  webidx.idxQuery   = webidx.db.prepare("SELECT `page_id` FROM `index` WHERE (`word`=:word)");
+  webidx.pageQuery  = webidx.db.prepare("SELECT `url`,`title` FROM `pages` WHERE (`id`=:id)");
+};
+
+webidx.getWordID = function (word) {
+  webidx.wordQuery.bind([word]);
+  webidx.wordQuery.step();
+  var word_id = webidx.wordQuery.get().shift();
+
+  webidx.wordQuery.reset();
+
+  return word_id;
+};
+
+webidx.getPagesHavingWord = function (word_id) {
+  var pages = [];
+
+  webidx.idxQuery.bind([word_id]);
+
+  while (webidx.idxQuery.step()) {
+    pages.push(webidx.idxQuery.get().shift());
+  }
+
+  webidx.idxQuery.reset();
+
+  return pages;
+};
+
+webidx.getPage = function (page_id) {
+  webidx.pageQuery.bind([page_id]);
+
+  webidx.pageQuery.step();
+
+  var page = webidx.pageQuery.getAsObject();
+
+  webidx.pageQuery.reset();
+
+  return page;
+};
+
+webidx.query = function (query) {
+  //
+  // split the search term into words
+  //
+  var words = query.toLowerCase().split(" ");
+
+  //
+  // this array maps page ID to rank
+  //
+  var pageRank = [];
+
+  //
+  // iterate over each word
+  //
+  while (words.length > 0) {
+    var word = words.shift();
+
+    var invert = false;
+    if (0 == word.indexOf("-")) {
+      invert = true;
+      word = word.substring(1);
+    }
+
+    var word_id = webidx.getWordID(word);
+
+    //
+    // if the word isn't present, ignore it
+    //
+    if (word_id) {
+      var pages = webidx.getPagesHavingWord(word_id);
+
+      pages.forEach(function (page_id) {
+        if (invert) {
+          if (pageRank[page_id]) {
+            pageRank[page_id] -= 65535;
+
+          } else {
+            pageRank[page_id] = -65535;
+            
+          }
+
+        } else {
+          if (pageRank[page_id]) {
+            pageRank[page_id]++;
+
+          } else {
+            pageRank[page_id] = 1;
+
+          }
+        }
+      });
+    }
+  }
+
+  //
+  // transform the results into a format that can be sorted
+  //
+  var sortedPages = [];
+
+  pageRank.forEach(function (rank, page_id) {
+    if (rank > 0) {
+      sortedPages.push({rank: rank, page_id: page_id});
+    }
+  })
+
+  //
+  // sort the results in descending rank order
+  //
+  sortedPages.sort(function(a, b) {
+    return b.rank - a.rank;
+  });
+
+  //
+  // this will be populated with the actual pages
+  //
+  var pages = [];
+
+  //
+  // get page data for each result
+  //
+  sortedPages.forEach(function(result) {
+    pages.push(webidx.getPage(result.page_id));
+  });
+
+  return pages;
+};
+
+webidx.regExpQuote = function (str) {
+  return str.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
+};
+
+webidx.displayResults = function (pages, params) {
+  var callback = params.resultCallback ?? webidx.displayDialog;
+  callback(pages, params);
+};
+
+webidx.displayDialog = function (pages, params) {
+  var dialog = document.createElement('dialog');
+  dialog.classList.add('webidx-results-dialog')
+
+  dialog.appendChild(document.createElement('h2')).appendChild(document.createTextNode('Search Results'));
+
+  if (pages.length < 1) {
+    dialog.appendChild(document.createElement('p')).appendChild(document.createTextNode('Nothing found.'));
+
+  } else {
+    var ul = dialog.appendChild(document.createElement('ul'));
+
+    pages.forEach(function(page) {
+      var titleText = page.title;
+
+      if (params.titleSuffix) {
+        titleText = titleText.replace(new RegExp(webidx.regExpQuote(params.titleSuffix)+'$'), '');
+      }
+
+      if (params.titlePrefix) {
+        titleText = titleText.replace(new RegExp('^' + webidx.regExpQuote(params.titleSuffix)), '');
+      }
+
+      var li = ul.appendChild(document.createElement('li'));
+      var a = li.appendChild(document.createElement('a'));
+      a.setAttribute('href', page.url);
+      a.appendChild(document.createTextNode(titleText));
+      li.appendChild(document.createElement('br'));
+
+      var span = li.appendChild(document.createElement('span'));
+      span.classList.add('webidx-page-url');
+      span.appendChild(document.createTextNode(page.url));
+    });
+  }
+
+  var form = dialog.appendChild(document.createElement('form'));
+  form.setAttribute('method', 'dialog');
+
+  var button = form.appendChild(document.createElement('button'));
+  button.setAttribute('autofocus', true);
+  button.appendChild(document.createTextNode('Close'));
+
+  document.body.appendChild(dialog);
+
+  dialog.addEventListener('close', function() {
+    dialog.parentNode.removeChild(dialog);
+  });
+
+  dialog.showModal();
+  dialog.scrollTop = 0;
+};