2021-05-04 06:09:18 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<title>KonvaJS Sandbox</title>
|
|
|
|
<meta
|
|
|
|
name="viewport"
|
|
|
|
content="width=device-width, initial-scale=1.0, user-scalable=1.0, minimum-scale=1.0, maximum-scale=1.0"
|
|
|
|
/>
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
margin: 0;
|
2022-08-05 23:35:43 +08:00
|
|
|
width: 100vw;
|
|
|
|
height: 100vh;
|
2021-05-04 06:09:18 +08:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<!-- <script src="https://cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script> -->
|
|
|
|
<script>
|
2021-08-04 16:28:00 +08:00
|
|
|
// TouchEmulator();
|
2021-05-04 06:09:18 +08:00
|
|
|
</script>
|
|
|
|
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.7/hammer.js"></script> -->
|
|
|
|
<!-- <script src="https://cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script> -->
|
|
|
|
<!-- <script src="./hammer.js"></script> -->
|
2022-08-05 23:35:43 +08:00
|
|
|
<!-- <script src="https://unpkg.com/fabric@5.2.1/dist/fabric.js"></script> -->
|
2021-05-04 06:09:18 +08:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
2023-08-27 09:36:40 +08:00
|
|
|
<div id="container"></div>
|
2022-08-05 23:35:43 +08:00
|
|
|
|
2021-10-22 23:09:34 +08:00
|
|
|
<script type="module">
|
|
|
|
import Konva from '../src/index.ts';
|
2022-03-22 02:49:55 +08:00
|
|
|
|
2024-05-16 09:35:26 +08:00
|
|
|
var stageWidth = window.innerWidth;
|
|
|
|
var stageHeight = window.innerHeight;
|
|
|
|
|
2023-07-27 01:10:00 +08:00
|
|
|
var stage = new Konva.Stage({
|
2022-08-05 23:35:43 +08:00
|
|
|
container: 'container',
|
2024-05-16 09:35:26 +08:00
|
|
|
width: stageWidth,
|
|
|
|
height: stageHeight,
|
2022-08-05 23:35:43 +08:00
|
|
|
});
|
2023-07-27 01:10:00 +08:00
|
|
|
|
|
|
|
var layer = new Konva.Layer();
|
2022-08-05 23:35:43 +08:00
|
|
|
stage.add(layer);
|
2023-07-27 01:10:00 +08:00
|
|
|
|
2024-05-16 09:35:26 +08:00
|
|
|
// Stage Background
|
|
|
|
var background = new Konva.Rect({
|
|
|
|
width: stageWidth,
|
|
|
|
height: stageHeight,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
fill: 'red',
|
2023-08-27 09:36:40 +08:00
|
|
|
});
|
2024-05-16 09:35:26 +08:00
|
|
|
layer.add(background);
|
2023-09-10 05:39:57 +08:00
|
|
|
|
2024-05-16 09:35:26 +08:00
|
|
|
// Text Item
|
|
|
|
var text = new Konva.Text({
|
|
|
|
text: 'testtest',
|
|
|
|
x: 50,
|
|
|
|
y: 25,
|
|
|
|
// width: 400,
|
|
|
|
// height: 200,
|
|
|
|
fontSize: 64,
|
|
|
|
// verticalAlign: 'middle',
|
|
|
|
align: 'center',
|
|
|
|
fontFamily: 'Times New Roman',
|
|
|
|
// textBaseline: 'alphabetic',
|
|
|
|
});
|
|
|
|
layer.add(text);
|
2023-07-27 01:10:00 +08:00
|
|
|
|
2024-05-16 09:35:26 +08:00
|
|
|
// Top line lining up perfect in MAC OSX CHROME, inline with top of text
|
|
|
|
var topLine = new Konva.Line({
|
|
|
|
points: [125, 103, 400, 103],
|
|
|
|
stroke: 'green',
|
|
|
|
strokeWidth: 1,
|
2023-08-27 09:36:40 +08:00
|
|
|
});
|
2024-05-16 09:35:26 +08:00
|
|
|
layer.add(topLine);
|
2023-07-27 01:10:00 +08:00
|
|
|
|
2024-05-16 09:35:26 +08:00
|
|
|
// Bottom line lining up perfect in MAC OSX CHROME, inline with bottom of text
|
|
|
|
var bottomLine = new Konva.Line({
|
|
|
|
points: [125, 143, 400, 143],
|
|
|
|
stroke: 'green',
|
|
|
|
strokeWidth: 1,
|
2023-08-27 09:36:40 +08:00
|
|
|
});
|
2024-05-16 09:35:26 +08:00
|
|
|
layer.add(bottomLine);
|
2023-07-27 01:10:00 +08:00
|
|
|
|
2024-05-16 09:35:26 +08:00
|
|
|
layer.draw();
|
2023-07-27 01:10:00 +08:00
|
|
|
|
2024-05-16 09:35:26 +08:00
|
|
|
// Get text bounding box
|
|
|
|
var textRect = text.getClientRect();
|
|
|
|
|
|
|
|
// Create overlay text
|
|
|
|
var overlayText = document.createElement('div');
|
|
|
|
overlayText.id = 'overlayText';
|
|
|
|
overlayText.style.position = 'absolute';
|
|
|
|
overlayText.style.left = textRect.x + 'px';
|
|
|
|
overlayText.style.top = textRect.y + 'px';
|
|
|
|
overlayText.style.width = textRect.width + 'px';
|
|
|
|
overlayText.style.height = textRect.height + 'px';
|
|
|
|
overlayText.style.lineHeight = textRect.height + 'px'; // Center vertically
|
|
|
|
overlayText.style.textAlign = 'center';
|
|
|
|
overlayText.style.fontSize = '64px';
|
|
|
|
overlayText.innerHTML = 'testtest';
|
|
|
|
document.getElementById('container').appendChild(overlayText);
|
2021-10-22 23:09:34 +08:00
|
|
|
</script>
|
2021-05-04 06:09:18 +08:00
|
|
|
</body>
|
|
|
|
</html>
|