@foxycape/core 1.1.5 → 1.1.6

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.
@@ -13,6 +13,7 @@ export type ContentGeometry = {
13
13
  height: number;
14
14
  shape: ContentShape;
15
15
  coords: number[];
16
+ rotation?: number;
16
17
  };
17
18
  export type ReflowableAnchor = {
18
19
  tagName: string;
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./textRects.cjs"),t=require("./selectionToFixedContentRange.cjs");exports.collectPageElements=e.collectPageElements,exports.getPageLayoutRef=t.getPageLayoutRef,exports.getPagedSelectionRects=e.getPagedSelectionRects,exports.getSelectionText=e.getSelectionText,exports.mergeClientRects=e.mergeClientRects,exports.mergeClientRectsToLines=e.mergeClientRectsToLines,exports.resolvePageNumberForRect=e.resolvePageNumberForRect,exports.scaleGeometryCoords=t.scaleGeometryCoords,exports.selectionToFixedContentRange=t.selectionToFixedContentRange;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./textRects.cjs"),t=require("./selectionToFixedContentRange.cjs");exports.collectPageElements=e.collectPageElements,exports.getPageLayoutRef=t.getPageLayoutRef,exports.getPagedSelectionRects=e.getPagedSelectionRects,exports.getSelectionText=e.getSelectionText,exports.mergeClientRects=e.mergeClientRects,exports.mergeClientRectsToLines=e.mergeClientRectsToLines,exports.normalizePageRotation=t.normalizePageRotation,exports.resolvePageNumberForRect=e.resolvePageNumberForRect,exports.rotateRectInPage=t.rotateRectInPage,exports.scaleGeometryCoords=t.scaleGeometryCoords,exports.selectionToFixedContentRange=t.selectionToFixedContentRange;
@@ -1,3 +1,3 @@
1
1
  import { collectPageElements as e, getPagedSelectionRects as t, getSelectionText as n, mergeClientRects as r, mergeClientRectsToLines as i, resolvePageNumberForRect as a } from "./textRects.mjs";
2
- import { getPageLayoutRef as o, scaleGeometryCoords as s, selectionToFixedContentRange as c } from "./selectionToFixedContentRange.mjs";
3
- export { e as collectPageElements, o as getPageLayoutRef, t as getPagedSelectionRects, n as getSelectionText, r as mergeClientRects, i as mergeClientRectsToLines, a as resolvePageNumberForRect, s as scaleGeometryCoords, c as selectionToFixedContentRange };
2
+ import { getPageLayoutRef as o, normalizePageRotation as s, rotateRectInPage as c, scaleGeometryCoords as l, selectionToFixedContentRange as u } from "./selectionToFixedContentRange.mjs";
3
+ export { e as collectPageElements, o as getPageLayoutRef, t as getPagedSelectionRects, n as getSelectionText, r as mergeClientRects, i as mergeClientRectsToLines, s as normalizePageRotation, a as resolvePageNumberForRect, c as rotateRectInPage, l as scaleGeometryCoords, u as selectionToFixedContentRange };
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./textRects.cjs");var t=e=>{let t=e.getBoundingClientRect(),n=e.clientWidth,r=e.clientHeight;if(!(n<=0||r<=0))return{width:n,height:r,contentLeft:t.left+e.clientLeft,contentTop:t.top+e.clientTop}},n=(t,n)=>{let r=e.getPagedSelectionRects(t);if(r.length===0)return null;let i=[];for(let e of r){let t=n(e.pageNumber);if(!t)continue;let r=e.x-t.contentLeft,a=e.y-t.contentTop;i.push({pageNumber:e.pageNumber,width:t.width,height:t.height,shape:`rect`,coords:[r,a,e.width,e.height]})}return i.length===0?null:{kind:`fixed`,geometries:i}},r=(e,t,n)=>{let[r=0,i=0,a=0,o=0]=e.coords,s=e.width>0?t/e.width:1,c=e.height>0?n/e.height:1;return{x:r*s,y:i*c,width:a*s,height:o*c}};exports.getPageLayoutRef=t,exports.scaleGeometryCoords=r,exports.selectionToFixedContentRange=n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./textRects.cjs");var t=e=>{let t=(Math.round(e)%360+360)%360;return Math.round(t/90)*90%360},n=(e,n,r,i,a,o,s)=>{switch(t(s)){case 90:return{x:o-n-i,y:e,width:i,height:r};case 180:return{x:a-e-r,y:o-n-i,width:r,height:i};case 270:return{x:n,y:a-e-r,width:i,height:r};default:return{x:e,y:n,width:r,height:i}}},r=e=>{let t=e.getBoundingClientRect(),n=e.clientWidth,r=e.clientHeight;if(!(n<=0||r<=0))return{width:n,height:r,contentLeft:t.left+e.clientLeft,contentTop:t.top+e.clientTop}},i=(n,r)=>{let i=e.getPagedSelectionRects(n);if(i.length===0)return null;let a=[];for(let e of i){let n=r(e.pageNumber);if(!n)continue;let i=e.x-n.contentLeft,o=e.y-n.contentTop,s={pageNumber:e.pageNumber,width:n.width,height:n.height,shape:`rect`,coords:[i,o,e.width,e.height],rotation:t(n.rotation??0)};a.push(s)}return a.length===0?null:{kind:`fixed`,geometries:a}},a=(e,r,i,a=0)=>{let[o=0,s=0,c=0,l=0]=e.coords,u=t(a-(e.rotation??0)),d=n(o,s,c,l,e.width,e.height,u),f=u%180==0?e.width:e.height,p=u%180==0?e.height:e.width,m=f>0?r/f:1,h=p>0?i/p:1;return{x:d.x*m,y:d.y*h,width:d.width*m,height:d.height*h,rotationDelta:u}};exports.getPageLayoutRef=r,exports.normalizePageRotation=t,exports.rotateRectInPage=n,exports.scaleGeometryCoords=a,exports.selectionToFixedContentRange=i;
@@ -5,13 +5,23 @@ export type PageLayoutRef = {
5
5
  height: number;
6
6
  contentLeft: number;
7
7
  contentTop: number;
8
+ rotation?: number;
8
9
  };
