Skip to content

Commit

Permalink
Minify only internal APIs when building core
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Nov 30, 2024
1 parent 6494113 commit 5c1f7c8
Show file tree
Hide file tree
Showing 15 changed files with 381 additions and 381 deletions.
6 changes: 3 additions & 3 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const external = (id) =>
...Object.keys(pkg.devDependencies || {}),
].some((d) => id.startsWith(d));

const terserPlugin = ({ vue } = {}) =>
const terserPlugin = ({ core, vue } = {}) =>
terser({
ecma: 2018,
module: true,
compress: { passes: 5, unsafe: true, keep_fargs: false },
mangle: {
properties: {
// @vue/babel-plugin-jsx may generate _ field
regex: "^_.+",
regex: core ? "^_.+" : "^[$_].+",
...(vue && {
// [Vue warn]: Invalid prop name: "$" is a reserved property.
reserved: ["$"],
Expand Down Expand Up @@ -151,7 +151,7 @@ export default [
// declaration: true,
exclude: ["**/*.{spec,stories}.*"],
}),
terserPlugin(),
terserPlugin({ core: true }),
svelteCopy({
dir: path.dirname(pkg.exports["./svelte"].default),
coreDts: path.join(path.dirname(corePath), "index.d.ts"),
Expand Down
46 changes: 23 additions & 23 deletions src/core/resizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const createResizeObserver = (cb: ResizeObserverCallback) => {
export type ItemResizeObserver = (el: HTMLElement, i: number) => () => void;

interface ListResizer {
_observeRoot(viewportElement: HTMLElement): void;
_observeItem: ItemResizeObserver;
_dispose(): void;
$observeRoot(viewportElement: HTMLElement): void;
$observeItem: ItemResizeObserver;
$dispose(): void;
}

/**
Expand All @@ -58,7 +58,7 @@ export const createResizer = (
if (!(target as HTMLElement).offsetParent) continue;

if (target === viewportElement) {
store._update(ACTION_VIEWPORT_RESIZE, contentRect[sizeKey]);
store.$update(ACTION_VIEWPORT_RESIZE, contentRect[sizeKey]);
} else {
const index = mountedIndexes.get(target);
if (index != NULL) {
Expand All @@ -68,30 +68,30 @@ export const createResizer = (
}

if (resizes.length) {
store._update(ACTION_ITEM_RESIZE, resizes);
store.$update(ACTION_ITEM_RESIZE, resizes);
}
});

return {
_observeRoot(viewport: HTMLElement) {
$observeRoot(viewport: HTMLElement) {
resizeObserver._observe((viewportElement = viewport));
},
_observeItem: (el: HTMLElement, i: number) => {
$observeItem: (el: HTMLElement, i: number) => {
mountedIndexes.set(el, i);
resizeObserver._observe(el);
return () => {
mountedIndexes.delete(el);
resizeObserver._unobserve(el);
};
},
_dispose: resizeObserver._dispose,
$dispose: resizeObserver._dispose,
};
};

interface WindowListResizer {
_observeRoot(container: HTMLElement): void;
_observeItem: ItemResizeObserver;
_dispose(): void;
$observeRoot(container: HTMLElement): void;
$observeItem: ItemResizeObserver;
$dispose(): void;
}

/**
Expand All @@ -118,17 +118,17 @@ export const createWindowResizer = (
}

if (resizes.length) {
store._update(ACTION_ITEM_RESIZE, resizes);
store.$update(ACTION_ITEM_RESIZE, resizes);
}
});

let cleanupOnWindowResize: (() => void) | undefined;

return {
_observeRoot(container) {
$observeRoot(container) {
const window = getCurrentWindow(getCurrentDocument(container));
const onWindowResize = () => {
store._update(ACTION_VIEWPORT_RESIZE, window[windowSizeKey]);
store.$update(ACTION_VIEWPORT_RESIZE, window[windowSizeKey]);
};
window.addEventListener("resize", onWindowResize);
onWindowResize();
Expand All @@ -137,15 +137,15 @@ export const createWindowResizer = (
window.removeEventListener("resize", onWindowResize);
};
},
_observeItem: (el: HTMLElement, i: number) => {
$observeItem: (el: HTMLElement, i: number) => {
mountedIndexes.set(el, i);
resizeObserver._observe(el);
return () => {
mountedIndexes.delete(el);
resizeObserver._unobserve(el);
};
},
_dispose() {
$dispose() {
cleanupOnWindowResize && cleanupOnWindowResize();
resizeObserver._dispose();
},
Expand Down Expand Up @@ -183,8 +183,8 @@ export const createGridResizer = (
if (!(target as HTMLElement).offsetParent) continue;

if (target === viewportElement) {
vStore._update(ACTION_VIEWPORT_RESIZE, contentRect[heightKey]);
hStore._update(ACTION_VIEWPORT_RESIZE, contentRect[widthKey]);
vStore.$update(ACTION_VIEWPORT_RESIZE, contentRect[heightKey]);
hStore.$update(ACTION_VIEWPORT_RESIZE, contentRect[widthKey]);
} else {
const cell = mountedIndexes.get(target);
if (cell) {
Expand Down Expand Up @@ -234,7 +234,7 @@ export const createGridResizer = (
heightResizes.push([rowIndex, maxHeight]);
}
});
vStore._update(ACTION_ITEM_RESIZE, heightResizes);
vStore.$update(ACTION_ITEM_RESIZE, heightResizes);
}
if (resizedCols.size) {
const widthResizes: ItemResize[] = [];
Expand All @@ -250,15 +250,15 @@ export const createGridResizer = (
widthResizes.push([colIndex, maxWidth]);
}
});
hStore._update(ACTION_ITEM_RESIZE, widthResizes);
hStore.$update(ACTION_ITEM_RESIZE, widthResizes);
}
});

return {
_observeRoot(viewport: HTMLElement) {
$observeRoot(viewport: HTMLElement) {
resizeObserver._observe((viewportElement = viewport));
},
_observeItem(el: HTMLElement, rowIndex: number, colIndex: number) {
$observeItem(el: HTMLElement, rowIndex: number, colIndex: number) {
mountedIndexes.set(el, [rowIndex, colIndex]);
maybeCachedRowIndexes.add(rowIndex);
maybeCachedColIndexes.add(colIndex);
Expand All @@ -268,7 +268,7 @@ export const createGridResizer = (
resizeObserver._unobserve(el);
};
},
_dispose: resizeObserver._dispose,
$dispose: resizeObserver._dispose,
};
};

Expand Down
Loading

0 comments on commit 5c1f7c8

Please sign in to comment.