@swiftbrowser/react 0.9.8 → 0.9.9
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/README.md +3 -1
- package/dist/index.js +24 -21
- package/dist/index.js.map +1 -1
- package/dist/scrollReader.d.ts +13 -4
- package/dist/scrollReader.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -330,7 +330,9 @@ a `ScrollView` snaps, with `scrollTargetLayout` on the stack inside.
|
|
|
330
330
|
`scrollPosition={[id, setId]}` on a `ScrollView` is `.scrollPosition(id:)`:
|
|
331
331
|
when scrolling settles it is set to the `scrollID` of the view at the
|
|
332
332
|
scroll view's leading edge (or `scrollPositionAnchor`), and setting it
|
|
333
|
-
scrolls there.
|
|
333
|
+
scrolls there, on that scroll view's axes only. `proxy.scrollTo(id, anchor,
|
|
334
|
+
{ axes: 'horizontal' })` limits a reader's scroll the same way, so a pager
|
|
335
|
+
inside a list leaves the list where it is.
|
|
334
336
|
Name a coordinate space with `coordinateSpace="page"` on the `ScrollView`
|
|
335
337
|
(or any view), and a `GeometryReader` inside reads its frame there with
|
|
336
338
|
`proxy.frame({ named: 'page' })`, updated as the page scrolls.
|
package/dist/index.js
CHANGED
|
@@ -797,12 +797,15 @@ function insets(edges, amount) {
|
|
|
797
797
|
}
|
|
798
798
|
return result;
|
|
799
799
|
}
|
|
800
|
+
function command(request) {
|
|
801
|
+
return request.axes ? { anchor: request.anchor, serial: request.serial, axes: request.axes } : { anchor: request.anchor, serial: request.serial };
|
|
802
|
+
}
|
|
800
803
|
const ScrollRequestContext = createContext(null);
|
|
801
804
|
let nextSerial = 1;
|
|
802
805
|
function ScrollViewReader({ children }) {
|
|
803
806
|
const [request, setRequest] = useState(null);
|
|
804
807
|
const proxy = {
|
|
805
|
-
scrollTo: (id, anchor) => setRequest({ id, anchor: anchor === void 0 ? null : unitPoint(anchor), serial: nextSerial
|
|
808
|
+
scrollTo: (id, anchor, options) => setRequest({ id, anchor: anchor === void 0 ? null : unitPoint(anchor), serial: nextSerial++, ...options?.axes ? { axes: options.axes } : {} })
|
|
806
809
|
};
|
|
807
810
|
return /* @__PURE__ */ jsx(ScrollRequestContext.Provider, { value: request, children: children(proxy) });
|
|
808
811
|
}
|
|
@@ -810,12 +813,12 @@ function ScrollTarget({ id, children }) {
|
|
|
810
813
|
const request = useContext(ScrollRequestContext);
|
|
811
814
|
const position = useContext(ScrollPositionContext);
|
|
812
815
|
const on = position ? { scrollposition: () => position.report(id) } : void 0;
|
|
813
|
-
if (request && request.id === id) return sb("styled", { style: { scrollID: true, scrollTo:
|
|
816
|
+
if (request && request.id === id) return sb("styled", { style: { scrollID: true, scrollTo: command(request) } }, on, children);
|
|
814
817
|
if (on) return sb("styled", { style: { scrollID: true } }, on, children);
|
|
815
818
|
return styled({ scrollID: true }, children);
|
|
816
819
|
}
|
|
817
820
|
const ScrollPositionContext = createContext(null);
|
|
818
|
-
function useScrollPosition(binding, anchor) {
|
|
821
|
+
function useScrollPosition(binding, anchor, axes) {
|
|
819
822
|
const bound = binding !== void 0;
|
|
820
823
|
const [value, set] = bound ? readBinding(binding) : [null, () => void 0];
|
|
821
824
|
const last = useRef(void 0);
|
|
@@ -825,7 +828,7 @@ function useScrollPosition(binding, anchor) {
|
|
|
825
828
|
const point = anchor === void 0 ? null : unitPoint(anchor);
|
|
826
829
|
if (value !== last.current) {
|
|
827
830
|
last.current = value;
|
|
828
|
-
if (value !== null && value !== reported.current) request.current = { id: value, anchor: point, serial: nextSerial
|
|
831
|
+
if (value !== null && value !== reported.current) request.current = { id: value, anchor: point, serial: nextSerial++, axes };
|
|
829
832
|
reported.current = void 0;
|
|
830
833
|
}
|
|
831
834
|
if (!bound) return null;
|
|
@@ -1002,7 +1005,7 @@ function ScrollView(props) {
|
|
|
1002
1005
|
if (own.defaultScrollAnchor !== void 0) scroll["defaultScrollAnchor"] = unitPoint(own.defaultScrollAnchor);
|
|
1003
1006
|
const edgeEffect = edgeEffectProp(settings);
|
|
1004
1007
|
if (edgeEffect) scroll["edgeEffect"] = edgeEffect;
|
|
1005
|
-
const position = useScrollPosition(own.scrollPosition, own.scrollPositionAnchor);
|
|
1008
|
+
const position = useScrollPosition(own.scrollPosition, own.scrollPositionAnchor, axes);
|
|
1006
1009
|
if (position) Object.assign(scroll, position.props);
|
|
1007
1010
|
const content = marginedContent(own.children, settings.margins, axes === "horizontal" ? "horizontal" : "vertical");
|
|
1008
1011
|
const inner = providingScrollSettings(ownSettings, content);
|
|
@@ -1596,9 +1599,9 @@ function matchesKey(event, key) {
|
|
|
1596
1599
|
function matchesShortcut(event, shortcut) {
|
|
1597
1600
|
if (!matchesKey(event, shortcut.key)) return false;
|
|
1598
1601
|
const wanted = new Set(shortcut.modifiers ?? ["command"]);
|
|
1599
|
-
const
|
|
1602
|
+
const command2 = isApple() ? event.metaKey : event.ctrlKey;
|
|
1600
1603
|
const control = isApple() ? event.ctrlKey : false;
|
|
1601
|
-
return
|
|
1604
|
+
return command2 === wanted.has("command") && event.shiftKey === wanted.has("shift") && event.altKey === wanted.has("option") && control === (isApple() && wanted.has("control"));
|
|
1602
1605
|
}
|
|
1603
1606
|
function useKeyboardShortcut(shortcut, action) {
|
|
1604
1607
|
const latest = useRef(action);
|
|
@@ -4063,18 +4066,18 @@ class GraphicsContext {
|
|
|
4063
4066
|
}
|
|
4064
4067
|
stroke(path, with_, options = {}) {
|
|
4065
4068
|
const o = typeof options === "number" ? { lineWidth: options } : options;
|
|
4066
|
-
const
|
|
4067
|
-
if (o.lineCap)
|
|
4068
|
-
if (o.lineJoin)
|
|
4069
|
-
if (o.miterLimit !== void 0)
|
|
4070
|
-
if (o.dash)
|
|
4071
|
-
if (o.dashPhase !== void 0)
|
|
4072
|
-
this.push(
|
|
4069
|
+
const command2 = { op: "stroke", path: path.svg(), shading: shading(with_), lineWidth: o.lineWidth ?? 1 };
|
|
4070
|
+
if (o.lineCap) command2.lineCap = o.lineCap;
|
|
4071
|
+
if (o.lineJoin) command2.lineJoin = o.lineJoin;
|
|
4072
|
+
if (o.miterLimit !== void 0) command2.miterLimit = o.miterLimit;
|
|
4073
|
+
if (o.dash) command2.dash = o.dash;
|
|
4074
|
+
if (o.dashPhase !== void 0) command2.dashPhase = o.dashPhase;
|
|
4075
|
+
this.push(command2);
|
|
4073
4076
|
return this;
|
|
4074
4077
|
}
|
|
4075
4078
|
/** `draw(Text(...), at:anchor:)` */
|
|
4076
4079
|
drawText(text, at, options = {}) {
|
|
4077
|
-
const
|
|
4080
|
+
const command2 = {
|
|
4078
4081
|
op: "text",
|
|
4079
4082
|
text,
|
|
4080
4083
|
x: at.x,
|
|
@@ -4082,14 +4085,14 @@ class GraphicsContext {
|
|
|
4082
4085
|
anchor: unitPoint(options.anchor ?? "center"),
|
|
4083
4086
|
shading: shading(options.color ?? "primary")
|
|
4084
4087
|
};
|
|
4085
|
-
if (options.font !== void 0)
|
|
4086
|
-
this.push(
|
|
4088
|
+
if (options.font !== void 0) command2.font = font(options.font);
|
|
4089
|
+
this.push(command2);
|
|
4087
4090
|
return this;
|
|
4088
4091
|
}
|
|
4089
4092
|
/** `draw(Image(...), at:anchor:)` or `draw(_:in:)` with `size`. */
|
|
4090
4093
|
drawImage(image, at, options = {}) {
|
|
4091
4094
|
const props = "url" in image ? { ...image, resizable: true } : "name" in image ? { name: image.name, resizable: true } : image;
|
|
4092
|
-
const
|
|
4095
|
+
const command2 = {
|
|
4093
4096
|
op: "image",
|
|
4094
4097
|
image: props,
|
|
4095
4098
|
x: at.x,
|
|
@@ -4098,17 +4101,17 @@ class GraphicsContext {
|
|
|
4098
4101
|
...options.size ? { width: options.size.width, height: options.size.height } : {},
|
|
4099
4102
|
...options.color !== void 0 ? { shading: shading(options.color) } : {}
|
|
4100
4103
|
};
|
|
4101
|
-
this.push(
|
|
4104
|
+
this.push(command2);
|
|
4102
4105
|
return this;
|
|
4103
4106
|
}
|
|
4104
|
-
push(
|
|
4107
|
+
push(command2) {
|
|
4105
4108
|
const state = {};
|
|
4106
4109
|
if (this.state.transform.some((v, i) => v !== IDENTITY[i])) state.transform = this.state.transform.map((v) => Math.round(v * 1e4) / 1e4);
|
|
4107
4110
|
if (this.state.opacity !== 1) state.opacity = this.state.opacity;
|
|
4108
4111
|
if (this.state.blendMode) state.blendMode = this.state.blendMode;
|
|
4109
4112
|
if (this.state.clips.length) state.clips = [...this.state.clips];
|
|
4110
4113
|
if (this.state.filters.length) state.filters = [...this.state.filters];
|
|
4111
|
-
this.commands.push({ ...state, ...
|
|
4114
|
+
this.commands.push({ ...state, ...command2 });
|
|
4112
4115
|
}
|
|
4113
4116
|
}
|
|
4114
4117
|
function Canvas(props) {
|