= []; // the internal buffer of lines
+ const paint = () => {
+ println.paintedFrames++
+ target.innerText = buffer.join("\n")
+ scrollContainer.scrollTop = scrollContainer.scrollHeight
+ lastAnimationFrame = null
+ }
+
+ const println = (line: string, flush?: boolean) => {
+ // add the line
+ buffer.push(line)
+ if (size !== 0 && buffer.length > size) {
+ buffer.splice(0, buffer.length - size)
+ }
+
+ // and update the browser in the next animation frame
+ if (lastAnimationFrame !== null) {
+ println.missedFrames++
+ window.cancelAnimationFrame(lastAnimationFrame)
+ }
+
+ // force a repaint!
+ if(flush) return paint();
+
+ // schedule an animation frame
+ lastAnimationFrame = window.requestAnimationFrame(paint);
+ }
+ println.paintedFrames = 0;
+ println.missedFrames = 0;
+
+ return println;
+}
+
+const elements = document.getElementsByClassName('remote-action')
+Array.from(elements).forEach((element) => {
+ const action = element.getAttribute('data-action') as string;
+ const param = element.getAttribute('data-param') as string | undefined;
+ const bufferSize = (function () {
+ const number = parseInt(element.getAttribute('data-buffer') ?? "", 10) ?? 0;
+ return (isFinite(number) && number > 0) ? number : 0;
+ })()
+
+ element.addEventListener('click', function (ev) {
+ ev.preventDefault();
+
+ // create a modal dialog and append it to the body
+ const modal = document.createElement("div")
+ modal.className = "modal-terminal"
+ document.body.append(modal)
+
+ // create a to write stuff into
+ const target = document.createElement("pre")
+ const println = makeTextBuffer(target, modal, bufferSize)
+ modal.append(target)
+
+
+ // create a button to eventually close everything
+ const button = document.createElement("button")
+ button.className = "pure-button"
+ button.append("Close")
+ button.addEventListener('click', function (event) {
+ event.preventDefault();
+ modal.parentNode?.removeChild(modal);
+ })
+
+ // when closing, add a button to the modal!
+ let didClose = false
+ const close = function () {
+ if (didClose) return
+ didClose = true
+
+ modal.append(button)
+ // DEBUG: print terminal stats!
+ // const quota = (println.paintedFrames / (println.missedFrames + println.paintedFrames)) * 100
+ // println(`Terminal: painted=${println.paintedFrames} missed=${println.missedFrames} (${quota}%)`, true)
+ }
+
+ println("Connecting ...", true)
+
+ // connect to the socket and send the action
+ connectSocket((socket) => {
+ println("Connected", true)
+ socket.send(action);
+ if (typeof param === 'string') {
+ socket.send(param);
+ }
+ }, (data) => {
+ println(data);
+ }).then(() => {
+ println("Connection closed.", true)
+ close();
+ }).catch(() => {
+ println("Connection errored.", true)
+ close();
+ });
+ });
+})
\ No newline at end of file
diff --git a/internal/component/static/src/socket/socket.ts b/internal/component/static/src/lib/remote/socket.ts
similarity index 100%
rename from internal/component/static/src/socket/socket.ts
rename to internal/component/static/src/lib/remote/socket.ts
diff --git a/internal/component/static/static.go b/internal/component/static/static.go
index 676069b..08637a6 100644
--- a/internal/component/static/static.go
+++ b/internal/component/static/static.go
@@ -6,8 +6,10 @@ import (
"embed"
"io/fs"
"net/http"
+ "strings"
"github.com/FAU-CDI/wisski-distillery/internal/component"
+ "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/tkw1536/goprogram/stream"
)
@@ -25,6 +27,13 @@ func (static *Static) Handler(route string, context context.Context, io stream.I
return nil, err
}
+ // censor *.html in the filesystem
+ fs = fsx.Censor(fs, func(path string) bool {
+ suffix := "html"
+ return len(path) >= len(suffix) && strings.EqualFold(path[len(path)-len(suffix):], suffix)
+ })
+
+ // and serve it
return http.StripPrefix(route, http.FileServer(http.FS(fs))), nil
}
diff --git a/internal/component/static/tsconfig.json b/internal/component/static/tsconfig.json
new file mode 100644
index 0000000..b19b767
--- /dev/null
+++ b/internal/component/static/tsconfig.json
@@ -0,0 +1,105 @@
+{
+ "compilerOptions": {
+ /* Visit https://aka.ms/tsconfig to read more about this file */
+
+ /* Projects */
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
+
+ /* Language and Environment */
+ "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
+
+ /* Modules */
+ "module": "commonjs", /* Specify what module code is generated. */
+ // "rootDir": "./", /* Specify the root folder within your source files. */
+ // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
+ "paths": {
+ "~/*": ["./*"],
+ }, /* Specify a set of entries that re-map imports to additional lookup locations. */
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
+ // "resolveJsonModule": true, /* Enable importing .json files. */
+ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */
+
+ /* JavaScript Support */
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
+
+ /* Emit */
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
+ // "removeComments": true, /* Disable emitting comments. */
+ // "noEmit": true, /* Disable emitting files from a compilation. */
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
+
+ /* Interop Constraints */
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
+
+ /* Type Checking */
+ "strict": true, /* Enable all strict type-checking options. */
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
+
+ /* Completeness */
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
+ }
+}
diff --git a/internal/component/static/yarn.lock b/internal/component/static/yarn.lock
index 8def55b..a7554b5 100644
--- a/internal/component/static/yarn.lock
+++ b/internal/component/static/yarn.lock
@@ -891,6 +891,11 @@ csso@^4.2.0:
dependencies:
css-tree "^1.1.2"
+dayjs@^1.11.5:
+ version "1.11.5"
+ resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.5.tgz#00e8cc627f231f9499c19b38af49f56dc0ac5e93"
+ integrity sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==
+
detect-libc@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..6fb5314
--- /dev/null
+++ b/package.json
@@ -0,0 +1,5 @@
+{
+ "dependencies": {
+ "purecss": "^2.1.0"
+ }
+}
diff --git a/pkg/fsx/filter.go b/pkg/fsx/filter.go
new file mode 100644
index 0000000..3e7494f
--- /dev/null
+++ b/pkg/fsx/filter.go
@@ -0,0 +1,94 @@
+package fsx
+
+import (
+ "io/fs"
+ "path/filepath"
+
+ "github.com/tkw1536/goprogram/lib/collection"
+)
+
+// Censor returns a new filesystem censors files for which the censor function returns true.
+//
+// A censored file cannot be opened by the filesystem and return [fs.ErrNotExist].
+// Hard and Soft Links pointing to the file might still read it.
+func Censor(fsys fs.FS, censor func(name string) bool) fs.FS {
+ return &censorFS{
+ fsys: fsys,
+ censor: censor,
+ }
+}
+
+type censorFS struct {
+ censor func(path string) bool
+ fsys fs.FS
+}
+
+func (cf *censorFS) Sub(path string) (fs.FS, error) {
+ sub, err := fs.Sub(cf.fsys, path)
+ if err != nil {
+ return nil, err
+ }
+ return &censorFS{
+ censor: func(name string) bool {
+ return cf.censor(filepath.Join(path, name))
+ },
+ fsys: sub,
+ }, nil
+}
+
+func (ef *censorFS) Open(name string) (fs.File, error) {
+ if ef.censor(name) {
+ return nil, fs.ErrNotExist
+ }
+
+ file, err := ef.fsys.Open(name)
+
+ // we need to also censor the ReadDir function of the returned file
+ // this is to prevent the file from appearing in directory listings.
+ if rdf, ok := file.(fs.ReadDirFile); ok {
+ return &censorFSFile{
+ ReadDirFile: rdf,
+
+ name: name,
+ censor: ef,
+ }, err
+ }
+ return file, err
+}
+
+type censorFSFile struct {
+ fs.ReadDirFile
+
+ name string
+ censor *censorFS
+}
+
+func (f *censorFSFile) ReadDir(n int) ([]fs.DirEntry, error) {
+ entries, err := f.ReadDirFile.ReadDir(n)
+ return f.censor.handleReadDir(f.name, entries, err)
+}
+
+func (ef *censorFS) ReadDir(name string) ([]fs.DirEntry, error) {
+ if ef.censor(name) {
+ return nil, fs.ErrNotExist
+ }
+
+ // censor ReadDir() entries too
+ entries, err := fs.ReadDir(ef.fsys, name)
+ return ef.handleReadDir(name, entries, err)
+}
+
+// handleReadDir censors a ReadDir call
+func (ef *censorFS) handleReadDir(base string, entries []fs.DirEntry, err error) ([]fs.DirEntry, error) {
+ entries = collection.Filter(entries, func(entry fs.DirEntry) bool {
+ return !ef.censor(filepath.Join(base, entry.Name()))
+ })
+ return entries, err
+}
+
+func (ef *censorFS) ReadFile(name string) ([]byte, error) {
+ if ef.censor(name) {
+ return nil, fs.ErrNotExist
+ }
+ return fs.ReadFile(ef.fsys, name)
+}
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
new file mode 100644
index 0000000..fa58c1a
--- /dev/null
+++ b/pkg/resources/resources.go
@@ -0,0 +1,113 @@
+// Package resources provides Resources
+package resources
+
+import (
+ "html/template"
+ "io"
+ "strings"
+
+ "github.com/tkw1536/goprogram/lib/collection"
+ "golang.org/x/net/html"
+)
+
+// Resources represents resources found inside a "html" file
+type Resources struct {
+ JSModules []string // ")
+
+// WriteCSS writes all link tags to writer
+func (resources *Resources) WriteCSS(writer io.Writer) {
+ for _, href := range resources.CSS {
+ writer.Write(openLinkBytes)
+ writer.Write([]byte(attributeValue(href)))
+ writer.Write(closeLinkBytes)
+ }
+}
+
+func (resources *Resources) CSSTemplate() template.HTML {
+ var buffer strings.Builder
+ resources.WriteCSS(&buffer)
+ return template.HTML(buffer.String())
+}
+
+// WriteJS writes all JavaScript tags to writer
+func (resources *Resources) WriteJS(writer io.Writer) {
+ for _, href := range resources.JSModules {
+ writer.Write(openModuleBytes)
+ writer.Write([]byte(attributeValue(href)))
+ writer.Write(closeScriptBytes)
+ }
+ for _, href := range resources.JSRegular {
+ writer.Write(openRegularBytes)
+ writer.Write([]byte(attributeValue(href)))
+ writer.Write(closeScriptBytes)
+ }
+}
+
+func (resources *Resources) JSTemplate() template.HTML {
+ var buffer strings.Builder
+ resources.WriteJS(&buffer)
+ return template.HTML(buffer.String())
+}
+
+// Parse parses resources from reader
+func Parse(r io.Reader) (src Resources) {
+ z := html.NewTokenizer(r)
+ for {
+ // read the next token
+ z.Next()
+ token := z.Token()
+
+ switch {
+ case token.Type == html.ErrorToken:
+ return
+
+ case token.Type == html.StartTagToken && token.Data == "script":
+ //
+
+
+
+