inital commit

This commit is contained in:
TheGreydiamond
2025-08-18 20:02:43 +02:00
parent d812e8f4a7
commit 7b45a854fe
1672 changed files with 298536 additions and 1 deletions

5
js/buffer603.js Normal file
View File

@@ -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";

56
js/content_handler.js Normal file
View File

@@ -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)
}

170
js/print_handler.js Normal file
View File

@@ -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);
}

View File

@@ -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

File diff suppressed because one or more lines are too long

View File

@@ -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