inital commit
This commit is contained in:
1 parent
d812e8f4a7
commit
7b45a854fe
1672 files changed
+298536
-1
No files matched your search
@@ -0,0 +1,5 @@
|
||||
/* esm.sh - buffer@6.0.3 */
|
||||
import "./v135/base64-js@1.5.1/es2022/base64-js.js";
|
||||
import "./v135/ieee754@1.2.1/es2022/ieee754.js";
|
||||
export * from "./v135/buffer@6.0.3/es2022/buffer.js";
|
||||
export { default } from "./v135/buffer@6.0.3/es2022/buffer.js";
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Content Handler for Web Printing Toolkit
|
||||
Developed by Sören Oesterwind <software@tgd.fyi>
|
||||
Licensed under AGPL-3.0
|
||||
|
||||
Do not use for evil.
|
||||
*/
|
||||
|
||||
|
||||
// Printer Configuration
|
||||
|
||||
const paper_height = 400; // px
|
||||
const paper_width = 400; // px
|
||||
const print_server_url = "http://127.0.0.1:631/printers/PDF"; // The full path to the printer you wish to use, see README
|
||||
|
||||
// For this example a canvas is used to draw on
|
||||
// It will get sent to the printer
|
||||
const print_canvas = document.getElementById("print_canvas");
|
||||
const print_context = print_canvas.getContext("2d");
|
||||
|
||||
// Inputs
|
||||
const name_input = document.getElementById("input_text");
|
||||
|
||||
const printBtn = document.getElementById("btn_print");
|
||||
|
||||
|
||||
|
||||
name_input.addEventListener("input", update_canvas);
|
||||
|
||||
// This function gets run everytime some value which impacts the canvas area gets changed
|
||||
function update_canvas() {
|
||||
console.log("Updated Canvas")
|
||||
// Always set canvas size, this can be usefull when loading the size from a diffrent source
|
||||
print_canvas.width = paper_width;
|
||||
print_canvas.height = paper_height;
|
||||
|
||||
// Clear the entire canvas and make sure it is white
|
||||
print_context.fillStyle = "white";
|
||||
print_context.fillRect(0, 0, print_canvas.width, print_canvas.height);
|
||||
|
||||
// Setup basic controls
|
||||
print_context.fillStyle = "black";
|
||||
print_context.font = `40px sans-serif`;
|
||||
print_context.textAlign = "center";
|
||||
|
||||
// Place content on canvas
|
||||
print_context.fillText(name_input.value, paper_width/2, paper_height/2);
|
||||
}
|
||||
|
||||
printBtn.addEventListener("click", trigger_print_canvas);
|
||||
|
||||
function trigger_print_canvas() {
|
||||
// Usually it would be a good idea to disable the UI and show a loading screen here
|
||||
console.log("Kicked-of printing job")
|
||||
printViaIPP(print_server_url)
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
import Printer from "../node_modules/@digasystems/ipp-browser/dist/ipp-browser.js";
|
||||
import decodeResponse from "../node_modules/@digasystems/ipp-browser/dist/ipp-browser.js";
|
||||
import axios from "../node_modules/axios/dist/esm/axios.js";
|
||||
import { Buffer } from "./buffer603.js";
|
||||
|
||||
|
||||
// Get the canvas element
|
||||
const canvas = document.getElementById("print_canvas");
|
||||
|
||||
export function testModule() {
|
||||
console.log("Print Handler running");
|
||||
}
|
||||
|
||||
export function doIPPprint(targetURL) {
|
||||
let url = targetURL;
|
||||
let printer = new Printer(url);
|
||||
console.log(printer);
|
||||
// Ensure the canvas exists
|
||||
if (canvas && canvas instanceof HTMLCanvasElement) {
|
||||
// Export the canvas content to a Blob
|
||||
canvas.toBlob((blob) => {
|
||||
if (!blob) {
|
||||
console.error("Failed to create Blob from canvas.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Use FileReader to read the Blob as an ArrayBuffer
|
||||
const reader = new FileReader();
|
||||
reader.onload = function (event) {
|
||||
const arrayBuffer = event.target.result; // Get the ArrayBuffer
|
||||
|
||||
// Convert ArrayBuffer to Buffer
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
|
||||
let msg = {
|
||||
"operation-attributes-tag": {
|
||||
"document-format": "image/png",
|
||||
// "requesting-user-name": "Web user"
|
||||
},
|
||||
data: buffer,
|
||||
};
|
||||
|
||||
axios
|
||||
.post(url, printer.encodeMsg("Print-Job", msg), {
|
||||
headers: printer.getHeaders(),
|
||||
})
|
||||
.then((response) => {
|
||||
// This section aims to handle the sevres response. It is not finished.
|
||||
console.log("!!!");
|
||||
console.log(response.data);
|
||||
let da = response.data;
|
||||
da = da.split("ipp://")[1].split("!")[0];
|
||||
da = "ipp://" + da;
|
||||
console.log(da);
|
||||
let msgQuery = {
|
||||
"operation-attributes-tag": {
|
||||
"attributes-charset": "utf-8",
|
||||
"attributes-natural-language": "en-us",
|
||||
"job-uri": da, // Or you can use "job-id" and "printer-uri" instead
|
||||
},
|
||||
};
|
||||
|
||||
axios
|
||||
.post(url, printer.encodeMsg("Get-Job-Attributes", msgQuery), {
|
||||
headers: printer.getHeaders(),
|
||||
responseType: "arraybuffer",
|
||||
})
|
||||
.then((response) => {
|
||||
// Output the variable type of response
|
||||
// grab job-state-reasons and job-state from binary reponse
|
||||
const data = Buffer.from(response.data); // Convert to Buffer
|
||||
let dec = new decodeResponse(data);
|
||||
console.log(dec);
|
||||
const ippResponse = parseIPPResponse(data);
|
||||
console.log(ippResponse);
|
||||
|
||||
const jobStateAttribute = ippResponse.attributes.find(
|
||||
(attr) => attr.name === "job-state"
|
||||
);
|
||||
|
||||
if (jobStateAttribute) {
|
||||
console.log(`Job State: ${jobStateAttribute.value}`);
|
||||
} else {
|
||||
console.log("Job State attribute not found.");
|
||||
}
|
||||
});
|
||||
//
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
// alert("An issue occured while printing.")
|
||||
});
|
||||
};
|
||||
|
||||
reader.onerror = function () {
|
||||
console.error("Error reading Blob as ArrayBuffer.");
|
||||
};
|
||||
|
||||
reader.readAsArrayBuffer(blob);
|
||||
}, "image/png"); // Change MIME type if needed
|
||||
} else {
|
||||
console.error(
|
||||
'Canvas element with id "badge" not found or is not a canvas.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class IPPStatus {
|
||||
static SUCCESS = 0x0000;
|
||||
|
||||
static CLIENT_ERROR = 0x0400;
|
||||
|
||||
static SERVER_ERROR = 0x0500;
|
||||
}
|
||||
|
||||
class IPPAttribute {
|
||||
constructor(name, value) {
|
||||
this.name = name;
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
class IPPResponse {
|
||||
constructor(version, statusCode, requestId, attributes) {
|
||||
this.version = version;
|
||||
|
||||
this.statusCode = statusCode;
|
||||
|
||||
this.requestId = requestId;
|
||||
|
||||
this.attributes = attributes;
|
||||
}
|
||||
}
|
||||
|
||||
function parseIPPResponse(data) {
|
||||
const version = data.readUInt16BE(0);
|
||||
|
||||
const statusCode = data.readUInt16BE(2);
|
||||
|
||||
const requestId = data.readUInt32BE(4);
|
||||
|
||||
const length = data.readUInt32BE(8);
|
||||
|
||||
const attributes = [];
|
||||
|
||||
let offset = 12; // Start after the header
|
||||
|
||||
while (offset < length + 12) {
|
||||
const tag = data.readUInt8(offset);
|
||||
|
||||
const nameLength = data.readUInt16BE(offset + 1);
|
||||
|
||||
const valueLength = data.readUInt32BE(offset + 3);
|
||||
|
||||
const name = data.toString("utf8", offset + 5, offset + 5 + nameLength);
|
||||
|
||||
const value = data.toString(
|
||||
"utf8",
|
||||
offset + 5 + nameLength,
|
||||
offset + 5 + nameLength + valueLength
|
||||
);
|
||||
|
||||
attributes.push(new IPPAttribute(name, value));
|
||||
|
||||
offset += 5 + nameLength + valueLength; // Move to the next attribute
|
||||
}
|
||||
|
||||
return new IPPResponse(version, statusCode, requestId, attributes);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
/* esm.sh - esbuild bundle(base64-js@1.5.1) es2022 production */
|
||||
var B=Object.create;var l=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),U=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},A=(r,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!j.call(r,o)&&o!==t&&l(r,o,{get:()=>e[o],enumerable:!(a=_(e,o))||a.enumerable});return r},u=(r,e,t)=>(A(r,e,"default"),t&&A(t,e,"default")),C=(r,e,t)=>(t=r!=null?B(w(r)):{},A(e||!r||!r.__esModule?l(t,"default",{value:r,enumerable:!0}):t,r));var p=H(y=>{"use strict";y.byteLength=I;y.toByteArray=T;y.fromByteArray=D;var h=[],d=[],E=typeof Uint8Array<"u"?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(F=0,L=s.length;F<L;++F)h[F]=s[F],d[s.charCodeAt(F)]=F;var F,L;d[45]=62;d[95]=63;function g(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var a=t===e?0:4-t%4;return[t,a]}function I(r){var e=g(r),t=e[0],a=e[1];return(t+a)*3/4-a}function O(r,e,t){return(e+t)*3/4-t}function T(r){var e,t=g(r),a=t[0],o=t[1],n=new E(O(r,a,o)),v=0,x=o>0?a-4:a,f;for(f=0;f<x;f+=4)e=d[r.charCodeAt(f)]<<18|d[r.charCodeAt(f+1)]<<12|d[r.charCodeAt(f+2)]<<6|d[r.charCodeAt(f+3)],n[v++]=e>>16&255,n[v++]=e>>8&255,n[v++]=e&255;return o===2&&(e=d[r.charCodeAt(f)]<<2|d[r.charCodeAt(f+1)]>>4,n[v++]=e&255),o===1&&(e=d[r.charCodeAt(f)]<<10|d[r.charCodeAt(f+1)]<<4|d[r.charCodeAt(f+2)]>>2,n[v++]=e>>8&255,n[v++]=e&255),n}function q(r){return h[r>>18&63]+h[r>>12&63]+h[r>>6&63]+h[r&63]}function z(r,e,t){for(var a,o=[],n=e;n<t;n+=3)a=(r[n]<<16&16711680)+(r[n+1]<<8&65280)+(r[n+2]&255),o.push(q(a));return o.join("")}function D(r){for(var e,t=r.length,a=t%3,o=[],n=16383,v=0,x=t-a;v<x;v+=n)o.push(z(r,v,v+n>x?x:v+n));return a===1?(e=r[t-1],o.push(h[e>>2]+h[e<<4&63]+"==")):a===2&&(e=(r[t-2]<<8)+r[t-1],o.push(h[e>>10]+h[e>>4&63]+h[e<<2&63]+"=")),o.join("")}});var c={};U(c,{byteLength:()=>G,default:()=>N,fromByteArray:()=>K,toByteArray:()=>J});var i=C(p());u(c,C(p()));var{byteLength:G,toByteArray:J,fromByteArray:K}=i,{default:m,...M}=i,N=m!==void 0?m:M;export{G as byteLength,N as default,K as fromByteArray,J as toByteArray};
|
||||
//# sourceMappingURL=base64-js.mjs.map
|
||||
@@ -0,0 +1,16 @@
|
||||
/* esm.sh - esbuild bundle(buffer@6.0.3) es2022 production */
|
||||
import * as __0$ from "../../base64-js@1.5.1/es2022/base64-js.js";
|
||||
import * as __1$ from "../../ieee754@1.2.1/es2022/ieee754.js";
|
||||
var require=n=>{const e=m=>typeof m.default<"u"?m.default:m,c=m=>Object.assign({},m);switch(n){case"base64-js":return e(__0$);case"ieee754":return e(__1$);default:throw new Error("module \""+n+"\" not found");}};
|
||||
var or=Object.create;var S=Object.defineProperty;var ur=Object.getOwnPropertyDescriptor;var hr=Object.getOwnPropertyNames;var fr=Object.getPrototypeOf,cr=Object.prototype.hasOwnProperty;var O=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(r,t)=>(typeof require<"u"?require:r)[t]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var pr=(i,r)=>()=>(r||i((r={exports:{}}).exports,r),r.exports),lr=(i,r)=>{for(var t in r)S(i,t,{get:r[t],enumerable:!0})},_=(i,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of hr(r))!cr.call(i,e)&&e!==t&&S(i,e,{get:()=>r[e],enumerable:!(n=ur(r,e))||n.enumerable});return i},m=(i,r,t)=>(_(i,r,"default"),t&&_(t,r,"default")),G=(i,r,t)=>(t=i!=null?or(fr(i)):{},_(r||!i||!i.__esModule?S(t,"default",{value:i,enumerable:!0}):t,i));var M=pr(U=>{"use strict";var C=O("base64-js"),d=O("ieee754"),Y=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;U.Buffer=u;U.SlowBuffer=Br;U.INSPECT_MAX_BYTES=50;var R=2147483647;U.kMaxLength=R;u.TYPED_ARRAY_SUPPORT=sr();!u.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function sr(){try{let i=new Uint8Array(1),r={foo:function(){return 42}};return Object.setPrototypeOf(r,Uint8Array.prototype),Object.setPrototypeOf(i,r),i.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}});Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function x(i){if(i>R)throw new RangeError('The value "'+i+'" is invalid for option "size"');let r=new Uint8Array(i);return Object.setPrototypeOf(r,u.prototype),r}function u(i,r,t){if(typeof i=="number"){if(typeof r=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return N(i)}return V(i,r,t)}u.poolSize=8192;function V(i,r,t){if(typeof i=="string")return wr(i,r);if(ArrayBuffer.isView(i))return ar(i);if(i==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i);if(a(i,ArrayBuffer)||i&&a(i.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(a(i,SharedArrayBuffer)||i&&a(i.buffer,SharedArrayBuffer)))return L(i,r,t);if(typeof i=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=i.valueOf&&i.valueOf();if(n!=null&&n!==i)return u.from(n,r,t);let e=xr(i);if(e)return e;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof i[Symbol.toPrimitive]=="function")return u.from(i[Symbol.toPrimitive]("string"),r,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof i)}u.from=function(i,r,t){return V(i,r,t)};Object.setPrototypeOf(u.prototype,Uint8Array.prototype);Object.setPrototypeOf(u,Uint8Array);function j(i){if(typeof i!="number")throw new TypeError('"size" argument must be of type number');if(i<0)throw new RangeError('The value "'+i+'" is invalid for option "size"')}function yr(i,r,t){return j(i),i<=0?x(i):r!==void 0?typeof t=="string"?x(i).fill(r,t):x(i).fill(r):x(i)}u.alloc=function(i,r,t){return yr(i,r,t)};function N(i){return j(i),x(i<0?0:$(i)|0)}u.allocUnsafe=function(i){return N(i)};u.allocUnsafeSlow=function(i){return N(i)};function wr(i,r){if((typeof r!="string"||r==="")&&(r="utf8"),!u.isEncoding(r))throw new TypeError("Unknown encoding: "+r);let t=z(i,r)|0,n=x(t),e=n.write(i,r);return e!==t&&(n=n.slice(0,e)),n}function b(i){let r=i.length<0?0:$(i.length)|0,t=x(r);for(let n=0;n<r;n+=1)t[n]=i[n]&255;return t}function ar(i){if(a(i,Uint8Array)){let r=new Uint8Array(i);return L(r.buffer,r.byteOffset,r.byteLength)}return b(i)}function L(i,r,t){if(r<0||i.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(i.byteLength<r+(t||0))throw new RangeError('"length" is outside of buffer bounds');let n;return r===void 0&&t===void 0?n=new Uint8Array(i):t===void 0?n=new Uint8Array(i,r):n=new Uint8Array(i,r,t),Object.setPrototypeOf(n,u.prototype),n}function xr(i){if(u.isBuffer(i)){let r=$(i.length)|0,t=x(r);return t.length===0||i.copy(t,0,0,r),t}if(i.length!==void 0)return typeof i.length!="number"||P(i.length)?x(0):b(i);if(i.type==="Buffer"&&Array.isArray(i.data))return b(i.data)}function $(i){if(i>=R)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+R.toString(16)+" bytes");return i|0}function Br(i){return+i!=i&&(i=0),u.alloc(+i)}u.isBuffer=function(r){return r!=null&&r._isBuffer===!0&&r!==u.prototype};u.compare=function(r,t){if(a(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),a(t,Uint8Array)&&(t=u.from(t,t.offsetLine truncated
|
||||
/*! Bundled license information:
|
||||
|
||||
buffer/index.js:
|
||||
(*!
|
||||
* The buffer module from node.js, for the browser.
|
||||
*
|
||||
* @author Feross Aboukhadijeh <https://feross.org>
|
||||
* @license MIT
|
||||
*)
|
||||
*/
|
||||
//# sourceMappingURL=buffer.mjs.map
|
||||
@@ -0,0 +1,8 @@
|
||||
/* esm.sh - esbuild bundle(ieee754@1.2.1) es2022 production */
|
||||
var y=Object.create;var v=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var F=(a,r)=>()=>(r||a((r={exports:{}}).exports,r),r.exports),G=(a,r)=>{for(var i in r)v(a,i,{get:r[i],enumerable:!0})},e=(a,r,i,f)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of A(r))!D.call(a,o)&&o!==i&&v(a,o,{get:()=>r[o],enumerable:!(f=z(r,o))||f.enumerable});return a},_=(a,r,i)=>(e(a,r,"default"),i&&e(i,r,"default")),B=(a,r,i)=>(i=a!=null?y(C(a)):{},e(r||!a||!a.__esModule?v(i,"default",{value:a,enumerable:!0}):i,a));var g=F(I=>{I.read=function(a,r,i,f,o){var h,t,w=o*8-f-1,s=(1<<w)-1,N=s>>1,M=-7,p=i?o-1:0,c=i?-1:1,d=a[r+p];for(p+=c,h=d&(1<<-M)-1,d>>=-M,M+=w;M>0;h=h*256+a[r+p],p+=c,M-=8);for(t=h&(1<<-M)-1,h>>=-M,M+=f;M>0;t=t*256+a[r+p],p+=c,M-=8);if(h===0)h=1-N;else{if(h===s)return t?NaN:(d?-1:1)*(1/0);t=t+Math.pow(2,f),h=h-N}return(d?-1:1)*t*Math.pow(2,h-f)};I.write=function(a,r,i,f,o,h){var t,w,s,N=h*8-o-1,M=(1<<N)-1,p=M>>1,c=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=f?0:h-1,n=f?1:-1,q=r<0||r===0&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(w=isNaN(r)?1:0,t=M):(t=Math.floor(Math.log(r)/Math.LN2),r*(s=Math.pow(2,-t))<1&&(t--,s*=2),t+p>=1?r+=c/s:r+=c*Math.pow(2,1-p),r*s>=2&&(t++,s/=2),t+p>=M?(w=0,t=M):t+p>=1?(w=(r*s-1)*Math.pow(2,o),t=t+p):(w=r*Math.pow(2,p-1)*Math.pow(2,o),t=0));o>=8;a[i+d]=w&255,d+=n,w/=256,o-=8);for(t=t<<o|w,N+=o;N>0;a[i+d]=t&255,d+=n,t/=256,N-=8);a[i+d-n]|=q*128}});var x={};G(x,{default:()=>O,read:()=>H,write:()=>J});var k=B(g());_(x,B(g()));var{read:H,write:J}=k,{default:j,...K}=k,O=j!==void 0?j:K;export{O as default,H as read,J as write};
|
||||
/*! Bundled license information:
|
||||
|
||||
ieee754/index.js:
|
||||
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
||||
*/
|
||||
//# sourceMappingURL=ieee754.mjs.map
|
||||
Reference in new issue
Block a user