@aptoma/folio-tools 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +13 -0
- package/package.json +4 -2
- package/server/grid-overlay.js +36 -2
- package/test-vm.js +22 -6
package/dist/src/utils.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare function getGridCssProps({ column, baseline, dimensions, margin }
|
|
|
5
5
|
dimensions: Dimension;
|
|
6
6
|
margin: ComputedMargin;
|
|
7
7
|
}): string[];
|
|
8
|
+
export declare function getObjectCssProps(elements: PageElement[]): string[];
|
|
8
9
|
export declare function getMarginsInMm(edition: {
|
|
9
10
|
margin: RawMargin;
|
|
10
11
|
}, page: {
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAE/H,wBAAgB,eAAe,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAC,EAAE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,SAAS,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;CACvB,GAAG,MAAM,EAAE,CAqBX;AAMD,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAC,MAAM,EAAE,SAAS,CAAA;CAAC,EAAE,IAAI,EAAE;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;CAAC,GAAG,cAAc,CAYhH;AAMD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,YAAY,GAAG,WAAW,EAAE,CAQ/H"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAE/H,wBAAgB,eAAe,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAC,EAAE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,SAAS,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;CACvB,GAAG,MAAM,EAAE,CAqBX;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,CAWnE;AAMD,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAC,MAAM,EAAE,SAAS,CAAA;CAAC,EAAE,IAAI,EAAE;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;CAAC,GAAG,cAAc,CAYhH;AAMD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,YAAY,GAAG,WAAW,EAAE,CAQ/H"}
|
package/dist/src/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGridCssProps = getGridCssProps;
|
|
4
|
+
exports.getObjectCssProps = getObjectCssProps;
|
|
4
5
|
exports.getMarginsInMm = getMarginsInMm;
|
|
5
6
|
exports.convertObjectsToPageElements = convertObjectsToPageElements;
|
|
6
7
|
function getGridCssProps({ column, baseline, dimensions, margin }) {
|
|
@@ -22,6 +23,18 @@ function getGridCssProps({ column, baseline, dimensions, margin }) {
|
|
|
22
23
|
props.push(`--grid-baseline-increment: ${round(toMm(baseline.height))}mm`);
|
|
23
24
|
return props;
|
|
24
25
|
}
|
|
26
|
+
function getObjectCssProps(elements) {
|
|
27
|
+
const props = [`--obj-count: ${elements.length}`];
|
|
28
|
+
elements.forEach((e, i) => {
|
|
29
|
+
const n = i + 1;
|
|
30
|
+
props.push(`--obj-${n}-top: ${e.pagePosition.top}`);
|
|
31
|
+
props.push(`--obj-${n}-left: ${e.pagePosition.left}`);
|
|
32
|
+
props.push(`--obj-${n}-width: ${e.pagePosition.width}`);
|
|
33
|
+
props.push(`--obj-${n}-height: ${e.pagePosition.height}`);
|
|
34
|
+
props.push(`--obj-${n}-type: ${e.type || ''}`);
|
|
35
|
+
});
|
|
36
|
+
return props;
|
|
37
|
+
}
|
|
25
38
|
function round(n) {
|
|
26
39
|
return Math.round(n * 1000) / 1000;
|
|
27
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptoma/folio-tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Build tooling and dev server for Aptoma DrEdition print folio renderers",
|
|
5
5
|
"license": "Unlicensed",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"url": "git+https://github.com/aptoma/folio-tools.git"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
+
"test": "tsx --test src/*.test.ts",
|
|
26
27
|
"build": "tsc",
|
|
27
28
|
"prepublishOnly": "tsc",
|
|
28
29
|
"prerelease-check": "tsc --noEmit",
|
|
@@ -37,12 +38,13 @@
|
|
|
37
38
|
"joi": "^17.6.0",
|
|
38
39
|
"node-fetch": "^2.6.7",
|
|
39
40
|
"nodemon": "^2.0.15",
|
|
40
|
-
"
|
|
41
|
+
"isolated-vm": "^6.0.2"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@types/node": "^25.3.0",
|
|
44
45
|
"auto-changelog": "^2.5.0",
|
|
45
46
|
"release-it": "^19.0.5",
|
|
47
|
+
"tsx": "^4.21.0",
|
|
46
48
|
"typescript": "^5.9.3"
|
|
47
49
|
}
|
|
48
50
|
}
|
package/server/grid-overlay.js
CHANGED
|
@@ -15,8 +15,10 @@ class FgGridOverlay extends HTMLElement {
|
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const objCount = parseInt(st.getPropertyValue('--obj-count'), 10) || 0;
|
|
19
|
+
|
|
18
20
|
const shadow = this.attachShadow({mode: 'open'});
|
|
19
|
-
shadow.innerHTML = this._template(st, colCount);
|
|
21
|
+
shadow.innerHTML = this._template(st, colCount, objCount);
|
|
20
22
|
|
|
21
23
|
const root = shadow;
|
|
22
24
|
function wire(cbId, layerId) {
|
|
@@ -34,10 +36,12 @@ class FgGridOverlay extends HTMLElement {
|
|
|
34
36
|
wire('fg-cb-margins', 'fg-margins');
|
|
35
37
|
wire('fg-cb-columns', 'fg-columns');
|
|
36
38
|
wire('fg-cb-baseline', 'fg-baseline');
|
|
39
|
+
wire('fg-cb-objects', 'fg-objects');
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
_template(st, colCount) {
|
|
42
|
+
_template(st, colCount, objCount) {
|
|
40
43
|
const columnLines = this._buildColumnLines(st, colCount);
|
|
44
|
+
const objectBoxes = this._buildObjectBoxes(st, objCount);
|
|
41
45
|
return `
|
|
42
46
|
<style>
|
|
43
47
|
:host {
|
|
@@ -112,17 +116,47 @@ class FgGridOverlay extends HTMLElement {
|
|
|
112
116
|
gap: 4px;
|
|
113
117
|
align-items: center;
|
|
114
118
|
}
|
|
119
|
+
#fg-objects {
|
|
120
|
+
position: absolute;
|
|
121
|
+
top: var(--margin-top);
|
|
122
|
+
left: var(--margin-left);
|
|
123
|
+
pointer-events: none;
|
|
124
|
+
display: none;
|
|
125
|
+
}
|
|
126
|
+
.obj-box {
|
|
127
|
+
position: absolute;
|
|
128
|
+
background: rgba(0, 0, 0, 0.08);
|
|
129
|
+
box-sizing: border-box;
|
|
130
|
+
}
|
|
131
|
+
.obj-box[data-type="article"] { background: rgba(255, 200, 0, 0.3); }
|
|
132
|
+
.obj-box[data-type="ad"] { background: rgba(0, 100, 255, 0.2); }
|
|
133
|
+
.obj-box[data-type="pdf"] { background: rgba(255, 0, 150, 0.2); }
|
|
115
134
|
</style>
|
|
116
135
|
<div id="fg-margins"></div>
|
|
117
136
|
<div id="fg-columns">${columnLines}</div>
|
|
118
137
|
<div id="fg-baseline"></div>
|
|
138
|
+
<div id="fg-objects">${objectBoxes}</div>
|
|
119
139
|
<div id="fg-controls">
|
|
120
140
|
<label><input type="checkbox" id="fg-cb-margins"> <span style="color:#e040fb">Margins</span></label>
|
|
121
141
|
<label><input type="checkbox" id="fg-cb-columns"> <span style="color:#4db6ac">Columns</span></label>
|
|
122
142
|
<label><input type="checkbox" id="fg-cb-baseline"> <span style="color:#039be5">Baseline</span></label>
|
|
143
|
+
<label><input type="checkbox" id="fg-cb-objects"> <span style="color:#555">Objects</span></label>
|
|
123
144
|
</div>`;
|
|
124
145
|
}
|
|
125
146
|
|
|
147
|
+
_buildObjectBoxes(st, objCount) {
|
|
148
|
+
const boxes = [];
|
|
149
|
+
for (let i = 1; i <= objCount; i++) {
|
|
150
|
+
const top = st.getPropertyValue(`--obj-${i}-top`).trim();
|
|
151
|
+
const left = st.getPropertyValue(`--obj-${i}-left`).trim();
|
|
152
|
+
const width = st.getPropertyValue(`--obj-${i}-width`).trim();
|
|
153
|
+
const height = st.getPropertyValue(`--obj-${i}-height`).trim();
|
|
154
|
+
const type = st.getPropertyValue(`--obj-${i}-type`).trim();
|
|
155
|
+
boxes.push(`<div class="obj-box" style="top:${top};left:${left};width:${width};height:${height}" data-type="${type}"></div>`);
|
|
156
|
+
}
|
|
157
|
+
return boxes.join('\n');
|
|
158
|
+
}
|
|
159
|
+
|
|
126
160
|
_buildColumnLines(st, colCount) {
|
|
127
161
|
const lines = [];
|
|
128
162
|
for (let i = 1; i <= colCount; i++) {
|
package/test-vm.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
sandbox: {self: null}
|
|
7
|
-
});
|
|
4
|
+
const ivm = require('isolated-vm');
|
|
5
|
+
const isolate = new ivm.Isolate({memoryLimit: 128});
|
|
8
6
|
const file = require('fs').readFileSync('./files/index.js').toString();
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const context = await isolate.createContext();
|
|
10
|
+
try {
|
|
11
|
+
await context.global.set('self', null);
|
|
12
|
+
const script = await isolate.compileScript(wrapCJS(file));
|
|
13
|
+
await script.run(context);
|
|
14
|
+
} finally {
|
|
15
|
+
context.release();
|
|
16
|
+
}
|
|
17
|
+
})().catch(console.error);
|
|
18
|
+
|
|
19
|
+
function wrapCJS(code) {
|
|
20
|
+
return `(function() {
|
|
21
|
+
var module = { exports: {} };
|
|
22
|
+
var exports = module.exports;
|
|
23
|
+
${code}
|
|
24
|
+
globalThis.__moduleExports = module.exports;
|
|
25
|
+
})();`;
|
|
26
|
+
}
|