site-falcon/implementation.html

1107 lines
44 KiB
HTML
Raw Normal View History

2022-11-27 17:16:56 +11:00
<html>
<head>
2022-11-29 22:02:38 +11:00
<style>
@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200');
2022-11-30 20:56:37 +11:00
@import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200");
2022-11-29 22:02:38 +11:00
</style>
2022-11-27 17:16:56 +11:00
</head>
<body>
<div style="height: 50px; width: 10000px; background-color: blue;"></div>
2022-11-28 21:32:06 +11:00
<button id="button"></button>
2022-11-29 22:02:38 +11:00
<span class="material-symbols-rounded">
close
</span>
2022-11-27 17:16:56 +11:00
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
v
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<p>Nice thanks man awesome</p>
<template id="x-widget-template">
2022-12-02 00:44:55 +11:00
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"></script>
2022-11-27 17:16:56 +11:00
<style>
2022-11-30 20:56:37 +11:00
@import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200");
@import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200");
2022-11-29 22:02:38 +11:00
2022-11-27 17:16:56 +11:00
* {
box-sizing: border-box;
2022-11-30 20:56:37 +11:00
--unit-spacing: 8px;
2022-11-28 21:32:06 +11:00
--icon-default-dim: 60px;
2022-11-29 22:02:38 +11:00
--form-default-width: 450px;
2022-12-02 23:40:27 +11:00
--form-default-height: 580px;
2022-11-30 20:56:37 +11:00
--side-margin: calc(var(--unit-spacing) * 2);
--site-falcon-purple-1: #AE55E7;
--site-falcon-purple-2: #a544e3;
2022-12-02 23:40:27 +11:00
--site-falcon-blue: #0098FF;
--site-falcon-red: #FF4031;
2022-11-30 20:56:37 +11:00
--site-falcon-grey-1: #ececec;
--site-falcon-grey-2: #e0e0e0;
--site-falcon-grey-3: #d3d3d3;
--site-falcon-grey-4: #5A5A5A;
--form-element-border-size: 2px;
--form-border-radius: var(--unit-spacing);
2022-11-27 17:16:56 +11:00
}
#icon {
2022-11-28 21:32:06 +11:00
width: var(--icon-default-dim);
height: var(--icon-default-dim);
2022-11-27 17:16:56 +11:00
position: fixed;
2022-11-28 21:32:06 +11:00
visibility: visible;
opacity: 1;
2022-11-29 22:02:38 +11:00
transition: top 0.3s ease 0s, left 0.3s ease 0s, scale 0.2s ease, transform 0.5s ease, visibility 0s linear 0.3s, opacity 0.3s linear;
2022-11-27 17:16:56 +11:00
}
#icon.location-top-left {
left: var(--side-margin);
top: var(--side-margin);
}
#icon.location-top-right {
2022-11-28 21:32:06 +11:00
left: calc(100% - var(--icon-default-dim) - var(--side-margin));
2022-11-27 17:16:56 +11:00
top: var(--side-margin);
}
#icon.location-bottom-left {
left: var(--side-margin);
2022-11-28 21:32:06 +11:00
top: calc(100% - var(--icon-default-dim) - var(--side-margin));
2022-11-27 17:16:56 +11:00
}
#icon.location-bottom-right {
2022-11-28 21:32:06 +11:00
left: calc(100% - var(--icon-default-dim) - var(--side-margin));
top: calc(100% - var(--icon-default-dim) - var(--side-margin));
2022-11-27 17:16:56 +11:00
}
2022-11-28 21:32:06 +11:00
#icon:hover {
scale: 1.05;
}
2022-11-27 17:16:56 +11:00
#icon > img {
width: 100%;
height: 100%;
}
#form {
2022-11-28 21:32:06 +11:00
width: var(--form-default-width);
height: var(--form-default-height);
2022-11-27 17:16:56 +11:00
background-color: white;
border: 0px;
2022-11-30 20:56:37 +11:00
border-radius: var(--form-border-radius);
box-shadow: 0 calc(var(--unit-spacing) / 2) calc(var(--unit-spacing) * 2) rgb(0 0 0 / 25%);
2022-11-27 17:16:56 +11:00
position: fixed;
2022-11-28 21:32:06 +11:00
visibility: visible;
opacity: 1;
2022-11-30 20:56:37 +11:00
transition: transform 0.4s ease, visibility 0s linear 0.3s, opacity 0.3s linear;
2022-12-02 23:40:27 +11:00
display: flex;
flex-direction: column;
2022-11-27 17:16:56 +11:00
}
#form.location-top-left {
left: var(--side-margin);
2022-11-28 21:32:06 +11:00
top: var(--side-margin);
2022-11-27 17:16:56 +11:00
}
#form.location-top-right {
2022-11-28 21:32:06 +11:00
left: calc(100% - var(--form-default-width) - var(--side-margin));
top: var(--side-margin);
2022-11-27 17:16:56 +11:00
}
#form.location-bottom-left {
left: var(--side-margin);
2022-11-28 21:32:06 +11:00
top: calc(100% - var(--form-default-height) - var(--side-margin));
2022-11-27 17:16:56 +11:00
}
#form.location-bottom-right {
2022-11-28 21:32:06 +11:00
left: calc(100% - var(--form-default-width) - var(--side-margin));
top: calc(100% - var(--form-default-height) - var(--side-margin));
2022-11-27 17:16:56 +11:00
}
#form-header {
top: 0px;
width: 100%;
2022-11-30 20:56:37 +11:00
height: calc(var(--unit-spacing) * 8);
background-image: linear-gradient(var(--site-falcon-purple-2), var(--site-falcon-purple-1));
border-radius: var(--form-border-radius) var(--form-border-radius) 0px 0px;
2022-11-27 17:16:56 +11:00
border: 0px;
justify-content: center;
align-items: center;
display: flex;
}
2022-12-02 23:57:35 +11:00
.form-header-button {
2022-11-29 22:02:38 +11:00
cursor: pointer;
user-select: none;
color: white;
2022-11-30 20:56:37 +11:00
margin-left: calc(var(--unit-spacing) * 2);
2022-11-29 22:02:38 +11:00
font-size: 26px;
transition: scale 0.2s ease;
}
2022-12-02 23:57:35 +11:00
.form-header-button:hover {
2022-11-29 22:02:38 +11:00
scale: 1.1;
}
#form-button-help {
2022-11-30 20:56:37 +11:00
margin-left: calc(var(--unit-spacing) * 2);
2022-11-29 22:02:38 +11:00
}
#form-button-close {
2022-11-30 20:56:37 +11:00
margin-right: calc(var(--unit-spacing) * 2);
2022-11-29 22:02:38 +11:00
}
2022-11-27 17:16:56 +11:00
#form-title {
2022-11-29 22:02:38 +11:00
font-family: "Alexandria", sans-serif;
2022-11-27 17:16:56 +11:00
font-weight: 400;
font-size: 24px;
color: white;
text-align: center;
2022-11-29 22:02:38 +11:00
user-select: none;
flex-grow: 1;
2022-11-27 17:16:56 +11:00
}
#form-content-container {
width: 100%;
align-items: center;
2022-11-30 20:56:37 +11:00
padding-left: calc(var(--unit-spacing) * 4);
padding-right: calc(var(--unit-spacing) * 4);
2022-12-02 23:40:27 +11:00
padding: calc(var(--unit-spacing) * 4);
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
2022-11-27 17:16:56 +11:00
}
#input-name-container {
2022-11-27 18:31:55 +11:00
width: 100%;
2022-11-27 17:16:56 +11:00
position: relative;
}
2022-11-27 18:44:11 +11:00
.md-input {
2022-11-27 18:31:55 +11:00
width: 100%;
2022-11-30 20:56:37 +11:00
border: var(--form-element-border-size) solid var(--site-falcon-grey-3);
border-radius: calc(var(--unit-spacing) / 2);
2022-11-27 17:16:56 +11:00
padding: 16px;
}
2022-11-27 18:44:11 +11:00
#input-name {
2022-11-30 20:56:37 +11:00
height: calc(var(--unit-spacing) * 6);
2022-11-27 18:44:11 +11:00
}
.label-md-input {
2022-11-27 17:16:56 +11:00
position: absolute;
top: 0;
2022-11-30 20:56:37 +11:00
left: calc(var(--unit-spacing) * 2);
2022-11-27 17:16:56 +11:00
display: flex;
pointer-events: none;
}
2022-11-28 00:41:01 +11:00
#input-name + .label-md-input {
bottom: 0;
align-items: center;
}
2022-12-02 23:40:27 +11:00
#input-description + .label-md-input {
2022-11-30 20:56:37 +11:00
margin-top: calc(var(--unit-spacing) * 2);
2022-11-28 00:41:01 +11:00
}
2022-12-02 23:40:27 +11:00
#input-name:not(#input-name[value=""]), #input-description:not(#input-description[value=""]) {
2022-11-29 22:02:38 +11:00
font-size: 16px;
}
2022-11-27 18:44:11 +11:00
.md-input, .label-md-input > div {
2022-11-29 22:02:38 +11:00
font-family: "Alexandria", sans-serif;
2022-11-27 17:16:56 +11:00
font-weight: 300;
font-size: 16px;
}
2022-11-27 18:44:11 +11:00
.label-md-input > div {
2022-11-27 17:16:56 +11:00
transition: all 0.15s ease-out, visibility 0s;
color: grey;
}
2022-11-27 18:44:11 +11:00
.md-input:focus {
2022-11-27 17:16:56 +11:00
outline: none;
2022-11-30 20:56:37 +11:00
border: var(--form-element-border-size) solid var(--site-falcon-purple-1);
2022-11-27 17:16:56 +11:00
}
2022-11-27 18:55:16 +11:00
#input-name:focus + .label-md-input > div, #input-name:not(#input-name[value=""]) + .label-md-input > div {
2022-11-27 17:16:56 +11:00
font-size: 14px;
transform: translate(0, -150%);
background-color: white;
2022-11-30 20:56:37 +11:00
padding-left: calc(var(--unit-spacing) / 2);
padding-right: calc(var(--unit-spacing) / 2);
2022-11-27 17:16:56 +11:00
}
2022-12-02 23:40:27 +11:00
#input-description:focus + .label-md-input > div, #input-description:not(#input-description[value=""]) + .label-md-input > div {
2022-11-27 18:55:16 +11:00
font-size: 14px;
2022-11-28 00:41:01 +11:00
transform: translate(0, -150%);
2022-11-27 18:55:16 +11:00
background-color: white;
2022-11-30 20:56:37 +11:00
padding-left: calc(var(--unit-spacing) / 2);
padding-right: calc(var(--unit-spacing) / 2);
2022-11-27 18:55:16 +11:00
}
2022-11-27 18:44:11 +11:00
.md-input:focus + .label-md-input > div {
2022-11-30 20:56:37 +11:00
color: var(--site-falcon-purple-1);
2022-11-27 17:16:56 +11:00
}
2022-11-27 18:31:55 +11:00
#select-severity-container {
width: 100%;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-column-gap: 0px;
justify-content: center;
align-items: center;
}
.severity-option {
margin: 0px;
2022-11-30 20:56:37 +11:00
height: calc(var(--unit-spacing) * 6);
background-color: var(--site-falcon-grey-1);
border: var(--form-element-border-size) solid var(--site-falcon-grey-3);
2022-11-27 18:31:55 +11:00
border-left: 0px;
2022-11-29 22:02:38 +11:00
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
cursor: pointer;
user-select: none;
transition: background-color 0.15s ease;
}
.severity-option .material-symbols-rounded {
2022-11-30 20:56:37 +11:00
color: var(--site-falcon-grey-4);
font-size: 26px;
2022-11-29 22:02:38 +11:00
}
.severity-option .material-symbols-rounded:not(:first-child) {
2022-11-30 20:56:37 +11:00
margin-left: -14px;
2022-11-27 18:31:55 +11:00
}
.severity-option:hover:not(.selected) {
2022-11-30 20:56:37 +11:00
background-color: var(--site-falcon-grey-2);
2022-11-27 18:31:55 +11:00
}
.severity-option.selected {
2022-11-30 20:56:37 +11:00
background-color: var(--site-falcon-grey-3);
2022-11-27 18:31:55 +11:00
}
2022-11-29 22:02:38 +11:00
#select-severity-container > :first-child {
2022-11-30 20:56:37 +11:00
border-left: var(--form-element-border-size) solid var(--site-falcon-grey-3);
border-radius: calc(var(--unit-spacing) / 2) 0px 0px calc(var(--unit-spacing) / 2);
2022-11-27 18:31:55 +11:00
}
#select-severity-container :last-child {
2022-11-30 20:56:37 +11:00
border-radius: 0px calc(var(--unit-spacing) / 2) calc(var(--unit-spacing) / 2) 0px;
2022-11-27 18:31:55 +11:00
}
2022-11-27 18:44:11 +11:00
2022-12-02 23:40:27 +11:00
#input-description-container {
2022-11-27 18:44:11 +11:00
width: 100%;
position: relative;
}
2022-12-02 23:40:27 +11:00
#input-description {
2022-11-30 20:56:37 +11:00
height: calc(var(--unit-spacing) * 19);
2022-11-27 19:02:48 +11:00
resize: none;
2022-11-27 18:44:11 +11:00
}
2022-11-28 21:32:06 +11:00
#icon:not(.hidden), #form:not(.hidden) {
transition-delay: 0s;
}
#icon.hidden, #form.hidden {
pointer-events: none;
visibility: hidden;
opacity: 0;
}
#icon.hidden.location-bottom-left, #form.hidden.location-bottom-left,
#icon.hidden.location-bottom-right, #form.hidden.location-bottom-right {
2022-11-29 22:02:38 +11:00
transform: translateY(100%);
2022-11-28 21:32:06 +11:00
}
#icon.hidden.location-top-left, #form.hidden.location-top-left,
#icon.hidden.location-top-right, #form.hidden.location-top-right {
2022-11-29 22:02:38 +11:00
transform: translateY(-100%);
2022-11-28 21:32:06 +11:00
}
#icon.hidden {
scale: 1.05;
}
2022-11-30 20:56:37 +11:00
2022-12-02 23:40:27 +11:00
#container-snapshot {
width: 100%;
display: grid;
grid-template-columns: 1fr;
justify-content: center;
align-items: center;
}
#container-snapshot.snapshot-taken {
grid-template-columns: 7fr 1fr 1fr;
}
#container-snapshot .material-symbols-rounded.snapshot-taken {
display: block;
}
#container-snapshot .material-symbols-rounded:hover {
cursor: pointer;
}
2022-11-30 20:56:37 +11:00
#button-snapshot {
width: 100%;
height: calc(var(--unit-spacing) * 6);
border-radius: calc(var(--unit-spacing) / 2);
border: var(--form-element-border-size) dashed var(--site-falcon-grey-3);
background-color: var(--site-falcon-grey-1);
color: var(--site-falcon-grey-4);
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
user-select: none;
transition: background-color 0.15s ease;
}
#button-snapshot .material-symbols-outlined {
font-size: 30px;
}
#button-snapshot:hover {
background-color: var(--site-falcon-grey-3);
}
2022-12-02 23:40:27 +11:00
#container-snapshot > .material-symbols-rounded {
display: none;
margin-left: auto;
font-size: 30px;
}
#button-view-snapshot {
color: var(--site-falcon-blue);
}
#button-delete-snapshot {
color: var(--site-falcon-red);
}
#name-snapshot {
margin-left: auto;
font-family: "Alexandria", sans-serif;
font-weight: 400;
font-size: 24px;
color: green;
text-align: right;
user-select: none;
}
2022-12-02 23:57:35 +11:00
#footer-buttons-container {
2022-11-30 20:56:37 +11:00
width: 100%;
2022-12-02 23:57:35 +11:00
display: flex;
flex-direction: row;
}
#footer-buttons-container .form-footer-button {
width: 45%;
2022-11-30 20:56:37 +11:00
height: calc(var(--unit-spacing) * 6);
border-radius: calc(var(--unit-spacing) / 2);
font-family: "Alexandria", sans-serif;
font-weight: 400;
font-size: 20px;
border: 0px;
cursor: pointer;
user-select: none;
transition: background-color 0.15s ease;
}
2022-12-02 23:57:35 +11:00
#button-clear-form {
margin-right: auto;
color: var(--site-falcon-grey-4);
background-color: var(--site-falcon-grey-1);
}
#button-clear-form:hover {
background-color: var(--site-falcon-grey-2);
}
#button-submit {
margin-left: auto;
color: white;
background-color: var(--site-falcon-purple-1);
}
2022-11-30 20:56:37 +11:00
#button-submit:hover {
background-color: var(--site-falcon-purple-2);
}
#canvas-snapshot {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
visibility: hidden;
cursor: crosshair;
}
#canvas-snapshot.visible {
visibility: visible;
}
2022-11-27 17:16:56 +11:00
</style>
2022-11-30 20:56:37 +11:00
<canvas id="canvas-snapshot">
</canvas>
2022-11-27 17:16:56 +11:00
<div id="icon">
2022-11-28 21:32:06 +11:00
<img src="icon_open.png">
2022-11-27 17:16:56 +11:00
</div>
<div id="form">
<div id="form-header">
2022-12-02 23:57:35 +11:00
<span id="form-button-help" class="material-symbols-rounded form-header-button">
2022-11-29 22:02:38 +11:00
help
</span>
2022-11-27 17:16:56 +11:00
<div id="form-title">
New Ticket
</div>
2022-12-02 23:57:35 +11:00
<span id="form-button-close" class="material-symbols-rounded form-header-button">
2022-11-29 22:02:38 +11:00
close
</span>
2022-11-27 17:16:56 +11:00
</div>
<div id="form-content-container">
2022-11-27 18:31:55 +11:00
<div id="select-severity-container">
2022-11-30 20:56:37 +11:00
<div title="General Comment" class="severity-option selected" id="option-no-severity">
2022-11-29 22:02:38 +11:00
<span class="material-symbols-rounded">
info
</span>
</div>
<div title="Low Priority" class="severity-option" id="option-low-severity">
<span class="material-symbols-rounded">
2022-11-27 18:31:55 +11:00
priority_high
2022-11-29 22:02:38 +11:00
</span>
2022-11-27 18:31:55 +11:00
</div>
2022-11-29 22:02:38 +11:00
<div title="Medium Priority" class="severity-option" id="option-medium-severity">
<span class="material-symbols-rounded">
2022-11-27 18:31:55 +11:00
priority_high
</span>
<span class="material-symbols-rounded">
priority_high
2022-11-29 22:02:38 +11:00
</span>
2022-11-27 18:31:55 +11:00
</div>
2022-11-29 22:02:38 +11:00
<div title="High Priority" class="severity-option" id="option-high-severity">
<span class="material-symbols-rounded">
2022-11-27 18:31:55 +11:00
priority_high
</span>
<span class="material-symbols-rounded">
priority_high
</span>
<span class="material-symbols-rounded">
priority_high
2022-11-29 22:02:38 +11:00
</span>
2022-11-27 18:31:55 +11:00
</div>
</div>
2022-11-30 20:56:37 +11:00
<div id="input-name-container">
<input
type="text"
id="input-name"
class="md-input"
name="name"
value=""
aria-labelledby="label-input-name"
/>
<label for="name" class="label-md-input">
<div>Name</div>
</label>
</div>
2022-12-02 23:40:27 +11:00
<div id="input-description-container">
2022-11-27 18:44:11 +11:00
<textarea
type="text"
2022-12-02 23:40:27 +11:00
id="input-description"
2022-11-27 18:44:11 +11:00
class="md-input"
2022-12-02 23:40:27 +11:00
name="description"
2022-11-27 18:44:11 +11:00
value=""
2022-12-02 23:40:27 +11:00
aria-labelledby="label-input-description"
2022-11-27 18:44:11 +11:00
></textarea>
2022-12-02 23:40:27 +11:00
<label for="description" class="label-md-input">
<div>Description</div>
2022-11-27 18:44:11 +11:00
</label>
</div>
2022-12-02 23:40:27 +11:00
<div id="container-snapshot">
<button id="button-snapshot" class="taken">
<span class="material-symbols-outlined">
photo_camera
</span>
</button>
<span id="button-view-snapshot" class="material-symbols-rounded">
image
2022-11-30 20:56:37 +11:00
</span>
2022-12-02 23:40:27 +11:00
<span id="button-delete-snapshot" class="material-symbols-rounded">
delete
</span>
</div>
2022-12-02 23:57:35 +11:00
<div id="footer-buttons-container">
<button id="button-clear-form" class="form-footer-button">
Clear
</button>
<button id="button-submit" class="form-footer-button">
Submit
</button>
</div>
2022-11-27 17:16:56 +11:00
</div>
</div>
</template>
<script>
class XWidget extends HTMLElement {
#icon;
#form;
2022-11-30 20:56:37 +11:00
#canvas;
2022-12-02 00:44:55 +11:00
#canvasCtx;
2022-11-27 17:16:56 +11:00
#location;
constructor() {
super();
const shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.appendChild(document.getElementById("x-widget-template").content.cloneNode(true));
this.#icon = this.#createIcon();
this.#form = this.#createForm();
2022-12-02 00:44:55 +11:00
this.#canvas = this.#createCanvas();
this.#canvasCtx = this.#canvas.getContext("2d");
2022-11-27 17:16:56 +11:00
this.#location = "bottom-right";
}
connectedCallback() {
2022-11-29 22:02:38 +11:00
this.#renderInitial();
2022-11-27 17:16:56 +11:00
}
2022-11-29 22:02:38 +11:00
#renderInitial() {
2022-11-27 17:16:56 +11:00
if (this.isConnected) {
2022-11-28 21:32:06 +11:00
this.#renderIcon({visibility: "visible"});
2022-11-27 17:16:56 +11:00
this.#renderForm({visibility: "hidden"});
}
}
#createIcon() {
let icon = this.shadowRoot.getElementById("icon");
icon.addEventListener("pointerdown", (e) => this.#onIconPointerDown(e));
icon.addEventListener("pointermove", (e) => this.#onIconPointerMove(e));
icon.addEventListener("pointerup", (e) => this.#onIconPointerUp(e));
icon.addEventListener("pointerover", (e) => this.#onIconPointerOver(e));
icon.addEventListener("pointerout", (e) => this.#onIconPointerOut(e));
2022-12-02 00:44:55 +11:00
icon.pointerDown = false;
icon.moving = false;
2022-11-27 17:16:56 +11:00
return icon;
}
2022-12-02 00:44:55 +11:00
#createCanvas() {
let canvas = this.shadowRoot.getElementById("canvas-snapshot");
canvas.addEventListener("pointerdown", (e) => this.#onCanvasPointerDown(e));
canvas.addEventListener("pointermove", (e) => this.#onCanvasPointerMove(e));
canvas.addEventListener("pointerup", async (e) => await this.#onCanvasPointerUpAsync(e));
canvas.pointerDown = null;
canvas.initialX = null;
canvas.initialY = null;
return canvas;
}
2022-11-27 17:16:56 +11:00
#createForm() {
let form = this.shadowRoot.getElementById("form");
2022-11-29 22:02:38 +11:00
let buttonHelp = this.shadowRoot.getElementById("form-button-help");
buttonHelp.addEventListener("click", (e) => this.#onFormHelpButtonClicked(e));
let buttonClose = this.shadowRoot.getElementById("form-button-close");
buttonClose.addEventListener("click", (e) => this.#onFormCloseButtonClicked(e));
2022-11-27 17:16:56 +11:00
let inputName = this.shadowRoot.getElementById("input-name");
inputName.addEventListener("input", (e) => this.#onNameInput(e));
2022-11-27 18:31:55 +11:00
let selectSeverityContainer = this.shadowRoot.getElementById("select-severity-container");
for (let i = 0; i < selectSeverityContainer.childElementCount; i++) {
let severityOption = selectSeverityContainer.children[i];
severityOption.addEventListener("click", (e) => this.#OnSeverityOptionClicked(e));
}
2022-12-02 23:40:27 +11:00
let inputDescription = this.shadowRoot.getElementById("input-description");
inputDescription.addEventListener("input", (e) => this.#onDescriptionInput(e));
let buttonSnapshot = this.shadowRoot.getElementById("button-snapshot");
buttonSnapshot.addEventListener("click", (e) => this.#onsnapshotButtonClicked(e));
2022-11-27 19:02:48 +11:00
2022-12-02 23:40:27 +11:00
let buttonViewSnapshot = this.shadowRoot.getElementById("button-view-snapshot");
buttonSnapshot.addEventListener("click", (e) => this.#onViewSnapshotButtonClicked(e));
let buttonDeleteSnapshot = this.shadowRoot.getElementById("button-delete-snapshot");
buttonDeleteSnapshot.addEventListener("click", (e) => this.#onDeleteSnapshotButtonClicked(e));
2022-11-30 20:56:37 +11:00
2022-12-02 23:57:35 +11:00
let buttonClearForm = this.shadowRoot.getElementById("button-clear-form");
buttonClearForm.addEventListener("click", (e) => this.#onClearFormButtonClicked(e));
2022-11-30 20:56:37 +11:00
let buttonSubmit = this.shadowRoot.getElementById("button-submit");
buttonSubmit.addEventListener("click", (e) => this.#onSubmitButtonClicked(e));
2022-11-27 17:16:56 +11:00
return form;
}
#renderIcon(parameters={}) {
if (this.#location == "top-left") {
removeClassByPrefix(this.#icon, "location");
this.#icon.classList.add("location-top-left");
}
else if (this.#location == "top-right") {
removeClassByPrefix(this.#icon, "location");
this.#icon.classList.add("location-top-right");
}
else if (this.#location == "bottom-left") {
removeClassByPrefix(this.#icon, "location");
this.#icon.classList.add("location-bottom-left");
}
else if (this.#location == "bottom-right") {
removeClassByPrefix(this.#icon, "location");
this.#icon.classList.add("location-bottom-right");
}
2022-11-28 21:32:06 +11:00
if (parameters["visibility"]) {
if (parameters["visibility"] == "visible") {
this.#icon.classList.remove("hidden");
}
else if (parameters["visibility"] == "hidden") {
this.#icon.classList.add("hidden");
}
}
2022-11-27 17:16:56 +11:00
}
#renderForm(parameters={}) {
if (this.#location == "top-left") {
removeClassByPrefix(this.#form, "location");
this.#form.classList.add("location-top-left");
} else if (this.#location == "top-right") {
removeClassByPrefix(this.#form, "location");
this.#form.classList.add("location-top-right");
} else if (this.#location == "bottom-left") {
removeClassByPrefix(this.#form, "location");
this.#form.classList.add("location-bottom-left");
} else if (this.#location == "bottom-right") {
removeClassByPrefix(this.#form, "location");
this.#form.classList.add("location-bottom-right");
}
if (parameters["visibility"]) {
2022-11-28 21:32:06 +11:00
if (parameters["visibility"] == "visible") {
this.#form.classList.remove("hidden");
2022-11-27 17:16:56 +11:00
}
2022-11-28 21:32:06 +11:00
else if (parameters["visibility"] == "hidden") {
this.#form.classList.add("hidden");
2022-11-27 17:16:56 +11:00
}
}
}
2022-11-29 22:02:38 +11:00
#onFormHelpButtonClicked(e) {
console.log("help pressed");
}
#onFormCloseButtonClicked(e) {
if (!this.#form.classList.contains("hidden")) {
this.#renderIcon({visibility: "visible"});
this.#renderForm({visibility: "hidden"});
}
}
2022-11-27 17:16:56 +11:00
#onNameInput(e) {
let inputName = this.shadowRoot.getElementById("input-name");
inputName.setAttribute('value', inputName.value);
}
2022-12-02 23:40:27 +11:00
#onDescriptionInput(e) {
let inputDescription = this.shadowRoot.getElementById("input-description");
2022-11-27 19:02:48 +11:00
2022-12-02 23:40:27 +11:00
inputDescription.setAttribute('value', inputDescription.value);
2022-11-27 19:02:48 +11:00
}
2022-11-27 18:31:55 +11:00
#OnSeverityOptionClicked(e) {
let selectedSeverityOption = e.currentTarget;
let selectSeverityContainer = this.shadowRoot.getElementById("select-severity-container");
for (let i = 0; i < selectSeverityContainer.childElementCount; i++) {
let severityOption = selectSeverityContainer.children[i];
if (severityOption == selectedSeverityOption) {
if (!severityOption.classList.contains("selected")) {
severityOption.classList.add("selected");
}
}
else {
severityOption.classList.remove("selected");
}
}
}
2022-11-30 20:56:37 +11:00
#onsnapshotButtonClicked(e) {
this.#renderIcon({visibility: "visible"});
this.#renderForm({visibility: "hidden"});
2022-12-02 00:44:55 +11:00
this.#setBlankCanvas();
2022-11-30 20:56:37 +11:00
this.#canvas.classList.add("visible");
}
2022-12-02 00:44:55 +11:00
#setBlankCanvas() {
this.#canvas.width = this.#canvas.clientWidth;
this.#canvas.height = this.#canvas.clientHeight;
this.#canvasCtx.clearRect(0, 0, this.#canvas.width, this.#canvas.height);
this.#canvasCtx.globalAlpha = 0.5;
this.#canvasCtx.fillStyle = "white";
this.#canvasCtx.beginPath();
this.#canvasCtx.rect(0, 0, this.#canvas.width, this.#canvas.height);
this.#canvasCtx.fill();
this.#canvasCtx.closePath();
this.#setCanvasBrush("red");
}
#setCanvasBrush(colour) {
this.#canvasCtx.globalAlpha = 1;
this.#canvasCtx.strokeStyle = colour;
}
#onCanvasPointerDown(e) {
if (e.button !== 0) {
return;
}
e.preventDefault();
e.stopPropagation();
this.#canvas.initialX = e.offsetX;
this.#canvas.initialY = e.offsetY;
this.#canvas.pointerDown = true;
this.#renderIcon({visibility: "hidden"});
this.#canvas.setPointerCapture(e.pointerId);
}
#onCanvasPointerMove(e) {
e.preventDefault();
e.stopPropagation();
if (this.#canvas.pointerDown) {
let offsetX;
let offsetY;
if (e.offsetX < 0) {
offsetX = 0;
}
else if (e.offsetX > this.#canvas.width - 1) {
offsetX = this.#canvas.width - 1;
}
else {
offsetX = e.offsetX;
}
if (e.offsetY < 0) {
offsetY = 0;
}
else if (e.offsetY > this.#canvas.height - 1) {
offsetY = this.#canvas.height - 1;
}
else {
offsetY = e.offsetY;
}
let width = offsetX - this.#canvas.initialX;
let height = offsetY - this.#canvas.initialY;
this.#setBlankCanvas();
this.#canvasCtx.beginPath();
this.#canvasCtx.clearRect(this.#canvas.initialX, this.#canvas.initialY, width, height);
this.#canvasCtx.rect(this.#canvas.initialX, this.#canvas.initialY, width, height);
this.#canvasCtx.stroke();
this.#canvasCtx.closePath();
}
}
async #onCanvasPointerUpAsync(e) {
if (e.button !== 0) {
return;
}
e.preventDefault();
e.stopPropagation();
if (this.#canvas.pointerDown) {
let offsetX;
let offsetY;
if (e.offsetX < 0) {
offsetX = 0;
}
else if (e.offsetX > this.#canvas.width - 1) {
offsetX = this.#canvas.width - 1;
}
else {
offsetX = e.offsetX;
}
if (e.offsetY < 0) {
offsetY = 0;
}
else if (e.offsetY > this.#canvas.height - 1) {
offsetY = this.#canvas.height - 1;
}
else {
offsetY = e.offsetY;
}
if (Math.abs(offsetX - this.#canvas.initialX) > 10 && Math.abs(offsetY - this.#canvas.initialY) > 10) {
await this.#takeSnapshotAsync(offsetX, offsetY);
2022-12-02 23:40:27 +11:00
this.shadowRoot.getElementById("container-snapshot").classList.add("snapshot-taken");
this.shadowRoot.getElementById("button-view-snapshot").classList.add("snapshot-taken");
this.shadowRoot.getElementById("button-delete-snapshot").classList.add("snapshot-taken");
2022-12-02 00:44:55 +11:00
}
this.#canvas.initialX = null;
this.#canvas.initialY = null;
this.#canvas.pointerDown = false;
this.#canvas.classList.remove("visible");
this.#setBlankCanvas();
this.#renderForm({visibility: "visible"});
}
}
async #takeSnapshotAsync(offsetX, offsetY) {
let snapshotCanvas = await html2canvas(document.body, {
width: Math.abs(this.#canvas.initialX - offsetX),
height: Math.abs(this.#canvas.initialY - offsetY),
x: Math.min(this.#canvas.initialX, offsetX),
y: Math.min(this.#canvas.initialY, offsetY)
})
let base64image = snapshotCanvas.toDataURL("image/png");
// var image = new Image();
// image.src = base64image;
// var w = window.open("_blank");
// w.document.write(image.outerHTML);
}
2022-11-30 20:56:37 +11:00
2022-12-02 23:40:27 +11:00
#onViewSnapshotButtonClicked(e) {
}
#onDeleteSnapshotButtonClicked(e) {
this.#deleteSnapshot();
}
#deleteSnapshot() {
this.shadowRoot.getElementById("container-snapshot").classList.remove("snapshot-taken");
this.shadowRoot.getElementById("button-view-snapshot").classList.remove("snapshot-taken");
this.shadowRoot.getElementById("button-delete-snapshot").classList.remove("snapshot-taken");
}
2022-12-02 23:57:35 +11:00
#onClearFormButtonClicked(e){
let inputName = this.shadowRoot.getElementById("input-name");
inputName.setAttribute("value", "");
inputName.value = null;
this.#resetForm();
}
2022-11-30 20:56:37 +11:00
#onSubmitButtonClicked(e) {
2022-12-02 23:40:27 +11:00
this.#renderIcon({visibility: "visible"});
this.#renderForm({visibility: "hidden"});
this.#resetForm();
}
#resetForm() {
let selectSeverityContainer = this.shadowRoot.getElementById("select-severity-container");
selectSeverityContainer.children[0].classList.add("selected");
for (let i = 1; i < selectSeverityContainer.childElementCount; i++) {
let severityOption = selectSeverityContainer.children[i];
severityOption.classList.remove("selected");
}
let inputDescription = this.shadowRoot.getElementById("input-description");
inputDescription.setAttribute("value", "");
inputDescription.value = null;
this.#deleteSnapshot();
2022-11-30 20:56:37 +11:00
}
2022-11-27 17:16:56 +11:00
#onIconPointerOver(e) {
e.preventDefault();
e.stopPropagation();
}
#onIconPointerOut(e) {
e.preventDefault();
e.stopPropagation();
}
#onIconPointerDown(e) {
2022-11-28 21:32:06 +11:00
if (e.button !== 0) {
return;
}
2022-11-27 17:16:56 +11:00
e.preventDefault();
e.stopPropagation();
2022-12-02 00:44:55 +11:00
this.#icon.pointerDown = true;
2022-11-27 17:16:56 +11:00
this.#icon.setPointerCapture(e.pointerId);
}
#onIconPointerMove(e) {
e.preventDefault();
e.stopPropagation();
2022-12-02 00:44:55 +11:00
if (this.#icon.pointerDown) {
this.#icon.moving = true;
2022-11-27 17:16:56 +11:00
this.#icon.style.cursor = "grabbing";
this.#snapToCorner(e.clientX, e.clientY);
}
else {
this.#icon.style.cursor = "pointer";
}
}
#onIconPointerUp(e) {
2022-11-28 21:32:06 +11:00
if (e.button !== 0) {
return;
}
2022-11-27 17:16:56 +11:00
e.preventDefault();
e.stopPropagation();
this.#icon.style.cursor = "pointer";
2022-12-02 00:44:55 +11:00
this.#canvas.classList.remove("visible");
2022-11-27 17:16:56 +11:00
2022-12-02 00:44:55 +11:00
if (this.#icon.pointerDown && !this.#icon.moving) {
2022-11-28 21:32:06 +11:00
if (this.#form.classList.contains("hidden")) {
this.#renderIcon({visibility: "hidden"});
this.#renderForm({visibility: "visible"});
2022-11-27 17:16:56 +11:00
}
}
else {
2022-12-02 00:44:55 +11:00
this.#icon.moving = false;
2022-11-27 17:16:56 +11:00
}
2022-12-02 00:44:55 +11:00
this.#icon.pointerDown = false;
2022-11-27 17:16:56 +11:00
this.#icon.releasePointerCapture(e.pointerId);
}
#snapToCorner(anchorX, anchorY) {
let locationChanged = false;
2022-11-29 22:02:38 +11:00
if (anchorX < window.innerWidth / 2) {
if (this.#location != "top-left" && anchorY < window.innerHeight / 2) {
2022-11-27 17:16:56 +11:00
this.#location = "top-left";
locationChanged = true;
}
2022-11-29 22:02:38 +11:00
else if (this.#location != "bottom-left" && anchorY > window.innerHeight - window.innerHeight / 2) {
2022-11-27 17:16:56 +11:00
this.#location = "bottom-left";
locationChanged = true;
}
}
2022-11-29 22:02:38 +11:00
else if (anchorX > window.innerWidth - window.innerWidth / 2) {
if (this.#location != "top-right" && anchorY < window.innerHeight / 2) {
2022-11-27 17:16:56 +11:00
this.#location = "top-right";
locationChanged = true;
}
2022-11-29 22:02:38 +11:00
else if (this.#location != "bottom-right" && anchorY > window.innerHeight - window.innerHeight / 2) {
2022-11-27 17:16:56 +11:00
this.#location = "bottom-right";
locationChanged = true;
}
}
if (locationChanged) {
2022-11-28 21:32:06 +11:00
this.#renderIcon({visibility: "visible"});
2022-11-27 17:16:56 +11:00
this.#renderForm({visibility: "hidden"});
}
}
}
function removeClassByPrefix(el, prefix) {
if (!el.classList) {
return;
}
let filteredClassList = [];
for (let i = 0; i < el.classList.length; i++) {
if (!el.classList[i].startsWith(prefix)) {
filteredClassList.push(el.classList[i])
}
}
2022-11-28 21:32:06 +11:00
el.className = "";
2022-11-30 20:56:37 +11:00
for (let i = 0; i < filteredClassList.length; i++) {
2022-11-28 21:32:06 +11:00
el.classList.add(filteredClassList[i]);
}
2022-11-30 20:56:37 +11:00
let dsf = el;
let dsg = "";
2022-11-27 17:16:56 +11:00
}
customElements.define("x-widget", XWidget);
document.body.appendChild(document.createElement("x-widget"));
</script>
</body>
</html>