9
- export type PageLayoutResolver = (pageNumber: number) => PageLayoutRef | undefined;
10
- export declare const getPageLayoutRef: (pageEl: HTMLElement) => PageLayoutRef | undefined;
11
- export declare const selectionToFixedContentRange: (range: Range, resolveLayout: PageLayoutResolver) => FixedContentRange | null;
12
- export declare const scaleGeometryCoords: (geometry: ContentGeometry, currentWidth: number, currentHeight: number) => {
10
+ export type ScaledGeometryRect = {
13
11
  x: number;
14
12
  y: number;
15
13
  width: number;
16
14
  height: number;
15
+ rotationDelta: number;
17
16
  };
17
+ export declare const normalizePageRotation: (degrees: number) => number;
18
+ export declare const rotateRectInPage: (x: number, y: number, w: number, h: number, pageWidth: number, pageHeight: number, delta: number) => {
19
+ x: number;
20
+ y: number;
21
+ width: number;
22
+ height: number;
23
+ };
24
+ export type PageLayoutResolver = (pageNumber: number) => PageLayoutRef | undefined;
25
+ export declare const getPageLayoutRef: (pageEl: HTMLElement) => PageLayoutRef | undefined;
26
+ export declare const selectionToFixedContentRange: (range: Range, resolveLayout: PageLayoutResolver) => FixedContentRange | null;
27
+ export declare const scaleGeometryCoords: (geometry: ContentGeometry, currentWidth: number, currentHeight: number, currentRotation?: number) => ScaledGeometryRect;
@@ -1,6 +1,36 @@
1
1
  import { getPagedSelectionRects as e } from "./textRects.mjs";
2
2
  //#region mediaTypes/pdf/shared/geometry/selectionToFixedContentRange.ts
3
3
  var t = (e) => {
4
+ let t = (Math.round(e) % 360 + 360) % 360;
5
+ return Math.round(t / 90) * 90 % 360;
6
+ }, n = (e, n, r, i, a, o, s) => {
7
+ switch (t(s)) {
8
+ case 90: return {
9
+ x: o - n - i,
10
+ y: e,
11
+ width: i,
12
+ height: r
13
+ };
14
+ case 180: return {
15
+ x: a - e - r,
16
+ y: o - n - i,
17
+ width: r,
18
+ height: i
19
+ };
20
+ case 270: return {
21
+ x: n,
22
+ y: a - e - r,
23
+ width: i,
24
+ height: r
25
+ };
26
+ default: return {
27
+ x: e,
28
+ y: n,
29
+ width: r,
30
+ height: i
31
+ };
32
+ }
33
+ }, r = (e) => {
4
34
  let t = e.getBoundingClientRect(), n = e.clientWidth, r = e.clientHeight;
5
35
  if (!(n <= 0 || r <= 0)) return {
6
36
  width: n,
@@ -8,39 +38,41 @@ var t = (e) => {
8
38
  contentLeft: t.left + e.clientLeft,
9
39
  contentTop: t.top + e.clientTop
10
40
  };
11
- }, n = (t, n) => {
12
- let r = e(t);
13
- if (r.length === 0) return null;
14
- let i = [];
15
- for (let e of r) {
16
- let t = n(e.pageNumber);
17
- if (!t) continue;
18
- let r = e.x - t.contentLeft, a = e.y - t.contentTop;
19
- i.push({
41
+ }, i = (n, r) => {
42
+ let i = e(n);
43
+ if (i.length === 0) return null;
44
+ let a = [];
45
+ for (let e of i) {
46
+ let n = r(e.pageNumber);
47
+ if (!n) continue;
48
+ let i = e.x - n.contentLeft, o = e.y - n.contentTop, s = {
20
49
  pageNumber: e.pageNumber,
21
- width: t.width,
22
- height: t.height,
50
+ width: n.width,
51
+ height: n.height,
23
52
  shape: "rect",
24
53
  coords: [
25
- r,
26
- a,
54
+ i,
55
+ o,
27
56
  e.width,
28
57
  e.height
29
- ]
30
- });
58
+ ],
59
+ rotation: t(n.rotation ?? 0)
60
+ };
61
+ a.push(s);
31
62
  }
32
- return i.length === 0 ? null : {
63
+ return a.length === 0 ? null : {
33
64
  kind: "fixed",
34
- geometries: i
65
+ geometries: a
35
66
  };
36
- }, r = (e, t, n) => {
37
- let [r = 0, i = 0, a = 0, o = 0] = e.coords, s = e.width > 0 ? t / e.width : 1, c = e.height > 0 ? n / e.height : 1;
67
+ }, a = (e, r, i, a = 0) => {
68
+ let [o = 0, s = 0, c = 0, l = 0] = e.coords, u = t(a - (e.rotation ?? 0)), d = n(o, s, c, l, e.width, e.height, u), f = u % 180 == 0 ? e.width : e.height, p = u % 180 == 0 ? e.height : e.width, m = f > 0 ? r / f : 1, h = p > 0 ? i / p : 1;
38
69
  return {
39
- x: r * s,
40
- y: i * c,
41
- width: a * s,
42
- height: o * c
70
+ x: d.x * m,
71
+ y: d.y * h,
72
+ width: d.width * m,
73
+ height: d.height * h,
74
+ rotationDelta: u
43
75
  };
44
76
  };
45
77
  //#endregion
46
- export { t as getPageLayoutRef, r as scaleGeometryCoords, n as selectionToFixedContentRange };
78
+ export { r as getPageLayoutRef, t as normalizePageRotation, n as rotateRectInPage, a as scaleGeometryCoords, i as selectionToFixedContentRange };
package/global.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export declare global {
1
+ export {};
2
+
3
+ declare global {
2
4
  interface Element {
3
5
  /**Visible in a specified range, not necessarily visible on the screen */
4
6
  isVisible: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxycape/core",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Browser-side multi-format reader kernel with pluggable parsers, renderers, services, and plugins.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/types.d.ts CHANGED
@@ -1,13 +1,48 @@
1
-
2
- declare module '*.html';
3
- declare module "*.scss";
4
- declare module "*.css" {}
5
- declare module "*.png";
6
- declare module "*.js";
7
- declare module '*.html?raw';
8
- declare module '*.js?raw';
9
- declare module '*.mjs?raw';
10
- declare module '*.js?url';
11
- declare module '*.mjs?url';
12
- declare module '*/?url';
13
- declare module '*.css?raw';
1
+ declare module '*.html' {
2
+ const src: string;
3
+ export default src;
4
+ }
5
+ declare module '*.scss' {
6
+ const src: string;
7
+ export default src;
8
+ }
9
+ declare module '*.css' {
10
+ const src: string;
11
+ export default src;
12
+ }
13
+ declare module '*.png' {
14
+ const src: string;
15
+ export default src;
16
+ }
17
+ declare module '*.js' {
18
+ const src: string;
19
+ export default src;
20
+ }
21
+ declare module '*.html?raw' {
22
+ const src: string;
23
+ export default src;
24
+ }
25
+ declare module '*.js?raw' {
26
+ const src: string;
27
+ export default src;
28
+ }
29
+ declare module '*.mjs?raw' {
30
+ const src: string;
31
+ export default src;
32
+ }
33
+ declare module '*.js?url' {
34
+ const src: string;
35
+ export default src;
36
+ }
37
+ declare module '*.mjs?url' {
38
+ const src: string;
39
+ export default src;
40
+ }
41
+ declare module '*/?url' {
42
+ const src: string;
43
+ export default src;
44
+ }
45
+ declare module '*.css?raw' {
46
+ const src: string;
47
+ export default src;
48
+ }