summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-06-22 03:01:06 +0000
committerNorbert Preining <norbert@preining.info>2023-06-22 03:01:06 +0000
commitac667b3d60d89dfd061e15583ed0062204ec705c (patch)
tree2a22ace0947c6691f783ba4a418000310d911817 /web
parent16d6a70c44a97b15c195cf6b10f59f3deadd0e66 (diff)
CTAN sync 202306220301
Diffstat (limited to 'web')
-rw-r--r--web/javascripthttp/README.md60
-rw-r--r--web/javascripthttp/javascripthttp-doc.pdfbin177033 -> 0 bytes
-rw-r--r--web/javascripthttp/javascripthttp-doc.tex171
-rw-r--r--web/javascripthttp/javascripthttp.sty312
4 files changed, 0 insertions, 543 deletions
diff --git a/web/javascripthttp/README.md b/web/javascripthttp/README.md
deleted file mode 100644
index 4fac3528a3..0000000000
--- a/web/javascripthttp/README.md
+++ /dev/null
@@ -1,60 +0,0 @@
-# README for JAVASCRIPTHTTP
-Version v1.1
-
-## INTRODUCTION
-This small package adds commands for LaTeX to create buttons with which to fetch content from the internet. The content can be transformed and displayed in textfields. For these interactive elements to work, a PDF using the commands provided by this package must be opened in Acrobat Pro.
-
-This packages requires the acrotex macro.
-
-## PREREQUISITES
-
-To install acrotex, you need to add the tlcontrib repository to your installation:
-
-```
-tlmgr repository add https://mirror.ctan.org/systems/texlive/tlcontrib tlcontrib
-
-tlmgr pinning add tlcontrib "*"
-
-# Then install the package
-tlmgr install acrotex
-```
-
-## USAGE
-
-Here is a quick overview of the commands and their parameters. For further details and examples please read the package documentation.
-
-* SimpleGET, send a GET request:
- ```tex
- \SimpleGET{unique identifier}{label}{URL}{keypath}[target]
- ```
-
-* SimplePOST, send a POST request:
- ```tex
- \SimplePOST{id}{label}{URL}{keypath}{factory}{errors}[target]
- ```
-
-* SimpleTextField, adds a writeable textfield to your document:
- ```tex
- \SimpleTextfield{unique identifier}
- ```
-
-* SimpleTextFieldReadoly, adds a readonly textfield that can be updated through javascript:
- ```tex
- \SimpleTextfieldReadonly{unique identifier}
- ```
-
-* Errorfield, adds a field to your document that displays any errors that occur:
- ```tex
- \Errorfield
- ```
-
-
-## AUTHOR
-
-* Cedric V. Zwahlen (cedric-vince@gmx.ch)
-
-## LICENSE
-
-LATEX Project Public License, version 1.3c or later.
-
-
diff --git a/web/javascripthttp/javascripthttp-doc.pdf b/web/javascripthttp/javascripthttp-doc.pdf
deleted file mode 100644
index 850638ab7f..0000000000
--- a/web/javascripthttp/javascripthttp-doc.pdf
+++ /dev/null
Binary files differ
diff --git a/web/javascripthttp/javascripthttp-doc.tex b/web/javascripthttp/javascripthttp-doc.tex
deleted file mode 100644
index b836692eee..0000000000
--- a/web/javascripthttp/javascripthttp-doc.tex
+++ /dev/null
@@ -1,171 +0,0 @@
-\documentclass[a4paper]{article}
-\usepackage[english]{babel}
-\usepackage{listings}
-\usepackage{javascripthttp}
-\usepackage{hyperref}
-
-\begin{document}
-
-\setlength{\parindent}{0pt}
-\setlength{\parskip}{5pt plus 2pt minus 1pt}
-
-\title{JavascriptHttp Documentation \& Manual}
-\author{Cedric Zwahlen \\ \texttt{cedric-vince@gmx.ch}}
-
-
-\maketitle
-
-\tableofcontents
-
-\newpage
-
-\section{Introduction}
-
-{\noindent The aim of this package is to make it as easy as possible to \textit{get} or \textit{post} data from or to REST-API's from within a PDF document.
-Specifically, this package adds LaTeX commands to create highly customisable buttons with which to fetch, transform and display data from a remote location. \\
-These features make use of Javascript, which means a PDF using them \textbf{only works with Adobe Acrobat Pro}.
-Other PDF viewers (including Acrobat Reader) may still display the interactive elements, but will not be able to run Javascript or access the internet. }
-
-\section{Prerequisites}
-
-{\noindent Acrobat Pro blocks Networking code by default. Because this package requires it, you must first change some settings.\\
-Navigate to \textbf{Preferences\textgreater Security (Enhanced)}. Then, add the path to your PDF via the 'Add Folder Path' button. The javascripthttp package depends on the acrotex macro. More information about acrotex can be found here: \url{https://www.ctan.org/pkg/acrotex} }
-
-\section{Textfields}
-
-\begin{description}
- \item[\textbackslash SimpleTextField] { \sffamily
- \{$\langle$unique identifier$\rangle$\}
- }
-\end{description}
-
-{\noindent Adds a writable textfield to the document. $\langle$unique identifier$\rangle$ should not be reused by other Simple elements. It must not contain an underscore '\_'. Use this specifier to obtain a reference to the textfield in Javascript or as a $\langle$target$\rangle$ in other Simple elements. }
-
-\subsection{Readonly}
-
-\begin{description}
- \item[\textbackslash SimpleTextFieldReadonly] { \sffamily
- \{$\langle$unique identifier$\rangle$\}
- }
-\end{description}
-
-\begin{description}
- \item[\textbackslash SimpleTextFieldShortReadonly] { \sffamily
- \{$\langle$unique identifier$\rangle$\}
- }
-\end{description}
-
-\begin{description}
- \item[\textbackslash SimpleTextFieldMultilineReadonly] { \sffamily
- \{$\langle$unique identifier$\rangle$\}
- }
-\end{description}
-
-{\noindent A readonly textfield does not accept user input. It's content can only be changed through Javascript code. }
-
-\newpage
-
-\section{GET Requests}
-
-\hypertarget{get_1}{\subsection{The Simple Way}}
-
-\begin{description}
- \item[\textbackslash SimpleGET] { \sffamily
- \{$\langle$unique identifier$\rangle$\}
- \{$\langle$label$\rangle$\}
- \{$\langle$URL$\rangle$\}
- \{$\langle$keypath$\rangle$\}
- \lbrack$\langle$target$\rangle$\rbrack
- }
-\end{description}
-
-{\noindent If you want to get information from the internet, use this command.\\ This command adds a button that contains the text specified in $\langle$label$\rangle$.\\
-The $\langle$unique identifier$\rangle$ should not be reused by other Simple elements. It must not contain an underscore '\_'. This identifier can be used to obtain a reference to the button in Javascript.\\ $\langle$URL$\rangle$ refers to the address of the REST API endpoint. Note that if you pass a string, you must surround it with either ' or ", just like you would with Javascript strings.\\
-If the endpoint in question returns a json file, use $\langle$keypath$\rangle$ to refer to the property you would like to display in a textfield.
-As an example, consider the following JSON object:
-\begin{lstlisting}
-{
- "abc" :
- [
- {
- "xyz" : "Starfruit"
- },
- {
- "xyz" : "Mango"
- }
- ]
-}
-\end{lstlisting}
-To display the value "Mango", pass 'abc.1.xyz' (including ') as the keypath.\\
-Finally, $\langle$target$\rangle$ specifies the name of the textfield, in which to display the value of the property specified in $\langle$keypath$\rangle$. If no such textfield exists, then nothing is displayed. This parameter is optional.\\
-}
-
-\subsection{URL Interpolation}
-
-{\noindent You can use URL interpolation to insert contents of a textfield into your URL. To do this, wrap the $\langle$unique identifier$\rangle$ of a textfield in curly braces where you want to insert its content in the URL. An example:
-\begin{lstlisting}
-https://api.datamuse.com/words?rel_rhy={textfield1}
-\end{lstlisting}
-
-\subsection{Using Lambdas}
-
-\subsubsection{URL Argument}
-
-{\noindent In some cases, $\langle$URL$\rangle$ interpolation might not be enough to produce the URL that you need. If this is the case, you can also pass a Javascript lambda (a.k.a arrow function) as the parameter. This enables a great deal of freedom, but might present a security risk if you do not know the origin of a document.\\
-If you pass a lambda as the $\langle$URL$\rangle$ parameter, the function must return the final URL as a string. The lambda does not take any arguments.\\ You can obtain a valid reference to 'this' in the lambdas context. Refer to \url{https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html} for the Acrobat Javascript API Reference.\\
-}
-
-\subsubsection{Keypath Argument}
-
-{\noindent If you need to perform additional operations on received data, you can pass a Javascript lambda as the $\langle$keypath$\rangle$ parameter instead of a string. Allowing anyone to execute arbitrary code might introduce a security risk, so documents from unknown origins should not be trusted. The lambda takes two arguments; the data received from remote as a Javascript object, and a reference to 'this'. If your lambda returns a string, it will be displayed in the field specified by $\langle$target$\rangle$.\\
-Consider the below example. A lambda is used to get a list of holidays from \url{https://date.nager.at/api/v3/publicholidays/2023/CH}, and then pick one at random.\\}
-
-\begin{lstlisting}
-(json,doc) => {
- // json is a top level array
- const x = Math.floor(Math.random() * json.length);
- // get localName from element x
- const h = doc.extractKeypath(json,x + '.localName',doc);
- return h;
-}
-\end{lstlisting}
-
-\section{POST Requests}
-
-\begin{description}
- \item[\textbackslash SimplePOST] { \sffamily
- \{$\langle$id$\rangle$\}
- \{$\langle$label$\rangle$\}
- \{$\langle$URL$\rangle$\}
- \{$\langle$keypath$\rangle$\}
- \{$\langle$factory$\rangle$\}
- \{$\langle$errors$\rangle$\}
- \lbrack$\langle$target$\rangle$\rbrack
- }
-\end{description}
-
-{\noindent If you need to post information to the internet, then use this command. The first four parameters of the \textbf{\textbackslash SimplePOST} command work identically to the \textbf{\textbackslash SimpleGET} command. Refer to \hyperlink{get_1}{GET Requests} for more information.\\
-The $\langle$factory$\rangle$ parameter takes a lambda with no arguments to construct the body of your post request. It must return a Javascript object.\\
-If you want to display custom error messages in case an operation fails, you can pass a Javascript object specifying an error message for a given HTML error code, an example:
-\begin{lstlisting}
-{ "400": "error 400", "300": "error 300" , "500" : "error 500"}
-\end{lstlisting}
-If you do not want to display any custom error messages, simply pass \{\} – an empty object.\\}
-
-\section{Generic Button}
-
-\begin{description}
- \item[\textbackslash SimpleClosure] { \sffamily
- \{$\langle$id$\rangle$\}
- \{$\langle$label$\rangle$\}
- \{$\langle$closure$\rangle$\}
- }
-\end{description}
-
-{\noindent Also provided as part of this package is a button, that simply takes a lambda. This button can be used to provide other functionality to tie various components together.}
-
-\section{Error Handling}
-
-{\noindent Any errors that occur while posting or getting will be displayed in an alert box by default. If you do not want this, you can use the command \textbf{\textbackslash ErrorField\{\}}.\\ This command adds a Readonly Textfield with the $\langle$unique identifier$\rangle$ 'errorField'. If an error field exists in your document, any HTTP errors that occur will be silenced, and their error message displayed in the error field.}
-
-\end{document} \ No newline at end of file
diff --git a/web/javascripthttp/javascripthttp.sty b/web/javascripthttp/javascripthttp.sty
deleted file mode 100644
index 68a89a830a..0000000000
--- a/web/javascripthttp/javascripthttp.sty
+++ /dev/null
@@ -1,312 +0,0 @@
-%% javascripthttp.sty
-%% Copyright 2023 Cedric V. Zwahlen
-%
-% This work may be distributed and/or modified under the
-% conditions of the LaTeX Project Public License, either version 1.3
-% of this license or (at your option) any later version.
-% The latest version of this license is in
-% https://www.latex-project.org/lppl.txt
-% and version 1.3c or later is part of all distributions of LaTeX
-% version 2008 or later.
-%
-% This work has the LPPL maintenance status `maintained'.
-%
-% The Current Maintainer of this work is Cedric V. Zwahlen
-%
-% This work consists of the files javascripthttp.sty and javascripthttp-doc.tex
-\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{javascripthttp}[JavascriptHTTP Package, Version 1.1]
-
-\RequirePackage{setspace}
-\RequirePackage{insdljs}
-\RequirePackage{xparse}
-
-\newcommand{\SimpleButtonPOST}[7][\{\}] {
-\PushButton[name=#2, onclick={ processSimpleButton(#4,'POST',#5,#7,#6,#1); }]{\sffamily \large #3}
-}
-
-\newcommand{\SimpleTextFieldReadonly}[1] {
-\TextField[name=#1,width=29em,height=2em,bordercolor={0.5 .5 .5},readonly=true]{}
-}
-
-\newcommand{\SimpleTextFieldShortReadonly}[1] {
-\TextField[name=#1,width=9em,height=2em,bordercolor={0.5 .5 .5},readonly=true]{}
-}
-
-\newcommand{\SimpleTextFieldMultilineReadonly}[1] {
-\TextField[name=#1,width=29em,height=4em,bordercolor={0.5 .5 .5},readonly=true,multiline=true]{}
-}
-
-\newcommand{\SimpleTextField}[1] {
-\TextField[name=#1,width=29em,height=2em,bordercolor={0.5 .5 .5}]{}
-}
-
-\newcommand{\ErrorField} {
-\TextField[name=errorField,width=29em,height=2em,bordercolor={0.0 .0 .0},readonly=true]{}
-}
-
-% new
-
-\NewDocumentCommand{\SimpleGET}{v v +v +v o}{
-
- \IfNoValueTF{#5}
- { \PushButton[name=#1, onclick={ processSimpleButton(#3,'GET','','',#4,{}); }]{\sffamily \large #2} }
- { \PushButton[name=#1, onclick={ processSimpleButton(#3,'GET','#5','',#4,{}); }]{\sffamily \large #2} }
-
-
-}
-
-\NewDocumentCommand{\SimpleClosure}{v v +v}{
-
- \PushButton[name=#1, onclick={ this["simpleClosure"] = #3; this["simpleClosure"](this); }]{\sffamily \large #2}
-
-}
-
-\NewDocumentCommand{\SimplePOST}{v v +v +v +v +v o}{
-
- \IfNoValueTF{#7}
- { \PushButton[name=#1, onclick={ processSimpleButton(#3,'POST','#6',#5,#4,{}); }]{\sffamily \large #2} }
- { \PushButton[name=#1, onclick={ processSimpleButton(#3,'POST','#7',#5,#4,#6); }]{\sffamily \large #2} }
-
-}
-
-
-
-
-\begin{insDLJS}{test}{JavaScript}
-
-/*
-Displays a message e in a textfield named 'errorField'. If no such textfield exists and sentiment is 0, an alert is displayed instead.
-The parameter sentiment indicates the nature of the message e. If sentiment is:
-
- 0 => e is an error message
- 1 => e indicates success
- 2 => e is neutral
-
-*/
-function state(e, sentiment) {
- var f = this.getField("errorField")
-
- if (f != null) {
-
- f.value = e;
-
- if (sentiment == 0) { f.borderColor = ["RGB",0.8,0,0]; f.lineWidth = 1; }
- if (sentiment == 1) { f.borderColor = ["RGB",0,0.6,0]; f.lineWidth = 1; }
- if (sentiment == 2) { f.borderColor = ["RGB",1,1,1]; f.lineWidth = 0; }
-
- } else {
- if (sentiment == 0) {
- app.alert(e);
- }
- }
-}
-
-/*
-Attempts to retrieve a JSON object from a REST API endpoint.
-
- url => the endpoint to contact
- closure => is called with the received javascript object
- keypath => the keypath of a property in the javascript object received that should be displayed in a textfield
- payload => a javascript object to send in the body, as part of the request
- name => the name of the textfield, where the property defined by keypath should be displayed
- func => GET or POST
- errors => a javascript object that defines error messages
- example: { "404" : "The requested resource does not exist." }
- doc => a reference to this
-
- requires adobe acrobat pro, and the pdf needs to exist in a trusted folder
-
-*/
-function getJSONFrom(url,closure,keypath,payload,name,func,errors,doc)
-{
-
- doc["httpjavascripts_speedTest_t0"] = new Date();
-
- var o = {};
-
- if (payload != '') {
- o = payload();
- }
-
- var params =
- {
- cVerb: func,
- cURL: url,
- oRequest: util.streamFromString(JSON.stringify(o), "utf-8"),
- oHandler:
- {
- response: function(resp,uri,e)
- {
-
- if (e != undefined) {
-
- const known = errors[e.error];
-
- if (known != undefined) {
- state(known,0);
- } else {
-
- // still perform some basic checks
-
- state(e.text,0);
-
- }
-
- } else {
-
- const raw = util.stringFromStream(resp);
-
- const json = JSON.parse(raw);
-
- state("",2);
- const toDisplay = closure(json,keypath,doc);
-
- if (toDisplay != undefined) {
- doc.display(toDisplay,name,doc);
- }
- }
- }
- }
- }
-
-
- Net.HTTP.request(params);
-}
-/*
-Preprocesses the URL, and then passes the data to getJSONFrom function.
-
-if the URL is a function, then that function is executed. This could be a security concern if the origin of the document is not known.
-if the URL contains an interpolated link, the interpolated elements are resolved.
- example for an interpolated link:
-
- "https://api.datamuse.com/words?rel_rhy={xyz}"
-
- where xyz is the name of a textfield.
-
-otherwise, a string is expected.
-
-*/
-function processSimpleButton(url, method, name, payload, keypath, errors)
-{
-
- var resolved = url;
-
- if (typeof url != 'string') {
- resolved = url(); // may be a security concern
- } else if ( url.indexOf('{') >= 0 && url.indexOf('}') >= 0 ) {
-
- const re = /[^{}]*({(\w*)})+/g;
-
- var m;
-
- var stitch = 0;
- var res = '';
-
- do {
- m = re.exec(resolved);
- if (m) {
-
- const f = this.getField(m[2]);
-
- if (f != null) {
- stitch += m[0].length;
- res += m[0].substring(0, m[0].length - m[1].length) + f.value;
- } else {
- console.println("DEBUG HINT: The textfield used for the interpolation of the URL string could not be found.");
- }
-
- }
-
- } while (m);
-
- const appendix = url.substring(stitch);
- resolved = res;
-
- }
-
- getJSONFrom(resolved, extractKeypath, keypath, payload, name, method, errors, this);
-}
-
-function removeHTML(str) {
-
- const re = /(.*?)(&.*?;)/g;
-
- var m;
-
- var stitch = 0;
- var res = '';
-
- do {
- m = re.exec(str);
- if (m) {
-
- console.println(m[0]);
- console.println(m[1]);
-
- stitch += m[0].length;
- res += m[1];
-
- }
-
- } while (m);
-
- return res + str.substring(stitch);
-}
-
-/*
-Extracts a property of a javascript object based on the provided keypath.
-
- Example: the keypath 'rst.xyz' extracts the value of the property xyz from the object abc:
-
- const abc = { rst : { xyz = 123 } };
-
- elements of an array can be accessed via ascending numbers, for example the keypath '0.xyz' would access the first element of an array, an then extract the value of xyz of that first object.
-
-*/
-function extractKeypath(json,keypath,doc) {
-
- if (typeof keypath == 'function') {
- return keypath(json,doc);
- }
-
- if (typeof keypath == 'string') {
-
- const fun = doc[keypath];
-
- if (typeof fun == 'function') {
- return fun(); // may be a security concern
- } else {
-
- return keypath.split('.').reduce((previous, current) => {
- const parsed = parseInt(current);
-
- if (previous == undefined) {
- console.println("DEBUG HINT: Keypath may not match the json object, or a referenced textfield is empty.");
- return '';
- }
-
- if (isNaN(parsed)) {
- return previous[current];
- } else {
- return previous[parsed];
- }
-
- }, json);
- }
- }
-}
-
-/*
-Displays a text in a textfield, provided the textfield exists.
-*/
-function display(text,name,doc) {
-
- var f = doc.getField(name);
-
- if (f != undefined) {
- f.value = text;
- }
-}
-
-\end{insDLJS} \ No newline at end of file